Files
src
build.gradle
gradle.properties
settings.gradle
Code
53 42,853
src/main/java/com/kodari/skyponies/SkyWorldFeatures.java
package com.kodari.skyponies;
import com.kodari.skyponies.entity.UnicornEntity;
import com.kodari.skyponies.item.SkyPassageItem;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.minecraft.block.Blocks;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Heightmap;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
public final class SkyWorldFeatures implements ModInitializer {
public static final RegistryKey<World> SKY_WORLD = RegistryKey.of(
RegistryKeys.WORLD, new Identifier(SkyPoniesMod.MOD_ID, "bright_sky"));
private static final RegistryKey<Biome> SKY_BIOME = RegistryKey.of(
RegistryKeys.BIOME, new Identifier(SkyPoniesMod.MOD_ID, "bright_sky"));
public static final Item SKY_PASSAGE = Registry.register(
Registries.ITEM,
new Identifier(SkyPoniesMod.MOD_ID, "sky_passage"),
new SkyPassageItem()
);
public static final ItemGroup SKY_ITEMS = FabricItemGroup.builder(new Identifier(SkyPoniesMod.MOD_ID, "sky_items"))
.icon(() -> new ItemStack(SKY_PASSAGE))
.entries((context, entries) -> entries.add(SKY_PASSAGE))
.build();
@Override
public void onInitialize() {
BiomeModifications.addSpawn(BiomeSelectors.includeByKey(SKY_BIOME), SpawnGroup.CREATURE,
SkyPoniesMod.PEGASUS, 24, 1, 3);
BiomeModifications.addSpawn(BiomeSelectors.foundInOverworld(), SpawnGroup.CREATURE,
SkyPoniesMod.UNICORN, 1, 1, 1);
ServerLifecycleEvents.SERVER_STARTED.register(SkyWorldFeatures::buildFairytaleCastle);
}
private static void buildFairytaleCastle(MinecraftServer server) {
ServerWorld world = server.getOverworld();
BlockPos worldSpawn = world.getSpawnPos();
int centerX = worldSpawn.getX();
int centerZ = worldSpawn.getZ();
int markerX = centerX + 10;
int markerZ = centerZ + 10;
int markerSurfaceY = world.getTopY(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, markerX, markerZ);
if (world.getBlockState(new BlockPos(markerX, markerSurfaceY - 1, markerZ)).isOf(Blocks.LODESTONE)) {
return;
}
int baseY = world.getTopY(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, centerX, centerZ);
buildCastle(world, centerX, baseY, centerZ);
world.setBlockState(new BlockPos(markerX, markerSurfaceY, markerZ), Blocks.LODESTONE.getDefaultState());
spawnCastleUnicorns(world, centerX, baseY, centerZ);
}
private static void buildCastle(ServerWorld world, int centerX, int baseY, int centerZ) {
for (int x = -8; x <= 8; x++) {
for (int z = -8; z <= 8; z++) {
place(world, centerX + x, baseY, centerZ + z, Blocks.QUARTZ_BLOCK);
}
}
for (int y = 1; y <= 5; y++) {
for (int offset = -8; offset <= 8; offset++) {
if (!(offset >= -1 && offset <= 1 && y <= 2)) {
place(world, centerX + offset, baseY + y, centerZ + 8, Blocks.QUARTZ_BLOCK);
}
place(world, centerX + offset, baseY + y, centerZ - 8, Blocks.QUARTZ_BLOCK);
place(world, centerX + 8, baseY + y, centerZ + offset, Blocks.QUARTZ_BLOCK);
place(world, centerX - 8, baseY + y, centerZ + offset, Blocks.QUARTZ_BLOCK);
}
}
for (int towerX : new int[]{-7, 7}) {
for (int towerZ : new int[]{-7, 7}) {
for (int y = 1; y <= 10; y++) {
for (int x = -2; x <= 2; x++) {
for (int z = -2; z <= 2; z++) {
if (Math.abs(x) == 2 || Math.abs(z) == 2 || y == 10) {
place(world, centerX + towerX + x, baseY + y, centerZ + towerZ + z,
y % 3 == 0 ? Blocks.QUARTZ_PILLAR : Blocks.QUARTZ_BLOCK);
}
}
}
}
place(world, centerX + towerX, baseY + 11, centerZ + towerZ, Blocks.SEA_LANTERN);
}
}
for (int y = 1; y <= 7; y++) {
for (int x = -3; x <= 3; x++) {
for (int z = -3; z <= 3; z++) {
boolean edge = Math.abs(x) == 3 || Math.abs(z) == 3;
if (y == 7 || edge) {
if (!(z == 3 && x == 0 && y <= 2)) {
place(world, centerX + x, baseY + y, centerZ + z, Blocks.QUARTZ_BLOCK);
}
}
}
}
}
place(world, centerX, baseY + 4, centerZ, Blocks.SEA_LANTERN);
}
private static void spawnCastleUnicorns(ServerWorld world, int centerX, int baseY, int centerZ) {
int[][] positions = {{-2, 0}, {2, 0}, {0, -2}};
for (int[] offset : positions) {
UnicornEntity unicorn = new UnicornEntity(SkyPoniesMod.UNICORN, world);
unicorn.setPosition(centerX + offset[0] + 0.5D, baseY + 1.0D, centerZ + offset[1] + 0.5D);
unicorn.setPersistent();
world.spawnEntity(unicorn);
}
}
private static void place(ServerWorld world, int x, int y, int z, net.minecraft.block.Block block) {
world.setBlockState(new BlockPos(x, y, z), block.getDefaultState());
}
}