Add more crystal chest stuff...

This commit is contained in:
Christian Weeks 2012-02-11 01:55:30 -05:00
parent b43d4abdd5
commit e341f4d2f3
5 changed files with 75 additions and 21 deletions

View File

@ -12,20 +12,25 @@ import static org.lwjgl.opengl.GL11.glTranslatef;
import java.util.Random; import java.util.Random;
import net.minecraft.src.Block; import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack; import net.minecraft.src.ItemStack;
import net.minecraft.src.ModelChest; import net.minecraft.src.ModelChest;
import net.minecraft.src.RenderBlocks; import net.minecraft.src.RenderBlocks;
import net.minecraft.src.RenderManager;
import net.minecraft.src.Tessellator;
import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntity;
import net.minecraft.src.TileEntitySpecialRenderer; import net.minecraft.src.TileEntitySpecialRenderer;
import net.minecraft.src.forge.ForgeHooksClient; import net.minecraft.src.forge.ForgeHooksClient;
import net.minecraft.src.forge.ICustomItemRenderer;
import net.minecraft.src.forge.MinecraftForgeClient;
import cpw.mods.ironchest.TileEntityIronChest; import cpw.mods.ironchest.TileEntityIronChest;
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer { public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
private Random random; private Random random;
private RenderBlocks renderBlocks; private RenderBlocks renderBlocks;
private static float[][] shifts = { { 0.3F, 0.7F, 0.3F }, { 0.7F, 0.7F, 0.3F }, { 0.3F, 0.7F, 0.7F }, { 0.7F, 0.7F, 0.7F }, private static float[][] shifts = { { 0.3F, 0.45F, 0.3F }, { 0.7F, 0.45F, 0.3F }, { 0.3F, 0.45F, 0.7F }, { 0.7F, 0.45F, 0.7F },
{ 0.3F, 0.15F, 0.3F }, { 0.7F, 0.15F, 0.3F }, { 0.3F, 0.15F, 0.7F }, { 0.7F, 0.15F, 0.7F }, { 0.5F, 0.35F, 0.5F }, }; { 0.3F, 0.1F, 0.3F }, { 0.7F, 0.1F, 0.3F }, { 0.3F, 0.1F, 0.7F }, { 0.7F, 0.1F, 0.7F }, { 0.5F, 0.35F, 0.5F }, };
public TileEntityIronChestRenderer() { public TileEntityIronChestRenderer() {
model = new ModelChest(); model = new ModelChest();
@ -81,10 +86,13 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
float shiftY; float shiftY;
float shiftZ; float shiftZ;
int shift = 0; int shift = 0;
float blockScale = 0.125F; float spread = 0.1F;
float blockScale = 0.15F;
float timeD = (float) (360.0 * (double) (System.currentTimeMillis() & 0x3FFFL) / (double) 0x3FFFL);
if (tile.getTopItemStacks()[1] == null) { if (tile.getTopItemStacks()[1] == null) {
shift = 8; shift = 8;
blockScale = 0.25F; blockScale = 0.2F;
spread = 0.25F;
} }
for (ItemStack item : tile.getTopItemStacks()) { for (ItemStack item : tile.getTopItemStacks()) {
if (shift > shifts.length) { if (shift > shifts.length) {
@ -98,33 +106,66 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
shiftY = shifts[shift][1]; shiftY = shifts[shift][1];
shiftZ = shifts[shift][2]; shiftZ = shifts[shift][2];
shift++; shift++;
if (item.itemID < Block.blocksList.length && RenderBlocks.renderItemIn3d(Block.blocksList[item.itemID].getRenderType())) { ICustomItemRenderer customRenderer = MinecraftForgeClient.getCustomItemRenderer(item.itemID);
glPushMatrix(); float localScale = blockScale;
if (item.itemID < Block.blocksList.length) {
bindTextureByName("/terrain.png"); bindTextureByName("/terrain.png");
ForgeHooksClient.overrideTexture(Block.blocksList[item.itemID]); ForgeHooksClient.overrideTexture(Block.blocksList[item.itemID]);
int j = Block.blocksList[item.itemID].getRenderType(); int j = Block.blocksList[item.itemID].getRenderType();
float localScale = blockScale;
if (j == 1 || j == 19 || j == 12 || j == 2) { if (j == 1 || j == 19 || j == 12 || j == 2) {
localScale = 2 * blockScale; localScale = 2 * blockScale;
} }
glTranslatef(shiftX, shiftY, shiftZ); }
glScalef(localScale, localScale, localScale); glPushMatrix();
float timeD = (float) (360.0 * (double) (System.currentTimeMillis() & 0x3FFFL) / (double) 0x3FFFL); glTranslatef(shiftX, shiftY, shiftZ);
for (int miniBlocks = 0; miniBlocks < (item.stackSize / 32) + 1; miniBlocks++) { glScalef(localScale, localScale, localScale);
glPushMatrix(); for (int miniBlocks = 0; miniBlocks < (item.stackSize / 32) + 1; miniBlocks++) {
glRotatef(timeD, 0.0F, 1.0F, 0.0F); glPushMatrix();
if (miniBlocks > 0) { glRotatef(timeD, 0.0F, 1.0F, 0.0F);
float minishiftX = ((random.nextFloat() * 2.0F - 1.0F) * 0.1F) / localScale; if (miniBlocks > 0) {
float minishiftY = ((random.nextFloat() * 2.0F - 1.0F) * 0.1F) / localScale; float minishiftX = ((random.nextFloat() * 2.0F - 1.0F) * spread) / localScale;
float minishiftZ = ((random.nextFloat() * 2.0F - 1.0F) * 0.1F) / localScale; float minishiftY = ((random.nextFloat() * 2.0F - 1.0F) * spread) / localScale;
glTranslatef(minishiftX, minishiftY, minishiftZ); float minishiftZ = ((random.nextFloat() * 2.0F - 1.0F) * spread) / localScale;
} glTranslatef(minishiftX, minishiftY, minishiftZ);
renderBlocks.renderBlockAsItem(Block.blocksList[item.itemID], item.getItemDamage(), 1.0F); }
glPopMatrix(); if (customRenderer != null) {
ForgeHooksClient.renderCustomItem(customRenderer, renderBlocks, item.itemID, item.getItemDamage(), 1.0F);
} else if (item.itemID < Block.blocksList.length && RenderBlocks.renderItemIn3d(Block.blocksList[item.itemID].getRenderType())) {
renderBlocks.renderBlockAsItem(Block.blocksList[item.itemID], item.getItemDamage(), 1.0F);
} else {
int i = item.getIconIndex();
if (item.itemID >= Block.blocksList.length) {
bindTextureByName("/gui/items.png");
ForgeHooksClient.overrideTexture(Item.itemsList[item.itemID]);
}
Tessellator tessellator = Tessellator.instance;
float f5 = (float) ((i % 16) * 16 + 0) / 256F;
float f8 = (float) ((i % 16) * 16 + 16) / 256F;
float f10 = (float) ((i / 16) * 16 + 0) / 256F;
float f12 = (float) ((i / 16) * 16 + 16) / 256F;
float f13 = 1.0F;
float f14 = 0.5F;
float f15 = 0.25F;
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 1.0F, 0.0F);
tessellator.addVertexWithUV(0.0F - f14, 0.0F - f15, 0.0D, f5, f12);
tessellator.addVertexWithUV(f13 - f14, 0.0F - f15, 0.0D, f8, f12);
tessellator.addVertexWithUV(f13 - f14, 1.0F - f15, 0.0D, f8, f10);
tessellator.addVertexWithUV(0.0F - f14, 1.0F - f15, 0.0D, f5, f10);
tessellator.draw();
glScalef(-1.0F, 1.0F, 1.0F);
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 1.0F, 0.0F);
tessellator.addVertexWithUV(0.0F - f14, 0.0F - f15, 0.0D, f5, f12);
tessellator.addVertexWithUV(f13 - f14, 0.0F - f15, 0.0D, f8, f12);
tessellator.addVertexWithUV(f13 - f14, 1.0F - f15, 0.0D, f8, f10);
tessellator.addVertexWithUV(0.0F - f14, 1.0F - f15, 0.0D, f5, f10);
tessellator.draw();
} }
glPopMatrix(); glPopMatrix();
} }
glPopMatrix();
} }
glDisable(32826 /* GL_RESCALE_NORMAL_EXT */); glDisable(32826 /* GL_RESCALE_NORMAL_EXT */);
glEnable(2896 /* GL_LIGHTING */); glEnable(2896 /* GL_LIGHTING */);

View File

@ -0,0 +1,7 @@
package cpw.mods.ironchest;
public class TileEntityCrystalChest extends TileEntityIronChest {
public TileEntityCrystalChest() {
super(IronChestType.CRYSTAL);
}
}

View File

@ -20,6 +20,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
public ItemStack[] chestContents; public ItemStack[] chestContents;
private ItemStack[] topStacks; private ItemStack[] topStacks;
private byte facing; private byte facing;
private boolean inventoryTouched;
public TileEntityIronChest() { public TileEntityIronChest() {
this(IronChestType.IRON); this(IronChestType.IRON);
@ -54,6 +55,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
} }
@Override @Override
public ItemStack getStackInSlot(int i) { public ItemStack getStackInSlot(int i) {
inventoryTouched=true;
return chestContents[i]; return chestContents[i];
} }
@ -212,6 +214,10 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
// Resynchronize clients with the server state // Resynchronize clients with the server state
if ((++ticksSinceSync % 20) * 4 == 0) { if ((++ticksSinceSync % 20) * 4 == 0) {
worldObj.playNoteAt(xCoord, yCoord, zCoord, 3, ( ( numUsingPlayers<<3 ) & 0xF8 ) | (facing & 0x7)); worldObj.playNoteAt(xCoord, yCoord, zCoord, 3, ( ( numUsingPlayers<<3 ) & 0xF8 ) | (facing & 0x7));
if (inventoryTouched) {
inventoryTouched=false;
sortTopStacks();
}
} }
prevLidAngle = lidAngle; prevLidAngle = lidAngle;
float f = 0.1F; float f = 0.1F;

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB