Posted March 9, 20178 yr 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.? Edited March 11, 20178 yr by GregoriMarow
March 10, 20178 yr Author 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.
March 10, 20178 yr It's same size as default glass pane. BlockPane has AABB list and default(thin) one is new AxisAlignedBB(0.4375D, 0.0D, 0.4375D, 0.5625D, 1.0D, 0.5625D) . Min values can be greater than zero.
March 10, 20178 yr The parameters of the AxisAlignedBB constructor are two sets of x,y,z co-ordinates. The bounding box is then created as a cuboid with those two sets of co-ordinates defining opposite corners. So if you want the box to start at somewhere other than the bottom corner then you can just make the first set of co-ordinates in the constructor something other than 0,0,0. Edited March 10, 20178 yr by Jay Avery
March 10, 20178 yr Author 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. Edited March 10, 20178 yr by GregoriMarow
March 10, 20178 yr I'm afraid I don't - reading through the actual source code of vanilla classes is a good source of information if you're able to figure out (although that's not always easy). I learned about AxisAlignedBB through a combination of reading the code carefully, looking through different ways it's implemented in various vanilla blocks, and then a fair bit of experimenting with creating my own to see how they acted.
March 11, 20178 yr Author 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 Edited March 11, 20178 yr by GregoriMarow
March 11, 20178 yr This does actually nothing: 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; } If value is A, set value to A. If it's B, set it to B... You also have no code that supplies a different bounding box based on facing. You in fact, supply a single bounding box (which you reconstruct every time) regardless of block state: public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return new AxisAlignedBB(posX, posY, posZ, sizeX, sizeY, sizeZ); } 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.
March 11, 20178 yr Author 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. Edited March 11, 20178 yr by GregoriMarow
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.