Jump to content

Recommended Posts

Posted (edited)

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
Posted

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

Posted

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.

  • Like 1
Posted (edited)

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
Posted (edited)

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
Posted

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.

Posted (edited)

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
Posted

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.

Posted (edited)

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

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

    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } }  
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
  • Topics

×
×
  • Create New...

Important Information

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