diff --git a/src/main/java/slimeknights/mantle/registration/deferred/DeferredRegisterWrapper.java b/src/main/java/slimeknights/mantle/registration/deferred/DeferredRegisterWrapper.java index 76707bc..fe7c2ce 100644 --- a/src/main/java/slimeknights/mantle/registration/deferred/DeferredRegisterWrapper.java +++ b/src/main/java/slimeknights/mantle/registration/deferred/DeferredRegisterWrapper.java @@ -1,6 +1,7 @@ package slimeknights.mantle.registration.deferred; import net.minecraft.util.IStringSerializable; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.IForgeRegistry; @@ -35,6 +36,15 @@ public abstract class DeferredRegisterWrapper> /* Utilities */ + /** + * Gets a resource location object for the given name + * @param name Name + * @return Resource location string + */ + protected ResourceLocation resource(String name) { + return new ResourceLocation(modID, name); + } + /** * Gets a resource location string for the given name * @param name Name diff --git a/src/main/java/slimeknights/mantle/registration/deferred/FluidDeferredRegister.java b/src/main/java/slimeknights/mantle/registration/deferred/FluidDeferredRegister.java index 88009f6..c5141bf 100644 --- a/src/main/java/slimeknights/mantle/registration/deferred/FluidDeferredRegister.java +++ b/src/main/java/slimeknights/mantle/registration/deferred/FluidDeferredRegister.java @@ -53,6 +53,7 @@ public class FluidDeferredRegister extends DeferredRegisterWrapper { /** * Registers a fluid with still, flowing, block, and bucket * @param name Fluid name + * @param tagName Name for tagging under forge * @param builder Properties builder * @param still Function to create still from the properties * @param flowing Function to create flowing from the properties @@ -60,7 +61,7 @@ public class FluidDeferredRegister extends DeferredRegisterWrapper { * @param Fluid type * @return Fluid object */ - public FluidObject register(String name, FluidBuilder builder, Function still, + public FluidObject register(String name, String tagName, FluidBuilder builder, Function still, Function flowing, Function,? extends FlowingFluidBlock> block) { // have to create still and flowing later, as the props need these suppliers @@ -81,7 +82,42 @@ public class FluidDeferredRegister extends DeferredRegisterWrapper { flowingDelayed.setSupplier(flowingSup); // return the final nice object - return new FluidObject<>(stillSup, flowingSup, blockObj); + return new FluidObject<>(resource(name), tagName, stillSup, flowingSup, blockObj); + } + + /** + * Registers a fluid with still, flowing, block, bucket, and a common forgen name + * @param name Fluid name + * @param builder Properties builder + * @param still Function to create still from the properties + * @param flowing Function to create flowing from the properties + * @param block Function to create block from the fluid supplier + * @param Fluid type + * @return Fluid object + */ + public FluidObject register(String name, FluidBuilder builder, Function still, + Function flowing, Function,? extends FlowingFluidBlock> block) { + return register(name, name, builder, still, flowing, block); + } + + /** + * Registers a fluid with still, flowing, block, and bucket using the default fluid block + * @param name Fluid name + * @param tagName Name for tagging under forge + * @param builder Properties builder + * @param still Function to create still from the properties + * @param flowing Function to create flowing from the properties + * @param material Block material + * @param lightLevel Block light level + * @param Fluid type + * @return Fluid object + */ + public FluidObject register(String name, String tagName, FluidAttributes.Builder builder, + Function still, Function flowing, Material material, int lightLevel) { + return register( + name, tagName, new FluidBuilder(builder).explosionResistance(100f), still, flowing, + (fluid) -> new FlowingFluidBlock(fluid, Block.Properties.create(material).doesNotBlockMovement().hardnessAndResistance(100.0F).noDrops().setLightLevel((state) -> lightLevel)) + ); } /** @@ -97,11 +133,20 @@ public class FluidDeferredRegister extends DeferredRegisterWrapper { */ public FluidObject register(String name, FluidAttributes.Builder builder, Function still, Function flowing, Material material, int lightLevel) { + return register(name, name, builder, still, flowing, material, lightLevel); + } - return register( - name, new FluidBuilder(builder).explosionResistance(100f), still, flowing, - (fluid) -> new FlowingFluidBlock(fluid, Block.Properties.create(material).doesNotBlockMovement().hardnessAndResistance(100.0F).noDrops().setLightLevel((state) -> lightLevel)) - ); + /** + * Registers a fluid with generic still, flowing, block, and bucket using the default Forge fluid + * @param name Fluid name + * @param tagName Name for tagging under forge + * @param builder Properties builder + * @param material Block material + * @param lightLevel Block light level + * @return Fluid object + */ + public FluidObject register(String name, String tagName, FluidAttributes.Builder builder, Material material, int lightLevel) { + return register(name, tagName, builder, ForgeFlowingFluid.Source::new, ForgeFlowingFluid.Flowing::new, material, lightLevel); } /** @@ -113,6 +158,6 @@ public class FluidDeferredRegister extends DeferredRegisterWrapper { * @return Fluid object */ public FluidObject register(String name, FluidAttributes.Builder builder, Material material, int lightLevel) { - return register(name, builder, ForgeFlowingFluid.Source::new, ForgeFlowingFluid.Flowing::new, material, lightLevel); + return register(name, name, builder, material, lightLevel); } } diff --git a/src/main/java/slimeknights/mantle/registration/object/FluidObject.java b/src/main/java/slimeknights/mantle/registration/object/FluidObject.java index ee10205..388f3af 100644 --- a/src/main/java/slimeknights/mantle/registration/object/FluidObject.java +++ b/src/main/java/slimeknights/mantle/registration/object/FluidObject.java @@ -1,9 +1,12 @@ package slimeknights.mantle.registration.object; -import lombok.AllArgsConstructor; import net.minecraft.block.FlowingFluidBlock; +import net.minecraft.fluid.Fluid; import net.minecraft.item.Item; +import net.minecraft.tags.FluidTags; import net.minecraft.util.IItemProvider; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.Tags.IOptionalNamedTag; import net.minecraftforge.fluids.ForgeFlowingFluid; import javax.annotation.Nullable; @@ -15,13 +18,43 @@ import java.util.function.Supplier; * @param Fluid class */ @SuppressWarnings("WeakerAccess") -@AllArgsConstructor public class FluidObject implements Supplier, IItemProvider { + // TODO: make final in 1.17 + protected ResourceLocation id; + // TODO: make final in 1.17 + private IOptionalNamedTag localTag; + private IOptionalNamedTag forgeTag; private final Supplier still; private final Supplier flowing; @Nullable private final Supplier block; + /** Main constructor */ + public FluidObject(ResourceLocation id, String tagName, Supplier still, Supplier flowing, @Nullable Supplier block) { + this.id = id; + this.localTag = FluidTags.createOptional(id); + this.forgeTag = FluidTags.createOptional(new ResourceLocation("forge", tagName)); + this.still = still; + this.flowing = flowing; + this.block = block; + } + + /** @deprecated Use constructor with id and tag name parameter */ + @Deprecated + public FluidObject(Supplier still, Supplier flowing, @Nullable Supplier block) { + this.still = still; + this.flowing = flowing; + this.block = block; + } + + /** Gets the ID for this fluid object */ + public ResourceLocation getId() { + if (id == null) { + id = Objects.requireNonNull(getStill().getRegistryName(), "Fluid has null ID"); + } + return id; + } + /** * Gets the still form of this fluid * @return Still form @@ -63,4 +96,20 @@ public class FluidObject implements Supplier, II public Item asItem() { return still.get().getFilledBucket(); } + + /** Gets the mod local tag for this fluid object */ + public IOptionalNamedTag getLocalTag() { + if (localTag == null) { + localTag = FluidTags.createOptional(getId()); + } + return localTag; + } + + /** Gets the shared forge tag for this fluid object */ + public IOptionalNamedTag getForgeTag() { + if (forgeTag == null) { + forgeTag = FluidTags.createOptional(new ResourceLocation("forge", getId().getPath())); + } + return forgeTag; + } }