Jump to content

Recommended Posts

Posted

Yes do the

7 minutes ago, Leomelonseeds said:

Entity entity = new Entity(); ? replace Entity with your entity

thing, then replace

2 minutes ago, clowcadia said:

this.entity = entity;

with your variable

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

  • Replies 58
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted

Do the same thing in your guihandler and container and post your code.

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted
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 entity = world.getEntityByID(x);
			Basic basic = new Basic(world);
			return new GuiBasic(player.inventory, entity,basic);
		}
		return null;
	}

}
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;
	private World world;
	private Basic basic = new Basic(world);

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

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

Why do you have a Basic? I told you to replace the ENTITY with YOUR entity.

2 minutes ago, clowcadia said:

Entity entity = world.getEntityByID(x);

Also, replace world.getEntityByID(x) with an instance of your OWN entity(eg. new YourEntity();)

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted
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){
				if(foodStack.getUnlocalizedName().equals(Items.APPLE.getUnlocalizedName()) && stomach != stomachCap){
					Utils.getLogger().info("Stomach: "+foodStack.getUnlocalizedName());
					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;
    }




}

 

Posted

Ok

2 minutes ago, Leomelonseeds said:

Entity entity = world.getEntityByID(x);

I dont get why you are not merging this with basic tho. You do not need two lines for entiy and basic.

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted

Just try commenting the entity out and give the log if erroring.

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted (edited)

Ok everyline that has 

22 minutes ago, Leomelonseeds said:

Entity entity = world.getEntityByID(x);

or

28 minutes ago, clowcadia said:

private Entity entity;

put // infront of that to show its a comment.

 

Also replace

28 minutes ago, clowcadia said:

Entity basic = world.getEntityByID(x);

with:

28 minutes ago, clowcadia said:

Basic basic = new Basic(world);

 

 

After that  run minecraft.

Edited by Leomelonseeds

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted
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){
				if(foodStack.getUnlocalizedName().equals(Items.APPLE.getUnlocalizedName()) && stomach != stomachCap){
					Utils.getLogger().info("Stomach: "+foodStack.getUnlocalizedName());
					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;
    }




}
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){
			Basic basic = new Basic(world);
			
			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 entity = world.getEntityByID(x);
			Basic basic = new Basic(world);
			return new GuiBasic(player.inventory, basic);//entity,
		}
		return null;
	}

}
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;
	private World world;
	private Basic basic = new Basic(world);

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

	@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.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);
		
	}
	

}
package com.clowcadia.test.containers;

import com.clowcadia.test.npc.Basic;
import com.clowcadia.test.utils.Utils;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;

public class ContainerBasic extends Container{
	//public Entity entity;
	public Basic basic;
	
	public ContainerBasic(IInventory playerInv, Basic basic) {
		this.basic = basic;
		
		
		IItemHandler handler = basic.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); //Gets the inventory from our tile entity

		//Our tile entity slots
		this.addSlotToContainer(new SlotItemHandler(handler, 0, 8,8));
		
	//The player's inventory slots
		int xPos = 8; //The x position of the top left player inventory slot on our texture
		int yPos = 84; //The y position of the top left player inventory slot on our texture

		//Player slots
		for (int y = 0; y < 3; ++y) {
			for (int x = 0; x < 9; ++x) {
				this.addSlotToContainer(new Slot(playerInv, x + y * 9 + 9, xPos + x * 18, yPos + y * 18));
			}
		}

		for (int x = 0; x < 9; ++x) {
			this.addSlotToContainer(new Slot(playerInv, x, xPos + x * 18, yPos + 58));
		}
		Utils.getLogger().info("Finish ContainerBasic");
	}
	
	@Override
	public boolean canInteractWith(EntityPlayer player) {
		return !player.isSpectator();
	}
}

 

Posted (edited)
23 minutes ago, clowcadia said:

lost functionality in consuming items

Hmmmmmmmm

 

What does that mean?

Edited by Leomelonseeds

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted
13 minutes ago, clowcadia said:

Basic basic

Try replacing that with Entity basic (I doubt that will do anything)

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted
3 minutes ago, Leomelonseeds said:

Try replacing that with Entity basic (I doubt that will do anything)

That is saying to go back to entity rather then basic, i am assuming i should revert to my privious configurations?

Posted

Sure, if  it works better...

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted
stomachDisplay = Basic.getStomach();

Remeber this line?

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted
1 minute ago, Leomelonseeds said:

stomachDisplay = Basic.getStomach();

Remeber this line?

I stopped using it as a shorthand and just used the code instead (Basic.getStomach)

Posted
31 minutes ago, clowcadia said:

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

 

31 minutes ago, clowcadia said:

(stomachDisplay)

Huh??

 

Just do what you did befire.

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Guest
This topic is now closed to further replies.

Announcements




×
×
  • Create New...

Important Information

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