diff options
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/inventory/LoomMenu.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower/net/minecraft/world/inventory/LoomMenu.java.patch | 431 |
1 files changed, 431 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/inventory/LoomMenu.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/inventory/LoomMenu.java.patch new file mode 100644 index 0000000000..d5efb07af3 --- /dev/null +++ b/patch-remap/mache-vineflower/net/minecraft/world/inventory/LoomMenu.java.patch @@ -0,0 +1,431 @@ +--- a/net/minecraft/world/inventory/LoomMenu.java ++++ b/net/minecraft/world/inventory/LoomMenu.java +@@ -2,7 +2,6 @@ + + import com.google.common.collect.ImmutableList; + import java.util.List; +-import net.minecraft.core.BlockPos; + import net.minecraft.core.Holder; + import net.minecraft.core.registries.BuiltInRegistries; + import net.minecraft.nbt.CompoundTag; +@@ -13,49 +12,56 @@ + import net.minecraft.world.Container; + import net.minecraft.world.SimpleContainer; + import net.minecraft.world.entity.player.Inventory; +-import net.minecraft.world.entity.player.Player; + import net.minecraft.world.item.BannerItem; + import net.minecraft.world.item.BannerPatternItem; + import net.minecraft.world.item.BlockItem; + import net.minecraft.world.item.DyeColor; + import net.minecraft.world.item.DyeItem; ++import net.minecraft.world.item.Item; + import net.minecraft.world.item.ItemStack; +-import net.minecraft.world.level.Level; + import net.minecraft.world.level.block.Blocks; + import net.minecraft.world.level.block.entity.BannerPattern; + import net.minecraft.world.level.block.entity.BlockEntityType; ++// CraftBukkit start ++import org.bukkit.Location; ++import org.bukkit.craftbukkit.inventory.CraftInventoryLoom; ++import org.bukkit.craftbukkit.inventory.CraftInventoryView; ++import org.bukkit.entity.Player; ++// CraftBukkit end + + public class LoomMenu extends AbstractContainerMenu { ++ ++ // CraftBukkit start ++ private CraftInventoryView bukkitEntity = null; ++ private Player player; ++ ++ @Override ++ public CraftInventoryView getBukkitView() { ++ if (bukkitEntity != null) { ++ return bukkitEntity; ++ } ++ ++ CraftInventoryLoom inventory = new CraftInventoryLoom(this.inputContainer, this.outputContainer); ++ bukkitEntity = new CraftInventoryView(this.player, inventory, this); ++ return bukkitEntity; ++ } ++ // CraftBukkit end + private static final int PATTERN_NOT_SET = -1; + private static final int INV_SLOT_START = 4; + private static final int INV_SLOT_END = 31; + private static final int USE_ROW_SLOT_START = 31; + private static final int USE_ROW_SLOT_END = 40; + private final ContainerLevelAccess access; +- final DataSlot selectedBannerPatternIndex = DataSlot.standalone(); +- private List<Holder<BannerPattern>> selectablePatterns = List.of(); +- Runnable slotUpdateListener = () -> { +- }; ++ final DataSlot selectedBannerPatternIndex; ++ private List<Holder<BannerPattern>> selectablePatterns; ++ Runnable slotUpdateListener; + final Slot bannerSlot; + final Slot dyeSlot; + private final Slot patternSlot; + private final Slot resultSlot; + long lastSoundTime; +- private final Container inputContainer = new SimpleContainer(3) { +- @Override +- public void setChanged() { +- super.setChanged(); +- LoomMenu.this.slotsChanged(this); +- LoomMenu.this.slotUpdateListener.run(); +- } +- }; +- private final Container outputContainer = new SimpleContainer(1) { +- @Override +- public void setChanged() { +- super.setChanged(); +- LoomMenu.this.slotUpdateListener.run(); +- } +- }; ++ private final Container inputContainer; ++ private final Container outputContainer; + + public LoomMenu(int containerId, Inventory playerInventory) { + this(containerId, playerInventory, ContainerLevelAccess.NULL); +@@ -63,6 +69,39 @@ + + public LoomMenu(int containerId, Inventory playerInventory, final ContainerLevelAccess access) { + super(MenuType.LOOM, containerId); ++ this.selectedBannerPatternIndex = DataSlot.standalone(); ++ this.selectablePatterns = List.of(); ++ this.slotUpdateListener = () -> { ++ }; ++ this.inputContainer = new SimpleContainer(3) { ++ @Override ++ public void setChanged() { ++ super.setChanged(); ++ LoomMenu.this.slotsChanged(this); ++ LoomMenu.this.slotUpdateListener.run(); ++ } ++ ++ // CraftBukkit start ++ @Override ++ public Location getLocation() { ++ return access.getLocation(); ++ } ++ // CraftBukkit end ++ }; ++ this.outputContainer = new SimpleContainer(1) { ++ @Override ++ public void setChanged() { ++ super.setChanged(); ++ LoomMenu.this.slotUpdateListener.run(); ++ } ++ ++ // CraftBukkit start ++ @Override ++ public Location getLocation() { ++ return access.getLocation(); ++ } ++ // CraftBukkit end ++ }; + this.access = access; + this.bannerSlot = this.addSlot(new Slot(this.inputContainer, 0, 13, 26) { + @Override +@@ -89,47 +128,53 @@ + } + + @Override +- public void onTake(Player player, ItemStack stack) { ++ public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) { + LoomMenu.this.bannerSlot.remove(1); + LoomMenu.this.dyeSlot.remove(1); + if (!LoomMenu.this.bannerSlot.hasItem() || !LoomMenu.this.dyeSlot.hasItem()) { + LoomMenu.this.selectedBannerPatternIndex.set(-1); + } + +- access.execute((level, blockPos) -> { +- long gameTime = level.getGameTime(); +- if (LoomMenu.this.lastSoundTime != gameTime) { +- level.playSound(null, blockPos, SoundEvents.UI_LOOM_TAKE_RESULT, SoundSource.BLOCKS, 1.0F, 1.0F); +- LoomMenu.this.lastSoundTime = gameTime; ++ access.execute((world, blockposition) -> { ++ long j = world.getGameTime(); ++ ++ if (LoomMenu.this.lastSoundTime != j) { ++ world.playSound((net.minecraft.world.entity.player.Player) null, blockposition, SoundEvents.UI_LOOM_TAKE_RESULT, SoundSource.BLOCKS, 1.0F, 1.0F); ++ LoomMenu.this.lastSoundTime = j; + } ++ + }); + super.onTake(player, stack); + } + }); + +- 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)); ++ int j; ++ ++ for (j = 0; j < 3; ++j) { ++ for (int 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)); + } + + this.addDataSlot(this.selectedBannerPatternIndex); ++ player = (Player) playerInventory.player.getBukkitEntity(); // CraftBukkit + } + + @Override +- public boolean stillValid(Player player) { ++ public boolean stillValid(net.minecraft.world.entity.player.Player player) { ++ if (!this.checkReachable) return true; // CraftBukkit + return stillValid(this.access, player, Blocks.LOOM); + } + + @Override +- public boolean clickMenuButton(Player player, int id) { ++ public boolean clickMenuButton(net.minecraft.world.entity.player.Player player, int id) { + if (id >= 0 && id < this.selectablePatterns.size()) { + this.selectedBannerPatternIndex.set(id); +- this.setupResultSlot(this.selectablePatterns.get(id)); ++ this.setupResultSlot((Holder) this.selectablePatterns.get(id)); + return true; + } else { + return false; +@@ -138,11 +183,17 @@ + + private List<Holder<BannerPattern>> getSelectablePatterns(ItemStack stack) { + if (stack.isEmpty()) { +- return BuiltInRegistries.BANNER_PATTERN.getTag(BannerPatternTags.NO_ITEM_REQUIRED).map(ImmutableList::copyOf).orElse(ImmutableList.of()); ++ return (List) BuiltInRegistries.BANNER_PATTERN.getTag(BannerPatternTags.NO_ITEM_REQUIRED).map(ImmutableList::copyOf).orElse(ImmutableList.of()); + } else { +- return (List<Holder<BannerPattern>>)(stack.getItem() instanceof BannerPatternItem bannerPatternItem +- ? BuiltInRegistries.BANNER_PATTERN.getTag(bannerPatternItem.getBannerPattern()).map(ImmutableList::copyOf).orElse(ImmutableList.of()) +- : List.of()); ++ Item item = stack.getItem(); ++ ++ if (item instanceof BannerPatternItem) { ++ BannerPatternItem itembannerpattern = (BannerPatternItem) item; ++ ++ return (List) BuiltInRegistries.BANNER_PATTERN.getTag(itembannerpattern.getBannerPattern()).map(ImmutableList::copyOf).orElse(ImmutableList.of()); ++ } else { ++ return List.of(); ++ } + } + } + +@@ -152,27 +203,31 @@ + + @Override + public void slotsChanged(Container inventory) { +- ItemStack item = this.bannerSlot.getItem(); +- ItemStack item1 = this.dyeSlot.getItem(); +- ItemStack item2 = this.patternSlot.getItem(); +- if (!item.isEmpty() && !item1.isEmpty()) { ++ ItemStack itemstack = this.bannerSlot.getItem(); ++ ItemStack itemstack1 = this.dyeSlot.getItem(); ++ ItemStack itemstack2 = this.patternSlot.getItem(); ++ ++ if (!itemstack.isEmpty() && !itemstack1.isEmpty()) { + int i = this.selectedBannerPatternIndex.get(); +- boolean isValidPatternIndex = this.isValidPatternIndex(i); ++ boolean flag = this.isValidPatternIndex(i); + List<Holder<BannerPattern>> list = this.selectablePatterns; +- this.selectablePatterns = this.getSelectablePatterns(item2); +- Holder<BannerPattern> holder; ++ ++ this.selectablePatterns = this.getSelectablePatterns(itemstack2); ++ Holder holder; ++ + if (this.selectablePatterns.size() == 1) { + this.selectedBannerPatternIndex.set(0); +- holder = this.selectablePatterns.get(0); +- } else if (!isValidPatternIndex) { ++ holder = (Holder) this.selectablePatterns.get(0); ++ } else if (!flag) { + this.selectedBannerPatternIndex.set(-1); + holder = null; + } else { +- Holder<BannerPattern> holder1 = list.get(i); +- int index = this.selectablePatterns.indexOf(holder1); +- if (index != -1) { ++ Holder<BannerPattern> holder1 = (Holder) list.get(i); ++ int j = this.selectablePatterns.indexOf(holder1); ++ ++ if (j != -1) { + holder = holder1; +- this.selectedBannerPatternIndex.set(index); ++ this.selectedBannerPatternIndex.set(j); + } else { + holder = null; + this.selectedBannerPatternIndex.set(-1); +@@ -180,12 +235,10 @@ + } + + if (holder != null) { +- CompoundTag blockEntityData = BlockItem.getBlockEntityData(item); +- boolean flag = blockEntityData != null +- && blockEntityData.contains("Patterns", 9) +- && !item.isEmpty() +- && blockEntityData.getList("Patterns", 10).size() >= 6; +- if (flag) { ++ CompoundTag nbttagcompound = BlockItem.getBlockEntityData(itemstack); ++ boolean flag1 = nbttagcompound != null && nbttagcompound.contains("Patterns", 9) && !itemstack.isEmpty() && nbttagcompound.getList("Patterns", 10).size() >= 6; ++ ++ if (flag1) { + this.selectedBannerPatternIndex.set(-1); + this.resultSlot.set(ItemStack.EMPTY); + } else { +@@ -216,94 +269,107 @@ + } + + @Override +- public ItemStack quickMoveStack(Player player, int index) { +- ItemStack itemStack = ItemStack.EMPTY; +- Slot slot = this.slots.get(index); ++ public ItemStack quickMoveStack(net.minecraft.world.entity.player.Player player, int 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 == this.resultSlot.index) { +- if (!this.moveItemStackTo(item, 4, 40, true)) { ++ if (!this.moveItemStackTo(itemstack1, 4, 40, true)) { + return ItemStack.EMPTY; + } + +- slot.onQuickCraft(item, itemStack); ++ slot.onQuickCraft(itemstack1, itemstack); + } else if (index != this.dyeSlot.index && index != this.bannerSlot.index && index != this.patternSlot.index) { +- if (item.getItem() instanceof BannerItem) { +- if (!this.moveItemStackTo(item, this.bannerSlot.index, this.bannerSlot.index + 1, false)) { ++ if (itemstack1.getItem() instanceof BannerItem) { ++ if (!this.moveItemStackTo(itemstack1, this.bannerSlot.index, this.bannerSlot.index + 1, false)) { + return ItemStack.EMPTY; + } +- } else if (item.getItem() instanceof DyeItem) { +- if (!this.moveItemStackTo(item, this.dyeSlot.index, this.dyeSlot.index + 1, false)) { ++ } else if (itemstack1.getItem() instanceof DyeItem) { ++ if (!this.moveItemStackTo(itemstack1, this.dyeSlot.index, this.dyeSlot.index + 1, false)) { + return ItemStack.EMPTY; + } +- } else if (item.getItem() instanceof BannerPatternItem) { +- if (!this.moveItemStackTo(item, this.patternSlot.index, this.patternSlot.index + 1, false)) { ++ } else if (itemstack1.getItem() instanceof BannerPatternItem) { ++ if (!this.moveItemStackTo(itemstack1, this.patternSlot.index, this.patternSlot.index + 1, false)) { + return ItemStack.EMPTY; + } + } else if (index >= 4 && index < 31) { +- if (!this.moveItemStackTo(item, 31, 40, false)) { ++ if (!this.moveItemStackTo(itemstack1, 31, 40, false)) { + return ItemStack.EMPTY; + } +- } else if (index >= 31 && index < 40 && !this.moveItemStackTo(item, 4, 31, false)) { ++ } else if (index >= 31 && index < 40 && !this.moveItemStackTo(itemstack1, 4, 31, false)) { + return ItemStack.EMPTY; + } +- } else if (!this.moveItemStackTo(item, 4, 40, false)) { ++ } else if (!this.moveItemStackTo(itemstack1, 4, 40, 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); + } + +- return itemStack; ++ return itemstack; + } + + @Override +- public void removed(Player player) { ++ public void removed(net.minecraft.world.entity.player.Player player) { + super.removed(player); +- this.access.execute((level, blockPos) -> this.clearContainer(player, this.inputContainer)); ++ this.access.execute((world, blockposition) -> { ++ this.clearContainer(player, this.inputContainer); ++ }); + } + + private void setupResultSlot(Holder<BannerPattern> pattern) { +- ItemStack item = this.bannerSlot.getItem(); +- ItemStack item1 = this.dyeSlot.getItem(); +- ItemStack itemStack = ItemStack.EMPTY; +- if (!item.isEmpty() && !item1.isEmpty()) { +- itemStack = item.copyWithCount(1); +- DyeColor dyeColor = ((DyeItem)item1.getItem()).getDyeColor(); +- CompoundTag blockEntityData = BlockItem.getBlockEntityData(itemStack); +- ListTag list; +- if (blockEntityData != null && blockEntityData.contains("Patterns", 9)) { +- list = blockEntityData.getList("Patterns", 10); ++ ItemStack itemstack = this.bannerSlot.getItem(); ++ ItemStack itemstack1 = this.dyeSlot.getItem(); ++ ItemStack itemstack2 = ItemStack.EMPTY; ++ ++ if (!itemstack.isEmpty() && !itemstack1.isEmpty()) { ++ itemstack2 = itemstack.copyWithCount(1); ++ DyeColor enumcolor = ((DyeItem) itemstack1.getItem()).getDyeColor(); ++ CompoundTag nbttagcompound = BlockItem.getBlockEntityData(itemstack2); ++ ListTag nbttaglist; ++ ++ if (nbttagcompound != null && nbttagcompound.contains("Patterns", 9)) { ++ nbttaglist = nbttagcompound.getList("Patterns", 10); ++ // CraftBukkit start ++ while (nbttaglist.size() > 20) { ++ nbttaglist.remove(20); ++ } ++ // CraftBukkit end + } else { +- list = new ListTag(); +- if (blockEntityData == null) { +- blockEntityData = new CompoundTag(); ++ nbttaglist = new ListTag(); ++ if (nbttagcompound == null) { ++ nbttagcompound = new CompoundTag(); + } + +- blockEntityData.put("Patterns", list); ++ nbttagcompound.put("Patterns", nbttaglist); + } + +- CompoundTag compoundTag = new CompoundTag(); +- compoundTag.putString("Pattern", pattern.value().getHashname()); +- compoundTag.putInt("Color", dyeColor.getId()); +- list.add(compoundTag); +- BlockItem.setBlockEntityData(itemStack, BlockEntityType.BANNER, blockEntityData); ++ CompoundTag nbttagcompound1 = new CompoundTag(); ++ ++ nbttagcompound1.putString("Pattern", ((BannerPattern) pattern.value()).getHashname()); ++ nbttagcompound1.putInt("Color", enumcolor.getId()); ++ nbttaglist.add(nbttagcompound1); ++ BlockItem.setBlockEntityData(itemstack2, BlockEntityType.BANNER, nbttagcompound); + } + +- if (!ItemStack.matches(itemStack, this.resultSlot.getItem())) { +- this.resultSlot.set(itemStack); ++ if (!ItemStack.matches(itemstack2, this.resultSlot.getItem())) { ++ this.resultSlot.set(itemstack2); + } ++ + } + + public Slot getBannerSlot() { |