Skip to content

Commit

Permalink
Make them build bridges as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Raycoms committed Sep 6, 2018
1 parent cf255d8 commit 41f0bde
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class BarbarianConstants
/**
* Amount of ticks to despawn the barbarian.
*/
public static final int TICKS_TO_DESPAWN = Constants.TICKS_SECOND * Constants.SECONDS_A_MINUTE * 5;
public static final int TICKS_TO_DESPAWN = Constants.TICKS_SECOND * Constants.SECONDS_A_MINUTE * 10;

/**
* Randomly execute it every this ticks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import com.minecolonies.coremod.colony.ColonyManager;
import com.minecolonies.coremod.colony.buildings.AbstractBuilding;
import com.minecolonies.coremod.entity.pathfinding.GeneralEntityWalkToProxy;
import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.BlockLadder;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
Expand Down Expand Up @@ -146,7 +148,7 @@ private boolean isEntityAtSiteWithMove(@NotNull final BlockPos site, final int r
proxy = new GeneralEntityWalkToProxy(entity);
}

if (new AxisAlignedBB(entity.getPosition()).expand(1, 1, 1)
if (new AxisAlignedBB(entity.getPosition()).expand(1, 2, 1)
.intersects(new AxisAlignedBB(lastPos)))
{
stuckTime++;
Expand All @@ -161,6 +163,12 @@ private boolean isEntityAtSiteWithMove(@NotNull final BlockPos site, final int r
entity.getNavigator().clearPath();
stuckTime = 0;
entity.setStuckCounter(entity.getStuckCounter() + 1);
final BlockPos front = entity.getPosition().down().offset(entity.getHorizontalFacing());

if (!world.getBlockState(front).getMaterial().isSolid())
{
world.setBlockState(front, Blocks.COBBLESTONE.getDefaultState());
}

if (entity.getStuckCounter() > 1)
{
Expand All @@ -169,29 +177,43 @@ private boolean isEntityAtSiteWithMove(@NotNull final BlockPos site, final int r
entity.setStuckCounter(0);
entity.setLadderCounter(entity.getLadderCounter() + 1);

if (entity.getLadderCounter() <= LADDERS_TO_PLACE)
final IBlockState ladderHere = world.getBlockState(entity.getPosition());
final IBlockState ladderUp = world.getBlockState(entity.getPosition().up());
if (entity.getLadderCounter() <= LADDERS_TO_PLACE || random.nextBoolean())
{
for (final EnumFacing dir : directions)
if (ladderHere.getBlock() == Blocks.LADDER && ladderUp.getBlock() != Blocks.LADDER)
{
world.setBlockState(entity.getPosition().up(), ladderHere);
}
else if(ladderUp.getBlock() == Blocks.LADDER && ladderHere.getBlock() != Blocks.LADDER)
{
if (world.getBlockState(entity.getPosition().offset(dir)).getMaterial().isSolid())
world.setBlockState(entity.getPosition(), ladderUp);
}
else if (ladderUp.getBlock() != Blocks.LADDER && ladderHere.getBlock() != Blocks.LADDER)
{
for (final EnumFacing dir : directions)
{
if (random.nextBoolean())
if (world.getBlockState(entity.getPosition().offset(dir)).getMaterial().isSolid())
{
world.setBlockState(entity.getPosition().up(), Blocks.LADDER.getDefaultState().withProperty(BlockLadder.FACING, dir.getOpposite()));
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;
}
else
{
world.setBlockState(entity.getPosition(), Blocks.LADDER.getDefaultState().withProperty(BlockLadder.FACING, dir.getOpposite()));
}
break;
}
}
}
else
{
for (final EnumFacing dir : directions)
{
if (world.getBlockState(entity.getPosition().offset(dir)).getMaterial().isSolid())
final IBlockState state = world.getBlockState(entity.getPosition().offset(dir));
if (state.getMaterial().isSolid() && state.getBlock() != Blocks.LADDER)
{
final BlockPos posToDestroy;
switch (random.nextInt(4))
Expand All @@ -203,7 +225,7 @@ private boolean isEntityAtSiteWithMove(@NotNull final BlockPos site, final int r
posToDestroy = entity.getPosition().offset(dir);
break;
default:
posToDestroy = entity.getPosition().up();
posToDestroy = entity.getPosition().up(2);
break;
}
world.destroyBlock(posToDestroy, true);
Expand Down

0 comments on commit 41f0bde

Please sign in to comment.