1
|
|
|
package de.kleiner3.lasertag.block.models; |
2
|
|
|
|
3
|
|
|
import com.mojang.datafixers.util.Pair; |
4
|
|
|
import de.kleiner3.lasertag.LasertagMod; |
5
|
|
|
import net.fabricmc.api.EnvType; |
6
|
|
|
import net.fabricmc.api.Environment; |
7
|
|
|
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter; |
8
|
|
|
import net.minecraft.client.render.model.UnbakedModel; |
9
|
|
|
import net.minecraft.client.texture.Sprite; |
10
|
|
|
import net.minecraft.client.texture.SpriteAtlasTexture; |
11
|
|
|
import net.minecraft.client.util.SpriteIdentifier; |
12
|
|
|
import net.minecraft.util.Identifier; |
13
|
|
|
import net.minecraft.util.math.Direction; |
14
|
|
|
|
15
|
|
|
import java.util.ArrayList; |
16
|
|
|
import java.util.Collection; |
17
|
|
|
import java.util.Set; |
18
|
|
|
import java.util.function.Function; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Base class for all simple emissive block models |
22
|
|
|
* |
23
|
|
|
* @author Étienne Muser |
24
|
|
|
*/ |
25
|
|
|
@Environment(EnvType.CLIENT) |
26
|
|
|
public abstract class EmissiveBlockModel extends AbstractEmissiveBlockModel { |
27
|
|
|
|
28
|
|
|
private final SpriteIdentifier textureSpriteId; |
29
|
|
|
private final SpriteIdentifier glowTextureSpriteId; |
30
|
|
|
|
31
|
|
|
private Sprite textureSprite; |
32
|
|
|
private Sprite glowTextureSprite; |
33
|
|
|
|
34
|
|
|
public EmissiveBlockModel(String texturePath, String glowTexturePath) { |
35
|
|
|
|
36
|
|
|
textureSpriteId = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new Identifier(LasertagMod.ID, texturePath)); |
37
|
|
|
glowTextureSpriteId = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new Identifier(LasertagMod.ID, glowTexturePath)); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
@Override |
41
|
|
|
public Collection<SpriteIdentifier> getTextureDependencies(Function<Identifier, UnbakedModel> unbakedModelGetter, Set<Pair<String, String>> unresolvedTextureReferences) { |
42
|
|
|
// The textures this model (and all its model dependencies, and their dependencies, etc...!) depends on. |
43
|
|
|
|
44
|
|
|
var textureDependencies = new ArrayList<SpriteIdentifier>(2); |
45
|
|
|
|
46
|
|
|
textureDependencies.add(textureSpriteId); |
47
|
|
|
textureDependencies.add(glowTextureSpriteId); |
48
|
|
|
|
49
|
|
|
return textureDependencies; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
@Override |
53
|
|
|
protected void getSprites(Function<SpriteIdentifier, Sprite> textureGetter) { |
54
|
|
|
|
55
|
|
|
textureSprite = textureGetter.apply(textureSpriteId); |
56
|
|
|
glowTextureSprite = textureGetter.apply(glowTextureSpriteId); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
@Override |
60
|
|
|
public Sprite getParticleSprite() { |
61
|
|
|
// Block break particle |
62
|
|
|
return textureSprite; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
@Override |
66
|
|
|
protected void addTextureToUnbakedModel(QuadEmitter emitter) { |
67
|
|
|
|
68
|
|
|
for(Direction direction : Direction.values()) { |
69
|
|
|
|
70
|
|
|
addTexture(direction, textureSprite, glowTextureSprite, emitter, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|