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);
}
}
}
}
}
}
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);
}
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);
}
}
}
}
Aggregations