aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/blocks/Block_ItemProxySource.java
blob: b2cdd4a6563026effb3831d100d465e867d29da5 (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
package blocks;

import cpw.mods.fml.common.registry.GameRegistry;
import itemBlocks.IB_ItemProxySource;
import items.Item_Configurator;
import kekztech.GuiHandler;
import kekztech.KekzCore;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import tileentities.TE_ItemProxySource;

public class Block_ItemProxySource extends BlockContainer {
	
	private static Block_ItemProxySource instance = new Block_ItemProxySource();
	
	private Block_ItemProxySource() {
		super(Material.glass);
	}
	
	public static Block_ItemProxySource getInstance() {
		return instance;
	}
	
	public void registerBlock() {
		final String blockName = "kekztech_itemproxysource_block";
		super.setBlockName(blockName);
		super.setCreativeTab(CreativeTabs.tabMisc);
		super.setBlockTextureName(KekzCore.MODID + ":" + "ItemProxySource");
		super.setHardness(3.0f);
		super.setResistance(2.0f);
		GameRegistry.registerBlock(getInstance(), IB_ItemProxySource.class, blockName);
	}
	
	@Override
	public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float lx, float ly, float lz) {
		if(world.isRemote) {
			return true;
		}
		
		final TileEntity te = world.getTileEntity(x, y, z);
		if(te != null && te instanceof TE_ItemProxySource) {
			final TE_ItemProxySource source = (TE_ItemProxySource) te;
			if(player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem().getItem() instanceof Item_Configurator) {
				
				final NBTTagCompound configNBT = new NBTTagCompound();
				configNBT.setString("config", source.getChannel().toString());
				final ItemStack held = player.inventory.getCurrentItem();
				held.setTagCompound(configNBT);
				
			} else {
				player.openGui(KekzCore.instance, GuiHandler.ITEM_PROXY_SOURCE, world, x, y, z);				
			}
			return true;
		}
		return false;
	}
	
	@Override
	public TileEntity createNewTileEntity(World world, int p_149915_2_) {
		return new TE_ItemProxySource();
	}

}