now uses Forge fake player, close #1786

This commit is contained in:
SpaceToad 2014-05-13 20:32:14 +02:00
parent 92adc79f21
commit 424a976cd0
12 changed files with 119 additions and 168 deletions

View file

@ -13,6 +13,7 @@ import java.util.LinkedList;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.WorldServer;
import buildcraft.api.core.BuildCraftAPI; import buildcraft.api.core.BuildCraftAPI;
@ -41,7 +42,7 @@ public class SchematicMask extends SchematicBlockBase {
context.world().setBlock(x, y, z, Blocks.air, 0, 3); context.world().setBlock(x, y, z, Blocks.air, 0, 3);
stack.tryPlaceItemIntoWorld( stack.tryPlaceItemIntoWorld(
BuildCraftAPI.proxy.getBuildCraftPlayer(context.world()), BuildCraftAPI.proxy.getBuildCraftPlayer((WorldServer) context.world()).get(),
context.world(), x, y, z, 1, 0.0f, 0.0f, 0.0f); context.world(), x, y, z, 1, 0.0f, 0.0f, 0.0f);
} }
} else { } else {

View file

@ -8,9 +8,11 @@
*/ */
package buildcraft.api.core; package buildcraft.api.core;
import java.lang.ref.WeakReference;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World; import net.minecraft.world.WorldServer;
public interface ICoreProxy { public interface ICoreProxy {
EntityPlayer getBuildCraftPlayer(World world); WeakReference<EntityPlayer> getBuildCraftPlayer(WorldServer world);
} }

View file

@ -15,6 +15,8 @@ import java.nio.IntBuffer;
import java.util.HashSet; import java.util.HashSet;
import java.util.TreeMap; import java.util.TreeMap;
import com.mojang.authlib.GameProfile;
import org.lwjgl.input.Mouse; import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU; import org.lwjgl.util.glu.GLU;
@ -204,6 +206,8 @@ public class BuildCraftCore extends BuildCraftMod {
public static float diffX, diffY, diffZ; public static float diffX, diffY, diffZ;
public static GameProfile gameProfile = new GameProfile("buildcraft.core", "[BuildCraft]");
private static FloatBuffer modelviewF; private static FloatBuffer modelviewF;
private static FloatBuffer projectionF; private static FloatBuffer projectionF;
private static IntBuffer viewport; private static IntBuffer viewport;

View file

@ -8,11 +8,10 @@
*/ */
package buildcraft.core.proxy; package buildcraft.core.proxy;
import java.lang.ref.WeakReference;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import com.mojang.authlib.GameProfile;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -25,14 +24,14 @@ import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.network.INetHandler; import net.minecraft.network.INetHandler;
import net.minecraft.network.NetHandlerPlayServer; import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe; import net.minecraftforge.oredict.ShapelessOreRecipe;
@ -48,7 +47,7 @@ public class CoreProxy implements ICoreProxy {
public static CoreProxy proxy; public static CoreProxy proxy;
/* BUILDCRAFT PLAYER */ /* BUILDCRAFT PLAYER */
protected static EntityPlayer buildCraftPlayer; protected static WeakReference<EntityPlayer> buildCraftPlayer = new WeakReference<EntityPlayer>(null);
public String getMinecraftVersion() { public String getMinecraftVersion() {
return Loader.instance().getMinecraftModContainer().getVersion(); return Loader.instance().getMinecraftModContainer().getVersion();
@ -142,66 +141,38 @@ public class CoreProxy implements ICoreProxy {
return ""; return "";
} }
private EntityPlayer createNewPlayer(World world) { private WeakReference<EntityPlayer> createNewPlayer(WorldServer world) {
EntityPlayer player = new EntityPlayer(world, new GameProfile (null, "[BuildCraft]")) { EntityPlayer player = FakePlayerFactory.get(world, BuildCraftCore.gameProfile);
@Override
public void addChatMessage(IChatComponent var1) {
}
@Override return new WeakReference<EntityPlayer>(player);
public boolean canCommandSenderUseCommand(int var1, String var2) {
return false;
}
@Override
public ChunkCoordinates getPlayerCoordinates() {
return null;
}
};
return player;
} }
private EntityPlayer createNewPlayer(World world, int x, int y, int z) { private WeakReference<EntityPlayer> createNewPlayer(WorldServer world, int x, int y, int z) {
EntityPlayer player = new EntityPlayer(world, new GameProfile (null, "[BuildCraft]")) { EntityPlayer player = FakePlayerFactory.get(world, BuildCraftCore.gameProfile);
@Override
public void addChatMessage(IChatComponent var1) {
}
@Override
public boolean canCommandSenderUseCommand(int var1, String var2) {
return false;
}
@Override
public ChunkCoordinates getPlayerCoordinates() {
return null;
}
};
player.posX = x;
player.posY = y; player.posY = y;
player.posZ = z; player.posZ = z;
return player; return new WeakReference<EntityPlayer>(player);
} }
@Override @Override
public EntityPlayer getBuildCraftPlayer(World world) { public final WeakReference<EntityPlayer> getBuildCraftPlayer(WorldServer world) {
if (CoreProxy.buildCraftPlayer == null) { if (CoreProxy.buildCraftPlayer.get() == null) {
CoreProxy.buildCraftPlayer = createNewPlayer(world); CoreProxy.buildCraftPlayer = createNewPlayer(world);
} else { } else {
CoreProxy.buildCraftPlayer.worldObj = world; CoreProxy.buildCraftPlayer.get().worldObj = world;
} }
return CoreProxy.buildCraftPlayer; return CoreProxy.buildCraftPlayer;
} }
public EntityPlayer getBuildCraftPlayer(World world, int x, int y, int z) { public final WeakReference<EntityPlayer> getBuildCraftPlayer(WorldServer world, int x, int y, int z) {
if (CoreProxy.buildCraftPlayer == null) { if (CoreProxy.buildCraftPlayer.get() == null) {
CoreProxy.buildCraftPlayer = createNewPlayer(world, x, y, z); CoreProxy.buildCraftPlayer = createNewPlayer(world, x, y, z);
} else { } else {
CoreProxy.buildCraftPlayer.worldObj = world; CoreProxy.buildCraftPlayer.get().worldObj = world;
CoreProxy.buildCraftPlayer.posX = x; CoreProxy.buildCraftPlayer.get().posX = x;
CoreProxy.buildCraftPlayer.posY = y; CoreProxy.buildCraftPlayer.get().posY = y;
CoreProxy.buildCraftPlayer.posZ = z; CoreProxy.buildCraftPlayer.get().posZ = z;
} }
return CoreProxy.buildCraftPlayer; return CoreProxy.buildCraftPlayer;

View file

@ -10,8 +10,6 @@ package buildcraft.core.proxy;
import java.util.List; import java.util.List;
import com.mojang.authlib.GameProfile;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.multiplayer.WorldClient;
@ -24,8 +22,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.network.INetHandler; import net.minecraft.network.INetHandler;
import net.minecraft.network.NetHandlerPlayServer; import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.World; import net.minecraft.world.World;
import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.client.FMLClientHandler;
@ -121,35 +117,6 @@ public class CoreProxyClient extends CoreProxy {
return FMLClientHandler.instance().getClient().thePlayer.getDisplayName(); return FMLClientHandler.instance().getClient().thePlayer.getDisplayName();
} }
private EntityPlayer createNewPlayer(World world) {
EntityPlayer player = new EntityPlayer(world, new GameProfile(null, "[BuildCraft]")) {
@Override
public void addChatMessage(IChatComponent var1) {
}
@Override
public boolean canCommandSenderUseCommand(int var1, String var2) {
return false;
}
@Override
public ChunkCoordinates getPlayerCoordinates() {
return null;
}
};
return player;
}
@Override
public EntityPlayer getBuildCraftPlayer(World world) {
if (CoreProxy.buildCraftPlayer == null) {
CoreProxy.buildCraftPlayer = createNewPlayer(world);
}
return CoreProxy.buildCraftPlayer;
}
@Override @Override
public EntityBlock newEntityBlock(World world, double i, double j, double k, double iSize, double jSize, double kSize, LaserKind laserKind) { public EntityBlock newEntityBlock(World world, double i, double j, double k, double iSize, double jSize, double kSize, LaserKind laserKind) {
EntityBlock eb = super.newEntityBlock(world, i, j, k, iSize, jSize, kSize, laserKind); EntityBlock eb = super.newEntityBlock(world, i, j, k, iSize, jSize, kSize, laserKind);

View file

@ -15,6 +15,7 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
@ -85,7 +86,7 @@ public class EntityRobotBuilder extends EntityRobot implements
if (buildEnergy >= 25) { if (buildEnergy >= 25) {
buildingStack.getItem().onItemUse(buildingStack, buildingStack.getItem().onItemUse(buildingStack,
CoreProxy.proxy.getBuildCraftPlayer(worldObj), CoreProxy.proxy.getBuildCraftPlayer((WorldServer) worldObj).get(),
worldObj, x, y - 1, z, 1, 0.0f, 0.0f, 0.0f); worldObj, x, y - 1, z, 1, 0.0f, 0.0f, 0.0f);
buildingStack = null; buildingStack = null;

View file

@ -21,6 +21,7 @@ import net.minecraft.network.play.server.S27PacketExplosion;
import net.minecraft.world.ChunkPosition; import net.minecraft.world.ChunkPosition;
import net.minecraft.world.Explosion; import net.minecraft.world.Explosion;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLCommonHandler;
@ -44,7 +45,7 @@ public final class BlockUtil {
private BlockUtil() { private BlockUtil() {
} }
public static List<ItemStack> getItemStackFromBlock(World world, int i, int j, int k) { public static List<ItemStack> getItemStackFromBlock(WorldServer world, int i, int j, int k) {
Block block = world.getBlock(i, j, k); Block block = world.getBlock(i, j, k);
if (block == null) { if (block == null) {
@ -58,7 +59,8 @@ public final class BlockUtil {
int meta = world.getBlockMetadata(i, j, k); int meta = world.getBlockMetadata(i, j, k);
ArrayList<ItemStack> dropsList = block.getDrops(world, i, j, k, meta, 0); ArrayList<ItemStack> dropsList = block.getDrops(world, i, j, k, meta, 0);
float dropChance = ForgeEventFactory.fireBlockHarvesting(dropsList, world, block, i, j, k, meta, 0, 1.0F, false, CoreProxy.proxy.getBuildCraftPlayer(world)); float dropChance = ForgeEventFactory.fireBlockHarvesting(dropsList, world, block, i, j, k, meta, 0, 1.0F,
false, CoreProxy.proxy.getBuildCraftPlayer(world).get());
ArrayList<ItemStack> returnList = new ArrayList<ItemStack>(); ArrayList<ItemStack> returnList = new ArrayList<ItemStack>();
for (ItemStack s : dropsList) { for (ItemStack s : dropsList) {
@ -70,11 +72,11 @@ public final class BlockUtil {
return returnList; return returnList;
} }
public static void breakBlock(World world, int x, int y, int z) { public static void breakBlock(WorldServer world, int x, int y, int z) {
breakBlock(world, x, y, z, BuildCraftCore.itemLifespan); breakBlock(world, x, y, z, BuildCraftCore.itemLifespan);
} }
public static void breakBlock(World world, int x, int y, int z, int forcedLifespan) { public static void breakBlock(WorldServer world, int x, int y, int z, int forcedLifespan) {
if (!world.isAirBlock(x, y, z) && BuildCraftCore.dropBrokenBlocks && !world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops")) { if (!world.isAirBlock(x, y, z) && BuildCraftCore.dropBrokenBlocks && !world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops")) {
List<ItemStack> items = getItemStackFromBlock(world, x, y, z); List<ItemStack> items = getItemStackFromBlock(world, x, y, z);

View file

@ -8,7 +8,7 @@
*/ */
package buildcraft.factory; package buildcraft.factory;
import com.mojang.authlib.GameProfile; import java.lang.ref.WeakReference;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
@ -20,8 +20,7 @@ import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.WorldServer;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
@ -32,6 +31,7 @@ import buildcraft.core.inventory.InventoryConcatenator;
import buildcraft.core.inventory.InventoryIterator; import buildcraft.core.inventory.InventoryIterator;
import buildcraft.core.inventory.SimpleInventory; import buildcraft.core.inventory.SimpleInventory;
import buildcraft.core.inventory.StackHelper; import buildcraft.core.inventory.StackHelper;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.CraftingHelper; import buildcraft.core.utils.CraftingHelper;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
@ -50,7 +50,6 @@ public class TileAutoWorkbench extends TileBuildCraft implements ISidedInventory
private IInventory inv = InventoryConcatenator.make().add(resultInv).add(craftMatrix); private IInventory inv = InventoryConcatenator.make().add(resultInv).add(craftMatrix);
private EntityPlayer internalPlayer;
private SlotCrafting craftSlot; private SlotCrafting craftSlot;
private InventoryCraftResult craftResult = new InventoryCraftResult(); private InventoryCraftResult craftResult = new InventoryCraftResult();
@ -68,30 +67,8 @@ public class TileAutoWorkbench extends TileBuildCraft implements ISidedInventory
} }
} }
private final class InternalPlayer extends EntityPlayer { public WeakReference<EntityPlayer> getInternalPlayer() {
return CoreProxy.proxy.getBuildCraftPlayer((WorldServer) worldObj, xCoord, yCoord + 1, zCoord);
public InternalPlayer() {
super(TileAutoWorkbench.this.worldObj, new GameProfile(null, "[BuildCraft]"));
posX = TileAutoWorkbench.this.xCoord;
posY = TileAutoWorkbench.this.yCoord + 1;
posZ = TileAutoWorkbench.this.zCoord;
}
@Override
public void addChatMessage(IChatComponent var1) {
}
@Override
public boolean canCommandSenderUseCommand(int var1, String var2) {
return false;
}
@Override
public ChunkCoordinates getPlayerCoordinates() {
return null;
}
} }
@Override @Override
@ -194,6 +171,7 @@ public class TileAutoWorkbench extends TileBuildCraft implements ISidedInventory
@Override @Override
public void updateEntity() { public void updateEntity() {
super.updateEntity(); super.updateEntity();
if (worldObj.isRemote) { if (worldObj.isRemote) {
return; return;
} }
@ -201,8 +179,7 @@ public class TileAutoWorkbench extends TileBuildCraft implements ISidedInventory
balanceSlots(); balanceSlots();
if (craftSlot == null) { if (craftSlot == null) {
internalPlayer = new InternalPlayer(); craftSlot = new SlotCrafting(getInternalPlayer().get(), craftMatrix, craftResult, 0, 0, 0);
craftSlot = new SlotCrafting(internalPlayer, craftMatrix, craftResult, 0, 0, 0);
} }
if (resultInv.getStackInSlot(SLOT_RESULT) != null) { if (resultInv.getStackInSlot(SLOT_RESULT) != null) {
return; return;
@ -269,11 +246,11 @@ public class TileAutoWorkbench extends TileBuildCraft implements ISidedInventory
return; return;
} }
result = result.copy(); result = result.copy();
craftSlot.onPickupFromSlot(internalPlayer, result); craftSlot.onPickupFromSlot(getInternalPlayer().get(), result);
resultInv.setInventorySlotContents(SLOT_RESULT, result); resultInv.setInventorySlotContents(SLOT_RESULT, result);
// clean fake player inventory (crafting handler support) // clean fake player inventory (crafting handler support)
for (IInvSlot slot : InventoryIterator.getIterable(internalPlayer.inventory, ForgeDirection.UP)) { for (IInvSlot slot : InventoryIterator.getIterable(getInternalPlayer().get().inventory, ForgeDirection.UP)) {
ItemStack stack = slot.getStackInSlot(); ItemStack stack = slot.getStackInSlot();
if (stack != null) { if (stack != null) {
slot.setStackInSlot(null); slot.setStackInSlot(null);

View file

@ -13,7 +13,10 @@ import java.util.List;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftFactory; import buildcraft.BuildCraftFactory;
import buildcraft.api.gates.IAction; import buildcraft.api.gates.IAction;
@ -36,6 +39,10 @@ public class TileMiningWell extends TileBuildCraft implements IMachine {
*/ */
@Override @Override
public void updateEntity () { public void updateEntity () {
if (worldObj.isRemote) {
return;
}
float mj = BuildCraftFactory.MINING_MJ_COST_PER_BLOCK * BuildCraftFactory.miningMultiplier; float mj = BuildCraftFactory.MINING_MJ_COST_PER_BLOCK * BuildCraftFactory.miningMultiplier;
if (mjStored < mj) { if (mjStored < mj) {
@ -59,7 +66,7 @@ public class TileMiningWell extends TileBuildCraft implements IMachine {
boolean wasAir = world.isAirBlock(xCoord, depth, zCoord); boolean wasAir = world.isAirBlock(xCoord, depth, zCoord);
List<ItemStack> stacks = BlockUtil.getItemStackFromBlock(worldObj, xCoord, depth, zCoord); List<ItemStack> stacks = BlockUtil.getItemStackFromBlock((WorldServer) worldObj, xCoord, depth, zCoord);
world.setBlock(xCoord, depth, zCoord, BuildCraftFactory.plainPipeBlock); world.setBlock(xCoord, depth, zCoord, BuildCraftFactory.plainPipeBlock);

View file

@ -23,6 +23,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentText;
import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.ForgeChunkManager; import net.minecraftforge.common.ForgeChunkManager;
import net.minecraftforge.common.ForgeChunkManager.Ticket; import net.minecraftforge.common.ForgeChunkManager.Ticket;
@ -415,7 +416,7 @@ public class TileQuarry extends TileAbstractBuilder implements IMachine {
// Share this with mining well! // Share this with mining well!
List<ItemStack> stacks = BlockUtil.getItemStackFromBlock(worldObj, i, j, k); List<ItemStack> stacks = BlockUtil.getItemStackFromBlock((WorldServer) worldObj, i, j, k);
if (stacks != null) { if (stacks != null) {
for (ItemStack s : stacks) { for (ItemStack s : stacks) {

View file

@ -8,12 +8,12 @@
*/ */
package buildcraft.silicon; package buildcraft.silicon;
import java.lang.ref.WeakReference;
import java.util.Arrays; import java.util.Arrays;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
@ -26,8 +26,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.WorldServer;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
@ -47,6 +46,7 @@ import buildcraft.core.inventory.filters.CraftingFilter;
import buildcraft.core.inventory.filters.IStackFilter; import buildcraft.core.inventory.filters.IStackFilter;
import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketSlotChange; import buildcraft.core.network.PacketSlotChange;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.triggers.ActionMachineControl; import buildcraft.core.triggers.ActionMachineControl;
import buildcraft.core.utils.CraftingHelper; import buildcraft.core.utils.CraftingHelper;
import buildcraft.core.utils.StringUtils; import buildcraft.core.utils.StringUtils;
@ -64,7 +64,6 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
private SlotCrafting craftSlot; private SlotCrafting craftSlot;
private boolean craftable; private boolean craftable;
private boolean justCrafted; private boolean justCrafted;
private InternalPlayer internalPlayer;
private IRecipe currentRecipe; private IRecipe currentRecipe;
private TileBuffer[] cache; private TileBuffer[] cache;
private InventoryCraftResult craftResult; private InventoryCraftResult craftResult;
@ -90,6 +89,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
@Override @Override
public void setInventorySlotContents(int slotId, ItemStack itemstack) { public void setInventorySlotContents(int slotId, ItemStack itemstack) {
super.setInventorySlotContents(slotId, itemstack); super.setInventorySlotContents(slotId, itemstack);
if (TileAdvancedCraftingTable.this.getWorldObj() == null || !TileAdvancedCraftingTable.this.getWorldObj().isRemote) { if (TileAdvancedCraftingTable.this.getWorldObj() == null || !TileAdvancedCraftingTable.this.getWorldObj().isRemote) {
oreIDs[slotId] = itemstack == null ? -1 : OreDictionary.getOreID(itemstack); oreIDs[slotId] = itemstack == null ? -1 : OreDictionary.getOreID(itemstack);
} }
@ -139,9 +139,11 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
return result; return result;
} else { } else {
ItemStack result = tempStacks[bindings[slot]].splitStack(amount); ItemStack result = tempStacks[bindings[slot]].splitStack(amount);
if (tempStacks[bindings[slot]].stackSize <= 0) { if (tempStacks[bindings[slot]].stackSize <= 0) {
tempStacks[bindings[slot]] = null; tempStacks[bindings[slot]] = null;
} }
return result; return result;
} }
} else { } else {
@ -154,28 +156,8 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
} }
} }
private final class InternalPlayer extends EntityPlayer { public WeakReference<EntityPlayer> getInternalPlayer() {
return CoreProxy.proxy.getBuildCraftPlayer((WorldServer) worldObj, xCoord, yCoord + 1, zCoord);
public InternalPlayer() {
super(TileAdvancedCraftingTable.this.getWorldObj(), new GameProfile(null, "[BuildCraft]"));
posX = TileAdvancedCraftingTable.this.xCoord;
posY = TileAdvancedCraftingTable.this.yCoord + 1;
posZ = TileAdvancedCraftingTable.this.zCoord;
}
@Override
public void addChatMessage(IChatComponent var1) {
}
@Override
public boolean canCommandSenderUseCommand(int var1, String var2) {
return false;
}
@Override
public ChunkCoordinates getPlayerCoordinates() {
return null;
}
} }
public TileAdvancedCraftingTable() { public TileAdvancedCraftingTable() {
@ -241,10 +223,14 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
@Override @Override
public void updateEntity() { public void updateEntity() {
super.updateEntity(); super.updateEntity();
if (internalPlayer == null) {
if (worldObj.isRemote) {
return;
}
if (internalInventoryCrafting == null) {
internalInventoryCrafting = new InternalInventoryCrafting(); internalInventoryCrafting = new InternalInventoryCrafting();
internalPlayer = new InternalPlayer(); craftSlot = new SlotCrafting(getInternalPlayer().get(), internalInventoryCrafting, craftResult, 0, 0, 0);
craftSlot = new SlotCrafting(internalPlayer, internalInventoryCrafting, craftResult, 0, 0, 0);
updateRecipe(); updateRecipe();
} }
if (worldObj.isRemote) { if (worldObj.isRemote) {
@ -286,16 +272,21 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
internalInventoryCrafting.tempStacks = new InventoryCopy(inv).getItemStacks(); internalInventoryCrafting.tempStacks = new InventoryCopy(inv).getItemStacks();
internalInventoryCrafting.hitCount = new int[internalInventoryCrafting.tempStacks.length]; internalInventoryCrafting.hitCount = new int[internalInventoryCrafting.tempStacks.length];
ItemStack[] inputSlots = internalInventoryCrafting.tempStacks; ItemStack[] inputSlots = internalInventoryCrafting.tempStacks;
for (int gridSlot = 0; gridSlot < craftingSlots.getSizeInventory(); gridSlot++) { for (int gridSlot = 0; gridSlot < craftingSlots.getSizeInventory(); gridSlot++) {
internalInventoryCrafting.bindings[gridSlot] = -1; internalInventoryCrafting.bindings[gridSlot] = -1;
if (craftingSlots.getStackInSlot(gridSlot) == null) { if (craftingSlots.getStackInSlot(gridSlot) == null) {
continue; continue;
} }
boolean foundMatch = false; boolean foundMatch = false;
for (int inputSlot = 0; inputSlot < inputSlots.length; inputSlot++) { for (int inputSlot = 0; inputSlot < inputSlots.length; inputSlot++) {
if (!isMatchingIngredient(gridSlot, inputSlot)) { if (!isMatchingIngredient(gridSlot, inputSlot)) {
continue; continue;
} }
if (internalInventoryCrafting.hitCount[inputSlot] < inputSlots[inputSlot].stackSize if (internalInventoryCrafting.hitCount[inputSlot] < inputSlots[inputSlot].stackSize
&& internalInventoryCrafting.hitCount[inputSlot] < inputSlots[inputSlot].getMaxStackSize()) { && internalInventoryCrafting.hitCount[inputSlot] < inputSlots[inputSlot].getMaxStackSize()) {
internalInventoryCrafting.bindings[gridSlot] = inputSlot; internalInventoryCrafting.bindings[gridSlot] = inputSlot;
@ -304,6 +295,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
break; break;
} }
} }
if (!foundMatch) { if (!foundMatch) {
return; return;
} }
@ -312,16 +304,16 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
private boolean isMatchingIngredient(int gridSlot, int inputSlot) { private boolean isMatchingIngredient(int gridSlot, int inputSlot) {
ItemStack inputStack = internalInventoryCrafting.tempStacks[inputSlot]; ItemStack inputStack = internalInventoryCrafting.tempStacks[inputSlot];
if (inputStack == null) { if (inputStack == null) {
return false; return false;
} } else if (StackHelper.isMatchingItem(craftingSlots.getStackInSlot(gridSlot), inputStack, true, false)) {
if (StackHelper.isMatchingItem(craftingSlots.getStackInSlot(gridSlot), inputStack, true, false)) {
return true; return true;
} } else if (StackHelper.isCraftingEquivalent(craftingSlots.oreIDs[gridSlot], inputStack)) {
if (StackHelper.isCraftingEquivalent(craftingSlots.oreIDs[gridSlot], inputStack)) {
return true; return true;
} else {
return false;
} }
return false;
} }
private boolean hasIngredients() { private boolean hasIngredients() {
@ -329,28 +321,36 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
} }
private void craftItem() { private void craftItem() {
EntityPlayer internalPlayer = getInternalPlayer().get();
ItemStack recipeOutput = getRecipeOutput(); ItemStack recipeOutput = getRecipeOutput();
craftSlot.onPickupFromSlot(internalPlayer, recipeOutput); craftSlot.onPickupFromSlot(internalPlayer, recipeOutput);
ItemStack[] tempStorage = internalInventoryCrafting.tempStacks; ItemStack[] tempStorage = internalInventoryCrafting.tempStacks;
for (int i = 0; i < tempStorage.length; i++) { for (int i = 0; i < tempStorage.length; i++) {
if (tempStorage[i] != null && tempStorage[i].stackSize <= 0) { if (tempStorage[i] != null && tempStorage[i].stackSize <= 0) {
tempStorage[i] = null; tempStorage[i] = null;
} }
inv.getItemStacks()[i] = tempStorage[i]; inv.getItemStacks()[i] = tempStorage[i];
} }
subtractEnergy(getRequiredEnergy()); subtractEnergy(getRequiredEnergy());
List<ItemStack> outputs = Lists.newArrayList(recipeOutput.copy()); List<ItemStack> outputs = Lists.newArrayList(recipeOutput.copy());
for (int i = 0; i < internalPlayer.inventory.mainInventory.length; i++) { for (int i = 0; i < internalPlayer.inventory.mainInventory.length; i++) {
if (internalPlayer.inventory.mainInventory[i] != null) { if (internalPlayer.inventory.mainInventory[i] != null) {
outputs.add(internalPlayer.inventory.mainInventory[i]); outputs.add(internalPlayer.inventory.mainInventory[i]);
internalPlayer.inventory.mainInventory[i] = null; internalPlayer.inventory.mainInventory[i] = null;
} }
} }
for (ItemStack output : outputs) { for (ItemStack output : outputs) {
output.stackSize -= Transactor.getTransactorFor(invOutput).add(output, ForgeDirection.UP, true).stackSize; output.stackSize -= Transactor.getTransactorFor(invOutput).add(output, ForgeDirection.UP, true).stackSize;
if (output.stackSize > 0) { if (output.stackSize > 0) {
output.stackSize -= Utils.addToRandomInventoryAround(worldObj, xCoord, yCoord, zCoord, output); output.stackSize -= Utils.addToRandomInventoryAround(worldObj, xCoord, yCoord, zCoord, output);
} }
if (output.stackSize > 0) { if (output.stackSize > 0) {
InvUtils.dropItems(worldObj, output, xCoord, yCoord + 1, zCoord); InvUtils.dropItems(worldObj, output, xCoord, yCoord + 1, zCoord);
} }
@ -361,18 +361,24 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
if (cache == null) { if (cache == null) {
cache = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, false); cache = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, false);
} }
for (IInvSlot slot : InventoryIterator.getIterable(craftingSlots, ForgeDirection.UP)) { for (IInvSlot slot : InventoryIterator.getIterable(craftingSlots, ForgeDirection.UP)) {
ItemStack ingred = slot.getStackInSlot(); ItemStack ingred = slot.getStackInSlot();
if (ingred == null) { if (ingred == null) {
continue; continue;
} }
IStackFilter filter = new CraftingFilter(ingred); IStackFilter filter = new CraftingFilter(ingred);
if (InvUtils.countItems(invInput, ForgeDirection.UP, filter) < InvUtils.countItems(craftingSlots, ForgeDirection.UP, filter)) { if (InvUtils.countItems(invInput, ForgeDirection.UP, filter) < InvUtils.countItems(craftingSlots, ForgeDirection.UP, filter)) {
for (ForgeDirection side : SEARCH_SIDES) { for (ForgeDirection side : SEARCH_SIDES) {
TileEntity tile = cache[side.ordinal()].getTile(); TileEntity tile = cache[side.ordinal()].getTile();
if (tile instanceof IInventory) { if (tile instanceof IInventory) {
IInventory inv = InvUtils.getInventory((IInventory) tile); IInventory inv = InvUtils.getInventory((IInventory) tile);
ItemStack result = InvUtils.moveOneItem(inv, side.getOpposite(), invInput, side, filter); ItemStack result = InvUtils.moveOneItem(inv, side.getOpposite(), invInput, side, filter);
if (result != null) { if (result != null) {
return; return;
} }
@ -385,6 +391,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
public void updateCraftingMatrix(int slot, ItemStack stack) { public void updateCraftingMatrix(int slot, ItemStack stack) {
craftingSlots.setInventorySlotContents(slot, stack); craftingSlots.setInventorySlotContents(slot, stack);
updateRecipe(); updateRecipe();
if (worldObj.isRemote) { if (worldObj.isRemote) {
PacketSlotChange packet = new PacketSlotChange(PacketIds.ADVANCED_WORKBENCH_SETSLOT, xCoord, yCoord, zCoord, slot, stack); PacketSlotChange packet = new PacketSlotChange(PacketIds.ADVANCED_WORKBENCH_SETSLOT, xCoord, yCoord, zCoord, slot, stack);
BuildCraftSilicon.instance.sendToServer(packet); BuildCraftSilicon.instance.sendToServer(packet);
@ -395,10 +402,13 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
if (internalInventoryCrafting == null) { if (internalInventoryCrafting == null) {
return; return;
} }
internalInventoryCrafting.recipeUpdate(true); internalInventoryCrafting.recipeUpdate(true);
if (this.currentRecipe == null || !this.currentRecipe.matches(internalInventoryCrafting, worldObj)) { if (this.currentRecipe == null || !this.currentRecipe.matches(internalInventoryCrafting, worldObj)) {
currentRecipe = CraftingHelper.findMatchingRecipe(internalInventoryCrafting, worldObj); currentRecipe = CraftingHelper.findMatchingRecipe(internalInventoryCrafting, worldObj);
} }
internalInventoryCrafting.recipeUpdate(false); internalInventoryCrafting.recipeUpdate(false);
markDirty(); markDirty();
} }
@ -408,12 +418,15 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
craftResult.setInventorySlotContents(0, null); craftResult.setInventorySlotContents(0, null);
return; return;
} }
ItemStack resultStack = getRecipeOutput(); ItemStack resultStack = getRecipeOutput();
if (resultStack == null) { if (resultStack == null) {
internalInventoryCrafting.recipeUpdate(true); internalInventoryCrafting.recipeUpdate(true);
resultStack = getRecipeOutput(); resultStack = getRecipeOutput();
internalInventoryCrafting.recipeUpdate(false); internalInventoryCrafting.recipeUpdate(false);
} }
craftResult.setInventorySlotContents(0, resultStack); craftResult.setInventorySlotContents(0, resultStack);
markDirty(); markDirty();
} }
@ -421,8 +434,9 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
private ItemStack getRecipeOutput() { private ItemStack getRecipeOutput() {
if (internalInventoryCrafting == null || currentRecipe == null) { if (internalInventoryCrafting == null || currentRecipe == null) {
return null; return null;
} else {
return currentRecipe.getCraftingResult(internalInventoryCrafting);
} }
return currentRecipe.getCraftingResult(internalInventoryCrafting);
} }
public IInventory getCraftingSlots() { public IInventory getCraftingSlots() {

View file

@ -22,7 +22,10 @@ import net.minecraft.item.ItemBucket;
import net.minecraft.item.ItemPotion; import net.minecraft.item.ItemPotion;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider; import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position; import buildcraft.api.core.Position;
@ -102,13 +105,13 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> {
if (convertPipe(transport, event.item)) { if (convertPipe(transport, event.item)) {
BuildCraftTransport.pipeItemsStripes.onItemUse(new ItemStack( BuildCraftTransport.pipeItemsStripes.onItemUse(new ItemStack(
BuildCraftTransport.pipeItemsStripes), CoreProxy BuildCraftTransport.pipeItemsStripes), CoreProxy
.proxy.getBuildCraftPlayer(getWorld()), getWorld(), (int) p.x, .proxy.getBuildCraftPlayer((WorldServer) getWorld()).get(), getWorld(), (int) p.x,
(int) p.y, (int) p.z, 1, 0, 0, 0 (int) p.y, (int) p.z, 1, 0, 0, 0
); );
} else if (stack.getItem() instanceof ItemBlock) { } else if (stack.getItem() instanceof ItemBlock) {
if (getWorld().getBlock((int) p.x, (int) p.y, (int) p.z) == Blocks.air) { if (getWorld().getBlock((int) p.x, (int) p.y, (int) p.z) == Blocks.air) {
stack.tryPlaceItemIntoWorld( stack.tryPlaceItemIntoWorld(
CoreProxy.proxy.getBuildCraftPlayer(getWorld()), CoreProxy.proxy.getBuildCraftPlayer((WorldServer) getWorld()).get(),
getWorld(), (int) p.x, (int) p.y, (int) p.z, 1, 0.0f, 0.0f, getWorld(), (int) p.x, (int) p.y, (int) p.z, 1, 0.0f, 0.0f,
0.0f); 0.0f);
} }
@ -118,13 +121,14 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> {
if (block instanceof BlockLeavesBase) { if (block instanceof BlockLeavesBase) {
getWorld().playSoundEffect((int) p.x, (int) p.y, (int) p.z, Block.soundTypeGrass.getBreakSound(), 1, 1); getWorld().playSoundEffect((int) p.x, (int) p.y, (int) p.z, Block.soundTypeGrass.getBreakSound(), 1, 1);
getWorld().setBlockToAir((int) p.x, (int) p.y, (int) p.z); getWorld().setBlockToAir((int) p.x, (int) p.y, (int) p.z);
stack.damageItem(1, CoreProxy.proxy.getBuildCraftPlayer(getWorld())); stack.damageItem(1, CoreProxy.proxy.getBuildCraftPlayer((WorldServer) getWorld()).get());
} }
} else if (stack.getItem() == Items.arrow) { } else if (stack.getItem() == Items.arrow) {
stack.stackSize--; stack.stackSize--;
ForgeDirection direction = event.direction; ForgeDirection direction = event.direction;
EntityArrow entityArrow = new EntityArrow(getWorld(), CoreProxy.proxy.getBuildCraftPlayer(getWorld()), 0); EntityArrow entityArrow = new EntityArrow(getWorld(),
CoreProxy.proxy.getBuildCraftPlayer((WorldServer) getWorld()).get(), 0);
entityArrow.setPosition(p.x + 0.5d, p.y + 0.5d, p.z + 0.5d); entityArrow.setPosition(p.x + 0.5d, p.y + 0.5d, p.z + 0.5d);
entityArrow.setDamage(3); entityArrow.setDamage(3);
entityArrow.setKnockbackStrength(1); entityArrow.setKnockbackStrength(1);
@ -135,8 +139,8 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> {
} else if ((stack.getItem() == Items.potionitem && ItemPotion.isSplash(stack.getItemDamage())) } else if ((stack.getItem() == Items.potionitem && ItemPotion.isSplash(stack.getItemDamage()))
|| stack.getItem() == Items.egg || stack.getItem() == Items.egg
|| stack.getItem() == Items.snowball) { || stack.getItem() == Items.snowball) {
EntityPlayer player = CoreProxy.proxy.getBuildCraftPlayer(getWorld(), EntityPlayer player = CoreProxy.proxy.getBuildCraftPlayer((WorldServer) getWorld(),
(int) p.x, (int) p.y, (int) p.z); (int) p.x, (int) p.y, (int) p.z).get();
switch (event.direction) { switch (event.direction) {
case DOWN: case DOWN:
@ -170,8 +174,8 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> {
stack.getItem().onItemRightClick( stack.getItem().onItemRightClick(
stack, stack,
getWorld(), getWorld(),
CoreProxy.proxy.getBuildCraftPlayer(getWorld(), CoreProxy.proxy.getBuildCraftPlayer((WorldServer) getWorld(),
(int) p.x, (int) p.y, (int) p.z)); (int) p.x, (int) p.y, (int) p.z).get());
} else if (getWorld().getBlock((int) p.x, (int) p.y, (int) p.z) == Blocks.air) { } else if (getWorld().getBlock((int) p.x, (int) p.y, (int) p.z) == Blocks.air) {
if (stack.getItem() instanceof ItemBucket) { if (stack.getItem() instanceof ItemBucket) {
Block underblock = getWorld().getBlock((int) p.x, (int) p.y - 1, (int) p.z); Block underblock = getWorld().getBlock((int) p.x, (int) p.y - 1, (int) p.z);
@ -201,12 +205,12 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> {
} }
} else { } else {
stack.tryPlaceItemIntoWorld( stack.tryPlaceItemIntoWorld(
CoreProxy.proxy.getBuildCraftPlayer(getWorld()), CoreProxy.proxy.getBuildCraftPlayer((WorldServer) getWorld()).get(),
getWorld(), (int) p.x, (int) p.y - 1, (int) p.z, 1, 0.0f, 0.0f, 0.0f); getWorld(), (int) p.x, (int) p.y - 1, (int) p.z, 1, 0.0f, 0.0f, 0.0f);
} }
} else { } else {
stack.tryPlaceItemIntoWorld( stack.tryPlaceItemIntoWorld(
CoreProxy.proxy.getBuildCraftPlayer(getWorld()), CoreProxy.proxy.getBuildCraftPlayer((WorldServer) getWorld()).get(),
getWorld(), (int) p.x, (int) p.y, (int) p.z, 1, 0.0f, 0.0f, getWorld(), (int) p.x, (int) p.y, (int) p.z, 1, 0.0f, 0.0f,
0.0f); 0.0f);
} }