diff --git a/src/generated/resources/assets/gtceu/compass/nodes/generation/andesite.json b/src/generated/resources/assets/gtceu/compass/nodes/generation/andesite.json index d78be19130..069b9a59c1 100644 --- a/src/generated/resources/assets/gtceu/compass/nodes/generation/andesite.json +++ b/src/generated/resources/assets/gtceu/compass/nodes/generation/andesite.json @@ -113,11 +113,13 @@ "gtceu:andesite_diatomite_ore", "gtceu:andesite_granitic_mineral_sand_ore", "gtceu:andesite_garnet_sand_ore", - "gtceu:andesite_basaltic_mineral_sand_ore" + "gtceu:andesite_basaltic_mineral_sand_ore", + "gtceu:andesite_fluorite_ore", + "gtceu:andesite_dolomite_ore" ], "page": "gtceu:generation/andesite", "position": [ - -200, + -50, 50 ], "pre_nodes": [ diff --git a/src/generated/resources/assets/gtceu/compass/nodes/generation/basalt.json b/src/generated/resources/assets/gtceu/compass/nodes/generation/basalt.json index 002b0d86c9..0a736467c0 100644 --- a/src/generated/resources/assets/gtceu/compass/nodes/generation/basalt.json +++ b/src/generated/resources/assets/gtceu/compass/nodes/generation/basalt.json @@ -113,12 +113,14 @@ "gtceu:basalt_diatomite_ore", "gtceu:basalt_granitic_mineral_sand_ore", "gtceu:basalt_garnet_sand_ore", - "gtceu:basalt_basaltic_mineral_sand_ore" + "gtceu:basalt_basaltic_mineral_sand_ore", + "gtceu:basalt_fluorite_ore", + "gtceu:basalt_dolomite_ore" ], "page": "gtceu:generation/basalt", "position": [ - -50, - 50 + -150, + 150 ], "pre_nodes": [ "gtceu:generation/ore" diff --git a/src/generated/resources/assets/gtceu/compass/nodes/generation/deepslate.json b/src/generated/resources/assets/gtceu/compass/nodes/generation/deepslate.json index 833b576ec1..033faf0d0a 100644 --- a/src/generated/resources/assets/gtceu/compass/nodes/generation/deepslate.json +++ b/src/generated/resources/assets/gtceu/compass/nodes/generation/deepslate.json @@ -113,12 +113,14 @@ "gtceu:deepslate_diatomite_ore", "gtceu:deepslate_granitic_mineral_sand_ore", "gtceu:deepslate_garnet_sand_ore", - "gtceu:deepslate_basaltic_mineral_sand_ore" + "gtceu:deepslate_basaltic_mineral_sand_ore", + "gtceu:deepslate_fluorite_ore", + "gtceu:deepslate_dolomite_ore" ], "page": "gtceu:generation/deepslate", "position": [ - -150, - 150 + -200, + 100 ], "pre_nodes": [ "gtceu:generation/ore" diff --git a/src/generated/resources/assets/gtceu/compass/nodes/generation/diorite.json b/src/generated/resources/assets/gtceu/compass/nodes/generation/diorite.json index ed27573686..4e2bb7ad6a 100644 --- a/src/generated/resources/assets/gtceu/compass/nodes/generation/diorite.json +++ b/src/generated/resources/assets/gtceu/compass/nodes/generation/diorite.json @@ -113,12 +113,14 @@ "gtceu:diorite_diatomite_ore", "gtceu:diorite_granitic_mineral_sand_ore", "gtceu:diorite_garnet_sand_ore", - "gtceu:diorite_basaltic_mineral_sand_ore" + "gtceu:diorite_basaltic_mineral_sand_ore", + "gtceu:diorite_fluorite_ore", + "gtceu:diorite_dolomite_ore" ], "page": "gtceu:generation/diorite", "position": [ - -200, - 150 + -100, + 50 ], "pre_nodes": [ "gtceu:generation/ore" diff --git a/src/generated/resources/assets/gtceu/compass/nodes/generation/endstone.json b/src/generated/resources/assets/gtceu/compass/nodes/generation/endstone.json index 24ecd61b58..47c574c39f 100644 --- a/src/generated/resources/assets/gtceu/compass/nodes/generation/endstone.json +++ b/src/generated/resources/assets/gtceu/compass/nodes/generation/endstone.json @@ -113,12 +113,14 @@ "gtceu:endstone_diatomite_ore", "gtceu:endstone_granitic_mineral_sand_ore", "gtceu:endstone_garnet_sand_ore", - "gtceu:endstone_basaltic_mineral_sand_ore" + "gtceu:endstone_basaltic_mineral_sand_ore", + "gtceu:endstone_fluorite_ore", + "gtceu:endstone_dolomite_ore" ], "page": "gtceu:generation/endstone", "position": [ - -200, - 100 + -50, + 150 ], "pre_nodes": [ "gtceu:generation/ore" diff --git a/src/generated/resources/assets/gtceu/compass/nodes/generation/granite.json b/src/generated/resources/assets/gtceu/compass/nodes/generation/granite.json index 74152de990..107a3d83aa 100644 --- a/src/generated/resources/assets/gtceu/compass/nodes/generation/granite.json +++ b/src/generated/resources/assets/gtceu/compass/nodes/generation/granite.json @@ -113,12 +113,14 @@ "gtceu:granite_diatomite_ore", "gtceu:granite_granitic_mineral_sand_ore", "gtceu:granite_garnet_sand_ore", - "gtceu:granite_basaltic_mineral_sand_ore" + "gtceu:granite_basaltic_mineral_sand_ore", + "gtceu:granite_fluorite_ore", + "gtceu:granite_dolomite_ore" ], "page": "gtceu:generation/granite", "position": [ -150, - 100 + 50 ], "pre_nodes": [ "gtceu:generation/ore" diff --git a/src/generated/resources/assets/gtceu/compass/nodes/generation/gravel.json b/src/generated/resources/assets/gtceu/compass/nodes/generation/gravel.json index da8d1fe961..1d260c7bc4 100644 --- a/src/generated/resources/assets/gtceu/compass/nodes/generation/gravel.json +++ b/src/generated/resources/assets/gtceu/compass/nodes/generation/gravel.json @@ -113,11 +113,13 @@ "gtceu:gravel_diatomite_ore", "gtceu:gravel_granitic_mineral_sand_ore", "gtceu:gravel_garnet_sand_ore", - "gtceu:gravel_basaltic_mineral_sand_ore" + "gtceu:gravel_basaltic_mineral_sand_ore", + "gtceu:gravel_fluorite_ore", + "gtceu:gravel_dolomite_ore" ], "page": "gtceu:generation/gravel", "position": [ - -100, + -200, 150 ], "pre_nodes": [ diff --git a/src/generated/resources/assets/gtceu/compass/nodes/generation/netherrack.json b/src/generated/resources/assets/gtceu/compass/nodes/generation/netherrack.json index 81388da360..6a2f612856 100644 --- a/src/generated/resources/assets/gtceu/compass/nodes/generation/netherrack.json +++ b/src/generated/resources/assets/gtceu/compass/nodes/generation/netherrack.json @@ -113,12 +113,14 @@ "gtceu:netherrack_diatomite_ore", "gtceu:netherrack_granitic_mineral_sand_ore", "gtceu:netherrack_garnet_sand_ore", - "gtceu:netherrack_basaltic_mineral_sand_ore" + "gtceu:netherrack_basaltic_mineral_sand_ore", + "gtceu:netherrack_fluorite_ore", + "gtceu:netherrack_dolomite_ore" ], "page": "gtceu:generation/netherrack", "position": [ -100, - 100 + 150 ], "pre_nodes": [ "gtceu:generation/ore" diff --git a/src/generated/resources/assets/gtceu/compass/nodes/generation/red_sand.json b/src/generated/resources/assets/gtceu/compass/nodes/generation/red_sand.json index d4b938e780..3a2344060a 100644 --- a/src/generated/resources/assets/gtceu/compass/nodes/generation/red_sand.json +++ b/src/generated/resources/assets/gtceu/compass/nodes/generation/red_sand.json @@ -113,12 +113,14 @@ "gtceu:red_sand_diatomite_ore", "gtceu:red_sand_granitic_mineral_sand_ore", "gtceu:red_sand_garnet_sand_ore", - "gtceu:red_sand_basaltic_mineral_sand_ore" + "gtceu:red_sand_basaltic_mineral_sand_ore", + "gtceu:red_sand_fluorite_ore", + "gtceu:red_sand_dolomite_ore" ], "page": "gtceu:generation/red_sand", "position": [ - -100, - 50 + -50, + 100 ], "pre_nodes": [ "gtceu:generation/ore" diff --git a/src/generated/resources/assets/gtceu/compass/nodes/generation/sand.json b/src/generated/resources/assets/gtceu/compass/nodes/generation/sand.json index f15d2c299f..02247fc3b6 100644 --- a/src/generated/resources/assets/gtceu/compass/nodes/generation/sand.json +++ b/src/generated/resources/assets/gtceu/compass/nodes/generation/sand.json @@ -113,12 +113,14 @@ "gtceu:sand_diatomite_ore", "gtceu:sand_granitic_mineral_sand_ore", "gtceu:sand_garnet_sand_ore", - "gtceu:sand_basaltic_mineral_sand_ore" + "gtceu:sand_basaltic_mineral_sand_ore", + "gtceu:sand_fluorite_ore", + "gtceu:sand_dolomite_ore" ], "page": "gtceu:generation/sand", "position": [ - -150, - 50 + -100, + 100 ], "pre_nodes": [ "gtceu:generation/ore" diff --git a/src/generated/resources/assets/gtceu/compass/nodes/generation/stone.json b/src/generated/resources/assets/gtceu/compass/nodes/generation/stone.json index 5f7d9ecfe3..ef22267743 100644 --- a/src/generated/resources/assets/gtceu/compass/nodes/generation/stone.json +++ b/src/generated/resources/assets/gtceu/compass/nodes/generation/stone.json @@ -113,12 +113,14 @@ "gtceu:diatomite_ore", "gtceu:granitic_mineral_sand_ore", "gtceu:garnet_sand_ore", - "gtceu:basaltic_mineral_sand_ore" + "gtceu:basaltic_mineral_sand_ore", + "gtceu:fluorite_ore", + "gtceu:dolomite_ore" ], "page": "gtceu:generation/stone", "position": [ - -50, - 100 + -200, + 50 ], "pre_nodes": [ "gtceu:generation/ore" diff --git a/src/generated/resources/assets/gtceu/compass/nodes/generation/tuff.json b/src/generated/resources/assets/gtceu/compass/nodes/generation/tuff.json index da0dc4acaf..fe7888cc36 100644 --- a/src/generated/resources/assets/gtceu/compass/nodes/generation/tuff.json +++ b/src/generated/resources/assets/gtceu/compass/nodes/generation/tuff.json @@ -113,12 +113,14 @@ "gtceu:tuff_diatomite_ore", "gtceu:tuff_granitic_mineral_sand_ore", "gtceu:tuff_garnet_sand_ore", - "gtceu:tuff_basaltic_mineral_sand_ore" + "gtceu:tuff_basaltic_mineral_sand_ore", + "gtceu:tuff_fluorite_ore", + "gtceu:tuff_dolomite_ore" ], "page": "gtceu:generation/tuff", "position": [ - -50, - 150 + -150, + 100 ], "pre_nodes": [ "gtceu:generation/ore" diff --git a/src/generated/resources/assets/gtceu/lang/en_ud.json b/src/generated/resources/assets/gtceu/lang/en_ud.json index 22ab4ef53d..c4b16df315 100644 --- a/src/generated/resources/assets/gtceu/lang/en_ud.json +++ b/src/generated/resources/assets/gtceu/lang/en_ud.json @@ -1843,8 +1843,8 @@ "config.gtceu.option.addLoot": "ʇooꞀppɐ", "config.gtceu.option.allUniqueStoneTypes": "sǝdʎ⟘ǝuoʇSǝnbıu∩ןןɐ", "config.gtceu.option.animationTime": "ǝɯı⟘uoıʇɐɯıuɐ", + "config.gtceu.option.bedrockOreDistance": "ǝɔuɐʇsıᗡǝɹOʞɔoɹpǝq", "config.gtceu.option.bedrockOreDropTagPrefix": "xıɟǝɹԀbɐ⟘doɹᗡǝɹOʞɔoɹpǝq", - "config.gtceu.option.bedrockOreMultiplier": "ɹǝıןdıʇןnWǝɹOʞɔoɹpǝq", "config.gtceu.option.casingsPerCraft": "ʇɟɐɹƆɹǝԀsbuısɐɔ", "config.gtceu.option.cleanMultiblocks": "sʞɔoןqıʇןnWuɐǝןɔ", "config.gtceu.option.client": "ʇuǝıןɔ", @@ -3177,6 +3177,9 @@ "gtceu.multiblock.network_switch.description": "˙uoıʇɐʇndɯoƆ ɹıǝɥʇ ssǝɔɔɐ oʇ ǝןqɐ ǝq oʇ ɥɔʇıʍS ʞɹoʍʇǝN ǝɥʇ ɹoɟ ʇuǝuodɯoƆ ǝbpıɹᗺ ɐ ǝʌɐɥ ʇsnɯ sⱯƆԀH ˙ɥɔʇɐH uoıʇdǝɔǝᴚ ɐʇɐᗡ uoıʇɐʇndɯoƆ ǝuo ʇdǝɔɔɐ ʎןuo uɐɔ uoıʇɐʇS ɥɔɹɐǝsǝᴚ ǝɥʇ sɐ 'uoıʇɐʇndɯoƆ ɹǝɥbıɥ ɥɔnɯ sǝɹınbǝɹ ɥɔıɥʍ ɐʇɐᗡ ɥɔɹɐǝsǝᴚ ɹoɟ ʎɹɐssǝɔǝu sı ʇI ˙sǝɥɔʇɐH uoıssıɯsuɐɹ⟘ ɹo uoıʇdǝɔǝᴚ ɐʇɐᗡ uoıʇɐʇndɯoƆ ɟo ɹǝqɯnu ʎuɐ ʇdǝɔɔɐ uɐɔ ʇI ˙suoıʇɐuıʇsǝp ʎuɐɯ oʇ sǝɔɹnos ʎuɐɯ ɯoɹɟ uoıʇɐʇndɯoƆ buıʇnqıɹʇsıp ɹoɟ pǝsn ǝɹnʇɔnɹʇs ʞɔoןqıʇןnɯ ɐ sı ɥɔʇıʍS ʞɹoʍʇǝN ǝɥ⟘", "gtceu.multiblock.not_enough_energy": "˙ʎbɹǝuǝ ǝɹoɯ spǝǝu ǝuıɥɔɐW :⅁NINᴚⱯM", "gtceu.multiblock.not_enough_energy_output": "¡ʍoꞀ oo⟘ ɹǝı⟘ oɯɐuʎᗡ ʎbɹǝuƎ :⅁NINᴚⱯM", + "gtceu.multiblock.ore_rig.drilled_ore_entry": "%s - ", + "gtceu.multiblock.ore_rig.drilled_ores_list": ":sǝɹO", + "gtceu.multiblock.ore_rig.ore_amount": "%s :ǝʇɐᴚ buıןןıɹᗡ", "gtceu.multiblock.page_switcher.io.both": "sʇndʇnO + sʇnduI pǝuıqɯoƆϛ§", "gtceu.multiblock.page_switcher.io.export": "sʇndʇnOㄣ§", "gtceu.multiblock.page_switcher.io.import": "sʇnduIᄅ§", diff --git a/src/generated/resources/assets/gtceu/lang/en_us.json b/src/generated/resources/assets/gtceu/lang/en_us.json index 39f02967d3..698c7495c9 100644 --- a/src/generated/resources/assets/gtceu/lang/en_us.json +++ b/src/generated/resources/assets/gtceu/lang/en_us.json @@ -1843,8 +1843,8 @@ "config.gtceu.option.addLoot": "addLoot", "config.gtceu.option.allUniqueStoneTypes": "allUniqueStoneTypes", "config.gtceu.option.animationTime": "animationTime", + "config.gtceu.option.bedrockOreDistance": "bedrockOreDistance", "config.gtceu.option.bedrockOreDropTagPrefix": "bedrockOreDropTagPrefix", - "config.gtceu.option.bedrockOreMultiplier": "bedrockOreMultiplier", "config.gtceu.option.casingsPerCraft": "casingsPerCraft", "config.gtceu.option.cleanMultiblocks": "cleanMultiblocks", "config.gtceu.option.client": "client", @@ -3177,6 +3177,9 @@ "gtceu.multiblock.network_switch.description": "The Network Switch is a multiblock structure used for distributing Computation from many sources to many destinations. It can accept any number of Computation Data Reception or Transmission Hatches. It is necessary for Research Data which requires much higher Computation, as the Research Station can only accept one Computation Data Reception Hatch. HPCAs must have a Bridge Component for the Network Switch to be able to access their Computation.", "gtceu.multiblock.not_enough_energy": "WARNING: Machine needs more energy.", "gtceu.multiblock.not_enough_energy_output": "WARNING: Energy Dynamo Tier Too Low!", + "gtceu.multiblock.ore_rig.drilled_ore_entry": " - %s", + "gtceu.multiblock.ore_rig.drilled_ores_list": "Ores:", + "gtceu.multiblock.ore_rig.ore_amount": "Drilling Rate: %s", "gtceu.multiblock.page_switcher.io.both": "§5Combined Inputs + Outputs", "gtceu.multiblock.page_switcher.io.export": "§4Outputs", "gtceu.multiblock.page_switcher.io.import": "§2Inputs", diff --git a/src/main/java/com/gregtechceu/gtceu/api/addon/IGTAddon.java b/src/main/java/com/gregtechceu/gtceu/api/addon/IGTAddon.java index 74567eff0a..a05b4be13e 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/addon/IGTAddon.java +++ b/src/main/java/com/gregtechceu/gtceu/api/addon/IGTAddon.java @@ -124,6 +124,13 @@ default void registerFluidVeins() { } + /** + * Use {@link com.gregtechceu.gtceu.api.data.worldgen.bedrockore.BedrockOreDefinition#builder(ResourceLocation)} to register the veins. + */ + default void registerBedrockOreVeins() { + + } + /** * Register Material -> Casing block mappings here */ diff --git a/src/main/java/com/gregtechceu/gtceu/api/capability/recipe/ItemRecipeCapability.java b/src/main/java/com/gregtechceu/gtceu/api/capability/recipe/ItemRecipeCapability.java index 1c1fa30abc..1d8d55137f 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/capability/recipe/ItemRecipeCapability.java +++ b/src/main/java/com/gregtechceu/gtceu/api/capability/recipe/ItemRecipeCapability.java @@ -275,7 +275,7 @@ public void applyWidgetInfo(@NotNull Widget widget, slot.setHandlerSlot(items, index); slot.setIngredientIO(io == IO.IN ? IngredientIO.INPUT : IngredientIO.OUTPUT); slot.setCanTakeItems(!isXEI); - slot.setCanPutItems(false); + slot.setCanPutItems(!isXEI && io.support(IO.IN)); } // 1 over container size. // If in a recipe viewer and a research slot can be added, add it. diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/WorldGeneratorUtils.java b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/WorldGeneratorUtils.java index def81cce12..0d8d10c04f 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/WorldGeneratorUtils.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/WorldGeneratorUtils.java @@ -82,7 +82,7 @@ public static Optional getWorldGenLayerKey(IWorldGenLayer layer) { } public static boolean isSameDimension(ResourceKey first, ResourceKey second) { - return first.location().equals(second.location()); + return first == second; } public static Map> groupByChunks(Map input) { diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/bedrockfluid/BedrockFluidVeinSavedData.java b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/bedrockfluid/BedrockFluidVeinSavedData.java index 7d83354b5c..b050271128 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/bedrockfluid/BedrockFluidVeinSavedData.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/bedrockfluid/BedrockFluidVeinSavedData.java @@ -78,7 +78,8 @@ public CompoundTag save(CompoundTag nbt) { * @return The FluidVeinWorldInfo corresponding with the given chunk */ public FluidVeinWorldEntry getFluidVeinWorldEntry(int chunkX, int chunkZ) { - if (!veinFluids.containsKey(new ChunkPos(chunkX, chunkZ))) { + ChunkPos pos = new ChunkPos(chunkX, chunkZ); + if (!veinFluids.containsKey(pos)) { BedrockFluidDefinition definition = null; int query = RandomSource.create(Objects.hash(serverLevel.getSeed(), chunkX / VEIN_CHUNK_SIZE, chunkZ / VEIN_CHUNK_SIZE)).nextInt(); var biome = serverLevel.getBiome(new BlockPos(chunkX << 4, 64, chunkZ << 4)); @@ -108,10 +109,10 @@ public FluidVeinWorldEntry getFluidVeinWorldEntry(int chunkX, int chunkZ) { } maximumYield = Math.min(maximumYield, definition.getMaximumYield()); } - veinFluids.put(new ChunkPos(chunkX, chunkZ), new FluidVeinWorldEntry(definition, maximumYield, MAXIMUM_VEIN_OPERATIONS)); + veinFluids.put(pos, new FluidVeinWorldEntry(definition, maximumYield, MAXIMUM_VEIN_OPERATIONS)); setDirty(); } - return veinFluids.get(new ChunkPos(chunkX, chunkZ)); + return veinFluids.get(pos); } /** diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/bedrockore/BedrockOreDefinition.java b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/bedrockore/BedrockOreDefinition.java new file mode 100644 index 0000000000..1e92331d7e --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/bedrockore/BedrockOreDefinition.java @@ -0,0 +1,187 @@ +package com.gregtechceu.gtceu.api.data.worldgen.bedrockore; + +import com.gregtechceu.gtceu.api.GTCEuAPI; +import com.gregtechceu.gtceu.api.data.chemical.material.Material; +import com.gregtechceu.gtceu.api.data.worldgen.BiomeWeightModifier; +import com.gregtechceu.gtceu.api.registry.GTRegistries; +import com.gregtechceu.gtceu.common.data.GTOres; +import com.mojang.datafixers.util.Pair; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; +import net.minecraft.core.Holder; +import net.minecraft.core.HolderSet; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import net.minecraft.util.ExtraCodecs; +import net.minecraft.util.valueproviders.IntProvider; +import net.minecraft.util.valueproviders.UniformInt; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.biome.Biome; + +import java.util.*; + +@Accessors(fluent = true, chain = true) +public class BedrockOreDefinition { + public static final MapCodec> MATERIAL = Codec.mapPair(GTCEuAPI.materialManager.codec().fieldOf("material"), Codec.INT.fieldOf("chance")); + + public static final Codec FULL_CODEC = RecordCodecBuilder.create( + instance -> instance.group( + Codec.INT.fieldOf("weight").forGetter(ft -> ft.weight), + Codec.INT.fieldOf("size").forGetter(ft -> ft.size), + IntProvider.POSITIVE_CODEC.fieldOf("yield").forGetter(ft -> ft.yield), + Codec.INT.fieldOf("depletion_amount").forGetter(ft -> ft.depletionAmount), + ExtraCodecs.intRange(0, 100).fieldOf("depletion_chance").forGetter(ft -> ft.depletionChance), + Codec.INT.fieldOf("depleted_yield").forGetter(ft -> ft.depletedYield), + MATERIAL.codec().listOf().fieldOf("materials").forGetter(ft -> ft.materials), + BiomeWeightModifier.CODEC.listOf().optionalFieldOf("weight_modifier", List.of()).forGetter(ft -> ft.originalModifiers), + ResourceKey.codec(Registries.DIMENSION).listOf().fieldOf("dimension_filter").forGetter(ft -> new ArrayList<>(ft.dimensionFilter)) + ).apply(instance, (weight, size, yield, depletionAmount, depletionChance, depletedYield, materials, biomeWeightModifier, dimensionFilter) -> new BedrockOreDefinition(weight, size, yield, depletionAmount, depletionChance, depletedYield, materials, biomeWeightModifier, new HashSet<>(dimensionFilter))) + ); + + @Getter @Setter + private int weight; // weight value for determining which vein will appear + @Getter @Setter + private int size; // size in chunks + @Getter @Setter + private IntProvider yield;// the [minimum, maximum] yields + @Getter @Setter + private int depletionAmount; // amount of ore the vein gets drained by + @Getter @Setter + private int depletionChance; // the chance [0, 100] that the vein will deplete by 1 + @Getter @Setter + private int depletedYield; // yield after the vein is depleted + @Getter @Setter + private List> materials; // the ores which the vein contains + @Getter + private BiomeWeightModifier biomeWeightModifier; // weighting of biomes + private List originalModifiers; // weighting of biomes + @Getter @Setter + public Set> dimensionFilter; // filtering of dimensions + + public BedrockOreDefinition(ResourceLocation name, int size, int weight, IntProvider yield, int depletionAmount, int depletionChance, int depletedYield, List> materials, List originalModifiers, Set> dimensionFilter) { + this(weight, size, yield, depletionAmount, depletionChance, depletedYield, materials, originalModifiers, dimensionFilter); + GTRegistries.BEDROCK_ORE_DEFINITIONS.register(name, this); + } + + public BedrockOreDefinition(int weight, int size, IntProvider yield, int depletionAmount, int depletionChance, int depletedYield, List> materials, List originalModifiers, Set> dimensionFilter) { + this.weight = weight; + this.size = size; + this.yield = yield; + this.depletionAmount = depletionAmount; + this.depletionChance = depletionChance; + this.depletedYield = depletedYield; + this.materials = materials; + this.originalModifiers = originalModifiers; + this.biomeWeightModifier = new BiomeWeightModifier(() -> HolderSet.direct(originalModifiers.stream().flatMap(mod -> mod.biomes.get().stream()).toList()), originalModifiers.stream().mapToInt(mod -> mod.addedWeight).sum()) { + @Override + public Integer apply(Holder biome) { + int mod = 0; + for (var modifier : originalModifiers) { + if (modifier.biomes.get().contains(biome)) { + mod += modifier.apply(biome); + } + } + return mod; + } + }; + this.dimensionFilter = dimensionFilter; + } + + public void setOriginalModifiers(List modifiers) { + this.originalModifiers = modifiers; + this.biomeWeightModifier = new BiomeWeightModifier(() -> HolderSet.direct(originalModifiers.stream().flatMap(mod -> mod.biomes.get().stream()).toList()), originalModifiers.stream().mapToInt(mod -> mod.addedWeight).sum()) { + @Override + public Integer apply(Holder biome) { + int mod = 0; + for (var modifier : originalModifiers) { + if (modifier.biomes.get().contains(biome)) { + mod += modifier.apply(biome); + } + } + return mod; + } + }; + } + + public static Builder builder(ResourceLocation name) { + return new Builder(name); + } + + @Accessors(chain = true, fluent = true) + public static class Builder { + private final ResourceLocation name; + @Setter + private int weight; // weight value for determining which vein will appear + @Setter + private int size; // size of the vein, in chunks. + @Setter + private IntProvider yield;// the [minimum, maximum) yields + @Setter + private int depletionAmount; // amount of fluid the vein gets drained by + @Setter + private int depletionChance = 1; // the chance [0, 100] that the vein will deplete by 1 + @Setter + private int depletedYield; // yield after the vein is depleted + @Setter + private List> materials; // the ores which the vein contains + @Setter + private Set> dimensions; + private final List biomes = new LinkedList<>(); + + private Builder(ResourceLocation name) { + this.name = name; + } + + public Builder copy(ResourceLocation name) { + var copied = new Builder(name); + copied.weight = weight; + copied.yield = yield; + copied.depletionAmount = depletionAmount; + copied.depletionChance = depletionChance; + copied.depletedYield = depletedYield; + copied.materials = materials; + return copied; + } + + public Builder material(Material material, int amount) { + if (this.materials == null) this.materials = new ArrayList<>(); + this.materials.add(Pair.of(material, amount)); + return this; + } + + public Builder yield(int min, int max) { + return this.yield(UniformInt.of(min, max)); + } + + public Builder biomes(int weight, TagKey biomes) { + this.biomes.add(new BiomeWeightModifier(() -> GTRegistries.builtinRegistry() + .registryOrThrow(Registries.BIOME).getOrCreateTag(biomes), weight)); + return this; + } + + @SafeVarargs + public final Builder biomes(int weight, ResourceKey... biomes) { + this.biomes.add(new BiomeWeightModifier(() -> HolderSet.direct(GTRegistries.builtinRegistry() + .registryOrThrow(Registries.BIOME)::getHolderOrThrow, biomes), weight)); + return this; + } + + public Builder biomes(int weight, HolderSet biomes) { + this.biomes.add(new BiomeWeightModifier(() -> biomes, weight)); + return this; + } + + public BedrockOreDefinition register() { + var definition = new BedrockOreDefinition(weight, size, yield, depletionAmount, depletionChance, depletedYield, materials, biomes, dimensions); + GTOres.toReRegisterBedrock.put(name, definition); + return definition; + } + } + +} diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/bedrockore/BedrockOreVeinSavedData.java b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/bedrockore/BedrockOreVeinSavedData.java index ea330fefd9..8ce3af83ca 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/bedrockore/BedrockOreVeinSavedData.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/bedrockore/BedrockOreVeinSavedData.java @@ -2,7 +2,6 @@ import com.gregtechceu.gtceu.api.GTValues; import com.gregtechceu.gtceu.api.data.chemical.material.Material; -import com.gregtechceu.gtceu.api.data.worldgen.GTOreDefinition; import com.gregtechceu.gtceu.api.data.worldgen.WorldGeneratorUtils; import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.config.ConfigHolder; @@ -25,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.stream.Collectors; /** * @author KilaBash @@ -85,15 +85,22 @@ public CompoundTag save(CompoundTag nbt) { public OreVeinWorldEntry getOreVeinWorldEntry(int chunkX, int chunkZ) { ChunkPos pos = new ChunkPos(chunkX, chunkZ); if (!veinOres.containsKey(pos)) { - GTOreDefinition definition = null; + int minDistance = ConfigHolder.INSTANCE.worldgen.oreVeins.bedrockOreDistance; + if (chunkX % minDistance != 0 || chunkZ % minDistance != 0) { + OreVeinWorldEntry entry = new OreVeinWorldEntry(null, 0, MAXIMUM_VEIN_OPERATIONS); + veinOres.put(pos, entry); + return entry; + } + + BedrockOreDefinition definition = null; int query = RandomSource.create(Objects.hash(serverLevel.getSeed(), chunkX / VEIN_CHUNK_SIZE, chunkZ / VEIN_CHUNK_SIZE)).nextInt(); var biome = serverLevel.getBiome(new BlockPos(chunkX << 4, 64, chunkZ << 4)); int totalWeight = getTotalWeight(biome); if (totalWeight > 0) { int weight = Math.abs(query % totalWeight); - for (var oreDefinition : GTRegistries.ORE_VEINS) { + for (var oreDefinition : GTRegistries.BEDROCK_ORE_DEFINITIONS) { int veinWeight = oreDefinition.weight() + (oreDefinition.biomeWeightModifier() != null ? oreDefinition.biomeWeightModifier().apply(biome) : 0); - if (veinWeight > 0 && oreDefinition.dimensionFilter().stream().anyMatch(dim -> WorldGeneratorUtils.isSameDimension(dim, serverLevel.dimension()))) { + if (veinWeight > 0 && (oreDefinition.dimensionFilter == null || oreDefinition.dimensionFilter().stream().anyMatch(dim -> WorldGeneratorUtils.isSameDimension(dim, serverLevel.dimension())))) { weight -= veinWeight; if (weight < 0) { definition = oreDefinition; @@ -103,48 +110,34 @@ public OreVeinWorldEntry getOreVeinWorldEntry(int chunkX, int chunkZ) { } } - var random = RandomSource.create(31L * 31 * chunkX + chunkZ * 31L + Long.hashCode(serverLevel.getSeed())); - - int maximumYield = 0; - if (definition != null) { - if (definition.maximumYield() - definition.minimumYield() <= 0) { - maximumYield = definition.minimumYield(); - } else { - maximumYield = random.nextInt(definition.maximumYield() - definition.minimumYield()) + definition.minimumYield(); - } - maximumYield = Math.round(Math.min(maximumYield, definition.maximumYield()) * ConfigHolder.INSTANCE.worldgen.oreVeins.bedrockOreMultiplier); - } - veinOres.put(new ChunkPos(chunkX, chunkZ), new OreVeinWorldEntry(definition, maximumYield, MAXIMUM_VEIN_OPERATIONS)); + createVein(pos, definition); setDirty(); } return veinOres.get(pos); } - public void createVein(ChunkPos pos, GTOreDefinition definition) { + public void createVein(ChunkPos pos, @Nullable BedrockOreDefinition definition) { if (definition != null) { - int radius = SectionPos.blockToSectionCoord(definition.clusterSize() / 2f); + int radius = definition.size() / 2; for (int x = pos.x - radius; x <= pos.x + radius; ++x) { for (int z = pos.z - radius; z <= pos.z + radius; ++z) { ChunkPos pos2 = new ChunkPos(x, z); - if (!veinOres.containsKey(pos2)) { - float distanceFromOriginal = Math.abs(pos.x - x) + Math.abs(pos.z - z); - distanceFromOriginal = distanceFromOriginal == 0 ? 1 : distanceFromOriginal; - distanceFromOriginal = (float) Math.pow(distanceFromOriginal, 2); - - var random = RandomSource.create(31L * 31 * pos2.x + pos2.z * 31L + Long.hashCode(serverLevel.getSeed())); - - int maximumYield = 0; - if ((definition.maximumYield() - definition.minimumYield()) / distanceFromOriginal <= 0) { - maximumYield = definition.minimumYield(); - } else { - maximumYield = (int) (random.nextInt((definition.maximumYield() - definition.minimumYield()) + definition.minimumYield()) / distanceFromOriginal); - maximumYield = Math.max(maximumYield, definition.minimumYield()); - } - maximumYield = Math.min(maximumYield, definition.maximumYield()); - - veinOres.put(pos2, new OreVeinWorldEntry(definition, maximumYield, MAXIMUM_VEIN_OPERATIONS)); + float distanceFromOriginal = Math.abs(pos.x - x) + Math.abs(pos.z - z); + distanceFromOriginal = distanceFromOriginal == 0 ? 1 : distanceFromOriginal; + distanceFromOriginal = (float) Math.pow(distanceFromOriginal, 2); + + var random = RandomSource.create(31L * 31 * pos2.x + pos2.z * 31L + Long.hashCode(serverLevel.getSeed())); + + int maximumYield; + if ((definition.yield().getMaxValue() - definition.yield().getMinValue()) / distanceFromOriginal <= 0) { + maximumYield = definition.yield().getMinValue(); + } else { + maximumYield = (int) ((definition.yield().sample(random) + definition.yield().getMinValue()) / distanceFromOriginal); + maximumYield = Math.max(maximumYield, definition.yield().getMinValue()); } + maximumYield = Math.min(maximumYield, definition.yield().getMaxValue()); + veinOres.put(pos2, new OreVeinWorldEntry(definition, maximumYield, MAXIMUM_VEIN_OPERATIONS)); } } } @@ -159,8 +152,8 @@ public void createVein(ChunkPos pos, GTOreDefinition definition) { public int getTotalWeight(Holder biome) { return biomeWeights.computeIfAbsent(biome, b -> { int totalWeight = 0; - for (var definition : GTRegistries.ORE_VEINS) { - if (definition.dimensionFilter().stream().anyMatch(dim -> WorldGeneratorUtils.isSameDimension(dim, serverLevel.dimension()))) { + for (var definition : GTRegistries.BEDROCK_ORE_DEFINITIONS) { + if (definition.dimensionFilter == null || definition.dimensionFilter().stream().anyMatch(dim -> WorldGeneratorUtils.isSameDimension(dim, serverLevel.dimension()))) { totalWeight += definition.biomeWeightModifier() != null ? definition.biomeWeightModifier().apply(biome) : 0; totalWeight += definition.weight(); } @@ -215,7 +208,7 @@ public int getOperationsRemaining(int chunkX, int chunkZ) { public List> getOreInChunk(int chunkX, int chunkZ) { OreVeinWorldEntry info = getOreVeinWorldEntry(chunkX, chunkZ); if (info.getDefinition() == null) return null; - return info.getDefinition().getBedrockVeinMaterials(); + return info.getDefinition().materials().stream().map(pair -> Map.entry(pair.getSecond(), pair.getFirst())).collect(Collectors.toList()); } /** @@ -237,7 +230,7 @@ public void depleteVein(int chunkX, int chunkZ, int amount, boolean ignoreVeinSt return; } - GTOreDefinition definition = info.getDefinition(); + BedrockOreDefinition definition = info.getDefinition(); // prevent division by zero, veins that never deplete don't need updating if (definition == null || definition.depletionChance() == 0) diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/bedrockore/OreVeinWorldEntry.java b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/bedrockore/OreVeinWorldEntry.java index e62ff836f4..c1b3a74371 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/bedrockore/OreVeinWorldEntry.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/bedrockore/OreVeinWorldEntry.java @@ -1,6 +1,5 @@ package com.gregtechceu.gtceu.api.data.worldgen.bedrockore; -import com.gregtechceu.gtceu.api.data.worldgen.GTOreDefinition; import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.config.ConfigHolder; import lombok.Getter; @@ -11,21 +10,21 @@ import org.jetbrains.annotations.Nullable; /** - * @author KilaBash - * @date 2023/7/11 - * @implNote FluidVeinWorldEntry + * @author Screret + * @date 2023/12/20 + * @implNote OreVeinWorldEntry */ public class OreVeinWorldEntry { @Nullable @Getter - private GTOreDefinition vein; + private BedrockOreDefinition definition; @Getter private int oreYield; @Getter private int operationsRemaining; - public OreVeinWorldEntry(@Nullable GTOreDefinition vein, int oreYield, int operationsRemaining) { - this.vein = vein; + public OreVeinWorldEntry(@Nullable BedrockOreDefinition vein, int oreYield, int operationsRemaining) { + this.definition = vein; this.oreYield = oreYield; this.operationsRemaining = operationsRemaining; } @@ -34,10 +33,6 @@ private OreVeinWorldEntry() { } - public GTOreDefinition getDefinition() { - return this.vein; - } - @SuppressWarnings("unused") public void setOperationsRemaining(int amount) { this.operationsRemaining = amount; @@ -51,8 +46,8 @@ public CompoundTag writeToNBT() { var tag = new CompoundTag(); tag.putInt("oreYield", oreYield); tag.putInt("operationsRemaining", operationsRemaining); - if (vein != null) { - tag.putString("vein", GTRegistries.ORE_VEINS.getKey(vein).toString()); + if (definition != null) { + tag.putString("vein", GTRegistries.BEDROCK_ORE_DEFINITIONS.getKey(definition).toString()); } return tag; } @@ -64,7 +59,7 @@ public static OreVeinWorldEntry readFromNBT(@NotNull CompoundTag tag) { info.operationsRemaining = tag.getInt("operationsRemaining"); if (tag.contains("vein")) { - info.vein = GTRegistries.ORE_VEINS.get(new ResourceLocation(tag.getString("vein"))); + info.definition = GTRegistries.BEDROCK_ORE_DEFINITIONS.get(new ResourceLocation(tag.getString("vein"))); } return info; } 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 109472fe5c..b6be9dd315 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 @@ -37,7 +37,6 @@ import net.minecraft.world.level.levelgen.blending.Blender; import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration; import net.minecraft.world.level.levelgen.structure.templatesystem.AlwaysTrueTest; -import org.jetbrains.annotations.Nullable; import javax.annotation.ParametersAreNonnullByDefault; import java.util.ArrayList; @@ -68,8 +67,8 @@ public class VeinedVeinGenerator extends VeinGenerator { Codec.FLOAT.fieldOf("rare_block_chance").orElse(0.02f).forGetter(it -> it.rareBlockChance)//, ).apply(instance, VeinedVeinGenerator::new)); - public List oreBlocks; - public List rareBlocks; + public List oreBlocks = new ArrayList<>(); + public List rareBlocks = new ArrayList<>(); @Setter public BlockState fillerBlock; @Setter @@ -103,14 +102,14 @@ public List, Integer>> getAllEntries() { material -> Stream.of(Map.entry(Either.right(material), definition.weight)) ) ); - var s2 = this.rareBlocks == null ? null : this.rareBlocks.stream().flatMap(definition -> + var s2 = this.rareBlocks.stream().flatMap(definition -> definition.block.map( state -> state.stream().map(target -> Map.entry(Either.left(target.state), definition.weight)), material -> Stream.of(Map.entry(Either.right(material), definition.weight)) ) ); - return (s2 == null ? s1 : Stream.concat(s1, s2)).collect(Collectors.toList()); + return Stream.concat(s1, s2).collect(Collectors.toList()); } @Override @@ -120,7 +119,7 @@ public Map generate(WorldGenLevel level, RandomSource Registry densityFunctions = GTRegistries.builtinRegistry().registry(Registries.DENSITY_FUNCTION).get(); List> commonEntries = oreBlocks.stream().map(b -> Map.entry(b.weight, b)).toList(); - List> rareEntries = rareBlocks == null ? null : rareBlocks.stream().map(b -> Map.entry(b.weight, b)).toList(); // never accessed if rareBlocks is null + List> rareEntries = rareBlocks.stream().map(b -> Map.entry(b.weight, b)).toList(); // never accessed if rareBlocks is null RandomState randomState = level.getLevel().getChunkSource().randomState(); Blender blender; @@ -206,7 +205,6 @@ public Blender getBlender() { return generatedBlocks; } - @Nullable private void placeBlock(BulkSectionAccess access, LevelChunkSection section, long randomSeed, GTOreDefinition entry, double chance, List> rareEntries, BlockPos.MutableBlockPos pos, List> commonEntries) { RandomSource random = new XoroshiroRandomSource(randomSeed); int sectionX = SectionPos.sectionRelative(pos.getX()); @@ -283,7 +281,6 @@ public VeinedVeinGenerator oreBlock(BlockState blockState, int weight) { } public VeinedVeinGenerator oreBlock(VeinBlockDefinition material) { - if (this.oreBlocks == null) this.oreBlocks = new ArrayList<>(); this.oreBlocks.add(material); return this; } @@ -298,7 +295,6 @@ public VeinedVeinGenerator rareBlock(BlockState blockState, int weight) { } public VeinedVeinGenerator rareBlock(VeinBlockDefinition material) { - if (this.rareBlocks == null) this.rareBlocks = new ArrayList<>(); this.rareBlocks.add(material); return this; } diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/ores/OreGenerator.java b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/ores/OreGenerator.java index b420641cb3..05984f17a7 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/ores/OreGenerator.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/ores/OreGenerator.java @@ -100,19 +100,8 @@ private Optional generateOres(VeinConfiguration config, WorldGenL return Optional.empty(); } - generateBedrockOreVein(config, level); return Optional.of(new GeneratedVein(chunkPos, definition.layer(), generatedVeins)); } - - private static void generateBedrockOreVein(VeinConfiguration config, WorldGenLevel level) { - if (ConfigHolder.INSTANCE.machines.doBedrockOres) { - BedrockOreVeinSavedData.getOrCreate(level.getLevel()).createVein( - new ChunkPos(config.data.center()), - config.data.definition() - ); - } - } - private List createConfigs(WorldGenLevel level, ChunkGenerator generator, ChunkPos chunkPos) { var random = new XoroshiroRandomSource(level.getSeed() ^ chunkPos.toLong()); diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/ores/OreVeinUtil.java b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/ores/OreVeinUtil.java index f84c83507c..1990263f57 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/ores/OreVeinUtil.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/ores/OreVeinUtil.java @@ -119,8 +119,7 @@ public static Supplier> resolveBiomes(List biomes) { RegistryOps registryOps = RegistryOps.create(JsonOps.INSTANCE, GTRegistries.builtinRegistry()); JsonElement codecInput = resolveBiomeCodecInput(biomes); return () -> RegistryCodecs.homogeneousList(Registries.BIOME) - .decode(registryOps, codecInput) - .map(Pair::getFirst) + .parse(registryOps, codecInput) .getOrThrow(false, GTCEu.LOGGER::error); } diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/misc/ProspectorMode.java b/src/main/java/com/gregtechceu/gtceu/api/gui/misc/ProspectorMode.java index 87cabef36c..39bf1cde3c 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/misc/ProspectorMode.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/misc/ProspectorMode.java @@ -22,7 +22,6 @@ import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.core.BlockPos; -import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; @@ -244,8 +243,8 @@ public void scan(OreInfo[][][] storage, LevelChunk chunk) { var oreVein = BedrockOreVeinSavedData.getOrCreate(serverLevel).getOreVeinWorldEntry(chunk.getPos().x, chunk.getPos().z); if (oreVein.getDefinition() != null) { var left = 100 * oreVein.getOperationsRemaining() / BedrockOreVeinSavedData.MAXIMUM_VEIN_OPERATIONS; - for (var entry : oreVein.getDefinition().getBedrockVeinMaterials()) { - storage[0][0] = ArrayUtils.add(storage[0][0], new OreInfo(entry.getValue(), entry.getKey(), left, oreVein.getOreYield())); + for (var entry : oreVein.getDefinition().materials()) { + storage[0][0] = ArrayUtils.add(storage[0][0], new OreInfo(entry.getFirst(), entry.getSecond(), left, oreVein.getOreYield())); } } } @@ -263,7 +262,8 @@ public IGuiTexture getItemIcon(OreInfo item) { ItemStack stack = ChemicalHelper.get(TagPrefix.get(ConfigHolder.INSTANCE.machines.bedrockOreDropTagPrefix), material); if (stack.isEmpty()) stack = ChemicalHelper.get(TagPrefix.crushed, material); // backup 1: crushed; if raw ore doesn't exist if (stack.isEmpty()) stack = ChemicalHelper.get(TagPrefix.gem, material); // backup 2: gem; if crushed ore doesn't exist - if (stack.isEmpty()) stack = ChemicalHelper.get(TagPrefix.ore, material); // backup 3: just fallback to normal ore... + if (stack.isEmpty()) stack = ChemicalHelper.get(TagPrefix.ore, material); // backup 3: ore; if gem doesn't exist + if (stack.isEmpty()) stack = ChemicalHelper.get(TagPrefix.dust, material); // backup 4: just fallback to dust... return new ItemStackTexture(stack).scale(0.8f); } diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/RecipeLogic.java b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/RecipeLogic.java index e202bbc032..58a61d37b8 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/RecipeLogic.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/RecipeLogic.java @@ -18,6 +18,7 @@ import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; import lombok.Getter; +import lombok.Setter; import net.minecraft.Util; import net.minecraft.network.chat.Component; import net.minecraft.world.item.crafting.RecipeManager; @@ -60,7 +61,7 @@ public enum Status { @Nullable @Getter @Persisted protected GTRecipe lastOriginRecipe; @Persisted - @Getter + @Getter @Setter protected int progress; @Getter @Persisted protected int duration; 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 76e4505c39..83299a40f1 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/registry/GTRegistries.java +++ b/src/main/java/com/gregtechceu/gtceu/api/registry/GTRegistries.java @@ -9,6 +9,7 @@ import com.gregtechceu.gtceu.api.data.chemical.material.Material; import com.gregtechceu.gtceu.api.data.worldgen.GTOreDefinition; import com.gregtechceu.gtceu.api.data.worldgen.bedrockfluid.BedrockFluidDefinition; +import com.gregtechceu.gtceu.api.data.worldgen.bedrockore.BedrockOreDefinition; import com.gregtechceu.gtceu.api.machine.MachineDefinition; import com.gregtechceu.gtceu.api.recipe.GTRecipeType; import com.gregtechceu.gtceu.api.recipe.RecipeCondition; @@ -54,6 +55,7 @@ public final class GTRegistries { public static final GTRegistry.RL COMPASS_SECTIONS = new GTRegistry.RL<>(GTCEu.id("compass_section")); public static final GTRegistry.RL COMPASS_NODES = new GTRegistry.RL<>(GTCEu.id("compass_node")); public static final GTRegistry.RL BEDROCK_FLUID_DEFINITIONS = new GTRegistry.RL<>(GTCEu.id("bedrock_fluid")); + public static final GTRegistry.RL BEDROCK_ORE_DEFINITIONS = new GTRegistry.RL<>(GTCEu.id("bedrock_ore")); public static final GTRegistry.RL ORE_VEINS = new GTRegistry.RL<>(GTCEu.id("ore_vein")); public static final DeferredRegister> TRUNK_PLACER_TYPE = DeferredRegister.create(Registries.TRUNK_PLACER_TYPE, GTCEu.MOD_ID); 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 340beaec0e..d0583a7fcd 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTOres.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTOres.java @@ -4,6 +4,7 @@ import com.gregtechceu.gtceu.api.data.chemical.material.Material; import com.gregtechceu.gtceu.api.data.tag.TagPrefix; import com.gregtechceu.gtceu.api.data.worldgen.*; +import com.gregtechceu.gtceu.api.data.worldgen.bedrockore.BedrockOreDefinition; 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; @@ -50,6 +51,7 @@ public class GTOres { private static int largestIndicatorOffset = 0; private static final Map toReRegister = new HashMap<>(); + public static final Map toReRegisterBedrock = new HashMap<>(); static { VeinGenerators.registerAddonGenerators(); @@ -886,6 +888,7 @@ private static Supplier ore(TagPrefix oreTag, Material material public static void init() { toReRegister.forEach(GTRegistries.ORE_VEINS::registerOrOverride); + toReRegisterBedrock.forEach(GTRegistries.BEDROCK_ORE_DEFINITIONS::registerOrOverride); } public static void updateLargestVeinSize() { diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/BedrockOreMinerMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/BedrockOreMinerMachine.java index 0719dd121b..425bfcc523 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/BedrockOreMinerMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/BedrockOreMinerMachine.java @@ -2,6 +2,7 @@ import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.api.GTValues; +import com.gregtechceu.gtceu.api.data.chemical.material.Material; import com.gregtechceu.gtceu.api.data.tag.TagPrefix; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.feature.ITieredMachine; @@ -10,15 +11,19 @@ import com.gregtechceu.gtceu.common.data.GTBlocks; import com.gregtechceu.gtceu.common.data.GTMaterials; import com.gregtechceu.gtceu.common.machine.trait.BedrockOreMinerLogic; -import com.gregtechceu.gtceu.common.machine.trait.FluidDrillLogic; +import com.gregtechceu.gtceu.utils.FormattingUtil; import lombok.Getter; +import net.minecraft.ChatFormatting; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.HoverEvent; +import net.minecraft.network.chat.Style; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; import javax.annotation.ParametersAreNonnullByDefault; import java.util.List; +import java.util.Map; /** * @author Screret @@ -42,18 +47,47 @@ protected RecipeLogic createRecipeLogic(Object... args) { return new BedrockOreMinerLogic(this); } + @Override + public BedrockOreMinerLogic getRecipeLogic() { + return (BedrockOreMinerLogic) super.getRecipeLogic(); + } + public int getEnergyTier() { return Math.min(this.tier + 1 , Math.max(this.tier, getOverclockTier())); } @Override public void addDisplayText(List textList) { - super.addDisplayText(textList); if (isFormed()) { int energyContainer = getEnergyTier(); long maxVoltage = GTValues.V[energyContainer]; String voltageName = GTValues.VNF[energyContainer]; textList.add(Component.translatable("gtceu.multiblock.max_energy_per_tick", maxVoltage, voltageName)); + + if (getRecipeLogic().getVeinMaterials() != null) { + // Ore names + textList.add(Component.translatable("gtceu.multiblock.ore_rig.drilled_ores_list").withStyle(ChatFormatting.GREEN)); + List> drilledOres = getRecipeLogic().getVeinMaterials(); + for (var entry : drilledOres) { + Component fluidInfo = entry.getValue().getLocalizedName().withStyle(ChatFormatting.GREEN); + textList.add(Component.translatable("gtceu.multiblock.ore_rig.drilled_ore_entry", fluidInfo).withStyle(ChatFormatting.GRAY)); + } + + // Ore amount + Component amountInfo = Component.literal(FormattingUtil.formatNumbers( + getRecipeLogic().getOreToProduce() * 20L / BedrockOreMinerLogic.MAX_PROGRESS) + + "/s").withStyle(ChatFormatting.BLUE); + textList.add(Component.translatable("gtceu.multiblock.ore_rig.ore_amount", amountInfo).withStyle(ChatFormatting.GRAY)); + } else { + Component noOre = Component.translatable("gtceu.multiblock.fluid_rig.no_fluid_in_area").withStyle(ChatFormatting.RED); + textList.add(Component.translatable("gtceu.multiblock.ore_rig.drilled_ores_list").withStyle(ChatFormatting.GREEN)); + textList.add(Component.translatable("gtceu.multiblock.ore_rig.drilled_ore_entry", noOre).withStyle(ChatFormatting.GRAY)); + } + } else { + Component tooltip = Component.translatable("gtceu.multiblock.invalid_structure.tooltip").withStyle(ChatFormatting.GRAY); + textList.add(Component.translatable("gtceu.multiblock.invalid_structure") + .withStyle(Style.EMPTY.withColor(ChatFormatting.RED) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, tooltip)))); } } @@ -71,9 +105,9 @@ public static int getRigMultiplier(int tier) { if (tier == GTValues.MV) return 1; if (tier == GTValues.HV) - return 16; + return 4; if (tier == GTValues.EV) - return 64; + return 16; return 1; } diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/trait/BedrockOreMinerLogic.java b/src/main/java/com/gregtechceu/gtceu/common/machine/trait/BedrockOreMinerLogic.java index 4b5ff252f4..313bc18bd8 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/trait/BedrockOreMinerLogic.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/trait/BedrockOreMinerLogic.java @@ -71,12 +71,15 @@ public void findAndHandleRecipe() { @Nullable private GTRecipe getOreMinerRecipe() { if (getMachine().getLevel() instanceof ServerLevel serverLevel && veinMaterials != null) { - var data = BedrockOreVeinSavedData.getOrCreate(serverLevel); - Material material = veinMaterials.get(GTUtil.getRandomItem(veinMaterials, veinMaterials.size())).getValue(); - ItemStack stack = ChemicalHelper.get(TagPrefix.get(ConfigHolder.INSTANCE.machines.bedrockOreDropTagPrefix), material, getOreToProduce(data.getOreVeinWorldEntry(getChunkX(), getChunkZ()))); - if (stack.isEmpty()) stack = ChemicalHelper.get(TagPrefix.crushed, material, getOreToProduce(data.getOreVeinWorldEntry(getChunkX(), getChunkZ()))); // backup 1: crushed; if raw ore doesn't exist - if (stack.isEmpty()) stack = ChemicalHelper.get(TagPrefix.gem, material, getOreToProduce(data.getOreVeinWorldEntry(getChunkX(), getChunkZ()))); // backup 2: gem; if crushed ore doesn't exist - if (stack.isEmpty()) stack = ChemicalHelper.get(TagPrefix.ore, material, getOreToProduce(data.getOreVeinWorldEntry(getChunkX(), getChunkZ()))); // backup 3: just fallback to normal ore... + Material material = veinMaterials.get(GTUtil.getRandomItem(serverLevel.random, veinMaterials, veinMaterials.size())).getValue(); + ItemStack stack = ChemicalHelper.get(TagPrefix.get(ConfigHolder.INSTANCE.machines.bedrockOreDropTagPrefix), material, getOreToProduce()); + if (stack.isEmpty()) stack = ChemicalHelper.get(TagPrefix.crushed, material, getOreToProduce()); // backup 1: crushed; if raw ore doesn't exist + if (stack.isEmpty()) stack = ChemicalHelper.get(TagPrefix.gem, material, getOreToProduce()); // backup 2: gem; if crushed ore doesn't exist + if (stack.isEmpty()) stack = ChemicalHelper.get(TagPrefix.ore, material, getOreToProduce()); // backup 3: normal ore; if gem doesn't exist. + if (stack.isEmpty()) stack = ChemicalHelper.get(TagPrefix.dust, material, getOreToProduce()); // backup 4: fallback to dust + if (stack.isEmpty()) { + return null; + } var recipe = GTRecipeBuilder.ofRaw() .duration(MAX_PROGRESS) .EUt(GTValues.VA[getMachine().getEnergyTier()]) @@ -99,7 +102,7 @@ private int getOreToProduce(OreVeinWorldEntry entry) { int produced = Math.max(depletedYield, regularYield * remainingOperations / BedrockOreVeinSavedData.MAXIMUM_VEIN_OPERATIONS); produced *= BedrockOreMinerMachine.getRigMultiplier(getMachine().getTier()); - // Overclocks produce 50% more fluid + // Overclocks produce 50% more ore if (isOverclocked()) { produced = produced * 3 / 2; } @@ -108,6 +111,14 @@ private int getOreToProduce(OreVeinWorldEntry entry) { return 0; } + public int getOreToProduce() { + if (getMachine().getLevel() instanceof ServerLevel serverLevel && veinMaterials != null) { + var data = BedrockOreVeinSavedData.getOrCreate(serverLevel); + return getOreToProduce(data.getOreVeinWorldEntry(getChunkX(), getChunkZ())); + } + return 0; + } + @Override public void onRecipeFinish() { machine.afterWorking(); diff --git a/src/main/java/com/gregtechceu/gtceu/config/ConfigHolder.java b/src/main/java/com/gregtechceu/gtceu/config/ConfigHolder.java index 618155b0e2..dfb721c6a8 100644 --- a/src/main/java/com/gregtechceu/gtceu/config/ConfigHolder.java +++ b/src/main/java/com/gregtechceu/gtceu/config/ConfigHolder.java @@ -192,7 +192,6 @@ public static class OreVeinConfigs { "Default: 3" }) public int oreVeinGridSize = 3; - @Configurable @Configurable.Range(min = 0, max = 32 * 16) @Configurable.Comment({ @@ -200,23 +199,18 @@ public static class OreVeinConfigs { "Default: 12" }) public int oreVeinRandomOffset = 12; - @Configurable @Configurable.Comment({"Prevents regular vanilla ores from being generated outside GregTech ore veins", "Default: true"}) public boolean removeVanillaOreGen = true; - @Configurable @Configurable.Comment({"Prevents vanilla's large ore veins from being generated", "Default: true"}) public boolean removeVanillaLargeOreVeins = true; - - @Configurable - @Configurable.Comment({"Multiplier to bedrock ore generation amount", "Default: 1.0f"}) - public float bedrockOreMultiplier = 1.0f; + @Configurable.Comment({"Distance between bedrock ore veins in chunks, if enabled.", "Default: 16"}) + public int bedrockOreDistance = 16; @Configurable @Configurable.Comment({"Make bedrock ore/fluid veins infinite?", "Default: false"}) public boolean infiniteBedrockOresFluids = false; - @Configurable @Configurable.Comment({ "Sets the maximum number of chunks that may be cached for ore vein generation.", @@ -225,7 +219,6 @@ public static class OreVeinConfigs { "Default: 512 (requires restarting the server / re-opening the world)" }) public int oreGenerationChunkCacheSize = 512; - @Configurable @Configurable.Comment({ "Sets the maximum number of chunks for which ore indicators may be cached.", @@ -241,7 +234,6 @@ public static class MachineConfigs { @Configurable.Comment({"Whether insufficient energy supply should reset Machine recipe progress to zero.", "If true, progress will reset.", "If false, progress will decrease to zero with 2x speed", "Default: false"}) public boolean recipeProgressLowEnergy = false; - @Configurable @Configurable.Comment({"Whether to require a Wrench, Wirecutter, or other GregTech tools to break machines, casings, wires, and more.", "Default: false"}) public boolean requireGTToolsForBlocks = false; diff --git a/src/main/java/com/gregtechceu/gtceu/data/lang/MachineLang.java b/src/main/java/com/gregtechceu/gtceu/data/lang/MachineLang.java index ef156913c7..e2ccde7f34 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/lang/MachineLang.java +++ b/src/main/java/com/gregtechceu/gtceu/data/lang/MachineLang.java @@ -721,6 +721,9 @@ protected static void init(RegistrateLangProvider provider) { provider.add("gtceu.multiblock.fluid_rig.fluid_amount", "Pumping Rate: %s"); provider.add("gtceu.multiblock.fluid_rig.vein_depletion", "Vein Size: %s"); provider.add("gtceu.multiblock.fluid_rig.vein_depleted", "Vein Depleted."); + provider.add("gtceu.multiblock.ore_rig.drilled_ores_list", "Ores:"); + provider.add("gtceu.multiblock.ore_rig.drilled_ore_entry", " - %s"); + provider.add("gtceu.multiblock.ore_rig.ore_amount", "Drilling Rate: %s"); provider.add("gtceu.multiblock.pyrolyse_oven.speed", "Processing Speed: %s%%"); provider.add("gtceu.multiblock.cracking_unit.energy", "Energy Usage: %s%%"); provider.add("gtceu.multiblock.power_substation.stored", "Stored: %s EU"); diff --git a/src/main/java/com/gregtechceu/gtceu/data/loader/BedrockOreLoader.java b/src/main/java/com/gregtechceu/gtceu/data/loader/BedrockOreLoader.java new file mode 100644 index 0000000000..e45b00efd1 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/data/loader/BedrockOreLoader.java @@ -0,0 +1,88 @@ +package com.gregtechceu.gtceu.data.loader; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.gregtechceu.gtceu.GTCEu; +import com.gregtechceu.gtceu.api.GTCEuAPI; +import com.gregtechceu.gtceu.api.addon.AddonFinder; +import com.gregtechceu.gtceu.api.addon.IGTAddon; +import com.gregtechceu.gtceu.api.data.worldgen.bedrockore.BedrockOreDefinition; +import com.gregtechceu.gtceu.api.registry.GTRegistries; +import com.gregtechceu.gtceu.integration.kjs.GTCEuServerEvents; +import com.gregtechceu.gtceu.integration.kjs.events.GTBedrockOreVeinEventJS; +import com.mojang.serialization.JsonOps; +import dev.latvian.mods.kubejs.script.ScriptType; +import net.minecraft.resources.RegistryOps; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener; +import net.minecraft.util.GsonHelper; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.world.level.storage.loot.Deserializers; +import net.minecraftforge.fml.ModLoader; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import javax.annotation.ParametersAreNonnullByDefault; +import java.util.Map; + +@ParametersAreNonnullByDefault +public class BedrockOreLoader extends SimpleJsonResourceReloadListener { + public static BedrockOreLoader INSTANCE; + public static final Gson GSON_INSTANCE = Deserializers.createFunctionSerializer().create(); + private static final String FOLDER = "gtceu/bedrock_ore_veins"; + protected static final Logger LOGGER = LogManager.getLogger(); + + public BedrockOreLoader() { + super(GSON_INSTANCE, FOLDER); + INSTANCE = this; + } + + @Override + protected void apply(Map resourceList, ResourceManager resourceManager, ProfilerFiller profiler) { + if (GTRegistries.BEDROCK_ORE_DEFINITIONS.isFrozen()) { + GTRegistries.BEDROCK_ORE_DEFINITIONS.unfreeze(); + } + GTRegistries.BEDROCK_ORE_DEFINITIONS.registry().clear(); + + AddonFinder.getAddons().forEach(IGTAddon::registerFluidVeins); + ModLoader.get().postEvent(new GTCEuAPI.RegisterEvent<>(GTRegistries.BEDROCK_ORE_DEFINITIONS, BedrockOreDefinition.class)); + if (GTCEu.isKubeJSLoaded()) { + RunKJSEventInSeparateClassBecauseForgeIsDumb.fireKJSEvent(); + } + RegistryOps ops = RegistryOps.create(JsonOps.INSTANCE, GTRegistries.builtinRegistry()); + for(Map.Entry entry : resourceList.entrySet()) { + ResourceLocation location = entry.getKey(); + + try { + BedrockOreDefinition bedrockOre = fromJson(location, GsonHelper.convertToJsonObject(entry.getValue(), "top element"), ops); + if (bedrockOre == null) { + LOGGER.info("Skipping loading bedrock ore vein {} as it's serializer returned null", location); + } + GTRegistries.BEDROCK_ORE_DEFINITIONS.registerOrOverride(location, bedrockOre); + } catch (IllegalArgumentException | JsonParseException jsonParseException) { + LOGGER.error("Parsing error loading bedrock ore vein {}", location, jsonParseException); + } + } + + if (!GTRegistries.BEDROCK_ORE_DEFINITIONS.isFrozen()) { + GTRegistries.BEDROCK_ORE_DEFINITIONS.freeze(); + } + } + + public static BedrockOreDefinition fromJson(ResourceLocation id, JsonObject json, RegistryOps ops) { + return BedrockOreDefinition.FULL_CODEC.parse(ops, json).getOrThrow(false, LOGGER::error); + } + + /** + * Holy shit this is dumb, thanks forge for trying to classload things that are never called! + */ + public static final class RunKJSEventInSeparateClassBecauseForgeIsDumb { + public static void fireKJSEvent() { + GTCEuServerEvents.BEDROCK_ORE_VEIN_MODIFICATION.post(ScriptType.SERVER, new GTBedrockOreVeinEventJS()); + } + } +} + 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 c89372db34..98b2d58fef 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/loader/FluidVeinLoader.java +++ b/src/main/java/com/gregtechceu/gtceu/data/loader/FluidVeinLoader.java @@ -38,11 +38,14 @@ public class FluidVeinLoader extends SimpleJsonResourceReloadListener { public FluidVeinLoader() { super(GSON_INSTANCE, FOLDER); + INSTANCE = this; } @Override protected void apply(Map resourceList, ResourceManager resourceManager, ProfilerFiller profiler) { - GTRegistries.BEDROCK_FLUID_DEFINITIONS.unfreeze(); + if (GTRegistries.BEDROCK_FLUID_DEFINITIONS.isFrozen()) { + GTRegistries.BEDROCK_FLUID_DEFINITIONS.unfreeze(); + } GTRegistries.BEDROCK_FLUID_DEFINITIONS.registry().clear(); GTBedrockFluids.init(); @@ -59,24 +62,20 @@ protected void apply(Map resourceList, ResourceMa BedrockFluidDefinition fluid = fromJson(location, GsonHelper.convertToJsonObject(entry.getValue(), "top element"), ops); if (fluid == null) { LOGGER.info("Skipping loading fluid vein {} as it's serializer returned null", location); - } /*else if(fluid.getVeinGenerator() instanceof NoopVeinGenerator) { - LOGGER.info("Removing fluid vein {} as it's generator was marked as no-operation", location); - GTRegistries.BEDROCK_FLUID_DEFINITIONS.remove(location); - }*/else if (GTRegistries.BEDROCK_FLUID_DEFINITIONS.containKey(location)) { - GTRegistries.BEDROCK_FLUID_DEFINITIONS.replace(location, fluid); - } else { - GTRegistries.BEDROCK_FLUID_DEFINITIONS.register(location, fluid); } + GTRegistries.BEDROCK_FLUID_DEFINITIONS.registerOrOverride(location, fluid); } catch (IllegalArgumentException | JsonParseException jsonParseException) { LOGGER.error("Parsing error loading ore vein {}", location, jsonParseException); } } - GTRegistries.BEDROCK_FLUID_DEFINITIONS.freeze(); + if (!GTRegistries.BEDROCK_FLUID_DEFINITIONS.isFrozen()) { + GTRegistries.BEDROCK_FLUID_DEFINITIONS.freeze(); + } } public static BedrockFluidDefinition fromJson(ResourceLocation id, JsonObject json, RegistryOps ops) { - return BedrockFluidDefinition.FULL_CODEC.decode(ops, json).map(Pair::getFirst).getOrThrow(false, LOGGER::error); + return BedrockFluidDefinition.FULL_CODEC.parse(ops, json).getOrThrow(false, LOGGER::error); } /** 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 3e01c6649c..d1e0d9e4e3 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/loader/OreDataLoader.java +++ b/src/main/java/com/gregtechceu/gtceu/data/loader/OreDataLoader.java @@ -39,6 +39,7 @@ public class OreDataLoader extends SimpleJsonResourceReloadListener { public OreDataLoader() { super(GSON_INSTANCE, FOLDER); + INSTANCE = this; } @Override @@ -97,7 +98,7 @@ public static void buildVeinGenerator() { } public static GTOreDefinition fromJson(ResourceLocation id, JsonObject json, RegistryOps ops) { - return GTOreDefinition.FULL_CODEC.decode(ops, json).map(Pair::getFirst).getOrThrow(false, LOGGER::error); + return GTOreDefinition.FULL_CODEC.parse(ops, json).getOrThrow(false, LOGGER::error); } /** diff --git a/src/main/java/com/gregtechceu/gtceu/data/loader/forge/FluidVeinLoaderImpl.java b/src/main/java/com/gregtechceu/gtceu/data/loader/forge/FluidVeinLoaderImpl.java deleted file mode 100644 index 7b6bd67a26..0000000000 --- a/src/main/java/com/gregtechceu/gtceu/data/loader/forge/FluidVeinLoaderImpl.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.gregtechceu.gtceu.data.loader.forge; - -import com.gregtechceu.gtceu.data.loader.FluidVeinLoader; -import net.minecraft.core.RegistryAccess; - -public class FluidVeinLoaderImpl extends FluidVeinLoader { - - public FluidVeinLoaderImpl() { - super(); - FluidVeinLoader.INSTANCE = this; - } -} diff --git a/src/main/java/com/gregtechceu/gtceu/data/loader/forge/OreDataLoaderImpl.java b/src/main/java/com/gregtechceu/gtceu/data/loader/forge/OreDataLoaderImpl.java deleted file mode 100644 index 5d26d5e40b..0000000000 --- a/src/main/java/com/gregtechceu/gtceu/data/loader/forge/OreDataLoaderImpl.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.gregtechceu.gtceu.data.loader.forge; - -import com.gregtechceu.gtceu.data.loader.OreDataLoader; - -public class OreDataLoaderImpl extends OreDataLoader { - public OreDataLoaderImpl() { - super(); - OreDataLoader.INSTANCE = this; - } -} diff --git a/src/main/java/com/gregtechceu/gtceu/forge/ForgeCommonEventListener.java b/src/main/java/com/gregtechceu/gtceu/forge/ForgeCommonEventListener.java index d74dc3805a..332ffc4b41 100644 --- a/src/main/java/com/gregtechceu/gtceu/forge/ForgeCommonEventListener.java +++ b/src/main/java/com/gregtechceu/gtceu/forge/ForgeCommonEventListener.java @@ -13,8 +13,9 @@ import com.gregtechceu.gtceu.common.ServerCommands; import com.gregtechceu.gtceu.common.data.GTBlocks; import com.gregtechceu.gtceu.common.data.GTItems; -import com.gregtechceu.gtceu.data.loader.forge.FluidVeinLoaderImpl; -import com.gregtechceu.gtceu.data.loader.forge.OreDataLoaderImpl; +import com.gregtechceu.gtceu.data.loader.BedrockOreLoader; +import com.gregtechceu.gtceu.data.loader.FluidVeinLoader; +import com.gregtechceu.gtceu.data.loader.OreDataLoader; import com.gregtechceu.gtceu.utils.TaskHandler; import com.tterrag.registrate.util.entry.BlockEntry; import com.tterrag.registrate.util.entry.ItemEntry; @@ -93,8 +94,9 @@ public static void registerCommand(RegisterCommandsEvent event) { @SubscribeEvent public static void registerReloadListeners(AddReloadListenerEvent event) { - event.addListener(new OreDataLoaderImpl()); - event.addListener(new FluidVeinLoaderImpl()); + event.addListener(new OreDataLoader()); + event.addListener(new FluidVeinLoader()); + event.addListener(new BedrockOreLoader()); } @SubscribeEvent diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/GTCEuServerEvents.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/GTCEuServerEvents.java index 9ca4bc8f7c..4fd8b8d4d3 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/GTCEuServerEvents.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/GTCEuServerEvents.java @@ -1,5 +1,6 @@ package com.gregtechceu.gtceu.integration.kjs; +import com.gregtechceu.gtceu.integration.kjs.events.GTBedrockOreVeinEventJS; import com.gregtechceu.gtceu.integration.kjs.events.GTFluidVeinEventJS; import com.gregtechceu.gtceu.integration.kjs.events.GTOreVeinEventJS; import dev.latvian.mods.kubejs.event.EventGroup; @@ -9,5 +10,6 @@ public interface GTCEuServerEvents { EventGroup GROUP = EventGroup.of("GTCEuServerEvents"); EventHandler ORE_VEIN_MODIFICATION = GROUP.server("oreVeins", () -> GTOreVeinEventJS.class); + EventHandler BEDROCK_ORE_VEIN_MODIFICATION = GROUP.server("bedrockOreVeins", () -> GTBedrockOreVeinEventJS.class); EventHandler FLUID_VEIN_MODIFICATION = GROUP.server("fluidVeins", () -> GTFluidVeinEventJS.class); } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/events/GTBedrockOreVeinEventJS.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/events/GTBedrockOreVeinEventJS.java new file mode 100644 index 0000000000..6c1f42f27a --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/events/GTBedrockOreVeinEventJS.java @@ -0,0 +1,30 @@ +package com.gregtechceu.gtceu.integration.kjs.events; + +import com.gregtechceu.gtceu.api.data.worldgen.bedrockfluid.BedrockFluidDefinition; +import com.gregtechceu.gtceu.api.data.worldgen.bedrockore.BedrockOreDefinition; +import com.gregtechceu.gtceu.api.registry.GTRegistries; +import dev.latvian.mods.kubejs.event.EventJS; +import net.minecraft.resources.ResourceLocation; + +import java.util.function.Consumer; + +public class GTBedrockOreVeinEventJS extends EventJS { + + public GTBedrockOreVeinEventJS() { + + } + + public void add(ResourceLocation id, Consumer consumer) { + BedrockOreDefinition.Builder builder = BedrockOreDefinition.builder(id); + consumer.accept(builder); + builder.register(); + } + + public void remove(ResourceLocation id) { + GTRegistries.BEDROCK_ORE_DEFINITIONS.remove(id); + } + + public void modify(ResourceLocation id, Consumer consumer) { + consumer.accept(GTRegistries.BEDROCK_ORE_DEFINITIONS.get(id)); + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/events/GTFluidVeinEventJS.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/events/GTFluidVeinEventJS.java index 3945e103f8..4d45746832 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/events/GTFluidVeinEventJS.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/events/GTFluidVeinEventJS.java @@ -2,7 +2,6 @@ import com.gregtechceu.gtceu.api.data.worldgen.bedrockfluid.BedrockFluidDefinition; import com.gregtechceu.gtceu.api.registry.GTRegistries; -import com.gregtechceu.gtceu.integration.kjs.builders.FluidVeinBuilderJS; import dev.latvian.mods.kubejs.event.EventJS; import net.minecraft.resources.ResourceLocation; @@ -14,10 +13,10 @@ public GTFluidVeinEventJS() { } - public void add(ResourceLocation id, Consumer consumer) { - FluidVeinBuilderJS builder = new FluidVeinBuilderJS(id); + public void add(ResourceLocation id, Consumer consumer) { + BedrockFluidDefinition.Builder builder = BedrockFluidDefinition.builder(id); consumer.accept(builder); - builder.build(); + builder.register(); } public void remove(ResourceLocation id) {