Skip to content

Commit

Permalink
Merge branch 'version/1.21' into final-datacomps
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightenom committed Aug 25, 2024
2 parents 702c905 + d8c7738 commit bc29cfe
Show file tree
Hide file tree
Showing 28 changed files with 238 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
}
],
"intermediate": "minecraft:air",
"loot-table": "minecolonies:recipes/large_bottle",
"min-building-level": 4,
"result": {
"id": "minecolonies:cake_batter"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
}
],
"intermediate": "minecraft:air",
"loot-table": "minecolonies:recipes/large_bottle",
"min-building-level": 1,
"result": {
"id": "minecolonies:flatbread"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
}
],
"intermediate": "minecraft:air",
"loot-table": "minecolonies:recipes/glass_bottle",
"min-building-level": 1,
"result": {
"id": "minecolonies:lembas_scone"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
}
],
"intermediate": "minecraft:air",
"loot-table": "minecolonies:recipes/large_bottle",
"min-building-level": 4,
"result": {
"count": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
}
],
"intermediate": "minecraft:air",
"loot-table": "minecolonies:recipes/large_bottle",
"min-building-level": 4,
"result": {
"id": "minecolonies:cake_batter"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
}
],
"intermediate": "minecraft:air",
"loot-table": "minecolonies:recipes/large_bottle",
"min-building-level": 4,
"result": {
"count": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
}
],
"intermediate": "minecraft:air",
"loot-table": "minecolonies:recipes/glass_bottle",
"min-building-level": 3,
"result": {
"count": 4,
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
5 changes: 2 additions & 3 deletions src/main/java/com/minecolonies/api/util/EntityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,8 @@ public IRecipeStorage getFirstRecipe(final Predicate<ItemStack> 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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: ";
Expand Down Expand Up @@ -54,7 +54,7 @@ public int onExecute(final CommandContext<CommandSourceStack> 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()
Expand All @@ -63,7 +63,6 @@ public int onExecute(final CommandContext<CommandSourceStack> 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())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -98,7 +99,8 @@ private int executeCommand(final CommandContext<CommandSourceStack> 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,7 +68,7 @@ private IAIState study()
studyPos = building.getRandomBookShelf();
}

if (walkToBlock(studyPos))
if (PathfindingAIHelper.walkCloseToXNearY(worker, studyPos, building.getPosition(), 7))
{
return getState();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -1177,4 +1177,10 @@ public void setPauseTicks(final int pauseTicks)
this.pauseTicks = pauseTicks;
}
}

@Override
public PathResult getPathResult()
{
return pathResult;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit bc29cfe

Please sign in to comment.