-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathAvatarItemRenderRegister.java
More file actions
111 lines (81 loc) · 3.55 KB
/
AvatarItemRenderRegister.java
File metadata and controls
111 lines (81 loc) · 3.55 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
/*
This file is part of AvatarMod.
AvatarMod is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
AvatarMod is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with AvatarMod. If not, see <http://www.gnu.org/licenses/>.
*/
package com.crowsofwar.avatar.client;
import com.crowsofwar.avatar.common.item.AvatarItem;
import com.crowsofwar.avatar.common.item.AvatarItems;
import com.crowsofwar.avatar.common.item.ItemScroll.ScrollType;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import static net.minecraftforge.client.model.ModelLoader.setCustomModelResourceLocation;
/**
* @author CrowsOfWar
*/
public class AvatarItemRenderRegister {
private static ModelResourceLocation[] locationsRegular, locationsGlow;
public static void register() {
MinecraftForge.EVENT_BUS.register(new AvatarItemRenderRegister());
// Setup scrolls
locationsRegular = new ModelResourceLocation[ScrollType.amount()];
locationsGlow = new ModelResourceLocation[ScrollType.amount()];
for (int i = 0; i < ScrollType.amount(); i++) {
ScrollType type = ScrollType.get(i);
locationsRegular[i] = new ModelResourceLocation("avatarmod:scroll_" + type.displayName(),
"inventory");
locationsGlow[i] = new ModelResourceLocation("avatarmod:scroll_" + type.displayName() + "_glow",
"inventory");
setCustomModelResourceLocation(AvatarItems.itemScroll, i, locationsGlow[i]);
setCustomModelResourceLocation(AvatarItems.itemScroll, i, locationsRegular[i]);
}
for (int i = 0; i <= 5; i++) {
register(AvatarItems.itemWaterPouch, i);
}
register(AvatarItems.itemBisonWhistle);
register(AvatarItems.airbenderStaff);
for (int i = 0; i <= 3; i++) {
register(AvatarItems.itemBisonArmor, i);
register(AvatarItems.itemBisonSaddle, i);
register(AvatarItems.itemOstrichEquipment, i);
}
}
/**
* Registers the specified item with the given metadata(s). Maps it to
* {unlocalizedName}.json. Note that if no metadata is specified, the item
* will not be registered.
*/
private static void register(AvatarItem item, int... metadata) {
if (metadata.length == 0) {
metadata = new int[1];
}
for (int meta : metadata) {
ModelResourceLocation mrl = new ModelResourceLocation("avatarmod:" + item.getModelName(meta),
"inventory");
ModelLoader.setCustomModelResourceLocation(item.item(), meta, mrl);
}
}
@SubscribeEvent
public void modelBake(ModelBakeEvent e) {
for (int i = 0; i < ScrollType.amount(); i++) {
ModelResourceLocation mrlRegular = locationsRegular[i];
ModelResourceLocation mrlGlow = locationsGlow[i];
IBakedModel currentModel = e.getModelRegistry().getObject(mrlRegular);
ScrollsPerspectiveModel customModel = new ScrollsPerspectiveModel(mrlRegular, mrlGlow,
currentModel, e.getModelRegistry().getObject(mrlGlow));
e.getModelRegistry().putObject(mrlRegular, customModel);
}
}
}