public static void eventThor(EntityPlayer player) { if (player != null && player.getLookVec() != null) { Vec3 look = player.getLookVec(); EntityLightningBolt thor = new EntityLightningBolt(player.worldObj, look.xCoord, look.yCoord, look.zCoord); player.worldObj.spawnEntityInWorld(thor); } }
private void fire(ItemStack is, World world, EntityPlayer ep, Entity ent) { Vec3 look = ep.getLookVec(); double[] looks = ReikaVectorHelper.getPlayerLookCoords(ep, 2); if (!(ent instanceof EntityPlayer) && ReikaWorldHelper.lineOfSight(world, ep, ent)) { ItemStack fl = new ItemStack(Item.flint.itemID, 0, 0); EntityItem ei = new EntityItem( world, looks[0] / look.lengthVector(), looks[1] / look.lengthVector(), looks[2] / look.lengthVector(), fl); ei.delayBeforeCanPickup = 100; ei.motionX = look.xCoord / look.lengthVector(); ei.motionY = look.yCoord / look.lengthVector(); ei.motionZ = look.zCoord / look.lengthVector(); if (!world.isRemote) ei.velocityChanged = true; if (!world.isRemote) world.playSoundAtEntity(ep, "dig.gravel", 1.5F, 2F); world.spawnEntityInWorld(ei); if (is.getItemDamage() > 4096) { // approx the 1-hit kill of a 10-heart mob ReikaParticleHelper.EXPLODE.spawnAt(world, ent.posX, ent.posY, ent.posZ); world.playSoundAtEntity(ent, "random.explode", 1, 1); } ent.attackEntityFrom(DamageSource.causePlayerDamage(ep), this.getAttackDamage(is)); ReikaEntityHelper.knockbackEntity(ep, ent, 0.4); // ent.setRevengeTarget(ep); } }
@SubscribeEvent public void entityHurtEvent(LivingHurtEvent event) { if (!EtFuturum.enableDmgIndicator) return; int amount = MathHelper.floor_float(Math.min(event.entityLiving.getHealth(), event.ammount) / 2F); if (amount <= 0) return; // If the attacker is a player spawn the hearts aligned and facing it if (event.source instanceof EntityDamageSource) { EntityDamageSource src = (EntityDamageSource) event.source; Entity attacker = src.getSourceOfDamage(); if (attacker instanceof EntityPlayer && !(attacker instanceof FakePlayer)) { EntityPlayer player = (EntityPlayer) attacker; Vec3 look = player.getLookVec(); look.rotateAroundY((float) Math.PI / 2); for (int i = 0; i < amount; i++) { double x = event.entityLiving.posX - amount * 0.35 * look.xCoord / 2 + i * 0.35 * look.xCoord; double y = event.entityLiving.posY + 1.5 + event.entityLiving.worldObj.rand.nextGaussian() * 0.05; double z = event.entityLiving.posZ - amount * 0.35 * look.zCoord / 2 + i * 0.35 * look.zCoord; EtFuturum.networkWrapper.sendToAllAround( new BlackHeartParticlesMessage(x, y, z), new TargetPoint(player.worldObj.provider.dimensionId, x, y, z, 64)); } } } }
@Override public void onUsingTick(ItemStack is, EntityPlayer ep, int count) { if (is.getItemDamage() > 0 && this.getWater(is) > 0) { double r = 1; double d = ReikaRandomHelper.getRandomPlusMinus(2.5, 2); Vec3 vec = ep.getLookVec(); double dx = ep.posX + vec.xCoord * d; double dy = ep.posY + ep.getEyeHeight() + vec.yCoord * d; double dz = ep.posZ + vec.zCoord * d; if (count % TICK_PER_KJ == 0) { AxisAlignedBB box = AxisAlignedBB.getBoundingBox(dx, dy, dz, dx, dy, dz).expand(r, r, r); List<EntityRadiation> li = ep.worldObj.getEntitiesWithinAABB(EntityRadiation.class, box); for (EntityRadiation e : li) { e.clean(); } } int n = ReikaRandomHelper.getRandomPlusMinus(8, 4); for (int i = 0; i < n; i++) { double v = ReikaRandomHelper.getRandomPlusMinus(0.1875, 0.0625); double vx = vec.xCoord * v; double vy = vec.yCoord * v; double vz = vec.zCoord * v; vx = ReikaRandomHelper.getRandomPlusMinus(vx, 0.001); vz = ReikaRandomHelper.getRandomPlusMinus(vz, 0.001); ReikaParticleHelper.RAIN.spawnAt(ep.worldObj, dx, dy, dz, vx, vy, vz); } } }
@Override public void onUsingTick(ItemStack stack, EntityPlayer player, int count) { if (toolMaterial == ToolMaterial.EMERALD) { if (player.getHeldItem() != null && ZSSPlayerInfo.get(player).canBlock()) { Vec3 vec3 = player.getLookVec(); double dx = player.posX + vec3.xCoord * 2.0D; double dy = player.posY + player.getEyeHeight() + vec3.yCoord * 2.0D; double dz = player.posZ + vec3.zCoord * 2.0D; List<EntityFireball> list = player.worldObj.getEntitiesWithinAABB( EntityFireball.class, AxisAlignedBB.getBoundingBox(dx - 1, dy - 1, dz - 1, dx + 1, dy + 1, dz + 1)); for (EntityFireball fireball : list) { DamageSource source = DamageSource.causeFireballDamage(fireball, fireball.shootingEntity); if (canBlockDamage(stack, source) && fireball.attackEntityFrom(DamageSource.causePlayerDamage(player), 1.0F)) { fireball.getEntityData().setBoolean("isReflected", true); ZSSPlayerInfo.get(player).onAttackBlocked(stack, 1.0F); WorldUtils.playSoundAtEntity(player, Sounds.HAMMER, 0.4F, 0.5F); break; } } } } }
/** * Creates a MovingObjectPosition based on where a player is looking. * * @param player: The player to get the looking position of. * @param length: The distance to go outwards from the player, the maximum "reach". Default reach * is 4.5D. * @return MovingObjectPosition: A MovingObjectPosition containing the exact location where the * player is looking. */ public static RayTraceResult rayTrace(EntityPlayer player, double length) { final Vec3d vec1 = new Vec3d(player.posX, player.posY + player.getEyeHeight(), player.posZ); final Vec3d vec2 = player.getLookVec(); final Vec3d vec3 = vec1.addVector(vec2.xCoord * length, vec2.yCoord * length, vec2.zCoord * length); return player.worldObj.rayTraceBlocks(vec1, vec3); }
public static Tuple<Tuple<Vec3, Vec3i>, Block> searchTargetBlock(EntityPlayer player) { Vec3 lookAt = player.getLookVec(); lookAt = Vec3.createVectorHelper( lookAt.xCoord * TARGET_SEARCH_RANGE, lookAt.yCoord * TARGET_SEARCH_RANGE, lookAt.zCoord * TARGET_SEARCH_RANGE); Vec3 eye = getPlayerPosition(player); return searchTargetBlock(player, eye, lookAt); }
// tergetの検索 // see: https://github.com/bbc-mc/LockOnMod/blob/master/bbc_mc/LockOn/LockOn.java public static EntityLiving searchTarget(EntityPlayer player) { Vec3 lookAt = player.getLookVec(); lookAt = Vec3.createVectorHelper( lookAt.xCoord * TARGET_SEARCH_RANGE, lookAt.yCoord * TARGET_SEARCH_RANGE, lookAt.zCoord * TARGET_SEARCH_RANGE); Vec3 eye = getPlayerPosition(player); return searchTarget(player, eye, lookAt); }
@Override public void castSpell(EntityPlayer player) { World world = player.worldObj; Vec3 look = player.getLookVec(); if (!world.isRemote) { WaterOrb orb = new WaterOrb(world, player); if (!world.isRemote && player.dimension == 0) { world.spawnEntityInWorld(orb); } } }
@Override public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) { if (canAttack(item)) { setCanAttack(item, false); extractMagic(item, 10); if (getMagic(item) <= 0) { int sort = itemRand.nextInt(10) + 1; if (sort >= 1 && sort <= 3) { item.damageItem(101, player); } } if (ItemHelper.getString(item, "mode", "PROJECTILE").equals("PROJECTILE")) { if (!world.isRemote) { world.spawnEntityInWorld(new EntityFireBall(player.worldObj, player)); } } else if (ItemHelper.getString(item, "mode", "PROJECTILE").equals("FIRE")) { if (world.isRemote) { Vec3 look = player.getLookVec(); double vx = look.xCoord; double vy = look.yCoord; double vz = look.zCoord; player.worldObj.playAuxSFXAtEntity( player, 1009, (int) player.posX, (int) player.posY, (int) player.posZ, 0); EntityFireMode ent = new EntityFireMode(player.worldObj, player, vx, vy, vz); ent.setPosition(player.posX + vx, player.posY + vy, player.posZ + vz); ent.accelerationX = look.xCoord * 0.1; ent.accelerationY = look.yCoord * 0.1; ent.accelerationZ = look.zCoord * 0.1; player.worldObj.spawnEntityInWorld(ent); player.worldObj.playSoundAtEntity(ent, "random.bow", 1, 1); } } resetTimer(item); } return item; }
public void enterState() { SwingSilencer silencer = getItem().getAction("SwingSilencer"); if (silencer != null) { silencer.active = false; } EntityPlayer player = getPlayer(); player.swingItem(); if (!isRemote()) { Vec3 vec1 = Vec3.createVectorHelper(player.posX, player.posY + player.eyeHeight, player.posZ); Vec3 vec2 = VecUtils.add(vec1, VecUtils.multiply(player.getLookVec(), 1.5)); MovingObjectPosition ret = Raytrace.perform(player.worldObj, vec1, vec2, EntitySelectors.excludeOf(player)); if (ret != null && ret.typeOfHit == MovingObjectType.ENTITY) { ret.entityHit.attackEntityFrom(DamageSource.causePlayerDamage(player), stockDamage); player.worldObj.playSoundAtEntity(player, "dawn47:weapons.stock_attack", 0.5f, 1.0f); } else player.worldObj.playSoundAtEntity(player, "dawn47:weapons.stock_swing", 0.5f, 1.0f); } }
@Override public ItemStack onItemRightClick( ItemStack par1ItemStack, World par2World, EntityPlayer par3Entity) { super.onItemRightClick(par1ItemStack, par2World, par3Entity); if (!par2World.isRemote) { Vec3 look = par3Entity.getLookVec(); EntityLargeFireball fireball = new EntityLargeFireball(par2World); fireball.setPosition( par3Entity.posX + look.xCoord * 5, par3Entity.posY + 1 + look.yCoord * 5, par3Entity.posZ + look.zCoord * 5); fireball.accelerationX = look.xCoord * 0.1; fireball.accelerationY = look.yCoord * 0.1; fireball.accelerationZ = look.zCoord * 0.1; par2World.spawnEntityInWorld(fireball); if (!par3Entity.capabilities.isCreativeMode) { par1ItemStack.damageItem(5, par3Entity); } } return par1ItemStack; }
@Override public ItemStack onFocusRightClick( ItemStack itemstack, World world, EntityPlayer p, MovingObjectPosition movingobjectposition) { ItemWandCasting wand = (ItemWandCasting) itemstack.getItem(); if (!ConfigHandler.enableFlight) { return itemstack; } if (wand.consumeAllVis(itemstack, p, getVisCost(), true, false)) { Vec3 vec = p.getLookVec(); double force = 1 / 1.5 * (1 + EnchantmentHelper.getEnchantmentLevel( Config.enchPotency.effectId, wand.getFocusItem(itemstack)) * 0.2); p.motionX = vec.xCoord * force; p.motionY = vec.yCoord * force; p.motionZ = vec.zCoord * force; p.fallDistance = 0F; if (p instanceof EntityPlayerMP) { ((EntityPlayerMP) p).playerNetServerHandler.floatingTickCount = 0; } for (int i = 0; i < 5; i++) ThaumicTinkerer.tcProxy.smokeSpiral( world, p.posX, p.posY - p.motionY, p.posZ, 2F, (int) (Math.random() * 360), (int) p.posY); world.playSoundAtEntity(p, "thaumcraft:wind", 0.4F, 1F); } if (world.isRemote) p.swingItem(); return itemstack; }
public void onPlayerStoppedUsing( ItemStack par1ItemStack, World world, EntityPlayer entityplayer, int par4) { par1ItemStack.damageItem(27, entityplayer); entityplayer.addExhaustion(5.0F); world.playSoundAtEntity( entityplayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); if (!world.isRemote) { Vec3 look = entityplayer.getLookVec(); EntityWitherSkull fireball2 = new EntityWitherSkull(world, entityplayer, 1.0D, 1.0D, 1.0D); fireball2.setPosition( entityplayer.posX + look.xCoord * 1.0D, entityplayer.posY + look.yCoord + (double) entityplayer.getEyeHeight() - 0.10000000149011612D, entityplayer.posZ + look.zCoord * 1.0D); fireball2.accelerationX = look.xCoord * 0.1D; fireball2.accelerationY = look.yCoord * 0.1D; fireball2.accelerationZ = look.zCoord * 0.1D; world.spawnEntityInWorld(fireball2); } }
@Override public void spawnBullet(EntityPlayer player, ItemStack bulletStack, boolean electro) { Vec3 vec = player.getLookVec(); int type = bulletStack.getItemDamage() - 2; switch (type) { case 0: // casull doSpawnBullet(player, vec, vec, type, bulletStack, electro); break; case 1: // armorPiercing doSpawnBullet(player, vec, vec, type, bulletStack, electro); break; case 2: // buckshot for (int i = 0; i < 10; i++) { Vec3 vecDir = vec.addVector( player.getRNG().nextGaussian() * .1, player.getRNG().nextGaussian() * .1, player.getRNG().nextGaussian() * .1); doSpawnBullet(player, vec, vecDir, type, bulletStack, electro); } break; case 3: // HE doSpawnBullet(player, vec, vec, type, bulletStack, electro); break; case 4: // dragonsbreath for (int i = 0; i < 30; i++) { Vec3 vecDir = vec.addVector( player.getRNG().nextGaussian() * .1, player.getRNG().nextGaussian() * .1, player.getRNG().nextGaussian() * .1); EntityRevolvershot shot = doSpawnBullet(player, vec, vecDir, type, bulletStack, electro); shot.setTickLimit(10); shot.setFire(3); } break; } }
public EntityFlame(EntityPlayer player) { this(player.worldObj); Pos3D playerPos = new Pos3D(player).translate(0, 1.6, 0); Pos3D flameVec = new Pos3D(1, 1, 1); flameVec.multiply(new Pos3D(player.getLook(90))); flameVec.rotateYaw(6); Pos3D mergedVec = playerPos.clone().translate(flameVec); setPosition(mergedVec.xPos, mergedVec.yPos, mergedVec.zPos); Pos3D motion = new Pos3D(0.4, 0.4, 0.4); motion.multiply(new Pos3D(player.getLookVec())); setHeading(motion); motionX = motion.xPos; motionY = motion.yPos; motionZ = motion.zPos; owner = player; }
@Override public boolean onItemUse( ItemStack is, EntityPlayer ep, World world, int x, int y, int z, int side, float a, float b, float c) { if (is.stackTagCompound == null) { is.setTagCompound(new NBTTagCompound()); is.stackTagCompound.setInteger("sx", Integer.MIN_VALUE); is.stackTagCompound.setInteger("sy", Integer.MIN_VALUE); is.stackTagCompound.setInteger("sz", Integer.MIN_VALUE); is.stackTagCompound.setInteger("ex", Integer.MIN_VALUE); is.stackTagCompound.setInteger("ey", Integer.MIN_VALUE); is.stackTagCompound.setInteger("ez", Integer.MIN_VALUE); } MovingObjectPosition mov = new MovingObjectPosition(x, y, z, side, ep.getLookVec()); if (!WorldEditHelper.hasPlayer(ep)) { ReikaChatHelper.write("Player " + ep.getEntityName() + " has no chosen block!"); return false; } int id = WorldEditHelper.getCommandedID(ep); int meta = WorldEditHelper.getCommandedMetadata(ep); if (id != 0) { if (id >= Block.blocksList.length || Block.blocksList[id] == null || Block.blocksList[id].getLocalizedName() == "") { ReikaChatHelper.write("Block " + id + " does not exist!"); return false; } } if (ep.isSneaking()) { is.stackTagCompound.setInteger("ex", mov.blockX); is.stackTagCompound.setInteger("ey", mov.blockY); is.stackTagCompound.setInteger("ez", mov.blockZ); ReikaChatHelper.write( "Position 2 set to " + is.stackTagCompound.getInteger("ex") + ", " + is.stackTagCompound.getInteger("ey") + ", " + is.stackTagCompound.getInteger("ez")); } else { is.stackTagCompound.setInteger("sx", mov.blockX); is.stackTagCompound.setInteger("sy", mov.blockY); is.stackTagCompound.setInteger("sz", mov.blockZ); ReikaChatHelper.write( "Position 1 set to " + is.stackTagCompound.getInteger("sx") + ", " + is.stackTagCompound.getInteger("sy") + ", " + is.stackTagCompound.getInteger("sz")); } is.setItemDamage(1); ep.setCurrentItemOrArmor(0, is); int[] s = { is.stackTagCompound.getInteger("sx"), is.stackTagCompound.getInteger("sy"), is.stackTagCompound.getInteger("sz") }; int[] e = { is.stackTagCompound.getInteger("ex"), is.stackTagCompound.getInteger("ey"), is.stackTagCompound.getInteger("ez") }; if (s[0] != Integer.MIN_VALUE && s[1] != Integer.MIN_VALUE && s[2] != Integer.MIN_VALUE) { if (e[0] != Integer.MIN_VALUE && e[1] != Integer.MIN_VALUE && e[2] != Integer.MIN_VALUE) { if (s[0] != e[0] || s[1] != e[1] || s[2] != e[2]) { String name; if (id == 0) name = "Air"; else name = Block.blocksList[id].getLocalizedName(); ReikaChatHelper.write( String.format( "%d", Math.abs((s[0] - e[0] + 1) * (s[1] - e[1] + 1) * (s[2] - e[2] + 1))) + " blocks being changed to Block " + name + " (ID " + id + ") with Metadata " + meta); for (int m = 0; m < 3; m++) { if (s[m] > e[m]) { int sc = s[m]; s[m] = e[m]; e[m] = sc; } } if (!world.isRemote) for (int i = s[0]; i <= e[0]; i += 1) { for (int j = s[1]; j <= e[1]; j += 1) { for (int k = s[2]; k <= e[2]; k += 1) { world.setBlock(i, j, k, id, meta, 3); world.markBlockForUpdate(i, j, k); } } } this.reset(is, ep); } } } return true; }
@Override public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer ep) { if (is.getItemDamage() <= 0) { this.noCharge(); return is; } this.warnCharge(is); if (!ReikaPlayerAPI.playerHasOrIsCreative(ep, Block.gravel.blockID, -1)) { if (!world.isRemote) world.playAuxSFX(1001, (int) ep.posX, (int) ep.posY, (int) ep.posZ, 1); return is; } for (float i = 1; i <= 128; i += 0.5) { Vec3 look = ep.getLookVec(); double[] looks = ReikaVectorHelper.getPlayerLookCoords(ep, i); AxisAlignedBB fov = AxisAlignedBB.getBoundingBox( looks[0] - 0.5, looks[1] - 0.5, looks[2] - 0.5, looks[0] + 0.5, looks[1] + 0.5, looks[2] + 0.5); List infov = world.getEntitiesWithinAABB(EntityLivingBase.class, fov); for (int k = 0; k < infov.size(); k++) { EntityLivingBase ent = (EntityLivingBase) infov.get(k); if (!ep.equals(ent) && this.isEntityAttackable(ent) && ReikaWorldHelper.lineOfSight(world, ep, ent)) { double dist = ReikaMathLibrary.py3d(ep.posX - ent.posX, ep.posY - ent.posY, ep.posZ - ent.posZ); double x = ep.posX + look.xCoord; double y = ep.posY + ep.getEyeHeight() + look.yCoord; double z = ep.posZ + look.zCoord; double dx = ent.posX - ep.posX; double dy = ent.posY - ep.posY; double dz = ent.posZ - ep.posZ; if (!world.isRemote) { ItemStack fl = new ItemStack(Item.flint); EntityItem ei = new EntityItem( world, look.xCoord / look.lengthVector() + ep.posX, look.yCoord / look.lengthVector() + ep.posY, look.zCoord / look.lengthVector() + ep.posZ, fl); ei.delayBeforeCanPickup = 100; ei.motionX = dx; ei.motionY = dy + 1; ei.motionZ = dz; // ReikaChatHelper.writeCoords(world, ei.posX, ei.posY, ei.posZ); ei.velocityChanged = true; world.playSoundAtEntity(ep, "dig.gravel", 1.5F, 2F); ei.lifespan = 5; world.spawnEntityInWorld(ei); if (is.getItemDamage() > 4096) { // approx the 1-hit kill of a 10-heart mob // ReikaPacketHelper.sendUpdatePacket(RotaryCraft.packetChannel, // PacketRegistry.GRAVELGUN.getMinValue(), world, (int)ent.posX, (int)ent.posY, // (int)ent.posZ); // world.playSoundAtEntity(ep, "random.explode", 0.25F, 1F); } if (ent instanceof EntityDragon) { EntityDragon ed = (EntityDragon) ent; ed.attackEntityFromPart( ed.dragonPartBody, DamageSource.causePlayerDamage(ep), this.getAttackDamage(is)); } else { int dmg = this.getAttackDamage(is); if (ent instanceof EntityPlayer) { for (int n = 1; n < 5; n++) { ItemRegistry ir = ItemRegistry.getEntry(ent.getCurrentItemOrArmor(n)); if (ir != null) { if (ir.isBedrockArmor()) dmg *= 0.75; } } } ent.attackEntityFrom(DamageSource.causePlayerDamage(ep), dmg); if (dmg >= 500) RotaryAchievements.MASSIVEHIT.triggerAchievement(ep); } if (ent instanceof EntityMob && (ent.isDead || ent.getHealth() <= 0) && ReikaMathLibrary.py3d(ep.posX - ent.posX, ep.posY - ent.posY, ep.posZ - ent.posZ) >= 80) RotaryAchievements.GRAVELGUN.triggerAchievement(ep); } // ReikaWorldHelper.spawnParticleLine(world, x, y, z, ent.posX, ent.posY+ent.height/2, // ent.posZ, "crit", 0, 0, 0, 60); for (float t = 0; t < 2; t += 0.05F) world.spawnParticle("crit", x, y, z, dx / dist * t, dy / dist * t, dz / dist * t); } } if (infov.size() > 0 && !(infov.size() == 1 && infov.get(0) instanceof EntityPlayer)) { if (!ep.capabilities.isCreativeMode) ReikaInventoryHelper.findAndDecrStack( Block.gravel.blockID, -1, ep.inventory.mainInventory); return new ItemStack(is.itemID, is.stackSize, is.getItemDamage() - 1); } } return is; }