diff --git a/common/src/main/java/io/github/gregtechintergalactical/gtcore/block/BlockRedstoneWire.java b/common/src/main/java/io/github/gregtechintergalactical/gtcore/block/BlockRedstoneWire.java index b70850a..cbb6871 100644 --- a/common/src/main/java/io/github/gregtechintergalactical/gtcore/block/BlockRedstoneWire.java +++ b/common/src/main/java/io/github/gregtechintergalactical/gtcore/block/BlockRedstoneWire.java @@ -82,7 +82,7 @@ public int getBlockColor(BlockState state, @Nullable BlockGetter world, @Nullabl public int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { BlockEntity be = level.getBlockEntity(pos); if (be instanceof BlockEntityRedstoneWire wire){ - return wire.getWeakPower(direction); + return wire.getWeakPower(direction == null ? null : direction.getOpposite()); } return super.getSignal(state, level, pos, direction); } @@ -91,7 +91,7 @@ public int getSignal(BlockState state, BlockGetter level, BlockPos pos, Directio public int getDirectSignal(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { BlockEntity be = level.getBlockEntity(pos); if (be instanceof BlockEntityRedstoneWire wire){ - return wire.getStrongPower(direction); + return wire.getStrongPower(direction == null ? null : direction.getOpposite()); } return super.getDirectSignal(state, level, pos, direction); } diff --git a/common/src/main/java/io/github/gregtechintergalactical/gtcore/blockentity/BlockEntityRedstoneWire.java b/common/src/main/java/io/github/gregtechintergalactical/gtcore/blockentity/BlockEntityRedstoneWire.java index c5619ad..df66a25 100644 --- a/common/src/main/java/io/github/gregtechintergalactical/gtcore/blockentity/BlockEntityRedstoneWire.java +++ b/common/src/main/java/io/github/gregtechintergalactical/gtcore/blockentity/BlockEntityRedstoneWire.java @@ -8,6 +8,7 @@ import muramasa.antimatter.capability.ICoverHandler; import muramasa.antimatter.cover.CoverFactory; import muramasa.antimatter.cover.ICover; +import muramasa.antimatter.util.AntimatterPlatformUtils; import muramasa.antimatter.util.CodeUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -17,6 +18,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.redstone.Redstone; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -67,8 +69,7 @@ public void toggleConnection(Direction side) { boolean oldConnectedToNonWire = mConnectedToNonWire; updateConnectionStatus(); if (updateRedstone()) doRedstoneUpdate(this); - if (mConnectedToNonWire || oldConnectedToNonWire) level.updateNeighborsAt(this.getBlockPos(), this.getBlockState().getBlock()); - //Antimatter.LOGGER.info("refresh connection"); + if (mConnectedToNonWire || oldConnectedToNonWire) updateBlock(side); } @Override @@ -94,22 +95,23 @@ public int getWeakPower(Direction side){ if (cover.isNode()){ return cover.getWeakPower(); } + Block block = level.getBlockState(this.getBlockPos().relative(side)).getBlock(); + if (block instanceof BlockRedstoneWire) return 0; boolean connects = connects(side); if (mRedstone <= 0 || !connects) return 0; - Block block = level.getBlockState(this.getBlockPos().relative(side)).getBlock(); - return CodeUtils.bind4(CodeUtils.divup(mRedstone, MAX_RANGE)- (block instanceof BlockRedstoneWire ? 1: 0)); + return CodeUtils.bind4(CodeUtils.divup(mRedstone, MAX_RANGE)) - 1; } public int getStrongPower(Direction side){ - return 0; - /*ICover cover = coverHandler.map(c -> c.get(side)).orElse(ICover.empty); + ICover cover = coverHandler.map(c -> c.get(side)).orElse(ICover.empty); if (cover.isNode()){ return cover.getStrongPower(); } + Block block = level.getBlockState(this.getBlockPos().relative(side)).getBlock(); + if (block instanceof BlockRedstoneWire) return 0; boolean connects = connects(side); if (mRedstone <= 0 || !connects) return 0; - Block block = level.getBlockState(this.getBlockPos().relative(side)).getBlock(); - return CodeUtils.bind4(CodeUtils.divup(mRedstone, MAX_RANGE)- (block instanceof BlockRedstoneWire ? 1: 0));*/ + return CodeUtils.bind4(CodeUtils.divup(mRedstone, MAX_RANGE)) - 1; } public int getComparatorInputOverride(byte aSide) { @@ -141,6 +143,13 @@ public long getRedstoneAtSide(int aSide) { return (long) (MAX_RANGE * redstoneLevel) - mLoss; } + private void updateBlock(Direction side){ + AntimatterPlatformUtils.markAndNotifyBlock(getLevel(), getBlockPos(), getLevel().getChunkAt(getBlockPos()), getBlockState(), getBlockState(), 1, 512); + BlockPos neighbor = getBlockPos().relative(side); + BlockState neighborState = getLevel().getBlockState(neighbor); + getLevel().updateNeighborsAtExceptFromFacing(neighbor, neighborState.getBlock(), side.getOpposite()); + } + public boolean updateRedstone() { long oRedstone = mRedstone, tRedstone = mMode * MAX_RANGE - mLoss; @@ -149,7 +158,11 @@ public boolean updateRedstone() { mRedstone = tRedstone; mReceived = 6; } + List sidesToUpdate = new ArrayList<>(); for (Direction tSide : Direction.values()) { + if (!(getLevel().getBlockState(getBlockPos().relative(tSide)).getBlock() instanceof BlockRedstoneWire)) { + sidesToUpdate.add(tSide); + } if (tSide.get3DDataValue() == oReceived) continue; if ((tRedstone = getRedstoneAtSide(tSide.get3DDataValue())) > mRedstone) { mRedstone = tRedstone; mReceived = (byte) tSide.get3DDataValue(); @@ -157,7 +170,11 @@ public boolean updateRedstone() { } if (mRedstone != oRedstone) { sidedSync(true); - if (mConnectedToNonWire) level.updateNeighborsAt(this.getBlockPos(), this.getBlockState().getBlock()); + if (mConnectedToNonWire) { + for (Direction tSide : sidesToUpdate) { + updateBlock(tSide); + } + } return true; } return false;