-
Notifications
You must be signed in to change notification settings - Fork 6
Make custom cable
SimElectricity offers a number of cover panel (led, voltage sensor, BuildCraft façade), they have different functions/looks. Their function (Redstone, ability to give off light) relies on their host block and tileEntity (Usually cable). Normally, cable blocks are not full blocks, advanced rendering and collision box implementation defines their complex shape.
All of these demand extremely complicated and boring coding. The good news is, if you just want to create your own cable(similar to the one in package essential) with custom thickness, resistivity and texture, you don't actually need much coding. To do this, follow the steps below:
Create your own Block class, your class should extend BlockCable in the essential package:
public class BlockMyCable extends BlockCable {
public BlockMyCable () {
super("mycable", Material.glass, ItemBlock.class,
new String[]{"copper", "gold", "iron", "glass", "tin"},
new double[]{0.22, 0.22, 0.22, 0.22, 0.22},
new double[]{0.05, 0.01, 0.1, 1, 0.5},
TileMyCable.class);
}
}
- The length of arrays should match
- ItemBlock is not the ItemBlock in minecraft, it is BlockCable.ItemBlock, if you want to implement some advanced feature(e.g. displaying extra information when mouse is hovering above the ItemStack), your ItemBlock class should extend BlockCable.ItemBlock
- Add the following code in your MOD file(the one with @Mod):
public static BlockMyCable myCable;
....
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
....
myCable = new BlockMyCable();
....
Create your own TileEntity Class:
public class TileMyCable extends TileCable{}
Then register it in your MOD file:
@EventHandler
public void init(FMLInitializationEvent event) {
....
GameRegistry.registerTileEntity(TileMyCable.class, "TileMyCable");
....
Note: You can directly use TileCable.class for your own cable, if you do this, you don't have to register it again!
In your client proxy (Methods in ClientProxy only gets called on the client side not server side, things like renders are registered here. If you don't know this, google it, almost every Minecraft Forge Mod should have one):
@Override
public void registerRenders() {
RenderBlockCable.bakeCableModel(MyMod.myCable);
}
In your common proxy, add a stub(skip this if you already have one):
public void registerRenders() {}
Note:
- Don't forget to call proxy.registerRenders(), it's a common mistake 23333333333333333333333333333333333333333333
- proxy is defined by a @SidedProxy
- Texture files should locate in src\main\resources\assets\sime_essential\textures\blocks\cable, a valid texture name looks like: essential_cable_aluminum_thin_inventory.png, essential_cable_copper_medium_copper.png, essential_cable_copper_medium_insulator.png, corresponding to inventory texture (the item on players hand), conductor(copper) and insulator(rubber)
Note: You can have your own cable implementation, cover panel supporting is not compulsory.