Vamos a crear vallas, escaleras, puertas, placas de presión, cualquier cosa de éstas con una única textura en Minecraft.
¿Donde está el truco?
El truco está en que Minecraft detecta este tipo de bloques por un tag, con lo cual, teniendo la clase del bloque hecho y los tags hechos, será simplemente añadir una textura.
Crear bloques
Escaleras
public static final Pair<Block, Item> URANIUM_STAIRS = registerBlock(
"uranium_stairs",
new StairsBlock(URANIUM_BLOCK.getLeft().getDefaultState(), AbstractBlock.Settings.copy(Blocks.IRON_BLOCK))
);
Escalones
public static final Pair<Block, Item> URANIUM_SLAB = registerBlock(
"uranium_slab",
new SlabBlock(AbstractBlock.Settings.copy(Blocks.IRON_BLOCK))
);
Botones
public static final Pair<Block, Item> URANIUM_BUTTON = registerBlock(
"uranium_button",
new ButtonBlock(BlockSetType.STONE, 10, AbstractBlock.Settings.copy(Blocks.IRON_BLOCK))
);
Placa de Presión
public static final Pair<Block, Item> URANIUM_PRESSURE_PLATE = registerBlock(
"uranium_pressure_plate",
new PressurePlateBlock(BlockSetType.STONE, AbstractBlock.Settings.copy(Blocks.IRON_BLOCK))
);
Valla
public static final Pair<Block, Item> URANIUM_FENCE = registerBlock(
"uranium_fence",
new FenceBlock(AbstractBlock.Settings.copy(Blocks.IRON_BLOCK))
);
public static final Pair<Block, Item> URANIUM_FENCE_GATE = registerBlock(
"uranium_fence_gate",
new FenceGateBlock(WoodType.WARPED, AbstractBlock.Settings.copy(Blocks.IRON_BLOCK))
);
Pared
public static final Pair<Block, Item> URANIUM_WALL = registerBlock(
"uranium_wall",
new WallBlock(AbstractBlock.Settings.copy(Blocks.IRON_BLOCK))
);
Puerta
public static final Pair<Block, Item> URANIUM_DOOR = registerBlock(
"uranium_door",
new DoorBlock(BlockSetType.CHERRY, AbstractBlock.Settings.copy(Blocks.IRON_BLOCK))
);
Trampilla
public static final Pair<Block, Item> URANIUM_TRAPDOOR = registerBlock(
"uranium_trapdoor",
new TrapdoorBlock(BlockSetType.CHERRY, AbstractBlock.Settings.copy(Blocks.IRON_BLOCK))
);
Recordad que todos estos ítems los habremos de añadir al Item Group.
Añadir tags
Una vez tenemos los bloques, hay que añadir los tags de los bloques de vallas, puertas de valla y paredes. Esto lo podemos hacer fácilmente desde nuestro BlockTagProvider.
getOrCreateTagBuilder(BlockTags.FENCES)
.add(ModBlocks.URANIUM_FENCE.getLeft());
getOrCreateTagBuilder(BlockTags.FENCE_GATES)
.add(ModBlocks.URANIUM_FENCE_GATE.getLeft());
getOrCreateTagBuilder(BlockTags.WALLS)
.add(ModBlocks.URANIUM_WALL.getLeft());
Añadir Loot Tables
Estos bloques, lo normal es que cuando los destruyamos y se rompan, nos los devuelvan. Para ello, necesitaremos añadir en nuestro LootTableProvider el drop de estos bloques.
addDrop(ModBlocks.URANIUM_STAIRS.getLeft());
addDrop(ModBlocks.URANIUM_BUTTON.getLeft());
addDrop(ModBlocks.URANIUM_PRESSURE_PLATE.getLeft());
addDrop(ModBlocks.URANIUM_FENCE.getLeft());
addDrop(ModBlocks.URANIUM_FENCE_GATE.getLeft());
addDrop(ModBlocks.URANIUM_WALL.getLeft());
addDrop(ModBlocks.URANIUM_TRAPDOOR.getLeft());
addDrop(ModBlocks.URANIUM_DOOR.getLeft(), doorDrops(ModBlocks.URANIUM_DOOR.getLeft()));
addDrop(ModBlocks.URANIUM_SLAB.getLeft(), slabDrops(ModBlocks.URANIUM_SLAB.getLeft()));
Añadir modelos
Todos estos bloques tienen un modelo extraño ya que no son un cubo con 6 caras y punto. Para ello, y para no tener que copiar la textura muchas veces, crearemos un objeto el cual contendrá la textura de nuestro bloque y a partir de ahí generaremos los modelos de los diferentes bloques.
BlockStateModelGenerator.BlockTexturePool uraniumTexturePool = blockStateModelGenerator.registerCubeAllModelTexturePool(ModBlocks.URANIUM_BLOCK.getLeft());
uraniumTexturePool.stairs(ModBlocks.URANIUM_STAIRS.getLeft());
uraniumTexturePool.slab(ModBlocks.URANIUM_SLAB.getLeft());
uraniumTexturePool.button(ModBlocks.URANIUM_BUTTON.getLeft());
uraniumTexturePool.pressurePlate(ModBlocks.URANIUM_PRESSURE_PLATE.getLeft());
uraniumTexturePool.fence(ModBlocks.URANIUM_FENCE.getLeft());
uraniumTexturePool.fenceGate(ModBlocks.URANIUM_FENCE_GATE.getLeft());
uraniumTexturePool.wall(ModBlocks.URANIUM_WALL.getLeft());
blockStateModelGenerator.registerDoor(ModBlocks.URANIUM_DOOR.getLeft());
blockStateModelGenerator.registerTrapdoor(ModBlocks.URANIUM_TRAPDOOR.getLeft());
Además habrá que añadir las texturas de la trampilla, la puerta, y la textura del item de la puerta
Crafteos
Por último queda añadir los crafteos. Yo no voy a crear todos los crafteos pero seguro que vosotros con un poco de paciencia podéis llegar a crear todos.
Y ya estaría, así estamos añadiendo un montón de bloques nuevos con una simple textura en nuestro mod de Fabric.