Jump to content

Jack4096

Members
  • Posts

    13
  • Joined

  • Last visited

Everything posted by Jack4096

  1. In that case, I will most likely just wait for 1.13 then.
  2. Honestly I have no idea how to write any of the code you guys are suggesting... I have no idea how. Could you guys just help with setting proper names for each plank in the enum? For all 4 plank types? For Magic, Maple, Redwood, and Yew?
  3. I tried to figure out where to put this code, but I couldn't figure it out, could you explain? Please. Also, what exactly would I put for "item" and "model location"?
  4. I tried to figure out how to do that, and I couldn't figure out how. Could you please explain?
  5. I am trying to set the name of the planks, but I have no idea even after studying the code for hours, how to even add the names of the blocks. Their name is just "planks" but I WANT to concatenate String "planks" with the planks' enum's assigned name, to add an "_", and then add the name of the enum of the plank. Please ask for additional information if my problem seems unclear, and there are no crashes or error messages: public class MagicPlank extends Block implements IHasModel { public static final PropertyEnum<MagicPlank.EnumType> VARIANT = PropertyEnum.<MagicPlank.EnumType>create("variant", MagicPlank.EnumType.class); public MagicPlank(String name, Material material) { super(material); setUnlocalizedName(name); setRegistryName(name); ModBlocks.BLOCKS.add(this); ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName())); this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS); this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, MagicPlank.EnumType.MAGIC)); } /** * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It * returns the metadata of the dropped item based on the old metadata of the block. */ public int damageDropped(IBlockState state) { return ((MagicPlank.EnumType)state.getValue(VARIANT)).getMetadata(); } /** * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) */ public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) { for (MagicPlank.EnumType magicplank$enumtype : MagicPlank.EnumType.values()) { items.add(new ItemStack(this, 1, magicplank$enumtype.getMetadata())); } } /** * Convert the given metadata into a BlockState for this Block */ public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(VARIANT, MagicPlank.EnumType.byMetadata(meta)); } /** * Get the MapColor for this Block and the given BlockState */ public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos) { return ((MagicPlank.EnumType)state.getValue(VARIANT)).getMapColor(); } /** * Convert the BlockState into the correct metadata value */ public int getMetaFromState(IBlockState state) { return ((MagicPlank.EnumType)state.getValue(VARIANT)).getMetadata(); } protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {VARIANT}); } public static enum EnumType implements IStringSerializable { MAGIC(0, "magic", MapColor.SAND), MAPLE(1, "maple", MapColor.SAND), REDWOOD(2, "redwood", MapColor.SAND), YEW(3, "yew", MapColor.SAND); private static final MagicPlank.EnumType[] META_LOOKUP = new MagicPlank.EnumType[values().length]; private final int meta; private final String name; private final String unlocalizedName; /** The color that represents this entry on a map. */ private final MapColor mapColor; private EnumType(int metaIn, String nameIn, MapColor mapColorIn) { this(metaIn, nameIn, nameIn, mapColorIn); } private EnumType(int metaIn, String nameIn, String unlocalizedNameIn, MapColor mapColorIn) { this.meta = metaIn; this.name = nameIn; this.unlocalizedName = unlocalizedNameIn; this.mapColor = mapColorIn; } public int getMetadata() { return this.meta; } /** * The color which represents this entry on a map. */ public MapColor getMapColor() { return this.mapColor; } public String toString() { return this.name; } public static MagicPlank.EnumType byMetadata(int meta) { if (meta < 0 || meta >= META_LOOKUP.length) { meta = 0; } return META_LOOKUP[meta]; } public String getName() { return this.name; } public String getUnlocalizedName() { return this.unlocalizedName; } static { for (MagicPlank.EnumType magicplank$enumtype : values()) { META_LOOKUP[magicplank$enumtype.getMetadata()] = magicplank$enumtype; } } } @Override public void registerModels() { Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory"); } }
  6. Sorry, I tried to figure out how to do that and didn't succeed in figuring out how, so could you please explain further?
  7. So Anime fan, I added this to the code: @Override protected BlockStateContainer createBlockState() { return super.createBlockState(); } So this is the code now: public class MagicLog extends BlockLog implements IHasModel { public static final PropertyEnum<MagicLog.EnumAxis> LOG_AXIS = PropertyEnum.<MagicLog.EnumAxis>create("axis", MagicLog.EnumAxis.class); public MagicLog(String name) { super(); setUnlocalizedName(name); setRegistryName(name); ModBlocks.BLOCKS.add(this); ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName())); } @Override protected BlockStateContainer createBlockState() { return super.createBlockState(); } /** * Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated */ public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { int i = 4; int j = 5; if (worldIn.isAreaLoaded(pos.add(-5, -5, -5), pos.add(5, 5, 5))) { for (BlockPos blockpos : BlockPos.getAllInBox(pos.add(-4, -4, -4), pos.add(4, 4, 4))) { IBlockState iblockstate = worldIn.getBlockState(blockpos); if (iblockstate.getBlock().isLeaves(iblockstate, worldIn, blockpos)) { iblockstate.getBlock().beginLeavesDecay(iblockstate, worldIn, blockpos); } } } } /** * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the * IBlockstate */ public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return this.getStateFromMeta(meta).withProperty(LOG_AXIS, MagicLog.EnumAxis.fromFacingAxis(facing.getAxis())); } /** * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed * blockstate. */ public IBlockState withRotation(IBlockState state, Rotation rot) { switch (rot) { case COUNTERCLOCKWISE_90: case CLOCKWISE_90: switch ((MagicLog.EnumAxis)state.getValue(LOG_AXIS)) { case X: return state.withProperty(LOG_AXIS, MagicLog.EnumAxis.Z); case Z: return state.withProperty(LOG_AXIS, MagicLog.EnumAxis.X); default: return state; } default: return state; } } @Override public boolean canSustainLeaves(IBlockState state, net.minecraft.world.IBlockAccess world, BlockPos pos){ return true; } @Override public boolean isWood(net.minecraft.world.IBlockAccess world, BlockPos pos){ return true; } public static enum EnumAxis implements IStringSerializable { X("x"), Y("y"), Z("z"), NONE("none"); private final String name; private EnumAxis(String name) { this.name = name; } public String toString() { return this.name; } public static MagicLog.EnumAxis fromFacingAxis(EnumFacing.Axis axis) { switch (axis) { case X: return X; case Y: return Y; case Z: return Z; default: return NONE; } } public String getName() { return this.name; } } @Override public void registerModels() { Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory"); } } And it gives this error in the crash report, after crashing on startup: java.lang.IllegalArgumentException: Cannot set property PropertyEnum{name=axis, clazz=class com.jack.tutorialmod.blocks.MagicLog$EnumAxis, values=[x, y, z, none]} as it does not exist in BlockStateContainer{block=tm:magic_log, properties=[axis]} I don't know how to get past this error, but you said something about adding the AXIS property to the BlockStateContainer. I just don't know how to add it, I tried to figure it out, but I couldn't figure it out. Help is appreciated.
  8. The line stating the error from the crash report: java.lang.IllegalArgumentException: Cannot set property PropertyEnum{name=axis, clazz=class com.jack.tutorialmod.blocks.MagicLog$EnumAxis, values=[x, y, z, none]} as it does not exist in BlockStateContainer{block=tm:magic_log, properties=[axis]} I am attempting to have class MagicLog extends (inherit from) BlockLog class. The game crashes when I place MagicLog. It has a texture and is named properly when it is in my character's hand, although for some reason it is all the bark texture. Here's my code: public class MagicLog extends BlockLog implements IHasModel { public static final PropertyEnum<MagicLog.EnumAxis> LOG_AXIS = PropertyEnum.<MagicLog.EnumAxis>create("axis", MagicLog.EnumAxis.class); public MagicLog(String name) { super(); setUnlocalizedName(name); setRegistryName(name); ModBlocks.BLOCKS.add(this); ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName())); } /** * Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated */ public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { int i = 4; int j = 5; if (worldIn.isAreaLoaded(pos.add(-5, -5, -5), pos.add(5, 5, 5))) { for (BlockPos blockpos : BlockPos.getAllInBox(pos.add(-4, -4, -4), pos.add(4, 4, 4))) { IBlockState iblockstate = worldIn.getBlockState(blockpos); if (iblockstate.getBlock().isLeaves(iblockstate, worldIn, blockpos)) { iblockstate.getBlock().beginLeavesDecay(iblockstate, worldIn, blockpos); } } } } /** * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the * IBlockstate */ public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return this.getStateFromMeta(meta).withProperty(LOG_AXIS, MagicLog.EnumAxis.fromFacingAxis(facing.getAxis())); } /** * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed * blockstate. */ public IBlockState withRotation(IBlockState state, Rotation rot) { switch (rot) { case COUNTERCLOCKWISE_90: case CLOCKWISE_90: switch ((MagicLog.EnumAxis)state.getValue(LOG_AXIS)) { case X: return state.withProperty(LOG_AXIS, MagicLog.EnumAxis.Z); case Z: return state.withProperty(LOG_AXIS, MagicLog.EnumAxis.X); default: return state; } default: return state; } } @Override public boolean canSustainLeaves(IBlockState state, net.minecraft.world.IBlockAccess world, BlockPos pos){ return true; } @Override public boolean isWood(net.minecraft.world.IBlockAccess world, BlockPos pos){ return true; } public static enum EnumAxis implements IStringSerializable { X("x"), Y("y"), Z("z"), NONE("none"); private final String name; private EnumAxis(String name) { this.name = name; } public String toString() { return this.name; } public static MagicLog.EnumAxis fromFacingAxis(EnumFacing.Axis axis) { switch (axis) { case X: return X; case Y: return Y; case Z: return Z; default: return NONE; } } public String getName() { return this.name; } } @Override public void registerModels() { Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory"); } } If you need more information on the error to help solve it, please do ask if it will help. I should also mention that I do not know how to make it so that the block does not have all the same texture (The MagicLog's bark texture) on all sides of the block. It would be appreciated if someone explained how to give it the top of the block's texture (The non-bark part that shows the inside of the wood, like on a vanilla log) on the top of the block.
  9. I have to admit, I made all this post and comments late at night when very sleepy. So I truly honestly do not remember if I did anything else, sorry.
  10. It ONLY fixed the crash on startup, ONLY. It's still bugged. Sorry, I should have specified. But the crash on startup is fixed, I feel that I can do all the rest of the debugging on my own, and if I can't, I'll ask on this forum for help if I can't figure it out.
  11. Thank you Cadiboo, putting @Override at the line over: protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {VARIANT}); } fixed the crash on startup. Updated code: public class BlockPlanksBase extends Block implements IHasModel { public static final PropertyEnum<BlockPlanksBase.EnumType> VARIANT = PropertyEnum.<BlockPlanksBase.EnumType>create("variant", BlockPlanksBase.EnumType.class); public BlockPlanksBase(String name) { super(Material.WOOD); setUnlocalizedName(name); setRegistryName(name); ModBlocks.BLOCKS.add(this); ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName())); this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS); this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockPlanksBase.EnumType.MAGIC)); } /** * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It * returns the metadata of the dropped item based on the old metadata of the block. */ public int damageDropped(IBlockState state) { return ((BlockPlanksBase.EnumType)state.getValue(VARIANT)).getMetadata(); } /** * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) */ public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) { for (BlockPlanksBase.EnumType blockplanksbase$enumtype : BlockPlanksBase.EnumType.values()) { items.add(new ItemStack(this, 1, blockplanksbase$enumtype.getMetadata())); } } /** * Convert the given metadata into a BlockState for this Block */ public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(VARIANT, BlockPlanksBase.EnumType.byMetadata(meta)); } /** * Get the MapColor for this Block and the given BlockState */ public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos) { return ((BlockPlanksBase.EnumType)state.getValue(VARIANT)).getMapColor(); } /** * Convert the BlockState into the correct metadata value */ public int getMetaFromState(IBlockState state) { return ((BlockPlanksBase.EnumType)state.getValue(VARIANT)).getMetadata(); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {VARIANT}); } public static enum EnumType implements IStringSerializable { MAGIC(0, "magic", MapColor.SAND), MAPLE(1, "maple", MapColor.SAND), REDWOOD(2, "redwood", MapColor.SAND), YEW(3, "yew", MapColor.SAND); private static final BlockPlanksBase.EnumType[] META_LOOKUP = new BlockPlanksBase.EnumType[values().length]; private final int meta; private final String name; private final String unlocalizedName; /** The color that represents this entry on a map. */ private final MapColor mapColor; private EnumType(int metaIn, String nameIn, MapColor mapColorIn) { this(metaIn, nameIn, nameIn, mapColorIn); } private EnumType(int metaIn, String nameIn, String unlocalizedNameIn, MapColor mapColorIn) { this.meta = metaIn; this.name = nameIn; this.unlocalizedName = unlocalizedNameIn; this.mapColor = mapColorIn; } public int getMetadata() { return this.meta; } /** * The color which represents this entry on a map. */ public MapColor getMapColor() { return this.mapColor; } public String toString() { return this.name; } public static BlockPlanksBase.EnumType byMetadata(int meta) { if (meta < 0 || meta >= META_LOOKUP.length) { meta = 0; } return META_LOOKUP[meta]; } public String getName() { return this.name; } public String getUnlocalizedName() { return this.unlocalizedName; } static { for (BlockPlanksBase.EnumType blockplanksbase$enumtype : values()) { META_LOOKUP[blockplanksbase$enumtype.getMetadata()] = blockplanksbase$enumtype; } } } @Override public void registerModels() { Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory"); } } So yes, that fixed it. Thank you Cadiboo.
  12. It's line 36 in the class constructor that shows up as the error with the crash report, after it crashes before it finishes starting up, the line that says: this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, MagicPlank.EnumType.MAGIC)); And this is the error message: Caused by: java.lang.IllegalArgumentException: Cannot set property PropertyEnum{name=variant, clazz=class net.minecraft.block.BlockPlanks$EnumType, values=[oak, spruce, birch, jungle, acacia, dark_oak]} as it does not exist in BlockStateContainer{block=null, properties=[variant]} package com.jack.tutorialmod.blocks; import com.jack.tutorialmod.Main; import com.jack.tutorialmod.util.IHasModel; import net.minecraft.block.BlockPlanks; import net.minecraft.block.SoundType; import net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.IStringSerializable; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; public class MagicPlank extends BlockPlanks implements IHasModel { public static final PropertyEnum<MagicPlank.EnumType> VARIANT = PropertyEnum.<MagicPlank.EnumType>create("variant", MagicPlank.EnumType.class); public MagicPlank(String name) { super(); setSoundType(SoundType.WOOD); setHardness(2.0F); setResistance(10.0F); setHarvestLevel("axe", 0); setUnlocalizedName(name); setRegistryName(name); this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, MagicPlank.EnumType.MAGIC)); this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS); } /** * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It * returns the metadata of the dropped item based on the old metadata of the block. */ public int damageDropped(IBlockState state) { return ((MagicPlank.EnumType)state.getValue(VARIANT)).getMetadata(); } /** * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) */ public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) { for (MagicPlank.EnumType magicplank$enumtype : MagicPlank.EnumType.values()) { items.add(new ItemStack(this, 1, magicplank$enumtype.getMetadata())); } } /** * Convert the given metadata into a BlockState for this Block */ public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(VARIANT, MagicPlank.EnumType.byMetadata(meta)); } /** * Get the MapColor for this Block and the given BlockState */ public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos) { return ((MagicPlank.EnumType)state.getValue(VARIANT)).getMapColor(); } /** * Convert the BlockState into the correct metadata value */ public int getMetaFromState(IBlockState state) { return ((MagicPlank.EnumType)state.getValue(VARIANT)).getMetadata(); } protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {VARIANT}); } public static enum EnumType implements IStringSerializable { MAGIC(0, "magic", MapColor.BLUE), MAPLE(1, "maple", MapColor.RED), YEW(2, "yew", MapColor.YELLOW), REDWOOD(3, "redwood", MapColor.RED); private static final MagicPlank.EnumType[] META_LOOKUP = new MagicPlank.EnumType[values().length]; private final int meta; private final String name; private final String unlocalizedName; /** The color that represents this entry on a map. */ private final MapColor mapColor; private EnumType(int metaIn, String nameIn, MapColor mapColorIn) { this(metaIn, nameIn, nameIn, mapColorIn); } private EnumType(int metaIn, String nameIn, String unlocalizedNameIn, MapColor mapColorIn) { this.meta = metaIn; this.name = nameIn; this.unlocalizedName = unlocalizedNameIn; this.mapColor = mapColorIn; } public int getMetadata() { return this.meta; } /** * The color which represents this entry on a map. */ public MapColor getMapColor() { return this.mapColor; } public String toString() { return this.name; } public static MagicPlank.EnumType byMetadata(int meta) { if (meta < 0 || meta >= META_LOOKUP.length) { meta = 0; } return META_LOOKUP[meta]; } public String getName() { return this.name; } public String getUnlocalizedName() { return this.unlocalizedName; } static { for (MagicPlank.EnumType magicplank$enumtype : values()) { META_LOOKUP[magicplank$enumtype.getMetadata()] = magicplank$enumtype; } } } @Override public void registerModels() { Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory"); } } I'm sorry if this is a rookie mistake or something. I am experienced with Java, just not Minecraft Forge modding.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.