Battery bugfixes
This commit is contained in:
parent
0134b505d2
commit
75b1a9804d
5 changed files with 81 additions and 31 deletions
|
@ -18,7 +18,7 @@ public class SetUtil
|
||||||
Set<V> toReturn = new HashSet<V>();
|
Set<V> toReturn = new HashSet<V>();
|
||||||
List list = Arrays.asList(set.toArray());
|
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));
|
toReturn.add((V)list.get(i));
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,10 @@ public class SetUtil
|
||||||
{
|
{
|
||||||
for(V obj : set)
|
for(V obj : set)
|
||||||
{
|
{
|
||||||
return obj;
|
if(obj != null)
|
||||||
|
{
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -235,6 +235,7 @@ public class BatteryUpdateProtocol
|
||||||
if(!didVisibleInventory)
|
if(!didVisibleInventory)
|
||||||
{
|
{
|
||||||
tile.structure.visibleInventory = oldStructure.visibleInventory;
|
tile.structure.visibleInventory = oldStructure.visibleInventory;
|
||||||
|
didVisibleInventory = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,9 @@ package resonantinduction.battery;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.inventory.ICrafting;
|
||||||
import net.minecraft.inventory.Slot;
|
import net.minecraft.inventory.Slot;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import resonantinduction.battery.BatteryManager.SlotBattery;
|
import resonantinduction.battery.BatteryManager.SlotBattery;
|
||||||
import resonantinduction.battery.BatteryManager.SlotOut;
|
import resonantinduction.battery.BatteryManager.SlotOut;
|
||||||
|
|
||||||
|
@ -37,6 +39,26 @@ public class ContainerBattery extends Container
|
||||||
tileEntity.openChest();
|
tileEntity.openChest();
|
||||||
tileEntity.playersUsing.add(inventory.player);
|
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
|
@Override
|
||||||
public void onContainerClosed(EntityPlayer entityplayer)
|
public void onContainerClosed(EntityPlayer entityplayer)
|
||||||
|
|
|
@ -27,11 +27,13 @@ public class SynchronizedBatteryData
|
||||||
|
|
||||||
public int height;
|
public int height;
|
||||||
|
|
||||||
|
public ItemStack tempStack;
|
||||||
|
|
||||||
public boolean isMultiblock;
|
public boolean isMultiblock;
|
||||||
|
|
||||||
public boolean didTick;
|
public boolean didTick;
|
||||||
|
|
||||||
public boolean wroteVisibleInventory;
|
public boolean wroteInventory;
|
||||||
|
|
||||||
public int getVolume()
|
public int getVolume()
|
||||||
{
|
{
|
||||||
|
@ -49,7 +51,7 @@ public class SynchronizedBatteryData
|
||||||
|
|
||||||
ItemStack[] toSort = new ItemStack[array.length];
|
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];
|
toSort[i] = (ItemStack)array[i];
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,14 +89,17 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
||||||
super.readFromNBT(nbtTags);
|
super.readFromNBT(nbtTags);
|
||||||
|
|
||||||
//Main inventory
|
//Main inventory
|
||||||
NBTTagList tagList = nbtTags.getTagList("Items");
|
if(nbtTags.hasKey("Items"))
|
||||||
structure.inventory = new HashSet<ItemStack>();
|
|
||||||
|
|
||||||
for(int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
|
|
||||||
{
|
{
|
||||||
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
|
//Visible inventory
|
||||||
|
@ -123,24 +126,24 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
||||||
{
|
{
|
||||||
super.writeToNBT(nbtTags);
|
super.writeToNBT(nbtTags);
|
||||||
|
|
||||||
//Inventory
|
if(!structure.wroteInventory)
|
||||||
NBTTagList tagList = new NBTTagList();
|
|
||||||
|
|
||||||
for(ItemStack itemStack : structure.inventory)
|
|
||||||
{
|
|
||||||
if(itemStack != null)
|
|
||||||
{
|
|
||||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
|
||||||
itemStack.writeToNBT(tagCompound);
|
|
||||||
tagList.appendTag(tagCompound);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nbtTags.setTag("Items", tagList);
|
|
||||||
|
|
||||||
//Visible inventory
|
|
||||||
if(!structure.wroteVisibleInventory)
|
|
||||||
{
|
{
|
||||||
|
//Inventory
|
||||||
|
NBTTagList tagList = new NBTTagList();
|
||||||
|
|
||||||
|
for(ItemStack itemStack : structure.inventory)
|
||||||
|
{
|
||||||
|
if(itemStack != null)
|
||||||
|
{
|
||||||
|
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||||
|
itemStack.writeToNBT(tagCompound);
|
||||||
|
tagList.appendTag(tagCompound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nbtTags.setTag("Items", tagList);
|
||||||
|
|
||||||
|
//Visible inventory
|
||||||
NBTTagList tagList1 = new NBTTagList();
|
NBTTagList tagList1 = new NBTTagList();
|
||||||
|
|
||||||
for(int slotCount = 0; slotCount < structure.visibleInventory.length; slotCount++)
|
for(int slotCount = 0; slotCount < structure.visibleInventory.length; slotCount++)
|
||||||
|
@ -155,7 +158,8 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
||||||
}
|
}
|
||||||
|
|
||||||
nbtTags.setTag("VisibleItems", tagList1);
|
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)
|
else if(i == 1)
|
||||||
{
|
{
|
||||||
return SetUtil.getTop(structure.inventory);
|
if(!worldObj.isRemote)
|
||||||
|
{
|
||||||
|
return SetUtil.getTop(structure.inventory);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return structure.tempStack;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return structure.visibleInventory[i-1];
|
return structure.visibleInventory[i-1];
|
||||||
|
@ -339,7 +349,19 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
||||||
{
|
{
|
||||||
if(itemstack == null)
|
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 {
|
else {
|
||||||
|
|
Loading…
Reference in a new issue