use of net.minecraft.util.EnumHand in project ElementalSorcery by Yuzunyannn.
the class ItemAncientPaper method doUnscramble.
/**
* 进行一次解读
*/
protected void doUnscramble(AncientPaper ap, World world, EntityPlayer player, EnumHand handIn) {
if (world.isRemote)
return;
NBTTagCompound playerData = EventServer.getPlayerNBT(player);
// 上次的时间
long nextTime = playerData.getLong("unsNext");
if (nextTime > world.getWorldTime() && !player.isCreative()) {
player.sendMessage(new TextComponentTranslation("info.want.not.unscramble").setStyle(new Style().setColor(TextFormatting.GRAY).setBold(true)));
return;
}
Random rand = world.rand;
// 一些前置处理
EnumHand offHand = handIn == EnumHand.MAIN_HAND ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND;
int noteEnergy = ItemUnscrambleNote.getNoteEnergy(player.getHeldItem(offHand), player);
float energy = Math.max(playerData.getFloat("unsEnergy"), 1);
boolean setTired = rand.nextFloat() < 0.5f / energy;
if (setTired)
playerData.setLong("unsNext", world.getWorldTime() + 12000);
// 增加研究力
playerData.setFloat("unsEnergy", Math.min(energy + 0.1f, 3));
ItemUnscrambleNote.growNoteEnergy(player.getHeldItem(offHand), player, rand.nextInt(3), false);
// 增加进度
float originProgress = ap.getProgress();
float grow = rand.nextFloat() * 0.04f + 0.01f + rand.nextFloat() * noteEnergy / 1000;
ap.setProgress(originProgress + grow);
if (player instanceof EntityPlayerMP)
ESCriteriaTriggers.ES_TRING.trigger((EntityPlayerMP) player, "unscramble:once");
if (!ap.hasType())
return;
// 增加研究点数
KnowledgeType type = ap.getType();
List<Entry<String, Integer>> topics = type.getTopics();
if (topics == null)
return;
Entry<String, Integer> topic = topics.get(rand.nextInt(topics.size()));
float rCount = topic.getValue() * grow * (ap.getEnd() - ap.getStart()) / 100.0f;
int count = MathHelper.floor(rCount);
float expect = (rCount) - MathHelper.floor(rCount);
count += rand.nextFloat() <= expect ? 1 : 0;
if (count > 0)
Researcher.research(player, topic.getKey(), count);
}
use of net.minecraft.util.EnumHand in project ElementalSorcery by Yuzunyannn.
the class ItemDejectedTear method onUpdate.
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
if (worldIn.isRemote)
return;
EnumHand hand = ItemVortex.inEntityHand(entityIn, stack, itemSlot, isSelected);
if (hand == null)
return;
if (entityIn.ticksExisted % 200 == 0) {
((EntityLivingBase) entityIn).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 220, 2));
((EntityLivingBase) entityIn).addPotionEffect(new PotionEffect(MobEffects.ABSORPTION, 220, 1));
((EntityLivingBase) entityIn).addPotionEffect(new PotionEffect(MobEffects.RESISTANCE, 220, 2));
}
}
use of net.minecraft.util.EnumHand in project ElementalSorcery by Yuzunyannn.
the class ItemDreadGem method onUpdate.
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
if (worldIn.isRemote)
return;
EnumHand hand = ItemVortex.inEntityHand(entityIn, stack, itemSlot, isSelected);
if (hand == null)
return;
if (entityIn.ticksExisted % 100 == 0) {
AxisAlignedBB aabb = WorldHelper.createAABB(entityIn.getPositionVector(), 5, 2, 1);
List<EntityLiving> mobs = worldIn.getEntitiesWithinAABB(EntityLiving.class, aabb, (e) -> {
return e instanceof IMob;
});
for (EntityLiving mob : mobs) {
EntityLivingBase player = (EntityLivingBase) entityIn;
if (mob.getRevengeTarget() != null)
mob.setRevengeTarget(player);
else
mob.setAttackTarget(player);
}
}
}
use of net.minecraft.util.EnumHand in project ElementalSorcery by Yuzunyannn.
the class ItemFusionCrystal method onUpdate.
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
if (entityIn.ticksExisted % (60 * 20) != 0)
return;
if (worldIn.isRemote)
return;
EnumHand hand = ItemVortex.inEntityHand(entityIn, stack, itemSlot, isSelected);
if (hand == null)
return;
Random rand = worldIn.rand;
EntityEquipmentSlot slot = hand == EnumHand.MAIN_HAND ? EntityEquipmentSlot.MAINHAND : EntityEquipmentSlot.OFFHAND;
stack.setTagCompound(null);
float at = 0.01f + rand.nextFloat() * 0.19f;
ItemLifeLeather.addAttributeModifier(stack, SharedMonsterAttributes.MAX_HEALTH, slot, at, 1);
ItemLifeLeather.addAttributeModifier(stack, SharedMonsterAttributes.ATTACK_SPEED, slot, at, 1);
ItemLifeLeather.addAttributeModifier(stack, SharedMonsterAttributes.MOVEMENT_SPEED, slot, at, 1);
ItemLifeLeather.addAttributeModifier(stack, SharedMonsterAttributes.LUCK, slot, at, 1);
}
use of net.minecraft.util.EnumHand in project ElementalSorcery by Yuzunyannn.
the class ItemCalamityGem method onUpdate.
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
if (worldIn.isRemote)
return;
if (entityIn.ticksExisted % 100 == 0) {
EnumHand hand = ItemVortex.inEntityHand(entityIn, stack, itemSlot, isSelected);
if (hand == null)
return;
calamityEntity((EntityLivingBase) entityIn, 100);
}
}
Aggregations