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.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • In order, X}   1.  (Force class to load, as was explained)  and was how it was shown.. I am up for 'changing it up' & optimizing it later,     That's  just the method that was shown.  I want to optimize it later for sure. 2.o_hand  ->   is offhand   I got sick to death of doing typos, and used it & m_hand for main hand ...   (offhand is the shield slot typically) 2. .... actually [ target = (LivingEntity)event.getTarget(); ]  inside of  (AttackEntityEvent event) is 100% capable of causing an error. -- Try setting it up & smacking with any melee attack (fist or weapon) the following a.  Any Minecart b. Any End Crystal c. Any Item Frame. d. Any Boat    ----  it literally causes the game to close with an exception.   All those things can both 'trigger the attackEntity event'  and be inside the target of the player, which will cause an exception when cast into a (Living Entity), which was used to apply the potion effects... ~~ Strangely enough,  a armor stand  not only is uneffected by it, but can accept potions applied to it as well. 3.  It does do something,  It fails & does nothing, which means 'target' is null still, and no potion effects get applied to the target that was hit. --- which means, it prevents the game from being shut down from an unintended casting of a target into a living entity object (which is needed to apply potion effects on) 4.  That's just nitpicking really,  That's an old logic habit....    Some reason it slipped my mind,  either way,     (!(thing == thing)) same effect of (thing != thing)   ---likely I honestly fell back into an old habit when inverse of true statement was my thought on that. 5. I know...  It's not complete (i've not  finished the blocks, as I'm working towards combat centric things, and I'm debating what I want to do with it) --- also,  to note, I remember why I put try { atker = (LivingEntity)livi.getAttackingEntity(); } catch (Exception e) { }  (for future use)      things like minecarts & end crystals can harm the player & other entities, and that event fires when an entity get hurt.... and given I just got off of just randomly finding out that casting the target of my hit into a (living entity) object can cause fatal exceptions, it's there to 'do NOTHING' if that happens, and an prevent fatal exceptions from going off because of a weird entity causing damage that isn't a livingentity for some reason. ~~~  Yes I plan to use it later..    that was for an armor thing. 6. meh...   Again   alot of the primary page is tutorial code....   I left what was shown,  and I'm learning what does what.. .and pruning what doesn't work.    -- yes, it annoys me as well but that's not on the short list atm. 7. as for 'fall = falls'  . I don't like doing that, as i prefer the geniune fallback if some unknown reason happens  a valid variable gets assign (right or wrong) and prevents weird unknown errors. 8.  The method is 100% straight forward    It's just a nested if loop that of course tests each string once (effectively) and doesn't attempt to assign an empty tooltip. _NormToolTip Is on it w/ no shift or cntl held down (either one) _When shift or cntrl is held down,  it shows the correct one. _When Shift & Cntrl are held down.. it shows Cntrl over Shift. ---- to be fair I actually didn't think to check for a method that checks if  a string is empty. ~~~  It uses Exclusionary logic, but if you can think of a faster way of doing  -normal tooltip (no keys held) -Shift Tooltip (either shift held) -Cntl ToolTip (either Cntrl held) -Cntl tooltip over  Shift tooltip (when a Cntrl & Shift is held, either side)  I'm all ears if you think you can do that faster and prevent it from using a null value.
    • What I've been trying to do is I have been attempting to implement an item that can create a transparent blue layer around the entire player. I am using Curios' API for this, as the item is meant to be an equippable accessory. There are also other accessories I have implemented to the mod using the API. I have been able to implement everything that handles this rendering with the accessory item, however I've become stuck after running into a specific issue: when the transparent blue layer is active, it will prevent any accessories specifically on the player's arms from rendering. As far as I can tell, this only happens with the accessories on the player's arms (such as the gloves or even Curios' template knuckles item), as accessories rendering on the player's body for some reason render just fine under the transparent layer. Images for better context: I have been at this for quite awhile but haven't able to figure out what is causing this issue, especially since the inconsistency between rendering for body parts has made me even more confused. It could be a Curios issue, but nothing in its accessory layer code exactly stands out as a cause (if it is indeed Curios' fault though it would at least be good to know what the issue is to pass on to the mod dev). The pendant and glove accessories both render with the same RenderType and render buffer, which I duplicated based on the vanilla armor layer's choices for that, as the vanilla armor layer is also immune to the transparency issue on the arm model part: The relevant code for items and renderers can be found below: Pendants: - https://github.com/Gilded-Games/The-Aether/blob/1.16/src/main/java/com/gildedgames/aether/common/item/accessories/pendant/PendantItem.java - https://github.com/Gilded-Games/The-Aether/blob/1.16/src/main/java/com/gildedgames/aether/client/renderer/accessory/model/PendantModel.java Gloves: - https://github.com/Gilded-Games/The-Aether/blob/1.16/src/main/java/com/gildedgames/aether/common/item/accessories/gloves/GlovesItem.java - https://github.com/Gilded-Games/The-Aether/blob/1.16/src/main/java/com/gildedgames/aether/client/renderer/accessory/model/GlovesModel.java Repulsion Shield (the item creating the transparency layer): - https://github.com/Gilded-Games/The-Aether/blob/1.16/src/main/java/com/gildedgames/aether/common/item/accessories/misc/RepulsionShieldItem.java - https://github.com/Gilded-Games/The-Aether/blob/1.16/src/main/java/com/gildedgames/aether/client/renderer/accessory/model/RepulsionShieldModel.java and, if necessary, Curios' Accessory Layer (code not mine, obviously): - https://github.com/TheIllusiveC4/Curios/blob/1.16.x-forge/src/main/java/top/theillusivec4/curios/client/render/CuriosLayer.java Any help would be appreciated, as I've run out of ideas for what could be causing this issue and how I could fix it. I can provide more information if needed.
    • Ok that's fair. But it's still terrible.
    • Really old Minecraft versions are no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • Ah sorry, you're right. I can refer you to the way Lycanites renders all of their .obj model entities, and best of all it's up to date for 1.16, but it is pretty complicated than just your standard java model. Depending on what you're doing it might not be worth it... https://gitlab.com/Lycanite/LycanitesMobs/-/tree/master/src/main/java/com/lycanitesmobs/client
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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