From 284b1821b49fd8412593c38640bee21acecda9f3 Mon Sep 17 00:00:00 2001 From: Integer Limit <103940576+IntegerLimit@users.noreply.github.com> Date: Sat, 5 Oct 2024 22:26:43 +1000 Subject: [PATCH] Fix Custom Upgrade NBT with Comp Drawers, Tooltip --- .../nomilabs/groovy/GroovyHelpers.java | 7 ++++ .../storagedrawers/ItemCompDrawersMixin.java | 39 +++++++++++++++++++ .../nomilabs/tooltip/LabsTooltipHelper.java | 3 ++ .../nomilabs/tooltip/TooltipAdder.java | 10 +++++ .../resources/assets/nomilabs/lang/en_us.lang | 2 + .../mixins.nomilabs.storagedrawers.json | 1 + 6 files changed, 62 insertions(+) create mode 100644 src/main/java/com/nomiceu/nomilabs/mixin/storagedrawers/ItemCompDrawersMixin.java diff --git a/src/main/java/com/nomiceu/nomilabs/groovy/GroovyHelpers.java b/src/main/java/com/nomiceu/nomilabs/groovy/GroovyHelpers.java index c1bb241..54f5e6d 100644 --- a/src/main/java/com/nomiceu/nomilabs/groovy/GroovyHelpers.java +++ b/src/main/java/com/nomiceu/nomilabs/groovy/GroovyHelpers.java @@ -590,6 +590,13 @@ public static NBTTagCompound transferTagAtPath(ItemStack orig, @Nullable NBTTagC /** * Only should be used for drawers (from Storage Drawers, Framed Compacting Drawers, GregTech Drawers, etc.). * Makes use of custom Labs mixins and nbt, so that the drawer does not appear taped. + *

+ * Confirmed to Work on: + *

*/ public static NBTTagCompound transferDrawerUpgradeData(ItemStack orig, @Nullable NBTTagCompound existing) { var origCompound = orig.getTagCompound(); diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/storagedrawers/ItemCompDrawersMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/storagedrawers/ItemCompDrawersMixin.java new file mode 100644 index 0000000..f0439d1 --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/mixin/storagedrawers/ItemCompDrawersMixin.java @@ -0,0 +1,39 @@ +package com.nomiceu.nomilabs.mixin.storagedrawers; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers; +import com.jaquadro.minecraft.storagedrawers.item.ItemCompDrawers; +import com.nomiceu.nomilabs.integration.storagedrawers.CustomUpgradeHandler; + +/** + * Reads from Labs Upgrade NBT. + *

+ * ItemCompDrawers doesn't inherit from ItemDrawers. + */ +@Mixin(value = ItemCompDrawers.class, remap = false) +public class ItemCompDrawersMixin { + + @Inject(method = "placeBlockAt", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/World;getTileEntity(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/tileentity/TileEntity;"), + remap = true, + require = 1) + private void handleCustomNBT(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, + float hitX, float hitY, float hitZ, IBlockState newState, + CallbackInfoReturnable cir) { + var te = world.getTileEntity(pos); + if (!(te instanceof TileEntityDrawers teDrawers)) return; + CustomUpgradeHandler.addCustomUpgradesToTile(teDrawers, stack.getTagCompound()); + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/tooltip/LabsTooltipHelper.java b/src/main/java/com/nomiceu/nomilabs/tooltip/LabsTooltipHelper.java index ef6ec86..ccb405d 100644 --- a/src/main/java/com/nomiceu/nomilabs/tooltip/LabsTooltipHelper.java +++ b/src/main/java/com/nomiceu/nomilabs/tooltip/LabsTooltipHelper.java @@ -29,6 +29,8 @@ public class LabsTooltipHelper { private static final Map> CACHED_TOOLTIPS = new Object2ObjectOpenHashMap<>(); private static final Map CACHED_NBT_WARNINGS = new Object2ObjectOpenHashMap<>(); + public static String DRAWER_UPDGRADE = LabsTranslate.translate("tooltip.nomilabs.drawers.upgrades"); + public static boolean isShiftDown() { return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); } @@ -70,6 +72,7 @@ public static void clearAll() { public static void onLanguageChange() { CACHED_TOOLTIPS.clear(); CACHED_NBT_WARNINGS.clear(); + DRAWER_UPDGRADE = LabsTranslate.translate("tooltip.nomilabs.drawers.upgrades"); } public static boolean shouldClear(ItemStack stack) { diff --git a/src/main/java/com/nomiceu/nomilabs/tooltip/TooltipAdder.java b/src/main/java/com/nomiceu/nomilabs/tooltip/TooltipAdder.java index 5ab4674..6975643 100644 --- a/src/main/java/com/nomiceu/nomilabs/tooltip/TooltipAdder.java +++ b/src/main/java/com/nomiceu/nomilabs/tooltip/TooltipAdder.java @@ -20,9 +20,12 @@ import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper; import com.enderio.core.client.handlers.SpecialTooltipHandler; +import com.jaquadro.minecraft.storagedrawers.item.ItemCompDrawers; +import com.jaquadro.minecraft.storagedrawers.item.ItemDrawers; import com.nomiceu.nomilabs.LabsValues; import com.nomiceu.nomilabs.config.LabsConfig; import com.nomiceu.nomilabs.groovy.NBTClearingRecipe; +import com.nomiceu.nomilabs.integration.storagedrawers.CustomUpgradeHandler; import com.nomiceu.nomilabs.util.ItemMeta; import crazypants.enderio.api.capacitor.CapabilityCapacitorData; @@ -32,6 +35,13 @@ public class TooltipAdder { public static void addTooltipNormal(List tooltip, ItemStack stack) { + // Drawer Upgrade Notice + if (stack.getTagCompound() != null && stack.getTagCompound().hasKey(CustomUpgradeHandler.CUSTOM_UPGRADES)) { + if (stack.getItem() instanceof ItemDrawers || stack.getItem() instanceof ItemCompDrawers) + tooltip.add(LabsTooltipHelper.DRAWER_UPDGRADE); + } + + // Custom Tooltips if (LabsTooltipHelper.shouldClear(stack)) tooltip.clear(); diff --git a/src/main/resources/assets/nomilabs/lang/en_us.lang b/src/main/resources/assets/nomilabs/lang/en_us.lang index a356deb..b4d796f 100644 --- a/src/main/resources/assets/nomilabs/lang/en_us.lang +++ b/src/main/resources/assets/nomilabs/lang/en_us.lang @@ -592,6 +592,8 @@ tooltip.nomilabs.item.can_clear=Place in Crafting Grid to §eClear Contents§r! tooltip.nomilabs.recipe.clearing=§cAll Contents Will be Voided!§r # Items +tooltip.nomilabs.drawers.upgrades=§eUpgrades sealed within§r + tooltip.nomilabs.excitationcoil.description=§7Crafting Component Only... Except:§r tooltip.nomilabs.excitationcoil.placeable=§7Placeable!§r tooltip.nomilabs.excitationcoil.wearable=§7Wearable on your head!§r diff --git a/src/main/resources/mixins.nomilabs.storagedrawers.json b/src/main/resources/mixins.nomilabs.storagedrawers.json index ef395ac..82a95d2 100644 --- a/src/main/resources/mixins.nomilabs.storagedrawers.json +++ b/src/main/resources/mixins.nomilabs.storagedrawers.json @@ -6,6 +6,7 @@ "compatibilityLevel": "JAVA_8", "mixins": [ "DrawerDataMixin", + "ItemCompDrawersMixin", "ItemDrawersMixin" ], "client": [],