Jump to content

1.8 get player mob kills


alexschopbarteld

Recommended Posts

A quick question, in my armor class i want

@Override

public boolean isValidArmor(ItemStack stack, int armorType, Entity entity) {

 

if([mobkills] > 10.0) {

return true;

}

 

else {

return false;

}

}

 

to return true if the player has killed more then 10 mobs, it needs to return false if the player hasnt killed 10 mobs, how do i code this?

Link to comment
Share on other sites

You need to store the mob-kills.

I recommend you store them in a

Capability

, and attach it to EntityPlayer, and then all you need to do is retrieve the Capability from the player that tries to wear this armour, and get their mob-kill count.

(Remember, mobs can also wear armour, so always check what is trying to wear the armour!)

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

 

package Capability;

 

public interface IDefence

{

    public void consume(float points);

 

    public void fill(float points);

 

    public void set(float points);

 

    public float getDefence();

 

}

 

 

 

package Capability;

 

import com.sun.glass.ui.View.Capability;

 

import net.minecraft.nbt.NBTBase;

import net.minecraft.nbt.NBTTagFloat;

import net.minecraft.util.EnumFacing;

 

public class DefenceStorage implements IDefence

{

    public NBTBase writeNBT(Capability capability, IDefence instance, EnumFacing side)

    {

        return new NBTTagFloat(instance.getDefence());

    }

 

    public void readNBT(Capability capability, IDefence instance, EnumFacing side, NBTBase nbt)

    {

        instance.set(((NBTTagFloat) nbt).getFloat());

    }

 

@Override

public void consume(float points) {

// TODO Auto-generated method stub

 

}

 

@Override

public void fill(float points) {

// TODO Auto-generated method stub

 

}

 

@Override

public void set(float points) {

// TODO Auto-generated method stub

 

}

 

 

@Override

public float getDefence() {

// TODO Auto-generated method stub

return 0;

}

}

 

 

 

package Capability;

 

public class Defence implements IDefence

{

    public static final String INSTANCE = null;

private float Defence = 0.0F;

 

    @Override

    public void consume(float points)

    {

        this.Defence -= points;

 

        if (this.Defence < 0.0F) this.Defence = 0.0F;

    }

 

    @Override

    public void fill(float points)

    {

        this.Defence += points;

    }

 

    @Override

    public void set(float points)

    {

        this.Defence = points;

    }

 

    @Override

    public float getDefence()

    {

        return this.Defence;

    }

 

}

 

 

 

 

package Capability;

 

import com.runecraft.Runecraft;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

 

public class CapabilityHandler

{

    private static final String CapabilitiesTest = null;

public static final ResourceLocation DEFENCE_CAP = new ResourceLocation(Runecraft.MODID, "Defence");

}

 

 

 

 

this is what the internet told me to make, hope it is correct.

Link to comment
Share on other sites

I have a Capability created but i cant find a way to use it in the if statement and add values to it when a player kills a mob.

 

Pseudo-code

if(entity instanceof EntityPlayer){
	IYourCapability capability = entity.getCapability(YourCapabilityProvider.INSTANCE, null);

	int mobKills = capability.getMobKills();
}

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

 

package Capability;

 

public interface IDefence

{

    public void consume(float points);

 

    public void fill(float points);

 

    public void set(float points);

 

    public float getDefence();

 

}

 

 

 

package Capability;

 

import com.sun.glass.ui.View.Capability;

 

import net.minecraft.nbt.NBTBase;

import net.minecraft.nbt.NBTTagFloat;

import net.minecraft.util.EnumFacing;

 

public class DefenceStorage implements IDefence

{

    public NBTBase writeNBT(Capability capability, IDefence instance, EnumFacing side)

    {

        return new NBTTagFloat(instance.getDefence());

    }

 

    public void readNBT(Capability capability, IDefence instance, EnumFacing side, NBTBase nbt)

    {

        instance.set(((NBTTagFloat) nbt).getFloat());

    }

 

@Override

public void consume(float points) {

// TODO Auto-generated method stub

 

}

 

@Override

public void fill(float points) {

// TODO Auto-generated method stub

 

}

 

@Override

public void set(float points) {

// TODO Auto-generated method stub

 

}

 

 

@Override

public float getDefence() {

// TODO Auto-generated method stub

return 0;

}

}

 

 

 

package Capability;

 

public class Defence implements IDefence

{

    public static final String INSTANCE = null;

private float Defence = 0.0F;

 

    @Override

    public void consume(float points)

    {

        this.Defence -= points;

 

        if (this.Defence < 0.0F) this.Defence = 0.0F;

    }

 

    @Override

    public void fill(float points)

    {

        this.Defence += points;

    }

 

    @Override

    public void set(float points)

    {

        this.Defence = points;

    }

 

    @Override

    public float getDefence()

    {

        return this.Defence;

    }

 

}

 

 

 

 

package Capability;

 

import com.runecraft.Runecraft;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

 

public class CapabilityHandler

{

    private static final String CapabilitiesTest = null;

public static final ResourceLocation DEFENCE_CAP = new ResourceLocation(Runecraft.MODID, "Defence");

}

 

 

 

 

this is what the internet told me to make, hope it is correct.

that is not a forge Capability

this is a forge Capability https://github.com/MinecraftForge/MinecraftForge/blob/17db34ae31f281221b661b72b6831880ce31116b/src/test/java/net/minecraftforge/test/TestCapabilityMod.java

and update to 1.10.2

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.