Posted November 2, 20169 yr 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?
November 2, 20169 yr 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.
November 2, 20169 yr Author 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.
November 2, 20169 yr Author 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.
November 2, 20169 yr 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.
November 2, 20169 yr 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
November 3, 20169 yr Author In the github it references to IExampleCapability and capabilitymanager, what is supposed to be in that class?
November 3, 20169 yr forgot to link this http://mcforge.readthedocs.io/en/latest/datastorage/capabilities/ hope this helps
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.