Allow chests to be placed with NBT data

This commit is contained in:
BillyGalbreath 2018-09-08 18:43:31 -05:00
parent 04afedcccf
commit ca341c9de8
2 changed files with 21 additions and 20 deletions

View file

@ -152,7 +152,7 @@
}); });
} }
} }
@@ -370,32 +418,190 @@ @@ -370,32 +418,191 @@
} }
public InteractionResult useOn(UseOnContext context) { public InteractionResult useOn(UseOnContext context) {
@ -169,7 +169,7 @@
+ DataComponentPatch oldData = this.components.asPatch(); + DataComponentPatch oldData = this.components.asPatch();
+ int oldCount = this.getCount(); + int oldCount = this.getCount();
+ ServerLevel world = (ServerLevel) context.getLevel(); + ServerLevel world = (ServerLevel) context.getLevel();
+
+ if (!(item instanceof BucketItem || item instanceof SolidBucketItem)) { // if not bucket + if (!(item instanceof BucketItem || item instanceof SolidBucketItem)) { // if not bucket
+ world.captureBlockStates = true; + world.captureBlockStates = true;
+ // special case bonemeal + // special case bonemeal
@ -200,7 +200,7 @@
+ structureEvent = new StructureGrowEvent(location, treeType, isBonemeal, (Player) entityhuman.getBukkitEntity(), (List< BlockState>) (List<? extends BlockState>) blocks); + structureEvent = new StructureGrowEvent(location, treeType, isBonemeal, (Player) entityhuman.getBukkitEntity(), (List< BlockState>) (List<? extends BlockState>) blocks);
+ org.bukkit.Bukkit.getPluginManager().callEvent(structureEvent); + org.bukkit.Bukkit.getPluginManager().callEvent(structureEvent);
+ } + }
+
+ BlockFertilizeEvent fertilizeEvent = new BlockFertilizeEvent(CraftBlock.at(world, blockposition), (Player) entityhuman.getBukkitEntity(), (List< BlockState>) (List<? extends BlockState>) blocks); + BlockFertilizeEvent fertilizeEvent = new BlockFertilizeEvent(CraftBlock.at(world, blockposition), (Player) entityhuman.getBukkitEntity(), (List< BlockState>) (List<? extends BlockState>) blocks);
+ fertilizeEvent.setCancelled(structureEvent != null && structureEvent.isCancelled()); + fertilizeEvent.setCancelled(structureEvent != null && structureEvent.isCancelled());
+ org.bukkit.Bukkit.getPluginManager().callEvent(fertilizeEvent); + org.bukkit.Bukkit.getPluginManager().callEvent(fertilizeEvent);
@ -242,6 +242,7 @@
+ enuminteractionresult = InteractionResult.FAIL; // cancel placement + enuminteractionresult = InteractionResult.FAIL; // cancel placement
+ // PAIL: Remove this when MC-99075 fixed + // PAIL: Remove this when MC-99075 fixed
+ placeEvent.getPlayer().updateInventory(); + placeEvent.getPlayer().updateInventory();
+ world.capturedTileEntities.clear(); // Paper - Allow chests to be placed with NBT data; clear out block entities as chests and such will pop loot
+ // revert back all captured blocks + // revert back all captured blocks
+ world.preventPoiUpdated = true; // CraftBukkit - SPIGOT-5710 + world.preventPoiUpdated = true; // CraftBukkit - SPIGOT-5710
+ for (BlockState blockstate : blocks) { + for (BlockState blockstate : blocks) {
@ -348,7 +349,7 @@
ItemStack itemstack = this.copy(); ItemStack itemstack = this.copy();
boolean flag = this.getUseDuration(user) <= 0; boolean flag = this.getUseDuration(user) <= 0;
InteractionResult enuminteractionresult = this.getItem().use(world, user, hand); InteractionResult enuminteractionresult = this.getItem().use(world, user, hand);
@@ -492,7 +698,22 @@ @@ -492,7 +699,22 @@
public void hurtAndBreak(int amount, ServerLevel world, @Nullable ServerPlayer player, Consumer<Item> breakCallback) { public void hurtAndBreak(int amount, ServerLevel world, @Nullable ServerPlayer player, Consumer<Item> breakCallback) {
int j = this.processDurabilityChange(amount, world, player); int j = this.processDurabilityChange(amount, world, player);
@ -371,7 +372,7 @@
if (j != 0) { if (j != 0) {
this.applyDamage(this.getDamageValue() + j, player, breakCallback); this.applyDamage(this.getDamageValue() + j, player, breakCallback);
} }
@@ -511,6 +732,11 @@ @@ -511,6 +733,11 @@
this.setDamageValue(damage); this.setDamageValue(damage);
if (this.isBroken()) { if (this.isBroken()) {
Item item = this.getItem(); Item item = this.getItem();
@ -383,7 +384,7 @@
this.shrink(1); this.shrink(1);
breakCallback.accept(item); breakCallback.accept(item);
@@ -518,7 +744,7 @@ @@ -518,7 +745,7 @@
} }
@ -392,7 +393,7 @@
if (player instanceof ServerPlayer entityplayer) { if (player instanceof ServerPlayer entityplayer) {
int j = this.processDurabilityChange(amount, entityplayer.serverLevel(), entityplayer); int j = this.processDurabilityChange(amount, entityplayer.serverLevel(), entityplayer);
@@ -580,11 +806,11 @@ @@ -580,11 +807,11 @@
return this.getItem().getBarColor(this); return this.getItem().getBarColor(this);
} }
@ -406,7 +407,7 @@
return this.getItem().overrideOtherStackedOnMe(this, stack, slot, clickType, player, cursorStackReference); return this.getItem().overrideOtherStackedOnMe(this, stack, slot, clickType, player, cursorStackReference);
} }
@@ -592,8 +818,8 @@ @@ -592,8 +819,8 @@
Item item = this.getItem(); Item item = this.getItem();
if (item.hurtEnemy(this, target, user)) { if (item.hurtEnemy(this, target, user)) {
@ -417,7 +418,7 @@
entityhuman.awardStat(Stats.ITEM_USED.get(item)); entityhuman.awardStat(Stats.ITEM_USED.get(item));
} }
@@ -608,7 +834,7 @@ @@ -608,7 +835,7 @@
this.getItem().postHurtEnemy(this, target, user); this.getItem().postHurtEnemy(this, target, user);
} }
@ -426,7 +427,7 @@
Item item = this.getItem(); Item item = this.getItem();
if (item.mineBlock(this, world, state, pos, miner)) { if (item.mineBlock(this, world, state, pos, miner)) {
@@ -617,11 +843,11 @@ @@ -617,11 +844,11 @@
} }
@ -440,7 +441,7 @@
return this.getItem().interactLivingEntity(this, user, entity, hand); return this.getItem().interactLivingEntity(this, user, entity, hand);
} }
@@ -736,7 +962,7 @@ @@ -736,7 +963,7 @@
} }
@ -449,7 +450,7 @@
player.awardStat(Stats.ITEM_CRAFTED.get(this.getItem()), amount); player.awardStat(Stats.ITEM_CRAFTED.get(this.getItem()), amount);
this.getItem().onCraftedBy(this, world, player); this.getItem().onCraftedBy(this, world, player);
} }
@@ -768,7 +994,13 @@ @@ -768,7 +995,13 @@
public boolean useOnRelease() { public boolean useOnRelease() {
return this.getItem().useOnRelease(this); return this.getItem().useOnRelease(this);
@ -463,7 +464,7 @@
@Nullable @Nullable
public <T> T set(DataComponentType<? super T> type, @Nullable T value) { public <T> T set(DataComponentType<? super T> type, @Nullable T value) {
@@ -806,6 +1038,25 @@ @@ -806,6 +1039,25 @@
} }
} }
@ -489,7 +490,7 @@
public void applyComponents(DataComponentPatch changes) { public void applyComponents(DataComponentPatch changes) {
this.components.applyPatch(changes); this.components.applyPatch(changes);
this.getItem().verifyComponentsAfterLoad(this); this.getItem().verifyComponentsAfterLoad(this);
@@ -858,7 +1109,7 @@ @@ -858,7 +1110,7 @@
} }
private <T extends TooltipProvider> void addToTooltip(DataComponentType<T> componentType, Item.TooltipContext context, Consumer<Component> textConsumer, TooltipFlag type) { private <T extends TooltipProvider> void addToTooltip(DataComponentType<T> componentType, Item.TooltipContext context, Consumer<Component> textConsumer, TooltipFlag type) {
@ -498,7 +499,7 @@
if (t0 != null) { if (t0 != null) {
t0.addToTooltip(context, textConsumer, type); t0.addToTooltip(context, textConsumer, type);
@@ -866,7 +1117,7 @@ @@ -866,7 +1118,7 @@
} }
@ -507,7 +508,7 @@
boolean flag = this.getItem().shouldPrintOpWarning(this, player); boolean flag = this.getItem().shouldPrintOpWarning(this, player);
if (!type.isCreative() && this.has(DataComponents.HIDE_TOOLTIP)) { if (!type.isCreative() && this.has(DataComponents.HIDE_TOOLTIP)) {
@@ -941,7 +1192,7 @@ @@ -941,7 +1193,7 @@
} }
} }
@ -516,7 +517,7 @@
ItemAttributeModifiers itemattributemodifiers = (ItemAttributeModifiers) this.getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY); ItemAttributeModifiers itemattributemodifiers = (ItemAttributeModifiers) this.getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY);
if (itemattributemodifiers.showInTooltip()) { if (itemattributemodifiers.showInTooltip()) {
@@ -966,7 +1217,7 @@ @@ -966,7 +1218,7 @@
} }
} }
@ -525,7 +526,7 @@
double d0 = modifier.amount(); double d0 = modifier.amount();
boolean flag = false; boolean flag = false;
@@ -1091,6 +1342,14 @@ @@ -1091,6 +1343,14 @@
EnchantmentHelper.forEachModifier(this, slot, attributeModifierConsumer); EnchantmentHelper.forEachModifier(this, slot, attributeModifierConsumer);
} }
@ -540,7 +541,7 @@
public Component getDisplayName() { public Component getDisplayName() {
MutableComponent ichatmutablecomponent = Component.empty().append(this.getHoverName()); MutableComponent ichatmutablecomponent = Component.empty().append(this.getHoverName());
@@ -1153,7 +1412,7 @@ @@ -1153,7 +1413,7 @@
} }
public void consume(int amount, @Nullable LivingEntity entity) { public void consume(int amount, @Nullable LivingEntity entity) {

View file

@ -5,7 +5,7 @@
public static final BlockEntityType<TrialSpawnerBlockEntity> TRIAL_SPAWNER = BlockEntityType.register("trial_spawner", TrialSpawnerBlockEntity::new, Blocks.TRIAL_SPAWNER); public static final BlockEntityType<TrialSpawnerBlockEntity> TRIAL_SPAWNER = BlockEntityType.register("trial_spawner", TrialSpawnerBlockEntity::new, Blocks.TRIAL_SPAWNER);
public static final BlockEntityType<VaultBlockEntity> VAULT = BlockEntityType.register("vault", VaultBlockEntity::new, Blocks.VAULT); public static final BlockEntityType<VaultBlockEntity> VAULT = BlockEntityType.register("vault", VaultBlockEntity::new, Blocks.VAULT);
- private static final Set<BlockEntityType<?>> OP_ONLY_CUSTOM_DATA = Set.of(BlockEntityType.COMMAND_BLOCK, BlockEntityType.LECTERN, BlockEntityType.SIGN, BlockEntityType.HANGING_SIGN, BlockEntityType.MOB_SPAWNER, BlockEntityType.TRIAL_SPAWNER); - private static final Set<BlockEntityType<?>> OP_ONLY_CUSTOM_DATA = Set.of(BlockEntityType.COMMAND_BLOCK, BlockEntityType.LECTERN, BlockEntityType.SIGN, BlockEntityType.HANGING_SIGN, BlockEntityType.MOB_SPAWNER, BlockEntityType.TRIAL_SPAWNER);
+ private static final Set<BlockEntityType<?>> OP_ONLY_CUSTOM_DATA = Set.of(BlockEntityType.COMMAND_BLOCK, BlockEntityType.LECTERN, BlockEntityType.SIGN, BlockEntityType.HANGING_SIGN, BlockEntityType.MOB_SPAWNER, BlockEntityType.TRIAL_SPAWNER, BlockEntityType.CHEST); // CraftBukkit + private static final Set<BlockEntityType<?>> OP_ONLY_CUSTOM_DATA = Set.of(BlockEntityType.COMMAND_BLOCK, BlockEntityType.LECTERN, BlockEntityType.SIGN, BlockEntityType.HANGING_SIGN, BlockEntityType.MOB_SPAWNER, BlockEntityType.TRIAL_SPAWNER); // CraftBukkit // Paper - Allow chests to be placed with NBT data
private final BlockEntityType.BlockEntitySupplier<? extends T> factory; private final BlockEntityType.BlockEntitySupplier<? extends T> factory;
public final Set<Block> validBlocks; public final Set<Block> validBlocks;
private final Holder.Reference<BlockEntityType<?>> builtInRegistryHolder; private final Holder.Reference<BlockEntityType<?>> builtInRegistryHolder;