use of net.minecraft.util.math.ChunkPos in project Railcraft by Railcraft.
the class EntityCartWorldspike method forceChunkLoading.
public void forceChunkLoading(int xChunk, int zChunk) {
if (ticket == null)
return;
setupChunks(xChunk, zChunk);
Set<ChunkPos> innerChunks = ChunkManager.getInstance().getChunksAround(xChunk, zChunk, 1);
// System.out.println("Chunks Loaded = " + Arrays.toString(chunks.toArray()));
for (ChunkPos chunk : chunks) {
ForgeChunkManager.forceChunk(ticket, chunk);
ForgeChunkManager.reorderChunk(ticket, chunk);
}
for (ChunkPos chunk : innerChunks) {
ForgeChunkManager.forceChunk(ticket, chunk);
ForgeChunkManager.reorderChunk(ticket, chunk);
}
ChunkPos myChunk = new ChunkPos(xChunk, zChunk);
ForgeChunkManager.forceChunk(ticket, myChunk);
ForgeChunkManager.reorderChunk(ticket, myChunk);
}
use of net.minecraft.util.math.ChunkPos in project RecurrentComplex by Ivorforce.
the class CommandDecorate method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
RCParameters parameters = RCParameters.of(args);
BlockSurfaceArea area = new BlockSurfaceArea(parameters.iv().surfacePos(commandSender.getPosition(), false).require(), parameters.iv().move(2).surfacePos(commandSender.getPosition(), false).require());
BlockSurfaceArea chunkArea = new BlockSurfaceArea(getChunkPos(area.getPoint1()), getChunkPos(area.getPoint2()));
Predicate<Structure> structurePredicate = parameters.rc("exp").structurePredicate().optional().orElse(structureInfo -> true);
WorldServer world = (WorldServer) commandSender.getEntityWorld();
chunkArea.forEach(coord -> WorldGenStructures.decorate(world, world.rand, new ChunkPos(coord.x, coord.z), structurePredicate));
}
use of net.minecraft.util.math.ChunkPos 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);
}
use of net.minecraft.util.math.ChunkPos in project RecurrentComplex by Ivorforce.
the class GenerationSanityChecker method init.
public static void init() {
FAILED_DIMENSIONS.clear();
// Sanity check for chunk population
GameRegistry.registerWorldGenerator((Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) -> {
ChunkPos pos = new ChunkPos(chunkX, chunkZ);
if (!WorldStructureGenerationData.get(world).checkChunk(pos))
return;
if (FAILED_DIMENSIONS.add(world.provider.getDimension()))
RecurrentComplex.logger.error(String.format("Chunk finished generating without Forge population being triggered (dimension %d). This is a bug with the dimension - please report this to the dimension's author. Recurrent Complex will proceed to generate in compatibility mode.", world.provider.getDimension()));
WorldGenStructures.decorate((WorldServer) world, random, pos, null);
}, 1);
}
use of net.minecraft.util.math.ChunkPos in project RecurrentComplex by Ivorforce.
the class WorldStructureGenerationData method addEntry.
public Set<ChunkPos> addEntry(Entry entry) {
entryMap.put(entry.getUuid(), entry);
Set<ChunkPos> rasterized = entry.rasterize();
for (ChunkPos coords : rasterized) chunkMap.put(coords, entry);
if (entry instanceof StructureEntry)
instanceMap.put(((StructureEntry) entry).getStructureID(), (StructureEntry) entry);
markDirty();
return Sets.intersection(checkedChunks, rasterized);
}
Aggregations