Skip to content

Commit

Permalink
removed useless ( i hope) duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
gemsb committed Aug 24, 2024
1 parent 91449f5 commit 3c7f40a
Showing 1 changed file with 12 additions and 57 deletions.
69 changes: 12 additions & 57 deletions src/main/java/net/ugi/sculk_depths/portal/GenerateStructureAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,10 @@ public static boolean generateStructure(World originalWorld, RegistryKey<World>
GenerateStructureAPI.generateStructure(originalWorld, ModDimensions.SCULK_DEPTHS_LEVEL_KEY, structure_, pos);
});*/
}

public static boolean generateStructure(World originalWorld, RegistryKey<World> targetWorldKey, RegistryKey<Structure> structure, BlockPos pos){
if(originalWorld.isClient)return false;
Optional<RegistryEntry.Reference<Structure>> structureReference = originalWorld.getRegistryManager().get(RegistryKeys.STRUCTURE).getEntry(structure);
if(structureReference.isEmpty()) return false;
ServerWorld serverWorld = originalWorld.getServer().getWorld(targetWorldKey);
StructureStart structureStart = structureStart(originalWorld, targetWorldKey, structure, pos);
if(structureStart == null)return false;
BlockBox blockBox = structureStart.getBoundingBox();
ChunkPos chunkPos = new ChunkPos(ChunkSectionPos.getSectionCoord(blockBox.getMinX()), ChunkSectionPos.getSectionCoord(blockBox.getMinZ()));
ChunkPos chunkPos2 = new ChunkPos(ChunkSectionPos.getSectionCoord(blockBox.getMaxX()), ChunkSectionPos.getSectionCoord(blockBox.getMaxZ()));
ChunkPos[] chunkPosArray = ChunkPos.stream(chunkPos, chunkPos2).toArray(ChunkPos[]::new);
return generate(serverWorld, structureStart, chunkPosArray);
return generateStructure(originalWorld, targetWorldKey, structure.getValue(), pos);
}

public static boolean generateStructure(World originalWorld, RegistryKey<World> targetWorldKey, RegistryKey<Structure> structure, StructureStart structureStart){
if(originalWorld.isClient)return false;
if(structureStart == null)return false;
Optional<RegistryEntry.Reference<Structure>> structureReference = originalWorld.getRegistryManager().get(RegistryKeys.STRUCTURE).getEntry(structure);
if(structureReference.isEmpty()) return false;
ServerWorld serverWorld = originalWorld.getServer().getWorld(targetWorldKey);
BlockBox blockBox = structureStart.getBoundingBox();
ChunkPos chunkPos = new ChunkPos(ChunkSectionPos.getSectionCoord(blockBox.getMinX()), ChunkSectionPos.getSectionCoord(blockBox.getMinZ()));
ChunkPos chunkPos2 = new ChunkPos(ChunkSectionPos.getSectionCoord(blockBox.getMaxX()), ChunkSectionPos.getSectionCoord(blockBox.getMaxZ()));
ChunkPos[] chunkPosArray = ChunkPos.stream(chunkPos, chunkPos2).toArray(ChunkPos[]::new);
return generate(serverWorld, structureStart, chunkPosArray);
}

public static boolean generateStructure(World originalWorld, RegistryKey<World> targetWorldKey, Identifier structure, StructureStart structureStart){
if(originalWorld.isClient)return false;
Expand All @@ -80,47 +57,22 @@ public static boolean generateStructure(World originalWorld, RegistryKey<World>
ChunkPos[] chunkPosArray = ChunkPos.stream(chunkPos, chunkPos2).toArray(ChunkPos[]::new);
return generate(serverWorld, structureStart, chunkPosArray);
}

public static boolean generateStructurePartial(World originalWorld, RegistryKey<World> targetWorldKey, RegistryKey<Structure> structure, StructureStart structureStart, ChunkPos[] chunkPosArray){
if(originalWorld.isClient)return false;
if(structureStart == null)return false;
Optional<RegistryEntry.Reference<Structure>> structureReference = originalWorld.getRegistryManager().get(RegistryKeys.STRUCTURE).getEntry(structure);
if(structureReference.isEmpty()) return false;
ServerWorld serverWorld = originalWorld.getServer().getWorld(targetWorldKey);
return generate(serverWorld, structureStart, chunkPosArray);
public static boolean generateStructure(World originalWorld, RegistryKey<World> targetWorldKey, RegistryKey<Structure> structure, StructureStart structureStart){
return generateStructure(originalWorld, targetWorldKey, structure.getValue(), structureStart);
}



public static boolean generateStructurePartial(World originalWorld, RegistryKey<World> targetWorldKey, Identifier structure, StructureStart structureStart, ChunkPos[] chunkPosArray){
if(originalWorld.isClient)return false;
if(structureStart == null)return false;
Optional<RegistryEntry.Reference<Structure>> structureReference = originalWorld.getRegistryManager().get(RegistryKeys.STRUCTURE).getEntry(structure);
if(structureReference.isEmpty()) return false;
ServerWorld serverWorld = originalWorld.getServer().getWorld(targetWorldKey);
ChunkGenerator chunkGenerator = serverWorld.getChunkManager().getChunkGenerator();
return generate( serverWorld, structureStart, chunkPosArray);
}


public static StructureStart structureStart (World originalWorld, RegistryKey<World> targetWorldKey, RegistryKey<Structure> structureKey, BlockPos pos){
if(originalWorld.isClient)return null;
RegistryEntry.Reference<Structure> structure = originalWorld.getRegistryManager().get(RegistryKeys.STRUCTURE).getEntry(structureKey).get();
System.out.println("1");
ServerWorld serverWorld = originalWorld.getServer().getWorld(targetWorldKey);
ChunkGenerator chunkGenerator = serverWorld.getChunkManager().getChunkGenerator();
Structure structure2 = structure.value();
StructureStart structureStart = structure2.createStructureStart(
originalWorld.getRegistryManager(),
chunkGenerator,
chunkGenerator.getBiomeSource(),
serverWorld.getChunkManager().getNoiseConfig(),
serverWorld.getStructureTemplateManager(),
originalWorld.getServer().getWorld(World.OVERWORLD).getSeed(),//maybe fix rotation
new ChunkPos(pos),
0,
serverWorld,
biome -> true
);
return structureStart;
public static boolean generateStructurePartial(World originalWorld, RegistryKey<World> targetWorldKey, RegistryKey<Structure> structure, StructureStart structureStart, ChunkPos[] chunkPosArray){
return generateStructurePartial(originalWorld, targetWorldKey, structure.getValue(), structureStart, chunkPosArray);
}

public static StructureStart structureStart (World originalWorld, RegistryKey<World> targetWorldKey, Identifier structureKey, BlockPos pos){
Expand All @@ -144,6 +96,9 @@ public static StructureStart structureStart (World originalWorld, RegistryKey<W
);
return structureStart;
}
public static StructureStart structureStart (World originalWorld, RegistryKey<World> targetWorldKey, RegistryKey<Structure> structureKey, BlockPos pos){
return structureStart (originalWorld,targetWorldKey,structureKey.getValue(),pos);;
}

private static boolean generate(ServerWorld serverWorld, StructureStart structureStart, ChunkPos[] chunkPosArray){
ChunkGenerator chunkGenerator = serverWorld.getChunkManager().getChunkGenerator();
Expand All @@ -157,7 +112,7 @@ private static boolean generate(ServerWorld serverWorld, StructureStart structur
return false;
}*/
for (ChunkPos chunkPosx : chunkPosArray) {
structureStart.place(
structureStart.place(
serverWorld,
serverWorld.getStructureAccessor(),
chunkGenerator,
Expand Down Expand Up @@ -188,4 +143,4 @@ private static void unloadNearbyChunks(ChunkPos[] chunkPosArray, ServerWorld wor
world.setChunkForced(chunkPos.x, chunkPos.z, true);
}
}
}
}

0 comments on commit 3c7f40a

Please sign in to comment.