net/minecraft/world + Tadpole?

This commit is contained in:
Noah van der Aa
2024-12-13 19:17:03 +01:00
parent 18a25937bc
commit 7d42b87010
8 changed files with 173 additions and 218 deletions

View File

@@ -1,86 +0,0 @@
--- a/net/minecraft/world/BossEvent.java
+++ b/net/minecraft/world/BossEvent.java
@@ -13,6 +13,7 @@
protected boolean darkenScreen;
protected boolean playBossMusic;
protected boolean createWorldFog;
+ public net.kyori.adventure.bossbar.BossBar adventure; // Paper
public BossEvent(UUID uuid, Component name, BossEvent.BossBarColor color, BossEvent.BossBarOverlay style) {
this.id = uuid;
@@ -27,61 +28,75 @@
}
public Component getName() {
+ if (this.adventure != null) return io.papermc.paper.adventure.PaperAdventure.asVanilla(this.adventure.name()); // Paper
return this.name;
}
public void setName(Component name) {
+ if (this.adventure != null) this.adventure.name(io.papermc.paper.adventure.PaperAdventure.asAdventure(name)); // Paper
this.name = name;
}
public float getProgress() {
+ if (this.adventure != null) return this.adventure.progress(); // Paper
return this.progress;
}
public void setProgress(float percent) {
+ if (this.adventure != null) this.adventure.progress(percent); // Paper
this.progress = percent;
}
public BossEvent.BossBarColor getColor() {
+ if (this.adventure != null) return io.papermc.paper.adventure.PaperAdventure.asVanilla(this.adventure.color()); // Paper
return this.color;
}
public void setColor(BossEvent.BossBarColor color) {
+ if (this.adventure != null) this.adventure.color(io.papermc.paper.adventure.PaperAdventure.asAdventure(color)); // Paper
this.color = color;
}
public BossEvent.BossBarOverlay getOverlay() {
+ if (this.adventure != null) return io.papermc.paper.adventure.PaperAdventure.asVanilla(this.adventure.overlay()); // Paper
return this.overlay;
}
public void setOverlay(BossEvent.BossBarOverlay style) {
+ if (this.adventure != null) this.adventure.overlay(io.papermc.paper.adventure.PaperAdventure.asAdventure(style)); // Paper
this.overlay = style;
}
public boolean shouldDarkenScreen() {
+ if (this.adventure != null) return this.adventure.hasFlag(net.kyori.adventure.bossbar.BossBar.Flag.DARKEN_SCREEN); // Paper
return this.darkenScreen;
}
public BossEvent setDarkenScreen(boolean darkenSky) {
+ if (this.adventure != null) io.papermc.paper.adventure.PaperAdventure.setFlag(this.adventure, net.kyori.adventure.bossbar.BossBar.Flag.DARKEN_SCREEN, darkenSky); // Paper
this.darkenScreen = darkenSky;
return this;
}
public boolean shouldPlayBossMusic() {
+ if (this.adventure != null) return this.adventure.hasFlag(net.kyori.adventure.bossbar.BossBar.Flag.PLAY_BOSS_MUSIC); // Paper
return this.playBossMusic;
}
public BossEvent setPlayBossMusic(boolean dragonMusic) {
+ if (this.adventure != null) io.papermc.paper.adventure.PaperAdventure.setFlag(this.adventure, net.kyori.adventure.bossbar.BossBar.Flag.PLAY_BOSS_MUSIC, dragonMusic); // Paper
this.playBossMusic = dragonMusic;
return this;
}
public BossEvent setCreateWorldFog(boolean thickenFog) {
+ if (this.adventure != null) io.papermc.paper.adventure.PaperAdventure.setFlag(this.adventure, net.kyori.adventure.bossbar.BossBar.Flag.CREATE_WORLD_FOG, thickenFog); // Paper
this.createWorldFog = thickenFog;
return this;
}
public boolean shouldCreateWorldFog() {
+ if (this.adventure != null) return this.adventure.hasFlag(net.kyori.adventure.bossbar.BossBar.Flag.CREATE_WORLD_FOG); // Paper
return this.createWorldFog;
}

View File

@@ -1,74 +0,0 @@
--- a/net/minecraft/world/CompoundContainer.java
+++ b/net/minecraft/world/CompoundContainer.java
@@ -3,11 +3,62 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
+// CraftBukkit start
+import java.util.ArrayList;
+import java.util.List;
+import org.bukkit.Location;
+
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
public class CompoundContainer implements Container {
public final Container container1;
public final Container container2;
+ // CraftBukkit start - add fields and methods
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+
+ public List<ItemStack> getContents() {
+ List<ItemStack> result = new ArrayList<ItemStack>(this.getContainerSize());
+ for (int i = 0; i < this.getContainerSize(); i++) {
+ result.add(this.getItem(i));
+ }
+ return result;
+ }
+
+ public void onOpen(CraftHumanEntity who) {
+ this.container1.onOpen(who);
+ this.container2.onOpen(who);
+ this.transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ this.container1.onClose(who);
+ this.container2.onClose(who);
+ this.transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return this.transaction;
+ }
+
+ public org.bukkit.inventory.InventoryHolder getOwner() {
+ return null; // This method won't be called since CraftInventoryDoubleChest doesn't defer to here
+ }
+
+ public void setMaxStackSize(int size) {
+ this.container1.setMaxStackSize(size);
+ this.container2.setMaxStackSize(size);
+ }
+
+ @Override
+ public Location getLocation() {
+ return this.container1.getLocation(); // TODO: right?
+ }
+ // CraftBukkit end
+
public CompoundContainer(Container first, Container second) {
this.container1 = first;
this.container2 = second;
@@ -54,7 +105,7 @@
@Override
public int getMaxStackSize() {
- return this.container1.getMaxStackSize();
+ return Math.min(this.container1.getMaxStackSize(), this.container2.getMaxStackSize()); // CraftBukkit - check both sides
}
@Override

View File

@@ -1,49 +0,0 @@
--- a/net/minecraft/world/Container.java
+++ b/net/minecraft/world/Container.java
@@ -6,8 +6,12 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
+// CraftBukkit start
+import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+// CraftBukkit end
public interface Container extends Clearable {
@@ -25,9 +29,7 @@
void setItem(int slot, ItemStack stack);
- default int getMaxStackSize() {
- return 99;
- }
+ int getMaxStackSize(); // CraftBukkit
default int getMaxStackSize(ItemStack stack) {
return Math.min(this.getMaxStackSize(), stack.getMaxStackSize());
@@ -91,4 +93,22 @@
return world == null ? false : (world.getBlockEntity(blockposition) != blockEntity ? false : player.canInteractWithBlock(blockposition, (double) range));
}
+
+ // CraftBukkit start
+ java.util.List<ItemStack> getContents();
+
+ void onOpen(CraftHumanEntity who);
+
+ void onClose(CraftHumanEntity who);
+
+ java.util.List<org.bukkit.entity.HumanEntity> getViewers();
+
+ org.bukkit.inventory.@org.jetbrains.annotations.Nullable InventoryHolder getOwner(); // Paper - annotation
+
+ void setMaxStackSize(int size);
+
+ org.bukkit.Location getLocation();
+
+ int MAX_STACK = 99;
+ // CraftBukkit end
}

View File

@@ -1,94 +0,0 @@
--- a/net/minecraft/world/RandomizableContainer.java
+++ b/net/minecraft/world/RandomizableContainer.java
@@ -28,7 +28,7 @@
void setLootTable(@Nullable ResourceKey<LootTable> lootTable);
- default void setLootTable(ResourceKey<LootTable> lootTableId, long lootTableSeed) {
+ default void setLootTable(@Nullable ResourceKey<LootTable> lootTableId, long lootTableSeed) { // Paper - add nullable
this.setLootTable(lootTableId);
this.setLootTableSeed(lootTableSeed);
}
@@ -50,14 +50,15 @@
default boolean tryLoadLootTable(CompoundTag nbt) {
if (nbt.contains("LootTable", 8)) {
- this.setLootTable(ResourceKey.create(Registries.LOOT_TABLE, ResourceLocation.parse(nbt.getString("LootTable"))));
+ this.setLootTable(net.minecraft.Optionull.map(ResourceLocation.tryParse(nbt.getString("LootTable")), rl -> ResourceKey.create(Registries.LOOT_TABLE, rl))); // Paper - Validate ResourceLocation
+ if (this.lootableData() != null && this.getLootTable() != null) this.lootableData().loadNbt(nbt); // Paper - LootTable API
if (nbt.contains("LootTableSeed", 4)) {
this.setLootTableSeed(nbt.getLong("LootTableSeed"));
} else {
this.setLootTableSeed(0L);
}
- return true;
+ return this.lootableData() == null; // Paper - only track the loot table if there is chance for replenish
} else {
return false;
}
@@ -69,26 +70,44 @@
return false;
} else {
nbt.putString("LootTable", resourceKey.location().toString());
+ if (this.lootableData() != null) this.lootableData().saveNbt(nbt); // Paper - LootTable API
long l = this.getLootTableSeed();
if (l != 0L) {
nbt.putLong("LootTableSeed", l);
}
- return true;
+ return this.lootableData() == null; // Paper - only track the loot table if there is chance for replenish
}
}
default void unpackLootTable(@Nullable Player player) {
+ // Paper start - LootTable API
+ this.unpackLootTable(player, false);
+ }
+ default void unpackLootTable(@Nullable final Player player, final boolean forceClearLootTable) {
+ // Paper end - LootTable API
Level level = this.getLevel();
BlockPos blockPos = this.getBlockPos();
ResourceKey<LootTable> resourceKey = this.getLootTable();
- if (resourceKey != null && level != null && level.getServer() != null) {
+ // Paper start - LootTable API
+ lootReplenish: if (resourceKey != null && level != null && level.getServer() != null) {
+ if (this.lootableData() != null && !this.lootableData().shouldReplenish(this, com.destroystokyo.paper.loottable.PaperLootableInventoryData.CONTAINER, player)) {
+ if (forceClearLootTable) {
+ this.setLootTable(null);
+ }
+ break lootReplenish;
+ }
+ // Paper end - LootTable API
LootTable lootTable = level.getServer().reloadableRegistries().getLootTable(resourceKey);
if (player instanceof ServerPlayer) {
CriteriaTriggers.GENERATE_LOOT.trigger((ServerPlayer)player, resourceKey);
}
- this.setLootTable(null);
+ // Paper start - LootTable API
+ if (forceClearLootTable || this.lootableData() == null || this.lootableData().shouldClearLootTable(this, com.destroystokyo.paper.loottable.PaperLootableInventoryData.CONTAINER, player)) {
+ this.setLootTable(null);
+ }
+ // Paper end - LootTable API
LootParams.Builder builder = new LootParams.Builder((ServerLevel)level).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockPos));
if (player != null) {
builder.withLuck(player.getLuck()).withParameter(LootContextParams.THIS_ENTITY, player);
@@ -97,4 +116,16 @@
lootTable.fill(this, builder.create(LootContextParamSets.CHEST), this.getLootTableSeed());
}
}
+
+ // Paper start - LootTable API
+ @Nullable @org.jetbrains.annotations.Contract(pure = true)
+ default com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData() {
+ return null; // some containers don't really have a "replenish" ability like decorated pots
+ }
+
+ default com.destroystokyo.paper.loottable.PaperLootableInventory getLootableInventory() {
+ final org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(java.util.Objects.requireNonNull(this.getLevel(), "Cannot manage loot tables on block entities not in world"), this.getBlockPos());
+ return (com.destroystokyo.paper.loottable.PaperLootableInventory) block.getState(false);
+ }
+ // Paper end - LootTable API
}

View File

@@ -1,103 +0,0 @@
--- a/net/minecraft/world/SimpleContainer.java
+++ b/net/minecraft/world/SimpleContainer.java
@@ -14,18 +14,98 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
+// CraftBukkit start
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
public class SimpleContainer implements Container, StackedContentsCompatible {
private final int size;
public final NonNullList<ItemStack> items;
@Nullable
private List<ContainerListener> listeners;
+
+ // CraftBukkit start - add fields and methods
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+ private int maxStack = MAX_STACK;
+ protected @Nullable org.bukkit.inventory.InventoryHolder bukkitOwner; // Paper - annotation
+
+ public List<ItemStack> getContents() {
+ return this.items;
+ }
+
+ public void onOpen(CraftHumanEntity who) {
+ this.transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ this.transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return this.transaction;
+ }
+
+ @Override
+ public int getMaxStackSize() {
+ return this.maxStack;
+ }
+
+ public void setMaxStackSize(int i) {
+ this.maxStack = i;
+ }
+
+ public org.bukkit.inventory.InventoryHolder getOwner() {
+ // Paper start - Add missing InventoryHolders
+ if (this.bukkitOwner == null && this.bukkitOwnerCreator != null) {
+ this.bukkitOwner = this.bukkitOwnerCreator.get();
+ }
+ // Paper end - Add missing InventoryHolders
+ return this.bukkitOwner;
+ }
+ @Override
+ public Location getLocation() {
+ // Paper start - Fix inventories returning null Locations
+ // When the block inventory does not have a tile state that implements getLocation, e. g. composters
+ if (this.bukkitOwner instanceof org.bukkit.inventory.BlockInventoryHolder blockInventoryHolder) {
+ return blockInventoryHolder.getBlock().getLocation();
+ }
+ // When the bukkit owner is a bukkit entity, but does not implement Container itself, e. g. horses
+ if (this.bukkitOwner instanceof org.bukkit.entity.Entity entity) {
+ return entity.getLocation();
+ }
+ // Paper end - Fix inventories returning null Locations
+ return null;
+ }
+
+ public SimpleContainer(SimpleContainer original) {
+ this(original.size);
+ for (int slot = 0; slot < original.size; slot++) {
+ this.items.set(slot, original.items.get(slot).copy());
+ }
+ }
+
public SimpleContainer(int size) {
- this.size = size;
- this.items = NonNullList.withSize(size, ItemStack.EMPTY);
+ this(size, null);
+ }
+ // Paper start - Add missing InventoryHolders
+ private @Nullable java.util.function.Supplier<? extends org.bukkit.inventory.InventoryHolder> bukkitOwnerCreator;
+ public SimpleContainer(java.util.function.Supplier<? extends org.bukkit.inventory.InventoryHolder> bukkitOwnerCreator, int size) {
+ this(size);
+ this.bukkitOwnerCreator = bukkitOwnerCreator;
}
+ // Paper end - Add missing InventoryHolders
+ public SimpleContainer(int i, org.bukkit.inventory.InventoryHolder owner) {
+ this.bukkitOwner = owner;
+ // CraftBukkit end
+ this.size = i;
+ this.items = NonNullList.withSize(i, ItemStack.EMPTY);
+ }
+
public SimpleContainer(ItemStack... items) {
this.size = items.length;
this.items = NonNullList.of(ItemStack.EMPTY, items);