Ran AStyle over forge code for uniform code formatting, and refactored old code a bit to have cleaner names.

This commit is contained in:
LexManos 2012-02-24 22:07:58 -08:00
parent f160e90738
commit c44aac2b39
61 changed files with 3675 additions and 3463 deletions

View File

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

View File

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

View File

@ -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<IHighlightHandler> highlightHandlers =
new LinkedList<IHighlightHandler>();
static LinkedList<IRenderWorldLastHandler> renderWorldLastHandlers =
new LinkedList<IRenderWorldLastHandler>();
public static LinkedList<IHighlightHandler> highlightHandlers = new LinkedList<IHighlightHandler>();
public static LinkedList<IRenderWorldLastHandler> renderWorldLastHandlers = new LinkedList<IRenderWorldLastHandler>();
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<TesKey> {
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<TesKey>
{
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<TesKey,Tessellator> tessellators=
new HashMap<TesKey,Tessellator>();
static HashMap<String,Integer> textures=new HashMap<String,Integer>();
static boolean inWorld=false;
static TreeSet<TesKey> renderTextures=new TreeSet<TesKey>();
static Tessellator defaultTessellator=null;
static HashMap<TesKey,IRenderContextHandler> renderHandlers=new
HashMap<TesKey,IRenderContextHandler>();
public static HashMap<TesKey, Tessellator> tessellators = new HashMap<TesKey, Tessellator>();
public static HashMap<String, Integer> textures = new HashMap<String, Integer>();
public static boolean inWorld = false;
public static TreeSet<TesKey> renderTextures = new TreeSet<TesKey>();
public static Tessellator defaultTessellator = null;
public static HashMap<TesKey, IRenderContextHandler> renderHandlers = new HashMap<TesKey, IRenderContextHandler>();
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);
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<BaseMod>)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<Integer, String> entry : pkt.Mods.entrySet())
{
if (mod.toString().equals(entry.getValue()))
{
ForgeHooks.networkMods.put(entry.getKey(), mod);
}
}
}
ArrayList<NetworkMod> missing = new ArrayList<NetworkMod>();
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<BaseMod>)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<Integer, String> entry : pkt.Mods.entrySet())
{
if (mod.toString().equals(entry.getValue()))
{
ForgeHooks.networkMods.put(entry.getKey(), mod);
}
}
}
ArrayList<NetworkMod> missing = new ArrayList<NetworkMod>();
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;
}
}
}

View File

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

View File

@ -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<ArmorProperties>
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<ArmorProperties> dmgVals = new ArrayList<ArmorProperties>();
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<ArmorProperties>
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<ArmorProperties>
level = prop.Priority;
}
ratio += prop.AbsorbRatio;
double absorb = damage * prop.AbsorbRatio;
if (absorb > 0)
{
@ -112,7 +112,7 @@ public class ArmorProperties implements Comparable<ArmorProperties>
}
inventory[prop.Slot] = null;
}
}
}
}
damage -= (damage * ratio);
}
@ -123,32 +123,34 @@ public class ArmorProperties implements Comparable<ArmorProperties>
}
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<ArmorProperties>
x = y;
break;
}
else
else
{
armor[y].AbsorbRatio = newRatio;
pFinished = true;
}
}
}
if (pChange && pFinished)
{
@ -205,7 +207,7 @@ public class ArmorProperties implements Comparable<ArmorProperties>
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<ArmorProperties>
}
}
}
}
}
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<ArmorProperties>
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);

View File

@ -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<String, Property> blockProperties = new TreeMap<String, Property>();
public TreeMap<String, Property> itemProperties = new TreeMap<String, Property>();
public TreeMap<String, Property> blockProperties = new TreeMap<String, Property>();
public TreeMap<String, Property> itemProperties = new TreeMap<String, Property>();
public TreeMap<String, Property> generalProperties = new TreeMap<String, Property>();
/**
* 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<String, Property> 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<String, Property> 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<Property> props) throws IOException {
for (Property property : props) {
if (property.comment != null) {
private void writeProperties(BufferedWriter buffer, Collection<Property> 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");
}
}
}

View File

@ -1,70 +1,70 @@
package net.minecraft.src.forge;
import java.util.Hashtable;
import net.minecraft.src.*;
public class DimensionManager
{
private static Hashtable<Integer, WorldProvider> providers = new Hashtable<Integer, WorldProvider>();
private static Hashtable<Integer, Boolean> spawnSettings = new Hashtable<Integer, Boolean>();
private static Hashtable<Integer, World> worlds = new Hashtable<Integer, World>();
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<Integer, WorldProvider> providers = new Hashtable<Integer, WorldProvider>();
private static Hashtable<Integer, Boolean> spawnSettings = new Hashtable<Integer, Boolean>();
private static Hashtable<Integer, World> worlds = new Hashtable<Integer, World>();
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();
}
}

View File

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

View File

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

View File

@ -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 extends Enum<?>> T makeEnum(boolean decompiled, Class<T> 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<T> enumType, String enumName, boolean decompiled) {
return addEnum(decompiled, enumType, enumName, new Class<?>[]{}, new Object[]{});
}
@SuppressWarnings("unchecked")
public static <T extends Enum<?>> T addEnum(boolean decompiled, Class<T> 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<T> values = new ArrayList<T>(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<T> 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<T> enumType, String enumName, boolean decompiled)
{
return addEnum(decompiled, enumType, enumName, new Class<?>[] {}, new Object[] {});
}
@SuppressWarnings("unchecked")
public static <T extends Enum<? >> T addEnum(boolean decompiled, Class<T> 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<T> values = new ArrayList<T>(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();
}
}
}

View File

@ -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<ICraftingHandler> craftingHandlers = new LinkedList<ICraftingHandler>();
public static void onDestroyCurrentItem(EntityPlayer player, ItemStack orig)
{
for (IDestroyToolHandler handler : destroyToolHandlers)
{
handler.onDestroyCurrentItem(player, orig);
}
}
static LinkedList<IDestroyToolHandler> destroyToolHandlers = new LinkedList<IDestroyToolHandler>();
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<IBonemealHandler> bonemealHandlers = new LinkedList<IBonemealHandler>();
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<IHoeHandler> hoeHandlers = new LinkedList<IHoeHandler>();
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<ISleepHandler> sleepHandlers = new LinkedList<ISleepHandler>();
// 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<ICraftingHandler> craftingHandlers = new LinkedList<ICraftingHandler>();
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<IDestroyToolHandler> destroyToolHandlers = new LinkedList<IDestroyToolHandler>();
static LinkedList<IMinecartHandler> minecartHandlers = new LinkedList<IMinecartHandler>();
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<IBonemealHandler> bonemealHandlers = new LinkedList<IBonemealHandler>();
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<IHoeHandler> hoeHandlers = new LinkedList<IHoeHandler>();
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<ISleepHandler> sleepHandlers = new LinkedList<ISleepHandler>();
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<IMinecartHandler> minecartHandlers = new LinkedList<IMinecartHandler>();
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<IConnectionHandler> connectionHandlers = new LinkedList<IConnectionHandler>();
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<IPickupHandler> pickupHandlers = new LinkedList<IPickupHandler>();
static LinkedList<IConnectionHandler> connectionHandlers = new LinkedList<IConnectionHandler>();
// 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<IPickupHandler> pickupHandlers = new LinkedList<IPickupHandler>();
static ProbableItem getRandomItem(List<ProbableItem> 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.wstart) return 1;
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<ProbableItem> plantGrassList;
static int plantGrassWeight;
static ProbableItem getRandomItem(List<ProbableItem> 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<ProbableItem> seedGrassList;
static int seedGrassWeight;
static List<ProbableItem> plantGrassList;
static int plantGrassWeight;
static {
plantGrassList = new ArrayList<ProbableItem>();
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<ProbableItem> seedGrassList;
static int seedGrassWeight;
seedGrassList = new ArrayList<ProbableItem>();
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<Class, EntityTrackerInfo> entityTrackerMap = new HashMap<Class, EntityTrackerInfo>();
/**
* 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<Class, EntityTrackerInfo> entityTrackerMap = new HashMap<Class, EntityTrackerInfo>();
/**
* 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<Integer, NetworkMod> networkMods = new Hashtable<Integer, NetworkMod>();
public static Hashtable<BaseMod, IGuiHandler> guiHandlers = new Hashtable<BaseMod, IGuiHandler>();
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<IArrowLooseHandler> arrowLooseHandlers = new ArrayList<IArrowLooseHandler>();
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<IArrowNockHandler> arrowNockHandlers = new ArrayList<IArrowNockHandler>();
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<ProbableItem>();
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<ProbableItem>();
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;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<ItemStack> 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<ItemStack> onSheared(ItemStack item, World world, int X, int Y, int Z, int fortune);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,11 +7,11 @@ import java.util.Map.Entry;
import net.minecraft.src.NetworkManager;
public class MessageManager
public class MessageManager
{
private Hashtable<NetworkManager, ConnectionInstance> connections = new Hashtable<NetworkManager, ConnectionInstance>();
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<String, ArrayList<IPacketHandler>> channelToHandlers = new Hashtable<String, ArrayList<IPacketHandler>>();
private Hashtable<IPacketHandler, ArrayList<String>> handlerToChannels = new Hashtable<IPacketHandler, ArrayList<String>>();
private HashSet<String> activeChannels = new HashSet<String>();
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<IPacketHandler> handlers = channelToHandlers.get(channel);
ArrayList<String> channels = handlerToChannels.get(handler);
boolean ret = false;
boolean ret = false;
if (handlers == null)
{
ret = true;
handlers = new ArrayList<IPacketHandler>();
channelToHandlers.put(channel, handlers);
}
if (channels == null)
{
channels = new ArrayList<String>();
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<IPacketHandler> 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<String> tmp = handlerToChannels.get(handler);
if (tmp != null)
{
String[] channels = tmp.toArray(new String[0]);
tmp = new ArrayList<String>();
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);
}
}
}
}
}

View File

@ -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<? extends EntityMinecart> minecart;
public final int type;
public MinecartKey(Class<? extends EntityMinecart> 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<? extends EntityMinecart> minecart;
public final int type;
public MinecartKey(Class<? extends EntityMinecart> 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;
}
}

View File

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

View File

@ -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 <T1> The type of the first value
* @param <T2> The Type of the second value
*/
public class ObjectPair<T1, T2>
{
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 <T1> The type of the first value
* @param <T2> The Type of the second value
*/
public class ObjectPair<T1, T2>
{
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;
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -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<Integer, String> Mods = new Hashtable<Integer, String>();
public int Length;
@Override
public void writeData(DataOutputStream data) throws IOException
{
data.writeInt(Mods.size());
for (Entry<Integer, String> 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<Integer, String> 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<Integer, String> Mods = new Hashtable<Integer, String>();
public int Length;
@Override
public void writeData(DataOutputStream data) throws IOException
{
data.writeInt(Mods.size());
for (Entry<Integer, String> 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<Integer, String> mod : Mods.entrySet())
{
ret.append(String.format(" %5d ", mod.getKey()) + mod.getValue() + '\n');
}
return ret.toString();
}
else
{
return toString();
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -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<NetworkMod> missing = new ArrayList<NetworkMod>();
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<NetworkMod> 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<NetworkMod> missing = new ArrayList<NetworkMod>();
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<NetworkMod> 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;
}
}

View File

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