From c7fe6aea3b5a825cfc05b6706d0a7efcfc83861e Mon Sep 17 00:00:00 2001 From: Swedz Date: Sun, 24 Nov 2024 19:50:42 -0500 Subject: [PATCH 1/9] Make machine component api more consistent and accessible across both gui and normal components --- .../impl/MachineScreenPredicateTest.java | 20 +-- .../machines/gui/MachineMenuClient.java | 16 +-- .../machines/gui/MachineScreen.java | 4 +- .../machines/ComponentStorage.java | 136 ++++++++++++++++++ .../machines/MachineBlockEntity.java | 75 ++-------- ...ElectricCraftingMultiblockBlockEntity.java | 4 +- .../machines/gui/MachineMenuCommon.java | 8 +- .../machines/gui/MachineMenuServer.java | 11 +- .../network/machines/ChangeShapePacket.java | 2 +- .../network/machines/ReiLockSlotsPacket.java | 2 +- .../machines/SetAutoExtractPacket.java | 2 +- 11 files changed, 180 insertions(+), 100 deletions(-) create mode 100644 src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java diff --git a/src/client/java/aztech/modern_industrialization/compat/viewer/impl/MachineScreenPredicateTest.java b/src/client/java/aztech/modern_industrialization/compat/viewer/impl/MachineScreenPredicateTest.java index cd198d1fe..16b638aaf 100644 --- a/src/client/java/aztech/modern_industrialization/compat/viewer/impl/MachineScreenPredicateTest.java +++ b/src/client/java/aztech/modern_industrialization/compat/viewer/impl/MachineScreenPredicateTest.java @@ -24,24 +24,24 @@ package aztech.modern_industrialization.compat.viewer.impl; import aztech.modern_industrialization.compat.rei.machines.ReiMachineRecipes; -import aztech.modern_industrialization.machines.gui.GuiComponentClient; import aztech.modern_industrialization.machines.gui.MachineScreen; import aztech.modern_industrialization.machines.guicomponents.CraftingMultiblockGuiClient; +import java.util.Optional; public class MachineScreenPredicateTest { public static boolean test(ReiMachineRecipes.MachineScreenPredicate predicate, MachineScreen screen) { return switch (predicate) { case ANY -> true; - case MULTIBLOCK -> { - for (GuiComponentClient client : screen.getMenu().components) { - if (client instanceof CraftingMultiblockGuiClient cmGui) { - if (cmGui.isShapeValid) { - yield true; + case MULTIBLOCK -> screen.getMenu().components.findOrDefault( + client -> { + if (client instanceof CraftingMultiblockGuiClient cmGui) { + if (cmGui.isShapeValid) { + return Optional.of(true); + } } - } - } - yield false; - } + return Optional.empty(); + }, + false); }; } } diff --git a/src/client/java/aztech/modern_industrialization/machines/gui/MachineMenuClient.java b/src/client/java/aztech/modern_industrialization/machines/gui/MachineMenuClient.java index 694019608..a4bee1d3a 100644 --- a/src/client/java/aztech/modern_industrialization/machines/gui/MachineMenuClient.java +++ b/src/client/java/aztech/modern_industrialization/machines/gui/MachineMenuClient.java @@ -27,6 +27,7 @@ import aztech.modern_industrialization.inventory.ConfigurableItemStack; import aztech.modern_industrialization.inventory.MIInventory; import aztech.modern_industrialization.inventory.SlotPositions; +import aztech.modern_industrialization.machines.ComponentStorage; import aztech.modern_industrialization.machines.GuiComponentsClient; import aztech.modern_industrialization.util.NbtHelper; import java.util.ArrayList; @@ -52,11 +53,11 @@ public static MachineMenuClient create(int syncId, Inventory playerInventory, Re SlotPositions fluidPositions = SlotPositions.read(buf); MIInventory inventory = new MIInventory(itemStacks, fluidStacks, itemPositions, fluidPositions); // Components - List components = new ArrayList<>(); + ComponentStorage components = new ComponentStorage<>(); int componentCount = buf.readInt(); for (int i = 0; i < componentCount; ++i) { ResourceLocation id = buf.readResourceLocation(); - components.add(GuiComponentsClient.get(id).createFromInitialData(buf)); + components.register(GuiComponentsClient.get(id).createFromInitialData(buf)); } // GUI params MachineGuiParameters guiParams = MachineGuiParameters.read(buf); @@ -64,9 +65,9 @@ public static MachineMenuClient create(int syncId, Inventory playerInventory, Re return new MachineMenuClient(syncId, playerInventory, inventory, components, guiParams); } - public final List components; + public final ComponentStorage components; - private MachineMenuClient(int syncId, Inventory playerInventory, MIInventory inventory, List components, + private MachineMenuClient(int syncId, Inventory playerInventory, MIInventory inventory, ComponentStorage components, MachineGuiParameters guiParams) { super(syncId, playerInventory, inventory, guiParams, components); this.components = components; @@ -74,12 +75,7 @@ private MachineMenuClient(int syncId, Inventory playerInventory, MIInventory inv @Nullable public T getComponent(Class klass) { - for (GuiComponentClient component : components) { - if (klass.isInstance(component)) { - return (T) component; - } - } - return null; + return components.get(klass).orElse(null); } @Override diff --git a/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java b/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java index ab75a6164..a36e5adbb 100644 --- a/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java +++ b/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java @@ -64,9 +64,7 @@ public class MachineScreen extends MIHandledScreen implements public MachineScreen(MachineMenuClient handler, Inventory inventory, Component title) { super(handler, inventory, title); - for (GuiComponentClient component : handler.components) { - renderers.add(component.createRenderer(this)); - } + handler.components.forEach(component -> renderers.add(component.createRenderer(this))); this.imageHeight = handler.guiParams.backgroundHeight; this.imageWidth = handler.guiParams.backgroundWidth; diff --git a/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java b/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java new file mode 100644 index 000000000..d174f62d6 --- /dev/null +++ b/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java @@ -0,0 +1,136 @@ +/* + * MIT License + * + * Copyright (c) 2020 Azercoco & Technici4n + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package aztech.modern_industrialization.machines; + +import aztech.modern_industrialization.machines.gui.GuiComponent; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.Function; +import net.minecraft.resources.ResourceLocation; + +public sealed class ComponentStorage permits ComponentStorage.GuiServer, ComponentStorage.Server { + protected final List components = new ArrayList<>(); + + @SafeVarargs + public final void register(C... components) { + Collections.addAll(this.components, components); + } + + @SafeVarargs + public final void unregister(C... components) { + for (C component : components) { + this.components.remove(component); + } + } + + public final int size() { + return components.size(); + } + + public final C get(int index) { + return components.get(index); + } + + public final void forEach(Consumer action) { + components.forEach(action); + } + + public final void forEachIndexed(BiConsumer action) { + for (int i = 0; i < components.size(); i++) { + action.accept(i, components.get(i)); + } + } + + public final Optional get(Class clazz) { + for (C component : components) { + if (clazz.isInstance(component)) { + return Optional.of((T) component); + } + } + return Optional.empty(); + } + + public final List tryGet(Class clazz) { + List components = new ArrayList<>(); + for (C component : this.components) { + if (clazz.isInstance(component)) { + components.add((T) component); + } + } + return components; + } + + public final void forType(Class clazz, Consumer action) { + List component = tryGet(clazz); + for (T c : component) { + action.accept(c); + } + } + + public final R mapOrDefault(Class clazz, Function action, R defaultValue) { + List components = tryGet(clazz); + if (components.isEmpty()) { + return defaultValue; + } else if (components.size() == 1) { + return action.apply(components.get(0)); + } else { + throw new RuntimeException("Multiple components of type " + clazz.getName() + " found"); + } + } + + public final R findOrDefault(Function> action, R defaultValue) { + for (C component : components) { + Optional result = action.apply(component); + if (result.isPresent()) { + return result.get(); + } + } + return defaultValue; + } + + public final R findOrDefault(Class clazz, Function> action, R defaultValue) { + return findOrDefault(component -> clazz.isInstance(component) ? action.apply((T) component) : Optional.empty(), defaultValue); + } + + public static final class GuiServer extends ComponentStorage { + /** + * @throws RuntimeException if the component doesn't exist. + */ + public S get(ResourceLocation componentId) { + for (GuiComponent.Server component : components) { + if (component.getId().equals(componentId)) { + return (S) component; + } + } + throw new RuntimeException("Couldn't find component " + componentId); + } + } + + public static final class Server extends ComponentStorage { + } +} diff --git a/src/main/java/aztech/modern_industrialization/machines/MachineBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/MachineBlockEntity.java index 026f30410..c9994ef50 100644 --- a/src/main/java/aztech/modern_industrialization/machines/MachineBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/MachineBlockEntity.java @@ -37,10 +37,7 @@ import aztech.modern_industrialization.util.NbtHelper; import aztech.modern_industrialization.util.WorldHelper; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.function.Consumer; -import java.util.function.Function; import net.minecraft.Util; import net.minecraft.core.Direction; import net.minecraft.core.HolderLookup; @@ -50,7 +47,6 @@ import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.ItemInteractionResult; @@ -75,8 +71,8 @@ @SuppressWarnings("rawtypes") public abstract class MachineBlockEntity extends FastBlockEntity implements MenuProvider, WrenchableBlockEntity { - public final List guiComponents = new ArrayList<>(); - private final List icomponents = new ArrayList<>(); + protected final ComponentStorage.GuiServer guiComponents = new ComponentStorage.GuiServer(); + protected final ComponentStorage.Server icomponents = new ComponentStorage.Server(); public final MachineGuiParameters guiParams; /** * Server-side only: true if the next call to sync() will trigger a remesh. @@ -101,11 +97,11 @@ public MachineBlockEntity(BEP bep, MachineGuiParameters guiParams, OrientationCo } protected final void registerGuiComponent(GuiComponent.Server... components) { - Collections.addAll(guiComponents, components); + guiComponents.register(components); } protected final void registerComponents(IComponent... components) { - Collections.addAll(icomponents, components); + icomponents.register(components); } /** @@ -113,45 +109,12 @@ protected final void registerComponents(IComponent... components) { */ public abstract MIInventory getInventory(); - /** - * @throws RuntimeException if the component doesn't exist. - */ - @SuppressWarnings("unchecked") - public S getComponent(ResourceLocation componentId) { - for (GuiComponent.Server component : guiComponents) { - if (component.getId().equals(componentId)) { - return (S) component; - } - } - throw new RuntimeException("Couldn't find component " + componentId); - } - - private List tryGetComponent(Class clazz) { - List components = new ArrayList<>(); - for (var component : icomponents) { - if (clazz.isInstance(component)) { - components.add((T) component); - } - } - return components; + public final ComponentStorage.GuiServer getGuiComponents() { + return guiComponents; } - public final void forComponentType(Class clazz, Consumer action) { - List component = tryGetComponent(clazz); - for (T c : component) { - action.accept(c); - } - } - - public R mapComponentOrDefault(Class clazz, Function action, R defaultValue) { - List components = tryGetComponent(clazz); - if (components.isEmpty()) { - return defaultValue; - } else if (components.size() == 1) { - return action.apply(components.get(0)); - } else { - throw new RuntimeException("Multiple components of type " + clazz.getName() + " found"); - } + public final ComponentStorage.Server getComponents() { + return icomponents; } @Override @@ -176,10 +139,10 @@ public final void writeScreenOpeningData(RegistryFriendlyByteBuf buf) { inv.fluidPositions.write(buf); buf.writeInt(guiComponents.size()); // Write components - for (GuiComponent.Server component : guiComponents) { + guiComponents.forEach(component -> { buf.writeResourceLocation(component.getId()); component.writeInitialData(buf); - } + }); // Write GUI params guiParams.write(buf); } @@ -238,17 +201,13 @@ public CompoundTag getUpdateTag(HolderLookup.Provider registries) { CompoundTag tag = new CompoundTag(); tag.putBoolean("remesh", syncCausesRemesh); syncCausesRemesh = false; - for (IComponent component : icomponents) { - component.writeClientNbt(tag, registries); - } + icomponents.forEach(component -> component.writeClientNbt(tag, registries)); return tag; } @Override public final void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) { - for (IComponent component : icomponents) { - component.writeNbt(tag, registries); - } + icomponents.forEach(component -> component.writeNbt(tag, registries)); } @Override @@ -258,14 +217,10 @@ public final void loadAdditional(CompoundTag tag, HolderLookup.Provider registri public final void load(CompoundTag tag, HolderLookup.Provider registries, boolean isUpgradingMachine) { if (!tag.contains("remesh")) { - for (IComponent component : icomponents) { - component.readNbt(tag, registries, isUpgradingMachine); - } + icomponents.forEach(component -> component.readNbt(tag, registries, isUpgradingMachine)); } else { boolean forceChunkRemesh = tag.getBoolean("remesh"); - for (IComponent component : icomponents) { - component.readClientNbt(tag, registries); - } + icomponents.forEach(component -> component.readClientNbt(tag, registries)); if (forceChunkRemesh) { WorldHelper.forceChunkRemesh(level, worldPosition); requestModelDataUpdate(); @@ -300,7 +255,7 @@ public static void registerFluidApi(BlockEntityType bet) { public List dropExtra() { List drops = new ArrayList<>(); - forComponentType(DropableComponent.class, u -> drops.add(u.getDrop())); + icomponents.forType(DropableComponent.class, u -> drops.add(u.getDrop())); return drops; } diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java index 1b564feaf..e164b6156 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java @@ -76,13 +76,13 @@ protected ItemInteractionResult useItemOn(Player player, InteractionHand hand, D result = LubricantHelper.onUse(this.crafter, player, hand); } if (!result.consumesAction()) { - result = mapComponentOrDefault(UpgradeComponent.class, upgrade -> upgrade.onUse(this, player, hand), result); + result = icomponents.mapOrDefault(UpgradeComponent.class, upgrade -> upgrade.onUse(this, player, hand), result); } if (!result.consumesAction()) { result = redstoneControl.onUse(this, player, hand); } if (!result.consumesAction()) { - result = mapComponentOrDefault(OverdriveComponent.class, overdrive -> overdrive.onUse(this, player, hand), result); + result = icomponents.mapOrDefault(OverdriveComponent.class, overdrive -> overdrive.onUse(this, player, hand), result); } return result; } diff --git a/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuCommon.java b/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuCommon.java index 591efa882..634aff0a6 100644 --- a/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuCommon.java +++ b/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuCommon.java @@ -29,7 +29,7 @@ import aztech.modern_industrialization.inventory.ConfigurableScreenHandler; import aztech.modern_industrialization.inventory.MIInventory; import aztech.modern_industrialization.inventory.SlotGroup; -import java.util.List; +import aztech.modern_industrialization.machines.ComponentStorage; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.inventory.Slot; @@ -38,7 +38,7 @@ public abstract class MachineMenuCommon extends ConfigurableScreenHandler implem public final MachineGuiParameters guiParams; MachineMenuCommon(int syncId, Inventory playerInventory, MIInventory inventory, MachineGuiParameters guiParams, - List guiComponents) { + ComponentStorage guiComponents) { super(MIRegistries.MACHINE_MENU.get(), syncId, playerInventory, inventory); this.guiParams = guiParams; @@ -53,9 +53,7 @@ public abstract class MachineMenuCommon extends ConfigurableScreenHandler implem } // Gui components first (we want to prioritize them with shift click) - for (var component : guiComponents) { - component.setupMenu(this); - } + guiComponents.forEach(component -> component.setupMenu(this)); // Configurable slots for (int i = 0; i < inventory.getItemStacks().size(); ++i) { diff --git a/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuServer.java b/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuServer.java index 44b635de6..4f700d1ce 100644 --- a/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuServer.java +++ b/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuServer.java @@ -39,19 +39,16 @@ public class MachineMenuServer extends MachineMenuCommon { protected final List trackedData; public MachineMenuServer(int syncId, Inventory playerInventory, MachineBlockEntity blockEntity, MachineGuiParameters guiParams) { - super(syncId, playerInventory, blockEntity.getInventory(), guiParams, blockEntity.guiComponents); + super(syncId, playerInventory, blockEntity.getInventory(), guiParams, blockEntity.getGuiComponents()); this.blockEntity = blockEntity; trackedData = new ArrayList<>(); - for (GuiComponent.Server component : blockEntity.guiComponents) { - trackedData.add(component.copyData()); - } + blockEntity.getGuiComponents().forEach(component -> trackedData.add(component.copyData())); } @Override public void broadcastChanges() { super.broadcastChanges(); - for (int i = 0; i < blockEntity.guiComponents.size(); ++i) { - GuiComponent.Server component = blockEntity.guiComponents.get(i); + blockEntity.getGuiComponents().forEachIndexed((i, component) -> { if (component.needsSync(trackedData.get(i))) { var buf = new RegistryFriendlyByteBuf(Unpooled.buffer(), blockEntity.getLevel().registryAccess()); component.writeCurrentData(buf); @@ -61,7 +58,7 @@ public void broadcastChanges() { trackedData.set(i, component.copyData()); buf.release(); } - } + }); } @Override diff --git a/src/main/java/aztech/modern_industrialization/network/machines/ChangeShapePacket.java b/src/main/java/aztech/modern_industrialization/network/machines/ChangeShapePacket.java index b92809545..84aacfeb2 100644 --- a/src/main/java/aztech/modern_industrialization/network/machines/ChangeShapePacket.java +++ b/src/main/java/aztech/modern_industrialization/network/machines/ChangeShapePacket.java @@ -50,7 +50,7 @@ public void handle(Context ctx) { AbstractContainerMenu menu = ctx.getPlayer().containerMenu; if (menu.containerId == syncId && menu instanceof MachineMenuServer machineMenu) { - ShapeSelection.Server shapeSelection = machineMenu.blockEntity.getComponent(GuiComponents.SHAPE_SELECTION); + ShapeSelection.Server shapeSelection = machineMenu.blockEntity.getGuiComponents().get(GuiComponents.SHAPE_SELECTION); shapeSelection.behavior.handleClick(shapeLine, clickedLeftButton ? -1 : +1); } } diff --git a/src/main/java/aztech/modern_industrialization/network/machines/ReiLockSlotsPacket.java b/src/main/java/aztech/modern_industrialization/network/machines/ReiLockSlotsPacket.java index 378aec6b6..9f0689be5 100644 --- a/src/main/java/aztech/modern_industrialization/network/machines/ReiLockSlotsPacket.java +++ b/src/main/java/aztech/modern_industrialization/network/machines/ReiLockSlotsPacket.java @@ -48,7 +48,7 @@ public void handle(Context ctx) { AbstractContainerMenu sh = ctx.getPlayer().containerMenu; if (sh.containerId == containedId && sh instanceof MachineMenuServer screenHandler) { // Check that locking the slots is allowed in the first place - ReiSlotLocking.Server slotLocking = screenHandler.blockEntity.getComponent(GuiComponents.REI_SLOT_LOCKING); + ReiSlotLocking.Server slotLocking = screenHandler.blockEntity.getGuiComponents().get(GuiComponents.REI_SLOT_LOCKING); if (!slotLocking.allowLocking.get()) return; diff --git a/src/main/java/aztech/modern_industrialization/network/machines/SetAutoExtractPacket.java b/src/main/java/aztech/modern_industrialization/network/machines/SetAutoExtractPacket.java index 24ee14798..b8ef3181d 100644 --- a/src/main/java/aztech/modern_industrialization/network/machines/SetAutoExtractPacket.java +++ b/src/main/java/aztech/modern_industrialization/network/machines/SetAutoExtractPacket.java @@ -50,7 +50,7 @@ public void handle(Context ctx) { if (ctx.getPlayer().containerMenu.containerId == syncId) { var screenHandler = (MachineMenuServer) ctx.getPlayer().containerMenu; - AutoExtract.Server autoExtract = screenHandler.blockEntity.getComponent(GuiComponents.AUTO_EXTRACT); + AutoExtract.Server autoExtract = screenHandler.blockEntity.getGuiComponents().get(GuiComponents.AUTO_EXTRACT); OrientationComponent orientation = autoExtract.getOrientation(); if (isItem) { orientation.extractItems = isExtract; From 62755b417ec14989f15a4425ce8d578e420659f0 Mon Sep 17 00:00:00 2001 From: Swedz Date: Mon, 25 Nov 2024 21:25:22 -0500 Subject: [PATCH 2/9] Make ComponentStorage iterable --- .../machines/gui/MachineScreen.java | 4 +++- .../machines/ComponentStorage.java | 14 ++++++++----- .../machines/MachineBlockEntity.java | 20 +++++++++++++------ .../machines/gui/MachineMenuCommon.java | 4 +++- .../machines/gui/MachineMenuServer.java | 4 +++- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java b/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java index a36e5adbb..ab75a6164 100644 --- a/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java +++ b/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java @@ -64,7 +64,9 @@ public class MachineScreen extends MIHandledScreen implements public MachineScreen(MachineMenuClient handler, Inventory inventory, Component title) { super(handler, inventory, title); - handler.components.forEach(component -> renderers.add(component.createRenderer(this))); + for (GuiComponentClient component : handler.components) { + renderers.add(component.createRenderer(this)); + } this.imageHeight = handler.guiParams.backgroundHeight; this.imageWidth = handler.guiParams.backgroundWidth; diff --git a/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java b/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java index d174f62d6..b942146ec 100644 --- a/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java +++ b/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java @@ -26,16 +26,24 @@ import aztech.modern_industrialization.machines.gui.GuiComponent; import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.List; import java.util.Optional; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.NotNull; -public sealed class ComponentStorage permits ComponentStorage.GuiServer, ComponentStorage.Server { +public sealed class ComponentStorage implements Iterable permits ComponentStorage.GuiServer, ComponentStorage.Server { protected final List components = new ArrayList<>(); + @NotNull + @Override + public Iterator iterator() { + return components.iterator(); + } + @SafeVarargs public final void register(C... components) { Collections.addAll(this.components, components); @@ -56,10 +64,6 @@ public final C get(int index) { return components.get(index); } - public final void forEach(Consumer action) { - components.forEach(action); - } - public final void forEachIndexed(BiConsumer action) { for (int i = 0; i < components.size(); i++) { action.accept(i, components.get(i)); diff --git a/src/main/java/aztech/modern_industrialization/machines/MachineBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/MachineBlockEntity.java index c9994ef50..ef05e4775 100644 --- a/src/main/java/aztech/modern_industrialization/machines/MachineBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/MachineBlockEntity.java @@ -139,10 +139,10 @@ public final void writeScreenOpeningData(RegistryFriendlyByteBuf buf) { inv.fluidPositions.write(buf); buf.writeInt(guiComponents.size()); // Write components - guiComponents.forEach(component -> { + for (GuiComponent.Server component : guiComponents) { buf.writeResourceLocation(component.getId()); component.writeInitialData(buf); - }); + } // Write GUI params guiParams.write(buf); } @@ -201,13 +201,17 @@ public CompoundTag getUpdateTag(HolderLookup.Provider registries) { CompoundTag tag = new CompoundTag(); tag.putBoolean("remesh", syncCausesRemesh); syncCausesRemesh = false; - icomponents.forEach(component -> component.writeClientNbt(tag, registries)); + for (IComponent component : icomponents) { + component.writeClientNbt(tag, registries); + } return tag; } @Override public final void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) { - icomponents.forEach(component -> component.writeNbt(tag, registries)); + for (IComponent component : icomponents) { + component.writeNbt(tag, registries); + } } @Override @@ -217,10 +221,14 @@ public final void loadAdditional(CompoundTag tag, HolderLookup.Provider registri public final void load(CompoundTag tag, HolderLookup.Provider registries, boolean isUpgradingMachine) { if (!tag.contains("remesh")) { - icomponents.forEach(component -> component.readNbt(tag, registries, isUpgradingMachine)); + for (IComponent component : icomponents) { + component.readNbt(tag, registries, isUpgradingMachine); + } } else { boolean forceChunkRemesh = tag.getBoolean("remesh"); - icomponents.forEach(component -> component.readClientNbt(tag, registries)); + for (IComponent component : icomponents) { + component.readClientNbt(tag, registries); + } if (forceChunkRemesh) { WorldHelper.forceChunkRemesh(level, worldPosition); requestModelDataUpdate(); diff --git a/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuCommon.java b/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuCommon.java index 634aff0a6..8f42f2fef 100644 --- a/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuCommon.java +++ b/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuCommon.java @@ -53,7 +53,9 @@ public abstract class MachineMenuCommon extends ConfigurableScreenHandler implem } // Gui components first (we want to prioritize them with shift click) - guiComponents.forEach(component -> component.setupMenu(this)); + for (GuiComponent.Common component : guiComponents) { + component.setupMenu(this); + } // Configurable slots for (int i = 0; i < inventory.getItemStacks().size(); ++i) { diff --git a/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuServer.java b/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuServer.java index 4f700d1ce..ba485c697 100644 --- a/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuServer.java +++ b/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuServer.java @@ -42,7 +42,9 @@ public MachineMenuServer(int syncId, Inventory playerInventory, MachineBlockEnti super(syncId, playerInventory, blockEntity.getInventory(), guiParams, blockEntity.getGuiComponents()); this.blockEntity = blockEntity; trackedData = new ArrayList<>(); - blockEntity.getGuiComponents().forEach(component -> trackedData.add(component.copyData())); + for (GuiComponent.Server component : blockEntity.getGuiComponents()) { + trackedData.add(component.copyData()); + } } @Override From 8a8b358e6f47a50b5218c927021f1f4b32d45116 Mon Sep 17 00:00:00 2001 From: Swedz Date: Mon, 25 Nov 2024 21:28:04 -0500 Subject: [PATCH 3/9] Rename components variable and make them public instead of using getters --- .../machines/MachineBlockEntity.java | 24 +++++++------------ ...ElectricCraftingMultiblockBlockEntity.java | 4 ++-- .../machines/gui/MachineMenuServer.java | 6 ++--- .../network/machines/ChangeShapePacket.java | 2 +- .../network/machines/ReiLockSlotsPacket.java | 2 +- .../machines/SetAutoExtractPacket.java | 2 +- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/main/java/aztech/modern_industrialization/machines/MachineBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/MachineBlockEntity.java index ef05e4775..2b95db8a3 100644 --- a/src/main/java/aztech/modern_industrialization/machines/MachineBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/MachineBlockEntity.java @@ -71,8 +71,8 @@ @SuppressWarnings("rawtypes") public abstract class MachineBlockEntity extends FastBlockEntity implements MenuProvider, WrenchableBlockEntity { - protected final ComponentStorage.GuiServer guiComponents = new ComponentStorage.GuiServer(); - protected final ComponentStorage.Server icomponents = new ComponentStorage.Server(); + public final ComponentStorage.GuiServer guiComponents = new ComponentStorage.GuiServer(); + public final ComponentStorage.Server components = new ComponentStorage.Server(); public final MachineGuiParameters guiParams; /** * Server-side only: true if the next call to sync() will trigger a remesh. @@ -101,7 +101,7 @@ protected final void registerGuiComponent(GuiComponent.Server... components) { } protected final void registerComponents(IComponent... components) { - icomponents.register(components); + this.components.register(components); } /** @@ -109,14 +109,6 @@ protected final void registerComponents(IComponent... components) { */ public abstract MIInventory getInventory(); - public final ComponentStorage.GuiServer getGuiComponents() { - return guiComponents; - } - - public final ComponentStorage.Server getComponents() { - return icomponents; - } - @Override public final Component getDisplayName() { return Component.translatable(Util.makeDescriptionId("block", guiParams.blockId)); @@ -201,7 +193,7 @@ public CompoundTag getUpdateTag(HolderLookup.Provider registries) { CompoundTag tag = new CompoundTag(); tag.putBoolean("remesh", syncCausesRemesh); syncCausesRemesh = false; - for (IComponent component : icomponents) { + for (IComponent component : components) { component.writeClientNbt(tag, registries); } return tag; @@ -209,7 +201,7 @@ public CompoundTag getUpdateTag(HolderLookup.Provider registries) { @Override public final void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) { - for (IComponent component : icomponents) { + for (IComponent component : components) { component.writeNbt(tag, registries); } } @@ -221,12 +213,12 @@ public final void loadAdditional(CompoundTag tag, HolderLookup.Provider registri public final void load(CompoundTag tag, HolderLookup.Provider registries, boolean isUpgradingMachine) { if (!tag.contains("remesh")) { - for (IComponent component : icomponents) { + for (IComponent component : components) { component.readNbt(tag, registries, isUpgradingMachine); } } else { boolean forceChunkRemesh = tag.getBoolean("remesh"); - for (IComponent component : icomponents) { + for (IComponent component : components) { component.readClientNbt(tag, registries); } if (forceChunkRemesh) { @@ -263,7 +255,7 @@ public static void registerFluidApi(BlockEntityType bet) { public List dropExtra() { List drops = new ArrayList<>(); - icomponents.forType(DropableComponent.class, u -> drops.add(u.getDrop())); + components.forType(DropableComponent.class, u -> drops.add(u.getDrop())); return drops; } diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java index e164b6156..621588eb0 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java @@ -76,13 +76,13 @@ protected ItemInteractionResult useItemOn(Player player, InteractionHand hand, D result = LubricantHelper.onUse(this.crafter, player, hand); } if (!result.consumesAction()) { - result = icomponents.mapOrDefault(UpgradeComponent.class, upgrade -> upgrade.onUse(this, player, hand), result); + result = components.mapOrDefault(UpgradeComponent.class, upgrade -> upgrade.onUse(this, player, hand), result); } if (!result.consumesAction()) { result = redstoneControl.onUse(this, player, hand); } if (!result.consumesAction()) { - result = icomponents.mapOrDefault(OverdriveComponent.class, overdrive -> overdrive.onUse(this, player, hand), result); + result = components.mapOrDefault(OverdriveComponent.class, overdrive -> overdrive.onUse(this, player, hand), result); } return result; } diff --git a/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuServer.java b/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuServer.java index ba485c697..447c2165d 100644 --- a/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuServer.java +++ b/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuServer.java @@ -39,10 +39,10 @@ public class MachineMenuServer extends MachineMenuCommon { protected final List trackedData; public MachineMenuServer(int syncId, Inventory playerInventory, MachineBlockEntity blockEntity, MachineGuiParameters guiParams) { - super(syncId, playerInventory, blockEntity.getInventory(), guiParams, blockEntity.getGuiComponents()); + super(syncId, playerInventory, blockEntity.getInventory(), guiParams, blockEntity.guiComponents); this.blockEntity = blockEntity; trackedData = new ArrayList<>(); - for (GuiComponent.Server component : blockEntity.getGuiComponents()) { + for (GuiComponent.Server component : blockEntity.guiComponents) { trackedData.add(component.copyData()); } } @@ -50,7 +50,7 @@ public MachineMenuServer(int syncId, Inventory playerInventory, MachineBlockEnti @Override public void broadcastChanges() { super.broadcastChanges(); - blockEntity.getGuiComponents().forEachIndexed((i, component) -> { + blockEntity.guiComponents.forEachIndexed((i, component) -> { if (component.needsSync(trackedData.get(i))) { var buf = new RegistryFriendlyByteBuf(Unpooled.buffer(), blockEntity.getLevel().registryAccess()); component.writeCurrentData(buf); diff --git a/src/main/java/aztech/modern_industrialization/network/machines/ChangeShapePacket.java b/src/main/java/aztech/modern_industrialization/network/machines/ChangeShapePacket.java index 84aacfeb2..df62e9011 100644 --- a/src/main/java/aztech/modern_industrialization/network/machines/ChangeShapePacket.java +++ b/src/main/java/aztech/modern_industrialization/network/machines/ChangeShapePacket.java @@ -50,7 +50,7 @@ public void handle(Context ctx) { AbstractContainerMenu menu = ctx.getPlayer().containerMenu; if (menu.containerId == syncId && menu instanceof MachineMenuServer machineMenu) { - ShapeSelection.Server shapeSelection = machineMenu.blockEntity.getGuiComponents().get(GuiComponents.SHAPE_SELECTION); + ShapeSelection.Server shapeSelection = machineMenu.blockEntity.guiComponents.get(GuiComponents.SHAPE_SELECTION); shapeSelection.behavior.handleClick(shapeLine, clickedLeftButton ? -1 : +1); } } diff --git a/src/main/java/aztech/modern_industrialization/network/machines/ReiLockSlotsPacket.java b/src/main/java/aztech/modern_industrialization/network/machines/ReiLockSlotsPacket.java index 9f0689be5..93439fa21 100644 --- a/src/main/java/aztech/modern_industrialization/network/machines/ReiLockSlotsPacket.java +++ b/src/main/java/aztech/modern_industrialization/network/machines/ReiLockSlotsPacket.java @@ -48,7 +48,7 @@ public void handle(Context ctx) { AbstractContainerMenu sh = ctx.getPlayer().containerMenu; if (sh.containerId == containedId && sh instanceof MachineMenuServer screenHandler) { // Check that locking the slots is allowed in the first place - ReiSlotLocking.Server slotLocking = screenHandler.blockEntity.getGuiComponents().get(GuiComponents.REI_SLOT_LOCKING); + ReiSlotLocking.Server slotLocking = screenHandler.blockEntity.guiComponents.get(GuiComponents.REI_SLOT_LOCKING); if (!slotLocking.allowLocking.get()) return; diff --git a/src/main/java/aztech/modern_industrialization/network/machines/SetAutoExtractPacket.java b/src/main/java/aztech/modern_industrialization/network/machines/SetAutoExtractPacket.java index b8ef3181d..4e9efc963 100644 --- a/src/main/java/aztech/modern_industrialization/network/machines/SetAutoExtractPacket.java +++ b/src/main/java/aztech/modern_industrialization/network/machines/SetAutoExtractPacket.java @@ -50,7 +50,7 @@ public void handle(Context ctx) { if (ctx.getPlayer().containerMenu.containerId == syncId) { var screenHandler = (MachineMenuServer) ctx.getPlayer().containerMenu; - AutoExtract.Server autoExtract = screenHandler.blockEntity.getGuiComponents().get(GuiComponents.AUTO_EXTRACT); + AutoExtract.Server autoExtract = screenHandler.blockEntity.guiComponents.get(GuiComponents.AUTO_EXTRACT); OrientationComponent orientation = autoExtract.getOrientation(); if (isItem) { orientation.extractItems = isExtract; From 99c0cbd7d4adf4dbac02ab7a5bd9a3e3968bcb4c Mon Sep 17 00:00:00 2001 From: Swedz Date: Tue, 26 Nov 2024 20:24:18 -0500 Subject: [PATCH 4/9] Revert changes to MachineScreenPredicateTest --- .../impl/MachineScreenPredicateTest.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/client/java/aztech/modern_industrialization/compat/viewer/impl/MachineScreenPredicateTest.java b/src/client/java/aztech/modern_industrialization/compat/viewer/impl/MachineScreenPredicateTest.java index 16b638aaf..3368e037d 100644 --- a/src/client/java/aztech/modern_industrialization/compat/viewer/impl/MachineScreenPredicateTest.java +++ b/src/client/java/aztech/modern_industrialization/compat/viewer/impl/MachineScreenPredicateTest.java @@ -24,24 +24,22 @@ package aztech.modern_industrialization.compat.viewer.impl; import aztech.modern_industrialization.compat.rei.machines.ReiMachineRecipes; +import aztech.modern_industrialization.machines.gui.GuiComponentClient; import aztech.modern_industrialization.machines.gui.MachineScreen; import aztech.modern_industrialization.machines.guicomponents.CraftingMultiblockGuiClient; -import java.util.Optional; public class MachineScreenPredicateTest { public static boolean test(ReiMachineRecipes.MachineScreenPredicate predicate, MachineScreen screen) { return switch (predicate) { case ANY -> true; - case MULTIBLOCK -> screen.getMenu().components.findOrDefault( - client -> { - if (client instanceof CraftingMultiblockGuiClient cmGui) { - if (cmGui.isShapeValid) { - return Optional.of(true); - } - } - return Optional.empty(); - }, - false); + case MULTIBLOCK -> { + for (GuiComponentClient client : screen.getMenu().components) { + if (client instanceof CraftingMultiblockGuiClient cmGui && cmGui.isShapeValid) { + yield true; + } + } + yield false; + } }; } } From d28b26cd9b17a8b61207c383323b35dad91ecdd9 Mon Sep 17 00:00:00 2001 From: Swedz Date: Tue, 26 Nov 2024 20:25:10 -0500 Subject: [PATCH 5/9] Dont use NotNull in ComponentStorage iterator method --- .../modern_industrialization/machines/ComponentStorage.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java b/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java index b942146ec..a2fefb810 100644 --- a/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java +++ b/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java @@ -33,12 +33,10 @@ import java.util.function.Consumer; import java.util.function.Function; import net.minecraft.resources.ResourceLocation; -import org.jetbrains.annotations.NotNull; public sealed class ComponentStorage implements Iterable permits ComponentStorage.GuiServer, ComponentStorage.Server { protected final List components = new ArrayList<>(); - @NotNull @Override public Iterator iterator() { return components.iterator(); From bce134cc955610d6974806e2f33439b9d1ae2443 Mon Sep 17 00:00:00 2001 From: Swedz Date: Tue, 26 Nov 2024 20:25:59 -0500 Subject: [PATCH 6/9] Unncessary var use removed (accident, whoops) --- .../machines/gui/MachineMenuCommon.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuCommon.java b/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuCommon.java index 8f42f2fef..0ab263493 100644 --- a/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuCommon.java +++ b/src/main/java/aztech/modern_industrialization/machines/gui/MachineMenuCommon.java @@ -53,7 +53,7 @@ public abstract class MachineMenuCommon extends ConfigurableScreenHandler implem } // Gui components first (we want to prioritize them with shift click) - for (GuiComponent.Common component : guiComponents) { + for (var component : guiComponents) { component.setupMenu(this); } From 8fb1f80e1973d382ef0a2dccde078bad1f13ec0d Mon Sep 17 00:00:00 2001 From: Swedz Date: Tue, 26 Nov 2024 20:28:44 -0500 Subject: [PATCH 7/9] Use null instead of optional --- .../machines/gui/MachineMenuClient.java | 2 +- .../machines/ComponentStorage.java | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/client/java/aztech/modern_industrialization/machines/gui/MachineMenuClient.java b/src/client/java/aztech/modern_industrialization/machines/gui/MachineMenuClient.java index a4bee1d3a..0ea706eee 100644 --- a/src/client/java/aztech/modern_industrialization/machines/gui/MachineMenuClient.java +++ b/src/client/java/aztech/modern_industrialization/machines/gui/MachineMenuClient.java @@ -75,7 +75,7 @@ private MachineMenuClient(int syncId, Inventory playerInventory, MIInventory inv @Nullable public T getComponent(Class klass) { - return components.get(klass).orElse(null); + return components.get(klass); } @Override diff --git a/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java b/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java index a2fefb810..7908a7407 100644 --- a/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java +++ b/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java @@ -33,6 +33,7 @@ import java.util.function.Consumer; import java.util.function.Function; import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.Nullable; public sealed class ComponentStorage implements Iterable permits ComponentStorage.GuiServer, ComponentStorage.Server { protected final List components = new ArrayList<>(); @@ -68,13 +69,14 @@ public final void forEachIndexed(BiConsumer action) { } } - public final Optional get(Class clazz) { + @Nullable + public final T get(Class clazz) { for (C component : components) { if (clazz.isInstance(component)) { - return Optional.of((T) component); + return (T) component; } } - return Optional.empty(); + return null; } public final List tryGet(Class clazz) { From 5eab0bbbd711a201394feb442998ee6d11586fa3 Mon Sep 17 00:00:00 2001 From: Swedz Date: Tue, 26 Nov 2024 20:29:50 -0500 Subject: [PATCH 8/9] Rename tryGet to getAll --- .../modern_industrialization/machines/ComponentStorage.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java b/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java index 7908a7407..2fdfc1c6b 100644 --- a/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java +++ b/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java @@ -79,7 +79,7 @@ public final T get(Class clazz) { return null; } - public final List tryGet(Class clazz) { + public final List getAll(Class clazz) { List components = new ArrayList<>(); for (C component : this.components) { if (clazz.isInstance(component)) { @@ -90,14 +90,14 @@ public final List tryGet(Class clazz) { } public final void forType(Class clazz, Consumer action) { - List component = tryGet(clazz); + List component = getAll(clazz); for (T c : component) { action.accept(c); } } public final R mapOrDefault(Class clazz, Function action, R defaultValue) { - List components = tryGet(clazz); + List components = getAll(clazz); if (components.isEmpty()) { return defaultValue; } else if (components.size() == 1) { From 40e056d38e0de9ef42962bf1e2f1b09099770d22 Mon Sep 17 00:00:00 2001 From: Swedz Date: Tue, 26 Nov 2024 20:31:52 -0500 Subject: [PATCH 9/9] Remove findOrDefault --- .../machines/ComponentStorage.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java b/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java index 2fdfc1c6b..3a006d7a9 100644 --- a/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java +++ b/src/main/java/aztech/modern_industrialization/machines/ComponentStorage.java @@ -28,7 +28,6 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; -import java.util.Optional; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; @@ -107,20 +106,6 @@ public final R mapOrDefault(Class clazz, Function R findOrDefault(Function> action, R defaultValue) { - for (C component : components) { - Optional result = action.apply(component); - if (result.isPresent()) { - return result.get(); - } - } - return defaultValue; - } - - public final R findOrDefault(Class clazz, Function> action, R defaultValue) { - return findOrDefault(component -> clazz.isInstance(component) ? action.apply((T) component) : Optional.empty(), defaultValue); - } - public static final class GuiServer extends ComponentStorage { /** * @throws RuntimeException if the component doesn't exist.