Change Java whitespace handling in .editorconfig (#425)

* Change whitespace handling in .editorconfig

* Reformat code

* fix format error

* Reformat code

---------

Co-authored-by: Zoë Gidiere <duplexsys@protonmail.com>
This commit is contained in:
Astrashh
2023-11-13 11:57:01 +11:00
committed by GitHub
parent a73fda7d04
commit defd775f13
793 changed files with 7579 additions and 7577 deletions
@@ -5,17 +5,17 @@ import java.util.concurrent.atomic.AtomicReference;
public final class CommonPlatform {
private static final AtomicReference<ModPlatform> platform = new AtomicReference<>();
public static ModPlatform get() {
ModPlatform modPlatform = platform.get();
if(modPlatform == null) {
throw new IllegalStateException("Platform is not yet initialised!");
}
return modPlatform;
}
public static void initialize(ModPlatform modPlatform) {
if(!platform.compareAndSet(null, modPlatform)) {
throw new IllegalStateException("Platform has already been initialized to " + platform.get());
@@ -37,37 +37,37 @@ public abstract class MinecraftAddon implements BaseAddon {
private static final Version VERSION = Versions.getVersion(1, 0, 0);
private static final Logger logger = LoggerFactory.getLogger(MinecraftAddon.class);
private final ModPlatform modPlatform;
public MinecraftAddon(ModPlatform modPlatform) {
this.modPlatform = modPlatform;
}
@Override
public void initialize() {
modPlatform.getEventManager()
.getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class)
.then(event -> event.getPack().getContext().put(event.loadTemplate(new PreLoadCompatibilityOptions())))
.global();
.getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class)
.then(event -> event.getPack().getContext().put(event.loadTemplate(new PreLoadCompatibilityOptions())))
.global();
modPlatform.getEventManager()
.getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPostLoadEvent.class)
.then(event -> event.getPack().getContext().put(event.loadTemplate(new PostLoadCompatibilityOptions())))
.priority(100)
.global();
.getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPostLoadEvent.class)
.then(event -> event.getPack().getContext().put(event.loadTemplate(new PostLoadCompatibilityOptions())))
.priority(100)
.global();
modPlatform.getEventManager()
.getHandler(FunctionalEventHandler.class)
.register(this, ConfigurationLoadEvent.class)
.then(event -> {
if(event.is(Biome.class)) {
event.getLoadedObject(Biome.class).getContext().put(event.load(new VanillaBiomeProperties()));
}
})
.global();
.getHandler(FunctionalEventHandler.class)
.register(this, ConfigurationLoadEvent.class)
.then(event -> {
if(event.is(Biome.class)) {
event.getLoadedObject(Biome.class).getContext().put(event.load(new VanillaBiomeProperties()));
}
})
.global();
}
@Override
public Version getVersion() {
return VERSION;
@@ -56,72 +56,72 @@ import com.dfsek.terra.mod.util.PresetUtil;
public abstract class ModPlatform extends AbstractPlatform {
private final ItemHandle itemHandle = new MinecraftItemHandle();
private final WorldHandle worldHandle = new MinecraftWorldHandle();
public abstract MinecraftServer getServer();
public void registerWorldTypes(BiConsumer<Identifier, WorldPreset> registerFunction) {
getRawConfigRegistry()
.forEach(pack -> PresetUtil.createDefault(pack, this).apply(registerFunction));
.forEach(pack -> PresetUtil.createDefault(pack, this).apply(registerFunction));
}
@Override
public void register(TypeRegistry registry) {
super.register(registry);
registry.registerLoader(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker))
.registerLoader(Identifier.class, (type, o, loader, depthTracker) -> {
Identifier identifier = Identifier.tryParse((String) o);
if(identifier == null)
throw new LoadException("Invalid identifier: " + o, depthTracker);
return identifier;
})
.registerLoader(Precipitation.class, (type, o, loader, depthTracker) -> Precipitation.valueOf(((String) o).toUpperCase(
Locale.ROOT)))
.registerLoader(GrassColorModifier.class,
(type, o, loader, depthTracker) -> GrassColorModifier.valueOf(((String) o).toUpperCase(
Locale.ROOT)))
.registerLoader(GrassColorModifier.class,
(type, o, loader, depthTracker) -> TemperatureModifier.valueOf(((String) o).toUpperCase(
Locale.ROOT)))
.registerLoader(BiomeParticleConfig.class, BiomeParticleConfigTemplate::new)
.registerLoader(SoundEvent.class, SoundEventTemplate::new)
.registerLoader(BiomeMoodSound.class, BiomeMoodSoundTemplate::new)
.registerLoader(BiomeAdditionsSound.class, BiomeAdditionsSoundTemplate::new)
.registerLoader(MusicSound.class, MusicSoundTemplate::new)
.registerLoader(EntityType.class, EntityTypeTemplate::new)
.registerLoader(SpawnCostConfig.class, SpawnCostConfig::new)
.registerLoader(SpawnEntry.class, SpawnEntryTemplate::new)
.registerLoader(SpawnGroup.class, SpawnGroupTemplate::new)
.registerLoader(SpawnTypeConfig.class, SpawnTypeConfig::new)
.registerLoader(SpawnSettings.class, SpawnSettingsTemplate::new)
.registerLoader(VillagerType.class, VillagerTypeTemplate::new);
.registerLoader(Identifier.class, (type, o, loader, depthTracker) -> {
Identifier identifier = Identifier.tryParse((String) o);
if(identifier == null)
throw new LoadException("Invalid identifier: " + o, depthTracker);
return identifier;
})
.registerLoader(Precipitation.class, (type, o, loader, depthTracker) -> Precipitation.valueOf(((String) o).toUpperCase(
Locale.ROOT)))
.registerLoader(GrassColorModifier.class,
(type, o, loader, depthTracker) -> GrassColorModifier.valueOf(((String) o).toUpperCase(
Locale.ROOT)))
.registerLoader(GrassColorModifier.class,
(type, o, loader, depthTracker) -> TemperatureModifier.valueOf(((String) o).toUpperCase(
Locale.ROOT)))
.registerLoader(BiomeParticleConfig.class, BiomeParticleConfigTemplate::new)
.registerLoader(SoundEvent.class, SoundEventTemplate::new)
.registerLoader(BiomeMoodSound.class, BiomeMoodSoundTemplate::new)
.registerLoader(BiomeAdditionsSound.class, BiomeAdditionsSoundTemplate::new)
.registerLoader(MusicSound.class, MusicSoundTemplate::new)
.registerLoader(EntityType.class, EntityTypeTemplate::new)
.registerLoader(SpawnCostConfig.class, SpawnCostConfig::new)
.registerLoader(SpawnEntry.class, SpawnEntryTemplate::new)
.registerLoader(SpawnGroup.class, SpawnGroupTemplate::new)
.registerLoader(SpawnTypeConfig.class, SpawnTypeConfig::new)
.registerLoader(SpawnSettings.class, SpawnSettingsTemplate::new)
.registerLoader(VillagerType.class, VillagerTypeTemplate::new);
}
private ProtoPlatformBiome parseBiome(String id, DepthTracker tracker) throws LoadException {
Identifier identifier = Identifier.tryParse(id);
if(!biomeRegistry().containsId(identifier)) throw new LoadException("Invalid Biome ID: " + identifier, tracker); // failure.
return new ProtoPlatformBiome(identifier);
}
@Override
protected Iterable<BaseAddon> platformAddon() {
return List.of(getPlatformAddon());
}
protected abstract BaseAddon getPlatformAddon();
public abstract Registry<DimensionType> dimensionTypeRegistry();
public abstract Registry<Biome> biomeRegistry();
public abstract Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry();
public abstract Registry<MultiNoiseBiomeSourceParameterList> multiNoiseBiomeSourceParameterListRegistry();
@Override
public @NotNull WorldHandle getWorldHandle() {
return worldHandle;
}
@Override
public @NotNull ItemHandle getItemHandle() {
return itemHandle;
@@ -12,11 +12,11 @@ public class BiomeAdditionsSoundTemplate implements ObjectTemplate<BiomeAddition
@Value("sound")
@Default
private SoundEvent sound = null;
@Value("sound-chance")
@Default
private Double soundChance = null;
@Override
public BiomeAdditionsSound get() {
if(sound == null || soundChance == null) {
@@ -12,19 +12,19 @@ public class BiomeMoodSoundTemplate implements ObjectTemplate<BiomeMoodSound> {
@Value("sound")
@Default
private SoundEvent sound = null;
@Value("cultivation-ticks")
@Default
private Integer soundCultivationTicks = null;
@Value("spawn-range")
@Default
private Integer soundSpawnRange = null;
@Value("extra-distance")
@Default
private Double soundExtraDistance = null;
@Override
public BiomeMoodSound get() {
if(sound == null || soundCultivationTicks == null || soundSpawnRange == null || soundExtraDistance == null) {
@@ -14,21 +14,21 @@ public class BiomeParticleConfigTemplate implements ObjectTemplate<BiomeParticle
@Value("particle")
@Default
private String particle = null;
@Value("probability")
@Default
private Integer probability = null;
@Override
public BiomeParticleConfig get() {
if(particle == null || probability == null) {
return null;
}
try {
return new BiomeParticleConfig(
ParticleEffectArgumentType.readParameters(new StringReader(particle), Registries.PARTICLE_TYPE.getReadOnlyWrapper()),
probability);
ParticleEffectArgumentType.readParameters(new StringReader(particle), Registries.PARTICLE_TYPE.getReadOnlyWrapper()),
probability);
} catch(CommandSyntaxException e) {
throw new RuntimeException(e);
}
@@ -12,7 +12,7 @@ public class EntityTypeTemplate implements ObjectTemplate<EntityType<?>> {
@Value("id")
@Default
private Identifier id = null;
@Override
public EntityType<?> get() {
return Registries.ENTITY_TYPE.get(id);
@@ -12,19 +12,19 @@ public class MusicSoundTemplate implements ObjectTemplate<MusicSound> {
@Value("sound")
@Default
private SoundEvent sound = null;
@Value("min-delay")
@Default
private Integer minDelay = null;
@Value("max-delay")
@Default
private Integer maxDelay = null;
@Value("replace-current-music")
@Default
private Boolean replaceCurrentMusic = null;
@Override
public MusicSound get() {
if(sound == null || minDelay == null || maxDelay == null || replaceCurrentMusic == null) {
@@ -29,31 +29,31 @@ public class PreLoadCompatibilityOptions implements ConfigTemplate, Properties {
@Value("minecraft.use-vanilla-biomes")
@Default
private boolean vanillaBiomes = false;
@Value("minecraft.beard.enable")
@Default
private boolean beard = true;
@Value("minecraft.beard.threshold")
@Default
private double beardThreshold = 0.5;
@Value("minecraft.beard.air-threshold")
@Default
private double airThreshold = -0.5;
public boolean useVanillaBiomes() {
return vanillaBiomes;
}
public boolean isBeard() {
return beard;
}
public double getBeardThreshold() {
return beardThreshold;
}
public double getAirThreshold() {
return airThreshold;
}
@@ -31,26 +31,26 @@ import com.dfsek.terra.mod.util.MinecraftUtil;
public class ProtoPlatformBiome implements PlatformBiome {
private final Identifier identifier;
private RegistryEntry<Biome> delegate;
public ProtoPlatformBiome(Identifier identifier) {
this.identifier = identifier;
}
public RegistryKey<Biome> get(Registry<net.minecraft.world.biome.Biome> registry) {
return MinecraftUtil.getEntry(registry, identifier).orElseThrow().getKey().orElseThrow();
}
@Override
public Identifier getHandle() {
return identifier;
}
public RegistryEntry<Biome> getDelegate() {
return delegate;
}
public void setDelegate(RegistryEntry<Biome> delegate) {
this.delegate = Objects.requireNonNull(delegate);
}
@@ -11,11 +11,11 @@ public class SoundEventTemplate implements ObjectTemplate<SoundEvent> {
@Value("id")
@Default
private Identifier id = null;
@Value("distance-to-travel")
@Default
private Float distanceToTravel = null;
@Override
public SoundEvent get() {
if(id == null) {
@@ -10,27 +10,27 @@ public class SpawnCostConfig implements ObjectTemplate<SpawnCostConfig> {
@Value("type")
@Default
private EntityType<?> type = null;
@Value("mass")
@Default
private Double mass = null;
@Value("gravity")
@Default
private Double gravity = null;
public EntityType<?> getType() {
return type;
}
public Double getMass() {
return mass;
}
public Double getGravity() {
return gravity;
}
@Override
public SpawnCostConfig get() {
return this;
@@ -11,19 +11,19 @@ public class SpawnEntryTemplate implements ObjectTemplate<SpawnEntry> {
@Value("type")
@Default
private EntityType<?> type = null;
@Value("weight")
@Default
private Integer weight = null;
@Value("min-group-size")
@Default
private Integer minGroupSize = null;
@Value("max-group-size")
@Default
private Integer maxGroupSize = null;
@Override
public SpawnEntry get() {
return new SpawnEntry(type, weight, minGroupSize, maxGroupSize);
@@ -10,7 +10,7 @@ public class SpawnGroupTemplate implements ObjectTemplate<SpawnGroup> {
@Value("group")
@Default
private String group = null;
@Override
public SpawnGroup get() {
return SpawnGroup.valueOf(group);
@@ -12,15 +12,15 @@ public class SpawnSettingsTemplate implements ObjectTemplate<SpawnSettings> {
@Value("spawns")
@Default
private List<SpawnTypeConfig> spawns = null;
@Value("costs")
@Default
private List<SpawnCostConfig> costs = null;
@Value("probability")
@Default
private Float probability = null;
@Override
public SpawnSettings get() {
SpawnSettings.Builder builder = new SpawnSettings.Builder();
@@ -33,7 +33,7 @@ public class SpawnSettingsTemplate implements ObjectTemplate<SpawnSettings> {
if(probability != null) {
builder.creatureSpawnProbability(probability);
}
return builder.build();
}
}
@@ -11,19 +11,19 @@ public class SpawnTypeConfig implements ObjectTemplate<SpawnTypeConfig> {
@Value("group")
@Default
private SpawnGroup group = null;
@Value("entry")
@Default
private SpawnEntry entry = null;
public SpawnGroup getGroup() {
return group;
}
public SpawnEntry getEntry() {
return entry;
}
@Override
public SpawnTypeConfig get() {
return this;
@@ -20,143 +20,143 @@ public class VanillaBiomeProperties implements ConfigTemplate, Properties {
@Value("colors.grass")
@Default
private Integer grassColor = null;
@Value("colors.fog")
@Default
private Integer fogColor = null;
@Value("colors.water")
@Default
private Integer waterColor = null;
@Value("colors.water-fog")
@Default
private Integer waterFogColor = null;
@Value("colors.foliage")
@Default
private Integer foliageColor = null;
@Value("colors.sky")
@Default
private Integer skyColor = null;
@Value("colors.modifier")
@Default
private GrassColorModifier grassColorModifier = null;
@Value("particles")
@Default
private BiomeParticleConfig particleConfig = null;
@Value("climate.precipitation")
@Default
private Boolean precipitation = true;
@Value("climate.temperature")
@Default
private Float temperature = null;
@Value("climate.temperature-modifier")
@Default
private TemperatureModifier temperatureModifier = null;
@Value("climate.downfall")
@Default
private Float downfall = null;
@Value("sound.loop-sound.sound")
@Default
private SoundEvent loopSound = null;
@Value("sound.mood-sound")
@Default
private BiomeMoodSound moodSound = null;
@Value("sound.additions-sound")
@Default
private BiomeAdditionsSound additionsSound = null;
@Value("sound.music")
@Default
private MusicSound music = null;
@Value("spawning")
@Default
private SpawnSettings spawnSettings = null;
@Value("villager-type")
@Default
private VillagerType villagerType = null;
public Integer getGrassColor() {
return grassColor;
}
public Integer getFogColor() {
return fogColor;
}
public Integer getWaterColor() {
return waterColor;
}
public Integer getWaterFogColor() {
return waterFogColor;
}
public Integer getFoliageColor() {
return foliageColor;
}
public Integer getSkyColor() {
return skyColor;
}
public GrassColorModifier getGrassColorModifier() {
return grassColorModifier;
}
public BiomeParticleConfig getParticleConfig() {
return particleConfig;
}
public Boolean getPrecipitation() {
return precipitation;
}
public Float getTemperature() {
return temperature;
}
public TemperatureModifier getTemperatureModifier() {
return temperatureModifier;
}
public Float getDownfall() {
return downfall;
}
public SoundEvent getLoopSound() {
return loopSound;
}
public BiomeMoodSound getMoodSound() {
return moodSound;
}
public BiomeAdditionsSound getAdditionsSound() {
return additionsSound;
}
public MusicSound getMusic() {
return music;
}
public SpawnSettings getSpawnSettings() {
return spawnSettings;
}
public VillagerType getVillagerType() {
return villagerType;
}
@@ -12,7 +12,7 @@ public class VillagerTypeTemplate implements ObjectTemplate<VillagerType> {
@Value("id")
@Default
private Identifier id = null;
@Override
public VillagerType get() {
return Registries.VILLAGER_TYPE.get(id);
@@ -13,45 +13,45 @@ import com.dfsek.terra.mod.generation.TerraBiomeSource;
public final class Codecs {
public static final Codec<RegistryKey> TERRA_REGISTRY_KEY = RecordCodecBuilder
.create(registryKey -> registryKey.group(Codec.STRING.fieldOf("namespace")
.stable()
.forGetter(RegistryKey::getNamespace),
Codec.STRING.fieldOf("id")
.stable()
.forGetter(RegistryKey::getID))
.apply(registryKey, registryKey.stable(RegistryKey::of)));
.create(registryKey -> registryKey.group(Codec.STRING.fieldOf("namespace")
.stable()
.forGetter(RegistryKey::getNamespace),
Codec.STRING.fieldOf("id")
.stable()
.forGetter(RegistryKey::getID))
.apply(registryKey, registryKey.stable(RegistryKey::of)));
public static final Codec<ConfigPack> CONFIG_PACK = RecordCodecBuilder
.create(config -> config.group(TERRA_REGISTRY_KEY.fieldOf("pack")
.stable()
.forGetter(ConfigPack::getRegistryKey))
.apply(config, config.stable(id -> CommonPlatform.get()
.getConfigRegistry()
.get(id)
.orElseThrow(() -> new IllegalArgumentException(
"No such config pack " +
id)))));
.create(config -> config.group(TERRA_REGISTRY_KEY.fieldOf("pack")
.stable()
.forGetter(ConfigPack::getRegistryKey))
.apply(config, config.stable(id -> CommonPlatform.get()
.getConfigRegistry()
.get(id)
.orElseThrow(() -> new IllegalArgumentException(
"No such config pack " +
id)))));
public static final Codec<TerraBiomeSource> TERRA_BIOME_SOURCE = RecordCodecBuilder
.create(instance -> instance.group(
CONFIG_PACK.fieldOf("pack")
.stable()
.forGetter(TerraBiomeSource::getPack))
.apply(instance, instance.stable(TerraBiomeSource::new)));
.create(instance -> instance.group(
CONFIG_PACK.fieldOf("pack")
.stable()
.forGetter(TerraBiomeSource::getPack))
.apply(instance, instance.stable(TerraBiomeSource::new)));
public static final Codec<MinecraftChunkGeneratorWrapper> MINECRAFT_CHUNK_GENERATOR_WRAPPER = RecordCodecBuilder
.create(
instance -> instance.group(
TERRA_BIOME_SOURCE.fieldOf("biome_source")
.stable()
.forGetter(MinecraftChunkGeneratorWrapper::getBiomeSource),
CONFIG_PACK.fieldOf("pack")
.stable()
.forGetter(MinecraftChunkGeneratorWrapper::getPack),
ChunkGeneratorSettings.REGISTRY_CODEC.fieldOf("settings")
.stable()
.forGetter(MinecraftChunkGeneratorWrapper::getSettings)
).apply(instance, instance.stable(
MinecraftChunkGeneratorWrapper::new))
);
.create(
instance -> instance.group(
TERRA_BIOME_SOURCE.fieldOf("biome_source")
.stable()
.forGetter(MinecraftChunkGeneratorWrapper::getBiomeSource),
CONFIG_PACK.fieldOf("pack")
.stable()
.forGetter(MinecraftChunkGeneratorWrapper::getPack),
ChunkGeneratorSettings.REGISTRY_CODEC.fieldOf("settings")
.stable()
.forGetter(MinecraftChunkGeneratorWrapper::getSettings)
).apply(instance, instance.stable(
MinecraftChunkGeneratorWrapper::new))
);
}
@@ -67,33 +67,33 @@ import com.dfsek.terra.mod.util.SeedHack;
public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.ChunkGenerator implements GeneratorWrapper {
private static final Logger logger = LoggerFactory.getLogger(MinecraftChunkGeneratorWrapper.class);
private final TerraBiomeSource biomeSource;
private final RegistryEntry<ChunkGeneratorSettings> settings;
private ChunkGenerator delegate;
private ConfigPack pack;
public MinecraftChunkGeneratorWrapper(TerraBiomeSource biomeSource, ConfigPack configPack,
RegistryEntry<ChunkGeneratorSettings> settingsSupplier) {
super(biomeSource);
this.pack = configPack;
this.settings = settingsSupplier;
this.delegate = pack.getGeneratorProvider().newInstance(pack);
logger.info("Loading world with config pack {}", pack.getID());
this.biomeSource = biomeSource;
}
@Override
protected Codec<? extends net.minecraft.world.gen.chunk.ChunkGenerator> getCodec() {
return Codecs.MINECRAFT_CHUNK_GENERATOR_WRAPPER;
}
@Override
public void buildSurface(ChunkRegion region, StructureAccessor structures, NoiseConfig noiseConfig, Chunk chunk) {
// no op
}
@Override
public void populateEntities(ChunkRegion region) {
if(!this.settings.value().mobGenerationDisabled()) {
@@ -104,13 +104,13 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
SpawnHelper.populateEntities(region, registryEntry, chunkPos, chunkRandom);
}
}
@Override
public int getWorldHeight() {
return settings.value().generationShapeConfig().height();
}
@Override
public CompletableFuture<Chunk> populateNoise(Executor executor, Blender blender, NoiseConfig noiseConfig,
StructureAccessor structureAccessor, Chunk chunk) {
@@ -118,7 +118,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
ProtoWorld world = (ProtoWorld) ((StructureAccessorAccessor) structureAccessor).getWorld();
BiomeProvider biomeProvider = pack.getBiomeProvider();
delegate.generateChunkData((ProtoChunk) chunk, world, biomeProvider, chunk.getPos().x, chunk.getPos().z);
PreLoadCompatibilityOptions compatibilityOptions = pack.getContext().get(PreLoadCompatibilityOptions.class);
if(compatibilityOptions.isBeard()) {
beard(structureAccessor, chunk, world, biomeProvider, compatibilityOptions);
@@ -126,11 +126,11 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
return chunk;
}, Util.getMainWorkerExecutor());
}
private void beard(StructureAccessor structureAccessor, Chunk chunk, WorldProperties world, BiomeProvider biomeProvider,
PreLoadCompatibilityOptions compatibilityOptions) {
StructureWeightSampler structureWeightSampler = StructureWeightSampler.createStructureWeightSampler(structureAccessor,
chunk.getPos());
chunk.getPos());
double threshold = compatibilityOptions.getBeardThreshold();
double airThreshold = compatibilityOptions.getAirThreshold();
int xi = chunk.getPos().x << 4;
@@ -142,8 +142,8 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
double noise = structureWeightSampler.sample(new UnblendedNoisePos(x + xi, y, z + zi));
if(noise > threshold) {
chunk.setBlockState(new BlockPos(x, y, z), (BlockState) delegate
.getPalette(x + xi, y, z + zi, world, biomeProvider)
.get(depth, x + xi, y, z + zi, world.getSeed()), false);
.getPalette(x + xi, y, z + zi, world, biomeProvider)
.get(depth, x + xi, y, z + zi, world.getSeed()), false);
depth++;
} else if(noise < airThreshold) {
chunk.setBlockState(new BlockPos(x, y, z), Blocks.AIR.getDefaultState(), false);
@@ -154,7 +154,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
}
}
}
@Override
public void generateFeatures(StructureWorldAccess world, Chunk chunk, StructureAccessor structureAccessor) {
super.generateFeatures(world, chunk, structureAccessor);
@@ -164,18 +164,18 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
}
});
}
@Override
public int getSeaLevel() {
return settings.value().seaLevel();
}
@Override
public int getMinimumY() {
return settings.value().generationShapeConfig().minimumY();
}
@Override
public int getHeight(int x, int z, Type heightmap, HeightLimitView height, NoiseConfig noiseConfig) {
WorldProperties properties = MinecraftAdapter.adapt(height, SeedHack.getSeed(noiseConfig.getMultiNoiseSampler()));
@@ -183,12 +183,12 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
int min = height.getBottomY();
for(int y = height.getTopY() - 1; y >= min; y--) {
if(heightmap
.getBlockPredicate()
.test((BlockState) delegate.getBlock(properties, x, y, z, biomeProvider))) return y + 1;
.getBlockPredicate()
.test((BlockState) delegate.getBlock(properties, x, y, z, biomeProvider))) return y + 1;
}
return min;
}
@Override
public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView height, NoiseConfig noiseConfig) {
BlockState[] array = new BlockState[height.getHeight()];
@@ -199,39 +199,39 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
}
return new VerticalBlockSample(height.getBottomY(), array);
}
@Override
public void getDebugHudText(List<String> text, NoiseConfig noiseConfig, BlockPos pos) {
}
public ConfigPack getPack() {
return pack;
}
public void setPack(ConfigPack pack) {
this.pack = pack;
this.delegate = pack.getGeneratorProvider().newInstance(pack);
biomeSource.setPack(pack);
logger.debug("Loading world with config pack {}", pack.getID());
}
@Override
public void carve(ChunkRegion chunkRegion, long seed, NoiseConfig noiseConfig, BiomeAccess world, StructureAccessor structureAccessor,
Chunk chunk, Carver carverStep) {
// no op
}
@Override
public ChunkGenerator getHandle() {
return delegate;
}
public RegistryEntry<ChunkGeneratorSettings> getSettings() {
return settings;
}
@Override
public TerraBiomeSource getBiomeSource() {
return biomeSource;
@@ -36,46 +36,46 @@ import com.dfsek.terra.mod.util.SeedHack;
public class TerraBiomeSource extends BiomeSource {
private static final Logger LOGGER = LoggerFactory.getLogger(TerraBiomeSource.class);
private ConfigPack pack;
public TerraBiomeSource(ConfigPack pack) {
this.pack = pack;
LOGGER.debug("Biomes: " + getBiomes());
}
@Override
protected Codec<? extends BiomeSource> getCodec() {
return Codecs.TERRA_BIOME_SOURCE;
}
@Override
protected Stream<RegistryEntry<Biome>> biomeStream() {
return StreamSupport
.stream(pack.getBiomeProvider()
.getBiomes()
.spliterator(), false)
.map(b -> ((ProtoPlatformBiome) b.getPlatformBiome()).getDelegate());
.stream(pack.getBiomeProvider()
.getBiomes()
.spliterator(), false)
.map(b -> ((ProtoPlatformBiome) b.getPlatformBiome()).getDelegate());
}
@Override
public RegistryEntry<Biome> getBiome(int biomeX, int biomeY, int biomeZ, MultiNoiseSampler noiseSampler) {
return ((ProtoPlatformBiome) pack
.getBiomeProvider()
.getBiome(biomeX << 2, biomeY << 2, biomeZ << 2, SeedHack.getSeed(noiseSampler))
.getPlatformBiome()).getDelegate();
.getBiomeProvider()
.getBiome(biomeX << 2, biomeY << 2, biomeZ << 2, SeedHack.getSeed(noiseSampler))
.getPlatformBiome()).getDelegate();
}
public BiomeProvider getProvider() {
return pack.getBiomeProvider();
}
public ConfigPack getPack() {
return pack;
}
public void setPack(ConfigPack pack) {
this.pack = pack;
}
@@ -37,7 +37,7 @@ import com.dfsek.terra.mod.CommonPlatform;
public class MinecraftItemHandle implements ItemHandle {
@Override
public Item createItem(String data) {
try {
@@ -51,12 +51,12 @@ public class MinecraftItemHandle implements ItemHandle {
throw new IllegalArgumentException("Invalid item data \"" + data + "\"", e);
}
}
@Override
public Enchantment getEnchantment(String id) {
return (Enchantment) (Registries.ENCHANTMENT.get(Identifier.tryParse(id)));
}
@Override
public Set<Enchantment> getEnchantments() {
return Registries.ENCHANTMENT.stream().map(enchantment -> (Enchantment) enchantment).collect(Collectors.toSet());
@@ -30,26 +30,26 @@ import com.dfsek.terra.api.handle.WorldHandle;
public class MinecraftWorldHandle implements WorldHandle {
private static final BlockState AIR = (BlockState) Blocks.AIR.getDefaultState();
@Override
public @NotNull BlockState createBlockState(@NotNull String data) {
try {
net.minecraft.block.BlockState state = BlockArgumentParser.block(Registries.BLOCK.getReadOnlyWrapper(), data, true)
.blockState();
.blockState();
if(state == null) throw new IllegalArgumentException("Invalid data: " + data);
return (BlockState) state;
} catch(CommandSyntaxException e) {
throw new IllegalArgumentException(e);
}
}
@Override
public @NotNull BlockState air() {
return AIR;
}
@Override
public @NotNull EntityType getEntity(@NotNull String id) {
Identifier identifier = Identifier.tryParse(id);
@@ -16,8 +16,8 @@ import com.dfsek.terra.mod.CommonPlatform;
* Bees spawning uses world.random without synchronization. This causes issues when spawning bees during world generation.
*/
@Mixin({
MoveToHiveGoal.class,
MoveToFlowerGoal.class
MoveToHiveGoal.class,
MoveToFlowerGoal.class
})
public class BeeMoveGoalsUnsynchronizedRandomAccessFix {
@Redirect(method = "<init>",
@@ -18,11 +18,11 @@ import com.dfsek.terra.mod.mixin_ifaces.FloraFeatureHolder;
@Implements(@Interface(iface = FloraFeatureHolder.class, prefix = "terra$"))
public class GenerationSettingsFloraFeaturesMixin {
private List<ConfiguredFeature<?, ?>> flora;
public void terra$setFloraFeatures(List<ConfiguredFeature<?, ?>> features) {
this.flora = features;
}
@Inject(method = "getFlowerFeatures", cancellable = true, at = @At("HEAD"))
public void inject(CallbackInfoReturnable<List<ConfiguredFeature<?, ?>>> cir) {
if(flora != null) {
@@ -28,29 +28,29 @@ import com.dfsek.terra.api.Handle;
* A ton of Minecraft classes must implement Handle identically, we can just take care of it here
*/
@Mixin({
ServerWorld.class,
ChunkRegion.class,
Block.class,
BlockState.class,
BlockEntity.class,
LootableContainerBlockEntity.class,
LockableContainerBlockEntity.class,
ProtoChunk.class,
WorldChunk.class,
Entity.class,
EntityType.class,
ServerCommandSource.class,
Item.class,
ItemStack.class,
Enchantment.class,
Biome.class
ServerWorld.class,
ChunkRegion.class,
Block.class,
BlockState.class,
BlockEntity.class,
LootableContainerBlockEntity.class,
LockableContainerBlockEntity.class,
ProtoChunk.class,
WorldChunk.class,
Entity.class,
EntityType.class,
ServerCommandSource.class,
Item.class,
ItemStack.class,
Enchantment.class,
Biome.class
})
@Implements(@Interface(iface = Handle.class, prefix = "terra$"))
public class HandleImplementationMixin {
@@ -32,11 +32,11 @@ public abstract class BlockMixin {
public com.dfsek.terra.api.block.state.BlockState terra$getDefaultState() {
return (com.dfsek.terra.api.block.state.BlockState) ((Block) (Object) this).getDefaultState();
}
public boolean terra$isSolid() {
return ((Block) (Object) this).getDefaultState().isOpaque();
}
@SuppressWarnings("ConstantConditions")
public boolean terra$isWater() {
return ((Object) this) == Blocks.WATER;
@@ -31,23 +31,23 @@ public abstract class BlockEntityMixin {
public boolean terra$update(boolean applyPhysics) {
if(((net.minecraft.block.entity.BlockEntity) (Object) this).hasWorld()) //noinspection ConstantConditions
((net.minecraft.block.entity.BlockEntity) (Object) this).getWorld().getChunk(
((net.minecraft.block.entity.BlockEntity) (Object) this).getPos()).setBlockEntity(
(net.minecraft.block.entity.BlockEntity) (Object) this);
((net.minecraft.block.entity.BlockEntity) (Object) this).getPos()).setBlockEntity(
(net.minecraft.block.entity.BlockEntity) (Object) this);
return true;
}
public int terra$getX() {
return ((net.minecraft.block.entity.BlockEntity) (Object) this).getPos().getX();
}
public int terra$getY() {
return ((net.minecraft.block.entity.BlockEntity) (Object) this).getPos().getY();
}
public int terra$getZ() {
return ((net.minecraft.block.entity.BlockEntity) (Object) this).getPos().getZ();
}
public BlockState terra$getBlockState() {
return (BlockState) ((net.minecraft.block.entity.BlockEntity) (Object) this).getCachedState();
}
@@ -45,78 +45,78 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
private MobSpawnerBlockEntityMixin(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
}
@Shadow
public abstract MobSpawnerLogic getLogic();
@Shadow
public abstract void setEntityType(net.minecraft.entity.EntityType<?> entityType, Random random);
public EntityType terra$getSpawnedType() {
return (EntityType) Registries.ENTITY_TYPE.get(
Identifier.tryParse(((MobSpawnerLogicAccessor) getLogic()).getSpawnEntry().getNbt().getString("id")));
Identifier.tryParse(((MobSpawnerLogicAccessor) getLogic()).getSpawnEntry().getNbt().getString("id")));
}
public void terra$setSpawnedType(@NotNull EntityType creatureType) {
setEntityType((net.minecraft.entity.EntityType<?>) creatureType, world.getRandom());
}
public int terra$getDelay() {
return 0;
}
public void terra$setDelay(int delay) {
}
public int terra$getMinSpawnDelay() {
return 0;
}
public void terra$setMinSpawnDelay(int delay) {
}
public int terra$getMaxSpawnDelay() {
return 0;
}
public void terra$setMaxSpawnDelay(int delay) {
}
public int terra$getSpawnCount() {
return 0;
}
public void terra$setSpawnCount(int spawnCount) {
}
public int terra$getMaxNearbyEntities() {
return 0;
}
public void terra$setMaxNearbyEntities(int maxNearbyEntities) {
}
public int terra$getRequiredPlayerRange() {
return 0;
}
public void terra$setRequiredPlayerRange(int requiredPlayerRange) {
}
public int terra$getSpawnRange() {
return 0;
}
public void terra$setSpawnRange(int spawnRange) {
}
public void terra$applyState(String state) {
SerialState.parse(state).forEach((k, v) -> {
switch(k) {
@@ -35,14 +35,14 @@ import com.dfsek.terra.api.block.entity.Sign;
public abstract class SignBlockEntityMixin {
@Shadow
private SignText frontText;
@Shadow
public abstract boolean setText(SignText text, boolean front);
public void terra$setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
setText(frontText.withMessage(index, Text.literal(line)), true);
}
public @NotNull String[] terra$getLines() {
Text[] texts = frontText.getMessages(false);
String[] lines = new String[texts.length];
@@ -51,11 +51,11 @@ public abstract class SignBlockEntityMixin {
}
return lines;
}
public @NotNull String terra$getLine(int index) throws IndexOutOfBoundsException {
return frontText.getMessage(index, false).getString();
}
public void terra$applyState(String state) {
SerialState.parse(state).forEach((k, v) -> {
if(!k.startsWith("text")) throw new IllegalArgumentException("Invalid property: " + k);
@@ -28,17 +28,17 @@ public abstract class BlockStateMixin extends State<Block, net.minecraft.block.B
MapCodec<net.minecraft.block.BlockState> codec) {
super(owner, entries, codec);
}
@Shadow
public abstract Block getBlock();
@Shadow
public abstract boolean isAir();
public boolean terra$matches(BlockState other) {
return getBlock() == ((net.minecraft.block.BlockState) other).getBlock();
}
@Intrinsic
public <T extends Comparable<T>> boolean terra$has(Property<T> property) {
if(property instanceof net.minecraft.state.property.Property<?> minecraftProperty) {
@@ -46,36 +46,36 @@ public abstract class BlockStateMixin extends State<Block, net.minecraft.block.B
}
return false;
}
@SuppressWarnings("unchecked")
@Intrinsic
public <T extends Comparable<T>> T terra$get(Property<T> property) {
return get((net.minecraft.state.property.Property<T>) property);
}
@SuppressWarnings("unchecked")
@Intrinsic
public <T extends Comparable<T>> BlockState terra$set(Property<T> property, T value) {
return (BlockState) with((net.minecraft.state.property.Property<T>) property, value);
}
@Intrinsic
public BlockType terra$getBlockType() {
return (BlockType) getBlock();
}
@Intrinsic
public String terra$getAsString(boolean properties) {
StringBuilder data = new StringBuilder(Registries.BLOCK.getId(getBlock()).toString());
if(properties && !getEntries().isEmpty()) {
data.append('[');
data.append(
getEntries().entrySet().stream().map(StateAccessor.getPropertyMapPrinter()).collect(Collectors.joining(",")));
getEntries().entrySet().stream().map(StateAccessor.getPropertyMapPrinter()).collect(Collectors.joining(",")));
data.append(']');
}
return data.toString();
}
@Intrinsic
public boolean terra$isAir() {
return isAir();
@@ -22,20 +22,20 @@ public abstract class PropertyMixin<T> {
@Shadow
@Final
private String name;
@Shadow
public abstract Collection<T> getValues();
@Intrinsic
public Collection<T> terra$values() {
return getValues();
}
@Intrinsic
public Class<T> terra$getType() {
return type;
}
@Intrinsic
public String terra$getID() {
return name;
@@ -33,25 +33,25 @@ import com.dfsek.terra.api.world.chunk.Chunk;
@Mixin(ChunkRegion.class)
@Implements(@Interface(iface = Chunk.class, prefix = "terraChunk$"))
public abstract class ChunkRegionMixin {
@Shadow
@Final
private net.minecraft.world.chunk.Chunk centerPos;
public void terraChunk$setBlock(int x, int y, int z, @NotNull BlockState blockState, boolean physics) {
((ChunkRegion) (Object) this).setBlockState(new BlockPos(x + (centerPos.getPos().x << 4), y, z + (centerPos.getPos().z << 4)),
(net.minecraft.block.BlockState) blockState, 0);
(net.minecraft.block.BlockState) blockState, 0);
}
public @NotNull BlockState terraChunk$getBlock(int x, int y, int z) {
return (BlockState) ((ChunkRegion) (Object) this).getBlockState(
new BlockPos(x + (centerPos.getPos().x << 4), y, z + (centerPos.getPos().z << 4)));
new BlockPos(x + (centerPos.getPos().x << 4), y, z + (centerPos.getPos().z << 4)));
}
public int terraChunk$getX() {
return centerPos.getPos().x;
}
public int terraChunk$getZ() {
return centerPos.getPos().z;
}
@@ -41,17 +41,17 @@ public abstract class WorldChunkMixin {
@Final
@Shadow
net.minecraft.world.World world;
@Shadow
public abstract net.minecraft.block.BlockState getBlockState(BlockPos pos);
@Shadow
@Nullable
public abstract net.minecraft.block.BlockState setBlockState(BlockPos pos, net.minecraft.block.BlockState state, boolean moved);
@Shadow
public abstract TickSchedulers getTickSchedulers();
public void terra$setBlock(int x, int y, int z, BlockState data, boolean physics) {
BlockPos blockPos = new BlockPos(x, y, z);
setBlockState(blockPos, (net.minecraft.block.BlockState) data, false);
@@ -62,28 +62,28 @@ public abstract class WorldChunkMixin {
} else {
world.getBlockTickScheduler().scheduleTick(OrderedTick.create(state.getBlock(), blockPos));
}
}
}
public void terra$setBlock(int x, int y, int z, @NotNull BlockState blockState) {
((net.minecraft.world.chunk.Chunk) (Object) this).setBlockState(new BlockPos(x, y, z), (net.minecraft.block.BlockState) blockState,
false);
false);
}
@Intrinsic
public @NotNull BlockState terra$getBlock(int x, int y, int z) {
return (BlockState) getBlockState(new BlockPos(x, y, z));
}
public int terra$getX() {
return ((net.minecraft.world.chunk.Chunk) (Object) this).getPos().x;
}
public int terra$getZ() {
return ((net.minecraft.world.chunk.Chunk) (Object) this).getPos().z;
}
public ServerWorld terra$getWorld() {
return (ServerWorld) world;
}
@@ -34,19 +34,19 @@ import com.dfsek.terra.api.world.chunk.generation.ProtoChunk;
public abstract class ProtoChunkMixin {
@Shadow
public abstract net.minecraft.block.BlockState getBlockState(BlockPos pos);
@Shadow
public abstract HeightLimitView getHeightLimitView();
public void terra$setBlock(int x, int y, int z, @NotNull BlockState blockState) {
((net.minecraft.world.chunk.Chunk) (Object) this).setBlockState(new BlockPos(x, y, z), (net.minecraft.block.BlockState) blockState,
false);
false);
}
public @NotNull BlockState terra$getBlock(int x, int y, int z) {
return (BlockState) getBlockState(new BlockPos(x, y, z));
}
public int terra$getMaxHeight() {
return getHeightLimitView().getTopY();
}
@@ -34,21 +34,21 @@ import com.dfsek.terra.mod.util.MinecraftAdapter;
public abstract class EntityMixin {
@Shadow
public net.minecraft.world.World world;
@Shadow
private BlockPos blockPos;
@Shadow
public abstract void teleport(double destX, double destY, double destZ);
public Vector3 terra$position() {
return MinecraftAdapter.adapt(blockPos);
}
public void terra$position(Vector3 location) {
teleport(location.getX(), location.getY(), location.getZ());
}
public ServerWorld terra$world() {
return (ServerWorld) world;
}
@@ -39,23 +39,23 @@ import com.dfsek.terra.api.entity.Player;
public abstract class ServerCommandSourceMixin {
@Shadow
public abstract ServerPlayerEntity getPlayer() throws CommandSyntaxException;
@Shadow
@Nullable
public abstract net.minecraft.entity.@Nullable Entity getEntity();
@Shadow
public abstract void sendMessage(Text message);
public void terra$sendMessage(String message) {
sendMessage(Text.literal(message));
}
@Nullable
public Optional<Entity> terra$getEntity() {
return Optional.ofNullable((Entity) getEntity());
}
public Optional<Player> terra$getPlayer() {
try {
return Optional.ofNullable((Player) getPlayer());
@@ -34,11 +34,11 @@ public class LockableContainerBlockEntityMixin {
public void terra$setItem(int slot, ItemStack newStack) {
((LockableContainerBlockEntity) (Object) this).setStack(slot, (net.minecraft.item.ItemStack) (Object) newStack);
}
public int terra$getSize() {
return ((LockableContainerBlockEntity) (Object) this).size();
}
@SuppressWarnings("ConstantConditions")
public ItemStack terra$getItem(int slot) {
net.minecraft.item.ItemStack itemStack = ((LockableContainerBlockEntity) (Object) this).getStack(slot);
@@ -31,12 +31,12 @@ import com.dfsek.terra.api.inventory.ItemStack;
public abstract class ItemMixin {
@Shadow
public abstract int getMaxDamage();
@SuppressWarnings("ConstantConditions")
public ItemStack terra$newItemStack(int amount) {
return (ItemStack) (Object) new net.minecraft.item.ItemStack((Item) (Object) this, amount);
}
public double terra$getMaxDurability() {
return getMaxDamage();
}
@@ -35,40 +35,40 @@ import com.dfsek.terra.api.inventory.item.ItemMeta;
public abstract class ItemStackMixin {
@Shadow
public abstract int getCount();
@Shadow
public abstract void setCount(int count);
@Shadow
public abstract net.minecraft.item.Item getItem();
@Shadow
public abstract boolean isDamageable();
@Shadow
public abstract void setNbt(@Nullable NbtCompound tag);
public int terra$getAmount() {
return getCount();
}
public void terra$setAmount(int i) {
setCount(i);
}
public Item terra$getType() {
return (Item) getItem();
}
public ItemMeta terra$getItemMeta() {
return (ItemMeta) this;
}
@SuppressWarnings("ConstantConditions")
public void terra$setItemMeta(ItemMeta meta) {
setNbt(((ItemStack) (Object) meta).getNbt());
}
@Intrinsic
public boolean terra$isDamageable() {
return isDamageable();
@@ -34,19 +34,19 @@ import com.dfsek.terra.api.inventory.ItemStack;
public abstract class EnchantmentMixin {
@Shadow
public abstract boolean isAcceptableItem(net.minecraft.item.ItemStack stack);
@Shadow
public abstract boolean canCombine(Enchantment other);
@SuppressWarnings("ConstantConditions")
public boolean terra$canEnchantItem(ItemStack itemStack) {
return isAcceptableItem((net.minecraft.item.ItemStack) (Object) itemStack);
}
public boolean terra$conflictsWith(com.dfsek.terra.api.inventory.item.Enchantment other) {
return !canCombine((Enchantment) other);
}
public String terra$getID() {
return Objects.requireNonNull(Registries.ENCHANTMENT.getId((Enchantment) (Object) this)).toString();
}
@@ -32,23 +32,23 @@ import com.dfsek.terra.api.inventory.item.Damageable;
public abstract class ItemStackDamageableMixin {
@Shadow
public abstract boolean isDamaged();
@Shadow
public abstract int getDamage();
@Shadow
public abstract void setDamage(int damage);
@Intrinsic
public int terra$getDamage() {
return getDamage();
}
@Intrinsic
public void terra$setDamage(int damage) {
setDamage(damage);
}
public boolean terra$hasDamage() {
return isDamaged();
}
@@ -40,22 +40,22 @@ import com.dfsek.terra.api.inventory.item.ItemMeta;
public abstract class ItemStackMetaMixin {
@Shadow
public abstract boolean hasEnchantments();
@Shadow
public abstract NbtList getEnchantments();
@Shadow
public abstract void addEnchantment(net.minecraft.enchantment.Enchantment enchantment, int level);
public void terra$addEnchantment(Enchantment enchantment, int level) {
addEnchantment((net.minecraft.enchantment.Enchantment) enchantment, level);
}
@Intrinsic(displace = true)
public Map<Enchantment, Integer> terra$getEnchantments() {
if(!hasEnchantments()) return Collections.emptyMap();
Map<Enchantment, Integer> map = new HashMap<>();
getEnchantments().forEach(enchantment -> {
NbtCompound eTag = (NbtCompound) enchantment;
map.put((Enchantment) Registries.ENCHANTMENT.get(eTag.getInt("id")), eTag.getInt("lvl"));
@@ -55,24 +55,24 @@ import com.dfsek.terra.mod.util.MinecraftUtil;
@Implements(@Interface(iface = ProtoWorld.class, prefix = "terraWorld$"))
public abstract class ChunkRegionMixin {
private ConfigPack terra$config;
@Shadow
@Final
private net.minecraft.server.world.ServerWorld world;
@Shadow
@Final
private long seed;
@Shadow
@Final
private Chunk centerPos;
@Shadow
@Final
private MultiTickScheduler<Fluid> fluidTickScheduler;
@Inject(at = @At("RETURN"),
method = "<init>(Lnet/minecraft/server/world/ServerWorld;Ljava/util/List;Lnet/minecraft/world/chunk/ChunkStatus;I)V")
public void injectConstructor(net.minecraft.server.world.ServerWorld world, List<net.minecraft.world.chunk.Chunk> list,
@@ -80,69 +80,69 @@ public abstract class ChunkRegionMixin {
CallbackInfo ci) {
this.terra$config = ((ServerWorld) world).getPack();
}
@Intrinsic(displace = true)
public void terraWorld$setBlockState(int x, int y, int z, BlockState data, boolean physics) {
BlockPos pos = new BlockPos(x, y, z);
((ChunkRegion) (Object) this).setBlockState(pos, (net.minecraft.block.BlockState) data, physics ? 3 : 1042);
if(physics && ((net.minecraft.block.BlockState) data).getBlock() instanceof FluidBlock) {
fluidTickScheduler.scheduleTick(
OrderedTick.create(((FluidBlock) ((net.minecraft.block.BlockState) data).getBlock()).getFluidState(
(net.minecraft.block.BlockState) data).getFluid(), pos));
OrderedTick.create(((FluidBlock) ((net.minecraft.block.BlockState) data).getBlock()).getFluidState(
(net.minecraft.block.BlockState) data).getFluid(), pos));
}
}
@Intrinsic
public long terraWorld$getSeed() {
return seed;
}
public int terraWorld$getMaxHeight() {
return world.getTopY();
}
@Intrinsic(displace = true)
public BlockState terraWorld$getBlockState(int x, int y, int z) {
BlockPos pos = new BlockPos(x, y, z);
return (BlockState) ((ChunkRegion) (Object) this).getBlockState(pos);
}
public BlockEntity terraWorld$getBlockEntity(int x, int y, int z) {
return MinecraftUtil.createState((WorldAccess) this, new BlockPos(x, y, z));
}
public int terraWorld$getMinHeight() {
return world.getBottomY();
}
public ChunkGenerator terraWorld$getGenerator() {
return ((MinecraftChunkGeneratorWrapper) world.getChunkManager().getChunkGenerator()).getHandle();
}
public BiomeProvider terraWorld$getBiomeProvider() {
return terra$config.getBiomeProvider();
}
public Entity terraWorld$spawnEntity(double x, double y, double z, EntityType entityType) {
net.minecraft.entity.Entity entity = ((net.minecraft.entity.EntityType<?>) entityType).create(world);
entity.setPos(x, y, z);
((ChunkRegion) (Object) this).spawnEntity(entity);
return (Entity) entity;
}
public int terraWorld$centerChunkX() {
return centerPos.getPos().x;
}
public int terraWorld$centerChunkZ() {
return centerPos.getPos().z;
}
public ServerWorld terraWorld$getWorld() {
return (ServerWorld) world;
}
public ConfigPack terraWorld$getPack() {
return terra$config;
}
@@ -47,53 +47,53 @@ public abstract class ServerWorldMixin {
((net.minecraft.server.world.ServerWorld) (Object) this).spawnEntity(entity);
return (Entity) entity;
}
public void terra$setBlockState(int x, int y, int z, BlockState data, boolean physics) {
BlockPos pos = new BlockPos(x, y, z);
((net.minecraft.server.world.ServerWorld) (Object) this).setBlockState(pos, (net.minecraft.block.BlockState) data,
physics ? 3 : 1042);
physics ? 3 : 1042);
}
@Intrinsic
public long terra$getSeed() {
return ((net.minecraft.server.world.ServerWorld) (Object) this).getSeed();
}
public int terra$getMaxHeight() {
return (((net.minecraft.server.world.ServerWorld) (Object) this).getBottomY()) +
((net.minecraft.server.world.ServerWorld) (Object) this).getHeight();
}
public Chunk terra$getChunkAt(int x, int z) {
return (Chunk) ((net.minecraft.server.world.ServerWorld) (Object) this).getChunk(x, z);
}
public BlockState terra$getBlockState(int x, int y, int z) {
return (BlockState) ((net.minecraft.server.world.ServerWorld) (Object) this).getBlockState(new BlockPos(x, y, z));
}
public BlockEntity terra$getBlockEntity(int x, int y, int z) {
return MinecraftUtil.createState((WorldAccess) this, new BlockPos(x, y, z));
}
public int terra$getMinHeight() {
return ((net.minecraft.server.world.ServerWorld) (Object) this).getBottomY();
}
public ChunkGenerator terra$getGenerator() {
return ((MinecraftChunkGeneratorWrapper) ((net.minecraft.server.world.ServerWorld) (Object) this).getChunkManager()
.getChunkGenerator()).getHandle();
.getChunkGenerator()).getHandle();
}
public BiomeProvider terra$getBiomeProvider() {
return ((TerraBiomeSource) ((net.minecraft.server.world.ServerWorld) (Object) this).getChunkManager()
.getChunkGenerator()
.getBiomeSource()).getProvider();
.getChunkGenerator()
.getBiomeSource()).getProvider();
}
public ConfigPack terra$getPack() {
net.minecraft.world.gen.chunk.ChunkGenerator generator =
(((net.minecraft.server.world.ServerWorld) (Object) this).getChunkManager()).getChunkGenerator();
(((net.minecraft.server.world.ServerWorld) (Object) this).getChunkManager()).getChunkGenerator();
if(generator instanceof MinecraftChunkGeneratorWrapper minecraftChunkGeneratorWrapper) {
return minecraftChunkGeneratorWrapper.getPack();
}
@@ -22,7 +22,7 @@ public class DataPackContentsMixin {
@Inject(method = "refresh(Lnet/minecraft/registry/DynamicRegistryManager;)V", at = @At("RETURN"))
private void injectReload(DynamicRegistryManager dynamicRegistryManager, CallbackInfo ci) {
TagUtil.registerWorldPresetTags(dynamicRegistryManager.get(RegistryKeys.WORLD_PRESET));
Registry<Biome> biomeRegistry = dynamicRegistryManager.get(RegistryKeys.BIOME);
TagUtil.registerBiomeTags(biomeRegistry);
MinecraftUtil.registerFlora(biomeRegistry);
@@ -25,28 +25,28 @@ import com.dfsek.terra.api.world.info.WorldProperties;
public final class MinecraftAdapter {
public static Vector3 adapt(BlockPos pos) {
return Vector3.of(pos.getX(), pos.getY(), pos.getZ());
}
public static WorldProperties adapt(HeightLimitView height, long seed) {
return new WorldProperties() {
@Override
public long getSeed() {
return seed;
}
@Override
public int getMaxHeight() {
return height.getTopY();
}
@Override
public int getMinHeight() {
return height.getBottomY();
}
@Override
public Object getHandle() {
return height;
@@ -39,18 +39,18 @@ import com.dfsek.terra.mod.mixin_ifaces.FloraFeatureHolder;
public final class MinecraftUtil {
public static final Logger logger = LoggerFactory.getLogger(MinecraftUtil.class);
public static final Map<Identifier, List<Identifier>>
TERRA_BIOME_MAP = new HashMap<>();
TERRA_BIOME_MAP = new HashMap<>();
private MinecraftUtil() {
}
public static <T> Optional<RegistryEntry<T>> getEntry(Registry<T> registry, Identifier identifier) {
return registry.getOrEmpty(identifier)
.flatMap(registry::getKey)
.flatMap(registry::getEntry);
.flatMap(registry::getKey)
.flatMap(registry::getEntry);
}
public static BlockEntity createState(WorldAccess worldAccess, BlockPos pos) {
net.minecraft.block.entity.BlockEntity entity = worldAccess.getBlockEntity(pos);
if(entity instanceof SignBlockEntity) {
@@ -62,116 +62,116 @@ public final class MinecraftUtil {
}
return null;
}
public static void registerFlora(Registry<net.minecraft.world.biome.Biome> biomes) {
logger.info("Injecting flora into Terra biomes...");
TERRA_BIOME_MAP
.forEach((vb, terraBiomes) ->
biomes.getOrEmpty(vb)
.ifPresentOrElse(vanilla -> terraBiomes
.forEach(tb -> biomes.getOrEmpty(tb)
.ifPresentOrElse(
terra -> {
List<ConfiguredFeature<?, ?>> flowerFeatures = List.copyOf(
vanilla.getGenerationSettings()
.getFlowerFeatures());
logger.debug("Injecting flora into biome" +
" {} : {}", tb,
flowerFeatures);
((FloraFeatureHolder) terra.getGenerationSettings()).setFloraFeatures(
flowerFeatures);
},
() -> logger.error(
"No such biome: {}",
tb))),
() -> logger.error("No vanilla biome: {}", vb)));
.forEach((vb, terraBiomes) ->
biomes.getOrEmpty(vb)
.ifPresentOrElse(vanilla -> terraBiomes
.forEach(tb -> biomes.getOrEmpty(tb)
.ifPresentOrElse(
terra -> {
List<ConfiguredFeature<?, ?>> flowerFeatures = List.copyOf(
vanilla.getGenerationSettings()
.getFlowerFeatures());
logger.debug("Injecting flora into biome" +
" {} : {}", tb,
flowerFeatures);
((FloraFeatureHolder) terra.getGenerationSettings()).setFloraFeatures(
flowerFeatures);
},
() -> logger.error(
"No such biome: {}",
tb))),
() -> logger.error("No vanilla biome: {}", vb)));
}
public static Map<Identifier, List<Identifier>> getTerraBiomeMap() {
return Map.copyOf(TERRA_BIOME_MAP);
}
public static RegistryKey<Biome> registerKey(Identifier identifier) {
return RegistryKey.of(RegistryKeys.BIOME, identifier);
}
public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla,
VanillaBiomeProperties vanillaBiomeProperties) {
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();
BiomeEffects.Builder effects = new BiomeEffects.Builder();
net.minecraft.world.biome.Biome.Builder builder = new Builder();
effects.waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor()))
.waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor()))
.fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor()))
.skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor()))
.grassColorModifier(
Objects.requireNonNullElse(vanillaBiomeProperties.getGrassColorModifier(),
vanilla.getEffects().getGrassColorModifier()));
.waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor()))
.fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor()))
.skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor()))
.grassColorModifier(
Objects.requireNonNullElse(vanillaBiomeProperties.getGrassColorModifier(),
vanilla.getEffects().getGrassColorModifier()));
if(vanillaBiomeProperties.getFoliageColor() == null) {
vanilla.getEffects().getFoliageColor().ifPresent(effects::foliageColor);
} else {
effects.foliageColor(vanillaBiomeProperties.getFoliageColor());
}
if(vanillaBiomeProperties.getGrassColor() == null) {
vanilla.getEffects().getGrassColor().ifPresent(effects::grassColor);
} else {
effects.grassColor(vanillaBiomeProperties.getGrassColor());
}
if(vanillaBiomeProperties.getParticleConfig() == null) {
vanilla.getEffects().getParticleConfig().ifPresent(effects::particleConfig);
} else {
effects.particleConfig(vanillaBiomeProperties.getParticleConfig());
}
if(vanillaBiomeProperties.getLoopSound() == null) {
vanilla.getEffects().getLoopSound().ifPresent(effects::loopSound);
} else {
effects.loopSound(Registries.SOUND_EVENT.getEntry(vanillaBiomeProperties.getLoopSound()));
}
if(vanillaBiomeProperties.getMoodSound() == null) {
vanilla.getEffects().getMoodSound().ifPresent(effects::moodSound);
} else {
effects.moodSound(vanillaBiomeProperties.getMoodSound());
}
if(vanillaBiomeProperties.getAdditionsSound() == null) {
vanilla.getEffects().getAdditionsSound().ifPresent(effects::additionsSound);
} else {
effects.additionsSound(vanillaBiomeProperties.getAdditionsSound());
}
if(vanillaBiomeProperties.getMusic() == null) {
vanilla.getEffects().getMusic().ifPresent(effects::music);
} else {
effects.music(vanillaBiomeProperties.getMusic());
}
builder.precipitation(Objects.requireNonNullElse(vanillaBiomeProperties.getPrecipitation(), vanilla.hasPrecipitation()));
builder.temperature(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperature(), vanilla.getTemperature()));
builder.downfall(Objects.requireNonNullElse(vanillaBiomeProperties.getDownfall(),
((BiomeAccessor) ((Object) vanilla)).getWeather().downfall()));
((BiomeAccessor) ((Object) vanilla)).getWeather().downfall()));
builder.temperatureModifier(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperatureModifier(),
((BiomeAccessor) ((Object) vanilla)).getWeather().temperatureModifier()));
((BiomeAccessor) ((Object) vanilla)).getWeather().temperatureModifier()));
builder.spawnSettings(Objects.requireNonNullElse(vanillaBiomeProperties.getSpawnSettings(), vanilla.getSpawnSettings()));
return builder
.effects(effects.build())
.generationSettings(generationSettings.build())
.build();
.effects(effects.build())
.generationSettings(generationSettings.build())
.build();
}
public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) {
return pack.getID()
.toLowerCase() + "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT) + "/" + biomeID.getID().toLowerCase(Locale.ROOT);
@@ -32,57 +32,57 @@ import com.dfsek.terra.mod.generation.TerraBiomeSource;
public class PresetUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(PresetUtil.class);
private static final List<Identifier> PRESETS = new ArrayList<>();
public static Pair<Identifier, WorldPreset> createDefault(ConfigPack pack, ModPlatform platform) {
Registry<DimensionType> dimensionTypeRegistry = platform.dimensionTypeRegistry();
Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry = platform.chunkGeneratorSettingsRegistry();
Registry<MultiNoiseBiomeSourceParameterList> multiNoiseBiomeSourceParameterLists =
platform.multiNoiseBiomeSourceParameterListRegistry();
platform.multiNoiseBiomeSourceParameterListRegistry();
RegistryEntry<DimensionType> overworldDimensionType = dimensionTypeRegistry.getEntry(DimensionTypes.OVERWORLD).orElseThrow();
RegistryEntry<ChunkGeneratorSettings> overworld = chunkGeneratorSettingsRegistry.getEntry(ChunkGeneratorSettings.OVERWORLD)
.orElseThrow();
.orElseThrow();
Identifier generatorID = Identifier.of("terra", pack.getID().toLowerCase(Locale.ROOT) + "/" + pack.getNamespace().toLowerCase(
Locale.ROOT));
Locale.ROOT));
PRESETS.add(generatorID);
RegistryEntry<DimensionType> registryEntry = dimensionTypeRegistry.getEntry(DimensionTypes.THE_NETHER).orElseThrow();
RegistryEntry.Reference<MultiNoiseBiomeSourceParameterList> reference = multiNoiseBiomeSourceParameterLists.getEntry(
MultiNoiseBiomeSourceParameterLists.NETHER).orElseThrow();
MultiNoiseBiomeSourceParameterLists.NETHER).orElseThrow();
RegistryEntry<ChunkGeneratorSettings> registryEntry2 = chunkGeneratorSettingsRegistry.getEntry(ChunkGeneratorSettings.NETHER)
.orElseThrow();
.orElseThrow();
RegistryEntry<DimensionType> registryEntry3 = dimensionTypeRegistry.getEntry(DimensionTypes.THE_END).orElseThrow();
RegistryEntry<ChunkGeneratorSettings> registryEntry4 = chunkGeneratorSettingsRegistry.getEntry(ChunkGeneratorSettings.END)
.orElseThrow();
.orElseThrow();
TerraBiomeSource biomeSource = new TerraBiomeSource(pack);
ChunkGenerator generator = new MinecraftChunkGeneratorWrapper(biomeSource, pack, overworld);
DimensionOptions dimensionOptions = new DimensionOptions(overworldDimensionType, generator);
DimensionOptions netherDimensionOptions = new DimensionOptions(registryEntry,
new NoiseChunkGenerator(MultiNoiseBiomeSource.create(reference),
registryEntry2));
new NoiseChunkGenerator(MultiNoiseBiomeSource.create(reference),
registryEntry2));
DimensionOptions endDimensionOptions = new DimensionOptions(registryEntry3, new NoiseChunkGenerator(
TheEndBiomeSource.createVanilla(platform.biomeRegistry().getReadOnlyWrapper()), registryEntry4));
TheEndBiomeSource.createVanilla(platform.biomeRegistry().getReadOnlyWrapper()), registryEntry4));
WorldPreset preset = createPreset(dimensionOptions, netherDimensionOptions, endDimensionOptions);
LOGGER.info("Created world type \"{}\"", generatorID);
return Pair.of(generatorID, preset);
}
private static WorldPreset createPreset(DimensionOptions dimensionOptions, DimensionOptions netherDimensionOptions,
DimensionOptions endDimensionOptions) {
return new WorldPreset(
Map.of(DimensionOptions.OVERWORLD, dimensionOptions, DimensionOptions.NETHER, netherDimensionOptions, DimensionOptions.END,
endDimensionOptions)
Map.of(DimensionOptions.OVERWORLD, dimensionOptions, DimensionOptions.NETHER, netherDimensionOptions, DimensionOptions.END,
endDimensionOptions)
);
}
public static List<Identifier> getPresets() {
return PRESETS;
}
@@ -12,16 +12,16 @@ import org.slf4j.LoggerFactory;
*/
public class SeedHack {
private static final Logger LOGGER = LoggerFactory.getLogger(SeedHack.class);
private static final Object2LongMap<MultiNoiseSampler> seedMap = new Object2LongOpenHashMap<>();
public static long getSeed(MultiNoiseSampler sampler) {
if(!seedMap.containsKey(sampler)) {
throw new IllegalArgumentException("Sampler is not registered: " + sampler);
}
return seedMap.getLong(sampler);
}
public static void register(MultiNoiseSampler sampler, long seed) {
LOGGER.info("Registered seed {} to sampler {}", seed, sampler.hashCode());
seedMap.put(sampler, seed);
@@ -18,86 +18,86 @@ import java.util.Map;
public final class TagUtil {
private static final Logger logger = LoggerFactory.getLogger(TagUtil.class);
private TagUtil() {
}
private static <T> Map<TagKey<T>, List<RegistryEntry<T>>> tagsToMutableMap(Registry<T> registry) {
return registry
.streamTagsAndEntries()
.collect(HashMap::new,
(map, pair) ->
map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())),
HashMap::putAll);
.streamTagsAndEntries()
.collect(HashMap::new,
(map, pair) ->
map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())),
HashMap::putAll);
}
public static void registerWorldPresetTags(Registry<WorldPreset> registry) {
logger.info("Doing preset tag garbage....");
Map<TagKey<WorldPreset>, List<RegistryEntry<WorldPreset>>> collect = tagsToMutableMap(registry);
PresetUtil
.getPresets()
.forEach(id -> MinecraftUtil
.getEntry(registry, id)
.ifPresentOrElse(
preset -> collect
.computeIfAbsent(WorldPresetTags.NORMAL, tag -> new ArrayList<>())
.add(preset),
() -> logger.error("Preset {} does not exist!", id)));
.getPresets()
.forEach(id -> MinecraftUtil
.getEntry(registry, id)
.ifPresentOrElse(
preset -> collect
.computeIfAbsent(WorldPresetTags.NORMAL, tag -> new ArrayList<>())
.add(preset),
() -> logger.error("Preset {} does not exist!", id)));
registry.clearTags();
registry.populateTags(ImmutableMap.copyOf(collect));
}
public static void registerBiomeTags(Registry<Biome> registry) {
logger.info("Doing biome tag garbage....");
Map<TagKey<Biome>, List<RegistryEntry<Biome>>> collect = tagsToMutableMap(registry);
MinecraftUtil
.getTerraBiomeMap()
.forEach((vb, terraBiomes) ->
MinecraftUtil
.getEntry(registry, vb)
.ifPresentOrElse(
vanilla -> terraBiomes
.forEach(tb -> MinecraftUtil
.getEntry(registry, tb)
.ifPresentOrElse(
terra -> {
logger.debug(
vanilla.getKey()
.orElseThrow()
.getValue() +
" (vanilla for " +
terra.getKey()
.orElseThrow()
.getValue() +
": " +
vanilla.streamTags()
.toList());
vanilla.streamTags()
.forEach(
tag -> collect
.computeIfAbsent(
tag,
t -> new ArrayList<>())
.add(terra));
},
() -> logger.error(
"No such biome: {}",
tb))),
() -> logger.error("No vanilla biome: {}", vb)));
.getTerraBiomeMap()
.forEach((vb, terraBiomes) ->
MinecraftUtil
.getEntry(registry, vb)
.ifPresentOrElse(
vanilla -> terraBiomes
.forEach(tb -> MinecraftUtil
.getEntry(registry, tb)
.ifPresentOrElse(
terra -> {
logger.debug(
vanilla.getKey()
.orElseThrow()
.getValue() +
" (vanilla for " +
terra.getKey()
.orElseThrow()
.getValue() +
": " +
vanilla.streamTags()
.toList());
vanilla.streamTags()
.forEach(
tag -> collect
.computeIfAbsent(
tag,
t -> new ArrayList<>())
.add(terra));
},
() -> logger.error(
"No such biome: {}",
tb))),
() -> logger.error("No vanilla biome: {}", vb)));
registry.clearTags();
registry.populateTags(ImmutableMap.copyOf(collect));
if(logger.isDebugEnabled()) {
registry.streamEntries()
.map(e -> e.registryKey().getValue() + ": " +
e.streamTags().reduce("", (s, t) -> t.id() + ", " + s, String::concat))
.forEach(logger::debug);
.map(e -> e.registryKey().getValue() + ": " +
e.streamTags().reduce("", (s, t) -> t.id() + ", " + s, String::concat))
.forEach(logger::debug);
}
}
}