From 6ab7973de8c5cba1c7401f9b295146000b9a1454 Mon Sep 17 00:00:00 2001 From: MCTian-mi <35869948+MCTian-mi@users.noreply.github.com> Date: Sun, 22 Dec 2024 19:53:53 +0800 Subject: [PATCH 1/3] feat: restrictive filter --- .../renderer/textures/SusyTextures.java | 3 +- .../common/covers/CoverRestrictive.java | 79 ++++++++++++++++++ .../common/covers/SuSyCoverBehaviors.java | 2 + .../common/item/SuSyMetaItems.java | 3 + .../item/metaitems/restrictive_filter.json | 6 ++ .../cover/overlay_restrictive_filter.png | Bin 0 -> 1948 bytes .../items/metaitems/restrictive_filter.png | Bin 0 -> 1948 bytes .../resources/assets/susy/lang/en_us.lang | 2 + 8 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/main/java/supersymmetry/common/covers/CoverRestrictive.java create mode 100644 src/main/resources/assets/gregtech/models/item/metaitems/restrictive_filter.json create mode 100644 src/main/resources/assets/gregtech/textures/blocks/cover/overlay_restrictive_filter.png create mode 100644 src/main/resources/assets/gregtech/textures/items/metaitems/restrictive_filter.png diff --git a/src/main/java/supersymmetry/client/renderer/textures/SusyTextures.java b/src/main/java/supersymmetry/client/renderer/textures/SusyTextures.java index fa465778c..e920caa0a 100644 --- a/src/main/java/supersymmetry/client/renderer/textures/SusyTextures.java +++ b/src/main/java/supersymmetry/client/renderer/textures/SusyTextures.java @@ -4,8 +4,8 @@ import gregtech.client.renderer.texture.cube.SimpleCubeRenderer; import gregtech.client.renderer.texture.cube.SimpleOverlayRenderer; import gregtech.client.renderer.texture.cube.SimpleSidedCubeRenderer; -import supersymmetry.client.renderer.textures.custom.ExtenderRender; import gregtech.client.renderer.texture.custom.DrumRenderer; +import supersymmetry.client.renderer.textures.custom.ExtenderRender; public class SusyTextures { @@ -84,6 +84,7 @@ public SusyTextures(){ public static final SimpleOverlayRenderer SILICON_CARBIDE_CASING = new SimpleOverlayRenderer("multiblock_casing/silicon_carbide_casing"); public static final SimpleOverlayRenderer ULV_STRUCTURAL_CASING = new SimpleOverlayRenderer("multiblock_casing/ulv_structural_casing"); public static final SimpleOverlayRenderer SLAG_HOT = new SimpleOverlayRenderer("resource/slag_hot"); + public static final SimpleOverlayRenderer RESTRICTIVE_FILTER_FILTER_OVERLAY = new SimpleOverlayRenderer("cover/overlay_restrictive_filter"); public static final SimpleCubeRenderer MASONRY_BRICK = new SimpleCubeRenderer("gregtech:blocks/multiblock_casing/masonry_brick"); diff --git a/src/main/java/supersymmetry/common/covers/CoverRestrictive.java b/src/main/java/supersymmetry/common/covers/CoverRestrictive.java new file mode 100644 index 000000000..b1af84b05 --- /dev/null +++ b/src/main/java/supersymmetry/common/covers/CoverRestrictive.java @@ -0,0 +1,79 @@ +package supersymmetry.common.covers; + +import codechicken.lib.render.CCRenderState; +import codechicken.lib.render.pipeline.IVertexOperation; +import codechicken.lib.vec.Cuboid6; +import codechicken.lib.vec.Matrix4; +import gregtech.api.capability.impl.ItemHandlerDelegate; +import gregtech.api.cover.CoverBase; +import gregtech.api.cover.CoverDefinition; +import gregtech.api.cover.CoverableView; +import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumFacing; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.items.IItemHandler; +import org.jetbrains.annotations.NotNull; +import supersymmetry.client.renderer.textures.SusyTextures; + +public class CoverRestrictive extends CoverBase { + + protected ItemHandlerRestrictive itemHandler; + + public CoverRestrictive(@NotNull CoverDefinition definition, @NotNull CoverableView coverableView, + @NotNull EnumFacing attachedSide) { + super(definition, coverableView, attachedSide); + } + + @Override + public boolean canAttach(@NotNull CoverableView coverable, @NotNull EnumFacing enumFacing) { + return coverable.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, getAttachedSide()) != null; + } + + @Override + public T getCapability(@NotNull Capability capability, T defaultValue) { + if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { + if (defaultValue == null) { + return null; + } + IItemHandler delegate = (IItemHandler) defaultValue; + if (itemHandler == null || itemHandler.delegate != delegate) { + this.itemHandler = new ItemHandlerRestrictive(delegate); + } + return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(itemHandler); + } + return defaultValue; + } + + @Override + public boolean canPipePassThrough() { + return true; + } + + @Override + public void renderCover(@NotNull CCRenderState renderState, @NotNull Matrix4 translation, @NotNull IVertexOperation[] pipeline, + @NotNull Cuboid6 plateBox, @NotNull BlockRenderLayer renderLayer) { + SusyTextures.RESTRICTIVE_FILTER_FILTER_OVERLAY.renderSided(getAttachedSide(), plateBox, renderState, pipeline, translation); + } + + protected static class ItemHandlerRestrictive extends ItemHandlerDelegate { + + public ItemHandlerRestrictive(IItemHandler delegate) { + super(delegate); + } + + @NotNull + @Override + public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) { + if (!stack.isEmpty() && !stack.isItemEqual(delegate.getStackInSlot(slot))) { + for (int i = 0; i < getSlots(); i++) { + if (i != slot && stack.isItemEqual(getStackInSlot(i))) { + return super.insertItem(i, stack, simulate); + } + } + } + return super.insertItem(slot, stack, simulate); + } + } +} diff --git a/src/main/java/supersymmetry/common/covers/SuSyCoverBehaviors.java b/src/main/java/supersymmetry/common/covers/SuSyCoverBehaviors.java index 67ed95677..67f948d66 100644 --- a/src/main/java/supersymmetry/common/covers/SuSyCoverBehaviors.java +++ b/src/main/java/supersymmetry/common/covers/SuSyCoverBehaviors.java @@ -22,6 +22,8 @@ public static void init() { registerBehavior(SuSyUtility.susyId("air_vent"), SuSyMetaItems.AIR_VENT, (definition, coverableView, attachedSide) -> new CoverAirVent(definition, coverableView, attachedSide, 100)); + + registerBehavior(SuSyUtility.susyId("restrictive_filter"), SuSyMetaItems.RESTRICTIVE_FILTER, CoverRestrictive::new); } } diff --git a/src/main/java/supersymmetry/common/item/SuSyMetaItems.java b/src/main/java/supersymmetry/common/item/SuSyMetaItems.java index 8a34c3ba3..4cd3cbf67 100644 --- a/src/main/java/supersymmetry/common/item/SuSyMetaItems.java +++ b/src/main/java/supersymmetry/common/item/SuSyMetaItems.java @@ -21,6 +21,7 @@ public class SuSyMetaItems { public static MetaValueItem CONVEYOR_STEAM; public static MetaValueItem PUMP_STEAM; public static MetaValueItem AIR_VENT; + public static MetaValueItem RESTRICTIVE_FILTER; public static MetaValueItem TRACK_SEGMENT; public static ArmorMetaItem.ArmorMetaValueItem JET_WINGPACK; @@ -58,6 +59,8 @@ private static void initMetaItem() { TRACK_SEGMENT = metaItem.addItem(5, "track_segment").addComponents(new TooltipBehavior((lines) -> { lines.add(I18n.format("metaitem.track_segment.length_info")); })); + + RESTRICTIVE_FILTER = metaItem.addItem(6, "restrictive_filter"); } private static void addTieredOredictItem (OreDictValueItem[] items, int id, int RGB, OrePrefix prefix) { diff --git a/src/main/resources/assets/gregtech/models/item/metaitems/restrictive_filter.json b/src/main/resources/assets/gregtech/models/item/metaitems/restrictive_filter.json new file mode 100644 index 000000000..6d5feb10c --- /dev/null +++ b/src/main/resources/assets/gregtech/models/item/metaitems/restrictive_filter.json @@ -0,0 +1,6 @@ +{ + "parent" : "item/generated", + "textures" : { + "layer0" : "gregtech:items/metaitems/restrictive_filter" + } +} diff --git a/src/main/resources/assets/gregtech/textures/blocks/cover/overlay_restrictive_filter.png b/src/main/resources/assets/gregtech/textures/blocks/cover/overlay_restrictive_filter.png new file mode 100644 index 0000000000000000000000000000000000000000..245fdd66e9982482ef1bdffa1e1a88a95bd49643 GIT binary patch literal 1948 zcmbVNeQXnD7(blOfee@s0YC7#IllCIAHB7`bKTfhaGP|@(S?Cx_V(`WdaS)W?rv*4 zG?-<&O@?4V93SxujHb~=2_gYyF~mt0Sd4#w#ORbM#1OI>G0VaP-|N~2%=idRuJ_)( zzvuV-o{#srj;hLMvZp*e1;eoH@-j~~y3eq#tW5O(_}|w6x=q%~))*M}z)b6!gzert z2gB|=D*I~9TJH)$RKqqPseWjShBbu7u!5qf2E+zv;(k~!D{f-wXb*wQlABna@1?z3 zDGbVG%{pAwTLwDr0$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VRRy!Y$O-Z{RvzB@G&+q!4r)vH%Bsw%~) zi$6S*SKIJhjiS!xyvO~2?VI)QS4RgmS6yf9`Ih$KKQAAw+f?{;smH~Smi3R8m8hN6 zys;xaAH|m_%CU_1;spg`wpG!ZlFpn9kA{ERIU_do`RRv72Bub5baY?*@lsP>-{L$^ l>m0E|&w76$7#`R(XqPTunP!~3w#E8>mM^RHbeGh%{0CI*oOA#H literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gregtech/textures/items/metaitems/restrictive_filter.png b/src/main/resources/assets/gregtech/textures/items/metaitems/restrictive_filter.png new file mode 100644 index 0000000000000000000000000000000000000000..9b5e7dd63ed2b595d845b6b9a4a3914461aacbf4 GIT binary patch literal 1948 zcmbVNeQeZZ7%xsIAcG-`fEp~t@uj_f-R-V*H`sQ}4Y@J5TNo&0?c4WuWp{09yWQQ; zV3z4N8A1ece8ev>nu{(<5DDlOL!4xR#rOwEjG~|rL&#>tkOc(a-tI17#z$z<_HFxn ze$Vguc%ODwRX&?D@zIGGhUHY0`>N4B*FMK*qw5oYUl-ABf?mGT#IT2^+2=TH=k6I8 z_P}8!P-oTomkB_NI7C^Kpd%L15gNk^7sYfDG(roPV1uH1iJ`-N1g^+lVuj03`}I;7 zQp#HlSkqD&04hmoS`Q# z5wa{@pr~jx>WFd<&1j$)p64l=rC63k2-1wJmKY;db55GU2Tfoox}|6;ZZnFK)?|4J zBy}`~h@PQU%~YOH#;BO6Q;dVQV@d*LkiqFqMmXtQ1{4g#2vjW-VVMk84{4TWhO}Ey zXFlKL0Oi*2&-fTqOC*wUVOmR?Q5dO&jEOb_aUD|C(A1g?0GBi)nRD!DbfMIMqNN!D zO$(Evjq+YpT9y;Wi4thxWNGWL<@QeyJ{rEk}Mlwc!A~wmVS!%2sAwk^=q;c zjE@E7c!A?@f})<0MN7ORSO!8+Ga@1iSc!-YkkZu#0?(vTDAmH6fgB@sTvCPKFI1?e zC8_{c_`C#)*`X-1z(83lklaC10ze{pk5eKgk#m!r>~aHHk|ieuX?vdrn(WG^?PX-| zaQiTbN5__GqHXcu%&D{67BB7G_Apa+s0S3iJEbK@>N*zWKKUXx zv~KXX-A7h!WU_}|j&EjWP3stcVpYMeoW#=ACqG_$ifB#zaDe2`gDJ+K=X_Od|5+w6 zaH(ZrWMn#4wr46f$oqcp#@k-G{LZ1Cm5#S3wU;{jR^Ru%Gv~rTI}?fFUoJnH*Sf8G zcK4d)r_?WBJl=EgVE1RIhjuLM{U8w=T7Uo7+5IyDZ+&-s8n$`YyldC4WK~syNeeza znP1oVe66ZYclwV=f9=Wp_p8Habx(a){Dszz;Xg0!uisGgOsUVqkCYFNl$U5-)U2zA z`aVi5RMp``TuJ jPGkK0^TgrP8_sg_r7M%oGuJoS|IdmgmA;;m`quvdr?8(u literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/susy/lang/en_us.lang b/src/main/resources/assets/susy/lang/en_us.lang index b3a8e6546..8a8886ac0 100644 --- a/src/main/resources/assets/susy/lang/en_us.lang +++ b/src/main/resources/assets/susy/lang/en_us.lang @@ -797,6 +797,8 @@ cover.conveyor.steam.title=Steam Conveyor Module metaitem.pump.steam.name=Steam Pump cover.pump.steam.title=Steam Pump metaitem.air_vent.name=Air Vent +metaitem.restrictive_filter.name=Restrictive Filter +metaitem.restrictive_filter.tooltip=§oHere you may come, but no further.§r §7Job 38:11 metaitem.air_vent.tooltip=Passively collects a Dimension's Air for your Machines when facing Air metaitem.track_segment.name=Monorail Track Segment metaitem.track_segment.tooltip=For use in the §8tunnelbore. From 08a6a45307eddcbcfda82d9d01dd7e8e971a7f32 Mon Sep 17 00:00:00 2001 From: bruberu <80226372+bruberu@users.noreply.github.com> Date: Sat, 28 Dec 2024 22:29:39 -0600 Subject: [PATCH 2/3] fix: better lang --- src/main/resources/assets/susy/lang/en_us.lang | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/assets/susy/lang/en_us.lang b/src/main/resources/assets/susy/lang/en_us.lang index 8a8886ac0..265a21374 100644 --- a/src/main/resources/assets/susy/lang/en_us.lang +++ b/src/main/resources/assets/susy/lang/en_us.lang @@ -797,8 +797,8 @@ cover.conveyor.steam.title=Steam Conveyor Module metaitem.pump.steam.name=Steam Pump cover.pump.steam.title=Steam Pump metaitem.air_vent.name=Air Vent -metaitem.restrictive_filter.name=Restrictive Filter -metaitem.restrictive_filter.tooltip=§oHere you may come, but no further.§r §7Job 38:11 +metaitem.restrictive_filter.name=Restrictive Item Filter +metaitem.restrictive_filter.tooltip=Allows only §6one stack§7 of any type of item inside. Can replace robot arms. %n§oHere you may come, but no further.§r §7Job 38:11 metaitem.air_vent.tooltip=Passively collects a Dimension's Air for your Machines when facing Air metaitem.track_segment.name=Monorail Track Segment metaitem.track_segment.tooltip=For use in the §8tunnelbore. From e2401d0687a86eb13ea8a8e935ae7ff45a3dbe8b Mon Sep 17 00:00:00 2001 From: bruberu <80226372+bruberu@users.noreply.github.com> Date: Mon, 30 Dec 2024 16:58:46 -0600 Subject: [PATCH 3/3] feat: add a map to make it faster --- .../common/covers/CoverRestrictive.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/supersymmetry/common/covers/CoverRestrictive.java b/src/main/java/supersymmetry/common/covers/CoverRestrictive.java index b1af84b05..79e3e6d08 100644 --- a/src/main/java/supersymmetry/common/covers/CoverRestrictive.java +++ b/src/main/java/supersymmetry/common/covers/CoverRestrictive.java @@ -8,6 +8,11 @@ import gregtech.api.cover.CoverBase; import gregtech.api.cover.CoverDefinition; import gregtech.api.cover.CoverableView; +import gregtech.api.util.ItemStackHashStrategy; +import it.unimi.dsi.fastutil.objects.Object2IntArrayMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenCustomHashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.EnumFacing; @@ -15,8 +20,11 @@ import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; +import supersymmetry.api.recipes.catalysts.CatalystInfo; import supersymmetry.client.renderer.textures.SusyTextures; +import java.util.Map; + public class CoverRestrictive extends CoverBase { protected ItemHandlerRestrictive itemHandler; @@ -58,6 +66,7 @@ public void renderCover(@NotNull CCRenderState renderState, @NotNull Matrix4 tra } protected static class ItemHandlerRestrictive extends ItemHandlerDelegate { + private final Map map = new Object2IntOpenCustomHashMap<>(ItemStackHashStrategy.comparingAllButCount()); public ItemHandlerRestrictive(IItemHandler delegate) { super(delegate); @@ -66,11 +75,23 @@ public ItemHandlerRestrictive(IItemHandler delegate) { @NotNull @Override public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) { - if (!stack.isEmpty() && !stack.isItemEqual(delegate.getStackInSlot(slot))) { - for (int i = 0; i < getSlots(); i++) { - if (i != slot && stack.isItemEqual(getStackInSlot(i))) { - return super.insertItem(i, stack, simulate); - } + if (stack.isEmpty() || stack.isItemEqual(getStackInSlot(slot))) { + return super.insertItem(slot, stack, simulate); + } + // Makes things more efficient for common items. + if (map.containsKey(stack)) { + int location = map.get(stack); + if (stack.isItemEqual(getStackInSlot(location))) { + return super.insertItem(location, stack, simulate); + } else { + map.remove(stack); + } + } + // If it's not already in the map of what goes where, we search if it happens to be anywhere already, for some reason. + for (int i = 0; i < getSlots(); i++) { + if (i != slot && stack.isItemEqual(getStackInSlot(i))) { + map.put(stack, i); + return super.insertItem(i, stack, simulate); } } return super.insertItem(slot, stack, simulate);