Search in sources :

Example 1 with CachedBlockPosition

use of net.minecraft.block.pattern.CachedBlockPosition 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 CachedBlockPosition

use of net.minecraft.block.pattern.CachedBlockPosition in project MCDoom by AzureDoom.

the class DoomWallBlock method checkIconSpawn.

public static void checkIconSpawn(World world, BlockPos pos, IconBlockEntity blockEntity) {
    if (!world.isClient()) {
        BlockState block = blockEntity.getCachedState();
        boolean flag = block.isOf(DoomBlocks.ICON_WALL1) || block.isOf(DoomBlocks.ICON_WALL2) || block.isOf(DoomBlocks.ICON_WALL3) || block.isOf(DoomBlocks.ICON_WALL4) || block.isOf(DoomBlocks.ICON_WALL5) || block.isOf(DoomBlocks.ICON_WALL6) || block.isOf(DoomBlocks.ICON_WALL7) || block.isOf(DoomBlocks.ICON_WALL8) || block.isOf(DoomBlocks.ICON_WALL9) || block.isOf(DoomBlocks.ICON_WALL10) || block.isOf(DoomBlocks.ICON_WALL11) || block.isOf(DoomBlocks.ICON_WALL12) || block.isOf(DoomBlocks.ICON_WALL13) || block.isOf(DoomBlocks.ICON_WALL14) || block.isOf(DoomBlocks.ICON_WALL15) || block.isOf(DoomBlocks.ICON_WALL16);
        if (flag && pos.getY() >= 3 && world.getDifficulty() != Difficulty.PEACEFUL) {
            BlockPattern blockPattern = getOrCreateIconFull();
            BlockPattern.Result result = blockPattern.searchAround(world, pos);
            if (result != null) {
                for (int i = 0; i < blockPattern.getWidth(); ++i) {
                    for (int j = 0; j < blockPattern.getHeight(); ++j) {
                        CachedBlockPosition cachedBlockPosition = result.translate(i, j, 0);
                        world.setBlockState(cachedBlockPosition.getBlockPos(), Blocks.AIR.getDefaultState(), 2);
                        world.syncWorldEvent(2001, cachedBlockPosition.getBlockPos(), Block.getRawIdFromState(cachedBlockPosition.getBlockState()));
                    }
                }
                IconofsinEntity witherentity = ModEntityTypes.ICONOFSIN.create(world);
                BlockPos blockPos = result.translate(1, 2, 0).getBlockPos();
                witherentity.refreshPositionAndAngles((double) blockPos.getX() + 0.5D, (double) blockPos.getY() + 0.55D, (double) blockPos.getZ() + 0.5D, result.getForwards().getAxis() == Direction.Axis.X ? 0.0F : 90.0F, 0.0F);
                witherentity.bodyYaw = result.getForwards().getAxis() == Direction.Axis.X ? 0.0F : 90.0F;
                witherentity.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 200, 4));
                witherentity.addStatusEffect(new StatusEffectInstance(StatusEffects.RESISTANCE, 200, 4));
                world.spawnEntity(witherentity);
                Iterator<ServerPlayerEntity> var13 = world.getNonSpectatingEntities(ServerPlayerEntity.class, witherentity.getBoundingBox().expand(50.0D)).iterator();
                while (var13.hasNext()) {
                    ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) var13.next();
                    Criteria.SUMMONED_ENTITY.trigger(serverPlayerEntity, witherentity);
                }
                for (int k = 0; k < blockPattern.getWidth(); ++k) {
                    for (int l = 0; l < blockPattern.getHeight(); ++l) {
                        world.updateNeighbors(result.translate(k, l, 0).getBlockPos(), Blocks.AIR);
                    }
                }
            }
        }
    }
}
Also used : CachedBlockPosition(net.minecraft.block.pattern.CachedBlockPosition) BlockState(net.minecraft.block.BlockState) BlockPattern(net.minecraft.block.pattern.BlockPattern) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) IconofsinEntity(mod.azure.doom.entity.tierboss.IconofsinEntity) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 3 with CachedBlockPosition

use of net.minecraft.block.pattern.CachedBlockPosition in project Biome-Makeover by Lemonszz.

the class CarvedPumpkinBlockMixin method trySpawnEntity.

// TODO: make more general system for golems to allow this to be easier to add later?
@Inject(at = @At("HEAD"), method = "trySpawnEntity", cancellable = true)
private void trySpawnEntity(World world, BlockPos pos, CallbackInfo cbi) {
    BlockPattern pattern = BMWorldEvents.getStoneGolemPattern();
    BlockPattern.Result result = pattern.searchAround(world, pos);
    if (result != null) {
        for (int x = 0; x < pattern.getWidth(); ++x) {
            for (int y = 0; y < pattern.getHeight(); ++y) {
                CachedBlockPosition golPos = result.translate(x, y, 0);
                world.setBlockState(golPos.getBlockPos(), Blocks.AIR.getDefaultState(), 2);
                world.syncWorldEvent(2001, golPos.getBlockPos(), Block.getRawIdFromState(golPos.getBlockState()));
            }
        }
        BlockPos spawnPos = result.translate(1, 2, 0).getBlockPos();
        StoneGolemEntity stoneGolem = BMEntities.STONE_GOLEM.create(world);
        stoneGolem.setPlayerCreated(true);
        stoneGolem.refreshPositionAndAngles((double) spawnPos.getX() + 0.5D, (double) spawnPos.getY() + 0.05D, (double) spawnPos.getZ() + 0.5D, 0.0F, 0.0F);
        world.spawnEntity(stoneGolem);
        Iterator<ServerPlayerEntity> playersNearby = world.getNonSpectatingEntities(ServerPlayerEntity.class, stoneGolem.getBoundingBox().expand(5.0D)).iterator();
        while (playersNearby.hasNext()) {
            ServerPlayerEntity pl = playersNearby.next();
            Criteria.SUMMONED_ENTITY.trigger(pl, stoneGolem);
        }
        for (int x = 0; x < pattern.getWidth(); ++x) {
            for (int y = 0; y < pattern.getHeight(); ++y) {
                CachedBlockPosition golemPos = result.translate(x, y, 0);
                world.updateNeighbors(golemPos.getBlockPos(), Blocks.AIR);
            }
        }
    }
}
Also used : CachedBlockPosition(net.minecraft.block.pattern.CachedBlockPosition) StoneGolemEntity(party.lemons.biomemakeover.entity.StoneGolemEntity) BlockPattern(net.minecraft.block.pattern.BlockPattern) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

BlockPattern (net.minecraft.block.pattern.BlockPattern)3 CachedBlockPosition (net.minecraft.block.pattern.CachedBlockPosition)3 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)3 BlockPos (net.minecraft.util.math.BlockPos)3 CopperGolemEntity (com.faboslav.friendsandfoes.entity.passive.CopperGolemEntity)1 IconofsinEntity (mod.azure.doom.entity.tierboss.IconofsinEntity)1 BlockState (net.minecraft.block.BlockState)1 StatusEffectInstance (net.minecraft.entity.effect.StatusEffectInstance)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 StoneGolemEntity (party.lemons.biomemakeover.entity.StoneGolemEntity)1