Jump to content

[1.7.10] Getting ItemStack from Slot.


SSslimer

Recommended Posts

Hey,

I have made entity with own inventory, it can store armor items.

Problem is when I am trying to get an ItemStack from Slot in armor render class.

 

Code in render class. That method returns itemstack from slot for armor.

ItemStack itemstack = villager.inventory.armorItemInSlot(3 - par2);

 

The villager isnt null and when I am trying to use the same method but from entity class I get an item.

But in this code it returns always null.

It should work but it doesnt. So here is my question for help.

Link to comment
Share on other sites

Hey,

I have made entity with own inventory, it can store armor items.

Problem is when I am trying to get an ItemStack from Slot in armor render class.

 

Code in render class. That method returns itemstack from slot for armor.

ItemStack itemstack = villager.inventory.armorItemInSlot(3 - par2);

 

The villager isnt null and when I am trying to use the same method but from entity class I get an item.

But in this code it returns always null.

It should work but it doesnt. So here is my question for help.

 

A better method might be to use a setter in your render class and call it from your entity class.

I have no idea what I'm doing.

Link to comment
Share on other sites

Please help me, I am working on this inventory for a long time and I want to finish it as fast as I can.

I am not sure what is wrong. I was considering NBT loading, but I dont have a knowledge how to do that.

Maybe packets, some special method or I made an error somewhere?

Link to comment
Share on other sites

It is a bit messy.

 

package BetterWorld.mobs;

public class EntityBetterVillager extends EntityAgeable implements INpc, IRangedAttackMob, IMob
{
    private int randomTickDivider;
    private boolean isMating;
    private boolean isPlaying;
    private boolean isLookingForHome;    
    private int tick;
    private String firstName;
    private String secondName;
    public String villageName;
    private int age;    
    private boolean canPickUpItems;
    
    public BetterVillage nearestVillager;
    public BetterVillage homevillage;
    public EntityPlayer boss;
    public ItemStack itemwlapie;
    public InventoryVillager inventory = new InventoryVillager(this, "Villager Inventory", false);
    
    public final EntityBetterAITasks bettertasks;
    public final EntityBetterAITasks bettertargetTasks;
    private EntityAIArrowAttack aiArrowAttack = new EntityAIArrowAttack(this, 0.6D, 20, 60, 15.0F);
    private EntityAIAttackOnCollide aiAttackOnCollide = new EntityAIAttackOnCollide(this, EntityZombie.class, 0.6D, true);
    
    private String[] firstnames = new String[] {"a", "b", "c"};
    private String[] secondnames = new String[] {"a", "b", "c"};
    

    public EntityBetterVillager(World par1World)
    {
        this(par1World, 0);       
    }

    public EntityBetterVillager(World par1World, int par2)
    {
        super(par1World);       
        this.setSize(0.6F, 1.8F);
        this.experienceValue = 5;
        this.setProfession(par2);               
        
        this.bettertasks = new EntityBetterAITasks(par1World != null && par1World.theProfiler != null ? par1World.theProfiler : null);
        this.bettertargetTasks = new EntityBetterAITasks(par1World != null && par1World.theProfiler != null ? par1World.theProfiler : null);


        this.getNavigator().setBreakDoors(true);
        this.getNavigator().setAvoidsWater(true);
        
        this.tasks.addTask(0, new EntityAISwimming(this));       
        this.tasks.addTask(1, new EntityAIAttackOnCollide(this, 0.6D, true));
        this.tasks.addTask(2, new EntityAIMoveIndoors(this));
        this.bettertasks.addTask(3, new EntityBetterAIRestrictOpenDoor(this));
        this.bettertasks.addTask(4, new EntityBetterAIOpenDoor(this, true));
        this.tasks.addTask(5, new EntityAIMoveTowardsTarget(this, 0.6D, 32.0F));
        this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 0.6D));
        this.tasks.addTask(6, new EntityAIFollowGolem(this));
        this.tasks.addTask(7, new EntityAIPlay(this, 0.32D));
        this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 3.0F, 1.0F));
        this.tasks.addTask(8, new EntityAIWatchClosest2(this, EntityBetterVillager.class, 5.0F, 0.02F));
        
        this.tasks.addTask(9, new EntityAIAvoidEntity(this, EntityZombie.class, 8.0F, 0.6D, 0.6D));
        this.tasks.addTask(6, new EntityAIVillagerMate(this));
        this.tasks.addTask(9, new EntityAIWander(this, 0.6D));
        
        this.targetTasks.addTask(2, new EntityAIHurtByTarget(this, false));
        this.bettertargetTasks.addTask(3, new EntityAINearestAttackableVillager(this, EntityBetterVillager.class, 0, true, true));
    }

    protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();	
        this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(50.0D);
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5D);
    }

    public boolean isAIEnabled()
    {
        return true;
    }
    
    public void onLivingUpdate()
    { 	
    	tick++;
    	if(this.firstName == null)this.setFirstName();
    	if(this.secondName == null)this.setRandomSecondName();
    	
    	
    	if(tick % 8766000 == 0)
    	{
    		this.age++;
    		tick = 0;
    	}
    	if(tick % 20 == 0)
    	{
    		//System.out.println(inventory.armorItemInSlot(3));
    		if(this.getProfession() == 5)this.setCombatTask();
    		if(this.villageName == null)this.setHomeVillage();
    	}
    	 	
    	if(!this.isChild())
    	{   		
    		this.setCanPickUpItems(true);
    	}else	this.setCanPickUpItems(false);
    	
        this.bettertargetTasks.onUpdateTasks();
        this.bettertasks.onUpdateTasks();
        this.updateArmSwingProgress();
        
        if (!this.worldObj.isRemote && !this.dead && this.canPickUpItems() == true){
            List list = this.worldObj.getEntitiesWithinAABB(EntityItem.class, this.boundingBox.expand(1.0D, 0.0D, 1.0D));
            Iterator iterator = list.iterator();

            while (iterator.hasNext()){
                EntityItem entityitem = (EntityItem)iterator.next();

                if (!entityitem.isDead && entityitem.getEntityItem() != null){
                    ItemStack itemstack = entityitem.getEntityItem();
                    this.inventory.addItemStackToInventory(itemstack);
                    this.onItemPickup(entityitem, 1);
                    entityitem.setDead();                                            
                }
            }
        }              
        super.onLivingUpdate();
    }
    
    protected boolean canPickUpItems(){
    	return this.canPickUpItems;
    }
    
    protected void setCanPickUpItems(boolean par1){
    	this.canPickUpItems = par1;
    }
    
    protected Entity findPlayerToAttack()
    {
        EntityPlayer entityplayer = this.worldObj.getClosestVulnerablePlayerToEntity(this, 16.0D);
        return entityplayer != null && this.canEntityBeSeen(entityplayer) ? entityplayer : null;
    }
    
    public boolean canAttackClass(Class p_70686_1_)
    {
    	Entity entity = this.entityToAttack;
        return ((this.villageName != null) && (entity != null) && (entity instanceof EntityBetterVillager) && (this.villageName != ((EntityBetterVillager) entity).villageName) && EntityBetterVillager.class.isAssignableFrom(p_70686_1_)) ? false : super.canAttackClass(p_70686_1_);
    }
    
    public boolean attackEntityFrom(DamageSource par1DamageSource, float par2)
    {
        if (this.isEntityInvulnerable())
        {
            return false;
        }
        else if (super.attackEntityFrom(par1DamageSource, par2))
        {
            Entity entity = par1DamageSource.getEntity();

            if (this.riddenByEntity != entity && this.ridingEntity != entity)
            {
                if (entity != this)
                {
                    this.entityToAttack = entity;
                }

                return true;
            }
            else
            {
                return true;
            }
        }
        else
        {
            return false;
        }
    }
    
    public boolean attackEntityAsMob(Entity par1Entity)
    {
        float f = (float) 1.0D;
        int i = 0;

        if (par1Entity instanceof EntityLivingBase)
        {
            f += EnchantmentHelper.getEnchantmentModifierLiving(this, (EntityLivingBase)par1Entity);
            i += EnchantmentHelper.getKnockbackModifier(this, (EntityLivingBase)par1Entity);
        }

        boolean flag = par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), f);

        if (flag)
        {
            if (i > 0)
            {
                par1Entity.addVelocity((double)(-MathHelper.sin(this.rotationYaw * (float)Math.PI / 180.0F) * (float)i * 0.5F), 0.1D, (double)(MathHelper.cos(this.rotationYaw * (float)Math.PI / 180.0F) * (float)i * 0.5F));
                this.motionX *= 0.6D;
                this.motionZ *= 0.6D;
            }

            int j = EnchantmentHelper.getFireAspectModifier(this);

            if (j > 0)
            {
                par1Entity.setFire(j * 4);
            }

            if (par1Entity instanceof EntityLivingBase)
            {
                EnchantmentHelper.func_151384_a((EntityLivingBase)par1Entity, this);
            }

            EnchantmentHelper.func_151385_b(this, par1Entity);
        }

        return flag;
    }
    
    protected void attackEntity(Entity par1Entity, float par2)
    {
        if (this.attackTime <= 0 && par2 < 2.0F && par1Entity.boundingBox.maxY > this.boundingBox.minY && par1Entity.boundingBox.minY < this.boundingBox.maxY)
        {
            this.attackTime = 20;
            this.attackEntityAsMob(par1Entity);
        }
    }

    protected void updateAITick()
    {
        if (--this.randomTickDivider <= 0)
        {
        	BetterVillageCollection vlgc = WorldHandler.villageCollectionObj; 
            vlgc.addVillagerPosition(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ));
            this.randomTickDivider = 70 + this.rand.nextInt(50);           
            this.nearestVillager = vlgc.findNearestVillage(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ), 32);


            
            if (this.nearestVillager == null)
            {
                this.detachHome();
            }
            else
            {
                ChunkCoordinates chunkcoordinates = this.nearestVillager.getCenter();
                this.setHomeArea(chunkcoordinates.posX, chunkcoordinates.posY, chunkcoordinates.posZ, (int)((float)this.nearestVillager.getVillageRadius() * 0.6F));

                if (this.isLookingForHome)
                {
                    this.isLookingForHome = false;
                    this.nearestVillager.setDefaultPlayerReputation(5);
                }
            }
        }
        super.updateAITick();
    }

    public boolean interact(EntityPlayer player)
    {
    Minecraft mc = FMLClientHandler.instance().getClient();
        if(mc == null || mc.thePlayer == null)return false;
        
        ItemStack itemstack = player.inventory.getCurrentItem();
        boolean flag = itemstack != null && itemstack.getItem() == Items.spawn_egg;
        int x = MathHelper.floor_double(posX);
        int y = MathHelper.floor_double(posY);
        int z = MathHelper.floor_double(posZ);
        
        if (this.isEntityAlive() && !this.isChild() && !player.isSneaking())
        {                
            mc.displayGuiScreen(new GuiVillager(this, player));
            return true;
        }
        else
        {
            return super.interact(player);
        }
    }

    protected void entityInit()
    {
        super.entityInit();
        this.dataWatcher.addObject(16, Integer.valueOf(0));
    }

    public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
    {
    	
        super.writeEntityToNBT(par1NBTTagCompound);
        par1NBTTagCompound.setInteger("Profession", this.getProfession());       
        if(this.firstName != null)par1NBTTagCompound.setString("FirstName", this.firstName);
        if(this.secondName != null)par1NBTTagCompound.setString("SecondName", this.secondName);
        if(this.villageName !=null)par1NBTTagCompound.setString("VillageName", this.villageName);
        par1NBTTagCompound.setInteger("Age", this.age);               
        par1NBTTagCompound.setTag("Inventory", this.inventory.writeToNBT(new NBTTagList()));        
    }

    public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.readEntityFromNBT(par1NBTTagCompound);
        this.setProfession(par1NBTTagCompound.getInteger("Profession"));
        this.age = par1NBTTagCompound.getInteger("Age");
        this.firstName = par1NBTTagCompound.getString("FirstName");
        this.secondName = par1NBTTagCompound.getString("SecondName");              
        this.villageName = par1NBTTagCompound.getString("VillageName");
        
        NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Inventory", 10);
        this.inventory.readFromNBT(nbttaglist);
    }

    protected boolean canDespawn(){
        return false;
    }

    protected String getLivingSound(){
        return "mob.villager.idle";
    }

    protected String getHurtSound(){
        return "mob.villager.hit";
    }

    protected String getDeathSound(){
        return "mob.villager.death";
    }

    public void setProfession(int par1){
        this.dataWatcher.updateObject(16, Integer.valueOf(par1));
    }
    
    public int getProfession(){
        return this.dataWatcher.getWatchableObjectInt(16);
    }

    public boolean isMating(){
        return this.isMating;
    }

    public void setMating(boolean par1){
        this.isMating = par1;
    }

    public void setPlaying(boolean par1){
            this.isPlaying = par1;
    }

    public boolean isPlaying(){
        return this.isPlaying;
    }
    
    public void setFirstName(){
    	this.firstName = this.firstnames[this.rand.nextInt(this.firstnames.length)];
    }
    
    public void setRandomSecondName(){
    	this.secondName = this.secondnames[this.rand.nextInt(this.secondnames.length)];
    }
    
    public void setSecondName(String par1){
    	this.secondName = par1;
    }
    
    public String getFirstName(){
    	return this.firstName;
    }
    
    public String getSecondName(){
    	return this.secondName;
    }
    
    public int getAge(){
    	return this.age;
    }
    
    public String getHomeName(){
    	if(this.villageName != null)
    	{
    		return this.villageName;  
    	}
    	return null;  	
    }
    
    public void setHomeVillage(){
    	VillageInfo info = VillageInfo.build();    	    
    	if(info !=null && info.getNearestVillage() != null)
    	{
    		this.villageName = info.getNearestVillage().getName();       
    	}
    }    

    public void setRevengeTarget(EntityLivingBase par1EntityLivingBase)
    {
        super.setRevengeTarget(par1EntityLivingBase);

        if (this.nearestVillager != null && par1EntityLivingBase != null)
        {
            this.nearestVillager.addOrRenewAgressor(par1EntityLivingBase);

            if (par1EntityLivingBase instanceof EntityPlayer)
            {
                byte b0 = -1;

                if (this.isChild())
                {
                    b0 = -3;
                }

                this.nearestVillager.setReputationForPlayer(par1EntityLivingBase.getCommandSenderName(), b0);

                if (this.isEntityAlive())
                {
                    this.worldObj.setEntityState(this, (byte)13);
                }
            }
        }
    }

    public void onDeath(DamageSource par1DamageSource)
    {        
        if (this.nearestVillager != null)
        {
            Entity entity = par1DamageSource.getEntity();

            if (entity != null)
            {
                if (entity instanceof EntityPlayer)
                {
                    this.nearestVillager.setReputationForPlayer(entity.getCommandSenderName(), -2);
                }
                else if (entity instanceof IMob)
                {
                    this.nearestVillager.endMatingSeason();
                }
            }else if (entity == null)
            {
                EntityPlayer entityplayer = this.worldObj.getClosestPlayerToEntity(this, 16.0D);

                if (entityplayer != null)
                {
                    this.nearestVillager.endMatingSeason();
                }
            }
        }           
        
        if (inventory != null && !this.worldObj.isRemote)
        {
        	for (int i = 0; i < inventory.getSizeInventory(); ++i)
        	{
        		ItemStack itemstack = inventory.getStackInSlot(i);

        		if (itemstack != null)
        		{
        			this.entityDropItem(itemstack, 0.0F);
        		}
        	}
        }        
        super.onDeath(par1DamageSource);
    }

    @SideOnly(Side.CLIENT)
    public void handleHealthUpdate(byte par1)
    {
        if (par1 == 12)
        {
            this.generateRandomParticles("heart");
        }
        else if (par1 == 13)
        {
            this.generateRandomParticles("angryVillager");
        }
        else if (par1 == 14)
        {
            this.generateRandomParticles("happyVillager");
        }
        else
        {
            super.handleHealthUpdate(par1);
        }
    }

    public IEntityLivingData onSpawnWithEgg(IEntityLivingData par1EntityLivingData)
    {
        par1EntityLivingData = super.onSpawnWithEgg(par1EntityLivingData);
        this.setFirstName(); 
        this.setRandomSecondName();
        this.setHomeVillage();
        return par1EntityLivingData;
    }

    @SideOnly(Side.CLIENT)
    private void generateRandomParticles(String par1Str)
    {
        for (int i = 0; i < 5; ++i)
        {
            double d0 = this.rand.nextGaussian() * 0.02D;
            double d1 = this.rand.nextGaussian() * 0.02D;
            double d2 = this.rand.nextGaussian() * 0.02D;
            this.worldObj.spawnParticle(par1Str, this.posX + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, this.posY + 1.0D + (double)(this.rand.nextFloat() * this.height), this.posZ + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, d0, d1, d2);
        }
    }

    public void setLookingForHome()
    {
        this.isLookingForHome = true;
    }

    public EntityBetterVillager createChild(EntityAgeable par1EntityAgeable)
    {
        EntityBetterVillager entityvillager = new EntityBetterVillager(this.worldObj);
        entityvillager.onSpawnWithEgg((IEntityLivingData)null);
        entityvillager.setFirstName();
        entityvillager.setSecondName(this.secondName);
        entityvillager.setHomeVillage();
        return entityvillager;
    }
    
    public boolean allowLeashing()
    {
        return false;
    }
    
    @Override
public void attackEntityWithRangedAttack(EntityLivingBase par1EntityLivingBase, float par2)
{	
	ItemStack itemstack = this.inventory.getStackInSlot(0);

	if (itemstack != null && itemstack.getItem() == Items.bow)
	{				
        EntityArrow entityarrow = new EntityArrow(this.worldObj, this, par1EntityLivingBase, 1.6F, (float)(14 - this.worldObj.difficultySetting.getDifficultyId() * 4));
        int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem());
        int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem());
        
        entityarrow.setDamage(4.5D);
        
        if (i > 0)entityarrow.setDamage(entityarrow.getDamage() + (double)i * 0.5D + 0.5D);	
        if (j > 0)entityarrow.setKnockbackStrength(j);
        
        this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
        this.worldObj.spawnEntityInWorld(entityarrow);
	}		
	else if (itemstack != null && itemstack.getItem() == ModBetterWorld.LongBow)
	{				
        EntityArrow entityarrow = new EntityArrow(this.worldObj, this, par1EntityLivingBase, 1.6F, (float)(14 - this.worldObj.difficultySetting.getDifficultyId() * 4));
        int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem());
        int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem());
        
        entityarrow.setDamage(6.0D);
        
        if (i > 0)entityarrow.setDamage(entityarrow.getDamage() + (double)i * 0.5D + 0.5D);
        if (j > 0)entityarrow.setKnockbackStrength(j);
        
        this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
        this.worldObj.spawnEntityInWorld(entityarrow);
	}
	else if (itemstack != null && itemstack.getItem() == ModBetterWorld.Crossbow)
	{				
		//na koncu jest jaki rozrzut na boki przy strzale
        EntityBolt entityarrow = new EntityBolt(this.worldObj, this, par1EntityLivingBase, 1.3F, (float)(14 - this.worldObj.difficultySetting.getDifficultyId() * 4));
        int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem());
        int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem());
        
        entityarrow.setDamage(7.5D);
        
        if (i > 0)entityarrow.setDamage(entityarrow.getDamage() + (double)i * 0.5D + 0.5D);	
        if (j > 0)entityarrow.setKnockbackStrength(j);
        
        this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
        this.worldObj.spawnEntityInWorld(entityarrow);
	}
}  

    public void setCombatTask()
    {   	
        ItemStack itemstack = this.getHeldItem();
        
        this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityZombie.class, 0, true, true));
        this.tasks.addTask(7, new EntityAIWatchClosest(this, EntityZombie.class, 64.0F));	            
        
        this.tasks.removeTask(new EntityAIAvoidEntity(this, EntityZombie.class, 8.0F, 0.6D, 0.6D));     
        
        if (itemstack != null && itemstack.getItem() == Items.bow)
        {       	
            this.tasks.addTask(4, this.aiArrowAttack);
            this.tasks.removeTask(this.aiAttackOnCollide);
        }
        else if(itemstack != null && itemstack.getItem() == ModBetterWorld.LongBow)
        {
            this.tasks.addTask(4, this.aiArrowAttack);
            this.tasks.removeTask(this.aiAttackOnCollide);
        }
        else if(itemstack != null && itemstack.getItem() == ModBetterWorld.Crossbow)
        {       	
            this.tasks.addTask(4, this.aiArrowAttack);    
            this.tasks.removeTask(this.aiAttackOnCollide);
        }
        else
        {
        	this.tasks.addTask(4, this.aiAttackOnCollide);
        	this.tasks.removeTask(this.aiArrowAttack);        
        }
    }
    
    public boolean func_142018_a(EntityLivingBase par1EntityLivingBase, EntityLivingBase par2EntityLivingBase)
    {
        return true;
    }

public EntityPlayer getBoss()
{
	return this.boss;
}

public void setBoss(EntityPlayer player)
{
	this.boss = player;
}
}

Link to comment
Share on other sites

As I said my entity code is messy.

Better tasks is my first step to make an orders and tasks system. This system is in second pos. of my plans after finishing inventory.

PersistenceRequired deleted - useless.

I am not sure when to use @Override. Sometimes I add this but when I know that it is needed.

WorldHandler.villageCollectionObj what is wrong with it?

Interact method, open gui by gui handler but why? Now it works fine.

 

By the way, thanks for help, I have learnt lot by fixing errors since my first contact with java.

 

 

Link to comment
Share on other sites

Some code edited in previous post.

I should have changed betterai to sth else. It wont be an ai but system of tasks. In ai system there are some issues that I dont like. Dont ask what and why.

@Override, ok I must read on forums how to properly use it. Ok now I think I know how to use it, I am not planing any other entities implementing my villager so I dont need to Override methods??

I will try to fix gui opening and villages handling.

My 17 holidays stared so I have a time to fix and add what I want :)

 

Link to comment
Share on other sites

GUI should be opened by displaying gui screen only if the gui to open we are opening from another gui??

I changed few guis to open from gui handler. Now I am trying to senda packet on client side to open gui which opens by interaction with villager.

Should I use method from SimpleNetworkWrapper sendTo or other? If sendTo what I need to change to make player  as a EntityPlayerMP?

Link to comment
Share on other sites

In interact method:

player.openGui(ModBetterWorld.instance, 4, world, this.getEntityId(), y, z);

In gui handler:

		        case 4:
			Entity villager = world.getEntityByID(x);
			if(villager!=null && villager instanceof EntityBetterVillager)
			{
				return new GuiVillager((EntityBetterVillager) villager, player);
			}

Works fine, now can it crash? So I can use show gui screen only in other guis when I want to open gui??

 

Link to comment
Share on other sites

Here is WordHandler class:

package BetterWorld;

public class WorldHandler
{
public WorldHandler() {}

public static BetterVillageCollection villageCollectionObj;

@SubscribeEvent
public void worldMethod(WorldEvent event) 
{	    
	BetterVillageCollection villagecollection = (BetterVillageCollection)event.world.perWorldStorage.loadData(BetterVillageCollection.class, "bettervillages"); 
        
	if (villagecollection == null)
	{
		this.villageCollectionObj = new BetterVillageCollection(event.world);
		event.world.perWorldStorage.setData("bettervillages", this.villageCollectionObj);
	}
	else
	{
		this.villageCollectionObj = villagecollection;		
		this.villageCollectionObj.func_82566_a(event.world);           
	}			
}
}

 

Inwentory works fine, items in slots can be saved and loaded.

When I try to get an itemstack to render armor and item in hand method returns always null.

ItemStack itemstack = villager.inventory.armorItemInSlot(3 - par2);

villager is correct(I can get its pos.)method for getting item is correct too. I think that inventory returns null so method after too.

Method works because it returns item when I use it in entity class.

 

 

Link to comment
Share on other sites

Hm ok, I need to change those class.

I found sth wired.

After changing profession system of villager. When I try to print int of prof. I see 0 and the prof. number.

I add that prof. can be changed in gui. Texture works fine and in villager info correct prof. shows.

After next word opening prof. turns to 0, despite NBT data laoding and saving.

Link to comment
Share on other sites

Method:

System.out.println(this.inventory.armorItemInSlot(1));

In entity class returns itemstack.

Method:

System.out.println(villager.inventory.armorItemInSlot(1));

In render class returns null.

I know that entity is correct, because I can get entity with armor in this code.

System.out.println(villager);

Link to comment
Share on other sites

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Man, I fcuked up my own URL tags by including the second link! xD

 

Haha.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

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