Jump to content

GregoriMarow

Members
  • Posts

    19
  • Joined

  • Last visited

Converted

  • URL
    https://www.mc-addicts.de

GregoriMarow's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. ups you are right. The code that does nothing is a leftover, because in the example they wanted the opposite direction of the facing. Just have replaced the directions, and as it was working as expected I forgot to remove the if states. Some models are centered but others not. I missed that totally. This will work for most, but not for all. okay now I am a litte bit downcast. Any guesses Normally someone might be able to translate the coordinates with the rotation? Can I? I think thats to complicated for me. Provide the box for standard north in the registration, read out the state of the block an then if its not north translate the coordinates. Uff sry thats to much for me.
  2. Okay i want to share the code for:" Custom Models with Rotation and resize-able collision box" Thanks to a good friend who helped here. ModBlocks: testblock = register(new BlockCustomCollisionWithRotation("testblock", 0.0D, 0.0D, 0.0D, 1.0D, 0.5D, 1.0D )); BlockCustomCollisionWithRotation: package mcaddicts.modpack.blocks; import java.awt.List; import javax.swing.text.html.parser.Entity; import akka.actor.Props; import mcaddicts.modpack.McaAdditionsMod; import net.minecraft.block.BlockHorizontal; import net.minecraft.block.SoundType; 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.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class BlockCustomCollisionWithRotation extends BlockBase { protected double posX; protected double posY; protected double posZ; protected double sizeX; protected double sizeY; protected double sizeZ; public static final PropertyDirection FACING = BlockHorizontal.FACING; public BlockCustomCollisionWithRotation(String name, double posX, double posY, double posZ, double sizeX, double sizeY, double sizeZ) { super(Material.ROCK, name); setSoundType(SoundType.STONE); setHardness(3f); setResistance(5f); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); this.posX = posX; this.posY = posY; this.posZ = posZ; this.sizeX = sizeX; this.sizeY = sizeY; this.sizeZ = sizeZ; } //standard values if no collision box data is provided public BlockCustomCollisionWithRotation(String name) { this (name, 0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D); } //examples for collision boxes: //lower half: 0.0D, 0.0D, 0.0D, 1.0D, 0.5D, 1.0D //upper half: 0.0D, 0.5D, 0.0D, 1.0D, 1.0D, 1.0D //full block (standard): 0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return new AxisAlignedBB(posX, posY, posZ, sizeX, sizeY, sizeZ); } //prevents, that blocks at side of it get transparent @Override @Deprecated public boolean isOpaqueCube(IBlockState state) { return false; } @Override @Deprecated public boolean isFullCube(IBlockState state) { return false; } @Override public BlockCustomCollisionWithRotation setCreativeTab(CreativeTabs tab) { super.setCreativeTab(tab); return this; } @Override public BlockStateContainer createBlockState() { return new BlockStateContainer(this, FACING); } //Meta from State @Override public int getMetaFromState(IBlockState state) { return ((EnumFacing)state.getValue(FACING)).getHorizontalIndex(); } //State from Meta @Override public IBlockState getStateFromMeta(int meta) { return getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)); } @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.SOUTH) { entityFacing = EnumFacing.SOUTH; } else if(entityFacing == EnumFacing.EAST) { entityFacing = EnumFacing.EAST; } else if(entityFacing == EnumFacing.WEST) { entityFacing = EnumFacing.WEST; } world.setBlockState(pos, state.withProperty(FACING, entityFacing), 2); } } } collision box calculation example: We have this pole with 2x2 units centered. the whole block is devided into 16 units. First make the offset: 7+2 = 9 (7 from the side and 2 for the model) 16 units = 1 Block 9 units = ? 9*1/16 or short 9/16= 0,5625 1-0,5625=0,4375 Then: 7 from the side 16 units = 1 Block 7 units = ? 7/16 = 0,4375 1-0,4375=0,5625 Height is unchanged 1 Now put the results into code: traffic_pole = register(new BlockCustomStatic("traffic_pole", 0.4375D, 0.0D, 0.4375D, 0.5625D, 1.0D, 0.5625D )); Result is seen in the image
  3. If you want to switch to json models you can try MrCrayfish's Model Creator for free. you have to friddle around a lot thats a bit annoying and its not running well on java installed on linux. (works under same java version installed on windows... lol? who said cross platform? ) So I have bought cubic studio, its very nice, runs perfectly under linux, but you have to pay for it!
  4. For those who have the same problem, here is the answer: http://forum.enginehub.org/threads/rotation-not-working-with-own-mod.16927/
  5. Ah okay, thanks. Do you know any source for a minecraft code documentation? I decompiled the mcp but the comments are very rare. I just found that new Axis snipped only by searching the code of the mc slab. But without documentation it is sometimes hard to understand how it works.
  6. okay i have made it static for testing porposes and will replace the values with variables later as you mentioned above. This is an example for a working lower half slab collision box: public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.5D, 1.0D); } But I haven't found any documentation about the axis definitions. Lets assume i have a small pole. I can not set the side coordinates because the collision box is then in the corner of its origin. How can i make a offset to center the box. Lets use an example (picture): I want a collision box for this lantern pole. 1 high / 0,125 width in both directions / centered (i don't want to have the box in the corner of origin, the pole is in the middle) How do I do that? I have googeled a lot for commented examples or a documentation of the collision boxes.
  7. Hi, I have custom models smaller than a regular block. Is it possible to set the size of the collision block with the blockstates or the model file? I want to avoid to create a new class file for every model. Or is there a possible code for auto detection of the model size and creating the collision box based on that.?
  8. okay i wanted to push this question one time after 11 days are over,
  9. I was just remembering that thing and it was an example. The real question belongs to the block names. Anyway I am sure its not enforced in 1.7.10 because before I started to learn how to program mods by hand I used MCreator. They enforce Captital Letters (nobody knows why) for modid and it worked. The first time i mentioned that warning was in 1.10.2. Just for explanation. My question with the block names was answered by kookie and it looks like there is no length limitation.
  10. do you know where the length limitation is? limitation for block name, limitation for modid and maybe a max. limitation modid:blockname e.g. block name max. 20, mod name max. 20 but all together max. 30?
  11. hi, I have a litte question for block naming conventions. During early testing of a demomod I used "Examplemod" as the mod id, and encountered a minecraft forge warning that lower case modnames will be enforce at 1.12+. Now I ask myself if this also belongs to block names? In my tutorial demo they used "copperOre" for a demoblock. Now i have started to name my blocks, textures like with captital letters for every new word, so its good to read for me in the code: "StripeWhiteSideInnerCorner" can I keep that or should i take the vanilla way "stripe_white_side_inner_corner" (maybe to long? mcaadditions:stripe_white_side_inner_corner) or every thing together in small letters "stripewhitesideinnercorner" (Bad to read)?
  12. 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?
  13. 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.
  14. 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)); }
  15. 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); } }
×
×
  • Create New...

Important Information

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