Battery bugfixes

This commit is contained in:
Aidan Brady 2013-08-05 01:29:39 -04:00
parent 0134b505d2
commit 75b1a9804d
5 changed files with 81 additions and 31 deletions

View file

@ -18,7 +18,7 @@ public class SetUtil
Set<V> toReturn = new HashSet<V>();
List list = Arrays.asList(set.toArray());
for(int i = list.size()-1; i >= 0; i--)
for(int i = list.size(); i >= 0; i--)
{
toReturn.add((V)list.get(i));
}
@ -189,7 +189,10 @@ public class SetUtil
{
for(V obj : set)
{
return obj;
if(obj != null)
{
return obj;
}
}
return null;

View file

@ -235,6 +235,7 @@ public class BatteryUpdateProtocol
if(!didVisibleInventory)
{
tile.structure.visibleInventory = oldStructure.visibleInventory;
didVisibleInventory = true;
}
}
}

View file

@ -3,7 +3,9 @@ package resonantinduction.battery;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import resonantinduction.battery.BatteryManager.SlotBattery;
import resonantinduction.battery.BatteryManager.SlotOut;
@ -38,6 +40,26 @@ public class ContainerBattery extends Container
tileEntity.playersUsing.add(inventory.player);
}
@Override
public ItemStack slotClick(int slotID, int par2, int par3, EntityPlayer par4EntityPlayer)
{
ItemStack stack = super.slotClick(slotID, par2, par3, par4EntityPlayer);
if(slotID == 1)
{
ItemStack itemstack = ((Slot)inventorySlots.get(slotID)).getStack();
ItemStack itemstack1 = itemstack == null ? null : itemstack.copy();
inventoryItemStacks.set(slotID, itemstack1);
for (int j = 0; j < this.crafters.size(); ++j)
{
((ICrafting)this.crafters.get(j)).sendSlotContents(this, slotID, itemstack1);
}
}
return stack;
}
@Override
public void onContainerClosed(EntityPlayer entityplayer)
{

View file

@ -27,11 +27,13 @@ public class SynchronizedBatteryData
public int height;
public ItemStack tempStack;
public boolean isMultiblock;
public boolean didTick;
public boolean wroteVisibleInventory;
public boolean wroteInventory;
public int getVolume()
{
@ -49,7 +51,7 @@ public class SynchronizedBatteryData
ItemStack[] toSort = new ItemStack[array.length];
for(int i = 0; i < array.length-1; i++)
for(int i = 0; i < array.length; i++)
{
toSort[i] = (ItemStack)array[i];
}

View file

@ -89,14 +89,17 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
super.readFromNBT(nbtTags);
//Main inventory
NBTTagList tagList = nbtTags.getTagList("Items");
structure.inventory = new HashSet<ItemStack>();
for(int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
if(nbtTags.hasKey("Items"))
{
NBTTagCompound tagCompound = (NBTTagCompound)tagList.tagAt(tagCount);
NBTTagList tagList = nbtTags.getTagList("Items");
structure.inventory = new HashSet<ItemStack>();
structure.inventory.add(ItemStack.loadItemStackFromNBT(tagCompound));
for(int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
{
NBTTagCompound tagCompound = (NBTTagCompound)tagList.tagAt(tagCount);
structure.inventory.add(ItemStack.loadItemStackFromNBT(tagCompound));
}
}
//Visible inventory
@ -123,24 +126,24 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
{
super.writeToNBT(nbtTags);
//Inventory
NBTTagList tagList = new NBTTagList();
for(ItemStack itemStack : structure.inventory)
if(!structure.wroteInventory)
{
if(itemStack != null)
{
NBTTagCompound tagCompound = new NBTTagCompound();
itemStack.writeToNBT(tagCompound);
tagList.appendTag(tagCompound);
}
}
//Inventory
NBTTagList tagList = new NBTTagList();
nbtTags.setTag("Items", tagList);
for(ItemStack itemStack : structure.inventory)
{
if(itemStack != null)
{
NBTTagCompound tagCompound = new NBTTagCompound();
itemStack.writeToNBT(tagCompound);
tagList.appendTag(tagCompound);
}
}
//Visible inventory
if(!structure.wroteVisibleInventory)
{
nbtTags.setTag("Items", tagList);
//Visible inventory
NBTTagList tagList1 = new NBTTagList();
for(int slotCount = 0; slotCount < structure.visibleInventory.length; slotCount++)
@ -155,7 +158,8 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
}
nbtTags.setTag("VisibleItems", tagList1);
structure.wroteVisibleInventory = true;
structure.wroteInventory = true;
}
}
@ -286,7 +290,13 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
}
else if(i == 1)
{
return SetUtil.getTop(structure.inventory);
if(!worldObj.isRemote)
{
return SetUtil.getTop(structure.inventory);
}
else {
return structure.tempStack;
}
}
else {
return structure.visibleInventory[i-1];
@ -339,7 +349,19 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
{
if(itemstack == null)
{
structure.inventory.remove(SetUtil.getTop(structure.inventory));
if(!worldObj.isRemote)
{
structure.inventory.remove(SetUtil.getTop(structure.inventory));
}
else {
structure.tempStack = null;
}
}
else {
if(worldObj.isRemote)
{
structure.tempStack = itemstack;
}
}
}
else {