Jump to content

Recommended Posts

Posted

Hello to all and nice to meet you since this is my first post here  :)

 

Ive read similar post about my question but since no two issues are alike im making this post hoping one of you can help me.

 

Im making my first mod and made a custom block that is 2 blocks tall

now i managed to get it render properly and place on the world.

 

the problem i have is this the lower block works just fine but i cant click on the second top block nor has any collation on it.

 

here is the code im using

 

package com.projects.tallblocksample.blocks;

import java.util.Random;
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.entity.player.EntityPlayer;
import net.minecraft.item.Item;
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 com.projects.tallblocksample.tallblocksample;
import com.projects.tallblocksample.tileentity.TileEntityTallBlock;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class TallBlockBlock extends BlockContainer {

public TallBlockBlock() {
	super(Material.wood);
	this.setHardness(2.0F);
	this.setResistance(5.0F);
	this.setBlockBounds(0.05F, 0.05F, 0.05F, 0.95F, 2F, 0.95F);
	this.setCreativeTab(tallblocksample.tabtallblocksample);

}

public int getRenderType() {
	return -1;
}

public boolean isOpaqueCube() {
	return false;
}

public boolean renderAsNormalBlock() {
	return false;
}

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

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

public Item getItemDropped(int i, Random random, int j) {
	return Item.getItemFromBlock(tallblocksample.blockTallBlock);
}

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

}

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);
	}

}

public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityplayer, ItemStack itemstack) 
{
	int l = MathHelper.floor_double((double)(entityplayer.rotationYaw * 4.0F / 360.F) + 0.5D) & 3;
	if(l == 0) 
	{
		world.setBlockMetadataWithNotify(x, y, z, 3, 1); 
	}
	if(l == 1) 
	{
		world.setBlockMetadataWithNotify(x, y, z, 4, 1); 
	}
	if(l == 2) 
	{
		world.setBlockMetadataWithNotify(x, y, z, 1, 1);
	}
	if(l == 3) 
	{
		world.setBlockMetadataWithNotify(x, y, z, 2, 1);
	}
	if(itemstack.hasDisplayName()) 
	{
		//TO DO
	}
}
}

 

i realize this might be easy for some of you but please understand im new to MC modding (not new to coding)

 

thank you very much in advance

 

ps: sry English not my first language doing my best  ::)

Posted

I'd make an invisible filler block for the top that has the same breaking characteristics and calls the bottom's methods for things like onblockdestroy or onRightClick... (Whatever you're using). The bottom block would destroy the top one on onBlockDesteoy.

Posted
  On 9/11/2014 at 2:09 AM, david476 said:

I'd make an invisible filler block for the top that has the same breaking characteristics and calls the bottom's methods for things like onblockdestroy or onRightClick... (Whatever you're using). The bottom block would destroy the top one on onBlockDesteoy.

 

interesting suggestion, ty, but do you know of anyway to set the size of the model to 2x blocks high?

Posted
  On 9/11/2014 at 2:09 AM, david476 said:

I'd make an invisible filler block for the top that has the same breaking characteristics and calls the bottom's methods for things like onblockdestroy or onRightClick... (Whatever you're using). The bottom block would destroy the top one on onBlockDesteoy.

 

UPDATE: hey david ive been doing some test based on ur idea and is looking promising, ty again for the idea

Posted

I have done this for several blocks in my mod, was pretty hard to figure out, but now I know how, it is really easy.

 

Now it is impossible to make a block larger than 1x1x1 without gag blocks, at least, I couldn't figure it out, and so used this method, but it works great, gui's work, dont have to break all the gag blocks individually etc.

 

Now please for the sake of learning how to do this, don't copy and paste, you wont learn anything, and wont know how to fix any problems, or adapt my code to fit your code. For me, the only acception for copying and pasting code, is if you absolutely understand how it works, and what it all does, and wont learn anything you don't already know.

 

Here I will show you how to make a block more than one meter high, and also, at the end, a trick to make it look like the blocks bounding box is all one, where in reality, it is several blocks.

Method:

 

  Reveal hidden contents

 

 

Hope this helped.

 

Ps- I noticed that you are setting the blocks rotation with metadata in the main block class, now if you have a model, this wont work, the block will rotate, but the model wont, so unless you have already done so, rotate the model with GL11.rotatef(amount, rotateX, rotateY, rotateZ); and do this based on the metadata in the main block.

Just pointing that out.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

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



×
×
  • Create New...

Important Information

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