Jump to content

[1.12.2] WorldEdit ignores command when inserted with ITextComponent


Recommended Posts

Posted (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 by Stenbergcsgo
Posted
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?

Posted
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 =)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.