Jump to content

Custom Rendered Block Larger than 1x1x1 & Item damage inside inventory[UNSOLVED]


TheEpicTekkit

Recommended Posts

Hello everyone, sorry to bother you again, but I have some questions about a custom rendered block that is larger than 1 block. I am still working on my wind turbine, and I would like to do two things that I have been trying to figure out all day.

 

One: I cant seem to figure out how to set the hitbox for the model (it is about 1.4 blocks in width and depth, and 10 blocks high), I can set the block bounds, but I can still walk through it (I cant walk through the bottom part because that is solid as it is in 1x1x1 space but I can walk through any part of it above that) also, the block bounds don't show up unless I mouse over the bottom 1x1x1 space that actually has the hitbox. Is it possible to extend the hitbox of the block to a space larger than 1 block without using invisible gag blocks. And if I do end up having to use gag blocks, how would I go about doing this, would I need a different gag block for different models larger that 1 block, or would I be able to use the same gag block with different metadata? and how would I make all the gag blocks disappear if one is broken.

 

two: how would I make the rendered model face the player when placed? I know how to make  normal block face the player, but it doesn't work for a custom rendered block. I have got this in the block class:

 

 

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

and then:

private void setDefaultDirection(World world, int x, int y, int z) {
	if (!world.isRemote) {
		Block block = world.getBlock(x, y, z - 1);
		Block block1 = world.getBlock(x, y, z + 1);
		Block block2 = world.getBlock(x - 1, y, z);
		Block block3 = world.getBlock(x + 1, y, z);
		byte b0 = 3;

		if (block.func_149730_j() && !block1.func_149730_j()) {
			b0 = 3;
		}

		if (block1.func_149730_j() && !block.func_149730_j()) {
			b0 = 2;
		}

		if (block2.func_149730_j() && !block3.func_149730_j()) {
			b0 = 5;
		}

		if (block3.func_149730_j() && !block2.func_149730_j()) {
			b0 = 4;
		}
		world.setBlockMetadataWithNotify(x, y, z, b0, 2);
	}
}

and finally:

public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack) {
	int l = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

	if (l == 0) {
		world.setBlockMetadataWithNotify(x, y, z, 2, 2);
	}

	if (l == 1) {
		world.setBlockMetadataWithNotify(x, y, z, 5, 2);
	}

	if (l == 2) {
		world.setBlockMetadataWithNotify(x, y, z, 3, 2);
	}

	if (l == 3) {
		world.setBlockMetadataWithNotify(x, y, z, 4, 2);
	}

	if (itemStack.hasDisplayName()) {
		((TileEntityWindTurbine)world.getTileEntity(x, y, z)).setGuiDisplayName(itemStack.getDisplayName());
	}
	TileEntityWindTurbine tile = (TileEntityWindTurbine) world.getTileEntity(x, y, z);
}

 

 

Now, what do I have to add to the renderer class or block class to make this rotate the model?

 

Thanks for your help.

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

Link to comment
Share on other sites

It's actually quite simple. In your block class's constructor, type:

this.setBlockBounds(minX, minY, minZ, maxX, maxY, maxZ);

 

This is the simplest way of doing it. Please note, do not actually write minX and such, write the actual numbers you would like. There are definitely much better ways of doing it, like this one:

 

public AxisAlignedBB getCollisionBoundingBoxFromPool (World w, int x, int y, int z) {
                setBlockBounds(minX, minY, minZ, maxX, maxY, maxZ);		

	return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ);
}

@SideOnly(Side.CLIENT)
public AxisAlignedBB getSelectedBoundingBoxFromPool(World w, int x, int y, int z) {
                setBlockBounds(minX, minY, minZ, maxX, maxY, maxZ);	

	return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ);
}

 

If you would like to set the bounds based on metadata:

 

public void setBlockBoundsBasedOnState(IBlockAccess iba, int x, int y, int z) {
	float pixel = 1F/16F;

	if(iba.getBlockMetadata(x, y, z) < metadataYouWouldLike) {
		this.setBlockBounds(pixel*4, 0, pixel*4, 1-pixel*4, 1, 1-pixel*4);
	} else {
		this.setBlockBounds(0, 0, 0, 1, 1, 1);
	}
}

 

So, as you can see, it is not too difficult. After you have done that, simply render the block to be more than 16 pixels in your render file and you are good to go.

I am the self-nominated Lord of the Mastodons and don't you dare deny it. ;) Also, check out my YouTube channel: https://www.youtube.com/user/DerpDerp44/

Link to comment
Share on other sites

I have tried this (I should have actually included that bit in my first post) this just sets the block bounds, the actual hitbox is still only 1x1x1 and I still can go through any other part of the model and place blocks inside the blockbounds. I still dont know how mc allows that.

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

Link to comment
Share on other sites

Which method did you try? You are better off with AABB than the constructor version. As to your rotation problem, use

GL.rotatef(xRotation, yRotation, and zRotation);

This should solve your problem.

I am the self-nominated Lord of the Mastodons and don't you dare deny it. ;) Also, check out my YouTube channel: https://www.youtube.com/user/DerpDerp44/

Link to comment
Share on other sites

Okay, let me try this, and i'll update you on how it went.

Also, i tried the AxisAlignBB thing you said as it was a bit different from the one i already had, and for the setBlockBounds bit it has an error and says "create method setBlockBounds(double, double, double, double, double, double) i tried changing it to this.setBlockBounds.... and it still had the same error.

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

Link to comment
Share on other sites

Why you are using doubles is what I want to know. Use floats. That is the method Minecraft provides you with. If you started off with doubles, cast them to floats in the method itself. Also, don't specifically try to write out minX, as that is not what I meant.

I am the self-nominated Lord of the Mastodons and don't you dare deny it. ;) Also, check out my YouTube channel: https://www.youtube.com/user/DerpDerp44/

Link to comment
Share on other sites

If you don't manage to get it bigger than one block, try making the placement of one block place multiple blocks using world.setBlock and then cancel the default onBlockHighlightedEvent, and make a new one to make it seem like it's bigger than one block, when it's really not. If you're trying to make it something like 1.4 blocks wide, then you will have to make multiple block types.

I am the self-nominated Lord of the Mastodons and don't you dare deny it. ;) Also, check out my YouTube channel: https://www.youtube.com/user/DerpDerp44/

Link to comment
Share on other sites

Right, so it still hasn't worked properly, it has set the blockbounds correctly, but it displays them only when i hover over the default 1x1x1 space which is what it did before.

 

How do I attach a screenshot to my post? i wanna show u what is happening

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

Link to comment
Share on other sites

Okay, so how would I go about making it out of multiple blocks? I have never done that before. I know the world.setBlock method, but how would I make all of the gag blocks have the same gui, because I would have thought that having a bolck made of multiple blocks would cause the gag blocks to have a different inventory. for example, if I open the gui from the bottom block, and place something inside, then opened the gui from another block, the items would only be in the bottom block because the gag blocks would have a new instance of the tileEntity for each one, as if they were individual wind turbines in the world. so I would end up with 10 different inventories for a 10 block tall model.

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

Link to comment
Share on other sites

Okay, thanks, i'll try that, but how will I make it search downwards, also, I want things like pipes or hoppers to be able t interact with the inventory, how would I make it so that if the pipe is connected to one of the gag blocks, it pipes out of or into the bottom?

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

Link to comment
Share on other sites

How would I make the fake tileEntitys reference the main TileEntity, and how would I make items in the fake tileEntitys be transfered to the main one? Also (probably a dumb question, but) would I have a different tileEntity for each gag block?

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

Link to comment
Share on other sites

Okay, thanks for your help, i'm gonna do this, than update here how it went.

And I don't know why I thought the gag blocks needed an individual tileEntity. I just had a derp moment :P

 

I am gonna do the gag blocks with a different metadata though so that i can set the block bounds based on metadata, so that for example, if you look at the bottom gag block, the block bounds extend 1 block downwards, and 7 blocks up, if you look at the second gag block, the bounds extend 2 blocks down, and 6 up, so it looks like you are looking at the same block all the time.

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

Link to comment
Share on other sites

now, another thing i cant figure out, is how do I get the wind turbine block to place the gag block, in the

onBlockAdded(World world, int x, int y, int z) {...

method i have this:

super.onBlockAdded(world, x, y, z);
	for (int i = 0; i < this.height; i++) {
		world.setBlock(x, y+1+i, z, BlockHandler.gagWindTurbine, i, 2);
	}

(where it says this.height, there is an integer called height and has a value of 8.)

Now i want this to place the gag block up to the height of the wind turbine (which it does) but with a different metadata value for each block, currently it only places the same metadata: 0. for the first gag block i want it to place metadata 0, the second i want it to place metadata 1 etc all the way upto 8, so there is 9 blocks with different metadata.

This is what my block class looks like:

package net.theepictekkit.generator.common.blocks.advanced;

import java.util.List;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.theepictekkit.generator.GeneratorCreativeTabs;

public class BlockGagWindTurbine extends Block {

public BlockGagWindTurbine(Material mat) {
	super(mat);
	this.setHardness(4.0F);
	this.setResistance(4.0F);
	this.setCreativeTab(GeneratorCreativeTabs.Generator);
}

@Override
public int getRenderType() {
	return -1;
}

@Override
public boolean renderAsNormalBlock() {
	return false;
}

@Override
public boolean isOpaqueCube() {
	return false;
}

@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item itemStack, CreativeTabs tab, List list) {
	for (int i = 0; i < 8; ++i) {
		list.add(new ItemStack(itemStack, 1, i));
	}
}
}

(I dont want this block to render. Thats why i have the rendering methods in there)

Now i have looked at minecrafts wool block to see how they did metadata, and copied the relevant code from that class.

 

I just need the wind turbine to place the correct metadata when placed.

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

Link to comment
Share on other sites

Never mind, I just discovered that middle clicking on a metadata block no matter what metadata it has returns the block with metadata 0. There is a method that fixes this, but I cant remember what it is, nor do i need it as these are gag blocks

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

Link to comment
Share on other sites

If you would like, I can give you an example of a block that on placed would summon gag blocks wherever they needed to be. The way I did it was create an Item, and on right click the item would place the gag blocks, but I'm pretty sure it wouldn't be that hard to change over the code from onItemRightClick to onBlockAdded.

I am the self-nominated Lord of the Mastodons and don't you dare deny it. ;) Also, check out my YouTube channel: https://www.youtube.com/user/DerpDerp44/

Link to comment
Share on other sites

Okay, I now have the wind turbine properly adding gag blocks above it, in the right place and with the correct metadata.

And the gag blocks when break break all the gag blocks above it and below it including the actual wind turbine.

 

In the end, I decided to only have the inventory accessible from the bottom block instead of all of them.

 

Now, I am trying to make the actual turbine item inside the inventory take damage.

I would like it to take 1 damage every rotation of the rotor. I can't get this working either. I cant figure out the proper way of doing this, do I do this from the tileentity, or the block class?

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

Link to comment
Share on other sites

Okay, so the gag blocks are now working fine, they are in the right place, they have the correct metadata, and they break all the other gag blocks and the wind turbine when broken, and they drop the inventories contents instead of deleting them. In the end, i decided not to have the gag blocks open the wind turbines inventory because it was too complicated. and I thought about it, and thought there wasn't really much point.

 

Though now I have another problem (sorry to inconvenience you with all my problems today)

I am trying to make the turbine item inside the wind turbine take damage for every 36 degrees of rotation on the turbine. Any ideas on how I would do this? I have been trying to do this for about an hour now, and I cant get it working. Either what I have done has crashed the game, or simply done absolutely nothing.

 

Another question, would I be putting the method that damages the item in the block class or the tileentity class? I have tried both.

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

Link to comment
Share on other sites

My last 3 posts on this topic aren't showing up for me!?!? I can only see them from the reply page. post something below if you can see them because I don't know if this is just me or if they're not actually getting sent to the website.

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

Link to comment
Share on other sites

If you would like, I can give you an example of a block that on placed would summon gag blocks wherever they needed to be. The way I did it was create an Item, and on right click the item would place the gag blocks, but I'm pretty sure it wouldn't be that hard to change over the code from onItemRightClick to onBlockAdded.

Okay, all replies after this for some reason aren't showing up for me...

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

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.



×
×
  • Create New...

Important Information

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