mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-11-12 16:37:28 +00:00
Framing table rendering (:
This commit is contained in:
1 parent
79cde438d5
commit
275b68d2e5
12 files changed
+316
-6
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 306 B |
Binary file not shown.
|
After Width: | Height: | Size: 272 B |
Binary file not shown.
|
After Width: | Height: | Size: 279 B |
Binary file not shown.
|
After Width: | Height: | Size: 258 B |
@@ -4,14 +4,23 @@ import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityFramingTable;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ModCreativeTabs;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.handlers.GuiHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockFramingTable extends BlockContainer
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
IIcon iconBase;
|
||||
@SideOnly(Side.CLIENT)
|
||||
IIcon iconTrim;
|
||||
|
||||
public BlockFramingTable (String blockName) {
|
||||
super(Material.wood);
|
||||
|
||||
@@ -31,4 +40,35 @@ public class BlockFramingTable extends BlockContainer
|
||||
player.openGui(StorageDrawers.instance, GuiHandler.framingGuiID, world, x, y, z);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube () {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderAsNormalBlock () {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType () {
|
||||
return StorageDrawers.proxy.framingTableRenderID;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIconBase () {
|
||||
return iconBase;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIconTrim () {
|
||||
return iconTrim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBlockIcons (IIconRegister register) {
|
||||
iconBase = register.registerIcon(StorageDrawers.MOD_ID + ":base/base_oak");
|
||||
iconTrim = register.registerIcon(StorageDrawers.MOD_ID + ":base/trim_oak");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.client.renderer;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.BlockFramingTable;
|
||||
import com.jaquadro.minecraft.storagedrawers.client.renderer.common.CommonFramingRenderer;
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
public class FramingTableRenderer implements ISimpleBlockRenderingHandler
|
||||
{
|
||||
private CommonFramingRenderer framingRenderer = new CommonFramingRenderer();
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock (Block block, int metadata, int modelId, RenderBlocks renderer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock (IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
if (!(block instanceof BlockFramingTable))
|
||||
return false;
|
||||
|
||||
BlockFramingTable framingTable = (BlockFramingTable)block;
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
if ((meta & 0x8) == 0)
|
||||
framingRenderer.renderRight(world, x, y, z, framingTable);
|
||||
else
|
||||
framingRenderer.renderLeft(world, x, y, z, framingTable);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender3DInInventory (int modelId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderId () {
|
||||
return StorageDrawers.proxy.framingTableRenderID;
|
||||
}
|
||||
}
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.client.renderer.common;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.block.BlockFramingTable;
|
||||
import com.jaquadro.minecraft.storagedrawers.util.RenderHelper;
|
||||
import com.jaquadro.minecraft.storagedrawers.util.RenderHelperState;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
public class CommonFramingRenderer
|
||||
{
|
||||
private static double unit = .0625;
|
||||
private static double unit2 = unit * 2;
|
||||
private static double unit4 = unit * 4;
|
||||
private static double unit14 = unit * 14;
|
||||
|
||||
private static double[][] baseBoundsLeftY = new double[][] {
|
||||
{ unit, 1 - unit2, unit, 1, 1, 1 - unit }
|
||||
};
|
||||
|
||||
private static double[][] trimBoundsLeftY = new double[][] {
|
||||
{ 0, 1 - unit2, unit, unit, 1, 1 - unit },
|
||||
{ 0, 1 - unit2, 0, unit, 1, unit },
|
||||
{ 0, 1 - unit2, 1 - unit, unit, 1, 1 },
|
||||
{ unit, 1 - unit2, 0, 1, 1, unit },
|
||||
{ unit, 1 - unit2, 1 - unit, 1, 1, 1 },
|
||||
};
|
||||
|
||||
private static double[][] trimBoundsLeftZ = new double[][] {
|
||||
{ 0, 1 - unit2, 0, unit, 1, 1 },
|
||||
{ unit, 1 - unit2, 0, 1, 1, 1 },
|
||||
};
|
||||
|
||||
private static double[][] trimBoundsLeftX = new double[][] {
|
||||
{ 0, 1 - unit2, 0, 1, 1, unit },
|
||||
{ 0, 1 - unit2, unit, 1, 1, 1 - unit },
|
||||
{ 0, 1 - unit2, 1 - unit, 1, 1, 1 },
|
||||
};
|
||||
|
||||
private static double[][] baseBoundsRightY = new double[][] {
|
||||
{ 0, 1 - unit2, unit, 1 - unit, 1, 1 - unit }
|
||||
};
|
||||
|
||||
private static double[][] trimBoundsRightY = new double[][] {
|
||||
{ 1 - unit, 1 - unit2, unit, 1, 1, 1 - unit },
|
||||
{ 1 - unit, 1 - unit2, 0, 1, 1, unit },
|
||||
{ 1 - unit, 1 - unit2, 1 - unit, 1, 1, 1 },
|
||||
{ 0, 1 - unit2, 0, 1 - unit, 1, unit },
|
||||
{ 0, 1 - unit2, 1 - unit, 1 - unit, 1, 1 },
|
||||
};
|
||||
|
||||
private static double[][] trimBoundsRightZ = new double[][] {
|
||||
{ 1 - unit, 1 - unit2, 0, 1, 1, 1 },
|
||||
{ 0, 1 - unit2, 0, 1 - unit, 1, 1 },
|
||||
};
|
||||
|
||||
private static double[][] trimBoundsRightX = new double[][] {
|
||||
{ 0, 1 - unit2, 0, 1, 1, unit },
|
||||
{ 0, 1 - unit2, unit, 1, 1, 1 - unit },
|
||||
{ 0, 1 - unit2, 1 - unit, 1, 1, 1 },
|
||||
};
|
||||
|
||||
public void renderLeft (IBlockAccess blockAccess, int x, int y, int z, BlockFramingTable block) {
|
||||
renderTableBox(blockAccess, x, y, z, block, baseBoundsLeftY, trimBoundsLeftY, trimBoundsLeftZ, trimBoundsLeftX, true);
|
||||
renderStructure(blockAccess, x, y, z, block, true);
|
||||
}
|
||||
|
||||
public void renderRight (IBlockAccess blockAccess, int x, int y, int z, BlockFramingTable block) {
|
||||
renderTableBox(blockAccess, x, y, z, block, baseBoundsRightY, trimBoundsRightY, trimBoundsRightZ, trimBoundsRightX, false);
|
||||
renderStructure(blockAccess, x, y, z, block, false);
|
||||
}
|
||||
|
||||
private void renderStructure (IBlockAccess blockAccess, int x, int y, int z, BlockFramingTable block, boolean left) {
|
||||
IIcon iconSurface = block.getIconBase();
|
||||
|
||||
renderFoot(blockAccess, x, y, z, block, iconSurface, left);
|
||||
renderLegs(blockAccess, x, y, z, block, iconSurface, left);
|
||||
renderBraces(blockAccess, x, y, z, block, iconSurface, left);
|
||||
}
|
||||
|
||||
private void renderTableBox (IBlockAccess blockAccess, int x, int y, int z, BlockFramingTable block, double[][] baseBoundsY, double[][] trimBoundsY, double[][] trimBoundsZ, double[][] trimBoundsX, boolean left) {
|
||||
RenderHelper renderer = RenderHelper.instance;
|
||||
|
||||
IIcon iconSurface = block.getIconBase();
|
||||
IIcon iconTrim = block.getIconTrim();
|
||||
|
||||
int xSide = left ? RenderHelper.XNEG : RenderHelper.XPOS;
|
||||
|
||||
for (double[] bound : baseBoundsY) {
|
||||
renderer.setRenderBounds(bound);
|
||||
renderer.renderFace(RenderHelper.YPOS, blockAccess, block, x, y, z, iconSurface);
|
||||
renderer.renderFace(RenderHelper.YNEG, blockAccess, block, x, y, z, iconSurface);
|
||||
}
|
||||
|
||||
for (double[] bound : trimBoundsY) {
|
||||
renderer.setRenderBounds(bound);
|
||||
renderer.renderFace(RenderHelper.YPOS, blockAccess, block, x, y, z, iconTrim);
|
||||
renderer.renderFace(RenderHelper.YNEG, blockAccess, block, x, y, z, iconTrim);
|
||||
}
|
||||
|
||||
for (double[] bound : trimBoundsZ) {
|
||||
renderer.setRenderBounds(bound);
|
||||
renderer.renderFace(RenderHelper.ZNEG, blockAccess, block, x, y, z, iconTrim);
|
||||
renderer.renderFace(RenderHelper.ZPOS, blockAccess, block, x, y, z, iconTrim);
|
||||
}
|
||||
|
||||
for (double[] bound : trimBoundsX) {
|
||||
renderer.setRenderBounds(bound);
|
||||
renderer.renderFace(xSide, blockAccess, block, x, y, z, iconTrim);
|
||||
}
|
||||
}
|
||||
|
||||
private void renderFoot (IBlockAccess blockAccess, int x, int y, int z, BlockFramingTable block, IIcon icon, boolean left) {
|
||||
RenderHelper renderer = RenderHelper.instance;
|
||||
|
||||
double xStart = left ? unit2 : 1 - unit2 - unit2;
|
||||
|
||||
renderer.setRenderBounds(xStart, 0, 0, xStart + unit2, unit2, 1);
|
||||
for (int i = 0; i < 6; i++)
|
||||
renderer.renderFace(i, blockAccess, block, x,y , z, icon);
|
||||
}
|
||||
|
||||
private void renderLegs (IBlockAccess blockAccess, int x, int y, int z, BlockFramingTable block, IIcon icon, boolean left) {
|
||||
RenderHelper renderer = RenderHelper.instance;
|
||||
|
||||
double xStart = left ? unit2 : 1 - unit2 - unit2;
|
||||
|
||||
renderer.setRenderBounds(xStart, unit2, unit2, xStart + unit2, 1 - unit2, unit2 + unit2);
|
||||
for (int i = 2; i < 6; i++)
|
||||
renderer.renderFace(i, blockAccess, block, x, y, z, icon);
|
||||
|
||||
renderer.setRenderBounds(xStart, unit2, 1 - unit2 - unit2, xStart + unit2, 1 - unit2, 1 - unit2);
|
||||
for (int i = 2; i < 6; i++)
|
||||
renderer.renderFace(i, blockAccess, block, x, y, z, icon);
|
||||
}
|
||||
|
||||
private void renderBraces (IBlockAccess blockAccess, int x, int y, int z, BlockFramingTable block, IIcon icon, boolean left) {
|
||||
RenderHelper renderer = RenderHelper.instance;
|
||||
|
||||
double xStart = left ? unit2 + unit2 : 0;
|
||||
double xStop = left ? 1 : 1 - unit2 - unit2;
|
||||
|
||||
renderer.setRenderBounds(xStart, unit4, unit2, xStop, unit4 + unit2, unit2 + unit2);
|
||||
for (int i = 0; i < 4; i++)
|
||||
renderer.renderFace(i, blockAccess, block, x, y, z, icon);
|
||||
|
||||
renderer.setRenderBounds(xStart, unit4, 1 - unit2 - unit2, xStop, unit4 + unit2, 1 - unit2);
|
||||
for (int i = 0; i < 4; i++)
|
||||
renderer.renderFace(i, blockAccess, block, x, y, z, icon);
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,7 @@ package com.jaquadro.minecraft.storagedrawers.core;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersComp;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersStandard;
|
||||
import com.jaquadro.minecraft.storagedrawers.client.renderer.ControllerRenderer;
|
||||
import com.jaquadro.minecraft.storagedrawers.client.renderer.DrawersCustomRenderer;
|
||||
import com.jaquadro.minecraft.storagedrawers.client.renderer.DrawersItemRenderer;
|
||||
import com.jaquadro.minecraft.storagedrawers.client.renderer.DrawersRenderer;
|
||||
import com.jaquadro.minecraft.storagedrawers.client.renderer.TileEntityDrawersRenderer;
|
||||
import com.jaquadro.minecraft.storagedrawers.client.renderer.*;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -23,10 +19,12 @@ public class ClientProxy extends CommonProxy
|
||||
drawersRenderID = RenderingRegistry.getNextAvailableRenderId();
|
||||
controllerRenderID = RenderingRegistry.getNextAvailableRenderId();
|
||||
drawersCustomRenderID = RenderingRegistry.getNextAvailableRenderId();
|
||||
framingTableRenderID = RenderingRegistry.getNextAvailableRenderId();
|
||||
|
||||
RenderingRegistry.registerBlockHandler(drawersRenderID, new DrawersRenderer());
|
||||
RenderingRegistry.registerBlockHandler(controllerRenderID, new ControllerRenderer());
|
||||
RenderingRegistry.registerBlockHandler(drawersCustomRenderID, new DrawersCustomRenderer());
|
||||
RenderingRegistry.registerBlockHandler(framingTableRenderID, new FramingTableRenderer());
|
||||
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDrawersStandard.class, new TileEntityDrawersRenderer());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDrawersComp.class, new TileEntityDrawersRenderer());
|
||||
|
||||
@@ -9,6 +9,7 @@ public class CommonProxy
|
||||
public int drawersRenderID = -1;
|
||||
public int controllerRenderID = -1;
|
||||
public int drawersCustomRenderID = -1;
|
||||
public int framingTableRenderID = -1;
|
||||
|
||||
public void registerRenderers ()
|
||||
{ }
|
||||
|
||||
@@ -73,7 +73,7 @@ public class ModBlocks
|
||||
if (config.isBlockEnabled("trim"))
|
||||
GameRegistry.registerBlock(trim, ItemTrim.class, "trim");
|
||||
|
||||
GameRegistry.registerBlock(framingTable, "framingTable");
|
||||
GameRegistry.registerBlock(framingTable, ItemFramingTable.class, "framingTable");
|
||||
|
||||
GameRegistry.registerBlock(fullCustom1, ItemCustomDrawers.class, "fullCustom1");
|
||||
GameRegistry.registerBlock(fullCustom2, ItemCustomDrawers.class, "fullCustom2");
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemFramingTable extends ItemBlock
|
||||
{
|
||||
public ItemFramingTable (Block block) {
|
||||
super(block);
|
||||
setMaxDamage(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlockAt (ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) {
|
||||
metadata = 0;
|
||||
if (side == 0)
|
||||
return false;
|
||||
if (side == 1) {
|
||||
int quad = (MathHelper.floor_double((double) (player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3);
|
||||
if (quad == 0)
|
||||
side = 2;
|
||||
if (quad == 1)
|
||||
side = 5;
|
||||
if (quad == 2)
|
||||
side = 3;
|
||||
if (quad == 3)
|
||||
side = 4;
|
||||
}
|
||||
|
||||
int xOff = 0;
|
||||
int zOff = 0;
|
||||
|
||||
if (side == 2)
|
||||
xOff = 1;
|
||||
if (side == 3)
|
||||
xOff = -1;
|
||||
if (side == 4)
|
||||
zOff = -1;
|
||||
if (side == 5)
|
||||
zOff = 1;
|
||||
|
||||
if (!world.isAirBlock(x, y, z) || !world.isAirBlock(x, y + 1, z))
|
||||
return false;
|
||||
if (!world.isAirBlock(x + xOff, y, z + zOff) || !world.isAirBlock(x + xOff, y + 1, z + zOff)) {
|
||||
if (side == 2 || side == 3)
|
||||
xOff *= -1;
|
||||
if (side == 4 || side == 5)
|
||||
zOff *= -1;
|
||||
if (!world.isAirBlock(x + xOff, y, z + zOff) || !world.isAirBlock(x + xOff, y + 1, z + zOff))
|
||||
return false;
|
||||
metadata = 8;
|
||||
}
|
||||
|
||||
if (!world.setBlock(x, y, z, field_150939_a, metadata | side, 3))
|
||||
return false;
|
||||
if (!world.setBlock(x + xOff, y, z + zOff, field_150939_a, (8 - metadata) | side, 3)) {
|
||||
world.setBlockToAir(x, y, z);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (world.getBlock(x, y, z) == field_150939_a) {
|
||||
field_150939_a.onBlockPlacedBy(world, x, y, z, player, stack);
|
||||
field_150939_a.onPostBlockPlaced(world, x, y, z, metadata | side);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,10 @@ public class RenderHelper
|
||||
state.setRenderBounds(xMin, yMin, zMin, xMax, yMax, zMax);
|
||||
}
|
||||
|
||||
public void setRenderBounds (double[] bound) {
|
||||
state.setRenderBounds(bound[0], bound[1], bound[2], bound[3], bound[4], bound[5]);
|
||||
}
|
||||
|
||||
public void setRenderBounds (Block block) {
|
||||
setRenderBounds(block.getBlockBoundsMinX(), block.getBlockBoundsMinY(), block.getBlockBoundsMinZ(), block.getBlockBoundsMaxX(), block.getBlockBoundsMaxY(), block.getBlockBoundsMaxZ());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user