Created
August 29, 2020 04:03
-
-
Save Commoble/779560ac120dfa5321ae2be1207c231f to your computer and use it in GitHub Desktop.
Flowing Fluid Registry Helper for Minecraft Forge 1.16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FluidTest | |
{ | |
public static final DeferredRegister<Fluid> FLUIDS = DeferredRegister.create(ForgeRegistries.FLUIDS, "modid"); | |
public static final Pair<RegistryObject<ForgeFlowingFluid.Source>, RegistryObject<ForgeFlowingFluid.Flowing>> TEST_FLUIDS = | |
registerFluid("test_fluid", "flowing_test_fluid", | |
ForgeFlowingFluid.Source::new, | |
ForgeFlowingFluid.Flowing::new, | |
FluidAttributes.builder(new ResourceLocation("modid:block/test_fluid_still"), new ResourceLocation("modid:block/test_fluid_flowing"))); | |
public static <SOURCE extends ForgeFlowingFluid.Source, FLOW extends ForgeFlowingFluid.Flowing> // type args | |
Pair<RegistryObject<SOURCE>, RegistryObject<FLOW>> // return type | |
registerFluid(String sourceName, String flowName, | |
Function<ForgeFlowingFluid.Properties, SOURCE> sourceConstructor, | |
Function<ForgeFlowingFluid.Properties, FLOW> flowConstructor, | |
FluidAttributes.Builder attributes) | |
{ | |
// make fake suppliers that will point to the registry objects later | |
SupplierWrapper<SOURCE> sourceWrapper = new SupplierWrapper<>(); | |
SupplierWrapper<FLOW> flowWrapper = new SupplierWrapper<>(); | |
ForgeFlowingFluid.Properties props = new ForgeFlowingFluid.Properties(sourceWrapper, flowWrapper, attributes); | |
RegistryObject<SOURCE> sourceObject = FLUIDS.register(sourceName, () -> sourceConstructor.apply(props)); | |
RegistryObject<FLOW> flowObject = FLUIDS.register(flowName, () -> flowConstructor.apply(props)); | |
// now that the registry objects exist, we can use them as the real suppliers | |
sourceWrapper.setSupplier(sourceObject); | |
flowWrapper.setSupplier(flowObject); | |
return Pair.of(sourceObject, flowObject); | |
} | |
public static class SupplierWrapper<T> implements Supplier<T> | |
{ | |
private Supplier<T> baseSupplier = null; | |
// call this or ten thousand years dungeon | |
public void setSupplier(Supplier<T> supplier) | |
{ | |
this.baseSupplier = supplier; | |
} | |
@Override | |
public T get() | |
{ | |
Objects.requireNonNull(this.baseSupplier); | |
return this.baseSupplier.get(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment