diff options
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/inventory/CrafterMenu.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower/net/minecraft/world/inventory/CrafterMenu.java.patch | 204 |
1 files changed, 204 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/inventory/CrafterMenu.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/inventory/CrafterMenu.java.patch new file mode 100644 index 0000000000..db784515c3 --- /dev/null +++ b/patch-remap/mache-vineflower/net/minecraft/world/inventory/CrafterMenu.java.patch @@ -0,0 +1,204 @@ +--- a/net/minecraft/world/inventory/CrafterMenu.java ++++ b/net/minecraft/world/inventory/CrafterMenu.java +@@ -5,11 +5,30 @@ + import net.minecraft.world.entity.player.Inventory; + import net.minecraft.world.entity.player.Player; + import net.minecraft.world.item.ItemStack; +-import net.minecraft.world.item.crafting.CraftingRecipe; + import net.minecraft.world.level.Level; + import net.minecraft.world.level.block.CrafterBlock; + ++// CraftBukkit start ++import org.bukkit.craftbukkit.inventory.CraftInventoryCrafter; ++import org.bukkit.craftbukkit.inventory.CraftInventoryView; ++// CraftBukkit end ++ + public class CrafterMenu extends AbstractContainerMenu implements ContainerListener { ++ ++ // CraftBukkit start ++ private CraftInventoryView bukkitEntity = null; ++ ++ @Override ++ public CraftInventoryView getBukkitView() { ++ if (bukkitEntity != null) { ++ return bukkitEntity; ++ } ++ ++ CraftInventoryCrafter inventory = new CraftInventoryCrafter(this.container, this.resultContainer); ++ bukkitEntity = new CraftInventoryView(this.player.getBukkitEntity(), inventory, this); ++ return bukkitEntity; ++ } ++ // CraftBukkit end + protected static final int SLOT_COUNT = 9; + private static final int INV_SLOT_START = 9; + private static final int INV_SLOT_END = 36; +@@ -18,43 +37,47 @@ + private final ResultContainer resultContainer = new ResultContainer(); + private final ContainerData containerData; + private final Player player; +- private final CraftingContainer container; ++ private final InventoryCrafting container; + +- public CrafterMenu(int containerId, Inventory inventory) { +- super(MenuType.CRAFTER_3x3, containerId); +- this.player = inventory.player; ++ public CrafterMenu(int i, Inventory playerinventory) { ++ super(MenuType.CRAFTER_3x3, i); ++ this.player = playerinventory.player; + this.containerData = new SimpleContainerData(10); + this.container = new TransientCraftingContainer(this, 3, 3); +- this.addSlots(inventory); ++ this.addSlots(playerinventory); + } + +- public CrafterMenu(int containerId, Inventory inventory, CraftingContainer craftingContainer, ContainerData containerData) { +- super(MenuType.CRAFTER_3x3, containerId); +- this.player = inventory.player; +- this.containerData = containerData; +- this.container = craftingContainer; +- checkContainerSize(craftingContainer, 9); +- craftingContainer.startOpen(inventory.player); +- this.addSlots(inventory); ++ public CrafterMenu(int i, Inventory playerinventory, InventoryCrafting inventorycrafting, ContainerData icontainerproperties) { ++ super(MenuType.CRAFTER_3x3, i); ++ this.player = playerinventory.player; ++ this.containerData = icontainerproperties; ++ this.container = inventorycrafting; ++ checkContainerSize(inventorycrafting, 9); ++ inventorycrafting.startOpen(playerinventory.player); ++ this.addSlots(playerinventory); + this.addSlotListener(this); + } + +- private void addSlots(Inventory inventory) { +- for (int i = 0; i < 3; i++) { +- for (int i1 = 0; i1 < 3; i1++) { +- int i2 = i1 + i * 3; +- this.addSlot(new CrafterSlot(this.container, i2, 26 + i1 * 18, 17 + i * 18, this)); ++ private void addSlots(Inventory playerinventory) { ++ int i; ++ int j; ++ ++ for (j = 0; j < 3; ++j) { ++ for (i = 0; i < 3; ++i) { ++ int k = i + j * 3; ++ ++ this.addSlot(new CrafterSlot(this.container, k, 26 + i * 18, 17 + j * 18, this)); + } + } + +- for (int i = 0; i < 3; i++) { +- for (int i1 = 0; i1 < 9; i1++) { +- this.addSlot(new Slot(inventory, i1 + i * 9 + 9, 8 + i1 * 18, 84 + i * 18)); ++ for (j = 0; j < 3; ++j) { ++ for (i = 0; i < 9; ++i) { ++ this.addSlot(new Slot(playerinventory, i + j * 9 + 9, 8 + i * 18, 84 + j * 18)); + } + } + +- for (int i = 0; i < 9; i++) { +- this.addSlot(new Slot(inventory, i, 8 + i * 18, 142)); ++ for (j = 0; j < 9; ++j) { ++ this.addSlot(new Slot(playerinventory, j, 8 + j * 18, 142)); + } + + this.addSlot(new NonInteractiveResultSlot(this.resultContainer, 0, 134, 35)); +@@ -63,13 +86,14 @@ + } + + public void setSlotState(int i, boolean flag) { +- CrafterSlot crafterSlot = (CrafterSlot)this.getSlot(i); +- this.containerData.set(crafterSlot.index, flag ? 0 : 1); ++ CrafterSlot crafterslot = (CrafterSlot) this.getSlot(i); ++ ++ this.containerData.set(crafterslot.index, flag ? 0 : 1); + this.broadcastChanges(); + } + + public boolean isSlotDisabled(int i) { +- return i > -1 && i < 9 && this.containerData.get(i) == 1; ++ return i > -1 && i < 9 ? this.containerData.get(i) == 1 : false; + } + + public boolean isPowered() { +@@ -78,48 +102,56 @@ + + @Override + public ItemStack quickMoveStack(Player player, int index) { +- ItemStack itemStack = ItemStack.EMPTY; +- Slot slot = this.slots.get(index); ++ ItemStack itemstack = ItemStack.EMPTY; ++ Slot slot = (Slot) this.slots.get(index); ++ + if (slot != null && slot.hasItem()) { +- ItemStack item = slot.getItem(); +- itemStack = item.copy(); ++ ItemStack itemstack1 = slot.getItem(); ++ ++ itemstack = itemstack1.copy(); + if (index < 9) { +- if (!this.moveItemStackTo(item, 9, 45, true)) { ++ if (!this.moveItemStackTo(itemstack1, 9, 45, true)) { + return ItemStack.EMPTY; + } +- } else if (!this.moveItemStackTo(item, 0, 9, false)) { ++ } else if (!this.moveItemStackTo(itemstack1, 0, 9, false)) { + return ItemStack.EMPTY; + } + +- if (item.isEmpty()) { ++ if (itemstack1.isEmpty()) { + slot.set(ItemStack.EMPTY); + } else { + slot.setChanged(); + } + +- if (item.getCount() == itemStack.getCount()) { ++ if (itemstack1.getCount() == itemstack.getCount()) { + return ItemStack.EMPTY; + } + +- slot.onTake(player, item); ++ slot.onTake(player, itemstack1); + } + +- return itemStack; ++ return itemstack; + } + + @Override + public boolean stillValid(Player player) { ++ if (!this.checkReachable) return true; // CraftBukkit + return this.container.stillValid(player); + } + + private void refreshRecipeResult() { +- if (this.player instanceof ServerPlayer serverPlayer) { +- Level level = serverPlayer.level(); +- ItemStack itemStack = CrafterBlock.getPotentialResults(level, this.container) +- .map(craftingRecipe -> craftingRecipe.assemble(this.container, level.registryAccess())) +- .orElse(ItemStack.EMPTY); +- this.resultContainer.setItem(0, itemStack); ++ Player entityhuman = this.player; ++ ++ if (entityhuman instanceof ServerPlayer) { ++ ServerPlayer entityplayer = (ServerPlayer) entityhuman; ++ Level world = entityplayer.level(); ++ ItemStack itemstack = (ItemStack) CrafterBlock.getPotentialResults(world, this.container).map((recipecrafting) -> { ++ return recipecrafting.assemble(this.container, world.registryAccess()); ++ }).orElse(ItemStack.EMPTY); ++ ++ this.resultContainer.setItem(0, itemstack); + } ++ + } + + public Container getContainer() { +@@ -132,6 +164,5 @@ + } + + @Override +- public void dataChanged(AbstractContainerMenu containerMenu, int dataSlotIndex, int value) { +- } ++ public void dataChanged(AbstractContainerMenu containerMenu, int dataSlotIndex, int value) {} + } |