Update to 1.2.4, no modloadermp anymore
This commit is contained in:
parent
785aef9551
commit
e4d36feb31
|
@ -2,8 +2,7 @@
|
|||
<classpath>
|
||||
<classpathentry kind="src" path="client"/>
|
||||
<classpathentry kind="src" path="common"/>
|
||||
<classpathentry kind="src" path="server"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/forge-client"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -7,14 +7,20 @@
|
|||
|
||||
cpw
|
||||
====================================================================== -->
|
||||
<project name="mod_IronChests" default="build">
|
||||
<project name="mod_IronChests" default="buildandclean">
|
||||
<description>
|
||||
Iron Chests
|
||||
</description>
|
||||
|
||||
<property name="modname" value="mod_ironchests" />
|
||||
<property name="version" value="3.1" />
|
||||
<property name="mcp.home" location="/home/cpw/projects/mcworkspace/forge59" />
|
||||
<property name="version.file" value="cpw/mods/ironchest/Version.java"/>
|
||||
<property name="version.major" value="3"/>
|
||||
<property name="version.minor" value="2"/>
|
||||
<property name="version.rev" value="0"/>
|
||||
<property name="version.build" value="0"/>
|
||||
<property name="version" value="${version.major}.${version.minor}.${version.rev}.${version.build}" />
|
||||
<property name="mcdev.home" location="/home/cpw/projects/mcworkspace"/>
|
||||
<property name="mcp.home" location="${mcdev.home}/forge67" />
|
||||
<property name="mcp.obfoutput" location="${mcp.home}/reobf" />
|
||||
<property name="client.mcp.obfoutput" location="${mcp.obfoutput}/minecraft" />
|
||||
<property name="server.mcp.obfoutput" location="${mcp.obfoutput}/minecraft_server" />
|
||||
|
@ -74,7 +80,8 @@
|
|||
<target name="extract-built-jar">
|
||||
<side prop="output" src="mcp.obfoutput" side="${side}"/>
|
||||
<property name="jarname" value="${modname}-${side}-${version}" />
|
||||
<jar destfile="${basedir}/${jarname}.zip" >
|
||||
<mkdir dir="${basedir}/target"/>
|
||||
<jar destfile="${basedir}/target/${jarname}.zip" >
|
||||
<fileset dir="${output}" includes="**/*.class" />
|
||||
<fileset dir="${resource.dir}" erroronmissingdir="false">
|
||||
<selector if="is.client">
|
||||
|
@ -82,11 +89,13 @@
|
|||
</selector>
|
||||
</fileset>
|
||||
</jar>
|
||||
<jar destfile="${basedir}/${jarname}.zip" update="true">
|
||||
</jar>
|
||||
</target>
|
||||
<target name="build" depends="merge-client,merge-server,build-client,build-server" />
|
||||
|
||||
<target name="buildandclean" depends="build">
|
||||
<antcall target="clean"/>
|
||||
</target>
|
||||
|
||||
<!-- antcall target to merge source to a side -->
|
||||
<target name="clean-source">
|
||||
<side prop="delete-targ" src="mcp.srcdir" side="${side}"/>
|
||||
|
@ -108,6 +117,14 @@
|
|||
<copy todir="${merge-to}" overwrite="true" verbose="true">
|
||||
<fileset dir="${side-from}" includes="**/*.java" />
|
||||
<fileset dir="${common.src.dir}" includes="**/*.java" />
|
||||
<filterchain>
|
||||
<replacetokens>
|
||||
<token key="MAJOR" value="${version.major}" />
|
||||
<token key="MINOR" value="${version.minor}" />
|
||||
<token key="REV" value="${version.rev}" />
|
||||
<token key="BUILD" value="${version.build}" />
|
||||
</replacetokens>
|
||||
</filterchain>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
|
|
|
@ -3,112 +3,73 @@ package cpw.mods.ironchest.client;
|
|||
import java.io.File;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.src.BaseModMp;
|
||||
import net.minecraft.src.ChestItemRenderHelper;
|
||||
import net.minecraft.src.EntityItem;
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.EntityPlayerSP;
|
||||
import net.minecraft.src.GuiScreen;
|
||||
import net.minecraft.src.ModLoader;
|
||||
import net.minecraft.src.ModLoaderMp;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.Packet;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraft.src.forge.MinecraftForgeClient;
|
||||
import cpw.mods.ironchest.ChestChangerType;
|
||||
import cpw.mods.ironchest.IProxy;
|
||||
import cpw.mods.ironchest.IronChestType;
|
||||
import cpw.mods.ironchest.TileEntityIronChest;
|
||||
|
||||
public class ClientProxy extends BaseModMp implements IProxy {
|
||||
@Override
|
||||
public void registerRenderInformation() {
|
||||
ChestItemRenderHelper.instance=new IronChestRenderHelper();
|
||||
MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/block_textures.png");
|
||||
MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/item_textures.png");
|
||||
}
|
||||
public class ClientProxy implements IProxy {
|
||||
@Override
|
||||
public void registerRenderInformation() {
|
||||
ChestItemRenderHelper.instance = new IronChestRenderHelper();
|
||||
MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/block_textures.png");
|
||||
MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/item_textures.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerTileEntities() {
|
||||
for (IronChestType typ : IronChestType.values()) {
|
||||
ModLoader.registerTileEntity(typ.clazz, typ.name(), new TileEntityIronChestRenderer());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void registerTileEntities() {
|
||||
for (IronChestType typ : IronChestType.values()) {
|
||||
ModLoader.registerTileEntity(typ.clazz, typ.name(), new TileEntityIronChestRenderer());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerTranslations() {
|
||||
for (IronChestType typ : IronChestType.values()) {
|
||||
ModLoader.addLocalization(typ.name() + ".name", typ.friendlyName);
|
||||
}
|
||||
for (ChestChangerType typ : ChestChangerType.values()) {
|
||||
ModLoader.addLocalization("item."+typ.itemName+".name", typ.descriptiveName);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void registerTranslations() {
|
||||
for (IronChestType typ : IronChestType.values()) {
|
||||
ModLoader.addLocalization(typ.name() + ".name", typ.friendlyName);
|
||||
}
|
||||
for (ChestChangerType typ : ChestChangerType.values()) {
|
||||
ModLoader.addLocalization("item." + typ.itemName + ".name", typ.descriptiveName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showGUI(TileEntityIronChest te, EntityPlayer player) {
|
||||
GUIChest.GUI.showGUI(te, player);
|
||||
@Override
|
||||
public File getMinecraftDir() {
|
||||
return Minecraft.getMinecraftDir();
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void applyExtraDataToDrops(EntityItem entityitem, NBTTagCompound data) {
|
||||
entityitem.item.setTagCompound(data);
|
||||
|
||||
@Override
|
||||
public File getMinecraftDir() {
|
||||
return Minecraft.getMinecraftDir();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyExtraDataToDrops(EntityItem entityitem, NBTTagCompound data) {
|
||||
entityitem.item.setTagCompound(data);
|
||||
@Override
|
||||
public boolean isRemote() {
|
||||
return ModLoader.getMinecraftInstance().theWorld.isRemote;
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public GuiScreen getGuiScreen(int ID, EntityPlayerSP player, World world, int X, int Y, int Z) {
|
||||
TileEntity te = world.getBlockTileEntity(X, Y, Z);
|
||||
if (te != null && te instanceof TileEntityIronChest) {
|
||||
return GUIChest.GUI.buildGUI(IronChestType.values()[ID], player.inventory, (TileEntityIronChest) te);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerGUI(int guiId) {
|
||||
ModLoaderMp.registerGUI(this, guiId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
// Do nothing, we never get loaded like that
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
// Do Nothing, we never get loaded like that
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiScreen handleGUI(int i) {
|
||||
for (IronChestType type: IronChestType.values()) {
|
||||
if (type.guiId==i) {
|
||||
return GUIChest.GUI.buildGUI(type,ModLoader.getMinecraftInstance().thePlayer.inventory,IronChestType.makeEntity(type.ordinal()));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTileEntityPacket(int x, int y, int z, int type, int[] intData, float[] floatData, String[] stringData) {
|
||||
TileEntity te=ModLoader.getMinecraftInstance().theWorld.getBlockTileEntity(x, y, z);
|
||||
if (te!=null && te instanceof TileEntityIronChest) {
|
||||
TileEntityIronChest icte=(TileEntityIronChest)te;
|
||||
icte.handlePacketData(type,intData,floatData,stringData);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket(TileEntityIronChest tile) {
|
||||
// NOOP on client
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTileEntityUpdate(TileEntityIronChest tile) {
|
||||
// NOOP on client
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRemote() {
|
||||
return ModLoader.getMinecraftInstance().theWorld.isRemote;
|
||||
}
|
||||
@Override
|
||||
public World getCurrentWorld() {
|
||||
return ModLoader.getMinecraftInstance().theWorld;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,20 +38,7 @@ public class GUIChest extends GuiContainer {
|
|||
}
|
||||
|
||||
public static GUIChest buildGUI(IronChestType type, IInventory playerInventory, TileEntityIronChest chestInventory) {
|
||||
for (GUI gui : values()) {
|
||||
if (chestInventory.getType()==gui.mainType) {
|
||||
return new GUIChest(gui,playerInventory,chestInventory);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static void showGUI(TileEntityIronChest te, EntityPlayer player) {
|
||||
GUIChest gui=buildGUI(te.getType(),player.inventory,te);
|
||||
if (gui!=null) {
|
||||
ModLoader.openGUI(player, gui);
|
||||
} else {
|
||||
player.displayGUIChest(te);
|
||||
}
|
||||
return new GUIChest(values()[chestInventory.getType().ordinal()],playerInventory,chestInventory);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import static org.lwjgl.opengl.GL11.glTranslatef;
|
|||
import java.util.Random;
|
||||
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.EntityItem;
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.ModelChest;
|
||||
|
@ -20,7 +21,8 @@ import net.minecraft.src.Tessellator;
|
|||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.TileEntitySpecialRenderer;
|
||||
import net.minecraft.src.forge.ForgeHooksClient;
|
||||
import net.minecraft.src.forge.ICustomItemRenderer;
|
||||
import net.minecraft.src.forge.IItemRenderer;
|
||||
import net.minecraft.src.forge.ItemRenderType;
|
||||
import net.minecraft.src.forge.MinecraftForgeClient;
|
||||
import cpw.mods.ironchest.IronChestType;
|
||||
import cpw.mods.ironchest.TileEntityIronChest;
|
||||
|
@ -101,6 +103,7 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
|
|||
glDisable(2896 /* GL_LIGHTING */);
|
||||
glEnable(32826 /* GL_RESCALE_NORMAL_EXT */);
|
||||
glTranslatef((float) x, (float) y, (float) z);
|
||||
EntityItem customitem=new EntityItem(tileEntityRenderer.worldObj);
|
||||
for (ItemStack item : tile.getTopItemStacks()) {
|
||||
if (shift > shifts.length) {
|
||||
break;
|
||||
|
@ -113,7 +116,7 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
|
|||
shiftY = shifts[shift][1];
|
||||
shiftZ = shifts[shift][2];
|
||||
shift++;
|
||||
ICustomItemRenderer customRenderer = MinecraftForgeClient.getCustomItemRenderer(item.itemID);
|
||||
IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item,ItemRenderType.ENTITY);
|
||||
float localScale = blockScale;
|
||||
if (item.itemID < Block.blocksList.length && Block.blocksList[item.itemID]!=null) {
|
||||
int j = Block.blocksList[item.itemID].getRenderType();
|
||||
|
@ -135,9 +138,10 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
|
|||
}
|
||||
|
||||
if (customRenderer != null) {
|
||||
customitem.item=item;
|
||||
bindTextureByName("/terrain.png");
|
||||
ForgeHooksClient.overrideTexture(item.getItem());
|
||||
ForgeHooksClient.renderCustomItem(customRenderer, renderBlocks, item.itemID, item.getItemDamage(), 1.0F);
|
||||
ForgeHooksClient.overrideTexture(item.getItem());
|
||||
ForgeHooksClient.renderEntityItem(customRenderer, renderBlocks, customitem);
|
||||
} else if (item.itemID < Block.blocksList.length && Block.blocksList[item.itemID]!=null && RenderBlocks.renderItemIn3d(Block.blocksList[item.itemID].getRenderType())) {
|
||||
bindTextureByName("/terrain.png");
|
||||
ForgeHooksClient.overrideTexture(Block.blocksList[item.itemID]);
|
||||
|
|
|
@ -19,179 +19,185 @@ import net.minecraft.src.forge.ITextureProvider;
|
|||
|
||||
public class BlockIronChest extends BlockContainer implements ITextureProvider {
|
||||
|
||||
private Random random;
|
||||
public BlockIronChest(int id) {
|
||||
super(id, Material.iron);
|
||||
setBlockName("IronChest");
|
||||
setHardness(3.0F);
|
||||
setRequiresSelfNotify();
|
||||
if (id>=256) {
|
||||
disableStats();
|
||||
}
|
||||
random=new Random();
|
||||
}
|
||||
private Random random;
|
||||
|
||||
@Override
|
||||
public TileEntity getBlockEntity() {
|
||||
return null;
|
||||
}
|
||||
public BlockIronChest(int id) {
|
||||
super(id, Material.iron);
|
||||
setBlockName("IronChest");
|
||||
setHardness(3.0F);
|
||||
setRequiresSelfNotify();
|
||||
if (id >= 256) {
|
||||
disableStats();
|
||||
}
|
||||
random = new Random();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTextureFile() {
|
||||
return "/cpw/mods/ironchest/sprites/block_textures.png";
|
||||
}
|
||||
@Override
|
||||
public TileEntity getBlockEntity() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public String getTextureFile() {
|
||||
return "/cpw/mods/ironchest/sprites/block_textures.png";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderAsNormalBlock() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return 22;
|
||||
}
|
||||
@Override
|
||||
public TileEntity getBlockEntity(int metadata) {
|
||||
return IronChestType.makeEntity(metadata);
|
||||
}
|
||||
@Override
|
||||
public boolean isOpaqueCube() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getBlockTexture(IBlockAccess worldAccess, int i, int j, int k, int l) {
|
||||
int meta=worldAccess.getBlockMetadata(i, j, k);
|
||||
IronChestType type=IronChestType.values()[meta];
|
||||
TileEntity te = worldAccess.getBlockTileEntity(i, j, k);
|
||||
TileEntityIronChest icte=null;
|
||||
if (te!=null && te instanceof TileEntityIronChest) {
|
||||
icte=(TileEntityIronChest)te;
|
||||
}
|
||||
if (l==0 || l==1) { // Top and Bottom
|
||||
return type.getTextureRow()*16+1;
|
||||
} else if (icte!=null && l==icte.getFacing()) { // Front
|
||||
return type.getTextureRow()*16+2;
|
||||
} else { // Back and Sides
|
||||
return type.getTextureRow()*16;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean renderAsNormalBlock() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockTextureFromSideAndMetadata(int i, int j) {
|
||||
IronChestType typ=IronChestType.values()[j];
|
||||
switch (i) {
|
||||
case 0:
|
||||
case 1:
|
||||
return typ.getTextureRow()*16+1;
|
||||
case 3:
|
||||
return typ.getTextureRow()*16+2;
|
||||
default:
|
||||
return typ.getTextureRow()*16;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean blockActivated(World world, int i, int j, int k, EntityPlayer player) {
|
||||
TileEntity te = world.getBlockTileEntity(i, j, k);
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return 22;
|
||||
}
|
||||
|
||||
if(te == null || !(te instanceof TileEntityIronChest))
|
||||
@Override
|
||||
public TileEntity getBlockEntity(int metadata) {
|
||||
return IronChestType.makeEntity(metadata);
|
||||
}
|
||||
|
||||
public int getBlockTexture(IBlockAccess worldAccess, int i, int j, int k, int l) {
|
||||
int meta = worldAccess.getBlockMetadata(i, j, k);
|
||||
IronChestType type = IronChestType.values()[meta];
|
||||
TileEntity te = worldAccess.getBlockTileEntity(i, j, k);
|
||||
TileEntityIronChest icte = null;
|
||||
if (te != null && te instanceof TileEntityIronChest) {
|
||||
icte = (TileEntityIronChest) te;
|
||||
}
|
||||
if (l == 0 || l == 1) { // Top and Bottom
|
||||
return type.getTextureRow() * 16 + 1;
|
||||
} else if (icte != null && l == icte.getFacing()) { // Front
|
||||
return type.getTextureRow() * 16 + 2;
|
||||
} else { // Back and Sides
|
||||
return type.getTextureRow() * 16;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockTextureFromSideAndMetadata(int i, int j) {
|
||||
IronChestType typ = IronChestType.values()[j];
|
||||
switch (i) {
|
||||
case 0:
|
||||
case 1:
|
||||
return typ.getTextureRow() * 16 + 1;
|
||||
case 3:
|
||||
return typ.getTextureRow() * 16 + 2;
|
||||
default:
|
||||
return typ.getTextureRow() * 16;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blockActivated(World world, int i, int j, int k, EntityPlayer player) {
|
||||
TileEntity te = world.getBlockTileEntity(i, j, k);
|
||||
|
||||
if (te == null || !(te instanceof TileEntityIronChest))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (world.isBlockSolidOnSide(i, j + 1, k, 0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (world.isRemote) {
|
||||
return true;
|
||||
}
|
||||
|
||||
player.openGui(mod_IronChest.instance, ((TileEntityIronChest) te).getType().ordinal(), world, i, j, k);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(World world, int i, int j, int k) {
|
||||
super.onBlockAdded(world, i, j, k);
|
||||
world.markBlockNeedsUpdate(i, j, k);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving 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);
|
||||
world.markBlockNeedsUpdate(i, j, k);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int damageDropped(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
public void onBlockRemoval(World world, int i, int j, int k)
|
||||
{
|
||||
TileEntityIronChest tileentitychest = (TileEntityIronChest) world.getBlockTileEntity(i, j, k);
|
||||
if (tileentitychest != null)
|
||||
{
|
||||
dropContent(0, tileentitychest, world);
|
||||
}
|
||||
super.onBlockRemoval(world, i, j, k);
|
||||
}
|
||||
|
||||
public void dropContent(int newSize, TileEntityIronChest chest, World world) {
|
||||
for (int l = newSize; l < chest.getSizeInventory(); l++)
|
||||
{
|
||||
ItemStack itemstack = chest.getStackInSlot(l);
|
||||
if (itemstack == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
float f = random.nextFloat() * 0.8F + 0.1F;
|
||||
float f1 = random.nextFloat() * 0.8F + 0.1F;
|
||||
float f2 = random.nextFloat() * 0.8F + 0.1F;
|
||||
while (itemstack.stackSize > 0)
|
||||
{
|
||||
int i1 = random.nextInt(21) + 10;
|
||||
if (i1 > itemstack.stackSize)
|
||||
{
|
||||
return true;
|
||||
i1 = itemstack.stackSize;
|
||||
}
|
||||
|
||||
if(world.isBlockSolidOnSide(i, j + 1, k, 0))
|
||||
itemstack.stackSize -= i1;
|
||||
EntityItem entityitem = new EntityItem(world, (float) chest.xCoord + f, (float) chest.yCoord + (newSize > 0 ? 1 : 0) + f1, (float) chest.zCoord + f2,
|
||||
new ItemStack(itemstack.itemID, i1, itemstack.getItemDamage()));
|
||||
float f3 = 0.05F;
|
||||
entityitem.motionX = (float) random.nextGaussian() * f3;
|
||||
entityitem.motionY = (float) random.nextGaussian() * f3 + 0.2F;
|
||||
entityitem.motionZ = (float) random.nextGaussian() * f3;
|
||||
if (itemstack.hasTagCompound())
|
||||
{
|
||||
return true;
|
||||
mod_IronChest.proxy.applyExtraDataToDrops(entityitem, (NBTTagCompound) itemstack.getTagCompound().copy());
|
||||
}
|
||||
world.spawnEntityInWorld(entityitem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (world.isRemote) {
|
||||
return true;
|
||||
}
|
||||
|
||||
mod_IronChest.openGUI(player, (TileEntityIronChest)te);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(World world, int i, int j, int k) {
|
||||
super.onBlockAdded(world, i, j, k);
|
||||
world.markBlockNeedsUpdate(i, j, k);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving 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);
|
||||
world.markBlockNeedsUpdate(i, j, k);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected int damageDropped(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
public void onBlockRemoval(World world, int i, int j, int k)
|
||||
{
|
||||
TileEntityIronChest tileentitychest = (TileEntityIronChest)world.getBlockTileEntity(i, j, k);
|
||||
if (tileentitychest != null)
|
||||
{
|
||||
dropContent(0, tileentitychest, world);
|
||||
}
|
||||
super.onBlockRemoval(world, i, j, k);
|
||||
}
|
||||
|
||||
public void dropContent(int newSize, TileEntityIronChest chest, World world) {
|
||||
for (int l = newSize; l < chest.getSizeInventory(); l++)
|
||||
{
|
||||
ItemStack itemstack = chest.getStackInSlot(l);
|
||||
if (itemstack == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
float f = random.nextFloat() * 0.8F + 0.1F;
|
||||
float f1 = random.nextFloat() * 0.8F + 0.1F;
|
||||
float f2 = random.nextFloat() * 0.8F + 0.1F;
|
||||
while (itemstack.stackSize > 0)
|
||||
{
|
||||
int i1 = random.nextInt(21) + 10;
|
||||
if (i1 > itemstack.stackSize)
|
||||
{
|
||||
i1 = itemstack.stackSize;
|
||||
}
|
||||
itemstack.stackSize -= i1;
|
||||
EntityItem entityitem = new EntityItem(world, (float)chest.xCoord + f, (float)chest.yCoord + (newSize>0 ? 1 : 0) + f1, (float)chest.zCoord + f2, new ItemStack(itemstack.itemID, i1, itemstack.getItemDamage()));
|
||||
float f3 = 0.05F;
|
||||
entityitem.motionX = (float)random.nextGaussian() * f3;
|
||||
entityitem.motionY = (float)random.nextGaussian() * f3 + 0.2F;
|
||||
entityitem.motionZ = (float)random.nextGaussian() * f3;
|
||||
if (itemstack.hasTagCompound())
|
||||
{
|
||||
mod_IronChest.proxy.applyExtraDataToDrops(entityitem, (NBTTagCompound)itemstack.getTagCompound().copy());
|
||||
}
|
||||
world.spawnEntityInWorld(entityitem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public void addCreativeItems(ArrayList itemList) {
|
||||
for (IronChestType type : IronChestType.values()) {
|
||||
itemList.add(new ItemStack(this,1,type.ordinal()));
|
||||
}
|
||||
}
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public void addCreativeItems(ArrayList itemList) {
|
||||
for (IronChestType type : IronChestType.values()) {
|
||||
itemList.add(new ItemStack(this, 1, type.ordinal()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -43,7 +43,7 @@ public enum ChestChangerType {
|
|||
}
|
||||
|
||||
public ItemChestChanger buildItem(Configuration cfg, int id) {
|
||||
int itemId=Integer.parseInt(cfg.getOrCreateIntProperty(itemName, Configuration.ITEM_PROPERTY, id).value);
|
||||
int itemId=Integer.parseInt(cfg.getOrCreateIntProperty(itemName, Configuration.CATEGORY_ITEM, id).value);
|
||||
item=new ItemChestChanger(itemId,this);
|
||||
return item;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package cpw.mods.ironchest;
|
|||
import net.minecraft.src.Container;
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.IInventory;
|
||||
import net.minecraft.src.InventoryPlayer;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.Slot;
|
||||
|
||||
|
|
|
@ -3,11 +3,11 @@ package cpw.mods.ironchest;
|
|||
import java.io.File;
|
||||
|
||||
import net.minecraft.src.EntityItem;
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.Packet;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraft.src.forge.IGuiHandler;
|
||||
|
||||
public interface IProxy {
|
||||
public interface IProxy extends IGuiHandler {
|
||||
|
||||
public abstract void registerRenderInformation();
|
||||
|
||||
|
@ -15,19 +15,11 @@ public interface IProxy {
|
|||
|
||||
public abstract void registerTranslations();
|
||||
|
||||
public abstract void showGUI(TileEntityIronChest te, EntityPlayer player);
|
||||
|
||||
public abstract File getMinecraftDir();
|
||||
|
||||
public abstract void applyExtraDataToDrops(EntityItem item, NBTTagCompound data);
|
||||
|
||||
public abstract void registerGUI(int guiId);
|
||||
|
||||
public abstract void handleTileEntityPacket(int x, int y, int z, int type, int[] intData, float[] floatData, String[] stringData);
|
||||
|
||||
public abstract Packet getDescriptionPacket(TileEntityIronChest tile);
|
||||
|
||||
public abstract void sendTileEntityUpdate(TileEntityIronChest tile);
|
||||
|
||||
public abstract boolean isRemote();
|
||||
|
||||
public abstract World getCurrentWorld();
|
||||
}
|
||||
|
|
|
@ -7,131 +7,110 @@ import net.minecraft.src.Block;
|
|||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.ModLoader;
|
||||
import net.minecraft.src.mod_IronChest;
|
||||
import net.minecraft.src.forge.Configuration;
|
||||
|
||||
public enum IronChestType {
|
||||
IRON(54, 9, true, "Iron Chest", "guiIronChest", "ironchest.png", 0, Item.ingotIron, TileEntityIronChest.class, "mmmmPmmmm","mGmG3GmGm"),
|
||||
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", "mGmG3GmGm"),
|
||||
CRYSTAL(108, 12, true, "Crystal Chest", "guiDiamondChest", "crystalchest.png", 5, Item.itemsList[Block.glass.blockID], TileEntityCrystalChest.class, "GGGGPGGGG");
|
||||
int size;
|
||||
private int rowLength;
|
||||
public String friendlyName;
|
||||
private boolean tieredChest;
|
||||
private String modelTexture;
|
||||
private String guiName;
|
||||
private int textureRow;
|
||||
public Class<? extends TileEntityIronChest> clazz;
|
||||
Item mat;
|
||||
private String[] recipes;
|
||||
public int guiId;
|
||||
private ArrayList<ItemStack> matList;
|
||||
IRON(54, 9, true, "Iron Chest", "ironchest.png", 0, Item.ingotIron, TileEntityIronChest.class, "mmmmPmmmm", "mGmG3GmGm"),
|
||||
GOLD(81, 9, true, "Gold Chest", "goldchest.png", 1, Item.ingotGold, TileEntityGoldChest.class, "mmmmPmmmm", "mGmG4GmGm"),
|
||||
DIAMOND(108, 12, true, "Diamond Chest", "diamondchest.png", 2, Item.diamond, TileEntityDiamondChest.class, "GGGmPmGGG", "GGGG4Gmmm"),
|
||||
COPPER(45, 9, false, "Copper Chest", "copperchest.png", 3, null, TileEntityCopperChest.class, "mmmmCmmmm"),
|
||||
SILVER(72, 9, false, "Silver Chest", "silverchest.png", 4, null, TileEntitySilverChest.class, "mmmm0mmmm", "mGmG3GmGm"),
|
||||
CRYSTAL(108, 12, true, "Crystal Chest", "crystalchest.png", 5, Item.itemsList[Block.glass.blockID], TileEntityCrystalChest.class, "GGGGPGGGG");
|
||||
int size;
|
||||
private int rowLength;
|
||||
public String friendlyName;
|
||||
private boolean tieredChest;
|
||||
private String modelTexture;
|
||||
private int textureRow;
|
||||
public Class<? extends TileEntityIronChest> clazz;
|
||||
Item mat;
|
||||
private String[] recipes;
|
||||
private ArrayList<ItemStack> matList;
|
||||
|
||||
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String guiName, String modelTexture, int textureRow, Item mat,
|
||||
Class<? extends TileEntityIronChest> clazz, String... recipes) {
|
||||
this.size = size;
|
||||
this.rowLength = rowLength;
|
||||
this.tieredChest = tieredChest;
|
||||
this.friendlyName = friendlyName;
|
||||
this.guiName = guiName;
|
||||
this.modelTexture = "/cpw/mods/ironchest/sprites/" + modelTexture;
|
||||
this.textureRow = textureRow;
|
||||
this.clazz = clazz;
|
||||
this.mat = mat;
|
||||
this.recipes = recipes;
|
||||
this.matList=new ArrayList<ItemStack>();
|
||||
if (mat!=null) {
|
||||
matList.add(new ItemStack(mat));
|
||||
}
|
||||
}
|
||||
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, Item mat,
|
||||
Class<? extends TileEntityIronChest> clazz, String... recipes) {
|
||||
this.size = size;
|
||||
this.rowLength = rowLength;
|
||||
this.tieredChest = tieredChest;
|
||||
this.friendlyName = friendlyName;
|
||||
this.modelTexture = "/cpw/mods/ironchest/sprites/" + modelTexture;
|
||||
this.textureRow = textureRow;
|
||||
this.clazz = clazz;
|
||||
this.mat = mat;
|
||||
this.recipes = recipes;
|
||||
this.matList = new ArrayList<ItemStack>();
|
||||
if (mat != null) {
|
||||
matList.add(new ItemStack(mat));
|
||||
}
|
||||
}
|
||||
|
||||
public String getModelTexture() {
|
||||
return modelTexture;
|
||||
}
|
||||
public String getModelTexture() {
|
||||
return modelTexture;
|
||||
}
|
||||
|
||||
public int getTextureRow() {
|
||||
return textureRow;
|
||||
}
|
||||
public int getTextureRow() {
|
||||
return textureRow;
|
||||
}
|
||||
|
||||
public static TileEntityIronChest makeEntity(int metadata) {
|
||||
// Compatibility
|
||||
int chesttype = metadata;
|
||||
try {
|
||||
TileEntityIronChest te = values()[chesttype].clazz.newInstance();
|
||||
return te;
|
||||
} catch (InstantiationException e) {
|
||||
// unpossible
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// unpossible
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static TileEntityIronChest makeEntity(int metadata) {
|
||||
// Compatibility
|
||||
int chesttype = metadata;
|
||||
try {
|
||||
TileEntityIronChest te = values()[chesttype].clazz.newInstance();
|
||||
return te;
|
||||
} catch (InstantiationException e) {
|
||||
// unpossible
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// unpossible
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void registerTranslations() {
|
||||
}
|
||||
public static void registerTranslations() {
|
||||
}
|
||||
|
||||
public static void generateTieredRecipies(BlockIronChest blockResult) {
|
||||
ItemStack previous = new ItemStack(Block.chest);
|
||||
for (IronChestType typ : values()) {
|
||||
if (!typ.tieredChest)
|
||||
continue;
|
||||
generateRecipesForType(blockResult, previous, typ, typ.mat);
|
||||
previous = new ItemStack(blockResult, 1, typ.ordinal());
|
||||
}
|
||||
}
|
||||
public static void generateTieredRecipies(BlockIronChest blockResult) {
|
||||
ItemStack previous = new ItemStack(Block.chest);
|
||||
for (IronChestType typ : values()) {
|
||||
if (!typ.tieredChest)
|
||||
continue;
|
||||
generateRecipesForType(blockResult, previous, typ, typ.mat);
|
||||
previous = new ItemStack(blockResult, 1, typ.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateRecipesForType(BlockIronChest blockResult, Object previousTier, IronChestType type, Object mat) {
|
||||
for (String recipe : type.recipes) {
|
||||
String[] recipeSplit = new String[] { recipe.substring(0, 3), recipe.substring(3, 6), recipe.substring(6, 9) };
|
||||
addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit, 'm', mat, 'P', previousTier, 'G', Block.glass, 'C', Block.chest,
|
||||
'0', new ItemStack(blockResult, 1, 0)/* Iron */, '1', new ItemStack(blockResult, 1, 1)/* GOLD */, '3', new ItemStack(blockResult,
|
||||
1, 3)/* Copper */, '4', new ItemStack(blockResult,1,4));
|
||||
}
|
||||
}
|
||||
public static void generateRecipesForType(BlockIronChest blockResult, Object previousTier, IronChestType type, Object mat) {
|
||||
for (String recipe : type.recipes) {
|
||||
String[] recipeSplit = new String[] { recipe.substring(0, 3), recipe.substring(3, 6), recipe.substring(6, 9) };
|
||||
addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit, 'm', mat, 'P', previousTier, 'G', Block.glass, 'C', Block.chest,
|
||||
'0', new ItemStack(blockResult, 1, 0)/* Iron */, '1', new ItemStack(blockResult, 1, 1)/* GOLD */, '3', new ItemStack(blockResult,
|
||||
1, 3)/* Copper */, '4', new ItemStack(blockResult, 1, 4));
|
||||
}
|
||||
}
|
||||
|
||||
public static void addRecipe(ItemStack is, Object... parts) {
|
||||
ModLoader.addRecipe(is, parts);
|
||||
}
|
||||
public static void addRecipe(ItemStack is, Object... parts) {
|
||||
ModLoader.addRecipe(is, parts);
|
||||
}
|
||||
|
||||
public int getGUI() {
|
||||
return guiId;
|
||||
}
|
||||
public int getRowCount() {
|
||||
return size / rowLength;
|
||||
}
|
||||
|
||||
public static void initGUIs(Configuration cfg) {
|
||||
int defGUI = 51;
|
||||
for (IronChestType typ : values()) {
|
||||
if (typ.guiName != null) {
|
||||
typ.guiId = Integer.parseInt(cfg.getOrCreateIntProperty(typ.guiName, Configuration.GENERAL_PROPERTY, defGUI++).value);
|
||||
mod_IronChest.proxy.registerGUI(typ.guiId);
|
||||
} else {
|
||||
typ.guiId = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
public int getRowLength() {
|
||||
return rowLength;
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return size / rowLength;
|
||||
}
|
||||
public void addMat(ItemStack ore) {
|
||||
this.matList.add(ore);
|
||||
}
|
||||
|
||||
public int getRowLength() {
|
||||
return rowLength;
|
||||
}
|
||||
public List<ItemStack> getMatList() {
|
||||
return matList;
|
||||
}
|
||||
|
||||
public void addMat(ItemStack ore) {
|
||||
this.matList.add(ore);
|
||||
}
|
||||
|
||||
public List<ItemStack> getMatList() {
|
||||
return matList;
|
||||
}
|
||||
|
||||
public boolean isTransparent() {
|
||||
return this==CRYSTAL;
|
||||
}
|
||||
public boolean isTransparent() {
|
||||
return this == CRYSTAL;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,6 @@ import net.minecraft.src.Item;
|
|||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraft.src.mod_IronChest;
|
||||
import net.minecraft.src.forge.ITextureProvider;
|
||||
|
||||
public class ItemChestChanger extends Item implements ITextureProvider {
|
||||
|
@ -32,8 +31,8 @@ public class ItemChestChanger extends Item implements ITextureProvider {
|
|||
world.setBlockTileEntity(X, Y, Z, newchest);
|
||||
world.setBlockMetadataWithNotify(X, Y, Z, newchest.getType().ordinal());
|
||||
world.notifyBlocksOfNeighborChange(X, Y, Z, world.getBlockId(X, Y, Z));
|
||||
world.markBlockNeedsUpdate(X, Y, Z);
|
||||
stack.stackSize=0;
|
||||
mod_IronChest.proxy.sendTileEntityUpdate(newchest);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
package cpw.mods.ironchest;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.src.NetworkManager;
|
||||
import net.minecraft.src.Packet;
|
||||
import net.minecraft.src.Packet1Login;
|
||||
import net.minecraft.src.Packet250CustomPayload;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraft.src.mod_IronChest;
|
||||
import net.minecraft.src.forge.IConnectionHandler;
|
||||
import net.minecraft.src.forge.IPacketHandler;
|
||||
import net.minecraft.src.forge.MessageManager;
|
||||
|
||||
public class PacketHandler implements IPacketHandler, IConnectionHandler {
|
||||
@Override
|
||||
public void onConnect(NetworkManager network) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLogin(NetworkManager network, Packet1Login login) {
|
||||
MessageManager.getInstance().registerChannel(network, this, "IronChest");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnect(NetworkManager network, String message, Object[] args) {
|
||||
MessageManager.getInstance().removeConnection(network);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(NetworkManager network, String channel, byte[] data) {
|
||||
DataInputStream dis=new DataInputStream(new ByteArrayInputStream(data));
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
int typ;
|
||||
boolean hasStacks;
|
||||
int[] items=null;
|
||||
try {
|
||||
x = dis.readInt();
|
||||
y = dis.readInt();
|
||||
z = dis.readInt();
|
||||
typ=dis.readByte();
|
||||
hasStacks=dis.readByte()!=0;
|
||||
if (hasStacks) {
|
||||
items = new int[24];
|
||||
for (int i=0; i<items.length; i++) {
|
||||
items[i]=dis.readInt();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return;
|
||||
}
|
||||
World world=mod_IronChest.proxy.getCurrentWorld();
|
||||
TileEntity te=world.getBlockTileEntity(x, y, z);
|
||||
if (te instanceof TileEntityIronChest) {
|
||||
TileEntityIronChest icte = (TileEntityIronChest)te;
|
||||
icte.handlePacketData(typ, items);
|
||||
}
|
||||
}
|
||||
|
||||
public static Packet getPacket(TileEntityIronChest tileEntityIronChest) {
|
||||
ByteArrayOutputStream bos=new ByteArrayOutputStream(140);
|
||||
DataOutputStream dos=new DataOutputStream(bos);
|
||||
int x=tileEntityIronChest.xCoord;
|
||||
int y=tileEntityIronChest.yCoord;
|
||||
int z=tileEntityIronChest.zCoord;
|
||||
int typ=tileEntityIronChest.getType().ordinal();
|
||||
int[] items=tileEntityIronChest.buildIntDataList();
|
||||
boolean hasStacks=(items!=null);
|
||||
try {
|
||||
dos.writeInt(x);
|
||||
dos.writeInt(y);
|
||||
dos.writeInt(z);
|
||||
dos.writeByte(typ);
|
||||
dos.writeByte(hasStacks? 1 : 0);
|
||||
if (hasStacks) {
|
||||
for (int i=0; i<24; i++) {
|
||||
dos.writeInt(items[i]);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// UNPOSSIBLE?
|
||||
}
|
||||
Packet250CustomPayload pkt=new Packet250CustomPayload();
|
||||
pkt.channel="IronChest";
|
||||
pkt.data=bos.toByteArray();
|
||||
pkt.length=bos.size();
|
||||
return pkt;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package cpw.mods.ironchest;
|
||||
|
||||
import net.minecraft.src.ModLoader;
|
||||
import net.minecraft.src.forge.MinecraftForge;
|
||||
|
||||
public enum ServerClientProxy {
|
||||
CLIENT("cpw.mods.ironchest.client.ClientProxy"),
|
||||
|
@ -21,15 +22,10 @@ public enum ServerClientProxy {
|
|||
}
|
||||
}
|
||||
public static IProxy getProxy() {
|
||||
try {
|
||||
ModLoader.class.getMethod("getMinecraftInstance");
|
||||
} catch (SecurityException e) {
|
||||
// UNPOSSIBLE
|
||||
throw new RuntimeException(e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
return SERVER.buildProxy();
|
||||
if (MinecraftForge.isClient()) {
|
||||
return CLIENT.buildProxy();
|
||||
} else {
|
||||
return SERVER.buildProxy();
|
||||
}
|
||||
return CLIENT.buildProxy();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,369 +13,373 @@ import net.minecraft.src.TileEntity;
|
|||
import net.minecraft.src.mod_IronChest;
|
||||
|
||||
public class TileEntityIronChest extends TileEntity implements IInventory {
|
||||
private int ticksSinceSync;
|
||||
public float prevLidAngle;
|
||||
public float lidAngle;
|
||||
private int numUsingPlayers;
|
||||
private IronChestType type;
|
||||
public ItemStack[] chestContents;
|
||||
private ItemStack[] topStacks;
|
||||
private byte facing;
|
||||
private boolean inventoryTouched;
|
||||
private boolean hadStuff;
|
||||
private int ticksSinceSync;
|
||||
public float prevLidAngle;
|
||||
public float lidAngle;
|
||||
private int numUsingPlayers;
|
||||
private IronChestType type;
|
||||
public ItemStack[] chestContents;
|
||||
private ItemStack[] topStacks;
|
||||
private byte facing;
|
||||
private boolean inventoryTouched;
|
||||
private boolean hadStuff;
|
||||
|
||||
public TileEntityIronChest() {
|
||||
this(IronChestType.IRON);
|
||||
}
|
||||
public TileEntityIronChest() {
|
||||
this(IronChestType.IRON);
|
||||
}
|
||||
|
||||
protected TileEntityIronChest(IronChestType type) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.chestContents = new ItemStack[getSizeInventory()];
|
||||
this.topStacks = new ItemStack[8];
|
||||
}
|
||||
protected TileEntityIronChest(IronChestType type) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.chestContents = new ItemStack[getSizeInventory()];
|
||||
this.topStacks = new ItemStack[8];
|
||||
}
|
||||
|
||||
public ItemStack[] getContents() {
|
||||
return chestContents;
|
||||
}
|
||||
public ItemStack[] getContents() {
|
||||
return chestContents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return type.size;
|
||||
}
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return type.size;
|
||||
}
|
||||
|
||||
public byte getFacing() {
|
||||
return this.facing;
|
||||
}
|
||||
public byte getFacing() {
|
||||
return this.facing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInvName() {
|
||||
return type.name();
|
||||
}
|
||||
@Override
|
||||
public String getInvName() {
|
||||
return type.name();
|
||||
}
|
||||
|
||||
public IronChestType getType() {
|
||||
return type;
|
||||
}
|
||||
public IronChestType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
inventoryTouched = true;
|
||||
return chestContents[i];
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
inventoryTouched = true;
|
||||
return chestContents[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInventoryChanged() {
|
||||
super.onInventoryChanged();
|
||||
sortTopStacks();
|
||||
}
|
||||
@Override
|
||||
public void onInventoryChanged() {
|
||||
super.onInventoryChanged();
|
||||
sortTopStacks();
|
||||
}
|
||||
|
||||
protected void sortTopStacks() {
|
||||
if (!type.isTransparent() || mod_IronChest.proxy.isRemote()) {
|
||||
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 && hadStuff) {
|
||||
hadStuff = false;
|
||||
for (int i = 0; i < topStacks.length; i++) {
|
||||
topStacks[i] = null;
|
||||
}
|
||||
mod_IronChest.proxy.sendTileEntityUpdate(this);
|
||||
return;
|
||||
}
|
||||
hadStuff = true;
|
||||
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;
|
||||
}
|
||||
mod_IronChest.proxy.sendTileEntityUpdate(this);
|
||||
}
|
||||
protected void sortTopStacks() {
|
||||
if (!type.isTransparent() || mod_IronChest.proxy.isRemote()) {
|
||||
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 && hadStuff) {
|
||||
hadStuff = false;
|
||||
for (int i = 0; i < topStacks.length; i++) {
|
||||
topStacks[i] = null;
|
||||
}
|
||||
if (worldObj!=null) {
|
||||
worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
return;
|
||||
}
|
||||
hadStuff = true;
|
||||
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;
|
||||
}
|
||||
if (worldObj!=null) {
|
||||
worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
if (chestContents[i] != null)
|
||||
{
|
||||
if (chestContents[i].stackSize <= j)
|
||||
{
|
||||
ItemStack itemstack = chestContents[i];
|
||||
chestContents[i] = null;
|
||||
onInventoryChanged();
|
||||
return itemstack;
|
||||
}
|
||||
ItemStack itemstack1 = chestContents[i].splitStack(j);
|
||||
if (chestContents[i].stackSize == 0)
|
||||
{
|
||||
chestContents[i] = null;
|
||||
}
|
||||
onInventoryChanged();
|
||||
return itemstack1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
if (chestContents[i] != null)
|
||||
{
|
||||
if (chestContents[i].stackSize <= j)
|
||||
{
|
||||
ItemStack itemstack = chestContents[i];
|
||||
chestContents[i] = null;
|
||||
onInventoryChanged();
|
||||
return itemstack;
|
||||
}
|
||||
ItemStack itemstack1 = chestContents[i].splitStack(j);
|
||||
if (chestContents[i].stackSize == 0)
|
||||
{
|
||||
chestContents[i] = null;
|
||||
}
|
||||
onInventoryChanged();
|
||||
return itemstack1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
chestContents[i] = itemstack;
|
||||
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
|
||||
{
|
||||
itemstack.stackSize = getInventoryStackLimit();
|
||||
}
|
||||
onInventoryChanged();
|
||||
}
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
chestContents[i] = itemstack;
|
||||
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
|
||||
{
|
||||
itemstack.stackSize = getInventoryStackLimit();
|
||||
}
|
||||
onInventoryChanged();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
facing = nbttagcompound.getByte("facing");
|
||||
sortTopStacks();
|
||||
}
|
||||
@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);
|
||||
}
|
||||
}
|
||||
facing = nbttagcompound.getByte("facing");
|
||||
sortTopStacks();
|
||||
}
|
||||
|
||||
@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.appendTag(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.appendTag(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
|
||||
nbttagcompound.setTag("Items", nbttaglist);
|
||||
nbttagcompound.setByte("facing", facing);
|
||||
}
|
||||
nbttagcompound.setTag("Items", nbttaglist);
|
||||
nbttagcompound.setByte("facing", facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
if (worldObj == null) {
|
||||
return true;
|
||||
}
|
||||
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 boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
if (worldObj == null) {
|
||||
return true;
|
||||
}
|
||||
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, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7));
|
||||
if (inventoryTouched) {
|
||||
inventoryTouched = false;
|
||||
sortTopStacks();
|
||||
}
|
||||
}
|
||||
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 updateEntity() {
|
||||
super.updateEntity();
|
||||
// Resynchronize clients with the server state
|
||||
if ((++ticksSinceSync % 20) * 4 == 0) {
|
||||
worldObj.playNoteAt(xCoord, yCoord, zCoord, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7));
|
||||
if (inventoryTouched) {
|
||||
inventoryTouched = false;
|
||||
sortTopStacks();
|
||||
}
|
||||
}
|
||||
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;
|
||||
} else if (i == 2) {
|
||||
facing = (byte) j;
|
||||
} else if (i == 3) {
|
||||
facing = (byte) (j & 0x7);
|
||||
numUsingPlayers = (j & 0xF8) >> 3;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onTileEntityPowered(int i, int j)
|
||||
{
|
||||
if (i == 1)
|
||||
{
|
||||
numUsingPlayers = j;
|
||||
} else if (i == 2) {
|
||||
facing = (byte) j;
|
||||
} else if (i == 3) {
|
||||
facing = (byte) (j & 0x7);
|
||||
numUsingPlayers = (j & 0xF8) >> 3;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openChest() {
|
||||
if (worldObj == null)
|
||||
return;
|
||||
numUsingPlayers++;
|
||||
worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers);
|
||||
}
|
||||
@Override
|
||||
public void openChest() {
|
||||
if (worldObj == null)
|
||||
return;
|
||||
numUsingPlayers++;
|
||||
worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeChest() {
|
||||
if (worldObj == null)
|
||||
return;
|
||||
numUsingPlayers--;
|
||||
worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers);
|
||||
}
|
||||
@Override
|
||||
public void closeChest() {
|
||||
if (worldObj == null)
|
||||
return;
|
||||
numUsingPlayers--;
|
||||
worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers);
|
||||
}
|
||||
|
||||
public void setFacing(byte chestFacing) {
|
||||
this.facing = chestFacing;
|
||||
}
|
||||
public void setFacing(byte chestFacing) {
|
||||
this.facing = chestFacing;
|
||||
}
|
||||
|
||||
public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger) {
|
||||
if (numUsingPlayers > 0) {
|
||||
return null;
|
||||
}
|
||||
if (!itemChestChanger.getType().canUpgrade(this.getType())) {
|
||||
return null;
|
||||
}
|
||||
TileEntityIronChest newEntity = IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal()));
|
||||
int newSize = newEntity.chestContents.length;
|
||||
System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize, chestContents.length));
|
||||
BlockIronChest block = mod_IronChest.ironChestBlock;
|
||||
block.dropContent(newSize, this, this.worldObj);
|
||||
newEntity.setFacing(facing);
|
||||
newEntity.sortTopStacks();
|
||||
return newEntity;
|
||||
}
|
||||
public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger) {
|
||||
if (numUsingPlayers > 0) {
|
||||
return null;
|
||||
}
|
||||
if (!itemChestChanger.getType().canUpgrade(this.getType())) {
|
||||
return null;
|
||||
}
|
||||
TileEntityIronChest newEntity = IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal()));
|
||||
int newSize = newEntity.chestContents.length;
|
||||
System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize, chestContents.length));
|
||||
BlockIronChest block = mod_IronChest.ironChestBlock;
|
||||
block.dropContent(newSize, this, this.worldObj);
|
||||
newEntity.setFacing(facing);
|
||||
newEntity.sortTopStacks();
|
||||
return newEntity;
|
||||
}
|
||||
|
||||
public ItemStack[] getTopItemStacks() {
|
||||
return topStacks;
|
||||
}
|
||||
public ItemStack[] getTopItemStacks() {
|
||||
return topStacks;
|
||||
}
|
||||
|
||||
public TileEntityIronChest updateFromMetadata(int l) {
|
||||
if (worldObj != null && worldObj.isRemote) {
|
||||
if (l != type.ordinal()) {
|
||||
worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, IronChestType.makeEntity(l));
|
||||
return (TileEntityIronChest) worldObj.getBlockTileEntity(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public TileEntityIronChest updateFromMetadata(int l) {
|
||||
if (worldObj != null && worldObj.isRemote) {
|
||||
if (l != type.ordinal()) {
|
||||
worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, IronChestType.makeEntity(l));
|
||||
return (TileEntityIronChest) worldObj.getBlockTileEntity(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Packet getDescriptionPacket() {
|
||||
return mod_IronChest.proxy.getDescriptionPacket(this);
|
||||
}
|
||||
public Packet getDescriptionPacket() {
|
||||
return PacketHandler.getPacket(this);
|
||||
}
|
||||
|
||||
public void handlePacketData(int typeData, int[] intData, float[] floatData, String[] stringData) {
|
||||
TileEntityIronChest chest = this;
|
||||
if (this.type.ordinal() != typeData) {
|
||||
chest = updateFromMetadata(typeData);
|
||||
}
|
||||
if (IronChestType.values()[typeData].isTransparent() && intData != null) {
|
||||
int pos = 0;
|
||||
if (intData.length < chest.topStacks.length * 3) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < chest.topStacks.length; i++) {
|
||||
if (intData[pos + 2] != 0) {
|
||||
ItemStack is = new ItemStack(intData[pos], intData[pos + 2], intData[pos + 1]);
|
||||
chest.topStacks[i] = is;
|
||||
} else {
|
||||
chest.topStacks[i] = null;
|
||||
}
|
||||
pos += 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void handlePacketData(int typeData, int[] intData) {
|
||||
TileEntityIronChest chest = this;
|
||||
if (this.type.ordinal() != typeData) {
|
||||
chest = updateFromMetadata(typeData);
|
||||
}
|
||||
if (IronChestType.values()[typeData].isTransparent() && intData != null) {
|
||||
int pos = 0;
|
||||
if (intData.length < chest.topStacks.length * 3) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < chest.topStacks.length; i++) {
|
||||
if (intData[pos + 2] != 0) {
|
||||
ItemStack is = new ItemStack(intData[pos], intData[pos + 2], intData[pos + 1]);
|
||||
chest.topStacks[i] = is;
|
||||
} else {
|
||||
chest.topStacks[i] = null;
|
||||
}
|
||||
pos += 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int[] buildIntDataList() {
|
||||
if (type.isTransparent()) {
|
||||
int[] sortList = new int[topStacks.length * 3];
|
||||
int pos = 0;
|
||||
for (ItemStack is : topStacks) {
|
||||
if (is != null) {
|
||||
sortList[pos++] = is.itemID;
|
||||
sortList[pos++] = is.getItemDamage();
|
||||
sortList[pos++] = is.stackSize;
|
||||
} else {
|
||||
sortList[pos++] = 0;
|
||||
sortList[pos++] = 0;
|
||||
sortList[pos++] = 0;
|
||||
}
|
||||
}
|
||||
return sortList;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public int[] buildIntDataList() {
|
||||
if (type.isTransparent()) {
|
||||
int[] sortList = new int[topStacks.length * 3];
|
||||
int pos = 0;
|
||||
for (ItemStack is : topStacks) {
|
||||
if (is != null) {
|
||||
sortList[pos++] = is.itemID;
|
||||
sortList[pos++] = is.getItemDamage();
|
||||
sortList[pos++] = is.stackSize;
|
||||
} else {
|
||||
sortList[pos++] = 0;
|
||||
sortList[pos++] = 0;
|
||||
sortList[pos++] = 0;
|
||||
}
|
||||
}
|
||||
return sortList;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack getStackInSlotOnClosing(int par1)
|
||||
{
|
||||
if (this.chestContents[par1] != null)
|
||||
{
|
||||
ItemStack var2 = this.chestContents[par1];
|
||||
this.chestContents[par1] = null;
|
||||
return var2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public ItemStack getStackInSlotOnClosing(int par1)
|
||||
{
|
||||
if (this.chestContents[par1] != null)
|
||||
{
|
||||
ItemStack var2 = this.chestContents[par1];
|
||||
this.chestContents[par1] = null;
|
||||
return var2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package cpw.mods.ironchest;
|
||||
|
||||
|
||||
public class Version {
|
||||
public static final String MAJOR="@MAJOR@";
|
||||
public static final String MINOR="@MINOR@";
|
||||
public static final String REV="@REV@";
|
||||
public static final String BUILD="@BUILD@";
|
||||
|
||||
public static final String version() {
|
||||
return MAJOR+"."+MINOR;
|
||||
}
|
||||
|
||||
public static final String name() {
|
||||
return "Iron Chest ("+MAJOR+"."+MINOR+") rev "+REV+" build "+BUILD;
|
||||
}
|
||||
}
|
|
@ -6,103 +6,110 @@ import java.lang.reflect.Method;
|
|||
import net.minecraft.src.forge.Configuration;
|
||||
import net.minecraft.src.forge.IOreHandler;
|
||||
import net.minecraft.src.forge.MinecraftForge;
|
||||
import net.minecraft.src.forge.NetworkMod;
|
||||
import cpw.mods.ironchest.BlockIronChest;
|
||||
import cpw.mods.ironchest.ChestChangerType;
|
||||
import cpw.mods.ironchest.IProxy;
|
||||
import cpw.mods.ironchest.IronChestType;
|
||||
import cpw.mods.ironchest.ItemChestChanger;
|
||||
import cpw.mods.ironchest.ItemIronChest;
|
||||
import cpw.mods.ironchest.PacketHandler;
|
||||
import cpw.mods.ironchest.ServerClientProxy;
|
||||
import cpw.mods.ironchest.TileEntityIronChest;
|
||||
import cpw.mods.ironchest.Version;
|
||||
|
||||
public class mod_IronChest extends BaseModMp {
|
||||
public class mod_IronChest extends NetworkMod {
|
||||
|
||||
public static BlockIronChest ironChestBlock;
|
||||
public static ItemChestChanger itemChestChanger;
|
||||
public static IProxy proxy;
|
||||
public static BlockIronChest ironChestBlock;
|
||||
public static ItemChestChanger itemChestChanger;
|
||||
public static IProxy proxy;
|
||||
public static mod_IronChest instance;
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "3.1";
|
||||
}
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return Version.version();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
MinecraftForge.versionDetect("IronChest", 1, 4, 0);
|
||||
proxy = ServerClientProxy.getProxy();
|
||||
File cfgFile = new File(proxy.getMinecraftDir(), "config/IronChest.cfg");
|
||||
Configuration cfg = new Configuration(cfgFile);
|
||||
try {
|
||||
cfg.load();
|
||||
int bId=Integer.parseInt(cfg.getOrCreateBlockIdProperty("ironChests", 181).value);
|
||||
if (bId>=256) {
|
||||
throw new RuntimeException(String.format("IronChest detected an invalid block id %s\n",bId));
|
||||
}
|
||||
ironChestBlock = new BlockIronChest(bId);
|
||||
ChestChangerType.buildItems(cfg, 19501);
|
||||
IronChestType.initGUIs(cfg);
|
||||
} 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();
|
||||
}
|
||||
@Override
|
||||
public void load() {
|
||||
MinecraftForge.versionDetect("IronChest", 2, 0, 0);
|
||||
instance = this;
|
||||
proxy = ServerClientProxy.getProxy();
|
||||
File cfgFile = new File(proxy.getMinecraftDir(), "config/IronChest.cfg");
|
||||
Configuration cfg = new Configuration(cfgFile);
|
||||
try {
|
||||
cfg.load();
|
||||
int bId = cfg.getOrCreateBlockIdProperty("ironChests", 181).getInt(181);
|
||||
if (bId >= 256) {
|
||||
throw new RuntimeException(String.format("IronChest detected an invalid block id %s\n", bId));
|
||||
}
|
||||
ironChestBlock = new BlockIronChest(bId);
|
||||
ChestChangerType.buildItems(cfg, 19501);
|
||||
} 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();
|
||||
}
|
||||
|
||||
ModLoader.registerBlock(ironChestBlock, ItemIronChest.class);
|
||||
MinecraftForge.registerOreHandler(new IOreHandler() {
|
||||
@Override
|
||||
public void registerOre(String oreClass, ItemStack ore) {
|
||||
if ("ingotCopper".equals(oreClass)) {
|
||||
IronChestType.COPPER.addMat(ore);
|
||||
IronChestType.generateRecipesForType(ironChestBlock, Block.chest, IronChestType.COPPER, ore);
|
||||
ChestChangerType.generateRecipe(IronChestType.COPPER);
|
||||
}
|
||||
if ("ingotSilver".equals(oreClass)) {
|
||||
IronChestType.SILVER.addMat(ore);
|
||||
IronChestType.generateRecipesForType(ironChestBlock, ironChestBlock, IronChestType.SILVER, ore);
|
||||
ChestChangerType.generateRecipe(IronChestType.SILVER);
|
||||
}
|
||||
if ("ingotRefinedIron".equals(oreClass)) {
|
||||
IronChestType.IRON.addMat(ore);
|
||||
IronChestType.generateRecipesForType(ironChestBlock, Block.chest, IronChestType.IRON, ore);
|
||||
ChestChangerType.generateRecipe(IronChestType.IRON);
|
||||
}
|
||||
}
|
||||
});
|
||||
proxy.registerTranslations();
|
||||
proxy.registerTileEntities();
|
||||
ChestChangerType.generateRecipe(IronChestType.IRON);
|
||||
ChestChangerType.generateRecipe(IronChestType.GOLD);
|
||||
ChestChangerType.generateRecipe(IronChestType.DIAMOND);
|
||||
IronChestType.generateTieredRecipies(ironChestBlock);
|
||||
ModLoader.registerBlock(ironChestBlock, ItemIronChest.class);
|
||||
MinecraftForge.registerOreHandler(new IOreHandler() {
|
||||
@Override
|
||||
public void registerOre(String oreClass, ItemStack ore) {
|
||||
if ("ingotCopper".equals(oreClass)) {
|
||||
IronChestType.COPPER.addMat(ore);
|
||||
IronChestType.generateRecipesForType(ironChestBlock, Block.chest, IronChestType.COPPER, ore);
|
||||
ChestChangerType.generateRecipe(IronChestType.COPPER);
|
||||
}
|
||||
if ("ingotSilver".equals(oreClass)) {
|
||||
IronChestType.SILVER.addMat(ore);
|
||||
IronChestType.generateRecipesForType(ironChestBlock, ironChestBlock, IronChestType.SILVER, ore);
|
||||
ChestChangerType.generateRecipe(IronChestType.SILVER);
|
||||
}
|
||||
if ("ingotRefinedIron".equals(oreClass)) {
|
||||
IronChestType.IRON.addMat(ore);
|
||||
IronChestType.generateRecipesForType(ironChestBlock, Block.chest, IronChestType.IRON, ore);
|
||||
ChestChangerType.generateRecipe(IronChestType.IRON);
|
||||
}
|
||||
}
|
||||
});
|
||||
proxy.registerTranslations();
|
||||
proxy.registerTileEntities();
|
||||
ChestChangerType.generateRecipe(IronChestType.IRON);
|
||||
ChestChangerType.generateRecipe(IronChestType.GOLD);
|
||||
ChestChangerType.generateRecipe(IronChestType.DIAMOND);
|
||||
IronChestType.generateTieredRecipies(ironChestBlock);
|
||||
|
||||
proxy.registerRenderInformation();
|
||||
}
|
||||
MinecraftForge.setGuiHandler(this, proxy);
|
||||
MinecraftForge.registerConnectionHandler(new PacketHandler());
|
||||
proxy.registerRenderInformation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modsLoaded() {
|
||||
try {
|
||||
Class<?> equivexmaps = Class.forName("ee.EEMaps");
|
||||
Method addEMC = equivexmaps.getMethod("addEMC", int.class, int.class, int.class);
|
||||
Method addMeta = equivexmaps.getMethod("addMeta", int.class, int.class);
|
||||
int[] chestEMCValues = new int[] { 8 * 8 + 256 * 8, 8 * 8 + 256 * 8 + 2048 * 8, 2 * 8192 + 8 * 8 + 256 * 8 + 2048 * 8 + 6, 85 * 8 + 8 * 8,
|
||||
85 * 8 + 8 * 8 + 512 * 8, 2 * 8192 + 8 * 8 + 256 * 8 + 2048 * 8 + 6 + 8 };
|
||||
for (IronChestType icType : IronChestType.values()) {
|
||||
addEMC.invoke(null, ironChestBlock.blockID, icType.ordinal(), chestEMCValues[icType.ordinal()]);
|
||||
}
|
||||
addMeta.invoke(null, ironChestBlock.blockID, IronChestType.values().length - 1);
|
||||
ModLoader.getLogger().fine("mod_IronChest registered chests with Equivalent Exchange");
|
||||
} catch (Exception ex) {
|
||||
ModLoader.getLogger().fine("mod_IronChest unable to load Equivalent Exchange integration");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modsLoaded() {
|
||||
try {
|
||||
Class<?> equivexmaps=Class.forName("ee.EEMaps");
|
||||
Method addEMC=equivexmaps.getMethod("addEMC",int.class,int.class,int.class);
|
||||
Method addMeta=equivexmaps.getMethod("addMeta",int.class,int.class);
|
||||
int[] chestEMCValues=new int[] { 8*8+256*8, 8*8+256*8+2048*8, 2*8192+8*8+256*8+2048*8+6, 85*8+8*8, 85*8+8*8+512*8, 2*8192+8*8+256*8+2048*8+6+8 };
|
||||
for (IronChestType icType : IronChestType.values()) {
|
||||
addEMC.invoke(null,ironChestBlock.blockID,icType.ordinal(),chestEMCValues[icType.ordinal()]);
|
||||
}
|
||||
addMeta.invoke(null,ironChestBlock.blockID,IronChestType.values().length-1);
|
||||
ModLoader.getLogger().fine("mod_IronChest registered chests with Equivalent Exchange");
|
||||
} catch (Exception ex) {
|
||||
ModLoader.getLogger().fine("mod_IronChest unable to load Equivalent Exchange integration");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean clientSideRequired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void openGUI(EntityPlayer player, TileEntityIronChest te) {
|
||||
proxy.showGUI(te,player);
|
||||
}
|
||||
|
||||
public void handleTileEntityPacket(int x, int y, int z, int type, int[] intData, float[] floatData, String[] stringData) {
|
||||
proxy.handleTileEntityPacket(x,y,z,type,intData,floatData,stringData);
|
||||
}
|
||||
@Override
|
||||
public boolean serverSideRequired() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,14 +2,13 @@ package cpw.mods.ironchest.server;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import net.minecraft.src.BaseModMp;
|
||||
import net.minecraft.src.Container;
|
||||
import net.minecraft.src.EntityItem;
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.EntityPlayerMP;
|
||||
import net.minecraft.src.ModLoader;
|
||||
import net.minecraft.src.ModLoaderMp;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.Packet;
|
||||
import net.minecraft.src.mod_IronChest;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.World;
|
||||
import cpw.mods.ironchest.ContainerIronChestBase;
|
||||
import cpw.mods.ironchest.IProxy;
|
||||
import cpw.mods.ironchest.IronChestType;
|
||||
|
@ -34,11 +33,6 @@ public class ServerProxy implements IProxy {
|
|||
// NOOP on server
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showGUI(TileEntityIronChest te, EntityPlayer player) {
|
||||
ModLoader.openGUI(player, te.getType().guiId, te, new ContainerIronChestBase(player.inventory,te, te.getType(), 1, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getMinecraftDir() {
|
||||
return new File(".");
|
||||
|
@ -49,29 +43,26 @@ public class ServerProxy implements IProxy {
|
|||
entityitem.item.setTagCompound(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerGUI(int guiId) {
|
||||
// NOOP on server
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTileEntityPacket(int x, int y, int z, int type, int[] intData, float[] floatData, String[] stringData) {
|
||||
// NOOP on server
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket(TileEntityIronChest tile) {
|
||||
return ModLoaderMp.getTileEntityPacket(ModLoaderMp.getModInstance(mod_IronChest.class), tile.xCoord, tile.yCoord, tile.zCoord, tile.getType().ordinal(), tile.buildIntDataList(),null,null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTileEntityUpdate(TileEntityIronChest tile) {
|
||||
ModLoaderMp.sendTileEntityPacket(tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRemote() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getGuiContainer(int ID, EntityPlayerMP player, World world, int X, int Y, int Z) {
|
||||
TileEntity te=world.getBlockTileEntity(X, Y, Z);
|
||||
if (te!=null && te instanceof TileEntityIronChest) {
|
||||
TileEntityIronChest icte=(TileEntityIronChest) te;
|
||||
return new ContainerIronChestBase(player.inventory, icte, icte.getType(), 0, 0);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getCurrentWorld() {
|
||||
// NOOP on server: there's lots
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue