Last active
December 30, 2018 01:10
-
-
Save yrsegal/38cf26ceae24f8f3964089b96325e531 to your computer and use it in GitHub Desktop.
block creation code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package team.chisel.ctm; | |
import net.minecraft.block.Block; | |
import net.minecraft.block.material.Material; | |
import net.minecraft.client.renderer.block.model.ModelResourceLocation; | |
import net.minecraft.item.Item; | |
import net.minecraft.item.ItemBlock; | |
import net.minecraft.util.ResourceLocation; | |
import net.minecraftforge.client.event.ColorHandlerEvent; | |
import net.minecraftforge.client.event.ModelRegistryEvent; | |
import net.minecraftforge.client.model.ModelLoader; | |
import net.minecraftforge.client.model.ModelLoaderRegistry; | |
import net.minecraftforge.event.RegistryEvent; | |
import net.minecraftforge.fml.common.Mod; | |
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | |
@Mod.EventBusSubscriber | |
public class TestBlocks { | |
private static Block[] blocks = new Block[4]; | |
@SubscribeEvent | |
public static void createBlock(RegistryEvent.Register<Block> event) { | |
blocks = new Block[] { | |
new Block(Material.ROCK).setRegistryName(new ResourceLocation("emissive_tint")).setUnlocalizedName("emissive_tint"), | |
new Block(Material.ROCK).setRegistryName(new ResourceLocation("emissive_tint_same")).setUnlocalizedName("emissive_tint_same"), | |
new Block(Material.ROCK).setRegistryName(new ResourceLocation("normal_tint")).setUnlocalizedName("normal_tint"), | |
new Block(Material.ROCK).setRegistryName(new ResourceLocation("normal_tint_same")).setUnlocalizedName("normal_tint_same") | |
}; | |
event.getRegistry().registerAll(blocks); | |
} | |
@SubscribeEvent | |
public static void createItems(RegistryEvent.Register<Item> event) { | |
for (Block block : blocks) | |
event.getRegistry().register(new ItemBlock(block).setRegistryName(Objects.requireNonNull(block.getRegistryName()))); | |
} | |
@SubscribeEvent | |
public static void createModels(ModelRegistryEvent event) { | |
for (Block block : blocks) | |
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, | |
new ModelResourceLocation(Objects.requireNonNull(block.getRegistryName()), "inventory")); | |
} | |
@SubscribeEvent | |
public static void createItemColors(ColorHandlerEvent.Block event) { | |
for (Block block : blocks) | |
if (!block.getUnlocalizedName().contains("same")) | |
event.getBlockColors().registerBlockColorHandler((state, worldIn, pos, tintIndex) -> Color.HSBtoRGB(tintIndex / 16f, 1f, 1f), block); | |
else | |
event.getBlockColors().registerBlockColorHandler((state, worldIn, pos, tintIndex) -> 0xFFFFFF, block); | |
} | |
@SubscribeEvent | |
public static void createItemColors(ColorHandlerEvent.Item event) { | |
for (Block block : blocks) | |
if (!block.getUnlocalizedName().contains("same")) | |
event.getItemColors().registerItemColorHandler((stack, tintIndex) -> Color.HSBtoRGB(tintIndex / 16f, 1f, 1f), block); | |
else | |
event.getItemColors().registerItemColorHandler((stack, tintIndex) -> 0xFFFFFF, block); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment