Adding a crystal chest
This commit is contained in:
parent
6fd96b8e0d
commit
b43d4abdd5
|
@ -13,7 +13,7 @@
|
|||
</description>
|
||||
|
||||
<property name="modname" value="mod_ironchests" />
|
||||
<property name="version" value="2.3" />
|
||||
<property name="version" value="2.4" />
|
||||
<property name="mcp.home" location="/home/cpw/minecraft1dev/forge1.31" />
|
||||
<property name="mcp.obfoutput" location="${mcp.home}/reobf" />
|
||||
<property name="client.mcp.obfoutput" location="${mcp.obfoutput}/minecraft" />
|
||||
|
|
|
@ -18,7 +18,8 @@ public class GUIChest extends GuiContainer {
|
|||
GOLD(184,256,"/cpw/mods/ironchest/sprites/goldcontainer.png",IronChestType.GOLD),
|
||||
DIAMOND(238,256,"/cpw/mods/ironchest/sprites/diamondcontainer.png",IronChestType.DIAMOND),
|
||||
COPPER(184,184,"/cpw/mods/ironchest/sprites/coppercontainer.png",IronChestType.COPPER),
|
||||
SILVER(184,238,"/cpw/mods/ironchest/sprites/silvercontainer.png",IronChestType.SILVER);
|
||||
SILVER(184,238,"/cpw/mods/ironchest/sprites/silvercontainer.png",IronChestType.SILVER),
|
||||
CRYSTAL(184,238,"/cpw/mods/ironchest/sprites/silvercontainer.png",IronChestType.CRYSTAL);
|
||||
|
||||
private int xSize;
|
||||
private int ySize;
|
||||
|
|
|
@ -1,32 +1,51 @@
|
|||
package cpw.mods.ironchest.client;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import static org.lwjgl.opengl.GL11.glColor4f;
|
||||
import static org.lwjgl.opengl.GL11.glDisable;
|
||||
import static org.lwjgl.opengl.GL11.glEnable;
|
||||
import static org.lwjgl.opengl.GL11.glPopMatrix;
|
||||
import static org.lwjgl.opengl.GL11.glPushMatrix;
|
||||
import static org.lwjgl.opengl.GL11.glRotatef;
|
||||
import static org.lwjgl.opengl.GL11.glScalef;
|
||||
import static org.lwjgl.opengl.GL11.glTranslatef;
|
||||
|
||||
import cpw.mods.ironchest.TileEntityIronChest;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.ModelChest;
|
||||
import net.minecraft.src.RenderBlocks;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.TileEntitySpecialRenderer;
|
||||
import net.minecraft.src.forge.ForgeHooksClient;
|
||||
import cpw.mods.ironchest.TileEntityIronChest;
|
||||
|
||||
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
|
||||
private Random random;
|
||||
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 },
|
||||
{ 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 }, };
|
||||
|
||||
public TileEntityIronChestRenderer() {
|
||||
model = new ModelChest();
|
||||
random = new Random();
|
||||
renderBlocks = new RenderBlocks();
|
||||
}
|
||||
|
||||
public void render(TileEntityIronChest tile, double d, double d1, double d2, float f) {
|
||||
public void render(TileEntityIronChest tile, double x, double y, double z, float partialTick) {
|
||||
int facing = 3;
|
||||
if (tile != null && tile.worldObj != null) {
|
||||
facing = tile.getFacing();
|
||||
}
|
||||
bindTextureByName(tile.getType().getModelTexture());
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glEnable(32826 /* GL_RESCALE_NORMAL_EXT */);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GL11.glTranslatef((float) d, (float) d1 + 1.0F, (float) d2 + 1.0F);
|
||||
GL11.glScalef(1.0F, -1F, -1F);
|
||||
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
|
||||
glPushMatrix();
|
||||
glEnable(32826 /* GL_RESCALE_NORMAL_EXT */);
|
||||
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F);
|
||||
glScalef(1.0F, -1F, -1F);
|
||||
glTranslatef(0.5F, 0.5F, 0.5F);
|
||||
int k = 0;
|
||||
if (facing == 2) {
|
||||
k = 180;
|
||||
|
@ -40,20 +59,82 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
|
|||
if (facing == 5) {
|
||||
k = -90;
|
||||
}
|
||||
GL11.glRotatef(k, 0.0F, 1.0F, 0.0F);
|
||||
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
|
||||
float f1 = tile.prevLidAngle + (tile.lidAngle - tile.prevLidAngle) * f;
|
||||
f1 = 1.0F - f1;
|
||||
f1 = 1.0F - f1 * f1 * f1;
|
||||
model.chestLid.rotateAngleX = -((f1 * 3.141593F) / 2.0F);
|
||||
glRotatef(k, 0.0F, 1.0F, 0.0F);
|
||||
glTranslatef(-0.5F, -0.5F, -0.5F);
|
||||
float lidangle = tile.prevLidAngle + (tile.lidAngle - tile.prevLidAngle) * partialTick;
|
||||
lidangle = 1.0F - lidangle;
|
||||
lidangle = 1.0F - lidangle * lidangle * lidangle;
|
||||
model.chestLid.rotateAngleX = -((lidangle * 3.141593F) / 2.0F);
|
||||
// Render the chest itself
|
||||
model.func_35402_a();
|
||||
GL11.glDisable(32826 /* GL_RESCALE_NORMAL_EXT */);
|
||||
GL11.glPopMatrix();
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
glDisable(32826 /* GL_RESCALE_NORMAL_EXT */);
|
||||
glPopMatrix();
|
||||
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
if (tile.getType().isTransparent()) {
|
||||
random.setSeed(254L);
|
||||
glPushMatrix();
|
||||
glDisable(2896 /* GL_LIGHTING */);
|
||||
glEnable(32826 /* GL_RESCALE_NORMAL_EXT */);
|
||||
glTranslatef((float) x, (float) y, (float) z);
|
||||
float shiftX;
|
||||
float shiftY;
|
||||
float shiftZ;
|
||||
int shift = 0;
|
||||
float blockScale = 0.125F;
|
||||
if (tile.getTopItemStacks()[1] == null) {
|
||||
shift = 8;
|
||||
blockScale = 0.25F;
|
||||
}
|
||||
for (ItemStack item : tile.getTopItemStacks()) {
|
||||
if (shift > shifts.length) {
|
||||
break;
|
||||
}
|
||||
if (item == null) {
|
||||
shift++;
|
||||
continue;
|
||||
}
|
||||
shiftX = shifts[shift][0];
|
||||
shiftY = shifts[shift][1];
|
||||
shiftZ = shifts[shift][2];
|
||||
shift++;
|
||||
if (item.itemID < Block.blocksList.length && RenderBlocks.renderItemIn3d(Block.blocksList[item.itemID].getRenderType())) {
|
||||
glPushMatrix();
|
||||
bindTextureByName("/terrain.png");
|
||||
ForgeHooksClient.overrideTexture(Block.blocksList[item.itemID]);
|
||||
int j = Block.blocksList[item.itemID].getRenderType();
|
||||
float localScale = blockScale;
|
||||
if (j == 1 || j == 19 || j == 12 || j == 2) {
|
||||
localScale = 2 * blockScale;
|
||||
}
|
||||
glTranslatef(shiftX, shiftY, shiftZ);
|
||||
glScalef(localScale, localScale, localScale);
|
||||
float timeD = (float) (360.0 * (double) (System.currentTimeMillis() & 0x3FFFL) / (double) 0x3FFFL);
|
||||
for (int miniBlocks = 0; miniBlocks < (item.stackSize / 32) + 1; miniBlocks++) {
|
||||
glPushMatrix();
|
||||
glRotatef(timeD, 0.0F, 1.0F, 0.0F);
|
||||
if (miniBlocks > 0) {
|
||||
float minishiftX = ((random.nextFloat() * 2.0F - 1.0F) * 0.1F) / localScale;
|
||||
float minishiftY = ((random.nextFloat() * 2.0F - 1.0F) * 0.1F) / localScale;
|
||||
float minishiftZ = ((random.nextFloat() * 2.0F - 1.0F) * 0.1F) / localScale;
|
||||
glTranslatef(minishiftX, minishiftY, minishiftZ);
|
||||
}
|
||||
renderBlocks.renderBlockAsItem(Block.blocksList[item.itemID], item.getItemDamage(), 1.0F);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
glDisable(32826 /* GL_RESCALE_NORMAL_EXT */);
|
||||
glEnable(2896 /* GL_LIGHTING */);
|
||||
glPopMatrix();
|
||||
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
|
||||
public void renderTileEntityAt(TileEntity tileentity, double d, double d1, double d2, float f) {
|
||||
render((TileEntityIronChest) tileentity, d, d1, d2, f);
|
||||
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float partialTick) {
|
||||
render((TileEntityIronChest) tileentity, x, y, z, partialTick);
|
||||
}
|
||||
|
||||
private ModelChest model;
|
||||
|
|
|
@ -14,9 +14,10 @@ import net.minecraft.src.NBTTagCompound;
|
|||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraft.src.mod_IronChest;
|
||||
import net.minecraft.src.forge.IMultipassRender;
|
||||
import net.minecraft.src.forge.ITextureProvider;
|
||||
|
||||
public class BlockIronChest extends BlockContainer implements ITextureProvider {
|
||||
public class BlockIronChest extends BlockContainer implements ITextureProvider, IMultipassRender {
|
||||
|
||||
private Random random;
|
||||
public BlockIronChest(int id) {
|
||||
|
@ -179,4 +180,9 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRenderInPass(int n) {
|
||||
return n==0;
|
||||
}
|
||||
}
|
|
@ -15,7 +15,8 @@ public enum IronChestType {
|
|||
GOLD(81, 9, true, "Gold Chest", "guiGoldChest", "goldchest.png", 1, Item.ingotGold, TileEntityGoldChest.class, "mmmmPmmmm","mGmG4GmGm"),
|
||||
DIAMOND(108, 12, true, "Diamond Chest", "guiDiamondChest", "diamondchest.png", 2, Item.diamond, TileEntityDiamondChest.class, "GGGmPmGGG", "GGGG4Gmmm"),
|
||||
COPPER(45, 9, false, "Copper Chest", "guiCopperChest", "copperchest.png", 3, null, TileEntityCopperChest.class, "mmmmCmmmm"),
|
||||
SILVER(72, 9, false, "Silver Chest", "guiSilverChest", "silverchest.png", 4, null, TileEntitySilverChest.class, "mmmm0mmmm", "mmmm3mmmm");
|
||||
SILVER(72, 9, false, "Silver Chest", "guiSilverChest", "silverchest.png", 4, null, TileEntitySilverChest.class, "mmmm0mmmm", "mmmm3mmmm"),
|
||||
CRYSTAL(72, 9, true, "Crystal Chest", "guiSilverChest", "crystalchest.png", 5, null, TileEntityCrystalChest.class, "GGGGCGGGG");
|
||||
int size;
|
||||
private int rowLength;
|
||||
public String friendlyName;
|
||||
|
@ -129,4 +130,8 @@ public enum IronChestType {
|
|||
return matList;
|
||||
}
|
||||
|
||||
public boolean isTransparent() {
|
||||
return this==CRYSTAL;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
package cpw.mods.ironchest;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.IInventory;
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
@ -15,6 +18,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
|
|||
private int numUsingPlayers;
|
||||
private IronChestType type;
|
||||
public ItemStack[] chestContents;
|
||||
private ItemStack[] topStacks;
|
||||
private byte facing;
|
||||
|
||||
public TileEntityIronChest() {
|
||||
|
@ -25,6 +29,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
|
|||
super();
|
||||
this.type=type;
|
||||
this.chestContents=new ItemStack[getSizeInventory()];
|
||||
this.topStacks = new ItemStack[8];
|
||||
}
|
||||
|
||||
public ItemStack[] getContents() {
|
||||
|
@ -52,6 +57,65 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
|
|||
return chestContents[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInventoryChanged() {
|
||||
super.onInventoryChanged();
|
||||
sortTopStacks();
|
||||
}
|
||||
|
||||
protected void sortTopStacks() {
|
||||
if (!type.isTransparent()) {
|
||||
return;
|
||||
}
|
||||
ItemStack[] tempCopy=new ItemStack[getSizeInventory()];
|
||||
boolean hasStuff=false;
|
||||
int compressedIdx=0;
|
||||
mainLoop:
|
||||
for (int i=0; i<getSizeInventory(); i++) {
|
||||
if (chestContents[i]!=null) {
|
||||
for (int j=0; j<compressedIdx; j++) {
|
||||
if (tempCopy[j].isItemEqual(chestContents[i])) {
|
||||
tempCopy[j].stackSize+=chestContents[i].stackSize;
|
||||
continue mainLoop;
|
||||
}
|
||||
}
|
||||
tempCopy[compressedIdx++]=chestContents[i].copy();
|
||||
hasStuff=true;
|
||||
}
|
||||
}
|
||||
if (!hasStuff) {
|
||||
for (int i=0; i<topStacks.length; i++) {
|
||||
topStacks[i]=null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
Arrays.sort(tempCopy, new Comparator<ItemStack>() {
|
||||
@Override
|
||||
public int compare(ItemStack o1, ItemStack o2) {
|
||||
if (o1==null) {
|
||||
return 1;
|
||||
} else if (o2==null) {
|
||||
return -1;
|
||||
} else {
|
||||
return o2.stackSize-o1.stackSize;
|
||||
}
|
||||
}
|
||||
});
|
||||
int p=0;
|
||||
for (int i=0; i<tempCopy.length; i++) {
|
||||
if (tempCopy[i]!=null && tempCopy[i].stackSize>0) {
|
||||
topStacks[p++]=tempCopy[i];
|
||||
if (p==topStacks.length) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i=p; i<topStacks.length; i++) {
|
||||
topStacks[i]=null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
if (chestContents[i] != null)
|
||||
|
@ -103,6 +167,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
|
|||
}
|
||||
}
|
||||
facing=nbttagcompound.getByte("facing");
|
||||
sortTopStacks();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -225,4 +290,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
|
|||
return newEntity;
|
||||
}
|
||||
|
||||
public ItemStack[] getTopItemStacks() {
|
||||
return topStacks;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public class mod_IronChest extends BaseModMp {
|
|||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "2.3";
|
||||
return "2.4";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.8 KiB |
Binary file not shown.
Loading…
Reference in New Issue