Merge pull request #940 from binnie567/master

Changed Facades to store data in NBT. Changed recipe packets of Assembly Table to PacketNBT.
This commit is contained in:
SirSengir 2013-06-14 10:16:55 -07:00
commit ecf70dd0f6
7 changed files with 69 additions and 57 deletions

View file

@ -10,7 +10,9 @@ public class PacketIds {
public static final int REQUEST_ITEM_NBT = 5;
public static final int PIPE_ITEM_NBT = 6;
public static final int SELECTION_ASSEMBLY_GET = 20;
/** Packet sent to server when a recipe is clicked on in the assembly table */
public static final int SELECTION_ASSEMBLY = 21;
/** Packet to send recipes to client */
public static final int SELECTION_ASSEMBLY_SEND = 22;
public static final int DIAMOND_PIPE_SELECT = 31;
public static final int EMERALD_PIPE_SELECT = 32;

View file

@ -19,6 +19,7 @@ import buildcraft.core.DefaultProps;
import buildcraft.core.IMachine;
import buildcraft.core.inventory.StackHelper;
import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketNBT;
import buildcraft.core.network.PacketUpdate;
import buildcraft.core.network.TileNetworkData;
import buildcraft.core.network.TilePacketWrapper;
@ -38,23 +39,23 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor
public static class SelectionMessage {
/**
* If true, select, if false, unselect
*/
@TileNetworkData
public boolean select = true;
/**
* Id of the item to be crafted
*/
@TileNetworkData
public int itemID = 0;
/**
* Dmg of the item to be crafted
*/
@TileNetworkData
public int itemDmg = 0;
public boolean select;
public ItemStack stack;
public NBTTagCompound getNBT() {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setBoolean("s", select);
NBTTagCompound itemNBT = new NBTTagCompound();
stack.writeToNBT(itemNBT);
nbt.setCompoundTag("i", itemNBT);
return nbt;
}
public void fromNBT(NBTTagCompound nbt) {
select = nbt.getBoolean("s");
NBTTagCompound itemNBT = nbt.getCompoundTag("i");
stack = ItemStack.loadItemStackFromNBT(itemNBT);
}
}
public static TilePacketWrapper selectionMessageWrapper = new TilePacketWrapper(SelectionMessage.class);
public LinkedList<AssemblyRecipe> getPotentialOutputs() {
LinkedList<AssemblyRecipe> result = new LinkedList<AssemblyRecipe>();
@ -353,7 +354,7 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor
public void handleSelectionMessage(SelectionMessage message) {
for (AssemblyRecipe recipe : AssemblyRecipe.assemblyRecipes) {
if (recipe.output.itemID == message.itemID && recipe.output.getItemDamage() == message.itemDmg) {
if (recipe.output.isItemEqual(message.stack) && ItemStack.areItemStackTagsEqual(recipe.output, message.stack)) {
if (message.select) {
planOutput(recipe);
} else {
@ -369,8 +370,7 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor
for (AssemblyRecipe r : AssemblyRecipe.assemblyRecipes) {
SelectionMessage message = new SelectionMessage();
message.itemID = r.output.itemID;
message.itemDmg = r.output.getItemDamage();
message.stack = r.output;
if (isPlanned(r)) {
message.select = true;
@ -378,7 +378,7 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor
message.select = false;
}
PacketUpdate packet = new PacketUpdate(PacketIds.SELECTION_ASSEMBLY_SEND, selectionMessageWrapper.toPayload(xCoord, yCoord, zCoord, message));
PacketNBT packet = new PacketNBT(PacketIds.SELECTION_ASSEMBLY_SEND, message.getNBT(), xCoord, yCoord, zCoord);
packet.posX = xCoord;
packet.posY = yCoord;
packet.posZ = zCoord;

View file

@ -25,6 +25,7 @@ import buildcraft.core.DefaultProps;
import buildcraft.core.gui.GuiAdvancedInterface;
import buildcraft.core.network.PacketCoordinates;
import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketNBT;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketUpdate;
import buildcraft.core.proxy.CoreProxy;
@ -193,17 +194,11 @@ public class GuiAssemblyTable extends GuiAdvancedInterface {
message.select = true;
}
message.itemID = slot.recipe.output.itemID;
message.itemDmg = slot.recipe.output.getItemDamage();
message.stack = slot.recipe.output;
if (CoreProxy.proxy.isRenderWorld(assemblyTable.worldObj)) {
PacketPayload payload = TileAssemblyTable.selectionMessageWrapper.toPayload(assemblyTable.xCoord, assemblyTable.yCoord, assemblyTable.zCoord,
message);
PacketUpdate packet = new PacketUpdate(PacketIds.SELECTION_ASSEMBLY, payload);
packet.posX = assemblyTable.xCoord;
packet.posY = assemblyTable.yCoord;
packet.posZ = assemblyTable.zCoord;
PacketNBT packet = new PacketNBT(PacketIds.SELECTION_ASSEMBLY, message.getNBT(), assemblyTable.xCoord, assemblyTable.yCoord, assemblyTable.zCoord);
CoreProxy.proxy.sendToServer(packet.getPacket());
}

View file

@ -11,6 +11,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import buildcraft.core.network.PacketCoordinates;
import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketNBT;
import buildcraft.core.network.PacketSlotChange;
import buildcraft.core.network.PacketUpdate;
import buildcraft.silicon.TileAdvancedCraftingTable;
@ -30,13 +31,13 @@ public class PacketHandlerSilicon implements IPacketHandler {
int packetID = data.read();
switch (packetID) {
case PacketIds.SELECTION_ASSEMBLY_SEND:
PacketUpdate packetT = new PacketUpdate();
PacketNBT packetT = new PacketNBT();
packetT.readData(data);
onSelectionUpdate((EntityPlayer) player, packetT);
break;
case PacketIds.SELECTION_ASSEMBLY:
PacketUpdate packetA = new PacketUpdate();
PacketNBT packetA = new PacketNBT();
packetA.readData(data);
onAssemblySelect((EntityPlayer) player, packetA);
break;
@ -58,13 +59,13 @@ public class PacketHandlerSilicon implements IPacketHandler {
}
private void onSelectionUpdate(EntityPlayer player, PacketUpdate packet) {
private void onSelectionUpdate(EntityPlayer player, PacketNBT packet) {
Container container = player.openContainer;
if (container instanceof ContainerAssemblyTable) {
SelectionMessage message = new SelectionMessage();
TileAssemblyTable.selectionMessageWrapper.fromPayload(message, packet.payload);
message.fromNBT(packet.getTagCompound());
((ContainerAssemblyTable) container).handleSelectionMessage(message);
}
}
@ -112,16 +113,16 @@ public class PacketHandlerSilicon implements IPacketHandler {
* Sets the selection on an assembly table according to player request.
*
* @param player
* @param packet
* @param packetA
*/
private void onAssemblySelect(EntityPlayer player, PacketUpdate packet) {
private void onAssemblySelect(EntityPlayer player, PacketNBT packetA) {
TileAssemblyTable tile = getAssemblyTable(player.worldObj, packet.posX, packet.posY, packet.posZ);
TileAssemblyTable tile = getAssemblyTable(player.worldObj, packetA.posX, packetA.posY, packetA.posZ);
if (tile == null)
return;
TileAssemblyTable.SelectionMessage message = new TileAssemblyTable.SelectionMessage();
TileAssemblyTable.selectionMessageWrapper.fromPayload(message, packet.payload);
message.fromNBT(packetA.getTagCompound());
tile.handleSelectionMessage(message);
}

View file

@ -12,6 +12,7 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
@ -43,8 +44,8 @@ public class ItemFacade extends ItemBuildCraft {
@Override
public String getItemDisplayName(ItemStack itemstack) {
String name = super.getItemDisplayName(itemstack);
int decodedBlockId = ItemFacade.getBlockId(itemstack.getItemDamage());
int decodedMeta = ItemFacade.getMetaData(itemstack.getItemDamage());
int decodedBlockId = ItemFacade.getBlockId(itemstack);
int decodedMeta = ItemFacade.getMetaData(itemstack);
if (decodedBlockId < Block.blocksList.length && Block.blocksList[decodedBlockId] != null && Block.blocksList[decodedBlockId].getRenderType() == 31) {
decodedMeta &= 0x3;
}
@ -87,8 +88,8 @@ public class ItemFacade extends ItemBuildCraft {
pipeTile.dropFacade(ForgeDirection.VALID_DIRECTIONS[side]);
return true;
} else {
if (((TileGenericPipe) tile).addFacade(ForgeDirection.values()[side], ItemFacade.getBlockId(stack.getItemDamage()),
ItemFacade.getMetaData(stack.getItemDamage()))) {
if (((TileGenericPipe) tile).addFacade(ForgeDirection.values()[side], ItemFacade.getBlockId(stack),
ItemFacade.getMetaData(stack))) {
if (!player.capabilities.isCreativeMode) {
stack.stackSize--;
}
@ -137,16 +138,16 @@ public class ItemFacade extends ItemBuildCraft {
}
}
public static int encode(int blockId, int metaData) {
return metaData & 0xF | ((blockId & 0xFFF) << 4);
public static int getMetaData(ItemStack stack) {
if(stack.hasTagCompound() && stack.getTagCompound().hasKey("meta"))
return stack.getTagCompound().getInteger("meta");
return stack.getItemDamage() & 0x0000F;
}
public static int getMetaData(int encoded) {
return encoded & 0x0000F;
}
public static int getBlockId(int encoded) {
return ((encoded & 0xFFF0) >>> 4);
public static int getBlockId(ItemStack stack) {
if(stack.hasTagCompound() && stack.getTagCompound().hasKey("id"))
return stack.getTagCompound().getInteger("id");
return ((stack.getItemDamage() & 0xFFF0) >>> 4);
}
@Override
@ -156,19 +157,23 @@ public class ItemFacade extends ItemBuildCraft {
}
public static void addFacade(ItemStack itemStack) {
allFacades.add(new ItemStack(BuildCraftTransport.facadeItem, 1, ItemFacade.encode(itemStack.itemID, itemStack.getItemDamage())));
ItemStack facade = getStack(itemStack.itemID, itemStack.getItemDamage());
allFacades.add(facade);
ItemStack facade6 = facade.copy();
facade6.stackSize = 6;
// 3 Structurepipes + this block makes 6 facades
AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] { new ItemStack(BuildCraftTransport.pipeStructureCobblestone, 3), itemStack },
8000, new ItemStack(BuildCraftTransport.facadeItem, 6, ItemFacade.encode(itemStack.itemID, itemStack.getItemDamage()))));
8000, facade6));
if (itemStack.itemID < Block.blocksList.length && Block.blocksList[itemStack.itemID] != null) {
Block bl = Block.blocksList[itemStack.itemID];
// Special handling for logs
if (bl.getRenderType() == 31) {
ItemStack mainLog = new ItemStack(BuildCraftTransport.facadeItem, 1, ItemFacade.encode(itemStack.itemID, itemStack.getItemDamage()));
ItemStack rotLog1 = new ItemStack(BuildCraftTransport.facadeItem, 1, ItemFacade.encode(itemStack.itemID, itemStack.getItemDamage() | 4));
ItemStack rotLog2 = new ItemStack(BuildCraftTransport.facadeItem, 1, ItemFacade.encode(itemStack.itemID, itemStack.getItemDamage() | 8));
ItemStack mainLog = getStack(itemStack.itemID, itemStack.getItemDamage());
ItemStack rotLog1 = getStack(itemStack.itemID, itemStack.getItemDamage() | 4);
ItemStack rotLog2 = getStack(itemStack.itemID, itemStack.getItemDamage() | 8);
allFacades.add(rotLog1);
allFacades.add(rotLog2);
CoreProxy.proxy.addShapelessRecipe(rotLog1, new Object[] { mainLog });
@ -191,4 +196,13 @@ public class ItemFacade extends ItemBuildCraft {
{
return 0;
}
public static ItemStack getStack(int blockID, int metadata) {
ItemStack stack = new ItemStack(BuildCraftTransport.facadeItem, 1, 0);
NBTTagCompound nbt = new NBTTagCompound("tag");
nbt.setInteger("meta", metadata);
nbt.setInteger("id", blockID);
stack.setTagCompound(nbt);
return stack;
}
}

View file

@ -604,7 +604,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
}
private void dropFacadeItem(ForgeDirection direction){
Utils.dropItems(worldObj, new ItemStack(BuildCraftTransport.facadeItem, 1, ItemFacade.encode(this.facadeBlocks[direction.ordinal()], this.facadeMeta[direction.ordinal()])), this.xCoord, this.yCoord, this.zCoord);
Utils.dropItems(worldObj, ItemFacade.getStack(this.facadeBlocks[direction.ordinal()], this.facadeMeta[direction.ordinal()]), this.xCoord, this.yCoord, this.zCoord);
}
public void dropFacade(ForgeDirection direction) {

View file

@ -17,9 +17,9 @@ import buildcraft.transport.PipeIconProvider;
public class FacadeItemRenderer implements IItemRenderer {
private void renderFacadeItem(RenderBlocks render, ItemStack item, float translateX, float translateY, float translateZ) {
int decodedMeta = ItemFacade.getMetaData(item.getItemDamage());
int decodedBlockId = ItemFacade.getBlockId(item.getItemDamage());
int decodedMeta = ItemFacade.getMetaData(item);
int decodedBlockId = ItemFacade.getBlockId(item);
Tessellator tessellator = Tessellator.instance;