Search in sources :

Example 1 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project minecolonies by Minecolonies.

the class AbstractEntityAIBasic method checkForWeapon.

/**
     * Ensures that we have a pickaxe available.
     * Will set {@code needsPickaxe} accordingly.
     *
     * @return true if we have a pickaxe
     */
public boolean checkForWeapon() {
    //Check for a pickaxe
    getOwnBuilding().setNeedsWeapon(!InventoryFunctions.matchFirstInProvider(worker, stack -> stack != null && Utils.doesItemServeAsWeapon(stack)));
    delay += DELAY_RECHECK;
    if (getOwnBuilding().needsWeapon()) {
        if (walkToBuilding()) {
            return false;
        }
        if (isWeaponInHut()) {
            return true;
        }
        requestWithoutSpam(new TextComponentTranslation("com.minecolonies.coremod.job.guard.needWeapon"));
    }
    return getOwnBuilding().needsWeapon();
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation)

Example 2 with TextComponentTranslation

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

the class MessageJumpPad method onMessage.

@Override
public MessageJumpPad onMessage(MessageJumpPad message, MessageContext ctx) {
    if (ctx.side == Side.CLIENT)
        return null;
    EntityPlayer p = ctx.getServerHandler().player;
    BlockPos pos = new BlockPos(p).down();
    if (p.world.getBlockState(pos).getBlock() == ModBlocks.jumpPad) {
        BlockPos target = ModBlocks.jumpPad.getTargetLocation(pos, p.world, !message.jump);
        if (target != null) {
            if (target.distanceSq(pos) > Math.pow(ModConfigMachines.jumpPad_range, 2)) {
                p.sendMessage(new TextComponentTranslation("message." + ModConstants.Mod.MODID + ":jumpPad.outOfRange"));
            } else if (!MinecraftForge.EVENT_BUS.post(new EnderTeleportEvent(p, target.getX() + .5, target.getY() + 1, target.getZ() + .5, 0f))) {
                p.world.playSound(null, p.posX, p.posY, p.posZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.BLOCKS, .15F, 2F);
                p.world.playSound(null, target.getX() + .5, target.getY() + 1, target.getZ() + .5, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.BLOCKS, .15F, 2F);
                p.setPositionAndUpdate(target.getX() + .5, target.getY() + 1, target.getZ() + .5);
            }
        }
    }
    return null;
}
Also used : EnderTeleportEvent(net.minecraftforge.event.entity.living.EnderTeleportEvent) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project ImmersiveEngineering by BluSunrize.

the class ItemIETool method onItemUseFirst.

//	@Override
//	public boolean doesContainerItemLeaveCraftingGrid(ItemStack stack)
//	{
//		return stack.getItemDamage()!=0;
//	}
@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    TileEntity tileEntity = world.getTileEntity(pos);
    if (stack.getItemDamage() == 0) {
        if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
            return EnumActionResult.PASS;
        String[] permittedMultiblocks = null;
        String[] interdictedMultiblocks = null;
        if (ItemNBTHelper.hasKey(stack, "multiblockPermission")) {
            NBTTagList list = stack.getTagCompound().getTagList("multiblockPermission", 8);
            permittedMultiblocks = new String[list.tagCount()];
            for (int i = 0; i < permittedMultiblocks.length; i++) permittedMultiblocks[i] = list.getStringTagAt(i);
        }
        if (ItemNBTHelper.hasKey(stack, "multiblockInterdiction")) {
            NBTTagList list = stack.getTagCompound().getTagList("multiblockInterdiction", 8);
            interdictedMultiblocks = new String[list.tagCount()];
            for (int i = 0; i < interdictedMultiblocks.length; i++) interdictedMultiblocks[i] = list.getStringTagAt(i);
        }
        for (IMultiblock mb : MultiblockHandler.getMultiblocks()) if (mb.isBlockTrigger(world.getBlockState(pos))) {
            boolean b = permittedMultiblocks == null;
            if (permittedMultiblocks != null)
                for (String s : permittedMultiblocks) if (mb.getUniqueName().equalsIgnoreCase(s)) {
                    b = true;
                    continue;
                }
            if (!b)
                break;
            if (interdictedMultiblocks != null)
                for (String s : interdictedMultiblocks) if (mb.getUniqueName().equalsIgnoreCase(s)) {
                    b = false;
                    continue;
                }
            if (!b)
                break;
            if (MultiblockHandler.postMultiblockFormationEvent(player, mb, pos, stack).isCanceled())
                continue;
            if (mb.createStructure(world, pos, side, player))
                return EnumActionResult.SUCCESS;
        }
        TileEntity tile = world.getTileEntity(pos);
        if (!(tile instanceof IDirectionalTile) && !(tile instanceof IHammerInteraction) && !(tile instanceof IConfigurableSides))
            return RotationUtil.rotateBlock(world, pos, side) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
    } else if (stack.getItemDamage() == 1 && tileEntity instanceof IImmersiveConnectable && !world.isRemote) {
        TargetingInfo target = new TargetingInfo(side, hitX, hitY, hitZ);
        BlockPos masterPos = ((IImmersiveConnectable) tileEntity).getConnectionMaster(null, target);
        tileEntity = world.getTileEntity(masterPos);
        if (!(tileEntity instanceof IImmersiveConnectable))
            return EnumActionResult.PASS;
        IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
        boolean cut = ImmersiveNetHandler.INSTANCE.clearAllConnectionsFor(Utils.toCC(nodeHere), world, target);
        IESaveData.setDirty(world.provider.getDimension());
        if (cut) {
            int nbtDamage = ItemNBTHelper.getInt(stack, "cutterDmg") + 1;
            if (nbtDamage < cutterMaxDamage)
                ItemNBTHelper.setInt(stack, "cutterDmg", nbtDamage);
            else {
                player.renderBrokenItemStack(stack);
                player.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, null);
            }
        }
        return EnumActionResult.SUCCESS;
    } else if (stack.getItemDamage() == 2 && !world.isRemote) {
        if (!player.isSneaking() && (tileEntity instanceof IFluxReceiver || tileEntity instanceof IFluxProvider)) {
            int max = 0;
            int stored = 0;
            if (tileEntity instanceof IFluxReceiver) {
                max = ((IFluxReceiver) tileEntity).getMaxEnergyStored(side);
                stored = ((IFluxReceiver) tileEntity).getEnergyStored(side);
            } else {
                max = ((IFluxProvider) tileEntity).getMaxEnergyStored(side);
                stored = ((IFluxProvider) tileEntity).getEnergyStored(side);
            }
            if (max > 0)
                ChatUtils.sendServerNoSpamMessages(player, new TextComponentTranslation(Lib.CHAT_INFO + "energyStorage", stored, max));
            return EnumActionResult.SUCCESS;
        }
        if (player.isSneaking() && tileEntity instanceof IImmersiveConnectable) {
            if (!ItemNBTHelper.hasKey(stack, "linkingPos"))
                ItemNBTHelper.setIntArray(stack, "linkingPos", new int[] { world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ() });
            else {
                int[] array = ItemNBTHelper.getIntArray(stack, "linkingPos");
                BlockPos linkPos = new BlockPos(array[1], array[2], array[3]);
                TileEntity tileEntityLinkingPos = world.getTileEntity(linkPos);
                if (array[0] == world.provider.getDimension()) {
                    IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
                    IImmersiveConnectable nodeLink = (IImmersiveConnectable) tileEntityLinkingPos;
                    if (nodeLink != null) {
                        Set<AbstractConnection> connections = ImmersiveNetHandler.INSTANCE.getIndirectEnergyConnections(Utils.toCC(nodeLink), world, true);
                        for (AbstractConnection con : connections) if (Utils.toCC(nodeHere).equals(con.end))
                            player.addChatComponentMessage(new TextComponentTranslation(Lib.CHAT_INFO + "averageLoss", Utils.formatDouble(con.getAverageLossRate() * 100, "###.000")));
                    }
                }
                ItemNBTHelper.remove(stack, "linkingPos");
            }
            return EnumActionResult.SUCCESS;
        }
    }
    return EnumActionResult.PASS;
}
Also used : IHammerInteraction(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHammerInteraction) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) IFluxProvider(blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxProvider) IDirectionalTile(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile) TileEntity(net.minecraft.tileentity.TileEntity) NBTTagList(net.minecraft.nbt.NBTTagList) TargetingInfo(blusunrize.immersiveengineering.api.TargetingInfo) IMultiblock(blusunrize.immersiveengineering.api.MultiblockHandler.IMultiblock) IFluxReceiver(blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxReceiver) AbstractConnection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.AbstractConnection) IConfigurableSides(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IConfigurableSides) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project ImmersiveEngineering by BluSunrize.

the class ItemWireCoil method onItemUseFirst.

@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) {
        TileEntity tileEntity = world.getTileEntity(pos);
        if (tileEntity instanceof IImmersiveConnectable && ((IImmersiveConnectable) tileEntity).canConnect()) {
            TargetingInfo target = new TargetingInfo(side, hitX, hitY, hitZ);
            WireType wire = getWireType(stack);
            BlockPos masterPos = ((IImmersiveConnectable) tileEntity).getConnectionMaster(wire, target);
            tileEntity = world.getTileEntity(masterPos);
            if (!(tileEntity instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntity).canConnect())
                return EnumActionResult.PASS;
            if (!((IImmersiveConnectable) tileEntity).canConnectCable(wire, target)) {
                player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongCable"));
                return EnumActionResult.FAIL;
            }
            if (!ItemNBTHelper.hasKey(stack, "linkingPos")) {
                ItemNBTHelper.setIntArray(stack, "linkingPos", new int[] { world.provider.getDimension(), masterPos.getX(), masterPos.getY(), masterPos.getZ() });
                NBTTagCompound targetNbt = new NBTTagCompound();
                target.writeToNBT(targetNbt);
                ItemNBTHelper.setTagCompound(stack, "targettingInfo", targetNbt);
            } else {
                WireType type = getWireType(stack);
                int[] array = ItemNBTHelper.getIntArray(stack, "linkingPos");
                BlockPos linkPos = new BlockPos(array[1], array[2], array[3]);
                TileEntity tileEntityLinkingPos = world.getTileEntity(linkPos);
                int distanceSq = (int) Math.ceil(linkPos.distanceSq(masterPos));
                if (array[0] != world.provider.getDimension())
                    player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongDimension"));
                else if (linkPos.equals(masterPos))
                    player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "sameConnection"));
                else if (distanceSq > (type.getMaxLength() * type.getMaxLength()))
                    player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "tooFar"));
                else {
                    TargetingInfo targetLink = TargetingInfo.readFromNBT(ItemNBTHelper.getTagCompound(stack, "targettingInfo"));
                    if (!(tileEntityLinkingPos instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntityLinkingPos).canConnectCable(wire, targetLink))
                        player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "invalidPoint"));
                    else {
                        IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
                        IImmersiveConnectable nodeLink = (IImmersiveConnectable) tileEntityLinkingPos;
                        boolean connectionExists = false;
                        Set<Connection> outputs = ImmersiveNetHandler.INSTANCE.getConnections(world, Utils.toCC(nodeHere));
                        if (outputs != null)
                            for (Connection con : outputs) {
                                if (con.end.equals(Utils.toCC(nodeLink)))
                                    connectionExists = true;
                            }
                        if (connectionExists)
                            player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "connectionExists"));
                        else {
                            Vec3d rtOff0 = nodeHere.getRaytraceOffset(nodeLink).addVector(masterPos.getX(), masterPos.getY(), masterPos.getZ());
                            Vec3d rtOff1 = nodeLink.getRaytraceOffset(nodeHere).addVector(linkPos.getX(), linkPos.getY(), linkPos.getZ());
                            Set<BlockPos> ignore = new HashSet<>();
                            ignore.addAll(nodeHere.getIgnored(nodeLink));
                            ignore.addAll(nodeLink.getIgnored(nodeHere));
                            boolean canSee = Utils.rayTraceForFirst(rtOff0, rtOff1, world, ignore) == null;
                            if (canSee) {
                                ImmersiveNetHandler.INSTANCE.addConnection(world, Utils.toCC(nodeHere), Utils.toCC(nodeLink), (int) Math.sqrt(distanceSq), type);
                                nodeHere.connectCable(type, target, nodeLink);
                                nodeLink.connectCable(type, targetLink, nodeHere);
                                IESaveData.setDirty(world.provider.getDimension());
                                player.addStat(IEAchievements.connectWire);
                                if (!player.capabilities.isCreativeMode)
                                    stack.stackSize--;
                                ((TileEntity) nodeHere).markDirty();
                                world.addBlockEvent(masterPos, ((TileEntity) nodeHere).getBlockType(), -1, 0);
                                IBlockState state = world.getBlockState(masterPos);
                                world.notifyBlockUpdate(masterPos, state, state, 3);
                                ((TileEntity) nodeLink).markDirty();
                                world.addBlockEvent(linkPos, ((TileEntity) nodeLink).getBlockType(), -1, 0);
                                state = world.getBlockState(linkPos);
                                world.notifyBlockUpdate(linkPos, state, state, 3);
                            } else
                                player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "cantSee"));
                        }
                    }
                }
                ItemNBTHelper.remove(stack, "linkingPos");
                ItemNBTHelper.remove(stack, "targettingInfo");
            }
            return EnumActionResult.SUCCESS;
        }
    }
    return EnumActionResult.PASS;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) WireType(blusunrize.immersiveengineering.api.energy.wires.WireType) Vec3d(net.minecraft.util.math.Vec3d) TileEntity(net.minecraft.tileentity.TileEntity) TargetingInfo(blusunrize.immersiveengineering.api.TargetingInfo) BlockPos(net.minecraft.util.math.BlockPos) HashSet(java.util.HashSet)

Example 5 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project ImmersiveEngineering by BluSunrize.

the class CommandShaders method perform.

@Override
public void perform(CommandHandler h, MinecraftServer server, ICommandSender sender, String[] args) {
    if (args.length > 1) {
        switch(args[1]) {
            case "clear":
                String player = args.length > 2 ? args[2].trim() : sender.getName();
                if (ShaderRegistry.receivedShaders.containsKey(player))
                    ShaderRegistry.receivedShaders.get(player).clear();
                ShaderRegistry.recalculatePlayerTotalWeight(player);
                sender.addChatMessage(new TextComponentTranslation(Lib.CHAT_COMMAND + getIdent() + ".clear.sucess", player));
                break;
            default:
                sender.addChatMessage(new TextComponentTranslation(getHelp("")));
                break;
        }
    } else
        sender.addChatMessage(new TextComponentTranslation(getHelp("")));
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation)

Aggregations

TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)262 ItemStack (net.minecraft.item.ItemStack)63 BlockPos (net.minecraft.util.math.BlockPos)49 EntityPlayer (net.minecraft.entity.player.EntityPlayer)37 TileEntity (net.minecraft.tileentity.TileEntity)32 TextComponentString (net.minecraft.util.text.TextComponentString)28 ITextComponent (net.minecraft.util.text.ITextComponent)25 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)23 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)19 IBlockState (net.minecraft.block.state.IBlockState)17 Style (net.minecraft.util.text.Style)17 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)16 EnumFacing (net.minecraft.util.EnumFacing)14 World (net.minecraft.world.World)14 ArrayList (java.util.ArrayList)12 Entity (net.minecraft.entity.Entity)12 EnumActionResult (net.minecraft.util.EnumActionResult)12 ActionResult (net.minecraft.util.ActionResult)11 Block (net.minecraft.block.Block)10 CommandException (net.minecraft.command.CommandException)10