now uses Forge fake player, close #1786
This commit is contained in:
parent
92adc79f21
commit
424a976cd0
12 changed files with 119 additions and 168 deletions
|
@ -13,6 +13,7 @@ import java.util.LinkedList;
|
|||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
import buildcraft.api.core.BuildCraftAPI;
|
||||
|
||||
|
@ -41,7 +42,7 @@ public class SchematicMask extends SchematicBlockBase {
|
|||
context.world().setBlock(x, y, z, Blocks.air, 0, 3);
|
||||
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -8,9 +8,11 @@
|
|||
*/
|
||||
package buildcraft.api.core;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
public interface ICoreProxy {
|
||||
EntityPlayer getBuildCraftPlayer(World world);
|
||||
WeakReference<EntityPlayer> getBuildCraftPlayer(WorldServer world);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ import java.nio.IntBuffer;
|
|||
import java.util.HashSet;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.util.glu.GLU;
|
||||
|
@ -204,6 +206,8 @@ public class BuildCraftCore extends BuildCraftMod {
|
|||
|
||||
public static float diffX, diffY, diffZ;
|
||||
|
||||
public static GameProfile gameProfile = new GameProfile("buildcraft.core", "[BuildCraft]");
|
||||
|
||||
private static FloatBuffer modelviewF;
|
||||
private static FloatBuffer projectionF;
|
||||
private static IntBuffer viewport;
|
||||
|
|
|
@ -8,11 +8,10 @@
|
|||
*/
|
||||
package buildcraft.core.proxy;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
@ -25,14 +24,14 @@ import net.minecraft.item.crafting.CraftingManager;
|
|||
import net.minecraft.network.INetHandler;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
|
@ -48,7 +47,7 @@ public class CoreProxy implements ICoreProxy {
|
|||
public static CoreProxy proxy;
|
||||
|
||||
/* BUILDCRAFT PLAYER */
|
||||
protected static EntityPlayer buildCraftPlayer;
|
||||
protected static WeakReference<EntityPlayer> buildCraftPlayer = new WeakReference<EntityPlayer>(null);
|
||||
|
||||
public String getMinecraftVersion() {
|
||||
return Loader.instance().getMinecraftModContainer().getVersion();
|
||||
|
@ -142,66 +141,38 @@ public class CoreProxy implements ICoreProxy {
|
|||
return "";
|
||||
}
|
||||
|
||||
private EntityPlayer createNewPlayer(World world) {
|
||||
EntityPlayer player = new EntityPlayer(world, new GameProfile (null, "[BuildCraft]")) {
|
||||
@Override
|
||||
public void addChatMessage(IChatComponent var1) {
|
||||
}
|
||||
private WeakReference<EntityPlayer> createNewPlayer(WorldServer world) {
|
||||
EntityPlayer player = FakePlayerFactory.get(world, BuildCraftCore.gameProfile);
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(int var1, String var2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkCoordinates getPlayerCoordinates() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
return player;
|
||||
return new WeakReference<EntityPlayer>(player);
|
||||
}
|
||||
|
||||
private EntityPlayer createNewPlayer(World world, int x, int y, int z) {
|
||||
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;
|
||||
}
|
||||
};
|
||||
player.posX = x;
|
||||
private WeakReference<EntityPlayer> createNewPlayer(WorldServer world, int x, int y, int z) {
|
||||
EntityPlayer player = FakePlayerFactory.get(world, BuildCraftCore.gameProfile);
|
||||
player.posY = y;
|
||||
player.posZ = z;
|
||||
return player;
|
||||
return new WeakReference<EntityPlayer>(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPlayer getBuildCraftPlayer(World world) {
|
||||
if (CoreProxy.buildCraftPlayer == null) {
|
||||
public final WeakReference<EntityPlayer> getBuildCraftPlayer(WorldServer world) {
|
||||
if (CoreProxy.buildCraftPlayer.get() == null) {
|
||||
CoreProxy.buildCraftPlayer = createNewPlayer(world);
|
||||
} else {
|
||||
CoreProxy.buildCraftPlayer.worldObj = world;
|
||||
CoreProxy.buildCraftPlayer.get().worldObj = world;
|
||||
}
|
||||
|
||||
return CoreProxy.buildCraftPlayer;
|
||||
}
|
||||
|
||||
public EntityPlayer getBuildCraftPlayer(World world, int x, int y, int z) {
|
||||
if (CoreProxy.buildCraftPlayer == null) {
|
||||
public final WeakReference<EntityPlayer> getBuildCraftPlayer(WorldServer world, int x, int y, int z) {
|
||||
if (CoreProxy.buildCraftPlayer.get() == null) {
|
||||
CoreProxy.buildCraftPlayer = createNewPlayer(world, x, y, z);
|
||||
} else {
|
||||
CoreProxy.buildCraftPlayer.worldObj = world;
|
||||
CoreProxy.buildCraftPlayer.posX = x;
|
||||
CoreProxy.buildCraftPlayer.posY = y;
|
||||
CoreProxy.buildCraftPlayer.posZ = z;
|
||||
CoreProxy.buildCraftPlayer.get().worldObj = world;
|
||||
CoreProxy.buildCraftPlayer.get().posX = x;
|
||||
CoreProxy.buildCraftPlayer.get().posY = y;
|
||||
CoreProxy.buildCraftPlayer.get().posZ = z;
|
||||
}
|
||||
|
||||
return CoreProxy.buildCraftPlayer;
|
||||
|
|
|
@ -10,8 +10,6 @@ package buildcraft.core.proxy;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
|
@ -24,8 +22,6 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.network.INetHandler;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
|
@ -121,35 +117,6 @@ public class CoreProxyClient extends CoreProxy {
|
|||
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
|
||||
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);
|
||||
|
|
|
@ -15,6 +15,7 @@ import net.minecraft.inventory.IInventory;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
|
||||
|
||||
|
@ -85,7 +86,7 @@ public class EntityRobotBuilder extends EntityRobot implements
|
|||
|
||||
if (buildEnergy >= 25) {
|
||||
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);
|
||||
|
||||
buildingStack = null;
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.minecraft.network.play.server.S27PacketExplosion;
|
|||
import net.minecraft.world.ChunkPosition;
|
||||
import net.minecraft.world.Explosion;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
||||
|
@ -44,7 +45,7 @@ public final class 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);
|
||||
|
||||
if (block == null) {
|
||||
|
@ -58,7 +59,8 @@ public final class BlockUtil {
|
|||
int meta = world.getBlockMetadata(i, j, k);
|
||||
|
||||
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>();
|
||||
for (ItemStack s : dropsList) {
|
||||
|
@ -70,11 +72,11 @@ public final class BlockUtil {
|
|||
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);
|
||||
}
|
||||
|
||||
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")) {
|
||||
List<ItemStack> items = getItemStackFromBlock(world, x, y, z);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
package buildcraft.factory;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
|
@ -20,8 +20,7 @@ import net.minecraft.inventory.SlotCrafting;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
|
@ -32,6 +31,7 @@ import buildcraft.core.inventory.InventoryConcatenator;
|
|||
import buildcraft.core.inventory.InventoryIterator;
|
||||
import buildcraft.core.inventory.SimpleInventory;
|
||||
import buildcraft.core.inventory.StackHelper;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.CraftingHelper;
|
||||
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 EntityPlayer internalPlayer;
|
||||
private SlotCrafting craftSlot;
|
||||
private InventoryCraftResult craftResult = new InventoryCraftResult();
|
||||
|
||||
|
@ -68,30 +67,8 @@ public class TileAutoWorkbench extends TileBuildCraft implements ISidedInventory
|
|||
}
|
||||
}
|
||||
|
||||
private final class InternalPlayer extends EntityPlayer {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
public WeakReference<EntityPlayer> getInternalPlayer() {
|
||||
return CoreProxy.proxy.getBuildCraftPlayer((WorldServer) worldObj, xCoord, yCoord + 1, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -194,6 +171,7 @@ public class TileAutoWorkbench extends TileBuildCraft implements ISidedInventory
|
|||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
@ -201,8 +179,7 @@ public class TileAutoWorkbench extends TileBuildCraft implements ISidedInventory
|
|||
balanceSlots();
|
||||
|
||||
if (craftSlot == null) {
|
||||
internalPlayer = new InternalPlayer();
|
||||
craftSlot = new SlotCrafting(internalPlayer, craftMatrix, craftResult, 0, 0, 0);
|
||||
craftSlot = new SlotCrafting(getInternalPlayer().get(), craftMatrix, craftResult, 0, 0, 0);
|
||||
}
|
||||
if (resultInv.getStackInSlot(SLOT_RESULT) != null) {
|
||||
return;
|
||||
|
@ -269,11 +246,11 @@ public class TileAutoWorkbench extends TileBuildCraft implements ISidedInventory
|
|||
return;
|
||||
}
|
||||
result = result.copy();
|
||||
craftSlot.onPickupFromSlot(internalPlayer, result);
|
||||
craftSlot.onPickupFromSlot(getInternalPlayer().get(), result);
|
||||
resultInv.setInventorySlotContents(SLOT_RESULT, result);
|
||||
|
||||
// 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();
|
||||
if (stack != null) {
|
||||
slot.setStackInSlot(null);
|
||||
|
|
|
@ -13,7 +13,10 @@ import java.util.List;
|
|||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.BuildCraftFactory;
|
||||
import buildcraft.api.gates.IAction;
|
||||
|
@ -36,6 +39,10 @@ public class TileMiningWell extends TileBuildCraft implements IMachine {
|
|||
*/
|
||||
@Override
|
||||
public void updateEntity () {
|
||||
if (worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
float mj = BuildCraftFactory.MINING_MJ_COST_PER_BLOCK * BuildCraftFactory.miningMultiplier;
|
||||
|
||||
if (mjStored < mj) {
|
||||
|
@ -59,7 +66,7 @@ public class TileMiningWell extends TileBuildCraft implements IMachine {
|
|||
|
||||
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);
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
import net.minecraftforge.common.ForgeChunkManager;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||
|
@ -415,7 +416,7 @@ public class TileQuarry extends TileAbstractBuilder implements IMachine {
|
|||
|
||||
// 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) {
|
||||
for (ItemStack s : stacks) {
|
||||
|
|
|
@ -8,12 +8,12 @@
|
|||
*/
|
||||
package buildcraft.silicon;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
|
@ -26,8 +26,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
@ -47,6 +46,7 @@ import buildcraft.core.inventory.filters.CraftingFilter;
|
|||
import buildcraft.core.inventory.filters.IStackFilter;
|
||||
import buildcraft.core.network.PacketIds;
|
||||
import buildcraft.core.network.PacketSlotChange;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.triggers.ActionMachineControl;
|
||||
import buildcraft.core.utils.CraftingHelper;
|
||||
import buildcraft.core.utils.StringUtils;
|
||||
|
@ -64,7 +64,6 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
private SlotCrafting craftSlot;
|
||||
private boolean craftable;
|
||||
private boolean justCrafted;
|
||||
private InternalPlayer internalPlayer;
|
||||
private IRecipe currentRecipe;
|
||||
private TileBuffer[] cache;
|
||||
private InventoryCraftResult craftResult;
|
||||
|
@ -90,6 +89,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
@Override
|
||||
public void setInventorySlotContents(int slotId, ItemStack itemstack) {
|
||||
super.setInventorySlotContents(slotId, itemstack);
|
||||
|
||||
if (TileAdvancedCraftingTable.this.getWorldObj() == null || !TileAdvancedCraftingTable.this.getWorldObj().isRemote) {
|
||||
oreIDs[slotId] = itemstack == null ? -1 : OreDictionary.getOreID(itemstack);
|
||||
}
|
||||
|
@ -139,9 +139,11 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
return result;
|
||||
} else {
|
||||
ItemStack result = tempStacks[bindings[slot]].splitStack(amount);
|
||||
|
||||
if (tempStacks[bindings[slot]].stackSize <= 0) {
|
||||
tempStacks[bindings[slot]] = null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
|
@ -154,28 +156,8 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
}
|
||||
}
|
||||
|
||||
private final class InternalPlayer extends EntityPlayer {
|
||||
|
||||
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 WeakReference<EntityPlayer> getInternalPlayer() {
|
||||
return CoreProxy.proxy.getBuildCraftPlayer((WorldServer) worldObj, xCoord, yCoord + 1, zCoord);
|
||||
}
|
||||
|
||||
public TileAdvancedCraftingTable() {
|
||||
|
@ -241,10 +223,14 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
if (internalPlayer == null) {
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (internalInventoryCrafting == null) {
|
||||
internalInventoryCrafting = new InternalInventoryCrafting();
|
||||
internalPlayer = new InternalPlayer();
|
||||
craftSlot = new SlotCrafting(internalPlayer, internalInventoryCrafting, craftResult, 0, 0, 0);
|
||||
craftSlot = new SlotCrafting(getInternalPlayer().get(), internalInventoryCrafting, craftResult, 0, 0, 0);
|
||||
updateRecipe();
|
||||
}
|
||||
if (worldObj.isRemote) {
|
||||
|
@ -286,16 +272,21 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
internalInventoryCrafting.tempStacks = new InventoryCopy(inv).getItemStacks();
|
||||
internalInventoryCrafting.hitCount = new int[internalInventoryCrafting.tempStacks.length];
|
||||
ItemStack[] inputSlots = internalInventoryCrafting.tempStacks;
|
||||
|
||||
for (int gridSlot = 0; gridSlot < craftingSlots.getSizeInventory(); gridSlot++) {
|
||||
internalInventoryCrafting.bindings[gridSlot] = -1;
|
||||
|
||||
if (craftingSlots.getStackInSlot(gridSlot) == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean foundMatch = false;
|
||||
|
||||
for (int inputSlot = 0; inputSlot < inputSlots.length; inputSlot++) {
|
||||
if (!isMatchingIngredient(gridSlot, inputSlot)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (internalInventoryCrafting.hitCount[inputSlot] < inputSlots[inputSlot].stackSize
|
||||
&& internalInventoryCrafting.hitCount[inputSlot] < inputSlots[inputSlot].getMaxStackSize()) {
|
||||
internalInventoryCrafting.bindings[gridSlot] = inputSlot;
|
||||
|
@ -304,6 +295,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundMatch) {
|
||||
return;
|
||||
}
|
||||
|
@ -312,16 +304,16 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
|
||||
private boolean isMatchingIngredient(int gridSlot, int inputSlot) {
|
||||
ItemStack inputStack = internalInventoryCrafting.tempStacks[inputSlot];
|
||||
|
||||
if (inputStack == null) {
|
||||
return false;
|
||||
}
|
||||
if (StackHelper.isMatchingItem(craftingSlots.getStackInSlot(gridSlot), inputStack, true, false)) {
|
||||
} else if (StackHelper.isMatchingItem(craftingSlots.getStackInSlot(gridSlot), inputStack, true, false)) {
|
||||
return true;
|
||||
}
|
||||
if (StackHelper.isCraftingEquivalent(craftingSlots.oreIDs[gridSlot], inputStack)) {
|
||||
} else if (StackHelper.isCraftingEquivalent(craftingSlots.oreIDs[gridSlot], inputStack)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean hasIngredients() {
|
||||
|
@ -329,28 +321,36 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
}
|
||||
|
||||
private void craftItem() {
|
||||
EntityPlayer internalPlayer = getInternalPlayer().get();
|
||||
ItemStack recipeOutput = getRecipeOutput();
|
||||
craftSlot.onPickupFromSlot(internalPlayer, recipeOutput);
|
||||
ItemStack[] tempStorage = internalInventoryCrafting.tempStacks;
|
||||
|
||||
for (int i = 0; i < tempStorage.length; i++) {
|
||||
if (tempStorage[i] != null && tempStorage[i].stackSize <= 0) {
|
||||
tempStorage[i] = null;
|
||||
}
|
||||
|
||||
inv.getItemStacks()[i] = tempStorage[i];
|
||||
}
|
||||
|
||||
subtractEnergy(getRequiredEnergy());
|
||||
List<ItemStack> outputs = Lists.newArrayList(recipeOutput.copy());
|
||||
|
||||
for (int i = 0; i < internalPlayer.inventory.mainInventory.length; i++) {
|
||||
if (internalPlayer.inventory.mainInventory[i] != null) {
|
||||
outputs.add(internalPlayer.inventory.mainInventory[i]);
|
||||
internalPlayer.inventory.mainInventory[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStack output : outputs) {
|
||||
output.stackSize -= Transactor.getTransactorFor(invOutput).add(output, ForgeDirection.UP, true).stackSize;
|
||||
|
||||
if (output.stackSize > 0) {
|
||||
output.stackSize -= Utils.addToRandomInventoryAround(worldObj, xCoord, yCoord, zCoord, output);
|
||||
}
|
||||
|
||||
if (output.stackSize > 0) {
|
||||
InvUtils.dropItems(worldObj, output, xCoord, yCoord + 1, zCoord);
|
||||
}
|
||||
|
@ -361,18 +361,24 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
if (cache == null) {
|
||||
cache = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, false);
|
||||
}
|
||||
|
||||
for (IInvSlot slot : InventoryIterator.getIterable(craftingSlots, ForgeDirection.UP)) {
|
||||
ItemStack ingred = slot.getStackInSlot();
|
||||
|
||||
if (ingred == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
IStackFilter filter = new CraftingFilter(ingred);
|
||||
|
||||
if (InvUtils.countItems(invInput, ForgeDirection.UP, filter) < InvUtils.countItems(craftingSlots, ForgeDirection.UP, filter)) {
|
||||
for (ForgeDirection side : SEARCH_SIDES) {
|
||||
TileEntity tile = cache[side.ordinal()].getTile();
|
||||
|
||||
if (tile instanceof IInventory) {
|
||||
IInventory inv = InvUtils.getInventory((IInventory) tile);
|
||||
ItemStack result = InvUtils.moveOneItem(inv, side.getOpposite(), invInput, side, filter);
|
||||
|
||||
if (result != null) {
|
||||
return;
|
||||
}
|
||||
|
@ -385,6 +391,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
public void updateCraftingMatrix(int slot, ItemStack stack) {
|
||||
craftingSlots.setInventorySlotContents(slot, stack);
|
||||
updateRecipe();
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
PacketSlotChange packet = new PacketSlotChange(PacketIds.ADVANCED_WORKBENCH_SETSLOT, xCoord, yCoord, zCoord, slot, stack);
|
||||
BuildCraftSilicon.instance.sendToServer(packet);
|
||||
|
@ -395,10 +402,13 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
if (internalInventoryCrafting == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
internalInventoryCrafting.recipeUpdate(true);
|
||||
|
||||
if (this.currentRecipe == null || !this.currentRecipe.matches(internalInventoryCrafting, worldObj)) {
|
||||
currentRecipe = CraftingHelper.findMatchingRecipe(internalInventoryCrafting, worldObj);
|
||||
}
|
||||
|
||||
internalInventoryCrafting.recipeUpdate(false);
|
||||
markDirty();
|
||||
}
|
||||
|
@ -408,12 +418,15 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
craftResult.setInventorySlotContents(0, null);
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack resultStack = getRecipeOutput();
|
||||
|
||||
if (resultStack == null) {
|
||||
internalInventoryCrafting.recipeUpdate(true);
|
||||
resultStack = getRecipeOutput();
|
||||
internalInventoryCrafting.recipeUpdate(false);
|
||||
}
|
||||
|
||||
craftResult.setInventorySlotContents(0, resultStack);
|
||||
markDirty();
|
||||
}
|
||||
|
@ -421,8 +434,9 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
private ItemStack getRecipeOutput() {
|
||||
if (internalInventoryCrafting == null || currentRecipe == null) {
|
||||
return null;
|
||||
} else {
|
||||
return currentRecipe.getCraftingResult(internalInventoryCrafting);
|
||||
}
|
||||
return currentRecipe.getCraftingResult(internalInventoryCrafting);
|
||||
}
|
||||
|
||||
public IInventory getCraftingSlots() {
|
||||
|
|
|
@ -22,7 +22,10 @@ import net.minecraft.item.ItemBucket;
|
|||
import net.minecraft.item.ItemPotion;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.BuildCraftTransport;
|
||||
import buildcraft.api.core.IIconProvider;
|
||||
import buildcraft.api.core.Position;
|
||||
|
@ -102,13 +105,13 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> {
|
|||
if (convertPipe(transport, event.item)) {
|
||||
BuildCraftTransport.pipeItemsStripes.onItemUse(new ItemStack(
|
||||
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
|
||||
);
|
||||
} else if (stack.getItem() instanceof ItemBlock) {
|
||||
if (getWorld().getBlock((int) p.x, (int) p.y, (int) p.z) == Blocks.air) {
|
||||
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,
|
||||
0.0f);
|
||||
}
|
||||
|
@ -118,13 +121,14 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> {
|
|||
if (block instanceof BlockLeavesBase) {
|
||||
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);
|
||||
stack.damageItem(1, CoreProxy.proxy.getBuildCraftPlayer(getWorld()));
|
||||
stack.damageItem(1, CoreProxy.proxy.getBuildCraftPlayer((WorldServer) getWorld()).get());
|
||||
}
|
||||
} else if (stack.getItem() == Items.arrow) {
|
||||
stack.stackSize--;
|
||||
|
||||
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.setDamage(3);
|
||||
entityArrow.setKnockbackStrength(1);
|
||||
|
@ -135,8 +139,8 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> {
|
|||
} else if ((stack.getItem() == Items.potionitem && ItemPotion.isSplash(stack.getItemDamage()))
|
||||
|| stack.getItem() == Items.egg
|
||||
|| stack.getItem() == Items.snowball) {
|
||||
EntityPlayer player = CoreProxy.proxy.getBuildCraftPlayer(getWorld(),
|
||||
(int) p.x, (int) p.y, (int) p.z);
|
||||
EntityPlayer player = CoreProxy.proxy.getBuildCraftPlayer((WorldServer) getWorld(),
|
||||
(int) p.x, (int) p.y, (int) p.z).get();
|
||||
|
||||
switch (event.direction) {
|
||||
case DOWN:
|
||||
|
@ -170,8 +174,8 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> {
|
|||
stack.getItem().onItemRightClick(
|
||||
stack,
|
||||
getWorld(),
|
||||
CoreProxy.proxy.getBuildCraftPlayer(getWorld(),
|
||||
(int) p.x, (int) p.y, (int) p.z));
|
||||
CoreProxy.proxy.getBuildCraftPlayer((WorldServer) getWorld(),
|
||||
(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) {
|
||||
if (stack.getItem() instanceof ItemBucket) {
|
||||
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 {
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
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,
|
||||
0.0f);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue