Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ore vein network sync #1354

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public record HazardType(String name, ProtectionType protectionType, Set<TagPref

public static final HazardType INHALATION_POISON = new HazardType("inhalation_poison", ProtectionType.MASK,
TagPrefix.dust, TagPrefix.dustSmall, TagPrefix.dustTiny, TagPrefix.dustPure, TagPrefix.dustImpure);
public static final HazardType CONTACT_POISON = new HazardType("contacy_poison", ProtectionType.FULL);
public static final HazardType CONTACT_POISON = new HazardType("contact_poison", ProtectionType.FULL);
public static final HazardType RADIOACTIVE = new HazardType("radioactive", ProtectionType.FULL);
public static final HazardType CORROSIVE = new HazardType("corrosive", ProtectionType.HANDS,
TagPrefix.dust, TagPrefix.dustSmall, TagPrefix.dustTiny);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

public class BiomeWeightModifier implements Function<Holder<Biome>, Integer> {

public static final BiomeWeightModifier EMPTY = new BiomeWeightModifier(HolderSet::direct, 0);

public static final Codec<BiomeWeightModifier> 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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();
Expand All @@ -107,7 +107,7 @@ public class GTOreDefinition {
private Supplier<HolderSet<Biome>> biomes;
@Getter
@Setter
private BiomeWeightModifier biomeWeightModifier;
private BiomeWeightModifier biomeWeightModifier = BiomeWeightModifier.EMPTY;

@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class VeinedVeinGenerator extends VeinGenerator {
public List<VeinBlockDefinition> oreBlocks = new ArrayList<>();
public List<VeinBlockDefinition> rareBlocks = new ArrayList<>();
@Setter
public BlockState fillerBlock;
public BlockState fillerBlock = Blocks.AIR.defaultBlockState();
@Setter
public int minYLevel;
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.minecraftforge.registries.ForgeRegistries;

import com.mojang.serialization.Codec;
import org.jetbrains.annotations.Nullable;

/**
* @author KilaBash
Expand Down Expand Up @@ -97,6 +98,7 @@ public static void init(IEventBus eventBus) {
GLOBAL_LOOT_MODIFIES.register(eventBus);
}

@Nullable
public static RegistryAccess builtinRegistry() {
return Platform.getFrozenRegistry();
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/gregtechceu/gtceu/common/data/GTOres.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class GTNetwork {

public static void init() {
NETWORK.registerC2S(CPacketKeysPressed.class);
NETWORK.registerC2S(SPacketSyncOreVeins.class);
NETWORK.registerC2S(SPacketSyncFluidVeins.class);
NETWORK.registerC2S(SPacketSyncBedrockOreVeins.class);
NETWORK.registerS2C(SPacketSyncOreVeins.class);
NETWORK.registerS2C(SPacketSyncFluidVeins.class);
NETWORK.registerS2C(SPacketSyncBedrockOreVeins.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -32,7 +31,7 @@ public SPacketSyncOreVeins() {

@Override
public void encode(FriendlyByteBuf buf) {
RegistryOps<Tag> ops = RegistryOps.create(NbtOps.INSTANCE, Platform.getFrozenRegistry());
RegistryOps<Tag> ops = RegistryOps.create(NbtOps.INSTANCE, GTRegistries.builtinRegistry());
int size = veins.size();
buf.writeVarInt(size);
for (var entry : veins.entrySet()) {
Expand All @@ -45,7 +44,7 @@ public void encode(FriendlyByteBuf buf) {

@Override
public void decode(FriendlyByteBuf buf) {
RegistryOps<Tag> ops = RegistryOps.create(NbtOps.INSTANCE, Platform.getFrozenRegistry());
RegistryOps<Tag> ops = RegistryOps.create(NbtOps.INSTANCE, GTRegistries.builtinRegistry());
Stream.generate(() -> {
ResourceLocation id = buf.readResourceLocation();
CompoundTag tag = buf.readAnySizeNbt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -82,7 +84,9 @@ protected void apply(Map<ResourceLocation, JsonElement> 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<JsonElement> ops) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,7 +81,10 @@ protected void apply(Map<ResourceLocation, JsonElement> 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<JsonElement> ops) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,7 +92,9 @@ protected void apply(Map<ResourceLocation, JsonElement> 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() {
Expand Down
Loading