Skip to content

Commit

Permalink
To account for Forge events cancelling entity spawning, we remove rea…
Browse files Browse the repository at this point in the history
…cting to the return value of Level#addFreshEntity
  • Loading branch information
shartte committed Oct 1, 2023
1 parent 88cfab6 commit a749b44
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/main/java/appeng/parts/automation/ItemPlacementStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ public final long placeInWorld(AEKey what, long amount, Actionable type, boolean

if (type == Actionable.MODULATE) {
is.setCount(maxStorage);
if (!spawnItemEntity(level, host, side, is)) {
// revert in case something prevents spawning.
worked = false;
}

spawnItemEntity(level, host, side, is);
}
}
} else {
Expand Down Expand Up @@ -123,7 +119,7 @@ public final long placeInWorld(AEKey what, long amount, Actionable type, boolean
return 0;
}

private static boolean spawnItemEntity(Level level, BlockEntity te, Direction side, ItemStack is) {
private static void spawnItemEntity(Level level, BlockEntity te, Direction side, ItemStack is) {
// The center of the block the plane is located in
final var centerX = te.getBlockPos().getX() + .5;
final double centerY = te.getBlockPos().getY();
Expand Down Expand Up @@ -166,12 +162,11 @@ private static boolean spawnItemEntity(Level level, BlockEntity te, Direction si
entity.setPos(absoluteX, absoluteY, absoluteZ);
entity.setDeltaMovement(side.getStepX() * .1, side.getStepY() * 0.1, side.getStepZ() * 0.1);

// Try to spawn it and destroy it in case it's not possible
if (!level.addFreshEntity(entity)) {
entity.discard();
return false;
}
return true;
// NOTE: Vanilla generally ignores the return-value of this method when spawning items into the world
// Forge will return false when the embedded event is canceled, but the event canceller is responsible
// for cleaning up the entity in that case, so we should always assume our spawning was successful,
// and consume items...
level.addFreshEntity(entity);
}

private int countEntitesAround(Level level, BlockPos pos) {
Expand Down

0 comments on commit a749b44

Please sign in to comment.