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) {
@ -169,7 +169,7 @@
+ DataComponentPatch oldData = this.components.asPatch();
+ int oldCount = this.getCount();
+ ServerLevel world = (ServerLevel) context.getLevel();
+
+ if (!(item instanceof BucketItem || item instanceof SolidBucketItem)) { // if not bucket
+ world.captureBlockStates = true;
+ // special case bonemeal
@ -200,7 +200,7 @@
+ structureEvent = new StructureGrowEvent(location, treeType, isBonemeal, (Player) entityhuman.getBukkitEntity(), (List< BlockState>) (List<? extends BlockState>) blocks);
+ org.bukkit.Bukkit.getPluginManager().callEvent(structureEvent);
+ }
+
+ BlockFertilizeEvent fertilizeEvent = new BlockFertilizeEvent(CraftBlock.at(world, blockposition), (Player) entityhuman.getBukkitEntity(), (List< BlockState>) (List<? extends BlockState>) blocks);
+ fertilizeEvent.setCancelled(structureEvent != null && structureEvent.isCancelled());
+ org.bukkit.Bukkit.getPluginManager().callEvent(fertilizeEvent);
@ -242,6 +242,7 @@
+ enuminteractionresult = InteractionResult.FAIL; // cancel placement
+ // PAIL: Remove this when MC-99075 fixed
+ 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
+ world.preventPoiUpdated = true; // CraftBukkit - SPIGOT-5710
+ for (BlockState blockstate : blocks) {
@ -348,7 +349,7 @@
ItemStack itemstack = this.copy();
boolean flag = this.getUseDuration(user) <= 0;
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) {
int j = this.processDurabilityChange(amount, world, player);
@ -371,7 +372,7 @@
if (j != 0) {
this.applyDamage(this.getDamageValue() + j, player, breakCallback);
}
@@ -511,6 +732,11 @@
@@ -511,6 +733,11 @@
this.setDamageValue(damage);
if (this.isBroken()) {
Item item = this.getItem();
@ -383,7 +384,7 @@
this.shrink(1);
breakCallback.accept(item);
@@ -518,7 +744,7 @@
@@ -518,7 +745,7 @@
}
@ -392,7 +393,7 @@
if (player instanceof ServerPlayer entityplayer) {
int j = this.processDurabilityChange(amount, entityplayer.serverLevel(), entityplayer);
@@ -580,11 +806,11 @@
@@ -580,11 +807,11 @@
return this.getItem().getBarColor(this);
}
@ -406,7 +407,7 @@
return this.getItem().overrideOtherStackedOnMe(this, stack, slot, clickType, player, cursorStackReference);
}
@@ -592,8 +818,8 @@
@@ -592,8 +819,8 @@
Item item = this.getItem();
if (item.hurtEnemy(this, target, user)) {
@ -417,7 +418,7 @@
entityhuman.awardStat(Stats.ITEM_USED.get(item));
}
@@ -608,7 +834,7 @@
@@ -608,7 +835,7 @@
this.getItem().postHurtEnemy(this, target, user);
}
@ -426,7 +427,7 @@
Item item = this.getItem();
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);
}
@@ -736,7 +962,7 @@
@@ -736,7 +963,7 @@
}
@ -449,7 +450,7 @@
player.awardStat(Stats.ITEM_CRAFTED.get(this.getItem()), amount);
this.getItem().onCraftedBy(this, world, player);
}
@@ -768,7 +994,13 @@
@@ -768,7 +995,13 @@
public boolean useOnRelease() {
return this.getItem().useOnRelease(this);
@ -463,7 +464,7 @@
@Nullable
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) {
this.components.applyPatch(changes);
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) {
@ -498,7 +499,7 @@
if (t0 != null) {
t0.addToTooltip(context, textConsumer, type);
@@ -866,7 +1117,7 @@
@@ -866,7 +1118,7 @@
}
@ -507,7 +508,7 @@
boolean flag = this.getItem().shouldPrintOpWarning(this, player);
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);
if (itemattributemodifiers.showInTooltip()) {
@@ -966,7 +1217,7 @@
@@ -966,7 +1218,7 @@
}
}
@ -525,7 +526,7 @@
double d0 = modifier.amount();
boolean flag = false;
@@ -1091,6 +1342,14 @@
@@ -1091,6 +1343,14 @@
EnchantmentHelper.forEachModifier(this, slot, attributeModifierConsumer);
}
@ -540,7 +541,7 @@
public Component getDisplayName() {
MutableComponent ichatmutablecomponent = Component.empty().append(this.getHoverName());
@@ -1153,7 +1412,7 @@
@@ -1153,7 +1413,7 @@
}
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<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, 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;
public final Set<Block> validBlocks;
private final Holder.Reference<BlockEntityType<?>> builtInRegistryHolder;