Posted June 22, 201510 yr Hello guys, Im still trying to understand on how you make a custom GUI inventory for a custom Entity. I searched online and found and made it to work. The problem is that I can't seem to make the Entity store the items that it picks up into the custom Inventory GUI. I have tested on the Entity and it is working only to see the GUI Inventory and storing items to it but not storing picked up items. Heres my Entity class: package minecraft.FirstPlugin.entities; import minecraft.FirstPlugin.FirstMod; import minecraft.FirstPlugin.Ref; import minecraft.FirstPlugin.Inventory.FBInventory; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAIHarvestFarmland; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryBasic; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.DamageSource; import net.minecraft.world.World; public class FarmingBot extends EntityVillager { public FBInventory gear; public FarmingBot(World worldIn) { super(worldIn); this.setupGear(); this.setSize(0.6F, 1.8F); this.tasks.addTask(1, new EntityAIHarvestFarmland(this, 0.6D)); this.setCanPickUpLoot(true); } public boolean isAIEnable() { return true; } protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.35D); this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(0.2D); } @Override public boolean interact(EntityPlayer player) { super.interact(player); //if(!player.worldObj.isRemote) player.openGui(Ref.MOD_ID, 5, this.worldObj, this.getEntityId(), 0, 0); //we will use x coord for sending entityId return true; } public void onInventoryChanged(InventoryBasic inv) {} public int howManySlots() { return 8; } private void setupGear() { FBInventory gear1 = this.gear; this.gear = new FBInventory("FBInventory", howManySlots()); this.gear.setCustomName(gear.getName()); if (gear1 != null) { //gear1.func_110132_b(this); int i = Math.min(gear1.getSizeInventory(), this.gear.getSizeInventory()); for (int j = 0; j < i; ++j) { ItemStack itemstack = gear1.getStackInSlot(j); if (itemstack != null) { this.gear.setInventorySlotContents(j, itemstack.copy()); } } gear1 = null; } //this.gear.func_110134_a(this); } public void onDeath(DamageSource ds) { super.onDeath(ds); if (gear != null && !this.worldObj.isRemote) { for (int i = 0; i < gear.getSizeInventory(); ++i) { ItemStack itemstack = gear.getStackInSlot(i); if (itemstack != null) { this.entityDropItem(itemstack, 0.0F); } } } } public void writeEntityToNBT(NBTTagCompound com) { NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < this.gear.getSizeInventory(); ++i) { ItemStack itemstack = this.gear.getStackInSlot(i); if (itemstack != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte) i); itemstack.writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } com.setTag("Items", nbttaglist); } } public void readEntityFromNBT(NBTTagCompound com) { NBTTagList nbttaglist = com.getTagList("Items", 10); this.setupGear(); for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); int j = nbttagcompound1.getByte("Slot") & 255; if (j >= 0 && j < this.gear.getSizeInventory()) { this.gear.setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(nbttagcompound1)); } } } public InventoryBasic testing() { return this.gear; } }
June 22, 201510 yr Most of the tutorials on custom inventory GUI are setup for creating a 'new' inventory. Are you sure when you used the tutorial you changed over the the entities inventory instead of a new custom one? Long time Bukkit & Forge Programmer Happy to try and help
June 23, 201510 yr Author I think that the tutorial is just for creating a new inventory. How do i change over the entities inventory instead? Im on 1.8.
June 23, 201510 yr Author Ok i managed to solved it. I spent hours learning Inventories in the EntityVillager.class and found out these method links the custom inventory: public boolean func_175556_cs() { for (int i = 0; i < this.gear.getSizeInventory(); ++i) { ItemStack itemstack = this.gear.getStackInSlot(i); if (itemstack != null && (itemstack.getItem() == Items.wheat_seeds || itemstack.getItem() == Items.potato || itemstack.getItem() == Items.carrot)) { return true; } } return false; } protected void func_175445_a(EntityItem p_175445_1_) { ItemStack itemstack = p_175445_1_.getEntityItem(); Item item = itemstack.getItem(); if (this.func_175558_a(item)) { ItemStack itemstack1 = this.gear.func_174894_a(itemstack); if (itemstack1 == null) { p_175445_1_.setDead(); } else { itemstack.stackSize = itemstack1.stackSize; } } } private boolean func_175558_a(Item p_175558_1_) { return p_175558_1_ == Items.bread || p_175558_1_ == Items.potato || p_175558_1_ == Items.carrot || p_175558_1_ == Items.wheat || p_175558_1_ == Items.wheat_seeds; } public InventoryBasic func_175551_co() { return this.gear; } Cheers
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.