Workaround for a bug that broke the packet handling

This commit is contained in:
Ellpeck 2016-01-11 22:33:54 +01:00
parent dbf8093ea0
commit 85428e885d
2 changed files with 43 additions and 30 deletions

View file

@ -39,6 +39,8 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
private boolean activateOnceWithSignal;
private int oldEnergy;
public boolean syncSlotsNextTime;
public TileEntityAtomicReconstructor(){
super(1, "reconstructor");
}
@ -109,11 +111,12 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
super.writeSyncableNBT(compound, sync);
compound.setInteger("CurrentTime", this.currentTime);
this.storage.writeToNBT(compound);
}
@Override
public boolean shouldSyncSlots(){
return true;
if(this.syncSlotsNextTime){
this.writeSlotsToCompound(compound);
compound.setBoolean("ShouldSync", true);
this.syncSlotsNextTime = false;
}
}
@Override
@ -121,16 +124,22 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
super.readSyncableNBT(compound, sync);
this.currentTime = compound.getInteger("CurrentTime");
this.storage.readFromNBT(compound);
if(compound.getBoolean("ShouldSync")){
this.readSlotsFromCompound(compound);
}
}
@Override
public void setInventorySlotContents(int i, ItemStack stack){
super.setInventorySlotContents(i, stack);
this.syncSlotsNextTime = true;
this.sendUpdate();
}
@Override
public ItemStack decrStackSize(int i, int j){
this.syncSlotsNextTime = true;
this.sendUpdate();
return super.decrStackSize(i, j);
}

View file

@ -41,7 +41,20 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
@Override
public void writeSyncableNBT(NBTTagCompound compound, boolean isForSync){
super.writeSyncableNBT(compound, isForSync);
if(!isForSync || this.shouldSyncSlots()){
if(!isForSync){
this.writeSlotsToCompound(compound);
}
}
@Override
public void readSyncableNBT(NBTTagCompound compound, boolean isForSync){
super.readSyncableNBT(compound, isForSync);
if(!isForSync){
this.readSlotsFromCompound(compound);
}
}
public void writeSlotsToCompound(NBTTagCompound compound){
if(this.slots.length > 0){
NBTTagList tagList = new NBTTagList();
for(int currentIndex = 0; currentIndex < slots.length; currentIndex++){
@ -55,16 +68,8 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
compound.setTag("Items", tagList);
}
}
}
public boolean shouldSyncSlots(){
return false;
}
@Override
public void readSyncableNBT(NBTTagCompound compound, boolean isForSync){
super.readSyncableNBT(compound, isForSync);
if(!isForSync || this.shouldSyncSlots()){
public void readSlotsFromCompound(NBTTagCompound compound){
if(this.slots.length > 0){
NBTTagList tagList = compound.getTagList("Items", 10);
for(int i = 0; i < tagList.tagCount(); i++){
@ -76,7 +81,6 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
}
}
}
}
@Override
public int getInventoryStackLimit(){