我正在为Minecraft制作模组,现在我正在制作附魔,为您带来特殊的药水效果。我一直在进行Health Boost附魔,并从每次更新激活效果开始。执行此操作时,每次更新都会使凸轮效果受损,因此我切换到每次设备更改。这种方法效果更好,但是每次我多得到一个半心半意的人并更换/丢下一个物品时,它又成为了受伤的摄像头。我想使用某种onArmorEquip
事件,但没有看到一个选项。我正在使用Minecraft 1.12.2 Eclipse,有人有建议吗?这是我的代码:
@SubscribeEvent
public static void enchantTankFunction(LivingEquipmentChangeEvent event)
{
Object player = event.getEntityLiving();
if(player instanceof EntityLivingBase)
{
EntityLivingBase entityPlayer = (EntityLivingBase)player;
int levelFeet = EnchantmentHelper.getEnchantmentLevel(ENCHANT_TANK, entityPlayer.getItemStackFromSlot(EntityEquipmentSlot.FEET));
int levelLegs = EnchantmentHelper.getEnchantmentLevel(ENCHANT_TANK, entityPlayer.getItemStackFromSlot(EntityEquipmentSlot.LEGS));
int levelChest = EnchantmentHelper.getEnchantmentLevel(ENCHANT_TANK, entityPlayer.getItemStackFromSlot(EntityEquipmentSlot.CHEST));
int levelHead = EnchantmentHelper.getEnchantmentLevel(ENCHANT_TANK, entityPlayer.getItemStackFromSlot(EntityEquipmentSlot.HEAD));
if(!entityPlayer.getEntityWorld().isRemote && (levelFeet > 0 || levelLegs > 0 || levelChest > 0 || levelHead > 0))
{
entityPlayer.removePotionEffect(MobEffects.HEALTH_BOOST);
entityPlayer.addPotionEffect(new PotionEffect(MobEffects.HEALTH_BOOST, (24 * 60 * 60 * 20), (levelFeet) + (levelLegs) + (levelChest) + (levelHead) - 1, false, false));
}
else
{
entityPlayer.removePotionEffect(MobEffects.HEALTH_BOOST);
}
}
}
最佳答案
这就是我要做的。您可以先更改哪个设备插槽,然后再更改该项目。这未经测试,但与此类似的东西应该起作用。
这会检查该实体是否是玩家,并且设备更改是在装甲插槽中进行的(您可能只需要此部分的帮助)。
@SubscribeEvent
public static void enchantSaturationFunction(LivingEquipmentChangeEvent event)
{
if (event.getEntityLiving() instanceof EntityPlayer) // Remove this if you want other mobs to get the benefits
{
EntityEquipmentSlot slotChanged = event.getSlot();
if (slotChanged.getSlotIndex() > 0 && slotChanged.getSlotIndex() < 5) // Check out the class EntityEquipmentSlot
{
然后,要完成任务,将获得新装甲的
ItemStack
并检查结界。我从ItemStack::getTooltip
偷了一些代码。 ItemStack previousArmorPiece = event.getFrom();
ItemStack newArmorPiece = event.getTo();
NBTTagList nbtTagList = newArmorPiece.getEnchantmentTagList();
for (int k1 = 0; k1 < nbtTagList.tagCount(); ++k1)
{
NBTTagCompound nbttagcompound = nbtTagList.getCompoundTagAt(k1);
int enchantmentID = nbttagcompound.getShort("id");
int enchantmentLevel = nbttagcompound.getShort("lvl");
Enchantment enchantment = Enchantment.getEnchantmentByID(enchantmentID);
if (enchantment instanceof MY_ENCHANTMENT)
{
// They equipped armor with the necessary enchantment, so do what you want.
}
}
}
}
}