Skip to content

Commit

Permalink
improved wall scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Raycoms committed Sep 6, 2018
1 parent 4d317ed commit cf255d8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class BarbarianConstants
/**
* Amount of ladders to place before destroying blocks.
*/
public static final int LADDERS_TO_PLACE = 6;
public static final int LADDERS_TO_PLACE = 10;

/**
* Amount of ticks to despawn the barbarian.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
import com.minecolonies.coremod.colony.ColonyManager;
import com.minecolonies.coremod.colony.buildings.AbstractBuilding;
import com.minecolonies.coremod.entity.pathfinding.GeneralEntityWalkToProxy;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.BlockLadder;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Random;
import java.util.*;

import static com.minecolonies.api.util.constant.BarbarianConstants.*;

Expand All @@ -29,6 +30,11 @@ public class EntityAIWalkToRandomHuts extends EntityAIBase
*/
protected final AbstractEntityBarbarian entity;

/**
* All directions.
*/
private final List<EnumFacing> directions = Arrays.asList(EnumFacing.HORIZONTALS);

/**
* The world.
*/
Expand Down Expand Up @@ -81,6 +87,7 @@ public EntityAIWalkToRandomHuts(final AbstractEntityBarbarian creatureIn, final
this.entity = creatureIn;
this.speed = speedIn;
this.world = creatureIn.getEntityWorld();
lastPos = entity.getPosition();
this.setMutexBits(1);
}

Expand Down Expand Up @@ -154,48 +161,60 @@ private boolean isEntityAtSiteWithMove(@NotNull final BlockPos site, final int r
entity.getNavigator().clearPath();
stuckTime = 0;
entity.setStuckCounter(entity.getStuckCounter() + 1);
Log.getLogger().warn("runnin");
if (entity.getStuckCounter() > 2)

if (entity.getStuckCounter() > 1)
{
Collections.shuffle(directions);

entity.setStuckCounter(0);
entity.setLadderCounter(entity.getLadderCounter()+1);
Log.getLogger().warn("ladders");
entity.setLadderCounter(entity.getLadderCounter() + 1);

if (world.getBlockState(entity.getPosition().offset(entity.getHorizontalFacing())).getMaterial().isSolid())
if (entity.getLadderCounter() <= LADDERS_TO_PLACE)
{
if (random.nextBoolean())
for (final EnumFacing dir : directions)
{
world.setBlockState(entity.getPosition().up(), Blocks.LADDER.getDefaultState().withProperty(BlockLadder.FACING, entity.getHorizontalFacing().getOpposite()));
}
else
{
world.setBlockState(entity.getPosition(), Blocks.LADDER.getDefaultState().withProperty(BlockLadder.FACING, entity.getHorizontalFacing().getOpposite()));
if (world.getBlockState(entity.getPosition().offset(dir)).getMaterial().isSolid())
{
if (random.nextBoolean())
{
world.setBlockState(entity.getPosition().up(), Blocks.LADDER.getDefaultState().withProperty(BlockLadder.FACING, dir.getOpposite()));
}
else
{
world.setBlockState(entity.getPosition(), Blocks.LADDER.getDefaultState().withProperty(BlockLadder.FACING, dir.getOpposite()));
}
break;
}
}
}

if (entity.getLadderCounter() >= LADDERS_TO_PLACE)
else
{
final BlockPos posToDestroy;
Log.getLogger().warn("destroy!");
switch (random.nextInt(4))
for (final EnumFacing dir : directions)
{
case 1:
posToDestroy = entity.getPosition().offset(entity.getHorizontalFacing());
if (world.getBlockState(entity.getPosition().offset(dir)).getMaterial().isSolid())
{
final BlockPos posToDestroy;
switch (random.nextInt(4))
{
case 1:
posToDestroy = entity.getPosition().offset(dir).up();
break;
case 2:
posToDestroy = entity.getPosition().offset(dir);
break;
default:
posToDestroy = entity.getPosition().up();
break;
}
world.destroyBlock(posToDestroy, true);
break;
case 2:
posToDestroy = entity.getPosition().offset(entity.getHorizontalFacing());
break;
default:
posToDestroy = entity.getPosition().up();
break;

}
}
world.destroyBlock(posToDestroy, true);
}
}
else
{
entity.getNavigator().moveAwayFromXYZ(entity.getPosition(), random.nextInt(MOVE_AWAY_RANGE), 2);
entity.getNavigator().moveAwayFromXYZ(entity.getPosition(), random.nextInt(4), 2);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public PathJobMoveAwayFromLocation(final World world, @NotNull final BlockPos st
this.avoid = new BlockPos(avoid);
this.avoidDistance = avoidDistance;

double dx = (double) (start.getX() - avoid.getX());
double dz = (double) (start.getZ() - avoid.getZ());
double dx = (double) (start.getX() - avoid.getX()) + 1;
double dz = (double) (start.getZ() - avoid.getZ()) + 1;

final double scalar = avoidDistance / Math.sqrt(dx * dx + dz * dz);
dx *= scalar;
Expand Down Expand Up @@ -138,7 +138,9 @@ protected double computeHeuristic(@NotNull final BlockPos pos)
protected boolean isAtDestination(@NotNull final Node n)
{
final BlockPos vector = n.pos.subtract(avoid);
return getNodeResultScore(n) >= (avoidDistance * avoidDistance) && EnumFacing.getFacingFromVector(vector.getX(), 0, vector.getZ()).equals(direction);
final double nodeResult = getNodeResultScore(n);
final int avoidSq = (avoidDistance * avoidDistance);
return nodeResult >= avoidSq && (EnumFacing.getFacingFromVector(vector.getX(), 0, vector.getZ()).equals(direction) || nodeResult > avoidSq * avoidDistance);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public void onUpdateNavigation()

if (pEx.isOnLadder())
{
final Vec3d vec3 = this.getPath().getPosition(this.ourEntity);
Vec3d vec3 = this.getPath().getPosition(this.ourEntity);

if (vec3.squareDistanceTo(ourEntity.posX, vec3.y, ourEntity.posZ) < Math.random() * 0.1)
{
Expand All @@ -275,16 +275,16 @@ public void onUpdateNavigation()
{
// Any of these values is climbing, so adjust our direction of travel towards the ladder
case NORTH:
vec3.add(0, 0, 1);
vec3 = vec3.add(0, 0, 1);
break;
case SOUTH:
vec3.add(0, 0, -1);
vec3 = vec3.add(0, 0, -1);
break;
case WEST:
vec3.add(1, 0, 0);
vec3 = vec3.add(1, 0, 0);
break;
case EAST:
vec3.add(-1, 0, 0);
vec3 = vec3.add(-1, 0, 0);
break;
// Any other value is going down, so lets not move at all
default:
Expand Down

0 comments on commit cf255d8

Please sign in to comment.