Fixed a Digital Miner oversight, fixed Bins losing NBT data and allow Bins to accept items with varying item damage

This commit is contained in:
Aidan C. Brady 2014-08-05 20:58:22 -04:00
parent 06c66d5fbe
commit 12215490f0
6 changed files with 89 additions and 37 deletions

View file

@ -61,6 +61,11 @@ import mekanism.common.network.PacketWalkieTalkieState;
import mekanism.common.network.PacketWalkieTalkieState.WalkieTalkieStateMessage; import mekanism.common.network.PacketWalkieTalkieState.WalkieTalkieStateMessage;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTSizeTracker;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Vec3; import net.minecraft.util.Vec3;
@ -151,6 +156,14 @@ public class PacketHandler
{ {
output.writeByte((Byte)data); output.writeByte((Byte)data);
} }
else if(data instanceof ItemStack)
{
writeStack(output, (ItemStack)data);
}
else if(data instanceof NBTTagCompound)
{
writeNBT(output, (NBTTagCompound)data);
}
else if(data instanceof int[]) else if(data instanceof int[])
{ {
for(int i : (int[])data) for(int i : (int[])data)
@ -187,6 +200,67 @@ public class PacketHandler
return new String(input.readBytes(input.readInt()).array()); return new String(input.readBytes(input.readInt()).array());
} }
public static void writeStack(ByteBuf output, ItemStack stack)
{
output.writeInt(stack != null ? Item.getIdFromItem(stack.getItem()) : -1);
if(stack != null)
{
output.writeInt(stack.stackSize);
output.writeInt(stack.getItemDamage());
if(stack.getTagCompound() != null && stack.getItem().getShareTag())
{
output.writeBoolean(true);
writeNBT(output, stack.getTagCompound());
}
else {
output.writeBoolean(false);
}
}
}
public static ItemStack readStack(ByteBuf input)
{
int id = input.readInt();
if(id >= 0)
{
ItemStack stack = new ItemStack(Item.getItemById(id), input.readInt(), input.readInt());
if(input.readBoolean())
{
stack.setTagCompound(readNBT(input));
}
return stack;
}
return null;
}
public static void writeNBT(ByteBuf output, NBTTagCompound nbtTags)
{
try {
byte[] buffer = CompressedStreamTools.compress(nbtTags);
output.writeInt(buffer.length);
output.writeBytes(buffer);
} catch(Exception e) {}
}
public static NBTTagCompound readNBT(ByteBuf input)
{
try {
byte[] buffer = new byte[input.readInt()];
input.readBytes(buffer);
return CompressedStreamTools.func_152457_a(buffer, new NBTSizeTracker(2097152L));
} catch(Exception e) {
return null;
}
}
public static EntityPlayer getPlayer(MessageContext context) public static EntityPlayer getPlayer(MessageContext context)
{ {
return Mekanism.proxy.getPlayer(context); return Mekanism.proxy.getPlayer(context);

View file

@ -380,7 +380,7 @@ public class BlockBasic extends Block
if(bin.getItemCount() < bin.MAX_STORAGE) if(bin.getItemCount() < bin.MAX_STORAGE)
{ {
if(bin.addTicks == 0) if(bin.addTicks == 0 && entityplayer.getCurrentEquippedItem() != null)
{ {
if(entityplayer.getCurrentEquippedItem() != null) if(entityplayer.getCurrentEquippedItem() != null)
{ {
@ -389,7 +389,8 @@ public class BlockBasic extends Block
bin.addTicks = 5; bin.addTicks = 5;
} }
} }
else { else if(bin.addTicks > 0 && bin.getItemCount() > 0)
{
ItemStack[] inv = entityplayer.inventory.mainInventory; ItemStack[] inv = entityplayer.inventory.mainInventory;
for(int i = 0; i < inv.length; i++) for(int i = 0; i < inv.length; i++)
@ -403,6 +404,7 @@ public class BlockBasic extends Block
{ {
ItemStack remain = bin.add(inv[i]); ItemStack remain = bin.add(inv[i]);
inv[i] = remain; inv[i] = remain;
bin.addTicks = 5;
} }
((EntityPlayerMP)entityplayer).sendContainerAndContentsToPlayer(entityplayer.openContainer, entityplayer.openContainer.getInventory()); ((EntityPlayerMP)entityplayer).sendContainerAndContentsToPlayer(entityplayer.openContainer, entityplayer.openContainer.getInventory());

View file

@ -1,5 +1,6 @@
package mekanism.common.inventory; package mekanism.common.inventory;
import mekanism.api.StackUtils;
import mekanism.common.item.ItemBlockBasic; import mekanism.common.item.ItemBlockBasic;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -77,11 +78,6 @@ public class InventoryBin
return false; return false;
} }
if(stack.isItemStackDamageable() && stack.isItemDamaged())
{
return false;
}
if(stack.getItem() instanceof ItemBlockBasic && stack.getItemDamage() == 6) if(stack.getItem() instanceof ItemBlockBasic && stack.getItemDamage() == 6)
{ {
return false; return false;
@ -132,16 +128,7 @@ public class InventoryBin
return null; return null;
} }
int id = bin.stackTagCompound.getInteger("itemID"); return ItemStack.loadItemStackFromNBT(bin.stackTagCompound.getCompoundTag("storedItem"));
int meta = bin.stackTagCompound.getInteger("itemMeta");
if(getItemCount() == 0 || id == 0)
{
setItemType(null);
return null;
}
return new ItemStack(Item.getItemById(id), 1, meta);
} }
public void setItemType(ItemStack stack) public void setItemType(ItemStack stack)
@ -153,15 +140,12 @@ public class InventoryBin
if(stack == null) if(stack == null)
{ {
bin.stackTagCompound.removeTag("itemID"); bin.stackTagCompound.removeTag("storedItem");
bin.stackTagCompound.removeTag("itemMeta");
return; return;
} }
ItemStack ret = stack.copy(); ItemStack ret = StackUtils.size(stack, 1);
ret.stackSize = 1;
bin.stackTagCompound.setInteger("itemID", MekanismUtils.getID(stack)); bin.stackTagCompound.setTag("storedItem", StackUtils.size(stack, 1).writeToNBT(new NBTTagCompound()));
bin.stackTagCompound.setInteger("itemMeta", stack.getItemDamage());
} }
} }

View file

@ -4,10 +4,8 @@ import ic2.api.tile.IWrenchable;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import mekanism.api.Coord4D; import mekanism.api.Coord4D;
import mekanism.common.ITileComponent; import mekanism.common.ITileComponent;
@ -33,10 +31,10 @@ public abstract class TileEntityBasicBlock extends TileEntity implements IWrench
public int clientFacing; public int clientFacing;
public Set<EntityPlayer> openedThisTick = Collections.synchronizedSet(new HashSet<EntityPlayer>()); public HashSet<EntityPlayer> openedThisTick = new HashSet<EntityPlayer>();
/** The players currently using this block. */ /** The players currently using this block. */
public Set<EntityPlayer> playersUsing = Collections.synchronizedSet(new HashSet<EntityPlayer>()); public HashSet<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
/** A timer used to send packets to clients. */ /** A timer used to send packets to clients. */
public int ticker; public int ticker;

View file

@ -9,6 +9,7 @@ import mekanism.api.IConfigurable;
import mekanism.common.IActiveState; import mekanism.common.IActiveState;
import mekanism.common.ILogisticalTransporter; import mekanism.common.ILogisticalTransporter;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.item.ItemBlockBasic; import mekanism.common.item.ItemBlockBasic;
import mekanism.common.network.PacketTileEntity.TileEntityMessage; import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.transporter.TransporterManager; import mekanism.common.transporter.TransporterManager;
@ -25,7 +26,6 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.Optional.Interface; import cpw.mods.fml.common.Optional.Interface;
import powercrystals.minefactoryreloaded.api.IDeepStorageUnit; import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
@Interface(iface = "powercrystals.minefactoryreloaded.api.IDeepStorageUnit", modid = "MineFactoryReloaded") @Interface(iface = "powercrystals.minefactoryreloaded.api.IDeepStorageUnit", modid = "MineFactoryReloaded")
@ -95,11 +95,6 @@ public class TileEntityBin extends TileEntityBasicBlock implements ISidedInvento
return false; return false;
} }
if(stack.isItemStackDamageable() && stack.isItemDamaged())
{
return false;
}
if(stack.getItem() instanceof ItemBlockBasic && stack.getItemDamage() == 6) if(stack.getItem() instanceof ItemBlockBasic && stack.getItemDamage() == 6)
{ {
return false; return false;
@ -273,8 +268,7 @@ public class TileEntityBin extends TileEntityBasicBlock implements ISidedInvento
if(getItemCount() > 0) if(getItemCount() > 0)
{ {
data.add(MekanismUtils.getID(itemType)); data.add(itemType);
data.add(itemType.getItemDamage());
} }
return data; return data;
@ -290,7 +284,7 @@ public class TileEntityBin extends TileEntityBasicBlock implements ISidedInvento
if(clientAmount > 0) if(clientAmount > 0)
{ {
itemType = new ItemStack(Item.getItemById(dataStream.readInt()), 1, dataStream.readInt()); itemType = PacketHandler.readStack(dataStream);
} }
else { else {
itemType = null; itemType = null;

View file

@ -118,7 +118,7 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
if(getActive()) if(getActive())
{ {
for(EntityPlayer player : playersUsing) for(EntityPlayer player : (HashSet<EntityPlayer>)playersUsing.clone())
{ {
if(player.openContainer instanceof ContainerNull || player.openContainer instanceof ContainerFilter) if(player.openContainer instanceof ContainerNull || player.openContainer instanceof ContainerFilter)
{ {