/
ItemBlockMetaExtra.java
47 lines (37 loc) · 1.58 KB
/
ItemBlockMetaExtra.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
package slimeknights.tmechworks.items;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.StringUtils;
import scala.actors.threadpool.Arrays;
import slimeknights.mantle.item.ItemBlockMeta;
import java.util.Collection;
public class ItemBlockMetaExtra extends ItemBlockMeta {
private String extra = "";
public ItemBlockMetaExtra(Block block, String... extraData) {
super(block);
if (extraData.length == 0) {
this.extra = "facing=inv";
} else {
Arrays.sort(extraData);
this.extra = StringUtils.join(extraData, ',');
}
}
@SideOnly(Side.CLIENT)
@Override
public void registerItemModels() {
final Item item = this;
final ResourceLocation loc = block.getRegistryName();
for (Comparable o : (Collection<Comparable>) mappingProperty.getAllowedValues()) {
int meta = block.getMetaFromState(block.getDefaultState().withProperty(mappingProperty, o));
String name = mappingProperty.getName(o);
String[] props = (extra + "," + mappingProperty.getName() + "=" + name).split(",");
Arrays.sort(props);
ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(loc, StringUtils.join(props, ',')));
}
}
}