Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Alternate methods for opening a GUI


Recommended Posts

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?

Link to post
Share on other sites

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?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to post
Share on other sites

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;
}

}

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



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.