Search in sources :

Example 1 with MinecoloniesMinecart

use of com.minecolonies.api.entity.MinecoloniesMinecart in project minecolonies by Minecolonies.

the class MinecoloniesAdvancedPathNavigate method canUpdatePath.

@Override
protected boolean canUpdatePath() {
    // Auto dismount when trying to path.
    if (ourEntity.vehicle != null) {
        @NotNull final PathPointExtended pEx = (PathPointExtended) this.getPath().getNode(this.getPath().getNextNodeIndex());
        if (pEx.isRailsExit()) {
            final Entity entity = ourEntity.vehicle;
            ourEntity.stopRiding();
            entity.remove();
        } else if (!pEx.isOnRails()) {
            if (ourEntity.vehicle instanceof MinecoloniesMinecart) {
                final Entity entity = ourEntity.vehicle;
                ourEntity.stopRiding();
                entity.remove();
            } else {
                ourEntity.stopRiding();
            }
        } else if ((Math.abs(pEx.x - mob.getX()) > 7 || Math.abs(pEx.z - mob.getZ()) > 7) && ourEntity.vehicle != null) {
            final Entity entity = ourEntity.vehicle;
            ourEntity.stopRiding();
            entity.remove();
        }
    }
    return true;
}
Also used : MobEntity(net.minecraft.entity.MobEntity) Entity(net.minecraft.entity.Entity) MinecoloniesMinecart(com.minecolonies.api.entity.MinecoloniesMinecart) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with MinecoloniesMinecart

use of com.minecolonies.api.entity.MinecoloniesMinecart in project minecolonies by ldtteam.

the class MinecoloniesAdvancedPathNavigate method canUpdatePath.

@Override
protected boolean canUpdatePath() {
    // Auto dismount when trying to path.
    if (ourEntity.vehicle != null) {
        @NotNull final PathPointExtended pEx = (PathPointExtended) this.getPath().getNode(this.getPath().getNextNodeIndex());
        if (pEx.isRailsExit()) {
            final Entity entity = ourEntity.vehicle;
            ourEntity.stopRiding();
            entity.remove();
        } else if (!pEx.isOnRails()) {
            if (ourEntity.vehicle instanceof MinecoloniesMinecart) {
                final Entity entity = ourEntity.vehicle;
                ourEntity.stopRiding();
                entity.remove();
            } else {
                ourEntity.stopRiding();
            }
        } else if ((Math.abs(pEx.x - mob.getX()) > 7 || Math.abs(pEx.z - mob.getZ()) > 7) && ourEntity.vehicle != null) {
            final Entity entity = ourEntity.vehicle;
            ourEntity.stopRiding();
            entity.remove();
        }
    }
    return true;
}
Also used : MobEntity(net.minecraft.entity.MobEntity) Entity(net.minecraft.entity.Entity) MinecoloniesMinecart(com.minecolonies.api.entity.MinecoloniesMinecart) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with MinecoloniesMinecart

use of com.minecolonies.api.entity.MinecoloniesMinecart in project minecolonies by ldtteam.

the class MinecoloniesAdvancedPathNavigate method handlePathOnRails.

/**
 * Handle pathing on rails.
 *
 * @param pEx     the current path point.
 * @param pExNext the next path point.
 * @return if go to next point.
 */
private boolean handlePathOnRails(final PathPointExtended pEx, final PathPointExtended pExNext) {
    if (pEx.isRailsEntry()) {
        final BlockPos blockPos = new BlockPos(pEx.x, pEx.y, pEx.z);
        if (!spawnedPos.equals(blockPos)) {
            final BlockState blockstate = level.getBlockState(blockPos);
            RailShape railshape = blockstate.getBlock() instanceof AbstractRailBlock ? ((AbstractRailBlock) blockstate.getBlock()).getRailDirection(blockstate, level, blockPos, null) : RailShape.NORTH_SOUTH;
            double yOffset = 0.0D;
            if (railshape.isAscending()) {
                yOffset = 0.5D;
            }
            if (mob.vehicle instanceof MinecoloniesMinecart) {
                ((MinecoloniesMinecart) mob.vehicle).setHurtDir(1);
            } else {
                MinecoloniesMinecart minecart = (MinecoloniesMinecart) ModEntities.MINECART.create(level);
                final double x = pEx.x + 0.5D;
                final double y = pEx.y + 0.625D + yOffset;
                final double z = pEx.z + 0.5D;
                minecart.setPos(x, y, z);
                minecart.setDeltaMovement(Vector3d.ZERO);
                minecart.xo = x;
                minecart.yo = y;
                minecart.zo = z;
                level.addFreshEntity(minecart);
                minecart.setHurtDir(1);
                mob.startRiding(minecart, true);
            }
            spawnedPos = blockPos;
        }
    } else {
        spawnedPos = BlockPos.ZERO;
    }
    if (mob.vehicle instanceof MinecoloniesMinecart && pExNext != null) {
        final BlockPos blockPos = new BlockPos(pEx.x, pEx.y, pEx.z);
        final BlockPos blockPosNext = new BlockPos(pExNext.x, pExNext.y, pExNext.z);
        final Vector3d motion = mob.vehicle.getDeltaMovement();
        double forward;
        switch(BlockPosUtil.getXZFacing(blockPos, blockPosNext).getOpposite()) {
            case EAST:
                forward = Math.min(Math.max(motion.x() - 1 * 0.01D, -1), 0);
                mob.vehicle.setDeltaMovement(motion.add(forward == -1 ? -1 : -0.01D, 0.0D, 0.0D));
                break;
            case WEST:
                forward = Math.max(Math.min(motion.x() + 0.01D, 1), 0);
                mob.vehicle.setDeltaMovement(motion.add(forward == 1 ? 1 : 0.01D, 0.0D, 0.0D));
                break;
            case NORTH:
                forward = Math.max(Math.min(motion.z() + 0.01D, 1), 0);
                mob.vehicle.setDeltaMovement(motion.add(0.0D, 0.0D, forward == 1 ? 1 : 0.01D));
                break;
            case SOUTH:
                forward = Math.min(Math.max(motion.z() - 1 * 0.01D, -1), 0);
                mob.vehicle.setDeltaMovement(motion.add(0.0D, 0.0D, forward == -1 ? -1 : -0.01D));
                break;
            case DOWN:
            case UP:
                // unreachable
                break;
        }
    }
    return false;
}
Also used : BlockState(net.minecraft.block.BlockState) Vector3d(net.minecraft.util.math.vector.Vector3d) RailShape(net.minecraft.state.properties.RailShape) BlockPos(net.minecraft.util.math.BlockPos) MinecoloniesMinecart(com.minecolonies.api.entity.MinecoloniesMinecart) AbstractRailBlock(net.minecraft.block.AbstractRailBlock)

Example 4 with MinecoloniesMinecart

use of com.minecolonies.api.entity.MinecoloniesMinecart in project minecolonies by Minecolonies.

the class MinecoloniesAdvancedPathNavigate method handlePathOnRails.

/**
 * Handle pathing on rails.
 *
 * @param pEx     the current path point.
 * @param pExNext the next path point.
 * @return if go to next point.
 */
private boolean handlePathOnRails(final PathPointExtended pEx, final PathPointExtended pExNext) {
    if (pEx.isRailsEntry()) {
        final BlockPos blockPos = new BlockPos(pEx.x, pEx.y, pEx.z);
        if (!spawnedPos.equals(blockPos)) {
            final BlockState blockstate = level.getBlockState(blockPos);
            RailShape railshape = blockstate.getBlock() instanceof AbstractRailBlock ? ((AbstractRailBlock) blockstate.getBlock()).getRailDirection(blockstate, level, blockPos, null) : RailShape.NORTH_SOUTH;
            double yOffset = 0.0D;
            if (railshape.isAscending()) {
                yOffset = 0.5D;
            }
            if (mob.vehicle instanceof MinecoloniesMinecart) {
                ((MinecoloniesMinecart) mob.vehicle).setHurtDir(1);
            } else {
                MinecoloniesMinecart minecart = (MinecoloniesMinecart) ModEntities.MINECART.create(level);
                final double x = pEx.x + 0.5D;
                final double y = pEx.y + 0.625D + yOffset;
                final double z = pEx.z + 0.5D;
                minecart.setPos(x, y, z);
                minecart.setDeltaMovement(Vector3d.ZERO);
                minecart.xo = x;
                minecart.yo = y;
                minecart.zo = z;
                level.addFreshEntity(minecart);
                minecart.setHurtDir(1);
                mob.startRiding(minecart, true);
            }
            spawnedPos = blockPos;
        }
    } else {
        spawnedPos = BlockPos.ZERO;
    }
    if (mob.vehicle instanceof MinecoloniesMinecart && pExNext != null) {
        final BlockPos blockPos = new BlockPos(pEx.x, pEx.y, pEx.z);
        final BlockPos blockPosNext = new BlockPos(pExNext.x, pExNext.y, pExNext.z);
        final Vector3d motion = mob.vehicle.getDeltaMovement();
        double forward;
        switch(BlockPosUtil.getXZFacing(blockPos, blockPosNext).getOpposite()) {
            case EAST:
                forward = Math.min(Math.max(motion.x() - 1 * 0.01D, -1), 0);
                mob.vehicle.setDeltaMovement(motion.add(forward == -1 ? -1 : -0.01D, 0.0D, 0.0D));
                break;
            case WEST:
                forward = Math.max(Math.min(motion.x() + 0.01D, 1), 0);
                mob.vehicle.setDeltaMovement(motion.add(forward == 1 ? 1 : 0.01D, 0.0D, 0.0D));
                break;
            case NORTH:
                forward = Math.max(Math.min(motion.z() + 0.01D, 1), 0);
                mob.vehicle.setDeltaMovement(motion.add(0.0D, 0.0D, forward == 1 ? 1 : 0.01D));
                break;
            case SOUTH:
                forward = Math.min(Math.max(motion.z() - 1 * 0.01D, -1), 0);
                mob.vehicle.setDeltaMovement(motion.add(0.0D, 0.0D, forward == -1 ? -1 : -0.01D));
                break;
            case DOWN:
            case UP:
                // unreachable
                break;
        }
    }
    return false;
}
Also used : BlockState(net.minecraft.block.BlockState) Vector3d(net.minecraft.util.math.vector.Vector3d) RailShape(net.minecraft.state.properties.RailShape) BlockPos(net.minecraft.util.math.BlockPos) MinecoloniesMinecart(com.minecolonies.api.entity.MinecoloniesMinecart) AbstractRailBlock(net.minecraft.block.AbstractRailBlock)

Aggregations

MinecoloniesMinecart (com.minecolonies.api.entity.MinecoloniesMinecart)4 AbstractRailBlock (net.minecraft.block.AbstractRailBlock)2 BlockState (net.minecraft.block.BlockState)2 Entity (net.minecraft.entity.Entity)2 MobEntity (net.minecraft.entity.MobEntity)2 RailShape (net.minecraft.state.properties.RailShape)2 BlockPos (net.minecraft.util.math.BlockPos)2 Vector3d (net.minecraft.util.math.vector.Vector3d)2 NotNull (org.jetbrains.annotations.NotNull)2