mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-29 08:26:37 +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.IBlockReader;
|
||||||
import net.minecraft.world.IWorldReader;
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.server.ServerWorld;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import net.minecraftforge.fml.DistExecutor;
|
import net.minecraftforge.fml.DistExecutor;
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class StockpileSwitchBlock extends HorizontalBlock implements ITE<StockpileSwitchTileEntity>, IWrenchable {
|
public class StockpileSwitchBlock extends HorizontalBlock implements ITE<StockpileSwitchTileEntity>, IWrenchable {
|
||||||
|
|
||||||
public static final IntegerProperty INDICATOR = IntegerProperty.create("indicator", 0, 6);
|
public static final IntegerProperty INDICATOR = IntegerProperty.create("indicator", 0, 6);
|
||||||
|
@ -89,6 +92,14 @@ public class StockpileSwitchBlock extends HorizontalBlock implements ITE<Stockpi
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void scheduledTick(BlockState blockState, ServerWorld world, BlockPos pos, Random random) {
|
||||||
|
try {
|
||||||
|
getTileEntity(world, pos).updatePowerAfterDelay();
|
||||||
|
} catch (TileEntityException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
||||||
builder.add(HORIZONTAL_FACING, INDICATOR);
|
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;
|
||||||
import com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour.InterfaceProvider;
|
import com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour.InterfaceProvider;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
import net.minecraft.tileentity.TileEntityType;
|
import net.minecraft.tileentity.TileEntityType;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.vector.Vector3d;
|
import net.minecraft.util.math.vector.Vector3d;
|
||||||
|
import net.minecraft.world.TickPriority;
|
||||||
|
import net.minecraft.world.server.ServerWorld;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
|
||||||
public class StockpileSwitchTileEntity extends SmartTileEntity {
|
public class StockpileSwitchTileEntity extends SmartTileEntity {
|
||||||
|
@ -23,6 +27,7 @@ public class StockpileSwitchTileEntity extends SmartTileEntity {
|
||||||
public float currentLevel;
|
public float currentLevel;
|
||||||
private boolean state;
|
private boolean state;
|
||||||
private boolean inverted;
|
private boolean inverted;
|
||||||
|
private boolean poweredAfterDelay;
|
||||||
|
|
||||||
private FilteringBehaviour filtering;
|
private FilteringBehaviour filtering;
|
||||||
private InvManipulationBehaviour observedInventory;
|
private InvManipulationBehaviour observedInventory;
|
||||||
|
@ -34,6 +39,7 @@ public class StockpileSwitchTileEntity extends SmartTileEntity {
|
||||||
currentLevel = -1;
|
currentLevel = -1;
|
||||||
state = false;
|
state = false;
|
||||||
inverted = false;
|
inverted = false;
|
||||||
|
poweredAfterDelay = false;
|
||||||
setLazyTickRate(10);
|
setLazyTickRate(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +50,7 @@ public class StockpileSwitchTileEntity extends SmartTileEntity {
|
||||||
currentLevel = compound.getFloat("Current");
|
currentLevel = compound.getFloat("Current");
|
||||||
state = compound.getBoolean("Powered");
|
state = compound.getBoolean("Powered");
|
||||||
inverted = compound.getBoolean("Inverted");
|
inverted = compound.getBoolean("Inverted");
|
||||||
|
poweredAfterDelay = compound.getBoolean("PoweredAfterDelay");
|
||||||
super.fromTag(blockState, compound, clientPacket);
|
super.fromTag(blockState, compound, clientPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +61,7 @@ public class StockpileSwitchTileEntity extends SmartTileEntity {
|
||||||
compound.putFloat("Current", currentLevel);
|
compound.putFloat("Current", currentLevel);
|
||||||
compound.putBoolean("Powered", state);
|
compound.putBoolean("Powered", state);
|
||||||
compound.putBoolean("Inverted", inverted);
|
compound.putBoolean("Inverted", inverted);
|
||||||
|
compound.putBoolean("PoweredAfterDelay", poweredAfterDelay);
|
||||||
super.write(compound, clientPacket);
|
super.write(compound, clientPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,8 +118,10 @@ public class StockpileSwitchTileEntity extends SmartTileEntity {
|
||||||
if (currentLevel > 0)
|
if (currentLevel > 0)
|
||||||
displayLevel = (int) (currentLevel * 6);
|
displayLevel = (int) (currentLevel * 6);
|
||||||
world.setBlockState(pos, getBlockState().with(StockpileSwitchBlock.INDICATOR, displayLevel), update ? 3 : 2);
|
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)
|
if (changed || update)
|
||||||
sendData();
|
sendData();
|
||||||
}
|
}
|
||||||
|
@ -137,19 +147,28 @@ public class StockpileSwitchTileEntity extends SmartTileEntity {
|
||||||
public float getLevelForDisplay() {
|
public float getLevelForDisplay() {
|
||||||
return currentLevel == -1 ? 0 : currentLevel;
|
return currentLevel == -1 ? 0 : currentLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getState() {
|
public boolean getState() {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPowered() {
|
public boolean shouldBePowered() {
|
||||||
return inverted != state;
|
return inverted != state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updatePowerAfterDelay() {
|
||||||
|
poweredAfterDelay = shouldBePowered();
|
||||||
|
world.updateNeighbors(pos, getBlockState().getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPowered() {
|
||||||
|
return poweredAfterDelay;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isInverted() {
|
public boolean isInverted() {
|
||||||
return inverted;
|
return inverted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInverted(boolean inverted) {
|
public void setInverted(boolean inverted) {
|
||||||
if (inverted == this.inverted)
|
if (inverted == this.inverted)
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue