From 33401d32527afa1a3686a57e22e12114a880da72 Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Sun, 28 Jul 2024 14:08:32 +0200 Subject: [PATCH 1/4] add chemical conduits --- .../client/gui/screen/FluidFilterScreen.java | 24 +++ .../capability/FluidFilterCapability.java | 1 - .../base/common/menu/FluidFilterMenu.java | 2 +- .../resources/assets/enderio/lang/en_us.json | 1 + .../enderio/models/item/chemical_filter.json | 6 + .../mods/laserio/LaserChemicalFilter.java | 99 +++++++++++ .../mods/laserio/LaserIOIntegration.java | 4 + .../mods/laserio/MekansimIntegration.java | 27 +++ .../mods/mekanism/ChemicalConduit.java | 11 +- .../mods/mekanism/ChemicalFilter.java | 10 ++ .../mekanism/ChemicalFilterCapability.java | 158 ++++++++++++++++++ .../mods/mekanism/ChemicalFilterItem.java | 48 ++++++ .../mods/mekanism/ChemicalFilterMenu.java | 97 +++++++++++ .../mods/mekanism/ChemicalFilterScreen.java | 103 ++++++++++++ .../mods/mekanism/ChemicalFilterSlot.java | 68 ++++++++ .../mods/mekanism/ChemicalTicker.java | 20 ++- .../mods/mekanism/MekanismModule.java | 44 +++++ .../enderio/textures/item/chemical_filter.png | Bin 0 -> 1662 bytes 18 files changed, 716 insertions(+), 7 deletions(-) create mode 100644 enderio-conduits-modded/src/generated/resources/assets/enderio/models/item/chemical_filter.json create mode 100644 enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserChemicalFilter.java create mode 100644 enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/MekansimIntegration.java create mode 100644 enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilter.java create mode 100644 enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterCapability.java create mode 100644 enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterItem.java create mode 100644 enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterMenu.java create mode 100644 enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterScreen.java create mode 100644 enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterSlot.java create mode 100644 enderio-conduits-modded/src/main/resources/assets/enderio/textures/item/chemical_filter.png diff --git a/enderio-base/src/main/java/com/enderio/base/client/gui/screen/FluidFilterScreen.java b/enderio-base/src/main/java/com/enderio/base/client/gui/screen/FluidFilterScreen.java index 517f42a65f..0dabf5bb7a 100644 --- a/enderio-base/src/main/java/com/enderio/base/client/gui/screen/FluidFilterScreen.java +++ b/enderio-base/src/main/java/com/enderio/base/client/gui/screen/FluidFilterScreen.java @@ -1,7 +1,11 @@ package com.enderio.base.client.gui.screen; import com.enderio.EnderIOBase; +import com.enderio.base.api.attachment.StoredEntityData; +import com.enderio.base.common.capability.EntityFilterCapability; import com.enderio.base.common.capability.FluidFilterCapability; +import com.enderio.base.common.init.EIODataComponents; +import com.enderio.base.common.init.EIOItems; import com.enderio.base.common.lang.EIOLang; import com.enderio.base.common.menu.FluidFilterMenu; import com.enderio.core.client.gui.screen.EIOScreen; @@ -16,6 +20,7 @@ import net.minecraft.util.FastColor; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions; import net.neoforged.neoforge.fluids.FluidStack; import org.apache.commons.lang3.NotImplementedException; @@ -75,6 +80,25 @@ public void renderSlot(GuiGraphics pGuiGraphics, Slot pSlot) { } } + @Override + protected void renderTooltip(GuiGraphics guiGraphics, int x, int y) { + if (this.menu.getCarried().isEmpty() && this.hoveredSlot != null) { + ItemStack itemstack = this.hoveredSlot.getItem(); + var capability = getMenu().getFilter(); + if (hoveredSlot.index < capability.getEntries().size()) { + FluidStack value = capability.getEntries().get(hoveredSlot.index); + if (!value.isEmpty()) { + guiGraphics.renderTooltip(this.font, value.getHoverName(), x, y); + return; + } + } + if (itemstack.isEmpty()) { + return; + } + guiGraphics.renderTooltip(this.font, this.getTooltipFromContainerItem(itemstack), itemstack.getTooltipImage(), itemstack, x, y); + } + } + @Override public ResourceLocation getBackgroundImage() { return BG_TEXTURE; diff --git a/enderio-base/src/main/java/com/enderio/base/common/capability/FluidFilterCapability.java b/enderio-base/src/main/java/com/enderio/base/common/capability/FluidFilterCapability.java index ce53812fab..b82bdd0ff5 100644 --- a/enderio-base/src/main/java/com/enderio/base/common/capability/FluidFilterCapability.java +++ b/enderio-base/src/main/java/com/enderio/base/common/capability/FluidFilterCapability.java @@ -48,7 +48,6 @@ private Component getComponent() { @Override public void setInverted(Boolean inverted) { container.set(componentType, this.getComponent().withInvert(inverted)); - } @Override diff --git a/enderio-base/src/main/java/com/enderio/base/common/menu/FluidFilterMenu.java b/enderio-base/src/main/java/com/enderio/base/common/menu/FluidFilterMenu.java index 57f89bfa59..b49b2fefb0 100644 --- a/enderio-base/src/main/java/com/enderio/base/common/menu/FluidFilterMenu.java +++ b/enderio-base/src/main/java/com/enderio/base/common/menu/FluidFilterMenu.java @@ -93,7 +93,7 @@ public void setInverted(Boolean inverted) { @Override public void clicked(int pSlotId, int pButton, ClickType pClickType, Player pPlayer) { - if (pSlotId < capability.getEntries().size()) { + if (pSlotId < capability.getEntries().size() && pSlotId >= 0) { if (!capability.getEntries().get(pSlotId).isEmpty()) { capability.setEntry(pSlotId, FluidStack.EMPTY); } diff --git a/enderio-conduits-modded/src/generated/resources/assets/enderio/lang/en_us.json b/enderio-conduits-modded/src/generated/resources/assets/enderio/lang/en_us.json index 4fb4c882ea..36352c9d53 100644 --- a/enderio-conduits-modded/src/generated/resources/assets/enderio/lang/en_us.json +++ b/enderio-conduits-modded/src/generated/resources/assets/enderio/lang/en_us.json @@ -1,4 +1,5 @@ { + "item.enderio.chemical_filter": "Chemical Filter", "item.enderio.conduit.chemical": "Chemical Conduit", "item.enderio.conduit.chemical.multi": "Allows multiple chemical types to be transported on the same line", "item.enderio.conduit.dense_me": "Dense ME Conduit", diff --git a/enderio-conduits-modded/src/generated/resources/assets/enderio/models/item/chemical_filter.json b/enderio-conduits-modded/src/generated/resources/assets/enderio/models/item/chemical_filter.json new file mode 100644 index 0000000000..48adc0c136 --- /dev/null +++ b/enderio-conduits-modded/src/generated/resources/assets/enderio/models/item/chemical_filter.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "enderio:item/chemical_filter" + } +} \ No newline at end of file diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserChemicalFilter.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserChemicalFilter.java new file mode 100644 index 0000000000..714020505a --- /dev/null +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserChemicalFilter.java @@ -0,0 +1,99 @@ +package com.enderio.modconduits.mods.laserio; + +import com.direwolf20.laserio.common.containers.customhandler.FilterCountHandler; +import com.direwolf20.laserio.common.items.cards.BaseCard; +import com.direwolf20.laserio.setup.LaserIODataComponents; +import com.enderio.base.common.capability.IFilterCapability; +import com.enderio.modconduits.mods.mekanism.ChemicalFilter; +import com.enderio.modconduits.mods.mekanism.MekanismModule; +import mekanism.api.chemical.IChemicalHandler; +import mekanism.api.chemical.merged.BoxedChemicalStack; +import net.minecraft.world.item.ItemStack; + +import java.util.ArrayList; +import java.util.List; + +public class LaserChemicalFilter implements IFilterCapability, ChemicalFilter { + + private final ItemStack container; + + public LaserChemicalFilter(ItemStack cardItem) { + this.container = BaseCard.getFilter(cardItem); + } + + @Override + public void setNbt(Boolean nbt) { + if (!nbt) { + container.remove(LaserIODataComponents.FILTER_COMPARE); + } else { + container.set(LaserIODataComponents.FILTER_COMPARE, nbt); + } + } + + @Override + public boolean isNbt() { + return container.getOrDefault(LaserIODataComponents.FILTER_COMPARE, false); + } + + @Override + public void setInverted(Boolean inverted) { + if (!inverted) { + container.remove(LaserIODataComponents.FILTER_ALLOW); + } else { + container.set(LaserIODataComponents.FILTER_ALLOW, false); + } + } + + @Override + public boolean isInvert() { + return !container.getOrDefault(LaserIODataComponents.FILTER_ALLOW, true); + } + + @Override + public List getEntries() { + List filteredChemicals = new ArrayList(); + FilterCountHandler filterSlotHandler = new FilterCountHandler(15, container); + + for(int i = 0; i < (filterSlotHandler).getSlots(); ++i) { + ItemStack stack = filterSlotHandler.getStackInSlot(i); + if (!stack.isEmpty()) { + IChemicalHandler capability = stack.getCapability(MekanismModule.Capabilities.Item.GAS); + if (capability == null) { + capability = stack.getCapability(MekanismModule.Capabilities.Item.SLURRY); + } + if (capability == null) { + capability = stack.getCapability(MekanismModule.Capabilities.Item.INFUSION); + } + if (capability == null) { + capability = stack.getCapability(MekanismModule.Capabilities.Item.PIGMENT); + } + if (capability != null) { + + for(int tank = 0; tank < capability.getTanks(); ++tank) { + var chemical = capability.getChemicalInTank(tank); + if (!chemical.isEmpty()) { + filteredChemicals.add(BoxedChemicalStack.box(chemical)); + } + } + } + } + } + + return filteredChemicals; + } + + @Override + public void setEntry(int index, BoxedChemicalStack entry) { + + } + + @Override + public boolean test(BoxedChemicalStack boxedChemicalStack) { + for (BoxedChemicalStack stack : getEntries()) { + if (stack.getChemicalStack().getChemical() == boxedChemicalStack.getChemicalStack().getChemical()) { + return !isInvert(); + } + } + return isInvert(); + } +} diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserIOIntegration.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserIOIntegration.java index 92ad300a01..ff6df1d732 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserIOIntegration.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserIOIntegration.java @@ -3,6 +3,8 @@ import com.direwolf20.laserio.setup.Registration; import com.enderio.base.api.filter.ResourceFilter; import com.enderio.base.api.integration.Integration; +import com.enderio.base.api.integration.IntegrationManager; +import com.enderio.base.api.integration.IntegrationWrapper; import com.enderio.base.common.init.EIOCapabilities; import com.enderio.modconduits.ModdedConduits; import net.minecraft.world.item.ItemStack; @@ -20,6 +22,8 @@ public class LaserIOIntegration implements Integration { public static ICapabilityProvider FLUID_FILTER_PROVIDER = (stack, v) -> new LaserFluidFilter(stack); + public static final IntegrationWrapper MEK_LASER_IO_INTEGRATION = IntegrationManager.wrapper("mekanism", () -> MekansimIntegration::new, ModdedConduits.modEventBus); + @Override public void addEventListener(IEventBus modEventBus, IEventBus forgeEventBus) { modEventBus.addListener(this::registerCapEvent); diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/MekansimIntegration.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/MekansimIntegration.java new file mode 100644 index 0000000000..9c0821fce9 --- /dev/null +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/MekansimIntegration.java @@ -0,0 +1,27 @@ +package com.enderio.modconduits.mods.laserio; + +import com.direwolf20.laserio.setup.Registration; +import com.enderio.base.api.filter.ResourceFilter; +import com.enderio.base.api.integration.Integration; +import com.enderio.base.common.init.EIOCapabilities; +import net.minecraft.world.item.ItemStack; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.neoforge.capabilities.ICapabilityProvider; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; + +public class MekansimIntegration implements Integration { + + public static ICapabilityProvider CHEMICAL_FILTER_PROVIDER = + (stack, v) -> new LaserChemicalFilter(stack); + + @Override + public void addEventListener(IEventBus modEventBus, IEventBus forgeEventBus) { + modEventBus.addListener(this::registerCapEvent); + } + + @SubscribeEvent + public void registerCapEvent(RegisterCapabilitiesEvent event) { + event.registerItem(EIOCapabilities.Filter.ITEM, CHEMICAL_FILTER_PROVIDER, Registration.Card_Chemical.get()); + } +} diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalConduit.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalConduit.java index b88654f62a..c2913eda3d 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalConduit.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalConduit.java @@ -1,9 +1,11 @@ package com.enderio.modconduits.mods.mekanism; +import com.enderio.base.api.filter.ResourceFilter; import com.enderio.conduits.api.Conduit; import com.enderio.conduits.api.ConduitMenuData; import com.enderio.conduits.api.ConduitNode; import com.enderio.conduits.api.ConduitType; +import com.enderio.conduits.api.SlotType; import com.enderio.conduits.common.init.ConduitLang; import com.enderio.core.common.util.TooltipUtil; import com.mojang.serialization.Codec; @@ -38,8 +40,8 @@ public record ChemicalConduit( private static final ChemicalTicker TICKER = new ChemicalTicker(MekanismModule.Capabilities.GAS, MekanismModule.Capabilities.SLURRY, MekanismModule.Capabilities.INFUSION, MekanismModule.Capabilities.PIGMENT); - private static final ConduitMenuData MENU_DATA = new ConduitMenuData.Simple(false, false, false, false, false, true); - private static final ConduitMenuData MULTI_MENU_DATA = new ConduitMenuData.Simple(false, false, false, true, true, true); + private static final ConduitMenuData MENU_DATA = new ConduitMenuData.Simple(true, true, false, false, false, true); + private static final ConduitMenuData MULTI_MENU_DATA = new ConduitMenuData.Simple(true, true, false, true, true, true); @Override public ConduitType type() { @@ -133,4 +135,9 @@ public int compareTo(@NotNull ChemicalConduit o) { } // TODO: Support for extract upgrades + + @Override + public boolean canApplyFilter(SlotType slotType, ResourceFilter resourceFilter) { + return resourceFilter instanceof ChemicalFilter; + } } diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilter.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilter.java new file mode 100644 index 0000000000..4c4586711c --- /dev/null +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilter.java @@ -0,0 +1,10 @@ +package com.enderio.modconduits.mods.mekanism; + +import com.enderio.base.api.filter.ResourceFilter; +import mekanism.api.chemical.merged.BoxedChemicalStack; + +import java.util.function.Predicate; + +public interface ChemicalFilter extends ResourceFilter, Predicate { + +} diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterCapability.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterCapability.java new file mode 100644 index 0000000000..75a5f7a690 --- /dev/null +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterCapability.java @@ -0,0 +1,158 @@ +package com.enderio.modconduits.mods.mekanism; + +import com.enderio.base.common.capability.IFilterCapability; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import mekanism.api.chemical.merged.BoxedChemicalStack; +import net.minecraft.core.NonNullList; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.world.item.ItemStack; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.OptionalInt; +import java.util.function.Supplier; + +public class ChemicalFilterCapability implements IFilterCapability, ChemicalFilter { + + public static final Component EMPTY = new Component(List.of(), false); + + private final Supplier> componentType; + private final ItemStack container; + + public ChemicalFilterCapability(Supplier> componentType, ItemStack container) { + this.componentType = componentType; + this.container = container; + } + + public Component getComponent() { + return this.container.getOrDefault(componentType, EMPTY); + } + + @Override + public void setNbt(Boolean nbt) { + + } + + @Override + public boolean isNbt() { + return false; + } + + @Override + public void setInverted(Boolean inverted) { + this.container.set(componentType, getComponent().withInvert(inverted)); + } + + @Override + public boolean isInvert() { + return getComponent().invert; + } + + @Override + public List getEntries() { + return getComponent().chemicals; + } + + @Override + public void setEntry(int index, BoxedChemicalStack entry) { + this.container.set(componentType, getComponent().withChemicals(index, entry)); + } + + + @Override + public boolean test(BoxedChemicalStack boxedChemicalStack) { + for (BoxedChemicalStack stack : getEntries()) { + if (stack.getChemicalStack().getChemical() == boxedChemicalStack.getChemicalStack().getChemical()) { + return !isInvert(); + } + } + return isInvert(); + } + + public record Component(List chemicals, boolean invert) { + public static Codec CODEC = RecordCodecBuilder.create(componentInstance -> componentInstance + .group(Component.Slot.CODEC.sizeLimitedListOf(256).fieldOf("chemicals").xmap(Component::fromList, Component::fromChemicals).forGetter( + Component::chemicals), + Codec.BOOL.fieldOf("nbt").forGetter(Component::invert)) + .apply(componentInstance, Component::new)); + + public static final StreamCodec STREAM_CODEC = StreamCodec.composite(BoxedChemicalStack.OPTIONAL_STREAM_CODEC + .apply(ByteBufCodecs.list(256)), Component::chemicals, + ByteBufCodecs.BOOL, Component::invert, Component::new); + + public Component(int size) { + this(NonNullList.withSize(size, BoxedChemicalStack.EMPTY), false); + } + + private static List fromChemicals(List chemicals) { + List slots = new ArrayList<>(); + for (int i = 0; i < chemicals.size(); i++) { + slots.add(new Component.Slot(i, chemicals.get(i))); + } + return slots; + } + + private static List fromList(List slots) { + OptionalInt optionalint = slots.stream().mapToInt(Component.Slot::index).max(); + if (optionalint.isEmpty()) { + return List.of(); + } + List chemicals = NonNullList.withSize(optionalint.getAsInt() + 1, BoxedChemicalStack.EMPTY); + for (Component.Slot slot : slots) { + chemicals.set(slot.index, slot.chemical); + } + return chemicals; + } + + public Component withInvert(boolean invert) { + return new Component(this.chemicals, invert); + } + + public Component withChemicals(int pSlotId, BoxedChemicalStack entry) { + List newChemicals = new ArrayList<>(); + chemicals.forEach(f -> newChemicals.add(f.copy())); + newChemicals.set(pSlotId, entry); + return new Component(newChemicals, invert); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Component component = (Component) o; + for (int i = 0; i < chemicals.size(); i++) { + if (!chemicals.get(i).equals(component.chemicals.get(i))) { + return false; + } + } + return invert == component.invert; + } + + @Override + public int hashCode() { + return Objects.hash(chemicals.hashCode(), invert); + } + + public record Slot(int index, BoxedChemicalStack chemical) { + public static final Codec CODEC = RecordCodecBuilder.create( + p_331695_ -> p_331695_.group( + Codec.intRange(0, 255).fieldOf("slot").forGetter(Component.Slot::index), + BoxedChemicalStack.OPTIONAL_CODEC.fieldOf("fluid").forGetter(Component.Slot::chemical) + ) + .apply(p_331695_, Component.Slot::new) + ); + } + } + +} diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterItem.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterItem.java new file mode 100644 index 0000000000..e3f243210b --- /dev/null +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterItem.java @@ -0,0 +1,48 @@ +package com.enderio.modconduits.mods.mekanism; + +import com.enderio.base.api.filter.ResourceFilter; +import com.enderio.base.common.menu.FluidFilterMenu; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.neoforged.neoforge.capabilities.ICapabilityProvider; + +public class ChemicalFilterItem extends Item { + + public static ICapabilityProvider FILTER_PROVIDER = + (stack, v) -> new ChemicalFilterCapability(MekanismModule.CHEMICAL_FILTER, stack); + + public ChemicalFilterItem(Properties properties) { + super(properties); + } + + @Override + public InteractionResultHolder use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { + if (pPlayer instanceof ServerPlayer serverPlayer) { + openMenu(serverPlayer); + } + return super.use(pLevel, pPlayer, pUsedHand); + } + + private static void openMenu(ServerPlayer player) { + player.openMenu(new MenuProvider() { + @Override + public Component getDisplayName() { + return Component.literal(""); + } + + @Override + public AbstractContainerMenu createMenu(int pContainerId, Inventory pInventory, Player pPlayer) { + return new ChemicalFilterMenu(pContainerId, pInventory, player.getMainHandItem()); + } + }); + } +} diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterMenu.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterMenu.java new file mode 100644 index 0000000000..9ae1ed4277 --- /dev/null +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterMenu.java @@ -0,0 +1,97 @@ +package com.enderio.modconduits.mods.mekanism; + +import com.enderio.base.common.init.EIOCapabilities; +import com.enderio.base.common.init.EIOMenus; +import com.enderio.base.common.network.FilterUpdatePacket; +import mekanism.api.chemical.merged.BoxedChemicalStack; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ClickType; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.network.PacketDistributor; + +import java.util.List; + +public class ChemicalFilterMenu extends AbstractContainerMenu { + + private final ItemStack stack; + private final ChemicalFilterCapability capability; + + public ChemicalFilterMenu(MenuType pMenuType, int pContainerId, Inventory inventory, ItemStack stack) { + super(pMenuType, pContainerId); + this.stack = stack; + + var resourceFilter = stack.getCapability(EIOCapabilities.Filter.ITEM); + if (!(resourceFilter instanceof ChemicalFilterCapability filterCapability)) { + throw new IllegalArgumentException(); + } + + capability = filterCapability; + + List items = capability.getEntries(); + for (int i = 0; i < items.size(); i++) { + int pSlot = i; + addSlot(new ChemicalFilterSlot(fluidStack -> capability.setEntry(pSlot, fluidStack) ,i ,14 + ( i % 5) * 18, 35 + 20 * ( i / 5))); + } + addInventorySlots(14,119, inventory); + } + + public ChemicalFilterMenu(int pContainerId, Inventory inventory, ItemStack stack) { + this(MekanismModule.CHEMICAL_FILTER_MENU.get(), pContainerId, inventory, stack); + } + + public static ChemicalFilterMenu factory(int pContainerId, Inventory inventory, FriendlyByteBuf buf) { + return new ChemicalFilterMenu(MekanismModule.CHEMICAL_FILTER_MENU.get(), pContainerId, inventory, inventory.player.getMainHandItem()); + } + + @Override + public ItemStack quickMoveStack(Player pPlayer, int pIndex) { + return ItemStack.EMPTY; + } + + @Override + public boolean stillValid(Player pPlayer) { + return pPlayer.getMainHandItem().equals(stack); + } + + public void addInventorySlots(int xPos, int yPos, Inventory inventory) { + + // Hotbar + for (int x = 0; x < 9; x++) { + Slot ref = new Slot(inventory, x, xPos + x * 18, yPos + 58); + this.addSlot(ref); + } + + // Inventory + for (int y = 0; y < 3; y++) { + for (int x = 0; x < 9; x++) { + Slot ref = new Slot(inventory, x + y * 9 + 9, xPos + x * 18, yPos + y * 18); + this.addSlot(ref); + } + } + + } + + public ChemicalFilterCapability getFilter() { + return capability; + } + + public void setInverted(Boolean inverted) { + PacketDistributor.sendToServer(new FilterUpdatePacket(capability.isNbt(), inverted)); + capability.setInverted(inverted); + } + + @Override + public void clicked(int pSlotId, int pButton, ClickType pClickType, Player pPlayer) { + if (pSlotId < capability.getEntries().size() && pSlotId >= 0) { + if (!capability.getEntries().get(pSlotId).isEmpty()) { + capability.setEntry(pSlotId, BoxedChemicalStack.EMPTY); + } + } + super.clicked(pSlotId, pButton, pClickType, pPlayer); + } +} diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterScreen.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterScreen.java new file mode 100644 index 0000000000..3a1228944b --- /dev/null +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterScreen.java @@ -0,0 +1,103 @@ +package com.enderio.modconduits.mods.mekanism; + +import com.enderio.EnderIOBase; +import com.enderio.base.common.lang.EIOLang; +import com.enderio.core.client.gui.screen.EIOScreen; +import com.enderio.core.client.gui.widgets.ToggleImageButton; +import com.mojang.blaze3d.systems.RenderSystem; +import mekanism.api.chemical.merged.BoxedChemicalStack; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.texture.TextureAtlas; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.FastColor; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.apache.commons.lang3.NotImplementedException; +import org.joml.Vector2i; + +public class ChemicalFilterScreen extends EIOScreen { + + private static final Vector2i BG_SIZE = new Vector2i(183,201); + private static ResourceLocation BG_TEXTURE = EnderIOBase.loc("textures/gui/40/item_filter.png"); + private static final ResourceLocation BLACKLIST_TEXTURE = EnderIOBase.loc("textures/gui/icons/blacklist.png"); + private static final ResourceLocation NBT_TEXTURE = EnderIOBase.loc("textures/gui/icons/range_buttons.png"); + + public ChemicalFilterScreen(ChemicalFilterMenu pMenu, Inventory pPlayerInventory, Component pTitle) { + super(pMenu, pPlayerInventory, pTitle); + BG_TEXTURE = switch (pMenu.getFilter().getEntries().size()) { + case 5 -> EnderIOBase.loc("textures/gui/40/basic_item_filter.png"); + case 2 * 5 -> EnderIOBase.loc("textures/gui/40/advanced_item_filter.png"); + case 4 * 9 -> EnderIOBase.loc("textures/gui/40/big_item_filter.png"); + default -> throw new NotImplementedException(); + }; + } + + @Override + protected void init() { + super.init(); + addRenderableWidget(new ToggleImageButton<>(this, getGuiLeft() + 110,getGuiTop() + 36 + 20, 16, 16, 0, 0, 16, 0, BLACKLIST_TEXTURE, getMenu().getFilter()::isInvert, getMenu()::setInverted, () -> getMenu().getFilter().isInvert() ? EIOLang.BLACKLIST_FILTER : EIOLang.WHITELIST_FILTER)); + + } + + @Override + public void renderSlot(GuiGraphics pGuiGraphics, Slot pSlot) { + ChemicalFilterCapability filterCapability = getMenu().getFilter(); + if (pSlot.index >= filterCapability.getEntries().size()) { + super.renderSlot(pGuiGraphics, pSlot); + return; + } + + BoxedChemicalStack stack = filterCapability.getEntries().get(pSlot.index); + + if (stack.isEmpty()) { + return; + } + TextureAtlasSprite sprite = Minecraft.getInstance() + .getTextureAtlas(TextureAtlas.LOCATION_BLOCKS) + .apply(stack.getChemicalStack().getChemical().getIcon()); + + int color = stack.getChemicalStack().getChemicalTint(); + RenderSystem.setShaderColor(((color >> 16) & 0xFF) / 255.0F, ((color >> 8) & 0xFF) / 255.0F, + (color & 0xFF) / 255.0F, 1); + RenderSystem.enableBlend(); + + int atlasWidth = (int) (sprite.contents().width() / (sprite.getU1() - sprite.getU0())); + int atlasHeight = (int) (sprite.contents().height() / (sprite.getV1() - sprite.getV0())); + pGuiGraphics.blit(TextureAtlas.LOCATION_BLOCKS, pSlot.x, pSlot.y, 16, 16, sprite.getU0() * atlasWidth, sprite.getV0() * atlasHeight, sprite.contents().width(), sprite.contents().height(), + atlasWidth, atlasHeight); + RenderSystem.setShaderColor(1, 1, 1, 1); + } + + @Override + protected void renderTooltip(GuiGraphics guiGraphics, int x, int y) { + if (this.menu.getCarried().isEmpty() && this.hoveredSlot != null) { + ItemStack itemstack = this.hoveredSlot.getItem(); + var capability = getMenu().getFilter(); + if (hoveredSlot.index < capability.getEntries().size()) { + BoxedChemicalStack value = capability.getEntries().get(hoveredSlot.index); + if (!value.isEmpty()) { + guiGraphics.renderTooltip(this.font, value.getTextComponent(), x, y); + return; + } + } + if (itemstack.isEmpty()) { + return; + } + guiGraphics.renderTooltip(this.font, this.getTooltipFromContainerItem(itemstack), itemstack.getTooltipImage(), itemstack, x, y); + } + } + + @Override + public ResourceLocation getBackgroundImage() { + return BG_TEXTURE; + } + + @Override + protected Vector2i getBackgroundImageSize() { + return BG_SIZE; + } +} diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterSlot.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterSlot.java new file mode 100644 index 0000000000..5a414b38b0 --- /dev/null +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterSlot.java @@ -0,0 +1,68 @@ +package com.enderio.modconduits.mods.mekanism; + +import mekanism.api.chemical.IChemicalHandler; +import mekanism.api.chemical.merged.BoxedChemicalStack; +import net.minecraft.world.Container; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; + +import java.util.function.Consumer; + +public class ChemicalFilterSlot extends Slot { + + private static final Container emptyInventory = new SimpleContainer(0); + private final Consumer consumer; + + public ChemicalFilterSlot(Consumer consumer, int pSlot, int pX, int pY) { + super(emptyInventory, pSlot, pX, pY); + this.consumer = consumer; + } + + @Override + public ItemStack getItem() { + return ItemStack.EMPTY; + } + + @Override + public void set(ItemStack pStack) { + setChanged(); + } + + @Override + public void setChanged() { + + } + + @Override + public ItemStack remove(int pAmount) { + set(ItemStack.EMPTY); + return ItemStack.EMPTY; + } + + @Override + public int getMaxStackSize() { + return getItem().getMaxStackSize(); + } + + @Override + public ItemStack safeInsert(ItemStack stack, int amount) { + // If this stack is valid, set the inventory slot value. + IChemicalHandler capability = stack.getCapability(MekanismModule.Capabilities.Item.GAS); + if (capability == null || capability.getChemicalInTank(0).isEmpty()) { + capability = stack.getCapability(MekanismModule.Capabilities.Item.SLURRY); + } + if (capability == null || capability.getChemicalInTank(0).isEmpty()) { + capability = stack.getCapability(MekanismModule.Capabilities.Item.INFUSION); + } + if (capability == null || capability.getChemicalInTank(0).isEmpty()) { + capability = stack.getCapability(MekanismModule.Capabilities.Item.PIGMENT); + } + if (!stack.isEmpty() && mayPlace(stack) && capability != null) { + var ghost = capability.getChemicalInTank(0).copy(); + consumer.accept(BoxedChemicalStack.box(ghost)); + } + + return stack; + } +} diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalTicker.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalTicker.java index bedc7cb2e0..4760999357 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalTicker.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalTicker.java @@ -8,6 +8,7 @@ import mekanism.api.chemical.ChemicalStack; import mekanism.api.chemical.ChemicalType; import mekanism.api.chemical.IChemicalHandler; +import mekanism.api.chemical.merged.BoxedChemicalStack; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; import net.neoforged.neoforge.capabilities.BlockCapability; @@ -30,12 +31,15 @@ protected void tickCapabilityGraph( ColoredRedstoneProvider coloredRedstoneProvider) { for (var extract : extractCaps) { - tickExtractCapability(conduit, extract.capability(), extract.node(), insertCaps); + tickExtractCapability(conduit, extract, insertCaps); } } - private , S extends ChemicalStack> void tickExtractCapability(ChemicalConduit conduit, IChemicalHandler extractHandler, - ConduitNode node, List>> insertCaps) { + private , S extends ChemicalStack> void tickExtractCapability(ChemicalConduit conduit, + CapabilityConnection> extractCap, List>> insertCaps) { + + IChemicalHandler extractHandler = (IChemicalHandler) extractCap.capability(); + ConduitNode node = extractCap.node(); ChemicalConduitData data = node.getOrCreateData(MekanismModule.CHEMICAL_DATA_TYPE.get()); @@ -52,9 +56,19 @@ private , S extends ChemicalStack> void tickExtractCapa if (result.isEmpty()) { return; } + if (extractCap.extractFilter() instanceof ChemicalFilter filter) { + if (!filter.test(BoxedChemicalStack.box(result))) { + return; + } + } long transferred = 0; for (var insert : insertCaps) { + if (insert.insertFilter() instanceof ChemicalFilter filter) { + if (!filter.test(BoxedChemicalStack.box(result))) { + continue; + } + } ChemicalType insertType = ChemicalType.getTypeFor(insert.capability()); if (extractType != insertType) { continue; diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/MekanismModule.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/MekanismModule.java index 99287b6f09..b90688030e 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/MekanismModule.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/MekanismModule.java @@ -1,7 +1,14 @@ package com.enderio.modconduits.mods.mekanism; import com.enderio.EnderIOBase; +import com.enderio.base.client.gui.screen.FluidFilterScreen; +import com.enderio.base.common.capability.FluidFilterCapability; +import com.enderio.base.common.init.EIOCapabilities; +import com.enderio.base.common.init.EIOCreativeTabs; +import com.enderio.base.common.init.EIODataComponents; import com.enderio.base.common.init.EIOItems; +import com.enderio.base.common.item.filter.FluidFilter; +import com.enderio.base.common.menu.FluidFilterMenu; import com.enderio.conduits.api.Conduit; import com.enderio.conduits.api.ConduitDataType; import com.enderio.conduits.api.ConduitType; @@ -10,6 +17,10 @@ import com.enderio.conduits.common.recipe.ConduitIngredient; import com.enderio.modconduits.ConduitModule; import com.enderio.modconduits.ModdedConduits; +import com.enderio.regilite.holder.RegiliteItem; +import com.enderio.regilite.holder.RegiliteMenu; +import com.enderio.regilite.registry.ItemRegistry; +import com.enderio.regilite.registry.MenuRegistry; import mekanism.api.MekanismAPI; import mekanism.api.chemical.gas.IGasHandler; import mekanism.api.chemical.infuse.IInfusionHandler; @@ -19,6 +30,7 @@ import net.minecraft.advancements.critereon.InventoryChangeTrigger; import net.minecraft.core.Direction; import net.minecraft.core.HolderLookup; +import net.minecraft.core.component.DataComponentType; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.recipes.RecipeCategory; import net.minecraft.data.recipes.RecipeOutput; @@ -30,6 +42,7 @@ import net.minecraft.resources.ResourceLocation; import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.capabilities.BlockCapability; +import net.neoforged.neoforge.capabilities.ItemCapability; import net.neoforged.neoforge.common.conditions.ICondition; import net.neoforged.neoforge.common.conditions.ModLoadedCondition; import net.neoforged.neoforge.registries.DeferredRegister; @@ -46,6 +59,23 @@ public class MekanismModule implements ConduitModule { public static final DeferredRegister> CONDUIT_DATA_TYPES = DeferredRegister.create(EnderIOConduitsRegistries.CONDUIT_DATA_TYPE, ModdedConduits.REGISTRY_NAMESPACE); + private static final DeferredRegister.DataComponents DATA_COMPONENT_TYPES = DeferredRegister.createDataComponents(ModdedConduits.REGISTRY_NAMESPACE); + + public static final Supplier> CHEMICAL_FILTER = DATA_COMPONENT_TYPES + .registerComponentType("chemical_filter", builder -> builder.persistent(ChemicalFilterCapability.Component.CODEC).networkSynchronized(ChemicalFilterCapability.Component.STREAM_CODEC)); + + private static final ItemRegistry ITEM_REGISTRY = ModdedConduits.REGILITE.itemRegistry(); + + public static final RegiliteItem BASIC_CHEMICAL_FILTER = ITEM_REGISTRY + .registerItem("chemical_filter", properties -> new ChemicalFilterItem(properties.component(CHEMICAL_FILTER, new ChemicalFilterCapability.Component(5)))) + .setTab(EIOCreativeTabs.GEAR) + .addCapability(EIOCapabilities.Filter.ITEM, ChemicalFilterItem.FILTER_PROVIDER); + + private static final MenuRegistry MENU_REGISTRY = ModdedConduits.REGILITE.menuRegistry(); + + public static final RegiliteMenu CHEMICAL_FILTER_MENU = MENU_REGISTRY + .registerMenu("chemical_filter", ChemicalFilterMenu::factory, () -> ChemicalFilterScreen::new); + public static class Types { private static final DeferredRegister> CONDUIT_TYPES = DeferredRegister.create(EnderIOConduitsRegistries.CONDUIT_TYPE, @@ -67,6 +97,17 @@ public static class Capabilities { ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "pigment_handler"), IPigmentHandler.class); public static final BlockCapability HEAT = BlockCapability.createSided( ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "heat_handler"), IHeatHandler.class); + + public static class Item { + public static final ItemCapability GAS = ItemCapability.createVoid( + ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "gas_handler"), IGasHandler.class); + public static final ItemCapability SLURRY = ItemCapability.createVoid( + ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "slurry_handler"), ISlurryHandler.class); + public static final ItemCapability INFUSION = ItemCapability.createVoid( + ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "infusion_handler"), IInfusionHandler.class); + public static final ItemCapability PIGMENT = ItemCapability.createVoid( + ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "pigment_handler"), IPigmentHandler.class); + } } public static final ResourceKey> CHEMICAL = ResourceKey.create(EnderIOConduitsRegistries.Keys.CONDUIT, EnderIOBase.loc("chemical")); @@ -95,6 +136,9 @@ private static MutableComponent addTranslation(String prefix, ResourceLocation i public void register(IEventBus modEventBus) { Types.CONDUIT_TYPES.register(modEventBus); CONDUIT_DATA_TYPES.register(modEventBus); + DATA_COMPONENT_TYPES.register(modEventBus); + ITEM_REGISTRY.register(modEventBus); + MENU_REGISTRY.register(modEventBus); } @Override diff --git a/enderio-conduits-modded/src/main/resources/assets/enderio/textures/item/chemical_filter.png b/enderio-conduits-modded/src/main/resources/assets/enderio/textures/item/chemical_filter.png new file mode 100644 index 0000000000000000000000000000000000000000..cea84d681b2319b6bb0113a008f3e6992a1bd9b8 GIT binary patch literal 1662 zcmbVNdraJP953LIF^7O6gfQ)jTOe7lzxIy1YsWExLmu0~1ulUt*|gXG?ylkbSX;O| zTrwuiK%&OzC0mvmmu2pc#aEUXlgUJ4G){r&O!&hkPG!XT$cWB_EM(}f_X;!9#Wnf0 zzhC?LK0e=9C;i>+n~ST9F$~+>+2QR)&r)j@6{7nSH~-?%W24rw*TAq%k60@YJ8`lK z!ydRH1qRFk-yTj-Wg9Q5L1>H18bV`O4r9rlfM2ZWJ9ffb2eO?YFRLkeVQ@_1a1Dh3z#5GlPJ+FP$F0#8BAK@ZVv8N>&C ze!NxHA-9dJF@{ba zB4U~vM^Uj@%oelTR6R`5EXz`Wp%{il2+~L>CLbpiqc*F-3k^Y+G*eO)+|tMg)gjYE zAXn2IWG$ywF*0#N5u@U~M$tB4aY_M2A&1k3^k~YsC{Qp8WvG}2!qPdc7Ew*rh^YUf zI`{bw11PpWU(Uu|eUasy3Bzm~Ml>=3xhvWTBs56%LPH(W1=u!>+^n_OXk4ofc~jK` zsv6B^%Aa)^XB;+w*Y!(^sK$)?bpp`Ko6tj`tl3H6BpGLbc5rq#XLpdm#Q~6p`czR0 zCDub-B+UjGh64_+fxQEYYDVNu{+?h_;6kb{^N6q{^I=G7N|?ZNVdPrXsH!8w$UA$= z3!jhcR1A|>1lZ~I5Qwu)l0=RLf-@L$1JZ2=A(Cxy1j!)lVoAHh&Wi#Ya=M|ImG`Q` zkd@i2y!b!mdvpo479YKDJyye6CBbz_21-^U(-D2}U}hJU@KhCWykJ$ghY+l^S`5;! zrTdORT0RzmNa=s1I}J0`kQw83*c?XDx@S32$a%`@!!!@-pA=Ky*7a-_js}6X&5a;* z$PF>5pvk495fwgK*@t0y&Q5Q0!2Qyjee}y?ptNSH@byhe8+Gv0H!gpDtssGwPwPF$ zoaI}X@|L&eDr%Z`{&4!W^K&~6%z?$D(f$30dUf@e3r&F&XE$P}lEt@spnOHiAKL%! zu`jpnd6E8V-zQZC*n11x^B3Kxf4xxg)OO+0xpQl9b>!j;2O1xqEPAHv$i%4<|3vZ+ z;+4t`@xA^>Hymf1f2x^UxxU&|ar|ukwIz6D)&TZ1No{^x-T2414t)k5n$GX4kG$=A zFj2BxbA5Dnc4p>hvun$5OD7A;X4=nGt#s93MP(CpiADR3vR8Lb)K1mzuD{w|+A=z^ z_T+NOk40OPbm4c;&EA}n$8MEgT)Fh^*yuvF@0;&`kB{?LSGKBCtCe}7dF6vE)raB2 vz9gJnz5V$77w5;{A3i*b;j4ef)(VB)mp@;6?4ud$57F7y?R}@^+2{WTR5vls literal 0 HcmV?d00001 From 7b7273c126fff1b5cffada9913f6577e9753ba18 Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Wed, 21 Aug 2024 19:30:36 +0200 Subject: [PATCH 2/4] update mek --- .../recipes/misc/mek_chemical_filter.json | 38 +++++++++++++++++++ .../enderio/recipe/mek_chemical_filter.json | 32 ++++++++++++++++ .../mods/laserio/LaserChemicalFilter.java | 31 ++++++--------- .../mods/mekanism/ChemicalFilter.java | 4 +- .../mekanism/ChemicalFilterCapability.java | 34 ++++++++--------- .../mods/mekanism/ChemicalFilterMenu.java | 7 ++-- .../mods/mekanism/ChemicalFilterScreen.java | 11 +++--- .../mods/mekanism/ChemicalFilterSlot.java | 19 +++------- .../mods/mekanism/ChemicalTicker.java | 17 +++++++-- .../mods/mekanism/MekanismModule.java | 33 +++++++++------- 10 files changed, 147 insertions(+), 79 deletions(-) create mode 100644 enderio-conduits-modded/src/generated/resources/data/enderio/advancement/recipes/misc/mek_chemical_filter.json create mode 100644 enderio-conduits-modded/src/generated/resources/data/enderio/recipe/mek_chemical_filter.json diff --git a/enderio-conduits-modded/src/generated/resources/data/enderio/advancement/recipes/misc/mek_chemical_filter.json b/enderio-conduits-modded/src/generated/resources/data/enderio/advancement/recipes/misc/mek_chemical_filter.json new file mode 100644 index 0000000000..3d5f2e9a55 --- /dev/null +++ b/enderio-conduits-modded/src/generated/resources/data/enderio/advancement/recipes/misc/mek_chemical_filter.json @@ -0,0 +1,38 @@ +{ + "neoforge:conditions": [ + { + "type": "neoforge:mod_loaded", + "modid": "mekanism" + } + ], + "parent": "minecraft:recipes/root", + "criteria": { + "has_ingredient": { + "conditions": { + "items": [ + { + "items": "minecraft:paper" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "enderio:mek_chemical_filter" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_ingredient" + ] + ], + "rewards": { + "recipes": [ + "enderio:mek_chemical_filter" + ] + } +} \ No newline at end of file diff --git a/enderio-conduits-modded/src/generated/resources/data/enderio/recipe/mek_chemical_filter.json b/enderio-conduits-modded/src/generated/resources/data/enderio/recipe/mek_chemical_filter.json new file mode 100644 index 0000000000..c6eabc971d --- /dev/null +++ b/enderio-conduits-modded/src/generated/resources/data/enderio/recipe/mek_chemical_filter.json @@ -0,0 +1,32 @@ +{ + "neoforge:conditions": [ + { + "type": "neoforge:mod_loaded", + "modid": "mekanism" + } + ], + "type": "minecraft:crafting_shaped", + "category": "misc", + "key": { + "O": { + "tag": "c:ingots/osmium" + }, + "P": [ + { + "item": "minecraft:paper" + }, + { + "item": "enderio:black_paper" + } + ] + }, + "pattern": [ + " P ", + "POP", + " P " + ], + "result": { + "count": 1, + "id": "enderio:chemical_filter" + } +} \ No newline at end of file diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserChemicalFilter.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserChemicalFilter.java index 714020505a..d89ffac349 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserChemicalFilter.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserChemicalFilter.java @@ -6,14 +6,14 @@ import com.enderio.base.common.capability.IFilterCapability; import com.enderio.modconduits.mods.mekanism.ChemicalFilter; import com.enderio.modconduits.mods.mekanism.MekanismModule; +import mekanism.api.chemical.ChemicalStack; import mekanism.api.chemical.IChemicalHandler; -import mekanism.api.chemical.merged.BoxedChemicalStack; import net.minecraft.world.item.ItemStack; import java.util.ArrayList; import java.util.List; -public class LaserChemicalFilter implements IFilterCapability, ChemicalFilter { +public class LaserChemicalFilter implements IFilterCapability, ChemicalFilter { private final ItemStack container; @@ -50,29 +50,20 @@ public boolean isInvert() { } @Override - public List getEntries() { - List filteredChemicals = new ArrayList(); + public List getEntries() { + List filteredChemicals = new ArrayList(); FilterCountHandler filterSlotHandler = new FilterCountHandler(15, container); for(int i = 0; i < (filterSlotHandler).getSlots(); ++i) { ItemStack stack = filterSlotHandler.getStackInSlot(i); if (!stack.isEmpty()) { - IChemicalHandler capability = stack.getCapability(MekanismModule.Capabilities.Item.GAS); - if (capability == null) { - capability = stack.getCapability(MekanismModule.Capabilities.Item.SLURRY); - } - if (capability == null) { - capability = stack.getCapability(MekanismModule.Capabilities.Item.INFUSION); - } - if (capability == null) { - capability = stack.getCapability(MekanismModule.Capabilities.Item.PIGMENT); - } + IChemicalHandler capability = stack.getCapability(MekanismModule.Capabilities.Item.CHEMICAL); if (capability != null) { - for(int tank = 0; tank < capability.getTanks(); ++tank) { + for(int tank = 0; tank < capability.getChemicalTanks(); ++tank) { var chemical = capability.getChemicalInTank(tank); if (!chemical.isEmpty()) { - filteredChemicals.add(BoxedChemicalStack.box(chemical)); + filteredChemicals.add(chemical); } } } @@ -83,14 +74,14 @@ public List getEntries() { } @Override - public void setEntry(int index, BoxedChemicalStack entry) { + public void setEntry(int index, ChemicalStack entry) { } @Override - public boolean test(BoxedChemicalStack boxedChemicalStack) { - for (BoxedChemicalStack stack : getEntries()) { - if (stack.getChemicalStack().getChemical() == boxedChemicalStack.getChemicalStack().getChemical()) { + public boolean test(ChemicalStack boxedChemicalStack) { + for (ChemicalStack stack : getEntries()) { + if (ChemicalStack.isSameChemical(stack, boxedChemicalStack)) { return !isInvert(); } } diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilter.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilter.java index 4c4586711c..d60cc85683 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilter.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilter.java @@ -1,10 +1,10 @@ package com.enderio.modconduits.mods.mekanism; import com.enderio.base.api.filter.ResourceFilter; -import mekanism.api.chemical.merged.BoxedChemicalStack; +import mekanism.api.chemical.ChemicalStack; import java.util.function.Predicate; -public interface ChemicalFilter extends ResourceFilter, Predicate { +public interface ChemicalFilter extends ResourceFilter, Predicate { } diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterCapability.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterCapability.java index 75a5f7a690..1acc4c7a2b 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterCapability.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterCapability.java @@ -3,7 +3,7 @@ import com.enderio.base.common.capability.IFilterCapability; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import mekanism.api.chemical.merged.BoxedChemicalStack; +import mekanism.api.chemical.ChemicalStack; import net.minecraft.core.NonNullList; import net.minecraft.core.component.DataComponentType; import net.minecraft.network.RegistryFriendlyByteBuf; @@ -17,7 +17,7 @@ import java.util.OptionalInt; import java.util.function.Supplier; -public class ChemicalFilterCapability implements IFilterCapability, ChemicalFilter { +public class ChemicalFilterCapability implements IFilterCapability, ChemicalFilter { public static final Component EMPTY = new Component(List.of(), false); @@ -54,42 +54,42 @@ public boolean isInvert() { } @Override - public List getEntries() { + public List getEntries() { return getComponent().chemicals; } @Override - public void setEntry(int index, BoxedChemicalStack entry) { + public void setEntry(int index, ChemicalStack entry) { this.container.set(componentType, getComponent().withChemicals(index, entry)); } @Override - public boolean test(BoxedChemicalStack boxedChemicalStack) { - for (BoxedChemicalStack stack : getEntries()) { - if (stack.getChemicalStack().getChemical() == boxedChemicalStack.getChemicalStack().getChemical()) { + public boolean test(ChemicalStack boxedChemicalStack) { + for (ChemicalStack stack : getEntries()) { + if (ChemicalStack.isSameChemical(stack, boxedChemicalStack)) { return !isInvert(); } } return isInvert(); } - public record Component(List chemicals, boolean invert) { + public record Component(List chemicals, boolean invert) { public static Codec CODEC = RecordCodecBuilder.create(componentInstance -> componentInstance .group(Component.Slot.CODEC.sizeLimitedListOf(256).fieldOf("chemicals").xmap(Component::fromList, Component::fromChemicals).forGetter( Component::chemicals), Codec.BOOL.fieldOf("nbt").forGetter(Component::invert)) .apply(componentInstance, Component::new)); - public static final StreamCodec STREAM_CODEC = StreamCodec.composite(BoxedChemicalStack.OPTIONAL_STREAM_CODEC + public static final StreamCodec STREAM_CODEC = StreamCodec.composite(ChemicalStack.OPTIONAL_STREAM_CODEC .apply(ByteBufCodecs.list(256)), Component::chemicals, ByteBufCodecs.BOOL, Component::invert, Component::new); public Component(int size) { - this(NonNullList.withSize(size, BoxedChemicalStack.EMPTY), false); + this(NonNullList.withSize(size, ChemicalStack.EMPTY), false); } - private static List fromChemicals(List chemicals) { + private static List fromChemicals(List chemicals) { List slots = new ArrayList<>(); for (int i = 0; i < chemicals.size(); i++) { slots.add(new Component.Slot(i, chemicals.get(i))); @@ -97,12 +97,12 @@ private static List fromChemicals(List chemi return slots; } - private static List fromList(List slots) { + private static List fromList(List slots) { OptionalInt optionalint = slots.stream().mapToInt(Component.Slot::index).max(); if (optionalint.isEmpty()) { return List.of(); } - List chemicals = NonNullList.withSize(optionalint.getAsInt() + 1, BoxedChemicalStack.EMPTY); + List chemicals = NonNullList.withSize(optionalint.getAsInt() + 1, ChemicalStack.EMPTY); for (Component.Slot slot : slots) { chemicals.set(slot.index, slot.chemical); } @@ -113,8 +113,8 @@ public Component withInvert(boolean invert) { return new Component(this.chemicals, invert); } - public Component withChemicals(int pSlotId, BoxedChemicalStack entry) { - List newChemicals = new ArrayList<>(); + public Component withChemicals(int pSlotId, ChemicalStack entry) { + List newChemicals = new ArrayList<>(); chemicals.forEach(f -> newChemicals.add(f.copy())); newChemicals.set(pSlotId, entry); return new Component(newChemicals, invert); @@ -144,11 +144,11 @@ public int hashCode() { return Objects.hash(chemicals.hashCode(), invert); } - public record Slot(int index, BoxedChemicalStack chemical) { + public record Slot(int index, ChemicalStack chemical) { public static final Codec CODEC = RecordCodecBuilder.create( p_331695_ -> p_331695_.group( Codec.intRange(0, 255).fieldOf("slot").forGetter(Component.Slot::index), - BoxedChemicalStack.OPTIONAL_CODEC.fieldOf("fluid").forGetter(Component.Slot::chemical) + ChemicalStack.OPTIONAL_CODEC.fieldOf("fluid").forGetter(Component.Slot::chemical) ) .apply(p_331695_, Component.Slot::new) ); diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterMenu.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterMenu.java index 9ae1ed4277..b9d3f33ca7 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterMenu.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterMenu.java @@ -1,9 +1,8 @@ package com.enderio.modconduits.mods.mekanism; import com.enderio.base.common.init.EIOCapabilities; -import com.enderio.base.common.init.EIOMenus; import com.enderio.base.common.network.FilterUpdatePacket; -import mekanism.api.chemical.merged.BoxedChemicalStack; +import mekanism.api.chemical.ChemicalStack; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; @@ -32,7 +31,7 @@ public ChemicalFilterMenu(MenuType pMenuType, int pContainerId, Inventory inv capability = filterCapability; - List items = capability.getEntries(); + List items = capability.getEntries(); for (int i = 0; i < items.size(); i++) { int pSlot = i; addSlot(new ChemicalFilterSlot(fluidStack -> capability.setEntry(pSlot, fluidStack) ,i ,14 + ( i % 5) * 18, 35 + 20 * ( i / 5))); @@ -89,7 +88,7 @@ public void setInverted(Boolean inverted) { public void clicked(int pSlotId, int pButton, ClickType pClickType, Player pPlayer) { if (pSlotId < capability.getEntries().size() && pSlotId >= 0) { if (!capability.getEntries().get(pSlotId).isEmpty()) { - capability.setEntry(pSlotId, BoxedChemicalStack.EMPTY); + capability.setEntry(pSlotId, ChemicalStack.EMPTY); } } super.clicked(pSlotId, pButton, pClickType, pPlayer); diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterScreen.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterScreen.java index 3a1228944b..88d3758ebe 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterScreen.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterScreen.java @@ -5,14 +5,13 @@ import com.enderio.core.client.gui.screen.EIOScreen; import com.enderio.core.client.gui.widgets.ToggleImageButton; import com.mojang.blaze3d.systems.RenderSystem; -import mekanism.api.chemical.merged.BoxedChemicalStack; +import mekanism.api.chemical.ChemicalStack; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.FastColor; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; @@ -51,16 +50,16 @@ public void renderSlot(GuiGraphics pGuiGraphics, Slot pSlot) { return; } - BoxedChemicalStack stack = filterCapability.getEntries().get(pSlot.index); + ChemicalStack stack = filterCapability.getEntries().get(pSlot.index); if (stack.isEmpty()) { return; } TextureAtlasSprite sprite = Minecraft.getInstance() .getTextureAtlas(TextureAtlas.LOCATION_BLOCKS) - .apply(stack.getChemicalStack().getChemical().getIcon()); + .apply(stack.getChemical().getIcon()); - int color = stack.getChemicalStack().getChemicalTint(); + int color = stack.getChemicalTint(); RenderSystem.setShaderColor(((color >> 16) & 0xFF) / 255.0F, ((color >> 8) & 0xFF) / 255.0F, (color & 0xFF) / 255.0F, 1); RenderSystem.enableBlend(); @@ -78,7 +77,7 @@ protected void renderTooltip(GuiGraphics guiGraphics, int x, int y) { ItemStack itemstack = this.hoveredSlot.getItem(); var capability = getMenu().getFilter(); if (hoveredSlot.index < capability.getEntries().size()) { - BoxedChemicalStack value = capability.getEntries().get(hoveredSlot.index); + ChemicalStack value = capability.getEntries().get(hoveredSlot.index); if (!value.isEmpty()) { guiGraphics.renderTooltip(this.font, value.getTextComponent(), x, y); return; diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterSlot.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterSlot.java index 5a414b38b0..8fff775d0e 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterSlot.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterSlot.java @@ -1,7 +1,7 @@ package com.enderio.modconduits.mods.mekanism; +import mekanism.api.chemical.ChemicalStack; import mekanism.api.chemical.IChemicalHandler; -import mekanism.api.chemical.merged.BoxedChemicalStack; import net.minecraft.world.Container; import net.minecraft.world.SimpleContainer; import net.minecraft.world.inventory.Slot; @@ -12,9 +12,9 @@ public class ChemicalFilterSlot extends Slot { private static final Container emptyInventory = new SimpleContainer(0); - private final Consumer consumer; + private final Consumer consumer; - public ChemicalFilterSlot(Consumer consumer, int pSlot, int pX, int pY) { + public ChemicalFilterSlot(Consumer consumer, int pSlot, int pX, int pY) { super(emptyInventory, pSlot, pX, pY); this.consumer = consumer; } @@ -48,19 +48,10 @@ public int getMaxStackSize() { @Override public ItemStack safeInsert(ItemStack stack, int amount) { // If this stack is valid, set the inventory slot value. - IChemicalHandler capability = stack.getCapability(MekanismModule.Capabilities.Item.GAS); - if (capability == null || capability.getChemicalInTank(0).isEmpty()) { - capability = stack.getCapability(MekanismModule.Capabilities.Item.SLURRY); - } - if (capability == null || capability.getChemicalInTank(0).isEmpty()) { - capability = stack.getCapability(MekanismModule.Capabilities.Item.INFUSION); - } - if (capability == null || capability.getChemicalInTank(0).isEmpty()) { - capability = stack.getCapability(MekanismModule.Capabilities.Item.PIGMENT); - } + IChemicalHandler capability = stack.getCapability(MekanismModule.Capabilities.Item.CHEMICAL); if (!stack.isEmpty() && mayPlace(stack) && capability != null) { var ghost = capability.getChemicalInTank(0).copy(); - consumer.accept(BoxedChemicalStack.box(ghost)); + consumer.accept(ghost); } return stack; diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalTicker.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalTicker.java index f14b18ef70..22abc21354 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalTicker.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalTicker.java @@ -25,12 +25,13 @@ protected void tickCapabilityGraph(ServerLevel level, ColoredRedstoneProvider coloredRedstoneProvider) { for (var extract : extracts) { - tickExtractCapability(conduit, extract.capability(), extract.node(), inserts); + tickExtractCapability(conduit, extract, inserts); } } - private void tickExtractCapability(ChemicalConduit conduit, IChemicalHandler extractHandler, - ConduitNode node, List insertCaps) { + private void tickExtractCapability(ChemicalConduit conduit, CapabilityConnection extract, List insertCaps) { + IChemicalHandler extractHandler = extract.capability(); + ConduitNode node = extract.node(); ChemicalConduitData data = node.getOrCreateData(MekanismModule.CHEMICAL_DATA_TYPE.get()); @@ -48,9 +49,19 @@ private void tickExtractCapability(ChemicalConduit conduit, IChemicalHandler ext if (result.isEmpty()) { return; } + if (extract.extractFilter() instanceof ChemicalFilter filter) { + if (!filter.test(result)) { + return; + } + } long transferred = 0; for (var insert : insertCaps) { + if (insert.insertFilter() instanceof ChemicalFilter filter) { + if (!filter.test(result)) { + continue; + } + } IChemicalHandler destinationHandler = insert.capability(); ChemicalStack transferredChemical; if (!data.lockedChemical.isEmpty()) { diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/MekanismModule.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/MekanismModule.java index ff19c277d3..0abc4ebafe 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/MekanismModule.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/MekanismModule.java @@ -1,14 +1,9 @@ package com.enderio.modconduits.mods.mekanism; import com.enderio.EnderIOBase; -import com.enderio.base.client.gui.screen.FluidFilterScreen; -import com.enderio.base.common.capability.FluidFilterCapability; import com.enderio.base.common.init.EIOCapabilities; import com.enderio.base.common.init.EIOCreativeTabs; -import com.enderio.base.common.init.EIODataComponents; import com.enderio.base.common.init.EIOItems; -import com.enderio.base.common.item.filter.FluidFilter; -import com.enderio.base.common.menu.FluidFilterMenu; import com.enderio.conduits.api.Conduit; import com.enderio.conduits.api.ConduitDataType; import com.enderio.conduits.api.ConduitType; @@ -25,6 +20,7 @@ import mekanism.api.chemical.IChemicalHandler; import mekanism.api.heat.IHeatHandler; import net.minecraft.advancements.critereon.InventoryChangeTrigger; +import net.minecraft.advancements.critereon.ItemPredicate; import net.minecraft.core.Direction; import net.minecraft.core.HolderLookup; import net.minecraft.core.component.DataComponentType; @@ -37,6 +33,11 @@ import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.ItemTags; +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.crafting.Ingredient; import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.capabilities.BlockCapability; import net.neoforged.neoforge.capabilities.ItemCapability; @@ -90,14 +91,8 @@ public static class Capabilities { ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "heat_handler"), IHeatHandler.class); public static class Item { - public static final ItemCapability GAS = ItemCapability.createVoid( - ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "gas_handler"), IGasHandler.class); - public static final ItemCapability SLURRY = ItemCapability.createVoid( - ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "slurry_handler"), ISlurryHandler.class); - public static final ItemCapability INFUSION = ItemCapability.createVoid( - ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "infusion_handler"), IInfusionHandler.class); - public static final ItemCapability PIGMENT = ItemCapability.createVoid( - ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "pigment_handler"), IPigmentHandler.class); + public static final ItemCapability CHEMICAL = ItemCapability.createVoid( + ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "chemical_handler"), IChemicalHandler.class); } } @@ -119,6 +114,8 @@ public static class Item { public static final Component LANG_MULTI_CHEMICAL_TOOLTIP = addTranslation("item", EnderIOBase.loc("conduit.chemical.multi"), "Allows multiple chemical types to be transported on the same line"); + private static final TagKey OSMIUM = ItemTags.create(ResourceLocation.fromNamespaceAndPath("c", "ingots/osmium")); + private static MutableComponent addTranslation(String prefix, ResourceLocation id, String translation) { return ModdedConduits.REGILITE.addTranslation(prefix, id, translation); } @@ -217,5 +214,15 @@ public void buildRecipes(HolderLookup.Provider lookupProvider, RecipeOutput reci .define('I', BuiltInRegistries.ITEM.get(ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "advanced_thermodynamic_conductor"))) .unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(EIOItems.CONDUIT_BINDER)) .save(mekRecipeOutput, EnderIOBase.loc("mek_advanced_thermodynamic_conductor")); + + ShapedRecipeBuilder + .shaped(RecipeCategory.MISC, BASIC_CHEMICAL_FILTER) + .pattern(" P ") + .pattern("POP") + .pattern(" P ") + .define('P', Ingredient.of(Items.PAPER, EIOItems.BLACK_PAPER)) // TODO: c:paper? + .define('O', OSMIUM) + .unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(ItemPredicate.Builder.item().of(OSMIUM))) + .save(mekRecipeOutput, EnderIOBase.loc("mek_chemical_filter")); } } From b6fad80a65e6e2d6fa1a64fecf6c61b27a4e1820 Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Wed, 21 Aug 2024 21:40:55 +0200 Subject: [PATCH 3/4] fix: laserio compat --- .../enderio/modconduits/mods/laserio/LaserChemicalFilter.java | 4 ++-- .../enderio/modconduits/mods/laserio/LaserFluidFilter.java | 4 ++-- .../com/enderio/modconduits/mods/laserio/LaserItemFilter.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserChemicalFilter.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserChemicalFilter.java index d89ffac349..f26a3eb5b1 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserChemicalFilter.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserChemicalFilter.java @@ -1,6 +1,6 @@ package com.enderio.modconduits.mods.laserio; -import com.direwolf20.laserio.common.containers.customhandler.FilterCountHandler; +import com.direwolf20.laserio.common.containers.customhandler.FilterBasicHandler; import com.direwolf20.laserio.common.items.cards.BaseCard; import com.direwolf20.laserio.setup.LaserIODataComponents; import com.enderio.base.common.capability.IFilterCapability; @@ -52,7 +52,7 @@ public boolean isInvert() { @Override public List getEntries() { List filteredChemicals = new ArrayList(); - FilterCountHandler filterSlotHandler = new FilterCountHandler(15, container); + FilterBasicHandler filterSlotHandler = new FilterBasicHandler(15, container); for(int i = 0; i < (filterSlotHandler).getSlots(); ++i) { ItemStack stack = filterSlotHandler.getStackInSlot(i); diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserFluidFilter.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserFluidFilter.java index c69c4634e8..39c5bb175f 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserFluidFilter.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserFluidFilter.java @@ -1,6 +1,6 @@ package com.enderio.modconduits.mods.laserio; -import com.direwolf20.laserio.common.containers.customhandler.FilterCountHandler; +import com.direwolf20.laserio.common.containers.customhandler.FilterBasicHandler; import com.direwolf20.laserio.common.items.cards.BaseCard; import com.direwolf20.laserio.setup.LaserIODataComponents; import com.enderio.base.api.filter.FluidStackFilter; @@ -54,7 +54,7 @@ public boolean isInvert() { @Override public List getEntries() { List filteredFluids = new ArrayList(); - FilterCountHandler filterSlotHandler = new FilterCountHandler(15, container); + FilterBasicHandler filterSlotHandler = new FilterBasicHandler(15, container); for(int i = 0; i < (filterSlotHandler).getSlots(); ++i) { ItemStack itemStack = filterSlotHandler.getStackInSlot(i); diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserItemFilter.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserItemFilter.java index 634ede188f..51b9000457 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserItemFilter.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/laserio/LaserItemFilter.java @@ -1,6 +1,6 @@ package com.enderio.modconduits.mods.laserio; -import com.direwolf20.laserio.common.containers.customhandler.FilterCountHandler; +import com.direwolf20.laserio.common.containers.customhandler.FilterBasicHandler; import com.direwolf20.laserio.common.items.cards.BaseCard; import com.direwolf20.laserio.setup.LaserIODataComponents; import com.enderio.base.api.filter.ItemStackFilter; @@ -48,7 +48,7 @@ public boolean isInvert() { @Override public List getEntries() { - FilterCountHandler handler = new FilterCountHandler(15, container); + FilterBasicHandler handler = new FilterBasicHandler(15, container); List list = NonNullList.withSize(15, ItemStack.EMPTY); for(int i = 0; i < 15; ++i) { ItemStack itemStack = handler.getStackInSlot(i); From 9f302971e7f77de551d22ba8b2c6bcb49ad293ca Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Sat, 14 Sep 2024 16:35:56 +0200 Subject: [PATCH 4/4] fix equals and hash code for lists --- .../capability/EntityFilterCapability.java | 34 +++++++++++++++++++ .../capability/FluidFilterCapability.java | 14 +++++++- .../capability/ItemFilterCapability.java | 2 +- .../base/common/menu/FluidFilterSlot.java | 4 +-- .../mekanism/ChemicalFilterCapability.java | 15 +++++++- .../mods/mekanism/ChemicalFilterScreen.java | 1 - .../mods/mekanism/ChemicalFilterSlot.java | 4 +-- 7 files changed, 66 insertions(+), 8 deletions(-) diff --git a/enderio-base/src/main/java/com/enderio/base/common/capability/EntityFilterCapability.java b/enderio-base/src/main/java/com/enderio/base/common/capability/EntityFilterCapability.java index eb779991e3..027a608e75 100644 --- a/enderio-base/src/main/java/com/enderio/base/common/capability/EntityFilterCapability.java +++ b/enderio-base/src/main/java/com/enderio/base/common/capability/EntityFilterCapability.java @@ -15,10 +15,13 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.fluids.FluidStack; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import java.util.Objects; import java.util.OptionalInt; import java.util.function.Supplier; @@ -150,6 +153,37 @@ public Component withEntities(int pSlotId, StoredEntityData entry) { return new Component(newEntities, nbt, invert); } + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Component component = (Component) o; + for (int i = 0; i < entities.size(); i++) { + if (!entities.get(i).equals(component.entities.get(i))) { + return false; + } + } + return nbt == component.nbt && invert == component.invert; + } + + @Override + public int hashCode() { + return Objects.hash(hashList(entities), nbt, invert); + } + + public static int hashList(List list) { + int i = 0; + + StoredEntityData stack; + for(Iterator var2 = list.iterator(); var2.hasNext(); i = i * 31 + stack.hashCode()) { + stack = var2.next(); + } + + return i; + } + public record Slot(int index, StoredEntityData entity) { public static final Codec CODEC = RecordCodecBuilder.create( p_331695_ -> p_331695_.group( diff --git a/enderio-base/src/main/java/com/enderio/base/common/capability/FluidFilterCapability.java b/enderio-base/src/main/java/com/enderio/base/common/capability/FluidFilterCapability.java index b82bdd0ff5..f8ee78b1f4 100644 --- a/enderio-base/src/main/java/com/enderio/base/common/capability/FluidFilterCapability.java +++ b/enderio-base/src/main/java/com/enderio/base/common/capability/FluidFilterCapability.java @@ -13,6 +13,7 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.OptionalInt; @@ -147,7 +148,18 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash(fluids.hashCode(), nbt, invert); + return Objects.hash(hashStackList(fluids), nbt, invert); + } + + public static int hashStackList(List list) { + int i = 0; + + FluidStack stack; + for(Iterator var2 = list.iterator(); var2.hasNext(); i = i * 31 + FluidStack.hashFluidAndComponents(stack)) { + stack = var2.next(); + } + + return i; } public record Slot(int index, FluidStack fluid) { diff --git a/enderio-base/src/main/java/com/enderio/base/common/capability/ItemFilterCapability.java b/enderio-base/src/main/java/com/enderio/base/common/capability/ItemFilterCapability.java index 3beb8c250b..af4985162c 100644 --- a/enderio-base/src/main/java/com/enderio/base/common/capability/ItemFilterCapability.java +++ b/enderio-base/src/main/java/com/enderio/base/common/capability/ItemFilterCapability.java @@ -141,7 +141,7 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash(items.hashCode(), nbt, invert); + return Objects.hash(ItemStack.hashStackList(items), nbt, invert); } public record Slot(int index, ItemStack item) { diff --git a/enderio-base/src/main/java/com/enderio/base/common/menu/FluidFilterSlot.java b/enderio-base/src/main/java/com/enderio/base/common/menu/FluidFilterSlot.java index 62df34d98d..58d9c65961 100644 --- a/enderio-base/src/main/java/com/enderio/base/common/menu/FluidFilterSlot.java +++ b/enderio-base/src/main/java/com/enderio/base/common/menu/FluidFilterSlot.java @@ -12,11 +12,11 @@ public class FluidFilterSlot extends Slot { - private static Container emptyInventory = new SimpleContainer(0); + private static Container EMPTY_INVENTORY = new SimpleContainer(0); private final Consumer consumer; public FluidFilterSlot(Consumer consumer, int pSlot, int pX, int pY) { - super(emptyInventory, pSlot, pX, pY); + super(EMPTY_INVENTORY, pSlot, pX, pY); this.consumer = consumer; } diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterCapability.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterCapability.java index 1acc4c7a2b..5728597155 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterCapability.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterCapability.java @@ -10,8 +10,10 @@ import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.fluids.FluidStack; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.OptionalInt; @@ -141,7 +143,18 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash(chemicals.hashCode(), invert); + return Objects.hash(hashStackList(chemicals), invert); + } + + public static int hashStackList(List list) { + int i = 0; + + ChemicalStack stack; + for(Iterator var2 = list.iterator(); var2.hasNext(); i = i * 31 + stack.hashCode()) { + stack = var2.next(); + } + + return i; } public record Slot(int index, ChemicalStack chemical) { diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterScreen.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterScreen.java index 88d3758ebe..fd37473c33 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterScreen.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterScreen.java @@ -39,7 +39,6 @@ public ChemicalFilterScreen(ChemicalFilterMenu pMenu, Inventory pPlayerInventory protected void init() { super.init(); addRenderableWidget(new ToggleImageButton<>(this, getGuiLeft() + 110,getGuiTop() + 36 + 20, 16, 16, 0, 0, 16, 0, BLACKLIST_TEXTURE, getMenu().getFilter()::isInvert, getMenu()::setInverted, () -> getMenu().getFilter().isInvert() ? EIOLang.BLACKLIST_FILTER : EIOLang.WHITELIST_FILTER)); - } @Override diff --git a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterSlot.java b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterSlot.java index 8fff775d0e..dca7efdda1 100644 --- a/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterSlot.java +++ b/enderio-conduits-modded/src/main/java/com/enderio/modconduits/mods/mekanism/ChemicalFilterSlot.java @@ -11,11 +11,11 @@ public class ChemicalFilterSlot extends Slot { - private static final Container emptyInventory = new SimpleContainer(0); + private static final Container EMPTY_INVENTORY = new SimpleContainer(0); private final Consumer consumer; public ChemicalFilterSlot(Consumer consumer, int pSlot, int pX, int pY) { - super(emptyInventory, pSlot, pX, pY); + super(EMPTY_INVENTORY, pSlot, pX, pY); this.consumer = consumer; }