aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/blocks/Block_ItemProxyEndpoint.java
blob: 762880c8779a26dec150607f7f2c9f0cc4a6bd6e (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 java.util.UUID;

import cpw.mods.fml.common.registry.GameRegistry;
import itemBlocks.IB_ItemProxyEndpoint;
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.tileentity.TileEntity;
import net.minecraft.world.World;
import tileentities.TE_ItemProxyEndpoint;

public class Block_ItemProxyEndpoint extends BlockContainer {
	
	private static Block_ItemProxyEndpoint instance = new Block_ItemProxyEndpoint();
	
	private Block_ItemProxyEndpoint() {
		super(Material.glass);
	}
	
	public static Block_ItemProxyEndpoint getInstance() {
		return instance;
	}
	
	public void registerBlock() {
		final String blockName = "kekztech_itemproxyendpoint_block";
		super.setBlockName(blockName);
		super.setCreativeTab(CreativeTabs.tabMisc);
		super.setBlockTextureName(KekzCore.MODID + ":" + "ItemProxyEndpoint");
		super.setHardness(3.0f);
		super.setResistance(2.0f);
		GameRegistry.registerBlock(getInstance(), IB_ItemProxyEndpoint.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_ItemProxyEndpoint) {
			final TE_ItemProxyEndpoint endpoint = (TE_ItemProxyEndpoint) te;
			if(player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem().getItem() instanceof Item_Configurator) {
				
				final ItemStack held = player.inventory.getCurrentItem();
				if(held.hasTagCompound() && held.getTagCompound().hasKey("config")) {
					endpoint.setChannel(UUID.fromString(held.getTagCompound().getString("config")));
				}
			} else {
				player.openGui(KekzCore.instance, GuiHandler.ITEM_PROXY_ENDPOINT, world, x, y, z);				
			}
			return true;
		}
		return false;
	}
	
	@Override
	public TileEntity createNewTileEntity(World world, int p_149915_2_) {
		return new TE_ItemProxyEndpoint();
	}

}