當前位置: 首頁>>代碼示例>>Java>>正文


Java AttributeModifier類代碼示例

本文整理匯總了Java中net.minecraft.entity.ai.attributes.AttributeModifier的典型用法代碼示例。如果您正苦於以下問題:Java AttributeModifier類的具體用法?Java AttributeModifier怎麽用?Java AttributeModifier使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AttributeModifier類屬於net.minecraft.entity.ai.attributes包,在下文中一共展示了AttributeModifier類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onInitialSpawn

import net.minecraft.entity.ai.attributes.AttributeModifier; //導入依賴的package包/類
/**
 * Called only once on an entity when first time spawned, via egg, mob spawner, natural spawning etc, but not called
 * when entity is reloaded from nbt. Mainly used for initializing attributes and inventory
 */
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata)
{
    this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).applyModifier(new AttributeModifier("Random spawn bonus", this.rand.nextGaussian() * 0.05D, 1));

    if (this.rand.nextFloat() < 0.05F)
    {
        this.setLeftHanded(true);
    }
    else
    {
        this.setLeftHanded(false);
    }

    return livingdata;
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:21,代碼來源:EntityLiving.java

示例2: readAttributeModifierFromNBT

import net.minecraft.entity.ai.attributes.AttributeModifier; //導入依賴的package包/類
@Nullable

    /**
     * Creates an AttributeModifier from an NBTTagCompound
     */
    public static AttributeModifier readAttributeModifierFromNBT(NBTTagCompound compound)
    {
        UUID uuid = compound.getUniqueId("UUID");

        try
        {
            return new AttributeModifier(uuid, compound.getString("Name"), compound.getDouble("Amount"), compound.getInteger("Operation"));
        }
        catch (Exception exception)
        {
            LOGGER.warn("Unable to create attribute: {}", new Object[] {exception.getMessage()});
            return null;
        }
    }
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:20,代碼來源:SharedMonsterAttributes.java

示例3: apply

import net.minecraft.entity.ai.attributes.AttributeModifier; //導入依賴的package包/類
public ItemStack apply(ItemStack stack, Random rand, LootContext context)
{
    for (SetAttributes.Modifier setattributes$modifier : this.modifiers)
    {
        UUID uuid = setattributes$modifier.uuid;

        if (uuid == null)
        {
            uuid = UUID.randomUUID();
        }

        EntityEquipmentSlot entityequipmentslot = setattributes$modifier.slots[rand.nextInt(setattributes$modifier.slots.length)];
        stack.addAttributeModifier(setattributes$modifier.attributeName, new AttributeModifier(uuid, setattributes$modifier.modifierName, (double)setattributes$modifier.amount.generateFloat(rand), setattributes$modifier.operation), entityequipmentslot);
    }

    return stack;
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:18,代碼來源:SetAttributes.java

示例4: onInitialSpawn

import net.minecraft.entity.ai.attributes.AttributeModifier; //導入依賴的package包/類
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
	livingdata = super.onInitialSpawn(difficulty, livingdata);
	float f = difficulty.getClampedAdditionalDifficulty();
	this.setCanPickUpLoot(false);
	this.setEquipmentBasedOnDifficulty(difficulty);
	this.setEnchantmentBasedOnDifficulty(difficulty);
	this.setCombatTask();

	this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).applyModifier(
			new AttributeModifier("Random spawn bonus", this.rand.nextDouble() * 0.05000000074505806D, 0));
	double d0 = this.rand.nextDouble() * 1.5D * (double) f;

	if (d0 > 1.0D) {
		this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE)
				.applyModifier(new AttributeModifier("Random zombie-spawn bonus", d0, 2));
	}

	return livingdata;
}
 
開發者ID:the-realest-stu,項目名稱:Infernum,代碼行數:21,代碼來源:EntityPigZombieMage.java

示例5: writeAttributeInstanceToNBT

import net.minecraft.entity.ai.attributes.AttributeModifier; //導入依賴的package包/類
/**
 * Creates an NBTTagCompound from an AttributeInstance, including its AttributeModifiers
 */
private static NBTTagCompound writeAttributeInstanceToNBT(IAttributeInstance p_111261_0_)
{
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    IAttribute iattribute = p_111261_0_.getAttribute();
    nbttagcompound.setString("Name", iattribute.getAttributeUnlocalizedName());
    nbttagcompound.setDouble("Base", p_111261_0_.getBaseValue());
    Collection<AttributeModifier> collection = p_111261_0_.func_111122_c();

    if (collection != null && !collection.isEmpty())
    {
        NBTTagList nbttaglist = new NBTTagList();

        for (AttributeModifier attributemodifier : collection)
        {
            if (attributemodifier.isSaved())
            {
                nbttaglist.appendTag(writeAttributeModifierToNBT(attributemodifier));
            }
        }

        nbttagcompound.setTag("Modifiers", nbttaglist);
    }

    return nbttagcompound;
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:29,代碼來源:SharedMonsterAttributes.java

示例6: writePacketData

import net.minecraft.entity.ai.attributes.AttributeModifier; //導入依賴的package包/類
/**
 * Writes the raw packet data to the data stream.
 */
public void writePacketData(PacketBuffer buf) throws IOException
{
    buf.writeVarIntToBuffer(this.entityId);
    buf.writeInt(this.field_149444_b.size());

    for (S20PacketEntityProperties.Snapshot s20packetentityproperties$snapshot : this.field_149444_b)
    {
        buf.writeString(s20packetentityproperties$snapshot.func_151409_a());
        buf.writeDouble(s20packetentityproperties$snapshot.func_151410_b());
        buf.writeVarIntToBuffer(s20packetentityproperties$snapshot.func_151408_c().size());

        for (AttributeModifier attributemodifier : s20packetentityproperties$snapshot.func_151408_c())
        {
            buf.writeUuid(attributemodifier.getID());
            buf.writeDouble(attributemodifier.getAmount());
            buf.writeByte(attributemodifier.getOperation());
        }
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:23,代碼來源:S20PacketEntityProperties.java

示例7: writeAttributeInstanceToNBT

import net.minecraft.entity.ai.attributes.AttributeModifier; //導入依賴的package包/類
/**
 * Creates an NBTTagCompound from an AttributeInstance, including its AttributeModifiers
 */
private static NBTTagCompound writeAttributeInstanceToNBT(IAttributeInstance instance)
{
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    IAttribute iattribute = instance.getAttribute();
    nbttagcompound.setString("Name", iattribute.getAttributeUnlocalizedName());
    nbttagcompound.setDouble("Base", instance.getBaseValue());
    Collection<AttributeModifier> collection = instance.getModifiers();

    if (collection != null && !collection.isEmpty())
    {
        NBTTagList nbttaglist = new NBTTagList();

        for (AttributeModifier attributemodifier : collection)
        {
            if (attributemodifier.isSaved())
            {
                nbttaglist.appendTag(writeAttributeModifierToNBT(attributemodifier));
            }
        }

        nbttagcompound.setTag("Modifiers", nbttaglist);
    }

    return nbttagcompound;
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:29,代碼來源:SharedMonsterAttributes.java

示例8: readAttributeModifierFromNBT

import net.minecraft.entity.ai.attributes.AttributeModifier; //導入依賴的package包/類
/**
 * Creates an AttributeModifier from an NBTTagCompound
 */
@Nullable
public static AttributeModifier readAttributeModifierFromNBT(NBTTagCompound compound)
{
    UUID uuid = compound.getUniqueId("UUID");

    try
    {
        return new AttributeModifier(uuid, compound.getString("Name"), compound.getDouble("Amount"), compound.getInteger("Operation"));
    }
    catch (Exception exception)
    {
        LOGGER.warn("Unable to create attribute: {}", new Object[] {exception.getMessage()});
        return null;
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:19,代碼來源:SharedMonsterAttributes.java

示例9: getAttributeModifiers

import net.minecraft.entity.ai.attributes.AttributeModifier; //導入依賴的package包/類
@Override
public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack) {
	Multimap<String, AttributeModifier> multimap = super.getAttributeModifiers(slot, stack);

	if (slot == EntityEquipmentSlot.MAINHAND && getData(stack) != ItemFromData.BLANK_DATA && stack.hasTagCompound()) {
		int heads=Math.min((int)TF2Attribute.getModifier("Kill Count", stack, 0, null), stack.getTagCompound().getInteger("Heads"));
		multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(),
				new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier",
						this.getWeaponDamage(stack, null, null) * this.getWeaponPelletCount(stack, null) - 1, 0));
		multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(
				ATTACK_SPEED_MODIFIER, "Weapon modifier", -4 + (1000D / this.getFiringSpeed(stack, null)), 0));
		float addHealth = TF2Attribute.getModifier("Health", stack, 0, null)+heads * TF2Attribute.getModifier("Max Health Kill", stack, 0, null);
		if (addHealth != 0)
			multimap.put(SharedMonsterAttributes.MAX_HEALTH.getName(),
					new AttributeModifier(HEALTH_MODIFIER, "Weapon modifier", addHealth, 0));
		float addSpeed = TF2Attribute.getModifier("Speed", stack, 1 + heads * TF2Attribute.getModifier("Speed Kill", stack, 0, null), null);
		if (addSpeed != 1)
			multimap.put(SharedMonsterAttributes.MOVEMENT_SPEED.getName(),
					new AttributeModifier(SPEED_MODIFIER, "Weapon modifier", addSpeed - 1, 2));
	}
	return multimap;
}
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:23,代碼來源:ItemWeapon.java

示例10: readPacketData

import net.minecraft.entity.ai.attributes.AttributeModifier; //導入依賴的package包/類
/**
 * Reads the raw packet data from the data stream.
 */
public void readPacketData(PacketBuffer buf) throws IOException
{
    this.entityId = buf.readVarIntFromBuffer();
    int i = buf.readInt();

    for (int j = 0; j < i; ++j)
    {
        String s = buf.readStringFromBuffer(64);
        double d0 = buf.readDouble();
        List<AttributeModifier> list = Lists.<AttributeModifier>newArrayList();
        int k = buf.readVarIntFromBuffer();

        for (int l = 0; l < k; ++l)
        {
            UUID uuid = buf.readUuid();
            list.add(new AttributeModifier(uuid, "Unknown synced attribute modifier", buf.readDouble(), buf.readByte()));
        }

        this.snapshots.add(new SPacketEntityProperties.Snapshot(s, d0, list));
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:25,代碼來源:SPacketEntityProperties.java

示例11: applyModifiersToAttributeInstance

import net.minecraft.entity.ai.attributes.AttributeModifier; //導入依賴的package包/類
private static void applyModifiersToAttributeInstance(IAttributeInstance p_111258_0_, NBTTagCompound p_111258_1_)
{
    p_111258_0_.setBaseValue(p_111258_1_.getDouble("Base"));

    if (p_111258_1_.hasKey("Modifiers", 9))
    {
        NBTTagList nbttaglist = p_111258_1_.getTagList("Modifiers", 10);

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            AttributeModifier attributemodifier = readAttributeModifierFromNBT(nbttaglist.getCompoundTagAt(i));

            if (attributemodifier != null)
            {
                AttributeModifier attributemodifier1 = p_111258_0_.getModifier(attributemodifier.getID());

                if (attributemodifier1 != null)
                {
                    p_111258_0_.removeModifier(attributemodifier1);
                }

                p_111258_0_.applyModifier(attributemodifier);
            }
        }
    }
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:27,代碼來源:SharedMonsterAttributes.java

示例12: readPacketData

import net.minecraft.entity.ai.attributes.AttributeModifier; //導入依賴的package包/類
/**
 * Reads the raw packet data from the data stream.
 */
public void readPacketData(PacketBuffer buf) throws IOException
{
    this.entityId = buf.readVarIntFromBuffer();
    int i = buf.readInt();

    for (int j = 0; j < i; ++j)
    {
        String s = buf.readStringFromBuffer(64);
        double d0 = buf.readDouble();
        List<AttributeModifier> list = Lists.<AttributeModifier>newArrayList();
        int k = buf.readVarIntFromBuffer();

        for (int l = 0; l < k; ++l)
        {
            UUID uuid = buf.readUuid();
            list.add(new AttributeModifier(uuid, "Unknown synced attribute modifier", buf.readDouble(), buf.readByte()));
        }

        this.field_149444_b.add(new S20PacketEntityProperties.Snapshot(s, d0, list));
    }
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:25,代碼來源:S20PacketEntityProperties.java

示例13: writeAttributeModifierToNBT

import net.minecraft.entity.ai.attributes.AttributeModifier; //導入依賴的package包/類
/**
 * Helper method for writing new attribute modifiers.
 * @param attribute
 * @param modifier
 * @param slot
 * @return
 */
public static NBTTagCompound writeAttributeModifierToNBT(IAttribute attribute, AttributeModifier modifier, EntityEquipmentSlot slot) 
{
	NBTTagCompound nbt = new NBTTagCompound();
	
	nbt.setString("AttributeName", attribute.getName());
	nbt.setString("Name", modifier.getName());
	nbt.setString("Slot", slot.getName());
	nbt.setDouble("Amount", modifier.getAmount());
	nbt.setInteger("Operation", modifier.getOperation());
	nbt.setLong("UUIDMost", modifier.getID().getMostSignificantBits());
	nbt.setLong("UUIDLeast", modifier.getID().getLeastSignificantBits());
	
	return nbt;
}
 
開發者ID:TheXFactor117,項目名稱:Loot-Slash-Conquer,代碼行數:22,代碼來源:ItemGeneratorHelper.java

示例14: setAttributeModifiers

import net.minecraft.entity.ai.attributes.AttributeModifier; //導入依賴的package包/類
public static void setAttributeModifiers(EntityLivingBase entity, int level)
{
	AttributeModifier attackDamage = new AttributeModifier(ATTACK_DAMAGE, "attackDamage", level * 0.1, 1);
	AttributeModifier maxHealth = new AttributeModifier(MAX_HEALTH, "maxHealth", level * 0.2, 1);
	
	if (!entity.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).hasModifier(attackDamage))
		entity.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).applyModifier(attackDamage);
	
	if (!entity.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).hasModifier(maxHealth))
	{
		entity.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).applyModifier(maxHealth);
		entity.setHealth(entity.getMaxHealth());
	}
}
 
開發者ID:TheXFactor117,項目名稱:Loot-Slash-Conquer,代碼行數:15,代碼來源:EventEntityJoinWorld.java

示例15: getAttributeModifiers

import net.minecraft.entity.ai.attributes.AttributeModifier; //導入依賴的package包/類
@Override
public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack) 
{
	final Multimap<String, AttributeModifier> modifiers = super.getAttributeModifiers(slot, stack);

	if (slot == EntityEquipmentSlot.MAINHAND) 
	{
		replaceModifier(modifiers, SharedMonsterAttributes.ATTACK_DAMAGE, ATTACK_DAMAGE_MODIFIER, damageMultiplier);
		replaceModifier(modifiers, SharedMonsterAttributes.ATTACK_SPEED, ATTACK_SPEED_MODIFIER, speedMultiplier);
	}

	return modifiers;
}
 
開發者ID:TheXFactor117,項目名稱:Loot-Slash-Conquer,代碼行數:14,代碼來源:ItemLEAdvancedMelee.java


注:本文中的net.minecraft.entity.ai.attributes.AttributeModifier類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。