Skip to content

Commit e41a444

Browse files
committed
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.
1 parent 8ec0db9 commit e41a444

File tree

6 files changed

+10
-5
lines changed

6 files changed

+10
-5
lines changed

src/main/java/com/simibubi/create/api/behaviour/movement/MovementBehaviour.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ default boolean mustTickWhileDisabled() {
6666
return false;
6767
}
6868

69+
@Deprecated
6970
default void dropItem(MovementContext context, ItemStack stack) {
71+
collectOrDropItem(context, stack);
72+
}
73+
74+
default void collectOrDropItem(MovementContext context, ItemStack stack) {
7075
ItemStack remainder;
7176
if (AllConfigs.server().kinetics.moveItemsToStorage.get())
7277
remainder = ItemHandlerHelper.insertItem(context.contraption.getStorage().getAllItems(), stack, false);

src/main/java/com/simibubi/create/content/contraptions/actors/harvester/HarvesterMovementBehaviour.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void visitNewPosition(MovementContext context, BlockPos pos) {
9090
stack.shrink(1);
9191
seedSubtracted.setTrue();
9292
}
93-
dropItem(context, stack);
93+
collectOrDropItem(context, stack);
9494
});
9595

9696
BlockState cutCrop = cutCrop(world, pos, stateVisited);

src/main/java/com/simibubi/create/content/contraptions/actors/plough/PloughMovementBehaviour.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ protected void onBlockBroken(MovementContext context, BlockPos pos, BlockState b
125125
.withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(pos))
126126
.withParameter(LootContextParams.THIS_ENTITY, getPlayer(context))
127127
.withParameter(LootContextParams.TOOL, new ItemStack(Items.IRON_SHOVEL)))
128-
.forEach(s -> dropItem(context, s));
128+
.forEach(s -> collectOrDropItem(context, s));
129129
}
130130
}
131131

src/main/java/com/simibubi/create/content/contraptions/actors/roller/RollerMovementBehaviour.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ protected void destroyBlock(MovementContext context, BlockPos breakingPos) {
178178
BlockHelper.destroyBlock(context.world, breakingPos, 1f, stack -> {
179179
if (noHarvest || context.world.random.nextBoolean())
180180
return;
181-
this.dropItem(context, stack);
181+
this.collectOrDropItem(context, stack);
182182
});
183183

184184
super.destroyBlock(context, breakingPos);

src/main/java/com/simibubi/create/content/kinetics/base/BlockBreakingMovementBehaviour.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public void tickBreaker(MovementContext context) {
218218
}
219219

220220
protected void destroyBlock(MovementContext context, BlockPos breakingPos) {
221-
BlockHelper.destroyBlock(context.world, breakingPos, 1f, stack -> this.dropItem(context, stack));
221+
BlockHelper.destroyBlock(context.world, breakingPos, 1f, stack -> this.collectOrDropItem(context, stack));
222222
}
223223

224224
protected float getBlockBreakingSpeed(MovementContext context) {

src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerMovementBehaviour.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ private void tryDisposeOfExcess(MovementContext context) {
259259
if (list == inv.items && i == inv.selected && filter.test(context.world, itemstack))
260260
continue;
261261

262-
dropItem(context, itemstack);
262+
collectOrDropItem(context, itemstack);
263263
list.set(i, ItemStack.EMPTY);
264264
}
265265
}

0 commit comments

Comments
 (0)