-
Notifications
You must be signed in to change notification settings - Fork 95
/
FluidDeferredRegister.java
162 lines (146 loc) · 7.41 KB
/
FluidDeferredRegister.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package slimeknights.mantle.registration.deferred;
import net.minecraft.core.Registry;
import net.minecraft.world.item.BucketItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.material.FlowingFluid;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.ForgeFlowingFluid;
import net.minecraftforge.fluids.ForgeFlowingFluid.Properties;
import net.minecraftforge.registries.RegistryObject;
import slimeknights.mantle.registration.DelayedSupplier;
import slimeknights.mantle.registration.FluidBuilder;
import slimeknights.mantle.registration.ItemProperties;
import slimeknights.mantle.registration.object.FluidObject;
import java.util.function.Function;
import java.util.function.Supplier;
@SuppressWarnings({"unused", "WeakerAccess"})
public class FluidDeferredRegister extends DeferredRegisterWrapper<Fluid> {
private final SynchronizedDeferredRegister<Block> blockRegister;
private final SynchronizedDeferredRegister<Item> itemRegister;
public FluidDeferredRegister(String modID) {
super(Registry.FLUID_REGISTRY, modID);
this.blockRegister = SynchronizedDeferredRegister.create(Registry.BLOCK_REGISTRY, modID);
this.itemRegister = SynchronizedDeferredRegister.create(Registry.ITEM_REGISTRY, modID);
}
@Override
public void register(IEventBus bus) {
super.register(bus);
blockRegister.register(bus);
itemRegister.register(bus);
}
/**
* Registers a fluid to the registry
* @param name Name of the fluid to register
* @param sup Fluid supplier
* @param <I> Fluid type
* @return Fluid to supply
*/
public <I extends Fluid> RegistryObject<I> registerFluid(final String name, final Supplier<? extends I> sup) {
return register.register(name, sup);
}
/**
* 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
* @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, String tagName, FluidBuilder builder, Function<Properties,? extends F> still,
Function<Properties,? extends F> flowing, Function<Supplier<? extends FlowingFluid>,? extends LiquidBlock> block) {
// have to create still and flowing later, as the props need these suppliers
DelayedSupplier<F> stillDelayed = new DelayedSupplier<>();
DelayedSupplier<F> flowingDelayed = new DelayedSupplier<>();
// create block and bucket, they just need a still supplier
RegistryObject<LiquidBlock> blockObj = blockRegister.register(name + "_fluid", () -> block.apply(stillDelayed));
builder.bucket(itemRegister.register(name + "_bucket", () -> new BucketItem(stillDelayed, ItemProperties.BUCKET_PROPS)));
// create props with the suppliers
Properties props = builder.block(blockObj).build(stillDelayed, flowingDelayed);
// create fluids now that we have props
Supplier<F> stillSup = registerFluid(name, () -> still.apply(props));
stillDelayed.setSupplier(stillSup);
Supplier<F> flowingSup = registerFluid("flowing_" + name, () -> flowing.apply(props));
flowingDelayed.setSupplier(flowingSup);
// return the final nice object
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 LiquidBlock> 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.luminosity(lightLevel)).explosionResistance(100f), still, flowing,
fluid -> new LiquidBlock(fluid, Block.Properties.of(material).noCollission().strength(100.0F).noDrops().lightLevel(state -> lightLevel))
);
}
/**
* Registers a fluid with still, flowing, block, and bucket using the default fluid block
* @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 material Block material
* @param lightLevel Block light level
* @param <F> Fluid type
* @return Fluid object
*/
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);
}
/**
* 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);
}
/**
* Registers a fluid with generic still, flowing, block, and bucket using the default Forge fluid
* @param name Fluid name
* @param builder Properties builder
* @param material Block material
* @param lightLevel Block light level
* @return Fluid object
*/
public FluidObject<ForgeFlowingFluid> register(String name, FluidAttributes.Builder builder, Material material, int lightLevel) {
return register(name, name, builder, material, lightLevel);
}
}