mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-22 12:59:49 +00:00
Add some tagging logic into the fluid objects
This commit is contained in:
1 parent
bc8b86168a
commit
bc3cc7bfac
3 files changed
+113
-9
No files matched your search
@@ -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<T extends IForgeRegistryEntry<T>>
|
||||
|
||||
/* 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
|
||||
|
||||
@@ -53,6 +53,7 @@ public class FluidDeferredRegister extends DeferredRegisterWrapper<Fluid> {
|
||||
/**
|
||||
* 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<Fluid> {
|
||||
* @param <F> Fluid type
|
||||
* @return Fluid object
|
||||
*/
|
||||
public <F extends ForgeFlowingFluid> FluidObject<F> register(String name, FluidBuilder builder, Function<Properties,? extends F> still,
|
||||
public <F extends ForgeFlowingFluid> FluidObject<F> register(String name, String tagName, FluidBuilder builder, Function<Properties,? extends F> still,
|
||||
Function<Properties,? extends F> flowing, Function<Supplier<? extends FlowingFluid>,? 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<Fluid> {
|
||||
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 <F> Fluid type
|
||||
* @return Fluid object
|
||||
*/
|
||||
public <F extends ForgeFlowingFluid> FluidObject<F> register(String name, FluidBuilder builder, Function<Properties,? extends F> still,
|
||||
Function<Properties,? extends F> flowing, Function<Supplier<? extends FlowingFluid>,? 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 <F> Fluid type
|
||||
* @return Fluid object
|
||||
*/
|
||||
public <F extends ForgeFlowingFluid> FluidObject<F> register(String name, String tagName, FluidAttributes.Builder builder,
|
||||
Function<Properties,? extends F> still, Function<Properties,? extends F> 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<Fluid> {
|
||||
*/
|
||||
public <F extends ForgeFlowingFluid> FluidObject<F> register(String name, FluidAttributes.Builder builder,
|
||||
Function<Properties,? extends F> still, Function<Properties,? extends F> 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<ForgeFlowingFluid> 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<Fluid> {
|
||||
* @return Fluid object
|
||||
*/
|
||||
public FluidObject<ForgeFlowingFluid> 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);
|
||||
}
|
||||
}
|
||||
@@ -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 <F> Fluid class
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
@AllArgsConstructor
|
||||
public class FluidObject<F extends ForgeFlowingFluid> implements Supplier<F>, IItemProvider {
|
||||
// TODO: make final in 1.17
|
||||
protected ResourceLocation id;
|
||||
// TODO: make final in 1.17
|
||||
private IOptionalNamedTag<Fluid> localTag;
|
||||
private IOptionalNamedTag<Fluid> forgeTag;
|
||||
private final Supplier<? extends F> still;
|
||||
private final Supplier<? extends F> flowing;
|
||||
@Nullable
|
||||
private final Supplier<? extends FlowingFluidBlock> block;
|
||||
|
||||
/** Main constructor */
|
||||
public FluidObject(ResourceLocation id, String tagName, Supplier<? extends F> still, Supplier<? extends F> flowing, @Nullable Supplier<? extends FlowingFluidBlock> 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<? extends F> still, Supplier<? extends F> flowing, @Nullable Supplier<? extends FlowingFluidBlock> 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<F extends ForgeFlowingFluid> implements Supplier<F>, II
|
||||
public Item asItem() {
|
||||
return still.get().getFilledBucket();
|
||||
}
|
||||
|
||||
/** Gets the mod local tag for this fluid object */
|
||||
public IOptionalNamedTag<Fluid> getLocalTag() {
|
||||
if (localTag == null) {
|
||||
localTag = FluidTags.createOptional(getId());
|
||||
}
|
||||
return localTag;
|
||||
}
|
||||
|
||||
/** Gets the shared forge tag for this fluid object */
|
||||
public IOptionalNamedTag<Fluid> getForgeTag() {
|
||||
if (forgeTag == null) {
|
||||
forgeTag = FluidTags.createOptional(new ResourceLocation("forge", getId().getPath()));
|
||||
}
|
||||
return forgeTag;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user