Search in sources :

Example 1 with BlockPattern

use of net.minecraft.block.pattern.BlockPattern 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 2 with BlockPattern

use of net.minecraft.block.pattern.BlockPattern in project Arclight by IzzelAliz.

the class TeleporterMixin_1_15 method findPortal.

public BlockPattern.PortalInfo findPortal(BlockPos p_222272_1_, Vec3d p_222272_2_, Direction directionIn, double p_222272_4_, double p_222272_6_, boolean p_222272_8_, int searchRadius) {
    PointOfInterestManager pointofinterestmanager = this.world.getPointOfInterestManager();
    pointofinterestmanager.ensureLoadedAndValid(this.world, p_222272_1_, 128);
    List<PointOfInterest> list = pointofinterestmanager.getInSquare((p_226705_0_) -> {
        return p_226705_0_ == PointOfInterestType.NETHER_PORTAL;
    }, p_222272_1_, searchRadius, PointOfInterestManager.Status.ANY).collect(Collectors.toList());
    Optional<PointOfInterest> optional = list.stream().min(Comparator.<PointOfInterest>comparingDouble((p_226706_1_) -> {
        return p_226706_1_.getPos().distanceSq(p_222272_1_);
    }).thenComparingInt((p_226704_0_) -> {
        return p_226704_0_.getPos().getY();
    }));
    return optional.map((p_226707_7_) -> {
        BlockPos blockpos = p_226707_7_.getPos();
        this.world.getChunkProvider().registerTicket(TicketType.PORTAL, new ChunkPos(blockpos), 3, blockpos);
        BlockPattern.PatternHelper blockpattern$patternhelper = NetherPortalBlock.createPatternHelper(this.world, blockpos);
        return blockpattern$patternhelper.getPortalInfo(directionIn, blockpos, p_222272_6_, p_222272_2_, p_222272_4_);
    }).orElse(null);
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) PortalCreateEvent(org.bukkit.event.world.PortalCreateEvent) Inject(org.spongepowered.asm.mixin.injection.Inject) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) Random(java.util.Random) Direction(net.minecraft.util.Direction) PointOfInterestManager(net.minecraft.village.PointOfInterestManager) PointOfInterestType(net.minecraft.village.PointOfInterestType) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) Vec3d(net.minecraft.util.math.Vec3d) Mixin(org.spongepowered.asm.mixin.Mixin) TicketType(net.minecraft.world.server.TicketType) BlockStateListPopulator(org.bukkit.craftbukkit.v.util.BlockStateListPopulator) BlockState(net.minecraft.block.BlockState) Bukkit(org.bukkit.Bukkit) At(org.spongepowered.asm.mixin.injection.At) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Redirect(org.spongepowered.asm.mixin.injection.Redirect) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) Final(org.spongepowered.asm.mixin.Final) PointOfInterest(net.minecraft.village.PointOfInterest) Collectors(java.util.stream.Collectors) Blocks(net.minecraft.block.Blocks) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) BlockPattern(net.minecraft.block.pattern.BlockPattern) Teleporter(net.minecraft.world.Teleporter) List(java.util.List) NetherPortalBlock(net.minecraft.block.NetherPortalBlock) MathHelper(net.minecraft.util.math.MathHelper) Shadow(org.spongepowered.asm.mixin.Shadow) Optional(java.util.Optional) Comparator(java.util.Comparator) TeleporterBridge(io.izzel.arclight.common.bridge.world.TeleporterBridge) PointOfInterest(net.minecraft.village.PointOfInterest) PointOfInterestManager(net.minecraft.village.PointOfInterestManager) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos)

Example 3 with BlockPattern

use of net.minecraft.block.pattern.BlockPattern 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 BlockPos (net.minecraft.util.math.BlockPos)3 BlockState (net.minecraft.block.BlockState)2 CachedBlockPosition (net.minecraft.block.pattern.CachedBlockPosition)2 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)1 TeleporterBridge (io.izzel.arclight.common.bridge.world.TeleporterBridge)1 WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Optional (java.util.Optional)1 Random (java.util.Random)1 Collectors (java.util.stream.Collectors)1 IconofsinEntity (mod.azure.doom.entity.tierboss.IconofsinEntity)1 Blocks (net.minecraft.block.Blocks)1 NetherPortalBlock (net.minecraft.block.NetherPortalBlock)1 Entity (net.minecraft.entity.Entity)1 StatusEffectInstance (net.minecraft.entity.effect.StatusEffectInstance)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1