Posted October 4, 201410 yr Alright so I have a block that can have multiple orientations but uses the same collision box for each. can you help me have a different collision box for each orientation.
October 4, 201410 yr 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
October 4, 201410 yr Author 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(); } ]
October 4, 201410 yr 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
October 4, 201410 yr Author 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 . [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); } } } ]
October 5, 201410 yr 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.
October 5, 201410 yr 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.