diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchBlock.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchBlock.java index 6055c1aac..ec43d44e9 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchBlock.java @@ -27,11 +27,14 @@ import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; +import net.minecraft.world.server.ServerWorld; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.items.CapabilityItemHandler; +import java.util.Random; + public class StockpileSwitchBlock extends HorizontalBlock implements ITE, IWrenchable { public static final IntegerProperty INDICATOR = IntegerProperty.create("indicator", 0, 6); @@ -89,6 +92,14 @@ public class StockpileSwitchBlock extends HorizontalBlock implements ITE builder) { builder.add(HORIZONTAL_FACING, INDICATOR); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchTileEntity.java index 87f406177..93351a61e 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchTileEntity.java @@ -8,12 +8,16 @@ import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBe import com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour.InterfaceProvider; +import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.world.TickPriority; +import net.minecraft.world.server.ServerWorld; import net.minecraftforge.items.IItemHandler; public class StockpileSwitchTileEntity extends SmartTileEntity { @@ -23,6 +27,7 @@ public class StockpileSwitchTileEntity extends SmartTileEntity { public float currentLevel; private boolean state; private boolean inverted; + private boolean poweredAfterDelay; private FilteringBehaviour filtering; private InvManipulationBehaviour observedInventory; @@ -34,6 +39,7 @@ public class StockpileSwitchTileEntity extends SmartTileEntity { currentLevel = -1; state = false; inverted = false; + poweredAfterDelay = false; setLazyTickRate(10); } @@ -44,6 +50,7 @@ public class StockpileSwitchTileEntity extends SmartTileEntity { currentLevel = compound.getFloat("Current"); state = compound.getBoolean("Powered"); inverted = compound.getBoolean("Inverted"); + poweredAfterDelay = compound.getBoolean("PoweredAfterDelay"); super.fromTag(blockState, compound, clientPacket); } @@ -54,6 +61,7 @@ public class StockpileSwitchTileEntity extends SmartTileEntity { compound.putFloat("Current", currentLevel); compound.putBoolean("Powered", state); compound.putBoolean("Inverted", inverted); + compound.putBoolean("PoweredAfterDelay", poweredAfterDelay); super.write(compound, clientPacket); } @@ -110,8 +118,10 @@ public class StockpileSwitchTileEntity extends SmartTileEntity { if (currentLevel > 0) displayLevel = (int) (currentLevel * 6); world.setBlockState(pos, getBlockState().with(StockpileSwitchBlock.INDICATOR, displayLevel), update ? 3 : 2); - if (update) - world.updateNeighbors(pos, getBlockState().getBlock()); + + if (update && !world.getPendingBlockTicks().isTickPending(pos, getBlockState().getBlock())) + world.getPendingBlockTicks().scheduleTick(pos, getBlockState().getBlock(), 2, TickPriority.NORMAL); + if (changed || update) sendData(); } @@ -137,19 +147,28 @@ public class StockpileSwitchTileEntity extends SmartTileEntity { public float getLevelForDisplay() { return currentLevel == -1 ? 0 : currentLevel; } - + public boolean getState() { return state; } - - public boolean isPowered() { + + public boolean shouldBePowered() { return inverted != state; } - + + public void updatePowerAfterDelay() { + poweredAfterDelay = shouldBePowered(); + world.updateNeighbors(pos, getBlockState().getBlock()); + } + + public boolean isPowered() { + return poweredAfterDelay; + } + public boolean isInverted() { return inverted; } - + public void setInverted(boolean inverted) { if (inverted == this.inverted) return;