diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/HazardProperty.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/HazardProperty.java index 76b3b92d49..d22eed16af 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/HazardProperty.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/HazardProperty.java @@ -75,7 +75,7 @@ public record HazardType(String name, ProtectionType protectionType, Set, Integer> { + public static final BiomeWeightModifier EMPTY = new BiomeWeightModifier(HolderSet::direct, 0); + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( RegistryCodecs.homogeneousList(Registries.BIOME).fieldOf("biomes").forGetter(mod -> mod.biomes.get()), Codec.INT.fieldOf("added_weight").forGetter(mod -> mod.addedWeight)) diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/GTOreDefinition.java b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/GTOreDefinition.java index 0999da193d..c0f5da91c0 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/GTOreDefinition.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/GTOreDefinition.java @@ -70,9 +70,9 @@ public class GTOreDefinition { HeightRangePlacement.CODEC.fieldOf("height_range").forGetter(ft -> ft.range), Codec.floatRange(0.0F, 1.0F).fieldOf("discard_chance_on_air_exposure") .forGetter(ft -> ft.discardChanceOnAirExposure), - RegistryCodecs.homogeneousList(Registries.BIOME).optionalFieldOf("biomes", null) - .forGetter(ext -> ext.biomes == null ? null : ext.biomes.get()), - BiomeWeightModifier.CODEC.optionalFieldOf("weight_modifier", null) + RegistryCodecs.homogeneousList(Registries.BIOME).optionalFieldOf("biomes", HolderSet.direct()) + .forGetter(ext -> ext.biomes == null ? HolderSet.direct() : ext.biomes.get()), + BiomeWeightModifier.CODEC.optionalFieldOf("weight_modifier", BiomeWeightModifier.EMPTY) .forGetter(ext -> ext.biomeWeightModifier), VeinGenerator.DIRECT_CODEC.fieldOf("generator").forGetter(ft -> ft.veinGenerator), Codec.list(IndicatorGenerator.DIRECT_CODEC).fieldOf("indicators") @@ -81,7 +81,7 @@ public class GTOreDefinition { (clusterSize, density, weight, layer, dimensionFilter, range, discardChanceOnAirExposure, biomes, biomeWeightModifier, veinGenerator, indicatorGenerators) -> new GTOreDefinition( clusterSize, density, weight, layer, new HashSet<>(dimensionFilter), range, - discardChanceOnAirExposure, biomes == null ? null : () -> biomes, + discardChanceOnAirExposure, biomes == null ? HolderSet::direct : () -> biomes, biomeWeightModifier, veinGenerator, indicatorGenerators))); private final InferredProperties inferredProperties = new InferredProperties(); @@ -107,7 +107,7 @@ public class GTOreDefinition { private Supplier> biomes; @Getter @Setter - private BiomeWeightModifier biomeWeightModifier; + private BiomeWeightModifier biomeWeightModifier = BiomeWeightModifier.EMPTY; @Getter @Setter diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/generator/veins/VeinedVeinGenerator.java b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/generator/veins/VeinedVeinGenerator.java index 755fa3f68e..a1676edcd2 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/generator/veins/VeinedVeinGenerator.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/generator/veins/VeinedVeinGenerator.java @@ -76,7 +76,7 @@ public class VeinedVeinGenerator extends VeinGenerator { public List oreBlocks = new ArrayList<>(); public List rareBlocks = new ArrayList<>(); @Setter - public BlockState fillerBlock; + public BlockState fillerBlock = Blocks.AIR.defaultBlockState(); @Setter public int minYLevel; @Setter diff --git a/src/main/java/com/gregtechceu/gtceu/api/registry/GTRegistries.java b/src/main/java/com/gregtechceu/gtceu/api/registry/GTRegistries.java index a09182af58..1cc90fa564 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/registry/GTRegistries.java +++ b/src/main/java/com/gregtechceu/gtceu/api/registry/GTRegistries.java @@ -33,6 +33,7 @@ import net.minecraftforge.registries.ForgeRegistries; import com.mojang.serialization.Codec; +import org.jetbrains.annotations.Nullable; /** * @author KilaBash @@ -97,6 +98,7 @@ public static void init(IEventBus eventBus) { GLOBAL_LOOT_MODIFIES.register(eventBus); } + @Nullable public static RegistryAccess builtinRegistry() { return Platform.getFrozenRegistry(); } diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTOres.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTOres.java index fb97fd7cfc..e4934ae445 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTOres.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTOres.java @@ -8,8 +8,10 @@ import com.gregtechceu.gtceu.api.data.worldgen.generator.IndicatorGenerators; import com.gregtechceu.gtceu.api.data.worldgen.generator.VeinGenerators; import com.gregtechceu.gtceu.api.data.worldgen.generator.indicators.SurfaceIndicatorGenerator; +import com.gregtechceu.gtceu.api.data.worldgen.generator.veins.NoopVeinGenerator; import com.gregtechceu.gtceu.api.registry.GTRegistries; +import net.minecraft.core.HolderSet; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BiomeTags; @@ -25,9 +27,7 @@ import lombok.Getter; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.function.Consumer; import java.util.function.Supplier; @@ -794,8 +794,9 @@ public static void updateLargestVeinSize() { public static GTOreDefinition blankOreDefinition() { return new GTOreDefinition( - ConstantInt.of(0), 0, 0, IWorldGenLayer.NOWHERE, Set.of(), + ConstantInt.ZERO, 0, 0, IWorldGenLayer.NOWHERE, Set.of(), HeightRangePlacement.uniform(VerticalAnchor.absolute(0), VerticalAnchor.absolute(0)), - 0, null, null, null, null); + 0, HolderSet::direct, BiomeWeightModifier.EMPTY, NoopVeinGenerator.INSTANCE, + new ArrayList<>()); } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncOreVeins.java b/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncOreVeins.java index f529e3843b..c4a24f22ad 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncOreVeins.java +++ b/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncOreVeins.java @@ -4,7 +4,6 @@ import com.gregtechceu.gtceu.api.data.worldgen.GTOreDefinition; import com.gregtechceu.gtceu.api.registry.GTRegistries; -import com.lowdragmc.lowdraglib.Platform; import com.lowdragmc.lowdraglib.networking.IHandlerContext; import com.lowdragmc.lowdraglib.networking.IPacket; @@ -32,7 +31,7 @@ public SPacketSyncOreVeins() { @Override public void encode(FriendlyByteBuf buf) { - RegistryOps ops = RegistryOps.create(NbtOps.INSTANCE, Platform.getFrozenRegistry()); + RegistryOps ops = RegistryOps.create(NbtOps.INSTANCE, GTRegistries.builtinRegistry()); int size = veins.size(); buf.writeVarInt(size); for (var entry : veins.entrySet()) { @@ -45,7 +44,7 @@ public void encode(FriendlyByteBuf buf) { @Override public void decode(FriendlyByteBuf buf) { - RegistryOps ops = RegistryOps.create(NbtOps.INSTANCE, Platform.getFrozenRegistry()); + RegistryOps ops = RegistryOps.create(NbtOps.INSTANCE, GTRegistries.builtinRegistry()); Stream.generate(() -> { ResourceLocation id = buf.readResourceLocation(); CompoundTag tag = buf.readAnySizeNbt(); diff --git a/src/main/java/com/gregtechceu/gtceu/data/loader/BedrockOreLoader.java b/src/main/java/com/gregtechceu/gtceu/data/loader/BedrockOreLoader.java index 8cc8c575dc..8ff6fe606a 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/loader/BedrockOreLoader.java +++ b/src/main/java/com/gregtechceu/gtceu/data/loader/BedrockOreLoader.java @@ -12,6 +12,8 @@ import com.gregtechceu.gtceu.integration.kjs.GTCEuServerEvents; import com.gregtechceu.gtceu.integration.kjs.events.GTBedrockOreVeinEventJS; +import com.lowdragmc.lowdraglib.Platform; + import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.ResourceManager; @@ -82,7 +84,9 @@ protected void apply(Map resourceList, ResourceMa GTRegistries.BEDROCK_ORE_DEFINITIONS.freeze(); } - GTNetwork.NETWORK.sendToAll(new SPacketSyncFluidVeins(GTRegistries.BEDROCK_FLUID_DEFINITIONS.registry())); + if (Platform.getMinecraftServer() != null) { + GTNetwork.NETWORK.sendToAll(new SPacketSyncFluidVeins(GTRegistries.BEDROCK_FLUID_DEFINITIONS.registry())); + } } public static BedrockOreDefinition fromJson(ResourceLocation id, JsonObject json, RegistryOps ops) { diff --git a/src/main/java/com/gregtechceu/gtceu/data/loader/FluidVeinLoader.java b/src/main/java/com/gregtechceu/gtceu/data/loader/FluidVeinLoader.java index c4fb6ca201..9ccecf4559 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/loader/FluidVeinLoader.java +++ b/src/main/java/com/gregtechceu/gtceu/data/loader/FluidVeinLoader.java @@ -12,6 +12,8 @@ import com.gregtechceu.gtceu.integration.kjs.GTCEuServerEvents; import com.gregtechceu.gtceu.integration.kjs.events.GTFluidVeinEventJS; +import com.lowdragmc.lowdraglib.Platform; + import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.ResourceManager; @@ -79,7 +81,10 @@ protected void apply(Map resourceList, ResourceMa GTRegistries.BEDROCK_FLUID_DEFINITIONS.freeze(); } - GTNetwork.NETWORK.sendToAll(new SPacketSyncBedrockOreVeins(GTRegistries.BEDROCK_ORE_DEFINITIONS.registry())); + if (Platform.getMinecraftServer() != null) { + GTNetwork.NETWORK + .sendToAll(new SPacketSyncBedrockOreVeins(GTRegistries.BEDROCK_ORE_DEFINITIONS.registry())); + } } public static BedrockFluidDefinition fromJson(ResourceLocation id, JsonObject json, RegistryOps ops) { diff --git a/src/main/java/com/gregtechceu/gtceu/data/loader/OreDataLoader.java b/src/main/java/com/gregtechceu/gtceu/data/loader/OreDataLoader.java index 97b4738057..ca3e8e7695 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/loader/OreDataLoader.java +++ b/src/main/java/com/gregtechceu/gtceu/data/loader/OreDataLoader.java @@ -13,6 +13,8 @@ import com.gregtechceu.gtceu.integration.kjs.GTCEuServerEvents; import com.gregtechceu.gtceu.integration.kjs.events.GTOreVeinEventJS; +import com.lowdragmc.lowdraglib.Platform; + import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.ResourceManager; @@ -90,7 +92,9 @@ protected void apply(Map resourceList, ResourceMa GTRegistries.ORE_VEINS.freeze(); } - GTNetwork.NETWORK.sendToAll(new SPacketSyncOreVeins(GTRegistries.ORE_VEINS.registry())); + if (Platform.getMinecraftServer() != null) { + GTNetwork.NETWORK.sendToAll(new SPacketSyncOreVeins(GTRegistries.ORE_VEINS.registry())); + } } public static void buildVeinGenerator() {