Skip to content
Permalink
Browse files

Fully implemented and polished tool racks.

Not only that, I also added 2 utility methods for smart placement, some quality of life improvements and some modifications here and there.
  • Loading branch information...
LightningSh0ck committed Sep 7, 2018
1 parent 8ace6f8 commit 2565e060de5348d23020e055267a8b0941cb0308
@@ -28,4 +28,6 @@
public static final String GUI_FACTORY = "net.dries007.tfc.client.TFCModGuiFactory";

public static final Random RNG = new Random();

public static final float[] META_TO_ANGLE = new float[]{180f, 90f, 0f, 270f};
}
@@ -43,7 +43,11 @@
import net.dries007.tfc.api.types.Metal;
import net.dries007.tfc.api.types.Ore;
import net.dries007.tfc.api.types.Rock;
import net.dries007.tfc.client.render.*;
import net.dries007.tfc.client.render.TESRChestTFC;
import net.dries007.tfc.client.render.TESRIngotPile;
import net.dries007.tfc.client.render.TESRPitKiln;
import net.dries007.tfc.client.render.TESRToolRack;
import net.dries007.tfc.client.render.TESRWorldItem;
import net.dries007.tfc.objects.Gem;
import net.dries007.tfc.objects.blocks.BlockSlabTFC;
import net.dries007.tfc.objects.blocks.BlocksTFC;
@@ -58,7 +62,11 @@
import net.dries007.tfc.objects.items.ItemsTFC;
import net.dries007.tfc.objects.items.ceramics.ItemMold;
import net.dries007.tfc.objects.items.metal.ItemOreTFC;
import net.dries007.tfc.objects.te.*;
import net.dries007.tfc.objects.te.TEChestTFC;
import net.dries007.tfc.objects.te.TEIngotPile;
import net.dries007.tfc.objects.te.TEPitKiln;
import net.dries007.tfc.objects.te.TEToolRack;
import net.dries007.tfc.objects.te.TEWorldItem;

import static net.dries007.tfc.api.util.TFCConstants.MOD_ID;

@@ -15,155 +15,86 @@

import net.dries007.tfc.objects.te.TEToolRack;

import static net.dries007.tfc.Constants.META_TO_ANGLE;

public class TESRToolRack extends TileEntitySpecialRenderer<TEToolRack>
{
//direction, slot, axis, that's the order.
static final float[][][] location = new float[4][4][3];
static{
//Config values for moving the item placement
final float heightLow = .28125f;
final float heightHigh = .78125f;
final float column1 = .25f;
final float column2 = .75f;
final float offset = .09375f;

final float offsetInv = 1f - offset;

//Hardcoding values so render doesn't have to calculate
for(int dir=0;dir<4;dir++)
{
for (int slot = 0; slot < 4; slot++)
{
if (slot < 2)
location[dir][slot][1] = heightHigh;
else
location[dir][slot][1] = heightLow;

if (dir % 2 == 0)
{
if (slot % 2 == 0)
location[dir][slot][0] = column1;
else
location[dir][slot][0] = column2;
}
else
{
if (slot % 2 == 0)
location[dir][slot][2] = column1;
else
location[dir][slot][2] = column2;
}

if (dir == 0)
{
location[dir][slot][2] = offset;
}
else if (dir == 1)
{
location[dir][slot][0] = offsetInv;
}
else if (dir == 2)
{
location[dir][slot][2] = offsetInv;
}
else //if (dir == 3)
{
location[dir][slot][0] = offset;
}
}
}
}

@Override
public void render(TEToolRack te, double x, double y, double z, float partialTicks, int destroyStage, float alpha)
{
{
int dir = te.getBlockMetadata();
//EntityItem customitem = new EntityItem(field_147501_a.field_147550_f); //tileEntityRenderer.worldObj
//customitem.hoverStart = 0f;
float blockScale = .5f;
//float timeD = (float) (360.0 * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL);
for (int i = 0; i < 4; i++)
{
ItemStack stack = te.getItems().get(i);
if (te.getItems().get(i) != ItemStack.EMPTY)
{
float[] loc = getLocation(dir, i);
GlStateManager.pushMatrix(); //start
GlStateManager.translate(x + loc[0], y + loc[1], z + loc[2]);
/*if (RenderManager.instance.options.fancyGraphics)
{
GlStateManager.glRotatef(loc[3], 0.0F, 1.0F, 0.0F);
}*/
GlStateManager.pushMatrix();
GlStateManager.translate(x + location[dir][i][0], y + location[dir][i][1], z + location[dir][i][2]);
GlStateManager.rotate(META_TO_ANGLE[dir], 0.0F, 1.0F, 0.0F);
GlStateManager.scale(blockScale, blockScale, blockScale);
Minecraft.getMinecraft().getRenderItem().renderItem(stack, ItemCameraTransforms.TransformType.FIXED);
/*customitem.setEntityItemStack(te.getStackInSlot(i));
itemRenderer.doRender(customitem, 0, 0, 0, 0, 0);*/
GlStateManager.popMatrix(); //end
GlStateManager.popMatrix();
}
}
}
}


public float[] getLocation(int dir, int slot)
{
float[] out = new float[4];
if (dir == 0)
{
out[3] = 0f;
if (slot == 0)
{
out[0] = 0.25f;
out[1] = 0.5f;
out[2] = 0.94f;
}
else if (slot == 1)
{
out[0] = 0.75f;
out[1] = 0.5f;
out[2] = 0.94f;
}
else if (slot == 2)
{
out[0] = 0.25f;
out[1] = 0.1f;
out[2] = 0.94f;
}
else if (slot == 3)
{
out[0] = 0.75f;
out[1] = 0.1f;
out[2] = 0.94f;
}
}
else if (dir == 1)
{
out[3] = 270f;
if (slot == 0)
{
out[0] = 0.06f;
out[1] = 0.5f;
out[2] = 0.25f;
}
else if (slot == 1)
{
out[0] = 0.06f;
out[1] = 0.5f;
out[2] = 0.75f;
}
else if (slot == 2)
{
out[0] = 0.06f;
out[1] = 0.1f;
out[2] = 0.25f;
}
else if (slot == 3)
{
out[0] = 0.06f;
out[1] = 0.1f;
out[2] = 0.75f;
}
}
else if (dir == 2)
{
out[3] = 180f;
if (slot == 0)
{
out[0] = 0.25f;
out[1] = 0.5f;
out[2] = 0.06f;
}
else if (slot == 1)
{
out[0] = 0.75f;
out[1] = 0.5f;
out[2] = 0.06f;
}
else if (slot == 2)
{
out[0] = 0.25f;
out[1] = 0.1f;
out[2] = 0.06f;
}
else if (slot == 3)
{
out[0] = 0.75f;
out[1] = 0.1f;
out[2] = 0.06f;
}
}
else if (dir == 3)
{
out[3] = 90f;
if (slot == 0)
{
out[0] = 0.94f;
out[1] = 0.5f;
out[2] = 0.25f;
}
else if (slot == 1)
{
out[0] = 0.94f;
out[1] = 0.5f;
out[2] = 0.75f;
}
else if (slot == 2)
{
out[0] = 0.94f;
out[1] = 0.1f;
out[2] = 0.25f;
}
else if (slot == 3)
{
out[0] = 0.94f;
out[1] = 0.1f;
out[2] = 0.75f;
}
}
return out;
}
}
@@ -27,7 +27,7 @@ public void render(TEWorldItem te, double x, double y, double z, float partialTi
//GlStateManager.translate((i % 2 == 0 ? 1 : 0), 0, (i < 2 ? 1 : 0));
//GlStateManager.rotate(timeD, 0, 1, 0);
GlStateManager.translate(x + 0.5D, y + 0.03125D, z + 0.5D);
GlStateManager.scale(.5d, .5d, .5d); //I used doubles here because I think they will cast to that anyway
GlStateManager.scale(.5f, .5f, .5f);
GlStateManager.rotate(90f, 1f, 0f, 0f);
GlStateManager.rotate(90f * (float) rotation, 0f, 0f, 1f);
Minecraft.getMinecraft().getRenderItem().renderItem(stack, ItemCameraTransforms.TransformType.FIXED);
@@ -61,6 +61,7 @@ public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos,
public IBlockState getStateFromMeta(int meta)
{
IBlockState state = getDefaultState().withProperty(LIT, (meta & 0b1000) == 0b1000);
//TODO: I recommend to replace this with state.withProperty(FACING, EnumFacing.byIndex(meta & 0b0111)) - LS
switch (meta & 0b0111)
{
default:
@@ -81,6 +82,7 @@ public IBlockState getStateFromMeta(int meta)
public int getMetaFromState(IBlockState state)
{
int meta = state.getValue(LIT) ? 0b1000 : 0;
//TODO: I recommend to replace this with state.getValue(FACING).getIndex() - LS
switch (state.getValue(FACING))
{
default:
@@ -293,7 +293,7 @@ public static void registerBlocks(RegistryEvent.Register<Block> event)
chests.add(register(r, "wood/chest/" + wood.getRegistryName().getPath(), new BlockChestTFC(BlockChest.Type.BASIC, wood), CT_DECORATIONS));
chests.add(register(r, "wood/chest_trap/" + wood.getRegistryName().getPath(), new BlockChestTFC(BlockChest.Type.TRAP, wood), CT_DECORATIONS));
inventoryItemBlocks.put(register(r, "wood/button/" + wood.getRegistryName().getPath(), new BlockButtonWoodTFC(wood), CT_DECORATIONS), ItemBlockTFC.class);
toolRacks.add(register(r, "wood/tool_rack/" + wood.getRegistryName().getPath(), new BlockToolRack(wood), CT_DECORATIONS));
toolRacks.add(register(r, "wood/tool_rack/" + wood.getRegistryName().getPath(), new BlockToolRack(wood, .5F, 3F), CT_DECORATIONS));
}
allLogBlocks = logs.build();
allLeafBlocks = leaves.build();
@@ -390,7 +390,6 @@ public static void registerBlocks(RegistryEvent.Register<Block> event)
// todo: supports (h & v)
// todo: farmland
// todo: barrels
// todo: tool racks
// todo: wood trap doors

// todo: metal lamps (on/off with states)

0 comments on commit 2565e06

Please sign in to comment.
You can’t perform that action at this time.