mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 06:11:24 +00:00
Fabric/Quilt fertilization support
This commit is contained in:
+25
-13
@@ -15,44 +15,52 @@ import net.minecraft.world.biome.BiomeEffects.GrassColorModifier;
|
||||
import net.minecraft.world.biome.BiomeParticleConfig;
|
||||
import net.minecraft.world.biome.SpawnSettings;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
||||
|
||||
public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
||||
|
||||
@Value("minecraft.fertilizables")
|
||||
@Default
|
||||
private Map<Identifier, ProbabilityCollection<ConfiguredStructure>> fertilizables = Collections.emptyMap();
|
||||
|
||||
@Value("minecraft.tags")
|
||||
@Default
|
||||
private List<Identifier> tags = null;
|
||||
private List<Identifier> tags = Collections.emptyList();
|
||||
|
||||
@Value("minecraft.colors.grass")
|
||||
@Default
|
||||
private Integer grassColor = null;
|
||||
private Integer grassColor = 0;
|
||||
|
||||
@Value("minecraft.colors.fog")
|
||||
@Default
|
||||
private Integer fogColor = null;
|
||||
private Integer fogColor = 0;
|
||||
|
||||
@Value("minecraft.colors.water")
|
||||
@Default
|
||||
private Integer waterColor = null;
|
||||
private Integer waterColor = 0;
|
||||
|
||||
@Value("minecraft.colors.water-fog")
|
||||
@Default
|
||||
private Integer waterFogColor = null;
|
||||
private Integer waterFogColor = 0;
|
||||
|
||||
@Value("minecraft.colors.foliage")
|
||||
@Default
|
||||
private Integer foliageColor = null;
|
||||
private Integer foliageColor = 0;
|
||||
|
||||
@Value("minecraft.colors.sky")
|
||||
@Default
|
||||
private Integer skyColor = null;
|
||||
private Integer skyColor = 0;
|
||||
|
||||
@Value("minecraft.colors.modifier")
|
||||
@Default
|
||||
private GrassColorModifier grassColorModifier = null;
|
||||
private GrassColorModifier grassColorModifier = GrassColorModifier.NONE;
|
||||
|
||||
@Value("minecraft.particles")
|
||||
@Default
|
||||
@@ -60,19 +68,19 @@ public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
||||
|
||||
@Value("minecraft.climate.precipitation")
|
||||
@Default
|
||||
private Precipitation precipitation = null;
|
||||
private Precipitation precipitation = Precipitation.NONE;
|
||||
|
||||
@Value("minecraft.climate.temperature")
|
||||
@Default
|
||||
private Float temperature = null;
|
||||
private Float temperature = 0.0f;
|
||||
|
||||
@Value("minecraft.climate.temperature-modifier")
|
||||
@Default
|
||||
private TemperatureModifier temperatureModifier = null;
|
||||
private TemperatureModifier temperatureModifier = TemperatureModifier.NONE;
|
||||
|
||||
@Value("minecraft.climate.downfall")
|
||||
@Default
|
||||
private Float downfall = null;
|
||||
private Float downfall = 0.0f;
|
||||
|
||||
@Value("minecraft.sound.loop-sound.sound")
|
||||
@Default
|
||||
@@ -92,12 +100,16 @@ public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
||||
|
||||
@Value("minecraft.spawning")
|
||||
@Default
|
||||
private SpawnSettings spawnSettings = null;
|
||||
private SpawnSettings spawnSettings = SpawnSettings.INSTANCE;
|
||||
|
||||
@Value("minecraft.villager-type")
|
||||
@Default
|
||||
private VillagerType villagerType = null;
|
||||
|
||||
public Map<Identifier, ProbabilityCollection<ConfiguredStructure>> getFertilizables() {
|
||||
return fertilizables;
|
||||
}
|
||||
|
||||
public List<Identifier> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.dfsek.terra.mod.mixin;
|
||||
|
||||
import net.minecraft.block.Fertilizable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
|
||||
@Mixin(Fertilizable.class)
|
||||
public class FertilizableMixin {
|
||||
|
||||
}
|
||||
@@ -4,16 +4,21 @@ import net.minecraft.tag.TagKey;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryEntry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.village.VillagerType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.mod.CommonPlatform;
|
||||
import com.dfsek.terra.mod.config.ProtoPlatformBiome;
|
||||
@@ -24,6 +29,12 @@ import com.dfsek.terra.mod.mixin.access.VillagerTypeAccessor;
|
||||
public class BiomeUtil {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BiomeUtil.class);
|
||||
|
||||
public static final Map<RegistryEntry<net.minecraft.world.biome.Biome>, Map<Identifier, ProbabilityCollection<ConfiguredStructure>>>
|
||||
TERRA_BIOME_FERTILIZABLE_MAP = new HashMap<>();
|
||||
|
||||
public static final Map<TagKey<net.minecraft.world.biome.Biome>, List<Identifier>>
|
||||
TERRA_BIOME_TAG_MAP = new HashMap<>();
|
||||
|
||||
public static void registerBiomes() {
|
||||
logger.info("Registering biomes...");
|
||||
CommonPlatform.get().getConfigRegistry().forEach(pack -> { // Register all Terra biomes.
|
||||
@@ -55,20 +66,22 @@ public class BiomeUtil {
|
||||
protected static void registerBiome(Biome biome, ConfigPack pack,
|
||||
com.dfsek.terra.api.registry.key.RegistryKey id) {
|
||||
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
|
||||
|
||||
|
||||
net.minecraft.world.biome.Biome minecraftBiome = MinecraftUtil.createBiome(vanillaBiomeProperties);
|
||||
|
||||
|
||||
Identifier identifier = new Identifier("terra", MinecraftUtil.createBiomeID(pack, id));
|
||||
|
||||
|
||||
biome.setPlatformBiome(new ProtoPlatformBiome(identifier, registerBiome(identifier, minecraftBiome)));
|
||||
|
||||
|
||||
Map villagerMap = VillagerTypeAccessor.getBiomeTypeToIdMap();
|
||||
|
||||
|
||||
villagerMap.put(RegistryKey.of(Registry.BIOME_KEY, identifier),
|
||||
Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(), VillagerType.PLAINS));
|
||||
|
||||
|
||||
TERRA_BIOME_FERTILIZABLE_MAP.put(RegistryEntry.of(minecraftBiome), vanillaBiomeProperties.getFertilizables());
|
||||
|
||||
for(Identifier tag : vanillaBiomeProperties.getTags()) {
|
||||
MinecraftUtil.TERRA_BIOME_TAG_MAP.getOrDefault(TagKey.of(Registry.BIOME_KEY, tag), new ArrayList<>()).add(identifier);
|
||||
TERRA_BIOME_TAG_MAP.getOrDefault(TagKey.of(Registry.BIOME_KEY, tag), new ArrayList<>()).add(identifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.dfsek.terra.mod.util;
|
||||
|
||||
import com.dfsek.terra.api.util.Rotation;
|
||||
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
||||
|
||||
public class FertilizableUtil {
|
||||
public static boolean grow(ServerWorld world, Random random, BlockPos pos, BlockState state) {
|
||||
Map<Identifier, ProbabilityCollection<ConfiguredStructure>> fertilizables = BiomeUtil.TERRA_BIOME_FERTILIZABLE_MAP.get(world.getBiome(pos));
|
||||
if (fertilizables != null) {
|
||||
ProbabilityCollection<ConfiguredStructure> probabilityCollection = fertilizables.get(Registry.BLOCK.getId(state.getBlock()));
|
||||
if (probabilityCollection != null) {
|
||||
ConfiguredStructure structure = probabilityCollection.get((java.util.Random) random);
|
||||
structure.getStructure().get((java.util.Random) random).generate(Vector3Int.of(pos.getX(), pos.getY(), pos.getZ()), (WritableWorld) world, (java.util.Random) random, Rotation.NONE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package com.dfsek.terra.mod.util;
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
import net.minecraft.block.entity.MobSpawnerBlockEntity;
|
||||
import net.minecraft.block.entity.SignBlockEntity;
|
||||
import net.minecraft.tag.TagKey;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
@@ -17,10 +16,7 @@ import net.minecraft.world.biome.GenerationSettings;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -35,8 +31,6 @@ import com.dfsek.terra.mod.config.VanillaBiomeProperties;
|
||||
public final class MinecraftUtil {
|
||||
public static final Logger logger = LoggerFactory.getLogger(MinecraftUtil.class);
|
||||
|
||||
public static final Map<TagKey<Biome>, List<Identifier>>
|
||||
TERRA_BIOME_TAG_MAP = new HashMap<>();
|
||||
|
||||
private MinecraftUtil() {
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public final class TagUtil {
|
||||
logger.info("who let this data drive?");
|
||||
Map<TagKey<Biome>, List<RegistryEntry<Biome>>> collect = tagsToMutableMap(registry);
|
||||
|
||||
MinecraftUtil.TERRA_BIOME_TAG_MAP.forEach((tag, biomeList) -> {
|
||||
BiomeUtil.TERRA_BIOME_TAG_MAP.forEach((tag, biomeList) -> {
|
||||
collect.getOrDefault(tag, new ArrayList<>())
|
||||
.addAll(biomeList.stream()
|
||||
.map(registry::getOrEmpty)
|
||||
|
||||
Reference in New Issue
Block a user