This commit is contained in:
Zoë Gidiere
2025-06-18 11:43:35 -06:00
parent 3f77b4a975
commit 46e603d681
233 changed files with 824 additions and 818 deletions
@@ -1,7 +1,5 @@
package com.dfsek.terra.bukkit.nms.v1_21_6;
import com.dfsek.terra.bukkit.nms.v1_21_6.config.VanillaBiomeProperties;
import net.minecraft.core.Holder;
import net.minecraft.core.Holder.Reference;
import net.minecraft.core.HolderSet;
@@ -25,6 +23,7 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import com.dfsek.terra.bukkit.nms.v1_21_6.config.VanillaBiomeProperties;
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
import com.dfsek.terra.registry.master.ConfigRegistry;
@@ -52,7 +51,8 @@ public class AwfulBukkitHacks {
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
Biome platform = NMSBiomeInjector.createBiome(biomeRegistry.get(vanillaMinecraftKey).orElseThrow().value(), vanillaBiomeProperties);
Biome platform = NMSBiomeInjector.createBiome(biomeRegistry.get(vanillaMinecraftKey).orElseThrow().value(),
vanillaBiomeProperties);
ResourceKey<Biome> delegateKey = ResourceKey.create(
Registries.BIOME,
@@ -112,39 +112,42 @@ public class AwfulBukkitHacks {
Map<Holder.Reference<T>, List<TagKey<T>>> map = new IdentityHashMap<>();
Reflection.MAPPED_REGISTRY.getByKey(registry).values().forEach(entry -> map.put(entry, new ArrayList<>()));
tagEntries.forEach((tag, entries) -> {
for (Holder<T> holder : entries) {
// if (!holder.canSerializeIn(registry.asLookup())) {
// throw new IllegalStateException("Can't create named set " + tag + " containing value " + holder + " from outside registry " + this);
// }
for(Holder<T> holder : entries) {
// if (!holder.canSerializeIn(registry.asLookup())) {
// throw new IllegalStateException("Can't create named set " + tag + " containing value " + holder + "
// from outside registry " + this);
// }
if (!(holder instanceof Holder.Reference<T> reference)) {
if(!(holder instanceof Holder.Reference<T> reference)) {
throw new IllegalStateException("Found direct holder " + holder + " value in tag " + tag);
}
map.get(reference).add(tag);
}
});
// Set<TagKey<T>> set = Sets.difference(registry.tags.keySet(), tagEntries.keySet());
// if (!set.isEmpty()) {
// LOGGER.warn(
// "Not all defined tags for registry {} are present in data pack: {}",
// registry.key(),
// set.stream().map(tag -> tag.location().toString()).sorted().collect(Collectors.joining(", "))
// );
// }
// Set<TagKey<T>> set = Sets.difference(registry.tags.keySet(), tagEntries.keySet());
// if (!set.isEmpty()) {
// LOGGER.warn(
// "Not all defined tags for registry {} are present in data pack: {}",
// registry.key(),
// set.stream().map(tag -> tag.location().toString()).sorted().collect(Collectors.joining(", "))
// );
// }
Map<TagKey<T>, HolderSet.Named<T>> map2 = new IdentityHashMap<>(registry.getTags().collect(Collectors.toMap(
Named::key,
(named) -> named
)));
tagEntries.forEach((tag, entries) -> Reflection.HOLDER_SET.invokeBind(map2.computeIfAbsent(tag, key -> Reflection.MAPPED_REGISTRY.invokeCreateTag(registry, key)), entries));
tagEntries.forEach((tag, entries) -> Reflection.HOLDER_SET.invokeBind(
map2.computeIfAbsent(tag, key -> Reflection.MAPPED_REGISTRY.invokeCreateTag(registry, key)), entries));
map.forEach(Reflection.HOLDER_REFERENCE::invokeBindTags);
Reflection.MAPPED_REGISTRY.setAllTags(registry, Reflection.MAPPED_REGISTRY_TAG_SET.invokeFromMap(map2));
}
private static void resetTags(MappedRegistry<?> registry) {
registry.getTags().forEach(entryList -> Reflection.HOLDER_SET.invokeBind(entryList, List.of()));
Reflection.MAPPED_REGISTRY.getByKey(registry).values().forEach(entry -> Reflection.HOLDER_REFERENCE.invokeBindTags(entry, Set.of()));
Reflection.MAPPED_REGISTRY.getByKey(registry).values().forEach(
entry -> Reflection.HOLDER_REFERENCE.invokeBindTags(entry, Set.of()));
}
}
@@ -33,7 +33,8 @@ public class NMSBiomeInjector {
.waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor()))
.waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor()))
.skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor()))
.grassColorModifier(Objects.requireNonNullElse(vanillaBiomeProperties.getGrassColorModifier(), vanilla.getSpecialEffects().getGrassColorModifier()))
.grassColorModifier(Objects.requireNonNullElse(vanillaBiomeProperties.getGrassColorModifier(),
vanilla.getSpecialEffects().getGrassColorModifier()))
.backgroundMusicVolume(Objects.requireNonNullElse(vanillaBiomeProperties.getMusicVolume(), vanilla.getBackgroundMusicVolume()));
if(vanillaBiomeProperties.getGrassColor() == null) {
@@ -84,7 +85,8 @@ public class NMSBiomeInjector {
builder.downfall(Objects.requireNonNullElse(vanillaBiomeProperties.getDownfall(), vanilla.climateSettings.downfall()));
builder.temperatureAdjustment(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperatureModifier(), vanilla.climateSettings.temperatureModifier()));
builder.temperatureAdjustment(
Objects.requireNonNullElse(vanillaBiomeProperties.getTemperatureModifier(), vanilla.climateSettings.temperatureModifier()));
builder.mobSpawnSettings(Objects.requireNonNullElse(vanillaBiomeProperties.getSpawnSettings(), vanilla.getMobSettings()));
@@ -1,9 +1,8 @@
package com.dfsek.terra.bukkit.nms.v1_21_6;
import com.dfsek.terra.bukkit.BukkitAddon;
import org.bukkit.Bukkit;
import com.dfsek.terra.bukkit.BukkitAddon;
import com.dfsek.terra.bukkit.PlatformImpl;
import com.dfsek.terra.bukkit.nms.Initializer;
@@ -68,6 +68,7 @@ public class Reflection {
<T> HolderSet.Named<T> invokeCreateTag(MappedRegistry<T> instance, TagKey<T> tag);
}
@Proxies(className = "net.minecraft.core.MappedRegistry$TagSet")
public interface MappedRegistryTagSetProxy {
@MethodName("fromMap")
@@ -92,6 +93,7 @@ public class Reflection {
<T> void invokeBindTags(Reference<T> instance, Collection<TagKey<T>> tags);
}
@Proxies(ChunkMap.class)
public interface ChunkMapProxy {
@FieldGetter("worldGenContext")
@@ -101,12 +103,14 @@ public class Reflection {
void setWorldGenContext(ChunkMap instance, WorldGenContext worldGenContext);
}
@Proxies(Holder.Reference.class)
public interface HolderReferenceProxy {
@MethodName("bindTags")
<T> void invokeBindTags(Holder.Reference<T> instance, Collection<TagKey<T>> tags);
}
@Proxies(HolderSet.Named.class)
public interface HolderSetNamedProxy {
@MethodName("bind")
@@ -116,6 +120,7 @@ public class Reflection {
<T> List<Holder<T>> invokeContents(HolderSet.Named<T> instance);
}
@Proxies(Biome.class)
public interface BiomeProxy {
@MethodName("getGrassColorFromTexture")
@@ -12,11 +12,11 @@ public class BiomeAdditionsSoundTemplate implements ObjectTemplate<AmbientAdditi
@Value("sound")
@Default
private SoundEvent sound = null;
@Value("sound-chance")
@Default
private Double soundChance = null;
@Override
public AmbientAdditionsSettings get() {
if(sound == null || soundChance == null) {
@@ -12,25 +12,26 @@ public class BiomeMoodSoundTemplate implements ObjectTemplate<AmbientMoodSetting
@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 AmbientMoodSettings get() {
if(sound == null || soundCultivationTicks == null || soundSpawnRange == null || soundExtraDistance == null) {
return null;
} else {
return new AmbientMoodSettings(BuiltInRegistries.SOUND_EVENT.wrapAsHolder(sound), soundCultivationTicks, soundSpawnRange, soundExtraDistance);
return new AmbientMoodSettings(BuiltInRegistries.SOUND_EVENT.wrapAsHolder(sound), soundCultivationTicks, soundSpawnRange,
soundExtraDistance);
}
}
}
@@ -15,17 +15,17 @@ public class BiomeParticleConfigTemplate implements ObjectTemplate<AmbientPartic
@Value("particle")
@Default
private String particle = null;
@Value("probability")
@Default
private Integer probability = null;
@Override
public AmbientParticleSettings get() {
if(particle == null || probability == null) {
return null;
}
try {
return new AmbientParticleSettings(ParticleArgument.readParticle(new StringReader(particle),
(Provider) BuiltInRegistries.PARTICLE_TYPE.asHolderIdMap()), probability);
@@ -12,7 +12,7 @@ public class EntityTypeTemplate implements ObjectTemplate<EntityType<?>> {
@Value("id")
@Default
private ResourceLocation id = null;
@Override
public EntityType<?> get() {
return BuiltInRegistries.ENTITY_TYPE.get(id).orElseThrow().value();
@@ -12,19 +12,19 @@ public class MusicSoundTemplate implements ObjectTemplate<Music> {
@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 Music get() {
if(sound == null || minDelay == null || maxDelay == null || replaceCurrentMusic == null) {
@@ -11,11 +11,11 @@ public class SoundEventTemplate implements ObjectTemplate<SoundEvent> {
@Value("id")
@Default
private ResourceLocation 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,15 +11,15 @@ public class SpawnEntryConfig implements ObjectTemplate<SpawnEntryConfig> {
@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;
@@ -31,7 +31,7 @@ public class SpawnEntryConfig implements ObjectTemplate<SpawnEntryConfig> {
public SpawnerData getSpawnerData() {
return new SpawnerData(type, minGroupSize, maxGroupSize);
}
@Override
public SpawnEntryConfig get() {
return this;
@@ -3,12 +3,13 @@ package com.dfsek.terra.bukkit.nms.v1_21_6.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import java.util.List;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.level.biome.MobSpawnSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
public class SpawnSettingsTemplate implements ObjectTemplate<MobSpawnSettings> {
@@ -18,15 +19,15 @@ public class SpawnSettingsTemplate implements ObjectTemplate<MobSpawnSettings> {
@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 MobSpawnSettings get() {
MobSpawnSettings.Builder builder = new MobSpawnSettings.Builder();
@@ -42,7 +43,7 @@ public class SpawnSettingsTemplate implements ObjectTemplate<MobSpawnSettings> {
if(probability != null) {
builder.creatureGenerationProbability(probability);
}
return builder.build();
}
}
@@ -3,9 +3,10 @@ package com.dfsek.terra.bukkit.nms.v1_21_6.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import java.util.List;
import net.minecraft.world.entity.MobCategory;
import java.util.List;
public class SpawnTypeConfig implements ObjectTemplate<SpawnTypeConfig> {
@Value("group")
@@ -3,9 +3,6 @@ package com.dfsek.terra.bukkit.nms.v1_21_6.config;
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.terra.api.properties.Properties;
import net.minecraft.sounds.Music;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.npc.VillagerType;
@@ -16,6 +13,8 @@ import net.minecraft.world.level.biome.Biome.TemperatureModifier;
import net.minecraft.world.level.biome.BiomeSpecialEffects.GrassColorModifier;
import net.minecraft.world.level.biome.MobSpawnSettings;
import com.dfsek.terra.api.properties.Properties;
public class VanillaBiomeProperties implements ConfigTemplate, Properties {
@Value("colors.grass")
@@ -12,7 +12,7 @@ public class VillagerTypeTemplate implements ObjectTemplate<VillagerType> {
@Value("id")
@Default
private ResourceLocation id = null;
@Override
public VillagerType get() {
return BuiltInRegistries.VILLAGER_TYPE.get(id).orElseThrow().value();