Search in sources :

Example 11 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ItemSystemLinker method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    IBlockState state = worldIn.getBlockState(pos);
    Block block = state.getBlock();
    NBTTagCompound stackCompound = stack.getTagCompound();
    if (stackCompound == null) {
        stackCompound = new NBTTagCompound();
        stack.setTagCompound(stackCompound);
    }
    if (block instanceof BlockHovercraftController) {
        if (!worldIn.isRemote) {
            NBTUtils.writeBlockPosToNBT("controllerPos", pos, stackCompound);
            playerIn.addChatMessage(new TextComponentString("ControllerPos set <" + pos.getX() + ":" + pos.getY() + ":" + pos.getZ() + ">"));
        } else {
            return EnumActionResult.SUCCESS;
        }
    }
    if (block instanceof BlockEtherCompressor) {
        if (!worldIn.isRemote) {
            BlockPos controllerPos = NBTUtils.readBlockPosFromNBT("controllerPos", stackCompound);
            if (controllerPos.equals(BlockPos.ORIGIN)) {
                playerIn.addChatMessage(new TextComponentString("No selected Controller"));
            } else {
                PhysicsWrapperEntity controllerWrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(worldIn, controllerPos);
                PhysicsWrapperEntity engineWrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(worldIn, pos);
                if (controllerWrapper != engineWrapper) {
                    playerIn.addChatMessage(new TextComponentString("Controller and Engine are on seperate ships"));
                    return EnumActionResult.SUCCESS;
                }
                TileEntity worldTile = worldIn.getTileEntity(pos);
                if (worldTile instanceof TileEntityEtherCompressor) {
                    TileEntityEtherCompressor tileEntity = (TileEntityEtherCompressor) worldTile;
                    BlockPos gravControllerPos = tileEntity.controllerPos;
                    if (gravControllerPos.equals(BlockPos.ORIGIN)) {
                        playerIn.addChatMessage(new TextComponentString("Set Controller To " + controllerPos.toString()));
                    } else {
                        playerIn.addChatMessage(new TextComponentString("Replaced controller position from: " + gravControllerPos.toString() + " to: " + controllerPos.toString()));
                    }
                    tileEntity.setController(controllerPos);
                }
            }
        } else {
            return EnumActionResult.SUCCESS;
        }
    }
    return EnumActionResult.PASS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockHovercraftController(ValkyrienWarfareControl.Block.BlockHovercraftController) BlockEtherCompressor(ValkyrienWarfareBase.API.Block.EtherCompressor.BlockEtherCompressor) IBlockState(net.minecraft.block.state.IBlockState) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) TileEntityEtherCompressor(ValkyrienWarfareBase.API.Block.EtherCompressor.TileEntityEtherCompressor) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 12 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project Overloaded by CJ-MC-Mods.

the class AbstractBlockHyperReceiver method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    ItemStack heldItem = playerIn.getHeldItem(hand);
    if (heldItem.getItem().equals(ModItems.linkingCard)) {
        NBTTagCompound tag = heldItem.getTagCompound();
        if (tag == null) {
            tag = new NBTTagCompound();
        }
        int worldId = worldIn.provider.getDimension();
        writeNodeData(tag, worldId, pos);
        heldItem.setTagCompound(tag);
        if (worldIn.isRemote) {
            playerIn.sendStatusMessage(new TextComponentString(String.format("Recorded: World: %d Position: %s", worldId, pos.toString())), false);
        }
        return true;
    } else {
        return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 13 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project Overloaded by CJ-MC-Mods.

the class AbstractBlockHyperSender method onBlockActivated.

@Override
public boolean onBlockActivated(@Nonnull World worldIn, @Nonnull BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (hand == EnumHand.MAIN_HAND) {
        ItemStack heldItem = playerIn.getHeldItem(hand);
        if (heldItem.isEmpty()) {
            // Should find a cleaner way of showing all of this
            if (!worldIn.isRemote) {
                String message = ((AbstractTileHyperSender) worldIn.getTileEntity(pos)).getRightClickMessage();
                playerIn.sendStatusMessage(new TextComponentString(message), false);
            }
        } else if (heldItem.getItem().equals(ModItems.linkingCard)) {
            NBTTagCompound tag = heldItem.getTagCompound();
            if (tag != null) {
                if (tag.getString("TYPE").equals(this.getType())) {
                    int worldID = tag.getInteger("WORLD");
                    int x = tag.getInteger("X");
                    int y = tag.getInteger("Y");
                    int z = tag.getInteger("Z");
                    bindToPartner(worldIn, pos, worldID, new BlockPos(x, y, z));
                    heldItem.setTagCompound(null);
                    if (worldIn.isRemote) {
                        playerIn.sendStatusMessage(new TextComponentString("Bound Hyper Nodes"), true);
                    }
                } else {
                    if (worldIn.isRemote) {
                        playerIn.sendStatusMessage(new TextComponentString("Incorrect Hyper Node Type to bind."), true);
                    }
                }
            }
        }
        return true;
    }
    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
}
Also used : AbstractTileHyperSender(com.cjm721.overloaded.block.tile.hyperTransfer.base.AbstractTileHyperSender) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 14 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project AgriCraft by AgriCraft.

the class ItemMagnifyingGlass method onItemUseFirst.

//this is called when you right click with this item in hand
@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    if (world.isRemote) {
        List<String> list = new ArrayList<>();
        IBlockState state = world.getBlockState(pos);
        Block block = state.getBlock();
        TileEntity te = world.getTileEntity(pos);
        // Add a separator.
        list.add("========== " + AgriCore.getTranslator().translate("item.agricraft:magnifying_glass.name") + " ==========");
        // Add lighting information.
        list.add("Brightness: (" + world.getLightFromNeighbors(pos.up()) + "/15)");
        // Add block information.
        if (block instanceof IAgriDisplayable) {
            ((IAgriDisplayable) block).addDisplayInfo(list::add);
        }
        // Add tile information.
        if (te instanceof IAgriDisplayable) {
            ((IAgriDisplayable) te).addDisplayInfo(list::add);
        }
        // Display information.
        for (String msg : list) {
            player.addChatComponentMessage(new TextComponentString(msg));
        }
    }
    return EnumActionResult.SUCCESS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) ArrayList(java.util.ArrayList) IAgriDisplayable(com.infinityraider.agricraft.api.v1.misc.IAgriDisplayable) Block(net.minecraft.block.Block) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 15 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project ConvenientAdditions by Necr0.

the class ItemPlayerChannelModule method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack item = player.getHeldItem(hand);
    if (!world.isRemote) {
        if (!item.hasTagCompound())
            item.setTagCompound(new NBTTagCompound());
        NBTTagCompound t = item.getTagCompound();
        if (!player.isSneaking()) {
            t.setString("MATCHER_PLAYER_ID", player.getUniqueID().toString());
            t.setString("MATCHER_PLAYER_NAME", player.getDisplayNameString());
            player.sendMessage(new TextComponentString(Helper.localize("message." + ModConstants.Mod.MODID + ":playerSetTo", player.getDisplayNameString())));
            new ActionResult<>(EnumActionResult.SUCCESS, item);
        } else {
            t.removeTag("MATCHER_PLAYER_ID");
            t.removeTag("MATCHER_PLAYER_NAME");
            player.sendMessage(new TextComponentString(Helper.localize("message." + ModConstants.Mod.MODID + ":playerReset")));
            new ActionResult<>(EnumActionResult.SUCCESS, item);
        }
    }
    return new ActionResult<>(EnumActionResult.PASS, item);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

TextComponentString (net.minecraft.util.text.TextComponentString)343 EntityPlayer (net.minecraft.entity.player.EntityPlayer)79 ItemStack (net.minecraft.item.ItemStack)68 BlockPos (net.minecraft.util.math.BlockPos)60 ITextComponent (net.minecraft.util.text.ITextComponent)48 TileEntity (net.minecraft.tileentity.TileEntity)41 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)35 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)32 Colony (com.minecolonies.coremod.colony.Colony)26 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)26 IBlockState (net.minecraft.block.state.IBlockState)23 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)21 Style (net.minecraft.util.text.Style)21 IColony (com.minecolonies.api.colony.IColony)19 ClickEvent (net.minecraft.util.text.event.ClickEvent)19 Entity (net.minecraft.entity.Entity)18 Block (net.minecraft.block.Block)17 World (net.minecraft.world.World)17 ArrayList (java.util.ArrayList)16 ActionResult (net.minecraft.util.ActionResult)13