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

As said in the title, I'm getting a NullPointerException when I edit the guiButton.displayText. I'm doing this while the gui is open and I'm not sure of any other way of doing it. Any help?

 

 protected void actionPerformed(GuiButton guiButton) {
	super.actionPerformed(guiButton);
	switch(guiButton.id) {
	case 1:
		System.out.println("Button clicked");
		if(this.isLinkEnabled == 0){
			System.out.println("Disabled");
			this.isLinkEnabled = 1;
			drawButton(false, isLinkEnabled);
		} else{
			System.out.println("Enabled");
			this.isLinkEnabled = 0;
			drawButton(false, isLinkEnabled);
		}
		break;
	}
	//Packet code here
	//PacketDispatcher.sendPacketToServer(packet); //send packet
}

private void drawButton(boolean firstRun, int enabled){
	if(firstRun){
		this.buttonList.clear();
		//id, x, y, width, height, text
		this.buttonList.add(new GuiButton(neiLinkID, this.textBoxFilter.xPosition, (this.textBoxFilter.yPosition + 10) + 2, neiLinkWidth, neiLinkHeight, "A"));
		this.isLinkEnabled = 0;
	}else{
		try{
			switch(enabled){
			case 0:
				this.neiLink.displayString = "A";
				break;
			case 1:
				this.neiLink.displayString = "B";
				break;
			}
		} catch(NullPointerException e){
			e.printStackTrace();
		}
	}
} 

  • Author

I'm adding a button to allow the search bar in ProjectE to interface with the NEI search bar. Here's the code:

 

package moze_intel.projecte.gameObjs.gui;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import moze_intel.projecte.PECore;
import moze_intel.projecte.gameObjs.container.TransmuteContainer;
import moze_intel.projecte.gameObjs.tiles.TransmuteTile;
import moze_intel.projecte.network.PacketHandler;
import moze_intel.projecte.network.packets.ClientSyncTabletLinkPKT;
import moze_intel.projecte.network.packets.SearchUpdatePKT;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;

import org.lwjgl.opengl.GL11;

public class GUITransmute extends GuiContainer
{
private static final ResourceLocation texture = new ResourceLocation(PECore.MODID.toLowerCase(), "textures/gui/transmute.png");
private TransmuteTile tile;
private GuiTextField textBoxFilter;
private GuiButton neiLink;

int xLocation;
int yLocation;

int neiLinkID = 1;
int neiLinkWidth = 15;
int neiLinkHeight = 10;

private static int isLinkEnabled = 0;

public GUITransmute(InventoryPlayer invPlayer, TransmuteTile tile) 
{
	super(new TransmuteContainer(invPlayer, tile));
	this.tile = tile;
	this.xSize = 228;
	this.ySize = 196;
}

@Override
public void initGui() 
{
	tile.setPlayer(Minecraft.getMinecraft().thePlayer);
	super.initGui();

	this.xLocation = (this.width - this.xSize) / 2;
	this.yLocation = (this.height - this.ySize) / 2;

	this.textBoxFilter = new GuiTextField(this.fontRendererObj, this.xLocation + 88, this.yLocation + 8, 45, 10);
	this.textBoxFilter.setText(tile.filter);
	drawButton(true, isLinkEnabled);
}

protected void actionPerformed(GuiButton guiButton) {
	super.actionPerformed(guiButton);
	switch(guiButton.id) {
	case 1:
		System.out.println("Button clicked");
		if(this.isLinkEnabled == 0){
			System.out.println("Disabled");
			PacketHandler.sendToServer(new ClientSyncTabletLinkPKT(1));
			drawButton(false, isLinkEnabled);
		} else{
			System.out.println("Enabled");
			PacketHandler.sendToServer(new ClientSyncTabletLinkPKT(0));
			drawButton(false, isLinkEnabled);
		}
		break;
	}
}

public static int getLinkEnabled(){
	return isLinkEnabled;
}

public static void setLinkEnabled(int i){
	isLinkEnabled = i;
}

private void drawButton(boolean firstRun, int enabled){
	if(firstRun){
		this.buttonList.clear();
		//id, x, y, width, height, text
		this.buttonList.add(new GuiButton(neiLinkID, this.textBoxFilter.xPosition, (this.textBoxFilter.yPosition + 10) + 2, neiLinkWidth, neiLinkHeight, "A"));
		this.isLinkEnabled = 0;
	}else{
		try{
			switch(enabled){
			case 0:
				this.neiLink.displayString = "A";
				break;
			case 1:
				this.neiLink.displayString = "B";
				break;
			}
		} catch(NullPointerException e){
			e.printStackTrace();
		}
	}
}

@Override
public void drawScreen(int par1, int par2, float par3)
{
	super.drawScreen(par1, par2, par3);
	this.textBoxFilter.drawTextBox();
}

@Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) 
{
	GL11.glColor4f(1F, 1F, 1F, 1F);
	Minecraft.getMinecraft().renderEngine.bindTexture(texture);
	this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
}

@Override
protected void drawGuiContainerForegroundLayer(int var1, int var2) 
{
	this.fontRendererObj.drawString("Transmutation", 6, 8, 4210752);
	String emc = String.format("EMC: %,d", (int) tile.getStoredEmc());
	this.fontRendererObj.drawString(emc, 6, this.ySize - 94, 4210752);

	if (tile.learnFlag > 0)
	{
		this.fontRendererObj.drawString("L", 98, 30, 4210752);
		this.fontRendererObj.drawString("e", 99, 38, 4210752);
		this.fontRendererObj.drawString("a", 100, 46, 4210752);
		this.fontRendererObj.drawString("r", 101, 54, 4210752);
		this.fontRendererObj.drawString("n", 102, 62, 4210752);
		this.fontRendererObj.drawString("e", 103, 70, 4210752);
		this.fontRendererObj.drawString("d", 104, 78, 4210752);
		this.fontRendererObj.drawString("!", 107, 86, 4210752);

		tile.learnFlag--;
	}
}

@Override
public void updateScreen() 
{
	super.updateScreen();
	this.textBoxFilter.updateCursorCounter();
}

@Override
protected void keyTyped(char par1, int par2)
{
	if (this.textBoxFilter.isFocused()) 
	{
		this.textBoxFilter.textboxKeyTyped(par1, par2);

		String srch = this.textBoxFilter.getText().toLowerCase();

		if (!tile.filter.equals(srch)) 
		{
			PacketHandler.sendToServer(new SearchUpdatePKT(srch));
			tile.filter = srch;
			tile.updateOutputs();
		}
	}

	if (par2 == 1 || par2 == this.mc.gameSettings.keyBindInventory.getKeyCode() && !this.textBoxFilter.isFocused())
	{
		this.mc.thePlayer.closeScreen();
	}
}

@Override
protected void mouseClicked(int x, int y, int mouseButton)
{
	super.mouseClicked(x, y, mouseButton);

	int minX = textBoxFilter.xPosition;
	int minY = textBoxFilter.yPosition;
	int maxX = minX + textBoxFilter.width;
	int maxY = minY + textBoxFilter.height;

	if (mouseButton == 1 && x >= minX && x <= maxX && y <= maxY)
	{
		PacketHandler.sendToServer(new SearchUpdatePKT(""));
		tile.filter = "";
		tile.updateOutputs();
		this.textBoxFilter.setText("");
	}

	this.textBoxFilter.mouseClicked(x, y, mouseButton);

}

@Override
public void onGuiClosed()
{
	super.onGuiClosed();
	tile.learnFlag = 0;
}
}

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.