diff --git a/src/generated/resources/assets/gtceu/compass/nodes/tools/mallet.json b/src/generated/resources/assets/gtceu/compass/nodes/tools/mallet.json index efa1d57879..1499be6747 100644 --- a/src/generated/resources/assets/gtceu/compass/nodes/tools/mallet.json +++ b/src/generated/resources/assets/gtceu/compass/nodes/tools/mallet.json @@ -1,7 +1,7 @@ { "button_texture": { "type": "item", - "res": "gtceu:polybenzimidazole_mallet" + "res": "gtceu:silicone_rubber_mallet" }, "items": [ "#forge:tools/mallets" diff --git a/src/generated/resources/assets/gtceu/compass/nodes/tools/plunger.json b/src/generated/resources/assets/gtceu/compass/nodes/tools/plunger.json index 32ff7c861d..332d6836a1 100644 --- a/src/generated/resources/assets/gtceu/compass/nodes/tools/plunger.json +++ b/src/generated/resources/assets/gtceu/compass/nodes/tools/plunger.json @@ -1,7 +1,7 @@ { "button_texture": { "type": "item", - "res": "gtceu:polybenzimidazole_plunger" + "res": "gtceu:silicone_rubber_plunger" }, "items": [ "#forge:tools/plungers" diff --git a/src/generated/resources/data/gtceu/worldgen/placed_feature/rubber_checked.json b/src/generated/resources/data/gtceu/worldgen/placed_feature/rubber_checked.json index 3dfbe7c54b..d4bc779df7 100644 --- a/src/generated/resources/data/gtceu/worldgen/placed_feature/rubber_checked.json +++ b/src/generated/resources/data/gtceu/worldgen/placed_feature/rubber_checked.json @@ -11,10 +11,7 @@ ] }, { - "type": "minecraft:count", - "count": { - "type": "gtceu:rubber_tree_chance" - } + "type": "gtceu:rubber_tree_chance" }, { "type": "minecraft:in_square" diff --git a/src/main/java/com/gregtechceu/gtceu/common/CommonProxy.java b/src/main/java/com/gregtechceu/gtceu/common/CommonProxy.java index 76d9c7d586..a061f55c0d 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/CommonProxy.java +++ b/src/main/java/com/gregtechceu/gtceu/common/CommonProxy.java @@ -96,7 +96,6 @@ public CommonProxy() { GTCommandArguments.init(eventBus); GTMobEffects.init(eventBus); GTParticleTypes.init(eventBus); - GTIntProviderTypes.init(eventBus); // init common features GTRegistries.GLOBAL_LOOT_MODIFIES.register("tool", () -> ToolLootModifier.CODEC); } diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTFeatures.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTFeatures.java index 034cf9efe6..4168436d81 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTFeatures.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTFeatures.java @@ -6,6 +6,7 @@ import com.gregtechceu.gtceu.api.data.worldgen.modifier.FrequencyModifier; import com.gregtechceu.gtceu.common.worldgen.feature.FluidSproutFeature; import com.gregtechceu.gtceu.common.worldgen.feature.StoneBlobFeature; +import com.gregtechceu.gtceu.common.worldgen.modifier.RubberTreeChancePlacement; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; @@ -36,6 +37,7 @@ public static void init() { Object inst = FrequencyModifier.FREQUENCY_MODIFIER; // seemingly useless access to init the class in time inst = DimensionFilter.DIMENSION_FILTER; inst = BiomePlacement.BIOME_PLACEMENT; + inst = RubberTreeChancePlacement.RUBBER_TREE_CHANCE_PLACEMENT; } public static void init(IEventBus modEventBus) { diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTIntProviderTypes.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTIntProviderTypes.java deleted file mode 100644 index db27c0f832..0000000000 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTIntProviderTypes.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.gregtechceu.gtceu.common.data; - -import com.gregtechceu.gtceu.GTCEu; -import com.gregtechceu.gtceu.common.worldgen.RubberTreeChanceWeightedListInt; - -import net.minecraft.core.registries.Registries; -import net.minecraft.util.valueproviders.IntProviderType; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.RegistryObject; - -public class GTIntProviderTypes { - - public static final DeferredRegister> INT_PROVIDER_TYPES = DeferredRegister - .create(Registries.INT_PROVIDER_TYPE, GTCEu.MOD_ID); - - public static final RegistryObject> RUBBER_TREE_CHANCE = INT_PROVIDER_TYPES - .register("rubber_tree_chance", () -> () -> RubberTreeChanceWeightedListInt.CODEC); - - public static void init(IEventBus modBus) { - INT_PROVIDER_TYPES.register(modBus); - } -} diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTPlacements.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTPlacements.java index 887f56ebbe..b6de314bb6 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTPlacements.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTPlacements.java @@ -3,7 +3,7 @@ import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.api.data.worldgen.BiomeWeightModifier; import com.gregtechceu.gtceu.api.data.worldgen.modifier.BiomePlacement; -import com.gregtechceu.gtceu.common.worldgen.RubberTreeChanceWeightedListInt; +import com.gregtechceu.gtceu.common.worldgen.modifier.RubberTreeChancePlacement; import com.gregtechceu.gtceu.data.recipe.CustomTags; import net.minecraft.core.HolderGetter; @@ -41,7 +41,7 @@ public static void bootstrap(BootstapContext ctx) { PlacementUtils.register(ctx, RUBBER_CHECKED, featureLookup.getOrThrow(GTConfiguredFeatures.RUBBER), new BiomePlacement(List.of( new BiomeWeightModifier(() -> biomeLookup.getOrThrow(CustomTags.IS_SWAMP), 50))), - CountPlacement.of(RubberTreeChanceWeightedListInt.INSTANCE), + RubberTreeChancePlacement.INSTANCE, InSquarePlacement.spread(), SurfaceWaterDepthFilter.forMaxDepth(0), PlacementUtils.HEIGHTMAP_TOP_SOLID, diff --git a/src/main/java/com/gregtechceu/gtceu/common/worldgen/RubberTreeChanceWeightedListInt.java b/src/main/java/com/gregtechceu/gtceu/common/worldgen/RubberTreeChanceWeightedListInt.java deleted file mode 100644 index 7d43294716..0000000000 --- a/src/main/java/com/gregtechceu/gtceu/common/worldgen/RubberTreeChanceWeightedListInt.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.gregtechceu.gtceu.common.worldgen; - -import com.gregtechceu.gtceu.common.data.GTIntProviderTypes; -import com.gregtechceu.gtceu.config.ConfigHolder; - -import net.minecraft.util.RandomSource; -import net.minecraft.util.random.SimpleWeightedRandomList; -import net.minecraft.util.valueproviders.ConstantInt; -import net.minecraft.util.valueproviders.IntProvider; -import net.minecraft.util.valueproviders.IntProviderType; - -import com.mojang.serialization.Codec; - -public class RubberTreeChanceWeightedListInt extends IntProvider { - - public static final RubberTreeChanceWeightedListInt INSTANCE = new RubberTreeChanceWeightedListInt(); - public static final Codec CODEC = Codec.unit(INSTANCE); - - private final SimpleWeightedRandomList distribution; - private final int maxValue; - - public RubberTreeChanceWeightedListInt() { - if (ConfigHolder.INSTANCE.worldgen.rubberTreeSpawnChance <= 0.0f) { - distribution = SimpleWeightedRandomList.builder() - .add(ConstantInt.of(0), 1) - .build(); - this.maxValue = 0; - } else { - float chance = 1.0F / ConfigHolder.INSTANCE.worldgen.rubberTreeSpawnChance; - if (Math.abs(chance - (int) chance) > 1.0E-5F) { - throw new IllegalStateException("Chance data cannot be represented as list weight"); - } else { - this.distribution = SimpleWeightedRandomList.builder() - .add(ConstantInt.of(0), (int) chance - 1) - .add(ConstantInt.of(1), 1) - .build(); - } - this.maxValue = 1; - } - } - - @Override - public int sample(RandomSource random) { - return this.distribution.getRandomValue(random).orElseThrow(IllegalStateException::new).sample(random); - } - - @Override - public int getMinValue() { - return 0; - } - - @Override - public int getMaxValue() { - return this.maxValue; - } - - @Override - public IntProviderType getType() { - return GTIntProviderTypes.RUBBER_TREE_CHANCE.get(); - } -} diff --git a/src/main/java/com/gregtechceu/gtceu/common/worldgen/modifier/RubberTreeChancePlacement.java b/src/main/java/com/gregtechceu/gtceu/common/worldgen/modifier/RubberTreeChancePlacement.java new file mode 100644 index 0000000000..e468a76fbc --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/common/worldgen/modifier/RubberTreeChancePlacement.java @@ -0,0 +1,34 @@ +package com.gregtechceu.gtceu.common.worldgen.modifier; + +import com.gregtechceu.gtceu.GTCEu; +import com.gregtechceu.gtceu.api.registry.GTRegistries; +import com.gregtechceu.gtceu.config.ConfigHolder; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.util.RandomSource; +import net.minecraft.world.level.levelgen.placement.PlacementModifierType; +import net.minecraft.world.level.levelgen.placement.RepeatingPlacement; + +import com.mojang.serialization.Codec; + +public class RubberTreeChancePlacement extends RepeatingPlacement { + + public static final PlacementModifierType RUBBER_TREE_CHANCE_PLACEMENT = GTRegistries + .register( + BuiltInRegistries.PLACEMENT_MODIFIER_TYPE, GTCEu.id("rubber_tree_chance"), + () -> RubberTreeChancePlacement.CODEC); + + public static final RubberTreeChancePlacement INSTANCE = new RubberTreeChancePlacement(); + public static final Codec CODEC = Codec.unit(INSTANCE); + + @Override + protected int count(RandomSource random, BlockPos pos) { + return random.nextFloat() < ConfigHolder.INSTANCE.worldgen.rubberTreeSpawnChance ? 1 : 0; + } + + @Override + public PlacementModifierType type() { + return RUBBER_TREE_CHANCE_PLACEMENT; + } +}