Repository navigation
Expand file tree
/
Copy pathMCreatorHelper.java
More file actions
217 lines (186 loc) · 6.87 KB
/
Copy pathMCreatorHelper.java
File metadata and controls
217 lines (186 loc) · 6.87 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package com.fluidphysics.mcreator;
import com.fluidphysics.core.*;
/**
* MCreator integration helper class.
* Provides simplified interfaces for MCreator to interact with the fluid physics system.
*/
public class MCreatorHelper {
// Singleton instance of the fluid simulator
private static FluidSimulator fluidSimulator;
// Singleton instance of the fluid registry
private static FluidRegistry fluidRegistry;
// Configuration
private static FluidPhysicsConfig config;
/**
* Initializes the fluid physics system with the specified configuration.
* Call this method from your MCreator mod's initialization procedure.
*
* @param simulationPrecision Simulation precision (1-4)
* @param flowRate Flow rate multiplier
* @param enablePressure Whether to enable pressure-based flow
* @param enableMomentum Whether to enable momentum-based flow
* @param enableFiniteFluids Whether to enable finite fluids
* @param updateFrequency How often the simulation runs (in ticks)
* @param activeRange Maximum distance for active fluid simulation
*/
public static void initialize(int simulationPrecision, float flowRate,
boolean enablePressure, boolean enableMomentum,
boolean enableFiniteFluids, int updateFrequency,
int activeRange) {
// Create configuration
config = new FluidPhysicsConfig(
simulationPrecision,
flowRate,
enablePressure,
enableMomentum,
enableFiniteFluids,
updateFrequency,
activeRange
);
// Initialize registry and simulator
fluidRegistry = FluidRegistry.getInstance(config);
fluidSimulator = new FluidSimulator(config);
System.out.println("[FluidPhysics] Initialized fluid physics system");
}
/**
* Processes a world tick for the fluid simulation.
* Call this method from your MCreator mod's world tick procedure.
*
* @param world The Minecraft world
*/
public static void processTick(Object world) {
// Skip if not initialized
if (fluidSimulator == null || fluidRegistry == null) {
return;
}
// Process the tick
fluidSimulator.processTick((net.minecraft.world.level.Level) world);
}
/**
* Registers a fluid block for processing.
* Call this method from your MCreator mod's block place procedure.
*
* @param world The Minecraft world
* @param x The x coordinate
* @param y The y coordinate
* @param z The z coordinate
*/
public static void registerFluidBlock(Object world, int x, int y, int z) {
// Skip if not initialized
if (fluidRegistry == null) {
return;
}
// Create block position
net.minecraft.core.BlockPos pos = new net.minecraft.core.BlockPos(x, y, z);
// Get block state
net.minecraft.world.level.Level level = (net.minecraft.world.level.Level) world;
net.minecraft.world.level.block.state.BlockState state = level.getBlockState(pos);
// Register the block
fluidRegistry.registerFluidBlock(pos, state);
}
/**
* Unregisters a fluid block.
* Call this method from your MCreator mod's block break procedure.
*
* @param x The x coordinate
* @param y The y coordinate
* @param z The z coordinate
*/
public static void unregisterFluidBlock(int x, int y, int z) {
// Skip if not initialized
if (fluidRegistry == null) {
return;
}
// Create block position
net.minecraft.core.BlockPos pos = new net.minecraft.core.BlockPos(x, y, z);
// Unregister the block
fluidRegistry.unregisterFluidBlock(pos);
}
/**
* Gets the fluid level at the specified position.
* Use this method in your MCreator mod's rendering procedures.
*
* @param x The x coordinate
* @param y The y coordinate
* @param z The z coordinate
* @return The fluid level (0-8), or 0 if no fluid
*/
public static int getFluidLevel(int x, int y, int z) {
// Skip if not initialized
if (fluidRegistry == null) {
return 0;
}
// Create block position
net.minecraft.core.BlockPos pos = new net.minecraft.core.BlockPos(x, y, z);
// Get fluid data
FluidLevelData fluidData = fluidRegistry.getFluidData(pos);
// Return level
return fluidData != null ? fluidData.getLevel() : 0;
}
/**
* Checks if a block is a fluid source.
* Use this method in your MCreator mod's block behavior procedures.
*
* @param x The x coordinate
* @param y The y coordinate
* @param z The z coordinate
* @return True if the block is a fluid source
*/
public static boolean isFluidSource(int x, int y, int z) {
// Skip if not initialized
if (fluidRegistry == null) {
return false;
}
// Create block position
net.minecraft.core.BlockPos pos = new net.minecraft.core.BlockPos(x, y, z);
// Get fluid data
FluidLevelData fluidData = fluidRegistry.getFluidData(pos);
// Return source status
return fluidData != null && fluidData.isSource();
}
/**
* Gets the flow direction at the specified position.
* Use this method in your MCreator mod's rendering procedures.
*
* @param x The x coordinate
* @param y The y coordinate
* @param z The z coordinate
* @return The flow direction as a string (NORTH, EAST, SOUTH, WEST, UP, DOWN, NONE)
*/
public static String getFlowDirection(int x, int y, int z) {
// Skip if not initialized
if (fluidRegistry == null) {
return "NONE";
}
// Create block position
net.minecraft.core.BlockPos pos = new net.minecraft.core.BlockPos(x, y, z);
// Get fluid data
FluidLevelData fluidData = fluidRegistry.getFluidData(pos);
// Return direction
return fluidData != null ? fluidData.getMomentum().name() : "NONE";
}
/**
* Gets the fluid simulator instance.
*
* @return The fluid simulator
*/
public static FluidSimulator getFluidSimulator() {
return fluidSimulator;
}
/**
* Gets the fluid registry instance.
*
* @return The fluid registry
*/
public static FluidRegistry getFluidRegistry() {
return fluidRegistry;
}
/**
* Gets the configuration instance.
*
* @return The configuration
*/
public static FluidPhysicsConfig getConfig() {
return config;
}
}