Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10] Getting ItemStack from Slot.


SSslimer
 Share

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

Why do you have those "better" AI tasks? What's "better" about them? Why can't you use the normal AI tasks?

 

Why do you have the persistenceRequired stuff in there? that is handled by the Entity class just fine.

 

Why are your parameters not named properly? Why do you not use @Override where appropriate?

 

Why is WorldHandler.villageCollectionObj? That is a bad idea!

 

Your interact method is completely broken. You cannot use the Minecraft class in common code like an Entity. Use a GuiHandler.

 

Fix all of that. Then come back.

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

As I said my entity code is messy.

You saying that does not help. You need to fix it.

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.
That did not answer my question.

I am not sure when to use @Override. Sometimes I add this but when I know that it is needed.
@Override does not change how your code executes, it is just a helper. Put it on a method when you intend to override with it. Then your IDE will issue an error when you don't actually override anything.

WorldHandler.villageCollectionObj what is wrong with it?
If you know what static means, you will know what is wrong with that. Remember: there is not one world. There are many.

Interact method, open gui by gui handler but why? Now it works fine.
Put your mod on a dedicated server. Try to use your mod with a LAN world with multiple people. Happy crashing.
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

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

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Ah, I see that world capabilities are per level. That complicates things. I guess I will need capabilities for every level. That actually removes the need to serialize/deserialize the level.
    • I decided to also implement #2 for learning purposes. How do I serialize the level then get it back at runtime? I know there is something called dimension ID, but I don't know how to use it.
    • What you posted looks like the latest.log, not debug.log. It also does not show any error, but a successful join of a single player world. Please answer this question.
    • [29Nov2021 13:35:13.629] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, Alsefri1423, --version, 1.17.1-forge-37.0.126, --gameDir, C:\Users\Gaming\AppData\Roaming\.minecraft, --assetsDir, C:\Users\Gaming\AppData\Roaming\.minecraft\assets, --assetIndex, 1.17, --uuid, a889dee5cd184fe7b91ede11d2acd85f, --accessToken, ????????, --userType, msa, --versionType, release, --launchTarget, forgeclient, --fml.forgeVersion, 37.0.126, --fml.mcVersion, 1.17.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20210706.113038] [29Nov2021 13:35:13.633] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 9.0.7+91+master.8569cdf starting: java version 16.0.1 by Microsoft [29Nov2021 13:35:13.746] [main/INFO] [mixin/]: SpongePowered MIXIN Subsystem Version=0.8.4 Source=union:/C:/Users/Gaming/AppData/Roaming/.minecraft/libraries/org/spongepowered/mixin/0.8.4/mixin-0.8.4.jar%2318! Service=ModLauncher Env=CLIENT [29Nov2021 13:35:15.296] [main/INFO] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Launching target 'forgeclient' with arguments [--version, 1.17.1-forge-37.0.126, --gameDir, C:\Users\Gaming\AppData\Roaming\.minecraft, --assetsDir, C:\Users\Gaming\AppData\Roaming\.minecraft\assets, --uuid, a889dee5cd184fe7b91ede11d2acd85f, --username, Alsefri1423, --assetIndex, 1.17, --accessToken, ????????, --userType, msa, --versionType, release] [13:35:21] [Render thread/WARN]: Assets URL 'union:/C:/Users/Gaming/AppData/Roaming/.minecraft/libraries/net/minecraft/client/1.17.1-20210706.113038/client-1.17.1-20210706.113038-srg.jar%2353!/assets/.mcassetsroot' uses unexpected schema [13:35:21] [Render thread/WARN]: Assets URL 'union:/C:/Users/Gaming/AppData/Roaming/.minecraft/libraries/net/minecraft/client/1.17.1-20210706.113038/client-1.17.1-20210706.113038-srg.jar%2353!/data/.mcassetsroot' uses unexpected schema [29Nov2021 13:35:21.370] [Render thread/INFO] [com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService/]: Environment: authHost='https://authserver.mojang.com', accountsHost='https://api.mojang.com', sessionHost='https://sessionserver.mojang.com', servicesHost='https://api.minecraftservices.com', name='PROD' [13:35:22] [Render thread/INFO]: Setting user: Alsefri1423 [13:35:22] [Render thread/INFO]: Backend library: LWJGL version 3.2.2 SNAPSHOT [13:35:24] [modloading-worker-2/INFO]: Forge mod loading, version 37.0.126, for MC 1.17.1 with MCP 20210706.113038 [13:35:24] [modloading-worker-2/INFO]: MinecraftForge v37.0.126 Initialized [13:35:24] [Render thread/WARN]: Removed resource pack Fabric Mods from options because it doesn't seem to exist anymore [29Nov2021 13:35:26.011] [Render thread/INFO] [com.mojang.text2speech.NarratorWindows/]: Narrator library for x64 successfully loaded [13:35:26] [Render thread/INFO]: Reloading ResourceManager: Default, Mod Resources [13:35:26] [modloading-worker-2/WARN]: Configuration file C:\Users\Gaming\AppData\Roaming\.minecraft\config\forge-client.toml is not correct. Correcting [13:35:26] [modloading-worker-2/WARN]: Incorrect key client.forceSystemNanoTime was corrected from null to its default, false.  [13:35:26] [modloading-worker-2/WARN]: Incorrect key client.disableStairSlabCulling was corrected from false to its default, null.  [13:35:26] [modloading-worker-2/WARN]: Incorrect key client.zoomInMissingModelTextInGui was corrected from false to its default, null.  [13:35:26] [modloading-worker-2/WARN]: Incorrect key client.forgeLightPipelineEnabled was corrected from true to its default, null.  [13:35:26] [modloading-worker-2/WARN]: Incorrect key client.forgeCloudsEnabled was corrected from true to its default, null.  [29Nov2021 13:35:26.669] [Forge Version Check/INFO] [net.minecraftforge.fml.VersionChecker/]: [forge] Starting version check at https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json [13:35:38] [Render thread/INFO]: OpenAL initialized. [13:35:38] [Render thread/INFO]: Sound engine started [13:35:38] [Render thread/INFO]: Created: 1024x512x4 minecraft:textures/atlas/blocks.png-atlas [13:35:38] [Render thread/INFO]: Created: 256x128x4 minecraft:textures/atlas/signs.png-atlas [13:35:38] [Render thread/INFO]: Created: 512x512x4 minecraft:textures/atlas/banner_patterns.png-atlas [13:35:38] [Render thread/INFO]: Created: 512x512x4 minecraft:textures/atlas/shield_patterns.png-atlas [13:35:38] [Render thread/INFO]: Created: 256x256x4 minecraft:textures/atlas/chest.png-atlas [13:35:38] [Render thread/INFO]: Created: 512x256x4 minecraft:textures/atlas/beds.png-atlas [13:35:38] [Render thread/INFO]: Created: 512x256x4 minecraft:textures/atlas/shulker_boxes.png-atlas [29Nov2021 13:35:38.817] [Forge Version Check/INFO] [net.minecraftforge.fml.VersionChecker/]: [forge] Found status: BETA Current: 37.0.126 Target: 37.0.126 [13:35:40] [Render thread/INFO]: Created: 256x256x0 minecraft:textures/atlas/particles.png-atlas [13:35:40] [Render thread/INFO]: Created: 256x256x0 minecraft:textures/atlas/paintings.png-atlas [13:35:40] [Render thread/INFO]: Created: 128x128x0 minecraft:textures/atlas/mob_effects.png-atlas [13:35:51] [Render thread/WARN]: Ambiguity between arguments [teleport, location] and [teleport, destination] with inputs: [0.1 -0.5 .9, 0 0 0] [13:35:51] [Render thread/WARN]: Ambiguity between arguments [teleport, location] and [teleport, targets] with inputs: [0.1 -0.5 .9, 0 0 0] [13:35:51] [Render thread/WARN]: Ambiguity between arguments [teleport, destination] and [teleport, targets] with inputs: [Player, 0123, @e, dd12be42-52a9-4a91-a8a1-11c01849e498] [13:35:51] [Render thread/WARN]: Ambiguity between arguments [teleport, targets] and [teleport, destination] with inputs: [Player, 0123, dd12be42-52a9-4a91-a8a1-11c01849e498] [13:35:51] [Render thread/WARN]: Ambiguity between arguments [teleport, targets, location] and [teleport, targets, destination] with inputs: [0.1 -0.5 .9, 0 0 0] [13:35:51] [Render thread/INFO]: Reloading ResourceManager: Default, forge-1.17.1-37.0.126-universal.jar [13:35:54] [Render thread/INFO]: Loaded 7 recipes [13:35:55] [Render thread/INFO]: Loaded 1137 advancements [13:35:55] [Render thread/INFO]: Injecting existing registry data into this CLIENT instance [13:35:56] [Render thread/WARN]: Ambiguity between arguments [teleport, location] and [teleport, destination] with inputs: [0.1 -0.5 .9, 0 0 0] [13:35:56] [Render thread/WARN]: Ambiguity between arguments [teleport, location] and [teleport, targets] with inputs: [0.1 -0.5 .9, 0 0 0] [13:35:56] [Render thread/WARN]: Ambiguity between arguments [teleport, destination] and [teleport, targets] with inputs: [Player, 0123, @e, dd12be42-52a9-4a91-a8a1-11c01849e498] [13:35:56] [Render thread/WARN]: Ambiguity between arguments [teleport, targets] and [teleport, destination] with inputs: [Player, 0123, dd12be42-52a9-4a91-a8a1-11c01849e498] [13:35:56] [Render thread/WARN]: Ambiguity between arguments [teleport, targets, location] and [teleport, targets, destination] with inputs: [0.1 -0.5 .9, 0 0 0] [13:35:56] [Render thread/INFO]: Reloading ResourceManager: Default, forge-1.17.1-37.0.126-universal.jar [13:35:58] [Render thread/INFO]: Loaded 7 recipes [13:35:59] [Render thread/INFO]: Loaded 1137 advancements [13:36:00] [Render thread/INFO]: Injecting existing registry data into this CLIENT instance [29Nov2021 13:36:00.780] [Render thread/INFO] [com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService/]: Environment: authHost='https://authserver.mojang.com', accountsHost='https://api.mojang.com', sessionHost='https://sessionserver.mojang.com', servicesHost='https://api.minecraftservices.com', name='PROD' [13:36:00] [Server thread/INFO]: Starting integrated minecraft server version 1.17.1 [13:36:00] [Server thread/INFO]: Generating keypair [13:36:01] [Server thread/INFO]: Preparing start region for dimension minecraft:overworld [13:36:01] [Render thread/INFO]: Preparing spawn area: 0% [13:36:05] [Render thread/INFO]: Preparing spawn area: 0% [13:36:05] [Render thread/INFO]: Preparing spawn area: 0% [13:36:05] [Render thread/INFO]: Preparing spawn area: 0% [13:36:05] [Render thread/INFO]: Preparing spawn area: 0% [13:36:05] [Render thread/INFO]: Preparing spawn area: 0% [13:36:05] [Render thread/INFO]: Preparing spawn area: 0% [13:36:05] [Render thread/INFO]: Preparing spawn area: 0% [13:36:05] [Render thread/INFO]: Preparing spawn area: 0% [13:36:06] [Render thread/INFO]: Preparing spawn area: 56% [13:36:06] [Render thread/INFO]: Preparing spawn area: 76% [13:36:06] [Render thread/INFO]: Preparing spawn area: 88% [13:36:06] [Render thread/INFO]: Time elapsed: 5638 ms [13:36:06] [Server thread/INFO]: Changing view distance to 31, from 10 [13:36:08] [Netty Local Client IO #0/INFO]: Connected to a modded server. [13:36:08] [Server thread/INFO]: Using new advancement loading for net.minecraft.server.PlayerAdvancements@334a2b19 [13:36:08] [Server thread/INFO]: Alsefri1423[local:E:9ebcee60] logged in with entity id 113 at (-1414.803438468965, 64.0, 25.132433578510874) [13:36:08] [Server thread/INFO]: Alsefri1423 joined the game [13:36:09] [Server thread/INFO]: Saving and pausing game... [13:36:09] [Server thread/INFO]: Saving chunks for level 'ServerLevel[New World]'/minecraft:overworld [13:36:09] [Server thread/INFO]: Saving chunks for level 'ServerLevel[New World]'/minecraft:the_nether [13:36:09] [Server thread/INFO]: Saving chunks for level 'ServerLevel[New World]'/minecraft:the_end [13:36:09] [Server thread/WARN]: Can't keep up! Is the server overloaded? Running 2136ms or 42 ticks behind [13:36:10] [Render thread/INFO]: Loaded 174 advancements   My OS is Windows 10
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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