public static void effect(TileTotemIntelligence totem, int i, int upgrades) { if (totem.worldObj.getWorldTime() % 80L == 0) { if (EntityUtil.getEntitiesInRange( totem.worldObj, totem.xCoord, totem.yCoord, totem.zCoord, 10 + (upgrades * 5), 10 + (upgrades * 5)) != null) { for (Entity entity : EntityUtil.getEntitiesInRange( totem.worldObj, totem.xCoord, totem.yCoord, totem.zCoord, 10 + (upgrades * 5), 10 + (upgrades * 5))) { if (entity instanceof EntityPlayer) { if (entity.isBurning()) { Random rand = new Random(); ((EntityPlayer) entity).heal(4 + rand.nextInt(4)); } ((EntityPlayer) entity) .addPotionEffect(new PotionEffect(Potion.fireResistance.id, 200, 0)); totem.decreaseChlorophyll(TotemUtil.decrementAmount(i)); } } } } }
/** * Will render the specified entity at the specified partial tick time. Args: entity, * partialTickTime */ public void renderEntity(Entity par1Entity, float par2) { if (par1Entity.ticksExisted == 0) { par1Entity.lastTickPosX = par1Entity.posX; par1Entity.lastTickPosY = par1Entity.posY; par1Entity.lastTickPosZ = par1Entity.posZ; } double d0 = par1Entity.lastTickPosX + (par1Entity.posX - par1Entity.lastTickPosX) * (double) par2; double d1 = par1Entity.lastTickPosY + (par1Entity.posY - par1Entity.lastTickPosY) * (double) par2; double d2 = par1Entity.lastTickPosZ + (par1Entity.posZ - par1Entity.lastTickPosZ) * (double) par2; float f1 = par1Entity.prevRotationYaw + (par1Entity.rotationYaw - par1Entity.prevRotationYaw) * par2; int i = par1Entity.getBrightnessForRender(par2); if (par1Entity.isBurning()) { i = 15728880; } int j = i % 65536; int k = i / 65536; OpenGlHelper.setLightmapTextureCoords( OpenGlHelper.lightmapTexUnit, (float) j / 1.0F, (float) k / 1.0F); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.renderEntityWithPosYaw( par1Entity, d0 - renderPosX, d1 - renderPosY, d2 - renderPosZ, f1, par2); }
@Override public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) { if (ServerHelper.isClientWorld(world)) return; if (world.getTotalWorldTime() % 8 != 0) return; if (entity instanceof EntityLivingBase) { if (entity.isBurning() || entity instanceof EntityBlaze) doIgnition(world, x, y, z); } }
@Override public void updateInPedestal(World world, int x, int y, int z) { if (!world.isRemote && ProjectEConfig.zeroPedCooldown != -1) { if (coolCooldown == 0) { TileEntity tile = world.getTileEntity(x, y, z); AxisAlignedBB aabb = ((DMPedestalTile) tile).getEffectBounds(); WorldHelper.freezeInBoundingBox(world, aabb); List<Entity> list = world.getEntitiesWithinAABB(Entity.class, aabb); for (Entity ent : list) { if (ent.isBurning()) { ent.extinguish(); } } coolCooldown = ProjectEConfig.zeroPedCooldown; } else { coolCooldown--; } } }
@Override public void updateInPedestal(@Nonnull World world, @Nonnull BlockPos pos) { if (!world.isRemote && ProjectEConfig.zeroPedCooldown != -1) { DMPedestalTile tile = ((DMPedestalTile) world.getTileEntity(pos)); if (tile.getActivityCooldown() == 0) { AxisAlignedBB aabb = tile.getEffectBounds(); WorldHelper.freezeInBoundingBox(world, aabb, null, false); List<Entity> list = world.getEntitiesWithinAABB(Entity.class, aabb); for (Entity ent : list) { if (ent.isBurning()) { ent.extinguish(); } } tile.setActivityCooldown(ProjectEConfig.zeroPedCooldown); } else { tile.decrementActivityCooldown(); } } }
@Override public void updateAITick(int pMode) { switch (pMode) { case mmode_Archer: // owner.getWeaponStatus(); updateGuns(); break; case mmode_Blazingstar: // owner.getWeaponStatus(); updateGuns(); // Blazingstarの特殊効果 World lworld = owner.worldObj; List<Entity> llist = lworld.getEntitiesWithinAABB( Entity.class, owner.getEntityBoundingBox().expand(16D, 16D, 16D)); for (int li = 0; li < llist.size(); li++) { Entity lentity = llist.get(li); if (lentity.isEntityAlive() && lentity.isBurning() && owner.getRNG().nextFloat() > 0.9F) { // 発火! int lx = (int) owner.posX; int ly = (int) owner.posY; int lz = (int) owner.posZ; if (lworld.isAirBlock(new BlockPos(lx, ly, lz)) || lworld .getBlockState(new BlockPos(lx, ly, lz)) .getBlock() .getMaterial() .getCanBurn()) { lworld.playSoundEffect( lx + 0.5D, ly + 0.5D, lz + 0.5D, "fire.ignite", 1.0F, owner.getRNG().nextFloat() * 0.4F + 0.8F); lworld.setBlockState(new BlockPos(lx, ly, lz), Blocks.fire.getDefaultState()); } } } break; } }
/** * @author gabizou - April 8th, 2016 * @reason Rewrites the attackTargetEntityWithCurrentItem to throw an {@link AttackEntityEvent} * prior to the ensuing {@link DamageEntityEvent}. This should cover all cases where players * are attacking entities and those entities override {@link * EntityLivingBase#attackEntityFrom(DamageSource, float)} and effectively bypass our damage * event hooks. * @param targetEntity The target entity */ @Overwrite public void attackTargetEntityWithCurrentItem(net.minecraft.entity.Entity targetEntity) { // Sponge Start - Add SpongeImpl hook to override in forge as necessary if (!SpongeImplHooks.checkAttackEntity((EntityPlayer) (Object) this, targetEntity)) { return; } // Sponge End if (targetEntity.canAttackWithItem()) { if (!targetEntity.hitByEntity((EntityPlayer) (Object) this)) { // Sponge Start - Prepare our event values // float baseDamage = // this.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue(); final double originalBaseDamage = this.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue(); float baseDamage = (float) originalBaseDamage; // Sponge End int knockbackModifier = 0; float enchantmentModifierAmount = 0.0F; // Sponge Start - gather the attack modifiers final List<Tuple<DamageModifier, Function<? super Double, Double>>> originalFunctions = new ArrayList<>(); final EnumCreatureAttribute creatureAttribute = targetEntity instanceof EntityLivingBase ? ((EntityLivingBase) targetEntity).getCreatureAttribute() : EnumCreatureAttribute.UNDEFINED; final List<Tuple<DamageModifier, Function<? super Double, Double>>> enchantmentModifierFunctions = DamageEventHandler.createAttackEnchamntmentFunction( this.getHeldItem(), creatureAttribute); // if (targetEntity instanceof EntityLivingBase) { // enchantmentModifierAmount = // EnchantmentHelper.getModifierForCreature(this.getHeldItem(), creatureAttribute); // } else { // enchantmentModifierAmount = // EnchantmentHelper.getModifierForCreature(this.getHeldItem(), // EnumCreatureAttribute.UNDEFINED); // } enchantmentModifierAmount = (float) enchantmentModifierFunctions .stream() .map(Tuple::getSecond) .mapToDouble(function -> function.apply(originalBaseDamage)) .sum(); originalFunctions.addAll(enchantmentModifierFunctions); // Sponge End knockbackModifier = knockbackModifier + EnchantmentHelper.getKnockbackModifier((EntityPlayer) (Object) this); if (this.isSprinting()) { ++knockbackModifier; } if (baseDamage > 0.0F || enchantmentModifierAmount > 0.0F) { boolean fallingCriticalHit = this.fallDistance > 0.0F && !this.onGround && !this.isOnLadder() && !this.isInWater() && !this.isPotionActive(Potion.blindness) && this.ridingEntity == null && targetEntity instanceof EntityLivingBase; if (fallingCriticalHit && baseDamage > 0.0F) { // Sponge - Add the function for critical attacking originalFunctions.add( DamageEventHandler.provideCriticalAttackTuple((EntityPlayer) (Object) this)); // baseDamage *= 1.5F; Sponge - remove since it's handled in the event } // baseDamage = baseDamage + enchantmentModifierAmount; // Sponge - remove since it is // delegated through the event. boolean targetLitOnFire = false; int fireAspectLevel = EnchantmentHelper.getFireAspectModifier((EntityPlayer) (Object) this); if (targetEntity instanceof EntityLivingBase && fireAspectLevel > 0 && !targetEntity.isBurning()) { targetLitOnFire = true; targetEntity.setFire(1); } double targetMotionX = targetEntity.motionX; double targetMotionY = targetEntity.motionY; double targetMotionZ = targetEntity.motionZ; // Sponge Start - Create the event and throw it final DamageSource damageSource = DamageSource.causePlayerDamage((EntityPlayer) (Object) this); final AttackEntityEvent event = SpongeEventFactory.createAttackEntityEvent( Cause.source(damageSource).build(), originalFunctions, EntityUtil.fromNative(targetEntity), knockbackModifier, originalBaseDamage); SpongeImpl.postEvent(event); if (event.isCancelled()) { if (targetLitOnFire) { targetEntity.extinguish(); } return; } baseDamage = (float) event.getFinalOutputDamage(); knockbackModifier = event.getKnockbackModifier(); boolean attackSucceded = targetEntity.attackEntityFrom(damageSource, (float) event.getFinalOutputDamage()); // Sponge End if (attackSucceded) { if (knockbackModifier > 0) { targetEntity.addVelocity( (double) (-MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F) * (float) knockbackModifier * 0.5F), 0.1D, (double) (MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F) * (float) knockbackModifier * 0.5F)); this.motionX *= 0.6D; this.motionZ *= 0.6D; this.setSprinting(false); } if (targetEntity instanceof EntityPlayerMP && targetEntity.velocityChanged) { ((EntityPlayerMP) targetEntity) .playerNetServerHandler.sendPacket(new S12PacketEntityVelocity(targetEntity)); targetEntity.velocityChanged = false; targetEntity.motionX = targetMotionX; targetEntity.motionY = targetMotionY; targetEntity.motionZ = targetMotionZ; } if (fallingCriticalHit) { this.onCriticalHit(targetEntity); } if (enchantmentModifierAmount > 0.0F) { this.onEnchantmentCritical(targetEntity); } if (baseDamage >= 18.0F) { this.triggerAchievement(AchievementList.overkill); } this.setLastAttacker(targetEntity); if (targetEntity instanceof EntityLivingBase) { EnchantmentHelper.applyThornEnchantments( (EntityLivingBase) targetEntity, (EntityPlayer) (Object) this); } EnchantmentHelper.applyArthropodEnchantments( (EntityPlayer) (Object) this, targetEntity); ItemStack itemstack = this.getCurrentEquippedItem(); net.minecraft.entity.Entity entity = targetEntity; if (targetEntity instanceof EntityDragonPart) { IEntityMultiPart ientitymultipart = ((EntityDragonPart) targetEntity).entityDragonObj; if (ientitymultipart instanceof EntityLivingBase) { entity = (EntityLivingBase) ientitymultipart; } } if (itemstack != null && entity instanceof EntityLivingBase) { itemstack.hitEntity((EntityLivingBase) entity, (EntityPlayer) (Object) this); if (itemstack.stackSize <= 0) { this.destroyCurrentEquippedItem(); } } if (targetEntity instanceof EntityLivingBase) { this.addStat(StatList.damageDealtStat, Math.round(baseDamage * 10.0F)); if (fireAspectLevel > 0) { targetEntity.setFire(fireAspectLevel * 4); } } this.addExhaustion(0.3F); } else if (targetLitOnFire) { targetEntity.extinguish(); } } } } }
@SubscribeEvent public void onAttackEntity(AttackEntityEvent event) { if (event.entityLiving.worldObj.isRemote) return; EntityLivingBase attacker = event.entityLiving; EntityPlayer player = event.entityPlayer; Entity target = event.target; ItemStack stack = attacker.getEquipmentInSlot(0); if (stack != null && stack.getItem().onLeftClickEntity(stack, player, target)) return; if (target.canAttackWithItem()) { if (!target.hitByEntity(target)) { float damageAmount = TFC_MobData.STEVE_DAMAGE; if (stack != null) { damageAmount = (float) player .getEntityAttribute(SharedMonsterAttributes.attackDamage) .getAttributeValue(); // player.addChatMessage("Damage: " + i); if (damageAmount == 1.0f) { damageAmount = TFC_MobData.STEVE_DAMAGE; // i = player.inventory.getCurrentItem().getItem().getDamageVsEntity(target, // player.inventory.getCurrentItem()); } } if (player.isPotionActive(Potion.damageBoost)) damageAmount += 3 << player.getActivePotionEffect(Potion.damageBoost).getAmplifier(); if (player.isPotionActive(Potion.weakness)) damageAmount -= 2 << player.getActivePotionEffect(Potion.weakness).getAmplifier(); int knockback = 0; float enchantmentDamage = 0; if (target instanceof EntityLiving) { enchantmentDamage = EnchantmentHelper.getEnchantmentModifierLiving(player, (EntityLiving) target); knockback += EnchantmentHelper.getKnockbackModifier(player, (EntityLiving) target); } if (player.isSprinting()) ++knockback; if (damageAmount > 0 || enchantmentDamage > 0) { boolean criticalHit = player.fallDistance > 0.0F && !player.onGround && !player.isOnLadder() && !player.isInWater() && !player.isPotionActive(Potion.blindness) && player.ridingEntity == null && target instanceof EntityLiving; if (criticalHit && damageAmount > 0) damageAmount += event.entity.worldObj.rand.nextInt((int) (damageAmount / 2 + 2)); damageAmount += enchantmentDamage; boolean onFire = false; int fireAspect = EnchantmentHelper.getFireAspectModifier(player); if (target instanceof EntityLiving && fireAspect > 0 && !target.isBurning()) { onFire = true; target.setFire(1); } boolean entityAttacked = target.attackEntityFrom(DamageSource.causePlayerDamage(player), damageAmount); if (entityAttacked) { if (knockback > 0) { target.addVelocity( -MathHelper.sin(player.rotationYaw * (float) Math.PI / 180.0F) * knockback * 0.5F, 0.1D, MathHelper.cos(player.rotationYaw * (float) Math.PI / 180.0F) * knockback * 0.5F); player.motionX *= 0.6D; player.motionZ *= 0.6D; player.setSprinting(false); } if (criticalHit) player.onCriticalHit(target); if (enchantmentDamage > 0) player.onEnchantmentCritical(target); if (damageAmount >= 18) player.triggerAchievement(AchievementList.overkill); player.setLastAttacker(target); if (target instanceof EntityLiving) target.attackEntityFrom(DamageSource.causeThornsDamage(attacker), damageAmount); } ItemStack itemstack = player.getCurrentEquippedItem(); Object object = target; if (target instanceof EntityDragonPart) { IEntityMultiPart ientitymultipart = ((EntityDragonPart) target).entityDragonObj; if (ientitymultipart instanceof EntityLiving) object = ientitymultipart; } if (itemstack != null && object instanceof EntityLiving) { itemstack.hitEntity((EntityLiving) object, player); if (itemstack.stackSize <= 0) player.destroyCurrentEquippedItem(); } if (target instanceof EntityLivingBase) { player.addStat(StatList.damageDealtStat, Math.round(damageAmount * 10.0f)); if (fireAspect > 0 && entityAttacked) target.setFire(fireAspect * 4); else if (onFire) target.extinguish(); } player.addExhaustion(0.3F); } } } event.setCanceled(true); }
@Override public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) { if (entity.canAttackWithItem()) { if (!entity.hitByEntity(player)) { float damage = (float) getAttackDamage(stack); int i = 0; float extraDamage = 0.0F; if (entity instanceof EntityLivingBase) { extraDamage = EnchantmentHelper.getEnchantmentModifierLiving(player, (EntityLivingBase) entity); i += EnchantmentHelper.getKnockbackModifier(player, (EntityLivingBase) entity); } if (player.isSprinting()) { i++; } if (damage > 0.0F || extraDamage > 0.0F) { boolean criricalHit = player.fallDistance > 0.0F && !player.onGround && !player.isOnLadder() && !player.isInWater() && !player.isPotionActive(Potion.blindness) && player.ridingEntity == null && entity instanceof EntityLivingBase; if (criricalHit && damage > 0.0F) { damage *= 1.5F; } damage += extraDamage; boolean fire = false; int j = EnchantmentHelper.getFireAspectModifier(player); if (entity instanceof EntityLivingBase && j > 0 && !entity.isBurning()) { fire = true; entity.setFire(1); } boolean attack = entity.attackEntityFrom(DamageSource.causePlayerDamage(player), damage); if (attack) { if (i > 0) { entity.addVelocity( (double) (-MathHelper.sin(player.rotationYaw * (float) Math.PI / 180.0F) * (float) i * 0.5F), 0.1D, (double) (MathHelper.cos(player.rotationYaw * (float) Math.PI / 180.0F) * (float) i * 0.5F)); player.motionX *= 0.6D; player.motionZ *= 0.6D; player.setSprinting(false); } if (criricalHit) { player.onCriticalHit(entity); } if (extraDamage > 0.0F) { player.onEnchantmentCritical(entity); } if (damage >= 18.0F) { player.triggerAchievement(AchievementList.overkill); } player.setLastAttacker(entity); if (entity instanceof EntityLivingBase) { EnchantmentHelper.func_151384_a((EntityLivingBase) entity, player); } } ItemStack itemstack = player.getCurrentEquippedItem(); Object object = entity; if (entity instanceof EntityDragonPart) { IEntityMultiPart entityMultipart = ((EntityDragonPart) entity).entityDragonObj; if (entityMultipart != null && entityMultipart instanceof EntityLivingBase) { object = (EntityLivingBase) entityMultipart; } } if (itemstack != null && object instanceof EntityLivingBase) { itemstack.hitEntity((EntityLivingBase) object, player); if (itemstack.stackSize <= 0) { player.destroyCurrentEquippedItem(); } } if (entity instanceof EntityLivingBase) { player.addStat(StatList.damageDealtStat, Math.round(damage * 10.0F)); if (j > 0 && attack) { entity.setFire(j * 4); } else if (fire) { entity.extinguish(); } } player.addExhaustion(0.3F); } } } return true; }