-
Notifications
You must be signed in to change notification settings - Fork 6
Make custom cable
One of SimElectricity's greatest feature is cover panel (led, voltage sensor, façades), they offer different functions and have different appearance. Their function (Redstone, ability to give off light) relies on their host block and tileEntity (Usually cable). Cable blocks are not ordinary blocks, in most case they require advanced rendering and collision box implementation.
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, actually you don't need much coding. To do this, follow the steps below:
You should create an enum which implements the ISECableMeta interface. Here you should state the resistivity and thickness of each cable type. Resistivity is handled on server only and thickness is used in client-side rendering only.
public static enum CableTypes implements ISECableMeta {
copper(0.22F, 0.05F),
silver(0.22F, 0.04F),
gold(0.22F, 0.02F);
private final float thickness;
private final float resistivity;
CableTypes(float thickness, float resistivity) {
this.thickness = thickness;
this.resistivity = resistivity;
}
public float thickness() {
return this.thickness;
}
public float resistivity() {
return this.resistivity;
}
}
Create your own Block class, your class should extend simelectricity.essential.cable.BlockCable in the essential package:
public class BlockMyCable extends BlockCable implements {
private BlockCable(ISECableMeta cableData) {
this("cable_name",
cableData,
Block.Properties.create(Material.GLASS).hardnessAndResistance(0.2F, 10.0F).sound(SoundType.METAL).notSolid()
, ItemBlockBase.class,
(new Item.Properties()).group(SEAPI.SETab),
TileCable.class);
}
public static BlockCable[] create() {
BlockCable[] ret = new BlockCable[CableTypes.values().length];
for (ISECableMeta cableData: CableTypes.values()) {
ret[cableData.ordinal()] = new BlockCable(cableData);
}
return ret;
}
......
- In Block Registration Event, first instantiate all cable types:
BlockCable[] blockCable = BlockCable.create();, then register all of them:registry.registerAll(blockCable ) - In Item Registration Event, register ItemBlocks for them:
for (BlockBase block: blocks)
registry.register(block.itemBlock);
You can either create your own TileEntity Class that extends TileCable or just simply use TileCable. Don't forget to register the TileEntity for all of your cable types!
- You need to have a json model file in
assets/MODID/models/itemto provide the inventory item model, the file name is like:cable_name_copper.json. The rule is that the cable name joined with the type name, seperated by_, then followed by.json.
{
"parent": "item/generated",
"textures": {
"layer0": "MODID:item/cable_name_copper_inventory"
}
}
- To render the cable in the world, first you need to by-pass the json blockstate loader. Create a file in
assets/MODID/blockstates, file name is the same as in step 1:
{
"variants": {
"waterlogged=false": {
"model": "minecraft:block/torch"
},
"waterlogged=true": {
"model": "minecraft:block/torch"
}
}
}
- Create your CableModel:
CableModel cableModel;
...
cableModel = new CableModel(blockCable);
Cable textures should be placed in assets/MODID/models/block/cable/, there are two possible suffixies: "_insulator" and "_conductor". File names are like: "cable_name_copper_insulator.png" and "cable_name_copper_conductor.png".
4. Call cableModel.onPreTextureStitchEvent in TextureStitchEvent.Pre event (bus = Mod.EventBusSubscriber.Bus.MOD).
5. Call cableModel.onModelBakeEvent in ModelBakeEvent event (bus = Mod.EventBusSubscriber.Bus.MOD), and then replace the dummy block model with CableModel:
event.getModelRegistry().put(BlockModelShapes.getModelLocation(blockstate), cableModel);
You need to have one CableModel for each instances of BlockCable
By default, TileCable and BlockCable supports cover panels. To display facade panels correctly, you need to register it:
registerColoredFacadeHost(blockCable)
Note: You can have your own cable implementation, cover panel supporting is not compulsory.