From c44aac2b395f059fbe469775a01c099033731f1a Mon Sep 17 00:00:00 2001 From: LexManos Date: Fri, 24 Feb 2012 22:07:58 -0800 Subject: [PATCH] Ran AStyle over forge code for uniform code formatting, and refactored old code a bit to have cleaner names. --- .../src/forge/BlockTextureParticles.java | 8 +- .../minecraft/src/forge/EnumHelperClient.java | 205 +++-- .../minecraft/src/forge/ForgeHooksClient.java | 440 ++++----- .../src/forge/GuiControlsScrollPanel.java | 247 ++--- .../minecraft/src/forge/GuiMissingMods.java | 78 +- .../src/forge/IArmorTextureProvider.java | 5 +- .../src/forge/ICustomItemRenderer.java | 5 +- .../net/minecraft/src/forge/IGuiHandler.java | 42 +- .../src/forge/IHighlightHandler.java | 11 +- .../src/forge/IRenderContextHandler.java | 17 +- .../src/forge/IRenderWorldLastHandler.java | 17 +- .../src/forge/MinecraftForgeClient.java | 182 ++-- .../src/forge/PacketHandlerClient.java | 486 +++++----- .../net/minecraft/src/mod_MinecraftForge.java | 10 +- .../minecraft/src/forge/ArmorProperties.java | 100 +- .../minecraft/src/forge/Configuration.java | 297 +++--- .../minecraft/src/forge/DimensionManager.java | 140 +-- .../net/minecraft/src/forge/DungeonLoot.java | 102 +-- .../src/forge/EntityTrackerInfo.java | 42 +- .../net/minecraft/src/forge/EnumHelper.java | 706 ++++++++------- .../net/minecraft/src/forge/ForgeHooks.java | 715 ++++++++------- .../src/forge/IArrowLooseHandler.java | 48 +- .../src/forge/IArrowNockHandler.java | 50 +- .../minecraft/src/forge/IBonemealHandler.java | 17 +- .../minecraft/src/forge/IBucketHandler.java | 9 +- .../minecraft/src/forge/IConnectRedstone.java | 11 +- .../src/forge/IConnectionHandler.java | 20 +- .../minecraft/src/forge/ICraftingHandler.java | 10 +- .../src/forge/IDestroyToolHandler.java | 11 +- .../net/minecraft/src/forge/IHoeHandler.java | 17 +- .../src/forge/IMinecartCollisionHandler.java | 100 +- .../minecraft/src/forge/IMinecartHandler.java | 77 +- .../minecraft/src/forge/IMultipassRender.java | 13 +- .../net/minecraft/src/forge/IOreHandler.java | 15 +- .../minecraft/src/forge/IOverrideReplace.java | 19 +- .../minecraft/src/forge/IPacketHandler.java | 8 +- .../minecraft/src/forge/IPickupHandler.java | 50 +- .../net/minecraft/src/forge/IShearable.java | 106 +-- .../minecraft/src/forge/ISidedInventory.java | 37 +- .../minecraft/src/forge/ISleepHandler.java | 7 +- .../minecraft/src/forge/ISpawnHandler.java | 54 +- .../minecraft/src/forge/ISpecialArmor.java | 62 +- .../src/forge/ISpecialResistance.java | 14 +- .../minecraft/src/forge/ITextureProvider.java | 5 +- .../minecraft/src/forge/IThrowableEntity.java | 44 +- .../minecraft/src/forge/MessageManager.java | 108 +-- .../net/minecraft/src/forge/MinecartKey.java | 99 +- .../minecraft/src/forge/MinecraftForge.java | 857 +++++++++--------- .../net/minecraft/src/forge/NetworkMod.java | 50 +- .../net/minecraft/src/forge/ObjectPair.java | 80 +- .../net/minecraft/src/forge/Property.java | 5 +- .../src/forge/packets/ForgePacket.java | 120 +-- .../src/forge/packets/PacketEntitySpawn.java | 212 ++--- .../src/forge/packets/PacketMissingMods.java | 42 +- .../src/forge/packets/PacketModIDs.java | 120 +-- .../src/forge/packets/PacketModList.java | 160 ++-- .../src/forge/packets/PacketOpenGUI.java | 152 ++-- .../minecraft/src/forge/ForgeHooksServer.java | 110 +-- .../net/minecraft/src/forge/IGuiHandler.java | 42 +- .../src/forge/PacketHandlerServer.java | 312 +++---- .../net/minecraft/src/mod_MinecraftForge.java | 10 +- 61 files changed, 3675 insertions(+), 3463 deletions(-) diff --git a/forge/forge_client/src/net/minecraft/src/forge/BlockTextureParticles.java b/forge/forge_client/src/net/minecraft/src/forge/BlockTextureParticles.java index f101913588..1bee16d347 100755 --- a/forge/forge_client/src/net/minecraft/src/forge/BlockTextureParticles.java +++ b/forge/forge_client/src/net/minecraft/src/forge/BlockTextureParticles.java @@ -3,11 +3,13 @@ package net.minecraft.src.forge; import java.util.ArrayList; import java.util.List; -public class BlockTextureParticles { +public class BlockTextureParticles +{ public String texture; public List effects; - - public BlockTextureParticles(){ + + public BlockTextureParticles() + { effects = new ArrayList(); } } diff --git a/forge/forge_client/src/net/minecraft/src/forge/EnumHelperClient.java b/forge/forge_client/src/net/minecraft/src/forge/EnumHelperClient.java index 9f9d41947c..06df7bbdcc 100644 --- a/forge/forge_client/src/net/minecraft/src/forge/EnumHelperClient.java +++ b/forge/forge_client/src/net/minecraft/src/forge/EnumHelperClient.java @@ -1,99 +1,106 @@ -package net.minecraft.src.forge; - -import net.minecraft.src.EnumJsonNodeType; -import net.minecraft.src.EnumOS2; -import net.minecraft.src.EnumOptions; -import net.minecraft.src.EnumRarity; - -public class EnumHelperClient extends EnumHelper { - - private static Class[][] ctrs = { - {EnumJsonNodeType.class}, - {EnumOptions.class, String.class, boolean.class, boolean.class}, - {EnumOS2.class}, - {EnumRarity.class, int.class, String.class} - }; - - private static boolean[] decompiled = new boolean[ctrs.length]; - private static boolean isSetup = false; - - public static EnumJsonNodeType addJsonNodeType(String name) - { - if (!isSetup) - { - setup(); - } - - return addEnum(decompiled[0], EnumJsonNodeType.class, name, - new Class[] {}, - new Object[]{}); - } - public static EnumOptions addOptions(String name, String langName, boolean isSlider, boolean isToggle) - { - if (!isSetup) - { - setup(); - } - - return addEnum(decompiled[1], EnumOptions.class, name, - new Class[] {String.class, boolean.class, boolean.class}, - new Object[]{langName, isSlider, isToggle }); - } - public static EnumOS2 addOS2(String name) - { - if (!isSetup) - { - setup(); - } - - return addEnum(decompiled[2], EnumOS2.class, name, - new Class[] {}, - new Object[]{}); - } - public static EnumRarity addRarity(String name, int color, String displayName) - { - if (!isSetup) - { - setup(); - } - - return addEnum(decompiled[3], EnumRarity.class, name, - new Class[] {int.class, String.class}, - new Object[]{color, displayName }); - } - - private static void setup() - { - //System.out.println("Enum Helper Initalizing: "); - for(int x = 0; x < ctrs.length; x++) - { - try { - Class[] enumHeaders = new Class[ctrs[x].length + 3]; - enumHeaders[0] = String.class; - enumHeaders[1] = int.class; - enumHeaders[2] = String.class; - enumHeaders[3] = int.class; - - for (int y = 1; y < ctrs[x].length; y++) - enumHeaders[3 + y] = ctrs[x][y]; - - ctrs[x][0].getDeclaredConstructor(enumHeaders); - decompiled[x] = true; - - } catch(Exception e) { - //Nom Nom Nom - } - //System.out.format("\t%-25s %s\r\n", ctrs[x][0].getName().replace("net.minecraft.src.", ""), decompiled[x]); - } - isSetup = true; - } - - static - { - if (!isSetup) - { - setup(); - } - } - -} +package net.minecraft.src.forge; + +import net.minecraft.src.EnumJsonNodeType; +import net.minecraft.src.EnumOS2; +import net.minecraft.src.EnumOptions; +import net.minecraft.src.EnumRarity; + +public class EnumHelperClient extends EnumHelper +{ + + private static Class[][] ctrs = + { + {EnumJsonNodeType.class}, + {EnumOptions.class, String.class, boolean.class, boolean.class}, + {EnumOS2.class}, + {EnumRarity.class, int.class, String.class} + }; + + private static boolean[] decompiled = new boolean[ctrs.length]; + private static boolean isSetup = false; + + public static EnumJsonNodeType addJsonNodeType(String name) + { + if (!isSetup) + { + setup(); + } + + return addEnum(decompiled[0], EnumJsonNodeType.class, name, + new Class[] {}, + new Object[] {}); + } + public static EnumOptions addOptions(String name, String langName, boolean isSlider, boolean isToggle) + { + if (!isSetup) + { + setup(); + } + + return addEnum(decompiled[1], EnumOptions.class, name, + new Class[] {String.class, boolean.class, boolean.class}, + new Object[]{langName, isSlider, isToggle }); + } + public static EnumOS2 addOS2(String name) + { + if (!isSetup) + { + setup(); + } + + return addEnum(decompiled[2], EnumOS2.class, name, + new Class[] {}, + new Object[]{}); + } + public static EnumRarity addRarity(String name, int color, String displayName) + { + if (!isSetup) + { + setup(); + } + + return addEnum(decompiled[3], EnumRarity.class, name, + new Class[] {int.class, String.class}, + new Object[]{color, displayName }); + } + + private static void setup() + { + //System.out.println("Enum Helper Initalizing: "); + for (int x = 0; x < ctrs.length; x++) + { + try + { + Class[] enumHeaders = new Class[ctrs[x].length + 3]; + enumHeaders[0] = String.class; + enumHeaders[1] = int.class; + enumHeaders[2] = String.class; + enumHeaders[3] = int.class; + + for (int y = 1; y < ctrs[x].length; y++) + { + enumHeaders[3 + y] = ctrs[x][y]; + } + + ctrs[x][0].getDeclaredConstructor(enumHeaders); + decompiled[x] = true; + + } + catch (Exception e) + { + //Nom Nom Nom + } + //System.out.format("\t%-25s %s\r\n", ctrs[x][0].getName().replace("net.minecraft.src.", ""), decompiled[x]); + } + isSetup = true; + } + + static + { + if (!isSetup) + { + setup(); + } + } + +} diff --git a/forge/forge_client/src/net/minecraft/src/forge/ForgeHooksClient.java b/forge/forge_client/src/net/minecraft/src/forge/ForgeHooksClient.java index d2ce4dd102..d14e578f02 100644 --- a/forge/forge_client/src/net/minecraft/src/forge/ForgeHooksClient.java +++ b/forge/forge_client/src/net/minecraft/src/forge/ForgeHooksClient.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -17,229 +17,253 @@ import org.lwjgl.opengl.GL11; import java.util.*; -public class ForgeHooksClient { +public class ForgeHooksClient +{ - public static boolean onBlockHighlight(RenderGlobal renderglobal, - EntityPlayer player, MovingObjectPosition mop, int i, - ItemStack itemstack, float f) { - for (IHighlightHandler handler : highlightHandlers) { - if(handler.onBlockHighlight(renderglobal,player,mop, - i,itemstack,f)) - return true; - } - return false; - } + public static boolean onBlockHighlight(RenderGlobal render, EntityPlayer player, MovingObjectPosition target, int i, ItemStack itemstack, float partialTicks) + { + for (IHighlightHandler handler : highlightHandlers) + { + if (handler.onBlockHighlight(render, player, target, i, itemstack, partialTicks)) + { + return true; + } + } + return false; + } - public static void onRenderWorldLast(RenderGlobal rg, float f) { - for (IRenderWorldLastHandler handler : renderWorldLastHandlers) { - handler.onRenderWorldLast(rg,f); - } - } + public static void onRenderWorldLast(RenderGlobal render, float partialTicks) + { + for (IRenderWorldLastHandler handler : renderWorldLastHandlers) + { + handler.onRenderWorldLast(render, partialTicks); + } + } - static LinkedList highlightHandlers = - new LinkedList(); - static LinkedList renderWorldLastHandlers = - new LinkedList(); + public static LinkedList highlightHandlers = new LinkedList(); + public static LinkedList renderWorldLastHandlers = new LinkedList(); - public static boolean canRenderInPass(Block block, int pass) { - if(block instanceof IMultipassRender) { - IMultipassRender impr = (IMultipassRender) block; - return impr.canRenderInPass(pass); - } - if(pass==block.getRenderBlockPass()) return true; - return false; - } + public static boolean canRenderInPass(Block block, int pass) + { + if (block instanceof IMultipassRender) + { + return ((IMultipassRender)block).canRenderInPass(pass); + } + if (pass == block.getRenderBlockPass()) + { + return true; + } + return false; + } - private static class TesKey implements Comparable { - public TesKey(int t, int s) { tex=t; sub=s; } - public int compareTo(TesKey key) { - if(sub==key.sub) return tex-key.tex; - return sub-key.sub; - } - public boolean equals(Object obj) { - return compareTo((TesKey)obj)==0; - } - public int hashCode() { - int c1=Integer.valueOf(tex).hashCode(); - int c2=Integer.valueOf(sub).hashCode(); - return c1+31*c2; - } - public int tex, sub; - } + private static class TesKey implements Comparable + { + public TesKey(int textureID, int subID) + { + tex = textureID; + sub = subID; + } + public int compareTo(TesKey key) + { + if (sub == key.sub) + { + return tex - key.tex; + } + return sub - key.sub; + } + public boolean equals(Object obj) + { + return compareTo((TesKey)obj) == 0; + } + public int hashCode() + { + int c1 = Integer.valueOf(tex).hashCode(); + int c2 = Integer.valueOf(sub).hashCode(); + return c1 + 31 * c2; + } + public int tex, sub; + } - static HashMap tessellators= - new HashMap(); - static HashMap textures=new HashMap(); - static boolean inWorld=false; - static TreeSet renderTextures=new TreeSet(); - static Tessellator defaultTessellator=null; - static HashMap renderHandlers=new - HashMap(); + public static HashMap tessellators = new HashMap(); + public static HashMap textures = new HashMap(); + public static boolean inWorld = false; + public static TreeSet renderTextures = new TreeSet(); + public static Tessellator defaultTessellator = null; + public static HashMap renderHandlers = new HashMap(); - protected static void registerRenderContextHandler(String tex, int sub, - IRenderContextHandler handler) { - Integer n; - n=textures.get(tex); - if(n==null) { - n=ModLoader.getMinecraftInstance().renderEngine - .getTexture(tex); - textures.put(tex,n); - } - renderHandlers.put(new TesKey(n,sub),handler); - } + protected static void registerRenderContextHandler(String texture, int subID, IRenderContextHandler handler) + { + Integer texID = textures.get(texture); + if (texID == null) + { + texID = ModLoader.getMinecraftInstance().renderEngine.getTexture(texture); + textures.put(texture, texID); + } + renderHandlers.put(new TesKey(texID, subID), handler); + } - protected static void bindTessellator(int tex, int sub) { - TesKey key=new TesKey(tex,sub); - Tessellator t; - t=tessellators.get(key); - if(t==null) { - t=new Tessellator(); - tessellators.put(key,t); - } - if(inWorld && !renderTextures.contains(key)) { - renderTextures.add(key); - t.startDrawingQuads(); - t.setTranslationD(defaultTessellator.xOffset, - defaultTessellator.yOffset, - defaultTessellator.zOffset); - } - Tessellator.instance=t; - } + protected static void bindTessellator(int texture, int subID) + { + TesKey key = new TesKey(texture, subID); + Tessellator tess = tessellators.get(key); + if (tess == null) + { + tess = new Tessellator(); + tessellators.put(key, tess); + } + if (inWorld && !renderTextures.contains(key)) + { + renderTextures.add(key); + tess.startDrawingQuads(); + tess.setTranslationD(defaultTessellator.xOffset, defaultTessellator.yOffset, defaultTessellator.zOffset); + } + Tessellator.instance = tess; + } - static IRenderContextHandler unbindContext=null; - protected static void bindTexture(String name, int sub) { - Integer n; - n=textures.get(name); - if(n==null) { - n=ModLoader.getMinecraftInstance().renderEngine - .getTexture(name); - textures.put(name,n); - } - if(!inWorld) { - if(unbindContext!=null) { - unbindContext.afterRenderContext(); - unbindContext=null; - } - if(Tessellator.instance.isDrawing) { - int mode=Tessellator.instance.drawMode; - Tessellator.instance.draw(); - Tessellator.instance.startDrawing(mode); - } - GL11.glBindTexture(3553 /* GL_TEXTURE_2D */,n); - unbindContext=renderHandlers.get(new TesKey(n,sub)); - if(unbindContext!=null) { - unbindContext.beforeRenderContext(); - } - return; - } - bindTessellator(n,sub); - } + public static IRenderContextHandler unbindContext = null; + protected static void bindTexture(String texture, int subID) + { + Integer texID = textures.get(texture); + if (texID == null) + { + texID = ModLoader.getMinecraftInstance().renderEngine.getTexture(texture); + textures.put(texture, texID); + } + if (!inWorld) + { + if (unbindContext != null) + { + unbindContext.afterRenderContext(); + unbindContext = null; + } + if (Tessellator.instance.isDrawing) + { + int mode = Tessellator.instance.drawMode; + Tessellator.instance.draw(); + Tessellator.instance.startDrawing(mode); + } + GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID); + unbindContext = renderHandlers.get(new TesKey(texID, subID)); + if (unbindContext != null) + { + unbindContext.beforeRenderContext(); + } + return; + } + bindTessellator(texID, subID); + } - protected static void unbindTexture() { - if(inWorld) { - Tessellator.instance=defaultTessellator; - } else { - if(Tessellator.instance.isDrawing) { - int mode=Tessellator.instance.drawMode; - Tessellator.instance.draw(); - if(unbindContext!=null) { - unbindContext.afterRenderContext(); - unbindContext=null; - } - Tessellator.instance.startDrawing(mode); - } - GL11.glBindTexture(3553 /* GL_TEXTURE_2D */, ModLoader - .getMinecraftInstance().renderEngine - .getTexture("/terrain.png")); - return; - } - } + protected static void unbindTexture() + { + if (inWorld) + { + Tessellator.instance = defaultTessellator; + } + else + { + if (Tessellator.instance.isDrawing) + { + int mode = Tessellator.instance.drawMode; + Tessellator.instance.draw(); + if (unbindContext != null) + { + unbindContext.afterRenderContext(); + unbindContext = null; + } + Tessellator.instance.startDrawing(mode); + } + GL11.glBindTexture(GL11.GL_TEXTURE_2D, ModLoader.getMinecraftInstance().renderEngine.getTexture("/terrain.png")); + return; + } + } - static int renderPass=-1; - public static void beforeRenderPass(int pass) { - renderPass=pass; - defaultTessellator=Tessellator.instance; - Tessellator.renderingWorldRenderer=true; - GL11.glBindTexture(3553 /* GL_TEXTURE_2D */, ModLoader - .getMinecraftInstance().renderEngine - .getTexture("/terrain.png")); - renderTextures.clear(); - inWorld=true; - } + static int renderPass = -1; + public static void beforeRenderPass(int pass) + { + renderPass = pass; + defaultTessellator = Tessellator.instance; + Tessellator.renderingWorldRenderer = true; + GL11.glBindTexture(GL11.GL_TEXTURE_2D, ModLoader.getMinecraftInstance().renderEngine.getTexture("/terrain.png")); + renderTextures.clear(); + inWorld = true; + } - public static void afterRenderPass(int pass) { - renderPass=-1; - inWorld=false; - for(TesKey tk : renderTextures) { - IRenderContextHandler irch=renderHandlers.get(tk); - GL11.glBindTexture(GL11.GL_TEXTURE_2D,tk.tex); - Tessellator t=tessellators.get(tk); - if(irch==null) { - t.draw(); - } else { - Tessellator.instance=t; - irch.beforeRenderContext(); - t.draw(); - irch.afterRenderContext(); - } - } - GL11.glBindTexture(3553 /* GL_TEXTURE_2D */, ModLoader - .getMinecraftInstance().renderEngine - .getTexture("/terrain.png")); - Tessellator.renderingWorldRenderer=false; - Tessellator.instance=defaultTessellator; - } + public static void afterRenderPass(int pass) + { + renderPass = -1; + inWorld = false; + for (TesKey info : renderTextures) + { + IRenderContextHandler handler = renderHandlers.get(info); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, info.tex); + Tessellator tess = tessellators.get(info); + if (handler == null) + { + tess.draw(); + } + else + { + Tessellator.instance = tess; + handler.beforeRenderContext(); + tess.draw(); + handler.afterRenderContext(); + } + } + GL11.glBindTexture(GL11.GL_TEXTURE_2D, ModLoader.getMinecraftInstance().renderEngine.getTexture("/terrain.png")); + Tessellator.renderingWorldRenderer = false; + Tessellator.instance = defaultTessellator; + } - public static void beforeBlockRender(Block block, - RenderBlocks renderblocks) { - if (block instanceof ITextureProvider - && renderblocks.overrideBlockTexture == -1) { - ITextureProvider itp=(ITextureProvider)block; - bindTexture(itp.getTextureFile(),0); - } - } + public static void beforeBlockRender(Block block, RenderBlocks render) + { + if (block instanceof ITextureProvider && render.overrideBlockTexture == -1) + { + bindTexture(((ITextureProvider)block).getTextureFile(), 0); + } + } - public static void afterBlockRender(Block block, - RenderBlocks renderblocks) { - if (block instanceof ITextureProvider - && renderblocks.overrideBlockTexture == -1) { - unbindTexture(); - } - } + public static void afterBlockRender(Block block, RenderBlocks render) + { + if (block instanceof ITextureProvider && render.overrideBlockTexture == -1) + { + unbindTexture(); + } + } - public static void overrideTexture (Object o) { - if (o instanceof ITextureProvider) { - GL11.glBindTexture(3553 /* GL_TEXTURE_2D */, ModLoader - .getMinecraftInstance().renderEngine - .getTexture(((ITextureProvider) (o)) - .getTextureFile())); - } - } - - public static String getTexture(String def, Object item) - { - if (item instanceof ITextureProvider) - { - return ((ITextureProvider)item).getTextureFile(); - } - else - { - return def; - } - } + public static void overrideTexture (Object obj) + { + if (obj instanceof ITextureProvider) + { + GL11.glBindTexture(GL11.GL_TEXTURE_2D, ModLoader.getMinecraftInstance().renderEngine.getTexture(((ITextureProvider)obj).getTextureFile())); + } + } - public static void renderCustomItem(ICustomItemRenderer customRenderer, RenderBlocks renderBlocks,int itemID, int meta, float f) { - Tessellator tessellator = Tessellator.instance; - if (renderBlocks.useInventoryTint) { - int j = 0xffffff;//block.getRenderColor(i); - float f1 = (float) (j >> 16 & 0xff) / 255F; - float f3 = (float) (j >> 8 & 0xff) / 255F; - float f5 = (float) (j & 0xff) / 255F; - GL11.glColor4f(f1 * f, f3 * f, f5 * f, 1.0F); - } + public static String getTexture(String def, Object obj) + { + if (obj instanceof ITextureProvider) + { + return ((ITextureProvider)obj).getTextureFile(); + } + else + { + return def; + } + } -// ModLoader.RenderInvBlock(this, block, i, k); - customRenderer.renderInventory(renderBlocks, itemID, meta); - } + public static void renderCustomItem(ICustomItemRenderer customRenderer, RenderBlocks renderBlocks, int itemID, int metadata, float brightness) + { + Tessellator tessellator = Tessellator.instance; + if (renderBlocks.useInventoryTint) + { + int j = 0xffffff;//block.getRenderColor(i); + float f1 = (float) (j >> 16 & 0xff) / 255F; + float f3 = (float) (j >> 8 & 0xff) / 255F; + float f5 = (float) (j & 0xff) / 255F; + GL11.glColor4f(f1 * brightness, f3 * brightness, f5 * brightness, 1.0F); + } + + //ModLoader.RenderInvBlock(this, block, i, k); + customRenderer.renderInventory(renderBlocks, itemID, metadata); + } } diff --git a/forge/forge_client/src/net/minecraft/src/forge/GuiControlsScrollPanel.java b/forge/forge_client/src/net/minecraft/src/forge/GuiControlsScrollPanel.java index 63deb0ed60..f8fc092739 100644 --- a/forge/forge_client/src/net/minecraft/src/forge/GuiControlsScrollPanel.java +++ b/forge/forge_client/src/net/minecraft/src/forge/GuiControlsScrollPanel.java @@ -1,123 +1,124 @@ -package net.minecraft.src.forge; - -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; - -import net.minecraft.client.Minecraft; -import net.minecraft.src.GameSettings; -import net.minecraft.src.GuiControls; -import net.minecraft.src.GuiSlot; -import net.minecraft.src.KeyBinding; -import net.minecraft.src.Tessellator; - -public class GuiControlsScrollPanel extends GuiSlot -{ - private GuiControls controls; - private GameSettings options; - private Minecraft mc; - private String[] message; - private int mouseX; - private int mouseY; - private int selected = -1; - - public GuiControlsScrollPanel(GuiControls controls, GameSettings options, Minecraft mc) - { - super(mc, controls.width, controls.height, 16, (controls.height - 32) + 4, 25); - this.controls = controls; - this.options = options; - this.mc = mc; - } - - @Override - protected int getSize() { - return options.keyBindings.length; - } - - @Override - protected void elementClicked(int i, boolean flag) - { - if (!flag) - { - if (selected == -1) - { - selected = i; - } - else - { - options.setKeyBinding(selected, -100); - selected = -1; - KeyBinding.resetKeyBindingArrayAndHash(); - } - } - } - - @Override - protected boolean isSelected(int i) - { - return false; - } - - @Override - protected void drawBackground() {} - - @Override - public void drawScreen(int mX, int mY, float f) - { - mouseX = mX; - mouseY = mY; - - if (selected != -1 && !Mouse.isButtonDown(0) && Mouse.getDWheel() == 0) - { - if (Mouse.next() && Mouse.getEventButtonState()) - { - System.out.println(Mouse.getEventButton()); - options.setKeyBinding(selected, -100 + Mouse.getEventButton()); - selected = -1; - KeyBinding.resetKeyBindingArrayAndHash(); - } - } - - super.drawScreen(mX, mY, f); - } - - @Override - protected void drawSlot(int index, int xPosition, int yPosition, int l, Tessellator tessellator) - { - int width = 70; - int height = 20; - xPosition -= 20; - boolean flag = mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + height; - int k = (flag ? 2 : 1); - - GL11.glBindTexture(3553 /*GL_TEXTURE_2D*/, mc.renderEngine.getTexture("/gui/gui.png")); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - controls.drawTexturedModalRect(xPosition, yPosition, 0, 46 + k * 20, width / 2, height); - controls.drawTexturedModalRect(xPosition + width / 2, yPosition, 200 - width / 2, 46 + k * 20, width / 2, height); - controls.drawString(mc.fontRenderer, options.getKeyBindingDescription(index), xPosition + width + 4, yPosition + 6, 0xFFFFFFFF); - - boolean conflict = false; - for (int x = 0; x < options.keyBindings.length; x++) - { - if (x != index && options.keyBindings[x].keyCode == options.keyBindings[index].keyCode) - { - conflict = true; - break; - } - } - String str = (conflict ? "\247c" : "") + options.getOptionDisplayString(index); - str = (index == selected ? "\247f> \247e??? \247f<" : str); - controls.drawCenteredString(mc.fontRenderer, str, xPosition + (width / 2), yPosition + (height - 8) / 2, 0xFFFFFFFF); - } - - public boolean keyTyped(char c, int i) - { - if (selected != -1) - { - options.setKeyBinding(selected, i); - selected = -1; - KeyBinding.resetKeyBindingArrayAndHash(); - return false; - } - return true; - } -} +package net.minecraft.src.forge; + +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +import net.minecraft.client.Minecraft; +import net.minecraft.src.GameSettings; +import net.minecraft.src.GuiControls; +import net.minecraft.src.GuiSlot; +import net.minecraft.src.KeyBinding; +import net.minecraft.src.Tessellator; + +public class GuiControlsScrollPanel extends GuiSlot +{ + private GuiControls controls; + private GameSettings options; + private Minecraft mc; + private String[] message; + private int mouseX; + private int mouseY; + private int selected = -1; + + public GuiControlsScrollPanel(GuiControls controls, GameSettings options, Minecraft mc) + { + super(mc, controls.width, controls.height, 16, (controls.height - 32) + 4, 25); + this.controls = controls; + this.options = options; + this.mc = mc; + } + + @Override + protected int getSize() + { + return options.keyBindings.length; + } + + @Override + protected void elementClicked(int i, boolean flag) + { + if (!flag) + { + if (selected == -1) + { + selected = i; + } + else + { + options.setKeyBinding(selected, -100); + selected = -1; + KeyBinding.resetKeyBindingArrayAndHash(); + } + } + } + + @Override + protected boolean isSelected(int i) + { + return false; + } + + @Override + protected void drawBackground() {} + + @Override + public void drawScreen(int mX, int mY, float f) + { + mouseX = mX; + mouseY = mY; + + if (selected != -1 && !Mouse.isButtonDown(0) && Mouse.getDWheel() == 0) + { + if (Mouse.next() && Mouse.getEventButtonState()) + { + System.out.println(Mouse.getEventButton()); + options.setKeyBinding(selected, -100 + Mouse.getEventButton()); + selected = -1; + KeyBinding.resetKeyBindingArrayAndHash(); + } + } + + super.drawScreen(mX, mY, f); + } + + @Override + protected void drawSlot(int index, int xPosition, int yPosition, int l, Tessellator tessellator) + { + int width = 70; + int height = 20; + xPosition -= 20; + boolean flag = mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + height; + int k = (flag ? 2 : 1); + + GL11.glBindTexture(3553 /*GL_TEXTURE_2D*/, mc.renderEngine.getTexture("/gui/gui.png")); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + controls.drawTexturedModalRect(xPosition, yPosition, 0, 46 + k * 20, width / 2, height); + controls.drawTexturedModalRect(xPosition + width / 2, yPosition, 200 - width / 2, 46 + k * 20, width / 2, height); + controls.drawString(mc.fontRenderer, options.getKeyBindingDescription(index), xPosition + width + 4, yPosition + 6, 0xFFFFFFFF); + + boolean conflict = false; + for (int x = 0; x < options.keyBindings.length; x++) + { + if (x != index && options.keyBindings[x].keyCode == options.keyBindings[index].keyCode) + { + conflict = true; + break; + } + } + String str = (conflict ? "\247c" : "") + options.getOptionDisplayString(index); + str = (index == selected ? "\247f> \247e??? \247f<" : str); + controls.drawCenteredString(mc.fontRenderer, str, xPosition + (width / 2), yPosition + (height - 8) / 2, 0xFFFFFFFF); + } + + public boolean keyTyped(char c, int i) + { + if (selected != -1) + { + options.setKeyBinding(selected, i); + selected = -1; + KeyBinding.resetKeyBindingArrayAndHash(); + return false; + } + return true; + } +} diff --git a/forge/forge_client/src/net/minecraft/src/forge/GuiMissingMods.java b/forge/forge_client/src/net/minecraft/src/forge/GuiMissingMods.java index edb6f76f70..53f12cfa9e 100644 --- a/forge/forge_client/src/net/minecraft/src/forge/GuiMissingMods.java +++ b/forge/forge_client/src/net/minecraft/src/forge/GuiMissingMods.java @@ -1,39 +1,39 @@ -package net.minecraft.src.forge; - -import net.minecraft.src.*; -import net.minecraft.src.forge.packets.PacketMissingMods; - -public class GuiMissingMods extends GuiScreen -{ - PacketMissingMods packet; - public GuiMissingMods(PacketMissingMods pkt) - { - packet = pkt; - } - - public void initGui() - { - controlList.clear(); - controlList.add(new GuiButton(0, width / 2 - 100, height - 60, StringTranslate.getInstance().translateKey("gui.toMenu"))); - } - - protected void actionPerformed(GuiButton guibutton) - { - if (guibutton.id == 0) - { - mc.displayGuiScreen(new GuiMainMenu()); - } - } - - public void drawScreen(int i, int j, float f) - { - drawDefaultBackground(); - drawCenteredString(fontRenderer, "The server requires the following mods:", width / 2, 50, 0xffffff); - int y = 0; - for (String mod : packet.Mods) - { - drawCenteredString(fontRenderer, mod, width / 2, 80 + y++ * 10, 0xffffff); - } - super.drawScreen(i, j, f); - } -} +package net.minecraft.src.forge; + +import net.minecraft.src.*; +import net.minecraft.src.forge.packets.PacketMissingMods; + +public class GuiMissingMods extends GuiScreen +{ + PacketMissingMods packet; + public GuiMissingMods(PacketMissingMods pkt) + { + packet = pkt; + } + + public void initGui() + { + controlList.clear(); + controlList.add(new GuiButton(0, width / 2 - 100, height - 60, StringTranslate.getInstance().translateKey("gui.toMenu"))); + } + + protected void actionPerformed(GuiButton guibutton) + { + if (guibutton.id == 0) + { + mc.displayGuiScreen(new GuiMainMenu()); + } + } + + public void drawScreen(int i, int j, float f) + { + drawDefaultBackground(); + drawCenteredString(fontRenderer, "The server requires you to have the following mods:", width / 2, 50, 0xffffff); + int y = 0; + for (String mod : packet.Mods) + { + drawCenteredString(fontRenderer, mod, width / 2, 80 + y++ * 10, 0xffffff); + } + super.drawScreen(i, j, f); + } +} diff --git a/forge/forge_client/src/net/minecraft/src/forge/IArmorTextureProvider.java b/forge/forge_client/src/net/minecraft/src/forge/IArmorTextureProvider.java index e024e23cbd..bf62be3c46 100644 --- a/forge/forge_client/src/net/minecraft/src/forge/IArmorTextureProvider.java +++ b/forge/forge_client/src/net/minecraft/src/forge/IArmorTextureProvider.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -12,7 +12,8 @@ import net.minecraft.src.ItemStack; * It allows for the application of a custom texture file to the player skin * when the armor is worn. */ -public interface IArmorTextureProvider { +public interface IArmorTextureProvider +{ /** * This interface has to return the path to a file that is the same diff --git a/forge/forge_client/src/net/minecraft/src/forge/ICustomItemRenderer.java b/forge/forge_client/src/net/minecraft/src/forge/ICustomItemRenderer.java index 030678b1da..7f676b861e 100755 --- a/forge/forge_client/src/net/minecraft/src/forge/ICustomItemRenderer.java +++ b/forge/forge_client/src/net/minecraft/src/forge/ICustomItemRenderer.java @@ -2,6 +2,7 @@ package net.minecraft.src.forge; import net.minecraft.src.RenderBlocks; -public interface ICustomItemRenderer { - public void renderInventory (RenderBlocks renderblocks, int itemID, int meta); +public interface ICustomItemRenderer +{ + public void renderInventory(RenderBlocks render, int itemID, int metadata); } diff --git a/forge/forge_client/src/net/minecraft/src/forge/IGuiHandler.java b/forge/forge_client/src/net/minecraft/src/forge/IGuiHandler.java index a654b7a8c7..1ce25b17b9 100644 --- a/forge/forge_client/src/net/minecraft/src/forge/IGuiHandler.java +++ b/forge/forge_client/src/net/minecraft/src/forge/IGuiHandler.java @@ -1,21 +1,21 @@ -package net.minecraft.src.forge; - -import net.minecraft.src.EntityPlayerSP; -import net.minecraft.src.GuiScreen; -import net.minecraft.src.World; - -public interface IGuiHandler -{ - /** - * Returns a GuiScreen to be displayed to the user. This is client side - * - * @param ID The Gui ID Number - * @param player The player viewing the Gui - * @param world The current world - * @param X X Position - * @param Y Y Position - * @param Z Z Position - * @return A GuiScreen to be displayed to the user, null if none. - */ - public GuiScreen getGuiScreen(int ID, EntityPlayerSP player, World world, int X, int Y, int Z); -} +package net.minecraft.src.forge; + +import net.minecraft.src.EntityPlayerSP; +import net.minecraft.src.GuiScreen; +import net.minecraft.src.World; + +public interface IGuiHandler +{ + /** + * Returns a GuiScreen to be displayed to the user. This is client side + * + * @param ID The Gui ID Number + * @param player The player viewing the Gui + * @param world The current world + * @param X X Position + * @param Y Y Position + * @param Z Z Position + * @return A GuiScreen to be displayed to the user, null if none. + */ + public GuiScreen getGuiScreen(int ID, EntityPlayerSP player, World world, int X, int Y, int Z); +} diff --git a/forge/forge_client/src/net/minecraft/src/forge/IHighlightHandler.java b/forge/forge_client/src/net/minecraft/src/forge/IHighlightHandler.java index a2fc3ce09a..7103a5162a 100644 --- a/forge/forge_client/src/net/minecraft/src/forge/IHighlightHandler.java +++ b/forge/forge_client/src/net/minecraft/src/forge/IHighlightHandler.java @@ -1,5 +1,5 @@ /* - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ package net.minecraft.src.forge; @@ -11,13 +11,12 @@ import net.minecraft.src.EntityPlayer; import net.minecraft.src.MovingObjectPosition; import net.minecraft.src.ItemStack; -public interface IHighlightHandler { +public interface IHighlightHandler +{ /** - * Allow custom handling of highlights. Return true if the hilight has + * Allow custom handling of highlights. Return true if the highlight has * been handled. */ - public boolean onBlockHighlight(RenderGlobal renderglobal, - EntityPlayer player, MovingObjectPosition mop, int i, - ItemStack itemstack, float f); + public boolean onBlockHighlight(RenderGlobal render, EntityPlayer player, MovingObjectPosition target, int i, ItemStack currentItem, float partialTicks); } diff --git a/forge/forge_client/src/net/minecraft/src/forge/IRenderContextHandler.java b/forge/forge_client/src/net/minecraft/src/forge/IRenderContextHandler.java index 4eb1ee05d9..21c78ce614 100644 --- a/forge/forge_client/src/net/minecraft/src/forge/IRenderContextHandler.java +++ b/forge/forge_client/src/net/minecraft/src/forge/IRenderContextHandler.java @@ -1,16 +1,17 @@ /* - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ package net.minecraft.src.forge; -public interface IRenderContextHandler { - /** Run before the specified rendering context. - */ - public void beforeRenderContext(); +public interface IRenderContextHandler +{ + /** Run before the specified rendering context. + */ + public void beforeRenderContext(); - /** Run after the specified rendering context. - */ - public void afterRenderContext(); + /** Run after the specified rendering context. + */ + public void afterRenderContext(); } diff --git a/forge/forge_client/src/net/minecraft/src/forge/IRenderWorldLastHandler.java b/forge/forge_client/src/net/minecraft/src/forge/IRenderWorldLastHandler.java index 53160895f3..040f534faa 100644 --- a/forge/forge_client/src/net/minecraft/src/forge/IRenderWorldLastHandler.java +++ b/forge/forge_client/src/net/minecraft/src/forge/IRenderWorldLastHandler.java @@ -1,17 +1,18 @@ /* - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ package net.minecraft.src.forge; import net.minecraft.src.RenderGlobal; -public interface IRenderWorldLastHandler { - /** Called after rendering all the 3D data of the world. This is - * called before the user's tool is rendered, but otherwise after all - * 3D content. It is called twice in anaglyph mode. This is intended - * for rendering visual effect overlays into the world. - */ - void onRenderWorldLast(RenderGlobal rg, float f); +public interface IRenderWorldLastHandler +{ + /** Called after rendering all the 3D data of the world. This is + * called before the user's tool is rendered, but otherwise after all + * 3D content. It is called twice in anaglyph mode. This is intended + * for rendering visual effect overlays into the world. + */ + void onRenderWorldLast(RenderGlobal renderer, float partialTicks); } diff --git a/forge/forge_client/src/net/minecraft/src/forge/MinecraftForgeClient.java b/forge/forge_client/src/net/minecraft/src/forge/MinecraftForgeClient.java index bbefddf77e..0eeff4c4a6 100755 --- a/forge/forge_client/src/net/minecraft/src/forge/MinecraftForgeClient.java +++ b/forge/forge_client/src/net/minecraft/src/forge/MinecraftForgeClient.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -10,97 +10,105 @@ import net.minecraft.src.Item; import net.minecraft.src.ModLoader; import net.minecraft.src.RenderBlocks; -public class MinecraftForgeClient { - /** - * Registers a new block highlight handler. - */ - public static void registerHighlightHandler(IHighlightHandler handler) { - ForgeHooksClient.highlightHandlers.add(handler); - } +public class MinecraftForgeClient +{ + /** + * Registers a new block highlight handler. + */ + public static void registerHighlightHandler(IHighlightHandler handler) + { + ForgeHooksClient.highlightHandlers.add(handler); + } - /** Register a new render context handler. A render context is a block - * of rendering performed with similar OpenGL modes, for example, - * texture name. - * @param tex The name of the texture for this render context. - * @param sub The subid of this render context. 0 is the default pass - * for normal rendering, higher subids render later. All subids of 0 - * will render before all subids of 1, etc. - * @param handler The handler to register. - */ - public static void registerRenderContextHandler(String tex, int sub, - IRenderContextHandler handler) { - ForgeHooksClient.registerRenderContextHandler(tex,sub,handler); - } + /** Register a new render context handler. A render context is a block + * of rendering performed with similar OpenGL modes, for example, + * texture name. + * @param texture The name of the texture for this render context. + * @param subid The subid of this render context. 0 is the default pass + * for normal rendering, higher subids render later. All subids of 0 + * will render before all subids of 1, etc. + * @param handler The handler to register. + */ + public static void registerRenderContextHandler(String texture, int subid, IRenderContextHandler handler) + { + ForgeHooksClient.registerRenderContextHandler(texture, subid, handler); + } - /** Bind a texture. This is used to bind a texture file when - * performing your own rendering, rather than using ITextureProvider. - * - * This variation is reserved for future expansion. - */ - public static void bindTexture(String name, int sub) { - ForgeHooksClient.bindTexture(name,sub); - } + /** Bind a texture. This is used to bind a texture file when + * performing your own rendering, rather than using ITextureProvider. + * + * This variation is reserved for future expansion. + */ + public static void bindTexture(String texture, int subid) + { + ForgeHooksClient.bindTexture(texture, subid); + } - /** Bind a texture. This is used to bind a texture file when - * performing your own rendering, rather than using ITextureProvider. - */ - public static void bindTexture(String name) { - ForgeHooksClient.bindTexture(name,0); - } + /** Bind a texture. This is used to bind a texture file when + * performing your own rendering, rather than using ITextureProvider. + */ + public static void bindTexture(String texture) + { + ForgeHooksClient.bindTexture(texture, 0); + } - /** Unbind a texture. This binds the default texture, when you are - * finished performing custom rendering. - */ - public static void unbindTexture() { - ForgeHooksClient.unbindTexture(); - } + /** Unbind a texture. This binds the default texture, when you are + * finished performing custom rendering. + */ + public static void unbindTexture() + { + ForgeHooksClient.unbindTexture(); + } - /** Preload a texture. Textures must be preloaded before the first - * use, or they will cause visual anomalies. - */ - public static void preloadTexture(String texture) { - ModLoader.getMinecraftInstance().renderEngine - .getTexture(texture); - } + /** Preload a texture. Textures must be preloaded before the first + * use, or they will cause visual anomalies. + */ + public static void preloadTexture(String texture) + { + ModLoader.getMinecraftInstance().renderEngine.getTexture(texture); + } - /** Render a block. Render a block which may have a custom texture. - */ - public static void renderBlock(RenderBlocks rb, Block bl, int i, int - j, int k) { - ForgeHooksClient.beforeBlockRender(bl,rb); - rb.renderBlockByRenderType(bl,i,j,k); - ForgeHooksClient.afterBlockRender(bl,rb); - } + /** Render a block. Render a block which may have a custom texture. + */ + public static void renderBlock(RenderBlocks render, Block block, int X, int Y, int Z) + { + ForgeHooksClient.beforeBlockRender(block, render); + render.renderBlockByRenderType(block, X, Y, Z); + ForgeHooksClient.afterBlockRender(block, render); + } - /** Get the current render pass. - */ - public static int getRenderPass() { - return ForgeHooksClient.renderPass; - } - - private static ICustomItemRenderer [] customItemRenderers = new ICustomItemRenderer [Item.itemsList.length]; - - public static void registerCustomItemRenderer (int itemID, ICustomItemRenderer renderer) { - customItemRenderers [itemID] = renderer; - } - - public static ICustomItemRenderer getCustomItemRenderer (int itemID) { - return customItemRenderers [itemID]; - } - - private static boolean hasInit = false; - public static void init() - { - if (hasInit) - { - return; - } - hasInit = true; - ForgeHooks.setPacketHandler(new PacketHandlerClient()); - } - - static - { - init(); - } + /** Get the current render pass. + */ + public static int getRenderPass() + { + return ForgeHooksClient.renderPass; + } + + private static ICustomItemRenderer[] customItemRenderers = new ICustomItemRenderer[Item.itemsList.length]; + + public static void registerCustomItemRenderer(int itemID, ICustomItemRenderer renderer) + { + customItemRenderers[itemID] = renderer; + } + + public static ICustomItemRenderer getCustomItemRenderer (int itemID) + { + return customItemRenderers[itemID]; + } + + private static boolean hasInit = false; + public static void init() + { + if (hasInit) + { + return; + } + hasInit = true; + ForgeHooks.setPacketHandler(new PacketHandlerClient()); + } + + static + { + init(); + } } diff --git a/forge/forge_client/src/net/minecraft/src/forge/PacketHandlerClient.java b/forge/forge_client/src/net/minecraft/src/forge/PacketHandlerClient.java index ea11cc3333..d5d0927792 100644 --- a/forge/forge_client/src/net/minecraft/src/forge/PacketHandlerClient.java +++ b/forge/forge_client/src/net/minecraft/src/forge/PacketHandlerClient.java @@ -1,243 +1,243 @@ -package net.minecraft.src.forge; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map.Entry; -import java.util.logging.Level; - -import net.minecraft.client.Minecraft; -import net.minecraft.src.*; -import net.minecraft.src.forge.packets.*; - -public class PacketHandlerClient implements IPacketHandler -{ - private static boolean DEBUG = false; - - @Override - public void onPacketData(NetworkManager network, String channel, byte[] bytes) - { - DataInputStream data = new DataInputStream(new ByteArrayInputStream(bytes)); - try - { - ForgePacket pkt = null; - NetClientHandler net = (NetClientHandler)network.getNetHandler(); - - int packetID = data.read(); - switch(packetID) - { - case ForgePacket.SPAWN: - pkt = new PacketEntitySpawn(); - pkt.readData(data); - onEntitySpawnPacket((PacketEntitySpawn)pkt, data, ModLoader.getMinecraftInstance().theWorld); - break; - - case ForgePacket.MODLIST: - /* - pkt = new PacketModList(false); - pkt.readData(data); - */ - onModListCheck(net); - break; - - case ForgePacket.MOD_MISSING: - pkt = new PacketMissingMods(false); - pkt.readData(data); - onMissingMods((PacketMissingMods)pkt, net); - break; - - case ForgePacket.MOD_IDS: - pkt = new PacketModIDs(); - pkt.readData(data); - onModIDs((PacketModIDs)pkt); - break; - - case ForgePacket.OPEN_GUI: - pkt = new PacketOpenGUI(); - pkt.readData(data); - onOpenGui((PacketOpenGUI)pkt); - break; - } - } - catch(IOException e) - { - ModLoader.getLogger().log(Level.SEVERE, "Exception in PacketHandlerClient.onPacketData", e); - e.printStackTrace(); - } - } - - /** - * Processes the Entity Spawn packet. And spawns an entity in world as needed. - * If the client has the required client mod. - * @param packet The Spawn Packet - * @param data A stream holding extra data for the entity to read - * @param world The world to spawn the entity in - */ - public void onEntitySpawnPacket(PacketEntitySpawn packet, DataInputStream data, World world) - { - if (DEBUG) - { - System.out.println("S->C: " + packet.toString(true)); - } - Class cls = MinecraftForge.getEntityClass(packet.modID, packet.typeID); - if (cls == null) - { - System.out.println("Could not find entity info for " + Integer.toHexString(packet.modID) + " : " + packet.typeID); - return; - } - - double posX = (double)packet.posX / 32D; - double posY = (double)packet.posY / 32D; - double posZ = (double)packet.posZ / 32D; - try - { - Entity entity = (Entity)(cls.getConstructor(World.class, double.class, double.class, double.class).newInstance(world, posX, posY, posZ)); - if (entity instanceof IThrowableEntity) - { - Minecraft mc = ModLoader.getMinecraftInstance(); - Entity thrower = (mc.thePlayer.entityId == packet.throwerID ? mc.thePlayer : ((WorldClient)world).getEntityByID(packet.throwerID)); - ((IThrowableEntity)entity).setThrower(thrower); - } - - entity.serverPosX = packet.posX; - entity.serverPosY = packet.posX; - entity.serverPosZ = packet.posZ; - entity.rotationYaw = 0.0F; - entity.rotationPitch = 0.0F; - - Entity parts[] = entity.getParts(); - if (parts != null) - { - int i = packet.entityID - entity.entityId; - for (int j = 0; j < parts.length; j++) - { - parts[j].entityId += i; - } - } - - entity.entityId = packet.entityID; - - if (packet.throwerID > 0) - { - entity.setVelocity(packet.speedX / 8000D, packet.speedY / 8000D, packet.speedZ / 8000D); - } - - if (entity instanceof ISpawnHandler) - { - ((ISpawnHandler)entity).readSpawnData(data); - } - - ((WorldClient)world).addEntityToWorld(packet.entityID, entity); - } - catch (Exception e) - { - e.printStackTrace(); - ModLoader.getLogger().throwing("ForgeHooksClient", "onEntitySpawnPacket", e); - ModLoader.ThrowException(String.format("Error spawning entity of type %d for %s.", packet.typeID, MinecraftForge.getModByID(packet.modID)), e); - } - } - - /** - * Sends a list of all loaded mods to the server. - * For now, it it simple a String[] of mod.toString() - * @param network The network connection to send the packet on. - */ - private void onModListCheck(NetClientHandler net) - { - if (DEBUG) - { - System.out.println("S->C: " + (new PacketModList(false)).toString(true)); - } - PacketModList pkt = new PacketModList(false); - pkt.Mods = new String[ModLoader.getLoadedMods().size()]; - int x = 0; - for(BaseMod mod : (List)ModLoader.getLoadedMods()) - { - pkt.Mods[x++] = mod.toString(); - } - net.addToSendQueue(pkt.getPacket()); - if (DEBUG) - { - System.out.println("C->S: " + pkt.toString(true)); - } - } - - /** - * Received when the client does not have a mod installed that the server requires them to. - * Displays a informative screen, and disconnects from the server. - * - * @param pkt The missing mods packet - * @param net The network handler - */ - private void onMissingMods(PacketMissingMods pkt, NetClientHandler net) - { - if (DEBUG) - { - System.out.println("S->C: " + pkt.toString(true)); - } - net.disconnect(); - Minecraft mc = ModLoader.getMinecraftInstance(); - mc.changeWorld1(null); - mc.displayGuiScreen(new GuiMissingMods(pkt)); - } - - /** - * Sets up the list of ID to mod mappings. - * TODO; Make it display an error, and prompt if the user wishes to continue anyways - * if it detects that the server does not have a corresponding mod to one it has installed. - * - * @param pkt The mod id packet - */ - private void onModIDs(PacketModIDs pkt) - { - if (DEBUG) - { - System.out.println("S->C: " + pkt.toString(true)); - } - ForgeHooks.networkMods.clear(); - NetworkMod[] mods = MinecraftForge.getNetworkMods(); - for (NetworkMod mod : mods) - { - for (Entry entry : pkt.Mods.entrySet()) - { - if (mod.toString().equals(entry.getValue())) - { - ForgeHooks.networkMods.put(entry.getKey(), mod); - } - } - } - ArrayList missing = new ArrayList(); - for (NetworkMod mod : mods) - { - if (MinecraftForge.getModID(mod) == -1 && mod.serverSideRequired()) - { - missing.add(mod); - } - } - //TODO: Display error/confirmation screen - } - - /** - * Handles opening the Gui for the player. - * - * @param pkt The Open Gui Packet - */ - private void onOpenGui(PacketOpenGUI pkt) - { - if (DEBUG) - { - System.out.println("S->C: " + pkt.toString(true)); - } - NetworkMod mod = MinecraftForge.getModByID(pkt.ModID); - if (mod != null) - { - EntityPlayerSP player = (EntityPlayerSP)ModLoader.getMinecraftInstance().thePlayer; - player.openGui(mod, pkt.GuiID, player.worldObj, pkt.X, pkt.Y, pkt.Z); - player.craftingInventory.windowId = pkt.WindowID; - } - } -} +package net.minecraft.src.forge; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; +import java.util.logging.Level; + +import net.minecraft.client.Minecraft; +import net.minecraft.src.*; +import net.minecraft.src.forge.packets.*; + +public class PacketHandlerClient implements IPacketHandler +{ + private static boolean DEBUG = false; + + @Override + public void onPacketData(NetworkManager network, String channel, byte[] bytes) + { + DataInputStream data = new DataInputStream(new ByteArrayInputStream(bytes)); + try + { + ForgePacket pkt = null; + NetClientHandler net = (NetClientHandler)network.getNetHandler(); + + int packetID = data.read(); + switch (packetID) + { + case ForgePacket.SPAWN: + pkt = new PacketEntitySpawn(); + pkt.readData(data); + onEntitySpawnPacket((PacketEntitySpawn)pkt, data, ModLoader.getMinecraftInstance().theWorld); + break; + + case ForgePacket.MODLIST: + /* + pkt = new PacketModList(false); + pkt.readData(data); + */ + onModListCheck(net); + break; + + case ForgePacket.MOD_MISSING: + pkt = new PacketMissingMods(false); + pkt.readData(data); + onMissingMods((PacketMissingMods)pkt, net); + break; + + case ForgePacket.MOD_IDS: + pkt = new PacketModIDs(); + pkt.readData(data); + onModIDs((PacketModIDs)pkt); + break; + + case ForgePacket.OPEN_GUI: + pkt = new PacketOpenGUI(); + pkt.readData(data); + onOpenGui((PacketOpenGUI)pkt); + break; + } + } + catch (IOException e) + { + ModLoader.getLogger().log(Level.SEVERE, "Exception in PacketHandlerClient.onPacketData", e); + e.printStackTrace(); + } + } + + /** + * Processes the Entity Spawn packet. And spawns an entity in world as needed. + * If the client has the required client mod. + * @param packet The Spawn Packet + * @param data A stream holding extra data for the entity to read + * @param world The world to spawn the entity in + */ + public void onEntitySpawnPacket(PacketEntitySpawn packet, DataInputStream data, World world) + { + if (DEBUG) + { + System.out.println("S->C: " + packet.toString(true)); + } + Class cls = MinecraftForge.getEntityClass(packet.modID, packet.typeID); + if (cls == null) + { + System.out.println("Could not find entity info for " + Integer.toHexString(packet.modID) + " : " + packet.typeID); + return; + } + + double posX = (double)packet.posX / 32D; + double posY = (double)packet.posY / 32D; + double posZ = (double)packet.posZ / 32D; + try + { + Entity entity = (Entity)(cls.getConstructor(World.class, double.class, double.class, double.class).newInstance(world, posX, posY, posZ)); + if (entity instanceof IThrowableEntity) + { + Minecraft mc = ModLoader.getMinecraftInstance(); + Entity thrower = (mc.thePlayer.entityId == packet.throwerID ? mc.thePlayer : ((WorldClient)world).getEntityByID(packet.throwerID)); + ((IThrowableEntity)entity).setThrower(thrower); + } + + entity.serverPosX = packet.posX; + entity.serverPosY = packet.posX; + entity.serverPosZ = packet.posZ; + entity.rotationYaw = 0.0F; + entity.rotationPitch = 0.0F; + + Entity parts[] = entity.getParts(); + if (parts != null) + { + int i = packet.entityID - entity.entityId; + for (int j = 0; j < parts.length; j++) + { + parts[j].entityId += i; + } + } + + entity.entityId = packet.entityID; + + if (packet.throwerID > 0) + { + entity.setVelocity(packet.speedX / 8000D, packet.speedY / 8000D, packet.speedZ / 8000D); + } + + if (entity instanceof ISpawnHandler) + { + ((ISpawnHandler)entity).readSpawnData(data); + } + + ((WorldClient)world).addEntityToWorld(packet.entityID, entity); + } + catch (Exception e) + { + e.printStackTrace(); + ModLoader.getLogger().throwing("ForgeHooksClient", "onEntitySpawnPacket", e); + ModLoader.ThrowException(String.format("Error spawning entity of type %d for %s.", packet.typeID, MinecraftForge.getModByID(packet.modID)), e); + } + } + + /** + * Sends a list of all loaded mods to the server. + * For now, it it simple a String[] of mod.toString() + * @param network The network connection to send the packet on. + */ + private void onModListCheck(NetClientHandler net) + { + if (DEBUG) + { + System.out.println("S->C: " + (new PacketModList(false)).toString(true)); + } + PacketModList pkt = new PacketModList(false); + pkt.Mods = new String[ModLoader.getLoadedMods().size()]; + int x = 0; + for (BaseMod mod : (List)ModLoader.getLoadedMods()) + { + pkt.Mods[x++] = mod.toString(); + } + net.addToSendQueue(pkt.getPacket()); + if (DEBUG) + { + System.out.println("C->S: " + pkt.toString(true)); + } + } + + /** + * Received when the client does not have a mod installed that the server requires them to. + * Displays a informative screen, and disconnects from the server. + * + * @param pkt The missing mods packet + * @param net The network handler + */ + private void onMissingMods(PacketMissingMods pkt, NetClientHandler net) + { + if (DEBUG) + { + System.out.println("S->C: " + pkt.toString(true)); + } + net.disconnect(); + Minecraft mc = ModLoader.getMinecraftInstance(); + mc.changeWorld1(null); + mc.displayGuiScreen(new GuiMissingMods(pkt)); + } + + /** + * Sets up the list of ID to mod mappings. + * TODO; Make it display an error, and prompt if the user wishes to continue anyways + * if it detects that the server does not have a corresponding mod to one it has installed. + * + * @param pkt The mod id packet + */ + private void onModIDs(PacketModIDs pkt) + { + if (DEBUG) + { + System.out.println("S->C: " + pkt.toString(true)); + } + ForgeHooks.networkMods.clear(); + NetworkMod[] mods = MinecraftForge.getNetworkMods(); + for (NetworkMod mod : mods) + { + for (Entry entry : pkt.Mods.entrySet()) + { + if (mod.toString().equals(entry.getValue())) + { + ForgeHooks.networkMods.put(entry.getKey(), mod); + } + } + } + ArrayList missing = new ArrayList(); + for (NetworkMod mod : mods) + { + if (MinecraftForge.getModID(mod) == -1 && mod.serverSideRequired()) + { + missing.add(mod); + } + } + //TODO: Display error/confirmation screen + } + + /** + * Handles opening the Gui for the player. + * + * @param pkt The Open Gui Packet + */ + private void onOpenGui(PacketOpenGUI pkt) + { + if (DEBUG) + { + System.out.println("S->C: " + pkt.toString(true)); + } + NetworkMod mod = MinecraftForge.getModByID(pkt.ModID); + if (mod != null) + { + EntityPlayerSP player = (EntityPlayerSP)ModLoader.getMinecraftInstance().thePlayer; + player.openGui(mod, pkt.GuiID, player.worldObj, pkt.X, pkt.Y, pkt.Z); + player.craftingInventory.windowId = pkt.WindowID; + } + } +} diff --git a/forge/forge_client/src/net/minecraft/src/mod_MinecraftForge.java b/forge/forge_client/src/net/minecraft/src/mod_MinecraftForge.java index 6673fba9d0..d92520bc76 100644 --- a/forge/forge_client/src/net/minecraft/src/mod_MinecraftForge.java +++ b/forge/forge_client/src/net/minecraft/src/mod_MinecraftForge.java @@ -9,15 +9,15 @@ import net.minecraft.src.forge.MinecraftForge; public class mod_MinecraftForge extends BaseMod { @Override - public String getVersion() - { - return String.format("%d.%d.%d.%d", - ForgeHooks.majorVersion, ForgeHooks.minorVersion, + public String getVersion() + { + return String.format("%d.%d.%d.%d", + ForgeHooks.majorVersion, ForgeHooks.minorVersion, ForgeHooks.revisionVersion, ForgeHooks.buildVersion); } @Override - public void load() + public void load() { MinecraftForge.getDungeonLootTries(); //Random thing to make things Initialize } diff --git a/forge/forge_common/net/minecraft/src/forge/ArmorProperties.java b/forge/forge_common/net/minecraft/src/forge/ArmorProperties.java index 72a253e20b..c2af61ae8f 100755 --- a/forge/forge_common/net/minecraft/src/forge/ArmorProperties.java +++ b/forge/forge_common/net/minecraft/src/forge/ArmorProperties.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -22,32 +22,32 @@ public class ArmorProperties implements Comparable public int Slot = 0; private static final boolean DEBUG = false; //Only enable this if you wish to be spamed with debugging information. //Left it in because I figured it'd be useful for modders developing custom armor. - - public ArmorProperties(int priority, double ratio, int max) - { - Priority = priority; - AbsorbRatio = ratio; - AbsorbMax = max; - } - - /** - * Gathers and applies armor reduction to damage being dealt to a entity. - * - * @param entity The Entity being damage - * @param inventory An array of armor items - * @param source The damage source type - * @param damage The total damage being done - * @return The left over damage that has not been absorbed by the armor - */ - public static int ApplyArmor(EntityLiving entity, ItemStack[] inventory, DamageSource source, double damage) - { + + public ArmorProperties(int priority, double ratio, int max) + { + Priority = priority; + AbsorbRatio = ratio; + AbsorbMax = max; + } + + /** + * Gathers and applies armor reduction to damage being dealt to a entity. + * + * @param entity The Entity being damage + * @param inventory An array of armor items + * @param source The damage source type + * @param damage The total damage being done + * @return The left over damage that has not been absorbed by the armor + */ + public static int ApplyArmor(EntityLiving entity, ItemStack[] inventory, DamageSource source, double damage) + { if (DEBUG) { System.out.println("Start: " + damage + " " + (damage * 25)); } - damage *= 25; + damage *= 25; ArrayList dmgVals = new ArrayList(); - for (int x = 0; x < inventory.length; x++) + for (int x = 0; x < inventory.length; x++) { ItemStack stack = inventory[x]; if (stack == null) @@ -55,11 +55,11 @@ public class ArmorProperties implements Comparable continue; } ArmorProperties prop = null; - if (stack.getItem() instanceof ISpecialArmor) + if (stack.getItem() instanceof ISpecialArmor) { - ISpecialArmor armor = (ISpecialArmor)stack.getItem(); + ISpecialArmor armor = (ISpecialArmor)stack.getItem(); prop = armor.getProperties(entity, stack, source, damage / 25D, x).copy(); - } + } else if (stack.getItem() instanceof ItemArmor && !source.isUnblockable()) { ItemArmor armor = (ItemArmor)stack.getItem(); @@ -86,7 +86,7 @@ public class ArmorProperties implements Comparable level = prop.Priority; } ratio += prop.AbsorbRatio; - + double absorb = damage * prop.AbsorbRatio; if (absorb > 0) { @@ -112,7 +112,7 @@ public class ArmorProperties implements Comparable } inventory[prop.Slot] = null; } - } + } } damage -= (damage * ratio); } @@ -123,32 +123,34 @@ public class ArmorProperties implements Comparable } entity.carryoverDamage = (int)damage % 25; return (int)(damage / 25D); - } - - /** - * Sorts and standardizes the distribution of damage over armor. - * - * @param armor The armor information - * @param damage The total damage being received - */ - private static void StandardizeList(ArmorProperties[] armor, double damage) - { + } + + /** + * Sorts and standardizes the distribution of damage over armor. + * + * @param armor The armor information + * @param damage The total damage being received + */ + private static void StandardizeList(ArmorProperties[] armor, double damage) + { Arrays.sort(armor); - + int start = 0; double total = 0; int priority = armor[0].Priority; int pStart = 0; boolean pChange = false; boolean pFinished = false; - + if (DEBUG) { for (ArmorProperties prop : armor) + { System.out.println(prop); + } System.out.println("========================"); } - + for (int x = 0; x < armor.length; x++) { total += armor[x].AbsorbRatio; @@ -177,11 +179,11 @@ public class ArmorProperties implements Comparable x = y; break; } - else + else { armor[y].AbsorbRatio = newRatio; pFinished = true; - } + } } if (pChange && pFinished) { @@ -205,7 +207,7 @@ public class ArmorProperties implements Comparable else { for (int y = start; y <= x; y++) - { + { total -= armor[y].AbsorbRatio; if (damage * armor[y].AbsorbRatio > armor[y].AbsorbMax) { @@ -232,14 +234,16 @@ public class ArmorProperties implements Comparable } } } - } + } if (DEBUG) { for (ArmorProperties prop : armor) + { System.out.println(prop); + } } - } - + } + public int compareTo(ArmorProperties o) { if (o.Priority != Priority) @@ -250,12 +254,12 @@ public class ArmorProperties implements Comparable double right = (o.AbsorbRatio == 0 ? 0 : o.AbsorbMax * 100.0D / o.AbsorbRatio); return (int)(left - right); } - + public String toString() { return String.format("%d, %d, %f, %d", Priority, AbsorbMax, AbsorbRatio, (AbsorbRatio == 0 ? 0 : (int)(AbsorbMax * 100.0D / AbsorbRatio))); } - + public ArmorProperties copy() { return new ArmorProperties(Priority, AbsorbRatio, AbsorbMax); diff --git a/forge/forge_common/net/minecraft/src/forge/Configuration.java b/forge/forge_common/net/minecraft/src/forge/Configuration.java index e9f1707e99..9591daf2f8 100755 --- a/forge/forge_common/net/minecraft/src/forge/Configuration.java +++ b/forge/forge_common/net/minecraft/src/forge/Configuration.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -20,125 +20,137 @@ import java.util.TreeMap; import net.minecraft.src.Block; -/** +/** * This class offers advanced configurations capabilities, allowing to provide * various categories for configuration variables. */ -public class Configuration { +public class Configuration +{ private boolean configBlocks[] = null; public static final int GENERAL_PROPERTY = 0; - public static final int BLOCK_PROPERTY = 1; - public static final int ITEM_PROPERTY = 2; - + public static final int BLOCK_PROPERTY = 1; + public static final int ITEM_PROPERTY = 2; + File file; - public TreeMap blockProperties = new TreeMap(); - public TreeMap itemProperties = new TreeMap(); + public TreeMap blockProperties = new TreeMap(); + public TreeMap itemProperties = new TreeMap(); public TreeMap generalProperties = new TreeMap(); /** * Create a configuration file for the file given in parameter. */ - public Configuration(File file) { + public Configuration(File file) + { this.file = file; } /** * Gets or create a block id property. If the block id property key is - * already in the configuration, then it will be used. Otherwise, + * already in the configuration, then it will be used. Otherwise, * defaultId will be used, except if already taken, in which case this - * will try to determine a free default id. + * will try to determine a free default id. */ - public Property getOrCreateBlockIdProperty(String key, int defaultId) { - if (configBlocks == null) { + public Property getOrCreateBlockIdProperty(String key, int defaultId) + { + if (configBlocks == null) + { configBlocks = new boolean[Block.blocksList.length]; - for (int i = 0; i < configBlocks.length; ++i) { + for (int i = 0; i < configBlocks.length; ++i) + { configBlocks[i] = false; } } - if (blockProperties.containsKey(key)) { - Property property = getOrCreateIntProperty(key, - Configuration.BLOCK_PROPERTY, defaultId); + if (blockProperties.containsKey(key)) + { + Property property = getOrCreateIntProperty(key, Configuration.BLOCK_PROPERTY, defaultId); configBlocks[Integer.parseInt(property.value)] = true; return property; - } else { + } + else + { Property property = new Property(); - blockProperties.put(key, property); property.name = key; - if (Block.blocksList[defaultId] == null - && !configBlocks[defaultId]) { + if (Block.blocksList[defaultId] == null && !configBlocks[defaultId]) + { property.value = Integer.toString(defaultId); configBlocks[defaultId] = true; return property; - } else { - for (int j = Block.blocksList.length - 1; j >= 0; --j) { - if (Block.blocksList[j] == null && !configBlocks[j]) { + } + else + { + for (int j = Block.blocksList.length - 1; j >= 0; --j) + { + if (Block.blocksList[j] == null && !configBlocks[j]) + { property.value = Integer.toString(j); configBlocks[j] = true; return property; } } - throw new RuntimeException("No more block ids available for " - + key); + throw new RuntimeException("No more block ids available for " + key); } } } - public Property getOrCreateIntProperty(String key, int kind, - int defaultValue) { - Property prop = getOrCreateProperty(key, kind, - Integer.toString(defaultValue)); - - try { + public Property getOrCreateIntProperty(String key, int kind, int defaultValue) + { + Property prop = getOrCreateProperty(key, kind, Integer.toString(defaultValue)); + try + { Integer.parseInt(prop.value); - return prop; - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) + { prop.value = Integer.toString(defaultValue); return prop; } } - public Property getOrCreateBooleanProperty(String key, int kind, - boolean defaultValue) { - Property prop = getOrCreateProperty(key, kind, - Boolean.toString(defaultValue)); - - if ("true".equals(prop.value.toLowerCase()) - || "false".equals(prop.value.toLowerCase())) { + public Property getOrCreateBooleanProperty(String key, int kind, boolean defaultValue) + { + Property prop = getOrCreateProperty(key, kind, Boolean.toString(defaultValue)); + if ("true".equals(prop.value.toLowerCase()) || "false".equals(prop.value.toLowerCase())) + { return prop; - } else { + } + else + { prop.value = Boolean.toString(defaultValue); return prop; } } - public Property getOrCreateProperty(String key, int kind, - String defaultValue) { + public Property getOrCreateProperty(String key, int kind, String defaultValue) + { TreeMap source = null; - - switch (kind) { - case GENERAL_PROPERTY: - source = generalProperties; - break; - case BLOCK_PROPERTY: - source = blockProperties; - break; - case ITEM_PROPERTY: - source = itemProperties; - break; + switch (kind) + { + case GENERAL_PROPERTY: + source = generalProperties; + break; + case BLOCK_PROPERTY: + source = blockProperties; + break; + case ITEM_PROPERTY: + source = itemProperties; + break; } - if (source.containsKey(key)) { + if (source.containsKey(key)) + { return source.get(key); - } else if (defaultValue != null) { + } + else if (defaultValue != null) + { Property property = new Property(); source.put(key, property); @@ -146,125 +158,145 @@ public class Configuration { property.value = defaultValue; return property; - } else { + } + else + { return null; } } - public void load() { - try { - if (file.getParentFile() != null) { + public void load() + { + try + { + if (file.getParentFile() != null) + { file.getParentFile().mkdirs(); } - if (!file.exists() && !file.createNewFile()) { + if (!file.exists() && !file.createNewFile()) + { return; } - if (file.canRead()) { + if (file.canRead()) + { FileInputStream fileinputstream = new FileInputStream(file); - - BufferedReader buffer = new BufferedReader( - new InputStreamReader(fileinputstream, "8859_1")); + BufferedReader buffer = new BufferedReader(new InputStreamReader(fileinputstream, "8859_1")); String line; TreeMap currentMap = null; - while (true) { + while (true) + { line = buffer.readLine(); - if (line == null) { + if (line == null) + { break; } int nameStart = -1, nameEnd = -1; boolean skip = false; - for (int i = 0; i < line.length() && !skip; ++i) { - if (Character.isLetterOrDigit(line.charAt(i)) - || line.charAt(i) == '.') { - if (nameStart == -1) { + for (int i = 0; i < line.length() && !skip; ++i) + { + if (Character.isLetterOrDigit(line.charAt(i)) || line.charAt(i) == '.') + { + if (nameStart == -1) + { nameStart = i; } nameEnd = i; - } else if (Character.isWhitespace(line.charAt(i))) { + } + else if (Character.isWhitespace(line.charAt(i))) + { // ignore space charaters - } else { - switch (line.charAt(i)) { - case '#': - skip = true; - continue; - case '{': - String scopeName = line.substring(nameStart, - nameEnd + 1); + } + else + { + switch (line.charAt(i)) + { + case '#': + skip = true; + continue; + case '{': + String scopeName = line.substring(nameStart, nameEnd + 1); - if (scopeName.equals("general")) { - currentMap = generalProperties; - } else if (scopeName.equals("block")) { - currentMap = blockProperties; - } else if (scopeName.equals("item")) { - currentMap = itemProperties; - } else { - throw new RuntimeException( - "unknown section " + scopeName); - } + if (scopeName.equals("general")) + { + currentMap = generalProperties; + } + else if (scopeName.equals("block")) + { + currentMap = blockProperties; + } + else if (scopeName.equals("item")) + { + currentMap = itemProperties; + } + else + { + throw new RuntimeException("unknown section " + scopeName); + } - break; - case '}': - currentMap = null; - break; - case '=': - String propertyName = line.substring(nameStart, - nameEnd + 1); + break; + case '}': + currentMap = null; + break; + case '=': + String propertyName = line.substring(nameStart, nameEnd + 1); - if (currentMap == null) { - throw new RuntimeException("property " - + propertyName + " has no scope"); - } + if (currentMap == null) + { + throw new RuntimeException("property " + propertyName + " has no scope"); + } - Property prop = new Property(); - prop.name = propertyName; - prop.value = line.substring(i + 1); - i = line.length(); + Property prop = new Property(); + prop.name = propertyName; + prop.value = line.substring(i + 1); + i = line.length(); - currentMap.put(propertyName, prop); + currentMap.put(propertyName, prop); - break; - default: - throw new RuntimeException("unknown character " - + line.charAt(i)); + break; + default: + throw new RuntimeException("unknown character " + line.charAt(i)); } } } } } - } catch (IOException e) { - // TODO Auto-generated catch block + } + catch (IOException e) + { e.printStackTrace(); } } - public void save() { - try { - if (file.getParentFile() != null) { + public void save() + { + try + { + if (file.getParentFile() != null) + { file.getParentFile().mkdirs(); } - if (!file.exists() && !file.createNewFile()) { + if (!file.exists() && !file.createNewFile()) + { return; } - if (file.canWrite()) { - FileOutputStream fileoutputstream = new FileOutputStream(file); - - BufferedWriter buffer = new BufferedWriter( - new OutputStreamWriter(fileoutputstream, "8859_1")); + if (file.canWrite()) + { + FileOutputStream fos = new FileOutputStream(file); + BufferedWriter buffer = new BufferedWriter(new OutputStreamWriter(fos, "8859_1")); buffer.write("# Configuration file\r\n"); - buffer.write("# Generated on " - + DateFormat.getInstance().format(new Date()) + "\r\n"); + buffer.write("# Generated on " + DateFormat.getInstance().format(new Date()) + "\r\n"); buffer.write("\r\n"); buffer.write("###########\r\n"); buffer.write("# General #\r\n"); @@ -291,17 +323,21 @@ public class Configuration { buffer.write("}\r\n\r\n"); buffer.close(); - fileoutputstream.close(); + fos.close(); } - } catch (IOException e) { + } + catch (IOException e) + { e.printStackTrace(); } } - private void writeProperties(BufferedWriter buffer, - Collection props) throws IOException { - for (Property property : props) { - if (property.comment != null) { + private void writeProperties(BufferedWriter buffer, Collection props) throws IOException + { + for (Property property : props) + { + if (property.comment != null) + { buffer.write(" # " + property.comment + "\r\n"); } @@ -309,5 +345,4 @@ public class Configuration { buffer.write("\r\n"); } } - } diff --git a/forge/forge_common/net/minecraft/src/forge/DimensionManager.java b/forge/forge_common/net/minecraft/src/forge/DimensionManager.java index ffe993d369..89ec7be184 100644 --- a/forge/forge_common/net/minecraft/src/forge/DimensionManager.java +++ b/forge/forge_common/net/minecraft/src/forge/DimensionManager.java @@ -1,70 +1,70 @@ -package net.minecraft.src.forge; - -import java.util.Hashtable; - -import net.minecraft.src.*; - -public class DimensionManager -{ - private static Hashtable providers = new Hashtable(); - private static Hashtable spawnSettings = new Hashtable(); - private static Hashtable worlds = new Hashtable(); - private static boolean hasInit = false; - - public static boolean registerDimension(int id, WorldProvider provider, boolean keepLoaded) - { - if (providers.containsValue(id)) - { - return false; - } - providers.put(id, provider); - spawnSettings.put(id, keepLoaded); - return true; - } - - public static void init() - { - if (hasInit) - { - return; - } - registerDimension( 0, new WorldProviderSurface(), true); - registerDimension(-1, new WorldProviderHell(), true); - registerDimension( 1, new WorldProviderEnd(), false); - } - - public static WorldProvider getProvider(int id) - { - return providers.get(id); - } - - public static Integer[] getIDs() - { - return providers.keySet().toArray(new Integer[0]); - } - - public static void setWorld(int id, World world) - { - worlds.put(id, world); - } - - public static World getWorld(int id) - { - return worlds.get(id); - } - - public static World[] getWorlds() - { - return worlds.values().toArray(new World[0]); - } - - public static boolean shouldLoadSpawn(int id) - { - return spawnSettings.contains(id) && spawnSettings.get(id); - } - - static - { - init(); - } -} +package net.minecraft.src.forge; + +import java.util.Hashtable; + +import net.minecraft.src.*; + +public class DimensionManager +{ + private static Hashtable providers = new Hashtable(); + private static Hashtable spawnSettings = new Hashtable(); + private static Hashtable worlds = new Hashtable(); + private static boolean hasInit = false; + + public static boolean registerDimension(int id, WorldProvider provider, boolean keepLoaded) + { + if (providers.containsValue(id)) + { + return false; + } + providers.put(id, provider); + spawnSettings.put(id, keepLoaded); + return true; + } + + public static void init() + { + if (hasInit) + { + return; + } + registerDimension( 0, new WorldProviderSurface(), true); + registerDimension(-1, new WorldProviderHell(), true); + registerDimension( 1, new WorldProviderEnd(), false); + } + + public static WorldProvider getProvider(int id) + { + return providers.get(id); + } + + public static Integer[] getIDs() + { + return providers.keySet().toArray(new Integer[0]); + } + + public static void setWorld(int id, World world) + { + worlds.put(id, world); + } + + public static World getWorld(int id) + { + return worlds.get(id); + } + + public static World[] getWorlds() + { + return worlds.values().toArray(new World[0]); + } + + public static boolean shouldLoadSpawn(int id) + { + return spawnSettings.contains(id) && spawnSettings.get(id); + } + + static + { + init(); + } +} diff --git a/forge/forge_common/net/minecraft/src/forge/DungeonLoot.java b/forge/forge_common/net/minecraft/src/forge/DungeonLoot.java index cf9c767c93..d3078f97b3 100644 --- a/forge/forge_common/net/minecraft/src/forge/DungeonLoot.java +++ b/forge/forge_common/net/minecraft/src/forge/DungeonLoot.java @@ -1,51 +1,51 @@ -package net.minecraft.src.forge; - -import java.util.Random; -import net.minecraft.src.ItemStack; - -/** - * - * Used to hold a list of all items that can be spawned in a world dungeon - * - */ -public class DungeonLoot -{ - private ItemStack item; - private int minCount = 1; - private int maxCount = 1; - - /** - * @param item A item stack - * @param min Minimum stack size when randomly generating - * @param max Maximum stack size when randomly generating - */ - public DungeonLoot(ItemStack item, int min, int max) - { - this.item = item; - minCount = min; - maxCount = max; - } - - /** - * Grabs a ItemStack ready to be added to the dungeon chest, - * the stack size will be between minCount and maxCount - * @param rand World gen random number generator - * @return The ItemStack to be added to the chest - */ - public ItemStack generateStack(Random rand) - { - ItemStack ret = this.item.copy(); - ret.stackSize = minCount + (rand.nextInt(maxCount - minCount + 1)); - return ret; - } - - public boolean equals(ItemStack item, int min, int max) - { - return (min == minCount && max == maxCount && item.isItemEqual(this.item)); - } - - public boolean equals(ItemStack item) - { - return item.isItemEqual(this.item); - } -} +package net.minecraft.src.forge; + +import java.util.Random; +import net.minecraft.src.ItemStack; + +/** + * + * Used to hold a list of all items that can be spawned in a world dungeon + * + */ +public class DungeonLoot +{ + private ItemStack item; + private int minCount = 1; + private int maxCount = 1; + + /** + * @param item A item stack + * @param min Minimum stack size when randomly generating + * @param max Maximum stack size when randomly generating + */ + public DungeonLoot(ItemStack item, int min, int max) + { + this.item = item; + minCount = min; + maxCount = max; + } + + /** + * Grabs a ItemStack ready to be added to the dungeon chest, + * the stack size will be between minCount and maxCount + * @param rand World gen random number generator + * @return The ItemStack to be added to the chest + */ + public ItemStack generateStack(Random rand) + { + ItemStack ret = this.item.copy(); + ret.stackSize = minCount + (rand.nextInt(maxCount - minCount + 1)); + return ret; + } + + public boolean equals(ItemStack item, int min, int max) + { + return (min == minCount && max == maxCount && item.isItemEqual(this.item)); + } + + public boolean equals(ItemStack item) + { + return item.isItemEqual(this.item); + } +} diff --git a/forge/forge_common/net/minecraft/src/forge/EntityTrackerInfo.java b/forge/forge_common/net/minecraft/src/forge/EntityTrackerInfo.java index e9444f1b7e..9a043769a8 100644 --- a/forge/forge_common/net/minecraft/src/forge/EntityTrackerInfo.java +++ b/forge/forge_common/net/minecraft/src/forge/EntityTrackerInfo.java @@ -1,21 +1,21 @@ -package net.minecraft.src.forge; - -import net.minecraft.src.BaseMod; - -public class EntityTrackerInfo -{ - public final NetworkMod Mod; - public final int ID; - public final int Range; - public final int UpdateFrequancy; - public final boolean SendVelocityInfo; - - public EntityTrackerInfo(NetworkMod mod, int ID, int range, int updateFrequancy, boolean sendVelocityInfo) - { - Mod = mod; - this.ID = ID; - Range = range; - UpdateFrequancy = updateFrequancy; - SendVelocityInfo = sendVelocityInfo; - } -} +package net.minecraft.src.forge; + +import net.minecraft.src.BaseMod; + +public class EntityTrackerInfo +{ + public final NetworkMod Mod; + public final int ID; + public final int Range; + public final int UpdateFrequancy; + public final boolean SendVelocityInfo; + + public EntityTrackerInfo(NetworkMod mod, int ID, int range, int updateFrequancy, boolean sendVelocityInfo) + { + Mod = mod; + this.ID = ID; + Range = range; + UpdateFrequancy = updateFrequancy; + SendVelocityInfo = sendVelocityInfo; + } +} diff --git a/forge/forge_common/net/minecraft/src/forge/EnumHelper.java b/forge/forge_common/net/minecraft/src/forge/EnumHelper.java index 923da66b7f..cb2cfca05d 100644 --- a/forge/forge_common/net/minecraft/src/forge/EnumHelper.java +++ b/forge/forge_common/net/minecraft/src/forge/EnumHelper.java @@ -1,342 +1,366 @@ -package net.minecraft.src.forge; - -import net.minecraft.src.*; -import java.lang.reflect.*; -import java.util.*; - -public class EnumHelper { - private static Object reflectionFactory = null; - private static Method newConstructorAccessor = null; - private static Method newInstance = null; - private static Method newFieldAccessor = null; - private static Method fieldAccessorSet = null; - private static boolean isSetup = false; - - //Some enums are decompiled with extra arguments, so lets check for that - private static Class[][] ctrs = { - {EnumAction.class}, - {EnumArmorMaterial.class, int.class, int[].class, int.class}, - {EnumArt.class, String.class, int.class, int.class, int.class, int.class}, - {EnumCreatureAttribute.class}, - {EnumCreatureType.class, Class.class, int.class, Material.class, boolean.class}, - {EnumDoor.class}, - {EnumEnchantmentType.class}, - {EnumMobType.class}, - {EnumMovingObjectType.class}, - {EnumSkyBlock.class, int.class}, - {EnumStatus.class}, - {EnumToolMaterial.class, int.class, int.class, float.class, int.class, int.class} - }; - - private static boolean[] decompiled = new boolean[ctrs.length]; - - public static EnumAction addAction(String name) - { - if (!isSetup) - { - setup(); - } - - return addEnum(decompiled[0], EnumAction.class, name, - new Class[] {}, - new Object[]{}); - } - public static EnumArmorMaterial addArmorMaterial(String name, int durability, int[] reductionAmounts, int enchantability) - { - if (!isSetup) - { - setup(); - } - - return addEnum(decompiled[1], EnumArmorMaterial.class, name, - new Class[] { int.class, int[].class, int.class }, - new Object[]{ durability, reductionAmounts, enchantability }); - } - public static EnumArt addArt(String name, String tile, int sizeX, int sizeY, int offsetX, int offsetY) - { - if (!isSetup) - { - setup(); - } - - return addEnum(decompiled[2], EnumArt.class, name, - new Class[] {String.class, int.class, int.class, int.class, int.class}, - new Object[]{tile, sizeX, sizeY, offsetX, offsetY}); - } - public static EnumCreatureAttribute addCreatureAttribute(String name) - { - if (!isSetup) - { - setup(); - } - - return addEnum(decompiled[3], EnumCreatureAttribute.class, name, - new Class[] {}, - new Object[]{}); - } - public static EnumCreatureType addCreatureType(String name, Class typeClass, int maxNumber, Material material, boolean peaceful) - { - if (!isSetup) - { - setup(); - } - - return addEnum(decompiled[4], EnumCreatureType.class, name, - new Class[] {Class.class, int.class, Material.class, boolean.class}, - new Object[]{typeClass, maxNumber, material, peaceful}); - } - public static EnumDoor addDoor(String name) - { - if (!isSetup) - { - setup(); - } - - return addEnum(decompiled[5], EnumDoor.class, name, - new Class[] {}, - new Object[]{}); - } - public static EnumEnchantmentType addEnchantmentType(String name) - { - if (!isSetup) - { - setup(); - } - - return addEnum(decompiled[6], EnumEnchantmentType.class, name, - new Class[] {}, - new Object[]{}); - } - public static EnumMobType addMobType(String name) - { - if (!isSetup) - { - setup(); - } - - return addEnum(decompiled[7], EnumMobType.class, name, - new Class[] {}, - new Object[]{}); - } - public static EnumMovingObjectType addMovingObjectType(String name) - { - if (!isSetup) - { - setup(); - } - - return addEnum(decompiled[8], EnumMovingObjectType.class, name, - new Class[] {}, - new Object[]{}); - } - public static EnumSkyBlock addSkyBlock(String name, int lightValue) - { - if (!isSetup) - { - setup(); - } - - return addEnum(decompiled[9], EnumSkyBlock.class, name, - new Class[] {int.class }, - new Object[]{lightValue}); - } - public static EnumStatus addStatus(String name) - { - if (!isSetup) - { - setup(); - } - - return addEnum(decompiled[10], EnumStatus.class, name, - new Class[] {}, - new Object[]{}); - } - public static EnumToolMaterial addToolMaterial(String name, int harvestLevel, int maxUses, float efficiency, int damage, int enchantability) - { - if (!isSetup) - { - setup(); - } - - return addEnum(decompiled[11], EnumToolMaterial.class, name, - new Class[] { int.class, int.class, float.class, int.class, int.class }, - new Object[]{ harvestLevel, maxUses, efficiency, damage, enchantability }); - } - - private static void setup() - { - if (isSetup) - { - return; - } - - //System.out.println("Enum Helper Initalizing: "); - for(int x = 0; x < ctrs.length; x++) - { - try { - Class[] enumHeaders = new Class[ctrs[x].length + 3]; - enumHeaders[0] = String.class; - enumHeaders[1] = int.class; - enumHeaders[2] = String.class; - enumHeaders[3] = int.class; - - for (int y = 1; y < ctrs[x].length; y++) - enumHeaders[3 + y] = ctrs[x][y]; - - ctrs[x][0].getDeclaredConstructor(enumHeaders); - decompiled[x] = true; - - } catch(Exception e) { - //Nom Nom Nom - } - //System.out.format("\t%-25s %s\r\n", ctrs[x][0].getName().replace("net.minecraft.src.", ""), decompiled[x]); - } - - - - try { - Method getReflectionFactory = Class.forName("sun.reflect.ReflectionFactory").getDeclaredMethod("getReflectionFactory"); - reflectionFactory = getReflectionFactory.invoke(null); - newConstructorAccessor = Class.forName("sun.reflect.ReflectionFactory").getDeclaredMethod("newConstructorAccessor", Constructor.class); - newInstance = Class.forName("sun.reflect.ConstructorAccessor").getDeclaredMethod("newInstance", Object[].class); - newFieldAccessor = Class.forName("sun.reflect.ReflectionFactory").getDeclaredMethod("newFieldAccessor", Field.class, boolean.class); - fieldAccessorSet = Class.forName("sun.reflect.FieldAccessor").getDeclaredMethod("set", Object.class, Object.class); - } catch (Exception e) { - e.printStackTrace(); - } - - isSetup = true; - } - - - /* - * Everything below this is found at the site below, and updated to be able to compile in Eclipse/Java 1.6+ - * Also modified for use in decompiled code. - * Found at: http://niceideas.ch/roller2/badtrash/entry/java_create_enum_instances_dynamically - */ - - private static Object getConstructorAccessor(boolean decompiled, Class enumClass, Class[] additionalParameterTypes) throws Exception { - Class[] parameterTypes = null; - if (decompiled) - { - parameterTypes = new Class[additionalParameterTypes.length + 4]; - parameterTypes[0] = String.class; - parameterTypes[1] = int.class; - parameterTypes[2] = String.class; - parameterTypes[3] = int.class; - System.arraycopy(additionalParameterTypes, 0, parameterTypes, 4, additionalParameterTypes.length); - } - else - { - parameterTypes = new Class[additionalParameterTypes.length + 2]; - parameterTypes[0] = String.class; - parameterTypes[1] = int.class; - System.arraycopy(additionalParameterTypes, 0, parameterTypes, 2, additionalParameterTypes.length); - } - return newConstructorAccessor.invoke(reflectionFactory, enumClass.getDeclaredConstructor(parameterTypes)); - } - - private static > T makeEnum(boolean decompiled, Class enumClass, String value, int ordinal, Class[] additionalTypes, Object[] additionalValues) throws Exception { - Object[] parms = null; - if (decompiled) - { - parms = new Object[additionalValues.length + 4]; - parms[0] = value; - parms[1] = Integer.valueOf(ordinal); - parms[2] = value; - parms[3] = Integer.valueOf(ordinal); - System.arraycopy(additionalValues, 0, parms, 4, additionalValues.length); - } - else - { - parms = new Object[additionalValues.length + 2]; - parms[0] = value; - parms[1] = Integer.valueOf(ordinal); - System.arraycopy(additionalValues, 0, parms, 2, additionalValues.length); - } - return enumClass.cast(newInstance.invoke(getConstructorAccessor(decompiled, enumClass, additionalTypes), new Object[]{parms})); - } - - private static void setFailsafeFieldValue(Field field, Object target, Object value) throws Exception { - field.setAccessible(true); - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); - Object fieldAccessor = newFieldAccessor.invoke(reflectionFactory, field, false); - fieldAccessorSet.invoke(fieldAccessor, target, value); - } - - private static void blankField(Class enumClass, String fieldName) throws Exception { - for (Field field : Class.class.getDeclaredFields()) { - if (field.getName().contains(fieldName)) { - field.setAccessible(true); - setFailsafeFieldValue(field, enumClass, null); - break; - } - } - } - - private static void cleanEnumCache(Class enumClass) throws Exception { - blankField(enumClass, "enumConstantDirectory"); - blankField(enumClass, "enumConstants"); - } - - public static > T addEnum(Class enumType, String enumName, boolean decompiled) { - return addEnum(decompiled, enumType, enumName, new Class[]{}, new Object[]{}); - } - - @SuppressWarnings("unchecked") - public static > T addEnum(boolean decompiled, Class enumType, String enumName, Class[] paramTypes, Object[] paramValues) { - if (!isSetup) - { - setup(); - } - - Field valuesField = null; - Field[] fields = enumType.getDeclaredFields(); - int flags = Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL | 0x1000 /*SYNTHETIC*/; - String valueType = String.format("[L%s;", enumType.getName().replace('.', '/')); - - for (Field field : fields) { - if (decompiled) - { - if (field.getName().contains("$VALUES")) - { - valuesField = field; - break; - } - } - else - { - if ((field.getModifiers() & flags) == flags && - field.getType().getName().replace('.', '/').equals(valueType)) //Apparently some JVMs return .'s and some don't.. - { - valuesField = field; - break; - } - } - } - valuesField.setAccessible(true); - - try { - T[] previousValues = (T[])valuesField.get(enumType); - List values = new ArrayList(Arrays.asList(previousValues)); - T newValue = (T)makeEnum(decompiled, enumType, enumName, values.size(), paramTypes, paramValues); - values.add(newValue); - setFailsafeFieldValue(valuesField, null, values.toArray((T[]) Array.newInstance(enumType, 0))); - cleanEnumCache(enumType); - - return newValue; - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e.getMessage(), e); - } - } - - static { - if (!isSetup) - { - setup(); - } - } +package net.minecraft.src.forge; + +import net.minecraft.src.*; +import java.lang.reflect.*; +import java.util.*; + +public class EnumHelper +{ + private static Object reflectionFactory = null; + private static Method newConstructorAccessor = null; + private static Method newInstance = null; + private static Method newFieldAccessor = null; + private static Method fieldAccessorSet = null; + private static boolean isSetup = false; + + //Some enums are decompiled with extra arguments, so lets check for that + private static Class[][] ctrs = + { + {EnumAction.class}, + {EnumArmorMaterial.class, int.class, int[].class, int.class}, + {EnumArt.class, String.class, int.class, int.class, int.class, int.class}, + {EnumCreatureAttribute.class}, + {EnumCreatureType.class, Class.class, int.class, Material.class, boolean.class}, + {EnumDoor.class}, + {EnumEnchantmentType.class}, + {EnumMobType.class}, + {EnumMovingObjectType.class}, + {EnumSkyBlock.class, int.class}, + {EnumStatus.class}, + {EnumToolMaterial.class, int.class, int.class, float.class, int.class, int.class} + }; + + private static boolean[] decompiled = new boolean[ctrs.length]; + + public static EnumAction addAction(String name) + { + if (!isSetup) + { + setup(); + } + + return addEnum(decompiled[0], EnumAction.class, name, + new Class[] {}, + new Object[]{}); + } + public static EnumArmorMaterial addArmorMaterial(String name, int durability, int[] reductionAmounts, int enchantability) + { + if (!isSetup) + { + setup(); + } + + return addEnum(decompiled[1], EnumArmorMaterial.class, name, + new Class[] { int.class, int[].class, int.class }, + new Object[]{ durability, reductionAmounts, enchantability }); + } + public static EnumArt addArt(String name, String tile, int sizeX, int sizeY, int offsetX, int offsetY) + { + if (!isSetup) + { + setup(); + } + + return addEnum(decompiled[2], EnumArt.class, name, + new Class[] {String.class, int.class, int.class, int.class, int.class}, + new Object[]{tile, sizeX, sizeY, offsetX, offsetY}); + } + public static EnumCreatureAttribute addCreatureAttribute(String name) + { + if (!isSetup) + { + setup(); + } + + return addEnum(decompiled[3], EnumCreatureAttribute.class, name, + new Class[] {}, + new Object[]{}); + } + public static EnumCreatureType addCreatureType(String name, Class typeClass, int maxNumber, Material material, boolean peaceful) + { + if (!isSetup) + { + setup(); + } + + return addEnum(decompiled[4], EnumCreatureType.class, name, + new Class[] {Class.class, int.class, Material.class, boolean.class}, + new Object[]{typeClass, maxNumber, material, peaceful}); + } + public static EnumDoor addDoor(String name) + { + if (!isSetup) + { + setup(); + } + + return addEnum(decompiled[5], EnumDoor.class, name, + new Class[] {}, + new Object[]{}); + } + public static EnumEnchantmentType addEnchantmentType(String name) + { + if (!isSetup) + { + setup(); + } + + return addEnum(decompiled[6], EnumEnchantmentType.class, name, + new Class[] {}, + new Object[]{}); + } + public static EnumMobType addMobType(String name) + { + if (!isSetup) + { + setup(); + } + + return addEnum(decompiled[7], EnumMobType.class, name, + new Class[] {}, + new Object[]{}); + } + public static EnumMovingObjectType addMovingObjectType(String name) + { + if (!isSetup) + { + setup(); + } + + return addEnum(decompiled[8], EnumMovingObjectType.class, name, + new Class[] {}, + new Object[]{}); + } + public static EnumSkyBlock addSkyBlock(String name, int lightValue) + { + if (!isSetup) + { + setup(); + } + + return addEnum(decompiled[9], EnumSkyBlock.class, name, + new Class[] {int.class }, + new Object[]{lightValue}); + } + public static EnumStatus addStatus(String name) + { + if (!isSetup) + { + setup(); + } + + return addEnum(decompiled[10], EnumStatus.class, name, + new Class[] {}, + new Object[]{}); + } + public static EnumToolMaterial addToolMaterial(String name, int harvestLevel, int maxUses, float efficiency, int damage, int enchantability) + { + if (!isSetup) + { + setup(); + } + + return addEnum(decompiled[11], EnumToolMaterial.class, name, + new Class[] { int.class, int.class, float.class, int.class, int.class }, + new Object[]{ harvestLevel, maxUses, efficiency, damage, enchantability }); + } + + private static void setup() + { + if (isSetup) + { + return; + } + + //System.out.println("Enum Helper Initalizing: "); + for (int x = 0; x < ctrs.length; x++) + { + try + { + Class[] enumHeaders = new Class[ctrs[x].length + 3]; + enumHeaders[0] = String.class; + enumHeaders[1] = int.class; + enumHeaders[2] = String.class; + enumHeaders[3] = int.class; + + for (int y = 1; y < ctrs[x].length; y++) + { + enumHeaders[3 + y] = ctrs[x][y]; + } + + ctrs[x][0].getDeclaredConstructor(enumHeaders); + decompiled[x] = true; + + } + catch (Exception e) + { + //Nom Nom Nom + } + //System.out.format("\t%-25s %s\r\n", ctrs[x][0].getName().replace("net.minecraft.src.", ""), decompiled[x]); + } + + + + try + { + Method getReflectionFactory = Class.forName("sun.reflect.ReflectionFactory").getDeclaredMethod("getReflectionFactory"); + reflectionFactory = getReflectionFactory.invoke(null); + newConstructorAccessor = Class.forName("sun.reflect.ReflectionFactory").getDeclaredMethod("newConstructorAccessor", Constructor.class); + newInstance = Class.forName("sun.reflect.ConstructorAccessor").getDeclaredMethod("newInstance", Object[].class); + newFieldAccessor = Class.forName("sun.reflect.ReflectionFactory").getDeclaredMethod("newFieldAccessor", Field.class, boolean.class); + fieldAccessorSet = Class.forName("sun.reflect.FieldAccessor").getDeclaredMethod("set", Object.class, Object.class); + } + catch (Exception e) + { + e.printStackTrace(); + } + + isSetup = true; + } + + + /* + * Everything below this is found at the site below, and updated to be able to compile in Eclipse/Java 1.6+ + * Also modified for use in decompiled code. + * Found at: http://niceideas.ch/roller2/badtrash/entry/java_create_enum_instances_dynamically + */ + + private static Object getConstructorAccessor(boolean decompiled, Class enumClass, Class[] additionalParameterTypes) throws Exception + { + Class[] parameterTypes = null; + if (decompiled) + { + parameterTypes = new Class[additionalParameterTypes.length + 4]; + parameterTypes[0] = String.class; + parameterTypes[1] = int.class; + parameterTypes[2] = String.class; + parameterTypes[3] = int.class; + System.arraycopy(additionalParameterTypes, 0, parameterTypes, 4, additionalParameterTypes.length); + } + else + { + parameterTypes = new Class[additionalParameterTypes.length + 2]; + parameterTypes[0] = String.class; + parameterTypes[1] = int.class; + System.arraycopy(additionalParameterTypes, 0, parameterTypes, 2, additionalParameterTypes.length); + } + return newConstructorAccessor.invoke(reflectionFactory, enumClass.getDeclaredConstructor(parameterTypes)); + } + + private static < T extends Enum> T makeEnum(boolean decompiled, Class enumClass, String value, int ordinal, Class[] additionalTypes, Object[] additionalValues) throws Exception + { + Object[] parms = null; + if (decompiled) + { + parms = new Object[additionalValues.length + 4]; + parms[0] = value; + parms[1] = Integer.valueOf(ordinal); + parms[2] = value; + parms[3] = Integer.valueOf(ordinal); + System.arraycopy(additionalValues, 0, parms, 4, additionalValues.length); + } + else + { + parms = new Object[additionalValues.length + 2]; + parms[0] = value; + parms[1] = Integer.valueOf(ordinal); + System.arraycopy(additionalValues, 0, parms, 2, additionalValues.length); + } + return enumClass.cast(newInstance.invoke(getConstructorAccessor(decompiled, enumClass, additionalTypes), new Object[] {parms})); + } + + private static void setFailsafeFieldValue(Field field, Object target, Object value) throws Exception + { + field.setAccessible(true); + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); + Object fieldAccessor = newFieldAccessor.invoke(reflectionFactory, field, false); + fieldAccessorSet.invoke(fieldAccessor, target, value); + } + + private static void blankField(Class enumClass, String fieldName) throws Exception + { + for (Field field : Class.class.getDeclaredFields()) + { + if (field.getName().contains(fieldName)) + { + field.setAccessible(true); + setFailsafeFieldValue(field, enumClass, null); + break; + } + } + } + + private static void cleanEnumCache(Class enumClass) throws Exception + { + blankField(enumClass, "enumConstantDirectory"); + blankField(enumClass, "enumConstants"); + } + + public static < T extends Enum> T addEnum(Class enumType, String enumName, boolean decompiled) + { + return addEnum(decompiled, enumType, enumName, new Class[] {}, new Object[] {}); + } + + @SuppressWarnings("unchecked") + public static > T addEnum(boolean decompiled, Class enumType, String enumName, Class[] paramTypes, Object[] paramValues) + { + if (!isSetup) + { + setup(); + } + + Field valuesField = null; + Field[] fields = enumType.getDeclaredFields(); + int flags = Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL | 0x1000 /*SYNTHETIC*/; + String valueType = String.format("[L%s;", enumType.getName().replace('.', '/')); + + for (Field field : fields) + { + if (decompiled) + { + if (field.getName().contains("$VALUES")) + { + valuesField = field; + break; + } + } + else + { + if ((field.getModifiers() & flags) == flags && + field.getType().getName().replace('.', '/').equals(valueType)) //Apparently some JVMs return .'s and some don't.. + { + valuesField = field; + break; + } + } + } + valuesField.setAccessible(true); + + try + { + T[] previousValues = (T[])valuesField.get(enumType); + List values = new ArrayList(Arrays.asList(previousValues)); + T newValue = (T)makeEnum(decompiled, enumType, enumName, values.size(), paramTypes, paramValues); + values.add(newValue); + setFailsafeFieldValue(valuesField, null, values.toArray((T[]) Array.newInstance(enumType, 0))); + cleanEnumCache(enumType); + + return newValue; + } + catch (Exception e) + { + e.printStackTrace(); + throw new RuntimeException(e.getMessage(), e); + } + } + + static + { + if (!isSetup) + { + setup(); + } + } } \ No newline at end of file diff --git a/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java b/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java index 13c73eaf74..6a88b654c6 100644 --- a/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java +++ b/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -29,108 +29,114 @@ import java.io.DataOutputStream; import java.io.IOException; import java.util.*; -public class ForgeHooks { - // TODO: move all app-side hooks from MinecraftForge +public class ForgeHooks +{ + // List Handling Hooks + // ------------------------------------------------------------ + public static void onTakenFromCrafting(EntityPlayer player, ItemStack stack, IInventory craftMatrix) + { + for (ICraftingHandler handler : craftingHandlers) + { + handler.onTakenFromCrafting(player, stack, craftMatrix); + } + } + static LinkedList craftingHandlers = new LinkedList(); + + public static void onDestroyCurrentItem(EntityPlayer player, ItemStack orig) + { + for (IDestroyToolHandler handler : destroyToolHandlers) + { + handler.onDestroyCurrentItem(player, orig); + } + } + static LinkedList destroyToolHandlers = new LinkedList(); + + public static boolean onUseBonemeal(World world, int blockID, int x, int y, int z) + { + for (IBonemealHandler handler : bonemealHandlers) + { + if (handler.onUseBonemeal(world, blockID, x, y, z)) + { + return true; + } + } + return false; + } + static LinkedList bonemealHandlers = new LinkedList(); + + public static boolean onUseHoe(ItemStack hoe, EntityPlayer player, World world, int x, int y, int z) + { + for (IHoeHandler handler : hoeHandlers) + { + if (handler.onUseHoe(hoe, player, world, x, y, z)) + { + return true; + } + } + return false; + } + static LinkedList hoeHandlers = new LinkedList(); + + public static EnumStatus sleepInBedAt(EntityPlayer player, int x, int y, int z) + { + for (ISleepHandler handler : sleepHandlers) + { + EnumStatus status = handler.sleepInBedAt(player, x, y, z); + if (status != null) + { + return status; + } + } + return null; + } + static LinkedList sleepHandlers = new LinkedList(); - // List Handling Hooks - // ------------------------------------------------------------ - public static void onTakenFromCrafting(EntityPlayer player, ItemStack ist, - IInventory craftMatrix) { - for (ICraftingHandler handler : craftingHandlers) { - handler.onTakenFromCrafting(player,ist,craftMatrix); - } - } + public static void onMinecartUpdate(EntityMinecart minecart, int x, int y, int z) + { + for (IMinecartHandler handler : minecartHandlers) + { + handler.onMinecartUpdate(minecart, x, y, z); + } + } - static LinkedList craftingHandlers = new LinkedList(); + public static void onMinecartEntityCollision(EntityMinecart minecart, Entity entity) + { + for (IMinecartHandler handler : minecartHandlers) + { + handler.onMinecartEntityCollision(minecart, entity); + } + } - public static void onDestroyCurrentItem(EntityPlayer player, ItemStack orig) { - for (IDestroyToolHandler handler : destroyToolHandlers) { - handler.onDestroyCurrentItem(player,orig); - } - } + public static boolean onMinecartInteract(EntityMinecart minecart, EntityPlayer player) + { + boolean canceled = true; + for (IMinecartHandler handler : minecartHandlers) + { + boolean tmp = handler.onMinecartInteract(minecart, player, canceled); + canceled = canceled && tmp; + } + return canceled; + } - static LinkedList destroyToolHandlers = new LinkedList(); + static LinkedList minecartHandlers = new LinkedList(); - public static boolean onUseBonemeal(World world, - int bid, int i, int j, int k) { - for(IBonemealHandler handler : bonemealHandlers) { - if(handler.onUseBonemeal(world,bid,i,j,k)) - return true; - } - return false; - } + public static void onConnect(NetworkManager network) + { + for (IConnectionHandler handler : connectionHandlers) + { + handler.OnConnect(network); + } + } - static LinkedList bonemealHandlers = new LinkedList(); + public static void onLogin(NetworkManager network, Packet1Login login) + { + for (IConnectionHandler handler : connectionHandlers) + { + handler.OnLogin(network, login); + } + } - public static boolean onUseHoe(ItemStack hoe, EntityPlayer player, - World world, int i, int j, int k) { - for(IHoeHandler handler : hoeHandlers) { - if(handler.onUseHoe(hoe,player,world,i,j,k)) - return true; - } - return false; - } - - static LinkedList hoeHandlers = new LinkedList(); - - public static EnumStatus sleepInBedAt(EntityPlayer player, int i, int j, int k) { - for (ISleepHandler handler : sleepHandlers) { - EnumStatus status = handler.sleepInBedAt(player, i, j, k); - if (status != null) - return status; - } - return null; - } - - static LinkedList sleepHandlers = new LinkedList(); - - - public static void onMinecartUpdate(EntityMinecart minecart, int x, int y, int z) - { - for (IMinecartHandler handler : minecartHandlers) - { - handler.onMinecartUpdate(minecart, x, y, z); - } - } - - public static void onMinecartEntityCollision(EntityMinecart minecart, Entity entity) - { - for (IMinecartHandler handler : minecartHandlers) - { - handler.onMinecartEntityCollision(minecart, entity); - } - } - - public static boolean onMinecartInteract(EntityMinecart minecart, EntityPlayer player) - { - boolean canceled = true; - for (IMinecartHandler handler : minecartHandlers) - { - boolean tmp = handler.onMinecartInteract(minecart, player, canceled); - canceled = canceled && tmp; - } - return canceled; - } - - static LinkedList minecartHandlers = new LinkedList(); - - public static void onConnect(NetworkManager network) - { - for (IConnectionHandler handler : connectionHandlers) - { - handler.OnConnect(network); - } - } - - public static void onLogin(NetworkManager network, Packet1Login login) - { - for (IConnectionHandler handler : connectionHandlers) - { - handler.OnLogin(network, login); - } - } - public static void onDisconnect(NetworkManager network, String message, Object[] args) { for (IConnectionHandler handler : connectionHandlers) @@ -138,239 +144,276 @@ public class ForgeHooks { handler.OnDisconnect(network, message, args); } } - static LinkedList connectionHandlers = new LinkedList(); - - public static boolean onItemPickup(EntityPlayer player, EntityItem item) - { - boolean cont = true; - for (IPickupHandler handler : pickupHandlers) - { - cont = cont && handler.onItemPickup(player, item); - if (!cont || item.item.stackSize <= 0) - { - return false; - } - } - return cont; - } - static LinkedList pickupHandlers = new LinkedList(); + static LinkedList connectionHandlers = new LinkedList(); - // Plant Management - // ------------------------------------------------------------ - static class ProbableItem { - public ProbableItem(int item, int md, int q, int st, int e) { - wstart=st; wend=e; - itemid=item; meta=md; - qty=q; - } - int wstart, wend; - int itemid, meta; - int qty; - } + public static boolean onItemPickup(EntityPlayer player, EntityItem item) + { + boolean cont = true; + for (IPickupHandler handler : pickupHandlers) + { + cont = cont && handler.onItemPickup(player, item); + if (!cont || item.item.stackSize <= 0) + { + return false; + } + } + return cont; + } + static LinkedList pickupHandlers = new LinkedList(); - static ProbableItem getRandomItem(List list, int prop) { - int n=Collections.binarySearch(list,prop,new Comparator(){ - public int compare(Object o1, Object o2) { - ProbableItem pi=(ProbableItem)o1; - Integer i1=(Integer)o2; - if(i1=pi.wend) return -1; - return 0; - } - }); - if(n<0) return null; - return list.get(n); - } + // Plant Management + // ------------------------------------------------------------ + static class ProbableItem + { + public ProbableItem(int item, int metadata, int quantity, int start, int end) + { + WeightStart = start; + WeightEnd = end; + ItemID = item; + Metadata = metadata; + Quantity = quantity; + } + int WeightStart, WeightEnd; + int ItemID, Metadata; + int Quantity; + } - static List plantGrassList; - static int plantGrassWeight; + static ProbableItem getRandomItem(List list, int prop) + { + int n = Collections.binarySearch(list, prop, new Comparator() + { + public int compare(Object o1, Object o2) + { + ProbableItem pi = (ProbableItem)o1; + Integer i1 = (Integer)o2; + if (i1 < pi.WeightStart) + { + return 1; + } + if (i1 >= pi.WeightEnd) + { + return -1; + } + return 0; + } + }); + if (n < 0) + { + return null; + } + return list.get(n); + } - static List seedGrassList; - static int seedGrassWeight; + static List plantGrassList; + static int plantGrassWeight; - static { - plantGrassList = new ArrayList(); - plantGrassList.add(new ProbableItem(Block.plantYellow.blockID, 0, 1, 0, 20)); - plantGrassList.add(new ProbableItem(Block.plantRed.blockID, 0, 1, 20, 30)); - plantGrassWeight = 30; + static List seedGrassList; + static int seedGrassWeight; - seedGrassList = new ArrayList(); - seedGrassList.add(new ProbableItem(Item.seeds.shiftedIndex, 0, 1, 0, 10)); - seedGrassWeight = 10; - } + public static void plantGrassPlant(World world, int x, int y, int z) + { + int index = world.rand.nextInt(plantGrassWeight); + ProbableItem item = getRandomItem(plantGrassList, index); + if (item == null) + { + return; + } + world.setBlockAndMetadataWithNotify(x, y, z, item.ItemID, item.Metadata); + } - public static void plantGrassPlant(World world, int i, int j, int k) { - int n = world.rand.nextInt(plantGrassWeight); - ProbableItem pi = getRandomItem(plantGrassList, n); - if (pi == null) return; - world.setBlockAndMetadataWithNotify(i, j, k, pi.itemid, pi.meta); - } + public static void addPlantGrass(int item, int metadata, int probability) + { + plantGrassList.add(new ProbableItem(item, metadata, 1, plantGrassWeight, plantGrassWeight + probability)); + plantGrassWeight += probability; + } - public static void addPlantGrass(int item, int md, int prop) { - plantGrassList.add(new ProbableItem(item, md, 1, plantGrassWeight, plantGrassWeight + prop)); - plantGrassWeight += prop; - } + public static ItemStack getGrassSeed(World world) + { + int index = world.rand.nextInt(seedGrassWeight); + ProbableItem item = getRandomItem(seedGrassList, index); + if (item == null) + { + return null; + } + return new ItemStack(item.ItemID, item.Quantity, item.Metadata); + } - public static ItemStack getGrassSeed(World world) { - int n = world.rand.nextInt(seedGrassWeight); - ProbableItem pi = getRandomItem(seedGrassList,n); - if (pi == null) return null; - return new ItemStack(pi.itemid, pi.qty, pi.meta); - } + public static void addGrassSeed(int item, int metadata, int quantity, int probability) + { + seedGrassList.add(new ProbableItem(item, metadata, quantity, seedGrassWeight, seedGrassWeight + probability)); + seedGrassWeight += probability; + } - public static void addGrassSeed(int item, int md, int qty, int prop) { - seedGrassList.add(new ProbableItem( - item,md,qty,seedGrassWeight,seedGrassWeight+prop)); - seedGrassWeight+=prop; - } + // Tool Path + // ------------------------------------------------------------ + public static boolean canHarvestBlock(Block block, EntityPlayer player, int metadata) + { + if (block.blockMaterial.isHarvestable()) + { + return true; + } + ItemStack stack = player.inventory.getCurrentItem(); + if (stack == null) + { + return false; + } - // Tool Path - // ------------------------------------------------------------ - public static boolean canHarvestBlock(Block bl, EntityPlayer player, int md) { - if(bl.blockMaterial.isHarvestable()) - return true; - ItemStack itemstack = player.inventory.getCurrentItem(); - if (itemstack == null) return false; + List info = (List)toolClasses.get(stack.itemID); + if (info == null) + { + return stack.canHarvestBlock(block); + } + Object[] tmp = info.toArray(); + String toolClass = (String)tmp[0]; + int harvestLevel = (Integer)tmp[1]; - List tc = (List)toolClasses.get(itemstack.itemID); - if (tc == null) return itemstack.canHarvestBlock(bl); - Object[] ta = tc.toArray(); - String cls = (String)ta[0]; - int hvl = (Integer)ta[1]; + Integer blockHarvestLevel = (Integer)toolHarvestLevels.get(Arrays.asList(block.blockID, metadata, toolClass)); + if (blockHarvestLevel == null) + { + return stack.canHarvestBlock(block); + } + if (blockHarvestLevel > harvestLevel) + { + return false; + } + return true; + } - Integer bhl = (Integer)toolHarvestLevels.get(Arrays.asList(bl.blockID, md, cls)); - if(bhl == null) return itemstack.canHarvestBlock(bl); - if(bhl > hvl) return false; - return true; - } + public static float blockStrength(Block block, EntityPlayer player, int metadata) + { + float hardness = block.getHardness(metadata); + if (hardness < 0.0F) + { + return 0.0F; + } - public static float blockStrength(Block bl, - EntityPlayer player, int md) { - float bh=bl.getHardness(md); - if(bh < 0.0F) return 0.0F; + if (!canHarvestBlock(block, player, metadata)) + { + return 1.0F / hardness / 100F; + } + else + { + return player.getCurrentPlayerStrVsBlock(block, metadata) / hardness / 30F; + } + } - if(!canHarvestBlock(bl,player,md)) { - return 1.0F / bh / 100F; - } else { - return player.getCurrentPlayerStrVsBlock(bl,md) / - bh / 30F; - } - } + public static boolean isToolEffective(ItemStack stack, Block block, int metadata) + { + List toolClass = (List)toolClasses.get(stack.itemID); + if (toolClass == null) + { + return false; + } + return toolEffectiveness.contains(Arrays.asList(block.blockID, metadata, (String)toolClass.get(0))); + } - public static boolean isToolEffective(ItemStack ist, Block bl, int md) { - List tc = (List)toolClasses.get(ist.itemID); - if (tc == null) - { - return false; - } - Object[] ta = tc.toArray(); - String cls = (String)ta[0]; - return toolEffectiveness.contains(Arrays.asList(bl.blockID, md, cls)); - } + static void initTools() + { + if (toolInit) + { + return; + } + toolInit = true; - static void initTools() { - if(toolInit) - { - return; - } - toolInit = true; + MinecraftForge.setToolClass(Item.pickaxeWood, "pickaxe", 0); + MinecraftForge.setToolClass(Item.pickaxeStone, "pickaxe", 1); + MinecraftForge.setToolClass(Item.pickaxeSteel, "pickaxe", 2); + MinecraftForge.setToolClass(Item.pickaxeGold, "pickaxe", 0); + MinecraftForge.setToolClass(Item.pickaxeDiamond, "pickaxe", 3); - MinecraftForge.setToolClass(Item.pickaxeWood, "pickaxe", 0); - MinecraftForge.setToolClass(Item.pickaxeStone, "pickaxe", 1); - MinecraftForge.setToolClass(Item.pickaxeSteel, "pickaxe", 2); - MinecraftForge.setToolClass(Item.pickaxeGold, "pickaxe", 0); - MinecraftForge.setToolClass(Item.pickaxeDiamond, "pickaxe", 3); + MinecraftForge.setToolClass(Item.axeWood, "axe", 0); + MinecraftForge.setToolClass(Item.axeStone, "axe", 1); + MinecraftForge.setToolClass(Item.axeSteel, "axe", 2); + MinecraftForge.setToolClass(Item.axeGold, "axe", 0); + MinecraftForge.setToolClass(Item.axeDiamond, "axe", 3); - MinecraftForge.setToolClass(Item.axeWood, "axe", 0); - MinecraftForge.setToolClass(Item.axeStone, "axe", 1); - MinecraftForge.setToolClass(Item.axeSteel, "axe", 2); - MinecraftForge.setToolClass(Item.axeGold, "axe", 0); - MinecraftForge.setToolClass(Item.axeDiamond, "axe", 3); + MinecraftForge.setToolClass(Item.shovelWood, "shovel", 0); + MinecraftForge.setToolClass(Item.shovelStone, "shovel", 1); + MinecraftForge.setToolClass(Item.shovelSteel, "shovel", 2); + MinecraftForge.setToolClass(Item.shovelGold, "shovel", 0); + MinecraftForge.setToolClass(Item.shovelDiamond, "shovel", 3); - MinecraftForge.setToolClass(Item.shovelWood, "shovel", 0); - MinecraftForge.setToolClass(Item.shovelStone, "shovel", 1); - MinecraftForge.setToolClass(Item.shovelSteel, "shovel", 2); - MinecraftForge.setToolClass(Item.shovelGold, "shovel", 0); - MinecraftForge.setToolClass(Item.shovelDiamond, "shovel", 3); + MinecraftForge.setBlockHarvestLevel(Block.obsidian, "pickaxe", 3); + MinecraftForge.setBlockHarvestLevel(Block.oreDiamond, "pickaxe", 2); + MinecraftForge.setBlockHarvestLevel(Block.blockDiamond, "pickaxe", 2); + MinecraftForge.setBlockHarvestLevel(Block.oreGold, "pickaxe", 2); + MinecraftForge.setBlockHarvestLevel(Block.blockGold, "pickaxe", 2); + MinecraftForge.setBlockHarvestLevel(Block.oreIron, "pickaxe", 1); + MinecraftForge.setBlockHarvestLevel(Block.blockSteel, "pickaxe", 1); + MinecraftForge.setBlockHarvestLevel(Block.oreLapis, "pickaxe", 1); + MinecraftForge.setBlockHarvestLevel(Block.blockLapis, "pickaxe", 1); + MinecraftForge.setBlockHarvestLevel(Block.oreRedstone, "pickaxe", 2); + MinecraftForge.setBlockHarvestLevel(Block.oreRedstoneGlowing, "pickaxe", 2); + MinecraftForge.removeBlockEffectiveness(Block.oreRedstone, "pickaxe"); + MinecraftForge.removeBlockEffectiveness(Block.obsidian, "pickaxe"); + MinecraftForge.removeBlockEffectiveness(Block.oreRedstoneGlowing, "pickaxe"); - MinecraftForge.setBlockHarvestLevel(Block.obsidian, "pickaxe", 3); - MinecraftForge.setBlockHarvestLevel(Block.oreDiamond, "pickaxe", 2); - MinecraftForge.setBlockHarvestLevel(Block.blockDiamond, "pickaxe", 2); - MinecraftForge.setBlockHarvestLevel(Block.oreGold, "pickaxe", 2); - MinecraftForge.setBlockHarvestLevel(Block.blockGold, "pickaxe", 2); - MinecraftForge.setBlockHarvestLevel(Block.oreIron, "pickaxe", 1); - MinecraftForge.setBlockHarvestLevel(Block.blockSteel, "pickaxe", 1); - MinecraftForge.setBlockHarvestLevel(Block.oreLapis, "pickaxe", 1); - MinecraftForge.setBlockHarvestLevel(Block.blockLapis, "pickaxe", 1); - MinecraftForge.setBlockHarvestLevel(Block.oreRedstone, "pickaxe", 2); - MinecraftForge.setBlockHarvestLevel(Block.oreRedstoneGlowing, "pickaxe", 2); - MinecraftForge.removeBlockEffectiveness(Block.oreRedstone, "pickaxe"); - MinecraftForge.removeBlockEffectiveness(Block.obsidian, "pickaxe"); - MinecraftForge.removeBlockEffectiveness(Block.oreRedstoneGlowing, "pickaxe"); + Block[] pickeff = + { + Block.cobblestone, Block.stairDouble, + Block.stairSingle, Block.stone, + Block.sandStone, Block.cobblestoneMossy, + Block.oreCoal, Block.ice, + Block.netherrack, Block.oreLapis, + Block.blockLapis + }; + for (Block block : pickeff) + { + MinecraftForge.setBlockHarvestLevel(block, "pickaxe", 0); + } - Block[] pickeff = { - Block.cobblestone, Block.stairDouble, - Block.stairSingle, Block.stone, - Block.sandStone, Block.cobblestoneMossy, - Block.oreCoal, Block.ice, - Block.netherrack, Block.oreLapis, - Block.blockLapis - }; - for (Block bl : pickeff) - { - MinecraftForge.setBlockHarvestLevel(bl, "pickaxe", 0); - } - - Block[] spadeEff = { - Block.grass, Block.dirt, - Block.sand, Block.gravel, - Block.snow, Block.blockSnow, - Block.blockClay, Block.tilledField, - Block.slowSand, Block.mycelium - }; - for (Block bl : spadeEff) - { - MinecraftForge.setBlockHarvestLevel(bl, "shovel", 0); - } - - Block[] axeEff = { - Block.planks, Block.bookShelf, - Block.wood, Block.chest, - Block.stairDouble, Block.stairSingle, - Block.pumpkin, Block.pumpkinLantern - }; - for (Block bl : axeEff) - { - MinecraftForge.setBlockHarvestLevel(bl, "axe", 0); - } + Block[] spadeEff = + { + Block.grass, Block.dirt, + Block.sand, Block.gravel, + Block.snow, Block.blockSnow, + Block.blockClay, Block.tilledField, + Block.slowSand, Block.mycelium + }; + for (Block block : spadeEff) + { + MinecraftForge.setBlockHarvestLevel(block, "shovel", 0); + } + + Block[] axeEff = + { + Block.planks, Block.bookShelf, + Block.wood, Block.chest, + Block.stairDouble, Block.stairSingle, + Block.pumpkin, Block.pumpkinLantern + }; + for (Block block : axeEff) + { + MinecraftForge.setBlockHarvestLevel(block, "axe", 0); + } + + } + + public static HashMap entityTrackerMap = new HashMap(); + + /** + * Builds the 'Spawn' packet using the Custom Payload packet on the 'Forge' channel. + * Supports entities that have custom spawn data, as well as the generic 'Owner' construct. + * + * @param entity The entity instance to spawn + * @return The spawn packet, or null if we arn't spawning it. + */ + public static Packet getEntitySpawnPacket(Entity entity) + { + EntityTrackerInfo info = MinecraftForge.getEntityTrackerInfo(entity, false); + if (info == null) + { + return null; + } + + PacketEntitySpawn pkt = new PacketEntitySpawn(entity, info.Mod, info.ID); + return pkt.getPacket(); + } - } - - public static HashMap entityTrackerMap = new HashMap(); - - /** - * Builds the 'Spawn' packet using the Custom Payload packet on the 'Forge' channel. - * Supports entities that have custom spawn data, as well as the generic 'Owner' construct. - * - * @param entity The entity instance to spawn - * @return The spawn packet, or null if we arn't spawning it. - */ - public static Packet getEntitySpawnPacket(Entity entity) - { - EntityTrackerInfo info = MinecraftForge.getEntityTrackerInfo(entity, false); - if (info == null) - { - return null; - } - - PacketEntitySpawn pkt = new PacketEntitySpawn(entity, info.Mod, info.ID); - return pkt.getPacket(); - } - public static Hashtable networkMods = new Hashtable(); public static Hashtable guiHandlers = new Hashtable(); - public static boolean onArrowLoose(ItemStack itemstack, World world, EntityPlayer player, int heldTime) + public static boolean onArrowLoose(ItemStack itemstack, World world, EntityPlayer player, int heldTime) { for (IArrowLooseHandler handler : arrowLooseHandlers) { @@ -381,10 +424,10 @@ public class ForgeHooks { } return false; } - + public static ArrayList arrowLooseHandlers = new ArrayList(); - - public static ItemStack onArrowNock(ItemStack itemstack, World world, EntityPlayer player) + + public static ItemStack onArrowNock(ItemStack itemstack, World world, EntityPlayer player) { for (IArrowNockHandler handler : arrowNockHandlers) { @@ -398,32 +441,42 @@ public class ForgeHooks { } public static ArrayList arrowNockHandlers = new ArrayList(); - public static final int majorVersion=0; - public static final int minorVersion=0; - public static final int revisionVersion=0; - public static final int buildVersion=0; - static { - System.out.printf("MinecraftForge v%d.%d.%d.%d Initialized\n", majorVersion, minorVersion, revisionVersion, buildVersion); - ModLoader.getLogger().info(String.format("MinecraftForge v%d.%d.%d.%d Initialized\n", majorVersion, minorVersion, revisionVersion, buildVersion)); - } + public static final int majorVersion=0; + public static final int minorVersion=0; + public static final int revisionVersion=0; + public static final int buildVersion=0; + static + { + plantGrassList = new ArrayList(); + plantGrassList.add(new ProbableItem(Block.plantYellow.blockID, 0, 1, 0, 20)); + plantGrassList.add(new ProbableItem(Block.plantRed.blockID, 0, 1, 20, 30)); + plantGrassWeight = 30; - static boolean toolInit=false; - static HashMap toolClasses=new HashMap(); - static HashMap toolHarvestLevels=new HashMap(); - static HashSet toolEffectiveness=new HashSet(); - - private static IPacketHandler forgePacketHandler = null; - public static void setPacketHandler(IPacketHandler handler) - { - if (forgePacketHandler != null) - { - throw new RuntimeException("Attempted to set Forge's Internal packet handler after it was already set"); - } - forgePacketHandler = handler; - } - public static IPacketHandler getPacketHandler() - { - return forgePacketHandler; - } + seedGrassList = new ArrayList(); + seedGrassList.add(new ProbableItem(Item.seeds.shiftedIndex, 0, 1, 0, 10)); + seedGrassWeight = 10; + + System.out.printf("MinecraftForge v%d.%d.%d.%d Initialized\n", majorVersion, minorVersion, revisionVersion, buildVersion); + ModLoader.getLogger().info(String.format("MinecraftForge v%d.%d.%d.%d Initialized\n", majorVersion, minorVersion, revisionVersion, buildVersion)); + } + + static boolean toolInit = false; + static HashMap toolClasses = new HashMap(); + static HashMap toolHarvestLevels = new HashMap(); + static HashSet toolEffectiveness = new HashSet(); + + private static IPacketHandler forgePacketHandler = null; + public static void setPacketHandler(IPacketHandler handler) + { + if (forgePacketHandler != null) + { + throw new RuntimeException("Attempted to set Forge's Internal packet handler after it was already set"); + } + forgePacketHandler = handler; + } + public static IPacketHandler getPacketHandler() + { + return forgePacketHandler; + } } diff --git a/forge/forge_common/net/minecraft/src/forge/IArrowLooseHandler.java b/forge/forge_common/net/minecraft/src/forge/IArrowLooseHandler.java index 1f77f46287..9646b9e6d2 100644 --- a/forge/forge_common/net/minecraft/src/forge/IArrowLooseHandler.java +++ b/forge/forge_common/net/minecraft/src/forge/IArrowLooseHandler.java @@ -1,24 +1,24 @@ -/** - * This software is provided under the terms of the Minecraft Forge Public - * License v1.0. - */ -package net.minecraft.src.forge; - -import net.minecraft.src.EntityPlayer; -import net.minecraft.src.ItemStack; -import net.minecraft.src.World; - -public interface IArrowLooseHandler -{ - /** - * This is called before a bow tries to shoot an arrow. If it - * returns a true result, then the normal arrow will not be shot. - * - * @param itemstack The ItemStack for the bow doing the firing - * @param world The current world - * @param player The player that is firing the bow - * @param heldTime The amount of ticks the bow was held ready. - * @return True if the event should be canceled. - */ - public boolean onArrowLoose(ItemStack itemstack, World world, EntityPlayer player, int heldTime); -} +/** + * This software is provided under the terms of the Minecraft Forge Public + * License v1.0. + */ +package net.minecraft.src.forge; + +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.ItemStack; +import net.minecraft.src.World; + +public interface IArrowLooseHandler +{ + /** + * This is called before a bow tries to shoot an arrow. If it + * returns a true result, then the normal arrow will not be shot. + * + * @param itemstack The ItemStack for the bow doing the firing + * @param world The current world + * @param player The player that is firing the bow + * @param heldTime The amount of ticks the bow was held ready. + * @return True if the event should be canceled. + */ + public boolean onArrowLoose(ItemStack itemstack, World world, EntityPlayer player, int heldTime); +} diff --git a/forge/forge_common/net/minecraft/src/forge/IArrowNockHandler.java b/forge/forge_common/net/minecraft/src/forge/IArrowNockHandler.java index d1858aecc3..9c5e9197b9 100644 --- a/forge/forge_common/net/minecraft/src/forge/IArrowNockHandler.java +++ b/forge/forge_common/net/minecraft/src/forge/IArrowNockHandler.java @@ -1,26 +1,26 @@ -/** - * This software is provided under the terms of the Minecraft Forge Public - * License v1.0. - */ -package net.minecraft.src.forge; - -import net.minecraft.src.ItemStack; -import net.minecraft.src.World; -import net.minecraft.src.EntityPlayer; - -public interface IArrowNockHandler -{ - - /** - * This is called before a player tries to load an arrow. If it returns - * a non-null result, then the normal arrow will not be loaded and the - * bow will be changed to the returned value. - * - * @param itemstack The ItemStack for the bow doing the firing - * @param world The current world - * @param player The player that is using the bow - * @return The new bow item, or null to continue normally. - */ - public ItemStack onArrowNock(ItemStack itemstack, World world, EntityPlayer player); - +/** + * This software is provided under the terms of the Minecraft Forge Public + * License v1.0. + */ +package net.minecraft.src.forge; + +import net.minecraft.src.ItemStack; +import net.minecraft.src.World; +import net.minecraft.src.EntityPlayer; + +public interface IArrowNockHandler +{ + + /** + * This is called before a player tries to load an arrow. If it returns + * a non-null result, then the normal arrow will not be loaded and the + * bow will be changed to the returned value. + * + * @param itemstack The ItemStack for the bow doing the firing + * @param world The current world + * @param player The player that is using the bow + * @return The new bow item, or null to continue normally. + */ + public ItemStack onArrowNock(ItemStack itemstack, World world, EntityPlayer player); + } \ No newline at end of file diff --git a/forge/forge_common/net/minecraft/src/forge/IBonemealHandler.java b/forge/forge_common/net/minecraft/src/forge/IBonemealHandler.java index ac2ae0b339..30b2d8a697 100644 --- a/forge/forge_common/net/minecraft/src/forge/IBonemealHandler.java +++ b/forge/forge_common/net/minecraft/src/forge/IBonemealHandler.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -7,12 +7,13 @@ package net.minecraft.src.forge; import net.minecraft.src.World; -public interface IBonemealHandler { - /** Called when bonemeal is used on a block. This is also called for - * multiplayer servers, which must still return true if appropriate but - * shouldn't actually perform world manipulation. - * @return true to use up the bonemeal and stop processing. - */ - public boolean onUseBonemeal(World world, int bid, int i, int j, int k); +public interface IBonemealHandler +{ + /** Called when bonemeal is used on a block. This is also called for + * multiplayer servers, which must still return true if appropriate but + * shouldn't actually perform world manipulation. + * @return true to use up the bonemeal and stop processing. + */ + public boolean onUseBonemeal(World world, int blockID, int X, int Y, int Z); } diff --git a/forge/forge_common/net/minecraft/src/forge/IBucketHandler.java b/forge/forge_common/net/minecraft/src/forge/IBucketHandler.java index 200eeb3406..aac05cf764 100755 --- a/forge/forge_common/net/minecraft/src/forge/IBucketHandler.java +++ b/forge/forge_common/net/minecraft/src/forge/IBucketHandler.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -8,16 +8,17 @@ package net.minecraft.src.forge; import net.minecraft.src.ItemStack; import net.minecraft.src.World; -public interface IBucketHandler { +public interface IBucketHandler +{ /** * This is called before Minecraft tries to fill a bucket with water or * lava. If it returns a non-null result, then the filling process will * be stopped and the empty bucket will be changed to the result of this * subprogram. - * + * * @see MinecraftForge#registerCustomBucketHander(IBucketHandler) */ - public ItemStack fillCustomBucket(World w, int i, int j, int k); + public ItemStack fillCustomBucket(World world, int X, int Y, int Z); } diff --git a/forge/forge_common/net/minecraft/src/forge/IConnectRedstone.java b/forge/forge_common/net/minecraft/src/forge/IConnectRedstone.java index 57d56a9f3e..6e581369fd 100644 --- a/forge/forge_common/net/minecraft/src/forge/IConnectRedstone.java +++ b/forge/forge_common/net/minecraft/src/forge/IConnectRedstone.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -11,17 +11,16 @@ import net.minecraft.src.IBlockAccess; /** * This interface is to be implemented by Block classes. It will override * standard algorithms controlling connection between two blocks by redstone - * + * * @see Block */ -public interface IConnectRedstone { - +public interface IConnectRedstone +{ /** * When this returns false, the block at location i, j, k cannot make * a redstone connection in the direction given in parameter, otherwise * it can. Use to control which sides are inputs and outputs for redstone * wires. */ - public boolean canConnectRedstone(IBlockAccess iba, int i, int j, int k, - int dir); + public boolean canConnectRedstone(IBlockAccess world, int X, int Y, int Z, int direction); } diff --git a/forge/forge_common/net/minecraft/src/forge/IConnectionHandler.java b/forge/forge_common/net/minecraft/src/forge/IConnectionHandler.java index 0bb81bbaf5..de01baf76f 100644 --- a/forge/forge_common/net/minecraft/src/forge/IConnectionHandler.java +++ b/forge/forge_common/net/minecraft/src/forge/IConnectionHandler.java @@ -3,33 +3,33 @@ package net.minecraft.src.forge; import net.minecraft.src.NetworkManager; import net.minecraft.src.Packet1Login; -public interface IConnectionHandler +public interface IConnectionHandler { /** * Raised when a Client successfully connects it's socket to the Server. * @param network The new NetworkManager associated with this connection. */ public void OnConnect(NetworkManager network); - + /** * Raised when you receive a Packet1Login. - * On the server, it is raised after the NetHandler is switched, and the + * On the server, it is raised after the NetHandler is switched, and the * initial user placement/info packets are sent. - * - * On the client, this is raised after the packet is parsed, and the user + * + * On the client, this is raised after the packet is parsed, and the user * is sitting at the 'Downloading Terrain' screen. - * + * * @param network The NetoworkManager associated with this connection. * @param login The login packet */ public void OnLogin(NetworkManager network, Packet1Login login); - + /** * Raised whenever the socket is closed, can be caused by various reasons. - * - * @param network The NetworkManager associated with this connection. + * + * @param network The NetworkManager associated with this connection. * @param message The translated message to be displayed for this disconnection. - * @param args Any additional arguments that the code may of provided. + * @param args Any additional arguments that the code may of provided. * Sometimes this is further explanation, or a Throwable, in the case of errors. */ public void OnDisconnect(NetworkManager network, String message, Object[] args); diff --git a/forge/forge_common/net/minecraft/src/forge/ICraftingHandler.java b/forge/forge_common/net/minecraft/src/forge/ICraftingHandler.java index 60d635b7bb..3ff0366ed1 100644 --- a/forge/forge_common/net/minecraft/src/forge/ICraftingHandler.java +++ b/forge/forge_common/net/minecraft/src/forge/ICraftingHandler.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -9,12 +9,10 @@ import net.minecraft.src.IInventory; import net.minecraft.src.EntityPlayer; import net.minecraft.src.ItemStack; -public interface ICraftingHandler { - +public interface ICraftingHandler +{ /** * Called after an item is taken from crafting. */ - public void onTakenFromCrafting(EntityPlayer player, ItemStack ist, - IInventory craftMatrix); - + public void onTakenFromCrafting(EntityPlayer player, ItemStack stack, IInventory craftMatrix); } diff --git a/forge/forge_common/net/minecraft/src/forge/IDestroyToolHandler.java b/forge/forge_common/net/minecraft/src/forge/IDestroyToolHandler.java index 5c67a0476e..bdbbb4331c 100644 --- a/forge/forge_common/net/minecraft/src/forge/IDestroyToolHandler.java +++ b/forge/forge_common/net/minecraft/src/forge/IDestroyToolHandler.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -8,9 +8,10 @@ package net.minecraft.src.forge; import net.minecraft.src.ItemStack; import net.minecraft.src.EntityPlayer; -public interface IDestroyToolHandler { - /** Called when the user's currently equipped item is destroyed. - */ - public void onDestroyCurrentItem(EntityPlayer player, ItemStack orig); +public interface IDestroyToolHandler +{ + /** Called when the user's currently equipped item is destroyed. + */ + public void onDestroyCurrentItem(EntityPlayer player, ItemStack orig); } diff --git a/forge/forge_common/net/minecraft/src/forge/IHoeHandler.java b/forge/forge_common/net/minecraft/src/forge/IHoeHandler.java index 78886bdbaa..a3f9daabc1 100644 --- a/forge/forge_common/net/minecraft/src/forge/IHoeHandler.java +++ b/forge/forge_common/net/minecraft/src/forge/IHoeHandler.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -9,13 +9,12 @@ import net.minecraft.src.World; import net.minecraft.src.ItemStack; import net.minecraft.src.EntityPlayer; -public interface IHoeHandler { - /** Called when a hoe is used on a block. This is called on both sides - * in SMP. - * @return true to consume a use of the hoe and return. - */ - public boolean onUseHoe(ItemStack hoe, EntityPlayer player, World world, - int i, int j, int k); - +public interface IHoeHandler +{ + /** Called when a hoe is used on a block. This is called on both sides + * in SMP. + * @return true to consume a use of the hoe and return. + */ + public boolean onUseHoe(ItemStack hoe, EntityPlayer player, World world, int X, int Y, int Z); } diff --git a/forge/forge_common/net/minecraft/src/forge/IMinecartCollisionHandler.java b/forge/forge_common/net/minecraft/src/forge/IMinecartCollisionHandler.java index 8858be2011..cf4f521816 100644 --- a/forge/forge_common/net/minecraft/src/forge/IMinecartCollisionHandler.java +++ b/forge/forge_common/net/minecraft/src/forge/IMinecartCollisionHandler.java @@ -1,50 +1,50 @@ -package net.minecraft.src.forge; - -import net.minecraft.src.AxisAlignedBB; -import net.minecraft.src.Entity; -import net.minecraft.src.EntityMinecart; - -/** - * This class defines a replacement for the default minecart collision code. - * Only one handler can be registered at a time. It it registered with EntityMinecart.registerCollisionHandler(). - * If you use this, make it a configuration option. - * @author CovertJaguar - */ -public interface IMinecartCollisionHandler -{ - - /** - * This basically replaces the function of the same name in EnityMinecart. - * Code in IMinecartHooks.applyEntityCollisionHook is still run. - * @param cart The cart that called the collision. - * @param other The object it collided with. - */ - public void onEntityCollision(EntityMinecart cart, Entity other); - - /** - * This function replaced the function of the same name in EntityMinecart. - * It is used to define whether minecarts collide with specific entities, - * for example items. - * @param cart The cart for which the collision box was requested. - * @param other The entity requesting the collision box. - * @return The collision box or null. - */ - public AxisAlignedBB getCollisionBox(EntityMinecart cart, Entity other); - - /** - * This function is used to define the box used for detecting minecart collisions. - * It is generally bigger that the normal collision box. - * @param cart The cart for which the collision box was requested. - * @return The collision box, cannot be null. - */ - public AxisAlignedBB getMinecartCollisionBox(EntityMinecart cart); - - /** - * This function replaces the function of the same name in EntityMinecart. - * It defines whether minecarts are solid to the player. - * @param cart The cart for which the bounding box was requested. - * @return The bounding box or null. - */ - public AxisAlignedBB getBoundingBox(EntityMinecart cart); -} - +package net.minecraft.src.forge; + +import net.minecraft.src.AxisAlignedBB; +import net.minecraft.src.Entity; +import net.minecraft.src.EntityMinecart; + +/** + * This class defines a replacement for the default minecart collision code. + * Only one handler can be registered at a time. It it registered with EntityMinecart.registerCollisionHandler(). + * If you use this, make it a configuration option. + * @author CovertJaguar + */ +public interface IMinecartCollisionHandler +{ + + /** + * This basically replaces the function of the same name in EnityMinecart. + * Code in IMinecartHooks.applyEntityCollisionHook is still run. + * @param cart The cart that called the collision. + * @param other The object it collided with. + */ + public void onEntityCollision(EntityMinecart cart, Entity other); + + /** + * This function replaced the function of the same name in EntityMinecart. + * It is used to define whether minecarts collide with specific entities, + * for example items. + * @param cart The cart for which the collision box was requested. + * @param other The entity requesting the collision box. + * @return The collision box or null. + */ + public AxisAlignedBB getCollisionBox(EntityMinecart cart, Entity other); + + /** + * This function is used to define the box used for detecting minecart collisions. + * It is generally bigger that the normal collision box. + * @param cart The cart for which the collision box was requested. + * @return The collision box, cannot be null. + */ + public AxisAlignedBB getMinecartCollisionBox(EntityMinecart cart); + + /** + * This function replaces the function of the same name in EntityMinecart. + * It defines whether minecarts are solid to the player. + * @param cart The cart for which the bounding box was requested. + * @return The bounding box or null. + */ + public AxisAlignedBB getBoundingBox(EntityMinecart cart); +} + diff --git a/forge/forge_common/net/minecraft/src/forge/IMinecartHandler.java b/forge/forge_common/net/minecraft/src/forge/IMinecartHandler.java index 8317904252..0ce53348ac 100644 --- a/forge/forge_common/net/minecraft/src/forge/IMinecartHandler.java +++ b/forge/forge_common/net/minecraft/src/forge/IMinecartHandler.java @@ -1,38 +1,39 @@ -package net.minecraft.src.forge; - -import net.minecraft.src.Entity; -import net.minecraft.src.EntityMinecart; -import net.minecraft.src.EntityPlayer; - -public interface IMinecartHandler { - - /** - * This functions is called at the end of every minecart's doUpdate loop. - * If you override EntityMinecart.doUpdate(), is recommended that you retain the code that calls this function. - * @param cart The cart that called the function. - * @param i X coordinate of the rail - * @param j Y coordinate of the rail - * @param k Z coordinate of the rail - */ - public void onMinecartUpdate(EntityMinecart minecart, int x, int y, int z); - - /** - * This function allows several mods to add code into the collision routine at the same time regardless of the collision handler registered. - * If you override EntityMinecart.applyEntityCollision(), is recommended that you retain the code that calls this function. - * @param cart The cart that called the function. - * @param other - */ - public void onMinecartEntityCollision(EntityMinecart minecart, Entity entity); - - /** - * This function is called whenever a player attempts to interact with a minecart. - * The primary reason for this hook is to fix a few bugs and put restrictions on how a minecart can be used under certain circumstances. - * If you override EntityMinecart.interact(), is recommended that you retain the code that calls this function. - * @param cart The cart that called the function. - * @param player The player that tried to interact with the minecart. - * @param canceled Wither or not a pervious hook has canceled the interaction of a player. - * @return Whether the player can interact with the minecart. - */ - public boolean onMinecartInteract(EntityMinecart minecart, EntityPlayer player, boolean canceled); - -} +package net.minecraft.src.forge; + +import net.minecraft.src.Entity; +import net.minecraft.src.EntityMinecart; +import net.minecraft.src.EntityPlayer; + +public interface IMinecartHandler +{ + + /** + * This functions is called at the end of every minecart's doUpdate loop. + * If you override EntityMinecart.doUpdate(), is recommended that you retain the code that calls this function. + * @param cart The cart that called the function. + * @param i X coordinate of the rail + * @param j Y coordinate of the rail + * @param k Z coordinate of the rail + */ + public void onMinecartUpdate(EntityMinecart minecart, int x, int y, int z); + + /** + * This function allows several mods to add code into the collision routine at the same time regardless of the collision handler registered. + * If you override EntityMinecart.applyEntityCollision(), is recommended that you retain the code that calls this function. + * @param cart The cart that called the function. + * @param other + */ + public void onMinecartEntityCollision(EntityMinecart minecart, Entity entity); + + /** + * This function is called whenever a player attempts to interact with a minecart. + * The primary reason for this hook is to fix a few bugs and put restrictions on how a minecart can be used under certain circumstances. + * If you override EntityMinecart.interact(), is recommended that you retain the code that calls this function. + * @param cart The cart that called the function. + * @param player The player that tried to interact with the minecart. + * @param canceled Wither or not a pervious hook has canceled the interaction of a player. + * @return Whether the player can interact with the minecart. + */ + public boolean onMinecartInteract(EntityMinecart minecart, EntityPlayer player, boolean canceled); + +} diff --git a/forge/forge_common/net/minecraft/src/forge/IMultipassRender.java b/forge/forge_common/net/minecraft/src/forge/IMultipassRender.java index 1f38104562..ff35ad3cb4 100644 --- a/forge/forge_common/net/minecraft/src/forge/IMultipassRender.java +++ b/forge/forge_common/net/minecraft/src/forge/IMultipassRender.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -9,9 +9,10 @@ package net.minecraft.src.forge; * type to perform rendering in both render passes, in case some parts of the * block are solid and others are transparent. */ -public interface IMultipassRender { - /** Returns true when the block has things to render in this render - * pass. - */ - public boolean canRenderInPass(int n); +public interface IMultipassRender +{ + /** Returns true when the block has things to render in this render + * pass. + */ + public boolean canRenderInPass(int pass); } diff --git a/forge/forge_common/net/minecraft/src/forge/IOreHandler.java b/forge/forge_common/net/minecraft/src/forge/IOreHandler.java index aa0e66d57e..088d2f42b0 100644 --- a/forge/forge_common/net/minecraft/src/forge/IOreHandler.java +++ b/forge/forge_common/net/minecraft/src/forge/IOreHandler.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -18,10 +18,11 @@ import net.minecraft.src.ItemStack; * itemRubber */ -public interface IOreHandler { - /** Called when a new ore is registered with the ore dictionary. - * @param oreClass The string class of the ore. - * @param ore The ItemStack for the ore. - */ - public void registerOre(String oreClass, ItemStack ore); +public interface IOreHandler +{ + /** Called when a new ore is registered with the ore dictionary. + * @param oreClass The string class of the ore. + * @param ore The ItemStack for the ore. + */ + public void registerOre(String oreClass, ItemStack ore); } diff --git a/forge/forge_common/net/minecraft/src/forge/IOverrideReplace.java b/forge/forge_common/net/minecraft/src/forge/IOverrideReplace.java index fbfcf8a172..e987a07fc2 100644 --- a/forge/forge_common/net/minecraft/src/forge/IOverrideReplace.java +++ b/forge/forge_common/net/minecraft/src/forge/IOverrideReplace.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -15,17 +15,18 @@ import net.minecraft.src.World; * @see Block * @deprecated. This functionality will be removed soon. */ -public interface IOverrideReplace { - +public interface IOverrideReplace +{ + /** * Return true if this block has to take control over replacement, for * the intended replacement given by the parameter bid. If false, then * the block replacement will be prevented. */ - public boolean canReplaceBlock(World world, int i, int j, int k, int bid); - - /** - * Return the status of the actual replacement. - */ - public boolean getReplacedSuccess(); + public boolean canReplaceBlock(World world, int X, int Y, int Z, int replacement); + + /** + * Return the status of the actual replacement. + */ + public boolean getReplacedSuccess(); } diff --git a/forge/forge_common/net/minecraft/src/forge/IPacketHandler.java b/forge/forge_common/net/minecraft/src/forge/IPacketHandler.java index ac39b17edc..41c1f5dd48 100644 --- a/forge/forge_common/net/minecraft/src/forge/IPacketHandler.java +++ b/forge/forge_common/net/minecraft/src/forge/IPacketHandler.java @@ -2,12 +2,12 @@ package net.minecraft.src.forge; import net.minecraft.src.NetworkManager; -public interface IPacketHandler -{ +public interface IPacketHandler +{ /** - * Called when we receive a Packet250CustomPayload for a channel that this + * Called when we receive a Packet250CustomPayload for a channel that this * handler is registered to. - * + * * @param network The NetworkManager for the current connection. * @param channel The Channel the message came on. * @param data The message payload. diff --git a/forge/forge_common/net/minecraft/src/forge/IPickupHandler.java b/forge/forge_common/net/minecraft/src/forge/IPickupHandler.java index 3f703c3e25..4f005c5a19 100644 --- a/forge/forge_common/net/minecraft/src/forge/IPickupHandler.java +++ b/forge/forge_common/net/minecraft/src/forge/IPickupHandler.java @@ -1,26 +1,26 @@ -package net.minecraft.src.forge; - -import net.minecraft.src.EntityItem; -import net.minecraft.src.EntityPlayer; -import net.minecraft.src.ItemStack; - -public interface IPickupHandler -{ - - /** - * Raised when a player collides with a EntityItem. - * The handler may consume all, or part of the stack. - * The handler will only be called if the stack size is > 0 - * The event may be cut part way through if the stack size - * falls to 0 or a previous handler returns false; - * Will only be called if delay before pickup is 0. - * - * The Entity will destroyed if the stack size falls to 0. - * - * @param player Player that picked up the item - * @param item Item picked up as entity. May be manipulated - * @return True If processing should continue. - */ - public boolean onItemPickup(EntityPlayer player, EntityItem item); - +package net.minecraft.src.forge; + +import net.minecraft.src.EntityItem; +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.ItemStack; + +public interface IPickupHandler +{ + + /** + * Raised when a player collides with a EntityItem. + * The handler may consume all, or part of the stack. + * The handler will only be called if the stack size is > 0 + * The event may be cut part way through if the stack size + * falls to 0 or a previous handler returns false; + * Will only be called if delay before pickup is 0. + * + * The Entity will destroyed if the stack size falls to 0. + * + * @param player Player that picked up the item + * @param item Item picked up as entity. May be manipulated + * @return True If processing should continue. + */ + public boolean onItemPickup(EntityPlayer player, EntityItem item); + } \ No newline at end of file diff --git a/forge/forge_common/net/minecraft/src/forge/IShearable.java b/forge/forge_common/net/minecraft/src/forge/IShearable.java index b65631be44..1a3243e702 100644 --- a/forge/forge_common/net/minecraft/src/forge/IShearable.java +++ b/forge/forge_common/net/minecraft/src/forge/IShearable.java @@ -1,53 +1,53 @@ -package net.minecraft.src.forge; - -import java.util.ArrayList; - -import net.minecraft.src.EntityPlayer; -import net.minecraft.src.ItemStack; -import net.minecraft.src.MovingObjectPosition; -import net.minecraft.src.World; - -/** - * - * This allows for mods to create there own Shear-like items - * and have them interact with Blocks/Entities without extra work. - * Also, if your block/entity supports the Shears, this allows you - * to support mod-shears as well. - * - */ -public interface IShearable -{ - /** - * Checks if the object is currently shearable - * Example: Sheep return false when they have no wool - * - * @param item The itemstack that is being used, Possible to be null - * @param world The current world - * @param X The X Position - * @param Y The Y Position - * @param Z The Z Position - * @return If this is shearable, and onSheared should be called. - */ - public boolean isShearable(ItemStack item, World world, int X, int Y, int Z); - - /** - * Performs the shear function on this object. - * This is called for both client, and server. - * The object should perform all actions related to being sheared, - * except for dropping of the items. - * - * Returns a list of items that resulted from the shearing process. - * - * For entities, they should trust there internal location information - * over the values passed into this function. - * - * @param item The itemstack that is being used, Possible to be null - * @param world The current world - * @param X The X Position - * @param Y The Y Position - * @param Z The Z Position - * @param fortune The fortune level of the shears being used - * @return A ArrayList containing all items from this shearing. Possible to be null. - */ - public ArrayList onSheared(ItemStack item, World world, int X, int Y, int Z, int fortune); -} +package net.minecraft.src.forge; + +import java.util.ArrayList; + +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.ItemStack; +import net.minecraft.src.MovingObjectPosition; +import net.minecraft.src.World; + +/** + * + * This allows for mods to create there own Shear-like items + * and have them interact with Blocks/Entities without extra work. + * Also, if your block/entity supports the Shears, this allows you + * to support mod-shears as well. + * + */ +public interface IShearable +{ + /** + * Checks if the object is currently shearable + * Example: Sheep return false when they have no wool + * + * @param item The itemstack that is being used, Possible to be null + * @param world The current world + * @param X The X Position + * @param Y The Y Position + * @param Z The Z Position + * @return If this is shearable, and onSheared should be called. + */ + public boolean isShearable(ItemStack item, World world, int X, int Y, int Z); + + /** + * Performs the shear function on this object. + * This is called for both client, and server. + * The object should perform all actions related to being sheared, + * except for dropping of the items. + * + * Returns a list of items that resulted from the shearing process. + * + * For entities, they should trust there internal location information + * over the values passed into this function. + * + * @param item The itemstack that is being used, Possible to be null + * @param world The current world + * @param X The X Position + * @param Y The Y Position + * @param Z The Z Position + * @param fortune The fortune level of the shears being used + * @return A ArrayList containing all items from this shearing. Possible to be null. + */ + public ArrayList onSheared(ItemStack item, World world, int X, int Y, int Z, int fortune); +} diff --git a/forge/forge_common/net/minecraft/src/forge/ISidedInventory.java b/forge/forge_common/net/minecraft/src/forge/ISidedInventory.java index 0afb2d3065..247ba82db4 100644 --- a/forge/forge_common/net/minecraft/src/forge/ISidedInventory.java +++ b/forge/forge_common/net/minecraft/src/forge/ISidedInventory.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -10,24 +10,25 @@ import net.minecraft.src.IInventory; /** Inventory ranges mapped by side. This class is implemented by TileEntities * that provide different inventory slot ranges to different sides. */ -public interface ISidedInventory extends IInventory { +public interface ISidedInventory extends IInventory +{ - /** - * Get the start of the side inventory. - * @param side The global side to get the start of range. - * 0: -Y (bottom side) - * 1: +Y (top side) - * 2: -Z - * 3: +Z - * 4: -X - * 5: +x - */ - int getStartInventorySide(int side); + /** + * Get the start of the side inventory. + * @param side The global side to get the start of range. + * 0: -Y (bottom side) + * 1: +Y (top side) + * 2: -Z + * 3: +Z + * 4: -X + * 5: +x + */ + int getStartInventorySide(int side); - /** - * Get the size of the side inventory. - * @param side The global side. - */ - int getSizeInventorySide(int side); + /** + * Get the size of the side inventory. + * @param side The global side. + */ + int getSizeInventorySide(int side); } diff --git a/forge/forge_common/net/minecraft/src/forge/ISleepHandler.java b/forge/forge_common/net/minecraft/src/forge/ISleepHandler.java index abaf2ce31a..f99aaf4dca 100644 --- a/forge/forge_common/net/minecraft/src/forge/ISleepHandler.java +++ b/forge/forge_common/net/minecraft/src/forge/ISleepHandler.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -8,7 +8,8 @@ package net.minecraft.src.forge; import net.minecraft.src.EntityPlayer; import net.minecraft.src.EnumStatus; -public interface ISleepHandler { +public interface ISleepHandler +{ /** * This is called before a player sleeps in a bed. If it returns a * non-null result, then the normal sleeping process will be skipped, and @@ -17,6 +18,6 @@ public interface ISleepHandler { * * @see MinecraftForge#registerSleepHandler(ISleepHandler) */ - public EnumStatus sleepInBedAt(EntityPlayer player, int i, int j, int k); + public EnumStatus sleepInBedAt(EntityPlayer player, int X, int Y, int Z); } diff --git a/forge/forge_common/net/minecraft/src/forge/ISpawnHandler.java b/forge/forge_common/net/minecraft/src/forge/ISpawnHandler.java index d902d675a3..291512de42 100644 --- a/forge/forge_common/net/minecraft/src/forge/ISpawnHandler.java +++ b/forge/forge_common/net/minecraft/src/forge/ISpawnHandler.java @@ -1,27 +1,27 @@ -package net.minecraft.src.forge; - -import java.io.DataInputStream; -import java.io.DataOutputStream; - -/** - * A interface for Entities that need extra information to be communicated - * between the server and client when they are spawned. - */ -public interface ISpawnHandler -{ - /** - * Called by the server when constructing the spawn packet. - * Data should be added to the provided stream. - * - * @param data The packet data stream - */ - public void writeSpawnData(DataOutputStream data); - - /** - * Called by the client when it receives a Entity spawn packet. - * Data should be read out of the stream in the same way as it was written. - * - * @param data The packet data stream - */ - public void readSpawnData(DataInputStream data); -} +package net.minecraft.src.forge; + +import java.io.DataInputStream; +import java.io.DataOutputStream; + +/** + * A interface for Entities that need extra information to be communicated + * between the server and client when they are spawned. + */ +public interface ISpawnHandler +{ + /** + * Called by the server when constructing the spawn packet. + * Data should be added to the provided stream. + * + * @param data The packet data stream + */ + public void writeSpawnData(DataOutputStream data); + + /** + * Called by the client when it receives a Entity spawn packet. + * Data should be read out of the stream in the same way as it was written. + * + * @param data The packet data stream + */ + public void readSpawnData(DataInputStream data); +} diff --git a/forge/forge_common/net/minecraft/src/forge/ISpecialArmor.java b/forge/forge_common/net/minecraft/src/forge/ISpecialArmor.java index 62f9cccfc1..7f5e1d3894 100755 --- a/forge/forge_common/net/minecraft/src/forge/ISpecialArmor.java +++ b/forge/forge_common/net/minecraft/src/forge/ISpecialArmor.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -18,47 +18,47 @@ import net.minecraft.src.ItemStack; * * @see ItemArmor */ -public interface ISpecialArmor +public interface ISpecialArmor { - /** + /** * Retrieves the modifiers to be used when calculating armor damage. - * + * * Armor will higher priority will have damage applied to them before * lower priority ones. If there are multiple pieces of armor with the * same priority, damage will be distributed between them based on there * absorption ratio. * * @param entity The entity wearing the armor. - * @param armor The ItemStack of the armor item itself. - * @param source The source of the damage, which can be used to alter armor - * properties based on the type or source of damage. - * @param damage The total damage being applied to the entity - * @param slot The armor slot the item is in. - * @return A ArmorProperties instance holding information about how the armor effects damage. - */ - public ArmorProperties getProperties(EntityLiving player, ItemStack armor, DamageSource source, double damage, int slot); - - /** - * Get the displayed effective armor. - * - * @param player The player wearing the armor. - * @param armor The ItemStack of the armor item itself. - * @param slot The armor slot the item is in. - * @return The number of armor points for display, 2 per shield. - */ - public abstract int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot); - - /** - * Applies damage to the ItemStack. The mod is responsible for reducing the - * item durability and stack size. If the stack is depleted it will be cleaned - * up automatically. - * - * @param entity The entity wearing the armor * @param armor The ItemStack of the armor item itself. * @param source The source of the damage, which can be used to alter armor * properties based on the type or source of damage. - * @param damage The amount of damage being applied to the armor + * @param damage The total damage being applied to the entity * @param slot The armor slot the item is in. - */ + * @return A ArmorProperties instance holding information about how the armor effects damage. + */ + public ArmorProperties getProperties(EntityLiving player, ItemStack armor, DamageSource source, double damage, int slot); + + /** + * Get the displayed effective armor. + * + * @param player The player wearing the armor. + * @param armor The ItemStack of the armor item itself. + * @param slot The armor slot the item is in. + * @return The number of armor points for display, 2 per shield. + */ + public abstract int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot); + + /** + * Applies damage to the ItemStack. The mod is responsible for reducing the + * item durability and stack size. If the stack is depleted it will be cleaned + * up automatically. + * + * @param entity The entity wearing the armor + * @param armor The ItemStack of the armor item itself. + * @param source The source of the damage, which can be used to alter armor + * properties based on the type or source of damage. + * @param damage The amount of damage being applied to the armor + * @param slot The armor slot the item is in. + */ public abstract void damageArmor(EntityLiving entity, ItemStack stack, DamageSource source, int damage, int slot); } diff --git a/forge/forge_common/net/minecraft/src/forge/ISpecialResistance.java b/forge/forge_common/net/minecraft/src/forge/ISpecialResistance.java index 971bacb47f..97547292df 100644 --- a/forge/forge_common/net/minecraft/src/forge/ISpecialResistance.java +++ b/forge/forge_common/net/minecraft/src/forge/ISpecialResistance.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -15,12 +15,12 @@ import net.minecraft.src.World; * * @see Block */ -public interface ISpecialResistance { - +public interface ISpecialResistance +{ + /** - * Return the explosion resistance of the block located at position i, j, - * k, from an exploder explosing on src_x, src_y, src_z. + * Return the explosion resistance of the block located at position X, Y, + * Z, from an exploder explosing on srcX, srcY, srcZ. */ - public float getSpecialExplosionResistance(World world, int i, int j, int k, - double src_x, double src_y, double src_z, Entity exploder); + public float getSpecialExplosionResistance(World world, int X, int Y, int Z, double srcX, double srcY, double srcZ, Entity exploder); } diff --git a/forge/forge_common/net/minecraft/src/forge/ITextureProvider.java b/forge/forge_common/net/minecraft/src/forge/ITextureProvider.java index 00ca569e62..d5184cf396 100755 --- a/forge/forge_common/net/minecraft/src/forge/ITextureProvider.java +++ b/forge/forge_common/net/minecraft/src/forge/ITextureProvider.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -9,7 +9,8 @@ package net.minecraft.src.forge; * This interface has to be implemented either by an instance of Block or Item. * It allow to use texture files different from terrain.png or items.png. */ -public interface ITextureProvider { +public interface ITextureProvider +{ /** * This interface has to return the path to a file that is the same size as diff --git a/forge/forge_common/net/minecraft/src/forge/IThrowableEntity.java b/forge/forge_common/net/minecraft/src/forge/IThrowableEntity.java index bb54bdebc5..e24b540d97 100644 --- a/forge/forge_common/net/minecraft/src/forge/IThrowableEntity.java +++ b/forge/forge_common/net/minecraft/src/forge/IThrowableEntity.java @@ -1,22 +1,22 @@ -package net.minecraft.src.forge; - -import net.minecraft.src.Entity; - -/** - * This interface should be implemented by an Entity that can be 'thrown', like snowballs. - * This was created to mimic ModLoaderMP's 'owner' functionality. - */ -public interface IThrowableEntity -{ - /** - * Gets the entity that threw/created this entity. - * @return The owner instance, Null if none. - */ - public Entity getThrower(); - - /** - * Sets the entity that threw/created this entity. - * @param entity The new thrower/creator. - */ - public void setThrower(Entity entity); -} +package net.minecraft.src.forge; + +import net.minecraft.src.Entity; + +/** + * This interface should be implemented by an Entity that can be 'thrown', like snowballs. + * This was created to mimic ModLoaderMP's 'owner' functionality. + */ +public interface IThrowableEntity +{ + /** + * Gets the entity that threw/created this entity. + * @return The owner instance, Null if none. + */ + public Entity getThrower(); + + /** + * Sets the entity that threw/created this entity. + * @param entity The new thrower/creator. + */ + public void setThrower(Entity entity); +} diff --git a/forge/forge_common/net/minecraft/src/forge/MessageManager.java b/forge/forge_common/net/minecraft/src/forge/MessageManager.java index f4b0df35ff..f18b2862b8 100644 --- a/forge/forge_common/net/minecraft/src/forge/MessageManager.java +++ b/forge/forge_common/net/minecraft/src/forge/MessageManager.java @@ -7,11 +7,11 @@ import java.util.Map.Entry; import net.minecraft.src.NetworkManager; -public class MessageManager +public class MessageManager { private Hashtable connections = new Hashtable(); private static MessageManager instance; - + public static MessageManager getInstance() { if (instance == null) @@ -20,19 +20,19 @@ public class MessageManager } return instance; } - + public class ConnectionInstance { private NetworkManager network; private Hashtable> channelToHandlers = new Hashtable>(); private Hashtable> handlerToChannels = new Hashtable>(); private HashSet activeChannels = new HashSet(); - + public ConnectionInstance(NetworkManager mgr) { network = mgr; } - + /** * Retrieves the associated NetworkManager * @return The associated NetworkManager; @@ -41,11 +41,11 @@ public class MessageManager { return network; } - + /** * Removes all channels and handlers from the registration. - * - * @return An array of channels that were in the registration + * + * @return An array of channels that were in the registration * If the connection is still active, you should send UNREGISTER messages for these. */ public String[] unregisterAll() @@ -58,32 +58,32 @@ public class MessageManager /** * Registers a channel to a specific handler. - * + * * @param handler The handler to register * @param channel The channel to register on * @return True if the channel was not previously registered to any handlers. * If True, the connection is still active, and this is not the OnLogin event, * you should send a REGISTER command for this channel. */ - public boolean registerChannel(IPacketHandler handler, String channel) + public boolean registerChannel(IPacketHandler handler, String channel) { ArrayList handlers = channelToHandlers.get(channel); ArrayList channels = handlerToChannels.get(handler); - boolean ret = false; - + boolean ret = false; + if (handlers == null) { ret = true; handlers = new ArrayList(); channelToHandlers.put(channel, handlers); } - + if (channels == null) { channels = new ArrayList(); handlerToChannels.put(handler, channels); } - + if (!channels.contains(channel)) { channels.add(channel); @@ -94,17 +94,17 @@ public class MessageManager } return ret; } - + /** * Unregisters a channel from the specified handler. - * + * * @param handler The handler to remove the channel from. * @param channel The channel to remove from the handler registration. * @return True if this was the last handler registered with the specified channel. * If this is the case, and the network connection is still alive, you should send * a UNREGISTER message for this channel. */ - public boolean unregisterChannel(IPacketHandler handler, String channel) + public boolean unregisterChannel(IPacketHandler handler, String channel) { boolean ret = false; ArrayList handlers = channelToHandlers.get(channel); @@ -119,7 +119,7 @@ public class MessageManager channelToHandlers.remove(channel); } } - + if (channels != null && channels.contains(channel)) { channels.remove(channel); @@ -128,26 +128,26 @@ public class MessageManager handlerToChannels.remove(handler); } } - + return ret; } /** * Unregisters a handler from all of it's associated channels. - * + * * @param handler The handler to unregister * @return A list of channels that now have no handlers. - * If the connection is still active, you should send a UNREGISTER + * If the connection is still active, you should send a UNREGISTER * message for each channel in this list. */ - public String[] unregisterHandler(IPacketHandler handler) + public String[] unregisterHandler(IPacketHandler handler) { ArrayList tmp = handlerToChannels.get(handler); if (tmp != null) { String[] channels = tmp.toArray(new String[0]); tmp = new ArrayList(); - + for (String channel : channels) { if (unregisterChannel(handler, channel)) @@ -162,14 +162,14 @@ public class MessageManager /** * Retrieves a list of all unique channels that currently have valid handlers. - * + * * @return The channel list */ - public String[] getRegisteredChannels() + public String[] getRegisteredChannels() { int x = 0; String[] ret = new String[channelToHandlers.size()]; - + for (String value : channelToHandlers.keySet()) { ret[x++] = value; @@ -179,7 +179,7 @@ public class MessageManager /** * Retrieves a list of all handlers currently registered to the specified channel. - * + * * @param channel The channel to get the handlers for. * @return A array containing all handlers for this channel. */ @@ -192,11 +192,11 @@ public class MessageManager } return new IPacketHandler[0]; } - + /** * Adds a channel to the active set. * This is a set that the other end of the connection has registered a channel. - * + * * @param channel The channel name */ public void addActiveChannel(String channel) @@ -206,11 +206,11 @@ public class MessageManager activeChannels.add(channel); } } - + /** * Removes a channel from the active set. * This should be done with the other end of the connection unregisters a channel. - * + * * @param channel */ public void removeActiveChannel(String channel) @@ -220,10 +220,10 @@ public class MessageManager activeChannels.remove(channel); } } - + /** * Checks if the specified channel is registered as active by the other end of the connection. - * + * * @param channel The channel to check * @return True if it's active, false otherwise. */ @@ -232,10 +232,10 @@ public class MessageManager return activeChannels.contains(channel); } } - + /** * Retrieves, or creates a ConnectionInstance associated with the specific NetworkManager. - * + * * @param manager The NetworkManager to look for. * @return A ConnectionInstance channel manager for this NetworkManager */ @@ -249,13 +249,13 @@ public class MessageManager } return ret; } - + /** * Removes the associated channel manager, and unregisters all channels/handlers from it. - * + * * @param manager The NetworkManager to look for. * @return An array of all channels that were still registered to this NetowrkManager. - * If the connection is still active, you should send a UNREGISTER request for + * If the connection is still active, you should send a UNREGISTER request for * all of these channels. */ public String[] removeConnection(NetworkManager manager) @@ -269,10 +269,10 @@ public class MessageManager } return new String[0]; } - + /** * Registers a channel to a specific handler. - * + * * @param manager The manager to register to * @param handler The handler to register * @param channel The channel to register on @@ -288,7 +288,7 @@ public class MessageManager /** * Unregisters a channel from the specified handler. - * + * * @param manager The manager to register to * @param handler The handler to remove the channel from. * @param channel The channel to remove from the handler registration. @@ -308,11 +308,11 @@ public class MessageManager /** * Unregisters a handler from all of it's associated channels. - * + * * @param manager The manager to register to * @param handler The handler to unregister * @return A list of channels that now have no handlers. - * If the connection is still active, you should send a UNREGISTER + * If the connection is still active, you should send a UNREGISTER * message for each channel in this list. */ public String[] unregisterHandler(NetworkManager manager, IPacketHandler handler) @@ -327,7 +327,7 @@ public class MessageManager /** * Retrieves a list of all unique channels that currently have valid handlers. - * + * * @param manager The NetworkManager to look for. * @return The channel list */ @@ -343,7 +343,7 @@ public class MessageManager /** * Retrieves a list of all handlers currently registered to the specified channel. - * + * * @param manager The NetworkManager to look for. * @param channel The channel to get the handlers for. * @return A array containing all handlers for this channel. @@ -357,11 +357,11 @@ public class MessageManager } return new IPacketHandler[0]; } - + /** * Adds a channel to the active set. * This is a set that the other end of the connection has registered a channel. - * + * * @param manager The NetworkManager to look for. * @param channel The channel name */ @@ -370,11 +370,11 @@ public class MessageManager ConnectionInstance con = getConnection(manager); con.addActiveChannel(channel); } - + /** * Removes a channel from the active set. * This should be done with the other end of the connection unregisters a channel. - * + * * @param manager The NetworkManager to look for. * @param channel */ @@ -386,10 +386,10 @@ public class MessageManager con.removeActiveChannel(channel); } } - + /** * Checks if the specified channel is registered as active by the other end of the connection. - * + * * @param manager The NetworkManager to look for. * @param channel The channel to check * @return True if it's active, false otherwise. @@ -404,7 +404,7 @@ public class MessageManager return false; } - public void dispatchIncomingMessage(NetworkManager manager, String channel, byte[] data) + public void dispatchIncomingMessage(NetworkManager manager, String channel, byte[] data) { if (channel.equals("Forge")) { @@ -415,7 +415,7 @@ public class MessageManager ForgeHooks.getPacketHandler().onPacketData(manager, channel, tmpData); } } - + if (connections.contains(manager)) { ConnectionInstance con = getConnection(manager); @@ -425,7 +425,7 @@ public class MessageManager { System.arraycopy(data, 0, tmpData, 0, data.length); handler.onPacketData(manager, channel, tmpData); - } + } } } } diff --git a/forge/forge_common/net/minecraft/src/forge/MinecartKey.java b/forge/forge_common/net/minecraft/src/forge/MinecartKey.java index 35b23da489..9ba6c6f977 100644 --- a/forge/forge_common/net/minecraft/src/forge/MinecartKey.java +++ b/forge/forge_common/net/minecraft/src/forge/MinecartKey.java @@ -1,49 +1,50 @@ -package net.minecraft.src.forge; - -import net.minecraft.src.EntityMinecart; - -/** - * Used to create hashmap values for Minecart/type pairs - * Written by CovertJaguar - */ -public class MinecartKey { - public final Class minecart; - public final int type; - - public MinecartKey(Class c, int t) - { - minecart = c; - type = t; - } - - @Override - public boolean equals(Object obj) - { - if(obj == null) - { - return false; - } - - if(getClass() != obj.getClass()) - { - return false; - } - - final MinecartKey other = (MinecartKey)obj; - if(this.minecart != other.minecart && (this.minecart == null || !this.minecart.equals(other.minecart))) - { - return false; - } - - return (this.type == other.type); - } - - @Override - public int hashCode() - { - int hash = 7; - hash = 59 * hash + (this.minecart != null ? this.minecart.hashCode() : 0); - hash = 59 * hash + this.type; - return hash; - } -} +package net.minecraft.src.forge; + +import net.minecraft.src.EntityMinecart; + +/** + * Used to create hashmap values for Minecart/type pairs + * Written by CovertJaguar + */ +public class MinecartKey +{ + public final Class minecart; + public final int type; + + public MinecartKey(Class cls, int typtID) + { + minecart = cls; + type = typtID; + } + + @Override + public boolean equals(Object obj) + { + if (obj == null) + { + return false; + } + + if (getClass() != obj.getClass()) + { + return false; + } + + final MinecartKey other = (MinecartKey)obj; + if (this.minecart != other.minecart && (this.minecart == null || !this.minecart.equals(other.minecart))) + { + return false; + } + + return (this.type == other.type); + } + + @Override + public int hashCode() + { + int hash = 7; + hash = 59 * hash + (this.minecart != null ? this.minecart.hashCode() : 0); + hash = 59 * hash + this.type; + return hash; + } +} diff --git a/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java b/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java index 1ac86308ec..374102351d 100755 --- a/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java +++ b/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java @@ -1,5 +1,5 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ @@ -17,15 +17,15 @@ import net.minecraft.src.World; import java.util.*; import java.util.Map.Entry; -public class MinecraftForge { - +public class MinecraftForge +{ private static LinkedList bucketHandlers = new LinkedList(); - + /** * Register a new custom bucket handler. * @param handler The Handler to be registered */ - public static void registerCustomBucketHandler(IBucketHandler handler) + public static void registerCustomBucketHandler(IBucketHandler handler) { bucketHandlers.add(handler); } @@ -34,7 +34,7 @@ public class MinecraftForge { * Registers a new sleeping handler. * @param handler The Handler to be registered */ - public static void registerSleepHandler(ISleepHandler handler) + public static void registerSleepHandler(ISleepHandler handler) { ForgeHooks.sleepHandlers.add(handler); } @@ -43,7 +43,7 @@ public class MinecraftForge { * Registers a new bonemeal handler. * @param handler The Handler to be registered */ - public static void registerBonemealHandler(IBonemealHandler handler) + public static void registerBonemealHandler(IBonemealHandler handler) { ForgeHooks.bonemealHandlers.add(handler); } @@ -52,7 +52,7 @@ public class MinecraftForge { * Registers a new hoe handler. * @param handler The Handler to be registered */ - public static void registerHoeHandler(IHoeHandler handler) + public static void registerHoeHandler(IHoeHandler handler) { ForgeHooks.hoeHandlers.add(handler); } @@ -61,7 +61,7 @@ public class MinecraftForge { * Registers a new destroy tool handler. * @param handler The Handler to be registered */ - public static void registerDestroyToolHandler(IDestroyToolHandler handler) + public static void registerDestroyToolHandler(IDestroyToolHandler handler) { ForgeHooks.destroyToolHandlers.add(handler); } @@ -74,16 +74,16 @@ public class MinecraftForge { { ForgeHooks.craftingHandlers.add(handler); } - + /** * Registers a new minecart handler * @param handler The Handler to be registered */ public static void registerMinecartHandler(IMinecartHandler handler) { - ForgeHooks.minecartHandlers.add(handler); + ForgeHooks.minecartHandlers.add(handler); } - + /** * Registers a new Connection event handler * @param handler The Handler to be registered @@ -105,11 +105,14 @@ public class MinecraftForge { /** * This is not supposed to be called outside of Minecraft internals. */ - public static ItemStack fillCustomBucket(World w, int i, int j, int k) { - for (IBucketHandler handler : bucketHandlers) { - ItemStack stack = handler.fillCustomBucket(w, i, j, k); + public static ItemStack fillCustomBucket(World world, int X, int Y, int Z) + { + for (IBucketHandler handler : bucketHandlers) + { + ItemStack stack = handler.fillCustomBucket(world, X, Y, Z); - if (stack != null) { + if (stack != null) + { return stack; } } @@ -120,189 +123,219 @@ public class MinecraftForge { // Ore Dictionary // ------------------------------------------------------------ private static LinkedList oreHandlers = new LinkedList(); - private static TreeMap> oreDict= - new TreeMap>(); + private static TreeMap> oreDict = new TreeMap>(); /** Register a new ore handler. This will automatically call the handler * with all current ores during registration, and every time a new ore is * added later. */ - public static void registerOreHandler(IOreHandler handler) { - oreHandlers.add(handler); + public static void registerOreHandler(IOreHandler handler) + { + oreHandlers.add(handler); - for(String key : oreDict.keySet()) { - List val=oreDict.get(key); - for(ItemStack ist : val) { - handler.registerOre(key,ist); - } - } + for (String key : oreDict.keySet()) + { + List ores = oreDict.get(key); + for (ItemStack stack : ores) + { + handler.registerOre(key, stack); + } + } } /** Register a new item with the ore dictionary. * @param oreClass The string class of the ore. * @param ore The ItemStack for the ore. */ - public static void registerOre(String oreClass, ItemStack ore) { - List orelist=oreDict.get(oreClass); - if(orelist==null) { - orelist=new ArrayList(); - oreDict.put(oreClass,orelist); - } - orelist.add(ore); - for(IOreHandler ioh : oreHandlers) { - ioh.registerOre(oreClass,ore); - } + public static void registerOre(String oreClass, ItemStack ore) + { + List orelist = oreDict.get(oreClass); + if (orelist == null) + { + orelist = new ArrayList(); + oreDict.put(oreClass, orelist); + } + orelist.add(ore); + for (IOreHandler ioh : oreHandlers) + { + ioh.registerOre(oreClass, ore); + } } /** Get the list of ores in a given class. */ - public static List getOreClass(String oreClass) { - return oreDict.get(oreClass); + public static List getOreClass(String oreClass) + { + return oreDict.get(oreClass); } - public static class OreQuery implements Iterable { - Object[] proto; + public static class OreQuery implements Iterable + { + Object[] proto; - public class OreQueryIterator implements Iterator { - LinkedList itering; - LinkedList output; + public class OreQueryIterator implements Iterator + { + LinkedList itering; + LinkedList output; - private OreQueryIterator() { - itering=new LinkedList(); - output=new LinkedList(); + private OreQueryIterator() + { + itering = new LinkedList(); + output = new LinkedList(); - for(int i=0; i iterator() { - return new OreQueryIterator(); - } + public Iterator iterator() + { + return new OreQueryIterator(); + } } /** Generate all valid legal recipe combinations. Any Lists in pattern * will be fully expanded to all valid combinations. */ - public static OreQuery generateRecipes(Object... pattern) { - return new OreQuery(pattern); + public static OreQuery generateRecipes(Object... pattern) + { + return new OreQuery(pattern); } // ------------------------------------------------------------ /** Register a new plant to be planted when bonemeal is used on grass. * @param bid The block ID to plant. - * @param md The metadata to plant. - * @param prop The relative probability of the plant, where red flowers are + * @param metadata The metadata to plant. + * @param probability The relative probability of the plant, where red flowers are * 10 and yellow flowers are 20. */ - public static void addGrassPlant(int item, int md, int prop) { - ForgeHooks.addPlantGrass(item,md,prop); + public static void addGrassPlant(int blockID, int metadata, int probability) + { + ForgeHooks.addPlantGrass(blockID, metadata, probability); } /** Register a new seed to be dropped when breaking tall grass. * @param bid The item ID of the seeds. - * @param md The metadata of the seeds. - * @param qty The quantity of seeds to drop. - * @param prop The relative probability of the seeds, where wheat seeds are + * @param metadata The metadata of the seeds. + * @param quantity The quantity of seeds to drop. + * @param probability The relative probability of the seeds, where wheat seeds are * 10. */ - public static void addGrassSeed(int item, int md, int qty, int prop) { - ForgeHooks.addGrassSeed(item,md,qty,prop); + public static void addGrassSeed(int itemID, int metadata, int quantity, int probability) + { + ForgeHooks.addGrassSeed(itemID, metadata, quantity, probability); } /** Register a tool as a tool class with a given harvest level. * * @param tool The custom tool to register. - * @param tclass The tool class to register as. The predefined tool + * @param toolClass The tool class to register as. The predefined tool * clases are "pickaxe", "shovel", "axe". You can add others for custom * tools. - * @param hlevel The harvest level of the tool. + * @param harvestLevel The harvest level of the tool. */ - public static void setToolClass(Item tool, String tclass, int hlevel) { - ForgeHooks.initTools(); - ForgeHooks.toolClasses.put(tool.shiftedIndex, - Arrays.asList(tclass,hlevel)); + public static void setToolClass(Item tool, String toolClass, int harvestLevel) + { + ForgeHooks.initTools(); + ForgeHooks.toolClasses.put(tool.shiftedIndex, Arrays.asList(toolClass, harvestLevel)); } /** Register a block to be harvested by a tool class. This is the metadata * sensitive version, use it if your blocks are using metadata variants. * By default, this sets the block class as effective against that type. * - * @param bl The block to register. - * @param md The metadata for the block subtype. - * @param tclass The tool class to register as able to remove this block. + * @param block The block to register. + * @param metadata The metadata for the block subtype. + * @param toolClass The tool class to register as able to remove this block. * You may register the same block multiple times with different tool * classes, if multiple tool types can be used to harvest this block. - * @param hlevel The minimum tool harvest level required to successfully + * @param harvestLevel The minimum tool harvest level required to successfully * harvest the block. * @see setToolClass for details on tool classes. */ - public static void setBlockHarvestLevel(Block bl, int md, String tclass, - int hlevel) { - ForgeHooks.initTools(); - List key=Arrays.asList(bl.blockID,md,tclass); - ForgeHooks.toolHarvestLevels.put(key,hlevel); - ForgeHooks.toolEffectiveness.add(key); + public static void setBlockHarvestLevel(Block block, int metadata, String toolClass, int harvestLevel) + { + ForgeHooks.initTools(); + List key = Arrays.asList(block.blockID, metadata, toolClass); + ForgeHooks.toolHarvestLevels.put(key, harvestLevel); + ForgeHooks.toolEffectiveness.add(key); } /** Remove a block effectiveness mapping. Since setBlockHarvestLevel @@ -310,37 +343,38 @@ public class MinecraftForge { * used to remove that mapping. This will force a block to be harvested at * the same speed regardless of tool quality, while still requiring a given * harvesting level. - * @param bl The block to remove effectiveness from. - * @param md The metadata for the block subtype. - * @param tclass The tool class to remove the effectiveness mapping from. + * @param block The block to remove effectiveness from. + * @param metadata The metadata for the block subtype. + * @param toolClass The tool class to remove the effectiveness mapping from. * @see setToolClass for details on tool classes. */ - public static void removeBlockEffectiveness(Block bl, int md, - String tclass) { - ForgeHooks.initTools(); - List key=Arrays.asList(bl.blockID,md,tclass); - ForgeHooks.toolEffectiveness.remove(key); + public static void removeBlockEffectiveness(Block block, int metadata, String toolClass) + { + ForgeHooks.initTools(); + List key = Arrays.asList(block.blockID, metadata, toolClass); + ForgeHooks.toolEffectiveness.remove(key); } /** Register a block to be harvested by a tool class. * By default, this sets the block class as effective against that type. * - * @param bl The block to register. - * @param tclass The tool class to register as able to remove this block. + * @param block The block to register. + * @param toolClass The tool class to register as able to remove this block. * You may register the same block multiple times with different tool * classes, if multiple tool types can be used to harvest this block. - * @param hlevel The minimum tool harvest level required to successfully + * @param harvestLevel The minimum tool harvest level required to successfully * harvest the block. * @see setToolClass for details on tool classes. */ - public static void setBlockHarvestLevel(Block bl, String tclass, - int hlevel) { - ForgeHooks.initTools(); - for(int md=0; md<16; md++) { - List key=Arrays.asList(bl.blockID,md,tclass); - ForgeHooks.toolHarvestLevels.put(key,hlevel); - ForgeHooks.toolEffectiveness.add(key); - } + public static void setBlockHarvestLevel(Block block, String toolClass, int harvestLevel) + { + ForgeHooks.initTools(); + for (int metadata = 0; metadata < 16; metadata++) + { + List key = Arrays.asList(block.blockID, metadata, toolClass); + ForgeHooks.toolHarvestLevels.put(key, harvestLevel); + ForgeHooks.toolEffectiveness.add(key); + } } /** Remove a block effectiveness mapping. Since setBlockHarvestLevel @@ -348,23 +382,26 @@ public class MinecraftForge { * used to remove that mapping. This will force a block to be harvested at * the same speed regardless of tool quality, while still requiring a given * harvesting level. - * @param bl The block to remove effectiveness from. - * @param tclass The tool class to remove the effectiveness mapping from. + * @param block The block to remove effectiveness from. + * @param toolClass The tool class to remove the effectiveness mapping from. * @see setToolClass for details on tool classes. */ - public static void removeBlockEffectiveness(Block bl, String tclass) { - ForgeHooks.initTools(); - for(int md=0; md<16; md++) { - List key=Arrays.asList(bl.blockID,md,tclass); - ForgeHooks.toolEffectiveness.remove(key); - } + public static void removeBlockEffectiveness(Block block, String toolClass) + { + ForgeHooks.initTools(); + for (int metadata = 0; metadata < 16; metadata++) + { + List key = Arrays.asList(block.blockID, metadata, toolClass); + ForgeHooks.toolEffectiveness.remove(key); + } } /** * Kill minecraft with an error message. */ - public static void killMinecraft(String modname, String msg) { - throw new RuntimeException(modname+": "+msg); + public static void killMinecraft(String mod, String message) + { + throw new RuntimeException(mod + ": " + message); } /** @@ -373,54 +410,62 @@ public class MinecraftForge { * mismatch or if the version is too old. Will print a warning message if * the minor versions don't match. */ - public static void versionDetect(String modname, - int major, int minor, int revision) { - if(major!=ForgeHooks.majorVersion) { - killMinecraft(modname,"MinecraftForge Major Version Mismatch, expecting "+major+".x.x"); - } else if(minor!=ForgeHooks.minorVersion) { - if(minor>ForgeHooks.minorVersion) { - killMinecraft(modname,"MinecraftForge Too Old, need at least "+major+"."+minor+"."+revision); - } else { - System.out.println(modname + ": MinecraftForge minor version mismatch, expecting "+major+"."+minor+".x, may lead to unexpected behavior"); - } - } else if(revision>ForgeHooks.revisionVersion) { - killMinecraft(modname,"MinecraftForge Too Old, need at least "+major+"."+minor+"."+revision); - } + public static void versionDetect(String mod, int major, int minor, int revision) + { + if (major != ForgeHooks.majorVersion) + { + killMinecraft(mod, "MinecraftForge Major Version Mismatch, expecting " + major + ".x.x"); + } + else if (minor != ForgeHooks.minorVersion) + { + if (minor > ForgeHooks.minorVersion) + { + killMinecraft(mod, "MinecraftForge Too Old, need at least " + major + "." + minor + "." + revision); + } + else + { + System.out.println(mod + ": MinecraftForge minor version mismatch, expecting " + major + "." + minor + ".x, may lead to unexpected behavior"); + } + } + else if (revision > ForgeHooks.revisionVersion) + { + killMinecraft(mod, "MinecraftForge Too Old, need at least " + major + "." + minor + "." + revision); + } } /** * Strict version checking. Ensures that a sufficiently recent version of - * Forge is installed. Will result in a fatal error if the major or minor + * Forge is installed. Will result in a fatal error if the major or minor * versions mismatch or if the version is too old. Use this function for * mods that use recent, new, or unstable APIs to prevent * incompatibilities. */ - public static void versionDetectStrict(String modname, int major, int minor, int revision) + public static void versionDetectStrict(String mod, int major, int minor, int revision) { - if(major!=ForgeHooks.majorVersion) - { - killMinecraft(modname,"MinecraftForge Major Version Mismatch, expecting "+major+".x.x"); - } - else if(minor!=ForgeHooks.minorVersion) - { - if(minor>ForgeHooks.minorVersion) - { - killMinecraft(modname,"MinecraftForge Too Old, need at least "+major+"."+minor+"."+revision); - } - else - { - killMinecraft(modname,"MinecraftForge minor version mismatch, expecting "+major+"."+minor+".x"); - } - } - else if(revision>ForgeHooks.revisionVersion) - { - killMinecraft(modname,"MinecraftForge Too Old, need at least "+major+"."+minor+"."+revision); - } + if (major != ForgeHooks.majorVersion) + { + killMinecraft(mod, "MinecraftForge Major Version Mismatch, expecting " + major + ".x.x"); + } + else if (minor != ForgeHooks.minorVersion) + { + if (minor > ForgeHooks.minorVersion) + { + killMinecraft(mod, "MinecraftForge Too Old, need at least " + major + "." + minor + "." + revision); + } + else + { + killMinecraft(mod, "MinecraftForge minor version mismatch, expecting " + major + "." + minor + ".x"); + } + } + else if (revision > ForgeHooks.revisionVersion) + { + killMinecraft(mod, "MinecraftForge Too Old, need at least " + major + "." + minor + "." + revision); + } } - private static int dungeonLootAttempts = 8; - private static ArrayList> dungeonMobs = new ArrayList>(); - private static ArrayList> dungeonLoot = new ArrayList>(); + private static int dungeonLootAttempts = 8; + private static ArrayList> dungeonMobs = new ArrayList>(); + private static ArrayList> dungeonLoot = new ArrayList>(); /** * Set the number of item stacks that will be attempted to be added to each Dungeon chest. * Note: Due to random number generation, you will not always get this amount per chest. @@ -428,22 +473,22 @@ public class MinecraftForge { */ public static void setDungeonLootTries(int number) { - dungeonLootAttempts = number; + dungeonLootAttempts = number; } - + /** * @return The max number of item stacks found in each dungeon chest. */ public static int getDungeonLootTries() { - return dungeonLootAttempts; + return dungeonLootAttempts; } - + /** * Adds a mob to the possible list of creatures the spawner will create. * If the mob is already in the spawn list, the rarity will be added to the existing one, * causing the mob to be more common. - * + * * @param name The name of the monster, use the same name used when registering the entity. * @param rarity The rarity of selecting this mob over others. Must be greater then 0. * Vanilla Minecraft has the following mobs: @@ -451,47 +496,47 @@ public class MinecraftForge { * Skeleton 1 * Zombie 2 * Meaning, Zombies are twice as common as spiders or skeletons. - * @return The new rarity of the monster, + * @return The new rarity of the monster, */ public static float addDungeonMob(String name, float rarity) { - if (rarity <= 0) - { - throw new IllegalArgumentException("Rarity must be greater then zero"); - } - - for(ObjectPair mob : dungeonMobs) - { - if (name.equals(mob.getValue2())) - { - mob.setValue1(mob.getValue1() + rarity); - return mob.getValue1(); - } - } + if (rarity <= 0) + { + throw new IllegalArgumentException("Rarity must be greater then zero"); + } - dungeonMobs.add(new ObjectPair(rarity, name)); - return rarity; + for (ObjectPair mob : dungeonMobs) + { + if (name.equals(mob.getValue2())) + { + mob.setValue1(mob.getValue1() + rarity); + return mob.getValue1(); + } + } + + dungeonMobs.add(new ObjectPair(rarity, name)); + return rarity; } - + /** * Will completely remove a Mob from the dungeon spawn list. - * + * * @param name The name of the mob to remove * @return The rarity of the removed mob, prior to being removed. */ public static float removeDungeonMob(String name) { - for (ObjectPair mob : dungeonMobs) - { - if (name.equals(name)) - { - dungeonMobs.remove(mob); - return mob.getValue1(); - } - } - return 0; + for (ObjectPair mob : dungeonMobs) + { + if (name.equals(name)) + { + dungeonMobs.remove(mob); + return mob.getValue1(); + } + } + return 0; } - + /** * Gets a random mob name from the list. * @param rand World generation random number generator @@ -499,118 +544,118 @@ public class MinecraftForge { */ public static String getRandomDungeonMob(Random rand) { - float maxRarity = 0f; - for (ObjectPair mob : dungeonMobs) - { - maxRarity += mob.getValue1(); - } - - float targetRarity = rand.nextFloat() * maxRarity; - for (ObjectPair mob : dungeonMobs) - { - if (targetRarity < mob.getValue1()) - { - return mob.getValue2(); - } - targetRarity -= mob.getValue1(); - } - - return ""; + float maxRarity = 0f; + for (ObjectPair mob : dungeonMobs) + { + maxRarity += mob.getValue1(); + } + + float targetRarity = rand.nextFloat() * maxRarity; + for (ObjectPair mob : dungeonMobs) + { + if (targetRarity < mob.getValue1()) + { + return mob.getValue2(); + } + targetRarity -= mob.getValue1(); + } + + return ""; } - + /** * Adds a item stack to the dungeon loot list with a stack size * of 1. - * + * * @param item The ItemStack to be added to the loot list - * @param rarity The relative chance that this item will spawn, Vanilla has - * most of its items set to 1. Like the saddle, bread, silk, wheat, etc.. - * Rarer items are set to lower values, EXA: Golden Apple 0.01 + * @param rarity The relative chance that this item will spawn, Vanilla has + * most of its items set to 1. Like the saddle, bread, silk, wheat, etc.. + * Rarer items are set to lower values, EXA: Golden Apple 0.01 */ public static void addDungeonLoot(ItemStack item, float rarity) { - addDungeonLoot(item, rarity, 1, 1); + addDungeonLoot(item, rarity, 1, 1); } - + /** * Adds a item stack, with a range of sizes, to the dungeon loot list. * If a stack matching the same item, and size range, is already in the list * the rarities will be added together making the item more common. - * + * * @param item The ItemStack to be added to the loot list - * @param rarity The relative chance that this item will spawn, Vanilla has - * most of its items set to 1. Like the saddle, bread, silk, wheat, etc.. - * Rarer items are set to lower values, EXA: Golden Apple 0.01 + * @param rarity The relative chance that this item will spawn, Vanilla has + * most of its items set to 1. Like the saddle, bread, silk, wheat, etc.. + * Rarer items are set to lower values, EXA: Golden Apple 0.01 * @param minCount When this item does generate, the minimum number that is in the stack * @param maxCount When this item does generate, the maximum number that can bein the stack - * @return The new rarity of the loot. + * @return The new rarity of the loot. */ public static float addDungeonLoot(ItemStack item, float rarity, int minCount, int maxCount) { - for (ObjectPair loot : dungeonLoot) - { - if (loot.getValue2().equals(item, minCount, maxCount)) - { - loot.setValue1(loot.getValue1() + rarity); - return loot.getValue1(); - } - } - - dungeonLoot.add(new ObjectPair(rarity, new DungeonLoot(item, minCount, maxCount))); - return rarity; + for (ObjectPair loot : dungeonLoot) + { + if (loot.getValue2().equals(item, minCount, maxCount)) + { + loot.setValue1(loot.getValue1() + rarity); + return loot.getValue1(); + } + } + + dungeonLoot.add(new ObjectPair(rarity, new DungeonLoot(item, minCount, maxCount))); + return rarity; } /** * Removes a item stack from the dungeon loot list, this will remove all items * as long as the item stack matches, it will not care about matching the stack * size ranges perfectly. - * + * * @param item The item stack to remove * @return The total rarity of all items removed */ public static float removeDungeonLoot(ItemStack item) { - return removeDungeonLoot(item, -1, 0); + return removeDungeonLoot(item, -1, 0); } - + /** - * Removes a item stack from the dungeon loot list. If 'minCount' parameter - * is greater then 0, it will only remove loot items that have the same exact + * Removes a item stack from the dungeon loot list. If 'minCount' parameter + * is greater then 0, it will only remove loot items that have the same exact * stack size range as passed in by parameters. - * + * * @param item The item stack to remove - * @param minCount The minimum count for the match check, if less then 0, - * the size check is skipped + * @param minCount The minimum count for the match check, if less then 0, + * the size check is skipped * @param maxCount The max count used in match check when 'minCount' is >= 0 * @return The total rarity of all items removed */ public static float removeDungeonLoot(ItemStack item, int minCount, int maxCount) { - float rarity = 0; - ArrayList> lootTmp = (ArrayList>)dungeonLoot.clone(); - if (minCount < 0) - { - for (ObjectPair loot : lootTmp) - { - if (loot.getValue2().equals(item)) - { - dungeonLoot.remove(loot); - rarity += loot.getValue1(); - } - } - } - else - { - for (ObjectPair loot : lootTmp) - { - if (loot.getValue2().equals(item, minCount, maxCount)) - { - dungeonLoot.remove(loot); - rarity += loot.getValue1(); - } - } - } - - return rarity; + float rarity = 0; + ArrayList> lootTmp = (ArrayList>)dungeonLoot.clone(); + if (minCount < 0) + { + for (ObjectPair loot : lootTmp) + { + if (loot.getValue2().equals(item)) + { + dungeonLoot.remove(loot); + rarity += loot.getValue1(); + } + } + } + else + { + for (ObjectPair loot : lootTmp) + { + if (loot.getValue2().equals(item, minCount, maxCount)) + { + dungeonLoot.remove(loot); + rarity += loot.getValue1(); + } + } + } + + return rarity; } /** @@ -620,25 +665,25 @@ public class MinecraftForge { */ public static ItemStack getRandomDungeonLoot(Random rand) { - float maxRarity = 0f; - for (ObjectPair loot : dungeonLoot) - { - maxRarity += loot.getValue1(); - } - - float targetRarity = rand.nextFloat() * maxRarity; - for (ObjectPair loot : dungeonLoot) - { - if (targetRarity < loot.getValue1()) - { - return loot.getValue2().generateStack(rand); - } - targetRarity -= loot.getValue1(); - } - - return null; + float maxRarity = 0f; + for (ObjectPair loot : dungeonLoot) + { + maxRarity += loot.getValue1(); + } + + float targetRarity = rand.nextFloat() * maxRarity; + for (ObjectPair loot : dungeonLoot) + { + if (targetRarity < loot.getValue1()) + { + return loot.getValue2().generateStack(rand); + } + targetRarity -= loot.getValue1(); + } + + return null; } - + //Minecart Dictionary -------------------------------------- private static Map itemForMinecart = new HashMap(); @@ -665,26 +710,26 @@ public class MinecraftForge { */ public static void registerMinecart(Class minecart, int type, ItemStack item) { - MinecartKey k = new MinecartKey(minecart, type); - itemForMinecart.put(k, item); - minecartForItem.put(item, k); - } - + MinecartKey key = new MinecartKey(minecart, type); + itemForMinecart.put(key, item); + minecartForItem.put(item, key); + } + /** * Removes a previously registered Minecart. Useful for replacing the vanilla minecarts. * @param minecart - * @param type + * @param type */ public static void removeMinecart(Class minecart, int type) { - MinecartKey k = new MinecartKey(minecart, type); - ItemStack item = itemForMinecart.remove(k); - if(item != null) + MinecartKey key = new MinecartKey(minecart, type); + ItemStack item = itemForMinecart.remove(key); + if (item != null) { minecartForItem.remove(item); } - } - + } + /** * This function returns an ItemStack that represents this cart. * The player should be able to use this item to place the minecart. @@ -712,7 +757,7 @@ public class MinecraftForge { ItemStack item = itemForMinecart.get(new MinecartKey(minecart, type)); if (item == null) { - return null; + return null; } return item.copy(); } @@ -727,7 +772,7 @@ public class MinecraftForge { */ public static ItemStack getItemForCart(EntityMinecart cart) { - if(cart.getClass() == EntityMinecart.class) + if (cart.getClass() == EntityMinecart.class) { return getItemForCart(cart.getClass(), cart.getMinecartType()); } @@ -742,18 +787,18 @@ public class MinecraftForge { */ public static Class getCartClassForItem(ItemStack item) { - MinecartKey k = null; - for (ItemStack key : minecartForItem.keySet()) - { - if (key.isItemEqual(item)) - { - k = minecartForItem.get(k); - break; - } - } - if(k != null) + MinecartKey key = null; + for (ItemStack tmpKey : minecartForItem.keySet()) { - return k.minecart; + if (tmpKey.isItemEqual(item)) + { + key = minecartForItem.get(key); + break; + } + } + if (key != null) + { + return key.minecart; } return null; } @@ -767,18 +812,18 @@ public class MinecraftForge { */ public static int getCartTypeForItem(ItemStack item) { - MinecartKey k = null; - for (ItemStack key : minecartForItem.keySet()) - { - if (key.isItemEqual(item)) - { - k = minecartForItem.get(k); - break; - } - } - if(k != null) + MinecartKey key = null; + for (ItemStack tmpKey : minecartForItem.keySet()) { - return k.type; + if (tmpKey.isItemEqual(item)) + { + key = minecartForItem.get(key); + break; + } + } + if (key != null) + { + return key.type; } return -1; } @@ -789,18 +834,18 @@ public class MinecraftForge { */ public static Set getAllCartItems() { - Set ret = new HashSet(); - for(ItemStack item : minecartForItem.keySet()) - { - ret.add(item.copy()); - } + Set ret = new HashSet(); + for (ItemStack item : minecartForItem.keySet()) + { + ret.add(item.copy()); + } return ret; } - + /** - * Registers a Entity class tracking information. Used for sendingEntity - * information over the network. - * + * Registers a Entity class tracking information. Used for sendingEntity + * information over the network. + * * @param entityClass The class for the Entity * @param mod The BaseMod that provides this Entity. * @param ID The ID for the Entity. Needs to be unique combination of Mod and ID. @@ -818,12 +863,12 @@ public class MinecraftForge { ForgeHooks.entityTrackerMap.put(entityClass, new EntityTrackerInfo(mod, ID, range, updateFrequancy, sendVelocityInfo)); return true; } - + /** * Retrieves the tracker info for input Entity. - * + * * @param entity The Entity to find tracking info for. - * @param checkSupers If we should check the super-classes for a match. + * @param checkSupers If we should check the super-classes for a match. * @return The information, or Null if not found. */ public static EntityTrackerInfo getEntityTrackerInfo(Entity entity, boolean checkSupers) @@ -840,10 +885,10 @@ public class MinecraftForge { } return null; } - + /** * Retrieves the Class for a registered Entity based on ModID and Entity Type. - * + * * @param modID The ID of the mod (mod.toString().hashCode()) * @param type The ID for the Entity * @return The entity Class, or null if not found. @@ -860,10 +905,10 @@ public class MinecraftForge { } return null; } - + /** * Retrieves a mod instance based on it's ID. (toString().hashCode()) - * + * * @param id The mod ID * @return The mod, or null if not found */ @@ -871,10 +916,10 @@ public class MinecraftForge { { return ForgeHooks.networkMods.get(id); } - + /** * Returns a unique index number for the specific mod. - * + * * @param mod The mod to find * @return The index number, -1 if no index found */ @@ -889,7 +934,7 @@ public class MinecraftForge { } return -1; } - + /** * Returns a list of mods that are designed to be used over the network. * @return @@ -897,7 +942,7 @@ public class MinecraftForge { public static NetworkMod[] getNetworkMods() { ArrayList ret = new ArrayList(); - for(BaseMod mod : (List)ModLoader.getLoadedMods()) + for (BaseMod mod : (List)ModLoader.getLoadedMods()) { if (mod instanceof NetworkMod) { @@ -906,10 +951,10 @@ public class MinecraftForge { } return ret.toArray(new NetworkMod[0]); } - + /** * Sets the GuiHandler associated with a mod. - * + * * @param mod The mod * @param handler The Gui Handler */ @@ -917,10 +962,10 @@ public class MinecraftForge { { ForgeHooks.guiHandlers.put(mod, handler); } - + /** * Gets the GuiHandler associated with a mod - * + * * @param mod The mod * @return The handler, or null if none associated. */ @@ -928,7 +973,7 @@ public class MinecraftForge { { return ForgeHooks.guiHandlers.get(mod); } - + /** * Registers a new Arrow Nock event handler * @param handler The Handler to be registered @@ -937,7 +982,7 @@ public class MinecraftForge { { ForgeHooks.arrowNockHandlers.add(handler); } - + /** * Registers a new Arrow Loose event handler * @param handler The Handler to be registered @@ -946,30 +991,28 @@ public class MinecraftForge { { ForgeHooks.arrowLooseHandlers.add(handler); } - - - static + + static { - addDungeonMob("Skeleton", 1.0f); - addDungeonMob("Zombie", 2.0f); - addDungeonMob("Spider", 1.0f); - - addDungeonLoot(new ItemStack(Item.saddle), 1.00f ); - addDungeonLoot(new ItemStack(Item.ingotIron), 1.00f, 1, 4); - addDungeonLoot(new ItemStack(Item.bread), 1.00f ); - addDungeonLoot(new ItemStack(Item.wheat), 1.00f, 1, 4); - addDungeonLoot(new ItemStack(Item.gunpowder), 1.00f, 1, 4); - addDungeonLoot(new ItemStack(Item.silk), 1.00f, 1, 4); - addDungeonLoot(new ItemStack(Item.bucketEmpty), 1.00f ); - addDungeonLoot(new ItemStack(Item.appleGold), 0.01f ); - addDungeonLoot(new ItemStack(Item.redstone), 0.50f, 1, 4); - addDungeonLoot(new ItemStack(Item.record13), 0.05f ); - addDungeonLoot(new ItemStack(Item.recordCat), 0.05f ); - addDungeonLoot(new ItemStack(Item.dyePowder, 1, 3), 1.00f ); - + addDungeonMob("Skeleton", 1.0f); + addDungeonMob("Zombie", 2.0f); + addDungeonMob("Spider", 1.0f); + + addDungeonLoot(new ItemStack(Item.saddle), 1.00f ); + addDungeonLoot(new ItemStack(Item.ingotIron), 1.00f, 1, 4); + addDungeonLoot(new ItemStack(Item.bread), 1.00f ); + addDungeonLoot(new ItemStack(Item.wheat), 1.00f, 1, 4); + addDungeonLoot(new ItemStack(Item.gunpowder), 1.00f, 1, 4); + addDungeonLoot(new ItemStack(Item.silk), 1.00f, 1, 4); + addDungeonLoot(new ItemStack(Item.bucketEmpty), 1.00f ); + addDungeonLoot(new ItemStack(Item.appleGold), 0.01f ); + addDungeonLoot(new ItemStack(Item.redstone), 0.50f, 1, 4); + addDungeonLoot(new ItemStack(Item.record13), 0.05f ); + addDungeonLoot(new ItemStack(Item.recordCat), 0.05f ); + addDungeonLoot(new ItemStack(Item.dyePowder, 1, 3), 1.00f ); + registerMinecart(EntityMinecart.class, 0, new ItemStack(Item.minecartEmpty)); registerMinecart(EntityMinecart.class, 1, new ItemStack(Item.minecartCrate)); registerMinecart(EntityMinecart.class, 2, new ItemStack(Item.minecartPowered)); } - } diff --git a/forge/forge_common/net/minecraft/src/forge/NetworkMod.java b/forge/forge_common/net/minecraft/src/forge/NetworkMod.java index a7aa76d9e5..c58909eb0d 100644 --- a/forge/forge_common/net/minecraft/src/forge/NetworkMod.java +++ b/forge/forge_common/net/minecraft/src/forge/NetworkMod.java @@ -1,25 +1,25 @@ -package net.minecraft.src.forge; - -import net.minecraft.src.BaseMod; - -/** - * This is for mods that are designed to be used on the server side alone, - * or both the client and server side. This class is used when registering - * various things relating to network traffic. Entity ID's, GUI Id's, etc.. - */ -public abstract class NetworkMod extends BaseMod -{ - /** - * Returns true if every client is required to have this - * mod installed when it is installed on a server. - * @return True if client is required, false if not. - */ - public abstract boolean clientSideRequired(); - - /** - * Returns true if the server is required to have this - * mod when it is installed on the client. - * @return True if server is required, false if not. - */ - public abstract boolean serverSideRequired(); -} +package net.minecraft.src.forge; + +import net.minecraft.src.BaseMod; + +/** + * This is for mods that are designed to be used on the server side alone, + * or both the client and server side. This class is used when registering + * various things relating to network traffic. Entity ID's, GUI Id's, etc.. + */ +public abstract class NetworkMod extends BaseMod +{ + /** + * Returns true if every client is required to have this + * mod installed when it is installed on a server. + * @return True if client is required, false if not. + */ + public abstract boolean clientSideRequired(); + + /** + * Returns true if the server is required to have this + * mod when it is installed on the client. + * @return True if server is required, false if not. + */ + public abstract boolean serverSideRequired(); +} diff --git a/forge/forge_common/net/minecraft/src/forge/ObjectPair.java b/forge/forge_common/net/minecraft/src/forge/ObjectPair.java index ec5f03a9a9..db062eab1d 100644 --- a/forge/forge_common/net/minecraft/src/forge/ObjectPair.java +++ b/forge/forge_common/net/minecraft/src/forge/ObjectPair.java @@ -1,40 +1,40 @@ -package net.minecraft.src.forge; - -/** - * A class that holds two generic values, can be used as a Key/Value pair, - * but is used in forge as a frequency/object pair. - * - * @param The type of the first value - * @param The Type of the second value - */ -public class ObjectPair -{ - private T1 object1; - private T2 object2; - - public ObjectPair(T1 obj1, T2 obj2) - { - this.object1 = obj1; - this.object2 = obj2; - } - - public T1 getValue1() - { - return this.object1; - } - - public T2 getValue2() - { - return this.object2; - } - - public void setValue1(T1 value) - { - object1 = value; - } - - public void setValue2(T2 value) - { - object2 = value; - } -} +package net.minecraft.src.forge; + +/** + * A class that holds two generic values, can be used as a Key/Value pair, + * but is used in forge as a frequency/object pair. + * + * @param The type of the first value + * @param The Type of the second value + */ +public class ObjectPair +{ + private T1 object1; + private T2 object2; + + public ObjectPair(T1 obj1, T2 obj2) + { + this.object1 = obj1; + this.object2 = obj2; + } + + public T1 getValue1() + { + return this.object1; + } + + public T2 getValue2() + { + return this.object2; + } + + public void setValue1(T1 value) + { + object1 = value; + } + + public void setValue2(T2 value) + { + object2 = value; + } +} diff --git a/forge/forge_common/net/minecraft/src/forge/Property.java b/forge/forge_common/net/minecraft/src/forge/Property.java index 08cc358daf..b7501a7bcf 100755 --- a/forge/forge_common/net/minecraft/src/forge/Property.java +++ b/forge/forge_common/net/minecraft/src/forge/Property.java @@ -1,11 +1,12 @@ /** - * This software is provided under the terms of the Minecraft Forge Public + * This software is provided under the terms of the Minecraft Forge Public * License v1.0. */ package net.minecraft.src.forge; -public class Property { +public class Property +{ public String name; public String value; public String comment; diff --git a/forge/forge_common/net/minecraft/src/forge/packets/ForgePacket.java b/forge/forge_common/net/minecraft/src/forge/packets/ForgePacket.java index 07f394ac0d..a457160397 100644 --- a/forge/forge_common/net/minecraft/src/forge/packets/ForgePacket.java +++ b/forge/forge_common/net/minecraft/src/forge/packets/ForgePacket.java @@ -1,60 +1,60 @@ -package net.minecraft.src.forge.packets; - -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.List; - -import net.minecraft.src.BaseMod; -import net.minecraft.src.ModLoader; -import net.minecraft.src.Packet; -import net.minecraft.src.Packet250CustomPayload; -import net.minecraft.src.forge.ForgeHooks; - -public abstract class ForgePacket -{ - //Forge Packet ID Constants. - public static final int FORGE_ID = 0x040E9B47; //"Forge".hashCode(); - public static final int SPAWN = 1; - public static final int MODLIST = 2; - public static final int MOD_MISSING = 3; - public static final int MOD_IDS = 4; - public static final int OPEN_GUI = 5; - - public Packet getPacket() - { - - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream data = new DataOutputStream(bytes); - try - { - data.writeByte(getID()); - writeData(data); - } - catch (IOException e) - { - e.printStackTrace(); - } - Packet250CustomPayload pkt = new Packet250CustomPayload(); - pkt.channel = "Forge"; - pkt.data = bytes.toByteArray(); - pkt.length = pkt.data.length; - pkt.isChunkDataPacket = true; //Make our packets higher priority, allowing the initial communication to happen before the client receives all world chunks. - return pkt; - } - - public abstract void writeData(DataOutputStream data) throws IOException; - public abstract void readData(DataInputStream data) throws IOException; - public abstract int getID(); - public String toString(boolean full) - { - return toString(); - } - - @Override - public String toString() - { - return getID() + " " + getClass().getSimpleName(); - } -} +package net.minecraft.src.forge.packets; + +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.List; + +import net.minecraft.src.BaseMod; +import net.minecraft.src.ModLoader; +import net.minecraft.src.Packet; +import net.minecraft.src.Packet250CustomPayload; +import net.minecraft.src.forge.ForgeHooks; + +public abstract class ForgePacket +{ + //Forge Packet ID Constants. + public static final int FORGE_ID = 0x040E9B47; //"Forge".hashCode(); + public static final int SPAWN = 1; + public static final int MODLIST = 2; + public static final int MOD_MISSING = 3; + public static final int MOD_IDS = 4; + public static final int OPEN_GUI = 5; + + public Packet getPacket() + { + + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + DataOutputStream data = new DataOutputStream(bytes); + try + { + data.writeByte(getID()); + writeData(data); + } + catch (IOException e) + { + e.printStackTrace(); + } + Packet250CustomPayload pkt = new Packet250CustomPayload(); + pkt.channel = "Forge"; + pkt.data = bytes.toByteArray(); + pkt.length = pkt.data.length; + pkt.isChunkDataPacket = true; //Make our packets higher priority, allowing the initial communication to happen before the client receives all world chunks. + return pkt; + } + + public abstract void writeData(DataOutputStream data) throws IOException; + public abstract void readData(DataInputStream data) throws IOException; + public abstract int getID(); + public String toString(boolean full) + { + return toString(); + } + + @Override + public String toString() + { + return getID() + " " + getClass().getSimpleName(); + } +} diff --git a/forge/forge_common/net/minecraft/src/forge/packets/PacketEntitySpawn.java b/forge/forge_common/net/minecraft/src/forge/packets/PacketEntitySpawn.java index 2a29ba47cf..aa250f622a 100644 --- a/forge/forge_common/net/minecraft/src/forge/packets/PacketEntitySpawn.java +++ b/forge/forge_common/net/minecraft/src/forge/packets/PacketEntitySpawn.java @@ -1,106 +1,106 @@ -package net.minecraft.src.forge.packets; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import net.minecraft.src.BaseMod; -import net.minecraft.src.Entity; -import net.minecraft.src.MathHelper; -import net.minecraft.src.forge.ISpawnHandler; -import net.minecraft.src.forge.IThrowableEntity; -import net.minecraft.src.forge.MinecraftForge; -import net.minecraft.src.forge.NetworkMod; - -public class PacketEntitySpawn extends ForgePacket -{ - public int entityID; - public int posX; - public int posY; - public int posZ; - public int speedX; - public int speedY; - public int speedZ; - public int typeID; - public int modID; - public int throwerID; - private ISpawnHandler handler; - - public PacketEntitySpawn(){} - public PacketEntitySpawn(Entity ent, NetworkMod mod, int type) - { - entityID = ent.entityId; - - posX = MathHelper.floor_double(ent.posX * 32D); - posY = MathHelper.floor_double(ent.posY * 32D); - posZ = MathHelper.floor_double(ent.posZ * 32D); - - typeID = type; - modID = MinecraftForge.getModID(mod); - - if (ent instanceof IThrowableEntity) - { - Entity owner = ((IThrowableEntity)ent).getThrower(); - throwerID = (owner == null ? ent.entityId : owner.entityId); - double maxVel = 3.9D; - double mX = ent.motionX; - double mY = ent.motionY; - double mZ = ent.motionZ; - if (mX < -maxVel) mX = -maxVel; - if (mY < -maxVel) mY = -maxVel; - if (mZ < -maxVel) mZ = -maxVel; - if (mX > maxVel) mX = maxVel; - if (mY > maxVel) mY = maxVel; - if (mZ > maxVel) mZ = maxVel; - speedX = (int)(mX * 8000D); - speedY = (int)(mY * 8000D); - speedZ = (int)(mZ * 8000D); - } - if (ent instanceof ISpawnHandler) - { - handler = (ISpawnHandler)ent; - } - } - public void writeData(DataOutputStream data) throws IOException - { - data.writeInt(modID); - data.writeInt(entityID); - data.writeByte(typeID); - data.writeInt(posX); - data.writeInt(posY); - data.writeInt(posZ); - data.writeInt(throwerID); - if (throwerID != 0) - { - data.writeShort(speedX); - data.writeShort(speedY); - data.writeShort(speedZ); - } - if (handler != null) - { - handler.writeSpawnData(data); - } - } - - public void readData(DataInputStream data) throws IOException - { - modID = data.readInt(); - entityID = data.readInt(); - typeID = data.readByte(); - posX = data.readInt(); - posY = data.readInt(); - posZ = data.readInt(); - throwerID = data.readInt(); - if (throwerID != 0) - { - speedX = data.readShort(); - speedY = data.readShort(); - speedX = data.readShort(); - } - } - @Override - public int getID() - { - return ForgePacket.SPAWN; - } -} +package net.minecraft.src.forge.packets; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import net.minecraft.src.BaseMod; +import net.minecraft.src.Entity; +import net.minecraft.src.MathHelper; +import net.minecraft.src.forge.ISpawnHandler; +import net.minecraft.src.forge.IThrowableEntity; +import net.minecraft.src.forge.MinecraftForge; +import net.minecraft.src.forge.NetworkMod; + +public class PacketEntitySpawn extends ForgePacket +{ + public int entityID; + public int posX; + public int posY; + public int posZ; + public int speedX; + public int speedY; + public int speedZ; + public int typeID; + public int modID; + public int throwerID; + private ISpawnHandler handler; + + public PacketEntitySpawn(){} + public PacketEntitySpawn(Entity ent, NetworkMod mod, int type) + { + entityID = ent.entityId; + + posX = MathHelper.floor_double(ent.posX * 32D); + posY = MathHelper.floor_double(ent.posY * 32D); + posZ = MathHelper.floor_double(ent.posZ * 32D); + + typeID = type; + modID = MinecraftForge.getModID(mod); + + if (ent instanceof IThrowableEntity) + { + Entity owner = ((IThrowableEntity)ent).getThrower(); + throwerID = (owner == null ? ent.entityId : owner.entityId); + double maxVel = 3.9D; + double mX = ent.motionX; + double mY = ent.motionY; + double mZ = ent.motionZ; + if (mX < -maxVel) mX = -maxVel; + if (mY < -maxVel) mY = -maxVel; + if (mZ < -maxVel) mZ = -maxVel; + if (mX > maxVel) mX = maxVel; + if (mY > maxVel) mY = maxVel; + if (mZ > maxVel) mZ = maxVel; + speedX = (int)(mX * 8000D); + speedY = (int)(mY * 8000D); + speedZ = (int)(mZ * 8000D); + } + if (ent instanceof ISpawnHandler) + { + handler = (ISpawnHandler)ent; + } + } + public void writeData(DataOutputStream data) throws IOException + { + data.writeInt(modID); + data.writeInt(entityID); + data.writeByte(typeID); + data.writeInt(posX); + data.writeInt(posY); + data.writeInt(posZ); + data.writeInt(throwerID); + if (throwerID != 0) + { + data.writeShort(speedX); + data.writeShort(speedY); + data.writeShort(speedZ); + } + if (handler != null) + { + handler.writeSpawnData(data); + } + } + + public void readData(DataInputStream data) throws IOException + { + modID = data.readInt(); + entityID = data.readInt(); + typeID = data.readByte(); + posX = data.readInt(); + posY = data.readInt(); + posZ = data.readInt(); + throwerID = data.readInt(); + if (throwerID != 0) + { + speedX = data.readShort(); + speedY = data.readShort(); + speedX = data.readShort(); + } + } + @Override + public int getID() + { + return ForgePacket.SPAWN; + } +} diff --git a/forge/forge_common/net/minecraft/src/forge/packets/PacketMissingMods.java b/forge/forge_common/net/minecraft/src/forge/packets/PacketMissingMods.java index c36f1cee6d..3edb0b311f 100644 --- a/forge/forge_common/net/minecraft/src/forge/packets/PacketMissingMods.java +++ b/forge/forge_common/net/minecraft/src/forge/packets/PacketMissingMods.java @@ -1,21 +1,21 @@ -package net.minecraft.src.forge.packets; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -public class PacketMissingMods extends PacketModList -{ - - public PacketMissingMods(boolean server) - { - super(!server); - } - - @Override - public int getID() - { - return ForgePacket.MOD_MISSING; - } - -} +package net.minecraft.src.forge.packets; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +public class PacketMissingMods extends PacketModList +{ + + public PacketMissingMods(boolean server) + { + super(!server); + } + + @Override + public int getID() + { + return ForgePacket.MOD_MISSING; + } + +} diff --git a/forge/forge_common/net/minecraft/src/forge/packets/PacketModIDs.java b/forge/forge_common/net/minecraft/src/forge/packets/PacketModIDs.java index ec31518bd7..38ab34a4d0 100644 --- a/forge/forge_common/net/minecraft/src/forge/packets/PacketModIDs.java +++ b/forge/forge_common/net/minecraft/src/forge/packets/PacketModIDs.java @@ -1,60 +1,60 @@ -package net.minecraft.src.forge.packets; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.Hashtable; -import java.util.Map.Entry; - -public class PacketModIDs extends ForgePacket -{ - public Hashtable Mods = new Hashtable(); - public int Length; - - @Override - public void writeData(DataOutputStream data) throws IOException - { - data.writeInt(Mods.size()); - for (Entry entry : Mods.entrySet()) - { - data.writeInt(entry.getKey()); - data.writeUTF(entry.getValue()); - } - } - - @Override - public void readData(DataInputStream data) throws IOException - { - Length = data.readInt(); - for(int x = 0; x < Length; x++) - { - Mods.put(data.readInt(), data.readUTF()); - } - } - - @Override - public int getID() - { - return ForgePacket.MOD_IDS; - } - - @Override - public String toString(boolean full) - { - if (full) - { - StringBuilder ret = new StringBuilder(); - ret.append(toString()).append('\n'); - for (Entry mod : Mods.entrySet()) - { - ret.append(String.format(" %5d ", mod.getKey()) + mod.getValue() + '\n'); - } - return ret.toString(); - } - else - { - return toString(); - } - } - -} +package net.minecraft.src.forge.packets; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.Hashtable; +import java.util.Map.Entry; + +public class PacketModIDs extends ForgePacket +{ + public Hashtable Mods = new Hashtable(); + public int Length; + + @Override + public void writeData(DataOutputStream data) throws IOException + { + data.writeInt(Mods.size()); + for (Entry entry : Mods.entrySet()) + { + data.writeInt(entry.getKey()); + data.writeUTF(entry.getValue()); + } + } + + @Override + public void readData(DataInputStream data) throws IOException + { + Length = data.readInt(); + for (int x = 0; x < Length; x++) + { + Mods.put(data.readInt(), data.readUTF()); + } + } + + @Override + public int getID() + { + return ForgePacket.MOD_IDS; + } + + @Override + public String toString(boolean full) + { + if (full) + { + StringBuilder ret = new StringBuilder(); + ret.append(toString()).append('\n'); + for (Entry mod : Mods.entrySet()) + { + ret.append(String.format(" %5d ", mod.getKey()) + mod.getValue() + '\n'); + } + return ret.toString(); + } + else + { + return toString(); + } + } + +} diff --git a/forge/forge_common/net/minecraft/src/forge/packets/PacketModList.java b/forge/forge_common/net/minecraft/src/forge/packets/PacketModList.java index cb85a1db89..1ee0991f17 100644 --- a/forge/forge_common/net/minecraft/src/forge/packets/PacketModList.java +++ b/forge/forge_common/net/minecraft/src/forge/packets/PacketModList.java @@ -1,80 +1,80 @@ -package net.minecraft.src.forge.packets; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.List; - -import net.minecraft.src.BaseMod; -import net.minecraft.src.ModLoader; - -public class PacketModList extends ForgePacket -{ - private boolean isServer = false; - public String[] Mods; - public int Length = -1; - - public PacketModList(boolean server) - { - isServer = server; - } - - @Override - public void writeData(DataOutputStream data) throws IOException - { - if (!isServer) - { - data.writeInt(Mods.length); - for(String mod : Mods) - { - data.writeUTF(mod); - } - } - } - - @Override - public void readData(DataInputStream data) throws IOException - { - if (isServer) - { - Length = data.readInt(); - if (Length >= 0) - { - Mods = new String[Length]; - for (int x = 0; x < Length; x++) - { - Mods[x] = data.readUTF(); - } - } - } - } - - @Override - public int getID() - { - return ForgePacket.MODLIST; - } - - @Override - public String toString(boolean full) - { - if (full) - { - StringBuilder ret = new StringBuilder(); - ret.append(toString()).append('\n'); - if (Mods != null) - { - for (String mod : Mods) - { - ret.append(" " + mod + '\n'); - } - } - return ret.toString(); - } - else - { - return toString(); - } - } - -} +package net.minecraft.src.forge.packets; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.List; + +import net.minecraft.src.BaseMod; +import net.minecraft.src.ModLoader; + +public class PacketModList extends ForgePacket +{ + private boolean isServer = false; + public String[] Mods; + public int Length = -1; + + public PacketModList(boolean server) + { + isServer = server; + } + + @Override + public void writeData(DataOutputStream data) throws IOException + { + if (!isServer) + { + data.writeInt(Mods.length); + for (String mod : Mods) + { + data.writeUTF(mod); + } + } + } + + @Override + public void readData(DataInputStream data) throws IOException + { + if (isServer) + { + Length = data.readInt(); + if (Length >= 0) + { + Mods = new String[Length]; + for (int x = 0; x < Length; x++) + { + Mods[x] = data.readUTF(); + } + } + } + } + + @Override + public int getID() + { + return ForgePacket.MODLIST; + } + + @Override + public String toString(boolean full) + { + if (full) + { + StringBuilder ret = new StringBuilder(); + ret.append(toString()).append('\n'); + if (Mods != null) + { + for (String mod : Mods) + { + ret.append(" " + mod + '\n'); + } + } + return ret.toString(); + } + else + { + return toString(); + } + } + +} diff --git a/forge/forge_common/net/minecraft/src/forge/packets/PacketOpenGUI.java b/forge/forge_common/net/minecraft/src/forge/packets/PacketOpenGUI.java index 00857712c9..7b5a1d9bcf 100644 --- a/forge/forge_common/net/minecraft/src/forge/packets/PacketOpenGUI.java +++ b/forge/forge_common/net/minecraft/src/forge/packets/PacketOpenGUI.java @@ -1,76 +1,76 @@ -package net.minecraft.src.forge.packets; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.Map.Entry; - -public class PacketOpenGUI extends ForgePacket -{ - public int WindowID; - public int ModID; - public int GuiID; - public int X; - public int Y; - public int Z; - - public PacketOpenGUI(){} - public PacketOpenGUI(int window, int mod, int id, int x, int y, int z) - { - WindowID = window; - ModID = mod; - GuiID = id; - X = x; - Y = y; - Z = z; - } - - @Override - public void writeData(DataOutputStream data) throws IOException - { - data.writeInt(WindowID); - data.writeInt(ModID); - data.writeInt(GuiID); - data.writeInt(X); - data.writeInt(Y); - data.writeInt(Z); - } - - @Override - public void readData(DataInputStream data) throws IOException - { - WindowID = data.readInt(); - ModID = data.readInt(); - GuiID = data.readInt(); - X = data.readInt(); - Y = data.readInt(); - Z = data.readInt(); - } - - @Override - public int getID() - { - return ForgePacket.OPEN_GUI; - } - - @Override - public String toString(boolean full) - { - if (full) - { - StringBuilder ret = new StringBuilder(); - ret.append(toString() + '\n'); - ret.append(" Window: " + WindowID + '\n'); - ret.append(" Mod: " + ModID + '\n'); - ret.append(" Gui: " + GuiID + '\n'); - ret.append(" X: " + X + '\n'); - ret.append(" Y: " + Y + '\n'); - ret.append(" Z: " + Z + '\n'); - return ret.toString(); - } - else - { - return toString(); - } - } -} +package net.minecraft.src.forge.packets; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.Map.Entry; + +public class PacketOpenGUI extends ForgePacket +{ + public int WindowID; + public int ModID; + public int GuiID; + public int X; + public int Y; + public int Z; + + public PacketOpenGUI(){} + public PacketOpenGUI(int window, int mod, int id, int x, int y, int z) + { + WindowID = window; + ModID = mod; + GuiID = id; + X = x; + Y = y; + Z = z; + } + + @Override + public void writeData(DataOutputStream data) throws IOException + { + data.writeInt(WindowID); + data.writeInt(ModID); + data.writeInt(GuiID); + data.writeInt(X); + data.writeInt(Y); + data.writeInt(Z); + } + + @Override + public void readData(DataInputStream data) throws IOException + { + WindowID = data.readInt(); + ModID = data.readInt(); + GuiID = data.readInt(); + X = data.readInt(); + Y = data.readInt(); + Z = data.readInt(); + } + + @Override + public int getID() + { + return ForgePacket.OPEN_GUI; + } + + @Override + public String toString(boolean full) + { + if (full) + { + StringBuilder ret = new StringBuilder(); + ret.append(toString() + '\n'); + ret.append(" Window: " + WindowID + '\n'); + ret.append(" Mod: " + ModID + '\n'); + ret.append(" Gui: " + GuiID + '\n'); + ret.append(" X: " + X + '\n'); + ret.append(" Y: " + Y + '\n'); + ret.append(" Z: " + Z + '\n'); + return ret.toString(); + } + else + { + return toString(); + } + } +} diff --git a/forge/forge_server/src/net/minecraft/src/forge/ForgeHooksServer.java b/forge/forge_server/src/net/minecraft/src/forge/ForgeHooksServer.java index 2f1bb6785b..53576425b2 100644 --- a/forge/forge_server/src/net/minecraft/src/forge/ForgeHooksServer.java +++ b/forge/forge_server/src/net/minecraft/src/forge/ForgeHooksServer.java @@ -1,55 +1,55 @@ -package net.minecraft.src.forge; - -import java.util.Map; - -import net.minecraft.src.*; -import net.minecraft.src.forge.packets.PacketModList; - -public class ForgeHooksServer -{ - /** - * Called when a Entity is being added to a EntityTracker. - * If we have valid info, register the entity. - * - * @param tracker The EntityTracker instance - * @param entity The Entity to add - * @return True if we registered the Entity - */ - public static boolean OnTrackEntity(EntityTracker tracker, Entity entity) - { - EntityTrackerInfo info = MinecraftForge.getEntityTrackerInfo(entity, true); - if (info != null) - { - tracker.trackEntity(entity, info.Range, info.UpdateFrequancy, info.SendVelocityInfo); - return true; - } - return false; - } - - public static void sendModListRequest(NetworkManager net) - { - PacketModList pkt = new PacketModList(true); - ((NetServerHandler)net.getNetHandler()).sendPacket(pkt.getPacket()); - if (((PacketHandlerServer)ForgeHooks.getPacketHandler()).DEBUG) - { - System.out.println("S->C: " + pkt.toString(true)); - } - } - - - private static boolean hasInit = false; - public static void init() - { - if (hasInit) - { - return; - } - hasInit = true; - ForgeHooks.setPacketHandler(new PacketHandlerServer()); - } - - static - { - init(); - } -} +package net.minecraft.src.forge; + +import java.util.Map; + +import net.minecraft.src.*; +import net.minecraft.src.forge.packets.PacketModList; + +public class ForgeHooksServer +{ + /** + * Called when a Entity is being added to a EntityTracker. + * If we have valid info, register the entity. + * + * @param tracker The EntityTracker instance + * @param entity The Entity to add + * @return True if we registered the Entity + */ + public static boolean OnTrackEntity(EntityTracker tracker, Entity entity) + { + EntityTrackerInfo info = MinecraftForge.getEntityTrackerInfo(entity, true); + if (info != null) + { + tracker.trackEntity(entity, info.Range, info.UpdateFrequancy, info.SendVelocityInfo); + return true; + } + return false; + } + + public static void sendModListRequest(NetworkManager net) + { + PacketModList pkt = new PacketModList(true); + ((NetServerHandler)net.getNetHandler()).sendPacket(pkt.getPacket()); + if (((PacketHandlerServer)ForgeHooks.getPacketHandler()).DEBUG) + { + System.out.println("S->C: " + pkt.toString(true)); + } + } + + + private static boolean hasInit = false; + public static void init() + { + if (hasInit) + { + return; + } + hasInit = true; + ForgeHooks.setPacketHandler(new PacketHandlerServer()); + } + + static + { + init(); + } +} diff --git a/forge/forge_server/src/net/minecraft/src/forge/IGuiHandler.java b/forge/forge_server/src/net/minecraft/src/forge/IGuiHandler.java index d4ab037225..e13d8cb512 100644 --- a/forge/forge_server/src/net/minecraft/src/forge/IGuiHandler.java +++ b/forge/forge_server/src/net/minecraft/src/forge/IGuiHandler.java @@ -1,21 +1,21 @@ -package net.minecraft.src.forge; - -import net.minecraft.src.Container; -import net.minecraft.src.EntityPlayerMP; -import net.minecraft.src.World; - -public interface IGuiHandler -{ - /** - * Returns a Container to be displayed to the user. This is server side - * - * @param ID The Gui ID Number - * @param player The player viewing the Gui - * @param world The current world - * @param X X Position - * @param Y Y Position - * @param Z Z Position - * @return A GuiScreen to be displayed to the user, null if none. - */ - public Container getGuiContainer(int ID, EntityPlayerMP player, World world, int X, int Y, int Z); -} +package net.minecraft.src.forge; + +import net.minecraft.src.Container; +import net.minecraft.src.EntityPlayerMP; +import net.minecraft.src.World; + +public interface IGuiHandler +{ + /** + * Returns a Container to be displayed to the user. This is server side + * + * @param ID The Gui ID Number + * @param player The player viewing the Gui + * @param world The current world + * @param X X Position + * @param Y Y Position + * @param Z Z Position + * @return A GuiScreen to be displayed to the user, null if none. + */ + public Container getGuiContainer(int ID, EntityPlayerMP player, World world, int X, int Y, int Z); +} diff --git a/forge/forge_server/src/net/minecraft/src/forge/PacketHandlerServer.java b/forge/forge_server/src/net/minecraft/src/forge/PacketHandlerServer.java index b63eda0484..3ba981e1c0 100644 --- a/forge/forge_server/src/net/minecraft/src/forge/PacketHandlerServer.java +++ b/forge/forge_server/src/net/minecraft/src/forge/PacketHandlerServer.java @@ -1,156 +1,156 @@ -package net.minecraft.src.forge; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.logging.Level; - -import net.minecraft.server.MinecraftServer; -import net.minecraft.src.*; -import net.minecraft.src.forge.packets.*; - -public class PacketHandlerServer implements IPacketHandler -{ - public static boolean DEBUG = false; - @Override - public void onPacketData(NetworkManager network, String channel, byte[] bytes) - { - NetServerHandler net = (NetServerHandler)network.getNetHandler(); - DataInputStream data = new DataInputStream(new ByteArrayInputStream(bytes)); - ForgePacket pkt = null; - - try - { - int packetID = data.read(); - switch(packetID) - { - case ForgePacket.MODLIST: - pkt = new PacketModList(true); - pkt.readData(data); - onModListResponse(net, (PacketModList)pkt); - break; - } - } - catch(IOException e) - { - ModLoader.getLogger().log(Level.SEVERE, "Exception in PacketHandlerServer.onPacketData", e); - e.printStackTrace(); - } - } - - private void onModListResponse(NetServerHandler net, PacketModList pkt) throws IOException - { - if (DEBUG) - { - System.out.println("C->S: " + pkt.toString(true)); - } - if (pkt.Length < 0) - { - net.kickPlayer("Invalid mod list response, Size: " + pkt.Length); - return; - } - if (pkt.Mods.length == 0) - { - ModLoader.getLogger().log(Level.INFO, net.getUsername() + " joined with no mods"); - } - else - { - ModLoader.getLogger().log(Level.INFO, net.getUsername() + " joined with: " + Arrays.toString(pkt.Mods).replaceAll("mod_", "")); - } - - //TODO: Write a 'banned mods' system and do the checks here - - NetworkMod[] serverMods = MinecraftForge.getNetworkMods(); - ArrayList missing = new ArrayList(); - for (NetworkMod mod : serverMods) - { - if (!mod.clientSideRequired()) - { - continue; - } - boolean found = true; - for (String modName : pkt.Mods) - { - if (modName.equals(mod.toString())) - { - found = false; - break; - } - } - if (!found) - { - missing.add(mod); - } - } - if (missing.size() > 0) - { - doMissingMods(net, missing); - } - else - { - sendModIDs(net, serverMods); - } - } - - /** - * Sends the user a list of mods they are missing and then disconnects them - * @param net The network handler - */ - private void doMissingMods(NetServerHandler net, ArrayList list) - { - PacketMissingMods pkt = new PacketMissingMods(true); - pkt.Mods = new String[list.size()]; - int x = 0; - for(NetworkMod mod : list) - { - pkt.Mods[x++] = mod.toString(); - } - if (DEBUG) - { - System.out.println("S->C: " + pkt.toString(true)); - } - net.sendPacket(pkt.getPacket()); - disconnectUser(net); - } - - - /** - * Sends a list of mod id mappings to the client. - * Only mod ID's are sent, not item or blocks. - * - * @param net The network handler - * @param list A list of network mods - */ - private void sendModIDs(NetServerHandler net, NetworkMod[] list) - { - PacketModIDs pkt = new PacketModIDs(); - for (NetworkMod mod : list) - { - pkt.Mods.put(MinecraftForge.getModID(mod), mod.toString()); - } - net.sendPacket(pkt.getPacket()); - if (DEBUG) - { - System.out.println("S->C: " + pkt.toString(true)); - } - } - - /** - * Disconnects the player just like kicking them, just without the kick message. - * @param net The network handler - */ - private void disconnectUser(NetServerHandler net) - { - MinecraftServer mc = ModLoader.getMinecraftServerInstance(); - net.getPlayerEntity().func_30002_A(); - net.netManager.serverShutdown(); - mc.configManager.sendPacketToAllPlayers(new Packet3Chat("\247e" + net.getUsername() + " left the game.")); - mc.configManager.playerLoggedOut(net.getPlayerEntity()); - net.connectionClosed = true; - } -} +package net.minecraft.src.forge; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; + +import net.minecraft.server.MinecraftServer; +import net.minecraft.src.*; +import net.minecraft.src.forge.packets.*; + +public class PacketHandlerServer implements IPacketHandler +{ + public static boolean DEBUG = false; + @Override + public void onPacketData(NetworkManager network, String channel, byte[] bytes) + { + NetServerHandler net = (NetServerHandler)network.getNetHandler(); + DataInputStream data = new DataInputStream(new ByteArrayInputStream(bytes)); + ForgePacket pkt = null; + + try + { + int packetID = data.read(); + switch (packetID) + { + case ForgePacket.MODLIST: + pkt = new PacketModList(true); + pkt.readData(data); + onModListResponse(net, (PacketModList)pkt); + break; + } + } + catch (IOException e) + { + ModLoader.getLogger().log(Level.SEVERE, "Exception in PacketHandlerServer.onPacketData", e); + e.printStackTrace(); + } + } + + private void onModListResponse(NetServerHandler net, PacketModList pkt) throws IOException + { + if (DEBUG) + { + System.out.println("C->S: " + pkt.toString(true)); + } + if (pkt.Length < 0) + { + net.kickPlayer("Invalid mod list response, Size: " + pkt.Length); + return; + } + if (pkt.Mods.length == 0) + { + ModLoader.getLogger().log(Level.INFO, net.getUsername() + " joined with no mods"); + } + else + { + ModLoader.getLogger().log(Level.INFO, net.getUsername() + " joined with: " + Arrays.toString(pkt.Mods).replaceAll("mod_", "")); + } + + //TODO: Write a 'banned mods' system and do the checks here + + NetworkMod[] serverMods = MinecraftForge.getNetworkMods(); + ArrayList missing = new ArrayList(); + for (NetworkMod mod : serverMods) + { + if (!mod.clientSideRequired()) + { + continue; + } + boolean found = true; + for (String modName : pkt.Mods) + { + if (modName.equals(mod.toString())) + { + found = false; + break; + } + } + if (!found) + { + missing.add(mod); + } + } + if (missing.size() > 0) + { + doMissingMods(net, missing); + } + else + { + sendModIDs(net, serverMods); + } + } + + /** + * Sends the user a list of mods they are missing and then disconnects them + * @param net The network handler + */ + private void doMissingMods(NetServerHandler net, ArrayList list) + { + PacketMissingMods pkt = new PacketMissingMods(true); + pkt.Mods = new String[list.size()]; + int x = 0; + for (NetworkMod mod : list) + { + pkt.Mods[x++] = mod.toString(); + } + if (DEBUG) + { + System.out.println("S->C: " + pkt.toString(true)); + } + net.sendPacket(pkt.getPacket()); + disconnectUser(net); + } + + + /** + * Sends a list of mod id mappings to the client. + * Only mod ID's are sent, not item or blocks. + * + * @param net The network handler + * @param list A list of network mods + */ + private void sendModIDs(NetServerHandler net, NetworkMod[] list) + { + PacketModIDs pkt = new PacketModIDs(); + for (NetworkMod mod : list) + { + pkt.Mods.put(MinecraftForge.getModID(mod), mod.toString()); + } + net.sendPacket(pkt.getPacket()); + if (DEBUG) + { + System.out.println("S->C: " + pkt.toString(true)); + } + } + + /** + * Disconnects the player just like kicking them, just without the kick message. + * @param net The network handler + */ + private void disconnectUser(NetServerHandler net) + { + MinecraftServer mc = ModLoader.getMinecraftServerInstance(); + net.getPlayerEntity().func_30002_A(); + net.netManager.serverShutdown(); + mc.configManager.sendPacketToAllPlayers(new Packet3Chat("\247e" + net.getUsername() + " left the game.")); + mc.configManager.playerLoggedOut(net.getPlayerEntity()); + net.connectionClosed = true; + } +} diff --git a/forge/forge_server/src/net/minecraft/src/mod_MinecraftForge.java b/forge/forge_server/src/net/minecraft/src/mod_MinecraftForge.java index 86c3d63dfb..cf5b596de3 100644 --- a/forge/forge_server/src/net/minecraft/src/mod_MinecraftForge.java +++ b/forge/forge_server/src/net/minecraft/src/mod_MinecraftForge.java @@ -9,15 +9,15 @@ import net.minecraft.src.forge.MinecraftForge; public class mod_MinecraftForge extends BaseModMp { @Override - public String getVersion() - { - return String.format("%d.%d.%d.%d", - ForgeHooks.majorVersion, ForgeHooks.minorVersion, + public String getVersion() + { + return String.format("%d.%d.%d.%d", + ForgeHooks.majorVersion, ForgeHooks.minorVersion, ForgeHooks.revisionVersion, ForgeHooks.buildVersion); } @Override - public void load() + public void load() { MinecraftForge.getDungeonLootTries(); //Random thing to make things Initialize }