Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Alternate methods for opening a GUI
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
Jershy

Alternate methods for opening a GUI

By Jershy, December 20, 2016 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Jershy    0

Jershy

Jershy    0

  • Tree Puncher
  • Jershy
  • Members
  • 0
  • 45 posts
Posted December 20, 2016

The normal way to call on a GUI seem to be by referring to an ID, which opens an instance of that Gui that has already been declared in the handler. However, my Gui needs an Interface to be passed through the constructor of that Gui. Is there any alternate method to call the Gui so that I can get a chance to pass in my variables?

  • Quote

Share this post


Link to post
Share on other sites

Animefan8888    677

Animefan8888

Animefan8888    677

  • Reality Controller
  • Animefan8888
  • Forge Modder
  • 677
  • 5746 posts
Posted December 20, 2016

The normal way to call on a GUI seem to be by referring to an ID, which opens an instance of that Gui that has already been declared in the handler. However, my Gui needs an Interface to be passed through the constructor of that Gui. Is there any alternate method to call the Gui so that I can get a chance to pass in my variables?

What interface, where is it stored?

  • Quote

Share this post


Link to post
Share on other sites

Jershy    0

Jershy

Jershy    0

  • Tree Puncher
  • Jershy
  • Members
  • 0
  • 45 posts
Posted December 20, 2016

The interface works similar to IMerchant which helps communicate between an entity and the Gui.

  • Quote

Share this post


Link to post
Share on other sites

Jershy    0

Jershy

Jershy    0

  • Tree Puncher
  • Jershy
  • Members
  • 0
  • 45 posts
Posted December 20, 2016

Here is the Entity Class;

ackage com.ageofempires.enitity.living;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import javax.annotation.Nullable;

import com.ageofempires.mod.AOE;
import com.ageofempires.mod.event.gui.GuiHandler;
import com.ageofempires.mod.gui.entity.IWorker;

import net.minecraft.client.main.Main;
import net.minecraft.entity.IMerchant;
import net.minecraft.entity.INpc;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.passive.EntityVillager.ITradeList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.MobEffects;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.pathfinding.PathNavigateGround;
import net.minecraft.potion.PotionEffect;
import net.minecraft.stats.StatList;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.village.MerchantRecipe;
import net.minecraft.village.MerchantRecipeList;
import net.minecraft.village.Village;
import net.minecraft.world.World;

public class EntityUsefulVillager extends EntityVillager implements IMerchant, IWorker, INpc{

private int randomTickDivider;
private boolean isMating;
private boolean isPlaying;
Village villageObj;
private EntityPlayer buyingPlayer;
private MerchantRecipeList buyingList;
private int timeUntilReset;
private boolean needsInitilization;
private boolean isWillingToMate;
private int wealth;
private String lastBuyingPlayer;
private int careerId;
private int careerLevel;
private boolean isLookingForHome;
private boolean areAdditionalTasksSet;
private final InventoryBasic villagerInventory;
private final boolean isMerchant;
private int profession;
private boolean isJob;
private int jobID;
private boolean isSoldier;
private int[] jobExp;
private boolean isJobInit;


public EntityUsefulVillager(World world) {
	this(world, 0, 2);

}

public EntityUsefulVillager(World world, int profession, int defaultLevel) {
	super(world);
	this.careerLevel = defaultLevel;
	this.villagerInventory = new InventoryBasic("Items", false, ;
	setProfession(profession);
	this.profession = profession;
	setSize(0.6F, 1.95F);
	((PathNavigateGround) getNavigator()).setBreakDoors(true);
	setCanPickUpLoot(true);
	this.isMerchant = world.rand.nextInt(11) <= 2 ? true : false;
	this.isJob = false;
}

public boolean processInteract(EntityPlayer player,
		EnumHand p_processInteract_2_,
		@Nullable ItemStack p_processInteract_3_) {
boolean flag = (p_processInteract_3_ != null)
		&& (p_processInteract_3_.getItem() == Items.SPAWN_EGG);

if ((!(this.worldObj.isRemote))) {
	if ((!(flag)) && (isEntityAlive()) && (!(isTrading()))
		&& (!(isChild()))) { 
			if (!player.isSneaking()) {

				if (((this.buyingList == null) || (!(this.buyingList
					.isEmpty())))) {
					setCustomer(player);
					player.displayVillagerTradeGui(this);

			}


			}else if(this.isJob){
			//TODO add CONTAINER gui for job.

			}else{
				this.setCustomer(player);
				player.openGui(AOE.instance, GuiHandler.USEFUL_VILLAGER_GUI_INIT_REQ, player.worldObj, (int)player.posX, (int)player.posY, (int)player.posZ);
			}
				player.addStat(StatList.TALKED_TO_VILLAGER);
		}
	}
	return super.processInteract(player, p_processInteract_2_, p_processInteract_3_);
}

@Override
protected void updateAITasks() {
	BlockPos blockpos;
	if (--this.randomTickDivider <= 0) {
		blockpos = new BlockPos(this);
		this.worldObj.getVillageCollection().addToVillagerPositionList(
				blockpos);
		this.randomTickDivider = (70 + this.rand.nextInt(50));
		this.villageObj = this.worldObj.getVillageCollection()
				.getNearestVillage(blockpos, 32);

		if (this.villageObj == null) {
			detachHome();
		} else {
			BlockPos blockpos1 = this.villageObj.getCenter();
			setHomePosAndDistance(blockpos1,
					this.villageObj.getVillageRadius());

			if (this.isLookingForHome) {
				this.isLookingForHome = false;
				this.villageObj.setDefaultPlayerReputation(5);
			}
		}
	}

	if ((!(isTrading())) && (this.timeUntilReset > 0)) {
		this.timeUntilReset -= 1;

		if (this.timeUntilReset <= 0) {
			if (this.needsInitilization) {
				for (MerchantRecipe merchantrecipe : this.buyingList) {
					if (merchantrecipe.isRecipeDisabled()) {
						merchantrecipe.increaseMaxTradeUses(this.rand
								.nextInt(6) + this.rand.nextInt(6) + 2);
					}
				}

				populateBuyingList();
				this.needsInitilization = false;

				if ((this.villageObj != null)
						&& (this.lastBuyingPlayer != null)) {
					this.worldObj.setEntityState(this, (byte) 14);
					this.villageObj.modifyPlayerReputation(
							this.lastBuyingPlayer, 1);
				}
			}

			addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 200,
					0));
		}
	}

	super.updateAITasks();
}


private boolean canVillagerPickupItem(Item p_canVillagerPickupItem_1_) {
	if(this.checkJob()) {
		List<Item> list = this.isItemRelatedToJob(jobID);
		if(list == null) {
			return false;
		}
		for(int i = 0; i < list.size(); i++) {
			if(p_canVillagerPickupItem_1_ == list.get(i)) {
				return true;
			}
		}
	}
	if(isSoldier) {
		return true;
	}


	return ((p_canVillagerPickupItem_1_ == Items.BREAD)
			|| (p_canVillagerPickupItem_1_ == Items.POTATO)
			|| (p_canVillagerPickupItem_1_ == Items.CARROT)
			|| (p_canVillagerPickupItem_1_ == Items.WHEAT)
			|| (p_canVillagerPickupItem_1_ == Items.WHEAT_SEEDS)
			|| (p_canVillagerPickupItem_1_ == Items.BEETROOT) || (p_canVillagerPickupItem_1_ == Items.BEETROOT_SEEDS));
}

public boolean checkJob() {
	return this.isJob;
}

public static List<Item> isItemRelatedToJob(int job) {
	List<Item> list = new ArrayList();
	switch(job) {
		case 1:
			list.add(Items.WHEAT);
			list.add(Items.WHEAT_SEEDS);
			list.add(Items.BEETROOT);
			list.add(Items.BEETROOT_SEEDS);
			list.add(Items.CARROT);
			list.add(Items.POTATO);
			return list;
		case 2:
			list.add(Item.getItemFromBlock(Blocks.IRON_ORE));
			list.add(Item.getItemFromBlock(Blocks.GOLD_ORE));
			list.add(Items.COAL);
			list.add(Items.DIAMOND);
		case 3:
			list.add(Item.getItemFromBlock(Blocks.LOG));
			list.add(Item.getItemFromBlock(Blocks.SAPLING));
		default:
			return null;
	}

}

private void populateBuyingList() {
	if ((this.careerId != 0) && (this.careerLevel != 0)) {
		this.careerLevel += 1;
	} else {
		this.careerId = (getProfessionForge().getRandomCareer(this.rand) + 1);
		this.careerLevel = 1;
	}

	if (this.buyingList == null) {
		this.buyingList = new MerchantRecipeList();
	}
	if(this.isMerchant) {
		this.buyingList.add(new MerchantRecipe(new ItemStack(getCareerTradesMerchant(this.profession)), null, new ItemStack(Items.EMERALD), 0, 10));
	}else{
		this.buyingList.add(new MerchantRecipe(new ItemStack(randomFoodSource(this.worldObj.rand)), null, new ItemStack(Items.EMERALD), 0, 3));
	}

	int i = this.careerId - 1;
	int j = this.careerLevel - 1;
	List<ITradeList> trades = (List<ITradeList>) getProfessionForge().getCareer(i).getTrades(j);

	if (trades == null)
		return;
	for (ITradeList entityvillager$itradelist : trades) {
		entityvillager$itradelist.modifyMerchantRecipeList(this.buyingList,
				this.rand);
	}
}

protected static Item getCareerTradesMerchant(int i) {
		switch(i) {
		case 0:
			return Items.WHEAT;
		case 1:
			return Items.PAPER;
		case 2:
			return Items.GOLD_INGOT;
		case 3:
			return Items.IRON_INGOT;
		case 4:
			return Items.COOKED_BEEF;
		case 5:
			return null;
		default:
			return Items.DIAMOND;	
		}
}

protected Item randomFoodSource(Random rand) {
	int i = rand.nextInt(4);
		switch(i) {
		case 0:
			return Items.BREAD;
		case 1:
			return Items.BAKED_POTATO;
		case 2:
			return Items.CARROT;
		default:
			return Items.BEETROOT;
		}
}

@Override
public int getJobID() {
	return this.jobID;
}

@Override
public int getJobExp() {
	return jobExp[this.jobID];
}

@Override
public boolean isJobIntialized() {
	return this.isJobInit;
}

@Override
public void setJobInitialized(boolean i) {
	this.isJobInit = i;

}

@Override
public void setJobID(int i) {
	this.jobID = i;
}

}

 

here is the Interface;

package com.ageofempires.mod.gui.entity;

import java.util.ArrayList;

import net.minecraft.entity.IMerchant;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.village.MerchantRecipe;
import net.minecraft.village.MerchantRecipeList;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public interface IWorker extends IMerchant{

public abstract void setCustomer(EntityPlayer paramEntityPlayer);

public abstract EntityPlayer getCustomer();

public abstract void setJobInitialized(boolean i);

public abstract int getJobID();

public abstract void setJobID(int i);

public abstract int getJobExp();

public abstract boolean isJobIntialized();

}

 

Here is the GUI class;

package com.ageofempires.mod.gui.entity;

import java.io.IOException;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ContainerMerchant;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;

public class GuiVillagerInitRequest extends GuiScreen {
private static final ResourceLocation MERCHANT_INIT_REQ_GUI_TEXTURE = new ResourceLocation(
		"textures/gui/entity/villagerInitReq.png");

private IWorker worker;
public final ITextComponent text;
public ITextComponent status;
private GuiButton Wood, Mine, Farm, Build; 	

public GuiVillagerInitRequest(IWorker worker, World world) {
	super();
	this.worker = worker;
	this.text = worker.getDisplayName();
	this.status = new TextComponentString("please slect a job you want me to preform.");
}

@Override
public void initGui() {
	this.Wood = new GuiButton(2, (3/4) * this.width, (3/4) * this.height, "Collect Wood");
	this.Mine = new GuiButton(1, (1/4) * this.width, (3/4) * this.height, "Mine Ore");
	this.Farm = new GuiButton(0, (3/4) * this.width, (1/4) * this.height, "Farm Crops");
	this.Build = new GuiButton(3, (1/4) * this.width, (1/4) * this.height, "Build");
}

@Override
public void actionPerformed(GuiButton button) throws IOException{
	int i = button.id;
	this.worker.setJobInitialized(false);
	switch(i) {
	case 0:
		this.worker.setJobID(i + 1);
		this.mc.displayGuiScreen(null);
        if (this.mc.currentScreen == null)
            this.mc.setIngameFocus();
	case 1:
		this.worker.setJobID(i + 1);
		this.mc.displayGuiScreen(null);
        if (this.mc.currentScreen == null)
            this.mc.setIngameFocus();
	case 2:
		this.worker.setJobID(i + 1);
		this.mc.displayGuiScreen(null);
        if (this.mc.currentScreen == null)
            this.mc.setIngameFocus();
	case 3:
		this.worker.setJobID(i + 1);
		this.mc.displayGuiScreen(null);
        if (this.mc.currentScreen == null)
            this.mc.setIngameFocus();
   default:
	   status.appendText("an error occured, please try again.");
	   return;
	}
}

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    this.drawDefaultBackground();
    super.drawScreen(mouseX, mouseY, partialTicks);
}

@Override
public boolean doesGuiPauseGame() {
    return false;
}

}

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45596 posts
Posted December 20, 2016

You have to realize how this works in vanilla. The

IMerchant

instance doesn't magically get transferred over the network. The client always uses an implementation called

NpcMerchant

. You have to do the same.

  • Quote

Share this post


Link to post
Share on other sites

Jershy    0

Jershy

Jershy    0

  • Tree Puncher
  • Jershy
  • Members
  • 0
  • 45 posts
Posted December 20, 2016

where is it implemented? I've been through the code the villager class and IMerchant, and haven't found any reference to it.

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45596 posts
Posted December 20, 2016

Use your IDE:

feFNKkh.png

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • plugsmustard
      on/off button for custom furnace

      By plugsmustard · Posted 17 minutes ago

    • anothertime
      1.14 - hot swap fails in IDEA

      By anothertime · Posted 17 minutes ago

      I usually rebuild the module with build\build module but I've also tried run\reload changes after looking for a solution on the web but the result is the same
    • DaemonUmbra
      1.14 - hot swap fails in IDEA

      By DaemonUmbra · Posted 19 minutes ago

      Are you running the build manually with a gradle task or are you clicking run -> reload changed classes?
    • Draco18s
      on/off button for custom furnace

      By Draco18s · Posted 19 minutes ago

      You linked to a specific commit, so when I looked at it, it was the old commit where it wasn't changed. As far as I can tell, it should work. Can you post a screenshot of the error?   As for what you put here, you put the code that does whatever you want the button to do.
    • anothertime
      1.14 - hot swap fails in IDEA

      By anothertime · Posted 21 minutes ago

      Changes to the body of an existing method
  • Topics

    • plugsmustard
      55
      on/off button for custom furnace

      By plugsmustard
      Started Wednesday at 03:11 PM

    • anothertime
      4
      1.14 - hot swap fails in IDEA

      By anothertime
      Started 9 hours ago

    • matt1999rd
      4
      [1.14-newer] how to keep value when closing minecraft

      By matt1999rd
      Started 2 hours ago

    • matt1999rd
      15
      [1.14-newer] deprecated method onBlockActivated

      By matt1999rd
      Started November 1

    • JetCobblestone
      9
      [1.14] moving item assignment to a separate function

      By JetCobblestone
      Started 2 hours ago

  • Who's Online (See full list)

    • sobrinth
    • anothertime
    • DaemonUmbra
    • plugsmustard
    • Yanny7
    • FaxeeK
    • loordgek
    • Nuparu00
    • Cerandior
    • LTNightshade
    • kuririn
    • diesieben07
    • Lea9ue
    • Ommina
    • Simon_kungen
    • CactusCoffee
    • Iterator
    • matt1999rd
    • vaartis
    • DragonITA
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Alternate methods for opening a GUI
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community