001package net.minecraft.world; 002 003import java.util.Iterator; 004import net.minecraft.entity.Entity; 005import net.minecraft.entity.player.EntityPlayer; 006import net.minecraft.entity.player.EntityPlayerMP; 007import net.minecraft.network.packet.Packet55BlockDestroy; 008import net.minecraft.network.packet.Packet61DoorChange; 009import net.minecraft.network.packet.Packet62LevelSound; 010import net.minecraft.server.MinecraftServer; 011 012public class WorldManager implements IWorldAccess 013{ 014 /** Reference to the MinecraftServer object. */ 015 private MinecraftServer mcServer; 016 017 /** The WorldServer object. */ 018 private WorldServer theWorldServer; 019 020 public WorldManager(MinecraftServer par1MinecraftServer, WorldServer par2WorldServer) 021 { 022 this.mcServer = par1MinecraftServer; 023 this.theWorldServer = par2WorldServer; 024 } 025 026 /** 027 * Spawns a particle. Arg: particleType, x, y, z, velX, velY, velZ 028 */ 029 public void spawnParticle(String par1Str, double par2, double par4, double par6, double par8, double par10, double par12) {} 030 031 /** 032 * Called on all IWorldAccesses when an entity is created or loaded. On client worlds, starts downloading any 033 * necessary textures. On server worlds, adds the entity to the entity tracker. 034 */ 035 public void onEntityCreate(Entity par1Entity) 036 { 037 this.theWorldServer.getEntityTracker().addEntityToTracker(par1Entity); 038 } 039 040 /** 041 * Called on all IWorldAccesses when an entity is unloaded or destroyed. On client worlds, releases any downloaded 042 * textures. On server worlds, removes the entity from the entity tracker. 043 */ 044 public void onEntityDestroy(Entity par1Entity) 045 { 046 this.theWorldServer.getEntityTracker().removeEntityFromAllTrackingPlayers(par1Entity); 047 } 048 049 /** 050 * Plays the specified sound. Arg: soundName, x, y, z, volume, pitch 051 */ 052 public void playSound(String par1Str, double par2, double par4, double par6, float par8, float par9) 053 { 054 this.mcServer.getConfigurationManager().sendToAllNear(par2, par4, par6, par8 > 1.0F ? (double)(16.0F * par8) : 16.0D, this.theWorldServer.provider.dimensionId, new Packet62LevelSound(par1Str, par2, par4, par6, par8, par9)); 055 } 056 057 /** 058 * Plays sound to all near players except the player reference given 059 */ 060 public void playSoundToNearExcept(EntityPlayer par1EntityPlayer, String par2Str, double par3, double par5, double par7, float par9, float par10) 061 { 062 this.mcServer.getConfigurationManager().sendToAllNearExcept(par1EntityPlayer, par3, par5, par7, par9 > 1.0F ? (double)(16.0F * par9) : 16.0D, this.theWorldServer.provider.dimensionId, new Packet62LevelSound(par2Str, par3, par5, par7, par9, par10)); 063 } 064 065 /** 066 * On the client, re-renders all blocks in this range, inclusive. On the server, does nothing. Args: min x, min y, 067 * min z, max x, max y, max z 068 */ 069 public void markBlockRangeForRenderUpdate(int par1, int par2, int par3, int par4, int par5, int par6) {} 070 071 /** 072 * On the client, re-renders the block. On the server, sends the block to the client (which will re-render it), 073 * including the tile entity description packet if applicable. Args: x, y, z 074 */ 075 public void markBlockForUpdate(int par1, int par2, int par3) 076 { 077 this.theWorldServer.getPlayerManager().flagChunkForUpdate(par1, par2, par3); 078 } 079 080 /** 081 * On the client, re-renders this block. On the server, does nothing. Used for lighting updates. 082 */ 083 public void markBlockForRenderUpdate(int par1, int par2, int par3) {} 084 085 /** 086 * Plays the specified record. Arg: recordName, x, y, z 087 */ 088 public void playRecord(String par1Str, int par2, int par3, int par4) {} 089 090 /** 091 * Plays a pre-canned sound effect along with potentially auxiliary data-driven one-shot behaviour (particles, etc). 092 */ 093 public void playAuxSFX(EntityPlayer par1EntityPlayer, int par2, int par3, int par4, int par5, int par6) 094 { 095 this.mcServer.getConfigurationManager().sendToAllNearExcept(par1EntityPlayer, (double)par3, (double)par4, (double)par5, 64.0D, this.theWorldServer.provider.dimensionId, new Packet61DoorChange(par2, par3, par4, par5, par6, false)); 096 } 097 098 public void broadcastSound(int par1, int par2, int par3, int par4, int par5) 099 { 100 this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new Packet61DoorChange(par1, par2, par3, par4, par5, true)); 101 } 102 103 /** 104 * Starts (or continues) destroying a block with given ID at the given coordinates for the given partially destroyed 105 * value 106 */ 107 public void destroyBlockPartially(int par1, int par2, int par3, int par4, int par5) 108 { 109 Iterator iterator = this.mcServer.getConfigurationManager().playerEntityList.iterator(); 110 111 while (iterator.hasNext()) 112 { 113 EntityPlayerMP entityplayermp = (EntityPlayerMP)iterator.next(); 114 115 if (entityplayermp != null && entityplayermp.worldObj == this.theWorldServer && entityplayermp.entityId != par1) 116 { 117 double d0 = (double)par2 - entityplayermp.posX; 118 double d1 = (double)par3 - entityplayermp.posY; 119 double d2 = (double)par4 - entityplayermp.posZ; 120 121 if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) 122 { 123 entityplayermp.playerNetServerHandler.sendPacketToPlayer(new Packet55BlockDestroy(par1, par2, par3, par4, par5)); 124 } 125 } 126 } 127 } 128}