Update to 1.2.4, no modloadermp anymore

This commit is contained in:
Christian Weeks 2012-03-29 00:31:46 -04:00
parent 785aef9551
commit e4d36feb31
17 changed files with 921 additions and 867 deletions

View File

@ -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>

View File

@ -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>

View File

@ -3,26 +3,24 @@ 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 {
public class ClientProxy implements IProxy {
@Override
public void registerRenderInformation() {
ChestItemRenderHelper.instance=new IronChestRenderHelper();
ChestItemRenderHelper.instance = new IronChestRenderHelper();
MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/block_textures.png");
MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/item_textures.png");
}
@ -40,16 +38,10 @@ public class ClientProxy extends BaseModMp implements IProxy {
ModLoader.addLocalization(typ.name() + ".name", typ.friendlyName);
}
for (ChestChangerType typ : ChestChangerType.values()) {
ModLoader.addLocalization("item."+typ.itemName+".name", typ.descriptiveName);
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();
@ -61,54 +53,23 @@ public class ClientProxy extends BaseModMp implements IProxy {
}
@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 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 World getCurrentWorld() {
return ModLoader.getMinecraftInstance().theWorld;
}
}

View File

@ -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);
}
}

View File

@ -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.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]);

View File

@ -20,15 +20,16 @@ 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) {
if (id >= 256) {
disableStats();
}
random=new Random();
random = new Random();
}
@Override
@ -50,55 +51,58 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
public boolean renderAsNormalBlock() {
return false;
}
@Override
public int getRenderType() {
return 22;
}
@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];
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;
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;
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;
return type.getTextureRow() * 16;
}
}
@Override
public int getBlockTextureFromSideAndMetadata(int i, int j) {
IronChestType typ=IronChestType.values()[j];
IronChestType typ = IronChestType.values()[j];
switch (i) {
case 0:
case 1:
return typ.getTextureRow()*16+1;
return typ.getTextureRow() * 16 + 1;
case 3:
return typ.getTextureRow()*16+2;
return typ.getTextureRow() * 16 + 2;
default:
return typ.getTextureRow()*16;
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))
if (te == null || !(te instanceof TileEntityIronChest))
{
return true;
}
if(world.isBlockSolidOnSide(i, j + 1, k, 0))
if (world.isBlockSolidOnSide(i, j + 1, k, 0))
{
return true;
}
@ -107,7 +111,7 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
return true;
}
mod_IronChest.openGUI(player, (TileEntityIronChest)te);
player.openGui(mod_IronChest.instance, ((TileEntityIronChest) te).getType().ordinal(), world, i, j, k);
return true;
}
@ -139,6 +143,7 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
world.markBlockNeedsUpdate(i, j, k);
}
}
@Override
protected int damageDropped(int i) {
return i;
@ -146,7 +151,7 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
public void onBlockRemoval(World world, int i, int j, int k)
{
TileEntityIronChest tileentitychest = (TileEntityIronChest)world.getBlockTileEntity(i, j, k);
TileEntityIronChest tileentitychest = (TileEntityIronChest) world.getBlockTileEntity(i, j, k);
if (tileentitychest != null)
{
dropContent(0, tileentitychest, world);
@ -173,14 +178,15 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
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()));
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;
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());
mod_IronChest.proxy.applyExtraDataToDrops(entityitem, (NBTTagCompound) itemstack.getTagCompound().copy());
}
world.spawnEntityInWorld(entityitem);
}
@ -191,7 +197,7 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
@Override
public void addCreativeItems(ArrayList itemList) {
for (IronChestType type : IronChestType.values()) {
itemList.add(new ItemStack(this,1,type.ordinal()));
itemList.add(new ItemStack(this, 1, type.ordinal()));
}
}
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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();
}

View File

@ -7,43 +7,38 @@ 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");
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 String guiName;
private int textureRow;
public Class<? extends TileEntityIronChest> clazz;
Item mat;
private String[] recipes;
public int guiId;
private ArrayList<ItemStack> matList;
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String guiName, String modelTexture, int textureRow, Item 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.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) {
this.matList = new ArrayList<ItemStack>();
if (mat != null) {
matList.add(new ItemStack(mat));
}
}
@ -90,7 +85,7 @@ public enum IronChestType {
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));
1, 3)/* Copper */, '4', new ItemStack(blockResult, 1, 4));
}
}
@ -98,22 +93,6 @@ public enum IronChestType {
ModLoader.addRecipe(is, parts);
}
public int getGUI() {
return guiId;
}
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 getRowCount() {
return size / rowLength;
}
@ -131,7 +110,7 @@ public enum IronChestType {
}
public boolean isTransparent() {
return this==CRYSTAL;
return this == CRYSTAL;
}
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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) {
if (MinecraftForge.isClient()) {
return CLIENT.buildProxy();
} else {
return SERVER.buildProxy();
}
return CLIENT.buildProxy();
}
}

View File

@ -93,7 +93,9 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
for (int i = 0; i < topStacks.length; i++) {
topStacks[i] = null;
}
mod_IronChest.proxy.sendTileEntityUpdate(this);
if (worldObj!=null) {
worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
}
return;
}
hadStuff = true;
@ -121,7 +123,9 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
for (int i = p; i < topStacks.length; i++) {
topStacks[i] = null;
}
mod_IronChest.proxy.sendTileEntityUpdate(this);
if (worldObj!=null) {
worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
}
}
@Override
@ -320,10 +324,10 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
}
public Packet getDescriptionPacket() {
return mod_IronChest.proxy.getDescriptionPacket(this);
return PacketHandler.getPacket(this);
}
public void handlePacketData(int typeData, int[] intData, float[] floatData, String[] stringData) {
public void handlePacketData(int typeData, int[] intData) {
TileEntityIronChest chest = this;
if (this.type.ordinal() != typeData) {
chest = updateFromMetadata(typeData);

View File

@ -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;
}
}

View File

@ -6,41 +6,44 @@ 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 mod_IronChest instance;
@Override
public String getVersion() {
return "3.1";
return Version.version();
}
@Override
public void load() {
MinecraftForge.versionDetect("IronChest", 1, 4, 0);
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=Integer.parseInt(cfg.getOrCreateBlockIdProperty("ironChests", 181).value);
if (bId>=256) {
throw new RuntimeException(String.format("IronChest detected an invalid block id %s\n",bId));
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);
IronChestType.initGUIs(cfg);
} catch (Exception e) {
ModLoader.getLogger().severe("IronChest was unable to load it's configuration successfully");
e.printStackTrace(System.err);
@ -77,32 +80,36 @@ public class mod_IronChest extends BaseModMp {
ChestChangerType.generateRecipe(IronChestType.DIAMOND);
IronChestType.generateTieredRecipies(ironChestBlock);
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 };
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()]);
addEMC.invoke(null, ironChestBlock.blockID, icType.ordinal(), chestEMCValues[icType.ordinal()]);
}
addMeta.invoke(null,ironChestBlock.blockID,IronChestType.values().length-1);
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");
}
}
public static void openGUI(EntityPlayer player, TileEntityIronChest te) {
proxy.showGUI(te,player);
@Override
public boolean clientSideRequired() {
return true;
}
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;
}
}

View File

@ -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;
}
}