Search in sources :

Example 1 with CopperGolemEntity

use of com.faboslav.friendsandfoes.entity.passive.CopperGolemEntity in project friends-and-foes by Faboslav.

the class LightningRodBlockMixin method tryToSpawnCopperGolem.

private void tryToSpawnCopperGolem(World world, BlockPos pos) {
    if (FriendsAndFoesConfig.enableCopperGolem == false) {
        return;
    }
    BlockPattern.Result patternSearchResult = this.getCopperGolemPattern().searchAround(world, pos);
    if (patternSearchResult == null) {
        return;
    }
    BlockState headBlockState = patternSearchResult.translate(0, 1, 0).getBlockState();
    BlockState bodyBlockState = patternSearchResult.translate(0, 2, 0).getBlockState();
    for (int i = 0; i < this.getCopperGolemPattern().getHeight(); ++i) {
        CachedBlockPosition cachedBlockPosition = patternSearchResult.translate(0, i, 0);
        world.setBlockState(cachedBlockPosition.getBlockPos(), Blocks.AIR.getDefaultState(), Block.NOTIFY_LISTENERS);
        world.syncWorldEvent(WorldEvents.BLOCK_BROKEN, cachedBlockPosition.getBlockPos(), Block.getRawIdFromState(cachedBlockPosition.getBlockState()));
    }
    BlockPos cachedBlockPosition = patternSearchResult.translate(0, 2, 0).getBlockPos();
    float copperGolemYaw = headBlockState.get(CarvedPumpkinBlock.FACING).asRotation();
    CopperGolemEntity copperGolemEntity = ModEntity.COPPER_GOLEM.get().create(world);
    copperGolemEntity.setPosition((double) cachedBlockPosition.getX() + 0.5D, (double) cachedBlockPosition.getY() + 0.05D, (double) cachedBlockPosition.getZ() + 0.5D);
    copperGolemEntity.setSpawnYaw(copperGolemYaw);
    world.spawnEntity(copperGolemEntity);
    Oxidizable.OxidationLevel oxidationLevel;
    if (bodyBlockState.isOf(Blocks.WAXED_COPPER_BLOCK)) {
        oxidationLevel = Oxidizable.OxidationLevel.UNAFFECTED;
    } else if (bodyBlockState.isOf(Blocks.WAXED_WEATHERED_COPPER)) {
        oxidationLevel = Oxidizable.OxidationLevel.WEATHERED;
    } else if (bodyBlockState.isOf(Blocks.WAXED_EXPOSED_COPPER)) {
        oxidationLevel = Oxidizable.OxidationLevel.EXPOSED;
    } else if (bodyBlockState.isOf(Blocks.WAXED_OXIDIZED_COPPER)) {
        oxidationLevel = Oxidizable.OxidationLevel.OXIDIZED;
    } else {
        oxidationLevel = ((OxidizableBlock) bodyBlockState.getBlock()).getDegradationLevel();
    }
    copperGolemEntity.setOxidationLevel(oxidationLevel);
    copperGolemEntity.setIsWaxed(this.isCopperBlockWaxed(bodyBlockState));
    for (ServerPlayerEntity serverPlayerEntity : world.getNonSpectatingEntities(ServerPlayerEntity.class, copperGolemEntity.getBoundingBox().expand(5.0D))) {
        Criteria.SUMMONED_ENTITY.trigger(serverPlayerEntity, copperGolemEntity);
    }
    for (int j = 0; j < this.getCopperGolemPattern().getHeight(); ++j) {
        CachedBlockPosition cachedBlockPosition2 = patternSearchResult.translate(0, j, 0);
        world.updateNeighbors(cachedBlockPosition2.getBlockPos(), Blocks.AIR);
    }
}
Also used : CachedBlockPosition(net.minecraft.block.pattern.CachedBlockPosition) BlockPattern(net.minecraft.block.pattern.BlockPattern) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) CopperGolemEntity(com.faboslav.friendsandfoes.entity.passive.CopperGolemEntity)

Example 2 with CopperGolemEntity

use of com.faboslav.friendsandfoes.entity.passive.CopperGolemEntity in project friends-and-foes by Faboslav.

the class CopperGolemFleeEntityGoal method canStart.

@Override
public boolean canStart() {
    if (((CopperGolemEntity) this.mob).isOxidized()) {
        return false;
    }
    TargetPredicate withinRangePredicate = TargetPredicate.createNonAttackable().setBaseMaxDistance(this.fleeDistance).setPredicate(inclusionSelector.and(extraInclusionSelector));
    this.targetEntity = this.mob.world.getClosestEntity(this.mob.world.getEntitiesByClass(this.classToFleeFrom, this.mob.getBoundingBox().expand(this.fleeDistance, 3.0D, this.fleeDistance), (livingEntity) -> {
        return true;
    }), withinRangePredicate, this.mob, this.mob.getX(), this.mob.getY(), this.mob.getZ());
    if (this.targetEntity == null) {
        return false;
    } else {
        Vec3d vec3d = NoPenaltyTargeting.findFrom(this.mob, 16, 7, this.targetEntity.getPos());
        if (vec3d == null) {
            return false;
        } else if (this.targetEntity.squaredDistanceTo(vec3d.x, vec3d.y, vec3d.z) < this.targetEntity.squaredDistanceTo(this.mob)) {
            return false;
        } else {
            this.fleePath = this.fleeingEntityNavigation.findPathTo(vec3d.x, vec3d.y, vec3d.z, 0);
            return this.fleePath != null;
        }
    }
}
Also used : TargetPredicate(net.minecraft.entity.ai.TargetPredicate) CopperGolemEntity(com.faboslav.friendsandfoes.entity.passive.CopperGolemEntity) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

CopperGolemEntity (com.faboslav.friendsandfoes.entity.passive.CopperGolemEntity)2 BlockPattern (net.minecraft.block.pattern.BlockPattern)1 CachedBlockPosition (net.minecraft.block.pattern.CachedBlockPosition)1 TargetPredicate (net.minecraft.entity.ai.TargetPredicate)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vec3d (net.minecraft.util.math.Vec3d)1