From 5781a9c01f82e0d23a9e1766a74bb4eae24138d7 Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Wed, 7 May 2014 20:29:11 +0300 Subject: [PATCH 1/2] In library set player even when shift clicked Was quite an annoying small bug. Was trying to put some blueprints in blueprint library, but they well wouldn't simply appear in the list. Came out the uploading and downloading player is only set when the slot is clicked. --- .../gui/ContainerBlueprintLibrary.java | 5 ++- .../core/gui/slots/SlotBlueprintLibrary.java | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 common/buildcraft/core/gui/slots/SlotBlueprintLibrary.java diff --git a/common/buildcraft/builders/gui/ContainerBlueprintLibrary.java b/common/buildcraft/builders/gui/ContainerBlueprintLibrary.java index 95876762..5c7fda76 100644 --- a/common/buildcraft/builders/gui/ContainerBlueprintLibrary.java +++ b/common/buildcraft/builders/gui/ContainerBlueprintLibrary.java @@ -16,6 +16,7 @@ import net.minecraft.item.ItemStack; import buildcraft.builders.TileBlueprintLibrary; import buildcraft.core.gui.BuildCraftContainer; +import buildcraft.core.gui.slots.SlotBlueprintLibrary; import buildcraft.core.gui.slots.SlotOutput; public class ContainerBlueprintLibrary extends BuildCraftContainer { @@ -30,10 +31,10 @@ public class ContainerBlueprintLibrary extends BuildCraftContainer { this.playerInventory = player.inventory; this.library = library; - addSlotToContainer(new Slot(library, 0, 211, 61)); + addSlotToContainer(new SlotBlueprintLibrary(library, player, 0, 211, 61)); addSlotToContainer(new SlotOutput(library, 1, 167, 61)); - addSlotToContainer(new Slot(library, 2, 167, 79)); + addSlotToContainer(new SlotBlueprintLibrary(library, player, 2, 167, 79)); addSlotToContainer(new SlotOutput(library, 3, 211, 79)); // Player inventory diff --git a/common/buildcraft/core/gui/slots/SlotBlueprintLibrary.java b/common/buildcraft/core/gui/slots/SlotBlueprintLibrary.java new file mode 100644 index 00000000..1199f1bc --- /dev/null +++ b/common/buildcraft/core/gui/slots/SlotBlueprintLibrary.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.core.gui.slots; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; + +import buildcraft.builders.TileBlueprintLibrary; + +public class SlotBlueprintLibrary extends SlotBase { + private TileBlueprintLibrary library; + private EntityPlayer player; + private int slot; + + public SlotBlueprintLibrary(IInventory iinventory, EntityPlayer player, int slotIndex, int posX, int posY) { + super(iinventory, slotIndex, posX, posY); + this.library = (TileBlueprintLibrary) iinventory; + this.slot = slotIndex; + this.player = player; + } + + public void onSlotChanged() { + if (slot == 0) { + library.uploadingPlayer = player; + } else if (slot == 2) { + library.downloadingPlayer = player; + } + + this.inventory.markDirty(); + } +} \ No newline at end of file From f63a16bd95e80259fbda5d8ceb793d339daa3a0a Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Wed, 7 May 2014 19:58:21 +0200 Subject: [PATCH 2/2] removed useless override to slotClick --- .../gui/ContainerBlueprintLibrary.java | 18 ------------------ .../core/gui/slots/SlotBlueprintLibrary.java | 7 +++++++ 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/common/buildcraft/builders/gui/ContainerBlueprintLibrary.java b/common/buildcraft/builders/gui/ContainerBlueprintLibrary.java index 5c7fda76..d058617e 100644 --- a/common/buildcraft/builders/gui/ContainerBlueprintLibrary.java +++ b/common/buildcraft/builders/gui/ContainerBlueprintLibrary.java @@ -12,7 +12,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; import buildcraft.builders.TileBlueprintLibrary; import buildcraft.core.gui.BuildCraftContainer; @@ -49,23 +48,6 @@ public class ContainerBlueprintLibrary extends BuildCraftContainer { } } - @Override - public ItemStack slotClick(int slotNum, int mouseButton, int modifier, EntityPlayer player) { - // When downloading or uploading a blueprint, the server needs to know - // who requested it. The way to do it so far is by recording the last - // player that clicks on the slots. To be improved if the method is - // not robust enough (e.g. what if the player is not logged anymore? - // is that robust against race conditions? etc.) - - if (slotNum == 0) { - library.uploadingPlayer = player; - } else if (slotNum == 2) { - library.downloadingPlayer = player; - } - - return super.slotClick(slotNum, mouseButton, modifier, player); - } - @Override public void detectAndSendChanges() { super.detectAndSendChanges(); diff --git a/common/buildcraft/core/gui/slots/SlotBlueprintLibrary.java b/common/buildcraft/core/gui/slots/SlotBlueprintLibrary.java index 1199f1bc..3ccfc902 100644 --- a/common/buildcraft/core/gui/slots/SlotBlueprintLibrary.java +++ b/common/buildcraft/core/gui/slots/SlotBlueprintLibrary.java @@ -25,7 +25,14 @@ public class SlotBlueprintLibrary extends SlotBase { this.player = player; } + @Override public void onSlotChanged() { + // When downloading or uploading a blueprint, the server needs to know + // who requested it. The way to do it so far is by recording the last + // player that clicks on the slots. To be improved if the method is + // not robust enough (e.g. what if the player is not logged anymore? + // is that robust against race conditions? etc.) + if (slot == 0) { library.uploadingPlayer = player; } else if (slot == 2) {