Search in sources :

Example 71 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project Minestuck by mraof.

the class HashmapModus method putItemStack.

@Override
public boolean putItemStack(ItemStack item) {
    if (list.size() == 0 || item.isEmpty())
        return false;
    int index = item.getUnlocalizedName().hashCode() % list.size();
    if (index < 0)
        index += list.size();
    if (!list.get(index).isEmpty()) {
        ItemStack otherItem = list.get(index);
        if (otherItem.getItem() == item.getItem() && otherItem.getItemDamage() == item.getItemDamage() && ItemStack.areItemStackTagsEqual(otherItem, item) && otherItem.getCount() + item.getCount() <= otherItem.getMaxStackSize()) {
            otherItem.grow(item.getCount());
            return true;
        } else
            CaptchaDeckHandler.launchItem(player, list.get(index));
    }
    list.set(index, item);
    if (ejectByChat && MinestuckConfig.hashmapChatModusSetting != 2 || MinestuckConfig.hashmapChatModusSetting == 1)
        this.player.sendMessage(new TextComponentTranslation("message.hashmap", item.getTextComponent(), getSize(), index));
    return true;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ItemStack(net.minecraft.item.ItemStack)

Example 72 with TextComponentTranslation

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

the class LanguageHandler method buildChatComponent.

private static ITextComponent buildChatComponent(final String key, final Object... message) {
    TextComponentTranslation translation = null;
    int onlyArgsUntil = 0;
    for (final Object object : message) {
        if (object instanceof ITextComponent) {
            if (onlyArgsUntil == 0) {
                onlyArgsUntil = -1;
            }
            break;
        }
        onlyArgsUntil++;
    }
    if (onlyArgsUntil >= 0) {
        final Object[] args = new Object[onlyArgsUntil];
        System.arraycopy(message, 0, args, 0, onlyArgsUntil);
        translation = new TextComponentTranslation(key, args);
    }
    for (final Object object : message) {
        if (translation == null) {
            if (object instanceof ITextComponent) {
                translation = new TextComponentTranslation(key);
            } else {
                translation = new TextComponentTranslation(key, object);
                continue;
            }
        }
        if (object instanceof ITextComponent) {
            translation.appendSibling((ITextComponent) object);
        } else if (object instanceof String) {
            boolean isInArgs = false;
            for (final Object obj : translation.getFormatArgs()) {
                if (obj.equals(object)) {
                    isInArgs = true;
                    break;
                }
            }
            if (!isInArgs) {
                translation.appendText((String) object);
            }
        }
    }
    if (translation == null) {
        translation = new TextComponentTranslation(key);
    }
    return translation;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ITextComponent(net.minecraft.util.text.ITextComponent)

Example 73 with TextComponentTranslation

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

the class BuildingBarracksTower method requestUpgrade.

@Override
public void requestUpgrade(final EntityPlayer player) {
    final int buildingLevel = getBuildingLevel();
    final AbstractBuilding building = getColony().getBuildingManager().getBuilding(barracks);
    if (building != null && buildingLevel < getMaxBuildingLevel() && buildingLevel < building.getBuildingLevel()) {
        requestWorkOrder(buildingLevel + 1);
    } else {
        player.sendMessage(new TextComponentTranslation("com.minecolonies.coremod.worker.needBarracks"));
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation)

Example 74 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project Waystones by blay09.

the class BlockWaystone method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (player.isSneaking() && (player.capabilities.isCreativeMode || !WaystoneConfig.general.creativeModeOnly)) {
        if (!world.isRemote) {
            TileWaystone tileWaystone = getTileWaystone(world, pos);
            if (tileWaystone == null) {
                return true;
            }
            if (WaystoneConfig.general.restrictRenameToOwner && !tileWaystone.isOwner(player)) {
                player.sendStatusMessage(new TextComponentTranslation("waystones:notTheOwner"), true);
                return true;
            }
            if (tileWaystone.isGlobal() && !player.capabilities.isCreativeMode && !WaystoneConfig.general.allowEveryoneGlobal) {
                player.sendStatusMessage(new TextComponentTranslation("waystones:creativeRequired"), true);
                return true;
            }
            player.openGui(Waystones.instance, 1, world, pos.getX(), pos.getY(), pos.getZ());
        }
        return true;
    }
    TileWaystone tileWaystone = getTileWaystone(world, pos);
    if (tileWaystone == null) {
        return true;
    }
    WaystoneEntry knownWaystone = world.isRemote ? ClientWaystones.getKnownWaystone(tileWaystone.getWaystoneName()) : null;
    if (knownWaystone != null) {
        Waystones.proxy.openWaystoneSelection(WarpMode.WAYSTONE, EnumHand.MAIN_HAND, knownWaystone);
    } else if (!world.isRemote) {
        WaystoneEntry waystone = new WaystoneEntry(tileWaystone);
        if (!WaystoneManager.checkAndUpdateWaystone(player, waystone)) {
            TextComponentString nameComponent = new TextComponentString(tileWaystone.getWaystoneName());
            nameComponent.getStyle().setColor(TextFormatting.WHITE);
            TextComponentTranslation chatComponent = new TextComponentTranslation("waystones:activatedWaystone", nameComponent);
            chatComponent.getStyle().setColor(TextFormatting.YELLOW);
            player.sendMessage(chatComponent);
            player.addStat(WAYSTONE_ACTIVATED);
            WaystoneManager.addPlayerWaystone(player, waystone);
            WaystoneManager.sendPlayerWaystones(player);
        }
        if (WaystoneConfig.general.setSpawnPoint) {
            EnumFacing blockFacing = state.getValue(FACING);
            player.setSpawnPoint(new BlockPos(tileWaystone.getPos().offset(blockFacing)), true);
        }
    } else {
        Waystones.proxy.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, pos, 1f);
        for (int i = 0; i < 32; i++) {
            world.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, pos.getX() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, pos.getY() + 3, pos.getZ() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, 0, -5, 0);
            world.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, pos.getX() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, pos.getY() + 4, pos.getZ() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, 0, -5, 0);
        }
    }
    return true;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 75 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project Waystones by blay09.

the class HandlerEditWaystone method onMessage.

@Override
@Nullable
public IMessage onMessage(final MessageEditWaystone message, final MessageContext ctx) {
    NetworkHandler.getThreadListener(ctx).addScheduledTask(() -> {
        EntityPlayer entityPlayer = ctx.getServerHandler().player;
        if (WaystoneConfig.general.creativeModeOnly && !entityPlayer.capabilities.isCreativeMode) {
            return;
        }
        World world = entityPlayer.getEntityWorld();
        BlockPos pos = message.getPos();
        if (entityPlayer.getDistance(pos.getX(), pos.getY(), pos.getZ()) > 10) {
            return;
        }
        GlobalWaystones globalWaystones = GlobalWaystones.get(ctx.getServerHandler().player.world);
        TileEntity tileEntity = world.getTileEntity(pos);
        if (tileEntity instanceof TileWaystone) {
            TileWaystone tileWaystone = ((TileWaystone) tileEntity).getParent();
            if (globalWaystones.getGlobalWaystone(tileWaystone.getWaystoneName()) != null && !ctx.getServerHandler().player.capabilities.isCreativeMode && !WaystoneConfig.general.allowEveryoneGlobal) {
                return;
            }
            if (WaystoneConfig.general.restrictRenameToOwner && !tileWaystone.isOwner(ctx.getServerHandler().player)) {
                ctx.getServerHandler().player.sendMessage(new TextComponentTranslation("waystones:notTheOwner"));
                return;
            }
            if (globalWaystones.getGlobalWaystone(message.getName()) != null && !ctx.getServerHandler().player.capabilities.isCreativeMode) {
                ctx.getServerHandler().player.sendMessage(new TextComponentTranslation("waystones:nameOccupied", message.getName()));
                return;
            }
            WaystoneEntry oldWaystone = new WaystoneEntry(tileWaystone);
            globalWaystones.removeGlobalWaystone(oldWaystone);
            tileWaystone.setWaystoneName(message.getName());
            WaystoneEntry newWaystone = new WaystoneEntry(tileWaystone);
            if (message.isGlobal() && (ctx.getServerHandler().player.capabilities.isCreativeMode || WaystoneConfig.general.allowEveryoneGlobal)) {
                tileWaystone.setGlobal(true);
                newWaystone.setGlobal(true);
                globalWaystones.addGlobalWaystone(newWaystone);
                for (Object obj : FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayers()) {
                    WaystoneManager.sendPlayerWaystones((EntityPlayer) obj);
                }
            }
        }
    });
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) GlobalWaystones(net.blay09.mods.waystones.GlobalWaystones) WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) TileWaystone(net.blay09.mods.waystones.block.TileWaystone) Nullable(javax.annotation.Nullable)

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