use of net.minecraft.core.Holder in project Panthalassa by Sniffity.
the class FeaturePanthalassaAbstractCoral method place.
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> p_159536_) {
Random rand = p_159536_.random();
WorldGenLevel worldgenlevel = p_159536_.level();
Optional<Block> optional = Registry.BLOCK.getTag(BlockTags.CORAL_BLOCKS).flatMap((p_204734_) -> {
return p_204734_.getRandomElement(rand);
}).map(Holder::value);
return this.placeFeature(worldgenlevel, rand, p_159536_.origin(), optional.get().defaultBlockState());
}
use of net.minecraft.core.Holder in project artifacts by ochotonida.
the class CampsiteFeature method placeChest.
public void placeChest(WorldGenLevel level, BlockPos pos, Random random, Direction facing) {
if (random.nextFloat() < ModConfig.common.campsiteMimicChance.get()) {
MimicEntity mimic = ModEntityTypes.MIMIC.get().create(level.getLevel());
if (mimic != null) {
mimic.setDormant(true);
mimic.setFacing(facing);
mimic.setPos(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
level.addFreshEntity(mimic);
}
} else {
BlockState chest;
if (random.nextInt(8) == 0) {
setBlock(level, pos.below(), Blocks.TNT.defaultBlockState());
chest = Blocks.TRAPPED_CHEST.defaultBlockState();
setBlock(level, pos, Blocks.TRAPPED_CHEST.defaultBlockState().setValue(ChestBlock.FACING, Direction.Plane.HORIZONTAL.getRandomDirection(random)));
} else if (ModConfig.common.useModdedChests.get()) {
// noinspection deprecation
chest = Registry.BLOCK.getTag(Tags.Blocks.CHESTS_WOODEN).flatMap((set) -> set.getRandomElement(random)).map(Holder::value).orElse(Blocks.CHEST).defaultBlockState();
} else {
chest = Blocks.CHEST.defaultBlockState();
}
if (chest.hasProperty(BlockStateProperties.HORIZONTAL_FACING)) {
chest = chest.setValue(BlockStateProperties.HORIZONTAL_FACING, facing);
}
setBlock(level, pos, chest);
RandomizableContainerBlockEntity.setLootTable(level, random, pos, CHEST_LOOT);
}
}
use of net.minecraft.core.Holder in project Mohist by MohistMC.
the class CustomWorldChunkManager method biomeListToBiomeBaseList.
private static List<Holder<net.minecraft.world.level.biome.Biome>> biomeListToBiomeBaseList(List<Biome> biomes, net.minecraft.core.Registry<net.minecraft.world.level.biome.Biome> registry) {
List<Holder<net.minecraft.world.level.biome.Biome>> biomeBases = new ArrayList<>();
for (Biome biome : biomes) {
Preconditions.checkArgument(biome != Biome.CUSTOM, "Cannot use the biome %s", biome);
biomeBases.add(CraftBlock.biomeToBiomeBase(registry, biome));
}
return biomeBases;
}
use of net.minecraft.core.Holder in project squaremap by jpenilla.
the class ChunkSnapshot method snapshot.
@SuppressWarnings({ "unchecked", "rawtypes" })
static ChunkSnapshot snapshot(final LevelChunk chunk, final boolean biomesOnly) {
// AsyncCatcher.catchOp("Chunk Snapshot");
final int sectionCount = chunk.getSectionsCount();
final LevelChunkSection[] sections = chunk.getSections();
final PalettedContainer<BlockState>[] states = new PalettedContainer[sectionCount];
final PalettedContainer<Holder<Biome>>[] biomes = new PalettedContainer[sectionCount];
final boolean[] empty = new boolean[sectionCount];
final Heightmap heightmap = new Heightmap(chunk, Heightmap.Types.WORLD_SURFACE);
if (!biomesOnly) {
if (!chunk.hasPrimedHeightmap(Heightmap.Types.WORLD_SURFACE)) {
throw new IllegalStateException("Expected WORLD_SURFACE heightmap to be present, but it wasn't! " + chunk.getPos());
}
heightmap.setRawData(chunk, Heightmap.Types.WORLD_SURFACE, chunk.getOrCreateHeightmapUnprimed(Heightmap.Types.WORLD_SURFACE).getRawData());
for (int i = 0; i < sectionCount; i++) {
final boolean sectionEmpty = sections[i].hasOnlyAir();
empty[i] = sectionEmpty;
if (sectionEmpty) {
states[i] = ChunkSnapshotImpl.EMPTY_SECTION_BLOCK_STATES;
} else {
states[i] = sections[i].getStates().copy();
}
biomes[i] = sections[i].getBiomes().copy();
}
} else {
for (int i = 0; i < sectionCount; i++) {
biomes[i] = sections[i].getBiomes().copy();
}
}
return new ChunkSnapshotImpl(LevelHeightAccessor.create(chunk.getMinBuildHeight(), chunk.getHeight()), states, biomes, Util.make(new EnumMap<>(Heightmap.Types.class), map -> map.put(Heightmap.Types.WORLD_SURFACE, heightmap)), empty, chunk.getLevel().dimensionType(), chunk.getPos());
}
use of net.minecraft.core.Holder in project AlexsMobs by Alex-the-666.
the class EntityMungus method transformBiome.
private void transformBiome(BlockPos pos, Holder<Biome> biome) {
LevelChunk chunk = level.getChunkAt(pos);
PalettedContainer<Holder<Biome>> container = getChunkBiomes(chunk);
if (this.entityData.get(REVERTING)) {
int lvt_4_1_ = chunk.getPos().getMinBlockX() >> 2;
int yChunk = (int) this.getY() >> 2;
int lvt_5_1_ = chunk.getPos().getMinBlockZ() >> 2;
ChunkGenerator chunkgenerator = ((ServerLevel) level).getChunkSource().getGenerator();
Biome b = null;
for (int k = 0; k < 4; ++k) {
for (int l = 0; l < 4; ++l) {
for (int i1 = 0; i1 < 4; ++i1) {
container.getAndSetUnchecked(k, l, i1, chunkgenerator.getBiomeSource().getNoiseBiome(lvt_4_1_ + k, yChunk + l, lvt_5_1_ + i1, chunkgenerator.climateSampler()));
}
}
}
if (b != null && !level.isClientSide) {
AlexsMobs.sendMSGToAll(new MessageMungusBiomeChange(this.getId(), pos.getX(), pos.getZ(), b.getRegistryName().toString()));
}
} else {
if (biome == null) {
return;
}
if (container != null && !level.isClientSide) {
for (int biomeX = 0; biomeX < 4; ++biomeX) {
for (int biomeY = 0; biomeY < 4; ++biomeY) {
for (int biomeZ = 0; biomeZ < 4; ++biomeZ) {
container.getAndSetUnchecked(biomeX, biomeY, biomeZ, biome);
}
}
}
int id = this.getId();
AlexsMobs.sendMSGToAll(new MessageMungusBiomeChange(this.getId(), pos.getX(), pos.getZ(), biome.value().getRegistryName().toString()));
}
}
}
Aggregations