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

@@ -0,0 +1,86 @@
--- a/net/minecraft/world/BossEvent.java
+++ b/net/minecraft/world/BossEvent.java
@@ -13,6 +_,7 @@
protected boolean darkenScreen;
protected boolean playBossMusic;
protected boolean createWorldFog;
+ public net.kyori.adventure.bossbar.BossBar adventure; // Paper
public BossEvent(UUID id, Component name, BossEvent.BossBarColor color, BossEvent.BossBarOverlay overlay) {
this.id = id;
@@ -27,61 +_,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 progress) {
+ if (this.adventure != null) this.adventure.progress(progress); // Paper
this.progress = progress;
}
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 overlay) {
+ if (this.adventure != null) this.adventure.overlay(io.papermc.paper.adventure.PaperAdventure.asAdventure(overlay)); // Paper
this.overlay = overlay;
}
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 playEndBossMusic) {
+ if (this.adventure != null) io.papermc.paper.adventure.PaperAdventure.setFlag(this.adventure, net.kyori.adventure.bossbar.BossBar.Flag.PLAY_BOSS_MUSIC, playEndBossMusic); // Paper
this.playBossMusic = playEndBossMusic;
return this;
}
public BossEvent setCreateWorldFog(boolean createFog) {
+ if (this.adventure != null) io.papermc.paper.adventure.PaperAdventure.setFlag(this.adventure, net.kyori.adventure.bossbar.BossBar.Flag.CREATE_WORLD_FOG, createFog); // Paper
this.createWorldFog = createFog;
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

@@ -0,0 +1,60 @@
--- a/net/minecraft/world/CompoundContainer.java
+++ b/net/minecraft/world/CompoundContainer.java
@@ -7,6 +_,48 @@
private final Container container1;
private final Container container2;
+ // Paper start - add fields and methods
+ public java.util.List<org.bukkit.entity.HumanEntity> transaction = new java.util.ArrayList<org.bukkit.entity.HumanEntity>();
+
+ public java.util.List<ItemStack> getContents() {
+ java.util.List<ItemStack> result = new java.util.ArrayList<>(this.getContainerSize());
+ for (int i = 0; i < this.getContainerSize(); i++) {
+ result.add(this.getItem(i));
+ }
+ return result;
+ }
+
+ public void onOpen(org.bukkit.craftbukkit.entity.CraftHumanEntity who) {
+ this.container1.onOpen(who);
+ this.container2.onOpen(who);
+ this.transaction.add(who);
+ }
+
+ public void onClose(org.bukkit.craftbukkit.entity.CraftHumanEntity who) {
+ this.container1.onClose(who);
+ this.container2.onClose(who);
+ this.transaction.remove(who);
+ }
+
+ public java.util.List<org.bukkit.entity.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 org.bukkit.Location getLocation() {
+ return this.container1.getLocation(); // TODO: right?
+ }
+ // Paper end
+
public CompoundContainer(Container container1, Container container2) {
this.container1 = container1;
this.container2 = container2;
@@ -58,7 +_,7 @@
@Override
public int getMaxStackSize() {
- return this.container1.getMaxStackSize();
+ return Math.min(this.container1.getMaxStackSize(), this.container2.getMaxStackSize()); // Paper - check both sides
}
@Override

View File

@@ -0,0 +1,36 @@
--- a/net/minecraft/world/Container.java
+++ b/net/minecraft/world/Container.java
@@ -24,9 +_,7 @@
void setItem(int slot, ItemStack stack);
- default int getMaxStackSize() {
- return 99;
- }
+ int getMaxStackSize(); // Paper
default int getMaxStackSize(ItemStack stack) {
return Math.min(this.getMaxStackSize(), stack.getMaxStackSize());
@@ -87,4 +_,22 @@
BlockPos blockPos = blockEntity.getBlockPos();
return level != null && level.getBlockEntity(blockPos) == blockEntity && player.canInteractWithBlock(blockPos, distance);
}
+
+ // Paper start
+ java.util.List<ItemStack> getContents();
+
+ void onOpen(org.bukkit.craftbukkit.entity.CraftHumanEntity who);
+
+ void onClose(org.bukkit.craftbukkit.entity.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;
+ // Paper end
}

View File

@@ -0,0 +1,92 @@
--- a/net/minecraft/world/RandomizableContainer.java
+++ b/net/minecraft/world/RandomizableContainer.java
@@ -28,7 +_,7 @@
void setLootTable(@Nullable ResourceKey<LootTable> lootTable);
- default void setLootTable(ResourceKey<LootTable> lootTable, long seed) {
+ default void setLootTable(@Nullable ResourceKey<LootTable> lootTable, long seed) { // Paper - add nullable
this.setLootTable(lootTable);
this.setLootTableSeed(seed);
}
@@ -50,14 +_,15 @@
default boolean tryLoadLootTable(CompoundTag tag) {
if (tag.contains("LootTable", 8)) {
- this.setLootTable(ResourceKey.create(Registries.LOOT_TABLE, ResourceLocation.parse(tag.getString("LootTable"))));
+ this.setLootTable(net.minecraft.Optionull.map(ResourceLocation.tryParse(tag.getString("LootTable")), rl -> ResourceKey.create(Registries.LOOT_TABLE, rl))); // Paper - Validate ResourceLocation
+ if (this.lootableData() != null && this.getLootTable() != null) this.lootableData().loadNbt(tag); // Paper - LootTable API
if (tag.contains("LootTableSeed", 4)) {
this.setLootTableSeed(tag.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 +_,42 @@
return false;
} else {
tag.putString("LootTable", lootTable.location().toString());
+ if (this.lootableData() != null) this.lootableData().saveNbt(tag); // Paper - LootTable API
long lootTableSeed = this.getLootTableSeed();
if (lootTableSeed != 0L) {
tag.putLong("LootTableSeed", lootTableSeed);
}
- 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> lootTable = this.getLootTable();
- if (lootTable != null && level != null && level.getServer() != null) {
+ // Paper start - LootTable API
+ lootReplenish: if (lootTable != 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 lootTable1 = level.getServer().reloadableRegistries().getLootTable(lootTable);
if (player instanceof ServerPlayer) {
CriteriaTriggers.GENERATE_LOOT.trigger((ServerPlayer)player, lootTable);
}
+ if (forceClearLootTable || this.lootableData() == null || this.lootableData().shouldClearLootTable(this, com.destroystokyo.paper.loottable.PaperLootableInventoryData.CONTAINER, player)) { // Paper - LootTable API
this.setLootTable(null);
+ } // Paper - 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 +_,17 @@
lootTable1.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

@@ -0,0 +1,87 @@
--- a/net/minecraft/world/SimpleContainer.java
+++ b/net/minecraft/world/SimpleContainer.java
@@ -19,7 +_,84 @@
@Nullable
private List<ContainerListener> listeners;
+ // Paper start - add fields and methods
+ public List<org.bukkit.entity.HumanEntity> transaction = new java.util.ArrayList<>();
+ private int maxStack = MAX_STACK;
+ protected @Nullable org.bukkit.inventory.InventoryHolder bukkitOwner; // Paper - annotation
+
+ public List<ItemStack> getContents() {
+ return this.items;
+ }
+
+ public void onOpen(org.bukkit.craftbukkit.entity.CraftHumanEntity who) {
+ this.transaction.add(who);
+ }
+
+ public void onClose(org.bukkit.craftbukkit.entity.CraftHumanEntity who) {
+ this.transaction.remove(who);
+ }
+
+ public List<org.bukkit.entity.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 org.bukkit.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());
+ }
+ }
+ // Paper end
+
public SimpleContainer(int size) {
+ 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 size, org.bukkit.inventory.InventoryHolder owner) {
+ this.bukkitOwner = owner;
+ // Paper end
this.size = size;
this.items = NonNullList.withSize(size, ItemStack.EMPTY);
}

View File

@@ -18,17 +18,17 @@
}
}
@@ -122,12 +_,14 @@
public void addAdditionalSaveData(CompoundTag compound) {
super.addAdditionalSaveData(compound);
compound.putInt("Age", this.age);
+ compound.putBoolean("AgeLocked", this.ageLocked); // Paper
public void addAdditionalSaveData(CompoundTag tag) {
super.addAdditionalSaveData(tag);
tag.putInt("Age", this.age);
+ tag.putBoolean("AgeLocked", this.ageLocked); // Paper
}
@Override
public void readAdditionalSaveData(CompoundTag compound) {
super.readAdditionalSaveData(compound);
this.setAge(compound.getInt("Age"));
+ this.ageLocked = compound.getBoolean("AgeLocked"); // Paper
public void readAdditionalSaveData(CompoundTag tag) {
super.readAdditionalSaveData(tag);
this.setAge(tag.getInt("Age"));
+ this.ageLocked = tag.getBoolean("AgeLocked"); // Paper
}
@Nullable
@@ -67,18 +67,18 @@
private void ageUp() {
if (this.level() instanceof ServerLevel serverLevel) {
- this.convertTo(EntityType.FROG, ConversionParams.single(this, false, false), mob -> {
+ Frog converted = this.convertTo(EntityType.FROG, ConversionParams.single(this, false, false), mob -> { // CraftBukkit
+ Frog converted = this.convertTo(EntityType.FROG, ConversionParams.single(this, false, false), mob -> { // Paper
mob.finalizeSpawn(serverLevel, this.level().getCurrentDifficultyAt(mob.blockPosition()), EntitySpawnReason.CONVERSION, null);
mob.setPersistenceRequired();
mob.fudgePositionAfterSizeChange(this.getDimensions(this.getPose()));
this.playSound(SoundEvents.TADPOLE_GROW_UP, 0.15F, 1.0F);
- });
+ // CraftBukkit start
+ // Paper start
+ }, org.bukkit.event.entity.EntityTransformEvent.TransformReason.METAMORPHOSIS, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.METAMORPHOSIS);
+ if (converted == null) {
+ this.setAge(0); // Sets the age to 0 for avoid a loop if the event is canceled
+ }
+ // CraftBukkit end
+ // Paper end
}
}