private void explode() { final float strength = 20.0F; final Explosion explosion = new Explosion(worldObj, null, posX, posY, posZ, strength); explosion.isFlaming = false; explosion.isSmoking = true; explosion.doExplosionA(); explosion.doExplosionB(true); if (!worldObj.isRemote) { final Iterator var12 = worldObj.playerEntities.iterator(); while (var12.hasNext()) { final EntityPlayer player = (EntityPlayer) var12.next(); if (player.getDistanceSq(posX, posY, posZ) < 4096.0D) { ((EntityPlayerMP) player) .playerNetServerHandler.sendPacketToPlayer( new Packet60Explosion( posX, posY, posZ, strength, explosion.affectedBlockPositions, (Vec3) explosion.func_77277_b().get(player))); sendPacket( posX, posY, posZ, strength, explosion.affectedBlockPositions, (Vec3) explosion.func_77277_b().get(player)); } } } }
@Override public void onPlayerLogin(EntityPlayer player) { // Server-side - called whenever a player logs in // I couldn't find a way to detect if the client has TerrainControl, // so for now the configs are sent anyway. // Get the config LocalWorld worldTC = WorldHelper.toLocalWorld(player.worldObj); if (worldTC == null) { // World not loaded return; } WorldConfig config = worldTC.getSettings(); // Serialize it ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); DataOutputStream stream = new DataOutputStream(outputStream); try { stream.writeInt(TCDefaultValues.ProtocolVersion.intValue()); config.Serialize(stream); } catch (IOException e) { e.printStackTrace(); } // Make the packet Packet250CustomPayload packet = new Packet250CustomPayload(); packet.channel = TCDefaultValues.ChannelName.stringValue(); packet.data = outputStream.toByteArray(); packet.length = outputStream.size(); // Send the packet ((EntityPlayerMP) player).playerNetServerHandler.sendPacketToPlayer(packet); System.out.println("TerrainControl: sent config"); }
public void addToParty(EntityPixelmon p) { if (mode == PokeballManagerMode.Player && pokedex != null) { pokedex.set(Pokedex.nameToID(p.getName()), DexRegisterStatus.caught); pokedex.sendToPlayer(pokedex.owner); } if (p.moveset.size() == 0) p.loadMoveset(); if (!hasSpace()) { ChatHandler.sendChat( p.getOwner(), "Your party is full, " + p.getName() + " is sent to your computer!"); PixelmonStorage.ComputerManager.getPlayerStorage(player).addToComputer(p); return; } if (p.caughtBall == null) p.caughtBall = EnumPokeballs.PokeBall; if (mode == PokeballManagerMode.Player) p.setOwner(player.username); else if (mode == PokeballManagerMode.Trainer) p.setTrainer(trainer); NBTTagCompound n = new NBTTagCompound(); int id = 0; if (mode == PokeballManagerMode.Player) id = new Random().nextInt(32000); else if (mode == PokeballManagerMode.Trainer) id = new Random().nextInt(32000) * -1 - 1; boolean isUsed = false; do { isUsed = false; for (int i = 0; i < partyPokemon.length; i++) { NBTTagCompound nbt = partyPokemon[i]; if (nbt != null) { if (mode == PokeballManagerMode.Player) { id = new Random().nextInt(32000); } else if (mode == PokeballManagerMode.Trainer) { id = new Random().nextInt(32000) * -1 - 1; } } } } while (contains(id)); p.setPokemonId(id); p.writeEntityToStorageNBT(n); p.writeToNBT(n); n.setString("id", "Pixelmon"); n.setName(p.getName()); n.setBoolean("IsInBall", true); n.setBoolean("IsShiny", p.getIsShiny()); n.setInteger("PixelmonOrder", getNextOpen()); if (p.getHeldItem() != null) { n.setCompoundTag("Held Item", p.getHeldItem().writeToNBT(new NBTTagCompound())); } partyPokemon[getNextOpen()] = n; if (p.getHealth() > 0) n.setBoolean("IsFainted", false); if (mode == PokeballManagerMode.Player) ((EntityPlayerMP) player) .playerNetServerHandler.sendPacketToPlayer( new PixelmonDataPacket(n, EnumPackets.AddToStorage).getPacket()); }
public void sendLaserPacket( Vector3 source, Vector3 dest, float r, float g, float b, int age, int energy, int radius) { Side side = FMLCommonHandler.instance().getEffectiveSide(); if (side == Side.SERVER) { ByteArrayOutputStream bos = new ByteArrayOutputStream(8); DataOutputStream outputStream = new DataOutputStream(bos); try { // Write source vector outputStream.writeDouble(source.x); outputStream.writeDouble(source.y); outputStream.writeDouble(source.z); // Write target vector outputStream.writeDouble(dest.x); outputStream.writeDouble(dest.y); outputStream.writeDouble(dest.z); // Write r, g, b of laser outputStream.writeFloat(r); outputStream.writeFloat(g); outputStream.writeFloat(b); // Write age outputStream.writeByte(age); // Write energy value outputStream.writeInt(energy); } catch (Exception ex) { ex.printStackTrace(); } Packet250CustomPayload packet = new Packet250CustomPayload(); packet.channel = "WarpDriveBeam"; packet.data = bos.toByteArray(); packet.length = bos.size(); // Send packet to all players within cloaked area List<Entity> list = worldObj.getEntitiesWithinAABB( EntityPlayerMP.class, AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ)); for (Entity e : list) { if (e != null && e instanceof EntityPlayer) { ((EntityPlayerMP) e).playerNetServerHandler.sendPacketToPlayer(packet); } } } }
/** Create an explosion which only affects a single block. */ @SuppressWarnings("unchecked") public static void explodeBlock(World world, int x, int y, int z) { if (FMLCommonHandler.instance().getEffectiveSide().isClient()) return; Explosion explosion = new Explosion(world, null, x + .5, y + .5, z + .5, 3f); explosion.affectedBlockPositions.add(new ChunkPosition(x, y, z)); explosion.doExplosionB(true); for (EntityPlayer player : (List<EntityPlayer>) world.playerEntities) { if (!(player instanceof EntityPlayerMP)) continue; if (player.getDistanceSq(x, y, z) < 4096) { ((EntityPlayerMP) player) .playerNetServerHandler.sendPacketToPlayer( new Packet60Explosion( x + .5, y + .5, z + .5, 3f, explosion.affectedBlockPositions, null)); } } }
@Override public void onUpdate() { super.onEntityUpdate(); if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); prevRotationYaw = rotationYaw = (float) (Math.atan2(motionX, motionZ) * 180.0D / Math.PI); prevRotationPitch = rotationPitch = (float) (Math.atan2(motionY, f) * 180.0D / Math.PI); } int i = worldObj.getBlockId(xTile, yTile, zTile); if (i > 0) { Block.blocksList[i].setBlockBoundsBasedOnState(worldObj, xTile, yTile, zTile); AxisAlignedBB axisalignedbb = Block.blocksList[i].getCollisionBoundingBoxFromPool(worldObj, xTile, yTile, zTile); if (axisalignedbb != null && axisalignedbb.isVecInside( worldObj.getWorldVec3Pool().getVecFromPool(posX, posY, posZ))) { this.setDead(); } } ++ticksInAir; Vec3 vec3 = worldObj.getWorldVec3Pool().getVecFromPool(posX, posY, posZ); Vec3 vec31 = worldObj.getWorldVec3Pool().getVecFromPool(posX + motionX, posY + motionY, posZ + motionZ); MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks_do_do(vec3, vec31, false, true); vec3 = worldObj.getWorldVec3Pool().getVecFromPool(posX, posY, posZ); vec31 = worldObj.getWorldVec3Pool().getVecFromPool(posX + motionX, posY + motionY, posZ + motionZ); if (movingobjectposition != null) { vec31 = worldObj .getWorldVec3Pool() .getVecFromPool( movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord); } Entity entity = null; List list = worldObj.getEntitiesWithinAABBExcludingEntity( this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D)); double d0 = 0.0D; int l; float f1; for (l = 0; l < list.size(); ++l) { Entity entity1 = (Entity) list.get(l); if (entity1.canBeCollidedWith() && (entity1 != shootingEntity || ticksInAir >= 5)) { f1 = 0.3F; AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand(f1, f1, f1); MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(vec3, vec31); if (movingobjectposition1 != null) { double d1 = vec3.distanceTo(movingobjectposition1.hitVec); if (d1 < d0 || d0 == 0.0D) { entity = entity1; d0 = d1; } } } } if (entity != null) { movingobjectposition = new MovingObjectPosition(entity); } if (movingobjectposition != null && movingobjectposition.entityHit != null && movingobjectposition.entityHit instanceof EntityPlayer) { EntityPlayer entityplayer = (EntityPlayer) movingobjectposition.entityHit; if (entityplayer.capabilities.disableDamage || shootingEntity instanceof EntityPlayer && !((EntityPlayer) shootingEntity).canAttackPlayer(entityplayer)) { movingobjectposition = null; } } float f2; float f3; if (movingobjectposition != null) { if (movingobjectposition.entityHit != null) { f2 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ); DamageSource damagesource = null; if (shootingEntity == null) { damagesource = DamageSource.causeArrowDamage(this, this); } else { damagesource = DamageSource.causeArrowDamage(this, shootingEntity); } if (type == DartType.POISON) { damage = 1; if (movingobjectposition.entityHit instanceof EntityLiving) { // // ((EntityLiving)movingobjectposition.entityHit).addPotionEffect(new // PotionEffect(Potion.poison.id, 100)); ((EntityLiving) movingobjectposition.entityHit) .addPotionEffect(new PotionEffect(Potions.paralysis.get().id, 100)); } } if (movingobjectposition.entityHit.attackEntityFrom(damagesource, damage)) { if (movingobjectposition.entityHit instanceof EntityLiving) { if (shootingEntity != null && movingobjectposition.entityHit != shootingEntity && movingobjectposition.entityHit instanceof EntityPlayer && shootingEntity instanceof EntityPlayerMP) { ((EntityPlayerMP) shootingEntity) .playerNetServerHandler.sendPacketToPlayer(new Packet70GameEvent(6, 0)); } } this.playSound("random.bowhit", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F)); this.setDead(); } else { motionX *= -0.10000000149011612D; motionY *= -0.10000000149011612D; motionZ *= -0.10000000149011612D; rotationYaw += 180.0F; prevRotationYaw += 180.0F; ticksInAir = 0; } } else { xTile = movingobjectposition.blockX; yTile = movingobjectposition.blockY; zTile = movingobjectposition.blockZ; motionX = ((float) (movingobjectposition.hitVec.xCoord - posX)); motionY = ((float) (movingobjectposition.hitVec.yCoord - posY)); motionZ = ((float) (movingobjectposition.hitVec.zCoord - posZ)); f2 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ); posX -= motionX / f2 * 0.05000000074505806D; posY -= motionY / f2 * 0.05000000074505806D; posZ -= motionZ / f2 * 0.05000000074505806D; for (int p = 0; p < 16; ++p) { if (isPoisonous()) { BiomesOPlenty.proxy.spawnParticle("poisondart", posX, posY, posZ); } else { BiomesOPlenty.proxy.spawnParticle("dart", posX, posY, posZ); } } this.playSound("random.bowhit", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F)); this.setDead(); } } posX += motionX; posY += motionY; posZ += motionZ; f2 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); rotationYaw = (float) (Math.atan2(motionX, motionZ) * 180.0D / Math.PI); for (rotationPitch = (float) (Math.atan2(motionY, f2) * 180.0D / Math.PI); rotationPitch - prevRotationPitch < -180.0F; prevRotationPitch -= 360.0F) {; } while (rotationPitch - prevRotationPitch >= 180.0F) { prevRotationPitch += 360.0F; } while (rotationYaw - prevRotationYaw < -180.0F) { prevRotationYaw -= 360.0F; } while (rotationYaw - prevRotationYaw >= 180.0F) { prevRotationYaw += 360.0F; } rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F; rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F; float f4 = 0.99F; f1 = 0.05F; if (this.isInWater()) { for (int j1 = 0; j1 < 4; ++j1) { f3 = 0.25F; worldObj.spawnParticle( "bubble", posX - motionX * f3, posY - motionY * f3, posZ - motionZ * f3, motionX, motionY, motionZ); } f4 = 0.8F; } motionX *= f4; motionY *= f4; motionZ *= f4; motionY -= f1; this.setPosition(posX, posY, posZ); this.doBlockCollisions(); }