diff options
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/inventory/CraftingMenu.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower/net/minecraft/world/inventory/CraftingMenu.java.patch | 251 |
1 files changed, 251 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/inventory/CraftingMenu.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/inventory/CraftingMenu.java.patch new file mode 100644 index 0000000000..c6d4c94f1e --- /dev/null +++ b/patch-remap/mache-vineflower/net/minecraft/world/inventory/CraftingMenu.java.patch @@ -0,0 +1,251 @@ +--- a/net/minecraft/world/inventory/CraftingMenu.java ++++ b/net/minecraft/world/inventory/CraftingMenu.java +@@ -1,7 +1,6 @@ + package net.minecraft.world.inventory; + + import java.util.Optional; +-import net.minecraft.core.BlockPos; + import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; + import net.minecraft.server.level.ServerPlayer; + import net.minecraft.world.Container; +@@ -9,14 +8,19 @@ + import net.minecraft.world.entity.player.Player; + import net.minecraft.world.entity.player.StackedContents; + import net.minecraft.world.item.ItemStack; +-import net.minecraft.world.item.crafting.CraftingRecipe; + import net.minecraft.world.item.crafting.Recipe; ++import net.minecraft.world.item.crafting.RecipeCrafting; + import net.minecraft.world.item.crafting.RecipeHolder; + import net.minecraft.world.item.crafting.RecipeType; ++import net.minecraft.world.item.crafting.RepairItemRecipe; + import net.minecraft.world.level.Level; + import net.minecraft.world.level.block.Blocks; ++import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting; ++import org.bukkit.craftbukkit.inventory.CraftInventoryView; ++// CraftBukkit end + +-public class CraftingMenu extends RecipeBookMenu<CraftingContainer> { ++public class CraftingMenu extends RecipeBookMenu<InventoryCrafting> { ++ + public static final int RESULT_SLOT = 0; + private static final int CRAFT_SLOT_START = 1; + private static final int CRAFT_SLOT_END = 10; +@@ -24,10 +28,13 @@ + private static final int INV_SLOT_END = 37; + private static final int USE_ROW_SLOT_START = 37; + private static final int USE_ROW_SLOT_END = 46; +- private final CraftingContainer craftSlots = new TransientCraftingContainer(this, 3, 3); +- private final ResultContainer resultSlots = new ResultContainer(); +- private final ContainerLevelAccess access; ++ public final TransientCraftingContainer craftSlots; // CraftBukkit ++ public final ResultContainer resultSlots; ++ public final ContainerLevelAccess access; + private final Player player; ++ // CraftBukkit start ++ private CraftInventoryView bukkitEntity = null; ++ // CraftBukkit end + + public CraftingMenu(int containerId, Inventory playerInventory) { + this(containerId, playerInventory, ContainerLevelAccess.NULL); +@@ -35,52 +42,67 @@ + + public CraftingMenu(int containerId, Inventory playerInventory, ContainerLevelAccess access) { + super(MenuType.CRAFTING, containerId); ++ // CraftBukkit start - Switched order of IInventory construction and stored player ++ this.resultSlots = new ResultContainer(); ++ this.craftSlots = new TransientCraftingContainer(this, 3, 3, playerInventory.player); // CraftBukkit - pass player ++ this.craftSlots.resultInventory = this.resultSlots; ++ // CraftBukkit end + this.access = access; + this.player = playerInventory.player; + this.addSlot(new ResultSlot(playerInventory.player, this.craftSlots, this.resultSlots, 0, 124, 35)); + +- for (int i = 0; i < 3; i++) { +- for (int i1 = 0; i1 < 3; i1++) { +- this.addSlot(new Slot(this.craftSlots, i1 + i * 3, 30 + i1 * 18, 17 + i * 18)); ++ int j; ++ int k; ++ ++ for (j = 0; j < 3; ++j) { ++ for (k = 0; k < 3; ++k) { ++ this.addSlot(new Slot(this.craftSlots, k + j * 3, 30 + k * 18, 17 + j * 18)); + } + } + +- for (int i = 0; i < 3; i++) { +- for (int i1 = 0; i1 < 9; i1++) { +- this.addSlot(new Slot(playerInventory, i1 + i * 9 + 9, 8 + i1 * 18, 84 + i * 18)); ++ for (j = 0; j < 3; ++j) { ++ for (k = 0; k < 9; ++k) { ++ this.addSlot(new Slot(playerInventory, k + j * 9 + 9, 8 + k * 18, 84 + j * 18)); + } + } + +- for (int i = 0; i < 9; i++) { +- this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 142)); ++ for (j = 0; j < 9; ++j) { ++ this.addSlot(new Slot(playerInventory, j, 8 + j * 18, 142)); + } ++ + } + +- protected static void slotChangedCraftingGrid(AbstractContainerMenu menu, Level level, Player player, CraftingContainer container, ResultContainer result) { ++ protected static void slotChangedCraftingGrid(AbstractContainerMenu menu, Level level, Player player, InventoryCrafting container, ResultContainer result) { + if (!level.isClientSide) { +- ServerPlayer serverPlayer = (ServerPlayer)player; +- ItemStack itemStack = ItemStack.EMPTY; +- Optional<RecipeHolder<CraftingRecipe>> recipeFor = level.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, container, level); +- if (recipeFor.isPresent()) { +- RecipeHolder<CraftingRecipe> recipeHolder = recipeFor.get(); +- CraftingRecipe craftingRecipe = recipeHolder.value(); +- if (result.setRecipeUsed(level, serverPlayer, recipeHolder)) { +- ItemStack itemStack1 = craftingRecipe.assemble(container, level.registryAccess()); +- if (itemStack1.isItemEnabled(level.enabledFeatures())) { +- itemStack = itemStack1; ++ ServerPlayer entityplayer = (ServerPlayer) player; ++ ItemStack itemstack = ItemStack.EMPTY; ++ Optional<RecipeHolder<RecipeCrafting>> optional = level.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, container, level); ++ ++ if (optional.isPresent()) { ++ RecipeHolder<RecipeCrafting> recipeholder = (RecipeHolder) optional.get(); ++ RecipeCrafting recipecrafting = (RecipeCrafting) recipeholder.value(); ++ ++ if (result.setRecipeUsed(level, entityplayer, recipeholder)) { ++ ItemStack itemstack1 = recipecrafting.assemble(container, level.registryAccess()); ++ ++ if (itemstack1.isItemEnabled(level.enabledFeatures())) { ++ itemstack = itemstack1; + } + } + } ++ itemstack = org.bukkit.craftbukkit.event.CraftEventFactory.callPreCraftEvent(container, result, itemstack, menu.getBukkitView(), optional.map(RecipeHolder::toBukkitRecipe).orElse(null) instanceof RepairItemRecipe); // CraftBukkit + +- result.setItem(0, itemStack); +- menu.setRemoteSlot(0, itemStack); +- serverPlayer.connection.send(new ClientboundContainerSetSlotPacket(menu.containerId, menu.incrementStateId(), 0, itemStack)); ++ result.setItem(0, itemstack); ++ menu.setRemoteSlot(0, itemstack); ++ entityplayer.connection.send(new ClientboundContainerSetSlotPacket(menu.containerId, menu.incrementStateId(), 0, itemstack)); + } + } + + @Override + public void slotsChanged(Container inventory) { +- this.access.execute((level, blockPos) -> slotChangedCraftingGrid(this, level, this.player, this.craftSlots, this.resultSlots)); ++ this.access.execute((world, blockposition) -> { ++ slotChangedCraftingGrid(this, world, this.player, this.craftSlots, this.resultSlots); ++ }); + } + + @Override +@@ -95,66 +117,73 @@ + } + + @Override +- public boolean recipeMatches(RecipeHolder<? extends Recipe<CraftingContainer>> recipeHolder) { +- return recipeHolder.value().matches(this.craftSlots, this.player.level()); ++ public boolean recipeMatches(RecipeHolder<? extends Recipe<InventoryCrafting>> recipeholder) { ++ return recipeholder.value().matches(this.craftSlots, this.player.level()); + } + + @Override + public void removed(Player player) { + super.removed(player); +- this.access.execute((level, blockPos) -> this.clearContainer(player, this.craftSlots)); ++ this.access.execute((world, blockposition) -> { ++ this.clearContainer(player, this.craftSlots); ++ }); + } + + @Override + public boolean stillValid(Player player) { ++ if (!this.checkReachable) return true; // CraftBukkit + return stillValid(this.access, player, Blocks.CRAFTING_TABLE); + } + + @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 == 0) { +- this.access.execute((level, blockPos) -> item.getItem().onCraftedBy(item, level, player)); +- if (!this.moveItemStackTo(item, 10, 46, true)) { ++ this.access.execute((world, blockposition) -> { ++ itemstack1.getItem().onCraftedBy(itemstack1, world, player); ++ }); ++ if (!this.moveItemStackTo(itemstack1, 10, 46, true)) { + return ItemStack.EMPTY; + } + +- slot.onQuickCraft(item, itemStack); ++ slot.onQuickCraft(itemstack1, itemstack); + } else if (index >= 10 && index < 46) { +- if (!this.moveItemStackTo(item, 1, 10, false)) { ++ if (!this.moveItemStackTo(itemstack1, 1, 10, false)) { + if (index < 37) { +- if (!this.moveItemStackTo(item, 37, 46, false)) { ++ if (!this.moveItemStackTo(itemstack1, 37, 46, false)) { + return ItemStack.EMPTY; + } +- } else if (!this.moveItemStackTo(item, 10, 37, false)) { ++ } else if (!this.moveItemStackTo(itemstack1, 10, 37, false)) { + return ItemStack.EMPTY; + } + } +- } else if (!this.moveItemStackTo(item, 10, 46, false)) { ++ } else if (!this.moveItemStackTo(itemstack1, 10, 46, false)) { + return ItemStack.EMPTY; + } + +- if (item.isEmpty()) { ++ if (itemstack1.isEmpty()) { + slot.setByPlayer(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); + if (index == 0) { +- player.drop(item, false); ++ player.drop(itemstack1, false); + } + } + +- return itemStack; ++ return itemstack; + } + + @Override +@@ -191,4 +220,17 @@ + public boolean shouldMoveToInventory(int slotIndex) { + return slotIndex != this.getResultSlotIndex(); + } ++ ++ // CraftBukkit start ++ @Override ++ public CraftInventoryView getBukkitView() { ++ if (bukkitEntity != null) { ++ return bukkitEntity; ++ } ++ ++ CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftSlots, this.resultSlots); ++ bukkitEntity = new CraftInventoryView(this.player.getBukkitEntity(), inventory, this); ++ return bukkitEntity; ++ } ++ // CraftBukkit end + } |