diff options
4 files changed, 62 insertions, 6 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/events/ReplaceItemEvent.java b/src/main/java/io/github/moulberry/notenoughupdates/events/ReplaceItemEvent.java index 2cdcf083..335d8fe0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/events/ReplaceItemEvent.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/events/ReplaceItemEvent.java @@ -19,17 +19,17 @@ package io.github.moulberry.notenoughupdates.events; -import net.minecraft.inventory.InventoryBasic; +import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; public class ReplaceItemEvent extends NEUEvent { final ItemStack original; - final InventoryBasic inventory; + final IInventory inventory; final int slotNumber; ItemStack replaceWith; - public ReplaceItemEvent(ItemStack original, InventoryBasic inventory, int slotNumber) { + public ReplaceItemEvent(ItemStack original, IInventory inventory, int slotNumber) { this.original = original; this.inventory = inventory; this.slotNumber = slotNumber; @@ -40,7 +40,7 @@ public class ReplaceItemEvent extends NEUEvent { return original; } - public InventoryBasic getInventory() { + public IInventory getInventory() { return inventory; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java index 8a487739..7e65e032 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java @@ -24,8 +24,10 @@ import com.google.gson.GsonBuilder; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.config.KeybindHelper; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; +import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent; import io.github.moulberry.notenoughupdates.events.SlotClickEvent; import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; +import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.SBInfo; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.ISound; @@ -39,7 +41,10 @@ import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.init.Blocks; import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.GuiScreenEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; @@ -416,6 +421,9 @@ public class SlotLocking { } drawLinkArrow(x1, y1, x2, y2); + setTopHalfBarrier = true; + } else { + setTopHalfBarrier = false; } } @@ -729,4 +737,27 @@ public class SlotLocking { return locked != null && (locked.locked || (NotEnoughUpdates.INSTANCE.config.slotLocking.bindingAlsoLocks && locked.boundTo != -1)); } + + boolean setTopHalfBarrier = false; + @SubscribeEvent + public void barrierInventory(ReplaceItemEvent event) { + if (event.getSlotNumber() < 9 || + (pairingSlot != null && (event.getSlotNumber() == pairingSlot.slotNumber || isArmourSlot(event.getSlotNumber(), pairingSlot.slotNumber))) || + !setTopHalfBarrier || + !(event.getInventory() instanceof InventoryPlayer)) return; + ItemStack stack = new ItemStack(Blocks.barrier); + ItemUtils.getOrCreateTag(stack).setBoolean( + "NEUHIDETOOLIP", + true + ); + event.replaceWith(stack); + } + + boolean isArmourSlot(int eventSlotNumber, int pairingSlotNumber) { + if (eventSlotNumber == 39 && pairingSlotNumber == 5) return true; + if (eventSlotNumber == 38 && pairingSlotNumber == 6) return true; + if (eventSlotNumber == 37 && pairingSlotNumber == 7) return true; + if (eventSlotNumber == 36 && pairingSlotNumber == 8) return true; + return false; + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java index 91d92091..a5bb99b8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java @@ -294,8 +294,9 @@ public abstract class MixinGuiContainer extends GuiScreen { @Redirect(method = "drawScreen", at = @At(value = "INVOKE", target = TARGET_CANBEHOVERED)) public boolean drawScreen_canBeHovered(Slot slot) { - if (NotEnoughUpdates.INSTANCE.config.improvedSBMenu.hideEmptyPanes && - BetterContainers.isOverriding() && BetterContainers.isBlankStack(slot.slotNumber, slot.getStack())) { + if ((NotEnoughUpdates.INSTANCE.config.improvedSBMenu.hideEmptyPanes && + BetterContainers.isOverriding() && BetterContainers.isBlankStack(slot.slotNumber, slot.getStack())) || + slot.getStack() != null && slot.getStack().hasTagCompound() && slot.getStack().getTagCompound().getBoolean("NEUHIDETOOLIP")) { return false; } return slot.canBeHovered(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryPlayer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryPlayer.java index de117002..22e53ae1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryPlayer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryPlayer.java @@ -19,13 +19,17 @@ package io.github.moulberry.notenoughupdates.mixins; +import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent; import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking; import io.github.moulberry.notenoughupdates.miscgui.InventoryStorageSelector; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(InventoryPlayer.class) public class MixinInventoryPlayer { @@ -42,4 +46,24 @@ public class MixinInventoryPlayer { SlotLocking.getInstance().changedSlot($this.currentItem); } + + @Shadow public ItemStack[] mainInventory; + @Shadow public ItemStack[] armorInventory; + + @Inject(method = "getStackInSlot", at = @At("HEAD"), cancellable = true) + public void on(int index, CallbackInfoReturnable<ItemStack> cir) { + ItemStack itemStack = + index < mainInventory.length + ? this.mainInventory[index] + : this.armorInventory[index - mainInventory.length]; + ReplaceItemEvent replaceItemEventInventory = new ReplaceItemEvent( + itemStack, + ((InventoryPlayer) (Object) this), + index + ); + replaceItemEventInventory.post(); + if (replaceItemEventInventory.getReplacement() != replaceItemEventInventory.getOriginal()) { + cir.setReturnValue(replaceItemEventInventory.getReplacement()); + } + } } |