use of net.minecraft.server.MinecraftServer in project NetherEx by LogicTechCorp.
the class WorldGenElderMushroom method generate.
@Override
public boolean generate(World world, Random rand, BlockPos pos) {
while (isWorldGen && world.isAirBlock(pos) && pos.getY() > 32) {
pos = pos.down();
}
for (int posX = -1; posX < 2; posX++) {
for (int posZ = -1; posZ < 2; posZ++) {
BlockPos newPos = pos.add(posX, 0, posZ);
IBlockState state = world.getBlockState(newPos);
if (!state.getBlock().canSustainPlant(state, world, newPos, EnumFacing.UP, NetherExBlocks.PLANT_MUSHROOM_ELDER) && state.getBlock() != Blocks.SOUL_SAND) {
return false;
}
}
}
pos = pos.up();
Mirror[] mirrors = Mirror.values();
Mirror mirror = mirrors[rand.nextInt(mirrors.length)];
Rotation[] rotations = Rotation.values();
Rotation rotation = rotations[rand.nextInt(rotations.length)];
MinecraftServer minecraftServer = world.getMinecraftServer();
TemplateManager templateManager = world.getSaveHandler().getStructureTemplateManager();
Template template = templateManager.getTemplate(minecraftServer, WeightedUtil.getRandomStructure(rand, variants));
PlacementSettings placementSettings = new PlacementSettings().setMirror(mirror).setRotation(rotation).setReplacedBlock(Blocks.AIR);
BlockPos structureSize = Template.transformedBlockPos(placementSettings.copy(), template.getSize());
float airAmount = 0;
float blockAmount = MathHelper.abs((structureSize.getX() + 2) * (structureSize.getY() + 1) * (structureSize.getZ() + 2));
for (int posX = -1; posX < structureSize.getX() + 1; posX++) {
for (int posZ = -1; posZ < structureSize.getZ() + 1; posZ++) {
for (int posY = 0; posY < structureSize.getY() + 1; posY++) {
BlockPos newPos = pos.add(-(posX / 2), posY, -(posZ / 2));
Block block = world.getBlockState(newPos).getBlock();
if (world.isAirBlock(newPos)) {
airAmount += 1.0F;
} else if (block == Blocks.NETHERRACK || block == Blocks.GLOWSTONE || block == NetherExBlocks.BLOCK_NETHERRACK || block == NetherExBlocks.PLANT_MUSHROOM_ELDER_CAP || block == NetherExBlocks.PLANT_MUSHROOM_ELDER_STEM) {
return false;
}
}
}
}
if (MathHelper.abs(airAmount) / MathHelper.abs(blockAmount) >= 0.75F) {
if (!isWorldGen) {
world.setBlockToAir(pos);
}
template.addBlocksToWorld(world, pos.add(-(structureSize.getX() / 2), 0, -(structureSize.getZ() / 2)), placementSettings.copy());
return true;
}
return false;
}
use of net.minecraft.server.MinecraftServer in project NetherEx by LogicTechCorp.
the class WorldGenAirStructure method generate.
@Override
public boolean generate(World world, Random rand, BlockPos pos) {
rand = world.getChunkFromBlockCoords(pos).getRandomWithSeed(world.getSeed());
Mirror[] mirrors = Mirror.values();
Rotation[] rotations = Rotation.values();
Mirror mirror = mirrors[rand.nextInt(mirrors.length)];
Rotation rotation = rotations[rand.nextInt(rotations.length)];
MinecraftServer server = world.getMinecraftServer();
TemplateManager manager = world.getSaveHandler().getStructureTemplateManager();
Template template = manager.getTemplate(server, WeightedUtil.getRandomStructure(rand, variants));
PlacementSettings placementSettings = new PlacementSettings().setMirror(mirror).setRotation(rotation).setReplacedBlock(Blocks.STRUCTURE_VOID).setRandom(rand);
BlockPos structureSize = Template.transformedBlockPos(placementSettings, template.getSize());
BlockPos newPos = new BlockPos(pos.getX() - structureSize.getX() / 2, 112, pos.getZ() - structureSize.getZ() / 2);
BlockPos spawnPos = WorldGenUtil.getSuitableAirPos(world, newPos, structureSize);
if (!spawnPos.equals(BlockPos.ORIGIN)) {
WorldGenUtil.generateStructure(world, spawnPos, rand, template, placementSettings, lootTables, spawnerMobs);
return true;
}
return false;
}
use of net.minecraft.server.MinecraftServer in project NetherEx by LogicTechCorp.
the class WorldGenGroundStructure method generate.
@Override
public boolean generate(World world, Random rand, BlockPos pos) {
rand = world.getChunkFromBlockCoords(pos).getRandomWithSeed(world.getSeed());
Mirror[] mirrors = Mirror.values();
Rotation[] rotations = Rotation.values();
Mirror mirror = mirrors[rand.nextInt(mirrors.length)];
Rotation rotation = rotations[rand.nextInt(rotations.length)];
MinecraftServer server = world.getMinecraftServer();
TemplateManager manager = world.getSaveHandler().getStructureTemplateManager();
Template template = manager.getTemplate(server, WeightedUtil.getRandomStructure(rand, variants));
PlacementSettings placementSettings = new PlacementSettings().setMirror(mirror).setRotation(rotation).setReplacedBlock(Blocks.STRUCTURE_VOID).setRandom(rand);
BlockPos structureSize = Template.transformedBlockPos(placementSettings, template.getSize());
BlockPos newPos = new BlockPos(pos.getX() - structureSize.getX() / 2, 96, pos.getZ() - structureSize.getZ() / 2);
BlockPos spawnPos = WorldGenUtil.getSuitableGroundPos(world, newPos, allowedBlocks, structureSize, 0.8F);
if (!spawnPos.equals(BlockPos.ORIGIN)) {
WorldGenUtil.generateStructure(world, spawnPos, rand, template, placementSettings, lootTables, spawnerMobs);
return true;
}
return false;
}
use of net.minecraft.server.MinecraftServer in project RecurrentComplex by Ivorforce.
the class CommandContaining method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
RCParameters parameters = RCParameters.of(args);
BlockExpression matcher = parameters.rc().expression(new BlockExpression(RecurrentComplex.specialRegistry)).require();
CommandSearchStructure.postResultMessage(commandSender, RCTextStyle::structure, CommandSearchStructure.search(StructureRegistry.INSTANCE.ids(), name -> containedBlocks(StructureRegistry.INSTANCE.get(name), matcher)));
}
use of net.minecraft.server.MinecraftServer in project RecurrentComplex by Ivorforce.
the class CommandWriteAll method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
RCParameters parameters = RCParameters.of(args);
String adapterID = parameters.get().first().require();
if (!RecurrentComplex.saver.has(adapterID))
throw ServerTranslations.commandException("commands.rcsaveall.noregistry");
ResourceDirectory directory = parameters.rc("dir").resourceDirectory().optional().orElse(ResourceDirectory.ACTIVE);
Optional<FileSaverAdapter<?>> adapterOptional = Optional.ofNullable(RecurrentComplex.saver.get(adapterID));
Set<String> ids = adapterOptional.map(a -> a.getRegistry().ids()).orElse(Collections.emptySet());
ResourceExpression resourceExpression = ExpressionCache.of(new ResourceExpression(id -> adapterOptional.map(a -> a.getRegistry().has(id)).orElse(false)), parameters.get().at(1).require());
int saved = 0, failed = 0;
for (String id : ids) {
if (!resourceExpression.test(new RawResourceLocation(adapterOptional.map(a -> a.getRegistry().status(id).getDomain()).orElseThrow(IllegalStateException::new), id)))
continue;
boolean success = RecurrentComplex.saver.trySave(directory.toPath(), adapterID, id);
if (success)
saved++;
else
failed++;
}
commandSender.sendMessage(ServerTranslations.format("commands.rcsaveall.result", saved, directory, failed));
RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
}
Aggregations