Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author
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?

  • Author
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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.