Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
fixed redstone output issues with red alloy cables
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Jun 9, 2024
1 parent c8f8eb1 commit 2ae19c9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -149,15 +158,23 @@ public boolean updateRedstone() {
mRedstone = tRedstone;
mReceived = 6;
}
List<Direction> 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();
}
}
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;
Expand Down

0 comments on commit 2ae19c9

Please sign in to comment.