commit c640fd5e63188078a6d1deb5f11b3e1ba0838f21 Author: Christian Weeks Date: Thu Jan 26 17:37:39 2012 -0500 Initial checkin. Build script works nicely. Some basic code in place. diff --git a/IronChests2/.classpath b/IronChests2/.classpath new file mode 100644 index 0000000..893f780 --- /dev/null +++ b/IronChests2/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/IronChests2/.gitignore b/IronChests2/.gitignore new file mode 100644 index 0000000..81886e9 --- /dev/null +++ b/IronChests2/.gitignore @@ -0,0 +1,2 @@ +/mod_ironchests-client-2.0.zip +/mod_ironchests-server-2.0.zip diff --git a/IronChests2/.project b/IronChests2/.project new file mode 100644 index 0000000..39d9b6c --- /dev/null +++ b/IronChests2/.project @@ -0,0 +1,17 @@ + + + IronChests2 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/IronChests2/.settings/org.eclipse.jdt.core.prefs b/IronChests2/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0f258a1 --- /dev/null +++ b/IronChests2/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Wed Jan 25 17:13:27 EST 2012 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/IronChests2/build.xml b/IronChests2/build.xml new file mode 100644 index 0000000..91c84b4 --- /dev/null +++ b/IronChests2/build.xml @@ -0,0 +1,121 @@ + + + + + Iron Chests + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java b/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java new file mode 100644 index 0000000..1acba70 --- /dev/null +++ b/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java @@ -0,0 +1,62 @@ +package cpw.mods.ironchest.client; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.ironchest.TileEntityIronChest; + +import net.minecraft.src.ModelChest; +import net.minecraft.src.TileEntity; +import net.minecraft.src.TileEntitySpecialRenderer; + +public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer { + + public TileEntityIronChestRenderer() { + model = new ModelChest(); + } + + public void render(TileEntityIronChest tile, double d, double d1, double d2, float f) { + int facing = 3; + int metatype = 0; + if (tile != null && tile.worldObj != null) { + metatype = tile.getBlockMetadata(); + 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); + int k = 0; + if (facing == 2) { + k = 180; + } + if (facing == 3) { + k = 0; + } + if (facing == 4) { + k = 90; + } + 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); + model.func_35402_a(); + GL11.glDisable(32826 /* GL_RESCALE_NORMAL_EXT */); + GL11.glPopMatrix(); + GL11.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); + } + + private ModelChest model; +} diff --git a/IronChests2/client/net/minecraft/src/mod_IronChest.java b/IronChests2/client/net/minecraft/src/mod_IronChest.java new file mode 100644 index 0000000..5c9cf1b --- /dev/null +++ b/IronChests2/client/net/minecraft/src/mod_IronChest.java @@ -0,0 +1,34 @@ +package net.minecraft.src; + +import java.io.File; + +import cpw.mods.ironchest.BlockIronChest; + +import net.minecraft.client.Minecraft; +import net.minecraft.src.forge.Configuration; + +public class mod_IronChest extends BaseModMp { + + public static BlockIronChest ironChestBlock; + + @Override + public String getVersion() { + return "2.0"; + } + + @Override + public void load() { + Configuration cfg=new Configuration(new File(Minecraft.getMinecraftDir(),"config/IronChest.cfg")); + try { + cfg.load(); + ironChestBlock=new BlockIronChest(Integer.parseInt(cfg.getOrCreateBlockIdProperty("blockVeryLargeChest", 181).value)); + } catch (Exception e) { + ModLoader.getLogger().severe("IronChest was unable to load it's configuration successfully"); + e.printStackTrace(System.err); + throw new RuntimeException(e); + } finally { + cfg.save(); + } + } + +} diff --git a/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java b/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java new file mode 100644 index 0000000..f01390c --- /dev/null +++ b/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java @@ -0,0 +1,86 @@ +package cpw.mods.ironchest; + +import net.minecraft.src.BlockContainer; +import net.minecraft.src.EntityLiving; +import net.minecraft.src.IBlockAccess; +import net.minecraft.src.Material; +import net.minecraft.src.MathHelper; +import net.minecraft.src.TileEntity; +import net.minecraft.src.World; +import net.minecraft.src.forge.ITextureProvider; + +public class BlockIronChest extends BlockContainer implements ITextureProvider { + + public BlockIronChest(int id) { + super(id, Material.iron); + setHardness(3.0F); + } + + @Override + public TileEntity getBlockEntity() { + return null; + } + + @Override + public String getTextureFile() { + return "ic2/sprites/ironchest_block_tex.png"; + } + + @Override + public TileEntity getBlockEntity(int metadata) { + return TileEntityIronChest.makeEntity(metadata); + } + + public int getBlockTexture(IBlockAccess worldAccess, int i, int j, int k, int l) { + TileEntity te = worldAccess.getBlockTileEntity(i, j, k); + if (te != null && te instanceof TileEntityIronChest) { + TileEntityIronChest icte=(TileEntityIronChest) te; + if (l==0 || l==1) { // Top and Bottom + return icte.getType().getTextureRow()*16; + } else if (l==getTextureFace(icte.getFacing())) { // Front + return icte.getType().getTextureRow()*16+1; + } else { // Back and Sides + return icte.getType().getTextureRow()*16+2; + } + } + return 0; + } + + public byte getTextureFace(byte facing) { + switch (facing) { + case 0: + return 3; + case 1: + return 4; + case 2: + return 2; + case 3: + return 5; + default: + return 0; + } + } + + @Override + public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving) { + super.onBlockPlacedBy(world, i, j, k, entityliving); + byte chestFacing = 0; + int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3; + if (facing == 0) { + chestFacing = 2; + } + if (facing == 1) { + chestFacing = 5; + } + if (facing == 2) { + chestFacing = 3; + } + if (facing == 3) { + chestFacing = 4; + } + TileEntity te = world.getBlockTileEntity(i, j, k); + if (te != null && te instanceof TileEntityIronChest) { + ((TileEntityIronChest) te).setFacing(chestFacing); + } + } +} diff --git a/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java b/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java new file mode 100644 index 0000000..c860582 --- /dev/null +++ b/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java @@ -0,0 +1,203 @@ +package cpw.mods.ironchest; + +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.IInventory; +import net.minecraft.src.ItemStack; +import net.minecraft.src.NBTTagCompound; +import net.minecraft.src.NBTTagList; +import net.minecraft.src.TileEntity; + +public class TileEntityIronChest extends TileEntity implements IInventory { + public enum Type { + IRON(54,"IronChest","ironchest.png",0), + GOLD(81,"GoldChest","goldchest.png",1), + DIAMOND(108,"DiamondChest","diamondchest.png",2); + private int size; + private String friendlyName; + private String modelTexture; + private int textureRow; + + Type(int size, String friendlyName, String modelTexture, int textureRow) { + this.size=size; + this.friendlyName=friendlyName; + this.modelTexture=modelTexture; + this.textureRow=textureRow; + } + + public String getModelTexture() { + return modelTexture; + } + + public int getTextureRow() { + return textureRow; + } + } + private int ticksSinceSync; + public float prevLidAngle; + public float lidAngle; + private int numUsingPlayers; + private Type type; + public ItemStack[] chestContents; + private byte facing; + + public TileEntityIronChest(Type type, byte facing) { + this.type=type; + this.facing=facing; + this.chestContents=new ItemStack[getSizeInventory()]; + } + @Override + public int getSizeInventory() { + return type.size; + } + + public byte getFacing() { + return this.facing; + } + @Override + public String getInvName() { + return type.friendlyName; + } + + public Type getType() { + return type; + } + @Override + public ItemStack getStackInSlot(int i) { + // TODO Auto-generated method stub + return null; + } + + @Override + public ItemStack decrStackSize(int i, int j) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setInventorySlotContents(int i, ItemStack itemstack) { + // TODO Auto-generated method stub + + } + + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) + { + super.readFromNBT(nbttagcompound); + NBTTagList nbttaglist = nbttagcompound.getTagList("Items"); + chestContents = new ItemStack[getSizeInventory()]; + for (int i = 0; i < nbttaglist.tagCount(); i++) + { + NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i); + int j = nbttagcompound1.getByte("Slot") & 0xff; + if (j >= 0 && j < chestContents.length) + { + chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); + } + } + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) + { + super.writeToNBT(nbttagcompound); + NBTTagList nbttaglist = new NBTTagList(); + for (int i = 0; i < chestContents.length; i++) + { + if (chestContents[i] != null) + { + NBTTagCompound nbttagcompound1 = new NBTTagCompound(); + nbttagcompound1.setByte("Slot", (byte)i); + chestContents[i].writeToNBT(nbttagcompound1); + nbttaglist.setTag(nbttagcompound1); + } + } + + nbttagcompound.setTag("Items", nbttaglist); + } + + @Override + public int getInventoryStackLimit() { + return 64; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer entityplayer) { + if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this) { + return false; + } + return entityplayer.getDistanceSq((double) xCoord + 0.5D, (double) yCoord + 0.5D, (double) zCoord + 0.5D) <= 64D; + } + + @Override + public void updateEntity() { + super.updateEntity(); + // Resynchronize clients with the server state + if ((++ticksSinceSync % 20) * 4 == 0) { + worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers); + } + prevLidAngle = lidAngle; + float f = 0.1F; + if (numUsingPlayers > 0 && lidAngle == 0.0F) { + double d = (double) xCoord + 0.5D; + double d1 = (double) zCoord + 0.5D; + worldObj.playSoundEffect(d, (double) yCoord + 0.5D, d1, "random.chestopen", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F); + } + if (numUsingPlayers == 0 && lidAngle > 0.0F || numUsingPlayers > 0 && lidAngle < 1.0F) { + float f1 = lidAngle; + if (numUsingPlayers > 0) { + lidAngle += f; + } else { + lidAngle -= f; + } + if (lidAngle > 1.0F) { + lidAngle = 1.0F; + } + float f2 = 0.5F; + if (lidAngle < f2 && f1 >= f2) { + double d2 = (double) xCoord + 0.5D; + double d3 = (double) zCoord + 0.5D; + worldObj.playSoundEffect(d2, (double) yCoord + 0.5D, d3, "random.chestclosed", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F); + } + if (lidAngle < 0.0F) { + lidAngle = 0.0F; + } + } + } + + @Override + public void onTileEntityPowered(int i, int j) + { + if (i == 1) + { + numUsingPlayers = j; + } + } + + @Override + public void openChest() { + numUsingPlayers++; + worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers); + } + + @Override + public void closeChest() { + numUsingPlayers--; + worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers); + } + + protected static TileEntity makeEntity(int metadata) { + //Compatibility + int chesttype=metadata; + int facing=0; + + if (metadata>2) { + chesttype=metadata<<2; + facing=metadata&3; + } + return new TileEntityIronChest(Type.values()[chesttype],(byte)facing); + } + public void setFacing(byte chestFacing) { + this.facing=chestFacing; + } + +}