Skip to content

Commit

Permalink
Fix Custom Upgrade NBT with Comp Drawers, Tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Oct 5, 2024
1 parent 786b44b commit 284b182
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/nomiceu/nomilabs/groovy/GroovyHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
* Confirmed to Work on:
* <ul>
* <li>Storage Drawers: Wooden Drawers, Compacting Drawers, Framed Drawers</li>
* <li>GregTech Drawers: Rubber Wood Drawers, Treated Wood Drawers</li>
* <li>Framed Compacting Drawers: Framed Compacting Drawers</li>
* </ul>
*/
public static NBTTagCompound transferDrawerUpgradeData(ItemStack orig, @Nullable NBTTagCompound existing) {
var origCompound = orig.getTagCompound();
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
* <p>
* 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<Boolean> cir) {
var te = world.getTileEntity(pos);
if (!(te instanceof TileEntityDrawers teDrawers)) return;
CustomUpgradeHandler.addCustomUpgradesToTile(teDrawers, stack.getTagCompound());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class LabsTooltipHelper {
private static final Map<ItemMeta, List<String>> CACHED_TOOLTIPS = new Object2ObjectOpenHashMap<>();
private static final Map<ItemMeta, String> 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);
}
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/nomiceu/nomilabs/tooltip/TooltipAdder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +35,13 @@
public class TooltipAdder {

public static void addTooltipNormal(List<String> 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();

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/nomilabs/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/mixins.nomilabs.storagedrawers.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"compatibilityLevel": "JAVA_8",
"mixins": [
"DrawerDataMixin",
"ItemCompDrawersMixin",
"ItemDrawersMixin"
],
"client": [],
Expand Down

0 comments on commit 284b182

Please sign in to comment.