Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fisher pathfinding #10436

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -52,7 +53,7 @@ public abstract class AbstractFastMinecoloniesEntity extends PathfinderMob imple
/**
* Entity push cache.
*/
private List<Entity> entityPushCache = new ArrayList<>();
private List<LivingEntity> entityPushCache = new ArrayList<>();

/**
* The timepoint at which the entity last collided
Expand Down Expand Up @@ -171,7 +172,7 @@ public void pushEntities()
{
if (this.tickCount % 10 == randomVariance % 10)
{
entityPushCache = this.level.getEntities(this, this.getBoundingBox(), EntityUtils.pushableBy());
entityPushCache = level.getEntitiesOfClass(LivingEntity.class, getBoundingBox());
}

if (!entityPushCache.isEmpty())
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/minecolonies/api/util/ShapeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ public static boolean hasCollision(final BlockGetter world, final BlockPos pos,
return hasCollision(state, state.getCollisionShape(world, pos));
}

/**
* Check if the given block has a collision shape
*
* @param world
* @param pos
* @param state
* @return
*/
public static boolean hasCollision(final BlockGetter world, final int x, final int y, final int z, final BlockState state)
{
if (!state.getBlock().hasCollision)
{
return false;
}

return hasCollision(state, state.getCollisionShape(world, new BlockPos(x, y, z)));
}

/**
* Check if the given block has a collision shape
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public CompoundTag serializeNBT()

compound.putInt(TAG_HEIGHT, this.height);

compound.putInt(TAG_ROTATION, getRotation());
compound.putInt(TAG_ROTATION, cachedRotation);

compound.putBoolean(TAG_DECONSTRUCTED, isDeconstructed);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ public int calculateRaiderAmount(final int raidLevel)
(int) ((raidLevel / SPAWN_MODIFIER)
* getRaidDifficultyModifier()
* (1.0 + nearbyColonyPlayers * INCREASE_PER_PLAYER)
* ((ColonyConstants.rand.nextDouble() * 0.5d) + 0.75)));
* ((ColonyConstants.rand.nextDouble() * 0.3) + 0.85)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.reflect.TypeToken;
import com.ldtteam.structurize.util.BlockUtils;
import com.minecolonies.api.colony.ICitizenData;
import com.minecolonies.api.colony.buildings.IBuilding;
import com.minecolonies.api.colony.interactionhandling.ChatPriority;
Expand Down Expand Up @@ -48,7 +47,6 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.ChestBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
Expand Down Expand Up @@ -216,7 +214,7 @@ protected AbstractEntityAIBasic(@NotNull final J job)
to resolve state.
*/
new AIEventTarget(AIBlockingEventType.STATE_BLOCKING, this::inventoryNeedsDump, INVENTORY_FULL, 100),
new AITarget(INVENTORY_FULL, this::dumpInventory, 10),
new AITarget(INVENTORY_FULL, this::dumpInventory, 20),
/*
Check if any items are needed.
If yes, transition to NEEDS_ITEM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,8 @@ public static boolean isAttackableTarget(final AbstractEntityCitizen user, final
}

// Other colonies guard citizen attacking the colony
if (entity instanceof EntityCitizen && colony.isValidAttackingGuard((AbstractEntityCitizen) entity))
if (entity instanceof EntityCitizen otherCitizen && otherCitizen.getCitizenColonyHandler().getColonyId() != colony.getID()
&& colony.isValidAttackingGuard((AbstractEntityCitizen) entity))
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import com.minecolonies.api.blocks.huts.AbstractBlockMinecoloniesDefault;
import com.minecolonies.api.entity.mobs.drownedpirate.AbstractDrownedEntityPirate;
import com.minecolonies.api.items.ModTags;
import com.minecolonies.api.util.ShapeUtil;
import com.minecolonies.core.Network;
import com.minecolonies.core.entity.pathfinding.world.CachingBlockLookup;
import com.minecolonies.core.network.messages.client.SyncPathReachedMessage;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -80,8 +82,8 @@ public static void syncDebugReachedPositions(final HashSet<BlockPos> reached, fi
public static BlockPos prepareStart(@NotNull final LivingEntity entity)
{
@NotNull BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(Mth.floor(entity.getX()),
Mth.floor(entity.getY()),
Mth.floor(entity.getZ()));
Mth.floor(entity.getY()),
Mth.floor(entity.getZ()));
final Level level = entity.level;
BlockState bs = level.getBlockState(pos);
// 1 Up when we're standing within this collision shape
Expand All @@ -95,8 +97,8 @@ public static BlockPos prepareStart(@NotNull final LivingEntity entity)
for (final AABB box : collisionShape.toAabbs())
{
if (relPosX >= box.minX && relPosX <= box.maxX
&& relPosZ >= box.minZ && relPosZ <= box.maxZ
&& box.maxY > 0)
&& relPosZ >= box.minZ && relPosZ <= box.maxZ
&& box.maxY > 0)
{
pos.set(pos.getX(), pos.getY() + 1, pos.getZ());
bs = level.getBlockState(pos);
Expand Down Expand Up @@ -164,7 +166,7 @@ else if (b instanceof FenceBlock || b instanceof WallBlock || b instanceof Abstr
private static boolean canStandInSolidBlock(final BlockState state)
{
return state.getBlock() instanceof DoorBlock || state.getBlock() instanceof TrapDoorBlock || (state.getBlock() instanceof PanelBlock && state.getValue(PanelBlock.OPEN))
|| !state.getBlock().properties.hasCollision;
|| !state.getBlock().properties.hasCollision;
}

/**
Expand Down Expand Up @@ -266,7 +268,7 @@ public static boolean isWater(@NotNull final BlockGetter world, final BlockPos p
}

if (state.getBlock() instanceof TrapdoorBlock
|| state.getBlock() instanceof PanelBlock && (!state.getValue(TrapdoorBlock.OPEN) && state.getValue(TrapdoorBlock.HALF) == Half.TOP))
|| state.getBlock() instanceof PanelBlock && (!state.getValue(TrapdoorBlock.OPEN) && state.getValue(TrapdoorBlock.HALF) == Half.TOP))
{
return false;
}
Expand Down Expand Up @@ -325,8 +327,8 @@ public static boolean isLadder(final BlockState blockState, @Nullable final Path
return true;
}
return blockState.is(BlockTags.CLIMBABLE) && ((options != null && options.canClimbAdvanced()) ||
blockState.getBlock() instanceof LadderBlock ||
blockState.is(ModTags.freeClimbBlocks));
blockState.getBlock() instanceof LadderBlock ||
blockState.is(ModTags.freeClimbBlocks));
}

/**
Expand All @@ -340,10 +342,80 @@ public static boolean isDangerous(final BlockState blockState)
final Block block = blockState.getBlock();

return blockState.is(ModTags.dangerousBlocks) ||
block instanceof FireBlock ||
block instanceof CampfireBlock ||
block instanceof MagmaBlock ||
block instanceof SweetBerryBushBlock ||
block instanceof PowderSnowBlock;
block instanceof FireBlock ||
block instanceof CampfireBlock ||
block instanceof MagmaBlock ||
block instanceof SweetBerryBushBlock ||
block instanceof PowderSnowBlock;
}

/**
* Checks for collisions along a line between two given positions
*
* @param startX
* @param startY
* @param startZ
* @param endX
* @param endY
* @param endZ
* @param blockLookup
* @return
*/
public static boolean hasAnyCollisionAlong(int startX, int startY, int startZ, int endX, int endY, int endZ, CachingBlockLookup blockLookup)
{
int x = startX, y = startY, z = startZ;

int dx = Math.abs(endX - startX);
int dy = Math.abs(endY - startY);
int dz = Math.abs(endZ - startZ);

int stepX = (endX > startX) ? 1 : -1;
int stepY = (endY > startY) ? 1 : -1;
int stepZ = (endZ > startZ) ? 1 : -1;

double tMaxX = (dx == 0) ? Double.POSITIVE_INFINITY : ((stepX > 0 ? 1.0 : 0.0) / dx);
double tMaxY = (dy == 0) ? Double.POSITIVE_INFINITY : ((stepY > 0 ? 1.0 : 0.0) / dy);
double tMaxZ = (dz == 0) ? Double.POSITIVE_INFINITY : ((stepZ > 0 ? 1.0 : 0.0) / dz);

double tDeltaX = (dx == 0) ? Double.POSITIVE_INFINITY : 1.0 / dx;
double tDeltaY = (dy == 0) ? Double.POSITIVE_INFINITY : 1.0 / dy;
double tDeltaZ = (dz == 0) ? Double.POSITIVE_INFINITY : 1.0 / dz;

while (x != endX || y != endY || z != endZ)
{
if (ShapeUtil.hasCollision(blockLookup, x, y, z, blockLookup.getBlockState(x, y, z)))
{
return true;
}

if (tMaxX < tMaxY)
{
if (tMaxX < tMaxZ)
{
x += stepX;
tMaxX += tDeltaX;
}
else
{
z += stepZ;
tMaxZ += tDeltaZ;
}
}
else
{
if (tMaxY < tMaxZ)
{
y += stepY;
tMaxY += tDeltaY;
}
else
{
z += stepZ;
tMaxZ += tDeltaZ;
}
}
}

return ShapeUtil.hasCollision(blockLookup, endX, endY, endZ, blockLookup.getBlockState(endX, endY, endZ));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,7 @@ public void initDebug()
*
* @param node
*/
private void handleDebugOptions(final MNode node)
protected void handleDebugOptions(final MNode node)
{
if (debugDrawEnabled)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.minecolonies.core.entity.pathfinding.pathjobs;

import com.minecolonies.core.entity.pathfinding.MNode;

/**
* Interface for area based search path jobs
*/
public interface ISearchPathJob
{
public double getEndNodeScore(MNode n);
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected boolean isAtDestination(final MNode n)
* @return double of the distance.
*/
@Override
protected double getEndNodeScore(@NotNull final MNode n)
public double getEndNodeScore(@NotNull final MNode n)
{
return BlockPosUtil.distManhattan(start, n.x, n.y, n.z);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private boolean isTree(final BlockPos pos)
}

@Override
protected double getEndNodeScore(final MNode n)
public double getEndNodeScore(final MNode n)
{
return BlockPosUtil.distManhattan(searchTowards, n.x, n.y, n.z);
}
Expand Down
Loading