summaryrefslogtreecommitdiff
path: root/ihl/explosion/PileBlock.java
blob: a2c56c3eedbccc43ec2a38f1c72a9a8bbebcf81f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package ihl.explosion;

import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ihl.IHLModInfo;
import ihl.items_blocks.IHLItemBlock;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class PileBlock extends Block implements ITileEntityProvider
{
	public static PileBlock instance;
	public static int id;
	protected PileBlock(Material material) {
		super(material);
		this.setBlockName("pileBlock");
		this.setBlockTextureName("tubBronzeIcon");
		instance = this;
		this.setBlockBounds(0f, 0f, 0f, 1f, 0.5f, 1f);
	}
	
	@Override
	public void onNeighborBlockChange(World world, int x, int y, int z, Block block)
	{
		if(!world.isRemote)
		{
			PileTileEntity pte = (PileTileEntity)world.getTileEntity(x, y, z);
			pte.checkAndFall();
		}
	}
	
	@Override
	public int getRenderType()
	{
		return PileBlockRender.renderId;
	}

	@Override
	public TileEntity createNewTileEntity(World word, int metadata) {
		return new PileTileEntity();
	}
	
	public static void init()
	{
		GameRegistry.registerBlock(new PileBlock(Material.sand), IHLItemBlock.class,"pileBlock");
		GameRegistry.registerTileEntity(PileTileEntity.class, "pileBlockTileEntity");
		id = Block.getIdFromBlock(instance);
	}
	
	@Override
	public boolean isOpaqueCube()
	{
		return false;
	}

	@Override
	public boolean renderAsNormalBlock()
	{
		return false;
	}
	
	@Override
	@SideOnly(Side.CLIENT)
	public void registerBlockIcons(IIconRegister par1IconRegister)
	{
		this.blockIcon = par1IconRegister.registerIcon(IHLModInfo.MODID + ":fluidAcetyleneFlowing");
	}
	
	@Override
	public boolean onBlockActivated(World world,int x,int y,int z,EntityPlayer entityPlayer,int i,float pos_x,float pos_y,float pos_z)
	{
		if(!world.isRemote && world.getTileEntity(x,y,z) instanceof PileTileEntity)
    	{
			PileTileEntity te = (PileTileEntity)world.getTileEntity(x,y,z);
			if(entityPlayer.inventory.addItemStackToInventory(te.content))
			{
				te.content=null;
				world.setBlockToAir(x, y, z);
				entityPlayer.inventoryContainer.detectAndSendChanges();
				return true;
			}
    	}
		return false;
	}
	
	@Override
	public void onBlockHarvested(World world,int x,int y,int z,int  meta, EntityPlayer entityPlayer)
	{
		if(!world.isRemote && world.getTileEntity(x,y,z) instanceof PileTileEntity)
    	{
			PileTileEntity te = (PileTileEntity)world.getTileEntity(x,y,z);
			if(entityPlayer.inventory.addItemStackToInventory(te.content))
			{
				te.content=null;
				entityPlayer.inventoryContainer.detectAndSendChanges();
			}
    	}
	}
	
	@Override
	@SideOnly(Side.CLIENT)
	public IIcon getIcon(IBlockAccess world, int x,int y,int z,int  meta)
	{
		if(world.getTileEntity(x,y,z) instanceof PileTileEntity)
    	{
			PileTileEntity te = (PileTileEntity)world.getTileEntity(x,y,z);
			if(te.content!=null)
			{
				return te.content.getIconIndex();
			}
    	}
		return this.blockIcon;
	}
	
	@Override
	public void	dropBlockAsItemWithChance(World world, int x, int y, int z, int meta, float chance, int flag){}
}