Skip to content

Extending Growthcraft

Alatyami edited this page Feb 10, 2020 · 4 revisions

This page includes how-to's for extending Growthcraft.

Growthcraft Rope Fence

Growthcraft Ropes can be attached to any vanilla or Growthcraft fence. If you want to extend this to your mod, you will need to do the following. The below assumes that you arleady have a custom fence block and its textures.

  1. Create a block class that extends growthcraft.core.common.block.BlockRopeKnot
public class BlockAppleFenceRopeKnot extends BlockRopeKnot {
    public BlockAppleFenceRopeKnot(String unlocalizedName, Block baseFence) {
        super(unlocalizedName, baseFence, YOUR.MODID);
    }
}

Note, the following can vary depending on the structure of your mod.

  1. Define your block in your mod class and instantiate it. In this example, you will want to change the GrowthcraftApplesBlocks.blockAppleFence.getBlock() in the preInit method to the given fence block that you want to enable for the Growthcraft ropes.
public class GrowthcraftApples {
  BlockAppleFenceRopeKnot ropeKnotApple;

  @Mod.EventHandler
  public static void preInit(FMLPreInitializationEvent event) {
    ropeKnotApple = new BlockAppleFenceRopeKnot("rope_knot_apple", 
                          GrowthcraftApplesBlocks.blockAppleFence.getBlock());
  }

  @Mod.EventHandler
  public static void postInit(FMLPostInitializationEvent event) {  
    OreDictionary.registerOre("ropeKnotFence", ropeKnotApple.getBlock());
  }

  @SubscribeEvent
  public void registerBlocks(RegistryEvent.Register<Block> event) {
    ropeKnotApple.registerBlock(registry);
  }

  // We have to register it as an item in order for the ore dictionary to work.
  @SubscribeEvent
  public void registerItems(RegistryEvent.Register<Item> event) {
    ropeKnotApple.registerBlockItem(registry);
  }
  1. Setup your blockstate asset resource. Replacing "growthcraft_apples:rope_knot_apple" with your custom rope knot fence model (see step 4) and "growthcraft_apples:apple_fence_side" with your fence's model.
assets/growthcraft_apples/blockstates/rope_knot_apple.json
{
  "multipart": [
    {
      "apply": { "model": "growthcraft_apples:rope_knot_apple" }
    },
    {
      "when": { "north": 1 },
      "apply": { "model": "growthcraft:rope_fence_side", "uvlock": false }
    },
    {
      "when": { "north": 2 },
      "apply": { "model": "growthcraft_apples:apple_fence_side", "uvlock": true }
    },
    {
      "when": { "east": 1 },
      "apply": { "model": "growthcraft:rope_fence_side", "y": 90, "uvlock": false }
    },
    {
      "when": { "east": 2 },
      "apply": { "model": "growthcraft_apples:apple_fence_side", "y": 90, "uvlock": true }
    },
    {
      "when": { "south": 1 },
      "apply": { "model": "growthcraft:rope_fence_side", "y": 180, "uvlock": false }
    },
    {
      "when": { "south": 2 },
      "apply": { "model": "growthcraft_apples:apple_fence_side", "y": 180, "uvlock": true }
    },
    {
      "when": { "west": 1 },
      "apply": { "model": "growthcraft:rope_fence_side", "y": 270, "uvlock": false }
    },
    {
      "when": { "west": 2 },
      "apply": { "model": "growthcraft_apples:apple_fence_side", "y": 270, "uvlock": true }
    }
  ]
}
  1. Setup your rope knot model. You will need to replace texture 1 with your wood planks texture for your mod's fence model.
assets/growthcraft_apples/models/block/rope_knot_apple.json
{
  "parent": "block/block",
  "textures": {
    "0": "growthcraft:blocks/rope_knot",
    "1": "growthcraft_apples:blocks/apple_planks",
    "particle": "growthcraft:blocks/rope_knot"
  },
  "display": {
    "gui": {
      "rotation": [ 30, 135, 0 ],
      "translation": [ 0, 0, 0],
      "scale":[ 0.625, 0.625, 0.625 ]
    },
    "fixed": {
      "rotation": [ 0, 90, 0 ],
      "translation": [ 0, 0, 0],
      "scale":[ 0.5, 0.5, 0.5 ]
    }
  },
  "elements": [
    {
      "name": "fence_post",
      "from": [ 6.0, 0.0, 6.0 ],
      "to":   [ 10.0, 16.0, 10.0 ],
      "faces": {
        "north": { "texture": "#1", "uv": [ 0.0, 0.0, 4.0, 16.0 ] },
        "east": { "texture": "#1", "uv": [ 0.0, 0.0, 4.0, 16.0 ] },
        "south": { "texture": "#1", "uv": [ 0.0, 0.0, 4.0, 16.0 ] },
        "west": { "texture": "#1", "uv": [ 0.0, 0.0, 4.0, 16.0 ] },
        "up": { "texture": "#1", "uv": [ 0.0, 0.0, 4.0, 4.0 ] },
        "down": { "texture": "#1", "uv": [ 0.0, 0.0, 4.0, 4.0 ] }
      }
    },
    {
      "name": "South",
      "from": [ 5.0, 6.0, 10.0 ],
      "to": [ 11.0, 14.0, 11.0 ],
      "faces": {
        "north": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 8.0 ] },
        "east": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 8.0 ] },
        "south": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 8.0 ] },
        "west": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 8.0 ] },
        "up": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 1.0 ] },
        "down": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 1.0 ] }
      }
    },
    {
      "name": "North",
      "from": [ 5.0, 6.0, 5.0 ],
      "to": [ 11.0, 14.0, 6.0 ],
      "faces": {
        "north": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 8.0 ] },
        "east": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 8.0 ] },
        "south": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 8.0 ] },
        "west": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 8.0 ] },
        "up": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 1.0 ] },
        "down": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 1.0 ] }
      }
    },
    {
      "name": "West",
      "from": [ 5.0, 6.0, 6.0 ],
      "to": [ 6.0, 14.0, 10.0 ],
      "faces": {
        "north": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 8.0 ] },
        "east": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 8.0 ] },
        "south": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 8.0 ] },
        "west": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 8.0 ] },
        "up": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
        "down": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 6.0 ] }
      }
    },
    {
      "name": "East",
      "from": [ 10.0, 6.0, 6.0 ],
      "to": [ 11.0, 14.0, 10.0 ],
      "faces": {
        "north": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 8.0 ] },
        "east": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 8.0 ] },
        "south": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 8.0 ] },
        "west": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 8.0 ] },
        "up": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
        "down": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 6.0 ] }
      }
    }
  ]
}
  1. Add your item model, that will inherit from your block model.
assets/growthcraft_apples/models/item/rope_knot_apple.json
{
  "parent": "growthcraft_apples:block/rope_knot_apple"
}