1
0
Fork 0
mirror of https://github.com/PaperMC/Paper.git synced 2025-02-19 11:39:50 +01:00

Extend block drop capture to capture all items added to the world

This commit is contained in:
Shane Freeder 2020-09-17 00:36:05 +01:00
parent a4cc307c2b
commit af1fabed04
2 changed files with 42 additions and 34 deletions
paper-server/patches/sources/net/minecraft/server/level

View file

@ -79,7 +79,7 @@
+ public final LevelStorageSource.LevelStorageAccess convertable;
+ public final UUID uuid;
+ public boolean hasPhysicsEvent = true; // Paper - BlockPhysicsEvent
+
+ public LevelChunk getChunkIfLoaded(int x, int z) {
+ return this.chunkSource.getChunk(x, z, false);
+ }
@ -218,7 +218,7 @@
+ chunkgenerator = new FlatLevelSource(cpf.settings(), worldChunkManager);
+ }
+ }
+
+ if (gen != null) {
+ 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);
}
@ -606,6 +606,12 @@
+ // WorldServer.LOGGER.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getKey(entity.getType())); // CraftBukkit
return false;
} 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.
+ if (spawnReason != null && !CraftEventFactory.doEntityAddEventCalling(this, entity, spawnReason)) {
+ return false;
@ -685,7 +691,7 @@
while (iterator.hasNext()) {
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
@@ -982,6 +1280,12 @@
@@ -982,6 +1286,12 @@
double d1 = (double) pos.getY() - entityplayer.getY();
double d2 = (double) pos.getZ() - entityplayer.getZ();
@ -698,7 +704,7 @@
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
entityplayer.connection.send(new ClientboundBlockDestructionPacket(entityId, pos, progress));
}
@@ -1030,7 +1334,7 @@
@@ -1030,7 +1340,7 @@
@Override
public void levelEvent(@Nullable Player player, int eventId, BlockPos pos, int data) {
@ -707,7 +713,7 @@
}
public int getLogicalHeight() {
@@ -1060,7 +1364,18 @@
@@ -1060,7 +1370,18 @@
Iterator iterator = this.navigatingMobs.iterator();
while (iterator.hasNext()) {
@ -727,7 +733,7 @@
PathNavigation navigationabstract = entityinsentient.getNavigation();
if (navigationabstract.shouldRecomputePath(pos)) {
@@ -1086,11 +1401,13 @@
@@ -1086,11 +1407,13 @@
@Override
public void updateNeighborsAt(BlockPos pos, Block block) {
@ -741,7 +747,7 @@
this.neighborUpdater.updateNeighborsAtExceptFromFacing(pos, sourceBlock, (Direction) null, orientation);
}
@@ -1126,9 +1443,20 @@
@@ -1126,9 +1449,20 @@
@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) {
@ -763,7 +769,7 @@
case NONE:
explosion_effect = Explosion.BlockInteraction.KEEP;
break;
@@ -1144,16 +1472,27 @@
@@ -1144,16 +1478,27 @@
case TRIGGER:
explosion_effect = Explosion.BlockInteraction.TRIGGER_BLOCK;
break;
@ -794,7 +800,7 @@
Iterator iterator = this.players.iterator();
while (iterator.hasNext()) {
@@ -1162,10 +1501,11 @@
@@ -1162,10 +1507,11 @@
if (entityplayer.distanceToSqr(vec3d) < 4096.0D) {
Optional<Vec3> optional = Optional.ofNullable((Vec3) serverexplosion.getHitPlayers().get(entityplayer));
@ -807,7 +813,7 @@
}
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) {
@ -843,7 +849,7 @@
++j;
}
}
@@ -1292,7 +1644,7 @@
@@ -1292,7 +1650,7 @@
@Nullable
public BlockPos findNearestMapStructure(TagKey<Structure> structureTag, BlockPos pos, int radius, boolean skipReferencedStructures) {
@ -852,7 +858,7 @@
return null;
} else {
Optional<HolderSet.Named<Structure>> optional = this.registryAccess().lookupOrThrow(Registries.STRUCTURE).get(structureTag);
@@ -1334,11 +1686,22 @@
@@ -1334,11 +1692,22 @@
@Nullable
@Override
public MapItemSavedData getMapData(MapId id) {
@ -876,7 +882,7 @@
this.getServer().overworld().getDataStorage().set(id.key(), state);
}
@@ -1352,7 +1715,9 @@
@@ -1352,7 +1721,9 @@
float f1 = this.levelData.getSpawnAngle();
if (!blockposition1.equals(pos) || f1 != angle) {
@ -886,7 +892,7 @@
this.getServer().getPlayerList().broadcastAll(new ClientboundSetDefaultSpawnPositionPacket(pos, angle));
}
@@ -1649,6 +2014,11 @@
@@ -1649,6 +2020,11 @@
@Override
public void blockUpdated(BlockPos pos, Block block) {
if (!this.isDebug()) {
@ -898,7 +904,7 @@
this.updateNeighborsAt(pos, block);
}
@@ -1668,12 +2038,12 @@
@@ -1668,12 +2044,12 @@
}
public boolean isFlat() {
@ -913,7 +919,7 @@
}
@Nullable
@@ -1696,7 +2066,7 @@
@@ -1696,7 +2072,7 @@
private static <T> String getTypeCount(Iterable<T> items, Function<T, String> classifier) {
try {
Object2IntOpenHashMap<String> object2intopenhashmap = new Object2IntOpenHashMap();
@ -922,7 +928,7 @@
while (iterator.hasNext()) {
T t0 = iterator.next();
@@ -1705,7 +2075,7 @@
@@ -1705,7 +2081,7 @@
object2intopenhashmap.addTo(s, 1);
}
@ -931,7 +937,7 @@
String s1 = (String) entry.getKey();
return s1 + ":" + entry.getIntValue();
@@ -1717,6 +2087,7 @@
@@ -1717,6 +2093,7 @@
@Override
public LevelEntityGetter<Entity> getEntities() {
@ -939,7 +945,7 @@
return this.entityManager.getEntityGetter();
}
@@ -1802,6 +2173,17 @@
@@ -1802,6 +2179,17 @@
return this.serverLevelData.getGameRules();
}
@ -957,7 +963,7 @@
@Override
public CrashReportCategory fillReportDetails(CrashReport report) {
CrashReportCategory crashreportsystemdetails = super.fillReportDetails(report);
@@ -1836,7 +2218,8 @@
@@ -1836,7 +2224,8 @@
}
public void onTrackingStart(Entity entity) {
@ -967,7 +973,7 @@
if (entity instanceof ServerPlayer entityplayer) {
ServerLevel.this.players.add(entityplayer);
ServerLevel.this.updateSleepingPlayerList();
@@ -1864,9 +2247,53 @@
@@ -1864,9 +2253,53 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
@ -1021,7 +1027,7 @@
ServerLevel.this.getChunkSource().removeEntity(entity);
if (entity instanceof ServerPlayer entityplayer) {
ServerLevel.this.players.remove(entityplayer);
@@ -1895,6 +2322,15 @@
@@ -1895,6 +2328,15 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::remove);

View file

@ -110,9 +110,9 @@
+ this.player.connection.send(tileentity.getUpdatePacket());
+ }
+ // CraftBukkit end
+ return;
+ }
+
return;
}
+ // CraftBukkit start
+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, pos, direction, this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND);
+ if (event.isCancelled()) {
@ -123,10 +123,10 @@
+ if (tileentity != null) {
+ this.player.connection.send(tileentity.getUpdatePacket());
+ }
return;
}
+ return;
+ }
+ // CraftBukkit end
+
if (this.isCreative()) {
this.destroyAndAck(pos, sequence, "creative destroy");
return;
@ -295,7 +295,7 @@
BlockState iblockdata1 = block.playerWillDestroy(this.level, pos, iblockdata, this.player);
boolean flag = this.level.removeBlock(pos, false);
@@ -263,19 +421,32 @@
@@ -263,19 +421,34 @@
}
if (this.isCreative()) {
@ -316,10 +316,12 @@
+ // return true; // CraftBukkit
}
+ // 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()) {
+ 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
+ if (flag && event != null) {
@ -331,7 +333,7 @@
}
}
}
@@ -321,15 +492,58 @@
@@ -321,15 +494,58 @@
}
}
@ -390,7 +392,7 @@
if (itileinventory != null) {
player.openMenu(itileinventory);
return InteractionResult.CONSUME;
@@ -359,7 +573,7 @@
@@ -359,7 +575,7 @@
}
}