From 4d2526d1b6891e43422cfcc6fcf260415e39951c Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Mon, 1 Aug 2022 22:37:39 +0200 Subject: [PATCH] Fluids & Biome Modifiers --- .../java/com/simibubi/create/AllFluids.java | 130 +++++++++++++----- src/main/java/com/simibubi/create/Create.java | 3 +- .../crafter/MechanicalCraftingInventory.java | 5 + .../actors/FluidManipulationBehaviour.java | 15 +- .../fluids/particle/FluidStackParticle.java | 28 ++-- .../fluids/potion/PotionFluid.java | 25 ++-- .../fluids/tank/FluidTankBlock.java | 16 +-- .../fluids/tank/FluidTankRenderer.java | 2 +- .../fluids/tank/FluidTankTileEntity.java | 10 +- .../curiosities/deco/SlidingDoorBlock.java | 20 --- .../curiosities/tools/BlueprintEntity.java | 5 + .../simibubi/create/events/CommonEvents.java | 8 -- .../foundation/data/CreateRegistrate.java | 33 ++--- .../foundation/data/VirtualFluidBuilder.java | 9 +- .../data/recipe/ProcessingRecipeGen.java | 3 +- .../create/foundation/fluid/FluidHelper.java | 30 +++- .../foundation/fluid/FluidRenderer.java | 72 +++++----- .../fluid/FluidMovementActorScenes.java | 2 +- .../ponder/content/fluid/FluidTankScenes.java | 2 +- .../ponder/content/fluid/PipeScenes.java | 2 +- .../ponder/content/fluid/SpoutScenes.java | 2 +- .../foundation/worldgen/AllWorldFeatures.java | 62 +++++---- .../foundation/worldgen/BiomeFilter.java | 9 +- .../worldgen/ConfigDrivenFeatureEntry.java | 4 +- 24 files changed, 275 insertions(+), 222 deletions(-) diff --git a/src/main/java/com/simibubi/create/AllFluids.java b/src/main/java/com/simibubi/create/AllFluids.java index 50e6ed263..47688078d 100644 --- a/src/main/java/com/simibubi/create/AllFluids.java +++ b/src/main/java/com/simibubi/create/AllFluids.java @@ -1,11 +1,13 @@ package com.simibubi.create; +import java.util.function.Consumer; + import javax.annotation.Nullable; import com.simibubi.create.AllTags.AllFluidTags; import com.simibubi.create.content.contraptions.fluids.VirtualFluid; import com.simibubi.create.content.contraptions.fluids.potion.PotionFluid; -import com.simibubi.create.content.contraptions.fluids.potion.PotionFluid.PotionFluidAttributes; +import com.simibubi.create.content.contraptions.fluids.potion.PotionFluid.PotionFluidType; import com.simibubi.create.content.palettes.AllPaletteStoneTypes; import com.simibubi.create.foundation.data.CreateRegistrate; import com.tterrag.registrate.util.entry.FluidEntry; @@ -13,13 +15,16 @@ import com.tterrag.registrate.util.entry.FluidEntry; import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.RenderType; import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.fluids.FluidAttributes; +import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; import net.minecraftforge.fluids.ForgeFlowingFluid; public class AllFluids { @@ -27,42 +32,42 @@ public class AllFluids { private static final CreateRegistrate REGISTRATE = Create.registrate(); public static final FluidEntry POTION = - REGISTRATE.virtualFluid("potion", PotionFluidAttributes::new, PotionFluid::new) - .lang(f -> "fluid.create.potion", "Potion") - .register(); - - public static final FluidEntry TEA = REGISTRATE.virtualFluid("tea") - .lang(f -> "fluid.create.tea", "Builder's Tea") - .tag(AllTags.forgeFluidTag("tea")) + REGISTRATE.virtualFluid("potion", PotionFluidType::new, PotionFluid::new) + .lang(f -> "fluid.create.potion", "Potion") .register(); + public static final FluidEntry TEA = REGISTRATE.virtualFluid("tea") + .lang(f -> "fluid.create.tea", "Builder's Tea") + .tag(AllTags.forgeFluidTag("tea")) + .register(); + public static final FluidEntry HONEY = - REGISTRATE.standardFluid("honey", NoColorFluidAttributes::new) - .lang(f -> "fluid.create.honey", "Honey") - .attributes(b -> b.viscosity(2000) - .density(1400)) - .properties(p -> p.levelDecreasePerBlock(2) - .tickRate(25) - .slopeFindDistance(3) - .explosionResistance(100f)) - .tag(AllFluidTags.HONEY.tag) - .source(ForgeFlowingFluid.Source::new) // TODO: remove when Registrate fixes FluidBuilder - .bucket() - .tag(AllTags.forgeItemTag("buckets/honey")) - .build() - .register(); + REGISTRATE.standardFluid("honey", NoColorFluidAttributes::new) + .lang(f -> "fluid.create.honey", "Honey") + .properties(b -> b.viscosity(2000) + .density(1400)) + .fluidProperties(p -> p.levelDecreasePerBlock(2) + .tickRate(25) + .slopeFindDistance(3) + .explosionResistance(100f)) + .tag(AllFluidTags.HONEY.tag) + .source(ForgeFlowingFluid.Source::new) // TODO: remove when Registrate fixes FluidBuilder + .bucket() + .tag(AllTags.forgeItemTag("buckets/honey")) + .build() + .register(); public static final FluidEntry CHOCOLATE = - REGISTRATE.standardFluid("chocolate", NoColorFluidAttributes::new) - .lang(f -> "fluid.create.chocolate", "Chocolate") - .tag(AllTags.forgeFluidTag("chocolate")) - .attributes(b -> b.viscosity(1500) - .density(1400)) - .properties(p -> p.levelDecreasePerBlock(2) - .tickRate(25) - .slopeFindDistance(3) - .explosionResistance(100f)) - .register(); + REGISTRATE.standardFluid("chocolate", NoColorFluidAttributes::new) + .lang(f -> "fluid.create.chocolate", "Chocolate") + .tag(AllTags.forgeFluidTag("chocolate")) + .properties(b -> b.viscosity(1500) + .density(1400)) + .fluidProperties(p -> p.levelDecreasePerBlock(2) + .tickRate(25) + .slopeFindDistance(3) + .explosionResistance(100f)) + .register(); // Load this class @@ -92,21 +97,70 @@ public class AllFluids { return null; } + public static abstract class TintedFluidType extends FluidType { + + protected static final int NO_TINT = 0xffffffff; + private ResourceLocation stillTexture; + private ResourceLocation flowingTexture; + + public TintedFluidType(Properties properties, ResourceLocation stillTexture, ResourceLocation flowingTexture) { + super(properties); + } + + @Override + public void initializeClient(Consumer consumer) { + consumer.accept(new IClientFluidTypeExtensions() { + + @Override + public ResourceLocation getFlowingTexture() { + return flowingTexture; + } + + @Override + public ResourceLocation getStillTexture() { + return stillTexture; + } + + @Override + public int getTintColor(FluidStack stack) { + return getTintColor(stack); + } + + @Override + public int getTintColor(FluidState state, BlockAndTintGetter getter, BlockPos pos) { + return getTintColor(state, getter, pos); + } + + }); + } + + protected abstract int getTintColor(FluidStack stack); + + protected abstract int getTintColor(FluidState state, BlockAndTintGetter getter, BlockPos pos); + + } + /** * Removing alpha from tint prevents optifine from forcibly applying biome * colors to modded fluids (Makes translucent fluids disappear) */ - private static class NoColorFluidAttributes extends FluidAttributes { + private static class NoColorFluidAttributes extends TintedFluidType { - protected NoColorFluidAttributes(Builder builder, Fluid fluid) { - super(builder, fluid); + public NoColorFluidAttributes(Properties properties, ResourceLocation stillTexture, + ResourceLocation flowingTexture) { + super(properties, stillTexture, flowingTexture); } @Override - public int getColor(BlockAndTintGetter world, BlockPos pos) { + public int getTintColor(FluidState state, BlockAndTintGetter world, BlockPos pos) { return 0x00ffffff; } + @Override + protected int getTintColor(FluidStack stack) { + return NO_TINT; + } + } - + } diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index 42972dfa9..4f3392d43 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -125,8 +125,6 @@ public class Create { modEventBus.addListener(AllSoundEvents::register); modEventBus.addListener(AllEntityDataSerializers::register); - forgeEventBus.addListener(EventPriority.HIGH, SlidingDoorBlock::stopItQuark); - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> CreateClient.onCtorClient(modEventBus, forgeEventBus)); Mods.CURIOS.executeIfInstalled(() -> Curios::init); @@ -156,6 +154,7 @@ public class Create { gen.addProvider(true, new MechanicalCraftingRecipeGen(gen)); gen.addProvider(true, new SequencedAssemblyRecipeGen(gen)); ProcessingRecipeGen.registerAll(gen); + AllWorldFeatures.generateBiomeModifiers(event); } public static CreateRegistrate registrate() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCraftingInventory.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCraftingInventory.java index 239c9c7b6..7e228de1e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCraftingInventory.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCraftingInventory.java @@ -15,6 +15,11 @@ public class MechanicalCraftingInventory extends CraftingContainer { public boolean stillValid(Player playerIn) { return false; } + + @Override + public ItemStack quickMoveStack(Player p_38941_, int p_38942_) { + return ItemStack.EMPTY; + } }; public MechanicalCraftingInventory(GroupedItems items) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/FluidManipulationBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/FluidManipulationBehaviour.java index a3f428274..c54ce7f5c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/FluidManipulationBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/FluidManipulationBehaviour.java @@ -23,9 +23,7 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtUtils; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundEvent; -import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; -import net.minecraft.tags.FluidTags; import net.minecraft.world.level.Level; import net.minecraft.world.level.levelgen.structure.BoundingBox; import net.minecraft.world.level.material.Fluid; @@ -197,19 +195,12 @@ public abstract class FluidManipulationBehaviour extends TileEntityBehaviour { protected void playEffect(Level world, BlockPos pos, Fluid fluid, boolean fillSound) { BlockPos splooshPos = pos == null ? tileEntity.getBlockPos() : pos; + FluidStack stack = new FluidStack(fluid, 1); - SoundEvent soundevent = fillSound ? fluid.getAttributes() - .getFillSound() - : fluid.getAttributes() - .getEmptySound(); - if (soundevent == null) - soundevent = FluidHelper.isTag(fluid, FluidTags.LAVA) - ? fillSound ? SoundEvents.BUCKET_FILL_LAVA : SoundEvents.BUCKET_EMPTY_LAVA - : fillSound ? SoundEvents.BUCKET_FILL : SoundEvents.BUCKET_EMPTY; - + SoundEvent soundevent = fillSound ? FluidHelper.getFillSound(stack) : FluidHelper.getEmptySound(stack); world.playSound(null, splooshPos, soundevent, SoundSource.BLOCKS, 0.3F, 1.0F); if (world instanceof ServerLevel) - AllPackets.sendToNear(world, splooshPos, 10, new FluidSplashPacket(splooshPos, new FluidStack(fluid, 1))); + AllPackets.sendToNear(world, splooshPos, 10, new FluidSplashPacket(splooshPos, stack)); } protected boolean canDrainInfinitely(Fluid fluid) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/FluidStackParticle.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/FluidStackParticle.java index f0e3a670c..b383b9405 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/FluidStackParticle.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/FluidStackParticle.java @@ -11,15 +11,17 @@ import net.minecraft.client.particle.TextureSheetParticle; import net.minecraft.core.particles.ParticleType; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.world.inventory.InventoryMenu; +import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions; import net.minecraftforge.fluids.FluidStack; public class FluidStackParticle extends TextureSheetParticle { private final float uo; private final float vo; private FluidStack fluid; + private IClientFluidTypeExtensions clientFluid; - public static FluidStackParticle create(ParticleType type, ClientLevel world, FluidStack fluid, double x, - double y, double z, double vx, double vy, double vz) { + public static FluidStackParticle create(ParticleType type, ClientLevel world, FluidStack fluid, + double x, double y, double z, double vx, double vy, double vz) { if (type == AllParticleTypes.BASIN_FLUID.get()) return new BasinFluidParticle(world, fluid, x, y, z, vx, vy, vz); return new FluidStackParticle(world, fluid, x, y, z, vx, vy, vz); @@ -28,20 +30,19 @@ public class FluidStackParticle extends TextureSheetParticle { public FluidStackParticle(ClientLevel world, FluidStack fluid, double x, double y, double z, double vx, double vy, double vz) { super(world, x, y, z, vx, vy, vz); + + clientFluid = IClientFluidTypeExtensions.of(fluid.getFluid()); + this.fluid = fluid; this.setSprite(Minecraft.getInstance() .getTextureAtlas(InventoryMenu.BLOCK_ATLAS) - .apply(fluid.getFluid() - .getAttributes() - .getStillTexture())); + .apply(clientFluid.getStillTexture(fluid))); this.gravity = 1.0F; this.rCol = 0.8F; this.gCol = 0.8F; this.bCol = 0.8F; - this.multiplyColor(fluid.getFluid() - .getAttributes() - .getColor(fluid)); + this.multiplyColor(clientFluid.getTintColor(fluid)); this.xd = vx; this.yd = vy; @@ -58,8 +59,8 @@ public class FluidStackParticle extends TextureSheetParticle { int skyLight = brightnessForRender >> 20; int blockLight = (brightnessForRender >> 4) & 0xf; blockLight = Math.max(blockLight, fluid.getFluid() - .getAttributes() - .getLuminosity(fluid)); + .getFluidType() + .getLightLevel(fluid)); return (skyLight << 20) | (blockLight << 4); } @@ -97,10 +98,9 @@ public class FluidStackParticle extends TextureSheetParticle { if (!onGround && level.random.nextFloat() < 1 / 8f) return; - Color color = new Color(fluid.getFluid() - .getAttributes() - .getColor(fluid)); - level.addParticle(ParticleTypes.ENTITY_EFFECT, x, y, z, color.getRedAsFloat(), color.getGreenAsFloat(), color.getBlueAsFloat()); + Color color = new Color(clientFluid.getTintColor(fluid)); + level.addParticle(ParticleTypes.ENTITY_EFFECT, x, y, z, color.getRedAsFloat(), color.getGreenAsFloat(), + color.getBlueAsFloat()); } protected boolean canEvaporate() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/potion/PotionFluid.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/potion/PotionFluid.java index 2a7482c07..892f09bcc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/potion/PotionFluid.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/potion/PotionFluid.java @@ -4,9 +4,11 @@ import java.util.Collection; import java.util.List; import com.simibubi.create.AllFluids; +import com.simibubi.create.AllFluids.TintedFluidType; import com.simibubi.create.content.contraptions.fluids.VirtualFluid; import com.simibubi.create.foundation.utility.NBTHelper; +import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.network.chat.Component; @@ -15,9 +17,9 @@ import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.item.alchemy.Potion; import net.minecraft.world.item.alchemy.PotionUtils; import net.minecraft.world.item.alchemy.Potions; +import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.ItemLike; -import net.minecraft.world.level.material.Fluid; -import net.minecraftforge.fluids.FluidAttributes; +import net.minecraft.world.level.material.FluidState; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.registries.ForgeRegistries; @@ -66,26 +68,26 @@ public class PotionFluid extends VirtualFluid { REGULAR, SPLASH, LINGERING; } - public static class PotionFluidAttributes extends FluidAttributes { + public static class PotionFluidType extends TintedFluidType { - public PotionFluidAttributes(Builder builder, Fluid fluid) { - super(builder, fluid); + public PotionFluidType(Properties properties, ResourceLocation stillTexture, ResourceLocation flowingTexture) { + super(properties, stillTexture, flowingTexture); } @Override - public int getColor(FluidStack stack) { + public int getTintColor(FluidStack stack) { CompoundTag tag = stack.getOrCreateTag(); int color = PotionUtils.getColor(PotionUtils.getAllEffects(tag)) | 0xff000000; return color; } @Override - public Component getDisplayName(FluidStack stack) { - return Component.translatable(getTranslationKey(stack)); + public Component getDescription(FluidStack stack) { + return Component.translatable(getDescriptionId(stack)); } @Override - public String getTranslationKey(FluidStack stack) { + public String getDescriptionId(FluidStack stack) { CompoundTag tag = stack.getOrCreateTag(); ItemLike itemFromBottleType = PotionFluidHandler.itemFromBottleType(NBTHelper.readEnum(tag, "Bottle", BottleType.class)); @@ -94,6 +96,11 @@ public class PotionFluid extends VirtualFluid { .getDescriptionId() + ".effect."); } + @Override + protected int getTintColor(FluidState state, BlockAndTintGetter getter, BlockPos pos) { + return NO_TINT; + } + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankBlock.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankBlock.java index 901263a43..a050729ea 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankBlock.java @@ -20,7 +20,6 @@ import net.minecraft.core.particles.ParticleTypes; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; -import net.minecraft.tags.FluidTags; import net.minecraft.util.Mth; import net.minecraft.util.StringRepresentable; import net.minecraft.world.InteractionHand; @@ -52,7 +51,6 @@ import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraftforge.common.util.ForgeSoundType; import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.fluids.FluidAttributes; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler; @@ -196,11 +194,7 @@ public class FluidTankBlock extends Block implements IWrenchable, ITE { @@ -52,24 +50,6 @@ public class SlidingDoorBlock extends DoorBlock implements IWrenchable, ITE items) { diff --git a/src/main/java/com/simibubi/create/events/CommonEvents.java b/src/main/java/com/simibubi/create/events/CommonEvents.java index 700931339..04159c8da 100644 --- a/src/main/java/com/simibubi/create/events/CommonEvents.java +++ b/src/main/java/com/simibubi/create/events/CommonEvents.java @@ -20,7 +20,6 @@ import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.ServerSpeedProvider; import com.simibubi.create.foundation.utility.WorldAttached; import com.simibubi.create.foundation.utility.recipe.RecipeFinder; -import com.simibubi.create.foundation.worldgen.AllWorldFeatures; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -57,8 +56,6 @@ import net.minecraftforge.event.level.BlockEvent.FluidPlaceBlockEvent; import net.minecraftforge.event.level.ChunkEvent; import net.minecraftforge.event.level.LevelEvent; import net.minecraftforge.event.server.ServerStoppingEvent; -import net.minecraftforge.event.world.BiomeLoadingEvent; -import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; @@ -211,11 +208,6 @@ public class CommonEvents { CapabilityMinecartController.startTracking(event); } - @SubscribeEvent(priority = EventPriority.HIGH) - public static void onBiomeLoad(BiomeLoadingEvent event) { - AllWorldFeatures.reload(event); - } - public static void leftClickEmpty(ServerPlayer player) { ItemStack stack = player.getMainHandItem(); if (stack.getItem() instanceof ZapperItem) { diff --git a/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java b/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java index d6caa6cba..8249a4b19 100644 --- a/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java +++ b/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java @@ -7,7 +7,6 @@ import java.util.IdentityHashMap; import java.util.Map; import java.util.Map.Entry; import java.util.function.BiConsumer; -import java.util.function.BiFunction; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -24,7 +23,6 @@ import com.tterrag.registrate.builders.BlockEntityBuilder.BlockEntityFactory; import com.tterrag.registrate.builders.Builder; import com.tterrag.registrate.builders.FluidBuilder; import com.tterrag.registrate.util.entry.RegistryEntry; -import com.tterrag.registrate.util.nullness.NonNullBiFunction; import com.tterrag.registrate.util.nullness.NonNullConsumer; import com.tterrag.registrate.util.nullness.NonNullFunction; import com.tterrag.registrate.util.nullness.NonNullSupplier; @@ -41,10 +39,8 @@ import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockBehaviour.Properties; -import net.minecraft.world.level.material.Fluid; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.fluids.FluidAttributes; import net.minecraftforge.fluids.ForgeFlowingFluid; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; @@ -77,8 +73,8 @@ public class CreateRegistrate extends AbstractRegistrate { } @Override - protected RegistryEntry accept(String name, - ResourceKey> type, Builder builder, NonNullSupplier creator, + protected RegistryEntry accept(String name, ResourceKey> type, + Builder builder, NonNullSupplier creator, NonNullFunction, ? extends RegistryEntry> entryFactory) { RegistryEntry ret = super.accept(name, type, builder, creator, entryFactory); sectionLookup.put(ret, currentSection()); @@ -164,19 +160,16 @@ public class CreateRegistrate extends AbstractRegistrate { /* Fluids */ public FluidBuilder virtualFluid(String name, - BiFunction attributesFactory, - NonNullFunction factory) { + FluidBuilder.FluidTypeFactory typeFactory, NonNullFunction factory) { return entry(name, c -> new VirtualFluidBuilder<>(self(), self(), name, c, Create.asResource("fluid/" + name + "_still"), - Create.asResource("fluid/" + name + "_flow"), attributesFactory, factory)); + Create.asResource("fluid/" + name + "_flow"), typeFactory, factory)); } - public FluidBuilder virtualFluid(String name, ResourceLocation still, ResourceLocation flow, - BiFunction attributesFactory, - NonNullFunction factory) { - return entry(name, - c -> new VirtualFluidBuilder<>(self(), self(), name, c, still, - flow, attributesFactory, factory)); + public FluidBuilder virtualFluid(String name, + ResourceLocation still, ResourceLocation flow, FluidBuilder.FluidTypeFactory typeFactory, + NonNullFunction factory) { + return entry(name, c -> new VirtualFluidBuilder<>(self(), self(), name, c, still, flow, typeFactory, factory)); } public FluidBuilder virtualFluid(String name) { @@ -185,10 +178,10 @@ public class CreateRegistrate extends AbstractRegistrate { Create.asResource("fluid/" + name + "_flow"), null, VirtualFluid::new)); } - public FluidBuilder virtualFluid(String name, ResourceLocation still, ResourceLocation flow) { + public FluidBuilder virtualFluid(String name, ResourceLocation still, + ResourceLocation flow) { return entry(name, - c -> new VirtualFluidBuilder<>(self(), self(), name, c, still, - flow, null, VirtualFluid::new)); + c -> new VirtualFluidBuilder<>(self(), self(), name, c, still, flow, null, VirtualFluid::new)); } public FluidBuilder standardFluid(String name) { @@ -196,9 +189,9 @@ public class CreateRegistrate extends AbstractRegistrate { } public FluidBuilder standardFluid(String name, - NonNullBiFunction attributesFactory) { + FluidBuilder.FluidTypeFactory typeFactory) { return fluid(name, Create.asResource("fluid/" + name + "_still"), Create.asResource("fluid/" + name + "_flow"), - attributesFactory); + typeFactory); } /* Util */ diff --git a/src/main/java/com/simibubi/create/foundation/data/VirtualFluidBuilder.java b/src/main/java/com/simibubi/create/foundation/data/VirtualFluidBuilder.java index fa57f81e1..9b7250346 100644 --- a/src/main/java/com/simibubi/create/foundation/data/VirtualFluidBuilder.java +++ b/src/main/java/com/simibubi/create/foundation/data/VirtualFluidBuilder.java @@ -1,7 +1,5 @@ package com.simibubi.create.foundation.data; -import java.util.function.BiFunction; - import com.tterrag.registrate.AbstractRegistrate; import com.tterrag.registrate.builders.BuilderCallback; import com.tterrag.registrate.builders.FluidBuilder; @@ -9,8 +7,6 @@ import com.tterrag.registrate.util.nullness.NonNullFunction; import com.tterrag.registrate.util.nullness.NonNullSupplier; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.material.Fluid; -import net.minecraftforge.fluids.FluidAttributes; import net.minecraftforge.fluids.ForgeFlowingFluid; import net.minecraftforge.fluids.ForgeFlowingFluid.Properties; @@ -20,10 +16,9 @@ import net.minecraftforge.fluids.ForgeFlowingFluid.Properties; public class VirtualFluidBuilder extends FluidBuilder { public VirtualFluidBuilder(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, - ResourceLocation stillTexture, ResourceLocation flowingTexture, - BiFunction attributesFactory, + ResourceLocation stillTexture, ResourceLocation flowingTexture, FluidBuilder.FluidTypeFactory typeFactory, NonNullFunction factory) { - super(owner, parent, name, callback, stillTexture, flowingTexture, attributesFactory, factory); + super(owner, parent, name, callback, stillTexture, flowingTexture, typeFactory, factory); source(factory); } diff --git a/src/main/java/com/simibubi/create/foundation/data/recipe/ProcessingRecipeGen.java b/src/main/java/com/simibubi/create/foundation/data/recipe/ProcessingRecipeGen.java index a41ff49c5..e36c844cc 100644 --- a/src/main/java/com/simibubi/create/foundation/data/recipe/ProcessingRecipeGen.java +++ b/src/main/java/com/simibubi/create/foundation/data/recipe/ProcessingRecipeGen.java @@ -19,11 +19,12 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.ItemLike; import net.minecraftforge.fluids.FluidAttributes; +import net.minecraftforge.fluids.FluidType; public abstract class ProcessingRecipeGen extends CreateRecipeProvider { protected static final List GENERATORS = new ArrayList<>(); - protected static final int BUCKET = FluidAttributes.BUCKET_VOLUME; + protected static final int BUCKET = FluidType.BUCKET_VOLUME; protected static final int BOTTLE = 250; public static void registerAll(DataGenerator gen) { diff --git a/src/main/java/com/simibubi/create/foundation/fluid/FluidHelper.java b/src/main/java/com/simibubi/create/foundation/fluid/FluidHelper.java index be7a06a2f..cffe97b80 100644 --- a/src/main/java/com/simibubi/create/foundation/fluid/FluidHelper.java +++ b/src/main/java/com/simibubi/create/foundation/fluid/FluidHelper.java @@ -15,6 +15,9 @@ import com.simibubi.create.foundation.utility.Pair; import net.minecraft.nbt.TagParser; import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.tags.FluidTags; import net.minecraft.tags.TagKey; import net.minecraft.util.GsonHelper; import net.minecraft.world.InteractionHand; @@ -26,6 +29,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.Fluids; +import net.minecraftforge.common.SoundActions; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.ForgeFlowingFluid; @@ -62,6 +66,26 @@ public class FluidHelper { return isTag(fluid.getFluid(), tag); } + public static SoundEvent getFillSound(FluidStack fluid) { + SoundEvent soundevent = fluid.getFluid() + .getFluidType() + .getSound(fluid, SoundActions.BUCKET_FILL); + if (soundevent == null) + soundevent = + FluidHelper.isTag(fluid, FluidTags.LAVA) ? SoundEvents.BUCKET_FILL_LAVA : SoundEvents.BUCKET_FILL; + return soundevent; + } + + public static SoundEvent getEmptySound(FluidStack fluid) { + SoundEvent soundevent = fluid.getFluid() + .getFluidType() + .getSound(fluid, SoundActions.BUCKET_EMPTY); + if (soundevent == null) + soundevent = + FluidHelper.isTag(fluid, FluidTags.LAVA) ? SoundEvents.BUCKET_EMPTY_LAVA : SoundEvents.BUCKET_EMPTY; + return soundevent; + } + public static boolean hasBlockState(Fluid fluid) { BlockState blockState = fluid.defaultFluidState() .createLegacyBlock(); @@ -157,7 +181,8 @@ public class FluidHelper { player.setItemInHand(handIn, emptyingResult.getSecond()); else { player.setItemInHand(handIn, copyOfHeld); - player.getInventory().placeItemBackInInventory(emptyingResult.getSecond()); + player.getInventory() + .placeItemBackInInventory(emptyingResult.getSecond()); } } return true; @@ -196,7 +221,8 @@ public class FluidHelper { tank.drain(copy, FluidAction.EXECUTE); if (!player.isCreative()) - player.getInventory().placeItemBackInInventory(out); + player.getInventory() + .placeItemBackInInventory(out); te.notifyUpdate(); return true; } diff --git a/src/main/java/com/simibubi/create/foundation/fluid/FluidRenderer.java b/src/main/java/com/simibubi/create/foundation/fluid/FluidRenderer.java index 3cd201912..a4cc11086 100644 --- a/src/main/java/com/simibubi/create/foundation/fluid/FluidRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/fluid/FluidRenderer.java @@ -25,8 +25,9 @@ import net.minecraft.world.level.material.Fluid; import net.minecraft.world.phys.Vec3; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.fluids.FluidAttributes; +import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions; import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; @OnlyIn(Dist.CLIENT) public class FluidRenderer { @@ -43,15 +44,16 @@ public class FluidRenderer { public static void renderFluidStream(FluidStack fluidStack, Direction direction, float radius, float progress, boolean inbound, VertexConsumer builder, PoseStack ms, int light) { Fluid fluid = fluidStack.getFluid(); - FluidAttributes fluidAttributes = fluid.getAttributes(); + IClientFluidTypeExtensions clientFluid = IClientFluidTypeExtensions.of(fluid); + FluidType fluidAttributes = fluid.getFluidType(); Function spriteAtlas = Minecraft.getInstance() .getTextureAtlas(InventoryMenu.BLOCK_ATLAS); - TextureAtlasSprite flowTexture = spriteAtlas.apply(fluidAttributes.getFlowingTexture(fluidStack)); - TextureAtlasSprite stillTexture = spriteAtlas.apply(fluidAttributes.getStillTexture(fluidStack)); + TextureAtlasSprite flowTexture = spriteAtlas.apply(clientFluid.getFlowingTexture(fluidStack)); + TextureAtlasSprite stillTexture = spriteAtlas.apply(clientFluid.getStillTexture(fluidStack)); - int color = fluidAttributes.getColor(fluidStack); + int color = clientFluid.getTintColor(fluidStack); int blockLightIn = (light >> 4) & 0xF; - int luminosity = Math.max(blockLightIn, fluidAttributes.getLuminosity(fluidStack)); + int luminosity = Math.max(blockLightIn, fluidAttributes.getLightLevel(fluidStack)); light = (light & 0xF00000) | luminosity << 4; if (inbound) @@ -74,42 +76,40 @@ public class FluidRenderer { for (int i = 0; i < 4; i++) { ms.pushPose(); - renderFlowingTiledFace(Direction.SOUTH, hMin, yMin, hMax, yMax, h, - builder, ms, light, color, flowTexture); + renderFlowingTiledFace(Direction.SOUTH, hMin, yMin, hMax, yMax, h, builder, ms, light, color, flowTexture); ms.popPose(); msr.rotateY(90); } if (progress != 1) - renderStillTiledFace(Direction.DOWN, hMin, hMin, hMax, hMax, yMin, - builder, ms, light, color, stillTexture); + renderStillTiledFace(Direction.DOWN, hMin, hMin, hMax, hMax, yMin, builder, ms, light, color, stillTexture); ms.popPose(); } - public static void renderFluidBox(FluidStack fluidStack, float xMin, float yMin, float zMin, float xMax, - float yMax, float zMax, MultiBufferSource buffer, PoseStack ms, int light, boolean renderBottom) { - renderFluidBox(fluidStack, xMin, yMin, zMin, xMax, yMax, zMax, getFluidBuilder(buffer), ms, light, renderBottom); + public static void renderFluidBox(FluidStack fluidStack, float xMin, float yMin, float zMin, float xMax, float yMax, + float zMax, MultiBufferSource buffer, PoseStack ms, int light, boolean renderBottom) { + renderFluidBox(fluidStack, xMin, yMin, zMin, xMax, yMax, zMax, getFluidBuilder(buffer), ms, light, + renderBottom); } - public static void renderFluidBox(FluidStack fluidStack, float xMin, float yMin, float zMin, float xMax, - float yMax, float zMax, VertexConsumer builder, PoseStack ms, int light, boolean renderBottom) { + public static void renderFluidBox(FluidStack fluidStack, float xMin, float yMin, float zMin, float xMax, float yMax, + float zMax, VertexConsumer builder, PoseStack ms, int light, boolean renderBottom) { Fluid fluid = fluidStack.getFluid(); - FluidAttributes fluidAttributes = fluid.getAttributes(); + IClientFluidTypeExtensions clientFluid = IClientFluidTypeExtensions.of(fluid); + FluidType fluidAttributes = fluid.getFluidType(); TextureAtlasSprite fluidTexture = Minecraft.getInstance() .getTextureAtlas(InventoryMenu.BLOCK_ATLAS) - .apply(fluidAttributes.getStillTexture(fluidStack)); + .apply(clientFluid.getStillTexture(fluidStack)); - int color = fluidAttributes.getColor(fluidStack); + int color = clientFluid.getTintColor(fluidStack); int blockLightIn = (light >> 4) & 0xF; - int luminosity = Math.max(blockLightIn, fluidAttributes.getLuminosity(fluidStack)); + int luminosity = Math.max(blockLightIn, fluidAttributes.getLightLevel(fluidStack)); light = (light & 0xF00000) | luminosity << 4; Vec3 center = new Vec3(xMin + (xMax - xMin) / 2, yMin + (yMax - yMin) / 2, zMin + (zMax - zMin) / 2); ms.pushPose(); - if (fluidStack.getFluid() - .getAttributes() - .isLighterThanAir()) + if (fluidAttributes.isLighterThanAir()) TransformStack.cast(ms) .translate(center) .rotateX(180) @@ -123,36 +123,36 @@ public class FluidRenderer { if (side.getAxis() .isHorizontal()) { if (side.getAxis() == Axis.X) { - renderStillTiledFace(side, zMin, yMin, zMax, yMax, positive ? xMax : xMin, - builder, ms, light, color, fluidTexture); + renderStillTiledFace(side, zMin, yMin, zMax, yMax, positive ? xMax : xMin, builder, ms, light, + color, fluidTexture); } else { - renderStillTiledFace(side, xMin, yMin, xMax, yMax, positive ? zMax : zMin, - builder, ms, light, color, fluidTexture); + renderStillTiledFace(side, xMin, yMin, xMax, yMax, positive ? zMax : zMin, builder, ms, light, + color, fluidTexture); } } else { - renderStillTiledFace(side, xMin, zMin, xMax, zMax, positive ? yMax : yMin, - builder, ms, light, color, fluidTexture); + renderStillTiledFace(side, xMin, zMin, xMax, zMax, positive ? yMax : yMin, builder, ms, light, color, + fluidTexture); } } ms.popPose(); } - public static void renderStillTiledFace(Direction dir, float left, float down, float right, float up, - float depth, VertexConsumer builder, PoseStack ms, int light, int color, TextureAtlasSprite texture) { + public static void renderStillTiledFace(Direction dir, float left, float down, float right, float up, float depth, + VertexConsumer builder, PoseStack ms, int light, int color, TextureAtlasSprite texture) { FluidRenderer.renderTiledFace(dir, left, down, right, up, depth, builder, ms, light, color, texture, 1); } - public static void renderFlowingTiledFace(Direction dir, float left, float down, float right, float up, - float depth, VertexConsumer builder, PoseStack ms, int light, int color, TextureAtlasSprite texture) { + public static void renderFlowingTiledFace(Direction dir, float left, float down, float right, float up, float depth, + VertexConsumer builder, PoseStack ms, int light, int color, TextureAtlasSprite texture) { FluidRenderer.renderTiledFace(dir, left, down, right, up, depth, builder, ms, light, color, texture, 0.5f); } - public static void renderTiledFace(Direction dir, float left, float down, float right, float up, - float depth, VertexConsumer builder, PoseStack ms, int light, int color, TextureAtlasSprite texture, - float textureScale) { + public static void renderTiledFace(Direction dir, float left, float down, float right, float up, float depth, + VertexConsumer builder, PoseStack ms, int light, int color, TextureAtlasSprite texture, float textureScale) { boolean positive = dir.getAxisDirection() == Direction.AxisDirection.POSITIVE; - boolean horizontal = dir.getAxis().isHorizontal(); + boolean horizontal = dir.getAxis() + .isHorizontal(); boolean x = dir.getAxis() == Axis.X; float shrink = texture.uvShrinkRatio() * 0.25f * textureScale; diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/FluidMovementActorScenes.java b/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/FluidMovementActorScenes.java index a0f01576d..6b861150a 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/FluidMovementActorScenes.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/FluidMovementActorScenes.java @@ -45,7 +45,7 @@ public class FluidMovementActorScenes { Capability fhc = CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY; Class type = FluidTankTileEntity.class; ItemStack bucket = AllFluids.CHOCOLATE.get() - .getAttributes() + .getFluidType() .getBucket(chocolate); scene.world.modifyTileEntity(st, type, te -> te.getCapability(fhc) diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/FluidTankScenes.java b/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/FluidTankScenes.java index bd82d86e7..fde787169 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/FluidTankScenes.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/FluidTankScenes.java @@ -199,7 +199,7 @@ public class FluidTankScenes { scene.idle(90); ItemStack chocBucket = AllFluids.CHOCOLATE.get() - .getAttributes() + .getFluidType() .getBucket(new FluidStack(FluidHelper.convertToStill(AllFluids.CHOCOLATE.get()), 1000)); scene.world.createItemOnBeltLike(util.grid.at(3, 1, 0), Direction.WEST, chocBucket); scene.idle(40); diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/PipeScenes.java b/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/PipeScenes.java index 891b07235..418837fc7 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/PipeScenes.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/PipeScenes.java @@ -527,7 +527,7 @@ public class PipeScenes { FluidStack chocolate = new FluidStack(FluidHelper.convertToStill(AllFluids.CHOCOLATE.get()), 1000); ItemStack bucket = AllFluids.CHOCOLATE.get() - .getAttributes() + .getFluidType() .getBucket(chocolate); ItemStack milkBucket = new ItemStack(Items.MILK_BUCKET); scene.overlay.showControls(new InputWindowElement(filterVec, Pointing.DOWN).rightClick() diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/SpoutScenes.java b/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/SpoutScenes.java index ffde57593..95f67f4d7 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/SpoutScenes.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/SpoutScenes.java @@ -70,7 +70,7 @@ public class SpoutScenes { scene.idle(20); FluidStack honey = new FluidStack(FluidHelper.convertToStill(AllFluids.HONEY.get()), 1000); ItemStack bucket = AllFluids.HONEY.get() - .getAttributes() + .getFluidType() .getBucket(honey); scene.overlay.showControls( new InputWindowElement(util.vector.blockSurface(util.grid.at(2, 3, 2), Direction.NORTH), Pointing.RIGHT) diff --git a/src/main/java/com/simibubi/create/foundation/worldgen/AllWorldFeatures.java b/src/main/java/com/simibubi/create/foundation/worldgen/AllWorldFeatures.java index 8db1b4845..fabcec9b4 100644 --- a/src/main/java/com/simibubi/create/foundation/worldgen/AllWorldFeatures.java +++ b/src/main/java/com/simibubi/create/foundation/worldgen/AllWorldFeatures.java @@ -2,41 +2,47 @@ package com.simibubi.create.foundation.worldgen; import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import com.google.common.collect.ImmutableList; +import com.google.gson.JsonElement; +import com.mojang.serialization.JsonOps; import com.simibubi.create.AllBlocks; import com.simibubi.create.Create; import com.simibubi.create.foundation.utility.Couple; +import net.minecraft.core.HolderSet; import net.minecraft.core.Registry; +import net.minecraft.core.RegistryAccess; import net.minecraft.data.BuiltinRegistries; +import net.minecraft.data.DataGenerator; +import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.biome.Biome.BiomeCategory; -import net.minecraft.world.level.levelgen.GenerationStep; +import net.minecraft.tags.BiomeTags; +import net.minecraft.tags.TagKey; +import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder; -import net.minecraftforge.event.world.BiomeLoadingEvent; +import net.minecraftforge.common.data.JsonCodecProvider; +import net.minecraftforge.common.world.BiomeModifier; +import net.minecraftforge.common.world.ForgeBiomeModifiers.AddFeaturesBiomeModifier; +import net.minecraftforge.data.event.GatherDataEvent; +import net.minecraftforge.registries.ForgeRegistries.Keys; import net.minecraftforge.registries.RegisterEvent; public class AllWorldFeatures { public static final Map ENTRIES = new HashMap<>(); - private static final BiomeFilter OVERWORLD_BIOMES = - (r, b) -> b != BiomeCategory.NETHER && b != BiomeCategory.THEEND && b != BiomeCategory.NONE; - - private static final BiomeFilter NETHER_BIOMES = (r, b) -> b == BiomeCategory.NETHER; - // public static final ConfigDrivenFeatureEntry ZINC_ORE = - register("zinc_ore", 12, 8, OVERWORLD_BIOMES).between(-63, 70) + register("zinc_ore", 12, 8, BiomeTags.IS_OVERWORLD).between(-63, 70) .withBlocks(Couple.create(AllBlocks.ZINC_ORE, AllBlocks.DEEPSLATE_ZINC_ORE)); public static final ConfigDrivenFeatureEntry STRIATED_ORES_OVERWORLD = - register("striated_ores_overworld", 32, 1 / 12f, OVERWORLD_BIOMES).between(-30, 70) + register("striated_ores_overworld", 32, 1 / 12f, BiomeTags.IS_OVERWORLD).between(-30, 70) .withLayerPattern(AllLayerPatterns.SCORIA) .withLayerPattern(AllLayerPatterns.CINNABAR) .withLayerPattern(AllLayerPatterns.MAGNETITE) @@ -45,16 +51,16 @@ public class AllWorldFeatures { .withLayerPattern(AllLayerPatterns.OCHRESTONE); public static final ConfigDrivenFeatureEntry STRIATED_ORES_NETHER = - register("striated_ores_nether", 32, 1 / 12f, NETHER_BIOMES).between(40, 90) + register("striated_ores_nether", 32, 1 / 12f, BiomeTags.IS_NETHER).between(40, 90) .withLayerPattern(AllLayerPatterns.SCORIA_NETHER) .withLayerPattern(AllLayerPatterns.SCORCHIA_NETHER); // private static ConfigDrivenFeatureEntry register(String id, int clusterSize, float frequency, - BiomeFilter biomeFilter) { + TagKey biomeTag) { ConfigDrivenFeatureEntry configDrivenFeatureEntry = new ConfigDrivenFeatureEntry(id, clusterSize, frequency); - configDrivenFeatureEntry.biomeFilter = biomeFilter; + configDrivenFeatureEntry.biomeTag = biomeTag; ENTRIES.put(Create.asResource(id), configDrivenFeatureEntry); return configDrivenFeatureEntry; } @@ -80,17 +86,6 @@ public class AllWorldFeatures { }); } - public static void reload(BiomeLoadingEvent event) { - BiomeGenerationSettingsBuilder generation = event.getGeneration(); - Decoration decoStep = GenerationStep.Decoration.UNDERGROUND_ORES; - ENTRIES.values() - .forEach(entry -> { - ConfigDrivenFeatureEntry value = entry; - if (value.biomeFilter.test(event.getName(), event.getCategory())) - generation.addFeature(decoStep, value.placedFeature); - }); - } - public static void fillConfig(ForgeConfigSpec.Builder builder) { ENTRIES.values() .forEach(entry -> { @@ -114,4 +109,21 @@ public class AllWorldFeatures { Registry.register(Registry.PLACEMENT_MODIFIERS, "create_config_driven", () -> ConfigDrivenDecorator.CODEC); } + public static void generateBiomeModifiers(GatherDataEvent event) { + Map modifiers = new HashMap<>(); + RegistryOps ops = RegistryOps.create(JsonOps.INSTANCE, RegistryAccess.builtinCopy()); + + for (Entry entry : ENTRIES.entrySet()) { + ConfigDrivenFeatureEntry feature = entry.getValue(); + HolderSet biomes = new HolderSet.Named<>(ops.registry(Registry.BIOME_REGISTRY) + .get(), feature.biomeTag); + modifiers.put(entry.getKey(), new AddFeaturesBiomeModifier(biomes, HolderSet.direct(feature.placedFeature), + Decoration.UNDERGROUND_ORES)); + } + + DataGenerator generator = event.getGenerator(); + generator.addProvider(event.includeServer(), JsonCodecProvider.forDatapackRegistry(generator, + event.getExistingFileHelper(), Create.ID, ops, Keys.BIOME_MODIFIERS, modifiers)); + } + } diff --git a/src/main/java/com/simibubi/create/foundation/worldgen/BiomeFilter.java b/src/main/java/com/simibubi/create/foundation/worldgen/BiomeFilter.java index b3cd9e2c9..4f6599610 100644 --- a/src/main/java/com/simibubi/create/foundation/worldgen/BiomeFilter.java +++ b/src/main/java/com/simibubi/create/foundation/worldgen/BiomeFilter.java @@ -1,10 +1,11 @@ package com.simibubi.create.foundation.worldgen; -import java.util.function.BiPredicate; +import java.util.function.Function; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.biome.Biome.BiomeCategory; +import net.minecraft.core.HolderSet; +import net.minecraft.resources.RegistryOps; +import net.minecraft.world.level.biome.Biome; -public interface BiomeFilter extends BiPredicate { +public interface BiomeFilter extends Function, HolderSet> { } diff --git a/src/main/java/com/simibubi/create/foundation/worldgen/ConfigDrivenFeatureEntry.java b/src/main/java/com/simibubi/create/foundation/worldgen/ConfigDrivenFeatureEntry.java index b2b87db7c..f6b15b983 100644 --- a/src/main/java/com/simibubi/create/foundation/worldgen/ConfigDrivenFeatureEntry.java +++ b/src/main/java/com/simibubi/create/foundation/worldgen/ConfigDrivenFeatureEntry.java @@ -12,6 +12,8 @@ import com.tterrag.registrate.util.nullness.NonNullSupplier; import net.minecraft.core.Holder; import net.minecraft.data.worldgen.features.OreFeatures; +import net.minecraft.tags.TagKey; +import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration; @@ -22,7 +24,7 @@ import net.minecraftforge.common.ForgeConfigSpec; public class ConfigDrivenFeatureEntry extends ConfigBase { public final String id; - public BiomeFilter biomeFilter; + public TagKey biomeTag; private NonNullSupplier block; private NonNullSupplier deepblock;