Skip to content

Commit

Permalink
Continued work on removing capturing lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
pupnewfster committed Apr 4, 2024
1 parent 4e2097b commit 303b59c
Show file tree
Hide file tree
Showing 30 changed files with 190 additions and 131 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mekanism.additions.client;

import java.util.Map;
import java.util.function.Function;
import mekanism.additions.common.MekanismAdditions;
import mekanism.additions.common.block.BlockGlowPanel;
import mekanism.additions.common.block.plastic.BlockPlasticFenceGate;
Expand All @@ -14,6 +15,7 @@
import net.minecraft.world.level.block.FenceGateBlock;
import net.minecraft.world.level.block.SlabBlock;
import net.minecraft.world.level.block.StairBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Half;
import net.minecraft.world.level.block.state.properties.SlabType;
import net.minecraft.world.level.block.state.properties.StairsShape;
Expand Down Expand Up @@ -48,9 +50,10 @@ protected void registerStatesAndModels() {

private void glowPanels() {
ModelFile model = models().getExistingFile(modLoc("block/glow_panel"));
Function<BlockState, ModelFile> modelFunc = state -> model;
for (BlockRegistryObject<BlockGlowPanel, ?> blockRO : AdditionsBlocks.GLOW_PANELS.values()) {
BlockGlowPanel glowPanel = blockRO.getBlock();
directionalBlock(glowPanel, state -> model, 180, glowPanel.getFluidLoggedProperty());
directionalBlock(glowPanel, modelFunc, 180, glowPanel.getFluidLoggedProperty());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import mekanism.generators.common.network.to_server.PacketGeneratorsGuiInteract;
import mekanism.generators.common.network.to_server.PacketGeneratorsGuiInteract.GeneratorsGuiInteraction;
import mekanism.generators.common.tile.fission.TileEntityFissionReactorLogicAdapter;
import mekanism.generators.common.tile.fission.TileEntityFissionReactorLogicAdapter.FissionReactorLogic;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
Expand All @@ -34,12 +35,13 @@ protected void addGuiElements() {
scrollBar = addRenderableWidget(new GuiScrollBar(this, 146, 31, 90, () -> tile.getModes().length, () -> DISPLAY_COUNT));
for (int i = 0; i < DISPLAY_COUNT; i++) {
int typeShift = 22 * i;
addRenderableWidget(new ReactorLogicButton<>(this, 17, 32 + typeShift, i, tile, scrollBar::getCurrentSelection, tile::getModes, type -> {
if (type == null) {
return;
}
PacketUtils.sendToServer(new PacketGeneratorsGuiInteract(GeneratorsGuiInteraction.LOGIC_TYPE, tile, type.ordinal()));
}));
addRenderableWidget(new ReactorLogicButton<>(this, 17, 32 + typeShift, i, tile, scrollBar::getCurrentSelection, tile::getModes, this::changeLogic));
}
}

private void changeLogic(FissionReactorLogic type) {
if (type != null) {
PacketUtils.sendToServer(new PacketGeneratorsGuiInteract(GeneratorsGuiInteraction.LOGIC_TYPE, tile, type.ordinal()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import mekanism.generators.common.network.to_server.PacketGeneratorsGuiInteract;
import mekanism.generators.common.network.to_server.PacketGeneratorsGuiInteract.GeneratorsGuiInteraction;
import mekanism.generators.common.tile.fusion.TileEntityFusionReactorLogicAdapter;
import mekanism.generators.common.tile.fusion.TileEntityFusionReactorLogicAdapter.FusionReactorLogic;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
Expand All @@ -40,12 +41,13 @@ protected void addGuiElements() {
scrollBar = addRenderableWidget(new GuiScrollBar(this, 146, 31, 90, () -> tile.getModes().length, () -> DISPLAY_COUNT));
for (int i = 0; i < DISPLAY_COUNT; i++) {
int typeShift = 22 * i;
addRenderableWidget(new ReactorLogicButton<>(this, 17, 32 + typeShift, i, tile, scrollBar::getCurrentSelection, tile::getModes, type -> {
if (type == null) {
return;
}
PacketUtils.sendToServer(new PacketGeneratorsGuiInteract(GeneratorsGuiInteraction.LOGIC_TYPE, tile, type.ordinal()));
}));
addRenderableWidget(new ReactorLogicButton<>(this, 17, 32 + typeShift, i, tile, scrollBar::getCurrentSelection, tile::getModes, this::changeLogic));
}
}

private void changeLogic(FusionReactorLogic type) {
if (type != null) {
PacketUtils.sendToServer(new PacketGeneratorsGuiInteract(GeneratorsGuiInteraction.LOGIC_TYPE, tile, type.ordinal()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ public static Map<ResourceLocation, FissionRecipeViewerRecipe> getFissionRecipes
MekanismGases.STEAM.getStack(coolantAmount), MekanismGases.NUCLEAR_WASTE.getStack(1)));
//Go through all gases and add each coolant
for (Gas gas : MekanismAPI.GAS_REGISTRY) {
gas.ifAttributePresent(CooledCoolant.class, cooledCoolant -> {
CooledCoolant cooledCoolant = gas.get(CooledCoolant.class);
if (cooledCoolant != null) {
//If it is a cooled coolant add a recipe for it
Gas heatedCoolant = cooledCoolant.getHeatedGas();
long amount = Math.round(energyPerFuel / cooledCoolant.getThermalEnthalpy());
recipes.put(RecipeViewerUtils.synthetic(gas.getRegistryName(), "fission", MekanismGenerators.MODID), new FissionRecipeViewerRecipe(IngredientCreatorAccess.gas().from(gas, amount),
IngredientCreatorAccess.gas().from(MekanismGases.FISSILE_FUEL, 1), heatedCoolant.getStack(amount), MekanismGases.NUCLEAR_WASTE.getStack(1)));
});
}
}
return recipes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,28 +364,34 @@ public void meltdownHappened(Level world) {
* @apiNote Assumes radiation is enabled instead of checking and returning zero if it is not.
*/
private double getWasteTankRadioactivity(boolean dump) {
if (wasteTank.isEmpty()) {
return MekanismGases.NUCLEAR_WASTE.get().mapAttributeToDouble(Radiation.class, attribute -> partialWaste * attribute.getRadioactivity());
GasStack stored = wasteTank.getStack();
Radiation attribute;
if (stored.isEmpty()) {
attribute = MekanismGases.NUCLEAR_WASTE.get().get(Radiation.class);
} else {
attribute = stored.get(Radiation.class);
}
return wasteTank.getStack().mapAttributeToDouble(Radiation.class, (stored, attribute) -> {
if (dump) {
//If we want to dump if we have a radioactive substance, then we need to set the tank to empty
wasteTank.setEmpty();
}
return (stored.getAmount() + partialWaste) * attribute.getRadioactivity();
});
if (attribute == null) {
return 0;
} else if (dump) {
//If we want to dump if we have a radioactive substance, then we need to set the tank to empty
wasteTank.setEmpty();
}
return (stored.getAmount() + partialWaste) * attribute.getRadioactivity();
}

/**
* @apiNote Assumes radiation is enabled instead of checking and returning zero if it is not.
*/
private double getTankRadioactivityAndDump(IGasTank tank) {
if (!tank.isEmpty()) {
return tank.getStack().mapAttributeToDouble(Radiation.class, (stored, attribute) -> {
GasStack stored = tank.getStack();
Radiation attribute = stored.get(Radiation.class);
if (attribute != null) {
//If we have a radioactive substance, then we need to set the tank to empty
tank.setEmpty();
return stored.getAmount() * attribute.getRadioactivity();
});
}
}
return 0;
}
Expand All @@ -406,7 +412,8 @@ private void handleCoolant() {
heatCapacitor.handleHeat(-caseCoolantHeat);
}
} else if (!gasCoolantTank.isEmpty()) {
gasCoolantTank.getStack().ifAttributePresent(CooledCoolant.class, coolantType -> {
CooledCoolant coolantType = gasCoolantTank.getStack().get(CooledCoolant.class);
if (coolantType != null) {
double caseCoolantHeat = heat * coolantType.getConductivity();
lastBoilRate = clampCoolantHeated(caseCoolantHeat / coolantType.getThermalEnthalpy(), gasCoolantTank.getStored());
if (lastBoilRate > 0) {
Expand All @@ -415,7 +422,7 @@ private void handleCoolant() {
caseCoolantHeat = lastBoilRate * coolantType.getThermalEnthalpy();
heatCapacitor.handleHeat(-caseCoolantHeat);
}
});
}
}
}

Expand Down Expand Up @@ -448,8 +455,10 @@ private void burnFuel(Level world) {
wasteTank.insert(wasteToAdd, Action.EXECUTE, AutomationType.INTERNAL);
if (leftoverWaste > 0 && IRadiationManager.INSTANCE.isRadiationEnabled()) {
//Check if radiation is enabled in order to allow for short-circuiting when it will NO-OP further down the line anyway
wasteToAdd.ifAttributePresent(Radiation.class, attribute ->
IRadiationManager.INSTANCE.radiate(GlobalPos.of(world.dimension(), getBounds().getCenter()), leftoverWaste * attribute.getRadioactivity()));
Radiation attribute = wasteToAdd.get(Radiation.class);
if (attribute != null) {
IRadiationManager.INSTANCE.radiate(GlobalPos.of(world.dimension(), getBounds().getCenter()), leftoverWaste * attribute.getRadioactivity());
}
}
}
// update previous burn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ protected boolean onUpdateServer() {
if (!fuelTank.isEmpty() && MekanismUtils.canFunction(this) && getEnergyContainer().insert(generationRate, Action.SIMULATE, AutomationType.INTERNAL).isZero()) {
setActive(true);
if (!fuelTank.isEmpty()) {
fuelTank.getType().ifAttributePresent(Fuel.class, fuel -> {
Fuel fuel = fuelTank.getType().get(Fuel.class);
if (fuel != null) {
//Ensure valid data
maxBurnTicks = Math.max(1, fuel.getBurnTicks());
generationRate = fuel.getEnergyPerTick();
});
}
}

long toUse = getToUse();
Expand Down Expand Up @@ -196,7 +197,10 @@ public void setStackUnchecked(@NotNull GasStack stack) {

private void recheckOutput(@NotNull GasStack stack, boolean wasEmpty) {
if (wasEmpty && !stack.isEmpty()) {
getType().ifAttributePresent(Fuel.class, fuel -> updateMaxOutputRaw(fuel.getEnergyPerTick()));
Fuel fuel = getType().get(Fuel.class);
if (fuel != null) {
updateMaxOutputRaw(fuel.getEnergyPerTick());
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mekanism/client/ClientTickHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ public void tickStart() {
ItemStack primaryJetpack = IJetpackItem.getPrimaryJetpack(minecraft.player);
if (!primaryJetpack.isEmpty()) {
JetpackMode primaryMode = ((IJetpackItem) primaryJetpack.getItem()).getJetpackMode(primaryJetpack);
JetpackMode mode = IJetpackItem.getPlayerJetpackMode(minecraft.player, primaryMode, () -> minecraft.player.input.jumping);
JetpackMode mode = IJetpackItem.getPlayerJetpackMode(minecraft.player, primaryMode, p -> p.input.jumping);
MekanismClient.updateKey(minecraft.player.input.jumping, KeySync.ASCEND);
double jetpackThrust = ((IJetpackItem) primaryJetpack.getItem()).getJetpackThrust(primaryJetpack);
if (jetpackInUse && IJetpackItem.handleJetpackMotion(minecraft.player, mode, jetpackThrust, () -> minecraft.player.input.jumping)) {
if (jetpackInUse && IJetpackItem.handleJetpackMotion(minecraft.player, mode, jetpackThrust, p -> p.input.jumping)) {
minecraft.player.resetFallDistance();
}
}
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/mekanism/client/gui/GuiFilterHolder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package mekanism.client.gui;

import java.util.ArrayList;
import java.util.List;
import mekanism.client.gui.element.GuiElementHolder;
import mekanism.client.gui.element.GuiInnerScreen;
Expand All @@ -23,6 +22,7 @@
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public abstract class GuiFilterHolder<FILTER extends IFilter<?>, TILE extends TileEntityMekanism & ITileFilterHolder<FILTER>, CONTAINER extends MekanismTileContainer<TILE>>
extends GuiMekanismTile<TILE, CONTAINER> {
Expand Down Expand Up @@ -64,20 +64,21 @@ protected void addGuiElements() {
GuiInteraction interaction = hasShiftDown() ? GuiInteraction.MOVE_FILTER_TO_BOTTOM : GuiInteraction.MOVE_FILTER_DOWN;
PacketUtils.sendToServer(new PacketGuiInteract(interaction, tile, index));
}
}, this::onClick, index -> PacketUtils.sendToServer(new PacketGuiInteract(GuiInteraction.TOGGLE_FILTER_STATE, tile, index)), filter -> {
List<ItemStack> list = new ArrayList<>();
if (filter != null) {
if (filter instanceof IItemStackFilter<?> itemFilter) {
list.add(itemFilter.getItemStack());
} else if (filter instanceof ITagFilter<?> tagFilter) {
list.addAll(getTagStacks(tagFilter.getTagName()));
} else if (filter instanceof IModIDFilter<?> modIDFilter) {
list.addAll(getModIDStacks(modIDFilter.getModID()));
}
}
return list;
}));
}, this::onClick, index -> PacketUtils.sendToServer(new PacketGuiInteract(GuiInteraction.TOGGLE_FILTER_STATE, tile, index)), this::getRenderStacks));
}
}

private List<ItemStack> getRenderStacks(@Nullable IFilter<?> filter) {
if (filter != null) {
if (filter instanceof IItemStackFilter<?> itemFilter) {
return List.of(itemFilter.getItemStack());
} else if (filter instanceof ITagFilter<?> tagFilter) {
return getTagStacks(tagFilter.getTagName());
} else if (filter instanceof IModIDFilter<?> modIDFilter) {
return getModIDStacks(modIDFilter.getModID());
}
}
return List.of();
}

protected FilterButton addFilterButton(FilterButton button) {
Expand Down

0 comments on commit 303b59c

Please sign in to comment.