本文整理匯總了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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
}
}
示例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;
}
示例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;
}
}
示例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;
}
示例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));
}
}
示例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);
}
}
}
}
示例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));
}
}
示例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;
}
示例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());
}
}
示例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;
}