-
Notifications
You must be signed in to change notification settings - Fork 497
/
BlockEngine.java
78 lines (66 loc) · 1.9 KB
/
BlockEngine.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
72
73
74
75
76
77
78
package buildcraft.core;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import buildcraft.core.lib.engines.BlockEngineBase;
import buildcraft.core.lib.engines.TileEngineBase;
public class BlockEngine extends BlockEngineBase {
private final Class[] engineTiles;
private final String[] names;
private final String[] texturePaths;
public BlockEngine() {
super();
setBlockName("engineBlock");
engineTiles = new Class[16];
names = new String[16];
texturePaths = new String[16];
}
@Override
public String getTexturePrefix(int meta, boolean addPrefix) {
if (texturePaths[meta] != null) {
if (addPrefix) {
return texturePaths[meta].replaceAll(":", ":textures/blocks/");
} else {
return texturePaths[meta];
}
} else {
return null;
}
}
@Override
public String getUnlocalizedName(int metadata) {
return names[metadata] != null ? names[metadata] : "unknown";
}
public void registerTile(Class<? extends TileEngineBase> engineTile, int meta, String name, String texturePath) {
if (BCRegistry.INSTANCE.isEnabled("engines", name)) {
engineTiles[meta] = engineTile;
names[meta] = name;
texturePaths[meta] = texturePath;
}
}
@Override
public TileEntity createTileEntity(World world, int metadata) {
try {
return (TileEntity) engineTiles[metadata].newInstance();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void getSubBlocks(Item item, CreativeTabs par2CreativeTabs, List itemList) {
for (int i = 0; i < 16; i++) {
if (engineTiles[i] != null) {
itemList.add(new ItemStack(this, 1, i));
}
}
}
public boolean hasEngine(int meta) {
return engineTiles[meta] != null;
}
}