diff --git a/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/cake_batter.json b/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/cake_batter.json index 35e2da9af25..1efb86a1507 100644 --- a/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/cake_batter.json +++ b/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/cake_batter.json @@ -19,6 +19,7 @@ } ], "intermediate": "minecraft:air", + "loot-table": "minecolonies:recipes/large_bottle", "min-building-level": 4, "result": { "id": "minecolonies:cake_batter" diff --git a/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/flatbread.json b/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/flatbread.json index 5f70372022f..53d198ff6e8 100644 --- a/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/flatbread.json +++ b/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/flatbread.json @@ -13,6 +13,7 @@ } ], "intermediate": "minecraft:air", + "loot-table": "minecolonies:recipes/large_bottle", "min-building-level": 1, "result": { "id": "minecolonies:flatbread" diff --git a/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/lembas_scone.json b/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/lembas_scone.json index 5a59bb459da..0d65dc1b9a6 100644 --- a/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/lembas_scone.json +++ b/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/lembas_scone.json @@ -13,6 +13,7 @@ } ], "intermediate": "minecraft:air", + "loot-table": "minecolonies:recipes/glass_bottle", "min-building-level": 1, "result": { "id": "minecolonies:lembas_scone" diff --git a/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/milky_bread.json b/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/milky_bread.json index 2ecab593321..1f91b7646ee 100644 --- a/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/milky_bread.json +++ b/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/milky_bread.json @@ -11,6 +11,7 @@ } ], "intermediate": "minecraft:air", + "loot-table": "minecolonies:recipes/large_bottle", "min-building-level": 4, "result": { "count": 4, diff --git a/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/scake_batter.json b/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/scake_batter.json index 25459602e8f..f8622eecb8d 100644 --- a/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/scake_batter.json +++ b/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/scake_batter.json @@ -19,6 +19,7 @@ } ], "intermediate": "minecraft:air", + "loot-table": "minecolonies:recipes/large_bottle", "min-building-level": 4, "result": { "id": "minecolonies:cake_batter" diff --git a/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/smilky_bread.json b/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/smilky_bread.json index a86fca5007c..56b6ea977de 100644 --- a/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/smilky_bread.json +++ b/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/smilky_bread.json @@ -11,6 +11,7 @@ } ], "intermediate": "minecraft:air", + "loot-table": "minecolonies:recipes/large_bottle", "min-building-level": 4, "result": { "count": 4, diff --git a/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/sugary_bread.json b/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/sugary_bread.json index f78bb71c44d..9e2eb6ee914 100644 --- a/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/sugary_bread.json +++ b/src/datagen/generated/minecolonies/data/minecolonies/crafterrecipes/baker/sugary_bread.json @@ -11,6 +11,7 @@ } ], "intermediate": "minecraft:air", + "loot-table": "minecolonies:recipes/glass_bottle", "min-building-level": 3, "result": { "count": 4, diff --git a/src/datagen/generated/minecolonies/data/minecolonies/loot_table/recipes/glass_bottle.json b/src/datagen/generated/minecolonies/data/minecolonies/loot_table/recipes/glass_bottle.json new file mode 100644 index 00000000000..68e0e0766eb --- /dev/null +++ b/src/datagen/generated/minecolonies/data/minecolonies/loot_table/recipes/glass_bottle.json @@ -0,0 +1,22 @@ +{ + "pools": [ + { + "bonus_rolls": 0.0, + "entries": [ + { + "type": "minecraft:empty", + "quality": -1, + "weight": 100 + }, + { + "type": "minecraft:item", + "name": "minecraft:glass_bottle", + "quality": 1, + "weight": 0 + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "minecolonies:recipes/glass_bottle" +} \ No newline at end of file diff --git a/src/main/java/com/minecolonies/api/util/EntityUtils.java b/src/main/java/com/minecolonies/api/util/EntityUtils.java index 9b056647114..e090f4f27fd 100755 --- a/src/main/java/com/minecolonies/api/util/EntityUtils.java +++ b/src/main/java/com/minecolonies/api/util/EntityUtils.java @@ -3,10 +3,9 @@ import com.ldtteam.structurize.util.BlockUtils; import com.minecolonies.api.crafting.ItemStorage; import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; -import com.minecolonies.core.entity.pathfinding.SurfaceType; import com.minecolonies.api.items.ModTags; +import com.minecolonies.core.entity.pathfinding.SurfaceType; import net.minecraft.core.BlockPos; -import net.minecraft.core.Vec3i; import net.minecraft.tags.BlockTags; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; @@ -325,7 +324,7 @@ public static boolean isEntityAtPosition(final Entity entity, final Level world, public static boolean isLivingAtSite(@NotNull final LivingEntity entityLiving, final int x, final int y, final int z, final int range) { final BlockPos pos = BlockPos.containing(entityLiving.getX(), entityLiving.getY(), entityLiving.getZ()); - return pos.distSqr(new Vec3i(x, y, z)) < MathUtils.square(range); + return BlockPosUtil.distSqr(pos, x, y, z) < MathUtils.square(range); } /** diff --git a/src/main/java/com/minecolonies/core/colony/buildings/modules/AbstractCraftingBuildingModule.java b/src/main/java/com/minecolonies/core/colony/buildings/modules/AbstractCraftingBuildingModule.java index 69b9d55dc7e..fac6c37a3e4 100644 --- a/src/main/java/com/minecolonies/core/colony/buildings/modules/AbstractCraftingBuildingModule.java +++ b/src/main/java/com/minecolonies/core/colony/buildings/modules/AbstractCraftingBuildingModule.java @@ -655,7 +655,8 @@ public IRecipeStorage getFirstRecipe(final Predicate stackPredicate) continue; } final IRecipeStorage storage = IColonyManager.getInstance().getRecipeManager().getRecipes().get(token); - if (storage != null && (stackPredicate.test(storage.getPrimaryOutput()) || storage.getAlternateOutputs().stream().anyMatch(stackPredicate::test))) + if (storage != null && (stackPredicate.test(storage.getPrimaryOutput()) || storage.getAlternateOutputs().stream().anyMatch(stackPredicate::test)) + && storage.getClassicForMultiOutput(stackPredicate) != null) { if(foundRecipe == null) { diff --git a/src/main/java/com/minecolonies/core/commands/colonycommands/CommandColonyInfo.java b/src/main/java/com/minecolonies/core/commands/colonycommands/CommandColonyInfo.java index 9cbfd481bf7..4055eb71444 100755 --- a/src/main/java/com/minecolonies/core/commands/colonycommands/CommandColonyInfo.java +++ b/src/main/java/com/minecolonies/core/commands/colonycommands/CommandColonyInfo.java @@ -22,7 +22,7 @@ public class CommandColonyInfo implements IMCColonyOfficerCommand { public static final String ID_TEXT = "ID: "; public static final String NAME_TEXT = "Name: "; - private static final String MAYOR_TEXT = "Mayor: "; + public static final String MAYOR_TEXT = "Mayor: "; private static final String COORDINATES_TEXT = "Coordinates: "; private static final String COORDINATES_XYZ = "x=%s y=%s z=%s"; private static final String CITIZENS = "Citizens: "; @@ -54,7 +54,7 @@ public int onExecute(final CommandContext context) } final BlockPos position = colony.getCenter(); - context.getSource().sendSuccess(() -> Component.literal(ID_TEXT + colony.getID() + NAME_TEXT + colony.getName()), true); + context.getSource().sendSuccess(() -> Component.literal(ID_TEXT + colony.getID() + " " + NAME_TEXT + colony.getName()), true); final String mayor = colony.getPermissions().getOwnerName(); context.getSource().sendSuccess(() -> Component.literal(MAYOR_TEXT + mayor), true); context.getSource() @@ -63,7 +63,6 @@ public int onExecute(final CommandContext context) .sendSuccess(() -> Component.literal(COORDINATES_TEXT + String.format(COORDINATES_XYZ, position.getX(), position.getY(), position.getZ())).setStyle(Style.EMPTY.withColor( ChatFormatting.GREEN)), true); context.getSource().sendSuccess(() -> Component.literal(String.format(LAST_CONTACT_TEXT, colony.getLastContactInHours())), true); - context.getSource().sendSuccess(() -> Component.literal(IS_DELETABLE + !colony.canBeAutoDeleted()), true); if (!colony.getRaiderManager().canHaveRaiderEvents()) { diff --git a/src/main/java/com/minecolonies/core/commands/colonycommands/CommandListColonies.java b/src/main/java/com/minecolonies/core/commands/colonycommands/CommandListColonies.java index 3b28cc4b5de..f2745ebafd3 100755 --- a/src/main/java/com/minecolonies/core/commands/colonycommands/CommandListColonies.java +++ b/src/main/java/com/minecolonies/core/commands/colonycommands/CommandListColonies.java @@ -6,17 +6,18 @@ import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; +import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; import java.util.ArrayList; import java.util.List; -import net.minecraft.ChatFormatting; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.network.chat.Style; +import static com.minecolonies.core.commands.colonycommands.CommandColonyInfo.MAYOR_TEXT; public class CommandListColonies implements IMCCommand { @@ -98,7 +99,8 @@ private int executeCommand(final CommandContext context, fin for (final IColony colony : coloniesPage) { context.getSource().sendSuccess(() -> Component.literal(String.format( - ID_AND_NAME_TEXT, colony.getID(), colony.getName())).setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, + ID_AND_NAME_TEXT, colony.getID(), colony.getName()) + " " + MAYOR_TEXT + colony.getPermissions().getOwnerName()) + .setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(COMMAND_COLONY_INFO, colony.getID())))), true); final BlockPos center = colony.getCenter(); diff --git a/src/main/java/com/minecolonies/core/commands/colonycommands/CommandSetDeletable.java b/src/main/java/com/minecolonies/core/commands/colonycommands/CommandSetDeletable.java index f0d4d18322c..69227ba733d 100755 --- a/src/main/java/com/minecolonies/core/commands/colonycommands/CommandSetDeletable.java +++ b/src/main/java/com/minecolonies/core/commands/colonycommands/CommandSetDeletable.java @@ -15,6 +15,7 @@ import static com.minecolonies.api.util.constant.translation.CommandTranslationConstants.COMMAND_COLONY_ID_NOT_FOUND; import static com.minecolonies.core.commands.CommandArgumentNames.COLONYID_ARG; +// TODO: Unused, maybe drop or add an auto delete feature public class CommandSetDeletable implements IMCOPCommand { diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/builder/EntityAIStructureBuilder.java b/src/main/java/com/minecolonies/core/entity/ai/workers/builder/EntityAIStructureBuilder.java index a40a49b4512..f76e4119c39 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/builder/EntityAIStructureBuilder.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/builder/EntityAIStructureBuilder.java @@ -212,10 +212,11 @@ public boolean walkToConstructionSite(final BlockPos currentBlock) final PathJobMoveCloseToXNearY pathJob = new PathJobMoveCloseToXNearY(world, currentBlock, job.getWorkOrder().getLocation(), - 5, + 4, worker); gotoPath = ((MinecoloniesAdvancedPathNavigate) worker.getNavigation()).setPathJob(pathJob, currentBlock, 1.0, false); pathJob.getPathingOptions().dropCost = 200; + pathJob.extraNodes = 0; } else if (gotoPath.isDone()) { diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIStudy.java b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIStudy.java index dc75056f0f7..3b389599029 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIStudy.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIStudy.java @@ -10,10 +10,11 @@ import com.minecolonies.core.colony.buildings.workerbuildings.BuildingLibrary; import com.minecolonies.core.colony.jobs.JobStudent; import com.minecolonies.core.entity.ai.workers.AbstractEntityAISkill; +import com.minecolonies.core.entity.pathfinding.navigation.PathfindingAIHelper; +import net.minecraft.core.BlockPos; import net.minecraft.sounds.SoundEvents; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.InteractionHand; -import net.minecraft.core.BlockPos; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import org.jetbrains.annotations.NotNull; @@ -108,7 +109,7 @@ private IAIState study() studyPos = building.getRandomBookShelf(); } - if (walkToBlock(studyPos)) + if (PathfindingAIHelper.walkCloseToXNearY(worker, studyPos, building.getPosition(), 7)) { setDelay(WALK_DELAY); return getState(); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkResearcher.java b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkResearcher.java index f3decd0ca28..976acb9d692 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkResearcher.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkResearcher.java @@ -7,6 +7,7 @@ import com.minecolonies.core.colony.buildings.workerbuildings.BuildingUniversity; import com.minecolonies.core.colony.jobs.JobResearch; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract; +import com.minecolonies.core.entity.pathfinding.navigation.PathfindingAIHelper; import net.minecraft.core.BlockPos; import net.minecraft.sounds.SoundEvents; import org.jetbrains.annotations.NotNull; @@ -67,7 +68,7 @@ private IAIState study() studyPos = building.getRandomBookShelf(); } - if (walkToBlock(studyPos)) + if (PathfindingAIHelper.walkCloseToXNearY(worker, studyPos, building.getPosition(), 7)) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java b/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java index a30a0b006e6..627ebffd6ac 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java @@ -27,9 +27,6 @@ import com.minecolonies.api.entity.citizen.citizenhandlers.*; import com.minecolonies.api.entity.citizen.happiness.ExpirationBasedHappinessModifier; import com.minecolonies.api.entity.citizen.happiness.StaticHappinessSupplier; -import com.minecolonies.api.util.constant.TranslationConstants; -import com.minecolonies.core.entity.ai.minimal.EntityAIFloat; -import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import com.minecolonies.api.entity.pathfinding.proxy.IWalkToProxy; import com.minecolonies.api.inventory.InventoryCitizen; import com.minecolonies.api.inventory.container.ContainerCitizenInventory; @@ -38,6 +35,7 @@ import com.minecolonies.api.util.*; import com.minecolonies.api.util.MessageUtils.MessagePriority; import com.minecolonies.api.util.constant.HappinessConstants; +import com.minecolonies.api.util.constant.TranslationConstants; import com.minecolonies.api.util.constant.TypeConstants; import com.minecolonies.core.MineColonies; import com.minecolonies.core.client.gui.WindowInteraction; @@ -50,14 +48,16 @@ import com.minecolonies.core.colony.jobs.JobNetherWorker; import com.minecolonies.core.colony.jobs.JobRanger; import com.minecolonies.core.entity.ai.minimal.EntityAICitizenChild; +import com.minecolonies.core.entity.ai.minimal.EntityAIFloat; import com.minecolonies.core.entity.ai.minimal.EntityAIInteractToggleAble; import com.minecolonies.core.entity.ai.minimal.LookAtEntityGoal; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIBasic; import com.minecolonies.core.entity.ai.workers.CitizenAI; import com.minecolonies.core.entity.ai.workers.guard.AbstractEntityAIGuard; import com.minecolonies.core.entity.citizen.citizenhandlers.*; -import com.minecolonies.core.entity.pathfinding.proxy.EntityCitizenWalkToProxy; import com.minecolonies.core.entity.pathfinding.navigation.MovementHandler; +import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; +import com.minecolonies.core.entity.pathfinding.proxy.EntityCitizenWalkToProxy; import com.minecolonies.core.event.EventHandler; import com.minecolonies.core.network.messages.client.ItemParticleEffectMessage; import com.minecolonies.core.network.messages.client.VanillaParticleMessage; @@ -68,6 +68,8 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.syncher.EntityDataAccessor; @@ -94,7 +96,10 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.item.*; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.ShieldItem; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; @@ -1868,12 +1873,22 @@ public void setTexture() @Override public void queueSound(@NotNull final SoundEvent soundEvent, final BlockPos pos, final int length, final int repetitions) { + if (soundEvent == null || !BuiltInRegistries.SOUND_EVENT.containsKey(soundEvent.getLocation())) + { + return; + } + new PlaySoundForCitizenMessage(this.getId(), soundEvent, this.getSoundSource(), pos, level(), length, repetitions).sendToTargetPoint((ServerLevel) level(), null, pos.getX(), pos.getY(), pos.getZ(), BLOCK_BREAK_SOUND_RANGE); } @Override public void queueSound(@NotNull final SoundEvent soundEvent, final BlockPos pos, final int length, final int repetitions, final float volume, final float pitch) { + if (soundEvent == null || !BuiltInRegistries.SOUND_EVENT.containsKey(soundEvent.getLocation())) + { + return; + } + new PlaySoundForCitizenMessage(this.getId(), soundEvent, this.getSoundSource(), pos, level(), volume, pitch, length, repetitions).sendToTargetPoint( (ServerLevel) level(), null, pos.getX(), pos.getY(), pos.getZ(), BLOCK_BREAK_SOUND_RANGE); } diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/AbstractAdvancedPathNavigate.java b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/AbstractAdvancedPathNavigate.java index b10f83e2bb1..69d0cc2eed1 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/AbstractAdvancedPathNavigate.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/AbstractAdvancedPathNavigate.java @@ -4,12 +4,10 @@ import com.minecolonies.api.crafting.ItemStorage; import com.minecolonies.api.entity.pathfinding.IPathJob; import com.minecolonies.api.entity.pathfinding.IStuckHandler; -import com.minecolonies.api.util.Tuple; import com.minecolonies.core.entity.pathfinding.PathingOptions; import com.minecolonies.core.entity.pathfinding.pathjobs.AbstractPathJob; import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import com.minecolonies.core.entity.pathfinding.pathresults.TreePathResult; -import com.minecolonies.core.entity.pathfinding.pathresults.WaterPathResult; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Mob; @@ -216,4 +214,11 @@ public Mob getOurEntity() * @param pauseTicks */ protected abstract void setPauseTicks(int pauseTicks); + + /** + * Gets the current path result + * + * @return + */ + public abstract PathResult getPathResult(); } 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 fc5553cccd0..1ec33e530c2 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 @@ -1177,4 +1177,10 @@ public void setPauseTicks(final int pauseTicks) this.pauseTicks = pauseTicks; } } + + @Override + public PathResult getPathResult() + { + return pathResult; + } } diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/PathfindingAIHelper.java b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/PathfindingAIHelper.java new file mode 100644 index 00000000000..e1ab74e97f6 --- /dev/null +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/PathfindingAIHelper.java @@ -0,0 +1,44 @@ +package com.minecolonies.core.entity.pathfinding.navigation; + +import com.minecolonies.api.entity.other.AbstractFastMinecoloniesEntity; +import com.minecolonies.api.util.BlockPosUtil; +import com.minecolonies.core.entity.pathfinding.pathjobs.PathJobMoveCloseToXNearY; +import net.minecraft.core.BlockPos; + +public class PathfindingAIHelper +{ + /** + * Tries to walk close to a given pos, staying near another position. + * + * @param entity + * @param desiredPosition + * @param nearbyPosition + * @param distToDesired + * @return True while walking, false when reached + */ + public static boolean walkCloseToXNearY( + final AbstractFastMinecoloniesEntity entity, final BlockPos desiredPosition, + final BlockPos nearbyPosition, + final int distToDesired) + { + final MinecoloniesAdvancedPathNavigate nav = ((MinecoloniesAdvancedPathNavigate) entity.getNavigation()); + + if (nav.isDone() || (nav.getPathResult() != null + && !(nav.getPathResult().getJob() instanceof PathJobMoveCloseToXNearY job + && job.nearbyPosition.equals(nearbyPosition) + && job.desiredPosition.equals(desiredPosition) + && job.distToDesired == distToDesired))) + { + // Check distance once navigation is done, to let the entity walk + if (BlockPosUtil.dist(entity.blockPosition(), desiredPosition) < distToDesired) + { + return false; + } + + PathJobMoveCloseToXNearY pathJob = new PathJobMoveCloseToXNearY(entity.level(), desiredPosition, nearbyPosition, distToDesired, entity); + nav.setPathJob(pathJob, desiredPosition, 1.0, false); + } + + return true; + } +} 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 f44aa1acb53..e63d177df65 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 @@ -112,7 +112,7 @@ public abstract class AbstractPathJob implements Callable, IPathJob * Additional nodes that get explored when reaching the target, useful when the destination is an area or not in a great spot. * Pathjobs may increase this value as they see fit */ - protected int extraNodes = 0; + public int extraNodes = 0; /** * Debug settings @@ -762,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, isDiving, onRoad, onRails, railsExit, swimStart, ladder, state, belowState, nextX, nextY, nextZ); + nextCost = computeCost(costFrom, dX, dY, dZ, isSwimming, onRoad, isDiving, onRails, railsExit, swimStart, ladder, state, belowState, nextX, nextY, nextZ); nextCost = modifyCost(nextCost, costFrom, swimStart, isSwimming, nextX, nextY, nextZ, state, belowState); if (nextCost > maxCost) @@ -895,6 +895,11 @@ protected double computeCost( { double cost = 1; + if (pathingOptions.randomnessFactor > 0.0d) + { + cost += ColonyConstants.rand.nextDouble() * pathingOptions.randomnessFactor; + } + if (!isSwimming) { if (onPath) @@ -907,11 +912,6 @@ protected double computeCost( } } - if (pathingOptions.randomnessFactor > 0.0d) - { - cost += ColonyConstants.rand.nextDouble() * pathingOptions.randomnessFactor; - } - if (state.getBlock() == Blocks.CAVE_AIR) { cost += pathingOptions.caveAirCost; diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveAwayFromLocation.java b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveAwayFromLocation.java index b12fd50eacf..c63f0cfcfc8 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveAwayFromLocation.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveAwayFromLocation.java @@ -2,12 +2,13 @@ import com.minecolonies.api.colony.IColony; import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; -import com.minecolonies.core.entity.pathfinding.SurfaceType; -import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import com.minecolonies.api.util.BlockPosUtil; import com.minecolonies.api.util.Log; import com.minecolonies.core.MineColonies; import com.minecolonies.core.entity.pathfinding.MNode; +import com.minecolonies.core.entity.pathfinding.PathingOptions; +import com.minecolonies.core.entity.pathfinding.SurfaceType; +import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Mob; import net.minecraft.world.level.Level; @@ -145,4 +146,11 @@ protected double getEndNodeScore(@NotNull final MNode n) { return -BlockPosUtil.dist(avoid, n.x, n.y, n.z); } + + @Override + public void setPathingOptions(final PathingOptions pathingOptions) + { + super.setPathingOptions(pathingOptions); + pathingOptions.dropCost = 5; + } } diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveCloseToXNearY.java b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveCloseToXNearY.java index 690b382acc2..4ce22b2ada0 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveCloseToXNearY.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveCloseToXNearY.java @@ -1,7 +1,6 @@ package com.minecolonies.core.entity.pathfinding.pathjobs; import com.minecolonies.api.util.BlockPosUtil; -import com.minecolonies.api.util.ShapeUtil; import com.minecolonies.core.entity.pathfinding.MNode; import com.minecolonies.core.entity.pathfinding.PathfindingUtils; import com.minecolonies.core.entity.pathfinding.SurfaceType; @@ -20,17 +19,17 @@ public class PathJobMoveCloseToXNearY extends AbstractPathJob /** * Position to go close to */ - protected final BlockPos desiredPosition; + public final BlockPos desiredPosition; /** * Position to stay nearby */ - protected final BlockPos nearbyPosition; + public final BlockPos nearbyPosition; /** * Required distance to reach */ - protected final int distToDesired; + public final int distToDesired; public PathJobMoveCloseToXNearY( final Level world, diff --git a/src/main/java/com/minecolonies/core/generation/defaults/workers/DefaultBakerCraftingProvider.java b/src/main/java/com/minecolonies/core/generation/defaults/workers/DefaultBakerCraftingProvider.java index 2b409590378..e7270d1f616 100644 --- a/src/main/java/com/minecolonies/core/generation/defaults/workers/DefaultBakerCraftingProvider.java +++ b/src/main/java/com/minecolonies/core/generation/defaults/workers/DefaultBakerCraftingProvider.java @@ -77,6 +77,7 @@ protected void registerRecipes(@NotNull final Consumer cons .inputs(List.of(new ItemStorage(new ItemStack(Items.WHEAT, 8)), new ItemStorage(new ItemStack(Items.HONEY_BOTTLE)))) .result(new ItemStack(ModItems.sugaryBread, 4)) + .lootTable(DefaultRecipeLootProvider.LOOT_TABLE_GLASS_BOTTLE) .minBuildingLevel(3) .showTooltip(true) .build(consumer); @@ -85,17 +86,19 @@ protected void registerRecipes(@NotNull final Consumer cons .inputs(List.of(new ItemStorage(new ItemStack(Items.WHEAT, 8)), new ItemStorage(new ItemStack(ModItems.large_milk_bottle)))) .result(new ItemStack(ModItems.milkyBread, 4)) + .lootTable(DefaultRecipeLootProvider.LOOT_TABLE_LARGE_BOTTLE) .minBuildingLevel(4) .showTooltip(true) .build(consumer); recipe(BAKER, MODULE_CRAFTING, "smilky_bread") - .inputs(List.of(new ItemStorage(new ItemStack(Items.WHEAT, 8)), - new ItemStorage(new ItemStack(ModItems.large_soy_milk_bottle)))) - .result(new ItemStack(ModItems.milkyBread, 4)) - .minBuildingLevel(4) - .showTooltip(true) - .build(consumer); + .inputs(List.of(new ItemStorage(new ItemStack(Items.WHEAT, 8)), + new ItemStorage(new ItemStack(ModItems.large_soy_milk_bottle)))) + .result(new ItemStack(ModItems.milkyBread, 4)) + .lootTable(DefaultRecipeLootProvider.LOOT_TABLE_LARGE_BOTTLE) + .minBuildingLevel(4) + .showTooltip(true) + .build(consumer); recipe(BAKER, MODULE_CRAFTING, "golden_bread") .inputs(List.of(new ItemStorage(new ItemStack(Items.WHEAT, 8)), @@ -150,19 +153,21 @@ protected void registerRecipes(@NotNull final Consumer cons new ItemStorage(new ItemStack(Items.SUGAR, 2)), new ItemStorage(new ItemStack(Items.EGG)))) .result(new ItemStack(ModItems.cakeBatter)) + .lootTable(DefaultRecipeLootProvider.LOOT_TABLE_LARGE_BOTTLE) .minBuildingLevel(4) .showTooltip(true) .build(consumer); recipe(BAKER, MODULE_CRAFTING, "scake_batter") - .inputs(List.of(new ItemStorage(new ItemStack(Items.WHEAT, 3)), - new ItemStorage(new ItemStack(ModItems.large_soy_milk_bottle, 3)), - new ItemStorage(new ItemStack(Items.SUGAR, 2)), - new ItemStorage(new ItemStack(Items.EGG)))) - .result(new ItemStack(ModItems.cakeBatter)) - .minBuildingLevel(4) - .showTooltip(true) - .build(consumer); + .inputs(List.of(new ItemStorage(new ItemStack(Items.WHEAT, 3)), + new ItemStorage(new ItemStack(ModItems.large_soy_milk_bottle, 3)), + new ItemStorage(new ItemStack(Items.SUGAR, 2)), + new ItemStorage(new ItemStack(Items.EGG)))) + .result(new ItemStack(ModItems.cakeBatter)) + .lootTable(DefaultRecipeLootProvider.LOOT_TABLE_LARGE_BOTTLE) + .minBuildingLevel(4) + .showTooltip(true) + .build(consumer); recipe(BAKER, MODULE_SMELTING, "cake") .inputs(List.of(new ItemStorage(new ItemStack(ModItems.cakeBatter)))) @@ -172,60 +177,62 @@ protected void registerRecipes(@NotNull final Consumer cons .build(consumer); recipe(BAKER, MODULE_CRAFTING, "lembas_scone") - .inputs(List.of( - new ItemStorage(new ItemStack(ModBlocks.blockDurum)), - new ItemStorage(new ItemStack(ModItems.butter)), - new ItemStorage(new ItemStack(Items.HONEY_BOTTLE)))) - .result(new ItemStack(ModItems.lembas_scone)) - .minBuildingLevel(1) - .build(consumer); + .inputs(List.of( + new ItemStorage(new ItemStack(ModBlocks.blockDurum)), + new ItemStorage(new ItemStack(ModItems.butter)), + new ItemStorage(new ItemStack(Items.HONEY_BOTTLE)))) + .result(new ItemStack(ModItems.lembas_scone)) + .lootTable(DefaultRecipeLootProvider.LOOT_TABLE_GLASS_BOTTLE) + .minBuildingLevel(1) + .build(consumer); recipe(BAKER, MODULE_CRAFTING, "manchet_dough") - .inputs(List.of( - new ItemStorage(new ItemStack(ModBlocks.blockDurum)), - new ItemStorage(new ItemStack(ModBlocks.blockDurum)), - new ItemStorage(new ItemStack(ModItems.butter)))) - .result(new ItemStack(ModItems.manchet_dough, 2)) - .minBuildingLevel(1) - .build(consumer); + .inputs(List.of( + new ItemStorage(new ItemStack(ModBlocks.blockDurum)), + new ItemStorage(new ItemStack(ModBlocks.blockDurum)), + new ItemStorage(new ItemStack(ModItems.butter)))) + .result(new ItemStack(ModItems.manchet_dough, 2)) + .minBuildingLevel(1) + .build(consumer); recipe(BAKER, MODULE_CRAFTING, "muffin_dough") - .inputs(List.of( - new ItemStorage(new ItemStack(ModBlocks.blockDurum)), - new ItemStorage(new ItemStack(ModBlocks.blockDurum)), - new ItemStorage(new ItemStack(ModItems.butter)), - new ItemStorage(new ItemStack(Items.SUGAR)), - new ItemStorage(new ItemStack(Items.SWEET_BERRIES)))) - .result(new ItemStack(ModItems.muffin_dough, 2)) - .minBuildingLevel(1) - .build(consumer); + .inputs(List.of( + new ItemStorage(new ItemStack(ModBlocks.blockDurum)), + new ItemStorage(new ItemStack(ModBlocks.blockDurum)), + new ItemStorage(new ItemStack(ModItems.butter)), + new ItemStorage(new ItemStack(Items.SUGAR)), + new ItemStorage(new ItemStack(Items.SWEET_BERRIES)))) + .result(new ItemStack(ModItems.muffin_dough, 2)) + .minBuildingLevel(1) + .build(consumer); recipe(BAKER, MODULE_CRAFTING, "flatbread") - .inputs(List.of( - new ItemStorage(new ItemStack(ModBlocks.blockDurum)), - new ItemStorage(new ItemStack(ModBlocks.blockDurum)), - new ItemStorage(ModItems.large_water_bottle.getDefaultInstance()))) - .result(new ItemStack(ModItems.flatbread, 1)) - .minBuildingLevel(1) - .build(consumer); + .inputs(List.of( + new ItemStorage(new ItemStack(ModBlocks.blockDurum)), + new ItemStorage(new ItemStack(ModBlocks.blockDurum)), + new ItemStorage(ModItems.large_water_bottle.getDefaultInstance()))) + .result(new ItemStack(ModItems.flatbread, 1)) + .lootTable(DefaultRecipeLootProvider.LOOT_TABLE_LARGE_BOTTLE) + .minBuildingLevel(1) + .build(consumer); recipe(BAKER, MODULE_SMELTING, "muffin") - .inputs(List.of(new ItemStorage(new ItemStack(ModItems.muffin_dough)))) - .result(new ItemStack(ModItems.muffin)) - .minBuildingLevel(1) - .intermediate(Blocks.FURNACE) - .build(consumer); + .inputs(List.of(new ItemStorage(new ItemStack(ModItems.muffin_dough)))) + .result(new ItemStack(ModItems.muffin)) + .minBuildingLevel(1) + .intermediate(Blocks.FURNACE) + .build(consumer); recipe(BAKER, MODULE_SMELTING, "manchet") - .inputs(List.of(new ItemStorage(new ItemStack(ModItems.manchet_dough)))) - .result(new ItemStack(ModItems.manchet_bread)) - .minBuildingLevel(1) - .intermediate(Blocks.FURNACE) - .build(consumer); + .inputs(List.of(new ItemStorage(new ItemStack(ModItems.manchet_dough)))) + .result(new ItemStack(ModItems.manchet_bread)) + .minBuildingLevel(1) + .intermediate(Blocks.FURNACE) + .build(consumer); recipe(BAKER, MODULE_CRAFTING, "water_jug") - .inputs(List.of(new ItemStorage(new ItemStack(ModItems.large_empty_bottle)))) - .result(ModItems.large_water_bottle.getDefaultInstance()) - .build(consumer); + .inputs(List.of(new ItemStorage(new ItemStack(ModItems.large_empty_bottle)))) + .result(ModItems.large_water_bottle.getDefaultInstance()) + .build(consumer); } } diff --git a/src/main/java/com/minecolonies/core/generation/defaults/workers/DefaultRecipeLootProvider.java b/src/main/java/com/minecolonies/core/generation/defaults/workers/DefaultRecipeLootProvider.java index 5d0e4c5efb1..211190e86b8 100644 --- a/src/main/java/com/minecolonies/core/generation/defaults/workers/DefaultRecipeLootProvider.java +++ b/src/main/java/com/minecolonies/core/generation/defaults/workers/DefaultRecipeLootProvider.java @@ -11,6 +11,7 @@ import net.minecraft.world.level.storage.loot.LootTable; import net.minecraft.world.level.storage.loot.entries.EmptyLootItem; import net.minecraft.world.level.storage.loot.entries.LootItem; +import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; import org.jetbrains.annotations.NotNull; import java.util.function.BiConsumer; @@ -23,17 +24,23 @@ */ public class DefaultRecipeLootProvider implements LootTableSubProvider { + public static final ResourceLocation LOOT_TABLE_GLASS_BOTTLE = new ResourceLocation(MOD_ID, "recipes/glass_bottle"); + public static final ResourceLocation LOOT_TABLE_LARGE_BOTTLE = new ResourceLocation(MOD_ID, "recipes/large_bottle"); + public static final ResourceLocation LOOT_TABLE_GRAVEL = new ResourceLocation(MOD_ID, "recipes/gravel"); + public DefaultRecipeLootProvider(@NotNull final HolderLookup.Provider provider) { } - public static final ResourceLocation LOOT_TABLE_LARGE_BOTTLE = new ResourceLocation(MOD_ID, "recipes/large_bottle"); - public static final ResourceLocation LOOT_TABLE_GRAVEL = new ResourceLocation(MOD_ID, "recipes/gravel"); - @Override public void generate(final BiConsumer, LootTable.Builder> generator) { + generator.accept(ResourceKey.create(Registries.LOOT_TABLE, LOOT_TABLE_GLASS_BOTTLE), LootTable.lootTable() + .withPool(LootPool.lootPool() + .add(EmptyLootItem.emptyItem().setWeight(100).setQuality(-1)) + .add(LootItem.lootTableItem(Items.GLASS_BOTTLE).setWeight(0).setQuality(1)))); + generator.accept(ResourceKey.create(Registries.LOOT_TABLE, LOOT_TABLE_LARGE_BOTTLE), LootTable.lootTable() .withPool(LootPool.lootPool() .add(EmptyLootItem.emptyItem().setWeight(100).setQuality(-1)) diff --git a/src/main/java/com/minecolonies/core/items/ItemResourceScroll.java b/src/main/java/com/minecolonies/core/items/ItemResourceScroll.java index 23aa8a31b4f..122c08c8f46 100644 --- a/src/main/java/com/minecolonies/core/items/ItemResourceScroll.java +++ b/src/main/java/com/minecolonies/core/items/ItemResourceScroll.java @@ -13,6 +13,7 @@ import com.minecolonies.core.colony.buildings.workerbuildings.BuildingBuilder; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingWareHouse; import com.minecolonies.core.network.messages.server.ResourceScrollSaveWarehouseSnapshotMessage; +import com.minecolonies.core.tileentities.TileEntityRack; import com.minecolonies.core.tileentities.TileEntityWareHouse; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; @@ -237,7 +238,7 @@ else if (buildingEntity.getBuilding() instanceof BuildingWareHouse) { MessageUtils.format(COM_MINECOLONIES_SCROLL_SNAPSHOT).sendTo(ctx.getPlayer()); } - else + else if (buildingEntity.getBuilding() != null) { final MutableComponent buildingTypeComponent = MessageUtils.format(buildingEntity.getBuilding().getBuildingType().getTranslationKey()).create(); MessageUtils.format(COM_MINECOLONIES_SCROLL_WRONG_BUILDING, buildingTypeComponent, buildingEntity.getColony().getName()).sendTo(ctx.getPlayer()); diff --git a/src/main/java/com/minecolonies/core/network/messages/client/colony/PlaySoundForCitizenMessage.java b/src/main/java/com/minecolonies/core/network/messages/client/colony/PlaySoundForCitizenMessage.java index 9facc376c9c..af0a26f4090 100644 --- a/src/main/java/com/minecolonies/core/network/messages/client/colony/PlaySoundForCitizenMessage.java +++ b/src/main/java/com/minecolonies/core/network/messages/client/colony/PlaySoundForCitizenMessage.java @@ -144,14 +144,14 @@ public PlaySoundForCitizenMessage(final int entityID, final SoundEvent event, fi protected void toBytes(final RegistryFriendlyByteBuf buf) { buf.writeResourceLocation(BuiltInRegistries.SOUND_EVENT.getKey(this.soundEvent)); - buf.writeInt(this.soundSource.ordinal()); - buf.writeBlockPos(this.pos); - buf.writeUtf(this.dimensionID.location().toString()); - buf.writeFloat(this.volume); - buf.writeFloat(this.pitch); - buf.writeInt(this.length); - buf.writeInt(this.repetitions); - buf.writeInt(this.entityid); + buf.writeInt(soundSource.ordinal()); + buf.writeBlockPos(pos); + buf.writeUtf(dimensionID.location().toString()); + buf.writeFloat(volume); + buf.writeFloat(pitch); + buf.writeInt(length); + buf.writeInt(repetitions); + buf.writeInt(entityid); } public PlaySoundForCitizenMessage(final RegistryFriendlyByteBuf buf, final PlayMessageType type) diff --git a/src/main/java/com/minecolonies/core/network/messages/server/GetColonyInfoMessage.java b/src/main/java/com/minecolonies/core/network/messages/server/GetColonyInfoMessage.java index a3db8345736..5c77fc3ee3b 100755 --- a/src/main/java/com/minecolonies/core/network/messages/server/GetColonyInfoMessage.java +++ b/src/main/java/com/minecolonies/core/network/messages/server/GetColonyInfoMessage.java @@ -22,7 +22,7 @@ import net.neoforged.neoforge.network.handling.IPayloadContext; import static com.minecolonies.api.util.constant.BuildingConstants.DEACTIVATED; -import static com.minecolonies.api.util.constant.TranslationConstants.*; +import static com.minecolonies.api.util.constant.TranslationConstants.HUT_BLOCK_MISSING_BUILDING; import static com.minecolonies.core.MineColonies.getConfig; /** @@ -99,6 +99,11 @@ else if (world.getBlockEntity(pos) instanceof TileEntityColonyBuilding townhall } else { + if (nextColony == null) + { + return; + } + final int blockRange = Math.max(MineColonies.getConfig().getServer().minColonyDistance.get(), getConfig().getServer().initialColonySize.get()) << 4; final int distance = (int) BlockPosUtil.getDistance(pos, nextColony.getCenter());