simple-tech

Minecraft: Better than Adventure! mod that adds simple blocks to automate tasks
git clone git://memoryshards.xyz/simple-tech.git
Log | Files | Refs | README | LICENSE

commit d20e7258c77b0132e3526f240aab518d3811f139
parent 43ea022d5f4f798a817dd00b7c7b090db3c9cccf
Author: Amb0s <ambos@disroot.org>
Date:   Sat, 26 Aug 2023 17:28:02 +0200

Fixed #5

Diffstat:
Msrc/main/java/turniplabs/simpletech/block/BlockLightSensor.java | 15++++++---------
Msrc/main/java/turniplabs/simpletech/block/entity/TileEntityLightSensor.java | 32+++++++++++++++++++++-----------
2 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/src/main/java/turniplabs/simpletech/block/BlockLightSensor.java b/src/main/java/turniplabs/simpletech/block/BlockLightSensor.java @@ -61,20 +61,17 @@ public class BlockLightSensor extends BlockTileEntity { @Override public boolean blockActivated(World world, int x, int y, int z, EntityPlayer player) { int metadata = world.getBlockMetadata(x, y, z); - int newMeta; - if (!isInverted(world, x, y, z)) { - newMeta = SimpleTech.getMetaWithInverted(metadata, 1, invertedOffset); - world.setBlockMetadataWithNotify(x, y, z, newMeta); - } else { - newMeta = SimpleTech.getMetaWithInverted(metadata, 0, invertedOffset); - world.setBlockMetadataWithNotify(x, y, z, newMeta); - } + int isInverted = !isInverted(world, x, y, z) ? 1 : 0; + + // Recreates metadata using the inverted state and the old metadata value. + world.setBlockMetadataWithNotify(x, y, z, SimpleTech.getMetaWithInverted(metadata, isInverted, invertedOffset)); return true; } - public void updateSensor(World world, int x, int y, int z, byte redstone) { + public void updateSensor(World world, int x, int y, int z, boolean powering) { int metadata = world.getBlockMetadata(x, y, z); + int redstone = powering ? 1 : 0; // Recreates metadata using the redstone signal and the old metadata value. world.setBlockMetadataWithNotify(x, y, z, SimpleTech.getMetaWithRedstone(metadata, redstone, redstoneOffset)); diff --git a/src/main/java/turniplabs/simpletech/block/entity/TileEntityLightSensor.java b/src/main/java/turniplabs/simpletech/block/entity/TileEntityLightSensor.java @@ -2,27 +2,37 @@ package turniplabs.simpletech.block.entity; import net.minecraft.core.block.Block; import net.minecraft.core.block.entity.TileEntity; +import turniplabs.simpletech.SimpleTech; import turniplabs.simpletech.block.BlockLightSensor; public class TileEntityLightSensor extends TileEntity { @Override public void updateEntity() { - // If the world object if valid... - if (this.worldObj != null && !this.worldObj.isClientSide) { - Block block = this.getBlockType(); + // If the world object is valid... + if (worldObj != null && !worldObj.isClientSide) { + Block block = getBlockType(); // If it's a light sensor... if (block instanceof BlockLightSensor) { BlockLightSensor lightSensor = ((BlockLightSensor) block); - byte redstone; - if (lightSensor.isInverted(this.worldObj, this.xCoord, this.yCoord, this.zCoord)) { - redstone = (byte) (this.worldObj.isDaytime() ? 1 : 0); // Daytime mode. + boolean isDay = worldObj.isDaytime(); + boolean isPowered = SimpleTech.getRedstoneFromMetadata( + worldObj.getBlockMetadata(xCoord, yCoord, zCoord), + BlockLightSensor.redstoneOffset) > 0; + boolean isInverted = lightSensor.isInverted(worldObj, xCoord, yCoord, zCoord); + if (isInverted) { + // Daytime mode. + if (isDay && !isPowered) + // Sends redstone value. + lightSensor.updateSensor(worldObj, xCoord, yCoord, zCoord, true); + if (!isDay && isPowered) + lightSensor.updateSensor(worldObj, xCoord, yCoord, zCoord, false); } else { - redstone = (byte) (this.worldObj.isDaytime() ? 0 : 1); // Nighttime mode. + // Nighttime mode. + if (isDay && isPowered) + lightSensor.updateSensor(worldObj, xCoord, yCoord, zCoord, false); + if (!isDay && !isPowered) + lightSensor.updateSensor(worldObj, xCoord, yCoord, zCoord, true); } - - // Sends redstone value. - lightSensor.updateSensor(this.worldObj, this.xCoord, this.yCoord, - this.zCoord, redstone); } } }