use of net.minecraft.world.gen.structure.StructureBoundingBox in project RecurrentComplex by Ivorforce.
the class GenericVillageCreationHandler method buildComponent.
@Override
public StructureVillagePieces.Village buildComponent(StructureVillagePieces.PieceWeight villagePiece, StructureVillagePieces.Start startPiece, List<StructureComponent> pieces, Random random, int x, int y, int z, EnumFacing front, int generationDepth) {
Structure structure = StructureRegistry.INSTANCE.get(structureID);
if (structure == null)
return kill(villagePiece);
GenerationType generationType = structure.generationType(generationID);
if (!(generationType instanceof VanillaGeneration))
return kill(villagePiece);
VanillaGeneration vanillaGenInfo = (VanillaGeneration) generationType;
boolean mirrorX = structure.isMirrorable() && random.nextBoolean();
AxisAlignedTransform2D transform = GenericVillagePiece.getTransform(vanillaGenInfo.front, mirrorX, front.getOpposite());
if (!vanillaGenInfo.generatesIn(startPiece.biome) || (!structure.isRotatable() && transform.getRotation() != 0))
return kill(villagePiece);
int[] structureSize = RCAxisAlignedTransform.applySize(transform, structure.size());
StructureBoundingBox strucBB = Structures.boundingBox(new BlockPos(x, y, z), structureSize);
if (!GenericVillagePiece.canVillageGoDeeperC(strucBB) || StructureComponent.findIntersecting(pieces, strucBB) != null)
return null;
GenericVillagePiece genericVillagePiece = GenericVillagePiece.create(structureID, generationID, startPiece, generationDepth);
genericVillagePiece.seed = random.nextLong();
if (genericVillagePiece == null)
return kill(villagePiece);
genericVillagePiece.setIds(structureID, generationID);
genericVillagePiece.setOrientation(front, mirrorX, strucBB);
return genericVillagePiece;
}
use of net.minecraft.world.gen.structure.StructureBoundingBox in project RecurrentComplex by Ivorforce.
the class TransformerRuins method transform.
@Override
public void transform(InstanceData instanceData, Phase phase, StructureSpawnContext context, IvWorldData worldData, RunTransformer transformer) {
// Can't use a cache since we modify blocks
if (phase == Phase.AFTER) {
WorldServer world = context.environment.world;
IvBlockCollection blockCollection = worldData.blockCollection;
int[] areaSize = new int[] { blockCollection.width, blockCollection.height, blockCollection.length };
BlockPos lowerCoord = StructureBoundingBoxes.min(context.boundingBox);
Map<BlockPos, NBTTagCompound> tileEntityCompounds = new HashMap<>();
for (NBTTagCompound tileEntityCompound : worldData.tileEntities) {
BlockPos key = new BlockPos(tileEntityCompound.getInteger("x"), tileEntityCompound.getInteger("y"), tileEntityCompound.getInteger("z"));
tileEntityCompounds.put(key, tileEntityCompound);
}
BlockPos.MutableBlockPos dest = new BlockPos.MutableBlockPos(lowerCoord);
for (BlockPos sourcePos : instanceData.fallingBlocks) {
IBlockState source = blockCollection.getBlockState(sourcePos);
if (!canLand(source))
continue;
IvMutableBlockPos.add(context.transform.applyOn(sourcePos, dest, areaSize), lowerCoord);
// TODO Bounce left/right
IBlockState destState;
while (dest.getY() > 0 && (destState = world.getBlockState(dest)).getBlock().isReplaceable(world, dest)) {
IvMutableBlockPos.offset(dest, dest, EnumFacing.DOWN);
}
IvMutableBlockPos.offset(dest, dest, EnumFacing.UP);
IBlockState state = PosTransformer.transformBlockState(source, context.transform);
GenericStructure.setBlock(context, areaSize, dest, state, () -> tileEntityCompounds.get(sourcePos));
}
StructureBoundingBox dropAreaBB = context.boundingBox;
RecurrentComplex.forgeEventHandler.disabledTileDropAreas.add(dropAreaBB);
if (blockErosion > 0.0f || vineGrowth > 0.0f) {
// Only place things on sides we KNOW we have generated already.
StructureBoundingBox relevantBB = context.generationBB != null ? Structures.intersection(context.boundingBox, context.generationBB) : context.boundingBox;
for (BlockPos sourceCoord : BlockAreas.mutablePositions(blockCollection.area())) {
BlockPos worldCoord = context.transform.apply(sourceCoord, areaSize).add(StructureBoundingBoxes.min(context.boundingBox));
if (context.includes(worldCoord)) {
IBlockState state = world.getBlockState(worldCoord);
if (!transformer.transformer.skipGeneration(transformer.instanceData, context, worldCoord, state, worldData, sourceCoord))
decayBlock(world, context.random, state, worldCoord, relevantBB);
}
}
}
RecurrentComplex.forgeEventHandler.disabledTileDropAreas.remove(dropAreaBB);
}
}
use of net.minecraft.world.gen.structure.StructureBoundingBox in project NetherEx by LogicTechCorp.
the class WorldGenUtil method generateStructure.
public static void generateStructure(World world, BlockPos pos, Random rand, Template template, PlacementSettings placementSettings, ResourceLocation[] lootTables, ResourceLocation[] spawnerMobs) {
try {
List<Template.BlockInfo> blocks = (List<Template.BlockInfo>) FIELD_BLOCKS.get(template);
List<Template.EntityInfo> entities = (List<Template.EntityInfo>) FIELD_ENTITIES.get(template);
if ((!blocks.isEmpty() || !placementSettings.getIgnoreEntities() && !entities.isEmpty()) && template.getSize().getX() >= 1 && template.getSize().getY() >= 1 && template.getSize().getZ() >= 1) {
BlockRotationProcessor processor = new BlockRotationProcessor(pos, placementSettings);
Block block = placementSettings.getReplacedBlock();
StructureBoundingBox boundingBox = placementSettings.getBoundingBox();
for (Template.BlockInfo blockInfo : blocks) {
BlockPos blockPos = Template.transformedBlockPos(placementSettings, blockInfo.pos).add(pos);
Template.BlockInfo blockInfo1 = processor != null ? processor.processBlock(world, blockPos, blockInfo) : blockInfo;
if (blockInfo1 != null) {
Block block1 = blockInfo1.blockState.getBlock();
if ((block == null || block != block1) && (!placementSettings.getIgnoreStructureBlock() || block1 != Blocks.STRUCTURE_BLOCK) && (boundingBox == null || boundingBox.isVecInside(blockPos))) {
IBlockState state = blockInfo1.blockState.withMirror(placementSettings.getMirror()).withRotation(placementSettings.getRotation());
if (blockInfo1.tileentityData != null) {
TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity != null) {
if (tileEntity instanceof IInventory) {
((IInventory) tileEntity).clear();
}
world.setBlockState(blockPos, Blocks.BARRIER.getDefaultState(), 4);
}
}
if (world.setBlockState(blockPos, state, 3) && blockInfo1.tileentityData != null) {
TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity != null) {
blockInfo1.tileentityData.setInteger("x", blockPos.getX());
blockInfo1.tileentityData.setInteger("y", blockPos.getY());
blockInfo1.tileentityData.setInteger("z", blockPos.getZ());
tileEntity.readFromNBT(blockInfo1.tileentityData);
tileEntity.mirror(placementSettings.getMirror());
tileEntity.rotate(placementSettings.getRotation());
if (state.getBlock() instanceof BlockChest) {
((TileEntityChest) tileEntity).setLootTable(lootTables[rand.nextInt(lootTables.length)], rand.nextLong());
} else if (state.getBlock() instanceof BlockMobSpawner) {
((TileEntityMobSpawner) tileEntity).getSpawnerBaseLogic().setEntityId(spawnerMobs[rand.nextInt(spawnerMobs.length)]);
} else if (state.getBlock() instanceof BlockUrnOfSorrow) {
((TileEntityUrnOfSorrow) tileEntity).setCanBreak(false);
}
}
}
}
}
}
for (Template.BlockInfo blockInfo2 : blocks) {
if (block == null || block != blockInfo2.blockState.getBlock()) {
BlockPos blockPos1 = Template.transformedBlockPos(placementSettings, blockInfo2.pos).add(pos);
if (boundingBox == null || boundingBox.isVecInside(blockPos1)) {
world.notifyNeighborsRespectDebug(blockPos1, blockInfo2.blockState.getBlock(), false);
if (blockInfo2.tileentityData != null) {
TileEntity tileEntity = world.getTileEntity(blockPos1);
if (tileEntity != null) {
tileEntity.markDirty();
}
}
}
}
}
if (!placementSettings.getIgnoreEntities()) {
addEntitiesToWorld(world, pos, placementSettings, entities, boundingBox);
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
use of net.minecraft.world.gen.structure.StructureBoundingBox in project RecurrentComplex by Ivorforce.
the class CommandGenerateStructure method execute.
@Override
@ParametersAreNonnullByDefault
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(null);
GenerationType generationType = parameters.rc("gen").generationType(structure).require();
BlockSurfacePos pos = parameters.surfacePos("x", "z", sender.getPosition(), false).require();
String seed = parameters.get("seed").first().optional().orElse(null);
boolean select = parameters.has("select");
Placer placer = generationType.placer();
StructureGenerator<?> generator = new StructureGenerator<>(structure).world(world).generationInfo(generationType).seed(RCStrings.seed(seed)).structureID(structureID).randomPosition(pos, placer).fromCenter(true).transform(transform);
Optional<StructureBoundingBox> boundingBox = generator.boundingBox();
if (!boundingBox.isPresent())
throw ServerTranslations.commandException("commands.strucGen.noPlace");
if (structure instanceof GenericStructure && world == sender.getEntityWorld()) {
GenericStructure genericStructureInfo = (GenericStructure) structure;
BlockPos lowerCoord = StructureBoundingBoxes.min(boundingBox.get());
OperationRegistry.queueOperation(new OperationGenerateStructure(genericStructureInfo, generationType.id(), generator.transform(), lowerCoord, false).withSeed(seed).withStructureID(structureID).prepare(world), sender);
} else {
if (generator.generate() == null)
throw ServerTranslations.commandException("commands.strucGen.noPlace");
}
if (select) {
SelectionOwner owner = RCCommands.getSelectionOwner(sender, null, false);
owner.setSelection(RCBlockAreas.from(boundingBox.get()));
}
}
use of net.minecraft.world.gen.structure.StructureBoundingBox in project RecurrentComplex by Ivorforce.
the class StructureGenerator method generate.
/**
* @return null when creation failed, empty when no entry was created and an entry when there was
*/
public Optional<WorldStructureGenerationData.StructureEntry> generate() {
Optional<S> optionalInstanceData = instanceData();
if (!optionalInstanceData.isPresent())
return failGenerate("failed to place");
S instanceData = optionalInstanceData.get();
StructureSpawnContext spawn = spawn().get();
Structure<S> structure = structure();
String structureID = structureID();
boolean firstTime = spawn.generateMaturity.isFirstTime();
WorldServer world = spawn.environment.world;
StructureBoundingBox boundingBox = spawn.boundingBox;
if (maturity().isSuggest() && (boundingBox.minY < MIN_DIST_TO_LIMIT || boundingBox.maxY > world.getHeight() - 1 - MIN_DIST_TO_LIMIT || (RCConfig.avoidOverlappingGeneration && !allowOverlaps && !WorldStructureGenerationData.get(world).entriesAt(boundingBox).noneMatch(WorldStructureGenerationData.Entry::blocking)) || RCEventBus.INSTANCE.post(new StructureGenerationEvent.Suggest(structure, spawn)) || (structureID != null && MinecraftForge.EVENT_BUS.post(new StructureGenerationEventLite.Suggest(world, structureID, boundingBox, spawn.generationLayer, firstTime)))))
return failGenerate("unknown reason");
if (firstTime) {
RCEventBus.INSTANCE.post(new StructureGenerationEvent.Pre(structure, spawn));
if (structureID != null)
MinecraftForge.EVENT_BUS.post(new StructureGenerationEventLite.Pre(world, structureID, boundingBox, spawn.generationLayer, firstTime));
}
structure.generate(spawn, instanceData, RCConfig.getUniversalTransformer());
if (!firstTime)
return Optional.empty();
RecurrentComplex.logger.trace(String.format("Generated structure '%s' in %s (%d)", name(structureID), boundingBox, world.provider.getDimension()));
RCEventBus.INSTANCE.post(new StructureGenerationEvent.Post(structure, spawn));
if (structureID != null)
MinecraftForge.EVENT_BUS.post(new StructureGenerationEventLite.Post(world, structureID, boundingBox, spawn.generationLayer, firstTime));
if (structureID == null || !memorize)
return Optional.empty();
String generationInfoID = generationType != null ? generationType.id() : null;
WorldStructureGenerationData.StructureEntry structureEntry = WorldStructureGenerationData.StructureEntry.complete(structureID, generationInfoID, boundingBox, spawn.transform, !partially);
structureEntry.blocking = structure.isBlocking();
// Been there done that
structureEntry.firstTime = false;
structureEntry.seed = seed();
try {
structureEntry.instanceData = instanceData.writeToNBT();
} catch (Exception e) {
RecurrentComplex.logger.error(String.format("Error saving instance data for structure %s in %s", structure, boundingBox), e);
}
Collection<ChunkPos> existingChunks = WorldStructureGenerationData.get(world).addEntry(structureEntry).stream().collect(Collectors.toList());
// Complement in all chunks that already exist
if (partially) {
maturity(StructureSpawnContext.GenerateMaturity.COMPLEMENT);
StructureBoundingBox oldBB = this.generationBB;
for (ChunkPos existingChunk : existingChunks) {
generationBB(Structures.chunkBoundingBox(existingChunk));
structure.generate(spawn().get(), instanceData, RCConfig.getUniversalTransformer());
}
generationBB(oldBB);
}
return Optional.of(structureEntry);
}
Aggregations