Stenbergcsgo Posted April 18, 2018 Posted April 18, 2018 (edited) I'm trying to create a mod where the player can load, paste, and undo schematics using custom items, compared to manually typing the text. I got the first part working, but for some reason MCEdit ignores messages posted directly using the ITextComponent, opposed to actually typing the text and hitting enter. An example of my Paste.class: package com.mta.utzonmod.items; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import com.mta.utzonmod.client.gui.signInputGui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumHand; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; import net.minecraft.world.World; public class Paste extends ItemBase{ public Paste(String name) { super(name); } static boolean canPlace = false; @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand handIn) { if(!worldIn.isRemote) { if(canPlace == true) { ITextComponent message = new TextComponentString("//paste"); player.sendMessage(message); canPlace = false; Undo.setCanUndo(true); } } return super.onItemRightClick(worldIn, player, handIn); } public static void setCanPlace(boolean cPlace) { canPlace = cPlace; } } Is there another component I can use for sending text, or is it a whole other size of problem? Edited April 18, 2018 by Stenbergcsgo Quote
Stenbergcsgo Posted April 18, 2018 Author Posted April 18, 2018 6 minutes ago, diesieben07 said: Calling sendMessage on the server sends a message to the player via chat. If you want to execute a command on behalf of a player, call ICommandManager::executeCommand. I assume this can't be done client-side? All the examples I see use: MinecraftServer minecraftserver = MinecraftServer.getServer(); Where I get told MinecraftServer's getServer() isn't static so I can't even call it if I wanted to. How would I implement this in the code from my original post? Quote
Stenbergcsgo Posted April 19, 2018 Author Posted April 19, 2018 18 hours ago, diesieben07 said: To obtain the server instance you can use ICommandSender::getServer (every entity is a command sender). On the client you can use EntityPlayerSP::sendChatMessage to send a command to the server. Worked like a charm, thank you very much =) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.