mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-28 07:56:44 +01:00
Gave stockpile switch output a delay (like comparators have) to improve stability
This commit is contained in:
parent
212cd593a7
commit
911aec5a3f
2 changed files with 37 additions and 7 deletions
|
@ -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<StockpileSwitchTileEntity>, IWrenchable {
|
||||
|
||||
public static final IntegerProperty INDICATOR = IntegerProperty.create("indicator", 0, 6);
|
||||
|
@ -89,6 +92,14 @@ public class StockpileSwitchBlock extends HorizontalBlock implements ITE<Stockpi
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduledTick(BlockState blockState, ServerWorld world, BlockPos pos, Random random) {
|
||||
try {
|
||||
getTileEntity(world, pos).updatePowerAfterDelay();
|
||||
} catch (TileEntityException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
||||
builder.add(HORIZONTAL_FACING, INDICATOR);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue