Jump to content

[1.10.2] collision block


GregoriMarow

Recommended Posts

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 by GregoriMarow
Link to comment
Share on other sites

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.

2017-03-10_16.31.22.png

Link to comment
Share on other sites

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 by Jay Avery
  • Like 1
Link to comment
Share on other sites

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 by GregoriMarow
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

2017-03-11_22_56_51.png.c8b4100a5b697feae70e3750044fdee1.png

 

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 by GregoriMarow
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by GregoriMarow
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • OLXTOTO - Bandar Togel Online Dan Slot Terbesar Di Indonesia OLXTOTO telah lama dikenal sebagai salah satu bandar online terkemuka di Indonesia, terutama dalam pasar togel dan slot. Dengan reputasi yang solid dan pengalaman bertahun-tahun, OLXTOTO menawarkan platform yang aman dan andal bagi para penggemar perjudian daring. DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI Beragam Permainan Togel Sebagai bandar online terbesar di Indonesia, OLXTOTO menawarkan berbagai macam permainan togel. Mulai dari togel Singapura, togel Hongkong, hingga togel Sidney, pemain memiliki banyak pilihan untuk mencoba keberuntungan mereka. Dengan sistem yang transparan dan hasil yang adil, OLXTOTO memastikan bahwa setiap taruhan diproses dengan cepat dan tanpa keadaan. Slot Online Berkualitas Selain togel, OLXTOTO juga menawarkan berbagai permainan slot online yang menarik. Dari slot klasik hingga slot video modern, pemain dapat menemukan berbagai opsi permainan yang sesuai dengan preferensi mereka. Dengan grafis yang memukau dan fitur bonus yang menggiurkan, pengalaman bermain slot di OLXTOTO tidak akan pernah membosankan. Keamanan dan Kepuasan Pelanggan Terjamin Keamanan dan kepuasan pelanggan merupakan prioritas utama di OLXTOTO. Mereka menggunakan teknologi enkripsi terbaru untuk melindungi data pribadi dan keuangan para pemain. Tim dukungan pelanggan yang ramah dan responsif siap membantu pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Promosi dan Bonus Menarik OLXTOTO sering menawarkan promosi dan bonus menarik kepada para pemainnya. Mulai dari bonus selamat datang hingga bonus deposit, pemain memiliki kesempatan untuk meningkatkan kemenangan mereka dengan memanfaatkan berbagai penawaran yang tersedia. Penutup Dengan reputasi yang solid, beragam permainan berkualitas, dan komitmen terhadap keamanan dan kepuasan pelanggan, OLXTOTO tetap menjadi salah satu pilihan utama bagi para pecinta judi online di Indonesia. Jika Anda mencari pengalaman berjudi yang menyenangkan dan terpercaya, OLXTOTO layak dipertimbangkan.
    • I have been having a problem with minecraft forge. Any version. Everytime I try to launch it it always comes back with error code 1. I have tried launching from curseforge, from the minecraft launcher. I have also tried resetting my computer to see if that would help. It works on my other computer but that one is too old to run it properly. I have tried with and without mods aswell. Fabric works, optifine works, and MultiMC works aswell but i want to use forge. If you can help with this issue please DM on discord my # is Haole_Dawg#6676
    • Add the latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • I have no idea how a UI mod crashed a whole world but HUGE props to you man, just saved me +2 months of progress!  
    • So i know for a fact this has been asked before but Render stuff troubles me a little and i didnt find any answer for recent version. I have a custom nausea effect. Currently i add both my nausea effect and the vanilla one for the effect. But the problem is that when I open the inventory, both are listed, while I'd only want mine to show up (both in the inv and on the GUI)   I've arrived to the GameRender (on joined/net/minecraft/client) and also found shaders on client-extra/assets/minecraft/shaders/post and client-extra/assets/minecraft/shaders/program but I'm lost. I understand that its like a regular screen, where I'd render stuff "over" the game depending on data on the server, but If someone could point to the right client and server classes that i can read to see how i can manage this or any tip would be apreciated
  • Topics

×
×
  • Create New...

Important Information

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