mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-19 11:49:08 +00:00
Ensure inventories and multiblock servants mark dirty when contents change
Using a new method markDirtyFast as the vanilla method also does a ton of block updates
This commit is contained in:
1 parent
3ac6614235
commit
458655ada2
3 files changed
+36
-14
No files matched your search
@@ -5,22 +5,19 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
import slimeknights.mantle.tileentity.MantleTileEntity;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class MultiServantLogic extends TileEntity implements IServantLogic {
|
||||
public class MultiServantLogic extends MantleTileEntity implements IServantLogic {
|
||||
|
||||
boolean hasMaster;
|
||||
|
||||
BlockPos master;
|
||||
|
||||
Block masterBlock;
|
||||
|
||||
IBlockState state;
|
||||
|
||||
public boolean canUpdate() {
|
||||
@@ -36,8 +33,8 @@ public class MultiServantLogic extends TileEntity implements IServantLogic {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(this.world.getBlockState(this.master).getBlock() == this.masterBlock && this.world
|
||||
.getBlockState(this.master) == this.state) {
|
||||
if(this.world.getBlockState(this.master).getBlock() == this.masterBlock
|
||||
&& this.world.getBlockState(this.master) == this.state) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
@@ -57,6 +54,7 @@ public class MultiServantLogic extends TileEntity implements IServantLogic {
|
||||
this.master = pos;
|
||||
this.state = this.world.getBlockState(this.master);
|
||||
this.masterBlock = this.state.getBlock();
|
||||
this.markDirtyFast();
|
||||
}
|
||||
|
||||
public void removeMaster() {
|
||||
@@ -64,6 +62,7 @@ public class MultiServantLogic extends TileEntity implements IServantLogic {
|
||||
this.master = null;
|
||||
this.masterBlock = null;
|
||||
this.state = null;
|
||||
this.markDirtyFast();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,8 +72,8 @@ public class MultiServantLogic extends TileEntity implements IServantLogic {
|
||||
|
||||
@Deprecated
|
||||
public boolean verifyMaster(IMasterLogic logic, BlockPos pos) {
|
||||
return this.master.equals(pos) && this.world.getBlockState(pos) == this.state && this.world.getBlockState(pos)
|
||||
.getBlock() == this.masterBlock;
|
||||
return this.master.equals(pos) && this.world.getBlockState(pos) == this.state
|
||||
&& this.world.getBlockState(pos).getBlock() == this.masterBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,8 +89,7 @@ public class MultiServantLogic extends TileEntity implements IServantLogic {
|
||||
|
||||
@Override
|
||||
public void invalidateMaster(IMasterLogic master, World w, BlockPos pos) {
|
||||
this.hasMaster = false;
|
||||
master = null;
|
||||
this.removeMaster();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,4 +7,14 @@ public class MantleTileEntity extends TileEntity {
|
||||
public boolean isClient() {
|
||||
return this.getWorld() != null && this.getWorld().isRemote;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the chunk dirty without performing comparator updates or block state checks
|
||||
* Used since most of our markDirty calls only adjust TE data
|
||||
*/
|
||||
public void markDirtyFast() {
|
||||
if (world != null) {
|
||||
world.markChunkDirty(pos, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@ public class TileInventory extends MantleTileEntity implements IInventory {
|
||||
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, EnumFacing facing) {
|
||||
if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
|
||||
@@ -80,12 +81,17 @@ public class TileInventory extends MantleTileEntity implements IInventory {
|
||||
}
|
||||
|
||||
public void resize(int size) {
|
||||
// save effort if the size did not change
|
||||
if(size == inventory.size()) {
|
||||
return;
|
||||
}
|
||||
ItemStackList newInventory = ItemStackList.withSize(size);
|
||||
|
||||
for (int i = 0; i < size && i < inventory.size(); i++) {
|
||||
newInventory.set(i, inventory.get(i));
|
||||
}
|
||||
inventory = newInventory;
|
||||
this.markDirtyFast();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,16 +110,23 @@ public class TileInventory extends MantleTileEntity implements IInventory {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack current = inventory.get(slot);
|
||||
inventory.set(slot, itemstack);
|
||||
|
||||
if(!itemstack.isEmpty() && itemstack.getCount() > getInventoryStackLimit()) {
|
||||
itemstack.setCount(getInventoryStackLimit());
|
||||
}
|
||||
if(!ItemStack.areItemStacksEqual(current, itemstack)) {
|
||||
this.markDirtyFast();
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int quantity) {
|
||||
if(quantity <= 0) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
ItemStack itemStack = getStackInSlot(slot);
|
||||
|
||||
if(itemStack.isEmpty()) {
|
||||
@@ -123,18 +136,19 @@ public class TileInventory extends MantleTileEntity implements IInventory {
|
||||
// whole itemstack taken out
|
||||
if(itemStack.getCount() <= quantity) {
|
||||
setInventorySlotContents(slot, ItemStack.EMPTY);
|
||||
this.markDirty();
|
||||
this.markDirtyFast();
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
// split itemstack
|
||||
itemStack = itemStack.splitStack(quantity);
|
||||
// slot is empty, set to ItemStack.EMPTY
|
||||
// isn't this redundant to the above check?
|
||||
if(getStackInSlot(slot).getCount() == 0) {
|
||||
setInventorySlotContents(slot, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
this.markDirty();
|
||||
this.markDirtyFast();
|
||||
// return remainder
|
||||
return itemStack;
|
||||
}
|
||||
@@ -200,7 +214,7 @@ public class TileInventory extends MantleTileEntity implements IInventory {
|
||||
}
|
||||
|
||||
return
|
||||
entityplayer.getDistanceSq((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D)
|
||||
entityplayer.getDistanceSq(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D)
|
||||
<= 64D;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user