Search in sources :

Example 1 with INBTDataTransferable

use of arekkuusu.implom.api.capability.INBTDataTransferable in project Solar by ArekkuusuJerii.

the class ItemBoundPhoton method pickSource.

@SubscribeEvent(priority = EventPriority.LOWEST)
public void pickSource(PlayerInteractEvent.RightClickBlock event) {
    ItemStack stack = event.getItemStack();
    if (stack.getItem() == this) {
        if (!event.getWorld().isRemote) {
            TileEntity tile = event.getWorld().getTileEntity(event.getPos());
            if (tile instanceof INBTDataTransferable) {
                NBTTagCompound compound = stack.getOrCreateSubCompound(Constants.NBT_BOUND);
                String key = ((INBTDataTransferable) tile).group();
                NBTTagCompound tag = compound.getCompoundTag(key);
                if (!compound.hasKey(key))
                    compound.setTag(key, tag);
                EnumActionResult result = ((INBTDataTransferable) tile).init(tag);
                if (result != EnumActionResult.FAIL) {
                    TextComponentTranslation bound = new TextComponentTranslation("tlp." + key + ".group", TextFormatting.DARK_GRAY);
                    TextComponentTranslation action = new TextComponentTranslation("status.bound", bound, TextFormatting.BLACK);
                    event.getEntityPlayer().sendStatusMessage(action, true);
                }
            }
        }
        event.setCanceled(true);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumActionResult(net.minecraft.util.EnumActionResult) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) INBTDataTransferable(arekkuusu.implom.api.capability.INBTDataTransferable) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

INBTDataTransferable (arekkuusu.implom.api.capability.INBTDataTransferable)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1