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..79e3e6d08 --- /dev/null +++ b/src/main/java/supersymmetry/common/covers/CoverRestrictive.java @@ -0,0 +1,100 @@ +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 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; +import net.minecraftforge.common.capabilities.Capability; +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; + + 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 { + private final Map map = new Object2IntOpenCustomHashMap<>(ItemStackHashStrategy.comparingAllButCount()); + + public ItemHandlerRestrictive(IItemHandler delegate) { + super(delegate); + } + + @NotNull + @Override + public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean 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); + } + } +} 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 000000000..245fdd66e Binary files /dev/null and b/src/main/resources/assets/gregtech/textures/blocks/cover/overlay_restrictive_filter.png differ 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 000000000..9b5e7dd63 Binary files /dev/null and b/src/main/resources/assets/gregtech/textures/items/metaitems/restrictive_filter.png differ diff --git a/src/main/resources/assets/susy/lang/en_us.lang b/src/main/resources/assets/susy/lang/en_us.lang index b3a8e6546..265a21374 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 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.