use of net.minecraft.world.gen.structure.StructureBoundingBox in project RecurrentComplex by Ivorforce.
the class CommandPaste method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
RCParameters parameters = RCParameters.of(args, "mirror", "generate", "select");
EntityPlayerMP entityPlayerMP = getCommandSenderAsPlayer(sender);
RCEntityInfo entityInfo = RCCommands.getStructureEntityInfo(entityPlayerMP, null);
NBTTagCompound worldData = entityInfo.getWorldDataClipboard();
if (worldData == null)
throw ServerTranslations.commandException("commands.strucPaste.noClipboard");
WorldServer world = (WorldServer) sender.getEntityWorld();
BlockPos pos = parameters.pos("x", "y", "z", sender.getPosition(), false).require();
AxisAlignedTransform2D transform = parameters.transform("rotation", "mirror").optional().orElse(AxisAlignedTransform2D.ORIGINAL);
String seed = parameters.get("seed").first().optional().orElse(null);
boolean generate = parameters.has("generate");
boolean select = parameters.has("select");
GenericStructure structure = GenericStructure.createDefaultStructure();
structure.worldDataCompound = worldData;
// TODO Generate with generation info?
OperationRegistry.queueOperation(new OperationGenerateStructure(structure, null, transform, pos, generate).withSeed(seed).prepare(world), sender);
if (select) {
StructureGenerator<?> generator = new StructureGenerator<>(structure).transform(transform).lowerCoord(pos);
// Can never not place so don't handle
//noinspection OptionalGetWithoutIsPresent
StructureBoundingBox boundingBox = generator.boundingBox().get();
SelectionOwner owner = RCCommands.getSelectionOwner(sender, null, false);
owner.setSelection(RCBlockAreas.from(boundingBox));
}
}
use of net.minecraft.world.gen.structure.StructureBoundingBox in project RecurrentComplex by Ivorforce.
the class CommandImportStructure method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
RCParameters parameters = RCParameters.of(args, "mirror", "select");
String structureID = parameters.get().first().require();
Structure<?> structure = parameters.rc().structure().require();
WorldServer world = parameters.mc("dimension").dimension(server, sender).require();
AxisAlignedTransform2D transform = parameters.transform("rotation", "mirror").optional().orElse(AxisAlignedTransform2D.ORIGINAL);
BlockPos pos = parameters.pos("x", "y", "z", sender.getPosition(), false).require();
boolean select = parameters.has("select");
StructureGenerator<?> generator = new StructureGenerator<>(structure).world(world).transform(transform).lowerCoord(pos).asSource(true);
// Can never not place so don't handle
//noinspection OptionalGetWithoutIsPresent
StructureBoundingBox boundingBox = generator.boundingBox().get();
if (structure instanceof GenericStructure && world == sender.getEntityWorld())
OperationRegistry.queueOperation(new OperationGenerateStructure((GenericStructure) structure, structureID, transform, pos, true).withStructureID(structureID).prepare(world), sender);
else
generator.generate();
if (select) {
SelectionOwner owner = RCCommands.getSelectionOwner(sender, null, false);
owner.setSelection(RCBlockAreas.from(boundingBox));
}
}
use of net.minecraft.world.gen.structure.StructureBoundingBox in project RecurrentComplex by Ivorforce.
the class GenericStructure method generate.
@Override
public void generate(@Nonnull final StructureSpawnContext context, @Nonnull InstanceData instanceData, @Nonnull TransformerMulti foreignTransformer) {
WorldServer world = context.environment.world;
IvWorldData worldData = constructWorldData();
boolean asSource = context.generateAsSource;
RunTransformer transformer = getRunTransformer(instanceData, foreignTransformer, asSource);
instanceData.variableDomain.fill(context.environment.variables);
// The world initializes the block event array after it generates the world - in the constructor
// This hackily sets the field to a temporary value. Yay.
// Hax
RCAccessorWorldServer.ensureBlockEventArray(world);
IvBlockCollection blockCollection = worldData.blockCollection;
int[] areaSize = new int[] { blockCollection.width, blockCollection.height, blockCollection.length };
BlockPos origin = StructureBoundingBoxes.min(context.boundingBox);
Map<BlockPos, GeneratingTileEntity<?>> generatingTEs = new HashMap<>();
Map<BlockPos, NBTTagCompound> tileEntityCompounds = new HashMap<>();
for (NBTTagCompound tileEntityCompound : worldData.tileEntities) {
BlockPos src = RCMover.getTileEntityPos(tileEntityCompound);
tileEntityCompounds.put(src, tileEntityCompound);
asGeneratingTileEntity(context, world, areaSize, origin, tileEntityCompound, generatingTEs::put);
}
if (transformer != null)
transformer.transformer.transform(transformer.instanceData, Transformer.Phase.BEFORE, context, worldData, transformer);
StructureBoundingBox relevantSourceArea = context.intersection(BlockAreas.toBoundingBox(blockCollection.area()));
if (// Why did we get asked to generate again?
relevantSourceArea != null) {
BlockPos.MutableBlockPos worldPos = new BlockPos.MutableBlockPos();
for (int pass = 0; pass < 2; pass++) {
for (BlockPos sourcePos : RCStructureBoundingBoxes.mutablePositions(relevantSourceArea)) {
IvMutableBlockPos.add(context.transform.applyOn(sourcePos, worldPos, areaSize), origin);
if (context.includesComplex(worldPos)) {
IBlockState state = PosTransformer.transformBlockState(blockCollection.getBlockState(sourcePos), context.transform);
if (RecurrentComplex.specialRegistry.isSafe(state.getBlock()) && pass == getPass(state) && (transformer == null || !transformer.transformer.skipGeneration(transformer.instanceData, context, worldPos, state, worldData, sourcePos))) {
GeneratingTileEntity<?> generatingTE = generatingTEs.get(sourcePos);
//noinspection unchecked
if (asSource || generatingTE == null || ((GeneratingTileEntity) generatingTE).shouldPlaceInWorld(context, instanceData.tileEntities.get(sourcePos)))
setBlock(context, areaSize, worldPos, state, () -> tileEntityCompounds.get(sourcePos));
else
// Replace with air
context.setBlock(worldPos, Blocks.AIR.getDefaultState(), 2);
}
}
}
}
}
if (transformer != null)
transformer.transformer.transform(transformer.instanceData, Transformer.Phase.AFTER, context, worldData, transformer);
for (NBTTagCompound entityCompound : worldData.entities) {
double[] transformedEntityPos = context.transform.applyOn(getEntityPos(entityCompound), areaSize);
if (context.includes(new Vec3i(transformedEntityPos[0] + origin.getX(), transformedEntityPos[1] + origin.getY(), transformedEntityPos[2] + origin.getZ()))) {
Entity entity = EntityList.createEntityFromNBT(entityCompound, world);
if (entity != null) {
PosTransformer.transformEntityPos(entity, context.transform, areaSize);
Mover.moveEntity(entity, origin);
RCAccessorEntity.setEntityUniqueID(entity, UUID.randomUUID());
generateEntityContents(context, entity);
world.spawnEntity(entity);
} else {
RecurrentComplex.logger.error("Error loading entity with ID '" + entityCompound.getString("id") + "'");
}
}
}
if (!asSource) {
if (context.generationLayer < MAX_GENERATING_LAYERS) {
generatingTEs.entrySet().forEach(entry -> {
NBTStorable teData = instanceData.tileEntities.get(entry.getKey());
if (teData != null)
((GeneratingTileEntity) entry.getValue()).generate(context, teData);
});
} else {
RecurrentComplex.logger.warn("Structure generated with over " + MAX_GENERATING_LAYERS + " layers; most likely infinite loop!");
}
}
}
use of net.minecraft.world.gen.structure.StructureBoundingBox in project RecurrentComplex by Ivorforce.
the class RCSaplingGenerator method findRandomSapling.
@Nullable
public static Pair<Structure<?>, SaplingGeneration> findRandomSapling(WorldServer world, BlockPos pos, Random random, boolean considerVanilla) {
Environment baseEnv = Environment.inNature(world, new StructureBoundingBox(pos, pos));
List<Pair<Structure<?>, SaplingGeneration>> applicable = StructureRegistry.INSTANCE.getStructureGenerations(SaplingGeneration.class).stream().filter(pair1 -> pair1.getRight().generatesIn(baseEnv.withGeneration(pair1.getRight()))).collect(Collectors.toCollection(ArrayList::new));
// Hackily consider big vanilla trees too
int vanillaComplexity = complexity(world, pos, random, predictors);
ImmutableMultimap<Integer, Pair<Structure<?>, SaplingGeneration>> groups = IvFunctions.groupMap(applicable, pair -> pair.getRight().pattern.pattern.compile(true).size());
List<Integer> complexities = Lists.newArrayList(groups.keySet());
if (vanillaComplexity > 0)
complexities.add(vanillaComplexity);
Collections.sort(complexities);
Pair<Structure<?>, SaplingGeneration> pair = null;
while (complexities.size() > 0 && pair == null) {
Integer complexity = complexities.remove(complexities.size() - 1);
Set<Pair<Structure<?>, SaplingGeneration>> placeable = groups.get(complexity).stream().filter(p -> p.getRight().pattern.canPlace(world, pos, p.getLeft().size(), p.getLeft().isRotatable(), p.getLeft().isMirrorable())).collect(Collectors.toSet());
double totalWeight = placeable.stream().mapToDouble(RCSaplingGenerator::getSpawnWeight).sum();
if (complexity == vanillaComplexity && considerVanilla) {
if (random.nextDouble() * (totalWeight * RCConfig.baseSaplingSpawnWeight + 1) < 1)
break;
}
if (totalWeight > 0)
pair = WeightedSelector.select(random, placeable, RCSaplingGenerator::getSpawnWeight);
}
return pair;
}
use of net.minecraft.world.gen.structure.StructureBoundingBox in project RecurrentComplex by Ivorforce.
the class CommandSelectMove method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
RCParameters parameters = RCParameters.of(args, "mirror", "noselect");
SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
RCCommands.assertSize(commandSender, selectionOwner);
BlockPos pos = parameters.pos("x", "y", "z", selectionOwner.getSelectedPoint1(), false).require();
AxisAlignedTransform2D transform = parameters.transform("rotation", "mirror").optional().orElse(AxisAlignedTransform2D.ORIGINAL);
boolean noselect = parameters.has("noselect");
BlockArea area = selectionOwner.getSelection();
IvWorldData worldData = IvWorldData.capture(commandSender.getEntityWorld(), area, true);
NBTTagCompound worldDataCompound = worldData.createTagCompound();
GenericStructure structure = GenericStructure.createDefaultStructure();
structure.worldDataCompound = worldDataCompound;
OperationRegistry.queueOperation(new OperationMulti(new OperationClearArea(area), new OperationGenerateStructure(structure, null, transform, pos, true).prepare((WorldServer) commandSender.getEntityWorld())), commandSender);
if (!noselect) {
StructureGenerator<GenericStructure.InstanceData> generator = new StructureGenerator<>(structure).transform(transform).lowerCoord(pos);
//noinspection OptionalGetWithoutIsPresent
StructureBoundingBox boundingBox = generator.boundingBox().get();
selectionOwner.setSelection(RCBlockAreas.from(boundingBox));
}
}
Aggregations