Search in sources :

Example 81 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project SpongeForge by SpongePowered.

the class SpongeForgeEventFactory method createServerChatEvent.

// Server events
private static ServerChatEvent createServerChatEvent(Event event) {
    MessageChannelEvent.Chat spongeEvent = (MessageChannelEvent.Chat) event;
    Optional<Player> player = spongeEvent.getCause().first(Player.class);
    if (!player.isPresent()) {
        return null;
    }
    Text spongeText = spongeEvent.getOriginalMessage();
    ITextComponent component = SpongeTexts.toComponent(spongeText);
    if (!(component instanceof TextComponentTranslation)) {
        component = new TextComponentTranslation("%s", component);
    }
    // Using toPlain here is fine, since the raw message from the client
    // can't have formatting.
    ServerChatEvent forgeEvent = new ServerChatEvent((EntityPlayerMP) player.get(), spongeEvent.getOriginalMessage().toPlain(), (TextComponentTranslation) component);
    ((IMixinInitCause) forgeEvent).initCause(spongeEvent.getCause());
    return forgeEvent;
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) MessageChannelEvent(org.spongepowered.api.event.message.MessageChannelEvent) ITextComponent(net.minecraft.util.text.ITextComponent) IMixinInitCause(org.spongepowered.common.interfaces.IMixinInitCause) Text(org.spongepowered.api.text.Text) ServerChatEvent(net.minecraftforge.event.ServerChatEvent)

Example 82 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project YABBA by LatvianModder.

the class TileBarrelBase method createConfig.

public void createConfig(YabbaConfigEvent event) {
    DataStorage data = getUpgradeData(YabbaItems.UPGRADE_REDSTONE_OUT);
    if (data instanceof ItemUpgradeRedstone.Data) {
        String group = Yabba.MOD_ID + ".redstone";
        event.getConfig().setGroupName(group, new TextComponentTranslation(YabbaItems.UPGRADE_REDSTONE_OUT.getUnlocalizedName() + ".name"));
        ItemUpgradeRedstone.Data data1 = (ItemUpgradeRedstone.Data) data;
        event.getConfig().add(group, "mode", data1.mode);
        event.getConfig().add(group, "count", data1.count);
    }
    data = getUpgradeData(YabbaItems.UPGRADE_HOPPER);
    if (data instanceof ItemUpgradeHopper.Data) {
        String group = Yabba.MOD_ID + ".hopper";
        event.getConfig().setGroupName(group, new TextComponentTranslation(YabbaItems.UPGRADE_HOPPER.getUnlocalizedName() + ".name"));
        ItemUpgradeHopper.Data data1 = (ItemUpgradeHopper.Data) data;
        event.getConfig().add(group, "up", data1.up);
        event.getConfig().add(group, "down", data1.down);
        event.getConfig().add(group, "collect", data1.collect);
    }
}
Also used : DataStorage(com.feed_the_beast.ftblib.lib.util.misc.DataStorage) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ItemUpgradeHopper(com.latmod.yabba.item.upgrade.ItemUpgradeHopper) ItemUpgradeRedstone(com.latmod.yabba.item.upgrade.ItemUpgradeRedstone)

Example 83 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project MineCamera by PorPit.

the class EventLoader method ActiveTripod.

private void ActiveTripod(String playername, int delay) {
    if (!TripodActiveThread.isshooting) {
        TripodActiveThread thread = new TripodActiveThread(playername, delay);
        thread.start();
    } else {
        Minecraft.getMinecraft().thePlayer.addChatComponentMessage(new TextComponentTranslation("chat.minecamera.isshooting"));
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) TripodActiveThread(com.porpit.minecamera.util.TripodActiveThread)

Example 84 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project MineCamera by PorPit.

the class ItemCamera method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
    // System.out.println("1:"+playerIn.getActiveHand());
    playerIn.setActiveHand(hand);
    // System.out.println("2:"+playerIn.getActiveHand());
    if (playerIn.isSneaking()) {
        if (!worldIn.isRemote) {
            BlockPos pos = playerIn.getPosition();
            int id = GuiElementLoader.GUI_CAMERA;
            playerIn.openGui(MineCamera.instance, id, worldIn, pos.getX(), pos.getY(), pos.getZ());
        }
    } else {
        // ��Ʒ����
        if (!itemStackIn.hasTagCompound()) {
            itemStackIn.setTagCompound(new NBTTagCompound());
        }
        if (itemStackIn.getTagCompound().hasKey("filmOutCatch")) {
            if (!worldIn.isRemote)
                playerIn.addChatComponentMessage(new TextComponentTranslation("chat.minecamera.isouting"));
            return new ActionResult(EnumActionResult.PASS, itemStackIn);
        }
        if (!itemStackIn.getTagCompound().hasKey("filmSlot")) {
            if (!worldIn.isRemote)
                playerIn.addChatComponentMessage(new TextComponentTranslation("chat.minecamera.nofilm"));
            return new ActionResult(EnumActionResult.PASS, itemStackIn);
        }
        if (!itemStackIn.getTagCompound().hasKey("betterySlot")) {
            if (!worldIn.isRemote)
                playerIn.addChatComponentMessage(new TextComponentTranslation("chat.minecamera.nobettery"));
            return new ActionResult(EnumActionResult.PASS, itemStackIn);
        }
        if (itemStackIn.getTagCompound().hasKey("filmOutSlot")) {
            if (!worldIn.isRemote)
                playerIn.addChatComponentMessage(new TextComponentTranslation("chat.minecamera.hasfilmout"));
            return new ActionResult(EnumActionResult.PASS, itemStackIn);
        }
        ItemStack betteryStack = ItemStack.loadItemStackFromNBT(itemStackIn.getTagCompound().getCompoundTag("betterySlot"));
        if (betteryStack.getItemDamage() == betteryStack.getMaxDamage()) {
            itemStackIn.getTagCompound().removeTag("betterySlot");
            if (!worldIn.isRemote)
                playerIn.addChatComponentMessage(new TextComponentTranslation("chat.minecamera.betteryrunout"));
        } else {
            betteryStack.damageItem(1, playerIn);
            NBTTagCompound itemTag = new NBTTagCompound();
            betteryStack.writeToNBT(itemTag);
            itemStackIn.getTagCompound().setTag("betterySlot", itemTag);
        }
        ItemStack filmStack = ItemStack.loadItemStackFromNBT(itemStackIn.getTagCompound().getCompoundTag("filmSlot"));
        String createdpid = playerIn.getName() + "%_%" + System.currentTimeMillis();
        if (filmStack.hasTagCompound() && filmStack.getTagCompound().hasKey("pid")) {
            if (!worldIn.isRemote)
                playerIn.addChatComponentMessage((new TextComponentTranslation("chat.minecamera.filmcantwrite")));
            return new ActionResult(EnumActionResult.PASS, itemStackIn);
        } else {
            itemStackIn.getTagCompound().removeTag("filmSlot");
            NBTTagCompound nbt = new NBTTagCompound();
            nbt.setString("pid", createdpid);
            filmStack.setTagCompound(nbt);
            NBTTagCompound itemTag = new NBTTagCompound();
            filmStack.writeToNBT(itemTag);
            itemStackIn.getTagCompound().setTag("filmOutCatch", itemTag);
            if (!worldIn.isRemote) {
                MessageImageSyncSave message = new MessageImageSyncSave();
                message.imageName = createdpid;
                NetworkLoader.instance.sendTo(message, (EntityPlayerMP) playerIn);
            }
        }
        itemStackIn.getTagCompound().setInteger("burnTime", 0);
        // ��Ⱦ
        if (!worldIn.isRemote) {
            double particlePosX = playerIn.posX, particlePosY = playerIn.posY + 1.35, particlePosZ = playerIn.posZ;
            particlePosX = particlePosX + (-Math.sin(Math.toRadians(playerIn.rotationYaw + 15)) * 0.7) * Math.cos(Math.toRadians(playerIn.rotationPitch));
            particlePosY = particlePosY + (-Math.sin(Math.toRadians(playerIn.rotationPitch)) * 0.7);
            particlePosZ = particlePosZ + (Math.cos(Math.toRadians(playerIn.rotationYaw + 15)) * 0.7) * Math.cos(Math.toRadians(playerIn.rotationPitch));
            List<EntityPlayer> listentity = worldIn.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(playerIn.posX - 16, playerIn.posY - 16, playerIn.posZ - 16, playerIn.posX + 16, playerIn.posY + 16, playerIn.posZ + 16));
            if (listentity != null) {
                for (EntityPlayer i : listentity) {
                    EntityPlayerMP entityplayermp = (EntityPlayerMP) i;
                    entityplayermp.connection.sendPacket(new SPacketCustomSound("minecamera:minecamera.kacha", SoundCategory.PLAYERS, playerIn.posX, playerIn.posY, playerIn.posZ, 1.0F, 1.0F));
                    MessageSpawnParticle message = new MessageSpawnParticle();
                    message.delay = 200;
                    message.typeid = EnumParticleTypes.FIREWORKS_SPARK.getParticleID();
                    message.PosX = particlePosX;
                    message.PosY = particlePosY;
                    message.PosZ = particlePosZ;
                    message.SpeedX = 0;
                    message.SpeedY = 0;
                    message.SpeedZ = 0;
                    NetworkLoader.instance.sendTo(message, entityplayermp);
                /*
						 * entityplayermp.connection.sendPacket(new
						 * SPacketParticles(EnumParticleTypes.FIREWORKS_SPARK,
						 * EnumParticleTypes.FIREWORKS_SPARK.
						 * getShouldIgnoreRange(), (float) particlePosX, (float)
						 * particlePosY, (float) particlePosZ, 0F, 0F, 0F,
						 * 0.03F, 1));
						 */
                }
            }
        }
        if (!worldIn.isRemote)
            playerIn.addChatComponentMessage((new TextComponentTranslation("chat.minecamera.success")));
    }
    return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) MessageImageSyncSave(com.porpit.minecamera.network.MessageImageSyncSave) MessageSpawnParticle(com.porpit.minecamera.network.MessageSpawnParticle) SPacketCustomSound(net.minecraft.network.play.server.SPacketCustomSound) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack)

Example 85 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project MineCamera by PorPit.

the class ItemTripod method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        if (!facing.equals(EnumFacing.UP)) {
            playerIn.addChatComponentMessage(new TextComponentTranslation("chat.tripod.mustup"));
            return EnumActionResult.PASS;
        }
        Entity entity = new EntityTripod(worldIn);
        entity.setPositionAndUpdate(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
        entity.rotationYaw = playerIn.rotationYaw;
        entity.rotationPitch = playerIn.rotationPitch;
        worldIn.spawnEntityInWorld(entity);
        // worldIn.updateEntities();
        stack.stackSize--;
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.PASS;
}
Also used : Entity(net.minecraft.entity.Entity) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) EntityTripod(com.porpit.minecamera.entity.EntityTripod)

Aggregations

TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)502 ItemStack (net.minecraft.item.ItemStack)134 ITextComponent (net.minecraft.util.text.ITextComponent)82 EntityPlayer (net.minecraft.entity.player.EntityPlayer)72 BlockPos (net.minecraft.util.math.BlockPos)70 TextComponentString (net.minecraft.util.text.TextComponentString)66 Style (net.minecraft.util.text.Style)60 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)58 TileEntity (net.minecraft.tileentity.TileEntity)45 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)36 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)33 ArrayList (java.util.ArrayList)32 World (net.minecraft.world.World)30 IBlockState (net.minecraft.block.state.IBlockState)28 EnumFacing (net.minecraft.util.EnumFacing)26 CommandException (net.minecraft.command.CommandException)25 Block (net.minecraft.block.Block)20 Nonnull (javax.annotation.Nonnull)19 WrongUsageException (net.minecraft.command.WrongUsageException)19 EnumActionResult (net.minecraft.util.EnumActionResult)19