Search in sources :

Example 46 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project EnderIO by SleepyTrousers.

the class ItemRemoteInvAccess method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    if (!world.isRemote) {
        ItemStack equipped = player.getHeldItem(hand);
        if (!REMOTE_X.hasTag(equipped) || !REMOTE_Y.hasTag(equipped) || !REMOTE_Z.hasTag(equipped) || !REMOTE_D.hasTag(equipped)) {
            player.sendStatusMessage(new TextComponentString(EnderIO.lang.localize("remoteinv.chat.notarget")), true);
            return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, equipped);
        }
        int x = REMOTE_X.getInt(equipped);
        int y = REMOTE_Y.getInt(equipped);
        int z = REMOTE_Z.getInt(equipped);
        int d = REMOTE_D.getInt(equipped);
        ItemRemoteInvAccessType type = ItemRemoteInvAccessType.fromStack(equipped);
        if (!type.inRange(d, x, y, z, world.provider.getDimension(), (int) player.posX, (int) player.posY, (int) player.posZ)) {
            player.sendStatusMessage(new TextComponentString(EnderIO.lang.localize("remoteinv.chat.outofrange")), true);
            return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, equipped);
        }
        World targetWorld = world;
        if (world.provider.getDimension() != d) {
            targetWorld = DimensionManager.getWorld(d);
            if (targetWorld == null) {
                player.sendStatusMessage(new TextComponentString(EnderIO.lang.localize("remoteinv.chat.invalidtargetworld")), true);
                return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, equipped);
            }
        }
        final BlockPos pos = new BlockPos(x, y, z);
        if (!targetWorld.isBlockLoaded(pos)) {
            player.sendStatusMessage(new TextComponentString(EnderIO.lang.localize("remoteinv.chat.notloaded")), true);
            return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, equipped);
        }
        if (targetWorld.getBlockState(pos).getBlock() != InvpanelObject.blockInventoryPanel.getBlock()) {
            player.sendStatusMessage(new TextComponentString(EnderIO.lang.localize("remoteinv.chat.invalidtarget")), true);
            return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, equipped);
        }
        if (!(world instanceof WorldServer) || !(player instanceof EntityPlayerMP)) {
            Log.warn("Unexpected world or player: " + world + " " + player);
            player.sendStatusMessage(new TextComponentString(EnderIO.lang.localize("remoteinv.chat.error")), true);
            return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, equipped);
        }
        if (getEnergyStored(equipped) < type.getRfPerTick() * 10) {
            player.sendStatusMessage(new TextComponentString(EnderIO.lang.localize("remoteinv.chat.outofpower")), true);
            return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, equipped);
        }
        if (!drain(equipped, type.getMbPerOpen())) {
            Fluid fluid = type.getFluidType();
            String fluidname = fluid.getLocalizedName(new FluidStack(fluid, 1));
            player.sendStatusMessage(new TextComponentString(EnderIO.lang.localize("remoteinv.chat.outoffluid").replace("{FLUIDNAME}", fluidname)), true);
            return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, equipped);
        }
        ServerRemoteGuiManager.openGui((EntityPlayerMP) player, targetWorld, pos);
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, equipped);
    }
    return super.onItemRightClick(world, player, hand);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) LangFluid(crazypants.enderio.base.lang.LangFluid) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TextComponentString(net.minecraft.util.text.TextComponentString) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 47 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project EnderIO by SleepyTrousers.

the class PacketRemoteInvPanel method onMessage.

@Override
public IMessage onMessage(PacketRemoteInvPanel message, MessageContext ctx) {
    EntityPlayerMP player = ctx.getServerHandler().player;
    ItemStack heldItem = player.getHeldItem(message.hand);
    if (heldItem == null || !(heldItem.getItem() instanceof ItemRemoteInvAccess)) {
        return null;
    }
    if (!REMOTE_X.hasTag(heldItem)) {
        return null;
    }
    int x = REMOTE_X.getInt(heldItem);
    int y = REMOTE_Y.getInt(heldItem);
    int z = REMOTE_Z.getInt(heldItem);
    int d = REMOTE_D.getInt(heldItem);
    ItemRemoteInvAccessType type = ItemRemoteInvAccessType.fromStack(heldItem);
    if (!type.inRange(d, x, y, z, player.getEntityWorld().provider.getDimension(), (int) player.posX, (int) player.posY, (int) player.posZ)) {
        player.sendStatusMessage(new TextComponentString(EnderIO.lang.localize("remoteinv.chat.outofrange")), true);
        return null;
    }
    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
    if (server == null) {
        return null;
    }
    WorldServer world = server.getWorld(d);
    if (world == null) {
        player.sendStatusMessage(new TextComponentString(EnderIO.lang.localize("remoteinv.chat.invalidtarget")), true);
        return null;
    }
    final BlockPos pos = new BlockPos(x, y, z);
    if (!world.isBlockLoaded(pos)) {
        player.sendStatusMessage(new TextComponentString(EnderIO.lang.localize("remoteinv.chat.notloaded")), true);
        return null;
    }
    TileEntity tileEntity = player.getEntityWorld().getTileEntity(pos);
    if (!(tileEntity instanceof TileInventoryPanel)) {
        player.sendStatusMessage(new TextComponentString(EnderIO.lang.localize("remoteinv.chat.invalidtarget")), true);
        return null;
    }
    Container c = player.openContainer;
    player.interactionManager.processRightClickBlock(player, player.world, null, EnumHand.MAIN_HAND, pos, EnumFacing.UP, 0f, 0f, 0f);
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileInventoryPanel(crazypants.enderio.machine.invpanel.TileInventoryPanel) Container(net.minecraft.inventory.Container) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 48 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project EnderIO by SleepyTrousers.

the class Config method onPlayerLoggon.

@SubscribeEvent
public void onPlayerLoggon(PlayerLoggedInEvent evt) {
    PacketHandler.INSTANCE.sendTo(new PacketConfigSync(), (EntityPlayerMP) evt.player);
    if (EnderIO.VERSION.contains("-") || EnderIO.VERSION.contains("@")) {
        // e.g. 1.2.3-nightly
        evt.player.sendMessage(new TextComponentString(TextFormatting.DARK_RED + "This is an " + TextFormatting.BLACK + "Ender IO " + TextFormatting.DARK_RED + "development build!"));
        evt.player.sendMessage(new TextComponentString(TextFormatting.DARK_RED + "It may trash your world at any time!"));
        evt.player.sendMessage(new TextComponentString(TextFormatting.DARK_RED + "Do not use it for anything but testing!"));
        evt.player.sendMessage(new TextComponentString("You have been warned..."));
    }
}
Also used : TextComponentString(net.minecraft.util.text.TextComponentString) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 49 with TextComponentString

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

the class StandardPlayerRequestResolver method resolve.

@Nullable
@Override
public void resolve(@NotNull final IRequestManager manager, @NotNull final IRequest request) throws RuntimeException {
    final IColony colony = manager.getColony();
    if (colony instanceof Colony) {
        if (Configurations.requestSystem.creativeResolve && request.getRequest() instanceof IDeliverable && request.getRequester() instanceof BuildingBasedRequester && ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getToken()).isPresent() && ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getToken()).get() instanceof AbstractBuilding) {
            final AbstractBuilding building = (AbstractBuilding) ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getToken()).get();
            final Optional<CitizenData> citizenDataOptional = building.getCitizenForRequest(request.getToken());
            final List<ItemStack> resolvablestacks = request.getDisplayStacks();
            if (!resolvablestacks.isEmpty() && citizenDataOptional.isPresent()) {
                final ItemStack resolveStack = resolvablestacks.get(0);
                resolveStack.setCount(Math.min(((IDeliverable) request.getRequest()).getCount(), resolveStack.getMaxStackSize()));
                final ItemStack remainingItemStack = InventoryUtils.addItemStackToItemHandlerWithResult(new InvWrapper(citizenDataOptional.get().getInventory()), resolveStack);
                if (ItemStackUtils.isEmpty(remainingItemStack)) {
                    manager.updateRequestState(request.getToken(), RequestState.COMPLETED);
                    return;
                }
            }
        }
        final List<EntityPlayer> players = new ArrayList<>(((Colony) colony).getMessageEntityPlayers());
        final EntityPlayer owner = ServerUtils.getPlayerFromUUID(colony.getWorld(), ((Colony) colony).getPermissions().getOwner());
        final TextComponentString colonyDescription = new TextComponentString(colony.getName() + ":");
        if (manager.getColony().getWorld().isDaytime()) {
            if (owner != null) {
                players.remove(owner);
                LanguageHandler.sendPlayerMessage(owner, "com.minecolonies.requestsystem.playerresolver", request.getRequester().getDisplayName(manager, request.getToken()).getFormattedText(), getRequestMessage(request).getFormattedText(), request.getRequester().getRequesterLocation().toString());
            }
            LanguageHandler.sendPlayersMessage(players, "com.minecolonies.requestsystem.playerresolver", colonyDescription.getFormattedText() + " " + request.getRequester().getDisplayName(manager, request.getToken()).getFormattedText(), getRequestMessage(request).getFormattedText(), request.getRequester().getRequesterLocation().toString());
        }
    }
    assignedRequests.add(request.getToken());
}
Also used : BuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester) IColony(com.minecolonies.api.colony.IColony) CitizenData(com.minecolonies.coremod.colony.CitizenData) TextComponentString(net.minecraft.util.text.TextComponentString) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) Nullable(org.jetbrains.annotations.Nullable)

Example 50 with TextComponentString

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

the class ClaimChunksCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final ActionMenu actionMenu) throws CommandException {
    // See if the player is opped.
    if (sender instanceof EntityPlayerMP && isPlayerOpped(sender)) {
        final Colony colony = actionMenu.getColonyForArgument("colony");
        if (colony == null) {
            sender.sendMessage(new TextComponentString(NO_COLONY_MESSAGE));
            return;
        }
        final int range = actionMenu.getIntegerForArgument("range");
        final Boolean add = actionMenu.getBooleanForArgument("add");
        final Chunk chunk = ((EntityPlayerMP) sender).getServerWorld().getChunkFromBlockCoords(sender.getPosition());
        ColonyManager.claimChunksInRange(colony.getID(), colony.getDimension(), add == null ? true : add, chunk.x, chunk.z, range, 0);
        return;
    } else {
        sender.sendMessage(new TextComponentString(NO_PERMISSION_TO_CLAIM_MESSAGE));
    }
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) TeleportToColony(com.minecolonies.coremod.util.TeleportToColony) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Chunk(net.minecraft.world.chunk.Chunk) 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