More work, moved over packet stuff, need to change everything to use new NetworkMod system

This commit is contained in:
LexManos 2012-08-06 20:45:37 -07:00
parent 8db1584730
commit 4e91293271
14 changed files with 250 additions and 160 deletions

View File

@ -33,3 +33,6 @@ public ayp.c # soundPoolStreaming
public ayp.d # soundPoolMusic
# EntityLiving
public jv.aM # carryoverDamage
# EntityPlayerMP
public gt.bO()V # incrementWindowID()
public gt.cq # currentWindowId

View File

@ -1,4 +1,4 @@
package net.minecraft.src.forge;
package net.minecraftforge.common;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.World;
@ -9,6 +9,9 @@ public interface IGuiHandler
* Returns a Container to be displayed to the user.
* On the client side, this needs to return a instance of GuiScreen
* On the server side, this needs to return a instance of Container
*
* On the client, the player will always be a instance of EntityPlayerSP
* On the server, the player will always be a instance of EntityPlayerMP
*
* @param ID The Gui ID Number
* @param player The player viewing the Gui

View File

@ -1,4 +1,4 @@
package net.minecraft.src.forge;
package net.minecraftforge.common;
import java.io.DataInputStream;
import java.io.DataOutputStream;

View File

@ -157,10 +157,10 @@ public interface ISpecialArmor
}
if (stack.stackSize <= 0)
{
if (entity instanceof EntityPlayer)
/*if (entity instanceof EntityPlayer)
{
stack.onItemDestroyedByUse((EntityPlayer)entity);
}
}*/
inventory[prop.Slot] = null;
}
}

View File

@ -1,4 +1,4 @@
package net.minecraft.src.forge;
package net.minecraftforge.common;
import net.minecraft.src.Entity;

View File

@ -1,4 +1,4 @@
package net.minecraft.src.forge.packets;
package net.minecraftforge.packets;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
@ -8,17 +8,14 @@ import java.util.List;
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 OPEN_GUI = 5;
public static final int TRACK = 6;
public static final int OPEN_GUI = 2;
public static final int TRACK = 3;
public Packet getPacket()
{

View File

@ -1,4 +1,4 @@
package net.minecraft.src.forge.packets;
package net.minecraftforge.packets;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -8,10 +8,9 @@ import net.minecraft.src.Entity;
import net.minecraft.src.EntityLiving;
import net.minecraft.src.DataWatcher;
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;
import net.minecraftforge.common.ISpawnHandler;
import net.minecraftforge.common.IThrowableEntity;
import net.minecraftforge.common.MinecraftForge;
public class PacketEntitySpawn extends ForgePacket
{

View File

@ -1,4 +1,4 @@
package net.minecraft.src.forge.packets;
package net.minecraftforge.packets;
import java.io.DataInputStream;
import java.io.DataOutputStream;

View File

@ -1,4 +1,4 @@
package net.minecraft.src.forge.packets;
package net.minecraftforge.packets;
import net.minecraft.src.NetworkManager;
import net.minecraft.src.Packet;

View File

@ -1,4 +1,4 @@
package net.minecraft.src.forge.packets;
package net.minecraftforge.packets;
import java.io.DataInputStream;
import java.io.DataOutputStream;

View File

@ -1,21 +0,0 @@
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,116 +0,0 @@
package net.minecraft.src.forge.packets;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.util.Hashtable;
import java.util.List;
import java.util.Map.Entry;
public class PacketModList extends ForgePacket
{
private boolean isServer = false;
public String[] Mods;
public Hashtable<Integer, String> ModIDs = new Hashtable<Integer, String>();
public int Length = -1;
public boolean has4096 = false;
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);
}
}
else
{
data.writeInt(ModIDs.size());
for (Entry<Integer, String> entry : ModIDs.entrySet())
{
data.writeInt(entry.getKey());
data.writeUTF(entry.getValue());
}
}
data.writeBoolean(true);
}
@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();
}
}
}
else
{
Length = data.readInt();
for (int x = 0; x < Length; x++)
{
ModIDs.put(data.readInt(), data.readUTF());
}
}
try
{
has4096 = data.readBoolean();
}
catch (EOFException e)
{
has4096 = false;
}
}
@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');
}
}
else if (ModIDs.size() != 0)
{
for (Entry<Integer, String> mod : ModIDs.entrySet())
{
ret.append(String.format(" %03d ", mod.getKey()) + mod.getValue() + '\n');
}
}
return ret.toString();
}
else
{
return toString();
}
}
}

View File

@ -1,15 +1,44 @@
--- ../src_base/minecraft/net/minecraft/src/EntityPlayer.java
+++ ../src_work/minecraft/net/minecraft/src/EntityPlayer.java
@@ -2,6 +2,8 @@
@@ -2,6 +2,11 @@
import java.util.Iterator;
import java.util.List;
+
+import net.minecraftforge.common.ForgeHooks;
+import net.minecraftforge.common.IGuiHandler;
+import net.minecraftforge.common.ISpecialArmor.ArmorProperties;
+import net.minecraftforge.common.MinecraftForge;
public abstract class EntityPlayer extends EntityLiving implements ICommandSender
{
@@ -673,13 +675,21 @@
@@ -207,6 +212,7 @@
if (var1 == this.itemInUse)
{
+ itemInUse.getItem().onUsingItemTick(itemInUse, this, itemInUseCount);
if (this.itemInUseCount <= 25 && this.itemInUseCount % 4 == 0)
{
this.updateItemUse(var1, 5);
@@ -607,7 +613,16 @@
*/
public EntityItem dropOneItem()
{
- return this.dropPlayerItemWithRandomChoice(this.inventory.decrStackSize(this.inventory.currentItem, 1), false);
+ ItemStack stack = inventory.getCurrentItem();
+ if (stack == null)
+ {
+ return null;
+ }
+ if (stack.getItem().onDroppedByPlayer(stack, this))
+ {
+ return dropPlayerItemWithRandomChoice(inventory.decrStackSize(inventory.currentItem, 1), false);
+ }
+ return null;
}
/**
@@ -673,13 +688,21 @@
/**
* Returns how strong the player is against the specified block at this moment
@ -34,7 +63,42 @@
{
var2 += (float)(var3 * var3 + 1);
}
@@ -1055,7 +1065,9 @@
@@ -972,12 +995,22 @@
*/
protected void damageEntity(DamageSource par1DamageSource, int par2)
{
+ par2 = ForgeHooks.onEntityLivingHurt(this, par1DamageSource, par2);
+ if (par2 == 0)
+ {
+ return;
+ }
+
if (!par1DamageSource.isUnblockable() && this.isBlocking())
{
par2 = 1 + par2 >> 1;
}
- par2 = this.applyArmorCalculations(par1DamageSource, par2);
+ par2 = ArmorProperties.ApplyArmor(this, inventory.armorInventory, par1DamageSource, par2);
+ if (par2 <= 0)
+ {
+ return;
+ }
par2 = this.applyPotionDamageCalculations(par1DamageSource, par2);
this.addExhaustion(par1DamageSource.getHungerDamage());
this.health -= par2;
@@ -1012,6 +1045,10 @@
public boolean interactWith(Entity par1Entity)
{
+ if (!ForgeHooks.onEntityInteract(this, par1Entity, false))
+ {
+ return false;
+ }
if (par1Entity.interact(this))
{
return true;
@@ -1055,7 +1092,9 @@
*/
public void destroyCurrentEquippedItem()
{
@ -44,3 +108,164 @@
}
/**
@@ -1084,6 +1123,15 @@
*/
public void attackTargetEntityWithCurrentItem(Entity par1Entity)
{
+ if (!ForgeHooks.onEntityInteract(this, par1Entity, true))
+ {
+ return;
+ }
+ ItemStack stack = getCurrentEquippedItem();
+ if (stack != null && stack.getItem().onLeftClickEntity(stack, this, par1Entity))
+ {
+ return;
+ }
if (par1Entity.canAttackWithItem())
{
int var2 = this.inventory.getDamageVsEntity(par1Entity);
@@ -1226,6 +1274,11 @@
*/
public EnumStatus sleepInBedAt(int par1, int par2, int par3)
{
+ EnumStatus customSleep = ForgeHooks.sleepInBedAt(this, par1, par2, par3);
+ if (customSleep != null)
+ {
+ return customSleep;
+ }
if (!this.worldObj.isRemote)
{
if (this.isPlayerSleeping() || !this.isEntityAlive())
@@ -1265,6 +1318,11 @@
{
int var9 = this.worldObj.getBlockMetadata(par1, par2, par3);
int var5 = BlockBed.getDirection(var9);
+ Block block = Block.blocksList[worldObj.getBlockId(par1, par2, par3)];
+ if (block != null)
+ {
+ var5 = block.getBedDirection(worldObj, par1, par2, par3);
+ }
float var10 = 0.5F;
float var7 = 0.5F;
@@ -1334,11 +1392,12 @@
this.resetHeight();
ChunkCoordinates var4 = this.playerLocation;
ChunkCoordinates var5 = this.playerLocation;
-
- if (var4 != null && this.worldObj.getBlockId(var4.posX, var4.posY, var4.posZ) == Block.bed.blockID)
- {
- BlockBed.setBedOccupied(this.worldObj, var4.posX, var4.posY, var4.posZ, false);
- var5 = BlockBed.getNearestEmptyChunkCoordinates(this.worldObj, var4.posX, var4.posY, var4.posZ, 0);
+ Block block = (var4 == null ? null : Block.blocksList[worldObj.getBlockId(var4.posX, var4.posY, var4.posZ)]);
+
+ if (var4 != null && block != null && block.isBed(worldObj, var4.posX, var4.posY, var4.posZ, this))
+ {
+ block.setBedOccupied(this.worldObj, var4.posX, var4.posY, var4.posZ, this, false);
+ var5 = block.getBedSpawnPosition(worldObj, var4.posX, var4.posY, var4.posZ, this);
if (var5 == null)
{
@@ -1375,7 +1434,9 @@
*/
private boolean isInBed()
{
- return this.worldObj.getBlockId(this.playerLocation.posX, this.playerLocation.posY, this.playerLocation.posZ) == Block.bed.blockID;
+ ChunkCoordinates c = playerLocation;
+ int blockID = worldObj.getBlockId(c.posX, c.posY, c.posZ);
+ return Block.blocksList[blockID] != null && Block.blocksList[blockID].isBed(worldObj, c.posX, c.posY, c.posZ, this);
}
/**
@@ -1389,14 +1450,15 @@
var2.loadChunk(par1ChunkCoordinates.posX + 3 >> 4, par1ChunkCoordinates.posZ - 3 >> 4);
var2.loadChunk(par1ChunkCoordinates.posX - 3 >> 4, par1ChunkCoordinates.posZ + 3 >> 4);
var2.loadChunk(par1ChunkCoordinates.posX + 3 >> 4, par1ChunkCoordinates.posZ + 3 >> 4);
-
- if (par0World.getBlockId(par1ChunkCoordinates.posX, par1ChunkCoordinates.posY, par1ChunkCoordinates.posZ) != Block.bed.blockID)
+ ChunkCoordinates c = par1ChunkCoordinates;
+ Block block = Block.blocksList[par0World.getBlockId(c.posX, c.posY, c.posZ)];
+ if (block == null || !block.isBed(par0World, c.posX, c.posY, c.posZ, null))
{
return null;
}
else
{
- ChunkCoordinates var3 = BlockBed.getNearestEmptyChunkCoordinates(par0World, par1ChunkCoordinates.posX, par1ChunkCoordinates.posY, par1ChunkCoordinates.posZ, 0);
+ ChunkCoordinates var3 = block.getBedSpawnPosition(par0World, c.posX, c.posY, c.posZ, null);
return var3;
}
}
@@ -1408,8 +1470,11 @@
{
if (this.playerLocation != null)
{
- int var1 = this.worldObj.getBlockMetadata(this.playerLocation.posX, this.playerLocation.posY, this.playerLocation.posZ);
- int var2 = BlockBed.getDirection(var1);
+ int x = playerLocation.posX;
+ int y = playerLocation.posY;
+ int z = playerLocation.posZ;
+ Block block = Block.blocksList[worldObj.getBlockId(x, y, z)];
+ int var2 = (block == null ? 0 : block.getBedDirection(worldObj, x, y, z));
switch (var2)
{
@@ -1699,6 +1764,7 @@
return 101;
}
}
+ var3 = par1ItemStack.getItem().getIconIndex(par1ItemStack, par2, this, itemInUse, itemInUseCount);
}
return var3;
@@ -1919,4 +1985,50 @@
{
return this.theInventoryEnderChest;
}
+
+ /**
+ * Opens a Gui for the player.
+ *
+ * @param mod The mod associated with the gui
+ * @param ID The ID number for the Gui
+ * @param world The World
+ * @param x X Position
+ * @param y Y Position
+ * @param z Z Position
+ */
+ public void openGui(BaseMod mod, int ID, World world, int x, int y, int z)
+ {
+ if (this instanceof EntityPlayerSP)
+ {
+ IGuiHandler handler = MinecraftForge.getGuiHandler(mod, true);
+ if (handler != null)
+ {
+ GuiScreen screen = (GuiScreen)handler.getGuiElement(ID, this, world, x, y, z);
+ if (screen != null)
+ {
+ ModLoader.getMinecraftInstance().displayGuiScreen(screen);
+ }
+ }
+ }
+ else if (this instanceof EntityPlayerMP)
+ {
+ EntityPlayerMP player = (EntityPlayerMP)this;
+ IGuiHandler handler = MinecraftForge.getGuiHandler(mod, false);
+
+ if (handler != null)
+ {
+ Container container = (Container)handler.getGuiElement(ID, player, world, x, y, z);
+ if (container != null)
+ {
+ player.incrementWindowID();
+ player.closeInventory();
+ PacketOpenGUI pkt = new PacketOpenGUI(player.currentWindowId, MinecraftForge.getModID((NetworkMod)mod), ID, x, y, z);
+ player.serverForThisPlayer.sendPacket(pkt.getPacket());
+ craftingInventory = container;
+ craftingInventory.windowId = player.currentWindowId;
+ craftingInventory.addCraftingToCrafters(player);
+ }
+ }
+ }
+ }
}

View File

@ -53,7 +53,7 @@
- for (var15 = 0; var15 <= 1; ++var15)
+ this.loadTexture(Item.itemsList[var10.itemID].getTextureFile());
+
+ for (var15 = 0; var15 <= var10.getItem().getRenderPasses(var10.getItemDamage(); ++var15)
+ for (var15 = 0; var15 <= var10.getItem().getRenderPasses(var10.getItemDamage()); ++var15)
{
+ this.random.setSeed(187L); //Fixes Vanilla bug where layers would not render aligns properly.
var16 = var10.getItem().getIconFromDamageForRenderPass(var10.getItemDamage(), var15);