From 08882bb76b2cafd4ef12ca8d3b87d69fb57d69e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Liszkai?= Date: Sat, 4 Oct 2025 22:10:02 +0200 Subject: [PATCH] refactor: Clarify collection step with Contraption Actors With the expectation that the various method signatures do describe what they do, the "dropItem" was exceptionally hard to doubt and gone past it several months before come to the conclusion that maybe there are some side effects implemented where the signature may not suggest. This does not do any functional change, but improves the readability as now the five places where this "dropItem" was used, there is a clear indication that the item collection does happen, and suggests that the context needed to be passed not for position only, but for the contraption storage as well. --- .../api/behaviour/movement/MovementBehaviour.java | 10 ++++++++++ .../actors/harvester/HarvesterMovementBehaviour.java | 2 +- .../actors/plough/PloughMovementBehaviour.java | 2 +- .../actors/roller/RollerMovementBehaviour.java | 2 +- .../kinetics/base/BlockBreakingMovementBehaviour.java | 2 +- .../kinetics/deployer/DeployerMovementBehaviour.java | 2 +- 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/simibubi/create/api/behaviour/movement/MovementBehaviour.java b/src/main/java/com/simibubi/create/api/behaviour/movement/MovementBehaviour.java index 83a6ba6095..7c92b55de2 100644 --- a/src/main/java/com/simibubi/create/api/behaviour/movement/MovementBehaviour.java +++ b/src/main/java/com/simibubi/create/api/behaviour/movement/MovementBehaviour.java @@ -66,7 +66,17 @@ default boolean mustTickWhileDisabled() { return false; } + /** + * @deprecated since 6.0.8 - use {@link #collectOrDropItem(context, stack)} instead. + * No behaviours altered, simply a rename to reflect that we do collect items when + * applicable before considering dropping the remainder into the world. + */ + @Deprecated(since = "6.0.8", forRemoval = true) default void dropItem(MovementContext context, ItemStack stack) { + collectOrDropItem(context, stack); + } + + default void collectOrDropItem(MovementContext context, ItemStack stack) { ItemStack remainder; if (AllConfigs.server().kinetics.moveItemsToStorage.get()) remainder = ItemHandlerHelper.insertItem(context.contraption.getStorage().getAllItems(), stack, false); diff --git a/src/main/java/com/simibubi/create/content/contraptions/actors/harvester/HarvesterMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/actors/harvester/HarvesterMovementBehaviour.java index d2e199ce1c..55b6ebee71 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/actors/harvester/HarvesterMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/actors/harvester/HarvesterMovementBehaviour.java @@ -90,7 +90,7 @@ public void visitNewPosition(MovementContext context, BlockPos pos) { stack.shrink(1); seedSubtracted.setTrue(); } - dropItem(context, stack); + collectOrDropItem(context, stack); }); BlockState cutCrop = cutCrop(world, pos, stateVisited); diff --git a/src/main/java/com/simibubi/create/content/contraptions/actors/plough/PloughMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/actors/plough/PloughMovementBehaviour.java index 7448ea6c5a..0a0cd6bad1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/actors/plough/PloughMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/actors/plough/PloughMovementBehaviour.java @@ -125,7 +125,7 @@ protected void onBlockBroken(MovementContext context, BlockPos pos, BlockState b .withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(pos)) .withParameter(LootContextParams.THIS_ENTITY, getPlayer(context)) .withParameter(LootContextParams.TOOL, new ItemStack(Items.IRON_SHOVEL))) - .forEach(s -> dropItem(context, s)); + .forEach(s -> collectOrDropItem(context, s)); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/actors/roller/RollerMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/actors/roller/RollerMovementBehaviour.java index 5c2a5d90bd..f43abc3b54 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/actors/roller/RollerMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/actors/roller/RollerMovementBehaviour.java @@ -178,7 +178,7 @@ protected void destroyBlock(MovementContext context, BlockPos breakingPos) { BlockHelper.destroyBlock(context.world, breakingPos, 1f, stack -> { if (noHarvest || context.world.random.nextBoolean()) return; - this.dropItem(context, stack); + this.collectOrDropItem(context, stack); }); super.destroyBlock(context, breakingPos); diff --git a/src/main/java/com/simibubi/create/content/kinetics/base/BlockBreakingMovementBehaviour.java b/src/main/java/com/simibubi/create/content/kinetics/base/BlockBreakingMovementBehaviour.java index bdac042324..b5c2c85af6 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/base/BlockBreakingMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/kinetics/base/BlockBreakingMovementBehaviour.java @@ -218,7 +218,7 @@ public void tickBreaker(MovementContext context) { } protected void destroyBlock(MovementContext context, BlockPos breakingPos) { - BlockHelper.destroyBlock(context.world, breakingPos, 1f, stack -> this.dropItem(context, stack)); + BlockHelper.destroyBlock(context.world, breakingPos, 1f, stack -> this.collectOrDropItem(context, stack)); } protected float getBlockBreakingSpeed(MovementContext context) { diff --git a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerMovementBehaviour.java b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerMovementBehaviour.java index 7af9ef6df1..fc1fab7ab3 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerMovementBehaviour.java @@ -259,7 +259,7 @@ private void tryDisposeOfExcess(MovementContext context) { if (list == inv.items && i == inv.selected && filter.test(context.world, itemstack)) continue; - dropItem(context, itemstack); + collectOrDropItem(context, itemstack); list.set(i, ItemStack.EMPTY); } }