Skip to content

Commit

Permalink
Use Redstone constants instead of PowerUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
Sm0keySa1m0n committed Sep 7, 2023
1 parent b039329 commit 4ceb2d0
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/main/java/mods/railcraft/client/ClientManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ static void handleClientLoggedOut(ClientPlayerNetworkEvent.LoggingOut event) {
shuntingAuraRenderer.clearCarts();
}

@SuppressWarnings("unused")
@SubscribeEvent
static void handleClientLoggedIn(ClientPlayerNetworkEvent.LoggingIn event) {
var modInfo = ModList.get().getModFileById(Railcraft.ID).getMods().get(0);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/mods/railcraft/loot/DungeonLootModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

public class DungeonLootModifier extends LootModifier {

public static final Supplier<Codec<DungeonLootModifier>> CODEC = Suppliers.memoize(() ->
RecordCodecBuilder.create(inst -> codecStart(inst)
public static final Supplier<Codec<DungeonLootModifier>> CODEC =
Suppliers.memoize(() -> RecordCodecBuilder.create(inst -> codecStart(inst)
.and(ResourceLocation.CODEC.fieldOf("lootTable").forGetter((m) -> m.lootTable))
.apply(inst, DungeonLootModifier::new)));
private final ResourceLocation lootTable;
Expand All @@ -34,7 +34,7 @@ protected ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generate
LootContext context) {
if (RailcraftConfig.SERVER.changeDungeonLoot.get()) {
var extraTable = context.getResolver().getLootTable(this.lootTable);
extraTable.getRandomItemsRaw(context,
extraTable.getRandomItems(context,
LootTable.createStackSplitter(context.getLevel(), generatedLoot::add));
}
return generatedLoot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;

public final class PowerUtil {

public static final int NO_POWER = 0;
public static final int FULL_POWER = 15;
public final class RedstoneUtil {

public static boolean hasRepeaterSignal(Level level, BlockPos pos, Direction from) {
Block block = level.getBlockState(pos.relative(from)).getBlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import mods.railcraft.api.signal.SimpleBlockSignalNetwork;
import mods.railcraft.api.signal.SimpleSignalController;
import mods.railcraft.api.signal.entity.SignalControllerEntity;
import mods.railcraft.util.PowerUtil;
import mods.railcraft.world.level.block.entity.RailcraftBlockEntityTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.redstone.Redstone;

public class BlockSignalRelayBoxBlockEntity extends ActionSignalBoxBlockEntity
implements BlockSignalEntity, SignalControllerEntity {
Expand Down Expand Up @@ -50,8 +50,8 @@ private void signalAspectChanged(SignalAspect signalAspect) {
@Override
public int getRedstoneSignal(Direction side) {
return this.isActionSignalAspect(this.blockSignal.aspect())
? PowerUtil.FULL_POWER
: PowerUtil.NO_POWER;
? Redstone.SIGNAL_MAX
: Redstone.SIGNAL_NONE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import mods.railcraft.client.gui.widget.button.ButtonTexture;
import mods.railcraft.client.gui.widget.button.TexturePosition;
import mods.railcraft.gui.button.ButtonState;
import mods.railcraft.util.PowerUtil;
import mods.railcraft.util.RedstoneUtil;
import mods.railcraft.world.level.block.entity.RailcraftBlockEntityTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -16,6 +16,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.redstone.Redstone;

public class SignalCapacitorBoxBlockEntity extends AbstractSignalBoxBlockEntity {

Expand Down Expand Up @@ -51,7 +52,7 @@ public static void serverTick(Level level, BlockPos blockPos, BlockState blockSt
if (blockEntity.ticksPowered-- > 0) {
if (blockEntity.mode == Mode.FALLING_EDGE) {
var signalAspect = SignalAspect.GREEN;
var powered = PowerUtil.hasRepeaterSignal(level, blockPos);
var powered = RedstoneUtil.hasRepeaterSignal(level, blockPos);
for (var direction : Direction.Plane.HORIZONTAL) {
var neighbor = level.getBlockEntity(blockPos.relative(direction));
if (neighbor instanceof AbstractSignalBoxBlockEntity box) {
Expand Down Expand Up @@ -89,7 +90,7 @@ public void neighborChanged() {
if (this.level.isClientSide()) {
return;
}
var powered = PowerUtil.hasRepeaterSignal(this.level, this.getBlockPos());
var powered = RedstoneUtil.hasRepeaterSignal(this.level, this.getBlockPos());
if (this.ticksPowered <= 0 && powered) {
this.ticksPowered = this.ticksToPower;
if (this.mode == Mode.RISING_EDGE) {
Expand All @@ -116,8 +117,8 @@ public int getRedstoneSignal(Direction direction) {
var blockEntity =
this.level.getBlockEntity(this.getBlockPos().relative(direction.getOpposite()));
return blockEntity instanceof AbstractSignalBoxBlockEntity || this.ticksPowered <= 0
? PowerUtil.NO_POWER
: PowerUtil.FULL_POWER;
? Redstone.SIGNAL_NONE
: Redstone.SIGNAL_MAX;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import mods.railcraft.api.signal.SignalReceiver;
import mods.railcraft.api.signal.SingleSignalReceiver;
import mods.railcraft.api.signal.entity.SignalReceiverEntity;
import mods.railcraft.util.PowerUtil;
import mods.railcraft.world.level.block.entity.RailcraftBlockEntityTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.redstone.Redstone;

public class SignalReceiverBoxBlockEntity extends ActionSignalBoxBlockEntity
implements SignalReceiverEntity {
Expand Down Expand Up @@ -39,8 +39,8 @@ public void blockRemoved() {
@Override
public int getRedstoneSignal(Direction direction) {
return this.isActionSignalAspect(this.signalReceiver.getPrimarySignalAspect())
? PowerUtil.FULL_POWER
: PowerUtil.NO_POWER;
? Redstone.SIGNAL_MAX
: Redstone.SIGNAL_NONE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.Set;
import mods.railcraft.api.signal.SignalAspect;
import mods.railcraft.tags.RailcraftTags;
import mods.railcraft.util.PowerUtil;
import mods.railcraft.util.RedstoneUtil;
import mods.railcraft.world.level.block.entity.RailcraftBlockEntityTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -14,6 +14,7 @@
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.redstone.Redstone;

public class SignalSequencerBoxBlockEntity extends AbstractSignalBoxBlockEntity {

Expand All @@ -31,7 +32,7 @@ public void neighborChanged() {
if (this.level.isClientSide()) {
return;
}
var powered = PowerUtil.hasRepeaterSignal(this.level, this.getBlockPos());
var powered = RedstoneUtil.hasRepeaterSignal(this.level, this.getBlockPos());
if (!this.powered && powered) {
this.powered = true;
this.incrementSequencer(true, new HashSet<>(), 0);
Expand Down Expand Up @@ -115,10 +116,10 @@ public void setChanged() {
public int getRedstoneSignal(Direction direction) {
return this.level.getBlockEntity(
this.getBlockPos().relative(direction)) instanceof AbstractSignalBoxBlockEntity
? PowerUtil.NO_POWER
? Redstone.SIGNAL_NONE
: this.outputDirection.getOpposite() == direction
? PowerUtil.FULL_POWER
: PowerUtil.NO_POWER;
? Redstone.SIGNAL_MAX
: Redstone.SIGNAL_NONE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package mods.railcraft.world.level.block.manipulator;

import mods.railcraft.util.PowerUtil;
import mods.railcraft.world.level.block.entity.manipulator.ManipulatorBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -21,6 +20,7 @@
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.redstone.Redstone;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.network.NetworkHooks;

Expand Down Expand Up @@ -73,7 +73,7 @@ public int getSignal(BlockState blockState, BlockGetter level, BlockPos blockPos
|| neighborBlockState.is(Blocks.REDSTONE_WIRE)
|| neighborBlockState.is(Blocks.REPEATER);
}
return emit ? PowerUtil.FULL_POWER : PowerUtil.NO_POWER;
return emit ? Redstone.SIGNAL_MAX : Redstone.SIGNAL_NONE;
}

@SuppressWarnings("deprecation")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mods.railcraft.world.level.block.track.actuator;

import mods.railcraft.api.track.ArrowDirection;
import mods.railcraft.util.PowerUtil;
import mods.railcraft.world.level.block.track.outfitted.SwitchTrackBlock;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -23,6 +22,7 @@
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.redstone.Redstone;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
Expand Down Expand Up @@ -115,7 +115,7 @@ public boolean hasAnalogOutputSignal(BlockState state) {

@Override
public int getAnalogOutputSignal(BlockState state, Level level, BlockPos pos) {
return isSwitched(state) ? PowerUtil.FULL_POWER : PowerUtil.NO_POWER;
return isSwitched(state) ? Redstone.SIGNAL_MAX : Redstone.SIGNAL_NONE;
}

@Override
Expand All @@ -134,8 +134,8 @@ public static void setSwitched(BlockState blockState, Level level, BlockPos bloc
}
level.setBlockAndUpdate(blockPos, blockState.setValue(SWITCHED, switched));
level.playSound(null, blockPos, switched
? SoundEvents.PISTON_CONTRACT
: SoundEvents.PISTON_EXTEND,
? SoundEvents.PISTON_CONTRACT
: SoundEvents.PISTON_EXTEND,
SoundSource.BLOCKS, 0.25F, level.getRandom().nextFloat() * 0.25F + 0.7F);
Direction.Plane.HORIZONTAL.forEach(direction -> {
BlockPos neighborPos = blockPos.relative(direction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import mods.railcraft.api.track.RailShapeUtil;
import mods.railcraft.api.track.TrackType;
import mods.railcraft.util.EntitySearcher;
import mods.railcraft.util.PowerUtil;
import mods.railcraft.world.entity.vehicle.CartConstants;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
Expand All @@ -34,6 +33,7 @@
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.RailShape;
import net.minecraft.world.level.redstone.Redstone;

public class DetectorTrackBlock extends OutfittedTrackBlock {

Expand Down Expand Up @@ -91,7 +91,7 @@ public boolean isSignalSource(BlockState state) {
@Override
public int getSignal(BlockState blockState, BlockGetter level, BlockPos blockPos,
Direction direction) {
return blockState.getValue(POWERED) ? PowerUtil.FULL_POWER : PowerUtil.NO_POWER;
return blockState.getValue(POWERED) ? Redstone.SIGNAL_MAX : Redstone.SIGNAL_NONE;
}

@Override
Expand Down Expand Up @@ -214,7 +214,6 @@ private Mode previous() {
return values()[(this.ordinal() + values().length - 1) % values().length];
}

protected void updatePowerState(BlockState blockState, Level level, BlockPos blockPos) {
}
protected void updatePowerState(BlockState blockState, Level level, BlockPos blockPos) {}
}
}

0 comments on commit 4ceb2d0

Please sign in to comment.