Only capture actual tree growth

This commit is contained in:
Jake Potrebic 2021-08-21 18:53:03 -07:00
parent 1754e3426c
commit 36ae0bcfea
5 changed files with 58 additions and 43 deletions

View file

@ -285,10 +285,11 @@
return this.consumeWithRemainder(pointer, stack, new ItemStack(item));
}
} else {
@@ -249,16 +436,44 @@
@@ -248,6 +435,30 @@
@Override
protected ItemStack execute(BlockSource pointer, ItemStack stack) {
ServerLevel worldserver = pointer.level();
+
+ // CraftBukkit start
+ org.bukkit.block.Block bukkitBlock = CraftBlock.at(worldserver, pointer.pos());
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack);
@ -312,10 +313,10 @@
+ }
+ }
+ // CraftBukkit end
+
this.setSuccess(true);
Direction enumdirection = (Direction) pointer.state().getValue(DispenserBlock.FACING);
BlockPos blockposition = pointer.pos().relative(enumdirection);
@@ -255,10 +466,14 @@
BlockState iblockdata = worldserver.getBlockState(blockposition);
if (BaseFireBlock.canBePlacedAt(worldserver, blockposition, enumdirection)) {
@ -333,7 +334,7 @@
TntBlock.explode(worldserver, blockposition);
worldserver.removeBlock(blockposition, false);
} else {
@@ -283,13 +498,63 @@
@@ -283,13 +498,64 @@
this.setSuccess(true);
ServerLevel worldserver = pointer.level();
BlockPos blockposition = pointer.pos().relative((Direction) pointer.state().getValue(DispenserBlock.FACING));
@ -389,6 +390,7 @@
+ if (!fertilizeEvent.isCancelled()) {
+ for (org.bukkit.block.BlockState blockstate : blocks) {
+ blockstate.update(true);
+ worldserver.checkCapturedTreeStateForObserverNotify(blockposition, (org.bukkit.craftbukkit.block.CraftBlockState) blockstate); // Paper - notify observers even if grow failed
+ }
+ }
+ }
@ -397,7 +399,7 @@
return stack;
}
});
@@ -298,12 +563,41 @@
@@ -298,12 +564,41 @@
protected ItemStack execute(BlockSource pointer, ItemStack stack) {
ServerLevel worldserver = pointer.level();
BlockPos blockposition = pointer.pos().relative((Direction) pointer.state().getValue(DispenserBlock.FACING));
@ -441,7 +443,7 @@
return stack;
}
});
@@ -313,7 +607,31 @@
@@ -313,7 +608,31 @@
ServerLevel worldserver = pointer.level();
Direction enumdirection = (Direction) pointer.state().getValue(DispenserBlock.FACING);
BlockPos blockposition = pointer.pos().relative(enumdirection);
@ -473,7 +475,7 @@
if (worldserver.isEmptyBlock(blockposition) && WitherSkullBlock.canSpawnMob(worldserver, blockposition, stack)) {
worldserver.setBlock(blockposition, (BlockState) Blocks.WITHER_SKELETON_SKULL.defaultBlockState().setValue(SkullBlock.ROTATION, RotationSegment.convertToSegment(enumdirection)), 3);
worldserver.gameEvent((Entity) null, (Holder) GameEvent.BLOCK_PLACE, blockposition);
@@ -339,6 +657,30 @@
@@ -339,6 +658,30 @@
BlockPos blockposition = pointer.pos().relative((Direction) pointer.state().getValue(DispenserBlock.FACING));
CarvedPumpkinBlock blockpumpkincarved = (CarvedPumpkinBlock) Blocks.CARVED_PUMPKIN;
@ -504,7 +506,7 @@
if (worldserver.isEmptyBlock(blockposition) && blockpumpkincarved.canSpawnGolem(worldserver, blockposition)) {
if (!worldserver.isClientSide) {
worldserver.setBlock(blockposition, blockpumpkincarved.defaultBlockState(), 3);
@@ -377,6 +719,30 @@
@@ -377,6 +720,30 @@
BlockPos blockposition = pointer.pos().relative((Direction) pointer.state().getValue(DispenserBlock.FACING));
BlockState iblockdata = worldserver.getBlockState(blockposition);
@ -535,7 +537,7 @@
if (iblockdata.is(BlockTags.BEEHIVES, (blockbase_blockdata) -> {
return blockbase_blockdata.hasProperty(BeehiveBlock.HONEY_LEVEL) && blockbase_blockdata.getBlock() instanceof BeehiveBlock;
}) && (Integer) iblockdata.getValue(BeehiveBlock.HONEY_LEVEL) >= 5) {
@@ -402,6 +768,13 @@
@@ -402,6 +769,13 @@
this.setSuccess(true);
if (iblockdata.is(Blocks.RESPAWN_ANCHOR)) {
if ((Integer) iblockdata.getValue(RespawnAnchorBlock.CHARGE) != 4) {
@ -549,7 +551,7 @@
RespawnAnchorBlock.charge((Entity) null, worldserver, blockposition, iblockdata);
stack.shrink(1);
} else {
@@ -426,6 +799,31 @@
@@ -426,6 +800,31 @@
this.setSuccess(false);
return stack;
} else {
@ -581,7 +583,7 @@
Iterator iterator1 = list.iterator();
Armadillo armadillo;
@@ -454,6 +852,13 @@
@@ -454,6 +853,13 @@
Optional<BlockState> optional = HoneycombItem.getWaxed(iblockdata);
if (optional.isPresent()) {
@ -595,7 +597,7 @@
worldserver.setBlockAndUpdate(blockposition, (BlockState) optional.get());
worldserver.levelEvent(3003, blockposition, 0);
stack.shrink(1);
@@ -481,6 +886,12 @@
@@ -481,6 +887,12 @@
if (!worldserver.getBlockState(blockposition1).is(BlockTags.CONVERTABLE_TO_MUD)) {
return this.defaultDispenseItemBehavior.dispense(pointer, stack);
} else {

View file

@ -97,7 +97,7 @@
+ // be more strict too, add a block (dumb plugins in move events?)
+ int minBlockX = Mth.floor(axisalignedbb.minX - 1.0E-7D) - 3;
+ int maxBlockX = Mth.floor(axisalignedbb.maxX + 1.0E-7D) + 3;
+
+ int minBlockZ = Mth.floor(axisalignedbb.minZ - 1.0E-7D) - 3;
+ int maxBlockZ = Mth.floor(axisalignedbb.maxZ + 1.0E-7D) + 3;
+
@ -227,7 +227,7 @@
+ boolean flag2 = minecraftserver.forceSynchronousWrites();
+ DataFixer datafixer = minecraftserver.getFixerUpper();
+ EntityPersistentStorage<Entity> entitypersistentstorage = new EntityStorage(new SimpleRegionStorage(new RegionStorageInfo(convertable_conversionsession.getLevelId(), resourcekey, "entities"), convertable_conversionsession.getDimensionPath(resourcekey).resolve("entities"), datafixer, flag2, DataFixTypes.ENTITY_CHUNK), this, minecraftserver);
+
this.entityManager = new PersistentEntitySectionManager<>(Entity.class, new ServerLevel.EntityCallbacks(), entitypersistentstorage);
- StructureTemplateManager structuretemplatemanager = server.getStructureManager();
- int j = server.getPlayerList().getViewDistance();
@ -1039,7 +1039,7 @@
return this.entityManager.getEntityGetter();
}
@@ -1802,6 +2203,17 @@
@@ -1802,6 +2203,27 @@
return this.serverLevelData.getGameRules();
}
@ -1053,11 +1053,21 @@
+ return range <= 0 ? 64.0 * 64.0 : range * range; // 64 is taken from default in ServerLevel#levelEvent
+ }
+ // Paper end - respect global sound events gamerule
+ // Paper start - notify observers even if grow failed
+ public void checkCapturedTreeStateForObserverNotify(final BlockPos pos, final org.bukkit.craftbukkit.block.CraftBlockState craftBlockState) {
+ // notify observers if the block state is the same and the Y level equals the original y level (for mega trees)
+ // blocks at the same Y level with the same state can be assumed to be saplings which trigger observers regardless of if the
+ // tree grew or not
+ if (craftBlockState.getPosition().getY() == pos.getY() && this.getBlockState(craftBlockState.getPosition()) == craftBlockState.getHandle()) {
+ this.notifyAndUpdatePhysics(craftBlockState.getPosition(), null, craftBlockState.getHandle(), craftBlockState.getHandle(), craftBlockState.getHandle(), craftBlockState.getFlag(), 512);
+ }
+ }
+ // Paper end - notify observers even if grow failed
+
@Override
public CrashReportCategory fillReportDetails(CrashReport report) {
CrashReportCategory crashreportsystemdetails = super.fillReportDetails(report);
@@ -1828,6 +2240,7 @@
@@ -1828,6 +2250,7 @@
}
public void onTickingStart(Entity entity) {
@ -1065,7 +1075,7 @@
ServerLevel.this.entityTickList.add(entity);
}
@@ -1836,14 +2249,15 @@
@@ -1836,14 +2259,15 @@
}
public void onTrackingStart(Entity entity) {
@ -1083,7 +1093,7 @@
String s = "onTrackingStart called during navigation iteration";
Util.logAndPauseIfInIde("onTrackingStart called during navigation iteration", new IllegalStateException("onTrackingStart called during navigation iteration"));
@@ -1864,9 +2278,58 @@
@@ -1864,9 +2288,58 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
@ -1142,7 +1152,7 @@
ServerLevel.this.getChunkSource().removeEntity(entity);
if (entity instanceof ServerPlayer entityplayer) {
ServerLevel.this.players.remove(entityplayer);
@@ -1874,7 +2337,7 @@
@@ -1874,7 +2347,7 @@
}
if (entity instanceof Mob entityinsentient) {
@ -1151,7 +1161,7 @@
String s = "onTrackingStart called during navigation iteration";
Util.logAndPauseIfInIde("onTrackingStart called during navigation iteration", new IllegalStateException("onTrackingStart called during navigation iteration"));
@@ -1895,10 +2358,27 @@
@@ -1895,10 +2368,27 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::remove);

View file

@ -152,7 +152,7 @@
});
}
}
@@ -370,32 +418,195 @@
@@ -370,32 +418,196 @@
}
public InteractionResult useOn(UseOnContext context) {
@ -214,6 +214,7 @@
+ for (CraftBlockState blockstate : blocks) {
+ // SPIGOT-7572 - Move fix for SPIGOT-7248 to CapturedBlockState, to allow bees in bee nest
+ CapturedBlockState.setBlockState(blockstate);
+ world.checkCapturedTreeStateForObserverNotify(blockposition, blockstate); // Paper - notify observers even if grow failed
+ }
+ entityhuman.awardStat(Stats.ITEM_USED.get(item)); // SPIGOT-7236 - award stat
+ }
@ -353,7 +354,7 @@
ItemStack itemstack = this.copy();
boolean flag = this.getUseDuration(user) <= 0;
InteractionResult enuminteractionresult = this.getItem().use(world, user, hand);
@@ -490,27 +701,66 @@
@@ -490,8 +702,37 @@
return this.isDamageableItem() && this.getDamageValue() >= this.getMaxDamage() - 1;
}
@ -371,7 +372,7 @@
+ if (player instanceof final ServerPlayer serverPlayer) { // Paper - Add EntityDamageItemEvent
+ PlayerItemDamageEvent event = new PlayerItemDamageEvent(serverPlayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), j, originalDamage); // Paper - Add EntityDamageItemEvent
+ event.getPlayer().getServer().getPluginManager().callEvent(event);
+
+ if (j != event.getDamage() || event.isCancelled()) {
+ event.getPlayer().updateInventory();
+ }
@ -390,10 +391,10 @@
+ // Paper end - Add EntityDamageItemEvent
+ }
+ // CraftBukkit end
+
if (j != 0) {
this.applyDamage(this.getDamageValue() + j, player, breakCallback);
}
@@ -499,18 +740,28 @@
}
@ -427,7 +428,7 @@
this.shrink(1);
breakCallback.accept(item);
@@ -518,7 +768,7 @@
@@ -518,7 +769,7 @@
}
@ -436,7 +437,7 @@
if (player instanceof ServerPlayer entityplayer) {
int j = this.processDurabilityChange(amount, entityplayer.serverLevel(), entityplayer);
@@ -535,6 +785,11 @@
@@ -535,6 +786,11 @@
}
public void hurtAndBreak(int amount, LivingEntity entity, EquipmentSlot slot) {
@ -448,7 +449,7 @@
Level world = entity.level();
if (world instanceof ServerLevel worldserver) {
@@ -546,9 +801,9 @@
@@ -546,9 +802,9 @@
entityplayer = null;
}
@ -461,7 +462,7 @@
}
}
@@ -580,11 +835,11 @@
@@ -580,11 +836,11 @@
return this.getItem().getBarColor(this);
}
@ -475,7 +476,7 @@
return this.getItem().overrideOtherStackedOnMe(this, stack, slot, clickType, player, cursorStackReference);
}
@@ -592,8 +847,8 @@
@@ -592,8 +848,8 @@
Item item = this.getItem();
if (item.hurtEnemy(this, target, user)) {
@ -486,7 +487,7 @@
entityhuman.awardStat(Stats.ITEM_USED.get(item));
}
@@ -608,7 +863,7 @@
@@ -608,7 +864,7 @@
this.getItem().postHurtEnemy(this, target, user);
}
@ -495,7 +496,7 @@
Item item = this.getItem();
if (item.mineBlock(this, world, state, pos, miner)) {
@@ -617,11 +872,11 @@
@@ -617,11 +873,11 @@
}
@ -509,7 +510,7 @@
return this.getItem().interactLivingEntity(this, user, entity, hand);
}
@@ -736,7 +991,7 @@
@@ -736,7 +992,7 @@
}
@ -518,7 +519,7 @@
player.awardStat(Stats.ITEM_CRAFTED.get(this.getItem()), amount);
this.getItem().onCraftedBy(this, world, player);
}
@@ -770,6 +1025,12 @@
@@ -770,6 +1026,12 @@
return this.getItem().useOnRelease(this);
}
@ -531,7 +532,7 @@
@Nullable
public <T> T set(DataComponentType<? super T> type, @Nullable T value) {
return this.components.set(type, value);
@@ -806,6 +1067,25 @@
@@ -806,6 +1068,25 @@
}
}
@ -557,7 +558,7 @@
public void applyComponents(DataComponentPatch changes) {
this.components.applyPatch(changes);
this.getItem().verifyComponentsAfterLoad(this);
@@ -858,7 +1138,7 @@
@@ -858,7 +1139,7 @@
}
private <T extends TooltipProvider> void addToTooltip(DataComponentType<T> componentType, Item.TooltipContext context, Consumer<Component> textConsumer, TooltipFlag type) {
@ -566,7 +567,7 @@
if (t0 != null) {
t0.addToTooltip(context, textConsumer, type);
@@ -866,7 +1146,7 @@
@@ -866,7 +1147,7 @@
}
@ -575,7 +576,7 @@
boolean flag = this.getItem().shouldPrintOpWarning(this, player);
if (!type.isCreative() && this.has(DataComponents.HIDE_TOOLTIP)) {
@@ -941,7 +1221,7 @@
@@ -941,7 +1222,7 @@
}
}
@ -584,7 +585,7 @@
ItemAttributeModifiers itemattributemodifiers = (ItemAttributeModifiers) this.getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY);
if (itemattributemodifiers.showInTooltip()) {
@@ -966,7 +1246,7 @@
@@ -966,7 +1247,7 @@
}
}
@ -593,7 +594,7 @@
double d0 = modifier.amount();
boolean flag = false;
@@ -1091,6 +1371,14 @@
@@ -1091,6 +1372,14 @@
EnchantmentHelper.forEachModifier(this, slot, attributeModifierConsumer);
}
@ -608,7 +609,7 @@
public Component getDisplayName() {
MutableComponent ichatmutablecomponent = Component.empty().append(this.getHoverName());
@@ -1153,7 +1441,7 @@
@@ -1153,7 +1442,7 @@
}
public void consume(int amount, @Nullable LivingEntity entity) {

View file

@ -29,7 +29,7 @@
@Override
public MapCodec<? extends SaplingBlock> codec() {
@@ -37,48 +45,73 @@
@@ -37,48 +45,74 @@
protected SaplingBlock(TreeGrower generator, BlockBehaviour.Properties settings) {
super(settings);
this.treeGrower = generator;
@ -81,6 +81,7 @@
+ if (event == null || !event.isCancelled()) {
+ for (BlockState blockstate : blocks) {
+ CapturedBlockState.setBlockState(blockstate);
+ world.checkCapturedTreeStateForObserverNotify(pos, (org.bukkit.craftbukkit.block.CraftBlockState) blockstate); // Paper - notify observers even if grow failed
+ }
+ }
+ }

View file

@ -572,6 +572,7 @@ public class CraftBlock implements Block {
if (!event.isCancelled()) {
for (BlockState blockstate : blocks) {
blockstate.update(true);
world.checkCapturedTreeStateForObserverNotify(this.position, (org.bukkit.craftbukkit.block.CraftBlockState) blockstate); // Paper - notify observers even if grow failed
}
}
}