Commits
coll1234567 authored and md_5 committed 669b4139388
1 1 | package org.bukkit.craftbukkit.block; |
2 2 | |
3 + | import com.google.common.base.Preconditions; |
4 + | import java.util.Optional; |
5 + | import net.minecraft.resources.ResourceKey; |
6 + | import net.minecraft.world.item.ItemStack; |
7 + | import net.minecraft.world.level.block.entity.trialspawner.PlayerDetector; |
3 8 | import net.minecraft.world.level.block.entity.vault.VaultBlockEntity; |
9 + | import net.minecraft.world.level.block.entity.vault.VaultConfig; |
10 + | import net.minecraft.world.level.storage.loot.LootTable; |
4 11 | import org.bukkit.Location; |
5 12 | import org.bukkit.World; |
6 13 | import org.bukkit.block.Vault; |
14 + | import org.bukkit.craftbukkit.CraftLootTable; |
15 + | import org.bukkit.craftbukkit.inventory.CraftItemStack; |
7 16 | |
8 17 | public class CraftVault extends CraftBlockEntityState<VaultBlockEntity> implements Vault { |
18 + | private final CraftVaultConfiguration config; |
9 19 | |
10 20 | public CraftVault(World world, VaultBlockEntity tileEntity) { |
11 21 | super(world, tileEntity); |
22 + | this.config = new CraftVaultConfiguration(tileEntity.getConfig()); |
12 23 | } |
13 24 | |
14 25 | protected CraftVault(CraftVault state, Location location) { |
15 26 | super(state, location); |
27 + | this.config = state.config; |
16 28 | } |
17 29 | |
18 30 | |
19 31 | public CraftVault copy() { |
20 32 | return new CraftVault(this, null); |
21 33 | } |
22 34 | |
23 35 | |
24 36 | public CraftVault copy(Location location) { |
25 37 | return new CraftVault(this, location); |
26 38 | } |
39 + | |
40 + | |
41 + | public double getActivationRange() { |
42 + | return config.activationRange; |
43 + | } |
44 + | |
45 + | |
46 + | public void setActivationRange(double range) { |
47 + | config.activationRange = range; |
48 + | } |
49 + | |
50 + | |
51 + | public double getDeactivationRange() { |
52 + | return config.deactivationRange; |
53 + | } |
54 + | |
55 + | |
56 + | public void setDeactivationRange(double range) { |
57 + | config.deactivationRange = range; |
58 + | } |
59 + | |
60 + | |
61 + | public org.bukkit.loot.LootTable getLootTable() { |
62 + | return CraftLootTable.minecraftToBukkit(config.lootTable); |
63 + | } |
64 + | |
65 + | |
66 + | public void setLootTable(org.bukkit.loot.LootTable lootTable) { |
67 + | Preconditions.checkArgument(lootTable != null, "LootTable cannot be null"); |
68 + | config.lootTable = CraftLootTable.bukkitToMinecraft(lootTable); |
69 + | } |
70 + | |
71 + | |
72 + | public org.bukkit.loot.LootTable getDisplayLootTable() { |
73 + | return config.overrideLootTableToDisplay.map(CraftLootTable::minecraftToBukkit).orElse(null); |
74 + | } |
75 + | |
76 + | |
77 + | public void setDisplayLootTable(org.bukkit.loot.LootTable lootTable) { |
78 + | config.overrideLootTableToDisplay = Optional.ofNullable(CraftLootTable.bukkitToMinecraft(lootTable)); |
79 + | } |
80 + | |
81 + | |
82 + | public org.bukkit.inventory.ItemStack getKeyItem() { |
83 + | return CraftItemStack.asBukkitCopy(config.keyItem); |
84 + | } |
85 + | |
86 + | |
87 + | public void setKeyItem(org.bukkit.inventory.ItemStack keyItem) { |
88 + | Preconditions.checkArgument(keyItem != null, "Key item cannot be null"); |
89 + | config.keyItem = CraftItemStack.asNMSCopy(keyItem); |
90 + | } |
91 + | |
92 + | |
93 + | protected void applyTo(VaultBlockEntity tileEntity) { |
94 + | super.applyTo(tileEntity); |
95 + | |
96 + | tileEntity.setConfig(this.config.toMinecraft()); |
97 + | } |
98 + | |
99 + | static class CraftVaultConfiguration { |
100 + | private ResourceKey<LootTable> lootTable; |
101 + | private double activationRange; |
102 + | private double deactivationRange; |
103 + | private ItemStack keyItem; |
104 + | private Optional<ResourceKey<LootTable>> overrideLootTableToDisplay; |
105 + | private PlayerDetector playerDetector; |
106 + | private net.minecraft.world.level.block.entity.trialspawner.PlayerDetector.a entitySelector; |
107 + | |
108 + | private CraftVaultConfiguration(VaultConfig minecraft) { |
109 + | this.lootTable = minecraft.lootTable(); |
110 + | this.activationRange = minecraft.activationRange(); |
111 + | this.deactivationRange = minecraft.deactivationRange(); |
112 + | this.keyItem = minecraft.keyItem(); |
113 + | this.overrideLootTableToDisplay = minecraft.overrideLootTableToDisplay(); |
114 + | this.playerDetector = minecraft.playerDetector(); |
115 + | this.entitySelector = minecraft.entitySelector(); |
116 + | } |
117 + | |
118 + | private VaultConfig toMinecraft() { |
119 + | return new VaultConfig(lootTable, activationRange, deactivationRange, keyItem, overrideLootTableToDisplay, playerDetector, entitySelector); |
120 + | } |
121 + | } |
27 122 | } |