Jump to content

Recommended Posts

Posted

Collision boxes are always aligned to the x,y,z axes (that's what "AxisAlignedBoundingBox" means), so you just need to change the x, y, or z sizes.

 

Post some code / pictures of what you're trying to do?

 

-TGG

Posted

So basically I need a way to set a box for each orientation and as an added bonus possibly

a better box.

 

 

 

block:

[package net.mymod.mod.blocks;

import java.util.ArrayList;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.mymod.mod.mymod;
import net.mymod.mod.tileentity.TileEntityPlank;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class Plank1 extends BlockContainer{
public Plank1(Material m) {
      super(m);
      this.setHardness(2.0F);
      this.setResistance(5.0F);
      this.setBlockBounds(0F, 0.3125F,0.935F, 1.0F, 0.875F, 1.0F);
      this.setCreativeTab(mymodtab.mymodtab);   }

public int getRenderType() {
   return -3;
}

public boolean isOpaqueCube() {
   return false;
}

public boolean renderAsNormalBlock() {
   return false;
}

@Override
public TileEntity createNewTileEntity(World var1, int var2) {
   return new TileEntityPlank();
}

@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
   this.blockIcon = iconRegister.registerIcon(MoreHorror.modid + ":" + this.getUnlocalizedName().substring(5));
}

@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack)
{
if (entity == null)
{
return;
}

TileEntityPlank tile = (TileEntityPlank) world.getTileEntity(x, y, z);
tile.direction = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
}}
]

 

Render:

[/package net.mymod.mod.rederer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.mymod.mod.mymod;
import net.morehorror.mod.model.ModelPlank1;
import net.morehorror.mod.tileentity.TileEntityPlank;

import org.lwjgl.opengl.GL11;

public class RenderPlank extends TileEntitySpecialRenderer{
      
   private static final ResourceLocation texture = new ResourceLocation(MoreHorror.modid + ":" + "textures/model/ModelPlank1.png");
      
      private ModelPlank1 model;
      
      public RenderPlank(){
         this.model = new ModelPlank1();
      }
      
      @Override
      public void renderTileEntityAt(TileEntity tileentity, double x, double y,double z, float f) {
         GL11.glPushMatrix();
            GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
            GL11.glRotatef(180, 0F, 0F, 1F);
            
            TileEntityPlank myTile = (TileEntityPlank) tileentity;
            int direction = myTile.direction;
            GL11.glRotatef(direction * 90, 0.0F, 1.0F, 0.0F);
            
            this.bindTexture(texture);
            Minecraft.getMinecraft().renderEngine.bindTexture(texture);
            GL11.glPushMatrix();
               this.model.renderModel(0.0625F);
            GL11.glPopMatrix();
            
         GL11.glPopMatrix();
      }
]

Posted

Hi

 

You could try looking at Vanilla code which does this

BlockSlab might be a good one if your block is basically like a cube with one or more of the faces chopped off shorter ; setBlockBoundsBasedOnState()  and perhaps addCollisionBoxesToList()

 

-TGG

 

Posted

Alright so now i am able to set the boxes for each orientation but every time I set a new one it alters the rest... I can assume It is the metadata not saving or something so Fix mahbe :D.

 

[package net.morehorror.mod.blocks;

import java.util.ArrayList;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.morehorror.mod.MoreHorror;
import net.morehorror.mod.tileentity.TileEntityCorpse;
import net.morehorror.mod.tileentity.TileEntityCreatureTable;
import net.morehorror.mod.tileentity.TileEntityPlank;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class Plank1 extends BlockContainer{
public Plank1(Material m) {
	super(m);
	this.setHardness(2.0F);
	this.setResistance(5.0F);
	this.setBlockBounds(0F, 0.3125F,0.935F, 1.0F, 0.875F, 1.0F);
	this.setCreativeTab(MoreHorror.MoreHorrorTab);	}

public void onBlockAdded(World world, int x, int y, int z) {
super.onBlockAdded(world, x, y, z);
this.setDefaultDirection(world, x, y, z);
}

public int getRenderType() {
return -3;
}

public boolean isOpaqueCube() {
return false;
}

public boolean renderAsNormalBlock() {
return false;
}

@Override
public TileEntity createNewTileEntity(World var1, int var2) {
return new TileEntityPlank();
}

@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
this.blockIcon = iconRegister.registerIcon(MoreHorror.modid + ":" + this.getUnlocalizedName().substring(5));
}

@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack)
{
int l = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.F) + 0.5D) & 3;
if (l == 0){
this.setBlockBounds(0F, 0.3125F,0.935F, 1.0F, 0.875F, 1.0F);
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
}

if (l == 1){
this.setBlockBounds(0F, 0.3125F,0.935F, 1.0F, 0.875F, 1.0F);
world.setBlockMetadataWithNotify(x, y, z, 5, 2);
}

if (l == 2){
this.setBlockBounds(0F, 0.3125F,0.0F, 1.0F, 0.875F, 0.065F);
world.setBlockMetadataWithNotify(x, y, z, 3, 2);
}

if (l == 3){
this.setBlockBounds(0F, 0.3125F,0.935F, 1.0F, 0.875F, 1.0F);
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
}

TileEntityPlank tile = (TileEntityPlank) world.getTileEntity(x, y, z);
tile.direction = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
}


private void setDefaultDirection(World world, int x, int y, int z) {
if(!world.isRemote) {
	Block b1 = world.getBlock(x, y, z - 1);
	Block b2 = world.getBlock(x,  y,  z + 1);
	Block b3 = world.getBlock(x - 1, y, z);
	Block b4  = world.getBlock(x + 1, y, z);

	byte b0 = 3;

	if(b1.func_149730_j() && !b2.func_149730_j()) {
		b0 = 3;	
	}

	if(b2.func_149730_j() && !b1.func_149730_j()) {
		b0 = 2;	
	}

	if(b3.func_149730_j() && !b4.func_149730_j()) {
		b0 = 5;	
	}

	if(b4.func_149730_j() && !b3.func_149730_j()) {
		b0 = 4;	
	}

	world.setBlockMetadataWithNotify(x, y, x, b0, 2);
}

}

}

]

Posted


	world.setBlockMetadataWithNotify(x, y, x, b0, 2);

 

what? x, y, x?

It has to be x, y, z

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Hi

 

Did you override setBlockBoundsBasedOnState()  and perhaps addCollisionBoxesToList() like BlockSlab does?

 

They are used to set the correct block bounds immediately before rendering (and collision detection)

 

-TGG

 

 

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

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

×
×
  • Create New...

Important Information

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