Jump to content

GUI Buttons and Packets || Adding a config to read other mods


Flenix

Recommended Posts

Can anyone point me in the right direction for buttons and packets?

 

It's mainly buttons I'm struggling with, I can't get them in-game and I can't find any up-to-date examples. I understand once I have the button, I need a packet to use it too?

 

What I'm trying to do is when a player presses a button in a GUI, it checks their NBT and if a condition is met, gives them an item.

 


 

Because I don't want to flood the forums too much, I'll post another question I have too.

 

My mod adds money, and ways of earning it. One thing I want is a forge answer to the Essentials /sell hand command from Bukkit. Basically, it checks what you're holding, reads it's "value" from a config file, then takes the item and gives you the money.

For this to be effective in Forge, I need a config file which lets people add support for other mods blocks/items themselves - without me having to add support for potentially hundreds of mods. What would be the best approach to reading from configs like this?

 

I was thinking somehow reading the modID and unlocalized name. Can I do that without specifying a particular mod to look at? Ideally I don't want to use item IDs, because if I do it with modID and name, people can share the config without worrying about different ID's between peoples clients.

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Link to comment
Share on other sites

well for the gui part its pretty straightfoward but here an example of my party gui (theres also a packet send in there)

 

 


import java.util.List;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;

import org.lwjgl.input.Keyboard;

import com.hydroflame.GuiApi.GuiNewList;
import com.hydroflame.mod.TheMod;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* The gui for party managing
* @author hydroflame
*
*/
@SideOnly(Side.CLIENT)
public class PartyGUI extends GuiScreen {

public static int GUI_ID = 0;
private boolean absorb = false;

private GuiNewList<String> newList;
private GuiButton[] guiButton;
private GuiButton acceptButton;
private GuiButton declineButton;
private GuiButton leavePartyButton;
private GuiButton inviteButton;
private GuiTextField userTextField;


public PartyGUI() {
}

// button is (id, x, y, width, height, text)
public void initGui() {
	newList = new GuiNewList<String>(125, this.width/2-200, this.height/2-50, 200, 100);

	List<String> alist = TheMod.proxy.getList();
	for (int i = 0; i < alist.size(); i++) {
		newList.add(alist.get(i));
	}

	acceptButton = new GuiButton(0, this.width / 2 + 30,
			this.height / 2 - 50, 60, 20, "accept");
	userTextField = new GuiTextField(fontRenderer, this.width / 2 - 130,
			this.height / 2 - 100, 103, 20);
	userTextField.setTextColor(-1);
	userTextField.setEnableBackgroundDrawing(true);
	userTextField.setMaxStringLength(30);
	userTextField.setFocused(true);
	inviteButton = new GuiButton(1, this.width / 2 - 20,
			this.height / 2 - 100, 50, 20, "invite");
	declineButton = new GuiButton(2, this.width / 2 + 30,
			this.height / 2 - 30, 60, 20, "decline");
	leavePartyButton = new GuiButton(3, this.width/2+30, this.height/2 -10, 60, 20, "leave party");

	buttonList.add(leavePartyButton);
	buttonList.add(declineButton);
	buttonList.add(acceptButton);
	buttonList.add(inviteButton);
	buttonList.add(newList);
	setAvailability();
}

protected void mouseClicked(int par1, int par2, int par3) {
	super.mouseClicked(par1, par2, par3);
}

protected void keyTyped(char par1, int par2) {
	if (absorb) {
		if (this.userTextField.textboxKeyTyped(par1, par2)) {

		} else if (userTextField.isFocused() && par2 == Keyboard.KEY_RETURN) {
			sendInvite();
		} else {
			super.keyTyped(par1, par2);
		}
		setAvailability();
	}else{
		absorb = true;
	}
}

protected void actionPerformed(GuiButton button) {
	if (button.id == acceptButton.id) {
		TheMod.proxy.acceptInvite(newList.getSelectedItem());
		TheMod.proxy.decline(newList.getSelected());
		newList.remove(newList.getSelected());
	} else if (button.id == declineButton.id) {
		TheMod.proxy.decline(newList.getSelected());
		newList.remove(newList.getSelected());
	}else if (button.id == inviteButton.id) {
		sendInvite();
	}else if (button.id == leavePartyButton.id) {
		leaveParty();
	}
	setAvailability();
}

private void leaveParty() {
	TheMod.proxy.leaveParty();
}

public void drawScreen(int x, int y, float idk) {
	this.drawDefaultBackground();
	super.drawScreen(x, y, idk);
	userTextField.drawTextBox();
	this.fontRenderer.drawStringWithShadow("invites:", this.width / 2 - 200,
			this.height / 2 - 60, 0xffffff);
}

private void sendInvite() {
	TheMod.proxy.sendInviteToServer(userTextField.getText());
	userTextField.setText("");
}

private void setAvailability(){
	if(TheMod.proxy.isInParty()){
		leavePartyButton.enabled = true;
	}else{
		leavePartyButton.enabled = false;
	}
	if(!userTextField.getText().equals("")){
		inviteButton.enabled = true;
	}else{
		inviteButton.enabled = false;
	}
	if(newList.getSelected() == -1){
		acceptButton.enabled = false;
		declineButton.enabled = false;
	}else{
		acceptButton.enabled = true;
		declineButton.enabled = true;
	}
}
}

for the nbt/item part, just open a container with that and you should have no problem figuring out how to manipulate PlayerInventory for you concern

 

==========================

 

about the 2nd question, i dont like to encourage anything related to bukkit but...

 

what i would do is make the mods register their config files to your mod, then reading would be easy if you setup a convention

aka something like

"place all item under the category "ItemFlenix" and place an array of 2 value containing {itemId, price}

then the same for block but under category "BlockFlenix""

 

but liek i said ... we probably shouldnt be encouraging bukkit

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

well for the gui part its pretty straightfoward but here an example of my party gui (theres also a packet send in there)

 

 


import java.util.List;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;

import org.lwjgl.input.Keyboard;

import com.hydroflame.GuiApi.GuiNewList;
import com.hydroflame.mod.TheMod;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* The gui for party managing
* @author hydroflame
*
*/
@SideOnly(Side.CLIENT)
public class PartyGUI extends GuiScreen {

public static int GUI_ID = 0;
private boolean absorb = false;

private GuiNewList<String> newList;
private GuiButton[] guiButton;
private GuiButton acceptButton;
private GuiButton declineButton;
private GuiButton leavePartyButton;
private GuiButton inviteButton;
private GuiTextField userTextField;


public PartyGUI() {
}

// button is (id, x, y, width, height, text)
public void initGui() {
	newList = new GuiNewList<String>(125, this.width/2-200, this.height/2-50, 200, 100);

	List<String> alist = TheMod.proxy.getList();
	for (int i = 0; i < alist.size(); i++) {
		newList.add(alist.get(i));
	}

	acceptButton = new GuiButton(0, this.width / 2 + 30,
			this.height / 2 - 50, 60, 20, "accept");
	userTextField = new GuiTextField(fontRenderer, this.width / 2 - 130,
			this.height / 2 - 100, 103, 20);
	userTextField.setTextColor(-1);
	userTextField.setEnableBackgroundDrawing(true);
	userTextField.setMaxStringLength(30);
	userTextField.setFocused(true);
	inviteButton = new GuiButton(1, this.width / 2 - 20,
			this.height / 2 - 100, 50, 20, "invite");
	declineButton = new GuiButton(2, this.width / 2 + 30,
			this.height / 2 - 30, 60, 20, "decline");
	leavePartyButton = new GuiButton(3, this.width/2+30, this.height/2 -10, 60, 20, "leave party");

	buttonList.add(leavePartyButton);
	buttonList.add(declineButton);
	buttonList.add(acceptButton);
	buttonList.add(inviteButton);
	buttonList.add(newList);
	setAvailability();
}

protected void mouseClicked(int par1, int par2, int par3) {
	super.mouseClicked(par1, par2, par3);
}

protected void keyTyped(char par1, int par2) {
	if (absorb) {
		if (this.userTextField.textboxKeyTyped(par1, par2)) {

		} else if (userTextField.isFocused() && par2 == Keyboard.KEY_RETURN) {
			sendInvite();
		} else {
			super.keyTyped(par1, par2);
		}
		setAvailability();
	}else{
		absorb = true;
	}
}

protected void actionPerformed(GuiButton button) {
	if (button.id == acceptButton.id) {
		TheMod.proxy.acceptInvite(newList.getSelectedItem());
		TheMod.proxy.decline(newList.getSelected());
		newList.remove(newList.getSelected());
	} else if (button.id == declineButton.id) {
		TheMod.proxy.decline(newList.getSelected());
		newList.remove(newList.getSelected());
	}else if (button.id == inviteButton.id) {
		sendInvite();
	}else if (button.id == leavePartyButton.id) {
		leaveParty();
	}
	setAvailability();
}

private void leaveParty() {
	TheMod.proxy.leaveParty();
}

public void drawScreen(int x, int y, float idk) {
	this.drawDefaultBackground();
	super.drawScreen(x, y, idk);
	userTextField.drawTextBox();
	this.fontRenderer.drawStringWithShadow("invites:", this.width / 2 - 200,
			this.height / 2 - 60, 0xffffff);
}

private void sendInvite() {
	TheMod.proxy.sendInviteToServer(userTextField.getText());
	userTextField.setText("");
}

private void setAvailability(){
	if(TheMod.proxy.isInParty()){
		leavePartyButton.enabled = true;
	}else{
		leavePartyButton.enabled = false;
	}
	if(!userTextField.getText().equals("")){
		inviteButton.enabled = true;
	}else{
		inviteButton.enabled = false;
	}
	if(newList.getSelected() == -1){
		acceptButton.enabled = false;
		declineButton.enabled = false;
	}else{
		acceptButton.enabled = true;
		declineButton.enabled = true;
	}
}
}

for the nbt/item part, just open a container with that and you should have no problem figuring out how to manipulate PlayerInventory for you concern

 

==========================

 

about the 2nd question, i dont like to encourage anything related to bukkit but...

 

what i would do is make the mods register their config files to your mod, then reading would be easy if you setup a convention

aka something like

"place all item under the category "ItemFlenix" and place an array of 2 value containing {itemId, price}

then the same for block but under category "BlockFlenix""

 

but liek i said ... we probably shouldnt be encouraging bukkit

 

Thanks, I'll tinker with the button stuff.

As for the second one, I'm not encouraging bukkit, just replacing one of the things I enjoyed from it. Forge is missing a decent economy system, so I'm trying to fill the void a bit and the more things I support, the better. I am actually adding bukkit support to the mod for MCPC+ servers, but that's irrelevant :P

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Link to comment
Share on other sites

@gotolink, if a mod ad a ore or a new kind of rare log, youd still need to find a way to price every "base" items

 

@op, well forge has "forge essentials" but idk how good it is

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

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.