commit 9f1d2a21b13aab06a4dde2faa282fd5fcd2eeb5e
parent 4718f361d3f6765156f22892ca1d649cec8acf24
Author: Amb0s <ambos@disroot.org>
Date: Thu, 24 Aug 2023 21:15:43 +0200
Added private flag to handle redstone state
Diffstat:
1 file changed, 14 insertions(+), 36 deletions(-)
diff --git a/src/main/java/turniplabs/simpletech/block/BlockTrappedChest.java b/src/main/java/turniplabs/simpletech/block/BlockTrappedChest.java
@@ -6,15 +6,16 @@ import net.minecraft.core.entity.player.EntityPlayer;
import net.minecraft.core.sound.SoundType;
import net.minecraft.core.world.World;
import net.minecraft.core.world.WorldSource;
-import turniplabs.simpletech.SimpleTech;
import java.util.Random;
public class BlockTrappedChest extends BlockChest {
+ private boolean activated;
+
public BlockTrappedChest(String key, int id, Material material) {
super(key, id, material);
- this.withTexCoords(9, 1, 9, 1, 11, 1, 10, 1, 10,
- 1, 10, 1);
+ this.activated = false;
+ this.withTexCoords(9, 1, 9, 1, 11, 1, 10, 1, 10, 1, 10, 1);
this.setTickOnLoad(true);
}
@@ -40,27 +41,13 @@ public class BlockTrappedChest extends BlockChest {
@Override
public boolean isPoweringTo(WorldSource blockAccess, int x, int y, int z, int side) {
- // Debug code to display metadata.
- boolean debug = false;
- if (debug) {
- System.out.println("METADATA: " + Integer.toString(
- blockAccess.getBlockMetadata(x, y, z), 2));
- System.out.println("DIRECTION: " + Integer.toString(
- SimpleTech.getDirectionFromMetadata(blockAccess.getBlockMetadata(x, y, z)), 2));
- System.out.println("REDSTONE: " + Integer.toString(SimpleTech.getRedstoneFromMetadata(
- blockAccess.getBlockMetadata(x, y, z)), 2));
- System.out.println("METADATA (recombined): " + Integer.toString(SimpleTech.createMetadata(
- SimpleTech.getDirectionFromMetadata(blockAccess.getBlockMetadata(x, y, z)),
- SimpleTech.getRedstoneFromMetadata(blockAccess.getBlockMetadata(x, y, z))), 2));
- }
-
- return SimpleTech.getRedstoneFromMetadata(blockAccess.getBlockMetadata(x, y, z)) > 0;
+ return this.activated;
}
@Override
public void onBlockRemoval(World world, int x, int y, int z) {
- if (SimpleTech.getRedstoneFromMetadata(world.getBlockMetadata(x, y, z)) > 0) {
- this.notifyNeighbors(world, x, y, z);
+ if (this.activated) {
+ world.notifyBlockChange(x, y, z, this.id);
}
super.onBlockRemoval(world, x, y, z);
@@ -68,7 +55,7 @@ public class BlockTrappedChest extends BlockChest {
@Override
public boolean blockActivated(World world, int x, int y, int z, EntityPlayer player) {
- this.setState(world, x, y, z, (byte) 1);
+ this.changeState(world, x, y, z);
world.scheduleBlockUpdate(x, y, z, this.id, this.tickRate());
world.playSoundEffect(SoundType.GUI_SOUNDS,x + 0.5, y + 0.5, z + 0.5,
@@ -80,26 +67,17 @@ public class BlockTrappedChest extends BlockChest {
@Override
public void updateTick(World world, int x, int y, int z, Random rand) {
if (!world.isClientSide) {
- if (SimpleTech.getRedstoneFromMetadata(world.getBlockMetadata(x, y, z)) > 0) {
- this.setState(world, x, y, z, (byte) 0);
+ if (this.activated) {
+ this.changeState(world, x, y, z);
}
}
}
- private void setState(World world, int x, int y, int z, byte redstone) {
- int direction = SimpleTech.getDirectionFromMetadata(world.getBlockMetadata(x, y, z));
-
- // Recreates metadata using the redstone signal and the block direction values.
- world.setBlockMetadataWithNotify(x, y, z, SimpleTech.createMetadata(direction, redstone));
+ private void changeState(World world, int x, int y, int z) {
+ // Reverses state.
+ this.activated = !activated;
// Updates block's neighbors.
- this.notifyNeighbors(world, x, y, z);
-
- world.markBlocksDirty(x, y, z, x, y, z);
- }
-
- private void notifyNeighbors(World world, int x, int y, int z) {
- world.notifyBlocksOfNeighborChange(x, y, z, this.id);
- world.notifyBlocksOfNeighborChange(x, y - 1, z, this.id);
+ world.notifyBlockChange(x, y, z, id);
}
}