Jump to content

Recommended Posts

Posted
  On 3/7/2017 at 3:53 AM, Leomelonseeds said:

 

Huh??

 

Just do what you did befire.

Expand  

its just an empty string, i am not worried about the centering so much as the output. what i did before does not refresh like it does on static value unfortunantly. but if i use a static value each time i exit and enter the game it starts the value over rather then reading from nbt

  • Replies 58
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted
  On 3/7/2017 at 3:21 AM, clowcadia said:

public static Basic instance;

Expand  

This line is meaningless because 1. You never initialise or use it, and 2. Your entity is not a singleton class. Every time one of your entity spawns in the world (however that happens), a new instance of the class is created - you can't use static fields or instances for this. It'd be like trying to apply damage to a particular zombie in the world by saying "Give all zombies 1/2 health". Anything that involves your entity needs to relate to the particular instance that is involved - in this case, the particular instance that the player clicked on to open the GUI.

 

  On 3/7/2017 at 3:21 AM, clowcadia said:
if(ID==BASIC){
	Basic basic = new Basic(world);
	return new ContainerBasic(player.inventory,basic);
}

 

Expand  

Creating a new Basic is not at all what you need to do - you need the specific Basic instance that the player clicked on. You were on the right track before when you were using getEntityByID.

  On 3/7/2017 at 3:21 AM, clowcadia said:

this.mc.fontRendererObj.drawString(basic.getStomach()+"", this.xSize / 2 - this.mc.fontRendererObj.getStringWidth(stomachDisplay) / 2, 20, 4210752);

Expand  

This is on the right track, too. Once you get your basic field pointing to the correct instance of the entity, this line should work.

 

If your entity data is being reset when the world is saved/loaded, that's not a problem with GUIs and Containers - it's to do with the entity itself (probably something to do with NBT). If that's still a problem, it's probably best to post a new thread about that specific topic to get more help.

Posted
  On 3/7/2017 at 8:21 AM, Jay Avery said:

If your entity data is being reset when the world is saved/loaded, that's not a problem with GUIs and Containers - it's to do with the entity itself (probably something to do with NBT). If that's still a problem, it's probably best to post a new thread about that specific topic to get more help.

Expand  

The data in NBT seams to reset only when it is on static where the value of stomach variable actually adjust in gui properly. Static shows correct gui change but resets the value always on restart thats the issue. other wise NBT runs correctly but the value does not change with in gui or just shows the initial value of creation of entity 0, weather the getStomach method is return stomach; or return this.stomach;

Posted (edited)
  On 3/7/2017 at 4:40 PM, clowcadia said:

The data in NBT seams to reset only when it is on static where the value of stomach variable actually adjust in gui properly. Static shows correct gui change but resets the value always on restart thats the issue. other wise NBT runs correctly but the value does not change with in gui or just shows the initial value of creation of entity 0, weather the getStomach method is return stomach; or return this.stomach;

Expand  

Whatever is happening when you make stomach static, it is not going to be what you want to happen - even if it seems that way at first glance. Post your most up-to-date code (with non-static stomach) and we'll see if we can fix the GUI issue.

Edited by Jay Avery
Posted

Ok thank you.

Basic

package com.clowcadia.test.npc;

import com.clowcadia.test.GuiHandler;
import com.clowcadia.test.TestModHandler;
import com.clowcadia.test.utils.Utils;

import net.minecraft.block.ITileEntityProvider;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import scala.reflect.internal.Trees.This;

public class Basic extends EntityLiving implements  ICapabilityProvider{
	
	public static Basic instance;
	
	private final ItemStackHandler handler;
	private String tagStomach = "Stomach";
	private int stomach;	
	private int stomachCap = 800;
	
	public Basic(World world) 
	{			
		super(world);		
		this.handler = new ItemStackHandler(9); 
		this.stomach = 0;
		//Utils.getLogger().info("basic constructor" +this.stomach);
	}
	public int getStomach(){
		return stomach;
	}
	@Override
	public void readEntityFromNBT(NBTTagCompound compound) {
		this.handler.deserializeNBT(compound.getCompoundTag("ItemStackHandler"));		
		this.stomach = compound.getInteger("Stomach");
		if(compound.hasKey(tagStomach)) Utils.getLogger().info("Reading Stomach");
		super.readEntityFromNBT(compound);
	}
	
	@Override
	public void writeEntityToNBT(NBTTagCompound compound) {
		super.writeEntityToNBT(compound);
		
		compound.setTag("ItemStackHandler", this.handler.serializeNBT());
		compound.setInteger("Stomach", this.stomach);
		if(compound.hasKey(tagStomach)) Utils.getLogger().info("Writing Stomach");
		
	}	
	
	@Override
	public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
		if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return (T) this.handler;		
		return super.getCapability(capability, facing);
	}
	
	@Override
	public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
		if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return true;
		return super.hasCapability(capability, facing);
	}
	
	@Override
	public void onEntityUpdate() {
		ItemStack foodStack = handler.getStackInSlot(0);
		if (this.world != null){
			if(!this.world.isRemote){
				Utils.getLogger().info("Stomach: "+stomach);
				if(foodStack.getUnlocalizedName().equals(Items.APPLE.getUnlocalizedName()) && stomach != stomachCap){
					
					foodStack.splitStack(1);
					stomach += 40;
				}
				
			}				
		}
			
			
		super.onEntityUpdate();
	}
	
	@Override
	public boolean processInteract(EntityPlayer player, EnumHand hand)
    {
		
		if (!this.world.isRemote)
		{			
			int basicID = this.getEntityId(); //for inputing into x/y/z in the opne gui to pass the entety id
			System.out.println("Player has interacted with the mob");	
			player.openGui(TestModHandler.instance, GuiHandler.BASIC, this.world, basicID,0, 0);	
		}
		return true;
    }




}

Gui Handler

package com.clowcadia.test;


import java.security.PublicKey;


import com.clowcadia.test.containers.ContainerBasic;
import com.clowcadia.test.gui.GuiBasic;
import com.clowcadia.test.npc.Basic;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.datafix.fixes.EntityId;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;

public class GuiHandler implements IGuiHandler{
	
	
	public static final int BASIC = 0;	

	@Override
	public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
		if(ID==BASIC){
			Entity basic = world.getEntityByID(x);
			
			return new ContainerBasic(player.inventory,basic);
		}
		return null;
	}

	@Override
	public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
		if(ID==BASIC){
			Entity basic = world.getEntityByID(x);
			return new GuiBasic(player.inventory, basic);
		}
		return null;
	}

}

GuiBasic

package com.clowcadia.test.gui;

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

import com.clowcadia.test.TestModHandler;
import com.clowcadia.test.containers.ContainerBasic;
import com.clowcadia.test.npc.Basic;
import com.clowcadia.tutorial3.Reference;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.Entity;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.items.CapabilityItemHandler;
import scala.reflect.internal.Trees.This;

public class GuiBasic extends GuiContainer{
	
	private IInventory playerInv;
	private Entity entity;
	private String stomachDisplay;

	public GuiBasic(IInventory playerInv, Entity entity) {
		super(new ContainerBasic(playerInv, entity));
		
		
		this.xSize=176;
		this.ySize=166;
		
		this.playerInv = playerInv;
		this.entity = entity;
	}

	@Override
	protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
		GlStateManager.color(1.0F, 1.0F, 1.0F,1.0F);
		this.mc.getTextureManager().bindTexture(new ResourceLocation(TestModHandler.modId, "textures/gui/container/basic.png"));
		this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize,this.ySize);
		
	}
	
	/**
	 * Draws the text that is an overlay, i.e where it says Block Breaker in the gui on the top
	 */
	@Override
	protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
		String s = I18n.format("container.basic"); //Gets the formatted name for the block breaker from the language file
		this.mc.fontRendererObj.drawString(s, this.xSize / 2 - this.mc.fontRendererObj.getStringWidth(s) / 2, 6, 4210752); //Draws the block breaker name in the center on the top of the gui
		this.mc.fontRendererObj.drawString(this.playerInv.getDisplayName().getFormattedText(), 8, 72, 4210752); //The player's inventory name
		this.mc.fontRendererObj.drawString(((Basic) entity).getStomach()+"", this.xSize / 2 - this.mc.fontRendererObj.getStringWidth(stomachDisplay) / 2, 20, 4210752);
		int actualMouseX = mouseX - ((this.width - this.xSize) / 2);
		int actualMouseY = mouseY - ((this.height - this.ySize) / 2);
		
	}
	

}

 

Posted (edited)

That code all looks fine and like it should be working.

 

The problem is likely to do with server/client syncing - you are updating your entity data on the server side (where !world.isRemote), but the GUI is drawn on the client side, where the data isn't changed. I think you'll need to use packets to send the updated stomach value to the client side when it gets changed on the server, so that it can be used in the GUI.

Edited by Jay Avery
Posted

I've never used packets with an Entity. I assume the process is more or less the same as for TIleEntities and suchlike, but you should probably ask someone who has direct experience if you need more help!

Posted

You can use Container#detectAndSendChanges() to send pakcet and Container#updateProgressBar(int, int)(clinet only) to update data.

in detectAndSendChanges(), compare values you want to update and call IContainerListener#sendProgressBarUpdate(Container, int, int) for every listener in Container#listeners.

in updateProgressBar(int, int), update values according to ids.

Look into the ContainerFurnace and GuiFurnace (container updats values in TE and GUI draws from TE's values)

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements




  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have no idea - maybe use a pre-configured modpack as working base and add some new mods one by one
    • Is there a crash-report?   The given log is literally just a 230 MB file of open GL error spam
    • Lemfi coupon code 15€ Bonus is the easiest way for you to turn a routine money‑transfer into instant savings—and we are thrilled to show you how. We tested it ourselves and unlocked the extra cash in seconds. RITEQH6J is the single code you need, and it delivers maximum benefits whether you are sending funds from Toronto, Paris, or Sydney. You simply enter the code once, and every eligible transaction keeps rewarding you. When you add Lemfi discount code 15€ off or Lemfi code 15€ Bonus to your transfer, you’re stacking value on security. In the next few minutes, we’ll prove that Lemfi is safe to use in Canada and walk you through the exact steps to claim your €15 windfall. What Is The Lemfi Promo Code for 15€ Bonus? Both new and existing customers enjoy a richer experience when they activate our Lemfi coupon 15€ Bonus—sometimes called the 15€ Bonus Lemfi coupon. It’s the same five‑character code, but the perks multiply depending on your status: RITEQH6J – 15 € instant bonus credited the moment you initiate a qualifying transfer RITEQH6J – 30 € sign‑up reward for brand‑new Lemfi users who complete KYC RITEQH6J – 10 % cashback (up to 50 €) on your very first transfer RITEQH6J – 20 € referral reward after your invitee finishes 20 transactions RITEQH6J – 20 € cashback on any recurring money‑transfer plan you schedule RITEQH6J – 30 € extra bonus when you send 100 € or more in a single transfer Lemfi First Time Promo Code 15€ Bonus For New Users In 2025 You get the richest haul of incentives when you join Lemfi in 2025 and apply our Lemfi First Time Promo Code for 15€ Bonus—also known as Lemfi Promo Code First Order 15€ Bonus. Below are the headline gains: RITEQH6J – 15 € credited to every qualified user, instantly RITEQH6J – 30 € one‑time welcome bonus the day you finish sign‑up RITEQH6J – 10 % cashback (max 50 €) on your inaugural transfer RITEQH6J – Second‑tier 30 € bump once your first transfer exceeds 100 € RITEQH6J – Free intra‑app transfers for 90 days, saving you FX mark‑ups How To Redeem The Lemfi Coupon 15€ Bonus For New Users? Lemfi First Time Promo Code for 15€ Bonus, Lemfi Promo Code First Order 15€ Bonus, and Lemfi First Time Promo Code 15€ Bonus for new users are redeemed in six quick moves: Download Lemfi from Google Play / App Store. Open an account with your legal name and Canadian address. Complete photo ID verification and selfie check. On the “Promo” screen, paste RITEQH6J and tap “Apply.” Initiate your first money transfer of 10 € or more. Watch the 15 € bonus hit your Lemfi balance before the funds even settle. Lemfi Promo Code 15€ Bonus For Existing Customers Already have a wallet? Great news: the lemfi promo code 15€ Bonus for existing users doubles down on loyalty, and the lemfi discount code 15€ Bonus for existing customers ensures you never miss a rebate. RITEQH6J – Flat 15 € credited to every fresh transaction over 10 € RITEQH6J – 20 € referral payout after each invited friend completes 20 transfers RITEQH6J – 20 € cashback when you fund a recurring transfer plan RITEQH6J – 30 € bonus when any single transfer tops 100 € How To Use The Lemfi Code for 15€ Bonus For Existing Customers? Follow this path to apply the Lemfi discount code for 15€ Bonus, the Code promo Lemfi for 15€ Bonus, after your Lemfi login: Sign in and tap the “Promotions” tab. Enter RITEQH6J in the promo box and confirm. Start a new transfer or schedule a future one. The system auto‑deducts the bonus from your payable amount or credits it to your wallet. Latest Lemfi Promo Code for 15€ Bonus The freshest drop—Lemfi first time promo code for 15€ Bonus first order, Lemfi discount code 15€ Bonus, and Lemfi cashback code—all point to one hero string: RITEQH6J – 15 € for every user, every time RITEQH6J – 30 € sign‑up sweetener for new users RITEQH6J – 10 % cashback (capped at 50 €) on your very first transfer RITEQH6J – 20 € friend‑referral reward after 20 completed transfers RITEQH6J – 20 € cashback on automated transfer plans RITEQH6J – 30 € bonus when you move 100 € or more in one go How To Find The Lemfi Code for 15€ Bonus? You can score the Lemfi code for 15€ Bonus, the Lemfi cashback code, and the crowd‑sourced Lemfi referral code Reddit for 15€ Bonus in three reliable ways. First, subscribe to the Lemfi newsletter—verified codes often land there before anywhere else. Second, follow Lemfi on X (formerly Twitter), Instagram, and LinkedIn for flash promos. Third, bookmark reputable coupon portals (like ours) where every code is tested daily for real‑world success. Is Lemfi 15€ Bonus Code Legit? Is Lemfi legit? Absolutely. Lemfi (legal name Lemonade Technology Ltd.) is a registered Money Service Business with FINTRAC in Canada under registration #M20383642 opengovca.com. That means every Canadian transfer is overseen by federal anti‑money‑laundering regulators. More importantly, code promo Lemfi legit status is guaranteed: we refresh and re‑test RITEQH6J weekly. The promo has no geographic restrictions, so you can claim the 15 € Bonus on your first Lemfi money transfer and stack it on future transactions worldwide. How Does Lemfi Code for 15€ Bonus Work? 15€ Bonus on first-time Lemfi money transfer is credited the moment our system recognises the code during checkout, and Lemfi promo code for recurring transactions continues to provide cashback or flat bonuses on qualified transfers thereafter. In practice, you paste RITEQH6J once, Lemfi tags it to your customer ID, and the platform’s automated ledger applies the correct reward (bonus credit or cashback) to each eligible transaction until you choose to remove or replace the code. How To Earn Lemfi 15€ Bonus Coupons As A New Customer? To grab the next Lemfi coupon code 15€ Bonus or the elusive 100 off Lemfi coupon code, complete KYC, enable two‑factor authentication, and engage with Lemfi’s seasonal challenges (e.g., “Send three transfers in one week”). Each milestone adds fresh coupons to your in‑app Promo Wallet, which you can stack on top of RITEQH6J for even bigger savings. What Are The Advantages Of Using The Lemfi Discount Code for 15€ Bonus? Lemfi promo code for 15€ bonus delivers an immediate 15 € credit Lemfi promo code for 15€ Bonus stacks with a 30 € sign‑up reward Up to 50 € cashback (10 %) on your inaugural transfer 20 € cash per referral after 20 transactions 20 € cashback on automated recurring transfers 30 € boost on any single 100 €+ transfer Unlimited global usage—no expiry date Works for both CAD and EUR wallets Lemfi Discount Code For 15€ Bonus And Free Gift For New And Existing Customers Our Lemfi Discount Code for 15€ Bonus—also known as the 15€ Bonus Lemfi discount code—unlocks a treasure chest of perks you won’t find elsewhere: RITEQH6J – 15 € for any qualified transfer RITEQH6J – 30 € welcome credit to brand‑new customers RITEQH6J – 10 % cashback (max 50 €) on your first deal RITEQH6J – 20 € per referral once the invitee completes 20 sends RITEQH6J – 30 € kicker on transfers worth 100 € or more Pros And Cons Of Using The Lemfi Discount Code 15€ Bonus for <July2025> Lemfi 15€ Bonus discount code and the wider Lemfi 15 Euro Bonus program bring clear upsides—plus a couple of caveats: Pros Immediate 15 € savings per qualifying transfer High 30 € sign‑up bonus for newcomers Legit FINTRAC‑regulated service in Canada support.lemfi.com Low FX margins versus banks Stackable with referral and cashback offers Cons Bonuses paid in EUR; conversion fees may apply if you withdraw in CAD Cashback rewards require minimum transfer values (10 € or 100 € tiers) Terms And Conditions Of Using The Lemfi Coupon 15€ Bonus In 2025 Lemfi 15€ Bonus code must be entered exactly as “RITEQH6J.” Only one active promo per transaction, but stackable across separate transfers. Latest Lemfi code 15€ Bonus has no expiration date and is valid worldwide. Available to KYC‑verified users aged 18 +. New‑user bonuses credited once per person; device or IP duplication voids offer. Existing‑user cashback requires recurring transfer setup. Lemfi reserves the right to amend terms with 30‑days’ notice. Final Note: Use The Latest Lemfi Discount Code 15€ Bonus Grab the Lemfi discount code for 15€ Bonus today, and you’ll feel the value the second you hit “Send.” We’ve tested it from coast to coast, and the results are always the same—instant savings. Keep Lemfi 15€ Bonus code RITEQH6J in your back pocket, and every future transfer can be a mini payday. Happy saving! FAQs Of Lemfi 15€ Bonus Code Q1. Is Lemfi safe to use in Canada? A1. Yes. Lemfi is a FINTRAC‑registered Money Service Business (MSB #M20383642) and must comply with strict anti‑money‑laundering laws, encryption standards, and regular audits. Q2. Can I combine RITEQH6J with other Lemfi promo codes? A2. You can’t stack two codes on a single transaction, but you may apply RITEQH6J on one transfer and another valid code on a separate transfer to maximise total savings. Q3. Does RITEQH6J expire? A3. No expiration date is set. The code remains active across 2025 and beyond unless Lemfi issues a formal sunset notice—unlikely given its popularity. Q4. How fast is the 15 € bonus credited? A4. The bonus shows up instantly in your Lemfi wallet once the transaction is submitted and KYC is complete, removing any waiting period. Q5. Is the 15 € bonus paid in CAD or EUR? A5. Lemfi credits the bonus in EUR. If your base wallet is CAD, you can convert inside the app at inter‑bank FX rates or keep it in EUR for cross‑border spending.
    • I am trying to make a custom item that converts to another custom item when eaten. The food properties includes "usingConvertsTo(ModItems.ITEM_NAME.get())", however since the item is not yet registered during the registration process, the get() method returns null. Is there any way to work around this?
    • Having problems with forge installation on headless arch linux, regardless of forge-server from yay or manual wget, Cant find class error and results in net/minecraft/world/waypoints/Waypoint$Icon.class   net/minecraft/world/waypoints/Waypoint.class   net/minecraft/world/waypoints/WaypointManager.class   net/minecraft/world/waypoints/WaypointStyleAsset.class   net/minecraft/world/waypoints/WaypointStyleAssets.class   net/minecraft/world/waypoints/WaypointTransmitter$BlockConnection.class   net/minecraft/world/waypoints/WaypointTransmitter$ChunkConnection.class   net/minecraft/world/waypoints/WaypointTransmitter$Connection.class   net/minecraft/world/waypoints/WaypointTransmitter$EntityAzimuthConnection.class   net/minecraft/world/waypoints/WaypointTransmitter$EntityBlockConnection.class   net/minecraft/world/waypoints/WaypointTransmitter$EntityChunkConnection.class   net/minecraft/world/waypoints/WaypointTransmitter.class   version.json   Processor failed, invalid outputs:     /srv/minecraft/./libraries/net/minecraft/server/1.21.6/server-1.21.6-official.jar       Expected: b1448d2c947e923ccd63224defc3b51e5a72a98d       Actual:   5f30bf411bd0d1208baca6b7be1584442f4f6579 There was an error during installation
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.