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

Commit

Permalink
fixed buffer and filter blocks not saving to nbt properly, added othe…
Browse files Browse the repository at this point in the history
…r 2 buttons to buffer
  • Loading branch information
Trinsdar committed Sep 20, 2023
1 parent c60e94e commit a11a331
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
public class BlockEntityBuffer extends BlockEntityMachine<BlockEntityBuffer> {
protected int stackLimit = 1;
boolean emitEnergy = false;
boolean outputRedstone = false;
boolean invertRedstone = false;

public BlockEntityBuffer(Machine<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
Expand Down Expand Up @@ -117,12 +119,18 @@ public static boolean transferItems(PlatformItemHandler from, PlatformItemHandle
public void saveAdditional(CompoundTag tag) {
super.saveAdditional(tag);
tag.putInt("stackLimit", stackLimit);
outputRedstone = tag.getBoolean("outputRedstone");
invertRedstone = tag.getBoolean("invertRedstone");
emitEnergy = tag.getBoolean("emitEnergy");
}

@Override
public void load(CompoundTag tag) {
super.load(tag);
stackLimit = tag.getInt("stackLimit");
tag.putBoolean("outputRedstone", outputRedstone);
tag.putBoolean("invertRedstone", invertRedstone);
tag.putBoolean("emitEnergy", emitEnergy);
}

@Override
Expand All @@ -136,9 +144,14 @@ public void onGuiEvent(IGuiEvent event, Player playerEntity) {
AntimatterPlatformUtils.markAndNotifyBlock(level, this.getBlockPos(), this.level.getChunkAt(this.getBlockPos()), this.getBlockState(), this.getBlockState(), 1, 512);
}
case 1 -> {
/*outputRedstone = !outputRedstone;
playerEntity.sendMessage(Utils.literal((outputRedstone ? "Emit redstone if slots contain something" : "Don't emit redstone")), playerEntity.getUUID());
AntimatterPlatformUtils.markAndNotifyBlock(level, this.getBlockPos(), this.level.getChunkAt(this.getBlockPos()), this.getBlockState(), this.getBlockState(), 1, 512);*/
outputRedstone = !outputRedstone;
playerEntity.sendMessage(Utils.literal( (outputRedstone ? "Emit redstone if slots contain something" : "Don't emit redstone")), playerEntity.getUUID());
AntimatterPlatformUtils.markAndNotifyBlock(level, this.getBlockPos(), this.level.getChunkAt(this.getBlockPos()), this.getBlockState(), this.getBlockState(), 1, 512);
}
case 2 -> {
invertRedstone = !invertRedstone;
playerEntity.sendMessage(Utils.literal( (invertRedstone ? "I" : "Don't i") + "nvert redstone"), playerEntity.getUUID());
AntimatterPlatformUtils.markAndNotifyBlock(level, this.getBlockPos(), this.level.getChunkAt(this.getBlockPos()), this.getBlockState(), this.getBlockState(), 1, 512);
}
}
}
Expand All @@ -148,6 +161,8 @@ public void onGuiEvent(IGuiEvent event, Player playerEntity) {
public void addWidgets(GuiInstance instance, IGuiElement parent) {
super.addWidgets(instance, parent);
instance.addSwitchButton(8, 63, 16, 16, ButtonOverlays.ENERGY_OFF, ButtonOverlays.ENERGY_ON, h -> ((BlockEntityBuffer)h).emitEnergy);
instance.addSwitchButton(26, 63, 16, 16, ButtonOverlays.REDSTONE_CONTROL_OFF, ButtonOverlays.REDSTONE_CONTROL_ON, h -> ((BlockEntityBuffer)h).outputRedstone);
instance.addSwitchButton(44, 63, 16, 16, ButtonOverlays.INVERT_REDSTONE_OFF, ButtonOverlays.INVERT_REDSTONE_ON, h -> ((BlockEntityBuffer)h).invertRedstone);
}

public static class BufferItemHandler extends MachineItemHandler<BlockEntityBuffer> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void load(CompoundTag tag) {
nbt = tag.getBoolean("nbt");
outputRedstone = tag.getBoolean("outputRedstone");
invertRedstone = tag.getBoolean("invertRedstone");
emitEnergy = tag.getBoolean("emitsEnergy");
emitEnergy = tag.getBoolean("emitEnergy");
}

@Override
Expand Down

0 comments on commit a11a331

Please sign in to comment.