GregoriMarow Posted February 17, 2017 Posted February 17, 2017 (edited) hi, I am a beginner in creating mods. I have used this tutorial for the first steps:https://shadowfacts.net/tutorials/forge-modding-1102/ It woked very well now I want to go the next step. While i want to create a litte street mod for my group of players. Therefor I have to rotate the top texture depending on the side from which the player places it. (North default, East +90°, South +180°, West +270°) Here is my blogstate test file for a test block. the red texture has an arrow facing north. The testfile is working. How can I get the red texture to rotate? { "forge_marker": 1, "defaults": { "textures": { "all": "mcaadditions:blocks/oreCopper", "up": "mcaadditions:blocks/red", "down": "mcaadditions:blocks/blue", "north": "mcaadditions:blocks/green", "east": "mcaadditions:blocks/orange", "south": "mcaadditions:blocks/black", "west": "mcaadditions:blocks/violet" } }, "variants": { "normal": { "model": "cube_all" }, "inventory": { "model": "cube_all" } } } Additional Questions: 1) is it better to rotate the whole block or only the top texture? 2) why have I to declare a "all" texture, otherwise when the block is destroyed the animation has no texture. 3) If there are several ways to reach the goal, which is best for forge dynmap rendering of blocks, so that the street arrows and lines are facing the right direction on the online map. ********************** EDITIED ********************** Quote Answers: 1) rotate the block is the better option 2) forgot to add particles texture in blockstates. Its needed for the texture of the destruction animation 3) got no answer on this, will tell you when i found out if this is a dynmap compatible solution Expand ********************************************************** I hope some can help. Please keep in mind I am a beginner Edited March 10, 2017 by GregoriMarow Quote
Guest Posted February 17, 2017 Posted February 17, 2017 I wanted basically the same question answered a while ago. You may find it helpful to look here. Quote
GregoriMarow Posted February 17, 2017 Author Posted February 17, 2017 (edited) okay seems to be more complicated then I have assumed. I will try. thx for the link Do you have any answers to the additional questions? Edited February 17, 2017 by GregoriMarow Quote
Guest Posted February 17, 2017 Posted February 17, 2017 Basically, add a PropertyFacing property to your block, make your blockstate have states for each facing value, and in each you would rotate it using a "y" value (an angle) in each blockstate when it is facing a certain way. Also, make it point to a model called "orientable" instead of "cube_all". Hope this helps. Quote
GregoriMarow Posted February 17, 2017 Author Posted February 17, 2017 (edited) Well it helps partitally. If you are an absolute beginner and you even get crazy when reading the forge documentation thats not so easy. To imagine on what state I am, before I started the first tutorial I used MCreator That was usable for easy things (currency mod) until the block rotation was needed. I will try it step by step. I have three classes: BlockBase, ModBlocks, BlockStreet: Block Base: package mcaddicts.modpack.blocks.example; import mcaddicts.modpack.McaAdditionsMod; import mcaddicts.modpack.item.ItemModelProvider; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; public class BlockBase extends Block implements ItemModelProvider{ protected String name; public BlockBase(Material materialIn, String name) { super(materialIn); this.name = name; setUnlocalizedName(name); setRegistryName(name); setCreativeTab(McaAdditionsMod.creativeTab); } @Override public void registerItemModel(Item itemBlock) { McaAdditionsMod.proxy.registerItemRenderer(itemBlock, 0, name); } @Override public BlockBase setCreativeTab(CreativeTabs tab) { super.setCreativeTab(tab); return this; } } ModBlocks: package mcaddicts.modpack.blocks.example; import mcaddicts.modpack.item.ItemModelProvider; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.ItemBlock; import net.minecraftforge.fml.common.registry.GameRegistry; public class ModBlocks { public static BlockOre oreCopper; public static BlockStreet streetTest; public static void init() { oreCopper = register(new BlockOre("oreCopper")); streetTest = register(new BlockStreet("streetTest")); } private static <T extends Block> T register (T block, ItemBlock itemBlock) { GameRegistry.register(block); if(itemBlock != null) { GameRegistry.register(itemBlock); } if(block instanceof ItemModelProvider) { ((ItemModelProvider)block).registerItemModel(itemBlock); } return block; } private static <T extends Block> T register(T block) { ItemBlock itemBlock = new ItemBlock(block); itemBlock.setRegistryName(block.getRegistryName()); return register(block, itemBlock); } } BlockStreet: package mcaddicts.modpack.blocks.example; import mcaddicts.modpack.McaAdditionsMod; import net.minecraft.block.BlockHorizontal; import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class BlockStreet extends BlockBase { public static final PropertyDirection FACING = BlockHorizontal.FACING; public BlockStreet(String name) { super(Material.ROCK, name); setHardness(3f); setResistance(5f); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); } @Override public BlockStreet setCreativeTab(CreativeTabs tab) { super.setCreativeTab(tab); return this; } @Override public BlockStateContainer createBlockState() { return new BlockStateContainer(this, FACING); } @Override public int getMetaFromState(IBlockState state) { return 0; } @Override public IBlockState getStateFromMeta(int meta) { return getDefaultState(); } @Override public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entity, ItemStack stack) { EnumFacing entityFacing = entity.getHorizontalFacing(); if(!world.isRemote) { if(entityFacing == EnumFacing.NORTH) { entityFacing = EnumFacing.SOUTH; } else if(entityFacing == EnumFacing.EAST) { entityFacing = EnumFacing.WEST; } else if(entityFacing == EnumFacing.SOUTH) { entityFacing = EnumFacing.NORTH; } else if(entityFacing == EnumFacing.WEST) { entityFacing = EnumFacing.EAST; } world.setBlockState(pos, state.withProperty(FACING, entityFacing), 2); } } } In the last ones i put your overrides. Have I missed anything? The Blockstates file is a another thing, i dont even have tryed to modify it because I think the class file should work correct. Okay when I start the game i didnt get a crash and i have a untextured block. Not the worst result possible. Animefan8888 wrote befor your last post: Quote You need to Override Block#getStateFromMeta and Block#getMetaFromState Expand You have not updated your code until that so i dont know what to do. I think this is definitely missing in the class file Edited February 17, 2017 by GregoriMarow Quote
Draco18s Posted February 17, 2017 Posted February 17, 2017 For meta/state conversion, here's an example. https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/ores/block/BlockMillstone.java#L53-L61 Note that I'm using a custom enum property in place of BlockDirectional.FACING for my specific purpose. Two-property example https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/ores/block/BlockAxel.java#L65-L77 Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
GregoriMarow Posted February 26, 2017 Author Posted February 26, 2017 (edited) okay sry i dont get it. It take me a lot of time to get it to work, but the state is not saved. When i leave the map it resets to default. Can you please look at the code in my own posting above this here? What exactly is missing? By the way this is my blockstates file: { "forge_marker": 1, "defaults": { "textures": { "up": "mcaadditions:blocks/red", "down": "mcaadditions:blocks/blue", "north": "mcaadditions:blocks/green", "east": "mcaadditions:blocks/orange", "south": "mcaadditions:blocks/black", "west": "mcaadditions:blocks/violet", "particle": "mcaadditions:blocks/red" } }, "variants": { "normal": { "model": "orientable" }, "inventory": { "model": "orientable" }, "facing=north": { "model": "orientable" }, "facing=east": { "model": "orientable", "y": 90 }, "facing=south": { "model": "orientable", "y": 180 }, "facing=west": { "model": "orientable", "y": 270 } } } Edited February 26, 2017 by GregoriMarow Quote
Lhykos Posted February 26, 2017 Posted February 26, 2017 Did you pass the correct values to getMetafromState() and getStateFromMeta() ? If you have still set it to "0" and "getDefaultState()" it won't save anything. Draco18s explained it in a good example. Quote
GregoriMarow Posted February 26, 2017 Author Posted February 26, 2017 (edited) Nope did not pass the correct values, found the passage you mean. But can not transform it to my use. MILL_ORIENTATION and MillstoneOrientation, where is this defined why a separated class? Did it need it? I even dont understand what it did exactly. I assume one is reading meta data from block, and the other is writing meta data to block. But how can i rewrite it to my use? When I understand it correct I have to write the facing direction in the meta data or read it from meta data? correct? but how? Normally I learn new things with good commented code. With this examples I can not track the steps. getMetaFromState: //My code: @Override public int getMetaFromState(IBlockState state) { return 0; } //Draco18s Code: @Override public int getMetaFromState(IBlockState state) { return state.getValue(Props.MILL_ORIENTATION).getOrdinal(); } getStateFromMeta: //My Code: @Override public IBlockState getStateFromMeta(int meta) { return getDefaultState(); } //Draco18s Code: @Override public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(Props.MILL_ORIENTATION, MillstoneOrientation.values()[meta]); } POSITION READOUT? @Override public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entity, ItemStack stack) { EnumFacing entityFacing = entity.getHorizontalFacing(); if(!world.isRemote) { if(entityFacing == EnumFacing.NORTH) { entityFacing = EnumFacing.NORTH; } else if(entityFacing == EnumFacing.EAST) { entityFacing = EnumFacing.EAST; } else if(entityFacing == EnumFacing.SOUTH) { entityFacing = EnumFacing.SOUTH; } else if(entityFacing == EnumFacing.WEST) { entityFacing = EnumFacing.WEST; } world.setBlockState(pos, state.withProperty(FACING, entityFacing), 2); } } Edited February 26, 2017 by GregoriMarow Quote
Guest Posted February 26, 2017 Posted February 26, 2017 Your getMetaFromState returns 0. You have to return a value or it won't save as Lhykos pointed out. I have a class that does this. You can find it here: https://github.com/WiseOwl5/RobotiCraft/blob/master/1.11/src/main/java/wiseowl5/roboticraft/Blocks/BlockSteamEngine.java#L74-L77 You would, from the state, get the value, cast it to an EnumFacing, and get the index. Quote
Guest Posted February 26, 2017 Posted February 26, 2017 And instead of defining blockstates like this: ... "variants": { "normal": { "model": "orientable" }, "inventory": { "model": "orientable" }, "facing=north": { "model": "orientable" }, "facing=east": { "model": "orientable", "y": 90 }, "facing=south": { "model": "orientable", "y": 180 }, "facing=west": { "model": "orientable", "y": 270 } ... Define them like this: https://github.com/WiseOwl5/RobotiCraft/blob/master/1.11/src/main/resources/assets/roboticraft/blockstates/steam_engine.json#L11-L35 Quote
GregoriMarow Posted February 26, 2017 Author Posted February 26, 2017 THANK YOU SO MUCH, THAT WAS THE MISSING PART Here the solution for others: @Override public int getMetaFromState(IBlockState state) { return ((EnumFacing)state.getValue(FACING)).getHorizontalIndex(); } // AND @Override public IBlockState getStateFromMeta(int meta) { return getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)); } Quote
GregoriMarow Posted February 26, 2017 Author Posted February 26, 2017 (edited) YES: Arrow is placed in the direction i am looking to. Now i just have to rewrite some litte things. e.g. remove setCreativeTab from the Block Base java, because i want different tabs for arrows, lines, sidewalks and so on. I will try to breakdown all possible options to the block base. Maybe i could also use the rotation code there because all blocks need to have this option. then i have only to create a class for where the tab is set and each type of blocks is registred. Thanks also for the optimized blockstates file, I will correct it. Edited February 26, 2017 by GregoriMarow Quote
GregoriMarow Posted February 27, 2017 Author Posted February 27, 2017 okay one question was coming up during first real used blocks. I have installed worldedit for forge and i can not rotate the blocks. Mark it //copy, then //rotate 90. The Blocks still have the same metadata [north=2,east=3,south= 0,west= 1] for orientation (see picture, readout with info tool). I rotated from north 90° to the right so normally it should change from 2 to 3. Have I to declare anything in the code so that worldedit knows metadata 2 = north and so on? Quote
GregoriMarow Posted March 9, 2017 Author Posted March 9, 2017 okay i wanted to push this question one time after 11 days are over, Quote
Draco18s Posted March 10, 2017 Posted March 10, 2017 On 2/27/2017 at 2:03 PM, GregoriMarow said: Have I to declare anything in the code so that worldedit knows metadata 2 = north and so on Expand that's a question for the developer of WorldEdit. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
GregoriMarow Posted March 10, 2017 Author Posted March 10, 2017 For those who have the same problem, here is the answer: http://forum.enginehub.org/threads/rotation-not-working-with-own-mod.16927/ Quote
Recommended Posts
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.