From 954fa56cffd0dab92f7b9d327b386a703ce6f1e1 Mon Sep 17 00:00:00 2001 From: Raycoms Date: Wed, 21 Aug 2024 12:47:32 +0200 Subject: [PATCH 1/5] Reached and prevent too long underwaterpathing --- .../MinecoloniesAdvancedPathNavigate.java | 13 +++++++------ .../pathfinding/pathjobs/PathJobEscapeWater.java | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java index 0a5e9e1112a..fc5553cccd0 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java @@ -966,6 +966,11 @@ protected void followThePath() boolean isTracking = PathfindingUtils.trackingMap.containsValue(ourEntity.getUUID()); HashSet reached = null; + if (isTracking) + { + reached = new HashSet<>(); + } + // Look at multiple points, incase we're too fast for (int i = this.path.getNextNodeIndex(); i < Math.min(this.path.getNodeCount(), this.path.getNextNodeIndex() + 4); i++) { @@ -979,17 +984,13 @@ protected void followThePath() if (isTracking) { - if (reached == null) - { - reached = new HashSet<>(); - } final Node point = path.getNode(i); reached.add(new BlockPos(point.x, point.y, point.z)); } } } - if (isTracking && reached != null) + if (isTracking) { PathfindingUtils.syncDebugReachedPositions(reached, ourEntity); reached.clear(); @@ -1033,7 +1034,7 @@ else if (isTracking) } } - if (isTracking && reached != null) + if (isTracking) { PathfindingUtils.syncDebugReachedPositions(reached, ourEntity); reached.clear(); diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobEscapeWater.java b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobEscapeWater.java index 11ebc4ab77b..bfddfb0cc0c 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobEscapeWater.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobEscapeWater.java @@ -90,7 +90,7 @@ protected Path search() @Override protected double computeHeuristic(final int x, final int y, final int z) { - return BlockPosUtil.dist(preferredDirection, x, y, z) * 2; + return BlockPosUtil.dist(preferredDirection, x, y, z) * 2 / (y / 10.0); } /** From 93ff7ebf1e6b1a2237a6c0af23dd53291609f46d Mon Sep 17 00:00:00 2001 From: Raycoms Date: Wed, 21 Aug 2024 13:53:45 +0200 Subject: [PATCH 2/5] better underwater calc --- .../AbstractDrownedEntityPirate.java | 2 +- .../entity/pathfinding/PathfindingUtils.java | 2 +- .../entity/pathfinding/PathingOptions.java | 14 ++++- .../pathfinding/pathjobs/AbstractPathJob.java | 61 +++++++++++++------ .../pathjobs/PathJobEscapeWater.java | 2 +- 5 files changed, 57 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/minecolonies/api/entity/mobs/drownedpirate/AbstractDrownedEntityPirate.java b/src/main/java/com/minecolonies/api/entity/mobs/drownedpirate/AbstractDrownedEntityPirate.java index 72df363707c..834f57a8c0d 100755 --- a/src/main/java/com/minecolonies/api/entity/mobs/drownedpirate/AbstractDrownedEntityPirate.java +++ b/src/main/java/com/minecolonies/api/entity/mobs/drownedpirate/AbstractDrownedEntityPirate.java @@ -93,7 +93,7 @@ public AbstractAdvancedPathNavigate getNavigation() this.navigation = newNavigator; newNavigator.setSwimSpeedFactor(getSwimSpeedFactor()); newNavigator.setSpeedModifier(0.5); - newNavigator.getPathingOptions().withStartSwimCost(2.5D).withSwimCost(1.0D).withCanEnterDoors(true).withDropCost(1D).withJumpCost(1D).withWalkUnderWater(true).withNonLadderClimbableCost(1D).setPassDanger(true); + newNavigator.getPathingOptions().withStartSwimCost(2.5D).withSwimCost(1.0D).withDivingCost(1.0D).withCanEnterDoors(true).withDropCost(1D).withJumpCost(1D).withWalkUnderWater(true).withNonLadderClimbableCost(1D).setPassDanger(true); PathingStuckHandler stuckHandler = PathingStuckHandler.createStuckHandler() .withTakeDamageOnStuck(0.4f) .withBuildLeafBridges() diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/PathfindingUtils.java b/src/main/java/com/minecolonies/core/entity/pathfinding/PathfindingUtils.java index f007dcf81fd..edfb59176b0 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/PathfindingUtils.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/PathfindingUtils.java @@ -259,7 +259,7 @@ public static boolean isWater(@NotNull final BlockGetter world, final BlockPos p FluidState fluidState = pFluidState; if (fluidState == null) { - fluidState = world.getFluidState(pos); + fluidState = state.getFluidState(); } if (fluidState == empty || fluidState.isEmpty()) diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/PathingOptions.java b/src/main/java/com/minecolonies/core/entity/pathfinding/PathingOptions.java index db68365fb50..1e680f16fd7 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/PathingOptions.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/PathingOptions.java @@ -67,6 +67,11 @@ public class PathingOptions */ public double walkInShapesCost = 2D; + /** + * Cost to dive (head underwater). + */ + public double divingCost = 4D; + /** * Factor multiplied to the small random base cost of values, increases this increases the paths randomness/volatilty. Set to 0 to disable rng. */ @@ -234,6 +239,12 @@ public PathingOptions withNonLadderClimbableCost(final double nonLadderClimbable return this; } + public PathingOptions withDivingCost(final double divingCost) + { + this.divingCost = divingCost; + return this; + } + /** * Sets swimming ability * @@ -284,6 +295,8 @@ public void importFrom(final PathingOptions pathingOptions) swimCostEnter = pathingOptions.swimCostEnter; traverseToggleAbleCost = pathingOptions.traverseToggleAbleCost; nonLadderClimbableCost = pathingOptions.nonLadderClimbableCost; + divingCost = pathingOptions.divingCost; + canUseRails = pathingOptions.canUseRails; canSwim = pathingOptions.canSwim; enterDoors = pathingOptions.enterDoors; @@ -294,5 +307,4 @@ public void importFrom(final PathingOptions pathingOptions) walkUnderWater = pathingOptions.walkUnderWater; canDrop = pathingOptions.canDrop; } - } diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/AbstractPathJob.java b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/AbstractPathJob.java index 5cd394f445c..f44aa1acb53 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/AbstractPathJob.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/AbstractPathJob.java @@ -732,19 +732,22 @@ else if (!node.isCornerNode() && newY - node.y < 0 && (dX != 0 || dZ != 0) && } } - final boolean isSwimming = calculateSwimming(world, nextX, nextY, nextZ, nextNode); + final BlockState aboveState = cachedBlockLookup.getBlockState(nextX, nextY + 1, nextZ); + final BlockState state = cachedBlockLookup.getBlockState(nextX, nextY, nextZ); + final BlockState belowState = cachedBlockLookup.getBlockState(nextX, nextY - 1, nextZ); + + final boolean isSwimming = calculateSwimming(belowState, state, aboveState, nextNode); if (isSwimming && !pathingOptions.canSwim()) { return; } final boolean swimStart = isSwimming && !node.isSwimming(); - final BlockState state = cachedBlockLookup.getBlockState(nextX, nextY, nextZ); - final BlockState belowState = cachedBlockLookup.getBlockState(nextX, nextY - 1, nextZ); final boolean onRoad = WorkerUtil.isPathBlock(belowState.getBlock()); final boolean onRails = pathingOptions.canUseRails() && (corner ? belowState : state).getBlock() instanceof BaseRailBlock; final boolean railsExit = !onRails && node != null && node.isOnRails(); final boolean ladder = PathfindingUtils.isLadder(state, pathingOptions); + final boolean isDiving = isSwimming && PathfindingUtils.isWater(world, null, aboveState, null); double nextCost = 0; if (!corner) @@ -759,7 +762,7 @@ else if (!node.isCornerNode() && newY - node.y < 0 && (dX != 0 || dZ != 0) && costFrom = node.parent; } - nextCost = computeCost(costFrom, dX, dY, dZ, isSwimming, onRoad, onRails, railsExit, swimStart, ladder, state, belowState, nextX, nextY, nextZ); + nextCost = computeCost(costFrom, dX, dY, dZ, isSwimming, isDiving, onRoad, onRails, railsExit, swimStart, ladder, state, belowState, nextX, nextY, nextZ); nextCost = modifyCost(nextCost, costFrom, swimStart, isSwimming, nextX, nextY, nextZ, state, belowState); if (nextCost > maxCost) @@ -882,6 +885,7 @@ protected double computeCost( final MNode parent, final int dX, final int dY, final int dZ, final boolean isSwimming, final boolean onPath, + final boolean isDiving, final boolean onRails, final boolean railsExit, final boolean swimStart, @@ -891,13 +895,16 @@ protected double computeCost( { double cost = 1; - if (onPath) + if (!isSwimming) { - cost *= pathingOptions.onPathCost; - } - if (onRails) - { - cost *= pathingOptions.onRailCost; + if (onPath) + { + cost *= pathingOptions.onPathCost; + } + if (onRails) + { + cost *= pathingOptions.onRailCost; + } } if (pathingOptions.randomnessFactor > 0.0d) @@ -910,15 +917,18 @@ protected double computeCost( cost += pathingOptions.caveAirCost; } - if (dY != 0 && !(ladder && parent.isLadder()) && !(Math.abs(dY) == 1 && below.is(BlockTags.STAIRS))) + if (!isDiving) { - if (dY > 0) + if (dY != 0 && !(ladder && parent.isLadder()) && !(Math.abs(dY) == 1 && below.is(BlockTags.STAIRS))) { - cost += pathingOptions.jumpCost; - } - else if (pathingOptions.dropCost != 0) - { - cost += pathingOptions.dropCost * Math.abs(dY * dY * dY); + if (dY > 0) + { + cost += pathingOptions.jumpCost; + } + else if (pathingOptions.dropCost != 0) + { + cost += pathingOptions.dropCost * Math.abs(dY * dY * dY); + } } } @@ -941,7 +951,7 @@ else if (!ShapeUtil.isEmpty(state.getCollisionShape(cachedBlockLookup, tempWorld cost += pathingOptions.railsExitCost; } - if (ladder && !parent.isLadder() && !(state.getBlock() instanceof LadderBlock)) + if (!isDiving && ladder && !parent.isLadder() && !(state.getBlock() instanceof LadderBlock)) { cost += pathingOptions.nonLadderClimbableCost; } @@ -956,6 +966,10 @@ else if (!ShapeUtil.isEmpty(state.getCollisionShape(cachedBlockLookup, tempWorld { cost += pathingOptions.swimCost; } + if (isDiving) + { + cost += pathingOptions.divingCost; + } } return cost; @@ -1528,9 +1542,16 @@ private boolean canLeaveBlock(final int x, final int y, final int z, final MNode return true; } - private boolean calculateSwimming(@NotNull final LevelReader world, final int x, final int y, final int z, @Nullable final MNode node) + private boolean calculateSwimming(final BlockState below, final BlockState state, final BlockState above, @Nullable final MNode node) { - return (node == null) ? PathfindingUtils.isWater(world, tempWorldPos.set(x, y - 1, z)) : node.isSwimming(); + if (node != null) + { + return node.isSwimming(); + } + + return PathfindingUtils.isWater(cachedBlockLookup, null, below,null) + || PathfindingUtils.isWater(cachedBlockLookup, null, state,null) + || PathfindingUtils.isWater(cachedBlockLookup, null, above,null); } /** diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobEscapeWater.java b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobEscapeWater.java index bfddfb0cc0c..11ebc4ab77b 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobEscapeWater.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobEscapeWater.java @@ -90,7 +90,7 @@ protected Path search() @Override protected double computeHeuristic(final int x, final int y, final int z) { - return BlockPosUtil.dist(preferredDirection, x, y, z) * 2 / (y / 10.0); + return BlockPosUtil.dist(preferredDirection, x, y, z) * 2; } /** From ecfd74754ef926ccef6201d2db4dc90fceb3f5d3 Mon Sep 17 00:00:00 2001 From: Raycoms Date: Wed, 21 Aug 2024 14:53:32 +0200 Subject: [PATCH 3/5] don't log this --- .../minecolonies/core/tileentities/TileEntityColonyBuilding.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/minecolonies/core/tileentities/TileEntityColonyBuilding.java b/src/main/java/com/minecolonies/core/tileentities/TileEntityColonyBuilding.java index cc8deb47488..e5d592c3e52 100755 --- a/src/main/java/com/minecolonies/core/tileentities/TileEntityColonyBuilding.java +++ b/src/main/java/com/minecolonies/core/tileentities/TileEntityColonyBuilding.java @@ -677,7 +677,6 @@ private void processBlueprint(final Blueprint blueprint) { if (blueprint == null) { - Log.getLogger().error("Invalid building details for reactivation"); return; } From 41932d2221a91fc93f80ddf942ef33653eefe8f0 Mon Sep 17 00:00:00 2001 From: Raycoms Date: Wed, 21 Aug 2024 20:44:48 +0200 Subject: [PATCH 4/5] stage --- .../requestable/IDeliverable.java | 1 - .../requestsystem/requestable/Stack.java | 2 +- .../AbstractTileEntityWareHouse.java | 9 + .../minecolonies/core/colony/ColonyView.java | 5 +- .../management/handlers/RequestHandler.java | 11 +- .../management/handlers/ResolverHandler.java | 2 - .../resolvers/DeliverymenRequestResolver.java | 8 + .../WarehouseConcreteRequestResolver.java | 47 ++--- .../resolvers/WarehouseRequestResolver.java | 31 +++- .../AbstractWarehouseRequestResolver.java | 165 ++++++++---------- .../tileentities/TileEntityWareHouse.java | 73 ++++++-- 11 files changed, 198 insertions(+), 156 deletions(-) diff --git a/src/main/java/com/minecolonies/api/colony/requestsystem/requestable/IDeliverable.java b/src/main/java/com/minecolonies/api/colony/requestsystem/requestable/IDeliverable.java index 7931fd28097..3abf250b078 100755 --- a/src/main/java/com/minecolonies/api/colony/requestsystem/requestable/IDeliverable.java +++ b/src/main/java/com/minecolonies/api/colony/requestsystem/requestable/IDeliverable.java @@ -53,7 +53,6 @@ public interface IDeliverable extends IRetryable */ IDeliverable copyWithCount(final int newCount); - /** * Can this type of request be resolved by the building, or only by external resolvers. * @return true if so. diff --git a/src/main/java/com/minecolonies/api/colony/requestsystem/requestable/Stack.java b/src/main/java/com/minecolonies/api/colony/requestsystem/requestable/Stack.java index 77601fc96e5..74f7b045272 100755 --- a/src/main/java/com/minecolonies/api/colony/requestsystem/requestable/Stack.java +++ b/src/main/java/com/minecolonies/api/colony/requestsystem/requestable/Stack.java @@ -344,7 +344,7 @@ public boolean matchDamage() @Override public IDeliverable copyWithCount(final int newCount) { - return new Stack(this.theStack, this.matchDamage, this.matchNBT, this.matchOreDic, this.result, newCount, this.minCount); + return new Stack(this.theStack, this.matchDamage, this.matchNBT, this.matchOreDic, this.result, newCount, Math.min(newCount, this.minCount)); } @NotNull diff --git a/src/main/java/com/minecolonies/api/tileentities/AbstractTileEntityWareHouse.java b/src/main/java/com/minecolonies/api/tileentities/AbstractTileEntityWareHouse.java index 6f8cb4e8f95..97a78fb4bb7 100755 --- a/src/main/java/com/minecolonies/api/tileentities/AbstractTileEntityWareHouse.java +++ b/src/main/java/com/minecolonies/api/tileentities/AbstractTileEntityWareHouse.java @@ -1,5 +1,6 @@ package com.minecolonies.api.tileentities; +import com.minecolonies.api.crafting.ItemStorage; import com.minecolonies.api.inventory.InventoryCitizen; import com.minecolonies.api.util.Tuple; import com.minecolonies.core.tileentities.TileEntityColonyBuilding; @@ -69,6 +70,14 @@ public AbstractTileEntityWareHouse(final BlockEntityType> getMatchingItemStacksInWarehouse(@NotNull Predicate itemStackSelectionPredicate); + /** + * Get the count up to some maxCount for some itemstorage in the warehouse. + * @param storage the storage. + * @param maxCount the count. + * @return the maxCount or less. + */ + public abstract int getCountInWarehouse(@NotNull final ItemStorage storage, int maxCount); + /** * Dump the inventory of a citizen into the warehouse. Go through all items and search the right chest to dump it in. * diff --git a/src/main/java/com/minecolonies/core/colony/ColonyView.java b/src/main/java/com/minecolonies/core/colony/ColonyView.java index 60c9b8587f1..55646a70eb7 100644 --- a/src/main/java/com/minecolonies/core/colony/ColonyView.java +++ b/src/main/java/com/minecolonies/core/colony/ColonyView.java @@ -826,7 +826,10 @@ public void handleColonyViewMessage(@NotNull final RegistryFriendlyByteBuf buf, if (buf.readBoolean()) { - this.requestManager = new StandardRequestManager(this); + if (this.requestManager == null) + { + this.requestManager = new StandardRequestManager(this); + } this.requestManager.deserialize(StandardFactoryController.getInstance(), buf); } diff --git a/src/main/java/com/minecolonies/core/colony/requestsystem/management/handlers/RequestHandler.java b/src/main/java/com/minecolonies/core/colony/requestsystem/management/handlers/RequestHandler.java index 46d1ead411d..127c4738e90 100755 --- a/src/main/java/com/minecolonies/core/colony/requestsystem/management/handlers/RequestHandler.java +++ b/src/main/java/com/minecolonies/core/colony/requestsystem/management/handlers/RequestHandler.java @@ -238,8 +238,7 @@ private IToken resolve( //TODO: Change this false to simulation. resolver.onRequestAssigned(manager, request, false); - for (final IToken childRequestToken : - attemptResult) + for (final IToken childRequestToken : attemptResult) { final IRequest childRequest = manager.getRequestHandler().getRequest(childRequestToken); @@ -247,8 +246,7 @@ private IToken resolve( request.addChild(childRequest.getId()); } - for (final IToken childRequestToken : - attemptResult) + for (final IToken childRequestToken : attemptResult) { final IRequest childRequest = manager.getRequestHandler().getRequest(childRequestToken); @@ -338,8 +336,7 @@ public void onRequestResolved(final IToken token) } //Assign the followup request if need be - if (followupRequests != null && !followupRequests.isEmpty() && - followupRequests.stream().anyMatch(followupRequest -> !isAssigned(followupRequest.getId()))) + if (followupRequests != null && !followupRequests.isEmpty()) { followupRequests.stream() .filter(followupRequest -> !isAssigned(followupRequest.getId())) @@ -614,8 +611,6 @@ public IRequest getRequest(final IToken token) @Override public IRequest getRequestOrNull(final IToken token) { - manager.log("Retrieving the request for: " + token); - return manager.getRequestIdentitiesDataStore().getIdentities().get(token); } diff --git a/src/main/java/com/minecolonies/core/colony/requestsystem/management/handlers/ResolverHandler.java b/src/main/java/com/minecolonies/core/colony/requestsystem/management/handlers/ResolverHandler.java index 92669168e75..f0697d9f921 100755 --- a/src/main/java/com/minecolonies/core/colony/requestsystem/management/handlers/ResolverHandler.java +++ b/src/main/java/com/minecolonies/core/colony/requestsystem/management/handlers/ResolverHandler.java @@ -284,8 +284,6 @@ public IRequestResolver getResolver(final IToken toke throw new IllegalArgumentException("The given token for a resolver is not known to this manager!"); } - manager.log("Retrieving resolver for: " + token); - return manager.getRequestResolverIdentitiesDataStore().getIdentities().get(token); } diff --git a/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/DeliverymenRequestResolver.java b/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/DeliverymenRequestResolver.java index 3dafe4c3dfd..0eedcd47a80 100644 --- a/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/DeliverymenRequestResolver.java +++ b/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/DeliverymenRequestResolver.java @@ -15,6 +15,7 @@ import com.minecolonies.core.colony.buildings.modules.BuildingModules; import com.minecolonies.core.colony.buildings.modules.CourierAssignmentModule; import com.minecolonies.core.colony.buildings.modules.WarehouseRequestQueueModule; +import com.minecolonies.core.colony.buildings.workerbuildings.BuildingWareHouse; import com.minecolonies.core.colony.jobs.JobDeliveryman; import com.minecolonies.core.colony.requestsystem.resolvers.core.AbstractRequestResolver; import net.minecraft.network.chat.MutableComponent; @@ -43,6 +44,13 @@ public boolean canResolveRequest(@NotNull final IRequestManager manager, final I { return false; } + final Colony colony = (Colony) manager.getColony(); + + if (colony.getBuildingManager().getBuilding(requestToCheck.getRequester().getLocation().getInDimensionLocation()) instanceof BuildingWareHouse buildingWareHouse + && !buildingWareHouse.getID().equals(getLocation().getInDimensionLocation())) + { + return false; + } return hasCouriers(manager); } diff --git a/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/WarehouseConcreteRequestResolver.java b/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/WarehouseConcreteRequestResolver.java index a78cef0735a..117efb8927e 100755 --- a/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/WarehouseConcreteRequestResolver.java +++ b/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/WarehouseConcreteRequestResolver.java @@ -7,9 +7,11 @@ import com.minecolonies.api.colony.requestsystem.requestable.INonExhaustiveDeliverable; import com.minecolonies.api.colony.requestsystem.requestable.Stack; import com.minecolonies.api.colony.requestsystem.token.IToken; +import com.minecolonies.api.crafting.ItemStorage; +import com.minecolonies.core.colony.buildings.workerbuildings.BuildingWareHouse; import com.minecolonies.core.colony.requestsystem.resolvers.core.AbstractWarehouseRequestResolver; -import com.minecolonies.core.tileentities.TileEntityWareHouse; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -27,42 +29,41 @@ public WarehouseConcreteRequestResolver( } @Override - protected boolean internalCanResolve(final List wareHouses, final IRequest requestToCheck) + protected boolean internalCanResolve(final Level level, final List wareHouses, final IRequest requestToCheck) { final IDeliverable deliverable = requestToCheck.getRequest(); - if(deliverable instanceof IConcreteDeliverable) + if (deliverable instanceof IConcreteDeliverable) { boolean ignoreNBT = false; boolean ignoreDamage = false; - if (deliverable instanceof Stack) + if (deliverable instanceof Stack stack) { - if (!((Stack) requestToCheck.getRequest()).matchNBT()) - { - ignoreNBT = true; - } - if (!((Stack) requestToCheck.getRequest()).matchDamage()) - { - ignoreDamage = true; - } + ignoreNBT = !stack.matchNBT(); + ignoreDamage = !stack.matchDamage(); } - for(final ItemStack possible : ((IConcreteDeliverable) deliverable).getRequestedItems()) + int totalCount = 0; + for (final ItemStack possible : ((IConcreteDeliverable) deliverable).getRequestedItems()) { - for (final TileEntityWareHouse wareHouse : wareHouses) + for (final BuildingWareHouse wareHouse : wareHouses) { - if (requestToCheck.getRequest() instanceof INonExhaustiveDeliverable) + if (wareHouse.getTileEntity() == null) + { + continue; + } + + if (requestToCheck.getRequest() instanceof INonExhaustiveDeliverable neDeliverable) { - if (wareHouse.hasMatchingItemStackInWarehouse(possible, requestToCheck.getRequest().getMinimumCount(), ignoreNBT, ignoreDamage, ((INonExhaustiveDeliverable) requestToCheck.getRequest()).getLeftOver())) - { - return true; - } + totalCount += Math.max(0, wareHouse.getTileEntity().getCountInWarehouse(new ItemStorage(possible, requestToCheck.getRequest().getMinimumCount(), ignoreDamage, ignoreNBT), requestToCheck.getRequest().getMinimumCount()) - neDeliverable.getLeftOver()); } else { - if (wareHouse.hasMatchingItemStackInWarehouse(possible, requestToCheck.getRequest().getMinimumCount(), ignoreNBT, ignoreDamage, 0)) - { - return true; - } + totalCount += wareHouse.getTileEntity().getCountInWarehouse(new ItemStorage(possible, requestToCheck.getRequest().getMinimumCount(), ignoreDamage, ignoreNBT), requestToCheck.getRequest().getMinimumCount()); + } + + if (totalCount >= requestToCheck.getRequest().getMinimumCount()) + { + return true; } } } diff --git a/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/WarehouseRequestResolver.java b/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/WarehouseRequestResolver.java index c1574212789..e427ad71154 100755 --- a/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/WarehouseRequestResolver.java +++ b/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/WarehouseRequestResolver.java @@ -5,8 +5,13 @@ import com.minecolonies.api.colony.requestsystem.requestable.IConcreteDeliverable; import com.minecolonies.api.colony.requestsystem.requestable.IDeliverable; import com.minecolonies.api.colony.requestsystem.token.IToken; +import com.minecolonies.api.util.WorldUtil; +import com.minecolonies.core.colony.buildings.workerbuildings.BuildingWareHouse; import com.minecolonies.core.colony.requestsystem.resolvers.core.AbstractWarehouseRequestResolver; -import com.minecolonies.core.tileentities.TileEntityWareHouse; +import com.minecolonies.core.tileentities.TileEntityRack; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -24,18 +29,30 @@ public WarehouseRequestResolver( } @Override - protected boolean internalCanResolve(final List wareHouses, final IRequest requestToCheck) + protected boolean internalCanResolve(final Level level, final List wareHouses, final IRequest requestToCheck) { - if(requestToCheck.getRequest() instanceof IConcreteDeliverable) + if (requestToCheck.getRequest() instanceof IConcreteDeliverable) { - return false; + return false; } - for (final TileEntityWareHouse wareHouse : wareHouses) + int totalCount = 0; + for (final BuildingWareHouse wareHouse : wareHouses) { - if (wareHouse.hasMatchingItemStackInWarehouse(itemStack -> requestToCheck.getRequest().matches(itemStack), requestToCheck.getRequest().getMinimumCount())) + for (@NotNull final BlockPos pos : wareHouse.getContainers()) { - return true; + if (WorldUtil.isBlockLoaded(level, pos)) + { + final BlockEntity entity = level.getBlockEntity(pos); + if (entity instanceof final TileEntityRack rack && !rack.isEmpty()) + { + totalCount += rack.getItemCount(itemStack -> requestToCheck.getRequest().matches(itemStack)); + if (totalCount >= requestToCheck.getRequest().getMinimumCount()) + { + return true; + } + } + } } } return false; diff --git a/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/core/AbstractWarehouseRequestResolver.java b/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/core/AbstractWarehouseRequestResolver.java index e73adc732c6..80def00d84e 100755 --- a/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/core/AbstractWarehouseRequestResolver.java +++ b/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/core/AbstractWarehouseRequestResolver.java @@ -3,6 +3,8 @@ import com.google.common.collect.Lists; import com.google.common.reflect.TypeToken; import com.minecolonies.api.colony.buildings.IBuilding; +import com.minecolonies.api.colony.buildings.ModBuildings; +import com.minecolonies.api.colony.buildings.workerbuildings.IWareHouse; import com.minecolonies.api.colony.requestsystem.location.ILocation; import com.minecolonies.api.colony.requestsystem.manager.IRequestManager; import com.minecolonies.api.colony.requestsystem.request.IRequest; @@ -13,12 +15,14 @@ import com.minecolonies.api.colony.requestsystem.requester.IRequester; import com.minecolonies.api.colony.requestsystem.token.IToken; import com.minecolonies.api.crafting.ItemStorage; +import com.minecolonies.api.util.BlockPosUtil; import com.minecolonies.api.util.ItemStackUtils; import com.minecolonies.api.util.Log; import com.minecolonies.api.util.Tuple; import com.minecolonies.api.util.constant.TranslationConstants; import com.minecolonies.api.util.constant.TypeConstants; import com.minecolonies.core.colony.Colony; +import com.minecolonies.core.colony.buildings.modules.BuildingModules; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingWareHouse; import com.minecolonies.core.colony.requestsystem.requesters.BuildingBasedRequester; import com.minecolonies.core.tileentities.TileEntityWareHouse; @@ -26,6 +30,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.Component; +import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -46,14 +51,6 @@ public AbstractWarehouseRequestResolver( super(location, token); } - /** - * Check to see if this object type is the same as the request - */ - protected boolean isRequestFromSelf(final IRequest requestToCheck) - { - return requestToCheck.getRequester().getClass().equals(this.getClass()); - } - @Override public TypeToken getRequestType() { @@ -66,7 +63,7 @@ public TypeToken getRequestType() * @param requestToCheck * @return */ - protected abstract boolean internalCanResolve(final List wareHouses, final IRequest requestToCheck); + protected abstract boolean internalCanResolve(final Level level, final List wareHouses, final IRequest requestToCheck); @Override public boolean canResolveRequest(@NotNull final IRequestManager manager, final IRequest requestToCheck) @@ -75,7 +72,7 @@ public boolean canResolveRequest(@NotNull final IRequestManager manager, final I { final BuildingBasedRequester requester = ((BuildingBasedRequester) requestToCheck.getRequester()); final Optional building = requester.getBuilding(manager, requestToCheck.getRequester().getId()); - if (building.isPresent() && building.get() instanceof BuildingWareHouse) + if (building.isPresent() && building.get() instanceof BuildingWareHouse buildingWareHouse && buildingWareHouse.getID().equals(getLocation().getInDimensionLocation())) { return false; } @@ -83,16 +80,29 @@ public boolean canResolveRequest(@NotNull final IRequestManager manager, final I if (!manager.getColony().getWorld().isClientSide) { - if (!isRequestChainValid(manager, requestToCheck)) + final Colony colony = (Colony) manager.getColony(); + final IBuilding wareHouse = colony.getBuildingManager().getBuilding(getLocation().getInDimensionLocation()); + if (wareHouse == null) { return false; } - final Colony colony = (Colony) manager.getColony(); + if (!isRequestChainValid(manager, requestToCheck)) + { + return false; + } try { - return internalCanResolve(getWareHousesInColony(colony, requestToCheck.getRequester().getLocation().getInDimensionLocation()), requestToCheck); + final List wareHouses = new ArrayList<>(); + for (final Map.Entry building : colony.getBuildingManager().getBuildings().entrySet()) + { + if (building.getValue().getBuildingType() == ModBuildings.wareHouse.value()) + { + wareHouses.add((BuildingWareHouse) building.getValue()); + } + } + return internalCanResolve(colony.getWorld(), wareHouses, requestToCheck); } catch (Exception e) { @@ -110,11 +120,6 @@ public boolean canResolveRequest(@NotNull final IRequestManager manager, final I */ public boolean isRequestChainValid(@NotNull final IRequestManager manager, final IRequest requestToCheck) { - if (isRequestFromSelf(requestToCheck)) - { - return false; - } - if (!requestToCheck.hasParent()) { return true; @@ -131,12 +136,8 @@ public boolean isRequestChainValid(@NotNull final IRequestManager manager, final return isRequestChainValid(manager, parentRequest); } - /* - * Moving the curly braces really makes the code hard to read. - */ @Nullable @Override - @SuppressWarnings("squid:LeftCurlyBraceStartLineCheck") public List> attemptResolveRequest(@NotNull final IRequestManager manager, @NotNull final IRequest request) { if (manager.getColony().getWorld().isClientSide) @@ -151,7 +152,7 @@ public List> attemptResolveRequest(@NotNull final IRequestManager mana final Colony colony = (Colony) manager.getColony(); - final List wareHouses = getWareHousesInColony(colony, request.getRequester().getLocation().getInDimensionLocation()); + final TileEntityWareHouse wareHouse = (TileEntityWareHouse) colony.getBuildingManager().getBuilding(getLocation().getInDimensionLocation()).getTileEntity(); final int totalRequested = request.getRequest().getCount(); int totalAvailable = 0; @@ -159,15 +160,13 @@ public List> attemptResolveRequest(@NotNull final IRequestManager mana { totalAvailable -= ((INonExhaustiveDeliverable) request.getRequest()).getLeftOver(); } - for (final TileEntityWareHouse tile : wareHouses) + + final List> inv = wareHouse.getMatchingItemStacksInWarehouse(itemStack -> request.getRequest().matches(itemStack)); + for (final Tuple stack : inv) { - final List> inv = tile.getMatchingItemStacksInWarehouse(itemStack -> request.getRequest().matches(itemStack)); - for (final Tuple stack : inv) + if (!stack.getA().isEmpty()) { - if (!stack.getA().isEmpty()) - { - totalAvailable += stack.getA().getCount(); - } + totalAvailable += stack.getA().getCount(); } } @@ -182,8 +181,7 @@ public List> attemptResolveRequest(@NotNull final IRequestManager mana } final int totalRemainingRequired = totalRequested - totalAvailable; - final IDeliverable remainingRequest = request.getRequest().copyWithCount(totalRemainingRequired); - return Lists.newArrayList(manager.createRequest(this, remainingRequest)); + return Lists.newArrayList(manager.createRequest(this, request.getRequest().copyWithCount(totalRemainingRequired))); } @Override @@ -202,7 +200,7 @@ public List> getFollowupRequestForCompletion(@NotNull final IRequest } final Colony colony = (Colony) manager.getColony(); - final List wareHouses = getWareHousesInColony(colony, completedRequest.getRequester().getLocation().getInDimensionLocation()); + final TileEntityWareHouse wareHouse = (TileEntityWareHouse) colony.getBuildingManager().getBuilding(getLocation().getInDimensionLocation()).getTileEntity(); List> deliveries = Lists.newArrayList(); int remainingCount = completedRequest.getRequest().getCount(); @@ -211,55 +209,46 @@ public List> getFollowupRequestForCompletion(@NotNull final IRequest final int keep = completedRequest.getRequest() instanceof INonExhaustiveDeliverable ? ((INonExhaustiveDeliverable) completedRequest.getRequest()).getLeftOver() : 0; - tileentities: - for (final TileEntityWareHouse wareHouse : wareHouses) + final List> targetStacks = wareHouse.getMatchingItemStacksInWarehouse(itemStack -> completedRequest.getRequest().matches(itemStack)); + for (final Tuple tuple : targetStacks) { - final List> targetStacks = wareHouse.getMatchingItemStacksInWarehouse(itemStack -> completedRequest.getRequest().matches(itemStack)); - for (final Tuple tuple : targetStacks) + if (ItemStackUtils.isEmpty(tuple.getA())) { - if (ItemStackUtils.isEmpty(tuple.getA())) - { - continue; - } + continue; + } - int leftOver = tuple.getA().getCount(); - if (keep > 0) + int leftOver = tuple.getA().getCount(); + if (keep > 0) + { + int kept = storages.getOrDefault(new ItemStorage(tuple.getA()), 0); + if (kept < keep) { - int kept = storages.getOrDefault(new ItemStorage(tuple.getA()), 0); - if (kept < keep) + if (leftOver + kept <= keep) { - if (leftOver + kept <= keep) - { - storages.put(new ItemStorage(tuple.getA()), storages.getOrDefault(new ItemStorage(tuple.getA()), 0) + tuple.getA().getCount()); - continue; - } - int toKeep = (leftOver + kept) - keep; - leftOver-=toKeep; - storages.put(new ItemStorage(tuple.getA()), storages.getOrDefault(new ItemStorage(tuple.getA()), 0) + toKeep); + storages.put(new ItemStorage(tuple.getA()), storages.getOrDefault(new ItemStorage(tuple.getA()), 0) + tuple.getA().getCount()); + continue; } + int toKeep = (leftOver + kept) - keep; + leftOver -= toKeep; + storages.put(new ItemStorage(tuple.getA()), storages.getOrDefault(new ItemStorage(tuple.getA()), 0) + toKeep); } + } - int count = Math.min(remainingCount, leftOver); - final ItemStack matchingStack = tuple.getA().copy(); - matchingStack.setCount(count); - - completedRequest.addDelivery(matchingStack); + int count = Math.min(remainingCount, leftOver); + final ItemStack matchingStack = tuple.getA().copy(); + matchingStack.setCount(count); - final ILocation itemStackLocation = manager.getFactoryController().getNewInstance(TypeConstants.ILOCATION, tuple.getB(), wareHouse.getLevel().dimension()); + completedRequest.addDelivery(matchingStack); - final Delivery delivery = - new Delivery(itemStackLocation, completedRequest.getRequester().getLocation(), matchingStack, getDefaultDeliveryPriority(true)); + final ILocation itemStackLocation = manager.getFactoryController().getNewInstance(TypeConstants.ILOCATION, tuple.getB(), wareHouse.getLevel().dimension()); + final Delivery delivery = + new Delivery(itemStackLocation, completedRequest.getRequester().getLocation(), matchingStack, getDefaultDeliveryPriority(true)); - final IToken requestToken = manager.createRequest(this, delivery); - deliveries.add(manager.getRequestForToken(requestToken)); - remainingCount -= count; - if (remainingCount <= 0) - { - break tileentities; - } - } + final IToken requestToken = manager.createRequest(this, delivery); + deliveries.add(manager.getRequestForToken(requestToken)); + remainingCount -= count; } return deliveries.isEmpty() ? null : deliveries; @@ -277,32 +266,6 @@ public void onAssignedRequestCancelled(@NotNull final IRequestManager manager, @ } - /** - * Use to get the ordered list of all warehouses. - * @param colony the colony in question. - * @return the ordered list. - */ - protected static List getWareHousesInColony(final Colony colony, final BlockPos requesterPosition) - { - final List wareHouses = new ArrayList<>(); - for (final IBuilding building : colony.getBuildingManager().getBuildings().values()) - { - if (building instanceof BuildingWareHouse && building.getTileEntity() != null) - { - wareHouses.add((TileEntityWareHouse) building.getTileEntity()); - } - } - - wareHouses.sort((w1, w2) -> - { - final double dist1 = w1.getPosition().distSqr(requesterPosition); - final double dist2 = w2.getPosition().distSqr(requesterPosition); - return Double.compare(dist1, dist2); - }); - - return wareHouses; - } - @Override public void onRequestedRequestComplete(@NotNull final IRequestManager manager, @NotNull final IRequest request) { @@ -332,4 +295,16 @@ public boolean isValid() // Always valid return true; } + + @Override + public int getSuitabilityMetric(final @NotNull IRequestManager manager, final @NotNull IRequest request) + { + final IWareHouse wareHouse = manager.getColony().getBuildingManager().getBuilding(getLocation().getInDimensionLocation(), IWareHouse.class); + final int distance = (int) BlockPosUtil.getDistance(request.getRequester().getLocation().getInDimensionLocation(), getLocation().getInDimensionLocation()); + if (wareHouse == null) + { + return distance; + } + return Math.max(distance/10, 1) + wareHouse.getModule(BuildingModules.WAREHOUSE_REQUEST_QUEUE).getMutableRequestList().size(); + } } diff --git a/src/main/java/com/minecolonies/core/tileentities/TileEntityWareHouse.java b/src/main/java/com/minecolonies/core/tileentities/TileEntityWareHouse.java index db254beaabe..45cc2f1f039 100755 --- a/src/main/java/com/minecolonies/core/tileentities/TileEntityWareHouse.java +++ b/src/main/java/com/minecolonies/core/tileentities/TileEntityWareHouse.java @@ -1,5 +1,6 @@ package com.minecolonies.core.tileentities; +import com.minecolonies.api.crafting.ItemStorage; import com.minecolonies.api.inventory.InventoryCitizen; import com.minecolonies.api.tileentities.AbstractTileEntityRack; import com.minecolonies.api.tileentities.AbstractTileEntityWareHouse; @@ -7,12 +8,9 @@ import com.minecolonies.api.util.*; import com.minecolonies.core.colony.buildings.modules.BuildingModules; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.entity.ChestBlockEntity; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.state.BlockState; -import net.neoforged.neoforge.capabilities.Capabilities.ItemHandler; -import net.neoforged.neoforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -43,8 +41,53 @@ public TileEntityWareHouse(final BlockPos pos, final BlockState state) @Override public boolean hasMatchingItemStackInWarehouse(@NotNull final Predicate itemStackSelectionPredicate, int count) { - final List> targetStacks = getMatchingItemStacksInWarehouse(itemStackSelectionPredicate); - return targetStacks.stream().mapToInt(tuple -> ItemStackUtils.getSize(tuple.getA())).sum() >= count; + int totalCount = 0; + if (getBuilding() != null) + { + for (@NotNull final BlockPos pos : getBuilding().getContainers()) + { + if (WorldUtil.isBlockLoaded(level, pos)) + { + final BlockEntity entity = getLevel().getBlockEntity(pos); + if (entity instanceof final TileEntityRack rack && !rack.isEmpty()) + { + totalCount += rack.getItemCount(itemStackSelectionPredicate); + if (totalCount >= count) + { + return true; + } + } + } + } + } + + return false; + } + + @Override + public int getCountInWarehouse(@NotNull final ItemStorage storage, int count) + { + int totalCount = 0; + if (getBuilding() != null) + { + for (@NotNull final BlockPos pos : getBuilding().getContainers()) + { + if (WorldUtil.isBlockLoaded(level, pos)) + { + final BlockEntity entity = getLevel().getBlockEntity(pos); + if (entity instanceof final TileEntityRack rack && !rack.isEmpty()) + { + totalCount += rack.getCount(storage); + if (totalCount >= count) + { + return totalCount; + } + } + } + } + } + + return totalCount; } @Override @@ -91,21 +134,15 @@ public List> getMatchingItemStacksInWarehouse(@NotNul { for (@NotNull final BlockPos pos : getBuilding().getContainers()) { - final BlockEntity entity = getLevel().getBlockEntity(pos); - if (entity instanceof final TileEntityRack rack && !rack.isEmpty() && rack.getItemCount(itemStackSelectionPredicate) > 0) + if (WorldUtil.isBlockLoaded(level, pos)) { - for (final ItemStack stack : (InventoryUtils.filterItemHandler(rack.getInventory(), itemStackSelectionPredicate))) + final BlockEntity entity = getLevel().getBlockEntity(pos); + if (entity instanceof final TileEntityRack rack && !rack.isEmpty() && rack.getItemCount(itemStackSelectionPredicate) > 0) { - found.add(new Tuple<>(stack, pos)); - } - } - - final IItemHandler cap; - if (entity instanceof ChestBlockEntity && InventoryUtils.hasItemInItemHandler((cap = ItemHandler.BLOCK.getCapability(entity.getLevel(), entity.getBlockPos(), entity.getBlockState(), entity, null)), itemStackSelectionPredicate)) - { - for (final ItemStack stack : InventoryUtils.filterItemHandler(cap, itemStackSelectionPredicate)) - { - found.add(new Tuple<>(stack, pos)); + for (final ItemStack stack : (InventoryUtils.filterItemHandler(rack.getInventory(), itemStackSelectionPredicate))) + { + found.add(new Tuple<>(stack, pos)); + } } } } From 727b8037d4c5347df9a8917af2a516241f82c16f Mon Sep 17 00:00:00 2001 From: Raycoms Date: Wed, 21 Aug 2024 20:45:32 +0200 Subject: [PATCH 5/5] Several fixes for bottles --- .../com/minecolonies/core/items/ItemLargeBottle.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/minecolonies/core/items/ItemLargeBottle.java b/src/main/java/com/minecolonies/core/items/ItemLargeBottle.java index e18968eb5bd..ee6641b7a56 100644 --- a/src/main/java/com/minecolonies/core/items/ItemLargeBottle.java +++ b/src/main/java/com/minecolonies/core/items/ItemLargeBottle.java @@ -12,7 +12,8 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.animal.Cow; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.*; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; import net.minecraft.world.phys.BlockHitResult; @@ -39,11 +40,11 @@ public ItemLargeBottle(@NotNull final Properties builder) @Override public InteractionResult interactLivingEntity(@NotNull final ItemStack stack, @NotNull final Player player, @NotNull final LivingEntity entity, @NotNull final InteractionHand hand) { - if (entity instanceof Cow && !entity.isBaby()) { + if (entity instanceof Cow && !entity.isBaby()) + { player.playSound(SoundEvents.COW_MILK, 1.0F, 1.0F); + InventoryUtils.addItemStackToItemHandler(new InvWrapper(player.getInventory()), ModItems.large_milk_bottle.getDefaultInstance()); stack.shrink(1); - final ItemStack newStack = ModItems.large_milk_bottle.getDefaultInstance(); - InventoryUtils.addItemStackToItemHandler(new InvWrapper(player.getInventory()), newStack); return InteractionResult.SUCCESS; } return super.interactLivingEntity(stack, player, entity, hand); @@ -68,9 +69,8 @@ public InteractionResultHolder use(@NotNull final Level level, final if (level.getFluidState(blockpos).is(FluidTags.WATER)) { level.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.BOTTLE_FILL, SoundSource.NEUTRAL, 1.0F, 1.0F); + InventoryUtils.addItemStackToItemHandler(new InvWrapper(player.getInventory()), ModItems.large_water_bottle.getDefaultInstance()); itemstack.shrink(1); - final ItemStack newStack = ModItems.large_water_bottle.getDefaultInstance(); - InventoryUtils.addItemStackToItemHandler(new InvWrapper(player.getInventory()), newStack); return InteractionResultHolder.success(itemstack); } }