net/minecraft/world/level/block/entity/vault

This commit is contained in:
Noah van der Aa 2024-12-14 19:37:31 +01:00
parent 27a47b77c7
commit 6a84e88e76
No known key found for this signature in database
GPG Key ID: 547D90BC6FF753CF
2 changed files with 26 additions and 83 deletions

View File

@ -0,0 +1,26 @@
--- a/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java
@@ -272,6 +_,11 @@
if (!list.isEmpty()) {
player.awardStat(Stats.ITEM_USED.get(stack.getItem()));
stack.consume(config.keyItem().getCount(), player);
+ // CraftBukkit start
+ org.bukkit.event.block.BlockDispenseLootEvent vaultDispenseLootEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDispenseLootEvent(level, pos, player, list);
+ if (vaultDispenseLootEvent.isCancelled()) return;
+ list = vaultDispenseLootEvent.getDispensedLoot().stream().map(org.bukkit.craftbukkit.inventory.CraftItemStack::asNMSCopy).toList();
+ // CraftBukkit end
unlock(level, state, pos, config, serverData, sharedData, list);
serverData.addToRewardedPlayers(player);
sharedData.updateConnectedPlayersWithinRange(level, pos, serverData, config, config.deactivationRange());
@@ -294,6 +_,11 @@
ItemStack randomDisplayItemFromLootTable = getRandomDisplayItemFromLootTable(
level, pos, config.overrideLootTableToDisplay().orElse(config.lootTable())
);
+ // CraftBukkit start
+ org.bukkit.event.block.VaultDisplayItemEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callVaultDisplayItemEvent(level, pos, randomDisplayItemFromLootTable);
+ if (event.isCancelled()) return;
+ randomDisplayItemFromLootTable = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getDisplayItem());
+ // CraftBukkit end
sharedData.setDisplayItem(randomDisplayItemFromLootTable);
}
}

View File

@ -1,83 +0,0 @@
--- a/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java
@@ -46,6 +46,13 @@
import net.minecraft.world.phys.Vec3;
import org.slf4j.Logger;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.block.BlockDispenseLootEvent;
+import org.bukkit.event.block.VaultDisplayItemEvent;
+// CraftBukkit end
+
public class VaultBlockEntity extends BlockEntity {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -96,18 +103,18 @@
dataresult = VaultServerData.CODEC.parse(dynamicops, nbt.get("server_data"));
logger = VaultBlockEntity.LOGGER;
Objects.requireNonNull(logger);
- optional = dataresult.resultOrPartial(logger::error);
+ optional = ((DataResult<VaultServerData>) dataresult).resultOrPartial(logger::error); // CraftBukkit - decompile error
VaultServerData vaultserverdata = this.serverData;
Objects.requireNonNull(this.serverData);
- optional.ifPresent(vaultserverdata::set);
+ ((Optional<VaultServerData>) optional).ifPresent(vaultserverdata::set); // CraftBukkit - decompile error
}
if (nbt.contains("config")) {
dataresult = VaultConfig.CODEC.parse(dynamicops, nbt.get("config"));
logger = VaultBlockEntity.LOGGER;
Objects.requireNonNull(logger);
- dataresult.resultOrPartial(logger::error).ifPresent((vaultconfig) -> {
+ ((DataResult<VaultConfig>) dataresult).resultOrPartial(logger::error).ifPresent((vaultconfig) -> { // CraftBukkit - decompile error
this.config = vaultconfig;
});
}
@@ -116,11 +123,11 @@
dataresult = VaultSharedData.CODEC.parse(dynamicops, nbt.get("shared_data"));
logger = VaultBlockEntity.LOGGER;
Objects.requireNonNull(logger);
- optional = dataresult.resultOrPartial(logger::error);
+ optional = ((DataResult<VaultSharedData>) dataresult).resultOrPartial(logger::error); // CraftBukkit - decompile error
VaultSharedData vaultshareddata = this.sharedData;
Objects.requireNonNull(this.sharedData);
- optional.ifPresent(vaultshareddata::set);
+ ((Optional<VaultSharedData>) optional).ifPresent(vaultshareddata::set); // CraftBukkit - decompile error
}
}
@@ -320,6 +327,14 @@
if (!list.isEmpty()) {
player.awardStat(Stats.ITEM_USED.get(stack.getItem()));
stack.consume(config.keyItem().getCount(), player);
+ // CraftBukkit start
+ BlockDispenseLootEvent vaultDispenseLootEvent = CraftEventFactory.callBlockDispenseLootEvent(world, pos, player, list);
+ if (vaultDispenseLootEvent.isCancelled()) {
+ return;
+ }
+
+ list = vaultDispenseLootEvent.getDispensedLoot().stream().map(CraftItemStack::asNMSCopy).toList();
+ // CraftBukkit end
Server.unlock(world, state, pos, config, serverData, sharedData, list);
serverData.addToRewardedPlayers(player);
sharedData.updateConnectedPlayersWithinRange(world, pos, serverData, config, config.deactivationRange());
@@ -341,7 +356,15 @@
sharedData.setDisplayItem(ItemStack.EMPTY);
} else {
ItemStack itemstack = Server.getRandomDisplayItemFromLootTable(world, pos, (ResourceKey) config.overrideLootTableToDisplay().orElse(config.lootTable()));
+ // CraftBukkit start
+ VaultDisplayItemEvent event = CraftEventFactory.callVaultDisplayItemEvent(world, pos, itemstack);
+ if (event.isCancelled()) {
+ return;
+ }
+ itemstack = CraftItemStack.asNMSCopy(event.getDisplayItem());
+ // CraftBukkit end
+
sharedData.setDisplayItem(itemstack);
}
}