-
Notifications
You must be signed in to change notification settings - Fork 754
/
TankModifierModel.java
65 lines (57 loc) · 2.71 KB
/
TankModifierModel.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
package slimeknights.tconstruct.library.client.modifiers;
import net.minecraft.client.resources.model.Material;
import net.minecraft.world.level.material.Fluid;
import net.minecraftforge.fluids.FluidStack;
import slimeknights.tconstruct.library.modifiers.Modifier;
import slimeknights.tconstruct.library.modifiers.ModifierEntry;
import slimeknights.tconstruct.library.tools.capability.fluid.ToolTankHelper;
import slimeknights.tconstruct.library.tools.nbt.IToolStackView;
import javax.annotation.Nullable;
import java.util.function.Function;
/**
* Model for tank modifiers, also displays the fluid
*/
public class TankModifierModel extends FluidModifierModel {
/** Constant unbaked model instance, as they are all the same */
public static final IUnbakedModifierModel UNBAKED_INSTANCE = new Unbaked(ToolTankHelper.TANK_HELPER);
public TankModifierModel(ToolTankHelper helper,
@Nullable Material smallTexture, @Nullable Material largeTexture,
@Nullable Material smallPartial, @Nullable Material largePartial,
@Nullable Material smallFull, @Nullable Material largeFull) {
super(helper, smallTexture, largeTexture, new Material[] { smallPartial, largePartial, smallFull, largeFull });
}
@Nullable
@Override
public Object getCacheKey(IToolStackView tool, ModifierEntry entry) {
FluidStack fluid = helper.getFluid(tool);
if (!fluid.isEmpty()) {
// cache by modifier, fluid, and not being full
return new TankModifierCacheKey(entry.getModifier(), fluid.getFluid(), fluid.getAmount() < helper.getCapacity(tool));
}
return entry.getModifier();
}
@Override
@Nullable
protected Material getTemplate(IToolStackView tool, ModifierEntry entry, FluidStack fluid, boolean isLarge) {
boolean isFull = fluid.getAmount() == helper.getCapacity(tool);
return fluidTextures[(isFull ? 2 : 0) | (isLarge ? 1 : 0)];
}
/**
* Cache key for the model
*/
private record TankModifierCacheKey(Modifier modifier, Fluid fluid, boolean isPartial) {}
public record Unbaked(ToolTankHelper helper) implements IUnbakedModifierModel {
@Nullable
@Override
public IBakedModifierModel forTool(Function<String,Material> smallGetter, Function<String,Material> largeGetter) {
Material smallTexture = smallGetter.apply("");
Material largeTexture = largeGetter.apply("");
if (smallTexture != null || largeTexture != null) {
return new TankModifierModel(helper, smallTexture, largeTexture,
smallGetter.apply("_partial"), largeGetter.apply("_partial"),
smallGetter.apply("_full"), largeGetter.apply("_full"));
}
return null;
}
}
}