mirror of
https://github.com/PaperMC/Paper.git
synced 2025-07-26 09:42:06 -07:00
Extend block drop capture to capture all items added to the world
This commit is contained in:
@@ -79,7 +79,7 @@
|
|||||||
+ public final LevelStorageSource.LevelStorageAccess convertable;
|
+ public final LevelStorageSource.LevelStorageAccess convertable;
|
||||||
+ public final UUID uuid;
|
+ public final UUID uuid;
|
||||||
+ public boolean hasPhysicsEvent = true; // Paper - BlockPhysicsEvent
|
+ public boolean hasPhysicsEvent = true; // Paper - BlockPhysicsEvent
|
||||||
+
|
|
||||||
+ public LevelChunk getChunkIfLoaded(int x, int z) {
|
+ public LevelChunk getChunkIfLoaded(int x, int z) {
|
||||||
+ return this.chunkSource.getChunk(x, z, false);
|
+ return this.chunkSource.getChunk(x, z, false);
|
||||||
+ }
|
+ }
|
||||||
@@ -218,7 +218,7 @@
|
|||||||
+ chunkgenerator = new FlatLevelSource(cpf.settings(), worldChunkManager);
|
+ chunkgenerator = new FlatLevelSource(cpf.settings(), worldChunkManager);
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
|
+
|
||||||
+ if (gen != null) {
|
+ if (gen != null) {
|
||||||
+ chunkgenerator = new org.bukkit.craftbukkit.generator.CustomChunkGenerator(this, chunkgenerator, gen);
|
+ chunkgenerator = new org.bukkit.craftbukkit.generator.CustomChunkGenerator(this, chunkgenerator, gen);
|
||||||
+ }
|
+ }
|
||||||
@@ -586,7 +586,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -939,41 +1185,93 @@
|
@@ -939,41 +1185,99 @@
|
||||||
this.entityManager.addNewEntity(player);
|
this.entityManager.addNewEntity(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -606,6 +606,12 @@
|
|||||||
+ // WorldServer.LOGGER.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getKey(entity.getType())); // CraftBukkit
|
+ // WorldServer.LOGGER.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getKey(entity.getType())); // CraftBukkit
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
+ // Paper start - capture all item additions to the world
|
||||||
|
+ if (captureDrops != null && entity instanceof net.minecraft.world.entity.item.ItemEntity) {
|
||||||
|
+ captureDrops.add((net.minecraft.world.entity.item.ItemEntity) entity);
|
||||||
|
+ return true;
|
||||||
|
+ }
|
||||||
|
+ // Paper end - capture all item additions to the world
|
||||||
+ // SPIGOT-6415: Don't call spawn event when reason is null. For example when an entity teleports to a new world.
|
+ // SPIGOT-6415: Don't call spawn event when reason is null. For example when an entity teleports to a new world.
|
||||||
+ if (spawnReason != null && !CraftEventFactory.doEntityAddEventCalling(this, entity, spawnReason)) {
|
+ if (spawnReason != null && !CraftEventFactory.doEntityAddEventCalling(this, entity, spawnReason)) {
|
||||||
+ return false;
|
+ return false;
|
||||||
@@ -685,7 +691,7 @@
|
|||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
|
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
|
||||||
|
|
||||||
@@ -982,6 +1280,12 @@
|
@@ -982,6 +1286,12 @@
|
||||||
double d1 = (double) pos.getY() - entityplayer.getY();
|
double d1 = (double) pos.getY() - entityplayer.getY();
|
||||||
double d2 = (double) pos.getZ() - entityplayer.getZ();
|
double d2 = (double) pos.getZ() - entityplayer.getZ();
|
||||||
|
|
||||||
@@ -698,7 +704,7 @@
|
|||||||
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
|
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
|
||||||
entityplayer.connection.send(new ClientboundBlockDestructionPacket(entityId, pos, progress));
|
entityplayer.connection.send(new ClientboundBlockDestructionPacket(entityId, pos, progress));
|
||||||
}
|
}
|
||||||
@@ -1030,7 +1334,7 @@
|
@@ -1030,7 +1340,7 @@
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void levelEvent(@Nullable Player player, int eventId, BlockPos pos, int data) {
|
public void levelEvent(@Nullable Player player, int eventId, BlockPos pos, int data) {
|
||||||
@@ -707,7 +713,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getLogicalHeight() {
|
public int getLogicalHeight() {
|
||||||
@@ -1060,7 +1364,18 @@
|
@@ -1060,7 +1370,18 @@
|
||||||
Iterator iterator = this.navigatingMobs.iterator();
|
Iterator iterator = this.navigatingMobs.iterator();
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
@@ -727,7 +733,7 @@
|
|||||||
PathNavigation navigationabstract = entityinsentient.getNavigation();
|
PathNavigation navigationabstract = entityinsentient.getNavigation();
|
||||||
|
|
||||||
if (navigationabstract.shouldRecomputePath(pos)) {
|
if (navigationabstract.shouldRecomputePath(pos)) {
|
||||||
@@ -1086,11 +1401,13 @@
|
@@ -1086,11 +1407,13 @@
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateNeighborsAt(BlockPos pos, Block block) {
|
public void updateNeighborsAt(BlockPos pos, Block block) {
|
||||||
@@ -741,7 +747,7 @@
|
|||||||
this.neighborUpdater.updateNeighborsAtExceptFromFacing(pos, sourceBlock, (Direction) null, orientation);
|
this.neighborUpdater.updateNeighborsAtExceptFromFacing(pos, sourceBlock, (Direction) null, orientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1126,9 +1443,20 @@
|
@@ -1126,9 +1449,20 @@
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void explode(@Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, double x, double y, double z, float power, boolean createFire, Level.ExplosionInteraction explosionSourceType, ParticleOptions smallParticle, ParticleOptions largeParticle, Holder<SoundEvent> soundEvent) {
|
public void explode(@Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, double x, double y, double z, float power, boolean createFire, Level.ExplosionInteraction explosionSourceType, ParticleOptions smallParticle, ParticleOptions largeParticle, Holder<SoundEvent> soundEvent) {
|
||||||
@@ -763,7 +769,7 @@
|
|||||||
case NONE:
|
case NONE:
|
||||||
explosion_effect = Explosion.BlockInteraction.KEEP;
|
explosion_effect = Explosion.BlockInteraction.KEEP;
|
||||||
break;
|
break;
|
||||||
@@ -1144,16 +1472,27 @@
|
@@ -1144,16 +1478,27 @@
|
||||||
case TRIGGER:
|
case TRIGGER:
|
||||||
explosion_effect = Explosion.BlockInteraction.TRIGGER_BLOCK;
|
explosion_effect = Explosion.BlockInteraction.TRIGGER_BLOCK;
|
||||||
break;
|
break;
|
||||||
@@ -794,7 +800,7 @@
|
|||||||
Iterator iterator = this.players.iterator();
|
Iterator iterator = this.players.iterator();
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
@@ -1162,10 +1501,11 @@
|
@@ -1162,10 +1507,11 @@
|
||||||
if (entityplayer.distanceToSqr(vec3d) < 4096.0D) {
|
if (entityplayer.distanceToSqr(vec3d) < 4096.0D) {
|
||||||
Optional<Vec3> optional = Optional.ofNullable((Vec3) serverexplosion.getHitPlayers().get(entityplayer));
|
Optional<Vec3> optional = Optional.ofNullable((Vec3) serverexplosion.getHitPlayers().get(entityplayer));
|
||||||
|
|
||||||
@@ -807,7 +813,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Explosion.BlockInteraction getDestroyType(GameRules.Key<GameRules.BooleanValue> decayRule) {
|
private Explosion.BlockInteraction getDestroyType(GameRules.Key<GameRules.BooleanValue> decayRule) {
|
||||||
@@ -1226,17 +1566,29 @@
|
@@ -1226,17 +1572,29 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends ParticleOptions> int sendParticles(T parameters, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double speed) {
|
public <T extends ParticleOptions> int sendParticles(T parameters, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double speed) {
|
||||||
@@ -843,7 +849,7 @@
|
|||||||
++j;
|
++j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1292,7 +1644,7 @@
|
@@ -1292,7 +1650,7 @@
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BlockPos findNearestMapStructure(TagKey<Structure> structureTag, BlockPos pos, int radius, boolean skipReferencedStructures) {
|
public BlockPos findNearestMapStructure(TagKey<Structure> structureTag, BlockPos pos, int radius, boolean skipReferencedStructures) {
|
||||||
@@ -852,7 +858,7 @@
|
|||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
Optional<HolderSet.Named<Structure>> optional = this.registryAccess().lookupOrThrow(Registries.STRUCTURE).get(structureTag);
|
Optional<HolderSet.Named<Structure>> optional = this.registryAccess().lookupOrThrow(Registries.STRUCTURE).get(structureTag);
|
||||||
@@ -1334,11 +1686,22 @@
|
@@ -1334,11 +1692,22 @@
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public MapItemSavedData getMapData(MapId id) {
|
public MapItemSavedData getMapData(MapId id) {
|
||||||
@@ -876,7 +882,7 @@
|
|||||||
this.getServer().overworld().getDataStorage().set(id.key(), state);
|
this.getServer().overworld().getDataStorage().set(id.key(), state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1352,7 +1715,9 @@
|
@@ -1352,7 +1721,9 @@
|
||||||
float f1 = this.levelData.getSpawnAngle();
|
float f1 = this.levelData.getSpawnAngle();
|
||||||
|
|
||||||
if (!blockposition1.equals(pos) || f1 != angle) {
|
if (!blockposition1.equals(pos) || f1 != angle) {
|
||||||
@@ -886,7 +892,7 @@
|
|||||||
this.getServer().getPlayerList().broadcastAll(new ClientboundSetDefaultSpawnPositionPacket(pos, angle));
|
this.getServer().getPlayerList().broadcastAll(new ClientboundSetDefaultSpawnPositionPacket(pos, angle));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1649,6 +2014,11 @@
|
@@ -1649,6 +2020,11 @@
|
||||||
@Override
|
@Override
|
||||||
public void blockUpdated(BlockPos pos, Block block) {
|
public void blockUpdated(BlockPos pos, Block block) {
|
||||||
if (!this.isDebug()) {
|
if (!this.isDebug()) {
|
||||||
@@ -898,7 +904,7 @@
|
|||||||
this.updateNeighborsAt(pos, block);
|
this.updateNeighborsAt(pos, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1668,12 +2038,12 @@
|
@@ -1668,12 +2044,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFlat() {
|
public boolean isFlat() {
|
||||||
@@ -913,7 +919,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -1696,7 +2066,7 @@
|
@@ -1696,7 +2072,7 @@
|
||||||
private static <T> String getTypeCount(Iterable<T> items, Function<T, String> classifier) {
|
private static <T> String getTypeCount(Iterable<T> items, Function<T, String> classifier) {
|
||||||
try {
|
try {
|
||||||
Object2IntOpenHashMap<String> object2intopenhashmap = new Object2IntOpenHashMap();
|
Object2IntOpenHashMap<String> object2intopenhashmap = new Object2IntOpenHashMap();
|
||||||
@@ -922,7 +928,7 @@
|
|||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
T t0 = iterator.next();
|
T t0 = iterator.next();
|
||||||
@@ -1705,7 +2075,7 @@
|
@@ -1705,7 +2081,7 @@
|
||||||
object2intopenhashmap.addTo(s, 1);
|
object2intopenhashmap.addTo(s, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -931,7 +937,7 @@
|
|||||||
String s1 = (String) entry.getKey();
|
String s1 = (String) entry.getKey();
|
||||||
|
|
||||||
return s1 + ":" + entry.getIntValue();
|
return s1 + ":" + entry.getIntValue();
|
||||||
@@ -1717,6 +2087,7 @@
|
@@ -1717,6 +2093,7 @@
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LevelEntityGetter<Entity> getEntities() {
|
public LevelEntityGetter<Entity> getEntities() {
|
||||||
@@ -939,7 +945,7 @@
|
|||||||
return this.entityManager.getEntityGetter();
|
return this.entityManager.getEntityGetter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1802,6 +2173,17 @@
|
@@ -1802,6 +2179,17 @@
|
||||||
return this.serverLevelData.getGameRules();
|
return this.serverLevelData.getGameRules();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -957,7 +963,7 @@
|
|||||||
@Override
|
@Override
|
||||||
public CrashReportCategory fillReportDetails(CrashReport report) {
|
public CrashReportCategory fillReportDetails(CrashReport report) {
|
||||||
CrashReportCategory crashreportsystemdetails = super.fillReportDetails(report);
|
CrashReportCategory crashreportsystemdetails = super.fillReportDetails(report);
|
||||||
@@ -1836,7 +2218,8 @@
|
@@ -1836,7 +2224,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onTrackingStart(Entity entity) {
|
public void onTrackingStart(Entity entity) {
|
||||||
@@ -967,7 +973,7 @@
|
|||||||
if (entity instanceof ServerPlayer entityplayer) {
|
if (entity instanceof ServerPlayer entityplayer) {
|
||||||
ServerLevel.this.players.add(entityplayer);
|
ServerLevel.this.players.add(entityplayer);
|
||||||
ServerLevel.this.updateSleepingPlayerList();
|
ServerLevel.this.updateSleepingPlayerList();
|
||||||
@@ -1864,9 +2247,53 @@
|
@@ -1864,9 +2253,53 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
|
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
|
||||||
@@ -1021,7 +1027,7 @@
|
|||||||
ServerLevel.this.getChunkSource().removeEntity(entity);
|
ServerLevel.this.getChunkSource().removeEntity(entity);
|
||||||
if (entity instanceof ServerPlayer entityplayer) {
|
if (entity instanceof ServerPlayer entityplayer) {
|
||||||
ServerLevel.this.players.remove(entityplayer);
|
ServerLevel.this.players.remove(entityplayer);
|
||||||
@@ -1895,6 +2322,15 @@
|
@@ -1895,6 +2328,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
entity.updateDynamicGameEventListener(DynamicGameEventListener::remove);
|
entity.updateDynamicGameEventListener(DynamicGameEventListener::remove);
|
||||||
|
@@ -110,9 +110,9 @@
|
|||||||
+ this.player.connection.send(tileentity.getUpdatePacket());
|
+ this.player.connection.send(tileentity.getUpdatePacket());
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
+ return;
|
return;
|
||||||
+ }
|
}
|
||||||
+
|
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, pos, direction, this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND);
|
+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, pos, direction, this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND);
|
||||||
+ if (event.isCancelled()) {
|
+ if (event.isCancelled()) {
|
||||||
@@ -123,10 +123,10 @@
|
|||||||
+ if (tileentity != null) {
|
+ if (tileentity != null) {
|
||||||
+ this.player.connection.send(tileentity.getUpdatePacket());
|
+ this.player.connection.send(tileentity.getUpdatePacket());
|
||||||
+ }
|
+ }
|
||||||
return;
|
+ return;
|
||||||
}
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
|
+
|
||||||
if (this.isCreative()) {
|
if (this.isCreative()) {
|
||||||
this.destroyAndAck(pos, sequence, "creative destroy");
|
this.destroyAndAck(pos, sequence, "creative destroy");
|
||||||
return;
|
return;
|
||||||
@@ -295,7 +295,7 @@
|
|||||||
BlockState iblockdata1 = block.playerWillDestroy(this.level, pos, iblockdata, this.player);
|
BlockState iblockdata1 = block.playerWillDestroy(this.level, pos, iblockdata, this.player);
|
||||||
boolean flag = this.level.removeBlock(pos, false);
|
boolean flag = this.level.removeBlock(pos, false);
|
||||||
|
|
||||||
@@ -263,19 +421,32 @@
|
@@ -263,19 +421,34 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isCreative()) {
|
if (this.isCreative()) {
|
||||||
@@ -316,10 +316,12 @@
|
|||||||
+ // return true; // CraftBukkit
|
+ // return true; // CraftBukkit
|
||||||
}
|
}
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
|
+ java.util.List<net.minecraft.world.entity.item.ItemEntity> itemsToDrop = this.level.captureDrops; // Paper - capture all item additions to the world
|
||||||
|
+ this.level.captureDrops = null; // Paper - capture all item additions to the world; Remove this earlier so that we can actually drop stuff
|
||||||
+ if (event.isDropItems()) {
|
+ if (event.isDropItems()) {
|
||||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockDropItemEvent(bblock, state, this.player, this.level.captureDrops);
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockDropItemEvent(bblock, state, this.player, itemsToDrop); // Paper - capture all item additions to the world
|
||||||
+ }
|
+ }
|
||||||
+ this.level.captureDrops = null;
|
+ //this.level.captureDrops = null; // Paper - capture all item additions to the world; move up
|
||||||
+
|
+
|
||||||
+ // Drop event experience
|
+ // Drop event experience
|
||||||
+ if (flag && event != null) {
|
+ if (flag && event != null) {
|
||||||
@@ -331,7 +333,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -321,15 +492,58 @@
|
@@ -321,15 +494,58 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,7 +392,7 @@
|
|||||||
if (itileinventory != null) {
|
if (itileinventory != null) {
|
||||||
player.openMenu(itileinventory);
|
player.openMenu(itileinventory);
|
||||||
return InteractionResult.CONSUME;
|
return InteractionResult.CONSUME;
|
||||||
@@ -359,7 +573,7 @@
|
@@ -359,7 +575,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user