Jump to content

[1.7.10] Don't want block to damage while in it


EmperorZelos

Recommended Posts

I am trying to make an illusion block, I know it has been done but half the fun is trying to do it yourself and figure out things. Unfortunately I am stuck at something. When I have the blocks placed in 1 high, either along the ground or one block above the ground it works fine, I can walk straight through the block and nothing happens, however when I put them it such that there is 1 block on the ground and then another block ontop of that, making them together 2 blocks high. THere is suddenly a wall on one of the sides of this 1 by 2 pile that I can't pass through and if I enter any other side it pushes me in the direction of this side I can't pass through. WHen I am in survival mode I ahve noticed however this is causing me damage so I am presuming I need to fix it so you can breath in it like it was air or something, I just seem to have trouble finding the proper function for that. What am I missing that would allow me to fix this?

 

package aerosteam.blocks.magic;

import net.minecraft.block.Block;
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.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import aerosteam.AeroSteam;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class MagicIllusion extends Block{

@SideOnly(Side.CLIENT)
private IIcon Icon;

public MagicIllusion() {
	super(Material.rock);
	this.setCreativeTab(AeroSteam.aeroTab);
	this.setBlockBounds(0, 0, 0, 0, 0, 0);
	// TODO Auto-generated constructor stub
}

@SideOnly(Side.CLIENT)
    public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side)
    {

	IIcon icon=this.blockIcon;
	int meta = world.getBlockMetadata(x, y, z);
	if (meta <6){
		ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[meta];
		Block block = world.getBlock(x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ);
		if (block.getRenderType() == 0) icon = block.getIcon(world, x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ, side);
	}

        return icon;
    }

@SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister icon)
    {
        this.blockIcon = icon.registerIcon(AeroSteam.MODID + ":" + "illusion");
    }
public int getRenderType(){
	return 0;
}

public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side){
	return true;
}
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 ;
	int t = MathHelper.floor_double((double)(entityplayer.rotationPitch * 4.0F/360.F)+0.5D) & 3;
	ForgeDirection dir = getDir(t,l);
	Block block = world.getBlock(x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ);
	if (isBlockValid(block)){
		if (!isCircular(world,x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ,x,y,z)){
			world.setBlockMetadataWithNotify(x, y, z, metaForge(dir), 2);
			return;
		}
	}
	for (int i = 0;i<6;i++){
		dir = ForgeDirection.VALID_DIRECTIONS[i];
		block = world.getBlock(x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ);
		if (isBlockValid(block)){
			world.setBlockMetadataWithNotify(x, y, z, i, 2);
			return;
		}
	}

}
public boolean isBlockValid(Block block){
	return block != Blocks.air && block.getRenderType() == 0;
}
public int metaForge(ForgeDirection dir){
	for (int i=0;i<6;i++){
		if (ForgeDirection.VALID_DIRECTIONS[i]==dir) return i;
	}
	return 7;
}
public ForgeDirection getDir(int t, int l){
	if (t==1) return ForgeDirection.DOWN;
	if (t==3) return ForgeDirection.UP;
	if (l==0) return ForgeDirection.SOUTH;
	if (l==1) return ForgeDirection.WEST;
	if (l==2) return ForgeDirection.NORTH;
	if (l==3) return ForgeDirection.EAST;
	return null;
}

public boolean 	onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ){
	int meta = world.getBlockMetadata(x, y, z);
	for (int i = 1;i<7;i++){
		int delta = (meta + i) % 6;
		ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[delta];
		Block block = world.getBlock(x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ);
		if (isBlockValid(block)){
			if (!isCircular(world,x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ,x,y,z)){
				world.setBlockMetadataWithNotify(x, y, z, delta, 2);
				break;
			}
		}
	}
	//System.out.println("meta: " + meta);
	return false;
}
public void onNeighborBlockChange(World world, int x, int y, int z, Block block){
	int meta = world.getBlockMetadata(x, y, z);
	if (meta < 6){
		ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[meta];
		if (world.isAirBlock(x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ)){
			for (int i = 1;i<7;i++){
				int delta = (meta + i) % 6;
				dir = ForgeDirection.VALID_DIRECTIONS[delta];
				Block blocky = world.getBlock(x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ);
				if (isBlockValid(blocky)){
					if (!isCircular(world,x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ,x,y,z)){
						world.setBlockMetadataWithNotify(x, y, z, delta, 2);
						return;
					}
				}
			}
			world.setBlockMetadataWithNotify(x, y, z, 6, 2);
		}
	}else{
		ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[0];
		for (int i = 0;i<6;i++){
			dir = ForgeDirection.VALID_DIRECTIONS[i];
			Block test = world.getBlock(x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ);
			if (isBlockValid(test)){
				world.setBlockMetadataWithNotify(x, y, z, i, 2);
				return;
			}
		}
	}

}
public boolean isCircular(World world,int x,int y,int z,int sX,int sY,int sZ){
	if (sX==x && sY==y & sZ==z) return true;
	int meta = world.getBlockMetadata(x, y, z);
	ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[meta];
	Block block = world.getBlock(x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ);
	if (block != this) return false;
	return isCircular(world,x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ,sX,sY,sZ);
}
public Block source(World world,int x,int y,int z){
	int meta = world.getBlockMetadata(x, y, z);
	ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[meta];
	Block kern = world.getBlock(x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ);
	if (kern==this){
		kern = source(world,x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ);
	}
	return this;
}
/*public Block source(World world,int x,int y,int z){
	int meta = world.getBlockMetadata(x, y, z);
	ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[meta];
	Block block = world.getBlock(x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ);
	if (block==this){
		return source(world,x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ);
	}
	return this;
}*/
    public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_, int p_149668_4_)
    {
        return null;
    }
    public boolean isOpaqueCube()
    {
        return false;
    }
    public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_) {
    	this.setBlockBounds(0,0,0,1,1,1);
    }
}

 

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.

Announcements



×
×
  • Create New...

Important Information

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