Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

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.

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

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.

 

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.