February 24, 201610 yr Hi everyone. Coding quite tired at the moment, and I have run into an error. I have a Coal Generator block with facing and on-off variants. I currently have implemented everything and it works fairly well, altough the blockstate/model JSONs aren't working as intended. Can any of you give a look at it, since I am fairly new to 1.8 and still unfamiliar with such errors? [spoiler=BlockCoalGenerator.java] package projectcoal.common.block.energy; import com.google.common.base.Predicate; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import projectcoal.api.energy.Energy; import projectcoal.api.energy.block.prefab.BlockEnergySourcePC; import projectcoal.client.Gui; import projectcoal.client.helper.GuiHelper; import projectcoal.common.tileentity.energy.TileCoalGenerator; @SuppressWarnings("rawtypes") public class BlockCoalGenerator extends BlockEnergySourcePC { public static final PropertyDirection FACING = PropertyDirection.create("facing", (Predicate) EnumFacing.Plane.HORIZONTAL); public static final PropertyBool BURNING = PropertyBool.create("burning"); public BlockCoalGenerator() { super(Energy.ELECTRICITY, Material.iron, 1.5F, 1.5F); setDefaultState(blockState.getBaseState().withProperty(BURNING, false).withProperty(FACING, EnumFacing.NORTH)); } @Override public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(FACING, placer.getHorizontalFacing().getOpposite()); } @Override public IBlockState getStateFromMeta(int meta) { boolean isBurning = (meta >> 2) != 0; return getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta & 3)).withProperty(BURNING, isBurning); } @Override public int getMetaFromState(IBlockState blockState) { int rotationBit = ((EnumFacing) blockState.getValue(FACING)).getHorizontalIndex(); int burningBit = ((Boolean) blockState.getValue(BURNING)).booleanValue() ? 1 : 0; return burningBit << 2 | rotationBit; } @Override protected BlockState createBlockState() { return new BlockState(this, new IProperty[] { BURNING, FACING }); } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileCoalGenerator(); } @Override public boolean useCustomRender() { return false; } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) { if (!player.isSneaking()) { GuiHelper.openGui(Gui.COAL_GENERATOR, world, pos, player); } else { rotateBlock(world, pos, side); } return !player.isSneaking(); } public static void setState(boolean isBurning, World world, BlockPos pos) { IBlockState blockState = world.getBlockState(pos); world.setBlockState(pos, blockState.withProperty(BURNING, isBurning), 3); } } [spoiler=BlockState JSON] { "defaults": { "model": "projectcoal:block_coal_generator" }, variants: { "burning" : {- "true": { "textures": { "front": "projectcoal:blocks/coal_generator_front", } }, "false": { "textures": { "front": "projectcoal:blocks/coal_generator_front_on", } } }, "facing": { "north": { }, "south": { "y": 180 }, "east": { "y": 90 }, "west": { "y": 270 } } } } [spoiler=Block Model JSON] { "parent": "block/orientable", "textures": { "top": "projectcoal:blocks/machine_connection", "bottom": "projectcoal:blocks/machine_side", "front": "projectcoal:blocks/coal_generator_front", "side": "projectcoal:blocks/machine_side" } } I suppose that's everything needed. Let me know if you need any more files or info. Going to rest a while now, thanks in advance if you happen to spot any issue, as I really couldn't. By the way, the console tells me that it couldn't load the model definition for projectcoal:block_coal_generator#burning=someValue,facing=someValue Oh, about to forget: [spoiler=BlockRegistry.java] public class BlockRegistry { private static Map<String, ItemStack> blockMap = new HashMap<String, ItemStack>(); public static void registerBlocks() { registerBlock(new BlockWorktable().setUnlocalizedName("block_worktable")); registerBlock(new BlockSieve().setUnlocalizedName("block_sieve")); registerBlock(new BlockNetherLog().setUnlocalizedName("block_log_nether")); registerBlock(new BlockNetherLeaves().setUnlocalizedName("block_leaves_nether")); registerBlockWithVariants(new BlockOre().setUnlocalizedName("block_ore"), ItemBlockOre.class, BlockOre.EnumType.class); registerBlock(new BlockCoalGenerator().setUnlocalizedName("block_coal_generator")); registerBlock(new BlockElectricConduit().setUnlocalizedName("block_electric_conduit")); } public static void registerTiles() { registerTile(TileWorktable.class, "tile_worktable"); registerTile(TileSieve.class, "tile_sieve"); registerTile(TileCoalGenerator.class, "tile_coal_generator"); } public static void registerBlockModels() { Iterator<Entry<String, ItemStack>> iterator = blockMap.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, ItemStack> entry = (Entry<String, ItemStack>) iterator.next(); registerBlockModel(entry.getValue().getItem(), entry.getValue().getMetadata(), entry.getKey()); } } public static void registerBlock(Block block) { GameRegistry.registerBlock(block, block.getUnlocalizedName().replace("tile.", "")); blockMap.put(block.getUnlocalizedName().replace("tile.", ""), new ItemStack(block, 1, 0)); } public static void registerBlock(Block block, Class<? extends ItemBlock> itemclass) { GameRegistry.registerBlock(block, itemclass, block.getUnlocalizedName().replace("tile.", "")); blockMap.put(block.getUnlocalizedName().replace("tile.", ""), new ItemStack(block, 1, 0)); } public static void registerTile(Class<? extends TileEntity> tileEntityClass, String id) { GameRegistry.registerTileEntity(tileEntityClass, id); } public static void registerBlockWithVariants(Block block, Class<? extends ItemBlock> itemclass, Class<? extends IMetadataItem> metadataClass) { GameRegistry.registerBlock(block, itemclass, block.getUnlocalizedName().replace("tile.", "")); String[] variants = new String[metadataClass.getEnumConstants().length]; for (IMetadataItem variant : metadataClass.getEnumConstants()) { variants[variant.getMetadata()] = ProjectCoal.RESOURCE_PREFIX + variant.getUnlocalizedName(); blockMap.put(variant.getUnlocalizedName(), new ItemStack(block, 1, variant.getMetadata())); } ModelBakery.addVariantName(Item.getItemFromBlock(block), variants); } public static void registerBlockModel(Item block, int meta, String name) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(block, meta, new ModelResourceLocation(ProjectCoal.RESOURCE_PREFIX + name, "inventory")); } public static Block getBlock(String name) { return GameRegistry.findBlock(ProjectCoal.MODID, name); } public static ItemStack getItemStack(String name, int amount, int meta) { return new ItemStack(getBlock(name), amount, meta); } public static Block getBlockFromMap(String name) { return Block.getBlockFromItem(blockMap.get(name).getItem()); } public static ItemStack getItemStackFromMap(String name, int amount, int meta) { return new ItemStack(getBlockFromMap(name), amount, meta); } } Sorry if it's so easy I couldn't even see the issue, but I am not feeling so well and I still want to keep coding. Have a good one! I try my best, so apologies if I said something obviously stupid!
February 25, 201610 yr Author I was totally sure I had. Sorry. I'll try to double-check next time. Have a good evening! I try my best, so apologies if I said something obviously stupid!
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.