-
Notifications
You must be signed in to change notification settings - Fork 755
/
NormalModifierModel.java
71 lines (63 loc) · 2.9 KB
/
NormalModifierModel.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
package slimeknights.tconstruct.library.client.modifiers;
import com.google.gson.JsonObject;
import com.mojang.math.Transformation;
import lombok.RequiredArgsConstructor;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.Material;
import net.minecraft.util.GsonHelper;
import slimeknights.mantle.client.model.util.MantleItemLayerModel;
import slimeknights.mantle.data.loadable.common.ColorLoadable;
import slimeknights.mantle.util.ItemLayerPixels;
import slimeknights.tconstruct.library.modifiers.ModifierEntry;
import slimeknights.tconstruct.library.tools.nbt.IToolStackView;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.function.Consumer;
import java.util.function.Function;
/**
* Default modifier model loader, loads a single texture from the standard path
*/
@RequiredArgsConstructor
public class NormalModifierModel implements IBakedModifierModel {
/** Constant unbaked model instance, as they are all the same */
public static final IUnbakedModifierModel UNBAKED_INSTANCE = new Unbaked(-1, 0);
/** Textures to show */
@Nullable
private final Material small;
@Nullable
private final Material large;
/** Color to apply to the texture */
private final int color;
/** Luminosity to apply to the texture */
private final int luminosity;
public NormalModifierModel(@Nullable Material smallTexture, @Nullable Material largeTexture) {
this(smallTexture, largeTexture, -1, 0);
}
@Override
public void addQuads(IToolStackView tool, ModifierEntry entry, Function<Material,TextureAtlasSprite> spriteGetter, Transformation transforms, boolean isLarge, int startTintIndex, Consumer<Collection<BakedQuad>> quadConsumer, @Nullable ItemLayerPixels pixels) {
quadConsumer.accept(MantleItemLayerModel.getQuadsForSprite(color, -1, spriteGetter.apply(isLarge ? large : small), transforms, luminosity, pixels));
}
private record Unbaked(int color, int luminosity) 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 NormalModifierModel(smallTexture, largeTexture, color, luminosity);
}
return null;
}
@Override
public IUnbakedModifierModel configure(JsonObject data) {
// parse the two keys, if we ended up with something new create an instance
int color = ColorLoadable.ALPHA.getOrDefault(data, "color", -1);
int luminosity = GsonHelper.getAsInt(data, "luminosity");
if (color != this.color || luminosity != this.luminosity) {
return new Unbaked(color, luminosity);
}
return this;
}
}
}