diff --git a/common/src/main/java/rearth/oritech/block/entity/reactor/ReactorAbsorberPortEntity.java b/common/src/main/java/rearth/oritech/block/entity/reactor/ReactorAbsorberPortEntity.java index 2cca77c9b..4e5866ee9 100644 --- a/common/src/main/java/rearth/oritech/block/entity/reactor/ReactorAbsorberPortEntity.java +++ b/common/src/main/java/rearth/oritech/block/entity/reactor/ReactorAbsorberPortEntity.java @@ -7,6 +7,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.Inventory; +import net.minecraft.item.Items; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.server.network.ServerPlayerEntity; @@ -17,6 +18,7 @@ import rearth.oritech.client.init.ModScreens; import rearth.oritech.client.ui.BasicMachineScreenHandler; import rearth.oritech.init.BlockEntitiesContent; +import rearth.oritech.network.NetworkContent; import rearth.oritech.util.*; import java.util.List; @@ -26,10 +28,43 @@ public class ReactorAbsorberPortEntity extends BlockEntity implements ExtendedSc private final SimpleSidedInventory inventory = new SimpleSidedInventory(1, new InventorySlotAssignment(0, 1, 1, 0)); private final InventoryStorage inventoryStorage = InventoryStorage.of(inventory, null); + public int availableFuel; + public int currentFuelOriginalCapacity; + public ReactorAbsorberPortEntity(BlockPos pos, BlockState state) { super(BlockEntitiesContent.REACTOR_ABSORBER_PORT_BLOCK_ENTITY, pos, state); } + public int getAvailableFuel() { + if (availableFuel > 0) { + return availableFuel; + } + + // try consume item + var inputStack = inventory.getStack(0); + if (inputStack.isEmpty()) return 0; + + if (inputStack.getItem().equals(Items.BLUE_ICE)) { + var capacity = 1000; + currentFuelOriginalCapacity = capacity; + availableFuel = capacity; + inputStack.decrement(1); + } + + return availableFuel; + } + + public void consumeFuel(int amount) { + if (availableFuel >= amount) { + availableFuel -= amount; + } + + } + + public void updateNetwork() { + NetworkContent.MACHINE_CHANNEL.serverHandle(this).send(new NetworkContent.ReactorPortDataPacket(pos, currentFuelOriginalCapacity, availableFuel)); + } + @Override public Object getScreenOpeningData(ServerPlayerEntity player) { return new ModScreens.BasicData(pos); diff --git a/common/src/main/java/rearth/oritech/block/entity/reactor/ReactorControllerBlockEntity.java b/common/src/main/java/rearth/oritech/block/entity/reactor/ReactorControllerBlockEntity.java index cbde22e95..cb7cf3941 100644 --- a/common/src/main/java/rearth/oritech/block/entity/reactor/ReactorControllerBlockEntity.java +++ b/common/src/main/java/rearth/oritech/block/entity/reactor/ReactorControllerBlockEntity.java @@ -132,14 +132,21 @@ public void tick(World world, BlockPos pos, BlockState state, ReactorControllerB } else if (component instanceof ReactorAbsorberBlock absorberBlock) { var sumRemovedHeat = 0; + var fuelAvailable = absorberPorts.get(localPos).getAvailableFuel(); - // take heat in from neighbors and remove it - for (var neighbor : getNeighborsInBounds(localPos, activeComponents.keySet())) { - var neighborHeat = componentHeats.get(neighbor); - if (neighborHeat <= 0) continue; - neighborHeat -= 6; - sumRemovedHeat += 6; - componentHeats.put(neighbor, neighborHeat); + if (fuelAvailable >= reactorStackHeight) { + // take heat in from neighbors and remove it + for (var neighbor : getNeighborsInBounds(localPos, activeComponents.keySet())) { + var neighborHeat = componentHeats.get(neighbor); + if (neighborHeat <= 0) continue; + neighborHeat -= 6; + sumRemovedHeat += 6; + componentHeats.put(neighbor, neighborHeat); + } + } + + if (sumRemovedHeat > 0) { + absorberPorts.get(localPos).consumeFuel(reactorStackHeight); } componentStats.put(localPos, new ComponentStatistics((short) 0, componentHeat, (short) sumRemovedHeat, (short) (0))); @@ -334,7 +341,7 @@ private void sendUINetworkData() { if (!active || activeComponents.isEmpty() || !isActivelyViewed()) return; for (var port : fuelPorts.values()) port.updateNetwork(); - // for (var port : absorberPorts.values()) port.updateNetwork(); + for (var port : absorberPorts.values()) port.updateNetwork(); var positionsFlat = activeComponents.keySet(); var positions = positionsFlat.stream().map(pos -> areaMin.add(pos.x + 1, 1, pos.y + 1)).toList(); diff --git a/common/src/main/java/rearth/oritech/client/ui/ReactorScreen.java b/common/src/main/java/rearth/oritech/client/ui/ReactorScreen.java index 88be25160..f194b843a 100644 --- a/common/src/main/java/rearth/oritech/client/ui/ReactorScreen.java +++ b/common/src/main/java/rearth/oritech/client/ui/ReactorScreen.java @@ -18,6 +18,7 @@ import rearth.oritech.block.blocks.reactor.ReactorHeatPipeBlock; import rearth.oritech.block.blocks.reactor.ReactorHeatVentBlock; import rearth.oritech.block.blocks.reactor.ReactorRodBlock; +import rearth.oritech.block.entity.reactor.ReactorAbsorberPortEntity; import rearth.oritech.block.entity.reactor.ReactorControllerBlockEntity; import rearth.oritech.block.entity.reactor.ReactorFuelPortEntity; import rearth.oritech.client.ui.components.ReactorBlockRenderComponent; @@ -136,7 +137,7 @@ protected void handledScreenTick() { for (var overlay : activeOverlays) { var data = getStatsAtPosition(overlay.pos); - var isEmpty = data.storedHeat() <= 0; + var isEmpty = data.storedHeat() <= 10; if (isEmpty) { overlay.state = Blocks.AIR.getDefaultState(); continue; @@ -241,7 +242,13 @@ public void addStatsToTooltip(BlockPos pos, BlockState state, FlowLayout contain } else if (state.getBlock() instanceof ReactorHeatVentBlock pipeBlock) { container.child(Components.label(Text.translatable("text.oritech.reactor.removed_heat", stats.heatChanged()).formatted(Formatting.WHITE))); } else if (state.getBlock() instanceof ReactorAbsorberBlock absorberBlock) { + + if (!(portEntity instanceof ReactorAbsorberPortEntity absorberPortEntity)) return; + var availableFuel = absorberPortEntity.availableFuel; + var maxFuel = absorberPortEntity.currentFuelOriginalCapacity; + container.child(Components.label(Text.translatable("text.oritech.reactor.absorbed_heat", stats.heatChanged()).formatted(Formatting.WHITE))); + container.child(Components.label(Text.translatable("text.oritech.reactor.absorbant", availableFuel, maxFuel).formatted(Formatting.WHITE))); } } diff --git a/common/src/main/java/rearth/oritech/network/NetworkContent.java b/common/src/main/java/rearth/oritech/network/NetworkContent.java index 33f963d3d..18699730e 100644 --- a/common/src/main/java/rearth/oritech/network/NetworkContent.java +++ b/common/src/main/java/rearth/oritech/network/NetworkContent.java @@ -26,6 +26,7 @@ import rearth.oritech.block.entity.interaction.*; import rearth.oritech.block.entity.pipes.ItemFilterBlockEntity; import rearth.oritech.block.entity.processing.CentrifugeBlockEntity; +import rearth.oritech.block.entity.reactor.ReactorAbsorberPortEntity; import rearth.oritech.block.entity.reactor.ReactorControllerBlockEntity; import rearth.oritech.block.entity.reactor.ReactorFuelPortEntity; import rearth.oritech.init.ComponentContent; @@ -502,9 +503,13 @@ public static void registerChannels() { var entity = access.player().getWorld().getBlockEntity(message.position); + // this is what happens when you're too lazy to add an interface if (entity instanceof ReactorFuelPortEntity port) { port.currentFuelOriginalCapacity = message.capacity; port.availableFuel = message.remaining; + } else if (entity instanceof ReactorAbsorberPortEntity port) { + port.currentFuelOriginalCapacity = message.capacity; + port.availableFuel = message.remaining; } })); diff --git a/common/src/main/resources/assets/oritech/lang/en_us.json b/common/src/main/resources/assets/oritech/lang/en_us.json index b3a70fa50..c468cdebd 100644 --- a/common/src/main/resources/assets/oritech/lang/en_us.json +++ b/common/src/main/resources/assets/oritech/lang/en_us.json @@ -580,6 +580,7 @@ "text.oritech.reactor.heat_to_reactor": "Heat to Reactor: %s K/t", "text.oritech.reactor.heat": "Heat: %s K", "text.oritech.reactor.fuel": "Fuel: %s/%s", + "text.oritech.reactor.absorbant": "Coolant: %s/%s", "text.oritech.reactor.collected_heat": "Ingested Heat: %s K/t", "text.oritech.reactor.removed_heat": "Dispersed Heat: %s K/t", "text.oritech.reactor.absorbed_heat": "Absorbed Heat: %s K/t",