diff --git a/src/main/java/net/minecraft/entity/player/EntityPlayerMP.java b/src/main/java/net/minecraft/entity/player/EntityPlayerMP.java index 4fb244f..c6a7cca 100644 --- a/src/main/java/net/minecraft/entity/player/EntityPlayerMP.java +++ b/src/main/java/net/minecraft/entity/player/EntityPlayerMP.java @@ -1,986 +1,986 @@ -package net.minecraft.entity.player; - -import com.google.common.collect.Sets; -import com.mojang.authlib.GameProfile; - -import io.netty.buffer.Unpooled; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import net.minecraft.crash.CrashReport; -import net.minecraft.crash.CrashReportCategory; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityList; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.IMerchant; -import net.minecraft.entity.item.EntityMinecartHopper; -import net.minecraft.entity.passive.EntityHorse; -import net.minecraft.entity.projectile.EntityArrow; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.ContainerBeacon; -import net.minecraft.inventory.ContainerBrewingStand; -import net.minecraft.inventory.ContainerChest; -import net.minecraft.inventory.ContainerDispenser; -import net.minecraft.inventory.ContainerEnchantment; -import net.minecraft.inventory.ContainerFurnace; -import net.minecraft.inventory.ContainerHopper; -import net.minecraft.inventory.ContainerHorseInventory; -import net.minecraft.inventory.ContainerMerchant; -import net.minecraft.inventory.ContainerRepair; -import net.minecraft.inventory.ContainerWorkbench; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.InventoryMerchant; -import net.minecraft.inventory.SlotCrafting; -import net.minecraft.item.EnumAction; -import net.minecraft.item.ItemMapBase; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.NetHandlerPlayServer; -import net.minecraft.network.Packet; -import net.minecraft.network.PacketBuffer; -import net.minecraft.network.play.client.C15PacketClientSettings; -import net.minecraft.network.play.server.S02PacketChat; -import net.minecraft.network.play.server.S06PacketUpdateHealth; -import net.minecraft.network.play.server.S0APacketUseBed; -import net.minecraft.network.play.server.S0BPacketAnimation; -import net.minecraft.network.play.server.S13PacketDestroyEntities; -import net.minecraft.network.play.server.S19PacketEntityStatus; -import net.minecraft.network.play.server.S1BPacketEntityAttach; -import net.minecraft.network.play.server.S1DPacketEntityEffect; -import net.minecraft.network.play.server.S1EPacketRemoveEntityEffect; -import net.minecraft.network.play.server.S1FPacketSetExperience; -import net.minecraft.network.play.server.S26PacketMapChunkBulk; -import net.minecraft.network.play.server.S2BPacketChangeGameState; -import net.minecraft.network.play.server.S2DPacketOpenWindow; -import net.minecraft.network.play.server.S2EPacketCloseWindow; -import net.minecraft.network.play.server.S2FPacketSetSlot; -import net.minecraft.network.play.server.S30PacketWindowItems; -import net.minecraft.network.play.server.S31PacketWindowProperty; -import net.minecraft.network.play.server.S36PacketSignEditorOpen; -import net.minecraft.network.play.server.S39PacketPlayerAbilities; -import net.minecraft.network.play.server.S3FPacketCustomPayload; -import net.minecraft.potion.PotionEffect; -import net.minecraft.scoreboard.IScoreObjectiveCriteria; -import net.minecraft.scoreboard.Score; -import net.minecraft.scoreboard.ScoreObjective; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.management.ItemInWorldManager; -import net.minecraft.stats.AchievementList; -import net.minecraft.stats.StatBase; -import net.minecraft.stats.StatList; -import net.minecraft.stats.StatisticsFile; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityBeacon; -import net.minecraft.tileentity.TileEntityBrewingStand; -import net.minecraft.tileentity.TileEntityDispenser; -import net.minecraft.tileentity.TileEntityDropper; -import net.minecraft.tileentity.TileEntityFurnace; -import net.minecraft.tileentity.TileEntityHopper; -import net.minecraft.tileentity.TileEntitySign; -import net.minecraft.util.ChunkCoordinates; -import net.minecraft.util.DamageSource; -import net.minecraft.util.EntityDamageSource; -import net.minecraft.util.IChatComponent; -import net.minecraft.util.JsonSerializableSet; -import net.minecraft.util.MathHelper; -import net.minecraft.util.ReportedException; -import net.minecraft.village.MerchantRecipeList; -import net.minecraft.world.ChunkCoordIntPair; -import net.minecraft.world.WorldServer; -import net.minecraft.world.WorldSettings; -import net.minecraft.world.biome.BiomeGenBase; -import net.minecraft.world.chunk.Chunk; - -import org.apache.commons.io.Charsets; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.ultramine.server.chunk.ChunkSendManager; - -import net.minecraft.entity.item.EntityItem; -import net.minecraftforge.common.ForgeHooks; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.entity.player.PlayerDropsEvent; -import net.minecraftforge.event.world.ChunkWatchEvent; - -public class EntityPlayerMP extends EntityPlayer implements ICrafting -{ - private static final Logger logger = LogManager.getLogger(); - private String translator = "en_US"; - public NetHandlerPlayServer playerNetServerHandler; - public final MinecraftServer mcServer; - public final ItemInWorldManager theItemInWorldManager; - public double managedPosX; - public double managedPosZ; - public final List loadedChunks = new LinkedList(); - public final List destroyedItemsNetCache = new LinkedList(); - private final StatisticsFile field_147103_bO; - private float field_130068_bO = Float.MIN_VALUE; - private float lastHealth = -1.0E8F; - private int lastFoodLevel = -99999999; - private boolean wasHungry = true; - private int lastExperience = -99999999; - private int field_147101_bU = 60; - private int renderDistance; - private EntityPlayer.EnumChatVisibility chatVisibility; - private boolean chatColours = true; - private long field_143005_bX = 0L; - public int currentWindowId; - public boolean isChangingQuantityOnly; - public int ping; - public boolean playerConqueredTheEnd; - private static final String __OBFID = "CL_00001440"; - - public EntityPlayerMP(MinecraftServer p_i45285_1_, WorldServer p_i45285_2_, GameProfile p_i45285_3_, ItemInWorldManager p_i45285_4_) - { - super(p_i45285_2_, p_i45285_3_); - p_i45285_4_.thisPlayerMP = this; - this.theItemInWorldManager = p_i45285_4_; - this.renderDistance = p_i45285_1_.getConfigurationManager().getViewDistance(); - ChunkCoordinates chunkcoordinates = p_i45285_2_.provider.getRandomizedSpawnPoint(); - int i = chunkcoordinates.posX; - int j = chunkcoordinates.posZ; - int k = chunkcoordinates.posY; - - this.mcServer = p_i45285_1_; - this.field_147103_bO = p_i45285_1_.getConfigurationManager().func_148538_i(this.getCommandSenderName()); - this.stepHeight = 0.0F; - this.yOffset = 0.0F; - this.setLocationAndAngles((double)i + 0.5D, (double)k, (double)j + 0.5D, 0.0F, 0.0F); - - while (!p_i45285_2_.getCollidingBoundingBoxes(this, this.boundingBox).isEmpty()) - { - this.setPosition(this.posX, this.posY + 1.0D, this.posZ); - } - } - - public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) - { - super.readEntityFromNBT(par1NBTTagCompound); - - if (par1NBTTagCompound.hasKey("playerGameType", 99)) - { - if (MinecraftServer.getServer().getForceGamemode()) - { - this.theItemInWorldManager.setGameType(MinecraftServer.getServer().getGameType()); - } - else - { - this.theItemInWorldManager.setGameType(WorldSettings.GameType.getByID(par1NBTTagCompound.getInteger("playerGameType"))); - } - } - } - - public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) - { - super.writeEntityToNBT(par1NBTTagCompound); - par1NBTTagCompound.setInteger("playerGameType", this.theItemInWorldManager.getGameType().getID()); - } - - public void addExperienceLevel(int par1) - { - super.addExperienceLevel(par1); - this.lastExperience = -1; - } - - public void addSelfToInternalCraftingInventory() - { - this.openContainer.addCraftingToCrafters(this); - } - - protected void resetHeight() - { - this.yOffset = 0.0F; - } - - public float getEyeHeight() - { - return super.getEyeHeight(); - } - - public void onUpdate() - { - this.theItemInWorldManager.updateBlockRemoving(); - --this.field_147101_bU; - - if (this.hurtResistantTime > 0) - { - --this.hurtResistantTime; - } - - this.openContainer.detectAndSendChanges(); - - if (!this.worldObj.isRemote && !ForgeHooks.canInteractWith(this, this.openContainer)) - { - this.closeScreen(); - this.openContainer = this.inventoryContainer; - } - - while (!this.destroyedItemsNetCache.isEmpty()) - { - int i = Math.min(this.destroyedItemsNetCache.size(), 127); - int[] aint = new int[i]; - Iterator iterator = this.destroyedItemsNetCache.iterator(); - int j = 0; - - while (iterator.hasNext() && j < i) - { - aint[j++] = ((Integer)iterator.next()).intValue(); - iterator.remove(); - } - - this.playerNetServerHandler.sendPacket(new S13PacketDestroyEntities(aint)); - } - - getChunkMgr().update(); - - if (this.field_143005_bX > 0L && this.mcServer.func_143007_ar() > 0 && MinecraftServer.getSystemTimeMillis() - this.field_143005_bX > (long)(this.mcServer.func_143007_ar() * 1000 * 60)) - { - this.playerNetServerHandler.kickPlayerFromServer("You have been idle for too long!"); - } - } - - public void onUpdateEntity() - { - try - { - super.onUpdate(); - - for (int i = 0; i < this.inventory.getSizeInventory(); ++i) - { - ItemStack itemstack = this.inventory.getStackInSlot(i); - - if (itemstack != null && itemstack.getItem().isMap()) - { - Packet packet = ((ItemMapBase)itemstack.getItem()).func_150911_c(itemstack, this.worldObj, this); - - if (packet != null) - { - this.playerNetServerHandler.sendPacket(packet); - } - } - } - - if (this.getHealth() != this.lastHealth || this.lastFoodLevel != this.foodStats.getFoodLevel() || this.foodStats.getSaturationLevel() == 0.0F != this.wasHungry) - { - this.playerNetServerHandler.sendPacket(new S06PacketUpdateHealth(this.getHealth(), this.foodStats.getFoodLevel(), this.foodStats.getSaturationLevel())); - this.lastHealth = this.getHealth(); - this.lastFoodLevel = this.foodStats.getFoodLevel(); - this.wasHungry = this.foodStats.getSaturationLevel() == 0.0F; - } - - if (this.getHealth() + this.getAbsorptionAmount() != this.field_130068_bO) - { - this.field_130068_bO = this.getHealth() + this.getAbsorptionAmount(); - Collection collection = this.getWorldScoreboard().func_96520_a(IScoreObjectiveCriteria.health); - Iterator iterator = collection.iterator(); - - while (iterator.hasNext()) - { - ScoreObjective scoreobjective = (ScoreObjective)iterator.next(); - this.getWorldScoreboard().func_96529_a(this.getCommandSenderName(), scoreobjective).func_96651_a(Arrays.asList(new EntityPlayer[] {this})); - } - } - - if (this.experienceTotal != this.lastExperience) - { - this.lastExperience = this.experienceTotal; - this.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(this.experience, this.experienceTotal, this.experienceLevel)); - } - - if (this.ticksExisted % 20 * 5 == 0 && !this.func_147099_x().hasAchievementUnlocked(AchievementList.field_150961_L)) - { - this.func_147098_j(); - } - } - catch (Throwable throwable) - { - CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Ticking player"); - CrashReportCategory crashreportcategory = crashreport.makeCategory("Player being ticked"); - this.addEntityCrashInfo(crashreportcategory); - throw new ReportedException(crashreport); - } - } - - protected void func_147098_j() - { - BiomeGenBase biomegenbase = this.worldObj.getBiomeGenForCoords(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posZ)); - - if (biomegenbase != null) - { - String s = biomegenbase.biomeName; - JsonSerializableSet jsonserializableset = (JsonSerializableSet)this.func_147099_x().func_150870_b(AchievementList.field_150961_L); - - if (jsonserializableset == null) - { - jsonserializableset = (JsonSerializableSet)this.func_147099_x().func_150872_a(AchievementList.field_150961_L, new JsonSerializableSet()); - } - - jsonserializableset.add(s); - - if (this.func_147099_x().canUnlockAchievement(AchievementList.field_150961_L) && jsonserializableset.size() == BiomeGenBase.explorationBiomesList.size()) - { - HashSet hashset = Sets.newHashSet(BiomeGenBase.explorationBiomesList); - Iterator iterator = jsonserializableset.iterator(); - - while (iterator.hasNext()) - { - String s1 = (String)iterator.next(); - Iterator iterator1 = hashset.iterator(); - - while (iterator1.hasNext()) - { - BiomeGenBase biomegenbase1 = (BiomeGenBase)iterator1.next(); - - if (biomegenbase1.biomeName.equals(s1)) - { - iterator1.remove(); - } - } - - if (hashset.isEmpty()) - { - break; - } - } - - if (hashset.isEmpty()) - { - this.triggerAchievement(AchievementList.field_150961_L); - } - } - } - } - - public void onDeath(DamageSource par1DamageSource) - { - if (ForgeHooks.onLivingDeath(this, par1DamageSource)) return; - this.mcServer.getConfigurationManager().sendChatMsg(this.func_110142_aN().func_151521_b()); - - if (!this.worldObj.getGameRules().getGameRuleBooleanValue("keepInventory")) - { - captureDrops = true; - capturedDrops.clear(); - - this.inventory.dropAllItems(); - - captureDrops = false; - PlayerDropsEvent event = new PlayerDropsEvent(this, par1DamageSource, capturedDrops, recentlyHit > 0); - if (!MinecraftForge.EVENT_BUS.post(event)) - { - for (EntityItem item : capturedDrops) - { - joinEntityItemWithWorld(item); - } - } - } - - Collection collection = this.worldObj.getScoreboard().func_96520_a(IScoreObjectiveCriteria.deathCount); - Iterator iterator = collection.iterator(); - - while (iterator.hasNext()) - { - ScoreObjective scoreobjective = (ScoreObjective)iterator.next(); - Score score = this.getWorldScoreboard().func_96529_a(this.getCommandSenderName(), scoreobjective); - score.func_96648_a(); - } - - EntityLivingBase entitylivingbase = this.func_94060_bK(); - - if (entitylivingbase != null) - { - int i = EntityList.getEntityID(entitylivingbase); - EntityList.EntityEggInfo entityegginfo = (EntityList.EntityEggInfo)EntityList.entityEggs.get(Integer.valueOf(i)); - - if (entityegginfo != null) - { - this.addStat(entityegginfo.field_151513_e, 1); - } - - entitylivingbase.addToPlayerScore(this, this.scoreValue); - } - - this.addStat(StatList.deathsStat, 1); - } - - public boolean attackEntityFrom(DamageSource par1DamageSource, float par2) - { - if (this.isEntityInvulnerable()) - { - return false; - } - else - { - boolean flag = this.mcServer.isDedicatedServer() && this.mcServer.isPVPEnabled() && "fall".equals(par1DamageSource.damageType); - - if (!flag && this.field_147101_bU > 0 && par1DamageSource != DamageSource.outOfWorld) - { - return false; - } - else - { - if (par1DamageSource instanceof EntityDamageSource) - { - Entity entity = par1DamageSource.getEntity(); - - if (entity instanceof EntityPlayer && !this.canAttackPlayer((EntityPlayer)entity)) - { - return false; - } - - if (entity instanceof EntityArrow) - { - EntityArrow entityarrow = (EntityArrow)entity; - - if (entityarrow.shootingEntity instanceof EntityPlayer && !this.canAttackPlayer((EntityPlayer)entityarrow.shootingEntity)) - { - return false; - } - } - } - - return super.attackEntityFrom(par1DamageSource, par2); - } - } - } - - public boolean canAttackPlayer(EntityPlayer par1EntityPlayer) - { - return !this.mcServer.isPVPEnabled() ? false : super.canAttackPlayer(par1EntityPlayer); - } - - public void travelToDimension(int par1) - { - if (this.dimension == 1 && par1 == 1) - { - this.triggerAchievement(AchievementList.theEnd2); - this.worldObj.removeEntity(this); - this.playerConqueredTheEnd = true; - this.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(4, 0.0F)); - } - else - { - if (this.dimension == 0 && par1 == 1) - { - this.triggerAchievement(AchievementList.theEnd); - ChunkCoordinates chunkcoordinates = this.mcServer.worldServerForDimension(par1).getEntrancePortalLocation(); - - if (chunkcoordinates != null) - { - this.playerNetServerHandler.setPlayerLocation((double)chunkcoordinates.posX, (double)chunkcoordinates.posY, (double)chunkcoordinates.posZ, 0.0F, 0.0F); - } - - par1 = 1; - } - else - { - this.triggerAchievement(AchievementList.portal); - } - - this.mcServer.getConfigurationManager().transferPlayerToDimension(this, par1); - this.lastExperience = -1; - this.lastHealth = -1.0F; - this.lastFoodLevel = -1; - } - } - - private void func_147097_b(TileEntity p_147097_1_) - { - if (p_147097_1_ != null) - { - Packet packet = p_147097_1_.getDescriptionPacket(); - - if (packet != null) - { - this.playerNetServerHandler.sendPacket(packet); - } - } - } - - public void onItemPickup(Entity par1Entity, int par2) - { - super.onItemPickup(par1Entity, par2); - this.openContainer.detectAndSendChanges(); - } - - public EntityPlayer.EnumStatus sleepInBedAt(int par1, int par2, int par3) - { - EntityPlayer.EnumStatus enumstatus = super.sleepInBedAt(par1, par2, par3); - - if (enumstatus == EntityPlayer.EnumStatus.OK) - { - S0APacketUseBed s0apacketusebed = new S0APacketUseBed(this, par1, par2, par3); - this.getServerForPlayer().getEntityTracker().func_151247_a(this, s0apacketusebed); - this.playerNetServerHandler.setPlayerLocation(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch); - this.playerNetServerHandler.sendPacket(s0apacketusebed); - } - - return enumstatus; - } - - public void wakeUpPlayer(boolean par1, boolean par2, boolean par3) - { - if (this.isPlayerSleeping()) - { - this.getServerForPlayer().getEntityTracker().func_151248_b(this, new S0BPacketAnimation(this, 2)); - } - - super.wakeUpPlayer(par1, par2, par3); - - if (this.playerNetServerHandler != null) - { - this.playerNetServerHandler.setPlayerLocation(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch); - } - } - - public void mountEntity(Entity par1Entity) - { - super.mountEntity(par1Entity); - this.playerNetServerHandler.sendPacket(new S1BPacketEntityAttach(0, this, this.ridingEntity)); - this.playerNetServerHandler.setPlayerLocation(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch); - } - - protected void updateFallState(double par1, boolean par3) {} - - public void handleFalling(double par1, boolean par3) - { - super.updateFallState(par1, par3); - } - - public void func_146100_a(TileEntity p_146100_1_) - { - if (p_146100_1_ instanceof TileEntitySign) - { - ((TileEntitySign)p_146100_1_).func_145912_a(this); - this.playerNetServerHandler.sendPacket(new S36PacketSignEditorOpen(p_146100_1_.xCoord, p_146100_1_.yCoord, p_146100_1_.zCoord)); - } - } - - public void getNextWindowId() - { - this.currentWindowId = this.currentWindowId % 100 + 1; - } - - public void displayGUIWorkbench(int par1, int par2, int par3) - { - this.getNextWindowId(); - this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 1, "Crafting", 9, true)); - this.openContainer = new ContainerWorkbench(this.inventory, this.worldObj, par1, par2, par3); - this.openContainer.windowId = this.currentWindowId; - this.openContainer.addCraftingToCrafters(this); - } - - public void displayGUIEnchantment(int par1, int par2, int par3, String par4Str) - { - this.getNextWindowId(); - this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 4, par4Str == null ? "" : par4Str, 9, par4Str != null)); - this.openContainer = new ContainerEnchantment(this.inventory, this.worldObj, par1, par2, par3); - this.openContainer.windowId = this.currentWindowId; - this.openContainer.addCraftingToCrafters(this); - } - - public void displayGUIAnvil(int par1, int par2, int par3) - { - this.getNextWindowId(); - this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 8, "Repairing", 9, true)); - this.openContainer = new ContainerRepair(this.inventory, this.worldObj, par1, par2, par3, this); - this.openContainer.windowId = this.currentWindowId; - this.openContainer.addCraftingToCrafters(this); - } - - public void displayGUIChest(IInventory par1IInventory) - { - if (this.openContainer != this.inventoryContainer) - { - this.closeScreen(); - } - - this.getNextWindowId(); - this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 0, par1IInventory.getInventoryName(), par1IInventory.getSizeInventory(), par1IInventory.hasCustomInventoryName())); - this.openContainer = new ContainerChest(this.inventory, par1IInventory); - this.openContainer.windowId = this.currentWindowId; - this.openContainer.addCraftingToCrafters(this); - } - - public void func_146093_a(TileEntityHopper p_146093_1_) - { - this.getNextWindowId(); - this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 9, p_146093_1_.getInventoryName(), p_146093_1_.getSizeInventory(), p_146093_1_.hasCustomInventoryName())); - this.openContainer = new ContainerHopper(this.inventory, p_146093_1_); - this.openContainer.windowId = this.currentWindowId; - this.openContainer.addCraftingToCrafters(this); - } - - public void displayGUIHopperMinecart(EntityMinecartHopper par1EntityMinecartHopper) - { - this.getNextWindowId(); - this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 9, par1EntityMinecartHopper.getInventoryName(), par1EntityMinecartHopper.getSizeInventory(), par1EntityMinecartHopper.hasCustomInventoryName())); - this.openContainer = new ContainerHopper(this.inventory, par1EntityMinecartHopper); - this.openContainer.windowId = this.currentWindowId; - this.openContainer.addCraftingToCrafters(this); - } - - public void func_146101_a(TileEntityFurnace p_146101_1_) - { - this.getNextWindowId(); - this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 2, p_146101_1_.getInventoryName(), p_146101_1_.getSizeInventory(), p_146101_1_.hasCustomInventoryName())); - this.openContainer = new ContainerFurnace(this.inventory, p_146101_1_); - this.openContainer.windowId = this.currentWindowId; - this.openContainer.addCraftingToCrafters(this); - } - - public void func_146102_a(TileEntityDispenser p_146102_1_) - { - this.getNextWindowId(); - this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, p_146102_1_ instanceof TileEntityDropper ? 10 : 3, p_146102_1_.getInventoryName(), p_146102_1_.getSizeInventory(), p_146102_1_.hasCustomInventoryName())); - this.openContainer = new ContainerDispenser(this.inventory, p_146102_1_); - this.openContainer.windowId = this.currentWindowId; - this.openContainer.addCraftingToCrafters(this); - } - - public void func_146098_a(TileEntityBrewingStand p_146098_1_) - { - this.getNextWindowId(); - this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 5, p_146098_1_.getInventoryName(), p_146098_1_.getSizeInventory(), p_146098_1_.hasCustomInventoryName())); - this.openContainer = new ContainerBrewingStand(this.inventory, p_146098_1_); - this.openContainer.windowId = this.currentWindowId; - this.openContainer.addCraftingToCrafters(this); - } - - public void func_146104_a(TileEntityBeacon p_146104_1_) - { - this.getNextWindowId(); - this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 7, p_146104_1_.getInventoryName(), p_146104_1_.getSizeInventory(), p_146104_1_.hasCustomInventoryName())); - this.openContainer = new ContainerBeacon(this.inventory, p_146104_1_); - this.openContainer.windowId = this.currentWindowId; - this.openContainer.addCraftingToCrafters(this); - } - - public void displayGUIMerchant(IMerchant par1IMerchant, String par2Str) - { - this.getNextWindowId(); - this.openContainer = new ContainerMerchant(this.inventory, par1IMerchant, this.worldObj); - this.openContainer.windowId = this.currentWindowId; - this.openContainer.addCraftingToCrafters(this); - InventoryMerchant inventorymerchant = ((ContainerMerchant)this.openContainer).getMerchantInventory(); - this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 6, par2Str == null ? "" : par2Str, inventorymerchant.getSizeInventory(), par2Str != null)); - MerchantRecipeList merchantrecipelist = par1IMerchant.getRecipes(this); - - if (merchantrecipelist != null) - { - try - { - PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer()); - packetbuffer.writeInt(this.currentWindowId); - merchantrecipelist.func_151391_a(packetbuffer); - this.playerNetServerHandler.sendPacket(new S3FPacketCustomPayload("MC|TrList", packetbuffer)); - } - catch (IOException ioexception) - { - logger.error("Couldn\'t send trade list", ioexception); - } - } - } - - public void displayGUIHorse(EntityHorse par1EntityHorse, IInventory par2IInventory) - { - if (this.openContainer != this.inventoryContainer) - { - this.closeScreen(); - } - - this.getNextWindowId(); - this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 11, par2IInventory.getInventoryName(), par2IInventory.getSizeInventory(), par2IInventory.hasCustomInventoryName(), par1EntityHorse.getEntityId())); - this.openContainer = new ContainerHorseInventory(this.inventory, par2IInventory, par1EntityHorse); - this.openContainer.windowId = this.currentWindowId; - this.openContainer.addCraftingToCrafters(this); - } - - public void sendSlotContents(Container par1Container, int par2, ItemStack par3ItemStack) - { - if (!(par1Container.getSlot(par2) instanceof SlotCrafting)) - { - if (!this.isChangingQuantityOnly) - { - this.playerNetServerHandler.sendPacket(new S2FPacketSetSlot(par1Container.windowId, par2, par3ItemStack)); - } - } - } - - public void sendContainerToPlayer(Container par1Container) - { - this.sendContainerAndContentsToPlayer(par1Container, par1Container.getInventory()); - } - - public void sendContainerAndContentsToPlayer(Container par1Container, List par2List) - { - this.playerNetServerHandler.sendPacket(new S30PacketWindowItems(par1Container.windowId, par2List)); - this.playerNetServerHandler.sendPacket(new S2FPacketSetSlot(-1, -1, this.inventory.getItemStack())); - } - - public void sendProgressBarUpdate(Container par1Container, int par2, int par3) - { - this.playerNetServerHandler.sendPacket(new S31PacketWindowProperty(par1Container.windowId, par2, par3)); - } - - public void closeScreen() - { - this.playerNetServerHandler.sendPacket(new S2EPacketCloseWindow(this.openContainer.windowId)); - this.closeContainer(); - } - - public void updateHeldItem() - { - if (!this.isChangingQuantityOnly) - { - this.playerNetServerHandler.sendPacket(new S2FPacketSetSlot(-1, -1, this.inventory.getItemStack())); - } - } - - public void closeContainer() - { - this.openContainer.onContainerClosed(this); - this.openContainer = this.inventoryContainer; - } - - public void setEntityActionState(float par1, float par2, boolean par3, boolean par4) - { - if (this.ridingEntity != null) - { - if (par1 >= -1.0F && par1 <= 1.0F) - { - this.moveStrafing = par1; - } - - if (par2 >= -1.0F && par2 <= 1.0F) - { - this.moveForward = par2; - } - - this.isJumping = par3; - this.setSneaking(par4); - } - } - - public void addStat(StatBase par1StatBase, int par2) - { - if (par1StatBase != null) - { - this.field_147103_bO.func_150871_b(this, par1StatBase, par2); - Iterator iterator = this.getWorldScoreboard().func_96520_a(par1StatBase.func_150952_k()).iterator(); - - while (iterator.hasNext()) - { - ScoreObjective scoreobjective = (ScoreObjective)iterator.next(); - this.getWorldScoreboard().func_96529_a(this.getCommandSenderName(), scoreobjective).func_96648_a(); - } - - if (this.field_147103_bO.func_150879_e()) - { - this.field_147103_bO.func_150876_a(this); - } - } - } - - public void mountEntityAndWakeUp() - { - if (this.riddenByEntity != null) - { - this.riddenByEntity.mountEntity(this); - } - - if (this.sleeping) - { - this.wakeUpPlayer(true, false, false); - } - } - - public void setPlayerHealthUpdated() - { - this.lastHealth = -1.0E8F; - } - - public void addChatComponentMessage(IChatComponent p_146105_1_) - { - this.playerNetServerHandler.sendPacket(new S02PacketChat(p_146105_1_)); - } - - protected void onItemUseFinish() - { - this.playerNetServerHandler.sendPacket(new S19PacketEntityStatus(this, (byte)9)); - super.onItemUseFinish(); - } - - public void setItemInUse(ItemStack par1ItemStack, int par2) - { - super.setItemInUse(par1ItemStack, par2); - - if (par1ItemStack != null && par1ItemStack.getItem() != null && par1ItemStack.getItem().getItemUseAction(par1ItemStack) == EnumAction.eat) - { - this.getServerForPlayer().getEntityTracker().func_151248_b(this, new S0BPacketAnimation(this, 3)); - } - } - - public void clonePlayer(EntityPlayer par1EntityPlayer, boolean par2) - { - super.clonePlayer(par1EntityPlayer, par2); - this.lastExperience = -1; - this.lastHealth = -1.0F; - this.lastFoodLevel = -1; - this.destroyedItemsNetCache.addAll(((EntityPlayerMP)par1EntityPlayer).destroyedItemsNetCache); - } - - protected void onNewPotionEffect(PotionEffect par1PotionEffect) - { - super.onNewPotionEffect(par1PotionEffect); - this.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(this.getEntityId(), par1PotionEffect)); - } - - protected void onChangedPotionEffect(PotionEffect par1PotionEffect, boolean par2) - { - super.onChangedPotionEffect(par1PotionEffect, par2); - this.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(this.getEntityId(), par1PotionEffect)); - } - - protected void onFinishedPotionEffect(PotionEffect par1PotionEffect) - { - super.onFinishedPotionEffect(par1PotionEffect); - this.playerNetServerHandler.sendPacket(new S1EPacketRemoveEntityEffect(this.getEntityId(), par1PotionEffect)); - } - - public void setPositionAndUpdate(double par1, double par3, double par5) - { - this.playerNetServerHandler.setPlayerLocation(par1, par3, par5, this.rotationYaw, this.rotationPitch); - } - - public void onCriticalHit(Entity par1Entity) - { - this.getServerForPlayer().getEntityTracker().func_151248_b(this, new S0BPacketAnimation(par1Entity, 4)); - } - - public void onEnchantmentCritical(Entity par1Entity) - { - this.getServerForPlayer().getEntityTracker().func_151248_b(this, new S0BPacketAnimation(par1Entity, 5)); - } - - public void sendPlayerAbilities() - { - if (this.playerNetServerHandler != null) - { - this.playerNetServerHandler.sendPacket(new S39PacketPlayerAbilities(this.capabilities)); - } - } - - public WorldServer getServerForPlayer() - { - return (WorldServer)this.worldObj; - } - - public void setGameType(WorldSettings.GameType par1EnumGameType) - { - this.theItemInWorldManager.setGameType(par1EnumGameType); - this.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(3, (float)par1EnumGameType.getID())); - } - - public void addChatMessage(IChatComponent p_145747_1_) - { - this.playerNetServerHandler.sendPacket(new S02PacketChat(p_145747_1_)); - } - - public boolean canCommandSenderUseCommand(int par1, String par2Str) - { - return "seed".equals(par2Str) && !this.mcServer.isDedicatedServer() ? true : (!"tell".equals(par2Str) && !"help".equals(par2Str) && !"me".equals(par2Str) ? (this.mcServer.getConfigurationManager().isPlayerOpped(this.getCommandSenderName()) ? this.mcServer.getOpPermissionLevel() >= par1 : false) : true); - } - - public String getPlayerIP() - { - String s = this.playerNetServerHandler.netManager.getSocketAddress().toString(); - s = s.substring(s.indexOf("/") + 1); - s = s.substring(0, s.indexOf(":")); - return s; - } - - public void func_147100_a(C15PacketClientSettings p_147100_1_) - { - this.translator = p_147100_1_.func_149524_c(); - int i = /*256 >>*/ p_147100_1_.func_149521_d(); - - if (i > 3 && i < 15) - { - this.renderDistance = i; - } - - this.chatVisibility = p_147100_1_.func_149523_e(); - this.chatColours = p_147100_1_.func_149520_f(); - - if (this.mcServer.isSinglePlayer() && this.mcServer.getServerOwner().equals(this.getCommandSenderName())) - { - this.mcServer.func_147139_a(p_147100_1_.func_149518_g()); - } - - this.setHideCape(1, !p_147100_1_.func_149519_h()); - } - - public EntityPlayer.EnumChatVisibility func_147096_v() - { - return this.chatVisibility; - } - - public void requestTexturePackLoad(String p_147095_1_) - { - this.playerNetServerHandler.sendPacket(new S3FPacketCustomPayload("MC|RPack", p_147095_1_.getBytes(Charsets.UTF_8))); - } - - public ChunkCoordinates getPlayerCoordinates() - { - return new ChunkCoordinates(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY + 0.5D), MathHelper.floor_double(this.posZ)); - } - - public void func_143004_u() - { - this.field_143005_bX = MinecraftServer.getSystemTimeMillis(); - } - - public StatisticsFile func_147099_x() - { - return this.field_147103_bO; - } - - /* ===================================== FORGE START =====================================*/ - /** - * Returns the default eye height of the player - * @return player default eye height - */ - @Override - public float getDefaultEyeHeight() - { - return 1.62F; - } - - /* ===================================== ULTRAMINE START =====================================*/ - - private final ChunkSendManager chunkMgr = new ChunkSendManager(this); - - @Override - public boolean isEntityPlayerMP() - { - return true; - } - - public ChunkSendManager getChunkMgr() - { - return chunkMgr; - } - - public int getRenderDistance() - { - return renderDistance; - } +package net.minecraft.entity.player; + +import com.google.common.collect.Sets; +import com.mojang.authlib.GameProfile; + +import io.netty.buffer.Unpooled; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.IMerchant; +import net.minecraft.entity.item.EntityMinecartHopper; +import net.minecraft.entity.passive.EntityHorse; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ContainerBeacon; +import net.minecraft.inventory.ContainerBrewingStand; +import net.minecraft.inventory.ContainerChest; +import net.minecraft.inventory.ContainerDispenser; +import net.minecraft.inventory.ContainerEnchantment; +import net.minecraft.inventory.ContainerFurnace; +import net.minecraft.inventory.ContainerHopper; +import net.minecraft.inventory.ContainerHorseInventory; +import net.minecraft.inventory.ContainerMerchant; +import net.minecraft.inventory.ContainerRepair; +import net.minecraft.inventory.ContainerWorkbench; +import net.minecraft.inventory.ICrafting; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.InventoryMerchant; +import net.minecraft.inventory.SlotCrafting; +import net.minecraft.item.EnumAction; +import net.minecraft.item.ItemMapBase; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetHandlerPlayServer; +import net.minecraft.network.Packet; +import net.minecraft.network.PacketBuffer; +import net.minecraft.network.play.client.C15PacketClientSettings; +import net.minecraft.network.play.server.S02PacketChat; +import net.minecraft.network.play.server.S06PacketUpdateHealth; +import net.minecraft.network.play.server.S0APacketUseBed; +import net.minecraft.network.play.server.S0BPacketAnimation; +import net.minecraft.network.play.server.S13PacketDestroyEntities; +import net.minecraft.network.play.server.S19PacketEntityStatus; +import net.minecraft.network.play.server.S1BPacketEntityAttach; +import net.minecraft.network.play.server.S1DPacketEntityEffect; +import net.minecraft.network.play.server.S1EPacketRemoveEntityEffect; +import net.minecraft.network.play.server.S1FPacketSetExperience; +import net.minecraft.network.play.server.S26PacketMapChunkBulk; +import net.minecraft.network.play.server.S2BPacketChangeGameState; +import net.minecraft.network.play.server.S2DPacketOpenWindow; +import net.minecraft.network.play.server.S2EPacketCloseWindow; +import net.minecraft.network.play.server.S2FPacketSetSlot; +import net.minecraft.network.play.server.S30PacketWindowItems; +import net.minecraft.network.play.server.S31PacketWindowProperty; +import net.minecraft.network.play.server.S36PacketSignEditorOpen; +import net.minecraft.network.play.server.S39PacketPlayerAbilities; +import net.minecraft.network.play.server.S3FPacketCustomPayload; +import net.minecraft.potion.PotionEffect; +import net.minecraft.scoreboard.IScoreObjectiveCriteria; +import net.minecraft.scoreboard.Score; +import net.minecraft.scoreboard.ScoreObjective; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.management.ItemInWorldManager; +import net.minecraft.stats.AchievementList; +import net.minecraft.stats.StatBase; +import net.minecraft.stats.StatList; +import net.minecraft.stats.StatisticsFile; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityBeacon; +import net.minecraft.tileentity.TileEntityBrewingStand; +import net.minecraft.tileentity.TileEntityDispenser; +import net.minecraft.tileentity.TileEntityDropper; +import net.minecraft.tileentity.TileEntityFurnace; +import net.minecraft.tileentity.TileEntityHopper; +import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EntityDamageSource; +import net.minecraft.util.IChatComponent; +import net.minecraft.util.JsonSerializableSet; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ReportedException; +import net.minecraft.village.MerchantRecipeList; +import net.minecraft.world.ChunkCoordIntPair; +import net.minecraft.world.WorldServer; +import net.minecraft.world.WorldSettings; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.world.chunk.Chunk; + +import org.apache.commons.io.Charsets; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.ultramine.server.chunk.ChunkSendManager; + +import net.minecraft.entity.item.EntityItem; +import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.player.PlayerDropsEvent; +import net.minecraftforge.event.world.ChunkWatchEvent; + +public class EntityPlayerMP extends EntityPlayer implements ICrafting +{ + private static final Logger logger = LogManager.getLogger(); + private String translator = "en_US"; + public NetHandlerPlayServer playerNetServerHandler; + public final MinecraftServer mcServer; + public final ItemInWorldManager theItemInWorldManager; + public double managedPosX; + public double managedPosZ; + public final List loadedChunks = new LinkedList(); + public final List destroyedItemsNetCache = new LinkedList(); + private final StatisticsFile field_147103_bO; + private float field_130068_bO = Float.MIN_VALUE; + private float lastHealth = -1.0E8F; + private int lastFoodLevel = -99999999; + private boolean wasHungry = true; + private int lastExperience = -99999999; + private int field_147101_bU = 60; + private int renderDistance; + private EntityPlayer.EnumChatVisibility chatVisibility; + private boolean chatColours = true; + private long field_143005_bX = 0L; + public int currentWindowId; + public boolean isChangingQuantityOnly; + public int ping; + public boolean playerConqueredTheEnd; + private static final String __OBFID = "CL_00001440"; + + public EntityPlayerMP(MinecraftServer p_i45285_1_, WorldServer p_i45285_2_, GameProfile p_i45285_3_, ItemInWorldManager p_i45285_4_) + { + super(p_i45285_2_, p_i45285_3_); + p_i45285_4_.thisPlayerMP = this; + this.theItemInWorldManager = p_i45285_4_; + this.renderDistance = p_i45285_1_.getConfigurationManager().getViewDistance(); + ChunkCoordinates chunkcoordinates = p_i45285_2_.provider.getRandomizedSpawnPoint(); + int i = chunkcoordinates.posX; + int j = chunkcoordinates.posZ; + int k = chunkcoordinates.posY; + + this.mcServer = p_i45285_1_; + this.field_147103_bO = p_i45285_1_.getConfigurationManager().func_148538_i(this.getCommandSenderName()); + this.stepHeight = 0.0F; + this.yOffset = 0.0F; + this.setLocationAndAngles((double)i + 0.5D, (double)k, (double)j + 0.5D, 0.0F, 0.0F); + + while (!p_i45285_2_.getCollidingBoundingBoxes(this, this.boundingBox).isEmpty()) + { + this.setPosition(this.posX, this.posY + 1.0D, this.posZ); + } + } + + public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) + { + super.readEntityFromNBT(par1NBTTagCompound); + + if (par1NBTTagCompound.hasKey("playerGameType", 99)) + { + if (MinecraftServer.getServer().getForceGamemode()) + { + this.theItemInWorldManager.setGameType(MinecraftServer.getServer().getGameType()); + } + else + { + this.theItemInWorldManager.setGameType(WorldSettings.GameType.getByID(par1NBTTagCompound.getInteger("playerGameType"))); + } + } + } + + public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) + { + super.writeEntityToNBT(par1NBTTagCompound); + par1NBTTagCompound.setInteger("playerGameType", this.theItemInWorldManager.getGameType().getID()); + } + + public void addExperienceLevel(int par1) + { + super.addExperienceLevel(par1); + this.lastExperience = -1; + } + + public void addSelfToInternalCraftingInventory() + { + this.openContainer.addCraftingToCrafters(this); + } + + protected void resetHeight() + { + this.yOffset = 0.0F; + } + + public float getEyeHeight() + { + return super.getEyeHeight(); + } + + public void onUpdate() + { + this.theItemInWorldManager.updateBlockRemoving(); + --this.field_147101_bU; + + if (this.hurtResistantTime > 0) + { + --this.hurtResistantTime; + } + + this.openContainer.detectAndSendChanges(); + + if (!this.worldObj.isRemote && !ForgeHooks.canInteractWith(this, this.openContainer)) + { + this.closeScreen(); + this.openContainer = this.inventoryContainer; + } + + while (!this.destroyedItemsNetCache.isEmpty()) + { + int i = Math.min(this.destroyedItemsNetCache.size(), 127); + int[] aint = new int[i]; + Iterator iterator = this.destroyedItemsNetCache.iterator(); + int j = 0; + + while (iterator.hasNext() && j < i) + { + aint[j++] = ((Integer)iterator.next()).intValue(); + iterator.remove(); + } + + this.playerNetServerHandler.sendPacket(new S13PacketDestroyEntities(aint)); + } + + getChunkMgr().update(); + + if (this.field_143005_bX > 0L && this.mcServer.func_143007_ar() > 0 && MinecraftServer.getSystemTimeMillis() - this.field_143005_bX > (long)(this.mcServer.func_143007_ar() * 1000 * 60)) + { + this.playerNetServerHandler.kickPlayerFromServer("You have been idle for too long!"); + } + } + + public void onUpdateEntity() + { + try + { + super.onUpdate(); + + for (int i = 0; i < this.inventory.getSizeInventory(); ++i) + { + ItemStack itemstack = this.inventory.getStackInSlot(i); + + if (itemstack != null && itemstack.getItem().isMap()) + { + Packet packet = ((ItemMapBase)itemstack.getItem()).func_150911_c(itemstack, this.worldObj, this); + + if (packet != null) + { + this.playerNetServerHandler.sendPacket(packet); + } + } + } + + if (this.getHealth() != this.lastHealth || this.lastFoodLevel != this.foodStats.getFoodLevel() || this.foodStats.getSaturationLevel() == 0.0F != this.wasHungry) + { + this.playerNetServerHandler.sendPacket(new S06PacketUpdateHealth(this.getHealth(), this.foodStats.getFoodLevel(), this.foodStats.getSaturationLevel())); + this.lastHealth = this.getHealth(); + this.lastFoodLevel = this.foodStats.getFoodLevel(); + this.wasHungry = this.foodStats.getSaturationLevel() == 0.0F; + } + + if (this.getHealth() + this.getAbsorptionAmount() != this.field_130068_bO) + { + this.field_130068_bO = this.getHealth() + this.getAbsorptionAmount(); + Collection collection = this.getWorldScoreboard().func_96520_a(IScoreObjectiveCriteria.health); + Iterator iterator = collection.iterator(); + + while (iterator.hasNext()) + { + ScoreObjective scoreobjective = (ScoreObjective)iterator.next(); + this.getWorldScoreboard().func_96529_a(this.getCommandSenderName(), scoreobjective).func_96651_a(Arrays.asList(new EntityPlayer[] {this})); + } + } + + if (this.experienceTotal != this.lastExperience) + { + this.lastExperience = this.experienceTotal; + this.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(this.experience, this.experienceTotal, this.experienceLevel)); + } + + if (this.ticksExisted % 20 * 5 == 0 && !this.func_147099_x().hasAchievementUnlocked(AchievementList.field_150961_L)) + { + this.func_147098_j(); + } + } + catch (Throwable throwable) + { + CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Ticking player"); + CrashReportCategory crashreportcategory = crashreport.makeCategory("Player being ticked"); + this.addEntityCrashInfo(crashreportcategory); + throw new ReportedException(crashreport); + } + } + + protected void func_147098_j() + { + BiomeGenBase biomegenbase = this.worldObj.getBiomeGenForCoords(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posZ)); + + if (biomegenbase != null) + { + String s = biomegenbase.biomeName; + JsonSerializableSet jsonserializableset = (JsonSerializableSet)this.func_147099_x().func_150870_b(AchievementList.field_150961_L); + + if (jsonserializableset == null) + { + jsonserializableset = (JsonSerializableSet)this.func_147099_x().func_150872_a(AchievementList.field_150961_L, new JsonSerializableSet()); + } + + jsonserializableset.add(s); + + if (this.func_147099_x().canUnlockAchievement(AchievementList.field_150961_L) && jsonserializableset.size() == BiomeGenBase.explorationBiomesList.size()) + { + HashSet hashset = Sets.newHashSet(BiomeGenBase.explorationBiomesList); + Iterator iterator = jsonserializableset.iterator(); + + while (iterator.hasNext()) + { + String s1 = (String)iterator.next(); + Iterator iterator1 = hashset.iterator(); + + while (iterator1.hasNext()) + { + BiomeGenBase biomegenbase1 = (BiomeGenBase)iterator1.next(); + + if (biomegenbase1.biomeName.equals(s1)) + { + iterator1.remove(); + } + } + + if (hashset.isEmpty()) + { + break; + } + } + + if (hashset.isEmpty()) + { + this.triggerAchievement(AchievementList.field_150961_L); + } + } + } + } + + public void onDeath(DamageSource par1DamageSource) + { + if (ForgeHooks.onLivingDeath(this, par1DamageSource)) return; + this.mcServer.getConfigurationManager().sendChatMsg(this.func_110142_aN().func_151521_b()); + + if (!this.worldObj.getGameRules().getGameRuleBooleanValue("keepInventory")) + { + captureDrops = true; + capturedDrops.clear(); + + this.inventory.dropAllItems(); + + captureDrops = false; + PlayerDropsEvent event = new PlayerDropsEvent(this, par1DamageSource, capturedDrops, recentlyHit > 0); + if (!MinecraftForge.EVENT_BUS.post(event)) + { + for (EntityItem item : capturedDrops) + { + joinEntityItemWithWorld(item); + } + } + } + + Collection collection = this.worldObj.getScoreboard().func_96520_a(IScoreObjectiveCriteria.deathCount); + Iterator iterator = collection.iterator(); + + while (iterator.hasNext()) + { + ScoreObjective scoreobjective = (ScoreObjective)iterator.next(); + Score score = this.getWorldScoreboard().func_96529_a(this.getCommandSenderName(), scoreobjective); + score.func_96648_a(); + } + + EntityLivingBase entitylivingbase = this.func_94060_bK(); + + if (entitylivingbase != null) + { + int i = EntityList.getEntityID(entitylivingbase); + EntityList.EntityEggInfo entityegginfo = (EntityList.EntityEggInfo)EntityList.entityEggs.get(Integer.valueOf(i)); + + if (entityegginfo != null) + { + this.addStat(entityegginfo.field_151513_e, 1); + } + + entitylivingbase.addToPlayerScore(this, this.scoreValue); + } + + this.addStat(StatList.deathsStat, 1); + } + + public boolean attackEntityFrom(DamageSource par1DamageSource, float par2) + { + if (this.isEntityInvulnerable()) + { + return false; + } + else + { + boolean flag = this.mcServer.isDedicatedServer() && getServerForPlayer().getConfig().settings.pvp && "fall".equals(par1DamageSource.damageType); + + if (!flag && this.field_147101_bU > 0 && par1DamageSource != DamageSource.outOfWorld) + { + return false; + } + else + { + if (par1DamageSource instanceof EntityDamageSource) + { + Entity entity = par1DamageSource.getEntity(); + + if (entity instanceof EntityPlayer && !this.canAttackPlayer((EntityPlayer)entity)) + { + return false; + } + + if (entity instanceof EntityArrow) + { + EntityArrow entityarrow = (EntityArrow)entity; + + if (entityarrow.shootingEntity instanceof EntityPlayer && !this.canAttackPlayer((EntityPlayer)entityarrow.shootingEntity)) + { + return false; + } + } + } + + return super.attackEntityFrom(par1DamageSource, par2); + } + } + } + + public boolean canAttackPlayer(EntityPlayer par1EntityPlayer) + { + return !getServerForPlayer().getConfig().settings.pvp ? false : super.canAttackPlayer(par1EntityPlayer); + } + + public void travelToDimension(int par1) + { + if (this.dimension == 1 && par1 == 1) + { + this.triggerAchievement(AchievementList.theEnd2); + this.worldObj.removeEntity(this); + this.playerConqueredTheEnd = true; + this.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(4, 0.0F)); + } + else + { + if (this.dimension == 0 && par1 == 1) + { + this.triggerAchievement(AchievementList.theEnd); + ChunkCoordinates chunkcoordinates = this.mcServer.worldServerForDimension(par1).getEntrancePortalLocation(); + + if (chunkcoordinates != null) + { + this.playerNetServerHandler.setPlayerLocation((double)chunkcoordinates.posX, (double)chunkcoordinates.posY, (double)chunkcoordinates.posZ, 0.0F, 0.0F); + } + + par1 = 1; + } + else + { + this.triggerAchievement(AchievementList.portal); + } + + this.mcServer.getConfigurationManager().transferPlayerToDimension(this, par1); + this.lastExperience = -1; + this.lastHealth = -1.0F; + this.lastFoodLevel = -1; + } + } + + private void func_147097_b(TileEntity p_147097_1_) + { + if (p_147097_1_ != null) + { + Packet packet = p_147097_1_.getDescriptionPacket(); + + if (packet != null) + { + this.playerNetServerHandler.sendPacket(packet); + } + } + } + + public void onItemPickup(Entity par1Entity, int par2) + { + super.onItemPickup(par1Entity, par2); + this.openContainer.detectAndSendChanges(); + } + + public EntityPlayer.EnumStatus sleepInBedAt(int par1, int par2, int par3) + { + EntityPlayer.EnumStatus enumstatus = super.sleepInBedAt(par1, par2, par3); + + if (enumstatus == EntityPlayer.EnumStatus.OK) + { + S0APacketUseBed s0apacketusebed = new S0APacketUseBed(this, par1, par2, par3); + this.getServerForPlayer().getEntityTracker().func_151247_a(this, s0apacketusebed); + this.playerNetServerHandler.setPlayerLocation(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch); + this.playerNetServerHandler.sendPacket(s0apacketusebed); + } + + return enumstatus; + } + + public void wakeUpPlayer(boolean par1, boolean par2, boolean par3) + { + if (this.isPlayerSleeping()) + { + this.getServerForPlayer().getEntityTracker().func_151248_b(this, new S0BPacketAnimation(this, 2)); + } + + super.wakeUpPlayer(par1, par2, par3); + + if (this.playerNetServerHandler != null) + { + this.playerNetServerHandler.setPlayerLocation(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch); + } + } + + public void mountEntity(Entity par1Entity) + { + super.mountEntity(par1Entity); + this.playerNetServerHandler.sendPacket(new S1BPacketEntityAttach(0, this, this.ridingEntity)); + this.playerNetServerHandler.setPlayerLocation(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch); + } + + protected void updateFallState(double par1, boolean par3) {} + + public void handleFalling(double par1, boolean par3) + { + super.updateFallState(par1, par3); + } + + public void func_146100_a(TileEntity p_146100_1_) + { + if (p_146100_1_ instanceof TileEntitySign) + { + ((TileEntitySign)p_146100_1_).func_145912_a(this); + this.playerNetServerHandler.sendPacket(new S36PacketSignEditorOpen(p_146100_1_.xCoord, p_146100_1_.yCoord, p_146100_1_.zCoord)); + } + } + + public void getNextWindowId() + { + this.currentWindowId = this.currentWindowId % 100 + 1; + } + + public void displayGUIWorkbench(int par1, int par2, int par3) + { + this.getNextWindowId(); + this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 1, "Crafting", 9, true)); + this.openContainer = new ContainerWorkbench(this.inventory, this.worldObj, par1, par2, par3); + this.openContainer.windowId = this.currentWindowId; + this.openContainer.addCraftingToCrafters(this); + } + + public void displayGUIEnchantment(int par1, int par2, int par3, String par4Str) + { + this.getNextWindowId(); + this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 4, par4Str == null ? "" : par4Str, 9, par4Str != null)); + this.openContainer = new ContainerEnchantment(this.inventory, this.worldObj, par1, par2, par3); + this.openContainer.windowId = this.currentWindowId; + this.openContainer.addCraftingToCrafters(this); + } + + public void displayGUIAnvil(int par1, int par2, int par3) + { + this.getNextWindowId(); + this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 8, "Repairing", 9, true)); + this.openContainer = new ContainerRepair(this.inventory, this.worldObj, par1, par2, par3, this); + this.openContainer.windowId = this.currentWindowId; + this.openContainer.addCraftingToCrafters(this); + } + + public void displayGUIChest(IInventory par1IInventory) + { + if (this.openContainer != this.inventoryContainer) + { + this.closeScreen(); + } + + this.getNextWindowId(); + this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 0, par1IInventory.getInventoryName(), par1IInventory.getSizeInventory(), par1IInventory.hasCustomInventoryName())); + this.openContainer = new ContainerChest(this.inventory, par1IInventory); + this.openContainer.windowId = this.currentWindowId; + this.openContainer.addCraftingToCrafters(this); + } + + public void func_146093_a(TileEntityHopper p_146093_1_) + { + this.getNextWindowId(); + this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 9, p_146093_1_.getInventoryName(), p_146093_1_.getSizeInventory(), p_146093_1_.hasCustomInventoryName())); + this.openContainer = new ContainerHopper(this.inventory, p_146093_1_); + this.openContainer.windowId = this.currentWindowId; + this.openContainer.addCraftingToCrafters(this); + } + + public void displayGUIHopperMinecart(EntityMinecartHopper par1EntityMinecartHopper) + { + this.getNextWindowId(); + this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 9, par1EntityMinecartHopper.getInventoryName(), par1EntityMinecartHopper.getSizeInventory(), par1EntityMinecartHopper.hasCustomInventoryName())); + this.openContainer = new ContainerHopper(this.inventory, par1EntityMinecartHopper); + this.openContainer.windowId = this.currentWindowId; + this.openContainer.addCraftingToCrafters(this); + } + + public void func_146101_a(TileEntityFurnace p_146101_1_) + { + this.getNextWindowId(); + this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 2, p_146101_1_.getInventoryName(), p_146101_1_.getSizeInventory(), p_146101_1_.hasCustomInventoryName())); + this.openContainer = new ContainerFurnace(this.inventory, p_146101_1_); + this.openContainer.windowId = this.currentWindowId; + this.openContainer.addCraftingToCrafters(this); + } + + public void func_146102_a(TileEntityDispenser p_146102_1_) + { + this.getNextWindowId(); + this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, p_146102_1_ instanceof TileEntityDropper ? 10 : 3, p_146102_1_.getInventoryName(), p_146102_1_.getSizeInventory(), p_146102_1_.hasCustomInventoryName())); + this.openContainer = new ContainerDispenser(this.inventory, p_146102_1_); + this.openContainer.windowId = this.currentWindowId; + this.openContainer.addCraftingToCrafters(this); + } + + public void func_146098_a(TileEntityBrewingStand p_146098_1_) + { + this.getNextWindowId(); + this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 5, p_146098_1_.getInventoryName(), p_146098_1_.getSizeInventory(), p_146098_1_.hasCustomInventoryName())); + this.openContainer = new ContainerBrewingStand(this.inventory, p_146098_1_); + this.openContainer.windowId = this.currentWindowId; + this.openContainer.addCraftingToCrafters(this); + } + + public void func_146104_a(TileEntityBeacon p_146104_1_) + { + this.getNextWindowId(); + this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 7, p_146104_1_.getInventoryName(), p_146104_1_.getSizeInventory(), p_146104_1_.hasCustomInventoryName())); + this.openContainer = new ContainerBeacon(this.inventory, p_146104_1_); + this.openContainer.windowId = this.currentWindowId; + this.openContainer.addCraftingToCrafters(this); + } + + public void displayGUIMerchant(IMerchant par1IMerchant, String par2Str) + { + this.getNextWindowId(); + this.openContainer = new ContainerMerchant(this.inventory, par1IMerchant, this.worldObj); + this.openContainer.windowId = this.currentWindowId; + this.openContainer.addCraftingToCrafters(this); + InventoryMerchant inventorymerchant = ((ContainerMerchant)this.openContainer).getMerchantInventory(); + this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 6, par2Str == null ? "" : par2Str, inventorymerchant.getSizeInventory(), par2Str != null)); + MerchantRecipeList merchantrecipelist = par1IMerchant.getRecipes(this); + + if (merchantrecipelist != null) + { + try + { + PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer()); + packetbuffer.writeInt(this.currentWindowId); + merchantrecipelist.func_151391_a(packetbuffer); + this.playerNetServerHandler.sendPacket(new S3FPacketCustomPayload("MC|TrList", packetbuffer)); + } + catch (IOException ioexception) + { + logger.error("Couldn\'t send trade list", ioexception); + } + } + } + + public void displayGUIHorse(EntityHorse par1EntityHorse, IInventory par2IInventory) + { + if (this.openContainer != this.inventoryContainer) + { + this.closeScreen(); + } + + this.getNextWindowId(); + this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 11, par2IInventory.getInventoryName(), par2IInventory.getSizeInventory(), par2IInventory.hasCustomInventoryName(), par1EntityHorse.getEntityId())); + this.openContainer = new ContainerHorseInventory(this.inventory, par2IInventory, par1EntityHorse); + this.openContainer.windowId = this.currentWindowId; + this.openContainer.addCraftingToCrafters(this); + } + + public void sendSlotContents(Container par1Container, int par2, ItemStack par3ItemStack) + { + if (!(par1Container.getSlot(par2) instanceof SlotCrafting)) + { + if (!this.isChangingQuantityOnly) + { + this.playerNetServerHandler.sendPacket(new S2FPacketSetSlot(par1Container.windowId, par2, par3ItemStack)); + } + } + } + + public void sendContainerToPlayer(Container par1Container) + { + this.sendContainerAndContentsToPlayer(par1Container, par1Container.getInventory()); + } + + public void sendContainerAndContentsToPlayer(Container par1Container, List par2List) + { + this.playerNetServerHandler.sendPacket(new S30PacketWindowItems(par1Container.windowId, par2List)); + this.playerNetServerHandler.sendPacket(new S2FPacketSetSlot(-1, -1, this.inventory.getItemStack())); + } + + public void sendProgressBarUpdate(Container par1Container, int par2, int par3) + { + this.playerNetServerHandler.sendPacket(new S31PacketWindowProperty(par1Container.windowId, par2, par3)); + } + + public void closeScreen() + { + this.playerNetServerHandler.sendPacket(new S2EPacketCloseWindow(this.openContainer.windowId)); + this.closeContainer(); + } + + public void updateHeldItem() + { + if (!this.isChangingQuantityOnly) + { + this.playerNetServerHandler.sendPacket(new S2FPacketSetSlot(-1, -1, this.inventory.getItemStack())); + } + } + + public void closeContainer() + { + this.openContainer.onContainerClosed(this); + this.openContainer = this.inventoryContainer; + } + + public void setEntityActionState(float par1, float par2, boolean par3, boolean par4) + { + if (this.ridingEntity != null) + { + if (par1 >= -1.0F && par1 <= 1.0F) + { + this.moveStrafing = par1; + } + + if (par2 >= -1.0F && par2 <= 1.0F) + { + this.moveForward = par2; + } + + this.isJumping = par3; + this.setSneaking(par4); + } + } + + public void addStat(StatBase par1StatBase, int par2) + { + if (par1StatBase != null) + { + this.field_147103_bO.func_150871_b(this, par1StatBase, par2); + Iterator iterator = this.getWorldScoreboard().func_96520_a(par1StatBase.func_150952_k()).iterator(); + + while (iterator.hasNext()) + { + ScoreObjective scoreobjective = (ScoreObjective)iterator.next(); + this.getWorldScoreboard().func_96529_a(this.getCommandSenderName(), scoreobjective).func_96648_a(); + } + + if (this.field_147103_bO.func_150879_e()) + { + this.field_147103_bO.func_150876_a(this); + } + } + } + + public void mountEntityAndWakeUp() + { + if (this.riddenByEntity != null) + { + this.riddenByEntity.mountEntity(this); + } + + if (this.sleeping) + { + this.wakeUpPlayer(true, false, false); + } + } + + public void setPlayerHealthUpdated() + { + this.lastHealth = -1.0E8F; + } + + public void addChatComponentMessage(IChatComponent p_146105_1_) + { + this.playerNetServerHandler.sendPacket(new S02PacketChat(p_146105_1_)); + } + + protected void onItemUseFinish() + { + this.playerNetServerHandler.sendPacket(new S19PacketEntityStatus(this, (byte)9)); + super.onItemUseFinish(); + } + + public void setItemInUse(ItemStack par1ItemStack, int par2) + { + super.setItemInUse(par1ItemStack, par2); + + if (par1ItemStack != null && par1ItemStack.getItem() != null && par1ItemStack.getItem().getItemUseAction(par1ItemStack) == EnumAction.eat) + { + this.getServerForPlayer().getEntityTracker().func_151248_b(this, new S0BPacketAnimation(this, 3)); + } + } + + public void clonePlayer(EntityPlayer par1EntityPlayer, boolean par2) + { + super.clonePlayer(par1EntityPlayer, par2); + this.lastExperience = -1; + this.lastHealth = -1.0F; + this.lastFoodLevel = -1; + this.destroyedItemsNetCache.addAll(((EntityPlayerMP)par1EntityPlayer).destroyedItemsNetCache); + } + + protected void onNewPotionEffect(PotionEffect par1PotionEffect) + { + super.onNewPotionEffect(par1PotionEffect); + this.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(this.getEntityId(), par1PotionEffect)); + } + + protected void onChangedPotionEffect(PotionEffect par1PotionEffect, boolean par2) + { + super.onChangedPotionEffect(par1PotionEffect, par2); + this.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(this.getEntityId(), par1PotionEffect)); + } + + protected void onFinishedPotionEffect(PotionEffect par1PotionEffect) + { + super.onFinishedPotionEffect(par1PotionEffect); + this.playerNetServerHandler.sendPacket(new S1EPacketRemoveEntityEffect(this.getEntityId(), par1PotionEffect)); + } + + public void setPositionAndUpdate(double par1, double par3, double par5) + { + this.playerNetServerHandler.setPlayerLocation(par1, par3, par5, this.rotationYaw, this.rotationPitch); + } + + public void onCriticalHit(Entity par1Entity) + { + this.getServerForPlayer().getEntityTracker().func_151248_b(this, new S0BPacketAnimation(par1Entity, 4)); + } + + public void onEnchantmentCritical(Entity par1Entity) + { + this.getServerForPlayer().getEntityTracker().func_151248_b(this, new S0BPacketAnimation(par1Entity, 5)); + } + + public void sendPlayerAbilities() + { + if (this.playerNetServerHandler != null) + { + this.playerNetServerHandler.sendPacket(new S39PacketPlayerAbilities(this.capabilities)); + } + } + + public WorldServer getServerForPlayer() + { + return (WorldServer)this.worldObj; + } + + public void setGameType(WorldSettings.GameType par1EnumGameType) + { + this.theItemInWorldManager.setGameType(par1EnumGameType); + this.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(3, (float)par1EnumGameType.getID())); + } + + public void addChatMessage(IChatComponent p_145747_1_) + { + this.playerNetServerHandler.sendPacket(new S02PacketChat(p_145747_1_)); + } + + public boolean canCommandSenderUseCommand(int par1, String par2Str) + { + return "seed".equals(par2Str) && !this.mcServer.isDedicatedServer() ? true : (!"tell".equals(par2Str) && !"help".equals(par2Str) && !"me".equals(par2Str) ? (this.mcServer.getConfigurationManager().isPlayerOpped(this.getCommandSenderName()) ? this.mcServer.getOpPermissionLevel() >= par1 : false) : true); + } + + public String getPlayerIP() + { + String s = this.playerNetServerHandler.netManager.getSocketAddress().toString(); + s = s.substring(s.indexOf("/") + 1); + s = s.substring(0, s.indexOf(":")); + return s; + } + + public void func_147100_a(C15PacketClientSettings p_147100_1_) + { + this.translator = p_147100_1_.func_149524_c(); + int i = /*256 >>*/ p_147100_1_.func_149521_d(); + + if (i > 3 && i < 15) + { + this.renderDistance = i; + } + + this.chatVisibility = p_147100_1_.func_149523_e(); + this.chatColours = p_147100_1_.func_149520_f(); + + if (this.mcServer.isSinglePlayer() && this.mcServer.getServerOwner().equals(this.getCommandSenderName())) + { + this.mcServer.func_147139_a(p_147100_1_.func_149518_g()); + } + + this.setHideCape(1, !p_147100_1_.func_149519_h()); + } + + public EntityPlayer.EnumChatVisibility func_147096_v() + { + return this.chatVisibility; + } + + public void requestTexturePackLoad(String p_147095_1_) + { + this.playerNetServerHandler.sendPacket(new S3FPacketCustomPayload("MC|RPack", p_147095_1_.getBytes(Charsets.UTF_8))); + } + + public ChunkCoordinates getPlayerCoordinates() + { + return new ChunkCoordinates(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY + 0.5D), MathHelper.floor_double(this.posZ)); + } + + public void func_143004_u() + { + this.field_143005_bX = MinecraftServer.getSystemTimeMillis(); + } + + public StatisticsFile func_147099_x() + { + return this.field_147103_bO; + } + + /* ===================================== FORGE START =====================================*/ + /** + * Returns the default eye height of the player + * @return player default eye height + */ + @Override + public float getDefaultEyeHeight() + { + return 1.62F; + } + + /* ===================================== ULTRAMINE START =====================================*/ + + private final ChunkSendManager chunkMgr = new ChunkSendManager(this); + + @Override + public boolean isEntityPlayerMP() + { + return true; + } + + public ChunkSendManager getChunkMgr() + { + return chunkMgr; + } + + public int getRenderDistance() + { + return renderDistance; + } } \ No newline at end of file diff --git a/src/main/java/net/minecraft/network/NetHandlerPlayServer.java b/src/main/java/net/minecraft/network/NetHandlerPlayServer.java index 429851a..5c6c9eb 100644 --- a/src/main/java/net/minecraft/network/NetHandlerPlayServer.java +++ b/src/main/java/net/minecraft/network/NetHandlerPlayServer.java @@ -1,1279 +1,1281 @@ -package net.minecraft.network; - -import com.google.common.base.Charsets; -import com.google.common.collect.Lists; -import io.netty.buffer.Unpooled; -import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.GenericFutureListener; -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.Random; -import java.util.concurrent.Callable; -import net.minecraft.block.material.Material; -import net.minecraft.command.server.CommandBlockLogic; -import net.minecraft.crash.CrashReport; -import net.minecraft.crash.CrashReportCategory; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityMinecartCommandBlock; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.item.EntityXPOrb; -import net.minecraft.entity.passive.EntityHorse; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.entity.projectile.EntityArrow; -import net.minecraft.init.Items; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.ContainerBeacon; -import net.minecraft.inventory.ContainerMerchant; -import net.minecraft.inventory.ContainerRepair; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemEditableBook; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemWritableBook; -import net.minecraft.nbt.NBTTagString; -import net.minecraft.network.play.INetHandlerPlayServer; -import net.minecraft.network.play.client.C00PacketKeepAlive; -import net.minecraft.network.play.client.C01PacketChatMessage; -import net.minecraft.network.play.client.C02PacketUseEntity; -import net.minecraft.network.play.client.C03PacketPlayer; -import net.minecraft.network.play.client.C07PacketPlayerDigging; -import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement; -import net.minecraft.network.play.client.C09PacketHeldItemChange; -import net.minecraft.network.play.client.C0APacketAnimation; -import net.minecraft.network.play.client.C0BPacketEntityAction; -import net.minecraft.network.play.client.C0CPacketInput; -import net.minecraft.network.play.client.C0DPacketCloseWindow; -import net.minecraft.network.play.client.C0EPacketClickWindow; -import net.minecraft.network.play.client.C0FPacketConfirmTransaction; -import net.minecraft.network.play.client.C10PacketCreativeInventoryAction; -import net.minecraft.network.play.client.C11PacketEnchantItem; -import net.minecraft.network.play.client.C12PacketUpdateSign; -import net.minecraft.network.play.client.C13PacketPlayerAbilities; -import net.minecraft.network.play.client.C14PacketTabComplete; -import net.minecraft.network.play.client.C15PacketClientSettings; -import net.minecraft.network.play.client.C16PacketClientStatus; -import net.minecraft.network.play.client.C17PacketCustomPayload; -import net.minecraft.network.play.server.S00PacketKeepAlive; -import net.minecraft.network.play.server.S02PacketChat; -import net.minecraft.network.play.server.S08PacketPlayerPosLook; -import net.minecraft.network.play.server.S23PacketBlockChange; -import net.minecraft.network.play.server.S2FPacketSetSlot; -import net.minecraft.network.play.server.S32PacketConfirmTransaction; -import net.minecraft.network.play.server.S3APacketTabComplete; -import net.minecraft.network.play.server.S40PacketDisconnect; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.management.BanEntry; -import net.minecraft.stats.AchievementList; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityBeacon; -import net.minecraft.tileentity.TileEntityCommandBlock; -import net.minecraft.tileentity.TileEntitySign; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.ChatAllowedCharacters; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.ChatComponentTranslation; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.IChatComponent; -import net.minecraft.util.IntHashMap; -import net.minecraft.util.ReportedException; -import net.minecraft.world.WorldServer; -import org.apache.commons.lang3.StringUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import net.minecraftforge.common.ForgeHooks; -import net.minecraftforge.common.MinecraftForge; -import cpw.mods.fml.common.eventhandler.Event; -import net.minecraftforge.event.ForgeEventFactory; -import net.minecraftforge.event.ServerChatEvent; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; -import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; - -public class NetHandlerPlayServer implements INetHandlerPlayServer -{ - private static final Logger logger = LogManager.getLogger(); - public final NetworkManager netManager; - private final MinecraftServer serverController; - public EntityPlayerMP playerEntity; - private int networkTickCount; - private int floatingTickCount; - private boolean field_147366_g; - private int field_147378_h; - private long field_147379_i; - private static Random field_147376_j = new Random(); - private long field_147377_k; - private int chatSpamThresholdCount; - private int field_147375_m; - private IntHashMap field_147372_n = new IntHashMap(); - private double lastPosX; - private double lastPosY; - private double lastPosZ; - private boolean hasMoved = true; - private static final String __OBFID = "CL_00001452"; - - public NetHandlerPlayServer(MinecraftServer par1MinecraftServer, NetworkManager par2INetworkManager, EntityPlayerMP par3EntityPlayerMP) - { - this.serverController = par1MinecraftServer; - this.netManager = par2INetworkManager; - par2INetworkManager.setNetHandler(this); - this.playerEntity = par3EntityPlayerMP; - par3EntityPlayerMP.playerNetServerHandler = this; - } - - public void onNetworkTick() - { - this.field_147366_g = false; - ++this.networkTickCount; - this.serverController.theProfiler.startSection("keepAlive"); - - if ((long)this.networkTickCount - this.field_147377_k > 40L) - { - this.field_147377_k = (long)this.networkTickCount; - this.field_147379_i = this.func_147363_d(); - this.field_147378_h = (int)this.field_147379_i; - this.sendPacket(new S00PacketKeepAlive(this.field_147378_h)); - } - - if (this.chatSpamThresholdCount > 0) - { - --this.chatSpamThresholdCount; - } - - if (this.field_147375_m > 0) - { - --this.field_147375_m; - } - - this.serverController.theProfiler.endStartSection("playerTick"); - this.serverController.theProfiler.endSection(); - } - - public NetworkManager func_147362_b() - { - return this.netManager; - } - - public void kickPlayerFromServer(String p_147360_1_) - { - final ChatComponentText chatcomponenttext = new ChatComponentText(p_147360_1_); - this.netManager.scheduleOutboundPacket(new S40PacketDisconnect(chatcomponenttext), new GenericFutureListener[] {new GenericFutureListener() - { - private static final String __OBFID = "CL_00001453"; - public void operationComplete(Future p_operationComplete_1_) - { - NetHandlerPlayServer.this.netManager.closeChannel(chatcomponenttext); - } - } - }); - this.netManager.disableAutoRead(); - } - - public void processInput(C0CPacketInput p_147358_1_) - { - this.playerEntity.setEntityActionState(p_147358_1_.func_149620_c(), p_147358_1_.func_149616_d(), p_147358_1_.func_149618_e(), p_147358_1_.func_149617_f()); - } - - public void processPlayer(C03PacketPlayer p_147347_1_) - { - WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension); - this.field_147366_g = true; - - if (!this.playerEntity.playerConqueredTheEnd) - { - double d0; - - if (!this.hasMoved) - { - d0 = p_147347_1_.func_149467_d() - this.lastPosY; - - if (p_147347_1_.func_149464_c() == this.lastPosX && d0 * d0 < 0.01D && p_147347_1_.func_149472_e() == this.lastPosZ) - { - this.hasMoved = true; - } - } - - if (this.hasMoved) - { - double d1; - double d2; - double d3; - - if (this.playerEntity.ridingEntity != null) - { - float f4 = this.playerEntity.rotationYaw; - float f = this.playerEntity.rotationPitch; - this.playerEntity.ridingEntity.updateRiderPosition(); - d1 = this.playerEntity.posX; - d2 = this.playerEntity.posY; - d3 = this.playerEntity.posZ; - - if (p_147347_1_.func_149463_k()) - { - f4 = p_147347_1_.func_149462_g(); - f = p_147347_1_.func_149470_h(); - } - - this.playerEntity.onGround = p_147347_1_.func_149465_i(); - this.playerEntity.onUpdateEntity(); - this.playerEntity.ySize = 0.0F; - this.playerEntity.setPositionAndRotation(d1, d2, d3, f4, f); - - if (this.playerEntity.ridingEntity != null) - { - this.playerEntity.ridingEntity.updateRiderPosition(); - } - - if (!this.hasMoved) //Fixes teleportation kick while riding entities - { - return; - } - - this.serverController.getConfigurationManager().updatePlayerPertinentChunks(this.playerEntity); - - if (this.hasMoved) - { - this.lastPosX = this.playerEntity.posX; - this.lastPosY = this.playerEntity.posY; - this.lastPosZ = this.playerEntity.posZ; - } - - worldserver.updateEntity(this.playerEntity); - return; - } - - if (this.playerEntity.isPlayerSleeping()) - { - this.playerEntity.onUpdateEntity(); - this.playerEntity.setPositionAndRotation(this.lastPosX, this.lastPosY, this.lastPosZ, this.playerEntity.rotationYaw, this.playerEntity.rotationPitch); - worldserver.updateEntity(this.playerEntity); - return; - } - - d0 = this.playerEntity.posY; - this.lastPosX = this.playerEntity.posX; - this.lastPosY = this.playerEntity.posY; - this.lastPosZ = this.playerEntity.posZ; - d1 = this.playerEntity.posX; - d2 = this.playerEntity.posY; - d3 = this.playerEntity.posZ; - float f1 = this.playerEntity.rotationYaw; - float f2 = this.playerEntity.rotationPitch; - - if (p_147347_1_.func_149466_j() && p_147347_1_.func_149467_d() == -999.0D && p_147347_1_.func_149471_f() == -999.0D) - { - p_147347_1_.func_149469_a(false); - } - - double d4; - - if (p_147347_1_.func_149466_j()) - { - d1 = p_147347_1_.func_149464_c(); - d2 = p_147347_1_.func_149467_d(); - d3 = p_147347_1_.func_149472_e(); - d4 = p_147347_1_.func_149471_f() - p_147347_1_.func_149467_d(); - - if (!this.playerEntity.isPlayerSleeping() && (d4 > 1.65D || d4 < 0.1D)) - { - this.kickPlayerFromServer("Illegal stance"); - logger.warn(this.playerEntity.getCommandSenderName() + " had an illegal stance: " + d4); - return; - } - - if (Math.abs(p_147347_1_.func_149464_c()) > 3.2E7D || Math.abs(p_147347_1_.func_149472_e()) > 3.2E7D) - { - this.kickPlayerFromServer("Illegal position"); - return; - } - } - - if (p_147347_1_.func_149463_k()) - { - f1 = p_147347_1_.func_149462_g(); - f2 = p_147347_1_.func_149470_h(); - } - - this.playerEntity.onUpdateEntity(); - this.playerEntity.ySize = 0.0F; - this.playerEntity.setPositionAndRotation(this.lastPosX, this.lastPosY, this.lastPosZ, f1, f2); - - if (!this.hasMoved) - { - return; - } - - d4 = d1 - this.playerEntity.posX; - double d5 = d2 - this.playerEntity.posY; - double d6 = d3 - this.playerEntity.posZ; - //BUGFIX: min -> max, grabs the highest distance - double d7 = Math.max(Math.abs(d4), Math.abs(this.playerEntity.motionX)); - double d8 = Math.max(Math.abs(d5), Math.abs(this.playerEntity.motionY)); - double d9 = Math.max(Math.abs(d6), Math.abs(this.playerEntity.motionZ)); - double d10 = d7 * d7 + d8 * d8 + d9 * d9; - - if (d10 > 100.0D && (!this.serverController.isSinglePlayer() || !this.serverController.getServerOwner().equals(this.playerEntity.getCommandSenderName()))) - { - logger.warn(this.playerEntity.getCommandSenderName() + " moved too quickly! " + d4 + "," + d5 + "," + d6 + " (" + d7 + ", " + d8 + ", " + d9 + ")"); - this.setPlayerLocation(this.lastPosX, this.lastPosY, this.lastPosZ, this.playerEntity.rotationYaw, this.playerEntity.rotationPitch); - return; - } - - float f3 = 0.0625F; - boolean flag = worldserver.getCollidingBoundingBoxes(this.playerEntity, this.playerEntity.boundingBox.copy().contract((double)f3, (double)f3, (double)f3)).isEmpty(); - - if (this.playerEntity.onGround && !p_147347_1_.func_149465_i() && d5 > 0.0D) - { - this.playerEntity.jump(); - } - - if (!this.hasMoved) //Fixes "Moved Too Fast" kick when being teleported while moving - { - return; - } - - this.playerEntity.moveEntity(d4, d5, d6); - this.playerEntity.onGround = p_147347_1_.func_149465_i(); - this.playerEntity.addMovementStat(d4, d5, d6); - double d11 = d5; - d4 = d1 - this.playerEntity.posX; - d5 = d2 - this.playerEntity.posY; - - if (d5 > -0.5D || d5 < 0.5D) - { - d5 = 0.0D; - } - - d6 = d3 - this.playerEntity.posZ; - d10 = d4 * d4 + d5 * d5 + d6 * d6; - boolean flag1 = false; - - if (d10 > 0.0625D && !this.playerEntity.isPlayerSleeping() && !this.playerEntity.theItemInWorldManager.isCreative()) - { - flag1 = true; - logger.warn(this.playerEntity.getCommandSenderName() + " moved wrongly!"); - } - - if (!this.hasMoved) //Fixes "Moved Too Fast" kick when being teleported while moving - { - return; - } - - this.playerEntity.setPositionAndRotation(d1, d2, d3, f1, f2); - boolean flag2 = worldserver.getCollidingBoundingBoxes(this.playerEntity, this.playerEntity.boundingBox.copy().contract((double)f3, (double)f3, (double)f3)).isEmpty(); - - if (flag && (flag1 || !flag2) && !this.playerEntity.isPlayerSleeping() && !this.playerEntity.noClip) - { - this.setPlayerLocation(this.lastPosX, this.lastPosY, this.lastPosZ, f1, f2); - return; - } - - AxisAlignedBB axisalignedbb = this.playerEntity.boundingBox.copy().expand((double)f3, (double)f3, (double)f3).addCoord(0.0D, -0.55D, 0.0D); - - if (!this.serverController.isFlightAllowed() && !this.playerEntity.theItemInWorldManager.isCreative() && !worldserver.checkBlockCollision(axisalignedbb) && !this.playerEntity.capabilities.allowFlying) - { - if (d11 >= -0.03125D) - { - ++this.floatingTickCount; - - if (this.floatingTickCount > 80) - { - logger.warn(this.playerEntity.getCommandSenderName() + " was kicked for floating too long!"); - this.kickPlayerFromServer("Flying is not enabled on this server"); - return; - } - } - } - else - { - this.floatingTickCount = 0; - } - - if (!this.hasMoved) //Fixes "Moved Too Fast" kick when being teleported while moving - { - return; - } - - this.playerEntity.onGround = p_147347_1_.func_149465_i(); - this.serverController.getConfigurationManager().updatePlayerPertinentChunks(this.playerEntity); - this.playerEntity.handleFalling(this.playerEntity.posY - d0, p_147347_1_.func_149465_i()); - } - else if (this.networkTickCount % 20 == 0) - { - this.setPlayerLocation(this.lastPosX, this.lastPosY, this.lastPosZ, this.playerEntity.rotationYaw, this.playerEntity.rotationPitch); - } - } - } - - public void setPlayerLocation(double p_147364_1_, double p_147364_3_, double p_147364_5_, float p_147364_7_, float p_147364_8_) - { - this.hasMoved = false; - this.lastPosX = p_147364_1_; - this.lastPosY = p_147364_3_; - this.lastPosZ = p_147364_5_; - this.playerEntity.setPositionAndRotation(p_147364_1_, p_147364_3_, p_147364_5_, p_147364_7_, p_147364_8_); - this.playerEntity.playerNetServerHandler.sendPacket(new S08PacketPlayerPosLook(p_147364_1_, p_147364_3_ + 1.6200000047683716D, p_147364_5_, p_147364_7_, p_147364_8_, false)); - } - - public void processPlayerDigging(C07PacketPlayerDigging p_147345_1_) - { - WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension); - this.playerEntity.func_143004_u(); - - if (p_147345_1_.func_149506_g() == 4) - { - this.playerEntity.dropOneItem(false); - } - else if (p_147345_1_.func_149506_g() == 3) - { - this.playerEntity.dropOneItem(true); - } - else if (p_147345_1_.func_149506_g() == 5) - { - this.playerEntity.stopUsingItem(); - } - else - { - boolean flag = false; - - if (p_147345_1_.func_149506_g() == 0) - { - flag = true; - } - - if (p_147345_1_.func_149506_g() == 1) - { - flag = true; - } - - if (p_147345_1_.func_149506_g() == 2) - { - flag = true; - } - - int i = p_147345_1_.func_149505_c(); - int j = p_147345_1_.func_149503_d(); - int k = p_147345_1_.func_149502_e(); - - if (flag) - { - double d0 = this.playerEntity.posX - ((double)i + 0.5D); - double d1 = this.playerEntity.posY - ((double)j + 0.5D) + 1.5D; - double d2 = this.playerEntity.posZ - ((double)k + 0.5D); - double d3 = d0 * d0 + d1 * d1 + d2 * d2; - - double dist = playerEntity.theItemInWorldManager.getBlockReachDistance() + 1; - dist *= dist; - - if (d3 > dist) - { - return; - } - - if (j >= this.serverController.getBuildLimit()) - { - return; - } - } - - if (p_147345_1_.func_149506_g() == 0) - { - if (!this.serverController.isBlockProtected(worldserver, i, j, k, this.playerEntity)) - { - this.playerEntity.theItemInWorldManager.onBlockClicked(i, j, k, p_147345_1_.func_149501_f()); - } - else - { - this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(i, j, k, worldserver)); - } - } - else if (p_147345_1_.func_149506_g() == 2) - { - this.playerEntity.theItemInWorldManager.uncheckedTryHarvestBlock(i, j, k); - - if (worldserver.getBlock(i, j, k).getMaterial() != Material.air) - { - this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(i, j, k, worldserver)); - } - } - else if (p_147345_1_.func_149506_g() == 1) - { - this.playerEntity.theItemInWorldManager.cancelDestroyingBlock(i, j, k); - - if (worldserver.getBlock(i, j, k).getMaterial() != Material.air) - { - this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(i, j, k, worldserver)); - } - } - } - } - - public void processPlayerBlockPlacement(C08PacketPlayerBlockPlacement p_147346_1_) - { - WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension); - ItemStack itemstack = this.playerEntity.inventory.getCurrentItem(); - boolean flag = false; - int i = p_147346_1_.func_149576_c(); - int j = p_147346_1_.func_149571_d(); - int k = p_147346_1_.func_149570_e(); - int l = p_147346_1_.func_149568_f(); - this.playerEntity.func_143004_u(); - - if (p_147346_1_.func_149568_f() == 255) - { - if (itemstack == null) - { - return; - } - - PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(playerEntity, PlayerInteractEvent.Action.RIGHT_CLICK_AIR, 0, 0, 0, -1); - if (event.useItem != Event.Result.DENY) - { - this.playerEntity.theItemInWorldManager.tryUseItem(this.playerEntity, worldserver, itemstack); - } - } - else if (p_147346_1_.func_149571_d() >= this.serverController.getBuildLimit() - 1 && (p_147346_1_.func_149568_f() == 1 || p_147346_1_.func_149571_d() >= this.serverController.getBuildLimit())) - { - ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("build.tooHigh", new Object[] {Integer.valueOf(this.serverController.getBuildLimit())}); - chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED); - this.playerEntity.playerNetServerHandler.sendPacket(new S02PacketChat(chatcomponenttranslation)); - flag = true; - } - else - { - double dist = playerEntity.theItemInWorldManager.getBlockReachDistance() + 1; - dist *= dist; - if (this.hasMoved && this.playerEntity.getDistanceSq((double)i + 0.5D, (double)j + 0.5D, (double)k + 0.5D) < dist && !this.serverController.isBlockProtected(worldserver, i, j, k, this.playerEntity)) - { - this.playerEntity.theItemInWorldManager.activateBlockOrUseItem(this.playerEntity, worldserver, itemstack, i, j, k, l, p_147346_1_.func_149573_h(), p_147346_1_.func_149569_i(), p_147346_1_.func_149575_j()); - } - - flag = true; - } - - if (flag) - { - this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(i, j, k, worldserver)); - - if (l == 0) - { - --j; - } - - if (l == 1) - { - ++j; - } - - if (l == 2) - { - --k; - } - - if (l == 3) - { - ++k; - } - - if (l == 4) - { - --i; - } - - if (l == 5) - { - ++i; - } - - this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(i, j, k, worldserver)); - } - - itemstack = this.playerEntity.inventory.getCurrentItem(); - - if (itemstack != null && itemstack.stackSize == 0) - { - this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = null; - itemstack = null; - } - - if (itemstack == null || itemstack.getMaxItemUseDuration() == 0) - { - this.playerEntity.isChangingQuantityOnly = true; - this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = ItemStack.copyItemStack(this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem]); - Slot slot = this.playerEntity.openContainer.getSlotFromInventory(this.playerEntity.inventory, this.playerEntity.inventory.currentItem); - this.playerEntity.openContainer.detectAndSendChanges(); - this.playerEntity.isChangingQuantityOnly = false; - - if (!ItemStack.areItemStacksEqual(this.playerEntity.inventory.getCurrentItem(), p_147346_1_.func_149574_g())) - { - this.sendPacket(new S2FPacketSetSlot(this.playerEntity.openContainer.windowId, slot.slotNumber, this.playerEntity.inventory.getCurrentItem())); - } - } - } - - public void onDisconnect(IChatComponent p_147231_1_) - { - logger.info(this.playerEntity.getCommandSenderName() + " lost connection: " + p_147231_1_); - this.serverController.func_147132_au(); - ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("multiplayer.player.left", new Object[] {this.playerEntity.func_145748_c_()}); - chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.YELLOW); - this.serverController.getConfigurationManager().sendChatMsg(chatcomponenttranslation); - this.playerEntity.mountEntityAndWakeUp(); - this.serverController.getConfigurationManager().playerLoggedOut(this.playerEntity); - - if (this.serverController.isSinglePlayer() && this.playerEntity.getCommandSenderName().equals(this.serverController.getServerOwner())) - { - logger.info("Stopping singleplayer server as player logged out"); - this.serverController.initiateShutdown(); - } - } - - public void sendPacket(final Packet p_147359_1_) - { - if (p_147359_1_ instanceof S02PacketChat) - { - S02PacketChat s02packetchat = (S02PacketChat)p_147359_1_; - EntityPlayer.EnumChatVisibility enumchatvisibility = this.playerEntity.func_147096_v(); - - if (enumchatvisibility == EntityPlayer.EnumChatVisibility.HIDDEN) - { - return; - } - - if (enumchatvisibility == EntityPlayer.EnumChatVisibility.SYSTEM && !s02packetchat.func_148916_d()) - { - return; - } - } - - try - { - this.netManager.scheduleOutboundPacket(p_147359_1_, new GenericFutureListener[0]); - } - catch (Throwable throwable) - { - CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Sending packet"); - CrashReportCategory crashreportcategory = crashreport.makeCategory("Packet being sent"); - crashreportcategory.addCrashSectionCallable("Packet class", new Callable() - { - private static final String __OBFID = "CL_00001454"; - public String call() - { - return p_147359_1_.getClass().getCanonicalName(); - } - }); - throw new ReportedException(crashreport); - } - } - - public void processHeldItemChange(C09PacketHeldItemChange p_147355_1_) - { - if (p_147355_1_.func_149614_c() >= 0 && p_147355_1_.func_149614_c() < InventoryPlayer.getHotbarSize()) - { - this.playerEntity.inventory.currentItem = p_147355_1_.func_149614_c(); - this.playerEntity.func_143004_u(); - } - else - { - logger.warn(this.playerEntity.getCommandSenderName() + " tried to set an invalid carried item"); - } - } - - public void processChatMessage(C01PacketChatMessage p_147354_1_) - { - if (this.playerEntity.func_147096_v() == EntityPlayer.EnumChatVisibility.HIDDEN) - { - ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("chat.cannotSend", new Object[0]); - chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED); - this.sendPacket(new S02PacketChat(chatcomponenttranslation)); - } - else - { - this.playerEntity.func_143004_u(); - String s = p_147354_1_.func_149439_c(); - s = StringUtils.normalizeSpace(s); - - for (int i = 0; i < s.length(); ++i) - { - if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i))) - { - this.kickPlayerFromServer("Illegal characters in chat"); - return; - } - } - - if (s.startsWith("/")) - { - this.handleSlashCommand(s); - } - else - { - ChatComponentTranslation chatcomponenttranslation1 = new ChatComponentTranslation("chat.type.text", new Object[] {this.playerEntity.func_145748_c_(), s}); - chatcomponenttranslation1 = ForgeHooks.onServerChatEvent(this, s, chatcomponenttranslation1); - if (chatcomponenttranslation1 == null) return; - this.serverController.getConfigurationManager().sendChatMsgImpl(chatcomponenttranslation1, false); - } - - this.chatSpamThresholdCount += 20; - - if (this.chatSpamThresholdCount > 200 && !this.serverController.getConfigurationManager().isPlayerOpped(this.playerEntity.getCommandSenderName())) - { - this.kickPlayerFromServer("disconnect.spam"); - } - } - } - - private void handleSlashCommand(String p_147361_1_) - { - this.serverController.getCommandManager().executeCommand(this.playerEntity, p_147361_1_); - } - - public void processAnimation(C0APacketAnimation p_147350_1_) - { - this.playerEntity.func_143004_u(); - - if (p_147350_1_.func_149421_d() == 1) - { - this.playerEntity.swingItem(); - } - } - - public void processEntityAction(C0BPacketEntityAction p_147357_1_) - { - this.playerEntity.func_143004_u(); - - if (p_147357_1_.func_149513_d() == 1) - { - this.playerEntity.setSneaking(true); - } - else if (p_147357_1_.func_149513_d() == 2) - { - this.playerEntity.setSneaking(false); - } - else if (p_147357_1_.func_149513_d() == 4) - { - this.playerEntity.setSprinting(true); - } - else if (p_147357_1_.func_149513_d() == 5) - { - this.playerEntity.setSprinting(false); - } - else if (p_147357_1_.func_149513_d() == 3) - { - this.playerEntity.wakeUpPlayer(false, true, true); - this.hasMoved = false; - } - else if (p_147357_1_.func_149513_d() == 6) - { - if (this.playerEntity.ridingEntity != null && this.playerEntity.ridingEntity instanceof EntityHorse) - { - ((EntityHorse)this.playerEntity.ridingEntity).setJumpPower(p_147357_1_.func_149512_e()); - } - } - else if (p_147357_1_.func_149513_d() == 7 && this.playerEntity.ridingEntity != null && this.playerEntity.ridingEntity instanceof EntityHorse) - { - ((EntityHorse)this.playerEntity.ridingEntity).openGUI(this.playerEntity); - } - } - - public void processUseEntity(C02PacketUseEntity p_147340_1_) - { - WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension); - Entity entity = p_147340_1_.func_149564_a(worldserver); - this.playerEntity.func_143004_u(); - - if (entity != null) - { - boolean flag = this.playerEntity.canEntityBeSeen(entity); - double d0 = 36.0D; - - if (!flag) - { - d0 = 9.0D; - } - - if (this.playerEntity.getDistanceSqToEntity(entity) < d0) - { - if (p_147340_1_.func_149565_c() == C02PacketUseEntity.Action.INTERACT) - { - this.playerEntity.interactWith(entity); - } - else if (p_147340_1_.func_149565_c() == C02PacketUseEntity.Action.ATTACK) - { - if (entity instanceof EntityItem || entity instanceof EntityXPOrb || entity instanceof EntityArrow || entity == this.playerEntity) - { - this.kickPlayerFromServer("Attempting to attack an invalid entity"); - this.serverController.logWarning("Player " + this.playerEntity.getCommandSenderName() + " tried to attack an invalid entity"); - return; - } - - this.playerEntity.attackTargetEntityWithCurrentItem(entity); - } - } - } - } - - public void processClientStatus(C16PacketClientStatus p_147342_1_) - { - this.playerEntity.func_143004_u(); - C16PacketClientStatus.EnumState enumstate = p_147342_1_.func_149435_c(); - - switch (NetHandlerPlayServer.SwitchEnumState.field_151290_a[enumstate.ordinal()]) - { - case 1: - if (this.playerEntity.playerConqueredTheEnd) - { - this.playerEntity = this.serverController.getConfigurationManager().respawnPlayer(this.playerEntity, 0, true); - } - else if (this.playerEntity.getServerForPlayer().getWorldInfo().isHardcoreModeEnabled()) - { - if (this.serverController.isSinglePlayer() && this.playerEntity.getCommandSenderName().equals(this.serverController.getServerOwner())) - { - this.playerEntity.playerNetServerHandler.kickPlayerFromServer("You have died. Game over, man, it\'s game over!"); - this.serverController.deleteWorldAndStopServer(); - } - else - { - BanEntry banentry = new BanEntry(this.playerEntity.getCommandSenderName()); - banentry.setBanReason("Death in Hardcore"); - this.serverController.getConfigurationManager().getBannedPlayers().put(banentry); - this.playerEntity.playerNetServerHandler.kickPlayerFromServer("You have died. Game over, man, it\'s game over!"); - } - } - else - { - if (this.playerEntity.getHealth() > 0.0F) - { - return; - } - - this.playerEntity = this.serverController.getConfigurationManager().respawnPlayer(this.playerEntity, playerEntity.dimension, false); - } - - break; - case 2: - this.playerEntity.func_147099_x().func_150876_a(this.playerEntity); - break; - case 3: - this.playerEntity.triggerAchievement(AchievementList.openInventory); - } - } - - public void processCloseWindow(C0DPacketCloseWindow p_147356_1_) - { - this.playerEntity.closeContainer(); - } - - public void processClickWindow(C0EPacketClickWindow p_147351_1_) - { - this.playerEntity.func_143004_u(); - - if (this.playerEntity.openContainer.windowId == p_147351_1_.func_149548_c() && this.playerEntity.openContainer.isPlayerNotUsingContainer(this.playerEntity)) - { - ItemStack itemstack = this.playerEntity.openContainer.slotClick(p_147351_1_.func_149544_d(), p_147351_1_.func_149543_e(), p_147351_1_.func_149542_h(), this.playerEntity); - - if (ItemStack.areItemStacksEqual(p_147351_1_.func_149546_g(), itemstack)) - { - this.playerEntity.playerNetServerHandler.sendPacket(new S32PacketConfirmTransaction(p_147351_1_.func_149548_c(), p_147351_1_.func_149547_f(), true)); - this.playerEntity.isChangingQuantityOnly = true; - this.playerEntity.openContainer.detectAndSendChanges(); - this.playerEntity.updateHeldItem(); - this.playerEntity.isChangingQuantityOnly = false; - } - else - { - this.field_147372_n.addKey(this.playerEntity.openContainer.windowId, Short.valueOf(p_147351_1_.func_149547_f())); - this.playerEntity.playerNetServerHandler.sendPacket(new S32PacketConfirmTransaction(p_147351_1_.func_149548_c(), p_147351_1_.func_149547_f(), false)); - this.playerEntity.openContainer.setPlayerIsPresent(this.playerEntity, false); - ArrayList arraylist = new ArrayList(); - - for (int i = 0; i < this.playerEntity.openContainer.inventorySlots.size(); ++i) - { - arraylist.add(((Slot)this.playerEntity.openContainer.inventorySlots.get(i)).getStack()); - } - - this.playerEntity.sendContainerAndContentsToPlayer(this.playerEntity.openContainer, arraylist); - } - } - } - - public void processEnchantItem(C11PacketEnchantItem p_147338_1_) - { - this.playerEntity.func_143004_u(); - - if (this.playerEntity.openContainer.windowId == p_147338_1_.func_149539_c() && this.playerEntity.openContainer.isPlayerNotUsingContainer(this.playerEntity)) - { - this.playerEntity.openContainer.enchantItem(this.playerEntity, p_147338_1_.func_149537_d()); - this.playerEntity.openContainer.detectAndSendChanges(); - } - } - - public void processCreativeInventoryAction(C10PacketCreativeInventoryAction p_147344_1_) - { - if (this.playerEntity.theItemInWorldManager.isCreative()) - { - boolean flag = p_147344_1_.func_149627_c() < 0; - ItemStack itemstack = p_147344_1_.func_149625_d(); - boolean flag1 = p_147344_1_.func_149627_c() >= 1 && p_147344_1_.func_149627_c() < 36 + InventoryPlayer.getHotbarSize(); - boolean flag2 = itemstack == null || itemstack.getItem() != null; - boolean flag3 = itemstack == null || itemstack.getItemDamage() >= 0 && itemstack.stackSize <= 64 && itemstack.stackSize > 0; - - if (flag1 && flag2 && flag3) - { - if (itemstack == null) - { - this.playerEntity.inventoryContainer.putStackInSlot(p_147344_1_.func_149627_c(), (ItemStack)null); - } - else - { - this.playerEntity.inventoryContainer.putStackInSlot(p_147344_1_.func_149627_c(), itemstack); - } - - this.playerEntity.inventoryContainer.setPlayerIsPresent(this.playerEntity, true); - } - else if (flag && flag2 && flag3 && this.field_147375_m < 200) - { - this.field_147375_m += 20; - EntityItem entityitem = this.playerEntity.dropPlayerItemWithRandomChoice(itemstack, true); - - if (entityitem != null) - { - entityitem.setAgeToCreativeDespawnTime(); - } - } - } - } - - public void processConfirmTransaction(C0FPacketConfirmTransaction p_147339_1_) - { - Short oshort = (Short)this.field_147372_n.lookup(this.playerEntity.openContainer.windowId); - - if (oshort != null && p_147339_1_.func_149533_d() == oshort.shortValue() && this.playerEntity.openContainer.windowId == p_147339_1_.func_149532_c() && !this.playerEntity.openContainer.isPlayerNotUsingContainer(this.playerEntity)) - { - this.playerEntity.openContainer.setPlayerIsPresent(this.playerEntity, true); - } - } - - public void processUpdateSign(C12PacketUpdateSign p_147343_1_) - { - this.playerEntity.func_143004_u(); - WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension); - - if (worldserver.blockExists(p_147343_1_.func_149588_c(), p_147343_1_.func_149586_d(), p_147343_1_.func_149585_e())) - { - TileEntity tileentity = worldserver.getTileEntity(p_147343_1_.func_149588_c(), p_147343_1_.func_149586_d(), p_147343_1_.func_149585_e()); - - if (tileentity instanceof TileEntitySign) - { - TileEntitySign tileentitysign = (TileEntitySign)tileentity; - - if (!tileentitysign.func_145914_a() || tileentitysign.func_145911_b() != this.playerEntity) - { - this.serverController.logWarning("Player " + this.playerEntity.getCommandSenderName() + " just tried to change non-editable sign"); - return; - } - } - - int i; - int j; - - for (j = 0; j < 4; ++j) - { - boolean flag = true; - - if (p_147343_1_.func_149589_f()[j].length() > 15) - { - flag = false; - } - else - { - for (i = 0; i < p_147343_1_.func_149589_f()[j].length(); ++i) - { - if (!ChatAllowedCharacters.isAllowedCharacter(p_147343_1_.func_149589_f()[j].charAt(i))) - { - flag = false; - } - } - } - - if (!flag) - { - p_147343_1_.func_149589_f()[j] = "!?"; - } - } - - if (tileentity instanceof TileEntitySign) - { - j = p_147343_1_.func_149588_c(); - int k = p_147343_1_.func_149586_d(); - i = p_147343_1_.func_149585_e(); - TileEntitySign tileentitysign1 = (TileEntitySign)tileentity; - System.arraycopy(p_147343_1_.func_149589_f(), 0, tileentitysign1.signText, 0, 4); - tileentitysign1.markDirty(); - worldserver.markBlockForUpdate(j, k, i); - } - } - } - - public void processKeepAlive(C00PacketKeepAlive p_147353_1_) - { - if (p_147353_1_.func_149460_c() == this.field_147378_h) - { - int i = (int)(this.func_147363_d() - this.field_147379_i); - this.playerEntity.ping = (this.playerEntity.ping * 3 + i) / 4; - } - } - - private long func_147363_d() - { - return System.nanoTime() / 1000000L; - } - - public void processPlayerAbilities(C13PacketPlayerAbilities p_147348_1_) - { - this.playerEntity.capabilities.isFlying = p_147348_1_.func_149488_d() && this.playerEntity.capabilities.allowFlying; - } - - public void processTabComplete(C14PacketTabComplete p_147341_1_) - { - ArrayList arraylist = Lists.newArrayList(); - Iterator iterator = this.serverController.getPossibleCompletions(this.playerEntity, p_147341_1_.func_149419_c()).iterator(); - - while (iterator.hasNext()) - { - String s = (String)iterator.next(); - arraylist.add(s); - } - - this.playerEntity.playerNetServerHandler.sendPacket(new S3APacketTabComplete((String[])arraylist.toArray(new String[arraylist.size()]))); - } - - public void processClientSettings(C15PacketClientSettings p_147352_1_) - { - this.playerEntity.func_147100_a(p_147352_1_); - } - - public void processVanilla250Packet(C17PacketCustomPayload p_147349_1_) - { - ItemStack itemstack; - ItemStack itemstack1; - - if ("MC|BEdit".equals(p_147349_1_.func_149559_c())) - { - try - { - itemstack = (new PacketBuffer(Unpooled.wrappedBuffer(p_147349_1_.func_149558_e()))).readItemStackFromBuffer(); - - if (!ItemWritableBook.func_150930_a(itemstack.getTagCompound())) - { - throw new IOException("Invalid book tag!"); - } - - itemstack1 = this.playerEntity.inventory.getCurrentItem(); - - if (itemstack.getItem() == Items.writable_book && itemstack.getItem() == itemstack1.getItem()) - { - itemstack1.setTagInfo("pages", itemstack.getTagCompound().getTagList("pages", 8)); - } - } - catch (Exception exception4) - { - logger.error("Couldn\'t handle book info", exception4); - } - } - else if ("MC|BSign".equals(p_147349_1_.func_149559_c())) - { - try - { - itemstack = (new PacketBuffer(Unpooled.wrappedBuffer(p_147349_1_.func_149558_e()))).readItemStackFromBuffer(); - - if (!ItemEditableBook.validBookTagContents(itemstack.getTagCompound())) - { - throw new IOException("Invalid book tag!"); - } - - itemstack1 = this.playerEntity.inventory.getCurrentItem(); - - if (itemstack.getItem() == Items.written_book && itemstack1.getItem() == Items.writable_book) - { - itemstack1.setTagInfo("author", new NBTTagString(this.playerEntity.getCommandSenderName())); - itemstack1.setTagInfo("title", new NBTTagString(itemstack.getTagCompound().getString("title"))); - itemstack1.setTagInfo("pages", itemstack.getTagCompound().getTagList("pages", 8)); - itemstack1.func_150996_a(Items.written_book); - } - } - catch (Exception exception3) - { - logger.error("Couldn\'t sign book", exception3); - } - } - else - { - DataInputStream datainputstream; - int i; - - if ("MC|TrSel".equals(p_147349_1_.func_149559_c())) - { - try - { - datainputstream = new DataInputStream(new ByteArrayInputStream(p_147349_1_.func_149558_e())); - i = datainputstream.readInt(); - Container container = this.playerEntity.openContainer; - - if (container instanceof ContainerMerchant) - { - ((ContainerMerchant)container).setCurrentRecipeIndex(i); - } - } - catch (Exception exception2) - { - logger.error("Couldn\'t select trade", exception2); - } - } - else if ("MC|AdvCdm".equals(p_147349_1_.func_149559_c())) - { - if (!this.serverController.isCommandBlockEnabled()) - { - this.playerEntity.addChatMessage(new ChatComponentTranslation("advMode.notEnabled", new Object[0])); - } - else if (this.playerEntity.canCommandSenderUseCommand(2, "") && this.playerEntity.capabilities.isCreativeMode) - { - try - { - PacketBuffer packetbuffer = new PacketBuffer(Unpooled.wrappedBuffer(p_147349_1_.func_149558_e())); - byte b0 = packetbuffer.readByte(); - CommandBlockLogic commandblocklogic = null; - - if (b0 == 0) - { - TileEntity tileentity = this.playerEntity.worldObj.getTileEntity(packetbuffer.readInt(), packetbuffer.readInt(), packetbuffer.readInt()); - - if (tileentity instanceof TileEntityCommandBlock) - { - commandblocklogic = ((TileEntityCommandBlock)tileentity).func_145993_a(); - } - } - else if (b0 == 1) - { - Entity entity = this.playerEntity.worldObj.getEntityByID(packetbuffer.readInt()); - - if (entity instanceof EntityMinecartCommandBlock) - { - commandblocklogic = ((EntityMinecartCommandBlock)entity).func_145822_e(); - } - } - - String s1 = packetbuffer.readStringFromBuffer(packetbuffer.readableBytes()); - - if (commandblocklogic != null) - { - commandblocklogic.func_145752_a(s1); - commandblocklogic.func_145756_e(); - this.playerEntity.addChatMessage(new ChatComponentTranslation("advMode.setCommand.success", new Object[] {s1})); - } - } - catch (Exception exception1) - { - logger.error("Couldn\'t set command block", exception1); - } - } - else - { - this.playerEntity.addChatMessage(new ChatComponentTranslation("advMode.notAllowed", new Object[0])); - } - } - else if ("MC|Beacon".equals(p_147349_1_.func_149559_c())) - { - if (this.playerEntity.openContainer instanceof ContainerBeacon) - { - try - { - datainputstream = new DataInputStream(new ByteArrayInputStream(p_147349_1_.func_149558_e())); - i = datainputstream.readInt(); - int j = datainputstream.readInt(); - ContainerBeacon containerbeacon = (ContainerBeacon)this.playerEntity.openContainer; - Slot slot = containerbeacon.getSlot(0); - - if (slot.getHasStack()) - { - slot.decrStackSize(1); - TileEntityBeacon tileentitybeacon = containerbeacon.func_148327_e(); - tileentitybeacon.setPrimaryEffect(i); - tileentitybeacon.setSecondaryEffect(j); - tileentitybeacon.markDirty(); - } - } - catch (Exception exception) - { - logger.error("Couldn\'t set beacon", exception); - } - } - } - else if ("MC|ItemName".equals(p_147349_1_.func_149559_c()) && this.playerEntity.openContainer instanceof ContainerRepair) - { - ContainerRepair containerrepair = (ContainerRepair)this.playerEntity.openContainer; - - if (p_147349_1_.func_149558_e() != null && p_147349_1_.func_149558_e().length >= 1) - { - String s = ChatAllowedCharacters.filerAllowedCharacters(new String(p_147349_1_.func_149558_e(), Charsets.UTF_8)); - - if (s.length() <= 30) - { - containerrepair.updateItemName(s); - } - } - else - { - containerrepair.updateItemName(""); - } - } - } - } - - public void onConnectionStateTransition(EnumConnectionState p_147232_1_, EnumConnectionState p_147232_2_) - { - if (p_147232_2_ != EnumConnectionState.PLAY) - { - throw new IllegalStateException("Unexpected change in protocol!"); - } - } - - static final class SwitchEnumState - { - static final int[] field_151290_a = new int[C16PacketClientStatus.EnumState.values().length]; - private static final String __OBFID = "CL_00001455"; - - static - { - try - { - field_151290_a[C16PacketClientStatus.EnumState.PERFORM_RESPAWN.ordinal()] = 1; - } - catch (NoSuchFieldError var3) - { - ; - } - - try - { - field_151290_a[C16PacketClientStatus.EnumState.REQUEST_STATS.ordinal()] = 2; - } - catch (NoSuchFieldError var2) - { - ; - } - - try - { - field_151290_a[C16PacketClientStatus.EnumState.OPEN_INVENTORY_ACHIEVEMENT.ordinal()] = 3; - } - catch (NoSuchFieldError var1) - { - ; - } - } - } +package net.minecraft.network; + +import com.google.common.base.Charsets; +import com.google.common.collect.Lists; +import io.netty.buffer.Unpooled; +import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.GenericFutureListener; +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.Random; +import java.util.concurrent.Callable; +import net.minecraft.block.material.Material; +import net.minecraft.command.server.CommandBlockLogic; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityMinecartCommandBlock; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.item.EntityXPOrb; +import net.minecraft.entity.passive.EntityHorse; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.init.Items; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ContainerBeacon; +import net.minecraft.inventory.ContainerMerchant; +import net.minecraft.inventory.ContainerRepair; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemEditableBook; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemWritableBook; +import net.minecraft.nbt.NBTTagString; +import net.minecraft.network.play.INetHandlerPlayServer; +import net.minecraft.network.play.client.C00PacketKeepAlive; +import net.minecraft.network.play.client.C01PacketChatMessage; +import net.minecraft.network.play.client.C02PacketUseEntity; +import net.minecraft.network.play.client.C03PacketPlayer; +import net.minecraft.network.play.client.C07PacketPlayerDigging; +import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement; +import net.minecraft.network.play.client.C09PacketHeldItemChange; +import net.minecraft.network.play.client.C0APacketAnimation; +import net.minecraft.network.play.client.C0BPacketEntityAction; +import net.minecraft.network.play.client.C0CPacketInput; +import net.minecraft.network.play.client.C0DPacketCloseWindow; +import net.minecraft.network.play.client.C0EPacketClickWindow; +import net.minecraft.network.play.client.C0FPacketConfirmTransaction; +import net.minecraft.network.play.client.C10PacketCreativeInventoryAction; +import net.minecraft.network.play.client.C11PacketEnchantItem; +import net.minecraft.network.play.client.C12PacketUpdateSign; +import net.minecraft.network.play.client.C13PacketPlayerAbilities; +import net.minecraft.network.play.client.C14PacketTabComplete; +import net.minecraft.network.play.client.C15PacketClientSettings; +import net.minecraft.network.play.client.C16PacketClientStatus; +import net.minecraft.network.play.client.C17PacketCustomPayload; +import net.minecraft.network.play.server.S00PacketKeepAlive; +import net.minecraft.network.play.server.S02PacketChat; +import net.minecraft.network.play.server.S08PacketPlayerPosLook; +import net.minecraft.network.play.server.S23PacketBlockChange; +import net.minecraft.network.play.server.S2FPacketSetSlot; +import net.minecraft.network.play.server.S32PacketConfirmTransaction; +import net.minecraft.network.play.server.S3APacketTabComplete; +import net.minecraft.network.play.server.S40PacketDisconnect; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.management.BanEntry; +import net.minecraft.stats.AchievementList; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityBeacon; +import net.minecraft.tileentity.TileEntityCommandBlock; +import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChatAllowedCharacters; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IChatComponent; +import net.minecraft.util.IntHashMap; +import net.minecraft.util.ReportedException; +import net.minecraft.world.WorldServer; +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.common.MinecraftForge; +import cpw.mods.fml.common.eventhandler.Event; +import net.minecraftforge.event.ForgeEventFactory; +import net.minecraftforge.event.ServerChatEvent; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; + +public class NetHandlerPlayServer implements INetHandlerPlayServer +{ + private static final Logger logger = LogManager.getLogger(); + public final NetworkManager netManager; + private final MinecraftServer serverController; + public EntityPlayerMP playerEntity; + private int networkTickCount; + private int floatingTickCount; + private boolean field_147366_g; + private int field_147378_h; + private long field_147379_i; + private static Random field_147376_j = new Random(); + private long field_147377_k; + private int chatSpamThresholdCount; + private int field_147375_m; + private IntHashMap field_147372_n = new IntHashMap(); + private double lastPosX; + private double lastPosY; + private double lastPosZ; + private boolean hasMoved = true; + private static final String __OBFID = "CL_00001452"; + + public NetHandlerPlayServer(MinecraftServer par1MinecraftServer, NetworkManager par2INetworkManager, EntityPlayerMP par3EntityPlayerMP) + { + this.serverController = par1MinecraftServer; + this.netManager = par2INetworkManager; + par2INetworkManager.setNetHandler(this); + this.playerEntity = par3EntityPlayerMP; + par3EntityPlayerMP.playerNetServerHandler = this; + } + + public void onNetworkTick() + { + this.field_147366_g = false; + ++this.networkTickCount; + this.serverController.theProfiler.startSection("keepAlive"); + + if ((long)this.networkTickCount - this.field_147377_k > 40L) + { + this.field_147377_k = (long)this.networkTickCount; + this.field_147379_i = this.func_147363_d(); + this.field_147378_h = (int)this.field_147379_i; + this.sendPacket(new S00PacketKeepAlive(this.field_147378_h)); + } + + if (this.chatSpamThresholdCount > 0) + { + --this.chatSpamThresholdCount; + } + + if (this.field_147375_m > 0) + { + --this.field_147375_m; + } + + this.serverController.theProfiler.endStartSection("playerTick"); + this.serverController.theProfiler.endSection(); + } + + public NetworkManager func_147362_b() + { + return this.netManager; + } + + public void kickPlayerFromServer(String p_147360_1_) + { + final ChatComponentText chatcomponenttext = new ChatComponentText(p_147360_1_); + this.netManager.scheduleOutboundPacket(new S40PacketDisconnect(chatcomponenttext), new GenericFutureListener[] {new GenericFutureListener() + { + private static final String __OBFID = "CL_00001453"; + public void operationComplete(Future p_operationComplete_1_) + { + NetHandlerPlayServer.this.netManager.closeChannel(chatcomponenttext); + } + } + }); + this.netManager.disableAutoRead(); + } + + public void processInput(C0CPacketInput p_147358_1_) + { + this.playerEntity.setEntityActionState(p_147358_1_.func_149620_c(), p_147358_1_.func_149616_d(), p_147358_1_.func_149618_e(), p_147358_1_.func_149617_f()); + } + + public void processPlayer(C03PacketPlayer p_147347_1_) + { + WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension); + this.field_147366_g = true; + + if (!this.playerEntity.playerConqueredTheEnd) + { + double d0; + + if (!this.hasMoved) + { + d0 = p_147347_1_.func_149467_d() - this.lastPosY; + + if (p_147347_1_.func_149464_c() == this.lastPosX && d0 * d0 < 0.01D && p_147347_1_.func_149472_e() == this.lastPosZ) + { + this.hasMoved = true; + } + } + + if (this.hasMoved) + { + double d1; + double d2; + double d3; + + if (this.playerEntity.ridingEntity != null) + { + float f4 = this.playerEntity.rotationYaw; + float f = this.playerEntity.rotationPitch; + this.playerEntity.ridingEntity.updateRiderPosition(); + d1 = this.playerEntity.posX; + d2 = this.playerEntity.posY; + d3 = this.playerEntity.posZ; + + if (p_147347_1_.func_149463_k()) + { + f4 = p_147347_1_.func_149462_g(); + f = p_147347_1_.func_149470_h(); + } + + this.playerEntity.onGround = p_147347_1_.func_149465_i(); + this.playerEntity.onUpdateEntity(); + this.playerEntity.ySize = 0.0F; + this.playerEntity.setPositionAndRotation(d1, d2, d3, f4, f); + + if (this.playerEntity.ridingEntity != null) + { + this.playerEntity.ridingEntity.updateRiderPosition(); + } + + if (!this.hasMoved) //Fixes teleportation kick while riding entities + { + return; + } + + this.serverController.getConfigurationManager().updatePlayerPertinentChunks(this.playerEntity); + + if (this.hasMoved) + { + this.lastPosX = this.playerEntity.posX; + this.lastPosY = this.playerEntity.posY; + this.lastPosZ = this.playerEntity.posZ; + } + + worldserver.updateEntity(this.playerEntity); + return; + } + + if (this.playerEntity.isPlayerSleeping()) + { + this.playerEntity.onUpdateEntity(); + this.playerEntity.setPositionAndRotation(this.lastPosX, this.lastPosY, this.lastPosZ, this.playerEntity.rotationYaw, this.playerEntity.rotationPitch); + worldserver.updateEntity(this.playerEntity); + return; + } + + d0 = this.playerEntity.posY; + this.lastPosX = this.playerEntity.posX; + this.lastPosY = this.playerEntity.posY; + this.lastPosZ = this.playerEntity.posZ; + d1 = this.playerEntity.posX; + d2 = this.playerEntity.posY; + d3 = this.playerEntity.posZ; + float f1 = this.playerEntity.rotationYaw; + float f2 = this.playerEntity.rotationPitch; + + if (p_147347_1_.func_149466_j() && p_147347_1_.func_149467_d() == -999.0D && p_147347_1_.func_149471_f() == -999.0D) + { + p_147347_1_.func_149469_a(false); + } + + double d4; + + if (p_147347_1_.func_149466_j()) + { + d1 = p_147347_1_.func_149464_c(); + d2 = p_147347_1_.func_149467_d(); + d3 = p_147347_1_.func_149472_e(); + d4 = p_147347_1_.func_149471_f() - p_147347_1_.func_149467_d(); + + if (!this.playerEntity.isPlayerSleeping() && (d4 > 1.65D || d4 < 0.1D)) + { + this.kickPlayerFromServer("Illegal stance"); + logger.warn(this.playerEntity.getCommandSenderName() + " had an illegal stance: " + d4); + return; + } + + if (Math.abs(p_147347_1_.func_149464_c()) > 3.2E7D || Math.abs(p_147347_1_.func_149472_e()) > 3.2E7D) + { + this.kickPlayerFromServer("Illegal position"); + return; + } + } + + if (p_147347_1_.func_149463_k()) + { + f1 = p_147347_1_.func_149462_g(); + f2 = p_147347_1_.func_149470_h(); + } + + this.playerEntity.onUpdateEntity(); + this.playerEntity.ySize = 0.0F; + this.playerEntity.setPositionAndRotation(this.lastPosX, this.lastPosY, this.lastPosZ, f1, f2); + + if (!this.hasMoved) + { + return; + } + + d4 = d1 - this.playerEntity.posX; + double d5 = d2 - this.playerEntity.posY; + double d6 = d3 - this.playerEntity.posZ; + //BUGFIX: min -> max, grabs the highest distance + double d7 = Math.max(Math.abs(d4), Math.abs(this.playerEntity.motionX)); + double d8 = Math.max(Math.abs(d5), Math.abs(this.playerEntity.motionY)); + double d9 = Math.max(Math.abs(d6), Math.abs(this.playerEntity.motionZ)); + double d10 = d7 * d7 + d8 * d8 + d9 * d9; + + if (d10 > 100.0D && (!this.serverController.isSinglePlayer() || !this.serverController.getServerOwner().equals(this.playerEntity.getCommandSenderName()))) + { + logger.warn(this.playerEntity.getCommandSenderName() + " moved too quickly! " + d4 + "," + d5 + "," + d6 + " (" + d7 + ", " + d8 + ", " + d9 + ")"); + this.setPlayerLocation(this.lastPosX, this.lastPosY, this.lastPosZ, this.playerEntity.rotationYaw, this.playerEntity.rotationPitch); + return; + } + + float f3 = 0.0625F; + boolean flag = worldserver.getCollidingBoundingBoxes(this.playerEntity, this.playerEntity.boundingBox.copy().contract((double)f3, (double)f3, (double)f3)).isEmpty(); + + if (this.playerEntity.onGround && !p_147347_1_.func_149465_i() && d5 > 0.0D) + { + this.playerEntity.jump(); + } + + if (!this.hasMoved) //Fixes "Moved Too Fast" kick when being teleported while moving + { + return; + } + + this.playerEntity.moveEntity(d4, d5, d6); + this.playerEntity.onGround = p_147347_1_.func_149465_i(); + this.playerEntity.addMovementStat(d4, d5, d6); + double d11 = d5; + d4 = d1 - this.playerEntity.posX; + d5 = d2 - this.playerEntity.posY; + + if (d5 > -0.5D || d5 < 0.5D) + { + d5 = 0.0D; + } + + d6 = d3 - this.playerEntity.posZ; + d10 = d4 * d4 + d5 * d5 + d6 * d6; + boolean flag1 = false; + + if (d10 > 0.0625D && !this.playerEntity.isPlayerSleeping() && !this.playerEntity.theItemInWorldManager.isCreative()) + { + flag1 = true; + logger.warn(this.playerEntity.getCommandSenderName() + " moved wrongly!"); + } + + if (!this.hasMoved) //Fixes "Moved Too Fast" kick when being teleported while moving + { + return; + } + + this.playerEntity.setPositionAndRotation(d1, d2, d3, f1, f2); + boolean flag2 = worldserver.getCollidingBoundingBoxes(this.playerEntity, this.playerEntity.boundingBox.copy().contract((double)f3, (double)f3, (double)f3)).isEmpty(); + + if (flag && (flag1 || !flag2) && !this.playerEntity.isPlayerSleeping() && !this.playerEntity.noClip) + { + this.setPlayerLocation(this.lastPosX, this.lastPosY, this.lastPosZ, f1, f2); + return; + } + + AxisAlignedBB axisalignedbb = this.playerEntity.boundingBox.copy().expand((double)f3, (double)f3, (double)f3).addCoord(0.0D, -0.55D, 0.0D); + + if (!this.serverController.isFlightAllowed() && !this.playerEntity.theItemInWorldManager.isCreative() && !worldserver.checkBlockCollision(axisalignedbb) && !this.playerEntity.capabilities.allowFlying) + { + if (d11 >= -0.03125D) + { + ++this.floatingTickCount; + + if (this.floatingTickCount > 80) + { + logger.warn(this.playerEntity.getCommandSenderName() + " was kicked for floating too long!"); + this.kickPlayerFromServer("Flying is not enabled on this server"); + return; + } + } + } + else + { + this.floatingTickCount = 0; + } + + if (!this.hasMoved) //Fixes "Moved Too Fast" kick when being teleported while moving + { + return; + } + + this.playerEntity.onGround = p_147347_1_.func_149465_i(); + this.serverController.getConfigurationManager().updatePlayerPertinentChunks(this.playerEntity); + this.playerEntity.handleFalling(this.playerEntity.posY - d0, p_147347_1_.func_149465_i()); + } + else if (this.networkTickCount % 20 == 0) + { + this.setPlayerLocation(this.lastPosX, this.lastPosY, this.lastPosZ, this.playerEntity.rotationYaw, this.playerEntity.rotationPitch); + } + } + } + + public void setPlayerLocation(double p_147364_1_, double p_147364_3_, double p_147364_5_, float p_147364_7_, float p_147364_8_) + { + this.hasMoved = false; + this.lastPosX = p_147364_1_; + this.lastPosY = p_147364_3_; + this.lastPosZ = p_147364_5_; + this.playerEntity.setPositionAndRotation(p_147364_1_, p_147364_3_, p_147364_5_, p_147364_7_, p_147364_8_); + this.playerEntity.playerNetServerHandler.sendPacket(new S08PacketPlayerPosLook(p_147364_1_, p_147364_3_ + 1.6200000047683716D, p_147364_5_, p_147364_7_, p_147364_8_, false)); + } + + public void processPlayerDigging(C07PacketPlayerDigging p_147345_1_) + { + WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension); + this.playerEntity.func_143004_u(); + + if (p_147345_1_.func_149506_g() == 4) + { + this.playerEntity.dropOneItem(false); + } + else if (p_147345_1_.func_149506_g() == 3) + { + this.playerEntity.dropOneItem(true); + } + else if (p_147345_1_.func_149506_g() == 5) + { + this.playerEntity.stopUsingItem(); + } + else + { + boolean flag = false; + + if (p_147345_1_.func_149506_g() == 0) + { + flag = true; + } + + if (p_147345_1_.func_149506_g() == 1) + { + flag = true; + } + + if (p_147345_1_.func_149506_g() == 2) + { + flag = true; + } + + int i = p_147345_1_.func_149505_c(); + int j = p_147345_1_.func_149503_d(); + int k = p_147345_1_.func_149502_e(); + + if (flag) + { + double d0 = this.playerEntity.posX - ((double)i + 0.5D); + double d1 = this.playerEntity.posY - ((double)j + 0.5D) + 1.5D; + double d2 = this.playerEntity.posZ - ((double)k + 0.5D); + double d3 = d0 * d0 + d1 * d1 + d2 * d2; + + double dist = playerEntity.theItemInWorldManager.getBlockReachDistance() + 1; + dist *= dist; + + if (d3 > dist) + { + return; + } + + if (j >= playerEntity.getServerForPlayer().getConfig().settings.maxBuildHeight) + { + return; + } + } + + if (p_147345_1_.func_149506_g() == 0) + { + if (!this.serverController.isBlockProtected(worldserver, i, j, k, this.playerEntity)) + { + this.playerEntity.theItemInWorldManager.onBlockClicked(i, j, k, p_147345_1_.func_149501_f()); + } + else + { + this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(i, j, k, worldserver)); + } + } + else if (p_147345_1_.func_149506_g() == 2) + { + this.playerEntity.theItemInWorldManager.uncheckedTryHarvestBlock(i, j, k); + + if (worldserver.getBlock(i, j, k).getMaterial() != Material.air) + { + this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(i, j, k, worldserver)); + } + } + else if (p_147345_1_.func_149506_g() == 1) + { + this.playerEntity.theItemInWorldManager.cancelDestroyingBlock(i, j, k); + + if (worldserver.getBlock(i, j, k).getMaterial() != Material.air) + { + this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(i, j, k, worldserver)); + } + } + } + } + + public void processPlayerBlockPlacement(C08PacketPlayerBlockPlacement p_147346_1_) + { + WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension); + ItemStack itemstack = this.playerEntity.inventory.getCurrentItem(); + boolean flag = false; + int i = p_147346_1_.func_149576_c(); + int j = p_147346_1_.func_149571_d(); + int k = p_147346_1_.func_149570_e(); + int l = p_147346_1_.func_149568_f(); + this.playerEntity.func_143004_u(); + + int buildlimit = playerEntity.getServerForPlayer().getConfig().settings.maxBuildHeight; + + if (p_147346_1_.func_149568_f() == 255) + { + if (itemstack == null) + { + return; + } + + PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(playerEntity, PlayerInteractEvent.Action.RIGHT_CLICK_AIR, 0, 0, 0, -1); + if (event.useItem != Event.Result.DENY) + { + this.playerEntity.theItemInWorldManager.tryUseItem(this.playerEntity, worldserver, itemstack); + } + } + else if (p_147346_1_.func_149571_d() >= buildlimit - 1 && (p_147346_1_.func_149568_f() == 1 || p_147346_1_.func_149571_d() >= buildlimit)) + { + ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("build.tooHigh", new Object[] {Integer.valueOf(buildlimit)}); + chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED); + this.playerEntity.playerNetServerHandler.sendPacket(new S02PacketChat(chatcomponenttranslation)); + flag = true; + } + else + { + double dist = playerEntity.theItemInWorldManager.getBlockReachDistance() + 1; + dist *= dist; + if (this.hasMoved && this.playerEntity.getDistanceSq((double)i + 0.5D, (double)j + 0.5D, (double)k + 0.5D) < dist && !this.serverController.isBlockProtected(worldserver, i, j, k, this.playerEntity)) + { + this.playerEntity.theItemInWorldManager.activateBlockOrUseItem(this.playerEntity, worldserver, itemstack, i, j, k, l, p_147346_1_.func_149573_h(), p_147346_1_.func_149569_i(), p_147346_1_.func_149575_j()); + } + + flag = true; + } + + if (flag) + { + this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(i, j, k, worldserver)); + + if (l == 0) + { + --j; + } + + if (l == 1) + { + ++j; + } + + if (l == 2) + { + --k; + } + + if (l == 3) + { + ++k; + } + + if (l == 4) + { + --i; + } + + if (l == 5) + { + ++i; + } + + this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(i, j, k, worldserver)); + } + + itemstack = this.playerEntity.inventory.getCurrentItem(); + + if (itemstack != null && itemstack.stackSize == 0) + { + this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = null; + itemstack = null; + } + + if (itemstack == null || itemstack.getMaxItemUseDuration() == 0) + { + this.playerEntity.isChangingQuantityOnly = true; + this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = ItemStack.copyItemStack(this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem]); + Slot slot = this.playerEntity.openContainer.getSlotFromInventory(this.playerEntity.inventory, this.playerEntity.inventory.currentItem); + this.playerEntity.openContainer.detectAndSendChanges(); + this.playerEntity.isChangingQuantityOnly = false; + + if (!ItemStack.areItemStacksEqual(this.playerEntity.inventory.getCurrentItem(), p_147346_1_.func_149574_g())) + { + this.sendPacket(new S2FPacketSetSlot(this.playerEntity.openContainer.windowId, slot.slotNumber, this.playerEntity.inventory.getCurrentItem())); + } + } + } + + public void onDisconnect(IChatComponent p_147231_1_) + { + logger.info(this.playerEntity.getCommandSenderName() + " lost connection: " + p_147231_1_); + this.serverController.func_147132_au(); + ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("multiplayer.player.left", new Object[] {this.playerEntity.func_145748_c_()}); + chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.YELLOW); + this.serverController.getConfigurationManager().sendChatMsg(chatcomponenttranslation); + this.playerEntity.mountEntityAndWakeUp(); + this.serverController.getConfigurationManager().playerLoggedOut(this.playerEntity); + + if (this.serverController.isSinglePlayer() && this.playerEntity.getCommandSenderName().equals(this.serverController.getServerOwner())) + { + logger.info("Stopping singleplayer server as player logged out"); + this.serverController.initiateShutdown(); + } + } + + public void sendPacket(final Packet p_147359_1_) + { + if (p_147359_1_ instanceof S02PacketChat) + { + S02PacketChat s02packetchat = (S02PacketChat)p_147359_1_; + EntityPlayer.EnumChatVisibility enumchatvisibility = this.playerEntity.func_147096_v(); + + if (enumchatvisibility == EntityPlayer.EnumChatVisibility.HIDDEN) + { + return; + } + + if (enumchatvisibility == EntityPlayer.EnumChatVisibility.SYSTEM && !s02packetchat.func_148916_d()) + { + return; + } + } + + try + { + this.netManager.scheduleOutboundPacket(p_147359_1_, new GenericFutureListener[0]); + } + catch (Throwable throwable) + { + CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Sending packet"); + CrashReportCategory crashreportcategory = crashreport.makeCategory("Packet being sent"); + crashreportcategory.addCrashSectionCallable("Packet class", new Callable() + { + private static final String __OBFID = "CL_00001454"; + public String call() + { + return p_147359_1_.getClass().getCanonicalName(); + } + }); + throw new ReportedException(crashreport); + } + } + + public void processHeldItemChange(C09PacketHeldItemChange p_147355_1_) + { + if (p_147355_1_.func_149614_c() >= 0 && p_147355_1_.func_149614_c() < InventoryPlayer.getHotbarSize()) + { + this.playerEntity.inventory.currentItem = p_147355_1_.func_149614_c(); + this.playerEntity.func_143004_u(); + } + else + { + logger.warn(this.playerEntity.getCommandSenderName() + " tried to set an invalid carried item"); + } + } + + public void processChatMessage(C01PacketChatMessage p_147354_1_) + { + if (this.playerEntity.func_147096_v() == EntityPlayer.EnumChatVisibility.HIDDEN) + { + ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("chat.cannotSend", new Object[0]); + chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED); + this.sendPacket(new S02PacketChat(chatcomponenttranslation)); + } + else + { + this.playerEntity.func_143004_u(); + String s = p_147354_1_.func_149439_c(); + s = StringUtils.normalizeSpace(s); + + for (int i = 0; i < s.length(); ++i) + { + if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i))) + { + this.kickPlayerFromServer("Illegal characters in chat"); + return; + } + } + + if (s.startsWith("/")) + { + this.handleSlashCommand(s); + } + else + { + ChatComponentTranslation chatcomponenttranslation1 = new ChatComponentTranslation("chat.type.text", new Object[] {this.playerEntity.func_145748_c_(), s}); + chatcomponenttranslation1 = ForgeHooks.onServerChatEvent(this, s, chatcomponenttranslation1); + if (chatcomponenttranslation1 == null) return; + this.serverController.getConfigurationManager().sendChatMsgImpl(chatcomponenttranslation1, false); + } + + this.chatSpamThresholdCount += 20; + + if (this.chatSpamThresholdCount > 200 && !this.serverController.getConfigurationManager().isPlayerOpped(this.playerEntity.getCommandSenderName())) + { + this.kickPlayerFromServer("disconnect.spam"); + } + } + } + + private void handleSlashCommand(String p_147361_1_) + { + this.serverController.getCommandManager().executeCommand(this.playerEntity, p_147361_1_); + } + + public void processAnimation(C0APacketAnimation p_147350_1_) + { + this.playerEntity.func_143004_u(); + + if (p_147350_1_.func_149421_d() == 1) + { + this.playerEntity.swingItem(); + } + } + + public void processEntityAction(C0BPacketEntityAction p_147357_1_) + { + this.playerEntity.func_143004_u(); + + if (p_147357_1_.func_149513_d() == 1) + { + this.playerEntity.setSneaking(true); + } + else if (p_147357_1_.func_149513_d() == 2) + { + this.playerEntity.setSneaking(false); + } + else if (p_147357_1_.func_149513_d() == 4) + { + this.playerEntity.setSprinting(true); + } + else if (p_147357_1_.func_149513_d() == 5) + { + this.playerEntity.setSprinting(false); + } + else if (p_147357_1_.func_149513_d() == 3) + { + this.playerEntity.wakeUpPlayer(false, true, true); + this.hasMoved = false; + } + else if (p_147357_1_.func_149513_d() == 6) + { + if (this.playerEntity.ridingEntity != null && this.playerEntity.ridingEntity instanceof EntityHorse) + { + ((EntityHorse)this.playerEntity.ridingEntity).setJumpPower(p_147357_1_.func_149512_e()); + } + } + else if (p_147357_1_.func_149513_d() == 7 && this.playerEntity.ridingEntity != null && this.playerEntity.ridingEntity instanceof EntityHorse) + { + ((EntityHorse)this.playerEntity.ridingEntity).openGUI(this.playerEntity); + } + } + + public void processUseEntity(C02PacketUseEntity p_147340_1_) + { + WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension); + Entity entity = p_147340_1_.func_149564_a(worldserver); + this.playerEntity.func_143004_u(); + + if (entity != null) + { + boolean flag = this.playerEntity.canEntityBeSeen(entity); + double d0 = 36.0D; + + if (!flag) + { + d0 = 9.0D; + } + + if (this.playerEntity.getDistanceSqToEntity(entity) < d0) + { + if (p_147340_1_.func_149565_c() == C02PacketUseEntity.Action.INTERACT) + { + this.playerEntity.interactWith(entity); + } + else if (p_147340_1_.func_149565_c() == C02PacketUseEntity.Action.ATTACK) + { + if (entity instanceof EntityItem || entity instanceof EntityXPOrb || entity instanceof EntityArrow || entity == this.playerEntity) + { + this.kickPlayerFromServer("Attempting to attack an invalid entity"); + this.serverController.logWarning("Player " + this.playerEntity.getCommandSenderName() + " tried to attack an invalid entity"); + return; + } + + this.playerEntity.attackTargetEntityWithCurrentItem(entity); + } + } + } + } + + public void processClientStatus(C16PacketClientStatus p_147342_1_) + { + this.playerEntity.func_143004_u(); + C16PacketClientStatus.EnumState enumstate = p_147342_1_.func_149435_c(); + + switch (NetHandlerPlayServer.SwitchEnumState.field_151290_a[enumstate.ordinal()]) + { + case 1: + if (this.playerEntity.playerConqueredTheEnd) + { + this.playerEntity = this.serverController.getConfigurationManager().respawnPlayer(this.playerEntity, 0, true); + } + else if (this.playerEntity.getServerForPlayer().getWorldInfo().isHardcoreModeEnabled()) + { + if (this.serverController.isSinglePlayer() && this.playerEntity.getCommandSenderName().equals(this.serverController.getServerOwner())) + { + this.playerEntity.playerNetServerHandler.kickPlayerFromServer("You have died. Game over, man, it\'s game over!"); + this.serverController.deleteWorldAndStopServer(); + } + else + { + BanEntry banentry = new BanEntry(this.playerEntity.getCommandSenderName()); + banentry.setBanReason("Death in Hardcore"); + this.serverController.getConfigurationManager().getBannedPlayers().put(banentry); + this.playerEntity.playerNetServerHandler.kickPlayerFromServer("You have died. Game over, man, it\'s game over!"); + } + } + else + { + if (this.playerEntity.getHealth() > 0.0F) + { + return; + } + + this.playerEntity = this.serverController.getConfigurationManager().respawnPlayer(this.playerEntity, playerEntity.dimension, false); + } + + break; + case 2: + this.playerEntity.func_147099_x().func_150876_a(this.playerEntity); + break; + case 3: + this.playerEntity.triggerAchievement(AchievementList.openInventory); + } + } + + public void processCloseWindow(C0DPacketCloseWindow p_147356_1_) + { + this.playerEntity.closeContainer(); + } + + public void processClickWindow(C0EPacketClickWindow p_147351_1_) + { + this.playerEntity.func_143004_u(); + + if (this.playerEntity.openContainer.windowId == p_147351_1_.func_149548_c() && this.playerEntity.openContainer.isPlayerNotUsingContainer(this.playerEntity)) + { + ItemStack itemstack = this.playerEntity.openContainer.slotClick(p_147351_1_.func_149544_d(), p_147351_1_.func_149543_e(), p_147351_1_.func_149542_h(), this.playerEntity); + + if (ItemStack.areItemStacksEqual(p_147351_1_.func_149546_g(), itemstack)) + { + this.playerEntity.playerNetServerHandler.sendPacket(new S32PacketConfirmTransaction(p_147351_1_.func_149548_c(), p_147351_1_.func_149547_f(), true)); + this.playerEntity.isChangingQuantityOnly = true; + this.playerEntity.openContainer.detectAndSendChanges(); + this.playerEntity.updateHeldItem(); + this.playerEntity.isChangingQuantityOnly = false; + } + else + { + this.field_147372_n.addKey(this.playerEntity.openContainer.windowId, Short.valueOf(p_147351_1_.func_149547_f())); + this.playerEntity.playerNetServerHandler.sendPacket(new S32PacketConfirmTransaction(p_147351_1_.func_149548_c(), p_147351_1_.func_149547_f(), false)); + this.playerEntity.openContainer.setPlayerIsPresent(this.playerEntity, false); + ArrayList arraylist = new ArrayList(); + + for (int i = 0; i < this.playerEntity.openContainer.inventorySlots.size(); ++i) + { + arraylist.add(((Slot)this.playerEntity.openContainer.inventorySlots.get(i)).getStack()); + } + + this.playerEntity.sendContainerAndContentsToPlayer(this.playerEntity.openContainer, arraylist); + } + } + } + + public void processEnchantItem(C11PacketEnchantItem p_147338_1_) + { + this.playerEntity.func_143004_u(); + + if (this.playerEntity.openContainer.windowId == p_147338_1_.func_149539_c() && this.playerEntity.openContainer.isPlayerNotUsingContainer(this.playerEntity)) + { + this.playerEntity.openContainer.enchantItem(this.playerEntity, p_147338_1_.func_149537_d()); + this.playerEntity.openContainer.detectAndSendChanges(); + } + } + + public void processCreativeInventoryAction(C10PacketCreativeInventoryAction p_147344_1_) + { + if (this.playerEntity.theItemInWorldManager.isCreative()) + { + boolean flag = p_147344_1_.func_149627_c() < 0; + ItemStack itemstack = p_147344_1_.func_149625_d(); + boolean flag1 = p_147344_1_.func_149627_c() >= 1 && p_147344_1_.func_149627_c() < 36 + InventoryPlayer.getHotbarSize(); + boolean flag2 = itemstack == null || itemstack.getItem() != null; + boolean flag3 = itemstack == null || itemstack.getItemDamage() >= 0 && itemstack.stackSize <= 64 && itemstack.stackSize > 0; + + if (flag1 && flag2 && flag3) + { + if (itemstack == null) + { + this.playerEntity.inventoryContainer.putStackInSlot(p_147344_1_.func_149627_c(), (ItemStack)null); + } + else + { + this.playerEntity.inventoryContainer.putStackInSlot(p_147344_1_.func_149627_c(), itemstack); + } + + this.playerEntity.inventoryContainer.setPlayerIsPresent(this.playerEntity, true); + } + else if (flag && flag2 && flag3 && this.field_147375_m < 200) + { + this.field_147375_m += 20; + EntityItem entityitem = this.playerEntity.dropPlayerItemWithRandomChoice(itemstack, true); + + if (entityitem != null) + { + entityitem.setAgeToCreativeDespawnTime(); + } + } + } + } + + public void processConfirmTransaction(C0FPacketConfirmTransaction p_147339_1_) + { + Short oshort = (Short)this.field_147372_n.lookup(this.playerEntity.openContainer.windowId); + + if (oshort != null && p_147339_1_.func_149533_d() == oshort.shortValue() && this.playerEntity.openContainer.windowId == p_147339_1_.func_149532_c() && !this.playerEntity.openContainer.isPlayerNotUsingContainer(this.playerEntity)) + { + this.playerEntity.openContainer.setPlayerIsPresent(this.playerEntity, true); + } + } + + public void processUpdateSign(C12PacketUpdateSign p_147343_1_) + { + this.playerEntity.func_143004_u(); + WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension); + + if (worldserver.blockExists(p_147343_1_.func_149588_c(), p_147343_1_.func_149586_d(), p_147343_1_.func_149585_e())) + { + TileEntity tileentity = worldserver.getTileEntity(p_147343_1_.func_149588_c(), p_147343_1_.func_149586_d(), p_147343_1_.func_149585_e()); + + if (tileentity instanceof TileEntitySign) + { + TileEntitySign tileentitysign = (TileEntitySign)tileentity; + + if (!tileentitysign.func_145914_a() || tileentitysign.func_145911_b() != this.playerEntity) + { + this.serverController.logWarning("Player " + this.playerEntity.getCommandSenderName() + " just tried to change non-editable sign"); + return; + } + } + + int i; + int j; + + for (j = 0; j < 4; ++j) + { + boolean flag = true; + + if (p_147343_1_.func_149589_f()[j].length() > 15) + { + flag = false; + } + else + { + for (i = 0; i < p_147343_1_.func_149589_f()[j].length(); ++i) + { + if (!ChatAllowedCharacters.isAllowedCharacter(p_147343_1_.func_149589_f()[j].charAt(i))) + { + flag = false; + } + } + } + + if (!flag) + { + p_147343_1_.func_149589_f()[j] = "!?"; + } + } + + if (tileentity instanceof TileEntitySign) + { + j = p_147343_1_.func_149588_c(); + int k = p_147343_1_.func_149586_d(); + i = p_147343_1_.func_149585_e(); + TileEntitySign tileentitysign1 = (TileEntitySign)tileentity; + System.arraycopy(p_147343_1_.func_149589_f(), 0, tileentitysign1.signText, 0, 4); + tileentitysign1.markDirty(); + worldserver.markBlockForUpdate(j, k, i); + } + } + } + + public void processKeepAlive(C00PacketKeepAlive p_147353_1_) + { + if (p_147353_1_.func_149460_c() == this.field_147378_h) + { + int i = (int)(this.func_147363_d() - this.field_147379_i); + this.playerEntity.ping = (this.playerEntity.ping * 3 + i) / 4; + } + } + + private long func_147363_d() + { + return System.nanoTime() / 1000000L; + } + + public void processPlayerAbilities(C13PacketPlayerAbilities p_147348_1_) + { + this.playerEntity.capabilities.isFlying = p_147348_1_.func_149488_d() && this.playerEntity.capabilities.allowFlying; + } + + public void processTabComplete(C14PacketTabComplete p_147341_1_) + { + ArrayList arraylist = Lists.newArrayList(); + Iterator iterator = this.serverController.getPossibleCompletions(this.playerEntity, p_147341_1_.func_149419_c()).iterator(); + + while (iterator.hasNext()) + { + String s = (String)iterator.next(); + arraylist.add(s); + } + + this.playerEntity.playerNetServerHandler.sendPacket(new S3APacketTabComplete((String[])arraylist.toArray(new String[arraylist.size()]))); + } + + public void processClientSettings(C15PacketClientSettings p_147352_1_) + { + this.playerEntity.func_147100_a(p_147352_1_); + } + + public void processVanilla250Packet(C17PacketCustomPayload p_147349_1_) + { + ItemStack itemstack; + ItemStack itemstack1; + + if ("MC|BEdit".equals(p_147349_1_.func_149559_c())) + { + try + { + itemstack = (new PacketBuffer(Unpooled.wrappedBuffer(p_147349_1_.func_149558_e()))).readItemStackFromBuffer(); + + if (!ItemWritableBook.func_150930_a(itemstack.getTagCompound())) + { + throw new IOException("Invalid book tag!"); + } + + itemstack1 = this.playerEntity.inventory.getCurrentItem(); + + if (itemstack.getItem() == Items.writable_book && itemstack.getItem() == itemstack1.getItem()) + { + itemstack1.setTagInfo("pages", itemstack.getTagCompound().getTagList("pages", 8)); + } + } + catch (Exception exception4) + { + logger.error("Couldn\'t handle book info", exception4); + } + } + else if ("MC|BSign".equals(p_147349_1_.func_149559_c())) + { + try + { + itemstack = (new PacketBuffer(Unpooled.wrappedBuffer(p_147349_1_.func_149558_e()))).readItemStackFromBuffer(); + + if (!ItemEditableBook.validBookTagContents(itemstack.getTagCompound())) + { + throw new IOException("Invalid book tag!"); + } + + itemstack1 = this.playerEntity.inventory.getCurrentItem(); + + if (itemstack.getItem() == Items.written_book && itemstack1.getItem() == Items.writable_book) + { + itemstack1.setTagInfo("author", new NBTTagString(this.playerEntity.getCommandSenderName())); + itemstack1.setTagInfo("title", new NBTTagString(itemstack.getTagCompound().getString("title"))); + itemstack1.setTagInfo("pages", itemstack.getTagCompound().getTagList("pages", 8)); + itemstack1.func_150996_a(Items.written_book); + } + } + catch (Exception exception3) + { + logger.error("Couldn\'t sign book", exception3); + } + } + else + { + DataInputStream datainputstream; + int i; + + if ("MC|TrSel".equals(p_147349_1_.func_149559_c())) + { + try + { + datainputstream = new DataInputStream(new ByteArrayInputStream(p_147349_1_.func_149558_e())); + i = datainputstream.readInt(); + Container container = this.playerEntity.openContainer; + + if (container instanceof ContainerMerchant) + { + ((ContainerMerchant)container).setCurrentRecipeIndex(i); + } + } + catch (Exception exception2) + { + logger.error("Couldn\'t select trade", exception2); + } + } + else if ("MC|AdvCdm".equals(p_147349_1_.func_149559_c())) + { + if (!this.serverController.isCommandBlockEnabled()) + { + this.playerEntity.addChatMessage(new ChatComponentTranslation("advMode.notEnabled", new Object[0])); + } + else if (this.playerEntity.canCommandSenderUseCommand(2, "") && this.playerEntity.capabilities.isCreativeMode) + { + try + { + PacketBuffer packetbuffer = new PacketBuffer(Unpooled.wrappedBuffer(p_147349_1_.func_149558_e())); + byte b0 = packetbuffer.readByte(); + CommandBlockLogic commandblocklogic = null; + + if (b0 == 0) + { + TileEntity tileentity = this.playerEntity.worldObj.getTileEntity(packetbuffer.readInt(), packetbuffer.readInt(), packetbuffer.readInt()); + + if (tileentity instanceof TileEntityCommandBlock) + { + commandblocklogic = ((TileEntityCommandBlock)tileentity).func_145993_a(); + } + } + else if (b0 == 1) + { + Entity entity = this.playerEntity.worldObj.getEntityByID(packetbuffer.readInt()); + + if (entity instanceof EntityMinecartCommandBlock) + { + commandblocklogic = ((EntityMinecartCommandBlock)entity).func_145822_e(); + } + } + + String s1 = packetbuffer.readStringFromBuffer(packetbuffer.readableBytes()); + + if (commandblocklogic != null) + { + commandblocklogic.func_145752_a(s1); + commandblocklogic.func_145756_e(); + this.playerEntity.addChatMessage(new ChatComponentTranslation("advMode.setCommand.success", new Object[] {s1})); + } + } + catch (Exception exception1) + { + logger.error("Couldn\'t set command block", exception1); + } + } + else + { + this.playerEntity.addChatMessage(new ChatComponentTranslation("advMode.notAllowed", new Object[0])); + } + } + else if ("MC|Beacon".equals(p_147349_1_.func_149559_c())) + { + if (this.playerEntity.openContainer instanceof ContainerBeacon) + { + try + { + datainputstream = new DataInputStream(new ByteArrayInputStream(p_147349_1_.func_149558_e())); + i = datainputstream.readInt(); + int j = datainputstream.readInt(); + ContainerBeacon containerbeacon = (ContainerBeacon)this.playerEntity.openContainer; + Slot slot = containerbeacon.getSlot(0); + + if (slot.getHasStack()) + { + slot.decrStackSize(1); + TileEntityBeacon tileentitybeacon = containerbeacon.func_148327_e(); + tileentitybeacon.setPrimaryEffect(i); + tileentitybeacon.setSecondaryEffect(j); + tileentitybeacon.markDirty(); + } + } + catch (Exception exception) + { + logger.error("Couldn\'t set beacon", exception); + } + } + } + else if ("MC|ItemName".equals(p_147349_1_.func_149559_c()) && this.playerEntity.openContainer instanceof ContainerRepair) + { + ContainerRepair containerrepair = (ContainerRepair)this.playerEntity.openContainer; + + if (p_147349_1_.func_149558_e() != null && p_147349_1_.func_149558_e().length >= 1) + { + String s = ChatAllowedCharacters.filerAllowedCharacters(new String(p_147349_1_.func_149558_e(), Charsets.UTF_8)); + + if (s.length() <= 30) + { + containerrepair.updateItemName(s); + } + } + else + { + containerrepair.updateItemName(""); + } + } + } + } + + public void onConnectionStateTransition(EnumConnectionState p_147232_1_, EnumConnectionState p_147232_2_) + { + if (p_147232_2_ != EnumConnectionState.PLAY) + { + throw new IllegalStateException("Unexpected change in protocol!"); + } + } + + static final class SwitchEnumState + { + static final int[] field_151290_a = new int[C16PacketClientStatus.EnumState.values().length]; + private static final String __OBFID = "CL_00001455"; + + static + { + try + { + field_151290_a[C16PacketClientStatus.EnumState.PERFORM_RESPAWN.ordinal()] = 1; + } + catch (NoSuchFieldError var3) + { + ; + } + + try + { + field_151290_a[C16PacketClientStatus.EnumState.REQUEST_STATS.ordinal()] = 2; + } + catch (NoSuchFieldError var2) + { + ; + } + + try + { + field_151290_a[C16PacketClientStatus.EnumState.OPEN_INVENTORY_ACHIEVEMENT.ordinal()] = 3; + } + catch (NoSuchFieldError var1) + { + ; + } + } + } } \ No newline at end of file diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index 6db220f..7f98691 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -80,6 +80,7 @@ import org.apache.logging.log4j.Logger; import org.ultramine.permission.IPermissionManager; import org.ultramine.server.ConfigurationHandler; +import org.ultramine.server.MultiWorld; import org.ultramine.server.WatchdogThread; import org.ultramine.server.chunk.ChunkIOExecutor; @@ -1438,6 +1439,13 @@ /* ========================================= ULTRAMINE START ======================================*/ + private final MultiWorld multiworld = new MultiWorld(this); + + public MultiWorld getMultiWorld() + { + return multiworld; + } + public IPermissionManager getPermissionManager() { return permissionManager; diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedPlayerList.java b/src/main/java/net/minecraft/server/dedicated/DedicatedPlayerList.java index 9a8016e..800f698 100644 --- a/src/main/java/net/minecraft/server/dedicated/DedicatedPlayerList.java +++ b/src/main/java/net/minecraft/server/dedicated/DedicatedPlayerList.java @@ -1,186 +1,186 @@ -package net.minecraft.server.dedicated; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.PrintWriter; -import java.util.Iterator; - -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.management.ServerConfigurationManager; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.ultramine.server.ConfigurationHandler; -import org.ultramine.server.PermissionHandler; - -@SideOnly(Side.SERVER) -public class DedicatedPlayerList extends ServerConfigurationManager -{ - private static final Logger field_164439_d = LogManager.getLogger(); - private File opsList; - private File whiteList; - private static final String __OBFID = "CL_00001783"; - - public DedicatedPlayerList(DedicatedServer par1DedicatedServer) - { - super(par1DedicatedServer); - this.opsList = par1DedicatedServer.getFile("ops.txt"); - this.whiteList = par1DedicatedServer.getFile("white-list.txt"); - this.viewDistance = ConfigurationHandler.getServerConfig().vanilla.viewDistance; - this.maxPlayers = ConfigurationHandler.getServerConfig().vanilla.maxPlayers; - this.setWhiteListEnabled(ConfigurationHandler.getServerConfig().vanilla.whiteList); - - if (!par1DedicatedServer.isSinglePlayer()) - { - this.getBannedPlayers().setListActive(true); - this.getBannedIPs().setListActive(true); - } - - this.getBannedPlayers().loadBanList(); - this.getBannedPlayers().saveToFileWithHeader(); - this.getBannedIPs().loadBanList(); - this.getBannedIPs().saveToFileWithHeader(); - this.readWhiteList(); - - if (!this.whiteList.exists()) - { - this.saveWhiteList(); - } - } - - public void setWhiteListEnabled(boolean par1) - { - super.setWhiteListEnabled(par1); - ConfigurationHandler.getServerConfig().vanilla.whiteList = par1; - this.getServerInstance().saveProperties(); - } - - public void addOp(String par1Str) - { - super.addOp(par1Str); - PermissionHandler.getInstance().save(); - } - - public void removeOp(String par1Str) - { - super.removeOp(par1Str); - PermissionHandler.getInstance().save(); - } - - public void removeFromWhitelist(String par1Str) - { - super.removeFromWhitelist(par1Str); - this.saveWhiteList(); - } - - public void addToWhiteList(String par1Str) - { - super.addToWhiteList(par1Str); - this.saveWhiteList(); - } - - public void loadWhiteList() - { - this.readWhiteList(); - } - - private void loadOpsList() - { - try - { - this.getOps().clear(); - BufferedReader bufferedreader = new BufferedReader(new FileReader(this.opsList)); - String s = ""; - - while ((s = bufferedreader.readLine()) != null) - { - this.getOps().add(s.trim().toLowerCase()); - } - - bufferedreader.close(); - } - catch (Exception exception) - { - field_164439_d.warn("Failed to load operators list: " + exception); - } - } - - private void saveOpsList() - { - try - { - PrintWriter printwriter = new PrintWriter(new FileWriter(this.opsList, false)); - Iterator iterator = this.getOps().iterator(); - - while (iterator.hasNext()) - { - String s = (String)iterator.next(); - printwriter.println(s); - } - - printwriter.close(); - } - catch (Exception exception) - { - field_164439_d.warn("Failed to save operators list: " + exception); - } - } - - private void readWhiteList() - { - try - { - this.getWhiteListedPlayers().clear(); - BufferedReader bufferedreader = new BufferedReader(new FileReader(this.whiteList)); - String s = ""; - - while ((s = bufferedreader.readLine()) != null) - { - this.getWhiteListedPlayers().add(s.trim().toLowerCase()); - } - - bufferedreader.close(); - } - catch (Exception exception) - { - field_164439_d.warn("Failed to load white-list: " + exception); - } - } - - private void saveWhiteList() - { - try - { - PrintWriter printwriter = new PrintWriter(new FileWriter(this.whiteList, false)); - Iterator iterator = this.getWhiteListedPlayers().iterator(); - - while (iterator.hasNext()) - { - String s = (String)iterator.next(); - printwriter.println(s); - } - - printwriter.close(); - } - catch (Exception exception) - { - field_164439_d.warn("Failed to save white-list: " + exception); - } - } - - public boolean isAllowedToLogin(String par1Str) - { - par1Str = par1Str.trim().toLowerCase(); - return !this.isWhiteListEnabled() || this.isPlayerOpped(par1Str) || this.getWhiteListedPlayers().contains(par1Str); - } - - public DedicatedServer getServerInstance() - { - return (DedicatedServer)super.getServerInstance(); - } +package net.minecraft.server.dedicated; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Iterator; + +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.management.ServerConfigurationManager; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.ultramine.server.ConfigurationHandler; +import org.ultramine.server.PermissionHandler; + +@SideOnly(Side.SERVER) +public class DedicatedPlayerList extends ServerConfigurationManager +{ + private static final Logger field_164439_d = LogManager.getLogger(); + private File opsList; + private File whiteList; + private static final String __OBFID = "CL_00001783"; + + public DedicatedPlayerList(DedicatedServer par1DedicatedServer) + { + super(par1DedicatedServer); + this.opsList = par1DedicatedServer.getFile("ops.txt"); + this.whiteList = par1DedicatedServer.getFile("white-list.txt"); + this.viewDistance = ConfigurationHandler.getWorldsConfig().global.chunkLoading.viewDistance; + this.maxPlayers = ConfigurationHandler.getServerConfig().vanilla.maxPlayers; + this.setWhiteListEnabled(ConfigurationHandler.getServerConfig().vanilla.whiteList); + + if (!par1DedicatedServer.isSinglePlayer()) + { + this.getBannedPlayers().setListActive(true); + this.getBannedIPs().setListActive(true); + } + + this.getBannedPlayers().loadBanList(); + this.getBannedPlayers().saveToFileWithHeader(); + this.getBannedIPs().loadBanList(); + this.getBannedIPs().saveToFileWithHeader(); + this.readWhiteList(); + + if (!this.whiteList.exists()) + { + this.saveWhiteList(); + } + } + + public void setWhiteListEnabled(boolean par1) + { + super.setWhiteListEnabled(par1); + ConfigurationHandler.getServerConfig().vanilla.whiteList = par1; + this.getServerInstance().saveProperties(); + } + + public void addOp(String par1Str) + { + super.addOp(par1Str); + PermissionHandler.getInstance().save(); + } + + public void removeOp(String par1Str) + { + super.removeOp(par1Str); + PermissionHandler.getInstance().save(); + } + + public void removeFromWhitelist(String par1Str) + { + super.removeFromWhitelist(par1Str); + this.saveWhiteList(); + } + + public void addToWhiteList(String par1Str) + { + super.addToWhiteList(par1Str); + this.saveWhiteList(); + } + + public void loadWhiteList() + { + this.readWhiteList(); + } + + private void loadOpsList() + { + try + { + this.getOps().clear(); + BufferedReader bufferedreader = new BufferedReader(new FileReader(this.opsList)); + String s = ""; + + while ((s = bufferedreader.readLine()) != null) + { + this.getOps().add(s.trim().toLowerCase()); + } + + bufferedreader.close(); + } + catch (Exception exception) + { + field_164439_d.warn("Failed to load operators list: " + exception); + } + } + + private void saveOpsList() + { + try + { + PrintWriter printwriter = new PrintWriter(new FileWriter(this.opsList, false)); + Iterator iterator = this.getOps().iterator(); + + while (iterator.hasNext()) + { + String s = (String)iterator.next(); + printwriter.println(s); + } + + printwriter.close(); + } + catch (Exception exception) + { + field_164439_d.warn("Failed to save operators list: " + exception); + } + } + + private void readWhiteList() + { + try + { + this.getWhiteListedPlayers().clear(); + BufferedReader bufferedreader = new BufferedReader(new FileReader(this.whiteList)); + String s = ""; + + while ((s = bufferedreader.readLine()) != null) + { + this.getWhiteListedPlayers().add(s.trim().toLowerCase()); + } + + bufferedreader.close(); + } + catch (Exception exception) + { + field_164439_d.warn("Failed to load white-list: " + exception); + } + } + + private void saveWhiteList() + { + try + { + PrintWriter printwriter = new PrintWriter(new FileWriter(this.whiteList, false)); + Iterator iterator = this.getWhiteListedPlayers().iterator(); + + while (iterator.hasNext()) + { + String s = (String)iterator.next(); + printwriter.println(s); + } + + printwriter.close(); + } + catch (Exception exception) + { + field_164439_d.warn("Failed to save white-list: " + exception); + } + } + + public boolean isAllowedToLogin(String par1Str) + { + par1Str = par1Str.trim().toLowerCase(); + return !this.isWhiteListEnabled() || this.isPlayerOpped(par1Str) || this.getWhiteListedPlayers().contains(par1Str); + } + + public DedicatedServer getServerInstance() + { + return (DedicatedServer)super.getServerInstance(); + } } \ No newline at end of file diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java index 433728e..63c07a4 100644 --- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java +++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java @@ -1,489 +1,497 @@ -package net.minecraft.server.dedicated; - -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.InetAddress; -import java.net.Proxy; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Random; -import java.util.concurrent.Callable; - -import net.minecraft.command.ICommandSender; -import net.minecraft.command.ServerCommand; -import net.minecraft.crash.CrashReport; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.network.rcon.IServer; -import net.minecraft.network.rcon.RConThreadMain; -import net.minecraft.network.rcon.RConThreadQuery; -import net.minecraft.profiler.PlayerUsageSnooper; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.gui.MinecraftServerGui; -import net.minecraft.server.management.ServerConfigurationManager; -import net.minecraft.util.ChunkCoordinates; -import net.minecraft.util.CryptManager; -import net.minecraft.util.MathHelper; -import net.minecraft.world.EnumDifficulty; -import net.minecraft.world.World; -import net.minecraft.world.WorldSettings; -import net.minecraft.world.WorldType; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.ultramine.permission.PermissionRepository; -import org.ultramine.permission.internal.ServerPermissionManager; -import org.ultramine.server.ConfigurationHandler; -import org.ultramine.server.UltramineServerConfig; -import org.ultramine.server.UltramineServerConfig.VanillaConfig; - -@SideOnly(Side.SERVER) -public class DedicatedServer extends MinecraftServer implements IServer -{ - private static final Logger field_155771_h = LogManager.getLogger(); - public final List pendingCommandList = Collections.synchronizedList(new ArrayList()); - private RConThreadQuery theRConThreadQuery; - private RConThreadMain theRConThreadMain; - private VanillaConfig settings; - private boolean canSpawnStructures; - private WorldSettings.GameType gameType; - private boolean guiIsEnabled; - public static boolean allowPlayerLogins = false; - private static final String __OBFID = "CL_00001784"; - - public DedicatedServer(File par1File) - { - super(par1File, Proxy.NO_PROXY); - Thread thread = new Thread("Server Infinisleeper") - { - private static final String __OBFID = "CL_00001787"; - { - this.setDaemon(true); - this.start(); - } - public void run() - { - while (true) - { - try - { - while (true) - { - Thread.sleep(2147483647L); - } - } - catch (InterruptedException interruptedexception) - { - ; - } - } - } - }; - } - - protected boolean startServer() throws IOException - { - Thread thread = new Thread("Server console handler") - { - private static final String __OBFID = "CL_00001786"; - public void run() - { - BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in)); - String s4; - - try - { - while (!DedicatedServer.this.isServerStopped() && DedicatedServer.this.isServerRunning() && (s4 = bufferedreader.readLine()) != null) - { - DedicatedServer.this.addPendingCommand(s4, DedicatedServer.this); - } - } - catch (IOException ioexception1) - { - DedicatedServer.field_155771_h.error("Exception handling console input", ioexception1); - } - } - }; - thread.setDaemon(true); - thread.start(); - field_155771_h.info("Starting minecraft server version 1.7.2"); - - if (Runtime.getRuntime().maxMemory() / 1024L / 1024L < 512L) - { - field_155771_h.warn("To start the server with more ram, launch it as \"java -Xmx1024M -Xms1024M -jar minecraft_server.jar\""); - } - - FMLCommonHandler.instance().onServerStart(this); - - field_155771_h.info("Loading properties"); - settings = ConfigurationHandler.getServerConfig().vanilla; - - if (this.isSinglePlayer()) - { - this.setHostname("127.0.0.1"); - } - else - { - this.setOnlineMode(settings.onlineMode); - this.setHostname(settings.serverIp); - } - - this.setCanSpawnAnimals(settings.spawnAnimals); - this.setCanSpawnNPCs(settings.spawnNPCs); - this.setAllowPvp(settings.pvp); - this.setAllowFlight(settings.allowFlight); - this.func_155759_m(settings.resourcePack); - this.setMOTD(settings.motd); - this.setForceGamemode(settings.forceGamemode); - this.func_143006_e(settings.playerIdleTimeout); - - if (settings.difficulty < 0) - { - settings.difficulty = 0; - } - else if (settings.difficulty > 3) - { - settings.difficulty = 3; - } - - this.canSpawnStructures = settings.generateStructures; - int i = settings.gamemode; - this.gameType = WorldSettings.getGameTypeById(i); - field_155771_h.info("Default game type: " + this.gameType); - InetAddress inetaddress = null; - - if (this.getServerHostname().length() > 0) - { - inetaddress = InetAddress.getByName(this.getServerHostname()); - } - - if (this.getServerPort() < 0) - { - this.setServerPort(settings.serverPort); - } - - field_155771_h.info("Generating keypair"); - this.setKeyPair(CryptManager.createNewKeyPair()); - field_155771_h.info("Starting Minecraft server on " + (this.getServerHostname().length() == 0 ? "*" : this.getServerHostname()) + ":" + this.getServerPort()); - - try - { - this.func_147137_ag().addLanEndpoint(inetaddress, this.getServerPort()); - } - catch (IOException ioexception) - { - field_155771_h.warn("**** FAILED TO BIND TO PORT!"); - field_155771_h.warn("The exception was: {}", new Object[] {ioexception.toString()}); - field_155771_h.warn("Perhaps a server is already running on that port?"); - return false; - } - - if (!this.isServerInOnlineMode()) - { - field_155771_h.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!"); - field_155771_h.warn("The server will make no attempt to authenticate usernames. Beware."); - field_155771_h.warn("While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose."); - field_155771_h.warn("To change this, set \"online-mode\" to \"true\" in the server.properties file."); - } - - FMLCommonHandler.instance().onServerStarted(); - - this.setConfigurationManager(new DedicatedPlayerList(this)); - long j = System.nanoTime(); - - if (this.getFolderName() == null) - { - this.setFolderName(settings.levelName); - } - - String s = settings.levelSeed; - String s1 = settings.levelType; - String s2 = settings.generatorSettings; - long k = (new Random()).nextLong(); - - if (s.length() > 0) - { - try - { - long l = Long.parseLong(s); - - if (l != 0L) - { - k = l; - } - } - catch (NumberFormatException numberformatexception) - { - k = (long)s.hashCode(); - } - } - - WorldType worldtype = WorldType.parseWorldType(s1); - - if (worldtype == null) - { - worldtype = WorldType.DEFAULT; - } - - this.func_147136_ar(); - this.isCommandBlockEnabled(); - this.getOpPermissionLevel(); - this.isSnooperEnabled(); - this.setBuildLimit(settings.maxBuildHeight); - this.setBuildLimit((this.getBuildLimit() + 8) / 16 * 16); - this.setBuildLimit(MathHelper.clamp_int(this.getBuildLimit(), 64, 256)); - settings.maxBuildHeight = this.getBuildLimit(); - this.setPermissionManager(new ServerPermissionManager(ConfigurationHandler.getSettingDir(), new PermissionRepository())); // ultramine - if (!FMLCommonHandler.instance().handleServerAboutToStart(this)) { return false; } - field_155771_h.info("Preparing level \"" + this.getFolderName() + "\""); - this.loadAllWorlds(this.getFolderName(), this.getFolderName(), k, worldtype, s2); - long i1 = System.nanoTime() - j; - String s3 = String.format("%.3fs", new Object[] {Double.valueOf((double)i1 / 1.0E9D)}); - field_155771_h.info("Done (" + s3 + ")! For help, type \"help\" or \"?\""); - - if (settings.enableQuery) - { - field_155771_h.info("Starting GS4 status listener"); - this.theRConThreadQuery = new RConThreadQuery(this); - this.theRConThreadQuery.startThread(); - } - - if (settings.enableRcon) - { - field_155771_h.info("Starting remote control listener"); - this.theRConThreadMain = new RConThreadMain(this); - this.theRConThreadMain.startThread(); - } - - allowPlayerLogins = true; - return FMLCommonHandler.instance().handleServerStarting(this); - } - - public boolean canStructuresSpawn() - { - return this.canSpawnStructures; - } - - public WorldSettings.GameType getGameType() - { - return this.gameType; - } - - public EnumDifficulty func_147135_j() - { - return EnumDifficulty.getDifficultyEnum(settings.difficulty); - } - - public boolean isHardcore() - { - return settings.hardcore; - } - - protected void finalTick(CrashReport par1CrashReport) - { - while (this.isServerRunning()) - { - this.executePendingCommands(); - - try - { - Thread.sleep(10L); - } - catch (InterruptedException interruptedexception) - { - ; - } - } - } - - public CrashReport addServerInfoToCrashReport(CrashReport par1CrashReport) - { - par1CrashReport = super.addServerInfoToCrashReport(par1CrashReport); - par1CrashReport.getCategory().addCrashSectionCallable("Is Modded", new Callable() - { - private static final String __OBFID = "CL_00001785"; - public String call() - { - String s = DedicatedServer.this.getServerModName(); - return !s.equals("vanilla") ? "Definitely; Server brand changed to \'" + s + "\'" : "Unknown (can\'t tell)"; - } - }); - par1CrashReport.getCategory().addCrashSectionCallable("Type", new Callable() - { - private static final String __OBFID = "CL_00001788"; - public String call() - { - return "Dedicated Server (map_server.txt)"; - } - }); - return par1CrashReport; - } - - protected void systemExitNow() - { - System.exit(0); - } - - public void updateTimeLightAndEntities() - { - super.updateTimeLightAndEntities(); - this.executePendingCommands(); - } - - public boolean getAllowNether() - { - return settings.allowNether; - } - - public boolean allowSpawnMonsters() - { - return settings.spawnMonsters; - } - - public void addServerStatsToSnooper(PlayerUsageSnooper par1PlayerUsageSnooper) - { - par1PlayerUsageSnooper.addData("whitelist_enabled", Boolean.valueOf(this.getConfigurationManager().isWhiteListEnabled())); - par1PlayerUsageSnooper.addData("whitelist_count", Integer.valueOf(this.getConfigurationManager().getWhiteListedPlayers().size())); - super.addServerStatsToSnooper(par1PlayerUsageSnooper); - } - - public boolean isSnooperEnabled() - { - return settings.snooperEnabled; - } - - public void addPendingCommand(String par1Str, ICommandSender par2ICommandSender) - { - this.pendingCommandList.add(new ServerCommand(par1Str, par2ICommandSender)); - } - - public void executePendingCommands() - { - while (!this.pendingCommandList.isEmpty()) - { - ServerCommand servercommand = (ServerCommand)this.pendingCommandList.remove(0); - this.getCommandManager().executeCommand(servercommand.sender, servercommand.command); - } - } - - public boolean isDedicatedServer() - { - return true; - } - - public DedicatedPlayerList getConfigurationManager() - { - return (DedicatedPlayerList)super.getConfigurationManager(); - } - - public int getIntProperty(String par1Str, int par2) - { - logInfo("Attempted to get server config unresolved integer parameter " + par1Str); - return settings.unresolved.containsKey(par1Str) ? (Integer)settings.unresolved.get(par1Str) : par2; - } - - public String getStringProperty(String par1Str, String par2Str) - { - logInfo("Attempted to get server config unresolved string parameter " + par1Str); - return settings.unresolved.containsKey(par1Str) ? (String)settings.unresolved.get(par1Str) : par2Str; - } - - public boolean getBooleanProperty(String par1Str, boolean par2) - { - logInfo("Attempted to get server config unresolved boolean parameter " + par1Str); - return settings.unresolved.containsKey(par1Str) ? (Boolean)settings.unresolved.get(par1Str) : par2; - } - - public void setProperty(String par1Str, Object par2Obj) - { - logInfo("Attempted to set server config unresolved parameter " + par1Str); - settings.unresolved.put(par1Str, par2Obj); - } - - public void saveProperties() - { - ConfigurationHandler.saveServerConfig(); - } - - public String getSettingsFilename() - { - return "server.yml"; - } - - public void setGuiEnabled() - { - MinecraftServerGui.createServerGui(this); - this.guiIsEnabled = true; - } - - public boolean getGuiEnabled() - { - return this.guiIsEnabled; - } - - public String shareToLAN(WorldSettings.GameType par1EnumGameType, boolean par2) - { - return ""; - } - - public boolean isCommandBlockEnabled() - { - return settings.enableCommandBlock; - } - - public int getSpawnProtectionSize() - { - return getIntProperty("spawn-protection", super.getSpawnProtectionSize()); - } - - public boolean isBlockProtected(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer) - { - if (par1World.provider.dimensionId != 0) - { - return false; - } - else if (this.getConfigurationManager().getOps().isEmpty()) - { - return false; - } - else if (this.getConfigurationManager().isPlayerOpped(par5EntityPlayer.getCommandSenderName())) - { - return false; - } - else if (this.getSpawnProtectionSize() <= 0) - { - return false; - } - else - { - ChunkCoordinates chunkcoordinates = par1World.getSpawnPoint(); - int l = MathHelper.abs_int(par2 - chunkcoordinates.posX); - int i1 = MathHelper.abs_int(par4 - chunkcoordinates.posZ); - int j1 = Math.max(l, i1); - return j1 <= this.getSpawnProtectionSize(); - } - } - - public int getOpPermissionLevel() - { - return settings.opPermissionLevel; - } - - public void func_143006_e(int par1) - { - super.func_143006_e(par1); - settings.playerIdleTimeout = par1; - this.saveProperties(); - } - - public boolean func_147136_ar() - { - return settings.announcePlayerAchievements; - } +package net.minecraft.server.dedicated; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.InetAddress; +import java.net.Proxy; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Random; +import java.util.concurrent.Callable; + +import net.minecraft.command.ICommandSender; +import net.minecraft.command.ServerCommand; +import net.minecraft.crash.CrashReport; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.rcon.IServer; +import net.minecraft.network.rcon.RConThreadMain; +import net.minecraft.network.rcon.RConThreadQuery; +import net.minecraft.profiler.PlayerUsageSnooper; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.gui.MinecraftServerGui; +import net.minecraft.server.management.ServerConfigurationManager; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.CryptManager; +import net.minecraft.util.MathHelper; +import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import net.minecraft.world.WorldSettings; +import net.minecraft.world.WorldType; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.ultramine.permission.PermissionRepository; +import org.ultramine.permission.internal.ServerPermissionManager; +import org.ultramine.server.ConfigurationHandler; +import org.ultramine.server.MultiWorld; +import org.ultramine.server.UltramineServerConfig; +import org.ultramine.server.UltramineServerConfig.VanillaConfig; +import org.ultramine.server.WorldsConfig.WorldConfig; + +@SideOnly(Side.SERVER) +public class DedicatedServer extends MinecraftServer implements IServer +{ + private static final Logger field_155771_h = LogManager.getLogger(); + public final List pendingCommandList = Collections.synchronizedList(new ArrayList()); + private RConThreadQuery theRConThreadQuery; + private RConThreadMain theRConThreadMain; + private VanillaConfig settings; + private boolean canSpawnStructures; + private WorldSettings.GameType gameType; + private boolean guiIsEnabled; + public static boolean allowPlayerLogins = false; + private static final String __OBFID = "CL_00001784"; + + public DedicatedServer(File par1File) + { + super(par1File, Proxy.NO_PROXY); + Thread thread = new Thread("Server Infinisleeper") + { + private static final String __OBFID = "CL_00001787"; + { + this.setDaemon(true); + this.start(); + } + public void run() + { + while (true) + { + try + { + while (true) + { + Thread.sleep(2147483647L); + } + } + catch (InterruptedException interruptedexception) + { + ; + } + } + } + }; + } + + protected boolean startServer() throws IOException + { + Thread thread = new Thread("Server console handler") + { + private static final String __OBFID = "CL_00001786"; + public void run() + { + BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in)); + String s4; + + try + { + while (!DedicatedServer.this.isServerStopped() && DedicatedServer.this.isServerRunning() && (s4 = bufferedreader.readLine()) != null) + { + DedicatedServer.this.addPendingCommand(s4, DedicatedServer.this); + } + } + catch (IOException ioexception1) + { + DedicatedServer.field_155771_h.error("Exception handling console input", ioexception1); + } + } + }; + thread.setDaemon(true); + thread.start(); + field_155771_h.info("Starting minecraft server version 1.7.2"); + + if (Runtime.getRuntime().maxMemory() / 1024L / 1024L < 512L) + { + field_155771_h.warn("To start the server with more ram, launch it as \"java -Xmx1024M -Xms1024M -jar minecraft_server.jar\""); + } + + FMLCommonHandler.instance().onServerStart(this); + + field_155771_h.info("Loading properties"); + settings = ConfigurationHandler.getServerConfig().vanilla; + WorldConfig globalWConf = ConfigurationHandler.getWorldsConfig().global; + + if (this.isSinglePlayer()) + { + this.setHostname("127.0.0.1"); + } + else + { + this.setOnlineMode(settings.onlineMode); + this.setHostname(settings.serverIp); + } + + this.setCanSpawnAnimals(globalWConf.mobSpawn.spawnAnimals); + this.setCanSpawnNPCs(globalWConf.mobSpawn.spawnNPCs); + this.setAllowPvp(globalWConf.settings.pvp); + this.setAllowFlight(settings.allowFlight); + this.func_155759_m(settings.resourcePack); + this.setMOTD(settings.motd); + this.setForceGamemode(settings.forceGamemode); + this.func_143006_e(settings.playerIdleTimeout); + + this.canSpawnStructures = globalWConf.generation.generateStructures; + int i = settings.gamemode; + this.gameType = WorldSettings.getGameTypeById(i); + field_155771_h.info("Default game type: " + this.gameType); + InetAddress inetaddress = null; + + if (this.getServerHostname().length() > 0) + { + inetaddress = InetAddress.getByName(this.getServerHostname()); + } + + if (this.getServerPort() < 0) + { + this.setServerPort(settings.serverPort); + } + + field_155771_h.info("Generating keypair"); + this.setKeyPair(CryptManager.createNewKeyPair()); + field_155771_h.info("Starting Minecraft server on " + (this.getServerHostname().length() == 0 ? "*" : this.getServerHostname()) + ":" + this.getServerPort()); + + try + { + this.func_147137_ag().addLanEndpoint(inetaddress, this.getServerPort()); + } + catch (IOException ioexception) + { + field_155771_h.warn("**** FAILED TO BIND TO PORT!"); + field_155771_h.warn("The exception was: {}", new Object[] {ioexception.toString()}); + field_155771_h.warn("Perhaps a server is already running on that port?"); + return false; + } + + if (!this.isServerInOnlineMode()) + { + field_155771_h.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!"); + field_155771_h.warn("The server will make no attempt to authenticate usernames. Beware."); + field_155771_h.warn("While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose."); + field_155771_h.warn("To change this, set \"online-mode\" to \"true\" in the server.properties file."); + } + + FMLCommonHandler.instance().onServerStarted(); + + this.setConfigurationManager(new DedicatedPlayerList(this)); + long j = System.nanoTime(); + + if (this.getFolderName() == null) + { + this.setFolderName("world"); + } + + String s = globalWConf.generation.seed; + String s1 = globalWConf.generation.levelType; + String s2 = globalWConf.generation.generatorSettings; + long k = (new Random()).nextLong(); + + if (s.length() > 0) + { + try + { + long l = Long.parseLong(s); + + if (l != 0L) + { + k = l; + } + } + catch (NumberFormatException numberformatexception) + { + k = (long)s.hashCode(); + } + } + + WorldType worldtype = WorldType.parseWorldType(s1); + + if (worldtype == null) + { + worldtype = WorldType.DEFAULT; + } + + this.func_147136_ar(); + this.isCommandBlockEnabled(); + this.getOpPermissionLevel(); + this.isSnooperEnabled(); + this.setBuildLimit(globalWConf.settings.maxBuildHeight); + this.setBuildLimit((this.getBuildLimit() + 8) / 16 * 16); + this.setBuildLimit(MathHelper.clamp_int(this.getBuildLimit(), 64, 256)); + globalWConf.settings.maxBuildHeight = this.getBuildLimit(); + this.setPermissionManager(new ServerPermissionManager(ConfigurationHandler.getSettingDir(), new PermissionRepository())); // ultramine + if (!FMLCommonHandler.instance().handleServerAboutToStart(this)) { return false; } + field_155771_h.info("Preparing level \"" + this.getFolderName() + "\""); + this.loadAllWorlds(this.getFolderName(), this.getFolderName(), k, worldtype, s2); + long i1 = System.nanoTime() - j; + String s3 = String.format("%.3fs", new Object[] {Double.valueOf((double)i1 / 1.0E9D)}); + field_155771_h.info("Done (" + s3 + ")! For help, type \"help\" or \"?\""); + + if (settings.enableQuery) + { + field_155771_h.info("Starting GS4 status listener"); + this.theRConThreadQuery = new RConThreadQuery(this); + this.theRConThreadQuery.startThread(); + } + + if (settings.enableRcon) + { + field_155771_h.info("Starting remote control listener"); + this.theRConThreadMain = new RConThreadMain(this); + this.theRConThreadMain.startThread(); + } + + allowPlayerLogins = true; + return FMLCommonHandler.instance().handleServerStarting(this); + } + + public boolean canStructuresSpawn() + { + return this.canSpawnStructures; + } + + public WorldSettings.GameType getGameType() + { + return this.gameType; + } + + public EnumDifficulty func_147135_j() + { + return EnumDifficulty.getDifficultyEnum(ConfigurationHandler.getWorldsConfig().global.settings.difficulty); + } + + public boolean isHardcore() + { + return settings.hardcore; + } + + protected void finalTick(CrashReport par1CrashReport) + { + while (this.isServerRunning()) + { + this.executePendingCommands(); + + try + { + Thread.sleep(10L); + } + catch (InterruptedException interruptedexception) + { + ; + } + } + } + + public CrashReport addServerInfoToCrashReport(CrashReport par1CrashReport) + { + par1CrashReport = super.addServerInfoToCrashReport(par1CrashReport); + par1CrashReport.getCategory().addCrashSectionCallable("Is Modded", new Callable() + { + private static final String __OBFID = "CL_00001785"; + public String call() + { + String s = DedicatedServer.this.getServerModName(); + return !s.equals("vanilla") ? "Definitely; Server brand changed to \'" + s + "\'" : "Unknown (can\'t tell)"; + } + }); + par1CrashReport.getCategory().addCrashSectionCallable("Type", new Callable() + { + private static final String __OBFID = "CL_00001788"; + public String call() + { + return "Dedicated Server (map_server.txt)"; + } + }); + return par1CrashReport; + } + + protected void systemExitNow() + { + System.exit(0); + } + + public void updateTimeLightAndEntities() + { + super.updateTimeLightAndEntities(); + this.executePendingCommands(); + } + + public boolean getAllowNether() + { + return this.getMultiWorld().getWorldById(-1) != null; + } + + public boolean allowSpawnMonsters() + { + return ConfigurationHandler.getWorldsConfig().global.mobSpawn.spawnMonsters; + } + + public void addServerStatsToSnooper(PlayerUsageSnooper par1PlayerUsageSnooper) + { + par1PlayerUsageSnooper.addData("whitelist_enabled", Boolean.valueOf(this.getConfigurationManager().isWhiteListEnabled())); + par1PlayerUsageSnooper.addData("whitelist_count", Integer.valueOf(this.getConfigurationManager().getWhiteListedPlayers().size())); + super.addServerStatsToSnooper(par1PlayerUsageSnooper); + } + + public boolean isSnooperEnabled() + { + return settings.snooperEnabled; + } + + public void addPendingCommand(String par1Str, ICommandSender par2ICommandSender) + { + this.pendingCommandList.add(new ServerCommand(par1Str, par2ICommandSender)); + } + + public void executePendingCommands() + { + while (!this.pendingCommandList.isEmpty()) + { + ServerCommand servercommand = (ServerCommand)this.pendingCommandList.remove(0); + this.getCommandManager().executeCommand(servercommand.sender, servercommand.command); + } + } + + public boolean isDedicatedServer() + { + return true; + } + + public DedicatedPlayerList getConfigurationManager() + { + return (DedicatedPlayerList)super.getConfigurationManager(); + } + + public int getIntProperty(String par1Str, int par2) + { + logInfo("Attempted to get server config unresolved integer parameter " + par1Str); + return settings.unresolved.containsKey(par1Str) ? (Integer)settings.unresolved.get(par1Str) : par2; + } + + public String getStringProperty(String par1Str, String par2Str) + { + logInfo("Attempted to get server config unresolved string parameter " + par1Str); + return settings.unresolved.containsKey(par1Str) ? (String)settings.unresolved.get(par1Str) : par2Str; + } + + public boolean getBooleanProperty(String par1Str, boolean par2) + { + logInfo("Attempted to get server config unresolved boolean parameter " + par1Str); + return settings.unresolved.containsKey(par1Str) ? (Boolean)settings.unresolved.get(par1Str) : par2; + } + + public void setProperty(String par1Str, Object par2Obj) + { + logInfo("Attempted to set server config unresolved parameter " + par1Str); + settings.unresolved.put(par1Str, par2Obj); + } + + public void saveProperties() + { + ConfigurationHandler.saveServerConfig(); + } + + public String getSettingsFilename() + { + return "server.yml"; + } + + public void setGuiEnabled() + { + MinecraftServerGui.createServerGui(this); + this.guiIsEnabled = true; + } + + public boolean getGuiEnabled() + { + return this.guiIsEnabled; + } + + public String shareToLAN(WorldSettings.GameType par1EnumGameType, boolean par2) + { + return ""; + } + + public boolean isCommandBlockEnabled() + { + return settings.enableCommandBlock; + } + + public int getSpawnProtectionSize() + { + return getIntProperty("spawn-protection", super.getSpawnProtectionSize()); + } + + public boolean isBlockProtected(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer) + { + if (par1World.provider.dimensionId != 0) + { + return false; + } + else if (this.getConfigurationManager().getOps().isEmpty()) + { + return false; + } + else if (this.getConfigurationManager().isPlayerOpped(par5EntityPlayer.getCommandSenderName())) + { + return false; + } + else if (this.getSpawnProtectionSize() <= 0) + { + return false; + } + else + { + ChunkCoordinates chunkcoordinates = par1World.getSpawnPoint(); + int l = MathHelper.abs_int(par2 - chunkcoordinates.posX); + int i1 = MathHelper.abs_int(par4 - chunkcoordinates.posZ); + int j1 = Math.max(l, i1); + return j1 <= this.getSpawnProtectionSize(); + } + } + + public int getOpPermissionLevel() + { + return settings.opPermissionLevel; + } + + public void func_143006_e(int par1) + { + super.func_143006_e(par1); + settings.playerIdleTimeout = par1; + this.saveProperties(); + } + + public boolean func_147136_ar() + { + return settings.announcePlayerAchievements; + } + + /* ======================================== ULTRAMINE START =====================================*/ + + protected void loadAllWorlds(String par1Str, String par2Str, long par3, WorldType par5WorldType, String par6Str) + { + convertMapIfNeeded(par1Str); + setUserMessage("menu.loadingLevel"); + + getMultiWorld().handleServerWorldsInit(); + + getConfigurationManager().setPlayerManager(new WorldServer[]{ getMultiWorld().getWorldById(0) }); + initialWorldChunkLoad(); + } } \ No newline at end of file diff --git a/src/main/java/net/minecraft/server/management/PlayerManager.java b/src/main/java/net/minecraft/server/management/PlayerManager.java index b8f3a65..06df095 100644 --- a/src/main/java/net/minecraft/server/management/PlayerManager.java +++ b/src/main/java/net/minecraft/server/management/PlayerManager.java @@ -1,417 +1,417 @@ -package net.minecraft.server.management; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; - -import org.ultramine.server.chunk.ChunkIOExecutor; - -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.network.Packet; -import net.minecraft.network.play.server.S21PacketChunkData; -import net.minecraft.network.play.server.S22PacketMultiBlockChange; -import net.minecraft.network.play.server.S23PacketBlockChange; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.LongHashMap; -import net.minecraft.world.ChunkCoordIntPair; -import net.minecraft.world.WorldProvider; -import net.minecraft.world.WorldServer; -import net.minecraft.world.chunk.Chunk; -import net.minecraftforge.common.ForgeModContainer; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.world.ChunkWatchEvent; - -public class PlayerManager -{ - private final WorldServer theWorldServer; - private final List players = new ArrayList(); - private final LongHashMap playerInstances = new LongHashMap(); - private final List chunkWatcherWithPlayers = new ArrayList(); - private final List playerInstanceList = new ArrayList(); - private final int playerViewRadius; - private long previousTotalWorldTime; - private final int[][] xzDirectionsConst = new int[][] {{1, 0}, {0, 1}, { -1, 0}, {0, -1}}; - private static final String __OBFID = "CL_00001434"; - - public PlayerManager(WorldServer par1WorldServer, int par2) - { - if (par2 > 15) - { - throw new IllegalArgumentException("Too big view radius!"); - } - else if (par2 < 3) - { - throw new IllegalArgumentException("Too small view radius!"); - } - else - { - this.playerViewRadius = par2; - this.theWorldServer = par1WorldServer; - } - } - - public WorldServer getWorldServer() - { - return this.theWorldServer; - } - - public void updatePlayerInstances() - { - long i = this.theWorldServer.getTotalWorldTime(); - int j; - PlayerManager.PlayerInstance playerinstance; - - if (i - this.previousTotalWorldTime > 8000L) - { - this.previousTotalWorldTime = i; - - for (j = 0; j < this.playerInstanceList.size(); ++j) - { - playerinstance = (PlayerManager.PlayerInstance)this.playerInstanceList.get(j); - playerinstance.sendChunkUpdate(); - playerinstance.processChunk(); - } - } - else - { - for (j = 0; j < this.chunkWatcherWithPlayers.size(); ++j) - { - playerinstance = (PlayerManager.PlayerInstance)this.chunkWatcherWithPlayers.get(j); - playerinstance.sendChunkUpdate(); - } - } - - this.chunkWatcherWithPlayers.clear(); - - if (this.players.isEmpty()) - { - WorldProvider worldprovider = this.theWorldServer.provider; - - if (!worldprovider.canRespawnHere()) - { - this.theWorldServer.theChunkProviderServer.unloadAllChunks(); - } - } - } - - public PlayerManager.PlayerInstance getOrCreateChunkWatcher(int par1, int par2, boolean par3) - { - long k = (long)par1 + 2147483647L | (long)par2 + 2147483647L << 32; - PlayerManager.PlayerInstance playerinstance = (PlayerManager.PlayerInstance)this.playerInstances.getValueByKey(k); - - if (playerinstance == null && par3) - { - playerinstance = new PlayerManager.PlayerInstance(par1, par2); - this.playerInstances.add(k, playerinstance); - this.playerInstanceList.add(playerinstance); - } - - return playerinstance; - } - - public void markBlockForUpdate(int p_151250_1_, int p_151250_2_, int p_151250_3_) - { - int l = p_151250_1_ >> 4; - int i1 = p_151250_3_ >> 4; - PlayerManager.PlayerInstance playerinstance = this.getOrCreateChunkWatcher(l, i1, false); - - if (playerinstance != null) - { - playerinstance.flagChunkForUpdate(p_151250_1_ & 15, p_151250_2_, p_151250_3_ & 15); - } - } - - public void addPlayer(EntityPlayerMP par1EntityPlayerMP) - { - par1EntityPlayerMP.getChunkMgr().addTo(this); - players.add(par1EntityPlayerMP); - } - - public void filterChunkLoadQueue(EntityPlayerMP par1EntityPlayerMP) - { - ArrayList arraylist = new ArrayList(par1EntityPlayerMP.loadedChunks); - int i = 0; - int j = this.playerViewRadius; - int k = (int)par1EntityPlayerMP.posX >> 4; - int l = (int)par1EntityPlayerMP.posZ >> 4; - int i1 = 0; - int j1 = 0; - ChunkCoordIntPair chunkcoordintpair = this.getOrCreateChunkWatcher(k, l, true).chunkLocation; - par1EntityPlayerMP.loadedChunks.clear(); - - if (arraylist.contains(chunkcoordintpair)) - { - par1EntityPlayerMP.loadedChunks.add(chunkcoordintpair); - } - - int k1; - - for (k1 = 1; k1 <= j * 2; ++k1) - { - for (int l1 = 0; l1 < 2; ++l1) - { - int[] aint = this.xzDirectionsConst[i++ % 4]; - - for (int i2 = 0; i2 < k1; ++i2) - { - i1 += aint[0]; - j1 += aint[1]; - chunkcoordintpair = this.getOrCreateChunkWatcher(k + i1, l + j1, true).chunkLocation; - - if (arraylist.contains(chunkcoordintpair)) - { - par1EntityPlayerMP.loadedChunks.add(chunkcoordintpair); - } - } - } - } - - i %= 4; - - for (k1 = 0; k1 < j * 2; ++k1) - { - i1 += this.xzDirectionsConst[i][0]; - j1 += this.xzDirectionsConst[i][1]; - chunkcoordintpair = this.getOrCreateChunkWatcher(k + i1, l + j1, true).chunkLocation; - - if (arraylist.contains(chunkcoordintpair)) - { - par1EntityPlayerMP.loadedChunks.add(chunkcoordintpair); - } - } - } - - public void removePlayer(EntityPlayerMP par1EntityPlayerMP) - { - par1EntityPlayerMP.getChunkMgr().removeFrom(this); - this.players.remove(par1EntityPlayerMP); - } - - private boolean overlaps(int par1, int par2, int par3, int par4, int par5) - { - int j1 = par1 - par3; - int k1 = par2 - par4; - return j1 >= -par5 && j1 <= par5 ? k1 >= -par5 && k1 <= par5 : false; - } - - public void updatePlayerPertinentChunks(EntityPlayerMP par1EntityPlayerMP) - { - par1EntityPlayerMP.getChunkMgr().updatePlayerPertinentChunks(); - } - - public boolean isPlayerWatchingChunk(EntityPlayerMP par1EntityPlayerMP, int par2, int par3) - { - PlayerManager.PlayerInstance playerinstance = this.getOrCreateChunkWatcher(par2, par3, false); - return playerinstance == null ? false : playerinstance.playersWatchingChunk.contains(par1EntityPlayerMP) && !par1EntityPlayerMP.loadedChunks.contains(playerinstance.chunkLocation); - } - - public static int getFurthestViewableBlock(int par0) - { - return par0 * 16 - 16; - } - - public class PlayerInstance - { - private final List playersWatchingChunk = new ArrayList(); - private final ChunkCoordIntPair chunkLocation; - private short[] locationOfBlockChange = new short[64]; - private int numberOfTilesToUpdate; - private int flagsYAreasToUpdate; - private long previousWorldTime; - private static final String __OBFID = "CL_00001435"; - - public PlayerInstance(int par2, int par3) - { - this.chunkLocation = new ChunkCoordIntPair(par2, par3); -// getWorldServer().theChunkProviderServer.loadAsync(par2, par3, this.loadedRunnable); - } - - public void addPlayer(EntityPlayerMP par1EntityPlayerMP) - { - if (this.playersWatchingChunk.contains(par1EntityPlayerMP)) - { - throw new IllegalStateException("Failed to add player. " + par1EntityPlayerMP + " already is in chunk " + this.chunkLocation.chunkXPos + ", " + this.chunkLocation.chunkZPos); - } - else - { - if (this.playersWatchingChunk.isEmpty()) - { - this.previousWorldTime = PlayerManager.this.theWorldServer.getTotalWorldTime(); - } - - this.playersWatchingChunk.add(par1EntityPlayerMP); - } - } - - public void removePlayer(EntityPlayerMP par1EntityPlayerMP) - { - if (this.playersWatchingChunk.contains(par1EntityPlayerMP)) - { - Chunk chunk = PlayerManager.this.theWorldServer.getChunkFromChunkCoords(this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos); - -// if (chunk.func_150802_k()) - { - par1EntityPlayerMP.playerNetServerHandler.sendPacket(S21PacketChunkData.makeForUnload(chunk)); - } - - this.playersWatchingChunk.remove(par1EntityPlayerMP); -// par1EntityPlayerMP.loadedChunks.remove(this.chunkLocation); - - MinecraftForge.EVENT_BUS.post(new ChunkWatchEvent.UnWatch(chunkLocation, par1EntityPlayerMP)); - - if (this.playersWatchingChunk.isEmpty()) - { - long i = (long)this.chunkLocation.chunkXPos + 2147483647L | (long)this.chunkLocation.chunkZPos + 2147483647L << 32; - this.increaseInhabitedTime(chunk); - PlayerManager.this.playerInstances.remove(i); - PlayerManager.this.playerInstanceList.remove(this); - - if (this.numberOfTilesToUpdate > 0) - { - PlayerManager.this.chunkWatcherWithPlayers.remove(this); - } - - PlayerManager.this.getWorldServer().theChunkProviderServer.unloadChunksIfNotNearSpawn(this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos); - } - } - } - - public void processChunk() - { - this.increaseInhabitedTime(PlayerManager.this.theWorldServer.getChunkFromChunkCoords(this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos)); - } - - private void increaseInhabitedTime(Chunk par1Chunk) - { - par1Chunk.inhabitedTime += PlayerManager.this.theWorldServer.getTotalWorldTime() - this.previousWorldTime; - this.previousWorldTime = PlayerManager.this.theWorldServer.getTotalWorldTime(); - } - - public void flagChunkForUpdate(int p_151253_1_, int p_151253_2_, int p_151253_3_) - { - if (this.numberOfTilesToUpdate == 0) - { - PlayerManager.this.chunkWatcherWithPlayers.add(this); - } - - this.flagsYAreasToUpdate |= 1 << (p_151253_2_ >> 4); - - //if (this.numberOfTilesToUpdate < 64) //Forge; Cache everything, so always run - { - short short1 = (short)(p_151253_1_ << 12 | p_151253_3_ << 8 | p_151253_2_); - - for (int l = 0; l < this.numberOfTilesToUpdate; ++l) - { - if (this.locationOfBlockChange[l] == short1) - { - return; - } - } - - if (numberOfTilesToUpdate == locationOfBlockChange.length) - { - locationOfBlockChange = Arrays.copyOf(locationOfBlockChange, locationOfBlockChange.length << 1); - } - this.locationOfBlockChange[this.numberOfTilesToUpdate++] = short1; - } - } - - public void sendToAllPlayersWatchingChunk(Packet p_151251_1_) - { - for (int i = 0; i < this.playersWatchingChunk.size(); ++i) - { - EntityPlayerMP entityplayermp = (EntityPlayerMP)this.playersWatchingChunk.get(i); - - if (!entityplayermp.loadedChunks.contains(this.chunkLocation)) - { - entityplayermp.playerNetServerHandler.sendPacket(p_151251_1_); - } - } - } - - public void sendChunkUpdate() - { - if (this.numberOfTilesToUpdate != 0) - { - int i; - int j; - int k; - - if (this.numberOfTilesToUpdate == 1) - { - i = this.chunkLocation.chunkXPos * 16 + (this.locationOfBlockChange[0] >> 12 & 15); - j = this.locationOfBlockChange[0] & 255; - k = this.chunkLocation.chunkZPos * 16 + (this.locationOfBlockChange[0] >> 8 & 15); - this.sendToAllPlayersWatchingChunk(new S23PacketBlockChange(i, j, k, PlayerManager.this.theWorldServer)); - - if (PlayerManager.this.theWorldServer.getBlock(i, j, k).hasTileEntity(PlayerManager.this.theWorldServer.getBlockMetadata(i, j, k))) - { - this.sendTileToAllPlayersWatchingChunk(PlayerManager.this.theWorldServer.getTileEntity(i, j, k)); - } - } - else - { - int l; - - if (this.numberOfTilesToUpdate == ForgeModContainer.clumpingThreshold) - { - i = this.chunkLocation.chunkXPos * 16; - j = this.chunkLocation.chunkZPos * 16; - this.sendToAllPlayersWatchingChunk(new S21PacketChunkData(PlayerManager.this.theWorldServer.getChunkFromChunkCoords(this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos), false, this.flagsYAreasToUpdate)); - - // Forge: Grabs ALL tile entities is costly on a modded server, only send needed ones - for (k = 0; false && k < 16; ++k) - { - if ((this.flagsYAreasToUpdate & 1 << k) != 0) - { - l = k << 4; - List list = PlayerManager.this.theWorldServer.func_147486_a(i, l, j, i + 16, l + 16, j + 16); - - for (int i1 = 0; i1 < list.size(); ++i1) - { - this.sendTileToAllPlayersWatchingChunk((TileEntity)list.get(i1)); - } - } - } - } - else - { - this.sendToAllPlayersWatchingChunk(new S22PacketMultiBlockChange(this.numberOfTilesToUpdate, this.locationOfBlockChange, PlayerManager.this.theWorldServer.getChunkFromChunkCoords(this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos))); - } - - { //Forge: Send only the tile entities that are updated, Adding this brace lets us keep the indent and the patch small - WorldServer world = PlayerManager.this.theWorldServer; - for (i = 0; i < this.numberOfTilesToUpdate; ++i) - { - j = this.chunkLocation.chunkXPos * 16 + (this.locationOfBlockChange[i] >> 12 & 15); - k = this.locationOfBlockChange[i] & 255; - l = this.chunkLocation.chunkZPos * 16 + (this.locationOfBlockChange[i] >> 8 & 15); - - if (world.getBlock(j, k, l).hasTileEntity(world.getBlockMetadata(j, k, l))) - { - this.sendTileToAllPlayersWatchingChunk(PlayerManager.this.theWorldServer.getTileEntity(j, k, l)); - } - } - } - } - - this.numberOfTilesToUpdate = 0; - this.flagsYAreasToUpdate = 0; - } - } - - private void sendTileToAllPlayersWatchingChunk(TileEntity p_151252_1_) - { - if (p_151252_1_ != null) - { - Packet packet = p_151252_1_.getDescriptionPacket(); - - if (packet != null) - { - this.sendToAllPlayersWatchingChunk(packet); - } - } - } - } +package net.minecraft.server.management; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +import org.ultramine.server.chunk.ChunkIOExecutor; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S21PacketChunkData; +import net.minecraft.network.play.server.S22PacketMultiBlockChange; +import net.minecraft.network.play.server.S23PacketBlockChange; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.LongHashMap; +import net.minecraft.world.ChunkCoordIntPair; +import net.minecraft.world.WorldProvider; +import net.minecraft.world.WorldServer; +import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.common.ForgeModContainer; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.ChunkWatchEvent; + +public class PlayerManager +{ + private final WorldServer theWorldServer; + private final List players = new ArrayList(); + private final LongHashMap playerInstances = new LongHashMap(); + private final List chunkWatcherWithPlayers = new ArrayList(); + private final List playerInstanceList = new ArrayList(); + private final int playerViewRadius; + private long previousTotalWorldTime; + private final int[][] xzDirectionsConst = new int[][] {{1, 0}, {0, 1}, { -1, 0}, {0, -1}}; + private static final String __OBFID = "CL_00001434"; + + public PlayerManager(WorldServer par1WorldServer, int par2) + { + if (par2 > 15) + { + throw new IllegalArgumentException("Too big view radius!"); + } + else if (par2 < 3) + { + throw new IllegalArgumentException("Too small view radius!"); + } + else + { + this.playerViewRadius = par1WorldServer.getConfig().chunkLoading.viewDistance; + this.theWorldServer = par1WorldServer; + } + } + + public WorldServer getWorldServer() + { + return this.theWorldServer; + } + + public void updatePlayerInstances() + { + long i = this.theWorldServer.getTotalWorldTime(); + int j; + PlayerManager.PlayerInstance playerinstance; + + if (i - this.previousTotalWorldTime > 8000L) + { + this.previousTotalWorldTime = i; + + for (j = 0; j < this.playerInstanceList.size(); ++j) + { + playerinstance = (PlayerManager.PlayerInstance)this.playerInstanceList.get(j); + playerinstance.sendChunkUpdate(); + playerinstance.processChunk(); + } + } + else + { + for (j = 0; j < this.chunkWatcherWithPlayers.size(); ++j) + { + playerinstance = (PlayerManager.PlayerInstance)this.chunkWatcherWithPlayers.get(j); + playerinstance.sendChunkUpdate(); + } + } + + this.chunkWatcherWithPlayers.clear(); + + if (this.players.isEmpty()) + { + WorldProvider worldprovider = this.theWorldServer.provider; + + if (!worldprovider.canRespawnHere()) + { + this.theWorldServer.theChunkProviderServer.unloadAllChunks(); + } + } + } + + public PlayerManager.PlayerInstance getOrCreateChunkWatcher(int par1, int par2, boolean par3) + { + long k = (long)par1 + 2147483647L | (long)par2 + 2147483647L << 32; + PlayerManager.PlayerInstance playerinstance = (PlayerManager.PlayerInstance)this.playerInstances.getValueByKey(k); + + if (playerinstance == null && par3) + { + playerinstance = new PlayerManager.PlayerInstance(par1, par2); + this.playerInstances.add(k, playerinstance); + this.playerInstanceList.add(playerinstance); + } + + return playerinstance; + } + + public void markBlockForUpdate(int p_151250_1_, int p_151250_2_, int p_151250_3_) + { + int l = p_151250_1_ >> 4; + int i1 = p_151250_3_ >> 4; + PlayerManager.PlayerInstance playerinstance = this.getOrCreateChunkWatcher(l, i1, false); + + if (playerinstance != null) + { + playerinstance.flagChunkForUpdate(p_151250_1_ & 15, p_151250_2_, p_151250_3_ & 15); + } + } + + public void addPlayer(EntityPlayerMP par1EntityPlayerMP) + { + par1EntityPlayerMP.getChunkMgr().addTo(this); + players.add(par1EntityPlayerMP); + } + + public void filterChunkLoadQueue(EntityPlayerMP par1EntityPlayerMP) + { + ArrayList arraylist = new ArrayList(par1EntityPlayerMP.loadedChunks); + int i = 0; + int j = this.playerViewRadius; + int k = (int)par1EntityPlayerMP.posX >> 4; + int l = (int)par1EntityPlayerMP.posZ >> 4; + int i1 = 0; + int j1 = 0; + ChunkCoordIntPair chunkcoordintpair = this.getOrCreateChunkWatcher(k, l, true).chunkLocation; + par1EntityPlayerMP.loadedChunks.clear(); + + if (arraylist.contains(chunkcoordintpair)) + { + par1EntityPlayerMP.loadedChunks.add(chunkcoordintpair); + } + + int k1; + + for (k1 = 1; k1 <= j * 2; ++k1) + { + for (int l1 = 0; l1 < 2; ++l1) + { + int[] aint = this.xzDirectionsConst[i++ % 4]; + + for (int i2 = 0; i2 < k1; ++i2) + { + i1 += aint[0]; + j1 += aint[1]; + chunkcoordintpair = this.getOrCreateChunkWatcher(k + i1, l + j1, true).chunkLocation; + + if (arraylist.contains(chunkcoordintpair)) + { + par1EntityPlayerMP.loadedChunks.add(chunkcoordintpair); + } + } + } + } + + i %= 4; + + for (k1 = 0; k1 < j * 2; ++k1) + { + i1 += this.xzDirectionsConst[i][0]; + j1 += this.xzDirectionsConst[i][1]; + chunkcoordintpair = this.getOrCreateChunkWatcher(k + i1, l + j1, true).chunkLocation; + + if (arraylist.contains(chunkcoordintpair)) + { + par1EntityPlayerMP.loadedChunks.add(chunkcoordintpair); + } + } + } + + public void removePlayer(EntityPlayerMP par1EntityPlayerMP) + { + par1EntityPlayerMP.getChunkMgr().removeFrom(this); + this.players.remove(par1EntityPlayerMP); + } + + private boolean overlaps(int par1, int par2, int par3, int par4, int par5) + { + int j1 = par1 - par3; + int k1 = par2 - par4; + return j1 >= -par5 && j1 <= par5 ? k1 >= -par5 && k1 <= par5 : false; + } + + public void updatePlayerPertinentChunks(EntityPlayerMP par1EntityPlayerMP) + { + par1EntityPlayerMP.getChunkMgr().updatePlayerPertinentChunks(); + } + + public boolean isPlayerWatchingChunk(EntityPlayerMP par1EntityPlayerMP, int par2, int par3) + { + PlayerManager.PlayerInstance playerinstance = this.getOrCreateChunkWatcher(par2, par3, false); + return playerinstance == null ? false : playerinstance.playersWatchingChunk.contains(par1EntityPlayerMP) && !par1EntityPlayerMP.loadedChunks.contains(playerinstance.chunkLocation); + } + + public static int getFurthestViewableBlock(int par0) + { + return par0 * 16 - 16; + } + + public class PlayerInstance + { + private final List playersWatchingChunk = new ArrayList(); + private final ChunkCoordIntPair chunkLocation; + private short[] locationOfBlockChange = new short[64]; + private int numberOfTilesToUpdate; + private int flagsYAreasToUpdate; + private long previousWorldTime; + private static final String __OBFID = "CL_00001435"; + + public PlayerInstance(int par2, int par3) + { + this.chunkLocation = new ChunkCoordIntPair(par2, par3); +// getWorldServer().theChunkProviderServer.loadAsync(par2, par3, this.loadedRunnable); + } + + public void addPlayer(EntityPlayerMP par1EntityPlayerMP) + { + if (this.playersWatchingChunk.contains(par1EntityPlayerMP)) + { + throw new IllegalStateException("Failed to add player. " + par1EntityPlayerMP + " already is in chunk " + this.chunkLocation.chunkXPos + ", " + this.chunkLocation.chunkZPos); + } + else + { + if (this.playersWatchingChunk.isEmpty()) + { + this.previousWorldTime = PlayerManager.this.theWorldServer.getTotalWorldTime(); + } + + this.playersWatchingChunk.add(par1EntityPlayerMP); + } + } + + public void removePlayer(EntityPlayerMP par1EntityPlayerMP) + { + if (this.playersWatchingChunk.contains(par1EntityPlayerMP)) + { + Chunk chunk = PlayerManager.this.theWorldServer.getChunkFromChunkCoords(this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos); + +// if (chunk.func_150802_k()) + { + par1EntityPlayerMP.playerNetServerHandler.sendPacket(S21PacketChunkData.makeForUnload(chunk)); + } + + this.playersWatchingChunk.remove(par1EntityPlayerMP); +// par1EntityPlayerMP.loadedChunks.remove(this.chunkLocation); + + MinecraftForge.EVENT_BUS.post(new ChunkWatchEvent.UnWatch(chunkLocation, par1EntityPlayerMP)); + + if (this.playersWatchingChunk.isEmpty()) + { + long i = (long)this.chunkLocation.chunkXPos + 2147483647L | (long)this.chunkLocation.chunkZPos + 2147483647L << 32; + this.increaseInhabitedTime(chunk); + PlayerManager.this.playerInstances.remove(i); + PlayerManager.this.playerInstanceList.remove(this); + + if (this.numberOfTilesToUpdate > 0) + { + PlayerManager.this.chunkWatcherWithPlayers.remove(this); + } + + PlayerManager.this.getWorldServer().theChunkProviderServer.unloadChunksIfNotNearSpawn(this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos); + } + } + } + + public void processChunk() + { + this.increaseInhabitedTime(PlayerManager.this.theWorldServer.getChunkFromChunkCoords(this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos)); + } + + private void increaseInhabitedTime(Chunk par1Chunk) + { + par1Chunk.inhabitedTime += PlayerManager.this.theWorldServer.getTotalWorldTime() - this.previousWorldTime; + this.previousWorldTime = PlayerManager.this.theWorldServer.getTotalWorldTime(); + } + + public void flagChunkForUpdate(int p_151253_1_, int p_151253_2_, int p_151253_3_) + { + if (this.numberOfTilesToUpdate == 0) + { + PlayerManager.this.chunkWatcherWithPlayers.add(this); + } + + this.flagsYAreasToUpdate |= 1 << (p_151253_2_ >> 4); + + //if (this.numberOfTilesToUpdate < 64) //Forge; Cache everything, so always run + { + short short1 = (short)(p_151253_1_ << 12 | p_151253_3_ << 8 | p_151253_2_); + + for (int l = 0; l < this.numberOfTilesToUpdate; ++l) + { + if (this.locationOfBlockChange[l] == short1) + { + return; + } + } + + if (numberOfTilesToUpdate == locationOfBlockChange.length) + { + locationOfBlockChange = Arrays.copyOf(locationOfBlockChange, locationOfBlockChange.length << 1); + } + this.locationOfBlockChange[this.numberOfTilesToUpdate++] = short1; + } + } + + public void sendToAllPlayersWatchingChunk(Packet p_151251_1_) + { + for (int i = 0; i < this.playersWatchingChunk.size(); ++i) + { + EntityPlayerMP entityplayermp = (EntityPlayerMP)this.playersWatchingChunk.get(i); + + if (!entityplayermp.loadedChunks.contains(this.chunkLocation)) + { + entityplayermp.playerNetServerHandler.sendPacket(p_151251_1_); + } + } + } + + public void sendChunkUpdate() + { + if (this.numberOfTilesToUpdate != 0) + { + int i; + int j; + int k; + + if (this.numberOfTilesToUpdate == 1) + { + i = this.chunkLocation.chunkXPos * 16 + (this.locationOfBlockChange[0] >> 12 & 15); + j = this.locationOfBlockChange[0] & 255; + k = this.chunkLocation.chunkZPos * 16 + (this.locationOfBlockChange[0] >> 8 & 15); + this.sendToAllPlayersWatchingChunk(new S23PacketBlockChange(i, j, k, PlayerManager.this.theWorldServer)); + + if (PlayerManager.this.theWorldServer.getBlock(i, j, k).hasTileEntity(PlayerManager.this.theWorldServer.getBlockMetadata(i, j, k))) + { + this.sendTileToAllPlayersWatchingChunk(PlayerManager.this.theWorldServer.getTileEntity(i, j, k)); + } + } + else + { + int l; + + if (this.numberOfTilesToUpdate == ForgeModContainer.clumpingThreshold) + { + i = this.chunkLocation.chunkXPos * 16; + j = this.chunkLocation.chunkZPos * 16; + this.sendToAllPlayersWatchingChunk(new S21PacketChunkData(PlayerManager.this.theWorldServer.getChunkFromChunkCoords(this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos), false, this.flagsYAreasToUpdate)); + + // Forge: Grabs ALL tile entities is costly on a modded server, only send needed ones + for (k = 0; false && k < 16; ++k) + { + if ((this.flagsYAreasToUpdate & 1 << k) != 0) + { + l = k << 4; + List list = PlayerManager.this.theWorldServer.func_147486_a(i, l, j, i + 16, l + 16, j + 16); + + for (int i1 = 0; i1 < list.size(); ++i1) + { + this.sendTileToAllPlayersWatchingChunk((TileEntity)list.get(i1)); + } + } + } + } + else + { + this.sendToAllPlayersWatchingChunk(new S22PacketMultiBlockChange(this.numberOfTilesToUpdate, this.locationOfBlockChange, PlayerManager.this.theWorldServer.getChunkFromChunkCoords(this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos))); + } + + { //Forge: Send only the tile entities that are updated, Adding this brace lets us keep the indent and the patch small + WorldServer world = PlayerManager.this.theWorldServer; + for (i = 0; i < this.numberOfTilesToUpdate; ++i) + { + j = this.chunkLocation.chunkXPos * 16 + (this.locationOfBlockChange[i] >> 12 & 15); + k = this.locationOfBlockChange[i] & 255; + l = this.chunkLocation.chunkZPos * 16 + (this.locationOfBlockChange[i] >> 8 & 15); + + if (world.getBlock(j, k, l).hasTileEntity(world.getBlockMetadata(j, k, l))) + { + this.sendTileToAllPlayersWatchingChunk(PlayerManager.this.theWorldServer.getTileEntity(j, k, l)); + } + } + } + } + + this.numberOfTilesToUpdate = 0; + this.flagsYAreasToUpdate = 0; + } + } + + private void sendTileToAllPlayersWatchingChunk(TileEntity p_151252_1_) + { + if (p_151252_1_ != null) + { + Packet packet = p_151252_1_.getDescriptionPacket(); + + if (packet != null) + { + this.sendToAllPlayersWatchingChunk(packet); + } + } + } + } } \ No newline at end of file diff --git a/src/main/java/net/minecraft/world/SpawnerAnimals.java b/src/main/java/net/minecraft/world/SpawnerAnimals.java index 890af08..da396fb 100644 --- a/src/main/java/net/minecraft/world/SpawnerAnimals.java +++ b/src/main/java/net/minecraft/world/SpawnerAnimals.java @@ -1,295 +1,295 @@ -package net.minecraft.world; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Random; - -import org.ultramine.server.ConfigurationHandler; - -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.entity.EntityLiving; -import net.minecraft.entity.EnumCreatureType; -import net.minecraft.entity.IEntityLivingData; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.util.ChunkCoordinates; -import net.minecraft.util.MathHelper; -import net.minecraft.util.WeightedRandom; -import net.minecraft.world.biome.BiomeGenBase; -import net.minecraft.world.chunk.Chunk; -import cpw.mods.fml.common.eventhandler.Event.Result; -import net.minecraftforge.event.ForgeEventFactory; - -public final class SpawnerAnimals -{ - private HashMap eligibleChunksForSpawning = new HashMap(); - private static final String __OBFID = "CL_00000152"; - - protected static ChunkPosition func_151350_a(World p_151350_0_, int p_151350_1_, int p_151350_2_) - { - Chunk chunk = p_151350_0_.getChunkFromChunkCoords(p_151350_1_, p_151350_2_); - int k = p_151350_1_ * 16 + p_151350_0_.rand.nextInt(16); - int l = p_151350_2_ * 16 + p_151350_0_.rand.nextInt(16); - int i1 = p_151350_0_.rand.nextInt(chunk == null ? p_151350_0_.getActualHeight() : chunk.getTopFilledSegment() + 16 - 1); - return new ChunkPosition(k, i1, l); - } - - public int findChunksForSpawning(WorldServer par1WorldServer, boolean par2, boolean par3, boolean par4) - { - if (!par2 && !par3) - { - return 0; - } - else - { - this.eligibleChunksForSpawning.clear(); - int i; - int k; - - for (i = 0; i < par1WorldServer.playerEntities.size(); ++i) - { - EntityPlayer entityplayer = (EntityPlayer)par1WorldServer.playerEntities.get(i); - int j = MathHelper.floor_double(entityplayer.posX / 16.0D); - k = MathHelper.floor_double(entityplayer.posZ / 16.0D); - int b0 = ConfigurationHandler.getServerConfig().chunkUpdateRadius; - - for (int l = -b0; l <= b0; ++l) - { - for (int i1 = -b0; i1 <= b0; ++i1) - { - int cx = l + j; - int cz = i1 + k; - - if(par1WorldServer.chunkExists(cx, cz)) - { - boolean flag3 = l == -b0 || l == b0 || i1 == -b0 || i1 == b0; - ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(cx, cz); - - if (!flag3) - { - this.eligibleChunksForSpawning.put(chunkcoordintpair, Boolean.valueOf(false)); - } - else if (!this.eligibleChunksForSpawning.containsKey(chunkcoordintpair)) - { - this.eligibleChunksForSpawning.put(chunkcoordintpair, Boolean.valueOf(true)); - } - } - } - } - } - - i = 0; - ChunkCoordinates chunkcoordinates = par1WorldServer.getSpawnPoint(); - EnumCreatureType[] aenumcreaturetype = EnumCreatureType.values(); - k = aenumcreaturetype.length; - - for (int k3 = 0; k3 < k; ++k3) - { - EnumCreatureType enumcreaturetype = aenumcreaturetype[k3]; - - if ((!enumcreaturetype.getPeacefulCreature() || par3) && (enumcreaturetype.getPeacefulCreature() || par2) && (!enumcreaturetype.getAnimal() || par4) && par1WorldServer.countEntities(enumcreaturetype, true) <= enumcreaturetype.getMaxNumberOfCreature() * this.eligibleChunksForSpawning.size() / 256) - { - Iterator iterator = this.eligibleChunksForSpawning.keySet().iterator(); - ArrayList tmp = new ArrayList(eligibleChunksForSpawning.keySet()); - Collections.shuffle(tmp); - iterator = tmp.iterator(); - label110: - - while (iterator.hasNext()) - { - ChunkCoordIntPair chunkcoordintpair1 = (ChunkCoordIntPair)iterator.next(); - - if (!((Boolean)this.eligibleChunksForSpawning.get(chunkcoordintpair1)).booleanValue()) - { - ChunkPosition chunkposition = func_151350_a(par1WorldServer, chunkcoordintpair1.chunkXPos, chunkcoordintpair1.chunkZPos); - int j1 = chunkposition.chunkPosX; - int k1 = chunkposition.chunkPosY; - int l1 = chunkposition.chunkPosZ; - - if (!par1WorldServer.getBlock(j1, k1, l1).isNormalCube() && par1WorldServer.getBlock(j1, k1, l1).getMaterial() == enumcreaturetype.getCreatureMaterial()) - { - int i2 = 0; - int j2 = 0; - - while (j2 < 3) - { - int k2 = j1; - int l2 = k1; - int i3 = l1; - byte b1 = 6; - BiomeGenBase.SpawnListEntry spawnlistentry = null; - IEntityLivingData ientitylivingdata = null; - int j3 = 0; - - while (true) - { - if (j3 < 4) - { - label103: - { - k2 += par1WorldServer.rand.nextInt(b1) - par1WorldServer.rand.nextInt(b1); - l2 += par1WorldServer.rand.nextInt(1) - par1WorldServer.rand.nextInt(1); - i3 += par1WorldServer.rand.nextInt(b1) - par1WorldServer.rand.nextInt(b1); - - if (canCreatureTypeSpawnAtLocation(enumcreaturetype, par1WorldServer, k2, l2, i3)) - { - float f = (float)k2 + 0.5F; - float f1 = (float)l2; - float f2 = (float)i3 + 0.5F; - - if (par1WorldServer.getClosestPlayer((double)f, (double)f1, (double)f2, 24.0D) == null) - { - float f3 = f - (float)chunkcoordinates.posX; - float f4 = f1 - (float)chunkcoordinates.posY; - float f5 = f2 - (float)chunkcoordinates.posZ; - float f6 = f3 * f3 + f4 * f4 + f5 * f5; - - if (f6 >= 576.0F) - { - if (spawnlistentry == null) - { - spawnlistentry = par1WorldServer.spawnRandomCreature(enumcreaturetype, k2, l2, i3); - - if (spawnlistentry == null) - { - break label103; - } - } - - EntityLiving entityliving; - - try - { - entityliving = (EntityLiving)spawnlistentry.entityClass.getConstructor(new Class[] {World.class}).newInstance(new Object[] {par1WorldServer}); - } - catch (Exception exception) - { - exception.printStackTrace(); - return i; - } - - entityliving.setLocationAndAngles((double)f, (double)f1, (double)f2, par1WorldServer.rand.nextFloat() * 360.0F, 0.0F); - - Result canSpawn = ForgeEventFactory.canEntitySpawn(entityliving, par1WorldServer, f, f1, f2); - if (canSpawn == Result.ALLOW || (canSpawn == Result.DEFAULT && entityliving.getCanSpawnHere())) - { - ++i2; - par1WorldServer.spawnEntityInWorld(entityliving); - if (!ForgeEventFactory.doSpecialSpawn(entityliving, par1WorldServer, f, f1, f2)) - { - ientitylivingdata = entityliving.onSpawnWithEgg(ientitylivingdata); - } - - if (j2 >= ForgeEventFactory.getMaxSpawnPackSize(entityliving)) - { - continue label110; - } - } - - i += i2; - } - } - } - - ++j3; - continue; - } - } - - ++j2; - break; - } - } - } - } - } - } - } - - return i; - } - } - - public static boolean canCreatureTypeSpawnAtLocation(EnumCreatureType par0EnumCreatureType, World par1World, int par2, int par3, int par4) - { - if(!par1World.blockExists(par2, par3, par4)) return false; - - if (par0EnumCreatureType.getCreatureMaterial() == Material.water) - { - return par1World.getBlock(par2, par3, par4).getMaterial().isLiquid() && par1World.getBlock(par2, par3 - 1, par4).getMaterial().isLiquid() && !par1World.getBlock(par2, par3 + 1, par4).isNormalCube(); - } - else if (!World.doesBlockHaveSolidTopSurface(par1World, par2, par3 - 1, par4)) - { - return false; - } - else - { - Block block = par1World.getBlock(par2, par3 - 1, par4); - boolean spawnBlock = block.canCreatureSpawn(par0EnumCreatureType, par1World, par2, par3 - 1, par4); - return spawnBlock && block != Blocks.bedrock && !par1World.getBlock(par2, par3, par4).isNormalCube() && !par1World.getBlock(par2, par3, par4).getMaterial().isLiquid() && !par1World.getBlock(par2, par3 + 1, par4).isNormalCube(); - } - } - - public static void performWorldGenSpawning(World par0World, BiomeGenBase par1BiomeGenBase, int par2, int par3, int par4, int par5, Random par6Random) - { - List list = par1BiomeGenBase.getSpawnableList(EnumCreatureType.creature); - - if (!list.isEmpty()) - { - while (par6Random.nextFloat() < par1BiomeGenBase.getSpawningChance()) - { - BiomeGenBase.SpawnListEntry spawnlistentry = (BiomeGenBase.SpawnListEntry)WeightedRandom.getRandomItem(par0World.rand, list); - IEntityLivingData ientitylivingdata = null; - int i1 = spawnlistentry.minGroupCount + par6Random.nextInt(1 + spawnlistentry.maxGroupCount - spawnlistentry.minGroupCount); - int j1 = par2 + par6Random.nextInt(par4); - int k1 = par3 + par6Random.nextInt(par5); - int l1 = j1; - int i2 = k1; - - for (int j2 = 0; j2 < i1; ++j2) - { - boolean flag = false; - - for (int k2 = 0; !flag && k2 < 4; ++k2) - { - int l2 = par0World.getTopSolidOrLiquidBlock(j1, k1); - - if (canCreatureTypeSpawnAtLocation(EnumCreatureType.creature, par0World, j1, l2, k1)) - { - float f = (float)j1 + 0.5F; - float f1 = (float)l2; - float f2 = (float)k1 + 0.5F; - EntityLiving entityliving; - - try - { - entityliving = (EntityLiving)spawnlistentry.entityClass.getConstructor(new Class[] {World.class}).newInstance(new Object[] {par0World}); - } - catch (Exception exception) - { - exception.printStackTrace(); - continue; - } - - entityliving.setLocationAndAngles((double)f, (double)f1, (double)f2, par6Random.nextFloat() * 360.0F, 0.0F); - par0World.spawnEntityInWorld(entityliving); - ientitylivingdata = entityliving.onSpawnWithEgg(ientitylivingdata); - flag = true; - } - - j1 += par6Random.nextInt(5) - par6Random.nextInt(5); - - for (k1 += par6Random.nextInt(5) - par6Random.nextInt(5); j1 < par2 || j1 >= par2 + par4 || k1 < par3 || k1 >= par3 + par4; k1 = i2 + par6Random.nextInt(5) - par6Random.nextInt(5)) - { - j1 = l1 + par6Random.nextInt(5) - par6Random.nextInt(5); - } - } - } - } - } - } +package net.minecraft.world; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Random; + +import org.ultramine.server.ConfigurationHandler; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EnumCreatureType; +import net.minecraft.entity.IEntityLivingData; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.MathHelper; +import net.minecraft.util.WeightedRandom; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.world.chunk.Chunk; +import cpw.mods.fml.common.eventhandler.Event.Result; +import net.minecraftforge.event.ForgeEventFactory; + +public final class SpawnerAnimals +{ + private HashMap eligibleChunksForSpawning = new HashMap(); + private static final String __OBFID = "CL_00000152"; + + protected static ChunkPosition func_151350_a(World p_151350_0_, int p_151350_1_, int p_151350_2_) + { + Chunk chunk = p_151350_0_.getChunkFromChunkCoords(p_151350_1_, p_151350_2_); + int k = p_151350_1_ * 16 + p_151350_0_.rand.nextInt(16); + int l = p_151350_2_ * 16 + p_151350_0_.rand.nextInt(16); + int i1 = p_151350_0_.rand.nextInt(chunk == null ? p_151350_0_.getActualHeight() : chunk.getTopFilledSegment() + 16 - 1); + return new ChunkPosition(k, i1, l); + } + + public int findChunksForSpawning(WorldServer par1WorldServer, boolean par2, boolean par3, boolean par4) + { + if (!par2 && !par3) + { + return 0; + } + else + { + this.eligibleChunksForSpawning.clear(); + int i; + int k; + + for (i = 0; i < par1WorldServer.playerEntities.size(); ++i) + { + EntityPlayer entityplayer = (EntityPlayer)par1WorldServer.playerEntities.get(i); + int j = MathHelper.floor_double(entityplayer.posX / 16.0D); + k = MathHelper.floor_double(entityplayer.posZ / 16.0D); + int b0 = par1WorldServer.getConfig().chunkLoading.chunkUpdateRadius; + + for (int l = -b0; l <= b0; ++l) + { + for (int i1 = -b0; i1 <= b0; ++i1) + { + int cx = l + j; + int cz = i1 + k; + + if(par1WorldServer.chunkExists(cx, cz)) + { + boolean flag3 = l == -b0 || l == b0 || i1 == -b0 || i1 == b0; + ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(cx, cz); + + if (!flag3) + { + this.eligibleChunksForSpawning.put(chunkcoordintpair, Boolean.valueOf(false)); + } + else if (!this.eligibleChunksForSpawning.containsKey(chunkcoordintpair)) + { + this.eligibleChunksForSpawning.put(chunkcoordintpair, Boolean.valueOf(true)); + } + } + } + } + } + + i = 0; + ChunkCoordinates chunkcoordinates = par1WorldServer.getSpawnPoint(); + EnumCreatureType[] aenumcreaturetype = EnumCreatureType.values(); + k = aenumcreaturetype.length; + + for (int k3 = 0; k3 < k; ++k3) + { + EnumCreatureType enumcreaturetype = aenumcreaturetype[k3]; + + if ((!enumcreaturetype.getPeacefulCreature() || par3) && (enumcreaturetype.getPeacefulCreature() || par2) && (!enumcreaturetype.getAnimal() || par4) && par1WorldServer.countEntities(enumcreaturetype, true) <= enumcreaturetype.getMaxNumberOfCreature() * this.eligibleChunksForSpawning.size() / 256) + { + Iterator iterator = this.eligibleChunksForSpawning.keySet().iterator(); + ArrayList tmp = new ArrayList(eligibleChunksForSpawning.keySet()); + Collections.shuffle(tmp); + iterator = tmp.iterator(); + label110: + + while (iterator.hasNext()) + { + ChunkCoordIntPair chunkcoordintpair1 = (ChunkCoordIntPair)iterator.next(); + + if (!((Boolean)this.eligibleChunksForSpawning.get(chunkcoordintpair1)).booleanValue()) + { + ChunkPosition chunkposition = func_151350_a(par1WorldServer, chunkcoordintpair1.chunkXPos, chunkcoordintpair1.chunkZPos); + int j1 = chunkposition.chunkPosX; + int k1 = chunkposition.chunkPosY; + int l1 = chunkposition.chunkPosZ; + + if (!par1WorldServer.getBlock(j1, k1, l1).isNormalCube() && par1WorldServer.getBlock(j1, k1, l1).getMaterial() == enumcreaturetype.getCreatureMaterial()) + { + int i2 = 0; + int j2 = 0; + + while (j2 < 3) + { + int k2 = j1; + int l2 = k1; + int i3 = l1; + byte b1 = 6; + BiomeGenBase.SpawnListEntry spawnlistentry = null; + IEntityLivingData ientitylivingdata = null; + int j3 = 0; + + while (true) + { + if (j3 < 4) + { + label103: + { + k2 += par1WorldServer.rand.nextInt(b1) - par1WorldServer.rand.nextInt(b1); + l2 += par1WorldServer.rand.nextInt(1) - par1WorldServer.rand.nextInt(1); + i3 += par1WorldServer.rand.nextInt(b1) - par1WorldServer.rand.nextInt(b1); + + if (canCreatureTypeSpawnAtLocation(enumcreaturetype, par1WorldServer, k2, l2, i3)) + { + float f = (float)k2 + 0.5F; + float f1 = (float)l2; + float f2 = (float)i3 + 0.5F; + + if (par1WorldServer.getClosestPlayer((double)f, (double)f1, (double)f2, 24.0D) == null) + { + float f3 = f - (float)chunkcoordinates.posX; + float f4 = f1 - (float)chunkcoordinates.posY; + float f5 = f2 - (float)chunkcoordinates.posZ; + float f6 = f3 * f3 + f4 * f4 + f5 * f5; + + if (f6 >= 576.0F) + { + if (spawnlistentry == null) + { + spawnlistentry = par1WorldServer.spawnRandomCreature(enumcreaturetype, k2, l2, i3); + + if (spawnlistentry == null) + { + break label103; + } + } + + EntityLiving entityliving; + + try + { + entityliving = (EntityLiving)spawnlistentry.entityClass.getConstructor(new Class[] {World.class}).newInstance(new Object[] {par1WorldServer}); + } + catch (Exception exception) + { + exception.printStackTrace(); + return i; + } + + entityliving.setLocationAndAngles((double)f, (double)f1, (double)f2, par1WorldServer.rand.nextFloat() * 360.0F, 0.0F); + + Result canSpawn = ForgeEventFactory.canEntitySpawn(entityliving, par1WorldServer, f, f1, f2); + if (canSpawn == Result.ALLOW || (canSpawn == Result.DEFAULT && entityliving.getCanSpawnHere())) + { + ++i2; + par1WorldServer.spawnEntityInWorld(entityliving); + if (!ForgeEventFactory.doSpecialSpawn(entityliving, par1WorldServer, f, f1, f2)) + { + ientitylivingdata = entityliving.onSpawnWithEgg(ientitylivingdata); + } + + if (j2 >= ForgeEventFactory.getMaxSpawnPackSize(entityliving)) + { + continue label110; + } + } + + i += i2; + } + } + } + + ++j3; + continue; + } + } + + ++j2; + break; + } + } + } + } + } + } + } + + return i; + } + } + + public static boolean canCreatureTypeSpawnAtLocation(EnumCreatureType par0EnumCreatureType, World par1World, int par2, int par3, int par4) + { + if(!par1World.blockExists(par2, par3, par4)) return false; + + if (par0EnumCreatureType.getCreatureMaterial() == Material.water) + { + return par1World.getBlock(par2, par3, par4).getMaterial().isLiquid() && par1World.getBlock(par2, par3 - 1, par4).getMaterial().isLiquid() && !par1World.getBlock(par2, par3 + 1, par4).isNormalCube(); + } + else if (!World.doesBlockHaveSolidTopSurface(par1World, par2, par3 - 1, par4)) + { + return false; + } + else + { + Block block = par1World.getBlock(par2, par3 - 1, par4); + boolean spawnBlock = block.canCreatureSpawn(par0EnumCreatureType, par1World, par2, par3 - 1, par4); + return spawnBlock && block != Blocks.bedrock && !par1World.getBlock(par2, par3, par4).isNormalCube() && !par1World.getBlock(par2, par3, par4).getMaterial().isLiquid() && !par1World.getBlock(par2, par3 + 1, par4).isNormalCube(); + } + } + + public static void performWorldGenSpawning(World par0World, BiomeGenBase par1BiomeGenBase, int par2, int par3, int par4, int par5, Random par6Random) + { + List list = par1BiomeGenBase.getSpawnableList(EnumCreatureType.creature); + + if (!list.isEmpty()) + { + while (par6Random.nextFloat() < par1BiomeGenBase.getSpawningChance()) + { + BiomeGenBase.SpawnListEntry spawnlistentry = (BiomeGenBase.SpawnListEntry)WeightedRandom.getRandomItem(par0World.rand, list); + IEntityLivingData ientitylivingdata = null; + int i1 = spawnlistentry.minGroupCount + par6Random.nextInt(1 + spawnlistentry.maxGroupCount - spawnlistentry.minGroupCount); + int j1 = par2 + par6Random.nextInt(par4); + int k1 = par3 + par6Random.nextInt(par5); + int l1 = j1; + int i2 = k1; + + for (int j2 = 0; j2 < i1; ++j2) + { + boolean flag = false; + + for (int k2 = 0; !flag && k2 < 4; ++k2) + { + int l2 = par0World.getTopSolidOrLiquidBlock(j1, k1); + + if (canCreatureTypeSpawnAtLocation(EnumCreatureType.creature, par0World, j1, l2, k1)) + { + float f = (float)j1 + 0.5F; + float f1 = (float)l2; + float f2 = (float)k1 + 0.5F; + EntityLiving entityliving; + + try + { + entityliving = (EntityLiving)spawnlistentry.entityClass.getConstructor(new Class[] {World.class}).newInstance(new Object[] {par0World}); + } + catch (Exception exception) + { + exception.printStackTrace(); + continue; + } + + entityliving.setLocationAndAngles((double)f, (double)f1, (double)f2, par6Random.nextFloat() * 360.0F, 0.0F); + par0World.spawnEntityInWorld(entityliving); + ientitylivingdata = entityliving.onSpawnWithEgg(ientitylivingdata); + flag = true; + } + + j1 += par6Random.nextInt(5) - par6Random.nextInt(5); + + for (k1 += par6Random.nextInt(5) - par6Random.nextInt(5); j1 < par2 || j1 >= par2 + par4 || k1 < par3 || k1 >= par3 + par4; k1 = i2 + par6Random.nextInt(5) - par6Random.nextInt(5)) + { + j1 = l1 + par6Random.nextInt(5) - par6Random.nextInt(5); + } + } + } + } + } + } } \ No newline at end of file diff --git a/src/main/java/net/minecraft/world/World.java b/src/main/java/net/minecraft/world/World.java index 42be661..dba6cf6 100644 --- a/src/main/java/net/minecraft/world/World.java +++ b/src/main/java/net/minecraft/world/World.java @@ -1,3990 +1,4000 @@ -package net.minecraft.world; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import gnu.trove.map.TIntByteMap; -import gnu.trove.map.hash.TIntByteHashMap; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Random; -import java.util.Set; -import java.util.concurrent.Callable; - -import org.ultramine.server.ConfigurationHandler; -import org.ultramine.server.chunk.ChunkHash; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockHopper; -import net.minecraft.block.BlockLiquid; -import net.minecraft.block.BlockSlab; -import net.minecraft.block.BlockSnow; -import net.minecraft.block.BlockStairs; -import net.minecraft.block.material.Material; -import net.minecraft.command.IEntitySelector; -import net.minecraft.crash.CrashReport; -import net.minecraft.crash.CrashReportCategory; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLiving; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.pathfinding.PathEntity; -import net.minecraft.pathfinding.PathFinder; -import net.minecraft.profiler.Profiler; -import net.minecraft.scoreboard.Scoreboard; -import net.minecraft.server.MinecraftServer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.ChunkCoordinates; -import net.minecraft.util.Direction; -import net.minecraft.util.Facing; -import net.minecraft.util.MathHelper; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.ReportedException; -import net.minecraft.util.Vec3; -import net.minecraft.util.Vec3Pool; -import net.minecraft.village.VillageCollection; -import net.minecraft.village.VillageSiege; -import net.minecraft.world.biome.BiomeGenBase; -import net.minecraft.world.biome.WorldChunkManager; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.storage.ISaveHandler; -import net.minecraft.world.storage.MapStorage; -import net.minecraft.world.storage.WorldInfo; -import cpw.mods.fml.common.FMLLog; - -import com.google.common.collect.ImmutableSetMultimap; - -import net.minecraftforge.client.ForgeHooksClient; -import net.minecraftforge.common.ForgeChunkManager; -import net.minecraftforge.common.ForgeChunkManager.Ticket; -import net.minecraftforge.common.ForgeModContainer; -import net.minecraftforge.common.ForgeHooks; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.common.WorldSpecificSaveHandler; -import net.minecraftforge.event.entity.EntityEvent; -import net.minecraftforge.event.entity.EntityJoinWorldEvent; -import net.minecraftforge.event.world.WorldEvent; -import net.minecraftforge.event.entity.PlaySoundAtEntityEvent; -import net.minecraft.entity.EnumCreatureType; - -public abstract class World implements IBlockAccess -{ -/** - * Used in the getEntitiesWithinAABB functions to expand the search area for entities. - * Modders should change this variable to a higher value if it is less then the radius - * of one of there entities. - */ - public static double MAX_ENTITY_RADIUS = 2.0D; - - public final MapStorage perWorldStorage; - - public boolean scheduledUpdatesAreImmediate; - public List loadedEntityList = new ArrayList(); - protected List unloadedEntityList = new ArrayList(); - public List loadedTileEntityList = new ArrayList(); - private List addedTileEntityList = new ArrayList(); - private List field_147483_b = new ArrayList(); - public List playerEntities = new ArrayList(); - public List weatherEffects = new ArrayList(); - private long cloudColour = 16777215L; - public int skylightSubtracted; - protected int updateLCG = (new Random()).nextInt(); - protected final int DIST_HASH_MAGIC = 1013904223; - public float prevRainingStrength; - public float rainingStrength; - public float prevThunderingStrength; - public float thunderingStrength; - public int lastLightningBolt; - public EnumDifficulty difficultySetting; - public Random rand = new Random(); - public final WorldProvider provider; - protected List worldAccesses = new ArrayList(); - protected IChunkProvider chunkProvider; - protected final ISaveHandler saveHandler; - protected WorldInfo worldInfo; - public boolean findingSpawnPoint; - public MapStorage mapStorage; - public VillageCollection villageCollectionObj; - protected final VillageSiege villageSiegeObj = new VillageSiege(this); - public final Profiler theProfiler; - private final Vec3Pool vecPool = new Vec3Pool(300, 2000); - private final Calendar theCalendar = Calendar.getInstance(); - protected Scoreboard worldScoreboard = new Scoreboard(); - public boolean isRemote; - protected TIntByteMap activeChunkSet = new TIntByteHashMap(512, 0.75F, 0, Byte.MAX_VALUE);//XXX - private int ambientTickCountdown; - protected boolean spawnHostileMobs; - protected boolean spawnPeacefulMobs; - private ArrayList collidingBoundingBoxes; - private boolean field_147481_N; - int[] lightUpdateBlockList; - private static final String __OBFID = "CL_00000140"; - - public BiomeGenBase getBiomeGenForCoords(final int par1, final int par2) - { - return provider.getBiomeGenForCoords(par1, par2); - } - - public BiomeGenBase getBiomeGenForCoordsBody(final int par1, final int par2) - { - if (this.blockExists(par1, 0, par2)) - { - Chunk chunk = this.getChunkFromBlockCoords(par1, par2); - - try - { - return chunk.getBiomeGenForWorldCoords(par1 & 15, par2 & 15, this.provider.worldChunkMgr); - } - catch (Throwable throwable) - { - CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Getting biome"); - CrashReportCategory crashreportcategory = crashreport.makeCategory("Coordinates of biome request"); - crashreportcategory.addCrashSectionCallable("Location", new Callable() - { - private static final String __OBFID = "CL_00000141"; - public String call() - { - return CrashReportCategory.getLocationInfo(par1, 0, par2); - } - }); - throw new ReportedException(crashreport); - } - } - else - { - return this.provider.worldChunkMgr.getBiomeGenAt(par1, par2); - } - } - - public WorldChunkManager getWorldChunkManager() - { - return this.provider.worldChunkMgr; - } - - @SideOnly(Side.CLIENT) - public World(ISaveHandler p_i45368_1_, String p_i45368_2_, WorldProvider p_i45368_3_, WorldSettings p_i45368_4_, Profiler p_i45368_5_) - { - this.ambientTickCountdown = this.rand.nextInt(12000); - this.spawnHostileMobs = true; - this.spawnPeacefulMobs = true; - this.collidingBoundingBoxes = new ArrayList(); - this.lightUpdateBlockList = new int[32768]; - this.saveHandler = p_i45368_1_; - this.theProfiler = p_i45368_5_; - this.worldInfo = new WorldInfo(p_i45368_4_, p_i45368_2_); - this.provider = p_i45368_3_; - perWorldStorage = new MapStorage((ISaveHandler)null); - } - - // Broken up so that the WorldClient gets the chance to set the mapstorage object before the dimension initializes - @SideOnly(Side.CLIENT) - protected void finishSetup() - { - VillageCollection villagecollection = (VillageCollection)this.mapStorage.loadData(VillageCollection.class, "villages"); - - if (villagecollection == null) - { - this.villageCollectionObj = new VillageCollection(this); - this.mapStorage.setData("villages", this.villageCollectionObj); - } - else - { - this.villageCollectionObj = villagecollection; - this.villageCollectionObj.func_82566_a(this); - } - - // Guarantee the dimension ID was not reset by the provider - int providerDim = this.provider.dimensionId; - this.provider.registerWorld(this); - this.provider.dimensionId = providerDim; - this.chunkProvider = this.createChunkProvider(); - this.calculateInitialSkylight(); - this.calculateInitialWeather(); - } - - public World(ISaveHandler p_i45369_1_, String p_i45369_2_, WorldSettings p_i45369_3_, WorldProvider p_i45369_4_, Profiler p_i45369_5_) - { - this.ambientTickCountdown = this.rand.nextInt(12000); - this.spawnHostileMobs = true; - this.spawnPeacefulMobs = true; - this.collidingBoundingBoxes = new ArrayList(); - this.lightUpdateBlockList = new int[32768]; - this.saveHandler = p_i45369_1_; - this.theProfiler = p_i45369_5_; - this.mapStorage = getMapStorage(p_i45369_1_); - this.worldInfo = p_i45369_1_.loadWorldInfo(); - - if (p_i45369_4_ != null) - { - this.provider = p_i45369_4_; - } - else if (this.worldInfo != null && this.worldInfo.getVanillaDimension() != 0) - { - this.provider = WorldProvider.getProviderForDimension(this.worldInfo.getVanillaDimension()); - } - else - { - this.provider = WorldProvider.getProviderForDimension(0); - } - - if (this.worldInfo == null) - { - this.worldInfo = new WorldInfo(p_i45369_3_, p_i45369_2_); - } - else - { - this.worldInfo.setWorldName(p_i45369_2_); - } - - this.provider.registerWorld(this); - this.chunkProvider = this.createChunkProvider(); - - if (this instanceof WorldServer) - { - this.perWorldStorage = new MapStorage(new WorldSpecificSaveHandler((WorldServer)this, p_i45369_1_)); - } - else - { - this.perWorldStorage = new MapStorage((ISaveHandler)null); - } - - if (!this.worldInfo.isInitialized()) - { - try - { - this.initialize(p_i45369_3_); - } - catch (Throwable throwable1) - { - CrashReport crashreport = CrashReport.makeCrashReport(throwable1, "Exception initializing level"); - - try - { - this.addWorldInfoToCrashReport(crashreport); - } - catch (Throwable throwable) - { - ; - } - - throw new ReportedException(crashreport); - } - - this.worldInfo.setServerInitialized(true); - } - - VillageCollection villagecollection = (VillageCollection)this.perWorldStorage.loadData(VillageCollection.class, "villages"); - - if (villagecollection == null) - { - this.villageCollectionObj = new VillageCollection(this); - this.perWorldStorage.setData("villages", this.villageCollectionObj); - } - else - { - this.villageCollectionObj = villagecollection; - this.villageCollectionObj.func_82566_a(this); - } - - this.calculateInitialSkylight(); - this.calculateInitialWeather(); - } - - private static MapStorage s_mapStorage; - private static ISaveHandler s_savehandler; - //Provides a solution for different worlds getting different copies of the same data, potentially rewriting the data or causing race conditions/stale data - //Buildcraft has suffered from the issue this fixes. If you load the same data from two different worlds they can get two different copies of the same object, thus the last saved gets final say. - private MapStorage getMapStorage(ISaveHandler savehandler) - { - if (s_savehandler != savehandler || s_mapStorage == null) - { - s_mapStorage = new MapStorage(savehandler); - s_savehandler = savehandler; - } - return s_mapStorage; - } - - protected abstract IChunkProvider createChunkProvider(); - - protected void initialize(WorldSettings par1WorldSettings) - { - this.worldInfo.setServerInitialized(true); - } - - @SideOnly(Side.CLIENT) - public void setSpawnLocation() - { - this.setSpawnLocation(8, 64, 8); - } - - public Block getTopBlock(int p_147474_1_, int p_147474_2_) - { - int k; - - for (k = 63; !this.isAirBlock(p_147474_1_, k + 1, p_147474_2_); ++k) - { - ; - } - - return this.getBlock(p_147474_1_, k, p_147474_2_); - } - - public Block getBlock(int p_147439_1_, int p_147439_2_, int p_147439_3_) - { - if (p_147439_1_ >= -MAX_BLOCK_COORD && p_147439_3_ >= -MAX_BLOCK_COORD && p_147439_1_ < MAX_BLOCK_COORD && p_147439_3_ < MAX_BLOCK_COORD && p_147439_2_ >= 0 && p_147439_2_ < 256) - { - Chunk chunk = null; - - try - { - chunk = this.getChunkFromChunkCoords(p_147439_1_ >> 4, p_147439_3_ >> 4); - return chunk.getBlock(p_147439_1_ & 15, p_147439_2_, p_147439_3_ & 15); - } - catch (Throwable throwable) - { - CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Exception getting block type in world"); - CrashReportCategory crashreportcategory = crashreport.makeCategory("Requested block coordinates"); - crashreportcategory.addCrashSection("Found chunk", Boolean.valueOf(chunk == null)); - crashreportcategory.addCrashSection("Location", CrashReportCategory.getLocationInfo(p_147439_1_, p_147439_2_, p_147439_3_)); - throw new ReportedException(crashreport); - } - } - else - { - return Blocks.air; - } - } - - public boolean isAirBlock(int p_147437_1_, int p_147437_2_, int p_147437_3_) - { - Block block = this.getBlock(p_147437_1_, p_147437_2_, p_147437_3_); - return block.isAir(this, p_147437_1_, p_147437_2_, p_147437_3_); - } - - public boolean blockExists(int par1, int par2, int par3) - { - return par2 >= 0 && par2 < 256 ? this.chunkExists(par1 >> 4, par3 >> 4) : false; - } - - public boolean doChunksNearChunkExist(int par1, int par2, int par3, int par4) - { - return this.checkChunksExist(par1 - par4, par2 - par4, par3 - par4, par1 + par4, par2 + par4, par3 + par4); - } - - public boolean checkChunksExist(int par1, int par2, int par3, int par4, int par5, int par6) - { - if (par5 >= 0 && par2 < 256) - { - par1 >>= 4; - par3 >>= 4; - par4 >>= 4; - par6 >>= 4; - - for (int k1 = par1; k1 <= par4; ++k1) - { - for (int l1 = par3; l1 <= par6; ++l1) - { - if (!this.chunkExists(k1, l1)) - { - return false; - } - } - } - - return true; - } - else - { - return false; - } - } - - public boolean chunkExists(int par1, int par2) - { - return this.chunkProvider.chunkExists(par1, par2); - } - - public Chunk getChunkFromBlockCoords(int par1, int par2) - { - return this.getChunkFromChunkCoords(par1 >> 4, par2 >> 4); - } - - public Chunk getChunkFromChunkCoords(int par1, int par2) - { - return this.chunkProvider.provideChunk(par1, par2); - } - - public boolean setBlock(int p_147465_1_, int p_147465_2_, int p_147465_3_, Block p_147465_4_, int p_147465_5_, int p_147465_6_) - { - if (p_147465_1_ >= -MAX_BLOCK_COORD && p_147465_3_ >= -MAX_BLOCK_COORD && p_147465_1_ < MAX_BLOCK_COORD && p_147465_3_ < MAX_BLOCK_COORD) - { - if (p_147465_2_ < 0) - { - return false; - } - else if (p_147465_2_ >= 256) - { - return false; - } - else - { - Chunk chunk = this.getChunkFromChunkCoords(p_147465_1_ >> 4, p_147465_3_ >> 4); - Block block1 = null; - - if ((p_147465_6_ & 1) != 0) - { - block1 = chunk.getBlock(p_147465_1_ & 15, p_147465_2_, p_147465_3_ & 15); - } - - boolean flag = chunk.func_150807_a(p_147465_1_ & 15, p_147465_2_, p_147465_3_ & 15, p_147465_4_, p_147465_5_); - this.theProfiler.startSection("checkLight"); - this.func_147451_t(p_147465_1_, p_147465_2_, p_147465_3_); - this.theProfiler.endSection(); - - if (flag) - { - if ((p_147465_6_ & 2) != 0 && (!this.isRemote || (p_147465_6_ & 4) == 0) && chunk.func_150802_k()) - { - this.markBlockForUpdate(p_147465_1_, p_147465_2_, p_147465_3_); - } - - if (!this.isRemote && (p_147465_6_ & 1) != 0) - { - this.notifyBlockChange(p_147465_1_, p_147465_2_, p_147465_3_, block1); - - if (p_147465_4_.hasComparatorInputOverride()) - { - this.func_147453_f(p_147465_1_, p_147465_2_, p_147465_3_, p_147465_4_); - } - } - } - - return flag; - } - } - else - { - return false; - } - } - - public int getBlockMetadata(int par1, int par2, int par3) - { - if (par1 >= -MAX_BLOCK_COORD && par3 >= -MAX_BLOCK_COORD && par1 < MAX_BLOCK_COORD && par3 < MAX_BLOCK_COORD) - { - if (par2 < 0) - { - return 0; - } - else if (par2 >= 256) - { - return 0; - } - else - { - Chunk chunk = this.getChunkFromChunkCoords(par1 >> 4, par3 >> 4); - par1 &= 15; - par3 &= 15; - return chunk.getBlockMetadata(par1, par2, par3); - } - } - else - { - return 0; - } - } - - public boolean setBlockMetadataWithNotify(int par1, int par2, int par3, int par4, int par5) - { - if (par1 >= -MAX_BLOCK_COORD && par3 >= -MAX_BLOCK_COORD && par1 < MAX_BLOCK_COORD && par3 < MAX_BLOCK_COORD) - { - if (par2 < 0) - { - return false; - } - else if (par2 >= 256) - { - return false; - } - else - { - Chunk chunk = this.getChunkFromChunkCoords(par1 >> 4, par3 >> 4); - int j1 = par1 & 15; - int k1 = par3 & 15; - boolean flag = chunk.setBlockMetadata(j1, par2, k1, par4); - - if (flag) - { - Block block = chunk.getBlock(j1, par2, k1); - - if ((par5 & 2) != 0 && (!this.isRemote || (par5 & 4) == 0) && chunk.func_150802_k()) - { - this.markBlockForUpdate(par1, par2, par3); - } - - if (!this.isRemote && (par5 & 1) != 0) - { - this.notifyBlockChange(par1, par2, par3, block); - - if (block.hasComparatorInputOverride()) - { - this.func_147453_f(par1, par2, par3, block); - } - } - } - - return flag; - } - } - else - { - return false; - } - } - - public boolean setBlockToAir(int p_147468_1_, int p_147468_2_, int p_147468_3_) - { - return this.setBlock(p_147468_1_, p_147468_2_, p_147468_3_, Blocks.air, 0, 3); - } - - public boolean func_147480_a(int p_147480_1_, int p_147480_2_, int p_147480_3_, boolean p_147480_4_) - { - Block block = this.getBlock(p_147480_1_, p_147480_2_, p_147480_3_); - - if (block.getMaterial() == Material.air) - { - return false; - } - else - { - int l = this.getBlockMetadata(p_147480_1_, p_147480_2_, p_147480_3_); - this.playAuxSFX(2001, p_147480_1_, p_147480_2_, p_147480_3_, Block.getIdFromBlock(block) + (l << 12)); - - if (p_147480_4_) - { - block.dropBlockAsItem(this, p_147480_1_, p_147480_2_, p_147480_3_, l, 0); - } - - return this.setBlock(p_147480_1_, p_147480_2_, p_147480_3_, Blocks.air, 0, 3); - } - } - - public boolean setBlock(int p_147449_1_, int p_147449_2_, int p_147449_3_, Block p_147449_4_) - { - return this.setBlock(p_147449_1_, p_147449_2_, p_147449_3_, p_147449_4_, 0, 3); - } - - public void markBlockForUpdate(int p_147471_1_, int p_147471_2_, int p_147471_3_) - { - for (int l = 0; l < this.worldAccesses.size(); ++l) - { - ((IWorldAccess)this.worldAccesses.get(l)).markBlockForUpdate(p_147471_1_, p_147471_2_, p_147471_3_); - } - } - - public void notifyBlockChange(int p_147444_1_, int p_147444_2_, int p_147444_3_, Block p_147444_4_) - { - this.notifyBlocksOfNeighborChange(p_147444_1_, p_147444_2_, p_147444_3_, p_147444_4_); - } - - public void markBlocksDirtyVertical(int par1, int par2, int par3, int par4) - { - int i1; - - if (par3 > par4) - { - i1 = par4; - par4 = par3; - par3 = i1; - } - - if (!this.provider.hasNoSky) - { - for (i1 = par3; i1 <= par4; ++i1) - { - this.updateLightByType(EnumSkyBlock.Sky, par1, i1, par2); - } - } - - this.markBlockRangeForRenderUpdate(par1, par3, par2, par1, par4, par2); - } - - public void markBlockRangeForRenderUpdate(int p_147458_1_, int p_147458_2_, int p_147458_3_, int p_147458_4_, int p_147458_5_, int p_147458_6_) - { - for (int k1 = 0; k1 < this.worldAccesses.size(); ++k1) - { - ((IWorldAccess)this.worldAccesses.get(k1)).markBlockRangeForRenderUpdate(p_147458_1_, p_147458_2_, p_147458_3_, p_147458_4_, p_147458_5_, p_147458_6_); - } - } - - public void notifyBlocksOfNeighborChange(int p_147459_1_, int p_147459_2_, int p_147459_3_, Block p_147459_4_) - { - this.notifyBlockOfNeighborChange(p_147459_1_ - 1, p_147459_2_, p_147459_3_, p_147459_4_); - this.notifyBlockOfNeighborChange(p_147459_1_ + 1, p_147459_2_, p_147459_3_, p_147459_4_); - this.notifyBlockOfNeighborChange(p_147459_1_, p_147459_2_ - 1, p_147459_3_, p_147459_4_); - this.notifyBlockOfNeighborChange(p_147459_1_, p_147459_2_ + 1, p_147459_3_, p_147459_4_); - this.notifyBlockOfNeighborChange(p_147459_1_, p_147459_2_, p_147459_3_ - 1, p_147459_4_); - this.notifyBlockOfNeighborChange(p_147459_1_, p_147459_2_, p_147459_3_ + 1, p_147459_4_); - } - - public void notifyBlocksOfNeighborChange(int p_147441_1_, int p_147441_2_, int p_147441_3_, Block p_147441_4_, int p_147441_5_) - { - if (p_147441_5_ != 4) - { - this.notifyBlockOfNeighborChange(p_147441_1_ - 1, p_147441_2_, p_147441_3_, p_147441_4_); - } - - if (p_147441_5_ != 5) - { - this.notifyBlockOfNeighborChange(p_147441_1_ + 1, p_147441_2_, p_147441_3_, p_147441_4_); - } - - if (p_147441_5_ != 0) - { - this.notifyBlockOfNeighborChange(p_147441_1_, p_147441_2_ - 1, p_147441_3_, p_147441_4_); - } - - if (p_147441_5_ != 1) - { - this.notifyBlockOfNeighborChange(p_147441_1_, p_147441_2_ + 1, p_147441_3_, p_147441_4_); - } - - if (p_147441_5_ != 2) - { - this.notifyBlockOfNeighborChange(p_147441_1_, p_147441_2_, p_147441_3_ - 1, p_147441_4_); - } - - if (p_147441_5_ != 3) - { - this.notifyBlockOfNeighborChange(p_147441_1_, p_147441_2_, p_147441_3_ + 1, p_147441_4_); - } - } - - public void notifyBlockOfNeighborChange(int p_147460_1_, int p_147460_2_, int p_147460_3_, final Block p_147460_4_) - { - if (!this.isRemote) - { - Block block = this.getBlock(p_147460_1_, p_147460_2_, p_147460_3_); - - try - { - block.onNeighborBlockChange(this, p_147460_1_, p_147460_2_, p_147460_3_, p_147460_4_); - } - catch (Throwable throwable1) - { - CrashReport crashreport = CrashReport.makeCrashReport(throwable1, "Exception while updating neighbours"); - CrashReportCategory crashreportcategory = crashreport.makeCategory("Block being updated"); - int l; - - try - { - l = this.getBlockMetadata(p_147460_1_, p_147460_2_, p_147460_3_); - } - catch (Throwable throwable) - { - l = -1; - } - - crashreportcategory.addCrashSectionCallable("Source block type", new Callable() - { - private static final String __OBFID = "CL_00000142"; - public String call() - { - try - { - return String.format("ID #%d (%s // %s)", new Object[] {Integer.valueOf(Block.getIdFromBlock(p_147460_4_)), p_147460_4_.getUnlocalizedName(), p_147460_4_.getClass().getCanonicalName()}); - } - catch (Throwable throwable2) - { - return "ID #" + Block.getIdFromBlock(p_147460_4_); - } - } - }); - CrashReportCategory.func_147153_a(crashreportcategory, p_147460_1_, p_147460_2_, p_147460_3_, block, l); - throw new ReportedException(crashreport); - } - } - } - - public boolean isBlockTickScheduledThisTick(int p_147477_1_, int p_147477_2_, int p_147477_3_, Block p_147477_4_) - { - return false; - } - - public boolean canBlockSeeTheSky(int par1, int par2, int par3) - { - return this.getChunkFromChunkCoords(par1 >> 4, par3 >> 4).canBlockSeeTheSky(par1 & 15, par2, par3 & 15); - } - - public int getFullBlockLightValue(int par1, int par2, int par3) - { - if (par2 < 0) - { - return 0; - } - else - { - if (par2 >= 256) - { - par2 = 255; - } - - return this.getChunkFromChunkCoords(par1 >> 4, par3 >> 4).getBlockLightValue(par1 & 15, par2, par3 & 15, 0); - } - } - - public int getBlockLightValue(int par1, int par2, int par3) - { - return this.getBlockLightValue_do(par1, par2, par3, true); - } - - public int getBlockLightValue_do(int par1, int par2, int par3, boolean par4) - { - if (par1 >= -MAX_BLOCK_COORD && par3 >= -MAX_BLOCK_COORD && par1 < MAX_BLOCK_COORD && par3 < MAX_BLOCK_COORD) - { - if (par4 && this.getBlock(par1, par2, par3).getUseNeighborBrightness()) - { - int l1 = this.getBlockLightValue_do(par1, par2 + 1, par3, false); - int l = this.getBlockLightValue_do(par1 + 1, par2, par3, false); - int i1 = this.getBlockLightValue_do(par1 - 1, par2, par3, false); - int j1 = this.getBlockLightValue_do(par1, par2, par3 + 1, false); - int k1 = this.getBlockLightValue_do(par1, par2, par3 - 1, false); - - if (l > l1) - { - l1 = l; - } - - if (i1 > l1) - { - l1 = i1; - } - - if (j1 > l1) - { - l1 = j1; - } - - if (k1 > l1) - { - l1 = k1; - } - - return l1; - } - else if (par2 < 0) - { - return 0; - } - else - { - if (par2 >= 256) - { - par2 = 255; - } - - Chunk chunk = this.getChunkFromChunkCoords(par1 >> 4, par3 >> 4); - par1 &= 15; - par3 &= 15; - return chunk.getBlockLightValue(par1, par2, par3, this.skylightSubtracted); - } - } - else - { - return 15; - } - } - - public int getHeightValue(int par1, int par2) - { - if (par1 >= -MAX_BLOCK_COORD && par2 >= -MAX_BLOCK_COORD && par1 < MAX_BLOCK_COORD && par2 < MAX_BLOCK_COORD) - { - if (!this.chunkExists(par1 >> 4, par2 >> 4)) - { - return 0; - } - else - { - Chunk chunk = this.getChunkFromChunkCoords(par1 >> 4, par2 >> 4); - return chunk.getHeightValue(par1 & 15, par2 & 15); - } - } - else - { - return 64; - } - } - - public int getChunkHeightMapMinimum(int par1, int par2) - { - if (par1 >= -MAX_BLOCK_COORD && par2 >= -MAX_BLOCK_COORD && par1 < MAX_BLOCK_COORD && par2 < MAX_BLOCK_COORD) - { - if (!this.chunkExists(par1 >> 4, par2 >> 4)) - { - return 0; - } - else - { - Chunk chunk = this.getChunkFromChunkCoords(par1 >> 4, par2 >> 4); - return chunk.heightMapMinimum; - } - } - else - { - return 64; - } - } - - @SideOnly(Side.CLIENT) - public int getSkyBlockTypeBrightness(EnumSkyBlock par1EnumSkyBlock, int par2, int par3, int par4) - { - if (this.provider.hasNoSky && par1EnumSkyBlock == EnumSkyBlock.Sky) - { - return 0; - } - else - { - if (par3 < 0) - { - par3 = 0; - } - - if (par3 >= 256) - { - return par1EnumSkyBlock.defaultLightValue; - } - else if (par2 >= -MAX_BLOCK_COORD && par4 >= -MAX_BLOCK_COORD && par2 < MAX_BLOCK_COORD && par4 < MAX_BLOCK_COORD) - { - int l = par2 >> 4; - int i1 = par4 >> 4; - - if (!this.chunkExists(l, i1)) - { - return par1EnumSkyBlock.defaultLightValue; - } - else if (this.getBlock(par2, par3, par4).getUseNeighborBrightness()) - { - int j2 = this.getSavedLightValue(par1EnumSkyBlock, par2, par3 + 1, par4); - int j1 = this.getSavedLightValue(par1EnumSkyBlock, par2 + 1, par3, par4); - int k1 = this.getSavedLightValue(par1EnumSkyBlock, par2 - 1, par3, par4); - int l1 = this.getSavedLightValue(par1EnumSkyBlock, par2, par3, par4 + 1); - int i2 = this.getSavedLightValue(par1EnumSkyBlock, par2, par3, par4 - 1); - - if (j1 > j2) - { - j2 = j1; - } - - if (k1 > j2) - { - j2 = k1; - } - - if (l1 > j2) - { - j2 = l1; - } - - if (i2 > j2) - { - j2 = i2; - } - - return j2; - } - else - { - Chunk chunk = this.getChunkFromChunkCoords(l, i1); - return chunk.getSavedLightValue(par1EnumSkyBlock, par2 & 15, par3, par4 & 15); - } - } - else - { - return par1EnumSkyBlock.defaultLightValue; - } - } - } - - public int getSavedLightValue(EnumSkyBlock par1EnumSkyBlock, int par2, int par3, int par4) - { - if (par3 < 0) - { - par3 = 0; - } - - if (par3 >= 256) - { - par3 = 255; - } - - if (par2 >= -MAX_BLOCK_COORD && par4 >= -MAX_BLOCK_COORD && par2 < MAX_BLOCK_COORD && par4 < MAX_BLOCK_COORD) - { - int l = par2 >> 4; - int i1 = par4 >> 4; - - if (!this.chunkExists(l, i1)) - { - return par1EnumSkyBlock.defaultLightValue; - } - else - { - Chunk chunk = this.getChunkFromChunkCoords(l, i1); - return chunk.getSavedLightValue(par1EnumSkyBlock, par2 & 15, par3, par4 & 15); - } - } - else - { - return par1EnumSkyBlock.defaultLightValue; - } - } - - public void setLightValue(EnumSkyBlock par1EnumSkyBlock, int par2, int par3, int par4, int par5) - { - if (par2 >= -MAX_BLOCK_COORD && par4 >= -MAX_BLOCK_COORD && par2 < MAX_BLOCK_COORD && par4 < MAX_BLOCK_COORD) - { - if (par3 >= 0) - { - if (par3 < 256) - { - if (this.chunkExists(par2 >> 4, par4 >> 4)) - { - Chunk chunk = this.getChunkFromChunkCoords(par2 >> 4, par4 >> 4); - chunk.setLightValue(par1EnumSkyBlock, par2 & 15, par3, par4 & 15, par5); - - for (int i1 = 0; i1 < this.worldAccesses.size(); ++i1) - { - ((IWorldAccess)this.worldAccesses.get(i1)).markBlockForRenderUpdate(par2, par3, par4); - } - } - } - } - } - } - - public void func_147479_m(int p_147479_1_, int p_147479_2_, int p_147479_3_) - { - for (int l = 0; l < this.worldAccesses.size(); ++l) - { - ((IWorldAccess)this.worldAccesses.get(l)).markBlockForRenderUpdate(p_147479_1_, p_147479_2_, p_147479_3_); - } - } - - @SideOnly(Side.CLIENT) - public int getLightBrightnessForSkyBlocks(int par1, int par2, int par3, int par4) - { - int i1 = this.getSkyBlockTypeBrightness(EnumSkyBlock.Sky, par1, par2, par3); - int j1 = this.getSkyBlockTypeBrightness(EnumSkyBlock.Block, par1, par2, par3); - - if (j1 < par4) - { - j1 = par4; - } - - return i1 << 20 | j1 << 4; - } - - public float getLightBrightness(int par1, int par2, int par3) - { - return this.provider.lightBrightnessTable[this.getBlockLightValue(par1, par2, par3)]; - } - - public boolean isDaytime() - { - return provider.isDaytime(); - } - - public MovingObjectPosition rayTraceBlocks(Vec3 par1Vec3, Vec3 par2Vec3) - { - return this.func_147447_a(par1Vec3, par2Vec3, false, false, false); - } - - public MovingObjectPosition rayTraceBlocks(Vec3 par1Vec3, Vec3 par2Vec3, boolean par3) - { - return this.func_147447_a(par1Vec3, par2Vec3, par3, false, false); - } - - public MovingObjectPosition func_147447_a(Vec3 p_147447_1_, Vec3 p_147447_2_, boolean p_147447_3_, boolean p_147447_4_, boolean p_147447_5_) - { - if (!Double.isNaN(p_147447_1_.xCoord) && !Double.isNaN(p_147447_1_.yCoord) && !Double.isNaN(p_147447_1_.zCoord)) - { - if (!Double.isNaN(p_147447_2_.xCoord) && !Double.isNaN(p_147447_2_.yCoord) && !Double.isNaN(p_147447_2_.zCoord)) - { - int i = MathHelper.floor_double(p_147447_2_.xCoord); - int j = MathHelper.floor_double(p_147447_2_.yCoord); - int k = MathHelper.floor_double(p_147447_2_.zCoord); - int l = MathHelper.floor_double(p_147447_1_.xCoord); - int i1 = MathHelper.floor_double(p_147447_1_.yCoord); - int j1 = MathHelper.floor_double(p_147447_1_.zCoord); - Block block = this.getBlock(l, i1, j1); - int k1 = this.getBlockMetadata(l, i1, j1); - - if ((!p_147447_4_ || block.getCollisionBoundingBoxFromPool(this, l, i1, j1) != null) && block.canCollideCheck(k1, p_147447_3_)) - { - MovingObjectPosition movingobjectposition = block.collisionRayTrace(this, l, i1, j1, p_147447_1_, p_147447_2_); - - if (movingobjectposition != null) - { - return movingobjectposition; - } - } - - MovingObjectPosition movingobjectposition2 = null; - k1 = 200; - - while (k1-- >= 0) - { - if (Double.isNaN(p_147447_1_.xCoord) || Double.isNaN(p_147447_1_.yCoord) || Double.isNaN(p_147447_1_.zCoord)) - { - return null; - } - - if (l == i && i1 == j && j1 == k) - { - return p_147447_5_ ? movingobjectposition2 : null; - } - - boolean flag6 = true; - boolean flag3 = true; - boolean flag4 = true; - double d0 = 999.0D; - double d1 = 999.0D; - double d2 = 999.0D; - - if (i > l) - { - d0 = (double)l + 1.0D; - } - else if (i < l) - { - d0 = (double)l + 0.0D; - } - else - { - flag6 = false; - } - - if (j > i1) - { - d1 = (double)i1 + 1.0D; - } - else if (j < i1) - { - d1 = (double)i1 + 0.0D; - } - else - { - flag3 = false; - } - - if (k > j1) - { - d2 = (double)j1 + 1.0D; - } - else if (k < j1) - { - d2 = (double)j1 + 0.0D; - } - else - { - flag4 = false; - } - - double d3 = 999.0D; - double d4 = 999.0D; - double d5 = 999.0D; - double d6 = p_147447_2_.xCoord - p_147447_1_.xCoord; - double d7 = p_147447_2_.yCoord - p_147447_1_.yCoord; - double d8 = p_147447_2_.zCoord - p_147447_1_.zCoord; - - if (flag6) - { - d3 = (d0 - p_147447_1_.xCoord) / d6; - } - - if (flag3) - { - d4 = (d1 - p_147447_1_.yCoord) / d7; - } - - if (flag4) - { - d5 = (d2 - p_147447_1_.zCoord) / d8; - } - - boolean flag5 = false; - byte b0; - - if (d3 < d4 && d3 < d5) - { - if (i > l) - { - b0 = 4; - } - else - { - b0 = 5; - } - - p_147447_1_.xCoord = d0; - p_147447_1_.yCoord += d7 * d3; - p_147447_1_.zCoord += d8 * d3; - } - else if (d4 < d5) - { - if (j > i1) - { - b0 = 0; - } - else - { - b0 = 1; - } - - p_147447_1_.xCoord += d6 * d4; - p_147447_1_.yCoord = d1; - p_147447_1_.zCoord += d8 * d4; - } - else - { - if (k > j1) - { - b0 = 2; - } - else - { - b0 = 3; - } - - p_147447_1_.xCoord += d6 * d5; - p_147447_1_.yCoord += d7 * d5; - p_147447_1_.zCoord = d2; - } - - Vec3 vec32 = this.getWorldVec3Pool().getVecFromPool(p_147447_1_.xCoord, p_147447_1_.yCoord, p_147447_1_.zCoord); - l = (int)(vec32.xCoord = (double)MathHelper.floor_double(p_147447_1_.xCoord)); - - if (b0 == 5) - { - --l; - ++vec32.xCoord; - } - - i1 = (int)(vec32.yCoord = (double)MathHelper.floor_double(p_147447_1_.yCoord)); - - if (b0 == 1) - { - --i1; - ++vec32.yCoord; - } - - j1 = (int)(vec32.zCoord = (double)MathHelper.floor_double(p_147447_1_.zCoord)); - - if (b0 == 3) - { - --j1; - ++vec32.zCoord; - } - - Block block1 = this.getBlock(l, i1, j1); - int l1 = this.getBlockMetadata(l, i1, j1); - - if (!p_147447_4_ || block1.getCollisionBoundingBoxFromPool(this, l, i1, j1) != null) - { - if (block1.canCollideCheck(l1, p_147447_3_)) - { - MovingObjectPosition movingobjectposition1 = block1.collisionRayTrace(this, l, i1, j1, p_147447_1_, p_147447_2_); - - if (movingobjectposition1 != null) - { - return movingobjectposition1; - } - } - else - { - movingobjectposition2 = new MovingObjectPosition(l, i1, j1, b0, p_147447_1_, false); - } - } - } - - return p_147447_5_ ? movingobjectposition2 : null; - } - else - { - return null; - } - } - else - { - return null; - } - } - - public void playSoundAtEntity(Entity par1Entity, String par2Str, float par3, float par4) - { - PlaySoundAtEntityEvent event = new PlaySoundAtEntityEvent(par1Entity, par2Str, par3, par4); - if (MinecraftForge.EVENT_BUS.post(event)) - { - return; - } - par2Str = event.name; - for (int i = 0; i < this.worldAccesses.size(); ++i) - { - ((IWorldAccess)this.worldAccesses.get(i)).playSound(par2Str, par1Entity.posX, par1Entity.posY - (double)par1Entity.yOffset, par1Entity.posZ, par3, par4); - } - } - - public void playSoundToNearExcept(EntityPlayer par1EntityPlayer, String par2Str, float par3, float par4) - { - PlaySoundAtEntityEvent event = new PlaySoundAtEntityEvent(par1EntityPlayer, par2Str, par3, par4); - if (MinecraftForge.EVENT_BUS.post(event)) - { - return; - } - par2Str = event.name; - for (int i = 0; i < this.worldAccesses.size(); ++i) - { - ((IWorldAccess)this.worldAccesses.get(i)).playSoundToNearExcept(par1EntityPlayer, par2Str, par1EntityPlayer.posX, par1EntityPlayer.posY - (double)par1EntityPlayer.yOffset, par1EntityPlayer.posZ, par3, par4); - } - } - - public void playSoundEffect(double par1, double par3, double par5, String par7Str, float par8, float par9) - { - for (int i = 0; i < this.worldAccesses.size(); ++i) - { - ((IWorldAccess)this.worldAccesses.get(i)).playSound(par7Str, par1, par3, par5, par8, par9); - } - } - - public void playSound(double par1, double par3, double par5, String par7Str, float par8, float par9, boolean par10) {} - - public void playRecord(String par1Str, int par2, int par3, int par4) - { - for (int l = 0; l < this.worldAccesses.size(); ++l) - { - ((IWorldAccess)this.worldAccesses.get(l)).playRecord(par1Str, par2, par3, par4); - } - } - - public void spawnParticle(String par1Str, double par2, double par4, double par6, double par8, double par10, double par12) - { - for (int i = 0; i < this.worldAccesses.size(); ++i) - { - ((IWorldAccess)this.worldAccesses.get(i)).spawnParticle(par1Str, par2, par4, par6, par8, par10, par12); - } - } - - public boolean addWeatherEffect(Entity par1Entity) - { - this.weatherEffects.add(par1Entity); - return true; - } - - public boolean spawnEntityInWorld(Entity par1Entity) - { - int i = MathHelper.floor_double(par1Entity.posX / 16.0D); - int j = MathHelper.floor_double(par1Entity.posZ / 16.0D); - boolean flag = par1Entity.forceSpawn; - - if (par1Entity instanceof EntityPlayer) - { - flag = true; - } - - if (!flag && !this.chunkExists(i, j)) - { - return false; - } - else - { - if (par1Entity instanceof EntityPlayer) - { - EntityPlayer entityplayer = (EntityPlayer)par1Entity; - this.playerEntities.add(entityplayer); - this.updateAllPlayersSleepingFlag(); - } - if (MinecraftForge.EVENT_BUS.post(new EntityJoinWorldEvent(par1Entity, this)) && !flag) return false; - - this.getChunkFromChunkCoords(i, j).addEntity(par1Entity); - this.loadedEntityList.add(par1Entity); - this.onEntityAdded(par1Entity); - return true; - } - } - - public void onEntityAdded(Entity par1Entity) - { - for (int i = 0; i < this.worldAccesses.size(); ++i) - { - ((IWorldAccess)this.worldAccesses.get(i)).onEntityCreate(par1Entity); - } - } - - public void onEntityRemoved(Entity par1Entity) - { - for (int i = 0; i < this.worldAccesses.size(); ++i) - { - ((IWorldAccess)this.worldAccesses.get(i)).onEntityDestroy(par1Entity); - } - } - - public void removeEntity(Entity par1Entity) - { - if (par1Entity.riddenByEntity != null) - { - par1Entity.riddenByEntity.mountEntity((Entity)null); - } - - if (par1Entity.ridingEntity != null) - { - par1Entity.mountEntity((Entity)null); - } - - par1Entity.setDead(); - - if (par1Entity instanceof EntityPlayer) - { - this.playerEntities.remove(par1Entity); - this.updateAllPlayersSleepingFlag(); - } - } - - public void removePlayerEntityDangerously(Entity par1Entity) - { - par1Entity.setDead(); - - if (par1Entity instanceof EntityPlayer) - { - this.playerEntities.remove(par1Entity); - this.updateAllPlayersSleepingFlag(); - } - - int i = par1Entity.chunkCoordX; - int j = par1Entity.chunkCoordZ; - - if (par1Entity.addedToChunk && this.chunkExists(i, j)) - { - this.getChunkFromChunkCoords(i, j).removeEntity(par1Entity); - } - - this.loadedEntityList.remove(par1Entity); - this.onEntityRemoved(par1Entity); - } - - public void addWorldAccess(IWorldAccess par1IWorldAccess) - { - this.worldAccesses.add(par1IWorldAccess); - } - - public List getCollidingBoundingBoxes(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB) - { - this.collidingBoundingBoxes.clear(); - int i = MathHelper.floor_double(par2AxisAlignedBB.minX); - int j = MathHelper.floor_double(par2AxisAlignedBB.maxX + 1.0D); - int k = MathHelper.floor_double(par2AxisAlignedBB.minY); - int l = MathHelper.floor_double(par2AxisAlignedBB.maxY + 1.0D); - int i1 = MathHelper.floor_double(par2AxisAlignedBB.minZ); - int j1 = MathHelper.floor_double(par2AxisAlignedBB.maxZ + 1.0D); - - for (int k1 = i; k1 < j; ++k1) - { - for (int l1 = i1; l1 < j1; ++l1) - { - if (this.blockExists(k1, 64, l1)) - { - for (int i2 = k - 1; i2 < l; ++i2) - { - Block block; - - if (k1 >= -MAX_BLOCK_COORD && k1 < MAX_BLOCK_COORD && l1 >= -MAX_BLOCK_COORD && l1 < MAX_BLOCK_COORD) - { - block = this.getBlock(k1, i2, l1); - } - else - { - block = Blocks.stone; - } - - block.addCollisionBoxesToList(this, k1, i2, l1, par2AxisAlignedBB, this.collidingBoundingBoxes, par1Entity); - } - } - } - } - - double d0 = 0.25D; - List list = this.getEntitiesWithinAABBExcludingEntity(par1Entity, par2AxisAlignedBB.expand(d0, d0, d0)); - - for (int j2 = 0; j2 < list.size(); ++j2) - { - AxisAlignedBB axisalignedbb1 = ((Entity)list.get(j2)).getBoundingBox(); - - if (axisalignedbb1 != null && axisalignedbb1.intersectsWith(par2AxisAlignedBB)) - { - this.collidingBoundingBoxes.add(axisalignedbb1); - } - - axisalignedbb1 = par1Entity.getCollisionBox((Entity)list.get(j2)); - - if (axisalignedbb1 != null && axisalignedbb1.intersectsWith(par2AxisAlignedBB)) - { - this.collidingBoundingBoxes.add(axisalignedbb1); - } - } - - return this.collidingBoundingBoxes; - } - - public List func_147461_a(AxisAlignedBB p_147461_1_) - { - this.collidingBoundingBoxes.clear(); - int i = MathHelper.floor_double(p_147461_1_.minX); - int j = MathHelper.floor_double(p_147461_1_.maxX + 1.0D); - int k = MathHelper.floor_double(p_147461_1_.minY); - int l = MathHelper.floor_double(p_147461_1_.maxY + 1.0D); - int i1 = MathHelper.floor_double(p_147461_1_.minZ); - int j1 = MathHelper.floor_double(p_147461_1_.maxZ + 1.0D); - - for (int k1 = i; k1 < j; ++k1) - { - for (int l1 = i1; l1 < j1; ++l1) - { - if (this.blockExists(k1, 64, l1)) - { - for (int i2 = k - 1; i2 < l; ++i2) - { - Block block; - - if (k1 >= -MAX_BLOCK_COORD && k1 < MAX_BLOCK_COORD && l1 >= -MAX_BLOCK_COORD && l1 < MAX_BLOCK_COORD) - { - block = this.getBlock(k1, i2, l1); - } - else - { - block = Blocks.bedrock; - } - - block.addCollisionBoxesToList(this, k1, i2, l1, p_147461_1_, this.collidingBoundingBoxes, (Entity)null); - } - } - } - } - - return this.collidingBoundingBoxes; - } - - public int calculateSkylightSubtracted(float par1) - { - float f1 = this.getCelestialAngle(par1); - float f2 = 1.0F - (MathHelper.cos(f1 * (float)Math.PI * 2.0F) * 2.0F + 0.5F); - - if (f2 < 0.0F) - { - f2 = 0.0F; - } - - if (f2 > 1.0F) - { - f2 = 1.0F; - } - - f2 = 1.0F - f2; - f2 = (float)((double)f2 * (1.0D - (double)(this.getRainStrength(par1) * 5.0F) / 16.0D)); - f2 = (float)((double)f2 * (1.0D - (double)(this.getWeightedThunderStrength(par1) * 5.0F) / 16.0D)); - f2 = 1.0F - f2; - return (int)(f2 * 11.0F); - } - - public void removeWorldAccess(IWorldAccess par1IWorldAccess) - { - this.worldAccesses.remove(par1IWorldAccess); - } - - @SideOnly(Side.CLIENT) - public float getSunBrightness(float par1) - { - float f1 = this.getCelestialAngle(par1); - float f2 = 1.0F - (MathHelper.cos(f1 * (float)Math.PI * 2.0F) * 2.0F + 0.2F); - - if (f2 < 0.0F) - { - f2 = 0.0F; - } - - if (f2 > 1.0F) - { - f2 = 1.0F; - } - - f2 = 1.0F - f2; - f2 = (float)((double)f2 * (1.0D - (double)(this.getRainStrength(par1) * 5.0F) / 16.0D)); - f2 = (float)((double)f2 * (1.0D - (double)(this.getWeightedThunderStrength(par1) * 5.0F) / 16.0D)); - return f2 * 0.8F + 0.2F; - } - - @SideOnly(Side.CLIENT) - public Vec3 getSkyColor(Entity par1Entity, float par2) - { - return provider.getSkyColor(par1Entity, par2); - } - - @SideOnly(Side.CLIENT) - public Vec3 getSkyColorBody(Entity par1Entity, float par2) - { - float f1 = this.getCelestialAngle(par2); - float f2 = MathHelper.cos(f1 * (float)Math.PI * 2.0F) * 2.0F + 0.5F; - - if (f2 < 0.0F) - { - f2 = 0.0F; - } - - if (f2 > 1.0F) - { - f2 = 1.0F; - } - - int i = MathHelper.floor_double(par1Entity.posX); - int j = MathHelper.floor_double(par1Entity.posY); - int k = MathHelper.floor_double(par1Entity.posZ); - int l = ForgeHooksClient.getSkyBlendColour(this, i, j, k); - float f4 = (float)(l >> 16 & 255) / 255.0F; - float f5 = (float)(l >> 8 & 255) / 255.0F; - float f6 = (float)(l & 255) / 255.0F; - f4 *= f2; - f5 *= f2; - f6 *= f2; - float f7 = this.getRainStrength(par2); - float f8; - float f9; - - if (f7 > 0.0F) - { - f8 = (f4 * 0.3F + f5 * 0.59F + f6 * 0.11F) * 0.6F; - f9 = 1.0F - f7 * 0.75F; - f4 = f4 * f9 + f8 * (1.0F - f9); - f5 = f5 * f9 + f8 * (1.0F - f9); - f6 = f6 * f9 + f8 * (1.0F - f9); - } - - f8 = this.getWeightedThunderStrength(par2); - - if (f8 > 0.0F) - { - f9 = (f4 * 0.3F + f5 * 0.59F + f6 * 0.11F) * 0.2F; - float f10 = 1.0F - f8 * 0.75F; - f4 = f4 * f10 + f9 * (1.0F - f10); - f5 = f5 * f10 + f9 * (1.0F - f10); - f6 = f6 * f10 + f9 * (1.0F - f10); - } - - if (this.lastLightningBolt > 0) - { - f9 = (float)this.lastLightningBolt - par2; - - if (f9 > 1.0F) - { - f9 = 1.0F; - } - - f9 *= 0.45F; - f4 = f4 * (1.0F - f9) + 0.8F * f9; - f5 = f5 * (1.0F - f9) + 0.8F * f9; - f6 = f6 * (1.0F - f9) + 1.0F * f9; - } - - return this.getWorldVec3Pool().getVecFromPool((double)f4, (double)f5, (double)f6); - } - - public float getCelestialAngle(float par1) - { - return this.provider.calculateCelestialAngle(this.worldInfo.getWorldTime(), par1); - } - - @SideOnly(Side.CLIENT) - public int getMoonPhase() - { - return this.provider.getMoonPhase(this.worldInfo.getWorldTime()); - } - - public float getCurrentMoonPhaseFactor() - { - return WorldProvider.moonPhaseFactors[this.provider.getMoonPhase(this.worldInfo.getWorldTime())]; - } - - public float getCelestialAngleRadians(float par1) - { - float f1 = this.getCelestialAngle(par1); - return f1 * (float)Math.PI * 2.0F; - } - - @SideOnly(Side.CLIENT) - public Vec3 getCloudColour(float par1) - { - return provider.drawClouds(par1); - } - - @SideOnly(Side.CLIENT) - public Vec3 drawCloudsBody(float par1) - { - float f1 = this.getCelestialAngle(par1); - float f2 = MathHelper.cos(f1 * (float)Math.PI * 2.0F) * 2.0F + 0.5F; - - if (f2 < 0.0F) - { - f2 = 0.0F; - } - - if (f2 > 1.0F) - { - f2 = 1.0F; - } - - float f3 = (float)(this.cloudColour >> 16 & 255L) / 255.0F; - float f4 = (float)(this.cloudColour >> 8 & 255L) / 255.0F; - float f5 = (float)(this.cloudColour & 255L) / 255.0F; - float f6 = this.getRainStrength(par1); - float f7; - float f8; - - if (f6 > 0.0F) - { - f7 = (f3 * 0.3F + f4 * 0.59F + f5 * 0.11F) * 0.6F; - f8 = 1.0F - f6 * 0.95F; - f3 = f3 * f8 + f7 * (1.0F - f8); - f4 = f4 * f8 + f7 * (1.0F - f8); - f5 = f5 * f8 + f7 * (1.0F - f8); - } - - f3 *= f2 * 0.9F + 0.1F; - f4 *= f2 * 0.9F + 0.1F; - f5 *= f2 * 0.85F + 0.15F; - f7 = this.getWeightedThunderStrength(par1); - - if (f7 > 0.0F) - { - f8 = (f3 * 0.3F + f4 * 0.59F + f5 * 0.11F) * 0.2F; - float f9 = 1.0F - f7 * 0.95F; - f3 = f3 * f9 + f8 * (1.0F - f9); - f4 = f4 * f9 + f8 * (1.0F - f9); - f5 = f5 * f9 + f8 * (1.0F - f9); - } - - return this.getWorldVec3Pool().getVecFromPool((double)f3, (double)f4, (double)f5); - } - - @SideOnly(Side.CLIENT) - public Vec3 getFogColor(float par1) - { - float f1 = this.getCelestialAngle(par1); - return this.provider.getFogColor(f1, par1); - } - - public int getPrecipitationHeight(int par1, int par2) - { - return this.getChunkFromBlockCoords(par1, par2).getPrecipitationHeight(par1 & 15, par2 & 15); - } - - public int getTopSolidOrLiquidBlock(int par1, int par2) - { - Chunk chunk = this.getChunkFromBlockCoords(par1, par2); - int x = par1; - int z = par2; - int k = chunk.getTopFilledSegment() + 15; - par1 &= 15; - - for (par2 &= 15; k > 0; --k) - { - Block block = chunk.getBlock(par1, k, par2); - - if (block.getMaterial().blocksMovement() && block.getMaterial() != Material.leaves && !block.isFoliage(this, x, k, z)) - { - return k + 1; - } - } - - return -1; - } - - @SideOnly(Side.CLIENT) - public float getStarBrightness(float par1) - { - return provider.getStarBrightness(par1); - } - - @SideOnly(Side.CLIENT) - public float getStarBrightnessBody(float par1) - { - float f1 = this.getCelestialAngle(par1); - float f2 = 1.0F - (MathHelper.cos(f1 * (float)Math.PI * 2.0F) * 2.0F + 0.25F); - - if (f2 < 0.0F) - { - f2 = 0.0F; - } - - if (f2 > 1.0F) - { - f2 = 1.0F; - } - - return f2 * f2 * 0.5F; - } - - public void scheduleBlockUpdate(int p_147464_1_, int p_147464_2_, int p_147464_3_, Block p_147464_4_, int p_147464_5_) {} - - public void scheduleBlockUpdateWithPriority(int p_147454_1_, int p_147454_2_, int p_147454_3_, Block p_147454_4_, int p_147454_5_, int p_147454_6_) {} - - public void func_147446_b(int p_147446_1_, int p_147446_2_, int p_147446_3_, Block p_147446_4_, int p_147446_5_, int p_147446_6_) {} - - public void updateEntities() - { - this.theProfiler.startSection("entities"); - this.theProfiler.startSection("global"); - int i; - Entity entity; - CrashReport crashreport; - CrashReportCategory crashreportcategory; - - for (i = 0; i < this.weatherEffects.size(); ++i) - { - entity = (Entity)this.weatherEffects.get(i); - - try - { - ++entity.ticksExisted; - entity.onUpdate(); - } - catch (Throwable throwable2) - { - crashreport = CrashReport.makeCrashReport(throwable2, "Ticking entity"); - crashreportcategory = crashreport.makeCategory("Entity being ticked"); - - if (entity == null) - { - crashreportcategory.addCrashSection("Entity", "~~NULL~~"); - } - else - { - entity.addEntityCrashInfo(crashreportcategory); - } - - if (ForgeModContainer.removeErroringEntities) - { - FMLLog.severe(crashreport.getCompleteReport()); - removeEntity(entity); - } - else - { - throw new ReportedException(crashreport); - } - } - - if (entity.isDead) - { - this.weatherEffects.remove(i--); - } - } - - this.theProfiler.endStartSection("remove"); - this.loadedEntityList.removeAll(this.unloadedEntityList); - int j; - int l; - - for (i = 0; i < this.unloadedEntityList.size(); ++i) - { - entity = (Entity)this.unloadedEntityList.get(i); - j = entity.chunkCoordX; - l = entity.chunkCoordZ; - - if (entity.addedToChunk && this.chunkExists(j, l)) - { - this.getChunkFromChunkCoords(j, l).removeEntity(entity); - } - } - - for (i = 0; i < this.unloadedEntityList.size(); ++i) - { - this.onEntityRemoved((Entity)this.unloadedEntityList.get(i)); - } - - this.unloadedEntityList.clear(); - this.theProfiler.endStartSection("regular"); - - for (i = 0; i < this.loadedEntityList.size(); ++i) - { - entity = (Entity)this.loadedEntityList.get(i); - - if (entity.ridingEntity != null) - { - if (!entity.ridingEntity.isDead && entity.ridingEntity.riddenByEntity == entity) - { - continue; - } - - entity.ridingEntity.riddenByEntity = null; - entity.ridingEntity = null; - } - - this.theProfiler.startSection("tick"); - - if (!entity.isDead) - { - try - { - this.updateEntity(entity); - } - catch (Throwable throwable1) - { - crashreport = CrashReport.makeCrashReport(throwable1, "Ticking entity"); - crashreportcategory = crashreport.makeCategory("Entity being ticked"); - entity.addEntityCrashInfo(crashreportcategory); - - if (ForgeModContainer.removeErroringEntities) - { - FMLLog.severe(crashreport.getCompleteReport()); - removeEntity(entity); - } - else - { - throw new ReportedException(crashreport); - } - } - } - - this.theProfiler.endSection(); - this.theProfiler.startSection("remove"); - - if (entity.isDead) - { - j = entity.chunkCoordX; - l = entity.chunkCoordZ; - - if (entity.addedToChunk && this.chunkExists(j, l)) - { - this.getChunkFromChunkCoords(j, l).removeEntity(entity); - } - - this.loadedEntityList.remove(i--); - this.onEntityRemoved(entity); - } - - this.theProfiler.endSection(); - } - - this.theProfiler.endStartSection("blockEntities"); - this.field_147481_N = true; - Iterator iterator = this.loadedTileEntityList.iterator(); - - while (iterator.hasNext()) - { - TileEntity tileentity = (TileEntity)iterator.next(); - - if (!tileentity.isInvalid() && tileentity.hasWorldObj() && activeChunkSet.containsKey(ChunkHash.chunkToKey(tileentity.xCoord >> 4, tileentity.zCoord >> 4))) - { - try - { - tileentity.updateEntity(); - } - catch (Throwable throwable) - { - crashreport = CrashReport.makeCrashReport(throwable, "Ticking block entity"); - crashreportcategory = crashreport.makeCategory("Block entity being ticked"); - tileentity.func_145828_a(crashreportcategory); - if (ForgeModContainer.removeErroringTileEntities) - { - FMLLog.severe(crashreport.getCompleteReport()); - tileentity.invalidate(); - setBlockToAir(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord); - } - else - { - throw new ReportedException(crashreport); - } - } - } - - if (tileentity.isInvalid()) - { - iterator.remove(); - - if (this.chunkExists(tileentity.xCoord >> 4, tileentity.zCoord >> 4)) - { - Chunk chunk = this.getChunkFromChunkCoords(tileentity.xCoord >> 4, tileentity.zCoord >> 4); - - if (chunk != null) - { - chunk.removeInvalidTileEntity(tileentity.xCoord & 15, tileentity.yCoord, tileentity.zCoord & 15); - } - } - } - } - - if (!this.field_147483_b.isEmpty()) - { - for (Object tile : field_147483_b) - { - ((TileEntity)tile).onChunkUnload(); - } - this.loadedTileEntityList.removeAll(this.field_147483_b); - this.field_147483_b.clear(); - } - - this.field_147481_N = false; - - this.theProfiler.endStartSection("pendingBlockEntities"); - - if (!this.addedTileEntityList.isEmpty()) - { - for (int k = 0; k < this.addedTileEntityList.size(); ++k) - { - TileEntity tileentity1 = (TileEntity)this.addedTileEntityList.get(k); - - if (!tileentity1.isInvalid()) - { - if (!this.loadedTileEntityList.contains(tileentity1)) - { - this.loadedTileEntityList.add(tileentity1); - } - } - else - { - if (this.chunkExists(tileentity1.xCoord >> 4, tileentity1.zCoord >> 4)) - { - Chunk chunk1 = this.getChunkFromChunkCoords(tileentity1.xCoord >> 4, tileentity1.zCoord >> 4); - - if (chunk1 != null) - { - chunk1.removeInvalidTileEntity(tileentity1.xCoord & 15, tileentity1.yCoord, tileentity1.zCoord & 15); - } - } - } - } - - this.addedTileEntityList.clear(); - } - - this.theProfiler.endSection(); - this.theProfiler.endSection(); - } - - public void func_147448_a(Collection p_147448_1_) - { - List dest = field_147481_N ? addedTileEntityList : loadedTileEntityList; - for(TileEntity entity : (Collection)p_147448_1_) - { - if(entity.canUpdate()) dest.add(entity); - } - } - - public void updateEntity(Entity par1Entity) - { - this.updateEntityWithOptionalForce(par1Entity, true); - } - - public void updateEntityWithOptionalForce(Entity par1Entity, boolean par2) - { - int i = MathHelper.floor_double(par1Entity.posX); - int j = MathHelper.floor_double(par1Entity.posZ); - //boolean isForced = getPersistentChunks().containsKey(new ChunkCoordIntPair(i >> 4, j >> 4)); - //byte b0 = isForced ? (byte)0 : 32; - //boolean canUpdate = !par2 || this.checkChunksExist(i - b0, 0, j - b0, i + b0, 0, j + b0); - boolean canUpdate = par1Entity.isEntityPlayerMP() || activeChunkSet.containsKey(ChunkHash.chunkToKey(i >> 4, j >> 4)) && this.chunkRoundExists(i >> 4, j >> 4, 3); - - //if (!canUpdate) - //{ - // EntityEvent.CanUpdate event = new EntityEvent.CanUpdate(par1Entity); - // MinecraftForge.EVENT_BUS.post(event); - // canUpdate = event.canUpdate; - //} - - if (canUpdate) - { - par1Entity.lastTickPosX = par1Entity.posX; - par1Entity.lastTickPosY = par1Entity.posY; - par1Entity.lastTickPosZ = par1Entity.posZ; - par1Entity.prevRotationYaw = par1Entity.rotationYaw; - par1Entity.prevRotationPitch = par1Entity.rotationPitch; - - if (par2 && par1Entity.addedToChunk) - { - ++par1Entity.ticksExisted; - - if (par1Entity.ridingEntity != null) - { - par1Entity.updateRidden(); - } - else - { - par1Entity.onUpdate(); - } - } - - this.theProfiler.startSection("chunkCheck"); - - if (Double.isNaN(par1Entity.posX) || Double.isInfinite(par1Entity.posX)) - { - par1Entity.posX = par1Entity.lastTickPosX; - } - - if (Double.isNaN(par1Entity.posY) || Double.isInfinite(par1Entity.posY)) - { - par1Entity.posY = par1Entity.lastTickPosY; - } - - if (Double.isNaN(par1Entity.posZ) || Double.isInfinite(par1Entity.posZ)) - { - par1Entity.posZ = par1Entity.lastTickPosZ; - } - - if (Double.isNaN((double)par1Entity.rotationPitch) || Double.isInfinite((double)par1Entity.rotationPitch)) - { - par1Entity.rotationPitch = par1Entity.prevRotationPitch; - } - - if (Double.isNaN((double)par1Entity.rotationYaw) || Double.isInfinite((double)par1Entity.rotationYaw)) - { - par1Entity.rotationYaw = par1Entity.prevRotationYaw; - } - - int k = MathHelper.floor_double(par1Entity.posX / 16.0D); - int l = MathHelper.floor_double(par1Entity.posY / 16.0D); - int i1 = MathHelper.floor_double(par1Entity.posZ / 16.0D); - - if (!par1Entity.addedToChunk || par1Entity.chunkCoordX != k || par1Entity.chunkCoordY != l || par1Entity.chunkCoordZ != i1) - { - if (par1Entity.addedToChunk && this.chunkExists(par1Entity.chunkCoordX, par1Entity.chunkCoordZ)) - { - this.getChunkFromChunkCoords(par1Entity.chunkCoordX, par1Entity.chunkCoordZ).removeEntityAtIndex(par1Entity, par1Entity.chunkCoordY); - } - - if (this.chunkExists(k, i1)) - { - par1Entity.addedToChunk = true; - this.getChunkFromChunkCoords(k, i1).addEntity(par1Entity); - } - else - { - par1Entity.addedToChunk = false; - } - } - - this.theProfiler.endSection(); - - if (par2 && par1Entity.addedToChunk && par1Entity.riddenByEntity != null) - { - if (!par1Entity.riddenByEntity.isDead && par1Entity.riddenByEntity.ridingEntity == par1Entity) - { - this.updateEntity(par1Entity.riddenByEntity); - } - else - { - par1Entity.riddenByEntity.ridingEntity = null; - par1Entity.riddenByEntity = null; - } - } - } - } - - public boolean checkNoEntityCollision(AxisAlignedBB par1AxisAlignedBB) - { - return this.checkNoEntityCollision(par1AxisAlignedBB, (Entity)null); - } - - public boolean checkNoEntityCollision(AxisAlignedBB par1AxisAlignedBB, Entity par2Entity) - { - List list = this.getEntitiesWithinAABBExcludingEntity((Entity)null, par1AxisAlignedBB); - - for (int i = 0; i < list.size(); ++i) - { - Entity entity1 = (Entity)list.get(i); - - if (!entity1.isDead && entity1.preventEntitySpawning && entity1 != par2Entity) - { - return false; - } - } - - return true; - } - - public boolean checkBlockCollision(AxisAlignedBB par1AxisAlignedBB) - { - int i = MathHelper.floor_double(par1AxisAlignedBB.minX); - int j = MathHelper.floor_double(par1AxisAlignedBB.maxX + 1.0D); - int k = MathHelper.floor_double(par1AxisAlignedBB.minY); - int l = MathHelper.floor_double(par1AxisAlignedBB.maxY + 1.0D); - int i1 = MathHelper.floor_double(par1AxisAlignedBB.minZ); - int j1 = MathHelper.floor_double(par1AxisAlignedBB.maxZ + 1.0D); - - if (par1AxisAlignedBB.minX < 0.0D) - { - --i; - } - - if (par1AxisAlignedBB.minY < 0.0D) - { - --k; - } - - if (par1AxisAlignedBB.minZ < 0.0D) - { - --i1; - } - - for (int k1 = i; k1 < j; ++k1) - { - for (int l1 = k; l1 < l; ++l1) - { - for (int i2 = i1; i2 < j1; ++i2) - { - Block block = this.getBlock(k1, l1, i2); - - if (block.getMaterial() != Material.air) - { - return true; - } - } - } - } - - return false; - } - - public boolean isAnyLiquid(AxisAlignedBB par1AxisAlignedBB) - { - int i = MathHelper.floor_double(par1AxisAlignedBB.minX); - int j = MathHelper.floor_double(par1AxisAlignedBB.maxX + 1.0D); - int k = MathHelper.floor_double(par1AxisAlignedBB.minY); - int l = MathHelper.floor_double(par1AxisAlignedBB.maxY + 1.0D); - int i1 = MathHelper.floor_double(par1AxisAlignedBB.minZ); - int j1 = MathHelper.floor_double(par1AxisAlignedBB.maxZ + 1.0D); - - if (par1AxisAlignedBB.minX < 0.0D) - { - --i; - } - - if (par1AxisAlignedBB.minY < 0.0D) - { - --k; - } - - if (par1AxisAlignedBB.minZ < 0.0D) - { - --i1; - } - - for (int k1 = i; k1 < j; ++k1) - { - for (int l1 = k; l1 < l; ++l1) - { - for (int i2 = i1; i2 < j1; ++i2) - { - Block block = this.getBlock(k1, l1, i2); - - if (block.getMaterial().isLiquid()) - { - return true; - } - } - } - } - - return false; - } - - public boolean func_147470_e(AxisAlignedBB p_147470_1_) - { - int i = MathHelper.floor_double(p_147470_1_.minX); - int j = MathHelper.floor_double(p_147470_1_.maxX + 1.0D); - int k = MathHelper.floor_double(p_147470_1_.minY); - int l = MathHelper.floor_double(p_147470_1_.maxY + 1.0D); - int i1 = MathHelper.floor_double(p_147470_1_.minZ); - int j1 = MathHelper.floor_double(p_147470_1_.maxZ + 1.0D); - - if (this.checkChunksExist(i, k, i1, j, l, j1)) - { - for (int k1 = i; k1 < j; ++k1) - { - for (int l1 = k; l1 < l; ++l1) - { - for (int i2 = i1; i2 < j1; ++i2) - { - Block block = this.getBlock(k1, l1, i2); - - if (block == Blocks.fire || block == Blocks.flowing_lava || block == Blocks.lava) - { - return true; - } - else - { - if (block.isBurning(this, k1, l1, i2)) return true; - } - } - } - } - } - - return false; - } - - public boolean handleMaterialAcceleration(AxisAlignedBB par1AxisAlignedBB, Material par2Material, Entity par3Entity) - { - int i = MathHelper.floor_double(par1AxisAlignedBB.minX); - int j = MathHelper.floor_double(par1AxisAlignedBB.maxX + 1.0D); - int k = MathHelper.floor_double(par1AxisAlignedBB.minY); - int l = MathHelper.floor_double(par1AxisAlignedBB.maxY + 1.0D); - int i1 = MathHelper.floor_double(par1AxisAlignedBB.minZ); - int j1 = MathHelper.floor_double(par1AxisAlignedBB.maxZ + 1.0D); - - if (!this.checkChunksExist(i, k, i1, j, l, j1)) - { - return false; - } - else - { - boolean flag = false; - Vec3 vec3 = this.getWorldVec3Pool().getVecFromPool(0.0D, 0.0D, 0.0D); - - for (int k1 = i; k1 < j; ++k1) - { - for (int l1 = k; l1 < l; ++l1) - { - for (int i2 = i1; i2 < j1; ++i2) - { - Block block = this.getBlock(k1, l1, i2); - - if (block.getMaterial() == par2Material) - { - double d0 = (double)((float)(l1 + 1) - BlockLiquid.getLiquidHeightPercent(this.getBlockMetadata(k1, l1, i2))); - - if ((double)l >= d0) - { - flag = true; - block.velocityToAddToEntity(this, k1, l1, i2, par3Entity, vec3); - } - } - } - } - } - - if (vec3.lengthVector() > 0.0D && par3Entity.isPushedByWater()) - { - vec3 = vec3.normalize(); - double d1 = 0.014D; - par3Entity.motionX += vec3.xCoord * d1; - par3Entity.motionY += vec3.yCoord * d1; - par3Entity.motionZ += vec3.zCoord * d1; - } - - return flag; - } - } - - public boolean isMaterialInBB(AxisAlignedBB par1AxisAlignedBB, Material par2Material) - { - int i = MathHelper.floor_double(par1AxisAlignedBB.minX); - int j = MathHelper.floor_double(par1AxisAlignedBB.maxX + 1.0D); - int k = MathHelper.floor_double(par1AxisAlignedBB.minY); - int l = MathHelper.floor_double(par1AxisAlignedBB.maxY + 1.0D); - int i1 = MathHelper.floor_double(par1AxisAlignedBB.minZ); - int j1 = MathHelper.floor_double(par1AxisAlignedBB.maxZ + 1.0D); - - for (int k1 = i; k1 < j; ++k1) - { - for (int l1 = k; l1 < l; ++l1) - { - for (int i2 = i1; i2 < j1; ++i2) - { - if (this.getBlock(k1, l1, i2).getMaterial() == par2Material) - { - return true; - } - } - } - } - - return false; - } - - public boolean isAABBInMaterial(AxisAlignedBB par1AxisAlignedBB, Material par2Material) - { - int i = MathHelper.floor_double(par1AxisAlignedBB.minX); - int j = MathHelper.floor_double(par1AxisAlignedBB.maxX + 1.0D); - int k = MathHelper.floor_double(par1AxisAlignedBB.minY); - int l = MathHelper.floor_double(par1AxisAlignedBB.maxY + 1.0D); - int i1 = MathHelper.floor_double(par1AxisAlignedBB.minZ); - int j1 = MathHelper.floor_double(par1AxisAlignedBB.maxZ + 1.0D); - - for (int k1 = i; k1 < j; ++k1) - { - for (int l1 = k; l1 < l; ++l1) - { - for (int i2 = i1; i2 < j1; ++i2) - { - Block block = this.getBlock(k1, l1, i2); - - if (block.getMaterial() == par2Material) - { - int j2 = this.getBlockMetadata(k1, l1, i2); - double d0 = (double)(l1 + 1); - - if (j2 < 8) - { - d0 = (double)(l1 + 1) - (double)j2 / 8.0D; - } - - if (d0 >= par1AxisAlignedBB.minY) - { - return true; - } - } - } - } - } - - return false; - } - - public Explosion createExplosion(Entity par1Entity, double par2, double par4, double par6, float par8, boolean par9) - { - return this.newExplosion(par1Entity, par2, par4, par6, par8, false, par9); - } - - public Explosion newExplosion(Entity par1Entity, double par2, double par4, double par6, float par8, boolean par9, boolean par10) - { - Explosion explosion = new Explosion(this, par1Entity, par2, par4, par6, par8); - explosion.isFlaming = par9; - explosion.isSmoking = par10; - explosion.doExplosionA(); - explosion.doExplosionB(true); - return explosion; - } - - public float getBlockDensity(Vec3 par1Vec3, AxisAlignedBB par2AxisAlignedBB) - { - double d0 = 1.0D / ((par2AxisAlignedBB.maxX - par2AxisAlignedBB.minX) * 2.0D + 1.0D); - double d1 = 1.0D / ((par2AxisAlignedBB.maxY - par2AxisAlignedBB.minY) * 2.0D + 1.0D); - double d2 = 1.0D / ((par2AxisAlignedBB.maxZ - par2AxisAlignedBB.minZ) * 2.0D + 1.0D); - int i = 0; - int j = 0; - - for (float f = 0.0F; f <= 1.0F; f = (float)((double)f + d0)) - { - for (float f1 = 0.0F; f1 <= 1.0F; f1 = (float)((double)f1 + d1)) - { - for (float f2 = 0.0F; f2 <= 1.0F; f2 = (float)((double)f2 + d2)) - { - double d3 = par2AxisAlignedBB.minX + (par2AxisAlignedBB.maxX - par2AxisAlignedBB.minX) * (double)f; - double d4 = par2AxisAlignedBB.minY + (par2AxisAlignedBB.maxY - par2AxisAlignedBB.minY) * (double)f1; - double d5 = par2AxisAlignedBB.minZ + (par2AxisAlignedBB.maxZ - par2AxisAlignedBB.minZ) * (double)f2; - - if (this.rayTraceBlocks(this.getWorldVec3Pool().getVecFromPool(d3, d4, d5), par1Vec3) == null) - { - ++i; - } - - ++j; - } - } - } - - return (float)i / (float)j; - } - - public boolean extinguishFire(EntityPlayer par1EntityPlayer, int par2, int par3, int par4, int par5) - { - if (par5 == 0) - { - --par3; - } - - if (par5 == 1) - { - ++par3; - } - - if (par5 == 2) - { - --par4; - } - - if (par5 == 3) - { - ++par4; - } - - if (par5 == 4) - { - --par2; - } - - if (par5 == 5) - { - ++par2; - } - - if (this.getBlock(par2, par3, par4) == Blocks.fire) - { - this.playAuxSFXAtEntity(par1EntityPlayer, 1004, par2, par3, par4, 0); - this.setBlockToAir(par2, par3, par4); - return true; - } - else - { - return false; - } - } - - @SideOnly(Side.CLIENT) - public String getDebugLoadedEntities() - { - return "All: " + this.loadedEntityList.size(); - } - - @SideOnly(Side.CLIENT) - public String getProviderName() - { - return this.chunkProvider.makeString(); - } - - public TileEntity getTileEntity(int p_147438_1_, int p_147438_2_, int p_147438_3_) - { - if (p_147438_2_ >= 0 && p_147438_2_ < 256) - { - TileEntity tileentity = null; - int l; - TileEntity tileentity1; - - if (this.field_147481_N) - { - for (l = 0; l < this.addedTileEntityList.size(); ++l) - { - tileentity1 = (TileEntity)this.addedTileEntityList.get(l); - - if (!tileentity1.isInvalid() && tileentity1.xCoord == p_147438_1_ && tileentity1.yCoord == p_147438_2_ && tileentity1.zCoord == p_147438_3_) - { - tileentity = tileentity1; - break; - } - } - } - - if (tileentity == null) - { - Chunk chunk = this.getChunkFromChunkCoords(p_147438_1_ >> 4, p_147438_3_ >> 4); - - if (chunk != null) - { - tileentity = chunk.func_150806_e(p_147438_1_ & 15, p_147438_2_, p_147438_3_ & 15); - } - } - - if (tileentity == null) - { - for (l = 0; l < this.addedTileEntityList.size(); ++l) - { - tileentity1 = (TileEntity)this.addedTileEntityList.get(l); - - if (!tileentity1.isInvalid() && tileentity1.xCoord == p_147438_1_ && tileentity1.yCoord == p_147438_2_ && tileentity1.zCoord == p_147438_3_) - { - tileentity = tileentity1; - break; - } - } - } - - return tileentity; - } - else - { - return null; - } - } - - public void setTileEntity(int p_147455_1_, int p_147455_2_, int p_147455_3_, TileEntity p_147455_4_) - { - if (p_147455_4_ == null || p_147455_4_.isInvalid()) - { - return; - } - - if (p_147455_4_.canUpdate()) - { - if (this.field_147481_N) - { - Iterator iterator = this.addedTileEntityList.iterator(); - - while (iterator.hasNext()) - { - TileEntity tileentity1 = (TileEntity)iterator.next(); - - if (tileentity1.xCoord == p_147455_1_ && tileentity1.yCoord == p_147455_2_ && tileentity1.zCoord == p_147455_3_) - { - tileentity1.invalidate(); - iterator.remove(); - } - } - - this.addedTileEntityList.add(p_147455_4_); - } - else - { - this.loadedTileEntityList.add(p_147455_4_); - } - } - Chunk chunk = this.getChunkFromChunkCoords(p_147455_1_ >> 4, p_147455_3_ >> 4); - if (chunk != null) - { - chunk.func_150812_a(p_147455_1_ & 15, p_147455_2_, p_147455_3_ & 15, p_147455_4_); - } - //notify tile changes - func_147453_f(p_147455_1_, p_147455_2_, p_147455_3_, getBlock(p_147455_1_, p_147455_2_, p_147455_3_)); - } - - public void removeTileEntity(int p_147475_1_, int p_147475_2_, int p_147475_3_) - { - Chunk chunk = getChunkFromChunkCoords(p_147475_1_ >> 4, p_147475_3_ >> 4); - if (chunk != null) chunk.removeTileEntity(p_147475_1_ & 15, p_147475_2_, p_147475_3_ & 15); - func_147453_f(p_147475_1_, p_147475_2_, p_147475_3_, getBlock(p_147475_1_, p_147475_2_, p_147475_3_)); - } - - public void func_147457_a(TileEntity p_147457_1_) - { - this.field_147483_b.add(p_147457_1_); - } - - public boolean func_147469_q(int p_147469_1_, int p_147469_2_, int p_147469_3_) - { - AxisAlignedBB axisalignedbb = this.getBlock(p_147469_1_, p_147469_2_, p_147469_3_).getCollisionBoundingBoxFromPool(this, p_147469_1_, p_147469_2_, p_147469_3_); - return axisalignedbb != null && axisalignedbb.getAverageEdgeLength() >= 1.0D; - } - - public static boolean doesBlockHaveSolidTopSurface(IBlockAccess p_147466_0_, int p_147466_1_, int p_147466_2_, int p_147466_3_) - { - Block block = p_147466_0_.getBlock(p_147466_1_, p_147466_2_, p_147466_3_); - return block.isSideSolid(p_147466_0_, p_147466_1_, p_147466_2_, p_147466_3_, ForgeDirection.UP); - } - - public boolean isBlockNormalCubeDefault(int p_147445_1_, int p_147445_2_, int p_147445_3_, boolean p_147445_4_) - { - if (p_147445_1_ >= -MAX_BLOCK_COORD && p_147445_3_ >= -MAX_BLOCK_COORD && p_147445_1_ < MAX_BLOCK_COORD && p_147445_3_ < MAX_BLOCK_COORD) - { - Chunk chunk = this.chunkProvider.provideChunk(p_147445_1_ >> 4, p_147445_3_ >> 4); - - if (chunk != null && !chunk.isEmpty()) - { - Block block = this.getBlock(p_147445_1_, p_147445_2_, p_147445_3_); - return block.isNormalCube(this, p_147445_1_, p_147445_2_, p_147445_3_); - } - else - { - return p_147445_4_; - } - } - else - { - return p_147445_4_; - } - } - - public void calculateInitialSkylight() - { - int i = this.calculateSkylightSubtracted(1.0F); - - if (i != this.skylightSubtracted) - { - this.skylightSubtracted = i; - } - } - - public void setAllowedSpawnTypes(boolean par1, boolean par2) - { - provider.setAllowedSpawnTypes(par1, par2); - } - - public void tick() - { - this.updateWeather(); - } - - private void calculateInitialWeather() - { - provider.calculateInitialWeather(); - } - - public void calculateInitialWeatherBody() - { - if (this.worldInfo.isRaining()) - { - this.rainingStrength = 1.0F; - - if (this.worldInfo.isThundering()) - { - this.thunderingStrength = 1.0F; - } - } - } - - protected void updateWeather() - { - provider.updateWeather(); - } - - public void updateWeatherBody() - { - if (!this.provider.hasNoSky) - { - if (!this.isRemote) - { - int i = this.worldInfo.getThunderTime(); - - if (i <= 0) - { - if (this.worldInfo.isThundering()) - { - this.worldInfo.setThunderTime(this.rand.nextInt(12000) + 3600); - } - else - { - this.worldInfo.setThunderTime(this.rand.nextInt(168000) + 12000); - } - } - else - { - --i; - this.worldInfo.setThunderTime(i); - - if (i <= 0) - { - this.worldInfo.setThundering(!this.worldInfo.isThundering()); - } - } - - this.prevThunderingStrength = this.thunderingStrength; - - if (this.worldInfo.isThundering()) - { - this.thunderingStrength = (float)((double)this.thunderingStrength + 0.01D); - } - else - { - this.thunderingStrength = (float)((double)this.thunderingStrength - 0.01D); - } - - this.thunderingStrength = MathHelper.clamp_float(this.thunderingStrength, 0.0F, 1.0F); - int j = this.worldInfo.getRainTime(); - - if (j <= 0) - { - if (this.worldInfo.isRaining()) - { - this.worldInfo.setRainTime(this.rand.nextInt(12000) + 12000); - } - else - { - this.worldInfo.setRainTime(this.rand.nextInt(168000) + 12000); - } - } - else - { - --j; - this.worldInfo.setRainTime(j); - - if (j <= 0) - { - this.worldInfo.setRaining(!this.worldInfo.isRaining()); - } - } - - this.prevRainingStrength = this.rainingStrength; - - if (this.worldInfo.isRaining()) - { - this.rainingStrength = (float)((double)this.rainingStrength + 0.01D); - } - else - { - this.rainingStrength = (float)((double)this.rainingStrength - 0.01D); - } - - this.rainingStrength = MathHelper.clamp_float(this.rainingStrength, 0.0F, 1.0F); - } - } - } - - protected void setActivePlayerChunksAndCheckLight() - { - this.activeChunkSet.clear(); - this.theProfiler.startSection("buildList"); - if(ConfigurationHandler.getServerConfig().enableChunkLoaders) - for(ChunkCoordIntPair c : getPersistentChunks().keySet()) activeChunkSet.put(ChunkHash.chunkToKey(c.chunkXPos, c.chunkZPos), (byte)100); - int i; - EntityPlayer entityplayer; - int j; - int k; - - for (i = 0; i < this.playerEntities.size(); ++i) - { - entityplayer = (EntityPlayer)this.playerEntities.get(i); - j = MathHelper.floor_double(entityplayer.posX / 16.0D); - k = MathHelper.floor_double(entityplayer.posZ / 16.0D); - int b0 = ConfigurationHandler.getServerConfig().chunkUpdateRadius; - - activeChunkSet.put(ChunkHash.chunkToKey(j, k), (byte)0); - for (int l = -b0; l <= b0; ++l) - { - for (int i1 = -b0; i1 <= b0; ++i1) - { - int cx = l + j; - int cz = i1 + k; - if(chunkExists(cx, cz) && chunkExists(cx-1, cz) && chunkExists(cx, cz-1) && chunkExists(cx+1, cz) && chunkExists(cx, cz+1)) - { - int key = ChunkHash.chunkToKey(cx, cz); - int priority = Math.max(Math.abs(l), Math.abs(i1)); - //Chunk chunk = this.chunkProvider.provideChunk(cx, cy); - //if(priority > 1) priority -= Math.min(priority-2, (int)(this.getTotalWorldTime() - chunk.lastActiveOrBindTick)/20); - activeChunkSet.put(key, (byte)Math.min(priority, activeChunkSet.get(key))); - } - } - } - } - - this.theProfiler.endSection(); - - if (this.ambientTickCountdown > 0) - { - --this.ambientTickCountdown; - } - - this.theProfiler.startSection("playerCheckLight"); - - if (!this.playerEntities.isEmpty()) - { - i = this.rand.nextInt(this.playerEntities.size()); - entityplayer = (EntityPlayer)this.playerEntities.get(i); - j = MathHelper.floor_double(entityplayer.posX) + this.rand.nextInt(11) - 5; - k = MathHelper.floor_double(entityplayer.posY) + this.rand.nextInt(11) - 5; - int j1 = MathHelper.floor_double(entityplayer.posZ) + this.rand.nextInt(11) - 5; - this.func_147451_t(j, k, j1); - } - - this.theProfiler.endSection(); - } - - protected void func_147467_a(int p_147467_1_, int p_147467_2_, Chunk p_147467_3_) - { - this.theProfiler.endStartSection("moodSound"); - - if (this.ambientTickCountdown == 0 && !this.isRemote) - { - this.updateLCG = this.updateLCG * 3 + 1013904223; - int k = this.updateLCG >> 2; - int l = k & 15; - int i1 = k >> 8 & 15; - int j1 = k >> 16 & 255; - Block block = p_147467_3_.getBlock(l, j1, i1); - l += p_147467_1_; - i1 += p_147467_2_; - - if (block.getMaterial() == Material.air && this.getFullBlockLightValue(l, j1, i1) <= this.rand.nextInt(8) && this.getSavedLightValue(EnumSkyBlock.Sky, l, j1, i1) <= 0) - { - EntityPlayer entityplayer = this.getClosestPlayer((double)l + 0.5D, (double)j1 + 0.5D, (double)i1 + 0.5D, 8.0D); - - if (entityplayer != null && entityplayer.getDistanceSq((double)l + 0.5D, (double)j1 + 0.5D, (double)i1 + 0.5D) > 4.0D) - { - this.playSoundEffect((double)l + 0.5D, (double)j1 + 0.5D, (double)i1 + 0.5D, "ambient.cave.cave", 0.7F, 0.8F + this.rand.nextFloat() * 0.2F); - this.ambientTickCountdown = this.rand.nextInt(12000) + 6000; - } - } - } - - this.theProfiler.endStartSection("checkLight"); - p_147467_3_.enqueueRelightChecks(); - } - - protected void func_147456_g() - { - this.setActivePlayerChunksAndCheckLight(); - } - - public boolean isBlockFreezable(int par1, int par2, int par3) - { - return this.canBlockFreeze(par1, par2, par3, false); - } - - public boolean isBlockFreezableNaturally(int par1, int par2, int par3) - { - return this.canBlockFreeze(par1, par2, par3, true); - } - - public boolean canBlockFreeze(int par1, int par2, int par3, boolean par4) - { - return provider.canBlockFreeze(par1, par2, par3, par4); - } - - public boolean canBlockFreezeBody(int par1, int par2, int par3, boolean par4) - { - BiomeGenBase biomegenbase = this.getBiomeGenForCoords(par1, par3); - float f = biomegenbase.getFloatTemperature(par1, par2, par3); - - if (f > 0.15F) - { - return false; - } - else - { - if (par2 >= 0 && par2 < 256 && this.getSavedLightValue(EnumSkyBlock.Block, par1, par2, par3) < 10) - { - Block block = this.getBlock(par1, par2, par3); - - if ((block == Blocks.water || block == Blocks.flowing_water) && this.getBlockMetadata(par1, par2, par3) == 0) - { - if (!par4) - { - return true; - } - - boolean flag1 = true; - - if (flag1 && this.getBlock(par1 - 1, par2, par3).getMaterial() != Material.water) - { - flag1 = false; - } - - if (flag1 && this.getBlock(par1 + 1, par2, par3).getMaterial() != Material.water) - { - flag1 = false; - } - - if (flag1 && this.getBlock(par1, par2, par3 - 1).getMaterial() != Material.water) - { - flag1 = false; - } - - if (flag1 && this.getBlock(par1, par2, par3 + 1).getMaterial() != Material.water) - { - flag1 = false; - } - - if (!flag1) - { - return true; - } - } - } - - return false; - } - } - - public boolean func_147478_e(int p_147478_1_, int p_147478_2_, int p_147478_3_, boolean p_147478_4_) - { - return provider.canSnowAt(p_147478_1_, p_147478_2_, p_147478_3_, p_147478_4_); - } - - public boolean canSnowAtBody(int p_147478_1_, int p_147478_2_, int p_147478_3_, boolean p_147478_4_) - { - BiomeGenBase biomegenbase = this.getBiomeGenForCoords(p_147478_1_, p_147478_3_); - float f = biomegenbase.getFloatTemperature(p_147478_1_, p_147478_2_, p_147478_3_); - - if (f > 0.15F) - { - return false; - } - else if (!p_147478_4_) - { - return true; - } - else - { - if (p_147478_2_ >= 0 && p_147478_2_ < 256 && this.getSavedLightValue(EnumSkyBlock.Block, p_147478_1_, p_147478_2_, p_147478_3_) < 10) - { - Block block = this.getBlock(p_147478_1_, p_147478_2_, p_147478_3_); - - if (block.getMaterial() == Material.air && Blocks.snow_layer.canPlaceBlockAt(this, p_147478_1_, p_147478_2_, p_147478_3_)) - { - return true; - } - } - - return false; - } - } - - public boolean func_147451_t(int p_147451_1_, int p_147451_2_, int p_147451_3_) - { - boolean flag = false; - - if (!this.provider.hasNoSky) - { - flag |= this.updateLightByType(EnumSkyBlock.Sky, p_147451_1_, p_147451_2_, p_147451_3_); - } - - flag |= this.updateLightByType(EnumSkyBlock.Block, p_147451_1_, p_147451_2_, p_147451_3_); - return flag; - } - - private int computeLightValue(int par1, int par2, int par3, EnumSkyBlock par4EnumSkyBlock) - { - if (par4EnumSkyBlock == EnumSkyBlock.Sky && this.canBlockSeeTheSky(par1, par2, par3)) - { - return 15; - } - else - { - Block block = this.getBlock(par1, par2, par3); - int blockLight = block.getLightValue(this, par1, par2, par3); - int l = par4EnumSkyBlock == EnumSkyBlock.Sky ? 0 : blockLight; - int i1 = block.getLightOpacity(this, par1, par2, par3); - - if (i1 >= 15 && blockLight > 0) - { - i1 = 1; - } - - if (i1 < 1) - { - i1 = 1; - } - - if (i1 >= 15) - { - return 0; - } - else if (l >= 14) - { - return l; - } - else - { - for (int j1 = 0; j1 < 6; ++j1) - { - int k1 = par1 + Facing.offsetsXForSide[j1]; - int l1 = par2 + Facing.offsetsYForSide[j1]; - int i2 = par3 + Facing.offsetsZForSide[j1]; - int j2 = this.getSavedLightValue(par4EnumSkyBlock, k1, l1, i2) - i1; - - if (j2 > l) - { - l = j2; - } - - if (l >= 14) - { - return l; - } - } - - return l; - } - } - } - - public boolean updateLightByType(EnumSkyBlock p_147463_1_, int p_147463_2_, int p_147463_3_, int p_147463_4_) - { - if (!this.doChunksNearChunkExist(p_147463_2_, p_147463_3_, p_147463_4_, 17)) - { - return false; - } - else - { - int l = 0; - int i1 = 0; - this.theProfiler.startSection("getBrightness"); - int j1 = this.getSavedLightValue(p_147463_1_, p_147463_2_, p_147463_3_, p_147463_4_); - int k1 = this.computeLightValue(p_147463_2_, p_147463_3_, p_147463_4_, p_147463_1_); - int l1; - int i2; - int j2; - int k2; - int l2; - int i3; - int j3; - int k3; - int l3; - - if (k1 > j1) - { - this.lightUpdateBlockList[i1++] = 133152; - } - else if (k1 < j1) - { - this.lightUpdateBlockList[i1++] = 133152 | j1 << 18; - - while (l < i1) - { - l1 = this.lightUpdateBlockList[l++]; - i2 = (l1 & 63) - 32 + p_147463_2_; - j2 = (l1 >> 6 & 63) - 32 + p_147463_3_; - k2 = (l1 >> 12 & 63) - 32 + p_147463_4_; - l2 = l1 >> 18 & 15; - i3 = this.getSavedLightValue(p_147463_1_, i2, j2, k2); - - if (i3 == l2) - { - this.setLightValue(p_147463_1_, i2, j2, k2, 0); - - if (l2 > 0) - { - j3 = MathHelper.abs_int(i2 - p_147463_2_); - k3 = MathHelper.abs_int(j2 - p_147463_3_); - l3 = MathHelper.abs_int(k2 - p_147463_4_); - - if (j3 + k3 + l3 < 17) - { - for (int i4 = 0; i4 < 6; ++i4) - { - int j4 = i2 + Facing.offsetsXForSide[i4]; - int k4 = j2 + Facing.offsetsYForSide[i4]; - int l4 = k2 + Facing.offsetsZForSide[i4]; - int i5 = Math.max(1, this.getBlock(j4, k4, l4).getLightOpacity(this, j4, k4, l4)); - i3 = this.getSavedLightValue(p_147463_1_, j4, k4, l4); - - if (i3 == l2 - i5 && i1 < this.lightUpdateBlockList.length) - { - this.lightUpdateBlockList[i1++] = j4 - p_147463_2_ + 32 | k4 - p_147463_3_ + 32 << 6 | l4 - p_147463_4_ + 32 << 12 | l2 - i5 << 18; - } - } - } - } - } - } - - l = 0; - } - - this.theProfiler.endSection(); - this.theProfiler.startSection("checkedPosition < toCheckCount"); - - while (l < i1) - { - l1 = this.lightUpdateBlockList[l++]; - i2 = (l1 & 63) - 32 + p_147463_2_; - j2 = (l1 >> 6 & 63) - 32 + p_147463_3_; - k2 = (l1 >> 12 & 63) - 32 + p_147463_4_; - l2 = this.getSavedLightValue(p_147463_1_, i2, j2, k2); - i3 = this.computeLightValue(i2, j2, k2, p_147463_1_); - - if (i3 != l2) - { - this.setLightValue(p_147463_1_, i2, j2, k2, i3); - - if (i3 > l2) - { - j3 = Math.abs(i2 - p_147463_2_); - k3 = Math.abs(j2 - p_147463_3_); - l3 = Math.abs(k2 - p_147463_4_); - boolean flag = i1 < this.lightUpdateBlockList.length - 6; - - if (j3 + k3 + l3 < 17 && flag) - { - if (this.getSavedLightValue(p_147463_1_, i2 - 1, j2, k2) < i3) - { - this.lightUpdateBlockList[i1++] = i2 - 1 - p_147463_2_ + 32 + (j2 - p_147463_3_ + 32 << 6) + (k2 - p_147463_4_ + 32 << 12); - } - - if (this.getSavedLightValue(p_147463_1_, i2 + 1, j2, k2) < i3) - { - this.lightUpdateBlockList[i1++] = i2 + 1 - p_147463_2_ + 32 + (j2 - p_147463_3_ + 32 << 6) + (k2 - p_147463_4_ + 32 << 12); - } - - if (this.getSavedLightValue(p_147463_1_, i2, j2 - 1, k2) < i3) - { - this.lightUpdateBlockList[i1++] = i2 - p_147463_2_ + 32 + (j2 - 1 - p_147463_3_ + 32 << 6) + (k2 - p_147463_4_ + 32 << 12); - } - - if (this.getSavedLightValue(p_147463_1_, i2, j2 + 1, k2) < i3) - { - this.lightUpdateBlockList[i1++] = i2 - p_147463_2_ + 32 + (j2 + 1 - p_147463_3_ + 32 << 6) + (k2 - p_147463_4_ + 32 << 12); - } - - if (this.getSavedLightValue(p_147463_1_, i2, j2, k2 - 1) < i3) - { - this.lightUpdateBlockList[i1++] = i2 - p_147463_2_ + 32 + (j2 - p_147463_3_ + 32 << 6) + (k2 - 1 - p_147463_4_ + 32 << 12); - } - - if (this.getSavedLightValue(p_147463_1_, i2, j2, k2 + 1) < i3) - { - this.lightUpdateBlockList[i1++] = i2 - p_147463_2_ + 32 + (j2 - p_147463_3_ + 32 << 6) + (k2 + 1 - p_147463_4_ + 32 << 12); - } - } - } - } - } - - this.theProfiler.endSection(); - return true; - } - } - - public boolean tickUpdates(boolean par1) - { - return false; - } - - public List getPendingBlockUpdates(Chunk par1Chunk, boolean par2) - { - return null; - } - - public List getEntitiesWithinAABBExcludingEntity(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB) - { - return this.getEntitiesWithinAABBExcludingEntity(par1Entity, par2AxisAlignedBB, (IEntitySelector)null); - } - - public List getEntitiesWithinAABBExcludingEntity(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB, IEntitySelector par3IEntitySelector) - { - ArrayList arraylist = new ArrayList(); - int i = MathHelper.floor_double((par2AxisAlignedBB.minX - MAX_ENTITY_RADIUS) / 16.0D); - int j = MathHelper.floor_double((par2AxisAlignedBB.maxX + MAX_ENTITY_RADIUS) / 16.0D); - int k = MathHelper.floor_double((par2AxisAlignedBB.minZ - MAX_ENTITY_RADIUS) / 16.0D); - int l = MathHelper.floor_double((par2AxisAlignedBB.maxZ + MAX_ENTITY_RADIUS) / 16.0D); - - for (int i1 = i; i1 <= j; ++i1) - { - for (int j1 = k; j1 <= l; ++j1) - { - if (this.chunkExists(i1, j1)) - { - this.getChunkFromChunkCoords(i1, j1).getEntitiesWithinAABBForEntity(par1Entity, par2AxisAlignedBB, arraylist, par3IEntitySelector); - } - } - } - - return arraylist; - } - - public List getEntitiesWithinAABB(Class par1Class, AxisAlignedBB par2AxisAlignedBB) - { - return this.selectEntitiesWithinAABB(par1Class, par2AxisAlignedBB, (IEntitySelector)null); - } - - public List selectEntitiesWithinAABB(Class par1Class, AxisAlignedBB par2AxisAlignedBB, IEntitySelector par3IEntitySelector) - { - int i = MathHelper.floor_double((par2AxisAlignedBB.minX - MAX_ENTITY_RADIUS) / 16.0D); - int j = MathHelper.floor_double((par2AxisAlignedBB.maxX + MAX_ENTITY_RADIUS) / 16.0D); - int k = MathHelper.floor_double((par2AxisAlignedBB.minZ - MAX_ENTITY_RADIUS) / 16.0D); - int l = MathHelper.floor_double((par2AxisAlignedBB.maxZ + MAX_ENTITY_RADIUS) / 16.0D); - ArrayList arraylist = new ArrayList(); - - for (int i1 = i; i1 <= j; ++i1) - { - for (int j1 = k; j1 <= l; ++j1) - { - if (this.chunkExists(i1, j1)) - { - this.getChunkFromChunkCoords(i1, j1).getEntitiesOfTypeWithinAAAB(par1Class, par2AxisAlignedBB, arraylist, par3IEntitySelector); - } - } - } - - return arraylist; - } - - public Entity findNearestEntityWithinAABB(Class par1Class, AxisAlignedBB par2AxisAlignedBB, Entity par3Entity) - { - List list = this.getEntitiesWithinAABB(par1Class, par2AxisAlignedBB); - Entity entity1 = null; - double d0 = Double.MAX_VALUE; - - for (int i = 0; i < list.size(); ++i) - { - Entity entity2 = (Entity)list.get(i); - - if (entity2 != par3Entity) - { - double d1 = par3Entity.getDistanceSqToEntity(entity2); - - if (d1 <= d0) - { - entity1 = entity2; - d0 = d1; - } - } - } - - return entity1; - } - - public abstract Entity getEntityByID(int var1); - - @SideOnly(Side.CLIENT) - public List getLoadedEntityList() - { - return this.loadedEntityList; - } - - public void markTileEntityChunkModified(int p_147476_1_, int p_147476_2_, int p_147476_3_, TileEntity p_147476_4_) - { - if (this.blockExists(p_147476_1_, p_147476_2_, p_147476_3_)) - { - this.getChunkFromBlockCoords(p_147476_1_, p_147476_3_).setChunkModified(); - } - } - - public int countEntities(Class par1Class) - { - int i = 0; - - for (int j = 0; j < this.loadedEntityList.size(); ++j) - { - Entity entity = (Entity)this.loadedEntityList.get(j); - - if ((!(entity instanceof EntityLiving) || !((EntityLiving)entity).isNoDespawnRequired()) && par1Class.isAssignableFrom(entity.getClass())) - { - ++i; - } - } - - return i; - } - - public void addLoadedEntities(List par1List) - { - for (int i = 0; i < par1List.size(); ++i) - { - Entity entity = (Entity)par1List.get(i); - if (!MinecraftForge.EVENT_BUS.post(new EntityJoinWorldEvent(entity, this))) - { - loadedEntityList.add(entity); - this.onEntityAdded(entity); - } - } - } - - public void unloadEntities(List par1List) - { - this.unloadedEntityList.addAll(par1List); - } - - public boolean canPlaceEntityOnSide(Block p_147472_1_, int p_147472_2_, int p_147472_3_, int p_147472_4_, boolean p_147472_5_, int p_147472_6_, Entity p_147472_7_, ItemStack p_147472_8_) - { - Block block1 = this.getBlock(p_147472_2_, p_147472_3_, p_147472_4_); - AxisAlignedBB axisalignedbb = p_147472_5_ ? null : p_147472_1_.getCollisionBoundingBoxFromPool(this, p_147472_2_, p_147472_3_, p_147472_4_); - return axisalignedbb != null && !this.checkNoEntityCollision(axisalignedbb, p_147472_7_) ? false : (block1.getMaterial() == Material.circuits && p_147472_1_ == Blocks.anvil ? true : block1.isReplaceable(this, p_147472_2_, p_147472_3_, p_147472_4_) && p_147472_1_.canReplace(this, p_147472_2_, p_147472_3_, p_147472_4_, p_147472_6_, p_147472_8_)); - } - - public PathEntity getPathEntityToEntity(Entity par1Entity, Entity par2Entity, float par3, boolean par4, boolean par5, boolean par6, boolean par7) - { - this.theProfiler.startSection("pathfind"); - int i = MathHelper.floor_double(par1Entity.posX); - int j = MathHelper.floor_double(par1Entity.posY + 1.0D); - int k = MathHelper.floor_double(par1Entity.posZ); - int l = (int)(par3 + 16.0F); - int i1 = i - l; - int j1 = j - l; - int k1 = k - l; - int l1 = i + l; - int i2 = j + l; - int j2 = k + l; - ChunkCache chunkcache = new ChunkCache(this, i1, j1, k1, l1, i2, j2, 0); - PathEntity pathentity = (new PathFinder(chunkcache, par4, par5, par6, par7)).createEntityPathTo(par1Entity, par2Entity, par3); - this.theProfiler.endSection(); - return pathentity; - } - - public PathEntity getEntityPathToXYZ(Entity par1Entity, int par2, int par3, int par4, float par5, boolean par6, boolean par7, boolean par8, boolean par9) - { - this.theProfiler.startSection("pathfind"); - int l = MathHelper.floor_double(par1Entity.posX); - int i1 = MathHelper.floor_double(par1Entity.posY); - int j1 = MathHelper.floor_double(par1Entity.posZ); - int k1 = (int)(par5 + 8.0F); - int l1 = l - k1; - int i2 = i1 - k1; - int j2 = j1 - k1; - int k2 = l + k1; - int l2 = i1 + k1; - int i3 = j1 + k1; - ChunkCache chunkcache = new ChunkCache(this, l1, i2, j2, k2, l2, i3, 0); - PathEntity pathentity = (new PathFinder(chunkcache, par6, par7, par8, par9)).createEntityPathTo(par1Entity, par2, par3, par4, par5); - this.theProfiler.endSection(); - return pathentity; - } - - public int isBlockProvidingPowerTo(int par1, int par2, int par3, int par4) - { - return this.getBlock(par1, par2, par3).isProvidingStrongPower(this, par1, par2, par3, par4); - } - - public int getBlockPowerInput(int par1, int par2, int par3) - { - byte b0 = 0; - int l = Math.max(b0, this.isBlockProvidingPowerTo(par1, par2 - 1, par3, 0)); - - if (l >= 15) - { - return l; - } - else - { - l = Math.max(l, this.isBlockProvidingPowerTo(par1, par2 + 1, par3, 1)); - - if (l >= 15) - { - return l; - } - else - { - l = Math.max(l, this.isBlockProvidingPowerTo(par1, par2, par3 - 1, 2)); - - if (l >= 15) - { - return l; - } - else - { - l = Math.max(l, this.isBlockProvidingPowerTo(par1, par2, par3 + 1, 3)); - - if (l >= 15) - { - return l; - } - else - { - l = Math.max(l, this.isBlockProvidingPowerTo(par1 - 1, par2, par3, 4)); - - if (l >= 15) - { - return l; - } - else - { - l = Math.max(l, this.isBlockProvidingPowerTo(par1 + 1, par2, par3, 5)); - return l >= 15 ? l : l; - } - } - } - } - } - } - - public boolean getIndirectPowerOutput(int par1, int par2, int par3, int par4) - { - return this.getIndirectPowerLevelTo(par1, par2, par3, par4) > 0; - } - - public int getIndirectPowerLevelTo(int par1, int par2, int par3, int par4) - { - Block block = this.getBlock(par1, par2, par3); - return block.shouldCheckWeakPower(this, par1, par2, par3, par4) ? this.getBlockPowerInput(par1, par2, par3) : block.isProvidingWeakPower(this, par1, par2, par3, par4); - } - - public boolean isBlockIndirectlyGettingPowered(int par1, int par2, int par3) - { - return this.getIndirectPowerLevelTo(par1, par2 - 1, par3, 0) > 0 ? true : (this.getIndirectPowerLevelTo(par1, par2 + 1, par3, 1) > 0 ? true : (this.getIndirectPowerLevelTo(par1, par2, par3 - 1, 2) > 0 ? true : (this.getIndirectPowerLevelTo(par1, par2, par3 + 1, 3) > 0 ? true : (this.getIndirectPowerLevelTo(par1 - 1, par2, par3, 4) > 0 ? true : this.getIndirectPowerLevelTo(par1 + 1, par2, par3, 5) > 0)))); - } - - public int getStrongestIndirectPower(int par1, int par2, int par3) - { - int l = 0; - - for (int i1 = 0; i1 < 6; ++i1) - { - int j1 = this.getIndirectPowerLevelTo(par1 + Facing.offsetsXForSide[i1], par2 + Facing.offsetsYForSide[i1], par3 + Facing.offsetsZForSide[i1], i1); - - if (j1 >= 15) - { - return 15; - } - - if (j1 > l) - { - l = j1; - } - } - - return l; - } - - public EntityPlayer getClosestPlayerToEntity(Entity par1Entity, double par2) - { - return this.getClosestPlayer(par1Entity.posX, par1Entity.posY, par1Entity.posZ, par2); - } - - public EntityPlayer getClosestPlayer(double par1, double par3, double par5, double par7) - { - double d4 = -1.0D; - EntityPlayer entityplayer = null; - - for (int i = 0; i < this.playerEntities.size(); ++i) - { - EntityPlayer entityplayer1 = (EntityPlayer)this.playerEntities.get(i); - double d5 = entityplayer1.getDistanceSq(par1, par3, par5); - - if ((par7 < 0.0D || d5 < par7 * par7) && (d4 == -1.0D || d5 < d4)) - { - d4 = d5; - entityplayer = entityplayer1; - } - } - - return entityplayer; - } - - public EntityPlayer getClosestVulnerablePlayerToEntity(Entity par1Entity, double par2) - { - return this.getClosestVulnerablePlayer(par1Entity.posX, par1Entity.posY, par1Entity.posZ, par2); - } - - public EntityPlayer getClosestVulnerablePlayer(double par1, double par3, double par5, double par7) - { - double d4 = -1.0D; - EntityPlayer entityplayer = null; - - for (int i = 0; i < this.playerEntities.size(); ++i) - { - EntityPlayer entityplayer1 = (EntityPlayer)this.playerEntities.get(i); - - if (!entityplayer1.capabilities.disableDamage && entityplayer1.isEntityAlive()) - { - double d5 = entityplayer1.getDistanceSq(par1, par3, par5); - double d6 = par7; - - if (entityplayer1.isSneaking()) - { - d6 = par7 * 0.800000011920929D; - } - - if (entityplayer1.isInvisible()) - { - float f = entityplayer1.getArmorVisibility(); - - if (f < 0.1F) - { - f = 0.1F; - } - - d6 *= (double)(0.7F * f); - } - - if ((par7 < 0.0D || d5 < d6 * d6) && (d4 == -1.0D || d5 < d4)) - { - d4 = d5; - entityplayer = entityplayer1; - } - } - } - - return entityplayer; - } - - public EntityPlayer getPlayerEntityByName(String par1Str) - { - for (int i = 0; i < this.playerEntities.size(); ++i) - { - if (par1Str.equals(((EntityPlayer)this.playerEntities.get(i)).getCommandSenderName())) - { - return (EntityPlayer)this.playerEntities.get(i); - } - } - - return null; - } - - @SideOnly(Side.CLIENT) - public void sendQuittingDisconnectingPacket() {} - - public void checkSessionLock() throws MinecraftException - { - this.saveHandler.checkSessionLock(); - } - - @SideOnly(Side.CLIENT) - public void func_82738_a(long par1) - { - this.worldInfo.incrementTotalWorldTime(par1); - } - - public long getSeed() - { - return provider.getSeed(); - } - - public long getTotalWorldTime() - { - return this.worldInfo.getWorldTotalTime(); - } - - public long getWorldTime() - { - return provider.getWorldTime(); - } - - public void setWorldTime(long par1) - { - provider.setWorldTime(par1); - } - - public ChunkCoordinates getSpawnPoint() - { - return provider.getSpawnPoint(); - } - - public void setSpawnLocation(int par1, int par2, int par3) - { - provider.setSpawnPoint(par1, par2, par3); - } - - @SideOnly(Side.CLIENT) - public void joinEntityInSurroundings(Entity par1Entity) - { - int i = MathHelper.floor_double(par1Entity.posX / 16.0D); - int j = MathHelper.floor_double(par1Entity.posZ / 16.0D); - byte b0 = 2; - - for (int k = i - b0; k <= i + b0; ++k) - { - for (int l = j - b0; l <= j + b0; ++l) - { - this.getChunkFromChunkCoords(k, l); - } - } - - if (!this.loadedEntityList.contains(par1Entity)) - { - if (!MinecraftForge.EVENT_BUS.post(new EntityJoinWorldEvent(par1Entity, this))) - { - this.loadedEntityList.add(par1Entity); - } - } - } - - public boolean canMineBlock(EntityPlayer par1EntityPlayer, int par2, int par3, int par4) - { - return provider.canMineBlock(par1EntityPlayer, par2, par3, par4); - } - - public boolean canMineBlockBody(EntityPlayer par1EntityPlayer, int par2, int par3, int par4) - { - return true; - } - - public void setEntityState(Entity par1Entity, byte par2) {} - - public IChunkProvider getChunkProvider() - { - return this.chunkProvider; - } - - public void addBlockEvent(int p_147452_1_, int p_147452_2_, int p_147452_3_, Block p_147452_4_, int p_147452_5_, int p_147452_6_) - { - p_147452_4_.onBlockEventReceived(this, p_147452_1_, p_147452_2_, p_147452_3_, p_147452_5_, p_147452_6_); - } - - public ISaveHandler getSaveHandler() - { - return this.saveHandler; - } - - public WorldInfo getWorldInfo() - { - return this.worldInfo; - } - - public GameRules getGameRules() - { - return this.worldInfo.getGameRulesInstance(); - } - - public void updateAllPlayersSleepingFlag() {} - - public float getWeightedThunderStrength(float par1) - { - return (this.prevThunderingStrength + (this.thunderingStrength - this.prevThunderingStrength) * par1) * this.getRainStrength(par1); - } - - @SideOnly(Side.CLIENT) - public void setThunderStrength(float p_147442_1_) - { - this.prevThunderingStrength = p_147442_1_; - this.thunderingStrength = p_147442_1_; - } - - public float getRainStrength(float par1) - { - return this.prevRainingStrength + (this.rainingStrength - this.prevRainingStrength) * par1; - } - - @SideOnly(Side.CLIENT) - public void setRainStrength(float par1) - { - this.prevRainingStrength = par1; - this.rainingStrength = par1; - } - - public boolean isThundering() - { - return (double)this.getWeightedThunderStrength(1.0F) > 0.9D; - } - - public boolean isRaining() - { - return (double)this.getRainStrength(1.0F) > 0.2D; - } - - public boolean canLightningStrikeAt(int par1, int par2, int par3) - { - if (!this.isRaining()) - { - return false; - } - else if (!this.canBlockSeeTheSky(par1, par2, par3)) - { - return false; - } - else if (this.getPrecipitationHeight(par1, par3) > par2) - { - return false; - } - else - { - BiomeGenBase biomegenbase = this.getBiomeGenForCoords(par1, par3); - return biomegenbase.getEnableSnow() ? false : (this.func_147478_e(par1, par2, par3, false) ? false : biomegenbase.canSpawnLightningBolt()); - } - } - - public boolean isBlockHighHumidity(int par1, int par2, int par3) - { - return provider.isBlockHighHumidity(par1, par2, par3); - } - - public void setItemData(String par1Str, WorldSavedData par2WorldSavedData) - { - this.mapStorage.setData(par1Str, par2WorldSavedData); - } - - public WorldSavedData loadItemData(Class par1Class, String par2Str) - { - return this.mapStorage.loadData(par1Class, par2Str); - } - - public int getUniqueDataId(String par1Str) - { - return this.mapStorage.getUniqueDataId(par1Str); - } - - public void playBroadcastSound(int par1, int par2, int par3, int par4, int par5) - { - for (int j1 = 0; j1 < this.worldAccesses.size(); ++j1) - { - ((IWorldAccess)this.worldAccesses.get(j1)).broadcastSound(par1, par2, par3, par4, par5); - } - } - - public void playAuxSFX(int par1, int par2, int par3, int par4, int par5) - { - this.playAuxSFXAtEntity((EntityPlayer)null, par1, par2, par3, par4, par5); - } - - public void playAuxSFXAtEntity(EntityPlayer par1EntityPlayer, int par2, int par3, int par4, int par5, int par6) - { - try - { - for (int j1 = 0; j1 < this.worldAccesses.size(); ++j1) - { - ((IWorldAccess)this.worldAccesses.get(j1)).playAuxSFX(par1EntityPlayer, par2, par3, par4, par5, par6); - } - } - catch (Throwable throwable) - { - CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Playing level event"); - CrashReportCategory crashreportcategory = crashreport.makeCategory("Level event being played"); - crashreportcategory.addCrashSection("Block coordinates", CrashReportCategory.getLocationInfo(par3, par4, par5)); - crashreportcategory.addCrashSection("Event source", par1EntityPlayer); - crashreportcategory.addCrashSection("Event type", Integer.valueOf(par2)); - crashreportcategory.addCrashSection("Event data", Integer.valueOf(par6)); - throw new ReportedException(crashreport); - } - } - - public int getHeight() - { - return provider.getHeight(); - } - - public int getActualHeight() - { - return provider.getActualHeight(); - } - - public Random setRandomSeed(int par1, int par2, int par3) - { - long l = (long)par1 * 341873128712L + (long)par2 * 132897987541L + this.getWorldInfo().getSeed() + (long)par3; - this.rand.setSeed(l); - return this.rand; - } - - public ChunkPosition findClosestStructure(String p_147440_1_, int p_147440_2_, int p_147440_3_, int p_147440_4_) - { - return this.getChunkProvider().func_147416_a(this, p_147440_1_, p_147440_2_, p_147440_3_, p_147440_4_); - } - - @SideOnly(Side.CLIENT) - public boolean extendedLevelsInChunkCache() - { - return false; - } - - @SideOnly(Side.CLIENT) - public double getHorizon() - { - return provider.getHorizon(); - } - - public CrashReportCategory addWorldInfoToCrashReport(CrashReport par1CrashReport) - { - CrashReportCategory crashreportcategory = par1CrashReport.makeCategoryDepth("Affected level", 1); - crashreportcategory.addCrashSection("Level name", this.worldInfo == null ? "????" : this.worldInfo.getWorldName()); - crashreportcategory.addCrashSectionCallable("All players", new Callable() - { - private static final String __OBFID = "CL_00000143"; - public String call() - { - return World.this.playerEntities.size() + " total; " + World.this.playerEntities.toString(); - } - }); - crashreportcategory.addCrashSectionCallable("Chunk stats", new Callable() - { - private static final String __OBFID = "CL_00000144"; - public String call() - { - return World.this.chunkProvider.makeString(); - } - }); - - try - { - this.worldInfo.addToCrashReport(crashreportcategory); - } - catch (Throwable throwable) - { - crashreportcategory.addCrashSectionThrowable("Level Data Unobtainable", throwable); - } - - return crashreportcategory; - } - - public void destroyBlockInWorldPartially(int p_147443_1_, int p_147443_2_, int p_147443_3_, int p_147443_4_, int p_147443_5_) - { - for (int j1 = 0; j1 < this.worldAccesses.size(); ++j1) - { - IWorldAccess iworldaccess = (IWorldAccess)this.worldAccesses.get(j1); - iworldaccess.destroyBlockPartially(p_147443_1_, p_147443_2_, p_147443_3_, p_147443_4_, p_147443_5_); - } - } - - public Vec3Pool getWorldVec3Pool() - { - return this.vecPool; - } - - public Calendar getCurrentDate() - { - if (this.getTotalWorldTime() % 600L == 0L) - { - this.theCalendar.setTimeInMillis(MinecraftServer.getSystemTimeMillis()); - } - - return this.theCalendar; - } - - @SideOnly(Side.CLIENT) - public void makeFireworks(double par1, double par3, double par5, double par7, double par9, double par11, NBTTagCompound par13NBTTagCompound) {} - - public Scoreboard getScoreboard() - { - return this.worldScoreboard; - } - - public void func_147453_f(int p_147453_1_, int p_147453_2_, int p_147453_3_, Block p_147453_4_) - { - for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) - { - int i1 = p_147453_1_ + dir.offsetX; - int y = p_147453_2_ + dir.offsetY; - int j1 = p_147453_3_ + dir.offsetZ; - Block block1 = this.getBlock(i1, y, j1); - - block1.onNeighborChange(this, i1, y, j1, p_147453_1_, p_147453_2_, p_147453_3_); - if (block1.isNormalCube(this, i1, p_147453_2_, j1)) - { - i1 += dir.offsetX; - y += dir.offsetY; - j1 += dir.offsetZ; - Block block2 = this.getBlock(i1, y, j1); - - if (block2.getWeakChanges(this, i1, y, j1)) - { - block2.onNeighborChange(this, i1, y, j1, p_147453_1_, p_147453_2_, p_147453_3_); - } - } - } - } - - public float func_147462_b(double p_147462_1_, double p_147462_3_, double p_147462_5_) - { - return this.func_147473_B(MathHelper.floor_double(p_147462_1_), MathHelper.floor_double(p_147462_3_), MathHelper.floor_double(p_147462_5_)); - } - - public float func_147473_B(int p_147473_1_, int p_147473_2_, int p_147473_3_) - { - float f = 0.0F; - boolean flag = this.difficultySetting == EnumDifficulty.HARD; - - if (this.blockExists(p_147473_1_, p_147473_2_, p_147473_3_)) - { - float f1 = this.getCurrentMoonPhaseFactor(); - f += MathHelper.clamp_float((float)this.getChunkFromBlockCoords(p_147473_1_, p_147473_3_).inhabitedTime / 3600000.0F, 0.0F, 1.0F) * (flag ? 1.0F : 0.75F); - f += f1 * 0.25F; - } - - if (this.difficultySetting == EnumDifficulty.EASY || this.difficultySetting == EnumDifficulty.PEACEFUL) - { - f *= (float)this.difficultySetting.getDifficultyId() / 2.0F; - } - - return MathHelper.clamp_float(f, 0.0F, flag ? 1.5F : 1.0F); - } - - public void func_147450_X() - { - Iterator iterator = this.worldAccesses.iterator(); - - while (iterator.hasNext()) - { - IWorldAccess iworldaccess = (IWorldAccess)iterator.next(); - iworldaccess.onStaticEntitiesChanged(); - } - } - - - /* ======================================== FORGE START =====================================*/ - /** - * Adds a single TileEntity to the world. - * @param entity The TileEntity to be added. - */ - public void addTileEntity(TileEntity entity) - { - List dest = field_147481_N ? addedTileEntityList : loadedTileEntityList; - if(entity.canUpdate()) - { - dest.add(entity); - } - } - - /** - * Determine if the given block is considered solid on the - * specified side. Used by placement logic. - * - * @param x Block X Position - * @param y Block Y Position - * @param z Block Z Position - * @param side The Side in question - * @return True if the side is solid - */ - public boolean isSideSolid(int x, int y, int z, ForgeDirection side) - { - return isSideSolid(x, y, z, side, false); - } - - /** - * Determine if the given block is considered solid on the - * specified side. Used by placement logic. - * - * @param x Block X Position - * @param y Block Y Position - * @param z Block Z Position - * @param side The Side in question - * @param _default The default to return if the block doesn't exist. - * @return True if the side is solid - */ - @Override - public boolean isSideSolid(int x, int y, int z, ForgeDirection side, boolean _default) - { - if (x < -MAX_BLOCK_COORD || z < -MAX_BLOCK_COORD || x >= MAX_BLOCK_COORD || z >= MAX_BLOCK_COORD) - { - return _default; - } - - Chunk chunk = this.chunkProvider.provideChunk(x >> 4, z >> 4); - if (chunk == null || chunk.isEmpty()) - { - return _default; - } - return getBlock(x, y, z).isSideSolid(this, x, y, z, side); - } - - /** - * Get the persistent chunks for this world - * - * @return - */ - public ImmutableSetMultimap getPersistentChunks() - { - return ForgeChunkManager.getPersistentChunksFor(this); - } - - /** - * Readded as it was removed, very useful helper function - * - * @param x X position - * @param y Y Position - * @param z Z Position - * @return The blocks light opacity - */ - public int getBlockLightOpacity(int x, int y, int z) - { - if (x < -MAX_BLOCK_COORD || z < -MAX_BLOCK_COORD || x >= MAX_BLOCK_COORD || z >= MAX_BLOCK_COORD) - { - return 0; - } - - if (y < 0 || y >= 256) - { - return 0; - } - - return getChunkFromChunkCoords(x >> 4, z >> 4).func_150808_b(x & 15, y, z & 15); - } - - /** - * Returns a count of entities that classify themselves as the specified creature type. - */ - public int countEntities(EnumCreatureType type, boolean forSpawnCount) - { - int count = 0; - for (int x = 0; x < loadedEntityList.size(); x++) - { - if (((Entity)loadedEntityList.get(x)).isCreatureType(type, forSpawnCount)) - { - count++; - } - } - return count; - } - - - - /* ======================================== ULTRAMINE START =====================================*/ - - - private static final int MAX_BLOCK_COORD = 500000;//524288; - - public boolean chunkRoundExists(int cx, int cz, int radius) - { - for(int x = cx - radius; x < cx + radius; x++) - for(int z = cz - radius; z < cz + radius; z++) - if(!chunkExists(x, z)) return false; - return true; - } +package net.minecraft.world; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gnu.trove.map.TIntByteMap; +import gnu.trove.map.hash.TIntByteHashMap; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Random; +import java.util.Set; +import java.util.concurrent.Callable; + +import org.ultramine.server.ConfigurationHandler; +import org.ultramine.server.chunk.ChunkHash; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockHopper; +import net.minecraft.block.BlockLiquid; +import net.minecraft.block.BlockSlab; +import net.minecraft.block.BlockSnow; +import net.minecraft.block.BlockStairs; +import net.minecraft.block.material.Material; +import net.minecraft.command.IEntitySelector; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.pathfinding.PathEntity; +import net.minecraft.pathfinding.PathFinder; +import net.minecraft.profiler.Profiler; +import net.minecraft.scoreboard.Scoreboard; +import net.minecraft.server.MinecraftServer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.Direction; +import net.minecraft.util.Facing; +import net.minecraft.util.MathHelper; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.ReportedException; +import net.minecraft.util.Vec3; +import net.minecraft.util.Vec3Pool; +import net.minecraft.village.VillageCollection; +import net.minecraft.village.VillageSiege; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.world.biome.WorldChunkManager; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.storage.ISaveHandler; +import net.minecraft.world.storage.MapStorage; +import net.minecraft.world.storage.WorldInfo; +import cpw.mods.fml.common.FMLLog; + +import com.google.common.collect.ImmutableSetMultimap; + +import net.minecraftforge.client.ForgeHooksClient; +import net.minecraftforge.common.ForgeChunkManager; +import net.minecraftforge.common.ForgeChunkManager.Ticket; +import net.minecraftforge.common.ForgeModContainer; +import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.common.WorldSpecificSaveHandler; +import net.minecraftforge.event.entity.EntityEvent; +import net.minecraftforge.event.entity.EntityJoinWorldEvent; +import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.event.entity.PlaySoundAtEntityEvent; +import net.minecraft.entity.EnumCreatureType; + +public abstract class World implements IBlockAccess +{ +/** + * Used in the getEntitiesWithinAABB functions to expand the search area for entities. + * Modders should change this variable to a higher value if it is less then the radius + * of one of there entities. + */ + public static double MAX_ENTITY_RADIUS = 2.0D; + + public final MapStorage perWorldStorage; + + public boolean scheduledUpdatesAreImmediate; + public List loadedEntityList = new ArrayList(); + protected List unloadedEntityList = new ArrayList(); + public List loadedTileEntityList = new ArrayList(); + private List addedTileEntityList = new ArrayList(); + private List field_147483_b = new ArrayList(); + public List playerEntities = new ArrayList(); + public List weatherEffects = new ArrayList(); + private long cloudColour = 16777215L; + public int skylightSubtracted; + protected int updateLCG = (new Random()).nextInt(); + protected final int DIST_HASH_MAGIC = 1013904223; + public float prevRainingStrength; + public float rainingStrength; + public float prevThunderingStrength; + public float thunderingStrength; + public int lastLightningBolt; + public EnumDifficulty difficultySetting; + public Random rand = new Random(); + public final WorldProvider provider; + protected List worldAccesses = new ArrayList(); + protected IChunkProvider chunkProvider; + protected final ISaveHandler saveHandler; + protected WorldInfo worldInfo; + public boolean findingSpawnPoint; + public MapStorage mapStorage; + public VillageCollection villageCollectionObj; + protected final VillageSiege villageSiegeObj = new VillageSiege(this); + public final Profiler theProfiler; + private final Vec3Pool vecPool = new Vec3Pool(300, 2000); + private final Calendar theCalendar = Calendar.getInstance(); + protected Scoreboard worldScoreboard = new Scoreboard(); + public boolean isRemote; + protected TIntByteMap activeChunkSet = new TIntByteHashMap(512, 0.75F, 0, Byte.MAX_VALUE);//XXX + private int ambientTickCountdown; + protected boolean spawnHostileMobs; + protected boolean spawnPeacefulMobs; + private ArrayList collidingBoundingBoxes; + private boolean field_147481_N; + int[] lightUpdateBlockList; + private static final String __OBFID = "CL_00000140"; + + public BiomeGenBase getBiomeGenForCoords(final int par1, final int par2) + { + return provider.getBiomeGenForCoords(par1, par2); + } + + public BiomeGenBase getBiomeGenForCoordsBody(final int par1, final int par2) + { + if (this.blockExists(par1, 0, par2)) + { + Chunk chunk = this.getChunkFromBlockCoords(par1, par2); + + try + { + return chunk.getBiomeGenForWorldCoords(par1 & 15, par2 & 15, this.provider.worldChunkMgr); + } + catch (Throwable throwable) + { + CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Getting biome"); + CrashReportCategory crashreportcategory = crashreport.makeCategory("Coordinates of biome request"); + crashreportcategory.addCrashSectionCallable("Location", new Callable() + { + private static final String __OBFID = "CL_00000141"; + public String call() + { + return CrashReportCategory.getLocationInfo(par1, 0, par2); + } + }); + throw new ReportedException(crashreport); + } + } + else + { + return this.provider.worldChunkMgr.getBiomeGenAt(par1, par2); + } + } + + public WorldChunkManager getWorldChunkManager() + { + return this.provider.worldChunkMgr; + } + + @SideOnly(Side.CLIENT) + public World(ISaveHandler p_i45368_1_, String p_i45368_2_, WorldProvider p_i45368_3_, WorldSettings p_i45368_4_, Profiler p_i45368_5_) + { + this.ambientTickCountdown = this.rand.nextInt(12000); + this.spawnHostileMobs = true; + this.spawnPeacefulMobs = true; + this.collidingBoundingBoxes = new ArrayList(); + this.lightUpdateBlockList = new int[32768]; + this.saveHandler = p_i45368_1_; + this.theProfiler = p_i45368_5_; + this.worldInfo = new WorldInfo(p_i45368_4_, p_i45368_2_); + this.provider = p_i45368_3_; + perWorldStorage = new MapStorage((ISaveHandler)null); + } + + // Broken up so that the WorldClient gets the chance to set the mapstorage object before the dimension initializes + @SideOnly(Side.CLIENT) + protected void finishSetup() + { + VillageCollection villagecollection = (VillageCollection)this.mapStorage.loadData(VillageCollection.class, "villages"); + + if (villagecollection == null) + { + this.villageCollectionObj = new VillageCollection(this); + this.mapStorage.setData("villages", this.villageCollectionObj); + } + else + { + this.villageCollectionObj = villagecollection; + this.villageCollectionObj.func_82566_a(this); + } + + // Guarantee the dimension ID was not reset by the provider + int providerDim = this.provider.dimensionId; + this.provider.registerWorld(this); + this.provider.dimensionId = providerDim; + this.chunkProvider = this.createChunkProvider(); + this.calculateInitialSkylight(); + this.calculateInitialWeather(); + } + + public World(ISaveHandler p_i45369_1_, String p_i45369_2_, WorldSettings p_i45369_3_, WorldProvider p_i45369_4_, Profiler p_i45369_5_) + { + this.ambientTickCountdown = this.rand.nextInt(12000); + this.spawnHostileMobs = true; + this.spawnPeacefulMobs = true; + this.collidingBoundingBoxes = new ArrayList(); + this.lightUpdateBlockList = new int[32768]; + this.saveHandler = p_i45369_1_; + this.theProfiler = p_i45369_5_; + this.mapStorage = getMapStorage(p_i45369_1_); + this.worldInfo = p_i45369_1_.loadWorldInfo(); + + if (p_i45369_4_ != null) + { + this.provider = p_i45369_4_; + } + else if (this.worldInfo != null && this.worldInfo.getVanillaDimension() != 0) + { + this.provider = WorldProvider.getProviderForDimension(this.worldInfo.getVanillaDimension()); + } + else + { + this.provider = WorldProvider.getProviderForDimension(0); + } + + if (this.worldInfo == null) + { + this.worldInfo = new WorldInfo(p_i45369_3_, p_i45369_2_); + } + else + { + this.worldInfo.setWorldName(p_i45369_2_); + } + + this.provider.registerWorld(this); + this.chunkProvider = this.createChunkProvider(); + + if (this instanceof WorldServer) + { + this.perWorldStorage = new MapStorage(new WorldSpecificSaveHandler((WorldServer)this, p_i45369_1_)); + } + else + { + this.perWorldStorage = new MapStorage((ISaveHandler)null); + } + + if (!this.worldInfo.isInitialized()) + { + try + { + this.initialize(p_i45369_3_); + } + catch (Throwable throwable1) + { + CrashReport crashreport = CrashReport.makeCrashReport(throwable1, "Exception initializing level"); + + try + { + this.addWorldInfoToCrashReport(crashreport); + } + catch (Throwable throwable) + { + ; + } + + throw new ReportedException(crashreport); + } + + this.worldInfo.setServerInitialized(true); + } + + VillageCollection villagecollection = (VillageCollection)this.perWorldStorage.loadData(VillageCollection.class, "villages"); + + if (villagecollection == null) + { + this.villageCollectionObj = new VillageCollection(this); + this.perWorldStorage.setData("villages", this.villageCollectionObj); + } + else + { + this.villageCollectionObj = villagecollection; + this.villageCollectionObj.func_82566_a(this); + } + + this.calculateInitialSkylight(); + this.calculateInitialWeather(); + } + + private static MapStorage s_mapStorage; + private static ISaveHandler s_savehandler; + //Provides a solution for different worlds getting different copies of the same data, potentially rewriting the data or causing race conditions/stale data + //Buildcraft has suffered from the issue this fixes. If you load the same data from two different worlds they can get two different copies of the same object, thus the last saved gets final say. + private MapStorage getMapStorage(ISaveHandler savehandler) + { + if (s_savehandler != savehandler || s_mapStorage == null) + { + s_mapStorage = new MapStorage(savehandler); + s_savehandler = savehandler; + } + return s_mapStorage; + } + + protected abstract IChunkProvider createChunkProvider(); + + protected void initialize(WorldSettings par1WorldSettings) + { + this.worldInfo.setServerInitialized(true); + } + + @SideOnly(Side.CLIENT) + public void setSpawnLocation() + { + this.setSpawnLocation(8, 64, 8); + } + + public Block getTopBlock(int p_147474_1_, int p_147474_2_) + { + int k; + + for (k = 63; !this.isAirBlock(p_147474_1_, k + 1, p_147474_2_); ++k) + { + ; + } + + return this.getBlock(p_147474_1_, k, p_147474_2_); + } + + public Block getBlock(int p_147439_1_, int p_147439_2_, int p_147439_3_) + { + if (p_147439_1_ >= -MAX_BLOCK_COORD && p_147439_3_ >= -MAX_BLOCK_COORD && p_147439_1_ < MAX_BLOCK_COORD && p_147439_3_ < MAX_BLOCK_COORD && p_147439_2_ >= 0 && p_147439_2_ < 256) + { + Chunk chunk = null; + + try + { + chunk = this.getChunkFromChunkCoords(p_147439_1_ >> 4, p_147439_3_ >> 4); + return chunk.getBlock(p_147439_1_ & 15, p_147439_2_, p_147439_3_ & 15); + } + catch (Throwable throwable) + { + CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Exception getting block type in world"); + CrashReportCategory crashreportcategory = crashreport.makeCategory("Requested block coordinates"); + crashreportcategory.addCrashSection("Found chunk", Boolean.valueOf(chunk == null)); + crashreportcategory.addCrashSection("Location", CrashReportCategory.getLocationInfo(p_147439_1_, p_147439_2_, p_147439_3_)); + throw new ReportedException(crashreport); + } + } + else + { + return Blocks.air; + } + } + + public boolean isAirBlock(int p_147437_1_, int p_147437_2_, int p_147437_3_) + { + Block block = this.getBlock(p_147437_1_, p_147437_2_, p_147437_3_); + return block.isAir(this, p_147437_1_, p_147437_2_, p_147437_3_); + } + + public boolean blockExists(int par1, int par2, int par3) + { + return par2 >= 0 && par2 < 256 ? this.chunkExists(par1 >> 4, par3 >> 4) : false; + } + + public boolean doChunksNearChunkExist(int par1, int par2, int par3, int par4) + { + return this.checkChunksExist(par1 - par4, par2 - par4, par3 - par4, par1 + par4, par2 + par4, par3 + par4); + } + + public boolean checkChunksExist(int par1, int par2, int par3, int par4, int par5, int par6) + { + if (par5 >= 0 && par2 < 256) + { + par1 >>= 4; + par3 >>= 4; + par4 >>= 4; + par6 >>= 4; + + for (int k1 = par1; k1 <= par4; ++k1) + { + for (int l1 = par3; l1 <= par6; ++l1) + { + if (!this.chunkExists(k1, l1)) + { + return false; + } + } + } + + return true; + } + else + { + return false; + } + } + + public boolean chunkExists(int par1, int par2) + { + return this.chunkProvider.chunkExists(par1, par2); + } + + public Chunk getChunkFromBlockCoords(int par1, int par2) + { + return this.getChunkFromChunkCoords(par1 >> 4, par2 >> 4); + } + + public Chunk getChunkFromChunkCoords(int par1, int par2) + { + return this.chunkProvider.provideChunk(par1, par2); + } + + public boolean setBlock(int p_147465_1_, int p_147465_2_, int p_147465_3_, Block p_147465_4_, int p_147465_5_, int p_147465_6_) + { + if (p_147465_1_ >= -MAX_BLOCK_COORD && p_147465_3_ >= -MAX_BLOCK_COORD && p_147465_1_ < MAX_BLOCK_COORD && p_147465_3_ < MAX_BLOCK_COORD) + { + if (p_147465_2_ < 0) + { + return false; + } + else if (p_147465_2_ >= 256) + { + return false; + } + else + { + Chunk chunk = this.getChunkFromChunkCoords(p_147465_1_ >> 4, p_147465_3_ >> 4); + Block block1 = null; + + if ((p_147465_6_ & 1) != 0) + { + block1 = chunk.getBlock(p_147465_1_ & 15, p_147465_2_, p_147465_3_ & 15); + } + + boolean flag = chunk.func_150807_a(p_147465_1_ & 15, p_147465_2_, p_147465_3_ & 15, p_147465_4_, p_147465_5_); + this.theProfiler.startSection("checkLight"); + this.func_147451_t(p_147465_1_, p_147465_2_, p_147465_3_); + this.theProfiler.endSection(); + + if (flag) + { + if ((p_147465_6_ & 2) != 0 && (!this.isRemote || (p_147465_6_ & 4) == 0) && chunk.func_150802_k()) + { + this.markBlockForUpdate(p_147465_1_, p_147465_2_, p_147465_3_); + } + + if (!this.isRemote && (p_147465_6_ & 1) != 0) + { + this.notifyBlockChange(p_147465_1_, p_147465_2_, p_147465_3_, block1); + + if (p_147465_4_.hasComparatorInputOverride()) + { + this.func_147453_f(p_147465_1_, p_147465_2_, p_147465_3_, p_147465_4_); + } + } + } + + return flag; + } + } + else + { + return false; + } + } + + public int getBlockMetadata(int par1, int par2, int par3) + { + if (par1 >= -MAX_BLOCK_COORD && par3 >= -MAX_BLOCK_COORD && par1 < MAX_BLOCK_COORD && par3 < MAX_BLOCK_COORD) + { + if (par2 < 0) + { + return 0; + } + else if (par2 >= 256) + { + return 0; + } + else + { + Chunk chunk = this.getChunkFromChunkCoords(par1 >> 4, par3 >> 4); + par1 &= 15; + par3 &= 15; + return chunk.getBlockMetadata(par1, par2, par3); + } + } + else + { + return 0; + } + } + + public boolean setBlockMetadataWithNotify(int par1, int par2, int par3, int par4, int par5) + { + if (par1 >= -MAX_BLOCK_COORD && par3 >= -MAX_BLOCK_COORD && par1 < MAX_BLOCK_COORD && par3 < MAX_BLOCK_COORD) + { + if (par2 < 0) + { + return false; + } + else if (par2 >= 256) + { + return false; + } + else + { + Chunk chunk = this.getChunkFromChunkCoords(par1 >> 4, par3 >> 4); + int j1 = par1 & 15; + int k1 = par3 & 15; + boolean flag = chunk.setBlockMetadata(j1, par2, k1, par4); + + if (flag) + { + Block block = chunk.getBlock(j1, par2, k1); + + if ((par5 & 2) != 0 && (!this.isRemote || (par5 & 4) == 0) && chunk.func_150802_k()) + { + this.markBlockForUpdate(par1, par2, par3); + } + + if (!this.isRemote && (par5 & 1) != 0) + { + this.notifyBlockChange(par1, par2, par3, block); + + if (block.hasComparatorInputOverride()) + { + this.func_147453_f(par1, par2, par3, block); + } + } + } + + return flag; + } + } + else + { + return false; + } + } + + public boolean setBlockToAir(int p_147468_1_, int p_147468_2_, int p_147468_3_) + { + return this.setBlock(p_147468_1_, p_147468_2_, p_147468_3_, Blocks.air, 0, 3); + } + + public boolean func_147480_a(int p_147480_1_, int p_147480_2_, int p_147480_3_, boolean p_147480_4_) + { + Block block = this.getBlock(p_147480_1_, p_147480_2_, p_147480_3_); + + if (block.getMaterial() == Material.air) + { + return false; + } + else + { + int l = this.getBlockMetadata(p_147480_1_, p_147480_2_, p_147480_3_); + this.playAuxSFX(2001, p_147480_1_, p_147480_2_, p_147480_3_, Block.getIdFromBlock(block) + (l << 12)); + + if (p_147480_4_) + { + block.dropBlockAsItem(this, p_147480_1_, p_147480_2_, p_147480_3_, l, 0); + } + + return this.setBlock(p_147480_1_, p_147480_2_, p_147480_3_, Blocks.air, 0, 3); + } + } + + public boolean setBlock(int p_147449_1_, int p_147449_2_, int p_147449_3_, Block p_147449_4_) + { + return this.setBlock(p_147449_1_, p_147449_2_, p_147449_3_, p_147449_4_, 0, 3); + } + + public void markBlockForUpdate(int p_147471_1_, int p_147471_2_, int p_147471_3_) + { + for (int l = 0; l < this.worldAccesses.size(); ++l) + { + ((IWorldAccess)this.worldAccesses.get(l)).markBlockForUpdate(p_147471_1_, p_147471_2_, p_147471_3_); + } + } + + public void notifyBlockChange(int p_147444_1_, int p_147444_2_, int p_147444_3_, Block p_147444_4_) + { + this.notifyBlocksOfNeighborChange(p_147444_1_, p_147444_2_, p_147444_3_, p_147444_4_); + } + + public void markBlocksDirtyVertical(int par1, int par2, int par3, int par4) + { + int i1; + + if (par3 > par4) + { + i1 = par4; + par4 = par3; + par3 = i1; + } + + if (!this.provider.hasNoSky) + { + for (i1 = par3; i1 <= par4; ++i1) + { + this.updateLightByType(EnumSkyBlock.Sky, par1, i1, par2); + } + } + + this.markBlockRangeForRenderUpdate(par1, par3, par2, par1, par4, par2); + } + + public void markBlockRangeForRenderUpdate(int p_147458_1_, int p_147458_2_, int p_147458_3_, int p_147458_4_, int p_147458_5_, int p_147458_6_) + { + for (int k1 = 0; k1 < this.worldAccesses.size(); ++k1) + { + ((IWorldAccess)this.worldAccesses.get(k1)).markBlockRangeForRenderUpdate(p_147458_1_, p_147458_2_, p_147458_3_, p_147458_4_, p_147458_5_, p_147458_6_); + } + } + + public void notifyBlocksOfNeighborChange(int p_147459_1_, int p_147459_2_, int p_147459_3_, Block p_147459_4_) + { + this.notifyBlockOfNeighborChange(p_147459_1_ - 1, p_147459_2_, p_147459_3_, p_147459_4_); + this.notifyBlockOfNeighborChange(p_147459_1_ + 1, p_147459_2_, p_147459_3_, p_147459_4_); + this.notifyBlockOfNeighborChange(p_147459_1_, p_147459_2_ - 1, p_147459_3_, p_147459_4_); + this.notifyBlockOfNeighborChange(p_147459_1_, p_147459_2_ + 1, p_147459_3_, p_147459_4_); + this.notifyBlockOfNeighborChange(p_147459_1_, p_147459_2_, p_147459_3_ - 1, p_147459_4_); + this.notifyBlockOfNeighborChange(p_147459_1_, p_147459_2_, p_147459_3_ + 1, p_147459_4_); + } + + public void notifyBlocksOfNeighborChange(int p_147441_1_, int p_147441_2_, int p_147441_3_, Block p_147441_4_, int p_147441_5_) + { + if (p_147441_5_ != 4) + { + this.notifyBlockOfNeighborChange(p_147441_1_ - 1, p_147441_2_, p_147441_3_, p_147441_4_); + } + + if (p_147441_5_ != 5) + { + this.notifyBlockOfNeighborChange(p_147441_1_ + 1, p_147441_2_, p_147441_3_, p_147441_4_); + } + + if (p_147441_5_ != 0) + { + this.notifyBlockOfNeighborChange(p_147441_1_, p_147441_2_ - 1, p_147441_3_, p_147441_4_); + } + + if (p_147441_5_ != 1) + { + this.notifyBlockOfNeighborChange(p_147441_1_, p_147441_2_ + 1, p_147441_3_, p_147441_4_); + } + + if (p_147441_5_ != 2) + { + this.notifyBlockOfNeighborChange(p_147441_1_, p_147441_2_, p_147441_3_ - 1, p_147441_4_); + } + + if (p_147441_5_ != 3) + { + this.notifyBlockOfNeighborChange(p_147441_1_, p_147441_2_, p_147441_3_ + 1, p_147441_4_); + } + } + + public void notifyBlockOfNeighborChange(int p_147460_1_, int p_147460_2_, int p_147460_3_, final Block p_147460_4_) + { + if (!this.isRemote) + { + Block block = this.getBlock(p_147460_1_, p_147460_2_, p_147460_3_); + + try + { + block.onNeighborBlockChange(this, p_147460_1_, p_147460_2_, p_147460_3_, p_147460_4_); + } + catch (Throwable throwable1) + { + CrashReport crashreport = CrashReport.makeCrashReport(throwable1, "Exception while updating neighbours"); + CrashReportCategory crashreportcategory = crashreport.makeCategory("Block being updated"); + int l; + + try + { + l = this.getBlockMetadata(p_147460_1_, p_147460_2_, p_147460_3_); + } + catch (Throwable throwable) + { + l = -1; + } + + crashreportcategory.addCrashSectionCallable("Source block type", new Callable() + { + private static final String __OBFID = "CL_00000142"; + public String call() + { + try + { + return String.format("ID #%d (%s // %s)", new Object[] {Integer.valueOf(Block.getIdFromBlock(p_147460_4_)), p_147460_4_.getUnlocalizedName(), p_147460_4_.getClass().getCanonicalName()}); + } + catch (Throwable throwable2) + { + return "ID #" + Block.getIdFromBlock(p_147460_4_); + } + } + }); + CrashReportCategory.func_147153_a(crashreportcategory, p_147460_1_, p_147460_2_, p_147460_3_, block, l); + throw new ReportedException(crashreport); + } + } + } + + public boolean isBlockTickScheduledThisTick(int p_147477_1_, int p_147477_2_, int p_147477_3_, Block p_147477_4_) + { + return false; + } + + public boolean canBlockSeeTheSky(int par1, int par2, int par3) + { + return this.getChunkFromChunkCoords(par1 >> 4, par3 >> 4).canBlockSeeTheSky(par1 & 15, par2, par3 & 15); + } + + public int getFullBlockLightValue(int par1, int par2, int par3) + { + if (par2 < 0) + { + return 0; + } + else + { + if (par2 >= 256) + { + par2 = 255; + } + + return this.getChunkFromChunkCoords(par1 >> 4, par3 >> 4).getBlockLightValue(par1 & 15, par2, par3 & 15, 0); + } + } + + public int getBlockLightValue(int par1, int par2, int par3) + { + return this.getBlockLightValue_do(par1, par2, par3, true); + } + + public int getBlockLightValue_do(int par1, int par2, int par3, boolean par4) + { + if (par1 >= -MAX_BLOCK_COORD && par3 >= -MAX_BLOCK_COORD && par1 < MAX_BLOCK_COORD && par3 < MAX_BLOCK_COORD) + { + if (par4 && this.getBlock(par1, par2, par3).getUseNeighborBrightness()) + { + int l1 = this.getBlockLightValue_do(par1, par2 + 1, par3, false); + int l = this.getBlockLightValue_do(par1 + 1, par2, par3, false); + int i1 = this.getBlockLightValue_do(par1 - 1, par2, par3, false); + int j1 = this.getBlockLightValue_do(par1, par2, par3 + 1, false); + int k1 = this.getBlockLightValue_do(par1, par2, par3 - 1, false); + + if (l > l1) + { + l1 = l; + } + + if (i1 > l1) + { + l1 = i1; + } + + if (j1 > l1) + { + l1 = j1; + } + + if (k1 > l1) + { + l1 = k1; + } + + return l1; + } + else if (par2 < 0) + { + return 0; + } + else + { + if (par2 >= 256) + { + par2 = 255; + } + + Chunk chunk = this.getChunkFromChunkCoords(par1 >> 4, par3 >> 4); + par1 &= 15; + par3 &= 15; + return chunk.getBlockLightValue(par1, par2, par3, this.skylightSubtracted); + } + } + else + { + return 15; + } + } + + public int getHeightValue(int par1, int par2) + { + if (par1 >= -MAX_BLOCK_COORD && par2 >= -MAX_BLOCK_COORD && par1 < MAX_BLOCK_COORD && par2 < MAX_BLOCK_COORD) + { + if (!this.chunkExists(par1 >> 4, par2 >> 4)) + { + return 0; + } + else + { + Chunk chunk = this.getChunkFromChunkCoords(par1 >> 4, par2 >> 4); + return chunk.getHeightValue(par1 & 15, par2 & 15); + } + } + else + { + return 64; + } + } + + public int getChunkHeightMapMinimum(int par1, int par2) + { + if (par1 >= -MAX_BLOCK_COORD && par2 >= -MAX_BLOCK_COORD && par1 < MAX_BLOCK_COORD && par2 < MAX_BLOCK_COORD) + { + if (!this.chunkExists(par1 >> 4, par2 >> 4)) + { + return 0; + } + else + { + Chunk chunk = this.getChunkFromChunkCoords(par1 >> 4, par2 >> 4); + return chunk.heightMapMinimum; + } + } + else + { + return 64; + } + } + + @SideOnly(Side.CLIENT) + public int getSkyBlockTypeBrightness(EnumSkyBlock par1EnumSkyBlock, int par2, int par3, int par4) + { + if (this.provider.hasNoSky && par1EnumSkyBlock == EnumSkyBlock.Sky) + { + return 0; + } + else + { + if (par3 < 0) + { + par3 = 0; + } + + if (par3 >= 256) + { + return par1EnumSkyBlock.defaultLightValue; + } + else if (par2 >= -MAX_BLOCK_COORD && par4 >= -MAX_BLOCK_COORD && par2 < MAX_BLOCK_COORD && par4 < MAX_BLOCK_COORD) + { + int l = par2 >> 4; + int i1 = par4 >> 4; + + if (!this.chunkExists(l, i1)) + { + return par1EnumSkyBlock.defaultLightValue; + } + else if (this.getBlock(par2, par3, par4).getUseNeighborBrightness()) + { + int j2 = this.getSavedLightValue(par1EnumSkyBlock, par2, par3 + 1, par4); + int j1 = this.getSavedLightValue(par1EnumSkyBlock, par2 + 1, par3, par4); + int k1 = this.getSavedLightValue(par1EnumSkyBlock, par2 - 1, par3, par4); + int l1 = this.getSavedLightValue(par1EnumSkyBlock, par2, par3, par4 + 1); + int i2 = this.getSavedLightValue(par1EnumSkyBlock, par2, par3, par4 - 1); + + if (j1 > j2) + { + j2 = j1; + } + + if (k1 > j2) + { + j2 = k1; + } + + if (l1 > j2) + { + j2 = l1; + } + + if (i2 > j2) + { + j2 = i2; + } + + return j2; + } + else + { + Chunk chunk = this.getChunkFromChunkCoords(l, i1); + return chunk.getSavedLightValue(par1EnumSkyBlock, par2 & 15, par3, par4 & 15); + } + } + else + { + return par1EnumSkyBlock.defaultLightValue; + } + } + } + + public int getSavedLightValue(EnumSkyBlock par1EnumSkyBlock, int par2, int par3, int par4) + { + if (par3 < 0) + { + par3 = 0; + } + + if (par3 >= 256) + { + par3 = 255; + } + + if (par2 >= -MAX_BLOCK_COORD && par4 >= -MAX_BLOCK_COORD && par2 < MAX_BLOCK_COORD && par4 < MAX_BLOCK_COORD) + { + int l = par2 >> 4; + int i1 = par4 >> 4; + + if (!this.chunkExists(l, i1)) + { + return par1EnumSkyBlock.defaultLightValue; + } + else + { + Chunk chunk = this.getChunkFromChunkCoords(l, i1); + return chunk.getSavedLightValue(par1EnumSkyBlock, par2 & 15, par3, par4 & 15); + } + } + else + { + return par1EnumSkyBlock.defaultLightValue; + } + } + + public void setLightValue(EnumSkyBlock par1EnumSkyBlock, int par2, int par3, int par4, int par5) + { + if (par2 >= -MAX_BLOCK_COORD && par4 >= -MAX_BLOCK_COORD && par2 < MAX_BLOCK_COORD && par4 < MAX_BLOCK_COORD) + { + if (par3 >= 0) + { + if (par3 < 256) + { + if (this.chunkExists(par2 >> 4, par4 >> 4)) + { + Chunk chunk = this.getChunkFromChunkCoords(par2 >> 4, par4 >> 4); + chunk.setLightValue(par1EnumSkyBlock, par2 & 15, par3, par4 & 15, par5); + + for (int i1 = 0; i1 < this.worldAccesses.size(); ++i1) + { + ((IWorldAccess)this.worldAccesses.get(i1)).markBlockForRenderUpdate(par2, par3, par4); + } + } + } + } + } + } + + public void func_147479_m(int p_147479_1_, int p_147479_2_, int p_147479_3_) + { + for (int l = 0; l < this.worldAccesses.size(); ++l) + { + ((IWorldAccess)this.worldAccesses.get(l)).markBlockForRenderUpdate(p_147479_1_, p_147479_2_, p_147479_3_); + } + } + + @SideOnly(Side.CLIENT) + public int getLightBrightnessForSkyBlocks(int par1, int par2, int par3, int par4) + { + int i1 = this.getSkyBlockTypeBrightness(EnumSkyBlock.Sky, par1, par2, par3); + int j1 = this.getSkyBlockTypeBrightness(EnumSkyBlock.Block, par1, par2, par3); + + if (j1 < par4) + { + j1 = par4; + } + + return i1 << 20 | j1 << 4; + } + + public float getLightBrightness(int par1, int par2, int par3) + { + return this.provider.lightBrightnessTable[this.getBlockLightValue(par1, par2, par3)]; + } + + public boolean isDaytime() + { + return provider.isDaytime(); + } + + public MovingObjectPosition rayTraceBlocks(Vec3 par1Vec3, Vec3 par2Vec3) + { + return this.func_147447_a(par1Vec3, par2Vec3, false, false, false); + } + + public MovingObjectPosition rayTraceBlocks(Vec3 par1Vec3, Vec3 par2Vec3, boolean par3) + { + return this.func_147447_a(par1Vec3, par2Vec3, par3, false, false); + } + + public MovingObjectPosition func_147447_a(Vec3 p_147447_1_, Vec3 p_147447_2_, boolean p_147447_3_, boolean p_147447_4_, boolean p_147447_5_) + { + if (!Double.isNaN(p_147447_1_.xCoord) && !Double.isNaN(p_147447_1_.yCoord) && !Double.isNaN(p_147447_1_.zCoord)) + { + if (!Double.isNaN(p_147447_2_.xCoord) && !Double.isNaN(p_147447_2_.yCoord) && !Double.isNaN(p_147447_2_.zCoord)) + { + int i = MathHelper.floor_double(p_147447_2_.xCoord); + int j = MathHelper.floor_double(p_147447_2_.yCoord); + int k = MathHelper.floor_double(p_147447_2_.zCoord); + int l = MathHelper.floor_double(p_147447_1_.xCoord); + int i1 = MathHelper.floor_double(p_147447_1_.yCoord); + int j1 = MathHelper.floor_double(p_147447_1_.zCoord); + Block block = this.getBlock(l, i1, j1); + int k1 = this.getBlockMetadata(l, i1, j1); + + if ((!p_147447_4_ || block.getCollisionBoundingBoxFromPool(this, l, i1, j1) != null) && block.canCollideCheck(k1, p_147447_3_)) + { + MovingObjectPosition movingobjectposition = block.collisionRayTrace(this, l, i1, j1, p_147447_1_, p_147447_2_); + + if (movingobjectposition != null) + { + return movingobjectposition; + } + } + + MovingObjectPosition movingobjectposition2 = null; + k1 = 200; + + while (k1-- >= 0) + { + if (Double.isNaN(p_147447_1_.xCoord) || Double.isNaN(p_147447_1_.yCoord) || Double.isNaN(p_147447_1_.zCoord)) + { + return null; + } + + if (l == i && i1 == j && j1 == k) + { + return p_147447_5_ ? movingobjectposition2 : null; + } + + boolean flag6 = true; + boolean flag3 = true; + boolean flag4 = true; + double d0 = 999.0D; + double d1 = 999.0D; + double d2 = 999.0D; + + if (i > l) + { + d0 = (double)l + 1.0D; + } + else if (i < l) + { + d0 = (double)l + 0.0D; + } + else + { + flag6 = false; + } + + if (j > i1) + { + d1 = (double)i1 + 1.0D; + } + else if (j < i1) + { + d1 = (double)i1 + 0.0D; + } + else + { + flag3 = false; + } + + if (k > j1) + { + d2 = (double)j1 + 1.0D; + } + else if (k < j1) + { + d2 = (double)j1 + 0.0D; + } + else + { + flag4 = false; + } + + double d3 = 999.0D; + double d4 = 999.0D; + double d5 = 999.0D; + double d6 = p_147447_2_.xCoord - p_147447_1_.xCoord; + double d7 = p_147447_2_.yCoord - p_147447_1_.yCoord; + double d8 = p_147447_2_.zCoord - p_147447_1_.zCoord; + + if (flag6) + { + d3 = (d0 - p_147447_1_.xCoord) / d6; + } + + if (flag3) + { + d4 = (d1 - p_147447_1_.yCoord) / d7; + } + + if (flag4) + { + d5 = (d2 - p_147447_1_.zCoord) / d8; + } + + boolean flag5 = false; + byte b0; + + if (d3 < d4 && d3 < d5) + { + if (i > l) + { + b0 = 4; + } + else + { + b0 = 5; + } + + p_147447_1_.xCoord = d0; + p_147447_1_.yCoord += d7 * d3; + p_147447_1_.zCoord += d8 * d3; + } + else if (d4 < d5) + { + if (j > i1) + { + b0 = 0; + } + else + { + b0 = 1; + } + + p_147447_1_.xCoord += d6 * d4; + p_147447_1_.yCoord = d1; + p_147447_1_.zCoord += d8 * d4; + } + else + { + if (k > j1) + { + b0 = 2; + } + else + { + b0 = 3; + } + + p_147447_1_.xCoord += d6 * d5; + p_147447_1_.yCoord += d7 * d5; + p_147447_1_.zCoord = d2; + } + + Vec3 vec32 = this.getWorldVec3Pool().getVecFromPool(p_147447_1_.xCoord, p_147447_1_.yCoord, p_147447_1_.zCoord); + l = (int)(vec32.xCoord = (double)MathHelper.floor_double(p_147447_1_.xCoord)); + + if (b0 == 5) + { + --l; + ++vec32.xCoord; + } + + i1 = (int)(vec32.yCoord = (double)MathHelper.floor_double(p_147447_1_.yCoord)); + + if (b0 == 1) + { + --i1; + ++vec32.yCoord; + } + + j1 = (int)(vec32.zCoord = (double)MathHelper.floor_double(p_147447_1_.zCoord)); + + if (b0 == 3) + { + --j1; + ++vec32.zCoord; + } + + Block block1 = this.getBlock(l, i1, j1); + int l1 = this.getBlockMetadata(l, i1, j1); + + if (!p_147447_4_ || block1.getCollisionBoundingBoxFromPool(this, l, i1, j1) != null) + { + if (block1.canCollideCheck(l1, p_147447_3_)) + { + MovingObjectPosition movingobjectposition1 = block1.collisionRayTrace(this, l, i1, j1, p_147447_1_, p_147447_2_); + + if (movingobjectposition1 != null) + { + return movingobjectposition1; + } + } + else + { + movingobjectposition2 = new MovingObjectPosition(l, i1, j1, b0, p_147447_1_, false); + } + } + } + + return p_147447_5_ ? movingobjectposition2 : null; + } + else + { + return null; + } + } + else + { + return null; + } + } + + public void playSoundAtEntity(Entity par1Entity, String par2Str, float par3, float par4) + { + PlaySoundAtEntityEvent event = new PlaySoundAtEntityEvent(par1Entity, par2Str, par3, par4); + if (MinecraftForge.EVENT_BUS.post(event)) + { + return; + } + par2Str = event.name; + for (int i = 0; i < this.worldAccesses.size(); ++i) + { + ((IWorldAccess)this.worldAccesses.get(i)).playSound(par2Str, par1Entity.posX, par1Entity.posY - (double)par1Entity.yOffset, par1Entity.posZ, par3, par4); + } + } + + public void playSoundToNearExcept(EntityPlayer par1EntityPlayer, String par2Str, float par3, float par4) + { + PlaySoundAtEntityEvent event = new PlaySoundAtEntityEvent(par1EntityPlayer, par2Str, par3, par4); + if (MinecraftForge.EVENT_BUS.post(event)) + { + return; + } + par2Str = event.name; + for (int i = 0; i < this.worldAccesses.size(); ++i) + { + ((IWorldAccess)this.worldAccesses.get(i)).playSoundToNearExcept(par1EntityPlayer, par2Str, par1EntityPlayer.posX, par1EntityPlayer.posY - (double)par1EntityPlayer.yOffset, par1EntityPlayer.posZ, par3, par4); + } + } + + public void playSoundEffect(double par1, double par3, double par5, String par7Str, float par8, float par9) + { + for (int i = 0; i < this.worldAccesses.size(); ++i) + { + ((IWorldAccess)this.worldAccesses.get(i)).playSound(par7Str, par1, par3, par5, par8, par9); + } + } + + public void playSound(double par1, double par3, double par5, String par7Str, float par8, float par9, boolean par10) {} + + public void playRecord(String par1Str, int par2, int par3, int par4) + { + for (int l = 0; l < this.worldAccesses.size(); ++l) + { + ((IWorldAccess)this.worldAccesses.get(l)).playRecord(par1Str, par2, par3, par4); + } + } + + public void spawnParticle(String par1Str, double par2, double par4, double par6, double par8, double par10, double par12) + { + for (int i = 0; i < this.worldAccesses.size(); ++i) + { + ((IWorldAccess)this.worldAccesses.get(i)).spawnParticle(par1Str, par2, par4, par6, par8, par10, par12); + } + } + + public boolean addWeatherEffect(Entity par1Entity) + { + this.weatherEffects.add(par1Entity); + return true; + } + + public boolean spawnEntityInWorld(Entity par1Entity) + { + int i = MathHelper.floor_double(par1Entity.posX / 16.0D); + int j = MathHelper.floor_double(par1Entity.posZ / 16.0D); + boolean flag = par1Entity.forceSpawn; + + if (par1Entity instanceof EntityPlayer) + { + flag = true; + } + + if (!flag && !this.chunkExists(i, j)) + { + return false; + } + else + { + if (par1Entity instanceof EntityPlayer) + { + EntityPlayer entityplayer = (EntityPlayer)par1Entity; + this.playerEntities.add(entityplayer); + this.updateAllPlayersSleepingFlag(); + } + if (MinecraftForge.EVENT_BUS.post(new EntityJoinWorldEvent(par1Entity, this)) && !flag) return false; + + this.getChunkFromChunkCoords(i, j).addEntity(par1Entity); + this.loadedEntityList.add(par1Entity); + this.onEntityAdded(par1Entity); + return true; + } + } + + public void onEntityAdded(Entity par1Entity) + { + for (int i = 0; i < this.worldAccesses.size(); ++i) + { + ((IWorldAccess)this.worldAccesses.get(i)).onEntityCreate(par1Entity); + } + } + + public void onEntityRemoved(Entity par1Entity) + { + for (int i = 0; i < this.worldAccesses.size(); ++i) + { + ((IWorldAccess)this.worldAccesses.get(i)).onEntityDestroy(par1Entity); + } + } + + public void removeEntity(Entity par1Entity) + { + if (par1Entity.riddenByEntity != null) + { + par1Entity.riddenByEntity.mountEntity((Entity)null); + } + + if (par1Entity.ridingEntity != null) + { + par1Entity.mountEntity((Entity)null); + } + + par1Entity.setDead(); + + if (par1Entity instanceof EntityPlayer) + { + this.playerEntities.remove(par1Entity); + this.updateAllPlayersSleepingFlag(); + } + } + + public void removePlayerEntityDangerously(Entity par1Entity) + { + par1Entity.setDead(); + + if (par1Entity instanceof EntityPlayer) + { + this.playerEntities.remove(par1Entity); + this.updateAllPlayersSleepingFlag(); + } + + int i = par1Entity.chunkCoordX; + int j = par1Entity.chunkCoordZ; + + if (par1Entity.addedToChunk && this.chunkExists(i, j)) + { + this.getChunkFromChunkCoords(i, j).removeEntity(par1Entity); + } + + this.loadedEntityList.remove(par1Entity); + this.onEntityRemoved(par1Entity); + } + + public void addWorldAccess(IWorldAccess par1IWorldAccess) + { + this.worldAccesses.add(par1IWorldAccess); + } + + public List getCollidingBoundingBoxes(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB) + { + this.collidingBoundingBoxes.clear(); + int i = MathHelper.floor_double(par2AxisAlignedBB.minX); + int j = MathHelper.floor_double(par2AxisAlignedBB.maxX + 1.0D); + int k = MathHelper.floor_double(par2AxisAlignedBB.minY); + int l = MathHelper.floor_double(par2AxisAlignedBB.maxY + 1.0D); + int i1 = MathHelper.floor_double(par2AxisAlignedBB.minZ); + int j1 = MathHelper.floor_double(par2AxisAlignedBB.maxZ + 1.0D); + + for (int k1 = i; k1 < j; ++k1) + { + for (int l1 = i1; l1 < j1; ++l1) + { + if (this.blockExists(k1, 64, l1)) + { + for (int i2 = k - 1; i2 < l; ++i2) + { + Block block; + + if (k1 >= -MAX_BLOCK_COORD && k1 < MAX_BLOCK_COORD && l1 >= -MAX_BLOCK_COORD && l1 < MAX_BLOCK_COORD) + { + block = this.getBlock(k1, i2, l1); + } + else + { + block = Blocks.stone; + } + + block.addCollisionBoxesToList(this, k1, i2, l1, par2AxisAlignedBB, this.collidingBoundingBoxes, par1Entity); + } + } + } + } + + double d0 = 0.25D; + List list = this.getEntitiesWithinAABBExcludingEntity(par1Entity, par2AxisAlignedBB.expand(d0, d0, d0)); + + for (int j2 = 0; j2 < list.size(); ++j2) + { + AxisAlignedBB axisalignedbb1 = ((Entity)list.get(j2)).getBoundingBox(); + + if (axisalignedbb1 != null && axisalignedbb1.intersectsWith(par2AxisAlignedBB)) + { + this.collidingBoundingBoxes.add(axisalignedbb1); + } + + axisalignedbb1 = par1Entity.getCollisionBox((Entity)list.get(j2)); + + if (axisalignedbb1 != null && axisalignedbb1.intersectsWith(par2AxisAlignedBB)) + { + this.collidingBoundingBoxes.add(axisalignedbb1); + } + } + + return this.collidingBoundingBoxes; + } + + public List func_147461_a(AxisAlignedBB p_147461_1_) + { + this.collidingBoundingBoxes.clear(); + int i = MathHelper.floor_double(p_147461_1_.minX); + int j = MathHelper.floor_double(p_147461_1_.maxX + 1.0D); + int k = MathHelper.floor_double(p_147461_1_.minY); + int l = MathHelper.floor_double(p_147461_1_.maxY + 1.0D); + int i1 = MathHelper.floor_double(p_147461_1_.minZ); + int j1 = MathHelper.floor_double(p_147461_1_.maxZ + 1.0D); + + for (int k1 = i; k1 < j; ++k1) + { + for (int l1 = i1; l1 < j1; ++l1) + { + if (this.blockExists(k1, 64, l1)) + { + for (int i2 = k - 1; i2 < l; ++i2) + { + Block block; + + if (k1 >= -MAX_BLOCK_COORD && k1 < MAX_BLOCK_COORD && l1 >= -MAX_BLOCK_COORD && l1 < MAX_BLOCK_COORD) + { + block = this.getBlock(k1, i2, l1); + } + else + { + block = Blocks.bedrock; + } + + block.addCollisionBoxesToList(this, k1, i2, l1, p_147461_1_, this.collidingBoundingBoxes, (Entity)null); + } + } + } + } + + return this.collidingBoundingBoxes; + } + + public int calculateSkylightSubtracted(float par1) + { + float f1 = this.getCelestialAngle(par1); + float f2 = 1.0F - (MathHelper.cos(f1 * (float)Math.PI * 2.0F) * 2.0F + 0.5F); + + if (f2 < 0.0F) + { + f2 = 0.0F; + } + + if (f2 > 1.0F) + { + f2 = 1.0F; + } + + f2 = 1.0F - f2; + f2 = (float)((double)f2 * (1.0D - (double)(this.getRainStrength(par1) * 5.0F) / 16.0D)); + f2 = (float)((double)f2 * (1.0D - (double)(this.getWeightedThunderStrength(par1) * 5.0F) / 16.0D)); + f2 = 1.0F - f2; + return (int)(f2 * 11.0F); + } + + public void removeWorldAccess(IWorldAccess par1IWorldAccess) + { + this.worldAccesses.remove(par1IWorldAccess); + } + + @SideOnly(Side.CLIENT) + public float getSunBrightness(float par1) + { + float f1 = this.getCelestialAngle(par1); + float f2 = 1.0F - (MathHelper.cos(f1 * (float)Math.PI * 2.0F) * 2.0F + 0.2F); + + if (f2 < 0.0F) + { + f2 = 0.0F; + } + + if (f2 > 1.0F) + { + f2 = 1.0F; + } + + f2 = 1.0F - f2; + f2 = (float)((double)f2 * (1.0D - (double)(this.getRainStrength(par1) * 5.0F) / 16.0D)); + f2 = (float)((double)f2 * (1.0D - (double)(this.getWeightedThunderStrength(par1) * 5.0F) / 16.0D)); + return f2 * 0.8F + 0.2F; + } + + @SideOnly(Side.CLIENT) + public Vec3 getSkyColor(Entity par1Entity, float par2) + { + return provider.getSkyColor(par1Entity, par2); + } + + @SideOnly(Side.CLIENT) + public Vec3 getSkyColorBody(Entity par1Entity, float par2) + { + float f1 = this.getCelestialAngle(par2); + float f2 = MathHelper.cos(f1 * (float)Math.PI * 2.0F) * 2.0F + 0.5F; + + if (f2 < 0.0F) + { + f2 = 0.0F; + } + + if (f2 > 1.0F) + { + f2 = 1.0F; + } + + int i = MathHelper.floor_double(par1Entity.posX); + int j = MathHelper.floor_double(par1Entity.posY); + int k = MathHelper.floor_double(par1Entity.posZ); + int l = ForgeHooksClient.getSkyBlendColour(this, i, j, k); + float f4 = (float)(l >> 16 & 255) / 255.0F; + float f5 = (float)(l >> 8 & 255) / 255.0F; + float f6 = (float)(l & 255) / 255.0F; + f4 *= f2; + f5 *= f2; + f6 *= f2; + float f7 = this.getRainStrength(par2); + float f8; + float f9; + + if (f7 > 0.0F) + { + f8 = (f4 * 0.3F + f5 * 0.59F + f6 * 0.11F) * 0.6F; + f9 = 1.0F - f7 * 0.75F; + f4 = f4 * f9 + f8 * (1.0F - f9); + f5 = f5 * f9 + f8 * (1.0F - f9); + f6 = f6 * f9 + f8 * (1.0F - f9); + } + + f8 = this.getWeightedThunderStrength(par2); + + if (f8 > 0.0F) + { + f9 = (f4 * 0.3F + f5 * 0.59F + f6 * 0.11F) * 0.2F; + float f10 = 1.0F - f8 * 0.75F; + f4 = f4 * f10 + f9 * (1.0F - f10); + f5 = f5 * f10 + f9 * (1.0F - f10); + f6 = f6 * f10 + f9 * (1.0F - f10); + } + + if (this.lastLightningBolt > 0) + { + f9 = (float)this.lastLightningBolt - par2; + + if (f9 > 1.0F) + { + f9 = 1.0F; + } + + f9 *= 0.45F; + f4 = f4 * (1.0F - f9) + 0.8F * f9; + f5 = f5 * (1.0F - f9) + 0.8F * f9; + f6 = f6 * (1.0F - f9) + 1.0F * f9; + } + + return this.getWorldVec3Pool().getVecFromPool((double)f4, (double)f5, (double)f6); + } + + public float getCelestialAngle(float par1) + { + return this.provider.calculateCelestialAngle(this.worldInfo.getWorldTime(), par1); + } + + @SideOnly(Side.CLIENT) + public int getMoonPhase() + { + return this.provider.getMoonPhase(this.worldInfo.getWorldTime()); + } + + public float getCurrentMoonPhaseFactor() + { + return WorldProvider.moonPhaseFactors[this.provider.getMoonPhase(this.worldInfo.getWorldTime())]; + } + + public float getCelestialAngleRadians(float par1) + { + float f1 = this.getCelestialAngle(par1); + return f1 * (float)Math.PI * 2.0F; + } + + @SideOnly(Side.CLIENT) + public Vec3 getCloudColour(float par1) + { + return provider.drawClouds(par1); + } + + @SideOnly(Side.CLIENT) + public Vec3 drawCloudsBody(float par1) + { + float f1 = this.getCelestialAngle(par1); + float f2 = MathHelper.cos(f1 * (float)Math.PI * 2.0F) * 2.0F + 0.5F; + + if (f2 < 0.0F) + { + f2 = 0.0F; + } + + if (f2 > 1.0F) + { + f2 = 1.0F; + } + + float f3 = (float)(this.cloudColour >> 16 & 255L) / 255.0F; + float f4 = (float)(this.cloudColour >> 8 & 255L) / 255.0F; + float f5 = (float)(this.cloudColour & 255L) / 255.0F; + float f6 = this.getRainStrength(par1); + float f7; + float f8; + + if (f6 > 0.0F) + { + f7 = (f3 * 0.3F + f4 * 0.59F + f5 * 0.11F) * 0.6F; + f8 = 1.0F - f6 * 0.95F; + f3 = f3 * f8 + f7 * (1.0F - f8); + f4 = f4 * f8 + f7 * (1.0F - f8); + f5 = f5 * f8 + f7 * (1.0F - f8); + } + + f3 *= f2 * 0.9F + 0.1F; + f4 *= f2 * 0.9F + 0.1F; + f5 *= f2 * 0.85F + 0.15F; + f7 = this.getWeightedThunderStrength(par1); + + if (f7 > 0.0F) + { + f8 = (f3 * 0.3F + f4 * 0.59F + f5 * 0.11F) * 0.2F; + float f9 = 1.0F - f7 * 0.95F; + f3 = f3 * f9 + f8 * (1.0F - f9); + f4 = f4 * f9 + f8 * (1.0F - f9); + f5 = f5 * f9 + f8 * (1.0F - f9); + } + + return this.getWorldVec3Pool().getVecFromPool((double)f3, (double)f4, (double)f5); + } + + @SideOnly(Side.CLIENT) + public Vec3 getFogColor(float par1) + { + float f1 = this.getCelestialAngle(par1); + return this.provider.getFogColor(f1, par1); + } + + public int getPrecipitationHeight(int par1, int par2) + { + return this.getChunkFromBlockCoords(par1, par2).getPrecipitationHeight(par1 & 15, par2 & 15); + } + + public int getTopSolidOrLiquidBlock(int par1, int par2) + { + Chunk chunk = this.getChunkFromBlockCoords(par1, par2); + int x = par1; + int z = par2; + int k = chunk.getTopFilledSegment() + 15; + par1 &= 15; + + for (par2 &= 15; k > 0; --k) + { + Block block = chunk.getBlock(par1, k, par2); + + if (block.getMaterial().blocksMovement() && block.getMaterial() != Material.leaves && !block.isFoliage(this, x, k, z)) + { + return k + 1; + } + } + + return -1; + } + + @SideOnly(Side.CLIENT) + public float getStarBrightness(float par1) + { + return provider.getStarBrightness(par1); + } + + @SideOnly(Side.CLIENT) + public float getStarBrightnessBody(float par1) + { + float f1 = this.getCelestialAngle(par1); + float f2 = 1.0F - (MathHelper.cos(f1 * (float)Math.PI * 2.0F) * 2.0F + 0.25F); + + if (f2 < 0.0F) + { + f2 = 0.0F; + } + + if (f2 > 1.0F) + { + f2 = 1.0F; + } + + return f2 * f2 * 0.5F; + } + + public void scheduleBlockUpdate(int p_147464_1_, int p_147464_2_, int p_147464_3_, Block p_147464_4_, int p_147464_5_) {} + + public void scheduleBlockUpdateWithPriority(int p_147454_1_, int p_147454_2_, int p_147454_3_, Block p_147454_4_, int p_147454_5_, int p_147454_6_) {} + + public void func_147446_b(int p_147446_1_, int p_147446_2_, int p_147446_3_, Block p_147446_4_, int p_147446_5_, int p_147446_6_) {} + + public void updateEntities() + { + this.theProfiler.startSection("entities"); + this.theProfiler.startSection("global"); + int i; + Entity entity; + CrashReport crashreport; + CrashReportCategory crashreportcategory; + + for (i = 0; i < this.weatherEffects.size(); ++i) + { + entity = (Entity)this.weatherEffects.get(i); + + try + { + ++entity.ticksExisted; + entity.onUpdate(); + } + catch (Throwable throwable2) + { + crashreport = CrashReport.makeCrashReport(throwable2, "Ticking entity"); + crashreportcategory = crashreport.makeCategory("Entity being ticked"); + + if (entity == null) + { + crashreportcategory.addCrashSection("Entity", "~~NULL~~"); + } + else + { + entity.addEntityCrashInfo(crashreportcategory); + } + + if (ForgeModContainer.removeErroringEntities) + { + FMLLog.severe(crashreport.getCompleteReport()); + removeEntity(entity); + } + else + { + throw new ReportedException(crashreport); + } + } + + if (entity.isDead) + { + this.weatherEffects.remove(i--); + } + } + + this.theProfiler.endStartSection("remove"); + this.loadedEntityList.removeAll(this.unloadedEntityList); + int j; + int l; + + for (i = 0; i < this.unloadedEntityList.size(); ++i) + { + entity = (Entity)this.unloadedEntityList.get(i); + j = entity.chunkCoordX; + l = entity.chunkCoordZ; + + if (entity.addedToChunk && this.chunkExists(j, l)) + { + this.getChunkFromChunkCoords(j, l).removeEntity(entity); + } + } + + for (i = 0; i < this.unloadedEntityList.size(); ++i) + { + this.onEntityRemoved((Entity)this.unloadedEntityList.get(i)); + } + + this.unloadedEntityList.clear(); + this.theProfiler.endStartSection("regular"); + + for (i = 0; i < this.loadedEntityList.size(); ++i) + { + entity = (Entity)this.loadedEntityList.get(i); + + if (entity.ridingEntity != null) + { + if (!entity.ridingEntity.isDead && entity.ridingEntity.riddenByEntity == entity) + { + continue; + } + + entity.ridingEntity.riddenByEntity = null; + entity.ridingEntity = null; + } + + this.theProfiler.startSection("tick"); + + if (!entity.isDead) + { + try + { + this.updateEntity(entity); + } + catch (Throwable throwable1) + { + crashreport = CrashReport.makeCrashReport(throwable1, "Ticking entity"); + crashreportcategory = crashreport.makeCategory("Entity being ticked"); + entity.addEntityCrashInfo(crashreportcategory); + + if (ForgeModContainer.removeErroringEntities) + { + FMLLog.severe(crashreport.getCompleteReport()); + removeEntity(entity); + } + else + { + throw new ReportedException(crashreport); + } + } + } + + this.theProfiler.endSection(); + this.theProfiler.startSection("remove"); + + if (entity.isDead) + { + j = entity.chunkCoordX; + l = entity.chunkCoordZ; + + if (entity.addedToChunk && this.chunkExists(j, l)) + { + this.getChunkFromChunkCoords(j, l).removeEntity(entity); + } + + this.loadedEntityList.remove(i--); + this.onEntityRemoved(entity); + } + + this.theProfiler.endSection(); + } + + this.theProfiler.endStartSection("blockEntities"); + this.field_147481_N = true; + Iterator iterator = this.loadedTileEntityList.iterator(); + + while (iterator.hasNext()) + { + TileEntity tileentity = (TileEntity)iterator.next(); + + if (!tileentity.isInvalid() && tileentity.hasWorldObj() && activeChunkSet.containsKey(ChunkHash.chunkToKey(tileentity.xCoord >> 4, tileentity.zCoord >> 4))) + { + try + { + tileentity.updateEntity(); + } + catch (Throwable throwable) + { + crashreport = CrashReport.makeCrashReport(throwable, "Ticking block entity"); + crashreportcategory = crashreport.makeCategory("Block entity being ticked"); + tileentity.func_145828_a(crashreportcategory); + if (ForgeModContainer.removeErroringTileEntities) + { + FMLLog.severe(crashreport.getCompleteReport()); + tileentity.invalidate(); + setBlockToAir(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord); + } + else + { + throw new ReportedException(crashreport); + } + } + } + + if (tileentity.isInvalid()) + { + iterator.remove(); + + if (this.chunkExists(tileentity.xCoord >> 4, tileentity.zCoord >> 4)) + { + Chunk chunk = this.getChunkFromChunkCoords(tileentity.xCoord >> 4, tileentity.zCoord >> 4); + + if (chunk != null) + { + chunk.removeInvalidTileEntity(tileentity.xCoord & 15, tileentity.yCoord, tileentity.zCoord & 15); + } + } + } + } + + if (!this.field_147483_b.isEmpty()) + { + for (Object tile : field_147483_b) + { + ((TileEntity)tile).onChunkUnload(); + } + this.loadedTileEntityList.removeAll(this.field_147483_b); + this.field_147483_b.clear(); + } + + this.field_147481_N = false; + + this.theProfiler.endStartSection("pendingBlockEntities"); + + if (!this.addedTileEntityList.isEmpty()) + { + for (int k = 0; k < this.addedTileEntityList.size(); ++k) + { + TileEntity tileentity1 = (TileEntity)this.addedTileEntityList.get(k); + + if (!tileentity1.isInvalid()) + { + if (!this.loadedTileEntityList.contains(tileentity1)) + { + this.loadedTileEntityList.add(tileentity1); + } + } + else + { + if (this.chunkExists(tileentity1.xCoord >> 4, tileentity1.zCoord >> 4)) + { + Chunk chunk1 = this.getChunkFromChunkCoords(tileentity1.xCoord >> 4, tileentity1.zCoord >> 4); + + if (chunk1 != null) + { + chunk1.removeInvalidTileEntity(tileentity1.xCoord & 15, tileentity1.yCoord, tileentity1.zCoord & 15); + } + } + } + } + + this.addedTileEntityList.clear(); + } + + this.theProfiler.endSection(); + this.theProfiler.endSection(); + } + + public void func_147448_a(Collection p_147448_1_) + { + List dest = field_147481_N ? addedTileEntityList : loadedTileEntityList; + for(TileEntity entity : (Collection)p_147448_1_) + { + if(entity.canUpdate()) dest.add(entity); + } + } + + public void updateEntity(Entity par1Entity) + { + this.updateEntityWithOptionalForce(par1Entity, true); + } + + public void updateEntityWithOptionalForce(Entity par1Entity, boolean par2) + { + int i = MathHelper.floor_double(par1Entity.posX); + int j = MathHelper.floor_double(par1Entity.posZ); + //boolean isForced = getPersistentChunks().containsKey(new ChunkCoordIntPair(i >> 4, j >> 4)); + //byte b0 = isForced ? (byte)0 : 32; + //boolean canUpdate = !par2 || this.checkChunksExist(i - b0, 0, j - b0, i + b0, 0, j + b0); + boolean canUpdate = par1Entity.isEntityPlayerMP() || activeChunkSet.containsKey(ChunkHash.chunkToKey(i >> 4, j >> 4)) && this.chunkRoundExists(i >> 4, j >> 4, 3); + + //if (!canUpdate) + //{ + // EntityEvent.CanUpdate event = new EntityEvent.CanUpdate(par1Entity); + // MinecraftForge.EVENT_BUS.post(event); + // canUpdate = event.canUpdate; + //} + + if (canUpdate) + { + par1Entity.lastTickPosX = par1Entity.posX; + par1Entity.lastTickPosY = par1Entity.posY; + par1Entity.lastTickPosZ = par1Entity.posZ; + par1Entity.prevRotationYaw = par1Entity.rotationYaw; + par1Entity.prevRotationPitch = par1Entity.rotationPitch; + + if (par2 && par1Entity.addedToChunk) + { + ++par1Entity.ticksExisted; + + if (par1Entity.ridingEntity != null) + { + par1Entity.updateRidden(); + } + else + { + par1Entity.onUpdate(); + } + } + + this.theProfiler.startSection("chunkCheck"); + + if (Double.isNaN(par1Entity.posX) || Double.isInfinite(par1Entity.posX)) + { + par1Entity.posX = par1Entity.lastTickPosX; + } + + if (Double.isNaN(par1Entity.posY) || Double.isInfinite(par1Entity.posY)) + { + par1Entity.posY = par1Entity.lastTickPosY; + } + + if (Double.isNaN(par1Entity.posZ) || Double.isInfinite(par1Entity.posZ)) + { + par1Entity.posZ = par1Entity.lastTickPosZ; + } + + if (Double.isNaN((double)par1Entity.rotationPitch) || Double.isInfinite((double)par1Entity.rotationPitch)) + { + par1Entity.rotationPitch = par1Entity.prevRotationPitch; + } + + if (Double.isNaN((double)par1Entity.rotationYaw) || Double.isInfinite((double)par1Entity.rotationYaw)) + { + par1Entity.rotationYaw = par1Entity.prevRotationYaw; + } + + int k = MathHelper.floor_double(par1Entity.posX / 16.0D); + int l = MathHelper.floor_double(par1Entity.posY / 16.0D); + int i1 = MathHelper.floor_double(par1Entity.posZ / 16.0D); + + if (!par1Entity.addedToChunk || par1Entity.chunkCoordX != k || par1Entity.chunkCoordY != l || par1Entity.chunkCoordZ != i1) + { + if (par1Entity.addedToChunk && this.chunkExists(par1Entity.chunkCoordX, par1Entity.chunkCoordZ)) + { + this.getChunkFromChunkCoords(par1Entity.chunkCoordX, par1Entity.chunkCoordZ).removeEntityAtIndex(par1Entity, par1Entity.chunkCoordY); + } + + if (this.chunkExists(k, i1)) + { + par1Entity.addedToChunk = true; + this.getChunkFromChunkCoords(k, i1).addEntity(par1Entity); + } + else + { + par1Entity.addedToChunk = false; + } + } + + this.theProfiler.endSection(); + + if (par2 && par1Entity.addedToChunk && par1Entity.riddenByEntity != null) + { + if (!par1Entity.riddenByEntity.isDead && par1Entity.riddenByEntity.ridingEntity == par1Entity) + { + this.updateEntity(par1Entity.riddenByEntity); + } + else + { + par1Entity.riddenByEntity.ridingEntity = null; + par1Entity.riddenByEntity = null; + } + } + } + } + + public boolean checkNoEntityCollision(AxisAlignedBB par1AxisAlignedBB) + { + return this.checkNoEntityCollision(par1AxisAlignedBB, (Entity)null); + } + + public boolean checkNoEntityCollision(AxisAlignedBB par1AxisAlignedBB, Entity par2Entity) + { + List list = this.getEntitiesWithinAABBExcludingEntity((Entity)null, par1AxisAlignedBB); + + for (int i = 0; i < list.size(); ++i) + { + Entity entity1 = (Entity)list.get(i); + + if (!entity1.isDead && entity1.preventEntitySpawning && entity1 != par2Entity) + { + return false; + } + } + + return true; + } + + public boolean checkBlockCollision(AxisAlignedBB par1AxisAlignedBB) + { + int i = MathHelper.floor_double(par1AxisAlignedBB.minX); + int j = MathHelper.floor_double(par1AxisAlignedBB.maxX + 1.0D); + int k = MathHelper.floor_double(par1AxisAlignedBB.minY); + int l = MathHelper.floor_double(par1AxisAlignedBB.maxY + 1.0D); + int i1 = MathHelper.floor_double(par1AxisAlignedBB.minZ); + int j1 = MathHelper.floor_double(par1AxisAlignedBB.maxZ + 1.0D); + + if (par1AxisAlignedBB.minX < 0.0D) + { + --i; + } + + if (par1AxisAlignedBB.minY < 0.0D) + { + --k; + } + + if (par1AxisAlignedBB.minZ < 0.0D) + { + --i1; + } + + for (int k1 = i; k1 < j; ++k1) + { + for (int l1 = k; l1 < l; ++l1) + { + for (int i2 = i1; i2 < j1; ++i2) + { + Block block = this.getBlock(k1, l1, i2); + + if (block.getMaterial() != Material.air) + { + return true; + } + } + } + } + + return false; + } + + public boolean isAnyLiquid(AxisAlignedBB par1AxisAlignedBB) + { + int i = MathHelper.floor_double(par1AxisAlignedBB.minX); + int j = MathHelper.floor_double(par1AxisAlignedBB.maxX + 1.0D); + int k = MathHelper.floor_double(par1AxisAlignedBB.minY); + int l = MathHelper.floor_double(par1AxisAlignedBB.maxY + 1.0D); + int i1 = MathHelper.floor_double(par1AxisAlignedBB.minZ); + int j1 = MathHelper.floor_double(par1AxisAlignedBB.maxZ + 1.0D); + + if (par1AxisAlignedBB.minX < 0.0D) + { + --i; + } + + if (par1AxisAlignedBB.minY < 0.0D) + { + --k; + } + + if (par1AxisAlignedBB.minZ < 0.0D) + { + --i1; + } + + for (int k1 = i; k1 < j; ++k1) + { + for (int l1 = k; l1 < l; ++l1) + { + for (int i2 = i1; i2 < j1; ++i2) + { + Block block = this.getBlock(k1, l1, i2); + + if (block.getMaterial().isLiquid()) + { + return true; + } + } + } + } + + return false; + } + + public boolean func_147470_e(AxisAlignedBB p_147470_1_) + { + int i = MathHelper.floor_double(p_147470_1_.minX); + int j = MathHelper.floor_double(p_147470_1_.maxX + 1.0D); + int k = MathHelper.floor_double(p_147470_1_.minY); + int l = MathHelper.floor_double(p_147470_1_.maxY + 1.0D); + int i1 = MathHelper.floor_double(p_147470_1_.minZ); + int j1 = MathHelper.floor_double(p_147470_1_.maxZ + 1.0D); + + if (this.checkChunksExist(i, k, i1, j, l, j1)) + { + for (int k1 = i; k1 < j; ++k1) + { + for (int l1 = k; l1 < l; ++l1) + { + for (int i2 = i1; i2 < j1; ++i2) + { + Block block = this.getBlock(k1, l1, i2); + + if (block == Blocks.fire || block == Blocks.flowing_lava || block == Blocks.lava) + { + return true; + } + else + { + if (block.isBurning(this, k1, l1, i2)) return true; + } + } + } + } + } + + return false; + } + + public boolean handleMaterialAcceleration(AxisAlignedBB par1AxisAlignedBB, Material par2Material, Entity par3Entity) + { + int i = MathHelper.floor_double(par1AxisAlignedBB.minX); + int j = MathHelper.floor_double(par1AxisAlignedBB.maxX + 1.0D); + int k = MathHelper.floor_double(par1AxisAlignedBB.minY); + int l = MathHelper.floor_double(par1AxisAlignedBB.maxY + 1.0D); + int i1 = MathHelper.floor_double(par1AxisAlignedBB.minZ); + int j1 = MathHelper.floor_double(par1AxisAlignedBB.maxZ + 1.0D); + + if (!this.checkChunksExist(i, k, i1, j, l, j1)) + { + return false; + } + else + { + boolean flag = false; + Vec3 vec3 = this.getWorldVec3Pool().getVecFromPool(0.0D, 0.0D, 0.0D); + + for (int k1 = i; k1 < j; ++k1) + { + for (int l1 = k; l1 < l; ++l1) + { + for (int i2 = i1; i2 < j1; ++i2) + { + Block block = this.getBlock(k1, l1, i2); + + if (block.getMaterial() == par2Material) + { + double d0 = (double)((float)(l1 + 1) - BlockLiquid.getLiquidHeightPercent(this.getBlockMetadata(k1, l1, i2))); + + if ((double)l >= d0) + { + flag = true; + block.velocityToAddToEntity(this, k1, l1, i2, par3Entity, vec3); + } + } + } + } + } + + if (vec3.lengthVector() > 0.0D && par3Entity.isPushedByWater()) + { + vec3 = vec3.normalize(); + double d1 = 0.014D; + par3Entity.motionX += vec3.xCoord * d1; + par3Entity.motionY += vec3.yCoord * d1; + par3Entity.motionZ += vec3.zCoord * d1; + } + + return flag; + } + } + + public boolean isMaterialInBB(AxisAlignedBB par1AxisAlignedBB, Material par2Material) + { + int i = MathHelper.floor_double(par1AxisAlignedBB.minX); + int j = MathHelper.floor_double(par1AxisAlignedBB.maxX + 1.0D); + int k = MathHelper.floor_double(par1AxisAlignedBB.minY); + int l = MathHelper.floor_double(par1AxisAlignedBB.maxY + 1.0D); + int i1 = MathHelper.floor_double(par1AxisAlignedBB.minZ); + int j1 = MathHelper.floor_double(par1AxisAlignedBB.maxZ + 1.0D); + + for (int k1 = i; k1 < j; ++k1) + { + for (int l1 = k; l1 < l; ++l1) + { + for (int i2 = i1; i2 < j1; ++i2) + { + if (this.getBlock(k1, l1, i2).getMaterial() == par2Material) + { + return true; + } + } + } + } + + return false; + } + + public boolean isAABBInMaterial(AxisAlignedBB par1AxisAlignedBB, Material par2Material) + { + int i = MathHelper.floor_double(par1AxisAlignedBB.minX); + int j = MathHelper.floor_double(par1AxisAlignedBB.maxX + 1.0D); + int k = MathHelper.floor_double(par1AxisAlignedBB.minY); + int l = MathHelper.floor_double(par1AxisAlignedBB.maxY + 1.0D); + int i1 = MathHelper.floor_double(par1AxisAlignedBB.minZ); + int j1 = MathHelper.floor_double(par1AxisAlignedBB.maxZ + 1.0D); + + for (int k1 = i; k1 < j; ++k1) + { + for (int l1 = k; l1 < l; ++l1) + { + for (int i2 = i1; i2 < j1; ++i2) + { + Block block = this.getBlock(k1, l1, i2); + + if (block.getMaterial() == par2Material) + { + int j2 = this.getBlockMetadata(k1, l1, i2); + double d0 = (double)(l1 + 1); + + if (j2 < 8) + { + d0 = (double)(l1 + 1) - (double)j2 / 8.0D; + } + + if (d0 >= par1AxisAlignedBB.minY) + { + return true; + } + } + } + } + } + + return false; + } + + public Explosion createExplosion(Entity par1Entity, double par2, double par4, double par6, float par8, boolean par9) + { + return this.newExplosion(par1Entity, par2, par4, par6, par8, false, par9); + } + + public Explosion newExplosion(Entity par1Entity, double par2, double par4, double par6, float par8, boolean par9, boolean par10) + { + Explosion explosion = new Explosion(this, par1Entity, par2, par4, par6, par8); + explosion.isFlaming = par9; + explosion.isSmoking = par10; + explosion.doExplosionA(); + explosion.doExplosionB(true); + return explosion; + } + + public float getBlockDensity(Vec3 par1Vec3, AxisAlignedBB par2AxisAlignedBB) + { + double d0 = 1.0D / ((par2AxisAlignedBB.maxX - par2AxisAlignedBB.minX) * 2.0D + 1.0D); + double d1 = 1.0D / ((par2AxisAlignedBB.maxY - par2AxisAlignedBB.minY) * 2.0D + 1.0D); + double d2 = 1.0D / ((par2AxisAlignedBB.maxZ - par2AxisAlignedBB.minZ) * 2.0D + 1.0D); + int i = 0; + int j = 0; + + for (float f = 0.0F; f <= 1.0F; f = (float)((double)f + d0)) + { + for (float f1 = 0.0F; f1 <= 1.0F; f1 = (float)((double)f1 + d1)) + { + for (float f2 = 0.0F; f2 <= 1.0F; f2 = (float)((double)f2 + d2)) + { + double d3 = par2AxisAlignedBB.minX + (par2AxisAlignedBB.maxX - par2AxisAlignedBB.minX) * (double)f; + double d4 = par2AxisAlignedBB.minY + (par2AxisAlignedBB.maxY - par2AxisAlignedBB.minY) * (double)f1; + double d5 = par2AxisAlignedBB.minZ + (par2AxisAlignedBB.maxZ - par2AxisAlignedBB.minZ) * (double)f2; + + if (this.rayTraceBlocks(this.getWorldVec3Pool().getVecFromPool(d3, d4, d5), par1Vec3) == null) + { + ++i; + } + + ++j; + } + } + } + + return (float)i / (float)j; + } + + public boolean extinguishFire(EntityPlayer par1EntityPlayer, int par2, int par3, int par4, int par5) + { + if (par5 == 0) + { + --par3; + } + + if (par5 == 1) + { + ++par3; + } + + if (par5 == 2) + { + --par4; + } + + if (par5 == 3) + { + ++par4; + } + + if (par5 == 4) + { + --par2; + } + + if (par5 == 5) + { + ++par2; + } + + if (this.getBlock(par2, par3, par4) == Blocks.fire) + { + this.playAuxSFXAtEntity(par1EntityPlayer, 1004, par2, par3, par4, 0); + this.setBlockToAir(par2, par3, par4); + return true; + } + else + { + return false; + } + } + + @SideOnly(Side.CLIENT) + public String getDebugLoadedEntities() + { + return "All: " + this.loadedEntityList.size(); + } + + @SideOnly(Side.CLIENT) + public String getProviderName() + { + return this.chunkProvider.makeString(); + } + + public TileEntity getTileEntity(int p_147438_1_, int p_147438_2_, int p_147438_3_) + { + if (p_147438_2_ >= 0 && p_147438_2_ < 256) + { + TileEntity tileentity = null; + int l; + TileEntity tileentity1; + + if (this.field_147481_N) + { + for (l = 0; l < this.addedTileEntityList.size(); ++l) + { + tileentity1 = (TileEntity)this.addedTileEntityList.get(l); + + if (!tileentity1.isInvalid() && tileentity1.xCoord == p_147438_1_ && tileentity1.yCoord == p_147438_2_ && tileentity1.zCoord == p_147438_3_) + { + tileentity = tileentity1; + break; + } + } + } + + if (tileentity == null) + { + Chunk chunk = this.getChunkFromChunkCoords(p_147438_1_ >> 4, p_147438_3_ >> 4); + + if (chunk != null) + { + tileentity = chunk.func_150806_e(p_147438_1_ & 15, p_147438_2_, p_147438_3_ & 15); + } + } + + if (tileentity == null) + { + for (l = 0; l < this.addedTileEntityList.size(); ++l) + { + tileentity1 = (TileEntity)this.addedTileEntityList.get(l); + + if (!tileentity1.isInvalid() && tileentity1.xCoord == p_147438_1_ && tileentity1.yCoord == p_147438_2_ && tileentity1.zCoord == p_147438_3_) + { + tileentity = tileentity1; + break; + } + } + } + + return tileentity; + } + else + { + return null; + } + } + + public void setTileEntity(int p_147455_1_, int p_147455_2_, int p_147455_3_, TileEntity p_147455_4_) + { + if (p_147455_4_ == null || p_147455_4_.isInvalid()) + { + return; + } + + if (p_147455_4_.canUpdate()) + { + if (this.field_147481_N) + { + Iterator iterator = this.addedTileEntityList.iterator(); + + while (iterator.hasNext()) + { + TileEntity tileentity1 = (TileEntity)iterator.next(); + + if (tileentity1.xCoord == p_147455_1_ && tileentity1.yCoord == p_147455_2_ && tileentity1.zCoord == p_147455_3_) + { + tileentity1.invalidate(); + iterator.remove(); + } + } + + this.addedTileEntityList.add(p_147455_4_); + } + else + { + this.loadedTileEntityList.add(p_147455_4_); + } + } + Chunk chunk = this.getChunkFromChunkCoords(p_147455_1_ >> 4, p_147455_3_ >> 4); + if (chunk != null) + { + chunk.func_150812_a(p_147455_1_ & 15, p_147455_2_, p_147455_3_ & 15, p_147455_4_); + } + //notify tile changes + func_147453_f(p_147455_1_, p_147455_2_, p_147455_3_, getBlock(p_147455_1_, p_147455_2_, p_147455_3_)); + } + + public void removeTileEntity(int p_147475_1_, int p_147475_2_, int p_147475_3_) + { + Chunk chunk = getChunkFromChunkCoords(p_147475_1_ >> 4, p_147475_3_ >> 4); + if (chunk != null) chunk.removeTileEntity(p_147475_1_ & 15, p_147475_2_, p_147475_3_ & 15); + func_147453_f(p_147475_1_, p_147475_2_, p_147475_3_, getBlock(p_147475_1_, p_147475_2_, p_147475_3_)); + } + + public void func_147457_a(TileEntity p_147457_1_) + { + this.field_147483_b.add(p_147457_1_); + } + + public boolean func_147469_q(int p_147469_1_, int p_147469_2_, int p_147469_3_) + { + AxisAlignedBB axisalignedbb = this.getBlock(p_147469_1_, p_147469_2_, p_147469_3_).getCollisionBoundingBoxFromPool(this, p_147469_1_, p_147469_2_, p_147469_3_); + return axisalignedbb != null && axisalignedbb.getAverageEdgeLength() >= 1.0D; + } + + public static boolean doesBlockHaveSolidTopSurface(IBlockAccess p_147466_0_, int p_147466_1_, int p_147466_2_, int p_147466_3_) + { + Block block = p_147466_0_.getBlock(p_147466_1_, p_147466_2_, p_147466_3_); + return block.isSideSolid(p_147466_0_, p_147466_1_, p_147466_2_, p_147466_3_, ForgeDirection.UP); + } + + public boolean isBlockNormalCubeDefault(int p_147445_1_, int p_147445_2_, int p_147445_3_, boolean p_147445_4_) + { + if (p_147445_1_ >= -MAX_BLOCK_COORD && p_147445_3_ >= -MAX_BLOCK_COORD && p_147445_1_ < MAX_BLOCK_COORD && p_147445_3_ < MAX_BLOCK_COORD) + { + Chunk chunk = this.chunkProvider.provideChunk(p_147445_1_ >> 4, p_147445_3_ >> 4); + + if (chunk != null && !chunk.isEmpty()) + { + Block block = this.getBlock(p_147445_1_, p_147445_2_, p_147445_3_); + return block.isNormalCube(this, p_147445_1_, p_147445_2_, p_147445_3_); + } + else + { + return p_147445_4_; + } + } + else + { + return p_147445_4_; + } + } + + public void calculateInitialSkylight() + { + int i = this.calculateSkylightSubtracted(1.0F); + + if (i != this.skylightSubtracted) + { + this.skylightSubtracted = i; + } + } + + public void setAllowedSpawnTypes(boolean par1, boolean par2) + { + provider.setAllowedSpawnTypes(par1, par2); + } + + public void tick() + { + this.updateWeather(); + } + + private void calculateInitialWeather() + { + provider.calculateInitialWeather(); + } + + public void calculateInitialWeatherBody() + { + if (this.worldInfo.isRaining()) + { + this.rainingStrength = 1.0F; + + if (this.worldInfo.isThundering()) + { + this.thunderingStrength = 1.0F; + } + } + } + + protected void updateWeather() + { + provider.updateWeather(); + } + + public void updateWeatherBody() + { + if (!this.provider.hasNoSky) + { + if (!this.isRemote) + { + int i = this.worldInfo.getThunderTime(); + + if (i <= 0) + { + if (this.worldInfo.isThundering()) + { + this.worldInfo.setThunderTime(this.rand.nextInt(12000) + 3600); + } + else + { + this.worldInfo.setThunderTime(this.rand.nextInt(168000) + 12000); + } + } + else + { + --i; + this.worldInfo.setThunderTime(i); + + if (i <= 0) + { + this.worldInfo.setThundering(!this.worldInfo.isThundering()); + } + } + + this.prevThunderingStrength = this.thunderingStrength; + + if (this.worldInfo.isThundering()) + { + this.thunderingStrength = (float)((double)this.thunderingStrength + 0.01D); + } + else + { + this.thunderingStrength = (float)((double)this.thunderingStrength - 0.01D); + } + + this.thunderingStrength = MathHelper.clamp_float(this.thunderingStrength, 0.0F, 1.0F); + int j = this.worldInfo.getRainTime(); + + if (j <= 0) + { + if (this.worldInfo.isRaining()) + { + this.worldInfo.setRainTime(this.rand.nextInt(12000) + 12000); + } + else + { + this.worldInfo.setRainTime(this.rand.nextInt(168000) + 12000); + } + } + else + { + --j; + this.worldInfo.setRainTime(j); + + if (j <= 0) + { + this.worldInfo.setRaining(!this.worldInfo.isRaining()); + } + } + + this.prevRainingStrength = this.rainingStrength; + + if (this.worldInfo.isRaining()) + { + this.rainingStrength = (float)((double)this.rainingStrength + 0.01D); + } + else + { + this.rainingStrength = (float)((double)this.rainingStrength - 0.01D); + } + + this.rainingStrength = MathHelper.clamp_float(this.rainingStrength, 0.0F, 1.0F); + } + } + } + + protected void setActivePlayerChunksAndCheckLight() + { + this.activeChunkSet.clear(); + this.theProfiler.startSection("buildList"); + if(isChunkLoaderEnabled()) + for(ChunkCoordIntPair c : getPersistentChunks().keySet()) activeChunkSet.put(ChunkHash.chunkToKey(c.chunkXPos, c.chunkZPos), (byte)100); + int i; + EntityPlayer entityplayer; + int j; + int k; + + for (i = 0; i < this.playerEntities.size(); ++i) + { + entityplayer = (EntityPlayer)this.playerEntities.get(i); + j = MathHelper.floor_double(entityplayer.posX / 16.0D); + k = MathHelper.floor_double(entityplayer.posZ / 16.0D); + int b0 = getChunkUpdateRadius(); + + activeChunkSet.put(ChunkHash.chunkToKey(j, k), (byte)0); + for (int l = -b0; l <= b0; ++l) + { + for (int i1 = -b0; i1 <= b0; ++i1) + { + int cx = l + j; + int cz = i1 + k; + if(chunkExists(cx, cz) && chunkExists(cx-1, cz) && chunkExists(cx, cz-1) && chunkExists(cx+1, cz) && chunkExists(cx, cz+1)) + { + int key = ChunkHash.chunkToKey(cx, cz); + int priority = Math.max(Math.abs(l), Math.abs(i1)); + //Chunk chunk = this.chunkProvider.provideChunk(cx, cy); + //if(priority > 1) priority -= Math.min(priority-2, (int)(this.getTotalWorldTime() - chunk.lastActiveOrBindTick)/20); + activeChunkSet.put(key, (byte)Math.min(priority, activeChunkSet.get(key))); + } + } + } + } + + this.theProfiler.endSection(); + + if (this.ambientTickCountdown > 0) + { + --this.ambientTickCountdown; + } + + this.theProfiler.startSection("playerCheckLight"); + + if (!this.playerEntities.isEmpty()) + { + i = this.rand.nextInt(this.playerEntities.size()); + entityplayer = (EntityPlayer)this.playerEntities.get(i); + j = MathHelper.floor_double(entityplayer.posX) + this.rand.nextInt(11) - 5; + k = MathHelper.floor_double(entityplayer.posY) + this.rand.nextInt(11) - 5; + int j1 = MathHelper.floor_double(entityplayer.posZ) + this.rand.nextInt(11) - 5; + this.func_147451_t(j, k, j1); + } + + this.theProfiler.endSection(); + } + + protected void func_147467_a(int p_147467_1_, int p_147467_2_, Chunk p_147467_3_) + { + this.theProfiler.endStartSection("moodSound"); + + if (this.ambientTickCountdown == 0 && !this.isRemote) + { + this.updateLCG = this.updateLCG * 3 + 1013904223; + int k = this.updateLCG >> 2; + int l = k & 15; + int i1 = k >> 8 & 15; + int j1 = k >> 16 & 255; + Block block = p_147467_3_.getBlock(l, j1, i1); + l += p_147467_1_; + i1 += p_147467_2_; + + if (block.getMaterial() == Material.air && this.getFullBlockLightValue(l, j1, i1) <= this.rand.nextInt(8) && this.getSavedLightValue(EnumSkyBlock.Sky, l, j1, i1) <= 0) + { + EntityPlayer entityplayer = this.getClosestPlayer((double)l + 0.5D, (double)j1 + 0.5D, (double)i1 + 0.5D, 8.0D); + + if (entityplayer != null && entityplayer.getDistanceSq((double)l + 0.5D, (double)j1 + 0.5D, (double)i1 + 0.5D) > 4.0D) + { + this.playSoundEffect((double)l + 0.5D, (double)j1 + 0.5D, (double)i1 + 0.5D, "ambient.cave.cave", 0.7F, 0.8F + this.rand.nextFloat() * 0.2F); + this.ambientTickCountdown = this.rand.nextInt(12000) + 6000; + } + } + } + + this.theProfiler.endStartSection("checkLight"); + p_147467_3_.enqueueRelightChecks(); + } + + protected void func_147456_g() + { + this.setActivePlayerChunksAndCheckLight(); + } + + public boolean isBlockFreezable(int par1, int par2, int par3) + { + return this.canBlockFreeze(par1, par2, par3, false); + } + + public boolean isBlockFreezableNaturally(int par1, int par2, int par3) + { + return this.canBlockFreeze(par1, par2, par3, true); + } + + public boolean canBlockFreeze(int par1, int par2, int par3, boolean par4) + { + return provider.canBlockFreeze(par1, par2, par3, par4); + } + + public boolean canBlockFreezeBody(int par1, int par2, int par3, boolean par4) + { + BiomeGenBase biomegenbase = this.getBiomeGenForCoords(par1, par3); + float f = biomegenbase.getFloatTemperature(par1, par2, par3); + + if (f > 0.15F) + { + return false; + } + else + { + if (par2 >= 0 && par2 < 256 && this.getSavedLightValue(EnumSkyBlock.Block, par1, par2, par3) < 10) + { + Block block = this.getBlock(par1, par2, par3); + + if ((block == Blocks.water || block == Blocks.flowing_water) && this.getBlockMetadata(par1, par2, par3) == 0) + { + if (!par4) + { + return true; + } + + boolean flag1 = true; + + if (flag1 && this.getBlock(par1 - 1, par2, par3).getMaterial() != Material.water) + { + flag1 = false; + } + + if (flag1 && this.getBlock(par1 + 1, par2, par3).getMaterial() != Material.water) + { + flag1 = false; + } + + if (flag1 && this.getBlock(par1, par2, par3 - 1).getMaterial() != Material.water) + { + flag1 = false; + } + + if (flag1 && this.getBlock(par1, par2, par3 + 1).getMaterial() != Material.water) + { + flag1 = false; + } + + if (!flag1) + { + return true; + } + } + } + + return false; + } + } + + public boolean func_147478_e(int p_147478_1_, int p_147478_2_, int p_147478_3_, boolean p_147478_4_) + { + return provider.canSnowAt(p_147478_1_, p_147478_2_, p_147478_3_, p_147478_4_); + } + + public boolean canSnowAtBody(int p_147478_1_, int p_147478_2_, int p_147478_3_, boolean p_147478_4_) + { + BiomeGenBase biomegenbase = this.getBiomeGenForCoords(p_147478_1_, p_147478_3_); + float f = biomegenbase.getFloatTemperature(p_147478_1_, p_147478_2_, p_147478_3_); + + if (f > 0.15F) + { + return false; + } + else if (!p_147478_4_) + { + return true; + } + else + { + if (p_147478_2_ >= 0 && p_147478_2_ < 256 && this.getSavedLightValue(EnumSkyBlock.Block, p_147478_1_, p_147478_2_, p_147478_3_) < 10) + { + Block block = this.getBlock(p_147478_1_, p_147478_2_, p_147478_3_); + + if (block.getMaterial() == Material.air && Blocks.snow_layer.canPlaceBlockAt(this, p_147478_1_, p_147478_2_, p_147478_3_)) + { + return true; + } + } + + return false; + } + } + + public boolean func_147451_t(int p_147451_1_, int p_147451_2_, int p_147451_3_) + { + boolean flag = false; + + if (!this.provider.hasNoSky) + { + flag |= this.updateLightByType(EnumSkyBlock.Sky, p_147451_1_, p_147451_2_, p_147451_3_); + } + + flag |= this.updateLightByType(EnumSkyBlock.Block, p_147451_1_, p_147451_2_, p_147451_3_); + return flag; + } + + private int computeLightValue(int par1, int par2, int par3, EnumSkyBlock par4EnumSkyBlock) + { + if (par4EnumSkyBlock == EnumSkyBlock.Sky && this.canBlockSeeTheSky(par1, par2, par3)) + { + return 15; + } + else + { + Block block = this.getBlock(par1, par2, par3); + int blockLight = block.getLightValue(this, par1, par2, par3); + int l = par4EnumSkyBlock == EnumSkyBlock.Sky ? 0 : blockLight; + int i1 = block.getLightOpacity(this, par1, par2, par3); + + if (i1 >= 15 && blockLight > 0) + { + i1 = 1; + } + + if (i1 < 1) + { + i1 = 1; + } + + if (i1 >= 15) + { + return 0; + } + else if (l >= 14) + { + return l; + } + else + { + for (int j1 = 0; j1 < 6; ++j1) + { + int k1 = par1 + Facing.offsetsXForSide[j1]; + int l1 = par2 + Facing.offsetsYForSide[j1]; + int i2 = par3 + Facing.offsetsZForSide[j1]; + int j2 = this.getSavedLightValue(par4EnumSkyBlock, k1, l1, i2) - i1; + + if (j2 > l) + { + l = j2; + } + + if (l >= 14) + { + return l; + } + } + + return l; + } + } + } + + public boolean updateLightByType(EnumSkyBlock p_147463_1_, int p_147463_2_, int p_147463_3_, int p_147463_4_) + { + if (!this.doChunksNearChunkExist(p_147463_2_, p_147463_3_, p_147463_4_, 17)) + { + return false; + } + else + { + int l = 0; + int i1 = 0; + this.theProfiler.startSection("getBrightness"); + int j1 = this.getSavedLightValue(p_147463_1_, p_147463_2_, p_147463_3_, p_147463_4_); + int k1 = this.computeLightValue(p_147463_2_, p_147463_3_, p_147463_4_, p_147463_1_); + int l1; + int i2; + int j2; + int k2; + int l2; + int i3; + int j3; + int k3; + int l3; + + if (k1 > j1) + { + this.lightUpdateBlockList[i1++] = 133152; + } + else if (k1 < j1) + { + this.lightUpdateBlockList[i1++] = 133152 | j1 << 18; + + while (l < i1) + { + l1 = this.lightUpdateBlockList[l++]; + i2 = (l1 & 63) - 32 + p_147463_2_; + j2 = (l1 >> 6 & 63) - 32 + p_147463_3_; + k2 = (l1 >> 12 & 63) - 32 + p_147463_4_; + l2 = l1 >> 18 & 15; + i3 = this.getSavedLightValue(p_147463_1_, i2, j2, k2); + + if (i3 == l2) + { + this.setLightValue(p_147463_1_, i2, j2, k2, 0); + + if (l2 > 0) + { + j3 = MathHelper.abs_int(i2 - p_147463_2_); + k3 = MathHelper.abs_int(j2 - p_147463_3_); + l3 = MathHelper.abs_int(k2 - p_147463_4_); + + if (j3 + k3 + l3 < 17) + { + for (int i4 = 0; i4 < 6; ++i4) + { + int j4 = i2 + Facing.offsetsXForSide[i4]; + int k4 = j2 + Facing.offsetsYForSide[i4]; + int l4 = k2 + Facing.offsetsZForSide[i4]; + int i5 = Math.max(1, this.getBlock(j4, k4, l4).getLightOpacity(this, j4, k4, l4)); + i3 = this.getSavedLightValue(p_147463_1_, j4, k4, l4); + + if (i3 == l2 - i5 && i1 < this.lightUpdateBlockList.length) + { + this.lightUpdateBlockList[i1++] = j4 - p_147463_2_ + 32 | k4 - p_147463_3_ + 32 << 6 | l4 - p_147463_4_ + 32 << 12 | l2 - i5 << 18; + } + } + } + } + } + } + + l = 0; + } + + this.theProfiler.endSection(); + this.theProfiler.startSection("checkedPosition < toCheckCount"); + + while (l < i1) + { + l1 = this.lightUpdateBlockList[l++]; + i2 = (l1 & 63) - 32 + p_147463_2_; + j2 = (l1 >> 6 & 63) - 32 + p_147463_3_; + k2 = (l1 >> 12 & 63) - 32 + p_147463_4_; + l2 = this.getSavedLightValue(p_147463_1_, i2, j2, k2); + i3 = this.computeLightValue(i2, j2, k2, p_147463_1_); + + if (i3 != l2) + { + this.setLightValue(p_147463_1_, i2, j2, k2, i3); + + if (i3 > l2) + { + j3 = Math.abs(i2 - p_147463_2_); + k3 = Math.abs(j2 - p_147463_3_); + l3 = Math.abs(k2 - p_147463_4_); + boolean flag = i1 < this.lightUpdateBlockList.length - 6; + + if (j3 + k3 + l3 < 17 && flag) + { + if (this.getSavedLightValue(p_147463_1_, i2 - 1, j2, k2) < i3) + { + this.lightUpdateBlockList[i1++] = i2 - 1 - p_147463_2_ + 32 + (j2 - p_147463_3_ + 32 << 6) + (k2 - p_147463_4_ + 32 << 12); + } + + if (this.getSavedLightValue(p_147463_1_, i2 + 1, j2, k2) < i3) + { + this.lightUpdateBlockList[i1++] = i2 + 1 - p_147463_2_ + 32 + (j2 - p_147463_3_ + 32 << 6) + (k2 - p_147463_4_ + 32 << 12); + } + + if (this.getSavedLightValue(p_147463_1_, i2, j2 - 1, k2) < i3) + { + this.lightUpdateBlockList[i1++] = i2 - p_147463_2_ + 32 + (j2 - 1 - p_147463_3_ + 32 << 6) + (k2 - p_147463_4_ + 32 << 12); + } + + if (this.getSavedLightValue(p_147463_1_, i2, j2 + 1, k2) < i3) + { + this.lightUpdateBlockList[i1++] = i2 - p_147463_2_ + 32 + (j2 + 1 - p_147463_3_ + 32 << 6) + (k2 - p_147463_4_ + 32 << 12); + } + + if (this.getSavedLightValue(p_147463_1_, i2, j2, k2 - 1) < i3) + { + this.lightUpdateBlockList[i1++] = i2 - p_147463_2_ + 32 + (j2 - p_147463_3_ + 32 << 6) + (k2 - 1 - p_147463_4_ + 32 << 12); + } + + if (this.getSavedLightValue(p_147463_1_, i2, j2, k2 + 1) < i3) + { + this.lightUpdateBlockList[i1++] = i2 - p_147463_2_ + 32 + (j2 - p_147463_3_ + 32 << 6) + (k2 + 1 - p_147463_4_ + 32 << 12); + } + } + } + } + } + + this.theProfiler.endSection(); + return true; + } + } + + public boolean tickUpdates(boolean par1) + { + return false; + } + + public List getPendingBlockUpdates(Chunk par1Chunk, boolean par2) + { + return null; + } + + public List getEntitiesWithinAABBExcludingEntity(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB) + { + return this.getEntitiesWithinAABBExcludingEntity(par1Entity, par2AxisAlignedBB, (IEntitySelector)null); + } + + public List getEntitiesWithinAABBExcludingEntity(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB, IEntitySelector par3IEntitySelector) + { + ArrayList arraylist = new ArrayList(); + int i = MathHelper.floor_double((par2AxisAlignedBB.minX - MAX_ENTITY_RADIUS) / 16.0D); + int j = MathHelper.floor_double((par2AxisAlignedBB.maxX + MAX_ENTITY_RADIUS) / 16.0D); + int k = MathHelper.floor_double((par2AxisAlignedBB.minZ - MAX_ENTITY_RADIUS) / 16.0D); + int l = MathHelper.floor_double((par2AxisAlignedBB.maxZ + MAX_ENTITY_RADIUS) / 16.0D); + + for (int i1 = i; i1 <= j; ++i1) + { + for (int j1 = k; j1 <= l; ++j1) + { + if (this.chunkExists(i1, j1)) + { + this.getChunkFromChunkCoords(i1, j1).getEntitiesWithinAABBForEntity(par1Entity, par2AxisAlignedBB, arraylist, par3IEntitySelector); + } + } + } + + return arraylist; + } + + public List getEntitiesWithinAABB(Class par1Class, AxisAlignedBB par2AxisAlignedBB) + { + return this.selectEntitiesWithinAABB(par1Class, par2AxisAlignedBB, (IEntitySelector)null); + } + + public List selectEntitiesWithinAABB(Class par1Class, AxisAlignedBB par2AxisAlignedBB, IEntitySelector par3IEntitySelector) + { + int i = MathHelper.floor_double((par2AxisAlignedBB.minX - MAX_ENTITY_RADIUS) / 16.0D); + int j = MathHelper.floor_double((par2AxisAlignedBB.maxX + MAX_ENTITY_RADIUS) / 16.0D); + int k = MathHelper.floor_double((par2AxisAlignedBB.minZ - MAX_ENTITY_RADIUS) / 16.0D); + int l = MathHelper.floor_double((par2AxisAlignedBB.maxZ + MAX_ENTITY_RADIUS) / 16.0D); + ArrayList arraylist = new ArrayList(); + + for (int i1 = i; i1 <= j; ++i1) + { + for (int j1 = k; j1 <= l; ++j1) + { + if (this.chunkExists(i1, j1)) + { + this.getChunkFromChunkCoords(i1, j1).getEntitiesOfTypeWithinAAAB(par1Class, par2AxisAlignedBB, arraylist, par3IEntitySelector); + } + } + } + + return arraylist; + } + + public Entity findNearestEntityWithinAABB(Class par1Class, AxisAlignedBB par2AxisAlignedBB, Entity par3Entity) + { + List list = this.getEntitiesWithinAABB(par1Class, par2AxisAlignedBB); + Entity entity1 = null; + double d0 = Double.MAX_VALUE; + + for (int i = 0; i < list.size(); ++i) + { + Entity entity2 = (Entity)list.get(i); + + if (entity2 != par3Entity) + { + double d1 = par3Entity.getDistanceSqToEntity(entity2); + + if (d1 <= d0) + { + entity1 = entity2; + d0 = d1; + } + } + } + + return entity1; + } + + public abstract Entity getEntityByID(int var1); + + @SideOnly(Side.CLIENT) + public List getLoadedEntityList() + { + return this.loadedEntityList; + } + + public void markTileEntityChunkModified(int p_147476_1_, int p_147476_2_, int p_147476_3_, TileEntity p_147476_4_) + { + if (this.blockExists(p_147476_1_, p_147476_2_, p_147476_3_)) + { + this.getChunkFromBlockCoords(p_147476_1_, p_147476_3_).setChunkModified(); + } + } + + public int countEntities(Class par1Class) + { + int i = 0; + + for (int j = 0; j < this.loadedEntityList.size(); ++j) + { + Entity entity = (Entity)this.loadedEntityList.get(j); + + if ((!(entity instanceof EntityLiving) || !((EntityLiving)entity).isNoDespawnRequired()) && par1Class.isAssignableFrom(entity.getClass())) + { + ++i; + } + } + + return i; + } + + public void addLoadedEntities(List par1List) + { + for (int i = 0; i < par1List.size(); ++i) + { + Entity entity = (Entity)par1List.get(i); + if (!MinecraftForge.EVENT_BUS.post(new EntityJoinWorldEvent(entity, this))) + { + loadedEntityList.add(entity); + this.onEntityAdded(entity); + } + } + } + + public void unloadEntities(List par1List) + { + this.unloadedEntityList.addAll(par1List); + } + + public boolean canPlaceEntityOnSide(Block p_147472_1_, int p_147472_2_, int p_147472_3_, int p_147472_4_, boolean p_147472_5_, int p_147472_6_, Entity p_147472_7_, ItemStack p_147472_8_) + { + Block block1 = this.getBlock(p_147472_2_, p_147472_3_, p_147472_4_); + AxisAlignedBB axisalignedbb = p_147472_5_ ? null : p_147472_1_.getCollisionBoundingBoxFromPool(this, p_147472_2_, p_147472_3_, p_147472_4_); + return axisalignedbb != null && !this.checkNoEntityCollision(axisalignedbb, p_147472_7_) ? false : (block1.getMaterial() == Material.circuits && p_147472_1_ == Blocks.anvil ? true : block1.isReplaceable(this, p_147472_2_, p_147472_3_, p_147472_4_) && p_147472_1_.canReplace(this, p_147472_2_, p_147472_3_, p_147472_4_, p_147472_6_, p_147472_8_)); + } + + public PathEntity getPathEntityToEntity(Entity par1Entity, Entity par2Entity, float par3, boolean par4, boolean par5, boolean par6, boolean par7) + { + this.theProfiler.startSection("pathfind"); + int i = MathHelper.floor_double(par1Entity.posX); + int j = MathHelper.floor_double(par1Entity.posY + 1.0D); + int k = MathHelper.floor_double(par1Entity.posZ); + int l = (int)(par3 + 16.0F); + int i1 = i - l; + int j1 = j - l; + int k1 = k - l; + int l1 = i + l; + int i2 = j + l; + int j2 = k + l; + ChunkCache chunkcache = new ChunkCache(this, i1, j1, k1, l1, i2, j2, 0); + PathEntity pathentity = (new PathFinder(chunkcache, par4, par5, par6, par7)).createEntityPathTo(par1Entity, par2Entity, par3); + this.theProfiler.endSection(); + return pathentity; + } + + public PathEntity getEntityPathToXYZ(Entity par1Entity, int par2, int par3, int par4, float par5, boolean par6, boolean par7, boolean par8, boolean par9) + { + this.theProfiler.startSection("pathfind"); + int l = MathHelper.floor_double(par1Entity.posX); + int i1 = MathHelper.floor_double(par1Entity.posY); + int j1 = MathHelper.floor_double(par1Entity.posZ); + int k1 = (int)(par5 + 8.0F); + int l1 = l - k1; + int i2 = i1 - k1; + int j2 = j1 - k1; + int k2 = l + k1; + int l2 = i1 + k1; + int i3 = j1 + k1; + ChunkCache chunkcache = new ChunkCache(this, l1, i2, j2, k2, l2, i3, 0); + PathEntity pathentity = (new PathFinder(chunkcache, par6, par7, par8, par9)).createEntityPathTo(par1Entity, par2, par3, par4, par5); + this.theProfiler.endSection(); + return pathentity; + } + + public int isBlockProvidingPowerTo(int par1, int par2, int par3, int par4) + { + return this.getBlock(par1, par2, par3).isProvidingStrongPower(this, par1, par2, par3, par4); + } + + public int getBlockPowerInput(int par1, int par2, int par3) + { + byte b0 = 0; + int l = Math.max(b0, this.isBlockProvidingPowerTo(par1, par2 - 1, par3, 0)); + + if (l >= 15) + { + return l; + } + else + { + l = Math.max(l, this.isBlockProvidingPowerTo(par1, par2 + 1, par3, 1)); + + if (l >= 15) + { + return l; + } + else + { + l = Math.max(l, this.isBlockProvidingPowerTo(par1, par2, par3 - 1, 2)); + + if (l >= 15) + { + return l; + } + else + { + l = Math.max(l, this.isBlockProvidingPowerTo(par1, par2, par3 + 1, 3)); + + if (l >= 15) + { + return l; + } + else + { + l = Math.max(l, this.isBlockProvidingPowerTo(par1 - 1, par2, par3, 4)); + + if (l >= 15) + { + return l; + } + else + { + l = Math.max(l, this.isBlockProvidingPowerTo(par1 + 1, par2, par3, 5)); + return l >= 15 ? l : l; + } + } + } + } + } + } + + public boolean getIndirectPowerOutput(int par1, int par2, int par3, int par4) + { + return this.getIndirectPowerLevelTo(par1, par2, par3, par4) > 0; + } + + public int getIndirectPowerLevelTo(int par1, int par2, int par3, int par4) + { + Block block = this.getBlock(par1, par2, par3); + return block.shouldCheckWeakPower(this, par1, par2, par3, par4) ? this.getBlockPowerInput(par1, par2, par3) : block.isProvidingWeakPower(this, par1, par2, par3, par4); + } + + public boolean isBlockIndirectlyGettingPowered(int par1, int par2, int par3) + { + return this.getIndirectPowerLevelTo(par1, par2 - 1, par3, 0) > 0 ? true : (this.getIndirectPowerLevelTo(par1, par2 + 1, par3, 1) > 0 ? true : (this.getIndirectPowerLevelTo(par1, par2, par3 - 1, 2) > 0 ? true : (this.getIndirectPowerLevelTo(par1, par2, par3 + 1, 3) > 0 ? true : (this.getIndirectPowerLevelTo(par1 - 1, par2, par3, 4) > 0 ? true : this.getIndirectPowerLevelTo(par1 + 1, par2, par3, 5) > 0)))); + } + + public int getStrongestIndirectPower(int par1, int par2, int par3) + { + int l = 0; + + for (int i1 = 0; i1 < 6; ++i1) + { + int j1 = this.getIndirectPowerLevelTo(par1 + Facing.offsetsXForSide[i1], par2 + Facing.offsetsYForSide[i1], par3 + Facing.offsetsZForSide[i1], i1); + + if (j1 >= 15) + { + return 15; + } + + if (j1 > l) + { + l = j1; + } + } + + return l; + } + + public EntityPlayer getClosestPlayerToEntity(Entity par1Entity, double par2) + { + return this.getClosestPlayer(par1Entity.posX, par1Entity.posY, par1Entity.posZ, par2); + } + + public EntityPlayer getClosestPlayer(double par1, double par3, double par5, double par7) + { + double d4 = -1.0D; + EntityPlayer entityplayer = null; + + for (int i = 0; i < this.playerEntities.size(); ++i) + { + EntityPlayer entityplayer1 = (EntityPlayer)this.playerEntities.get(i); + double d5 = entityplayer1.getDistanceSq(par1, par3, par5); + + if ((par7 < 0.0D || d5 < par7 * par7) && (d4 == -1.0D || d5 < d4)) + { + d4 = d5; + entityplayer = entityplayer1; + } + } + + return entityplayer; + } + + public EntityPlayer getClosestVulnerablePlayerToEntity(Entity par1Entity, double par2) + { + return this.getClosestVulnerablePlayer(par1Entity.posX, par1Entity.posY, par1Entity.posZ, par2); + } + + public EntityPlayer getClosestVulnerablePlayer(double par1, double par3, double par5, double par7) + { + double d4 = -1.0D; + EntityPlayer entityplayer = null; + + for (int i = 0; i < this.playerEntities.size(); ++i) + { + EntityPlayer entityplayer1 = (EntityPlayer)this.playerEntities.get(i); + + if (!entityplayer1.capabilities.disableDamage && entityplayer1.isEntityAlive()) + { + double d5 = entityplayer1.getDistanceSq(par1, par3, par5); + double d6 = par7; + + if (entityplayer1.isSneaking()) + { + d6 = par7 * 0.800000011920929D; + } + + if (entityplayer1.isInvisible()) + { + float f = entityplayer1.getArmorVisibility(); + + if (f < 0.1F) + { + f = 0.1F; + } + + d6 *= (double)(0.7F * f); + } + + if ((par7 < 0.0D || d5 < d6 * d6) && (d4 == -1.0D || d5 < d4)) + { + d4 = d5; + entityplayer = entityplayer1; + } + } + } + + return entityplayer; + } + + public EntityPlayer getPlayerEntityByName(String par1Str) + { + for (int i = 0; i < this.playerEntities.size(); ++i) + { + if (par1Str.equals(((EntityPlayer)this.playerEntities.get(i)).getCommandSenderName())) + { + return (EntityPlayer)this.playerEntities.get(i); + } + } + + return null; + } + + @SideOnly(Side.CLIENT) + public void sendQuittingDisconnectingPacket() {} + + public void checkSessionLock() throws MinecraftException + { + this.saveHandler.checkSessionLock(); + } + + @SideOnly(Side.CLIENT) + public void func_82738_a(long par1) + { + this.worldInfo.incrementTotalWorldTime(par1); + } + + public long getSeed() + { + return provider.getSeed(); + } + + public long getTotalWorldTime() + { + return this.worldInfo.getWorldTotalTime(); + } + + public long getWorldTime() + { + return provider.getWorldTime(); + } + + public void setWorldTime(long par1) + { + provider.setWorldTime(par1); + } + + public ChunkCoordinates getSpawnPoint() + { + return provider.getSpawnPoint(); + } + + public void setSpawnLocation(int par1, int par2, int par3) + { + provider.setSpawnPoint(par1, par2, par3); + } + + @SideOnly(Side.CLIENT) + public void joinEntityInSurroundings(Entity par1Entity) + { + int i = MathHelper.floor_double(par1Entity.posX / 16.0D); + int j = MathHelper.floor_double(par1Entity.posZ / 16.0D); + byte b0 = 2; + + for (int k = i - b0; k <= i + b0; ++k) + { + for (int l = j - b0; l <= j + b0; ++l) + { + this.getChunkFromChunkCoords(k, l); + } + } + + if (!this.loadedEntityList.contains(par1Entity)) + { + if (!MinecraftForge.EVENT_BUS.post(new EntityJoinWorldEvent(par1Entity, this))) + { + this.loadedEntityList.add(par1Entity); + } + } + } + + public boolean canMineBlock(EntityPlayer par1EntityPlayer, int par2, int par3, int par4) + { + return provider.canMineBlock(par1EntityPlayer, par2, par3, par4); + } + + public boolean canMineBlockBody(EntityPlayer par1EntityPlayer, int par2, int par3, int par4) + { + return true; + } + + public void setEntityState(Entity par1Entity, byte par2) {} + + public IChunkProvider getChunkProvider() + { + return this.chunkProvider; + } + + public void addBlockEvent(int p_147452_1_, int p_147452_2_, int p_147452_3_, Block p_147452_4_, int p_147452_5_, int p_147452_6_) + { + p_147452_4_.onBlockEventReceived(this, p_147452_1_, p_147452_2_, p_147452_3_, p_147452_5_, p_147452_6_); + } + + public ISaveHandler getSaveHandler() + { + return this.saveHandler; + } + + public WorldInfo getWorldInfo() + { + return this.worldInfo; + } + + public GameRules getGameRules() + { + return this.worldInfo.getGameRulesInstance(); + } + + public void updateAllPlayersSleepingFlag() {} + + public float getWeightedThunderStrength(float par1) + { + return (this.prevThunderingStrength + (this.thunderingStrength - this.prevThunderingStrength) * par1) * this.getRainStrength(par1); + } + + @SideOnly(Side.CLIENT) + public void setThunderStrength(float p_147442_1_) + { + this.prevThunderingStrength = p_147442_1_; + this.thunderingStrength = p_147442_1_; + } + + public float getRainStrength(float par1) + { + return this.prevRainingStrength + (this.rainingStrength - this.prevRainingStrength) * par1; + } + + @SideOnly(Side.CLIENT) + public void setRainStrength(float par1) + { + this.prevRainingStrength = par1; + this.rainingStrength = par1; + } + + public boolean isThundering() + { + return (double)this.getWeightedThunderStrength(1.0F) > 0.9D; + } + + public boolean isRaining() + { + return (double)this.getRainStrength(1.0F) > 0.2D; + } + + public boolean canLightningStrikeAt(int par1, int par2, int par3) + { + if (!this.isRaining()) + { + return false; + } + else if (!this.canBlockSeeTheSky(par1, par2, par3)) + { + return false; + } + else if (this.getPrecipitationHeight(par1, par3) > par2) + { + return false; + } + else + { + BiomeGenBase biomegenbase = this.getBiomeGenForCoords(par1, par3); + return biomegenbase.getEnableSnow() ? false : (this.func_147478_e(par1, par2, par3, false) ? false : biomegenbase.canSpawnLightningBolt()); + } + } + + public boolean isBlockHighHumidity(int par1, int par2, int par3) + { + return provider.isBlockHighHumidity(par1, par2, par3); + } + + public void setItemData(String par1Str, WorldSavedData par2WorldSavedData) + { + this.mapStorage.setData(par1Str, par2WorldSavedData); + } + + public WorldSavedData loadItemData(Class par1Class, String par2Str) + { + return this.mapStorage.loadData(par1Class, par2Str); + } + + public int getUniqueDataId(String par1Str) + { + return this.mapStorage.getUniqueDataId(par1Str); + } + + public void playBroadcastSound(int par1, int par2, int par3, int par4, int par5) + { + for (int j1 = 0; j1 < this.worldAccesses.size(); ++j1) + { + ((IWorldAccess)this.worldAccesses.get(j1)).broadcastSound(par1, par2, par3, par4, par5); + } + } + + public void playAuxSFX(int par1, int par2, int par3, int par4, int par5) + { + this.playAuxSFXAtEntity((EntityPlayer)null, par1, par2, par3, par4, par5); + } + + public void playAuxSFXAtEntity(EntityPlayer par1EntityPlayer, int par2, int par3, int par4, int par5, int par6) + { + try + { + for (int j1 = 0; j1 < this.worldAccesses.size(); ++j1) + { + ((IWorldAccess)this.worldAccesses.get(j1)).playAuxSFX(par1EntityPlayer, par2, par3, par4, par5, par6); + } + } + catch (Throwable throwable) + { + CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Playing level event"); + CrashReportCategory crashreportcategory = crashreport.makeCategory("Level event being played"); + crashreportcategory.addCrashSection("Block coordinates", CrashReportCategory.getLocationInfo(par3, par4, par5)); + crashreportcategory.addCrashSection("Event source", par1EntityPlayer); + crashreportcategory.addCrashSection("Event type", Integer.valueOf(par2)); + crashreportcategory.addCrashSection("Event data", Integer.valueOf(par6)); + throw new ReportedException(crashreport); + } + } + + public int getHeight() + { + return provider.getHeight(); + } + + public int getActualHeight() + { + return provider.getActualHeight(); + } + + public Random setRandomSeed(int par1, int par2, int par3) + { + long l = (long)par1 * 341873128712L + (long)par2 * 132897987541L + this.getWorldInfo().getSeed() + (long)par3; + this.rand.setSeed(l); + return this.rand; + } + + public ChunkPosition findClosestStructure(String p_147440_1_, int p_147440_2_, int p_147440_3_, int p_147440_4_) + { + return this.getChunkProvider().func_147416_a(this, p_147440_1_, p_147440_2_, p_147440_3_, p_147440_4_); + } + + @SideOnly(Side.CLIENT) + public boolean extendedLevelsInChunkCache() + { + return false; + } + + @SideOnly(Side.CLIENT) + public double getHorizon() + { + return provider.getHorizon(); + } + + public CrashReportCategory addWorldInfoToCrashReport(CrashReport par1CrashReport) + { + CrashReportCategory crashreportcategory = par1CrashReport.makeCategoryDepth("Affected level", 1); + crashreportcategory.addCrashSection("Level name", this.worldInfo == null ? "????" : this.worldInfo.getWorldName()); + crashreportcategory.addCrashSectionCallable("All players", new Callable() + { + private static final String __OBFID = "CL_00000143"; + public String call() + { + return World.this.playerEntities.size() + " total; " + World.this.playerEntities.toString(); + } + }); + crashreportcategory.addCrashSectionCallable("Chunk stats", new Callable() + { + private static final String __OBFID = "CL_00000144"; + public String call() + { + return World.this.chunkProvider.makeString(); + } + }); + + try + { + this.worldInfo.addToCrashReport(crashreportcategory); + } + catch (Throwable throwable) + { + crashreportcategory.addCrashSectionThrowable("Level Data Unobtainable", throwable); + } + + return crashreportcategory; + } + + public void destroyBlockInWorldPartially(int p_147443_1_, int p_147443_2_, int p_147443_3_, int p_147443_4_, int p_147443_5_) + { + for (int j1 = 0; j1 < this.worldAccesses.size(); ++j1) + { + IWorldAccess iworldaccess = (IWorldAccess)this.worldAccesses.get(j1); + iworldaccess.destroyBlockPartially(p_147443_1_, p_147443_2_, p_147443_3_, p_147443_4_, p_147443_5_); + } + } + + public Vec3Pool getWorldVec3Pool() + { + return this.vecPool; + } + + public Calendar getCurrentDate() + { + if (this.getTotalWorldTime() % 600L == 0L) + { + this.theCalendar.setTimeInMillis(MinecraftServer.getSystemTimeMillis()); + } + + return this.theCalendar; + } + + @SideOnly(Side.CLIENT) + public void makeFireworks(double par1, double par3, double par5, double par7, double par9, double par11, NBTTagCompound par13NBTTagCompound) {} + + public Scoreboard getScoreboard() + { + return this.worldScoreboard; + } + + public void func_147453_f(int p_147453_1_, int p_147453_2_, int p_147453_3_, Block p_147453_4_) + { + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) + { + int i1 = p_147453_1_ + dir.offsetX; + int y = p_147453_2_ + dir.offsetY; + int j1 = p_147453_3_ + dir.offsetZ; + Block block1 = this.getBlock(i1, y, j1); + + block1.onNeighborChange(this, i1, y, j1, p_147453_1_, p_147453_2_, p_147453_3_); + if (block1.isNormalCube(this, i1, p_147453_2_, j1)) + { + i1 += dir.offsetX; + y += dir.offsetY; + j1 += dir.offsetZ; + Block block2 = this.getBlock(i1, y, j1); + + if (block2.getWeakChanges(this, i1, y, j1)) + { + block2.onNeighborChange(this, i1, y, j1, p_147453_1_, p_147453_2_, p_147453_3_); + } + } + } + } + + public float func_147462_b(double p_147462_1_, double p_147462_3_, double p_147462_5_) + { + return this.func_147473_B(MathHelper.floor_double(p_147462_1_), MathHelper.floor_double(p_147462_3_), MathHelper.floor_double(p_147462_5_)); + } + + public float func_147473_B(int p_147473_1_, int p_147473_2_, int p_147473_3_) + { + float f = 0.0F; + boolean flag = this.difficultySetting == EnumDifficulty.HARD; + + if (this.blockExists(p_147473_1_, p_147473_2_, p_147473_3_)) + { + float f1 = this.getCurrentMoonPhaseFactor(); + f += MathHelper.clamp_float((float)this.getChunkFromBlockCoords(p_147473_1_, p_147473_3_).inhabitedTime / 3600000.0F, 0.0F, 1.0F) * (flag ? 1.0F : 0.75F); + f += f1 * 0.25F; + } + + if (this.difficultySetting == EnumDifficulty.EASY || this.difficultySetting == EnumDifficulty.PEACEFUL) + { + f *= (float)this.difficultySetting.getDifficultyId() / 2.0F; + } + + return MathHelper.clamp_float(f, 0.0F, flag ? 1.5F : 1.0F); + } + + public void func_147450_X() + { + Iterator iterator = this.worldAccesses.iterator(); + + while (iterator.hasNext()) + { + IWorldAccess iworldaccess = (IWorldAccess)iterator.next(); + iworldaccess.onStaticEntitiesChanged(); + } + } + + + /* ======================================== FORGE START =====================================*/ + /** + * Adds a single TileEntity to the world. + * @param entity The TileEntity to be added. + */ + public void addTileEntity(TileEntity entity) + { + List dest = field_147481_N ? addedTileEntityList : loadedTileEntityList; + if(entity.canUpdate()) + { + dest.add(entity); + } + } + + /** + * Determine if the given block is considered solid on the + * specified side. Used by placement logic. + * + * @param x Block X Position + * @param y Block Y Position + * @param z Block Z Position + * @param side The Side in question + * @return True if the side is solid + */ + public boolean isSideSolid(int x, int y, int z, ForgeDirection side) + { + return isSideSolid(x, y, z, side, false); + } + + /** + * Determine if the given block is considered solid on the + * specified side. Used by placement logic. + * + * @param x Block X Position + * @param y Block Y Position + * @param z Block Z Position + * @param side The Side in question + * @param _default The default to return if the block doesn't exist. + * @return True if the side is solid + */ + @Override + public boolean isSideSolid(int x, int y, int z, ForgeDirection side, boolean _default) + { + if (x < -MAX_BLOCK_COORD || z < -MAX_BLOCK_COORD || x >= MAX_BLOCK_COORD || z >= MAX_BLOCK_COORD) + { + return _default; + } + + Chunk chunk = this.chunkProvider.provideChunk(x >> 4, z >> 4); + if (chunk == null || chunk.isEmpty()) + { + return _default; + } + return getBlock(x, y, z).isSideSolid(this, x, y, z, side); + } + + /** + * Get the persistent chunks for this world + * + * @return + */ + public ImmutableSetMultimap getPersistentChunks() + { + return ForgeChunkManager.getPersistentChunksFor(this); + } + + /** + * Readded as it was removed, very useful helper function + * + * @param x X position + * @param y Y Position + * @param z Z Position + * @return The blocks light opacity + */ + public int getBlockLightOpacity(int x, int y, int z) + { + if (x < -MAX_BLOCK_COORD || z < -MAX_BLOCK_COORD || x >= MAX_BLOCK_COORD || z >= MAX_BLOCK_COORD) + { + return 0; + } + + if (y < 0 || y >= 256) + { + return 0; + } + + return getChunkFromChunkCoords(x >> 4, z >> 4).func_150808_b(x & 15, y, z & 15); + } + + /** + * Returns a count of entities that classify themselves as the specified creature type. + */ + public int countEntities(EnumCreatureType type, boolean forSpawnCount) + { + int count = 0; + for (int x = 0; x < loadedEntityList.size(); x++) + { + if (((Entity)loadedEntityList.get(x)).isCreatureType(type, forSpawnCount)) + { + count++; + } + } + return count; + } + + + + /* ======================================== ULTRAMINE START =====================================*/ + + + private static final int MAX_BLOCK_COORD = 500000;//524288; + + public boolean chunkRoundExists(int cx, int cz, int radius) + { + for(int x = cx - radius; x < cx + radius; x++) + for(int z = cz - radius; z < cz + radius; z++) + if(!chunkExists(x, z)) return false; + return true; + } + + protected boolean isChunkLoaderEnabled() + { + return true; + } + + protected int getChunkUpdateRadius() + { + return 7; + } } \ No newline at end of file diff --git a/src/main/java/net/minecraft/world/WorldServer.java b/src/main/java/net/minecraft/world/WorldServer.java index c0404a1..909f1cf 100644 --- a/src/main/java/net/minecraft/world/WorldServer.java +++ b/src/main/java/net/minecraft/world/WorldServer.java @@ -1,990 +1,1013 @@ -package net.minecraft.world; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import gnu.trove.iterator.TIntByteIterator; -import gnu.trove.set.TIntSet; -import gnu.trove.set.hash.TIntHashSet; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Random; -import java.util.Set; -import java.util.TreeSet; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockEventData; -import net.minecraft.block.material.Material; -import net.minecraft.crash.CrashReport; -import net.minecraft.crash.CrashReportCategory; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityTracker; -import net.minecraft.entity.EnumCreatureType; -import net.minecraft.entity.INpc; -import net.minecraft.entity.effect.EntityLightningBolt; -import net.minecraft.entity.passive.EntityAnimal; -import net.minecraft.entity.passive.EntityWaterMob; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.network.play.server.S19PacketEntityStatus; -import net.minecraft.network.play.server.S24PacketBlockAction; -import net.minecraft.network.play.server.S27PacketExplosion; -import net.minecraft.network.play.server.S2APacketParticles; -import net.minecraft.network.play.server.S2BPacketChangeGameState; -import net.minecraft.network.play.server.S2CPacketSpawnGlobalEntity; -import net.minecraft.profiler.Profiler; -import net.minecraft.scoreboard.ScoreboardSaveData; -import net.minecraft.scoreboard.ServerScoreboard; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.management.PlayerManager; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ChunkCoordinates; -import net.minecraft.util.IProgressUpdate; -import net.minecraft.util.IntHashMap; -import net.minecraft.util.ReportedException; -import net.minecraft.util.Vec3; -import net.minecraft.util.WeightedRandom; -import net.minecraft.util.WeightedRandomChestContent; -import net.minecraft.world.biome.BiomeGenBase; -import net.minecraft.world.biome.WorldChunkManager; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.chunk.storage.AnvilChunkLoader; -import net.minecraft.world.chunk.storage.ExtendedBlockStorage; -import net.minecraft.world.chunk.storage.IChunkLoader; -import net.minecraft.world.gen.ChunkProviderServer; -import net.minecraft.world.gen.feature.WorldGeneratorBonusChest; -import net.minecraft.world.storage.ISaveHandler; -import net.minecraftforge.common.ChestGenHooks; -import static net.minecraftforge.common.ChestGenHooks.BONUS_CHEST; -import net.minecraftforge.common.DimensionManager; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.ForgeEventFactory; -import net.minecraftforge.event.world.WorldEvent; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.ultramine.server.chunk.ChunkHash; -import org.ultramine.server.chunk.PendingBlockUpdate; - -public class WorldServer extends World -{ - private static final Logger logger = LogManager.getLogger(); - private final MinecraftServer mcServer; - private final EntityTracker theEntityTracker; - private final PlayerManager thePlayerManager; - private Set pendingTickListEntriesHashSet; - private TreeSet pendingTickListEntriesTreeSet; - public ChunkProviderServer theChunkProviderServer; - public boolean levelSaving; - private boolean allPlayersSleeping; - private int updateEntityTick; - private final Teleporter worldTeleporter; - private final SpawnerAnimals animalSpawner = new SpawnerAnimals(); - private WorldServer.ServerBlockEventList[] field_147490_S = new WorldServer.ServerBlockEventList[] {new WorldServer.ServerBlockEventList(null), new WorldServer.ServerBlockEventList(null)}; - private int blockEventCacheIndex; - public static final WeightedRandomChestContent[] bonusChestContent = new WeightedRandomChestContent[] {new WeightedRandomChestContent(Items.stick, 0, 1, 3, 10), new WeightedRandomChestContent(Item.getItemFromBlock(Blocks.planks), 0, 1, 3, 10), new WeightedRandomChestContent(Item.getItemFromBlock(Blocks.log), 0, 1, 3, 10), new WeightedRandomChestContent(Items.stone_axe, 0, 1, 1, 3), new WeightedRandomChestContent(Items.wooden_axe, 0, 1, 1, 5), new WeightedRandomChestContent(Items.stone_pickaxe, 0, 1, 1, 3), new WeightedRandomChestContent(Items.wooden_pickaxe, 0, 1, 1, 5), new WeightedRandomChestContent(Items.apple, 0, 2, 3, 5), new WeightedRandomChestContent(Items.bread, 0, 2, 3, 3), new WeightedRandomChestContent(Item.getItemFromBlock(Blocks.log2), 0, 1, 3, 10)}; - private List pendingTickListEntriesThisTick = new ArrayList(); - private IntHashMap entityIdMap; - private static final String __OBFID = "CL_00001437"; - - /** Stores the recently processed (lighting) chunks */ - protected TIntSet doneChunks = new TIntHashSet(512); - public List customTeleporters = new ArrayList(); - - public WorldServer(MinecraftServer p_i45284_1_, ISaveHandler p_i45284_2_, String p_i45284_3_, int p_i45284_4_, WorldSettings p_i45284_5_, Profiler p_i45284_6_) - { - super(p_i45284_2_, p_i45284_3_, p_i45284_5_, WorldProvider.getProviderForDimension(p_i45284_4_), p_i45284_6_); - this.mcServer = p_i45284_1_; - this.theEntityTracker = new EntityTracker(this); - this.thePlayerManager = new PlayerManager(this, p_i45284_1_.getConfigurationManager().getViewDistance()); - - if (this.entityIdMap == null) - { - this.entityIdMap = new IntHashMap(); - } - - if (this.pendingTickListEntriesHashSet == null) - { - this.pendingTickListEntriesHashSet = new HashSet(); - } - - if (this.pendingTickListEntriesTreeSet == null) - { - this.pendingTickListEntriesTreeSet = new TreeSet(); - } - - this.worldTeleporter = new Teleporter(this); - this.worldScoreboard = new ServerScoreboard(p_i45284_1_); - ScoreboardSaveData scoreboardsavedata = (ScoreboardSaveData)this.mapStorage.loadData(ScoreboardSaveData.class, "scoreboard"); - - if (scoreboardsavedata == null) - { - scoreboardsavedata = new ScoreboardSaveData(); - this.mapStorage.setData("scoreboard", scoreboardsavedata); - } - - if (!(this instanceof WorldServerMulti)) //Forge: We fix the global mapStorage, which causes us to share scoreboards early. So don't associate the save data with the temporary scoreboard - { - scoreboardsavedata.func_96499_a(this.worldScoreboard); - } - ((ServerScoreboard)this.worldScoreboard).func_96547_a(scoreboardsavedata); - DimensionManager.setWorld(p_i45284_4_, this); - } - - public void tick() - { - super.tick(); - - if (this.getWorldInfo().isHardcoreModeEnabled() && this.difficultySetting != EnumDifficulty.HARD) - { - this.difficultySetting = EnumDifficulty.HARD; - } - - this.provider.worldChunkMgr.cleanupCache(); - - if (this.areAllPlayersAsleep()) - { - if (this.getGameRules().getGameRuleBooleanValue("doDaylightCycle")) - { - long i = this.worldInfo.getWorldTime() + 24000L; - this.worldInfo.setWorldTime(i - i % 24000L); - } - - this.wakeAllPlayers(); - } - - this.theProfiler.startSection("mobSpawner"); - - if (this.getGameRules().getGameRuleBooleanValue("doMobSpawning")) - { - this.animalSpawner.findChunksForSpawning(this, this.spawnHostileMobs, this.spawnPeacefulMobs, this.worldInfo.getWorldTotalTime() % 400L == 0L); - } - - this.theProfiler.endStartSection("chunkSource"); - this.chunkProvider.unloadQueuedChunks(); - int j = this.calculateSkylightSubtracted(1.0F); - - if (j != this.skylightSubtracted) - { - this.skylightSubtracted = j; - } - - this.worldInfo.incrementTotalWorldTime(this.worldInfo.getWorldTotalTime() + 1L); - - if (this.getGameRules().getGameRuleBooleanValue("doDaylightCycle")) - { - this.worldInfo.setWorldTime(this.worldInfo.getWorldTime() + 1L); - } - - this.theProfiler.endStartSection("tickPending"); - this.tickUpdates(false); - this.theProfiler.endStartSection("tickBlocks"); - this.func_147456_g(); - this.theProfiler.endStartSection("chunkMap"); - this.thePlayerManager.updatePlayerInstances(); - this.theProfiler.endStartSection("village"); - this.villageCollectionObj.tick(); - this.villageSiegeObj.tick(); - this.theProfiler.endStartSection("portalForcer"); - this.worldTeleporter.removeStalePortalLocations(this.getTotalWorldTime()); - for (Teleporter tele : customTeleporters) - { - tele.removeStalePortalLocations(getTotalWorldTime()); - } - this.theProfiler.endSection(); - this.func_147488_Z(); - } - - public BiomeGenBase.SpawnListEntry spawnRandomCreature(EnumCreatureType par1EnumCreatureType, int par2, int par3, int par4) - { - List list = this.getChunkProvider().getPossibleCreatures(par1EnumCreatureType, par2, par3, par4); - list = ForgeEventFactory.getPotentialSpawns(this, par1EnumCreatureType, par2, par3, par4, list); - return list != null && !list.isEmpty() ? (BiomeGenBase.SpawnListEntry)WeightedRandom.getRandomItem(this.rand, list) : null; - } - - public void updateAllPlayersSleepingFlag() - { - this.allPlayersSleeping = !this.playerEntities.isEmpty(); - Iterator iterator = this.playerEntities.iterator(); - - while (iterator.hasNext()) - { - EntityPlayer entityplayer = (EntityPlayer)iterator.next(); - - if (!entityplayer.isPlayerSleeping()) - { - this.allPlayersSleeping = false; - break; - } - } - } - - protected void wakeAllPlayers() - { - this.allPlayersSleeping = false; - Iterator iterator = this.playerEntities.iterator(); - - while (iterator.hasNext()) - { - EntityPlayer entityplayer = (EntityPlayer)iterator.next(); - - if (entityplayer.isPlayerSleeping()) - { - entityplayer.wakeUpPlayer(false, false, true); - } - } - - this.resetRainAndThunder(); - } - - private void resetRainAndThunder() - { - provider.resetRainAndThunder(); - } - - public boolean areAllPlayersAsleep() - { - if (this.allPlayersSleeping && !this.isRemote) - { - Iterator iterator = this.playerEntities.iterator(); - EntityPlayer entityplayer; - - do - { - if (!iterator.hasNext()) - { - return true; - } - - entityplayer = (EntityPlayer)iterator.next(); - } - while (entityplayer.isPlayerFullyAsleep()); - - return false; - } - else - { - return false; - } - } - - @SideOnly(Side.CLIENT) - public void setSpawnLocation() - { - if (this.worldInfo.getSpawnY() <= 0) - { - this.worldInfo.setSpawnY(64); - } - - int i = this.worldInfo.getSpawnX(); - int j = this.worldInfo.getSpawnZ(); - int k = 0; - - while (this.getTopBlock(i, j).getMaterial() == Material.air) - { - i += this.rand.nextInt(8) - this.rand.nextInt(8); - j += this.rand.nextInt(8) - this.rand.nextInt(8); - ++k; - - if (k == 10000) - { - break; - } - } - - this.worldInfo.setSpawnX(i); - this.worldInfo.setSpawnZ(j); - } - - protected void func_147456_g() - { - super.func_147456_g(); - int i = 0; - int j = 0; - - doneChunks.retainAll(activeChunkSet.keySet()); - if (doneChunks.size() == activeChunkSet.size()) - { - doneChunks.clear(); - } - - final long startTime = System.nanoTime(); - - for (TIntByteIterator iter = activeChunkSet.iterator(); iter.hasNext();) - { - iter.advance(); - int chunkCoord = iter.key(); - int chunkX = ChunkHash.keyToX(chunkCoord); - int chunkZ = ChunkHash.keyToZ(chunkCoord); - int k = chunkX << 4; - int l = chunkZ << 4; - - this.theProfiler.startSection("getChunk"); - Chunk chunk = this.getChunkFromChunkCoords(chunkX, chunkZ); - this.theProfiler.startSection("updatePending"); - this.updatePendingOf(chunk); - this.func_147467_a(k, l, chunk); - this.theProfiler.endStartSection("tickChunk"); - //Limits and evenly distributes the lighting update time - if (System.nanoTime() - startTime <= 4000000 && doneChunks.add(chunkCoord)) - { - chunk.func_150804_b(false); - } - this.theProfiler.endStartSection("thunder"); - int i1; - int j1; - int k1; - int l1; - - if (provider.canDoLightning(chunk) && this.rand.nextInt(100000) == 0 && this.isRaining() && this.isThundering()) - { - this.updateLCG = this.updateLCG * 3 + 1013904223; - i1 = this.updateLCG >> 2; - j1 = k + (i1 & 15); - k1 = l + (i1 >> 8 & 15); - l1 = this.getPrecipitationHeight(j1, k1); - - if (this.canLightningStrikeAt(j1, l1, k1)) - { - this.addWeatherEffect(new EntityLightningBolt(this, (double)j1, (double)l1, (double)k1)); - } - } - - this.theProfiler.endStartSection("iceandsnow"); - - if (provider.canDoRainSnowIce(chunk) && this.rand.nextInt(16) == 0) - { - this.updateLCG = this.updateLCG * 3 + 1013904223; - i1 = this.updateLCG >> 2; - j1 = i1 & 15; - k1 = i1 >> 8 & 15; - l1 = this.getPrecipitationHeight(j1 + k, k1 + l); - - if (this.isBlockFreezableNaturally(j1 + k, l1 - 1, k1 + l)) - { - this.setBlock(j1 + k, l1 - 1, k1 + l, Blocks.ice); - } - - if (this.isRaining() && this.func_147478_e(j1 + k, l1, k1 + l, true)) - { - this.setBlock(j1 + k, l1, k1 + l, Blocks.snow_layer); - } - - if (this.isRaining()) - { - BiomeGenBase biomegenbase = this.getBiomeGenForCoords(j1 + k, k1 + l); - - if (biomegenbase.canSpawnLightningBolt()) - { - this.getBlock(j1 + k, l1 - 1, k1 + l).fillWithRain(this, j1 + k, l1 - 1, k1 + l); - } - } - } - - this.theProfiler.endStartSection("tickBlocks"); - ExtendedBlockStorage[] aextendedblockstorage = chunk.getBlockStorageArray(); - j1 = aextendedblockstorage.length; - - for (k1 = 0; k1 < j1; ++k1) - { - ExtendedBlockStorage extendedblockstorage = aextendedblockstorage[k1]; - - if (extendedblockstorage != null && extendedblockstorage.getNeedsRandomTick()) - { - for (int i3 = 0; i3 < 3; ++i3) - { - this.updateLCG = this.updateLCG * 3 + 1013904223; - int i2 = this.updateLCG >> 2; - int j2 = i2 & 15; - int k2 = i2 >> 8 & 15; - int l2 = i2 >> 16 & 15; - ++j; - Block block = extendedblockstorage.getBlockByExtId(j2, l2, k2); - - if (block.getTickRandomly()) - { - ++i; - block.updateTick(this, j2 + k, l2 + extendedblockstorage.getYLocation(), k2 + l, this.rand); - } - } - } - } - - this.theProfiler.endSection(); - } - } - - public boolean isBlockTickScheduledThisTick(int p_147477_1_, int p_147477_2_, int p_147477_3_, Block p_147477_4_) - { - //Это не заглушка. Этот метод может использоваться модами по назначению, все работает правильно. - return false; - } - - public void scheduleBlockUpdate(int p_147464_1_, int p_147464_2_, int p_147464_3_, Block p_147464_4_, int p_147464_5_) - { - this.scheduleBlockUpdateWithPriority(p_147464_1_, p_147464_2_, p_147464_3_, p_147464_4_, p_147464_5_, 0); - } - - public void scheduleBlockUpdateWithPriority(int x, int y, int z, Block block, int time, int priority) - { - //NextTickListEntry nextticklistentry = new NextTickListEntry(x, y, z, block); - //Keeping here as a note for future when it may be restored. - //boolean isForced = getPersistentChunks().containsKey(new ChunkCoordIntPair(nextticklistentry.xCoord >> 4, nextticklistentry.zCoord >> 4)); - //byte b0 = isForced ? 0 : 8; - byte b0 = 0; - - if (this.scheduledUpdatesAreImmediate && block.getMaterial() != Material.air) - { - if (block.func_149698_L()) - { - b0 = 8; - - if (this.checkChunksExist(x - b0, y - b0, z - b0, x + b0, y + b0, z + b0)) - { - Block block1 = this.getBlock(x, y, z); - - if (block1.getMaterial() != Material.air && block1 == block) - { - block1.updateTick(this, x, y, z, this.rand); - } - } - - return; - } - - time = 1; - } - - Chunk chunk = getChunkIfExists(x >> 4, z >> 4); - - if (chunk != null) - { - PendingBlockUpdate p = new PendingBlockUpdate(x&15, y, z&15, block, worldInfo.getWorldTotalTime() + (long)time, priority); - chunk.scheduleBlockUpdate(p, true); - } - } - - public void func_147446_b(int p_147446_1_, int p_147446_2_, int p_147446_3_, Block p_147446_4_, int p_147446_5_, int p_147446_6_) - { - //Данный метод вызывался только при загрузке чанка. Для совместимости с модами, которые неправильно используют этот метод, пытаемся запланировать обновление. - Chunk chunk = getChunkIfExists(p_147446_1_ >> 4, p_147446_3_ >> 4); - - if (chunk != null) - { - PendingBlockUpdate p = new PendingBlockUpdate(p_147446_1_&15, p_147446_2_, p_147446_3_&15, p_147446_4_, worldInfo.getWorldTotalTime() + (long)p_147446_5_, p_147446_6_); - chunk.scheduleBlockUpdate(p, true); - } - } - - public void updateEntities() - { - if (this.playerEntities.isEmpty() && getPersistentChunks().isEmpty()) - { - if (this.updateEntityTick++ >= 1200) - { - return; - } - } - else - { - this.resetUpdateEntityTick(); - } - - super.updateEntities(); - } - - public void resetUpdateEntityTick() - { - this.updateEntityTick = 0; - } - - public boolean tickUpdates(boolean par1) - { - //Выполнение отложенных обновлений перенесено в updatePendingOf(Chunk) - return false; - } - - public List getPendingBlockUpdates(Chunk par1Chunk, boolean par2) - { - //Данный метод вызывался только при сохранении чанка. Теперь он не может вызываться нигде, совместимость не предусмотрена. - logger.warn("Called deprecated method getPendingBlockUpdates", new Throwable()); - return null; - } - - public void updateEntityWithOptionalForce(Entity par1Entity, boolean par2) - { - if (!this.mcServer.getCanSpawnAnimals() && (par1Entity instanceof EntityAnimal || par1Entity instanceof EntityWaterMob)) - { - par1Entity.setDead(); - } - - if (!this.mcServer.getCanSpawnNPCs() && par1Entity instanceof INpc) - { - par1Entity.setDead(); - } - - super.updateEntityWithOptionalForce(par1Entity, par2); - } - - protected IChunkProvider createChunkProvider() - { - IChunkLoader ichunkloader = this.saveHandler.getChunkLoader(this.provider); - this.theChunkProviderServer = new ChunkProviderServer(this, ichunkloader, this.provider.createChunkGenerator()); - return this.theChunkProviderServer; - } - - public List func_147486_a(int p_147486_1_, int p_147486_2_, int p_147486_3_, int p_147486_4_, int p_147486_5_, int p_147486_6_) - { - ArrayList arraylist = new ArrayList(); - - for(int x = (p_147486_1_ >> 4); x <= (p_147486_4_ >> 4); x++) - { - for(int z = (p_147486_3_ >> 4); z <= (p_147486_6_ >> 4); z++) - { - Chunk chunk = getChunkFromChunkCoords(x, z); - if (chunk != null) - { - for(Object obj : chunk.chunkTileEntityMap.values()) - { - TileEntity entity = (TileEntity)obj; - if (!entity.isInvalid()) - { - if (entity.xCoord >= p_147486_1_ && entity.yCoord >= p_147486_2_ && entity.zCoord >= p_147486_3_ && - entity.xCoord <= p_147486_4_ && entity.yCoord <= p_147486_5_ && entity.zCoord <= p_147486_6_) - { - arraylist.add(entity); - } - } - } - } - } - } - - return arraylist; - } - - public boolean canMineBlock(EntityPlayer par1EntityPlayer, int par2, int par3, int par4) - { - return super.canMineBlock(par1EntityPlayer, par2, par3, par4); - } - - public boolean canMineBlockBody(EntityPlayer par1EntityPlayer, int par2, int par3, int par4) - { - return !this.mcServer.isBlockProtected(this, par2, par3, par4, par1EntityPlayer); - } - - protected void initialize(WorldSettings par1WorldSettings) - { - if (this.entityIdMap == null) - { - this.entityIdMap = new IntHashMap(); - } - - if (this.pendingTickListEntriesHashSet == null) - { - this.pendingTickListEntriesHashSet = new HashSet(); - } - - if (this.pendingTickListEntriesTreeSet == null) - { - this.pendingTickListEntriesTreeSet = new TreeSet(); - } - - this.createSpawnPosition(par1WorldSettings); - super.initialize(par1WorldSettings); - } - - protected void createSpawnPosition(WorldSettings par1WorldSettings) - { - if (!this.provider.canRespawnHere()) - { - this.worldInfo.setSpawnPosition(0, this.provider.getAverageGroundLevel(), 0); - } - else - { - this.findingSpawnPoint = true; - WorldChunkManager worldchunkmanager = this.provider.worldChunkMgr; - List list = worldchunkmanager.getBiomesToSpawnIn(); - Random random = new Random(this.getSeed()); - ChunkPosition chunkposition = worldchunkmanager.findBiomePosition(0, 0, 256, list, random); - int i = 0; - int j = this.provider.getAverageGroundLevel(); - int k = 0; - - if (chunkposition != null) - { - i = chunkposition.chunkPosX; - k = chunkposition.chunkPosZ; - } - else - { - logger.warn("Unable to find spawn biome"); - } - - int l = 0; - - while (!this.provider.canCoordinateBeSpawn(i, k)) - { - i += random.nextInt(64) - random.nextInt(64); - k += random.nextInt(64) - random.nextInt(64); - ++l; - - if (l == 1000) - { - break; - } - } - - this.worldInfo.setSpawnPosition(i, j, k); - this.findingSpawnPoint = false; - - if (par1WorldSettings.isBonusChestEnabled()) - { - this.createBonusChest(); - } - } - } - - protected void createBonusChest() - { - WorldGeneratorBonusChest worldgeneratorbonuschest = new WorldGeneratorBonusChest(ChestGenHooks.getItems(BONUS_CHEST, rand), ChestGenHooks.getCount(BONUS_CHEST, rand)); - - for (int i = 0; i < 10; ++i) - { - int j = this.worldInfo.getSpawnX() + this.rand.nextInt(6) - this.rand.nextInt(6); - int k = this.worldInfo.getSpawnZ() + this.rand.nextInt(6) - this.rand.nextInt(6); - int l = this.getTopSolidOrLiquidBlock(j, k) + 1; - - if (worldgeneratorbonuschest.generate(this, this.rand, j, l, k)) - { - break; - } - } - } - - public ChunkCoordinates getEntrancePortalLocation() - { - return this.provider.getEntrancePortalLocation(); - } - - public void saveAllChunks(boolean par1, IProgressUpdate par2IProgressUpdate) throws MinecraftException - { - if (this.chunkProvider.canSave()) - { - if (par2IProgressUpdate != null) - { - par2IProgressUpdate.displayProgressMessage("Saving level"); - } - - this.saveLevel(); - - if (par2IProgressUpdate != null) - { - par2IProgressUpdate.resetProgresAndWorkingMessage("Saving chunks"); - } - - this.chunkProvider.saveChunks(par1, par2IProgressUpdate); - MinecraftForge.EVENT_BUS.post(new WorldEvent.Save(this)); - } - } - - public void saveChunkData() - { - if (this.chunkProvider.canSave()) - { - this.chunkProvider.saveExtraData(); - } - } - - protected void saveLevel() throws MinecraftException - { - this.checkSessionLock(); - this.saveHandler.saveWorldInfoWithPlayer(this.worldInfo, this.mcServer.getConfigurationManager().getHostPlayerData()); - this.mapStorage.saveAllData(); - this.perWorldStorage.saveAllData(); - } - - public void onEntityAdded(Entity par1Entity) - { - super.onEntityAdded(par1Entity); - this.entityIdMap.addKey(par1Entity.getEntityId(), par1Entity); - Entity[] aentity = par1Entity.getParts(); - - if (aentity != null) - { - for (int i = 0; i < aentity.length; ++i) - { - this.entityIdMap.addKey(aentity[i].getEntityId(), aentity[i]); - } - } - } - - public void onEntityRemoved(Entity par1Entity) - { - super.onEntityRemoved(par1Entity); - this.entityIdMap.removeObject(par1Entity.getEntityId()); - Entity[] aentity = par1Entity.getParts(); - - if (aentity != null) - { - for (int i = 0; i < aentity.length; ++i) - { - this.entityIdMap.removeObject(aentity[i].getEntityId()); - } - } - } - - public Entity getEntityByID(int par1) - { - return (Entity)this.entityIdMap.lookup(par1); - } - - public boolean addWeatherEffect(Entity par1Entity) - { - if (super.addWeatherEffect(par1Entity)) - { - this.mcServer.getConfigurationManager().sendToAllNear(par1Entity.posX, par1Entity.posY, par1Entity.posZ, 512.0D, this.provider.dimensionId, new S2CPacketSpawnGlobalEntity(par1Entity)); - return true; - } - else - { - return false; - } - } - - public void setEntityState(Entity par1Entity, byte par2) - { - this.getEntityTracker().func_151248_b(par1Entity, new S19PacketEntityStatus(par1Entity, par2)); - } - - public Explosion newExplosion(Entity par1Entity, double par2, double par4, double par6, float par8, boolean par9, boolean par10) - { - Explosion explosion = new Explosion(this, par1Entity, par2, par4, par6, par8); - explosion.isFlaming = par9; - explosion.isSmoking = par10; - explosion.doExplosionA(); - explosion.doExplosionB(false); - - if (!par10) - { - explosion.affectedBlockPositions.clear(); - } - - Iterator iterator = this.playerEntities.iterator(); - - while (iterator.hasNext()) - { - EntityPlayer entityplayer = (EntityPlayer)iterator.next(); - - if (entityplayer.getDistanceSq(par2, par4, par6) < 4096.0D) - { - ((EntityPlayerMP)entityplayer).playerNetServerHandler.sendPacket(new S27PacketExplosion(par2, par4, par6, par8, explosion.affectedBlockPositions, (Vec3)explosion.func_77277_b().get(entityplayer))); - } - } - - return explosion; - } - - public void addBlockEvent(int p_147452_1_, int p_147452_2_, int p_147452_3_, Block p_147452_4_, int p_147452_5_, int p_147452_6_) - { - BlockEventData blockeventdata = new BlockEventData(p_147452_1_, p_147452_2_, p_147452_3_, p_147452_4_, p_147452_5_, p_147452_6_); - Iterator iterator = this.field_147490_S[this.blockEventCacheIndex].iterator(); - BlockEventData blockeventdata1; - - do - { - if (!iterator.hasNext()) - { - this.field_147490_S[this.blockEventCacheIndex].add(blockeventdata); - return; - } - - blockeventdata1 = (BlockEventData)iterator.next(); - } - while (!blockeventdata1.equals(blockeventdata)); - } - - private void func_147488_Z() - { - while (!this.field_147490_S[this.blockEventCacheIndex].isEmpty()) - { - int i = this.blockEventCacheIndex; - this.blockEventCacheIndex ^= 1; - Iterator iterator = this.field_147490_S[i].iterator(); - - while (iterator.hasNext()) - { - BlockEventData blockeventdata = (BlockEventData)iterator.next(); - - if (this.func_147485_a(blockeventdata)) - { - this.mcServer.getConfigurationManager().sendToAllNear((double)blockeventdata.func_151340_a(), (double)blockeventdata.func_151342_b(), (double)blockeventdata.func_151341_c(), 64.0D, this.provider.dimensionId, new S24PacketBlockAction(blockeventdata.func_151340_a(), blockeventdata.func_151342_b(), blockeventdata.func_151341_c(), blockeventdata.getBlock(), blockeventdata.getEventID(), blockeventdata.getEventParameter())); - } - } - - this.field_147490_S[i].clear(); - } - } - - private boolean func_147485_a(BlockEventData p_147485_1_) - { - Block block = this.getBlock(p_147485_1_.func_151340_a(), p_147485_1_.func_151342_b(), p_147485_1_.func_151341_c()); - return block == p_147485_1_.getBlock() ? block.onBlockEventReceived(this, p_147485_1_.func_151340_a(), p_147485_1_.func_151342_b(), p_147485_1_.func_151341_c(), p_147485_1_.getEventID(), p_147485_1_.getEventParameter()) : false; - } - - public void flush() - { - this.saveHandler.flush(); - } - - protected void updateWeather() - { - boolean flag = this.isRaining(); - super.updateWeather(); - - if (this.prevRainingStrength != this.rainingStrength) - { - this.mcServer.getConfigurationManager().sendPacketToAllPlayersInDimension(new S2BPacketChangeGameState(7, this.rainingStrength), this.provider.dimensionId); - } - - if (this.prevThunderingStrength != this.thunderingStrength) - { - this.mcServer.getConfigurationManager().sendPacketToAllPlayersInDimension(new S2BPacketChangeGameState(8, this.thunderingStrength), this.provider.dimensionId); - } - - if (flag != this.isRaining()) - { - if (flag) - { - this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new S2BPacketChangeGameState(2, 0.0F)); - } - else - { - this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new S2BPacketChangeGameState(1, 0.0F)); - } - - this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new S2BPacketChangeGameState(7, this.rainingStrength)); - this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new S2BPacketChangeGameState(8, this.thunderingStrength)); - } - } - - public MinecraftServer func_73046_m() - { - return this.mcServer; - } - - public EntityTracker getEntityTracker() - { - return this.theEntityTracker; - } - - public PlayerManager getPlayerManager() - { - return this.thePlayerManager; - } - - public Teleporter getDefaultTeleporter() - { - return this.worldTeleporter; - } - - public void func_147487_a(String p_147487_1_, double p_147487_2_, double p_147487_4_, double p_147487_6_, int p_147487_8_, double p_147487_9_, double p_147487_11_, double p_147487_13_, double p_147487_15_) - { - S2APacketParticles s2apacketparticles = new S2APacketParticles(p_147487_1_, (float)p_147487_2_, (float)p_147487_4_, (float)p_147487_6_, (float)p_147487_9_, (float)p_147487_11_, (float)p_147487_13_, (float)p_147487_15_, p_147487_8_); - - for (int j = 0; j < this.playerEntities.size(); ++j) - { - EntityPlayerMP entityplayermp = (EntityPlayerMP)this.playerEntities.get(j); - ChunkCoordinates chunkcoordinates = entityplayermp.getPlayerCoordinates(); - double d7 = p_147487_2_ - (double)chunkcoordinates.posX; - double d8 = p_147487_4_ - (double)chunkcoordinates.posY; - double d9 = p_147487_6_ - (double)chunkcoordinates.posZ; - double d10 = d7 * d7 + d8 * d8 + d9 * d9; - - if (d10 <= 256.0D) - { - entityplayermp.playerNetServerHandler.sendPacket(s2apacketparticles); - } - } - } - - public File getChunkSaveLocation() - { - return ((AnvilChunkLoader)theChunkProviderServer.currentChunkLoader).chunkSaveLocation; - } - - static class ServerBlockEventList extends ArrayList - { - private static final String __OBFID = "CL_00001439"; - - private ServerBlockEventList() {} - - ServerBlockEventList(Object par1ServerBlockEvent) - { - this(); - } - } - - /* ======================================== ULTRAMINE START =====================================*/ - - public void checkSessionLock() throws MinecraftException - { - //Removes world lock checking on server - } - - public Chunk getChunkIfExists(int cx, int cz) - { - return theChunkProviderServer.getChunkIfExists(cx, cz); - } - - private void updatePendingOf(Chunk chunk) - { - long time = worldInfo.getWorldTotalTime(); - int x = chunk.xPosition << 4; - int z = chunk.zPosition << 4; - - PendingBlockUpdate p; - while((p = chunk.pollPending(time)) != null) - { - updateBlock(x + p.x, p.y, z + p.z, p.getBlock()); - } - } - - private void updateBlock(int x, int y, int z, Block block1) - { - Block block = this.getBlock(x, y, z); - - if (block.getMaterial() != Material.air && Block.isEqualTo(block, block1)) - { - try - { - block.updateTick(this, x, y, z, this.rand); - } - catch (Throwable throwable1) - { - CrashReport crashreport = CrashReport.makeCrashReport(throwable1, "Exception while ticking a block"); - CrashReportCategory crashreportcategory = crashreport.makeCategory("Block being ticked"); - int k; - - try - { - k = this.getBlockMetadata(x, y, z); - } - catch (Throwable throwable) - { - k = -1; - } - - CrashReportCategory.func_147153_a(crashreportcategory, x, y, z, block, k); - throw new ReportedException(crashreport); - } - } - } +package net.minecraft.world; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gnu.trove.iterator.TIntByteIterator; +import gnu.trove.set.TIntSet; +import gnu.trove.set.hash.TIntHashSet; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Random; +import java.util.Set; +import java.util.TreeSet; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockEventData; +import net.minecraft.block.material.Material; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityTracker; +import net.minecraft.entity.EnumCreatureType; +import net.minecraft.entity.INpc; +import net.minecraft.entity.effect.EntityLightningBolt; +import net.minecraft.entity.passive.EntityAnimal; +import net.minecraft.entity.passive.EntityWaterMob; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.network.play.server.S19PacketEntityStatus; +import net.minecraft.network.play.server.S24PacketBlockAction; +import net.minecraft.network.play.server.S27PacketExplosion; +import net.minecraft.network.play.server.S2APacketParticles; +import net.minecraft.network.play.server.S2BPacketChangeGameState; +import net.minecraft.network.play.server.S2CPacketSpawnGlobalEntity; +import net.minecraft.profiler.Profiler; +import net.minecraft.scoreboard.ScoreboardSaveData; +import net.minecraft.scoreboard.ServerScoreboard; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.management.PlayerManager; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.IProgressUpdate; +import net.minecraft.util.IntHashMap; +import net.minecraft.util.ReportedException; +import net.minecraft.util.Vec3; +import net.minecraft.util.WeightedRandom; +import net.minecraft.util.WeightedRandomChestContent; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.world.biome.WorldChunkManager; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.chunk.storage.AnvilChunkLoader; +import net.minecraft.world.chunk.storage.ExtendedBlockStorage; +import net.minecraft.world.chunk.storage.IChunkLoader; +import net.minecraft.world.gen.ChunkProviderServer; +import net.minecraft.world.gen.feature.WorldGeneratorBonusChest; +import net.minecraft.world.storage.ISaveHandler; +import net.minecraftforge.common.ChestGenHooks; +import static net.minecraftforge.common.ChestGenHooks.BONUS_CHEST; +import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.ForgeEventFactory; +import net.minecraftforge.event.world.WorldEvent; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.ultramine.server.WorldsConfig.WorldConfig; +import org.ultramine.server.chunk.ChunkHash; +import org.ultramine.server.chunk.PendingBlockUpdate; + +public class WorldServer extends World +{ + private static final Logger logger = LogManager.getLogger(); + private final MinecraftServer mcServer; + private final EntityTracker theEntityTracker; + private final PlayerManager thePlayerManager; + private Set pendingTickListEntriesHashSet; + private TreeSet pendingTickListEntriesTreeSet; + public ChunkProviderServer theChunkProviderServer; + public boolean levelSaving; + private boolean allPlayersSleeping; + private int updateEntityTick; + private final Teleporter worldTeleporter; + private final SpawnerAnimals animalSpawner = new SpawnerAnimals(); + private WorldServer.ServerBlockEventList[] field_147490_S = new WorldServer.ServerBlockEventList[] {new WorldServer.ServerBlockEventList(null), new WorldServer.ServerBlockEventList(null)}; + private int blockEventCacheIndex; + public static final WeightedRandomChestContent[] bonusChestContent = new WeightedRandomChestContent[] {new WeightedRandomChestContent(Items.stick, 0, 1, 3, 10), new WeightedRandomChestContent(Item.getItemFromBlock(Blocks.planks), 0, 1, 3, 10), new WeightedRandomChestContent(Item.getItemFromBlock(Blocks.log), 0, 1, 3, 10), new WeightedRandomChestContent(Items.stone_axe, 0, 1, 1, 3), new WeightedRandomChestContent(Items.wooden_axe, 0, 1, 1, 5), new WeightedRandomChestContent(Items.stone_pickaxe, 0, 1, 1, 3), new WeightedRandomChestContent(Items.wooden_pickaxe, 0, 1, 1, 5), new WeightedRandomChestContent(Items.apple, 0, 2, 3, 5), new WeightedRandomChestContent(Items.bread, 0, 2, 3, 3), new WeightedRandomChestContent(Item.getItemFromBlock(Blocks.log2), 0, 1, 3, 10)}; + private List pendingTickListEntriesThisTick = new ArrayList(); + private IntHashMap entityIdMap; + private static final String __OBFID = "CL_00001437"; + + /** Stores the recently processed (lighting) chunks */ + protected TIntSet doneChunks = new TIntHashSet(512); + public List customTeleporters = new ArrayList(); + + public WorldServer(MinecraftServer p_i45284_1_, ISaveHandler p_i45284_2_, String p_i45284_3_, int p_i45284_4_, WorldSettings p_i45284_5_, Profiler p_i45284_6_) + { + super(p_i45284_2_, p_i45284_3_, p_i45284_5_, WorldProvider.getProviderForDimension(p_i45284_4_), p_i45284_6_); + this.mcServer = p_i45284_1_; + this.theEntityTracker = new EntityTracker(this); + this.thePlayerManager = new PlayerManager(this, p_i45284_1_.getConfigurationManager().getViewDistance()); + + if (this.entityIdMap == null) + { + this.entityIdMap = new IntHashMap(); + } + + if (this.pendingTickListEntriesHashSet == null) + { + this.pendingTickListEntriesHashSet = new HashSet(); + } + + if (this.pendingTickListEntriesTreeSet == null) + { + this.pendingTickListEntriesTreeSet = new TreeSet(); + } + + this.worldTeleporter = new Teleporter(this); + this.worldScoreboard = new ServerScoreboard(p_i45284_1_); + ScoreboardSaveData scoreboardsavedata = (ScoreboardSaveData)this.mapStorage.loadData(ScoreboardSaveData.class, "scoreboard"); + + if (scoreboardsavedata == null) + { + scoreboardsavedata = new ScoreboardSaveData(); + this.mapStorage.setData("scoreboard", scoreboardsavedata); + } + + if (!(this instanceof WorldServerMulti)) //Forge: We fix the global mapStorage, which causes us to share scoreboards early. So don't associate the save data with the temporary scoreboard + { + scoreboardsavedata.func_96499_a(this.worldScoreboard); + } + ((ServerScoreboard)this.worldScoreboard).func_96547_a(scoreboardsavedata); + DimensionManager.setWorld(p_i45284_4_, this); + } + + public void tick() + { + super.tick(); + + if (this.getWorldInfo().isHardcoreModeEnabled() && this.difficultySetting != EnumDifficulty.HARD) + { + this.difficultySetting = EnumDifficulty.HARD; + } + + this.provider.worldChunkMgr.cleanupCache(); + + if (this.areAllPlayersAsleep()) + { + if (this.getGameRules().getGameRuleBooleanValue("doDaylightCycle")) + { + long i = this.worldInfo.getWorldTime() + 24000L; + this.worldInfo.setWorldTime(i - i % 24000L); + } + + this.wakeAllPlayers(); + } + + this.theProfiler.startSection("mobSpawner"); + + if (this.getGameRules().getGameRuleBooleanValue("doMobSpawning")) + { + this.animalSpawner.findChunksForSpawning(this, this.spawnHostileMobs, this.spawnPeacefulMobs, this.worldInfo.getWorldTotalTime() % 400L == 0L); + } + + this.theProfiler.endStartSection("chunkSource"); + this.chunkProvider.unloadQueuedChunks(); + int j = this.calculateSkylightSubtracted(1.0F); + + if (j != this.skylightSubtracted) + { + this.skylightSubtracted = j; + } + + this.worldInfo.incrementTotalWorldTime(this.worldInfo.getWorldTotalTime() + 1L); + + if (this.getGameRules().getGameRuleBooleanValue("doDaylightCycle")) + { + this.worldInfo.setWorldTime(this.worldInfo.getWorldTime() + 1L); + } + + this.theProfiler.endStartSection("tickPending"); + this.tickUpdates(false); + this.theProfiler.endStartSection("tickBlocks"); + this.func_147456_g(); + this.theProfiler.endStartSection("chunkMap"); + this.thePlayerManager.updatePlayerInstances(); + this.theProfiler.endStartSection("village"); + this.villageCollectionObj.tick(); + this.villageSiegeObj.tick(); + this.theProfiler.endStartSection("portalForcer"); + this.worldTeleporter.removeStalePortalLocations(this.getTotalWorldTime()); + for (Teleporter tele : customTeleporters) + { + tele.removeStalePortalLocations(getTotalWorldTime()); + } + this.theProfiler.endSection(); + this.func_147488_Z(); + } + + public BiomeGenBase.SpawnListEntry spawnRandomCreature(EnumCreatureType par1EnumCreatureType, int par2, int par3, int par4) + { + List list = this.getChunkProvider().getPossibleCreatures(par1EnumCreatureType, par2, par3, par4); + list = ForgeEventFactory.getPotentialSpawns(this, par1EnumCreatureType, par2, par3, par4, list); + return list != null && !list.isEmpty() ? (BiomeGenBase.SpawnListEntry)WeightedRandom.getRandomItem(this.rand, list) : null; + } + + public void updateAllPlayersSleepingFlag() + { + this.allPlayersSleeping = !this.playerEntities.isEmpty(); + Iterator iterator = this.playerEntities.iterator(); + + while (iterator.hasNext()) + { + EntityPlayer entityplayer = (EntityPlayer)iterator.next(); + + if (!entityplayer.isPlayerSleeping()) + { + this.allPlayersSleeping = false; + break; + } + } + } + + protected void wakeAllPlayers() + { + this.allPlayersSleeping = false; + Iterator iterator = this.playerEntities.iterator(); + + while (iterator.hasNext()) + { + EntityPlayer entityplayer = (EntityPlayer)iterator.next(); + + if (entityplayer.isPlayerSleeping()) + { + entityplayer.wakeUpPlayer(false, false, true); + } + } + + this.resetRainAndThunder(); + } + + private void resetRainAndThunder() + { + provider.resetRainAndThunder(); + } + + public boolean areAllPlayersAsleep() + { + if (this.allPlayersSleeping && !this.isRemote) + { + Iterator iterator = this.playerEntities.iterator(); + EntityPlayer entityplayer; + + do + { + if (!iterator.hasNext()) + { + return true; + } + + entityplayer = (EntityPlayer)iterator.next(); + } + while (entityplayer.isPlayerFullyAsleep()); + + return false; + } + else + { + return false; + } + } + + @SideOnly(Side.CLIENT) + public void setSpawnLocation() + { + if (this.worldInfo.getSpawnY() <= 0) + { + this.worldInfo.setSpawnY(64); + } + + int i = this.worldInfo.getSpawnX(); + int j = this.worldInfo.getSpawnZ(); + int k = 0; + + while (this.getTopBlock(i, j).getMaterial() == Material.air) + { + i += this.rand.nextInt(8) - this.rand.nextInt(8); + j += this.rand.nextInt(8) - this.rand.nextInt(8); + ++k; + + if (k == 10000) + { + break; + } + } + + this.worldInfo.setSpawnX(i); + this.worldInfo.setSpawnZ(j); + } + + protected void func_147456_g() + { + super.func_147456_g(); + int i = 0; + int j = 0; + + doneChunks.retainAll(activeChunkSet.keySet()); + if (doneChunks.size() == activeChunkSet.size()) + { + doneChunks.clear(); + } + + final long startTime = System.nanoTime(); + + for (TIntByteIterator iter = activeChunkSet.iterator(); iter.hasNext();) + { + iter.advance(); + int chunkCoord = iter.key(); + int chunkX = ChunkHash.keyToX(chunkCoord); + int chunkZ = ChunkHash.keyToZ(chunkCoord); + int k = chunkX << 4; + int l = chunkZ << 4; + + this.theProfiler.startSection("getChunk"); + Chunk chunk = this.getChunkFromChunkCoords(chunkX, chunkZ); + this.theProfiler.startSection("updatePending"); + this.updatePendingOf(chunk); + this.func_147467_a(k, l, chunk); + this.theProfiler.endStartSection("tickChunk"); + //Limits and evenly distributes the lighting update time + if (System.nanoTime() - startTime <= 4000000 && doneChunks.add(chunkCoord)) + { + chunk.func_150804_b(false); + } + this.theProfiler.endStartSection("thunder"); + int i1; + int j1; + int k1; + int l1; + + if (provider.canDoLightning(chunk) && this.rand.nextInt(100000) == 0 && this.isRaining() && this.isThundering()) + { + this.updateLCG = this.updateLCG * 3 + 1013904223; + i1 = this.updateLCG >> 2; + j1 = k + (i1 & 15); + k1 = l + (i1 >> 8 & 15); + l1 = this.getPrecipitationHeight(j1, k1); + + if (this.canLightningStrikeAt(j1, l1, k1)) + { + this.addWeatherEffect(new EntityLightningBolt(this, (double)j1, (double)l1, (double)k1)); + } + } + + this.theProfiler.endStartSection("iceandsnow"); + + if (provider.canDoRainSnowIce(chunk) && this.rand.nextInt(16) == 0) + { + this.updateLCG = this.updateLCG * 3 + 1013904223; + i1 = this.updateLCG >> 2; + j1 = i1 & 15; + k1 = i1 >> 8 & 15; + l1 = this.getPrecipitationHeight(j1 + k, k1 + l); + + if (this.isBlockFreezableNaturally(j1 + k, l1 - 1, k1 + l)) + { + this.setBlock(j1 + k, l1 - 1, k1 + l, Blocks.ice); + } + + if (this.isRaining() && this.func_147478_e(j1 + k, l1, k1 + l, true)) + { + this.setBlock(j1 + k, l1, k1 + l, Blocks.snow_layer); + } + + if (this.isRaining()) + { + BiomeGenBase biomegenbase = this.getBiomeGenForCoords(j1 + k, k1 + l); + + if (biomegenbase.canSpawnLightningBolt()) + { + this.getBlock(j1 + k, l1 - 1, k1 + l).fillWithRain(this, j1 + k, l1 - 1, k1 + l); + } + } + } + + this.theProfiler.endStartSection("tickBlocks"); + ExtendedBlockStorage[] aextendedblockstorage = chunk.getBlockStorageArray(); + j1 = aextendedblockstorage.length; + + for (k1 = 0; k1 < j1; ++k1) + { + ExtendedBlockStorage extendedblockstorage = aextendedblockstorage[k1]; + + if (extendedblockstorage != null && extendedblockstorage.getNeedsRandomTick()) + { + for (int i3 = 0; i3 < 3; ++i3) + { + this.updateLCG = this.updateLCG * 3 + 1013904223; + int i2 = this.updateLCG >> 2; + int j2 = i2 & 15; + int k2 = i2 >> 8 & 15; + int l2 = i2 >> 16 & 15; + ++j; + Block block = extendedblockstorage.getBlockByExtId(j2, l2, k2); + + if (block.getTickRandomly()) + { + ++i; + block.updateTick(this, j2 + k, l2 + extendedblockstorage.getYLocation(), k2 + l, this.rand); + } + } + } + } + + this.theProfiler.endSection(); + } + } + + public boolean isBlockTickScheduledThisTick(int p_147477_1_, int p_147477_2_, int p_147477_3_, Block p_147477_4_) + { + //Это не заглушка. Этот метод может использоваться модами по назначению, все работает правильно. + return false; + } + + public void scheduleBlockUpdate(int p_147464_1_, int p_147464_2_, int p_147464_3_, Block p_147464_4_, int p_147464_5_) + { + this.scheduleBlockUpdateWithPriority(p_147464_1_, p_147464_2_, p_147464_3_, p_147464_4_, p_147464_5_, 0); + } + + public void scheduleBlockUpdateWithPriority(int x, int y, int z, Block block, int time, int priority) + { + //NextTickListEntry nextticklistentry = new NextTickListEntry(x, y, z, block); + //Keeping here as a note for future when it may be restored. + //boolean isForced = getPersistentChunks().containsKey(new ChunkCoordIntPair(nextticklistentry.xCoord >> 4, nextticklistentry.zCoord >> 4)); + //byte b0 = isForced ? 0 : 8; + byte b0 = 0; + + if (this.scheduledUpdatesAreImmediate && block.getMaterial() != Material.air) + { + if (block.func_149698_L()) + { + b0 = 8; + + if (this.checkChunksExist(x - b0, y - b0, z - b0, x + b0, y + b0, z + b0)) + { + Block block1 = this.getBlock(x, y, z); + + if (block1.getMaterial() != Material.air && block1 == block) + { + block1.updateTick(this, x, y, z, this.rand); + } + } + + return; + } + + time = 1; + } + + Chunk chunk = getChunkIfExists(x >> 4, z >> 4); + + if (chunk != null) + { + PendingBlockUpdate p = new PendingBlockUpdate(x&15, y, z&15, block, worldInfo.getWorldTotalTime() + (long)time, priority); + chunk.scheduleBlockUpdate(p, true); + } + } + + public void func_147446_b(int p_147446_1_, int p_147446_2_, int p_147446_3_, Block p_147446_4_, int p_147446_5_, int p_147446_6_) + { + //Данный метод вызывался только при загрузке чанка. Для совместимости с модами, которые неправильно используют этот метод, пытаемся запланировать обновление. + Chunk chunk = getChunkIfExists(p_147446_1_ >> 4, p_147446_3_ >> 4); + + if (chunk != null) + { + PendingBlockUpdate p = new PendingBlockUpdate(p_147446_1_&15, p_147446_2_, p_147446_3_&15, p_147446_4_, worldInfo.getWorldTotalTime() + (long)p_147446_5_, p_147446_6_); + chunk.scheduleBlockUpdate(p, true); + } + } + + public void updateEntities() + { + if (this.playerEntities.isEmpty() && getPersistentChunks().isEmpty()) + { + if (this.updateEntityTick++ >= 1200) + { + return; + } + } + else + { + this.resetUpdateEntityTick(); + } + + super.updateEntities(); + } + + public void resetUpdateEntityTick() + { + this.updateEntityTick = 0; + } + + public boolean tickUpdates(boolean par1) + { + //Выполнение отложенных обновлений перенесено в updatePendingOf(Chunk) + return false; + } + + public List getPendingBlockUpdates(Chunk par1Chunk, boolean par2) + { + //Данный метод вызывался только при сохранении чанка. Теперь он не может вызываться нигде, совместимость не предусмотрена. + logger.warn("Called deprecated method getPendingBlockUpdates", new Throwable()); + return null; + } + + public void updateEntityWithOptionalForce(Entity par1Entity, boolean par2) + { + if (!getConfig().mobSpawn.spawnAnimals && (par1Entity instanceof EntityAnimal || par1Entity instanceof EntityWaterMob)) + { + par1Entity.setDead(); + } + + if (!getConfig().mobSpawn.spawnNPCs && par1Entity instanceof INpc) + { + par1Entity.setDead(); + } + + super.updateEntityWithOptionalForce(par1Entity, par2); + } + + protected IChunkProvider createChunkProvider() + { + IChunkLoader ichunkloader = this.saveHandler.getChunkLoader(this.provider); + this.theChunkProviderServer = new ChunkProviderServer(this, ichunkloader, this.provider.createChunkGenerator()); + return this.theChunkProviderServer; + } + + public List func_147486_a(int p_147486_1_, int p_147486_2_, int p_147486_3_, int p_147486_4_, int p_147486_5_, int p_147486_6_) + { + ArrayList arraylist = new ArrayList(); + + for(int x = (p_147486_1_ >> 4); x <= (p_147486_4_ >> 4); x++) + { + for(int z = (p_147486_3_ >> 4); z <= (p_147486_6_ >> 4); z++) + { + Chunk chunk = getChunkFromChunkCoords(x, z); + if (chunk != null) + { + for(Object obj : chunk.chunkTileEntityMap.values()) + { + TileEntity entity = (TileEntity)obj; + if (!entity.isInvalid()) + { + if (entity.xCoord >= p_147486_1_ && entity.yCoord >= p_147486_2_ && entity.zCoord >= p_147486_3_ && + entity.xCoord <= p_147486_4_ && entity.yCoord <= p_147486_5_ && entity.zCoord <= p_147486_6_) + { + arraylist.add(entity); + } + } + } + } + } + } + + return arraylist; + } + + public boolean canMineBlock(EntityPlayer par1EntityPlayer, int par2, int par3, int par4) + { + return super.canMineBlock(par1EntityPlayer, par2, par3, par4); + } + + public boolean canMineBlockBody(EntityPlayer par1EntityPlayer, int par2, int par3, int par4) + { + return !this.mcServer.isBlockProtected(this, par2, par3, par4, par1EntityPlayer); + } + + protected void initialize(WorldSettings par1WorldSettings) + { + if (this.entityIdMap == null) + { + this.entityIdMap = new IntHashMap(); + } + + if (this.pendingTickListEntriesHashSet == null) + { + this.pendingTickListEntriesHashSet = new HashSet(); + } + + if (this.pendingTickListEntriesTreeSet == null) + { + this.pendingTickListEntriesTreeSet = new TreeSet(); + } + + this.createSpawnPosition(par1WorldSettings); + super.initialize(par1WorldSettings); + } + + protected void createSpawnPosition(WorldSettings par1WorldSettings) + { + if (!this.provider.canRespawnHere()) + { + this.worldInfo.setSpawnPosition(0, this.provider.getAverageGroundLevel(), 0); + } + else + { + this.findingSpawnPoint = true; + WorldChunkManager worldchunkmanager = this.provider.worldChunkMgr; + List list = worldchunkmanager.getBiomesToSpawnIn(); + Random random = new Random(this.getSeed()); + ChunkPosition chunkposition = worldchunkmanager.findBiomePosition(0, 0, 256, list, random); + int i = 0; + int j = this.provider.getAverageGroundLevel(); + int k = 0; + + if (chunkposition != null) + { + i = chunkposition.chunkPosX; + k = chunkposition.chunkPosZ; + } + else + { + logger.warn("Unable to find spawn biome"); + } + + int l = 0; + + while (!this.provider.canCoordinateBeSpawn(i, k)) + { + i += random.nextInt(64) - random.nextInt(64); + k += random.nextInt(64) - random.nextInt(64); + ++l; + + if (l == 1000) + { + break; + } + } + + this.worldInfo.setSpawnPosition(i, j, k); + this.findingSpawnPoint = false; + + if (par1WorldSettings.isBonusChestEnabled()) + { + this.createBonusChest(); + } + } + } + + protected void createBonusChest() + { + WorldGeneratorBonusChest worldgeneratorbonuschest = new WorldGeneratorBonusChest(ChestGenHooks.getItems(BONUS_CHEST, rand), ChestGenHooks.getCount(BONUS_CHEST, rand)); + + for (int i = 0; i < 10; ++i) + { + int j = this.worldInfo.getSpawnX() + this.rand.nextInt(6) - this.rand.nextInt(6); + int k = this.worldInfo.getSpawnZ() + this.rand.nextInt(6) - this.rand.nextInt(6); + int l = this.getTopSolidOrLiquidBlock(j, k) + 1; + + if (worldgeneratorbonuschest.generate(this, this.rand, j, l, k)) + { + break; + } + } + } + + public ChunkCoordinates getEntrancePortalLocation() + { + return this.provider.getEntrancePortalLocation(); + } + + public void saveAllChunks(boolean par1, IProgressUpdate par2IProgressUpdate) throws MinecraftException + { + if (this.chunkProvider.canSave()) + { + if (par2IProgressUpdate != null) + { + par2IProgressUpdate.displayProgressMessage("Saving level"); + } + + this.saveLevel(); + + if (par2IProgressUpdate != null) + { + par2IProgressUpdate.resetProgresAndWorkingMessage("Saving chunks"); + } + + this.chunkProvider.saveChunks(par1, par2IProgressUpdate); + MinecraftForge.EVENT_BUS.post(new WorldEvent.Save(this)); + } + } + + public void saveChunkData() + { + if (this.chunkProvider.canSave()) + { + this.chunkProvider.saveExtraData(); + } + } + + protected void saveLevel() throws MinecraftException + { + this.checkSessionLock(); + this.saveHandler.saveWorldInfoWithPlayer(this.worldInfo, this.mcServer.getConfigurationManager().getHostPlayerData()); + this.mapStorage.saveAllData(); + this.perWorldStorage.saveAllData(); + } + + public void onEntityAdded(Entity par1Entity) + { + super.onEntityAdded(par1Entity); + this.entityIdMap.addKey(par1Entity.getEntityId(), par1Entity); + Entity[] aentity = par1Entity.getParts(); + + if (aentity != null) + { + for (int i = 0; i < aentity.length; ++i) + { + this.entityIdMap.addKey(aentity[i].getEntityId(), aentity[i]); + } + } + } + + public void onEntityRemoved(Entity par1Entity) + { + super.onEntityRemoved(par1Entity); + this.entityIdMap.removeObject(par1Entity.getEntityId()); + Entity[] aentity = par1Entity.getParts(); + + if (aentity != null) + { + for (int i = 0; i < aentity.length; ++i) + { + this.entityIdMap.removeObject(aentity[i].getEntityId()); + } + } + } + + public Entity getEntityByID(int par1) + { + return (Entity)this.entityIdMap.lookup(par1); + } + + public boolean addWeatherEffect(Entity par1Entity) + { + if (super.addWeatherEffect(par1Entity)) + { + this.mcServer.getConfigurationManager().sendToAllNear(par1Entity.posX, par1Entity.posY, par1Entity.posZ, 512.0D, this.provider.dimensionId, new S2CPacketSpawnGlobalEntity(par1Entity)); + return true; + } + else + { + return false; + } + } + + public void setEntityState(Entity par1Entity, byte par2) + { + this.getEntityTracker().func_151248_b(par1Entity, new S19PacketEntityStatus(par1Entity, par2)); + } + + public Explosion newExplosion(Entity par1Entity, double par2, double par4, double par6, float par8, boolean par9, boolean par10) + { + Explosion explosion = new Explosion(this, par1Entity, par2, par4, par6, par8); + explosion.isFlaming = par9; + explosion.isSmoking = par10; + explosion.doExplosionA(); + explosion.doExplosionB(false); + + if (!par10) + { + explosion.affectedBlockPositions.clear(); + } + + Iterator iterator = this.playerEntities.iterator(); + + while (iterator.hasNext()) + { + EntityPlayer entityplayer = (EntityPlayer)iterator.next(); + + if (entityplayer.getDistanceSq(par2, par4, par6) < 4096.0D) + { + ((EntityPlayerMP)entityplayer).playerNetServerHandler.sendPacket(new S27PacketExplosion(par2, par4, par6, par8, explosion.affectedBlockPositions, (Vec3)explosion.func_77277_b().get(entityplayer))); + } + } + + return explosion; + } + + public void addBlockEvent(int p_147452_1_, int p_147452_2_, int p_147452_3_, Block p_147452_4_, int p_147452_5_, int p_147452_6_) + { + BlockEventData blockeventdata = new BlockEventData(p_147452_1_, p_147452_2_, p_147452_3_, p_147452_4_, p_147452_5_, p_147452_6_); + Iterator iterator = this.field_147490_S[this.blockEventCacheIndex].iterator(); + BlockEventData blockeventdata1; + + do + { + if (!iterator.hasNext()) + { + this.field_147490_S[this.blockEventCacheIndex].add(blockeventdata); + return; + } + + blockeventdata1 = (BlockEventData)iterator.next(); + } + while (!blockeventdata1.equals(blockeventdata)); + } + + private void func_147488_Z() + { + while (!this.field_147490_S[this.blockEventCacheIndex].isEmpty()) + { + int i = this.blockEventCacheIndex; + this.blockEventCacheIndex ^= 1; + Iterator iterator = this.field_147490_S[i].iterator(); + + while (iterator.hasNext()) + { + BlockEventData blockeventdata = (BlockEventData)iterator.next(); + + if (this.func_147485_a(blockeventdata)) + { + this.mcServer.getConfigurationManager().sendToAllNear((double)blockeventdata.func_151340_a(), (double)blockeventdata.func_151342_b(), (double)blockeventdata.func_151341_c(), 64.0D, this.provider.dimensionId, new S24PacketBlockAction(blockeventdata.func_151340_a(), blockeventdata.func_151342_b(), blockeventdata.func_151341_c(), blockeventdata.getBlock(), blockeventdata.getEventID(), blockeventdata.getEventParameter())); + } + } + + this.field_147490_S[i].clear(); + } + } + + private boolean func_147485_a(BlockEventData p_147485_1_) + { + Block block = this.getBlock(p_147485_1_.func_151340_a(), p_147485_1_.func_151342_b(), p_147485_1_.func_151341_c()); + return block == p_147485_1_.getBlock() ? block.onBlockEventReceived(this, p_147485_1_.func_151340_a(), p_147485_1_.func_151342_b(), p_147485_1_.func_151341_c(), p_147485_1_.getEventID(), p_147485_1_.getEventParameter()) : false; + } + + public void flush() + { + this.saveHandler.flush(); + } + + protected void updateWeather() + { + boolean flag = this.isRaining(); + super.updateWeather(); + + if (this.prevRainingStrength != this.rainingStrength) + { + this.mcServer.getConfigurationManager().sendPacketToAllPlayersInDimension(new S2BPacketChangeGameState(7, this.rainingStrength), this.provider.dimensionId); + } + + if (this.prevThunderingStrength != this.thunderingStrength) + { + this.mcServer.getConfigurationManager().sendPacketToAllPlayersInDimension(new S2BPacketChangeGameState(8, this.thunderingStrength), this.provider.dimensionId); + } + + if (flag != this.isRaining()) + { + if (flag) + { + this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new S2BPacketChangeGameState(2, 0.0F)); + } + else + { + this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new S2BPacketChangeGameState(1, 0.0F)); + } + + this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new S2BPacketChangeGameState(7, this.rainingStrength)); + this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new S2BPacketChangeGameState(8, this.thunderingStrength)); + } + } + + public MinecraftServer func_73046_m() + { + return this.mcServer; + } + + public EntityTracker getEntityTracker() + { + return this.theEntityTracker; + } + + public PlayerManager getPlayerManager() + { + return this.thePlayerManager; + } + + public Teleporter getDefaultTeleporter() + { + return this.worldTeleporter; + } + + public void func_147487_a(String p_147487_1_, double p_147487_2_, double p_147487_4_, double p_147487_6_, int p_147487_8_, double p_147487_9_, double p_147487_11_, double p_147487_13_, double p_147487_15_) + { + S2APacketParticles s2apacketparticles = new S2APacketParticles(p_147487_1_, (float)p_147487_2_, (float)p_147487_4_, (float)p_147487_6_, (float)p_147487_9_, (float)p_147487_11_, (float)p_147487_13_, (float)p_147487_15_, p_147487_8_); + + for (int j = 0; j < this.playerEntities.size(); ++j) + { + EntityPlayerMP entityplayermp = (EntityPlayerMP)this.playerEntities.get(j); + ChunkCoordinates chunkcoordinates = entityplayermp.getPlayerCoordinates(); + double d7 = p_147487_2_ - (double)chunkcoordinates.posX; + double d8 = p_147487_4_ - (double)chunkcoordinates.posY; + double d9 = p_147487_6_ - (double)chunkcoordinates.posZ; + double d10 = d7 * d7 + d8 * d8 + d9 * d9; + + if (d10 <= 256.0D) + { + entityplayermp.playerNetServerHandler.sendPacket(s2apacketparticles); + } + } + } + + public File getChunkSaveLocation() + { + return ((AnvilChunkLoader)theChunkProviderServer.currentChunkLoader).chunkSaveLocation; + } + + static class ServerBlockEventList extends ArrayList + { + private static final String __OBFID = "CL_00001439"; + + private ServerBlockEventList() {} + + ServerBlockEventList(Object par1ServerBlockEvent) + { + this(); + } + } + + /* ======================================== ULTRAMINE START =====================================*/ + + private WorldConfig config; + + public void checkSessionLock() throws MinecraftException + { + //Removes world lock checking on server + } + + public Chunk getChunkIfExists(int cx, int cz) + { + return theChunkProviderServer.getChunkIfExists(cx, cz); + } + + private void updatePendingOf(Chunk chunk) + { + long time = worldInfo.getWorldTotalTime(); + int x = chunk.xPosition << 4; + int z = chunk.zPosition << 4; + + PendingBlockUpdate p; + while((p = chunk.pollPending(time)) != null) + { + updateBlock(x + p.x, p.y, z + p.z, p.getBlock()); + } + } + + private void updateBlock(int x, int y, int z, Block block1) + { + Block block = this.getBlock(x, y, z); + + if (block.getMaterial() != Material.air && Block.isEqualTo(block, block1)) + { + try + { + block.updateTick(this, x, y, z, this.rand); + } + catch (Throwable throwable1) + { + CrashReport crashreport = CrashReport.makeCrashReport(throwable1, "Exception while ticking a block"); + CrashReportCategory crashreportcategory = crashreport.makeCategory("Block being ticked"); + int k; + + try + { + k = this.getBlockMetadata(x, y, z); + } + catch (Throwable throwable) + { + k = -1; + } + + CrashReportCategory.func_147153_a(crashreportcategory, x, y, z, block, k); + throw new ReportedException(crashreport); + } + } + } + + public void setConfig(WorldConfig config) + { + this.config = config; + } + + public WorldConfig getConfig() + { + return config; + } + + protected boolean isChunkLoaderEnabled() + { + return config.chunkLoading.enableChunkLoaders; + } + + protected int getChunkUpdateRadius() + { + return config.chunkLoading.chunkUpdateRadius; + } } \ No newline at end of file diff --git a/src/main/java/net/minecraft/world/chunk/storage/AnvilSaveHandler.java b/src/main/java/net/minecraft/world/chunk/storage/AnvilSaveHandler.java index 651f633..796d4c2 100644 --- a/src/main/java/net/minecraft/world/chunk/storage/AnvilSaveHandler.java +++ b/src/main/java/net/minecraft/world/chunk/storage/AnvilSaveHandler.java @@ -1,57 +1,66 @@ -package net.minecraft.world.chunk.storage; - -import java.io.File; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.WorldProvider; -import net.minecraft.world.WorldProviderEnd; -import net.minecraft.world.WorldProviderHell; -import net.minecraft.world.storage.SaveHandler; -import net.minecraft.world.storage.ThreadedFileIOBase; -import net.minecraft.world.storage.WorldInfo; - -public class AnvilSaveHandler extends SaveHandler -{ - private static final String __OBFID = "CL_00000581"; - - public AnvilSaveHandler(File par1File, String par2Str, boolean par3) - { - super(par1File, par2Str, par3); - } - - public IChunkLoader getChunkLoader(WorldProvider par1WorldProvider) - { - File file1 = this.getWorldDirectory(); - File file2; - - if (par1WorldProvider.getSaveFolder() != null) - { - file2 = new File(file1, par1WorldProvider.getSaveFolder()); - file2.mkdirs(); - return new AnvilChunkLoader(file2); - } - else - { - return new AnvilChunkLoader(file1); - } - } - - public void saveWorldInfoWithPlayer(WorldInfo par1WorldInfo, NBTTagCompound par2NBTTagCompound) - { - par1WorldInfo.setSaveVersion(19133); - super.saveWorldInfoWithPlayer(par1WorldInfo, par2NBTTagCompound); - } - - public void flush() - { - try - { - ThreadedFileIOBase.threadedIOInstance.waitForFinish(); - } - catch (InterruptedException interruptedexception) - { - interruptedexception.printStackTrace(); - } - - RegionFileCache.clearRegionFileReferences(); - } +package net.minecraft.world.chunk.storage; + +import java.io.File; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.WorldProvider; +import net.minecraft.world.WorldProviderEnd; +import net.minecraft.world.WorldProviderHell; +import net.minecraft.world.storage.SaveHandler; +import net.minecraft.world.storage.ThreadedFileIOBase; +import net.minecraft.world.storage.WorldInfo; + +public class AnvilSaveHandler extends SaveHandler +{ + private static final String __OBFID = "CL_00000581"; + + public AnvilSaveHandler(File par1File, String par2Str, boolean par3) + { + super(par1File, par2Str, par3); + } + + public IChunkLoader getChunkLoader(WorldProvider par1WorldProvider) + { + File file1 = this.getWorldDirectory(); + File file2; + + if (!isSingleStorage && par1WorldProvider.getSaveFolder() != null) + { + file2 = new File(file1, par1WorldProvider.getSaveFolder()); + file2.mkdirs(); + return new AnvilChunkLoader(file2); + } + else + { + return new AnvilChunkLoader(file1); + } + } + + public void saveWorldInfoWithPlayer(WorldInfo par1WorldInfo, NBTTagCompound par2NBTTagCompound) + { + par1WorldInfo.setSaveVersion(19133); + super.saveWorldInfoWithPlayer(par1WorldInfo, par2NBTTagCompound); + } + + public void flush() + { + try + { + ThreadedFileIOBase.threadedIOInstance.waitForFinish(); + } + catch (InterruptedException interruptedexception) + { + interruptedexception.printStackTrace(); + } + + RegionFileCache.clearRegionFileReferences(); + } + + /* ======================================== ULTRAMINE START =====================================*/ + + private boolean isSingleStorage; + + public void setSingleStorage() + { + isSingleStorage = true; + } } \ No newline at end of file diff --git a/src/main/java/org/ultramine/server/ConfigurationHandler.java b/src/main/java/org/ultramine/server/ConfigurationHandler.java index b23b36f..99fb251 100644 --- a/src/main/java/org/ultramine/server/ConfigurationHandler.java +++ b/src/main/java/org/ultramine/server/ConfigurationHandler.java @@ -1,50 +1,66 @@ -package org.ultramine.server; - -import java.io.File; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.ultramine.server.util.YamlConfigProvider; - -import cpw.mods.fml.relauncher.FMLLaunchHandler; - -public class ConfigurationHandler -{ - public static Logger log = LogManager.getLogger(); - - private static File settingsDir = new File(FMLLaunchHandler.getMinecraftHome(), "settings"); - private static File worldsDir = new File(FMLLaunchHandler.getMinecraftHome(), "worlds"); - private static File serverConfigFile = new File(getSettingDir(), "server.yml"); - - private static UltramineServerConfig serverConfig; - - static - { - if(!settingsDir.exists()) settingsDir.mkdir(); - if(!worldsDir.exists()) worldsDir.mkdir(); - } - - public static void load() - { - serverConfig = YamlConfigProvider.getOrCreateConfig(serverConfigFile, UltramineServerConfig.class); - } - - public static File getSettingDir() - { - return settingsDir; - } - - public static File getWorldsDir() - { - return worldsDir; - } - - public static UltramineServerConfig getServerConfig() - { - return serverConfig; - } - - public static void saveServerConfig() - { - YamlConfigProvider.saveConfig(serverConfigFile, serverConfig); - } -} +package org.ultramine.server; + +import java.io.File; +import java.util.Random; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.ultramine.server.util.Resources; +import org.ultramine.server.util.YamlConfigProvider; + +import cpw.mods.fml.relauncher.FMLLaunchHandler; + +public class ConfigurationHandler +{ + public static Logger log = LogManager.getLogger(); + + private static File settingsDir = new File(FMLLaunchHandler.getMinecraftHome(), "settings"); + private static File worldsDir = new File(FMLLaunchHandler.getMinecraftHome(), "worlds"); + + private static File serverConfigFile = new File(getSettingDir(), "server.yml"); + private static File worldsConfigFile = new File(getSettingDir(), "worlds.yml"); + + private static UltramineServerConfig serverConfig; + private static WorldsConfig worldsConfig; + + static + { + if(!settingsDir.exists()) settingsDir.mkdir(); + if(!worldsDir.exists()) worldsDir.mkdir(); + } + + public static void load() + { + serverConfig = YamlConfigProvider.getOrCreateConfig(serverConfigFile, UltramineServerConfig.class); + + if(!worldsConfigFile.exists()) + YamlConfigProvider.writeFile(worldsConfigFile, Resources.getAsString("/org/ultramine/defaults/defaultworlds.yml") + .replace("{seed}", Long.toString(Math.abs(new Random().nextLong())))); + worldsConfig = YamlConfigProvider.readConfig(worldsConfigFile, WorldsConfig.class); + } + + public static File getSettingDir() + { + return settingsDir; + } + + public static File getWorldsDir() + { + return worldsDir; + } + + public static UltramineServerConfig getServerConfig() + { + return serverConfig; + } + + public static WorldsConfig getWorldsConfig() + { + return worldsConfig; + } + + public static void saveServerConfig() + { + YamlConfigProvider.saveConfig(serverConfigFile, serverConfig); + } +} diff --git a/src/main/java/org/ultramine/server/MultiWorld.java b/src/main/java/org/ultramine/server/MultiWorld.java new file mode 100644 index 0000000..fc1d6e3 --- /dev/null +++ b/src/main/java/org/ultramine/server/MultiWorld.java @@ -0,0 +1,189 @@ +package org.ultramine.server; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.ultramine.server.WorldsConfig.WorldConfig; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.PlayerEvent; +import cpw.mods.fml.common.network.FMLEmbeddedChannel; +import cpw.mods.fml.common.network.FMLOutboundHandler; +import cpw.mods.fml.common.network.NetworkRegistry; +import cpw.mods.fml.relauncher.Side; +import gnu.trove.map.TIntObjectMap; +import gnu.trove.map.hash.TIntObjectHashMap; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.WorldManager; +import net.minecraft.world.WorldServer; +import net.minecraft.world.WorldServerMulti; +import net.minecraft.world.WorldSettings; +import net.minecraft.world.WorldType; +import net.minecraft.world.chunk.storage.AnvilSaveHandler; +import net.minecraft.world.storage.ISaveFormat; +import net.minecraft.world.storage.ISaveHandler; +import net.minecraft.world.storage.WorldInfo; +import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.network.ForgeMessage; +import net.minecraftforge.event.world.WorldEvent; + +public class MultiWorld +{ + private static final Logger log = LogManager.getLogger(); + private final TIntObjectMap dimToWorldMap = new TIntObjectHashMap(); + private final Map nameToWorldMap = new HashMap(); + private final MinecraftServer server; + + public MultiWorld(MinecraftServer server) + { + this.server = server; + } + + @SubscribeEvent + public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) + { + FMLEmbeddedChannel channel = NetworkRegistry.INSTANCE.getChannel("FORGE", Side.SERVER); + channel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER); + channel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(event.player); + for (int dim : DimensionManager.getStaticDimensionIDs()) + { + channel.writeAndFlush(new ForgeMessage.DimensionRegisterMessage(dim, DimensionManager.getProviderType(dim))); + } + } + + public void handleServerWorldsInit() + { + DimensionManager.unregisterDimension(-1); + DimensionManager.unregisterDimension(0); + DimensionManager.unregisterDimension(1); + + Map worlds = ConfigurationHandler.getWorldsConfig().worlds; + TIntObjectHashMap dimToNameMap = new TIntObjectHashMap(); + + for(Map.Entry ent : worlds.entrySet()) + { + WorldConfig conf = ent.getValue(); + DimensionManager.registerDimension(conf.dimension, conf.generation.providerID); + + dimToNameMap.put(conf.dimension, ent.getKey()); + } + + String mainWorldName = dimToNameMap.get(0); + if(mainWorldName == null) + mainWorldName = "world"; + + WorldConfig mainConf = worlds.get(mainWorldName); + if(mainConf == null) + mainConf = ConfigurationHandler.getWorldsConfig().global; + + ISaveFormat format = server.getActiveAnvilConverter(); + ISaveHandler mainSaveHandler = format.getSaveLoader(mainWorldName, true); + WorldSettings mainSettings = makeSettings(mainSaveHandler, mainConf); + + WorldServer mainWorld = new WorldServer(server, mainSaveHandler, mainWorldName, mainConf.dimension, mainSettings, server.theProfiler); + + initWorld(mainWorld, mainConf); + + for (int dim : DimensionManager.getStaticDimensionIDs()) + { + if(dim == mainConf.dimension) continue; + + String name = dimToNameMap.get(dim); + WorldConfig conf = name == null ? null : worlds.get(name); + WorldServer world; + + if(conf == null) + { + log.warn("World with dimension id:%d was loaded bypass worlds configuration. Using global config", dim); + world = new WorldServerMulti(server, mainSaveHandler, mainWorldName, dim, mainSettings, mainWorld, server.theProfiler); + } + else + { + ISaveHandler save = format.getSaveLoader(name, false); + ((AnvilSaveHandler)save).setSingleStorage(); + world = new WorldServer(server, save, name, dim, makeSettings(save, conf), server.theProfiler); + } + + initWorld(world, conf); + } + } + + private WorldSettings makeSettings(ISaveHandler save, WorldConfig conf) + { + WorldInfo mainWorldInfo = save.loadWorldInfo(); + WorldSettings mainSettings; + + if (mainWorldInfo == null) + { + mainSettings = new WorldSettings(toSeed(conf.generation.seed), server.getGameType(), conf.generation.generateStructures, + server.isHardcore(), WorldType.parseWorldType(conf.generation.levelType)); + mainSettings.func_82750_a(conf.generation.generatorSettings); + } + else + { + mainSettings = new WorldSettings(mainWorldInfo); + } + + return mainSettings; + } + + private static long toSeed(String seedstr) + { + try + { + return Long.parseLong(seedstr); + } + catch (NumberFormatException e) + { + return seedstr.hashCode(); + } + } + + private void initWorld(WorldServer world, WorldConfig conf) + { + world.addWorldAccess(new WorldManager(server, world)); + + if (!server.isSinglePlayer()) + world.getWorldInfo().setGameType(server.getGameType()); + + world.difficultySetting = EnumDifficulty.getDifficultyEnum(conf.settings.difficulty); + world.setAllowedSpawnTypes(conf.mobSpawn.spawnMonsters, conf.mobSpawn.spawnAnimals); + world.setConfig(conf); + + MinecraftForge.EVENT_BUS.post(new WorldEvent.Load(world)); + + String name = world.getWorldInfo().getWorldName(); + dimToWorldMap.put(world.provider.dimensionId, world); + if(nameToWorldMap.containsKey(name)) + nameToWorldMap.put(name + world.provider.dimensionId, world); + else + nameToWorldMap.put(name, world); + } + + public WorldServer getWorldById(int dim) + { + return dimToWorldMap.get(dim); + } + + public WorldServer getWorldByName(String name) + { + return nameToWorldMap.get(name); + } + + public void register() + { + FMLCommonHandler.instance().bus().register(this); + } + + public void unregister() + { + FMLCommonHandler.instance().bus().unregister(this); + dimToWorldMap.clear(); + nameToWorldMap.clear(); + } +} diff --git a/src/main/java/org/ultramine/server/UltramineServerModContainer.java b/src/main/java/org/ultramine/server/UltramineServerModContainer.java index f43619a..a70a6e9 100644 --- a/src/main/java/org/ultramine/server/UltramineServerModContainer.java +++ b/src/main/java/org/ultramine/server/UltramineServerModContainer.java @@ -1,98 +1,113 @@ -package org.ultramine.server; - -import java.io.File; -import java.util.List; -import java.util.Map; - -import com.google.common.collect.ImmutableList; -import com.google.common.eventbus.EventBus; -import com.google.common.eventbus.Subscribe; - -import cpw.mods.fml.common.DummyModContainer; -import cpw.mods.fml.common.LoadController; -import cpw.mods.fml.common.ModMetadata; -import cpw.mods.fml.common.event.FMLConstructionEvent; -import cpw.mods.fml.common.event.FMLPostInitializationEvent; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.event.FMLServerStartingEvent; -import cpw.mods.fml.common.event.FMLServerStoppedEvent; -import cpw.mods.fml.common.network.NetworkCheckHandler; -import cpw.mods.fml.common.network.NetworkRegistry; -import cpw.mods.fml.relauncher.Side; -import org.ultramine.commands.syntax.DefaultCompleters; -import org.ultramine.permission.commands.BasicPermissionCommands; - -public class UltramineServerModContainer extends DummyModContainer -{ - public UltramineServerModContainer() - { - super(new ModMetadata()); - ModMetadata meta = getMetadata(); - meta.modId = "UltramineServer"; - meta.name = "Ultramine Server"; - meta.version = "1.0"; - } - - @Override - public boolean registerBus(EventBus bus, LoadController controller) - { - bus.register(this); - return true; - } - - @Subscribe - public void modConstruction(FMLConstructionEvent evt) - { - NetworkRegistry.INSTANCE.register(this, this.getClass(), null, evt.getASMHarvestedData()); - } - - @Subscribe - public void preInit(FMLPreInitializationEvent e) - { - ConfigurationHandler.load(); - } - - @Subscribe - public void postInit(FMLPostInitializationEvent e) - { - ConfigurationHandler.saveServerConfig(); - } - - @NetworkCheckHandler - public boolean networkCheck(Map map, Side side) - { - return true; - } - - @Override - public File getSource() - { - return UltraminePlugin.location; - } - - @Override - public List getOwnedPackages() - { - return ImmutableList.of( - "org.ultramine.server" - ); - } - - @Subscribe - public void serverStarting(FMLServerStartingEvent e) - { - e.registerArgumentHandlers(DefaultCompleters.class); - e.registerCommands(BasicPermissionCommands.class); - } - - @Subscribe - public void stopServer(FMLServerStoppedEvent e) - { - } - - @Override - public Object getMod() - { - return this; - } -} +package org.ultramine.server; + +import java.io.File; +import java.util.List; +import java.util.Map; + +import net.minecraft.server.MinecraftServer; + +import com.google.common.collect.ImmutableList; +import com.google.common.eventbus.EventBus; +import com.google.common.eventbus.Subscribe; + +import cpw.mods.fml.common.DummyModContainer; +import cpw.mods.fml.common.LoadController; +import cpw.mods.fml.common.ModMetadata; +import cpw.mods.fml.common.event.FMLConstructionEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.event.FMLServerAboutToStartEvent; +import cpw.mods.fml.common.event.FMLServerStartingEvent; +import cpw.mods.fml.common.event.FMLServerStoppedEvent; +import cpw.mods.fml.common.network.NetworkCheckHandler; +import cpw.mods.fml.common.network.NetworkRegistry; +import cpw.mods.fml.relauncher.Side; +import org.ultramine.commands.syntax.DefaultCompleters; +import org.ultramine.permission.commands.BasicPermissionCommands; + +public class UltramineServerModContainer extends DummyModContainer +{ + public UltramineServerModContainer() + { + super(new ModMetadata()); + ModMetadata meta = getMetadata(); + meta.modId = "UltramineServer"; + meta.name = "Ultramine Server"; + meta.version = "1.0"; + } + + @Override + public boolean registerBus(EventBus bus, LoadController controller) + { + bus.register(this); + return true; + } + + @Subscribe + public void modConstruction(FMLConstructionEvent evt) + { + NetworkRegistry.INSTANCE.register(this, this.getClass(), null, evt.getASMHarvestedData()); + } + + @Subscribe + public void preInit(FMLPreInitializationEvent e) + { + ConfigurationHandler.load(); + } + + @Subscribe + public void postInit(FMLPostInitializationEvent e) + { + ConfigurationHandler.saveServerConfig(); + } + + @Subscribe + public void serverAboutToStart(FMLServerAboutToStartEvent e) + { + e.getServer().getMultiWorld().register(); + } + + @Subscribe + public void serverStopped(FMLServerStoppedEvent e) + { + MinecraftServer.getServer().getMultiWorld().unregister(); + } + + @NetworkCheckHandler + public boolean networkCheck(Map map, Side side) + { + return true; + } + + @Override + public File getSource() + { + return UltraminePlugin.location; + } + + @Override + public List getOwnedPackages() + { + return ImmutableList.of( + "org.ultramine.server" + ); + } + + @Subscribe + public void serverStarting(FMLServerStartingEvent e) + { + e.registerArgumentHandlers(DefaultCompleters.class); + e.registerCommands(BasicPermissionCommands.class); + } + + @Subscribe + public void stopServer(FMLServerStoppedEvent e) + { + } + + @Override + public Object getMod() + { + return this; + } +} diff --git a/src/main/java/org/ultramine/server/chunk/ChunkSendManager.java b/src/main/java/org/ultramine/server/chunk/ChunkSendManager.java index 1cf40ad..843e77c 100644 --- a/src/main/java/org/ultramine/server/chunk/ChunkSendManager.java +++ b/src/main/java/org/ultramine/server/chunk/ChunkSendManager.java @@ -1,331 +1,331 @@ -package org.ultramine.server.chunk; - -import gnu.trove.TCollections; -import gnu.trove.iterator.TIntIterator; -import gnu.trove.set.TIntSet; -import gnu.trove.set.hash.TIntHashSet; -import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.GenericFutureListener; - -import java.util.List; -import java.util.Queue; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicInteger; - -import org.ultramine.server.ConfigurationHandler; -import org.ultramine.server.util.BlockFace; -import org.ultramine.server.util.ChunkCoordComparator; -import org.ultramine.server.util.TIntArrayListImpl; - -import com.google.common.collect.Queues; - -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.network.Packet; -import net.minecraft.network.play.server.S21PacketChunkData; -import net.minecraft.server.management.PlayerManager; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.MathHelper; -import net.minecraft.world.WorldServer; -import net.minecraft.world.chunk.Chunk; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.world.ChunkWatchEvent; - -public class ChunkSendManager -{ - private static final ExecutorService executor = Executors.newFixedThreadPool(1); - private static final int MAX_QUEUE_SIZE = 4; - private static final int DEFAULT_RATE = 5; - private static final double MIN_RATE = 0.2d; - private static final double MAX_RATE = 16d; - - private final EntityPlayerMP player; - private PlayerManager manager; - private BlockFace lastFace; - - private final TIntArrayListImpl toSend = new TIntArrayListImpl((int)Math.pow(ConfigurationHandler.getServerConfig().vanilla.viewDistance, 2)); - private final TIntSet sending = TCollections.synchronizedSet(new TIntHashSet()); - private final TIntSet sended = new TIntHashSet(); - private final Queue toUpdate = Queues.newConcurrentLinkedQueue(); - private final Queue toUnload = Queues.newConcurrentLinkedQueue(); - private final AtomicInteger sendingQueueSize = new AtomicInteger(); - - private int lastQueueSize; - private double rate = DEFAULT_RATE; - private int intervalCounter = 1; - - public ChunkSendManager(EntityPlayerMP player) - { - this.player = player; - } - - private void sortSendQueue() - { - int cx = MathHelper.floor_double(player.posX) >> 4; - int cz = MathHelper.floor_double(player.posZ) >> 4; - toSend.sort(ChunkCoordComparator.get(lastFace = BlockFace.yawToFace(player.rotationYaw), cx, cz)); - } - - public void addTo(PlayerManager manager) - { - if(this.manager != null) throw new IllegalStateException("PlayerManager already set"); - this.manager = manager; - - player.managedPosX = player.posX; - player.managedPosZ = player.posZ; - - int cx = MathHelper.floor_double(player.posX) >> 4; - int cz = MathHelper.floor_double(player.posZ) >> 4; - int viewRadius = ConfigurationHandler.getServerConfig().vanilla.viewDistance; - - for (int x = cx - viewRadius; x <= cx + viewRadius; ++x) - { - for (int z = cz - viewRadius; z <= cz + viewRadius; ++z) - { - toSend.add(ChunkHash.chunkToKey(x, z)); - } - } - - sortSendQueue(); - - sendChunks(Math.max(1, (int)rate)); - } - - public void removeFrom(PlayerManager manager) - { - if(this.manager == null) return; - if(this.manager != manager) throw new IllegalStateException(); - - toSend.clear(); - sending.clear(); - - for(TIntIterator it = sended.iterator(); it.hasNext();) - { - int key = it.next(); - PlayerManager.PlayerInstance pi = manager.getOrCreateChunkWatcher(ChunkHash.keyToX(key), ChunkHash.keyToZ(key), false); - if (pi != null) pi.removePlayer(player); - } - - sended.clear(); - this.manager = null; - } - - public void update() - { - if(!toSend.isEmpty()) - { - int queueSize = sendingQueueSize.get(); - - if(queueSize == 0) - { - rate += 0.14; - } - else if(queueSize > lastQueueSize) - { - if(queueSize > MAX_QUEUE_SIZE) - rate -= 0.14; - else - rate -= 0.07; - } - if(rate < MIN_RATE) rate = MIN_RATE; - else if(rate > MAX_RATE) rate = MAX_RATE; - - if(queueSize == 0 || (queueSize != lastQueueSize && queueSize <= MAX_QUEUE_SIZE)) - { - lastQueueSize = queueSize; - - if(rate >= 1) - { - sendChunks((int)rate); - } - else - { - int interval = Math.max(1, (int)(1/rate)); - if(intervalCounter++ >= interval) - { - intervalCounter = 1; - sendChunks(1); - } - } - - } - } - - while(!toUpdate.isEmpty()) - { - Chunk chunk = toUpdate.poll(); - int key = ChunkHash.chunkToKey(chunk.xPosition, chunk.zPosition); - - if(sending.contains(key)) - { - manager.getOrCreateChunkWatcher(chunk.xPosition, chunk.zPosition, true).addPlayer(player); - - List tes = manager.getWorldServer().func_147486_a(chunk.xPosition * 16, 0, chunk.zPosition * 16, chunk.xPosition * 16 + 15, 256, chunk.zPosition * 16 + 15); - for(Object o : tes) - { - TileEntity te = (TileEntity)o; - Packet packet = te.getDescriptionPacket(); - - if (packet != null) - { - player.playerNetServerHandler.sendPacket(packet); - } - } - - manager.getWorldServer().getEntityTracker().func_85172_a(player, chunk); - MinecraftForge.EVENT_BUS.post(new ChunkWatchEvent.Watch(chunk.getChunkCoordIntPair(), player)); - - sended.add(key); - sending.remove(key); - } - else - { - player.playerNetServerHandler.sendPacket(S21PacketChunkData.makeForUnload(chunk)); - - PlayerManager.PlayerInstance pi = manager.getOrCreateChunkWatcher(chunk.xPosition, chunk.zPosition, false); - if (pi == null) - ((WorldServer)chunk.worldObj).theChunkProviderServer.unloadChunksIfNotNearSpawn(chunk.xPosition, chunk.zPosition); - } - } - - while(!toUnload.isEmpty()) - { - Chunk chunk = toUnload.poll(); - - PlayerManager.PlayerInstance pi = manager.getOrCreateChunkWatcher(chunk.xPosition, chunk.zPosition, false); - if (pi == null) - ((WorldServer)chunk.worldObj).theChunkProviderServer.unloadChunksIfNotNearSpawn(chunk.xPosition, chunk.zPosition); - } - } - - private void sendChunks(int count) - { - for(int i = 0, s = Math.min(count, toSend.size()); i < s; i++) - { - int key = toSend.removeAt(0); - sending.add(key); - sendingQueueSize.incrementAndGet(); - int ncx = ChunkHash.keyToX(key); - int ncz = ChunkHash.keyToZ(key); - manager.getWorldServer().theChunkProviderServer.loadAsync(ncx, ncz, chunkLoadCallback); - } - } - - public void updatePlayerPertinentChunks() - { - int cx = MathHelper.floor_double(player.posX) >> 4; - int cz = MathHelper.floor_double(player.posZ) >> 4; - double d0 = player.managedPosX - player.posX; - double d1 = player.managedPosZ - player.posZ; - double square = d0 * d0 + d1 * d1; - - boolean sorted = false; - - if (square >= 64.0D) - { - int lastX = MathHelper.floor_double(player.managedPosX) >> 4; - int lastZ = MathHelper.floor_double(player.managedPosZ) >> 4; - int view = ConfigurationHandler.getServerConfig().vanilla.viewDistance; - int movX = cx - lastX; - int movZ = cz - lastZ; - - if (movX != 0 || movZ != 0) - { - for (int x = cx - view; x <= cx + view; ++x) - { - for (int z = cz - view; z <= cz + view; ++z) - { - if (!overlaps(x, z, lastX, lastZ, view)) - { - toSend.add(ChunkHash.chunkToKey(x, z)); - } - - if (!overlaps(x - movX, z - movZ, cx, cz, view)) - { - int key = ChunkHash.chunkToKey(x - movX, z - movZ); - if(!toSend.remove(key)) - { - if(sended.contains(key)) - { - PlayerManager.PlayerInstance pi = manager.getOrCreateChunkWatcher(x - movX, z - movZ, false); - if(pi != null) pi.removePlayer(player); - sended.remove(key); - } - else - { - sending.remove(key); - } - } - } - } - } - - sortSendQueue(); - sorted = true; - player.managedPosX = player.posX; - player.managedPosZ = player.posZ; - } - } - - if(!sorted) - { - BlockFace face = BlockFace.yawToFace(player.rotationYaw); - if(face != lastFace) - { - sortSendQueue(); - } - } - } - - private boolean overlaps(int x, int z, int lastX, int lastZ, int radius) - { - int movX = x - lastX; - int movZ = z - lastZ; - return movX >= -radius && movX <= radius ? movZ >= -radius && movZ <= radius : false; - } - - - - - private IChunkLoadCallback chunkLoadCallback = new IChunkLoadCallback() - { - @Override - public void onChunkLoaded(Chunk chunk) - { - executor.execute(new CompressAndSendChunkTask(chunk)); - } - }; - - private class CompressAndSendChunkTask implements Runnable - { - private final Chunk chunk; - - public CompressAndSendChunkTask(Chunk chunk) - { - this.chunk = chunk; - } - - @Override - public void run() - { - if(sending.contains(ChunkHash.chunkToKey(chunk.xPosition, chunk.zPosition))) - { - player.playerNetServerHandler.netManager.scheduleOutboundPacket(S21PacketChunkData.makeDeflated(chunk), - new GenericFutureListener>() - { - @Override - public void operationComplete(Future future) throws Exception - { - sendingQueueSize.decrementAndGet(); - } - }); - - toUpdate.add(chunk); - } - else - { - toUnload.add(chunk); - } - } - } -} +package org.ultramine.server.chunk; + +import gnu.trove.TCollections; +import gnu.trove.iterator.TIntIterator; +import gnu.trove.set.TIntSet; +import gnu.trove.set.hash.TIntHashSet; +import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.GenericFutureListener; + +import java.util.List; +import java.util.Queue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicInteger; + +import org.ultramine.server.ConfigurationHandler; +import org.ultramine.server.util.BlockFace; +import org.ultramine.server.util.ChunkCoordComparator; +import org.ultramine.server.util.TIntArrayListImpl; + +import com.google.common.collect.Queues; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S21PacketChunkData; +import net.minecraft.server.management.PlayerManager; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MathHelper; +import net.minecraft.world.WorldServer; +import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.ChunkWatchEvent; + +public class ChunkSendManager +{ + private static final ExecutorService executor = Executors.newFixedThreadPool(1); + private static final int MAX_QUEUE_SIZE = 4; + private static final int DEFAULT_RATE = 5; + private static final double MIN_RATE = 0.2d; + private static final double MAX_RATE = 16d; + + private final EntityPlayerMP player; + private PlayerManager manager; + private BlockFace lastFace; + + private final TIntArrayListImpl toSend = new TIntArrayListImpl((int)Math.pow(ConfigurationHandler.getWorldsConfig().global.chunkLoading.viewDistance, 2)); + private final TIntSet sending = TCollections.synchronizedSet(new TIntHashSet()); + private final TIntSet sended = new TIntHashSet(); + private final Queue toUpdate = Queues.newConcurrentLinkedQueue(); + private final Queue toUnload = Queues.newConcurrentLinkedQueue(); + private final AtomicInteger sendingQueueSize = new AtomicInteger(); + + private int lastQueueSize; + private double rate = DEFAULT_RATE; + private int intervalCounter = 1; + + public ChunkSendManager(EntityPlayerMP player) + { + this.player = player; + } + + private void sortSendQueue() + { + int cx = MathHelper.floor_double(player.posX) >> 4; + int cz = MathHelper.floor_double(player.posZ) >> 4; + toSend.sort(ChunkCoordComparator.get(lastFace = BlockFace.yawToFace(player.rotationYaw), cx, cz)); + } + + public void addTo(PlayerManager manager) + { + if(this.manager != null) throw new IllegalStateException("PlayerManager already set"); + this.manager = manager; + + player.managedPosX = player.posX; + player.managedPosZ = player.posZ; + + int cx = MathHelper.floor_double(player.posX) >> 4; + int cz = MathHelper.floor_double(player.posZ) >> 4; + int viewRadius = manager.getWorldServer().getConfig().chunkLoading.viewDistance; + + for (int x = cx - viewRadius; x <= cx + viewRadius; ++x) + { + for (int z = cz - viewRadius; z <= cz + viewRadius; ++z) + { + toSend.add(ChunkHash.chunkToKey(x, z)); + } + } + + sortSendQueue(); + + sendChunks(Math.max(1, (int)rate)); + } + + public void removeFrom(PlayerManager manager) + { + if(this.manager == null) return; + if(this.manager != manager) throw new IllegalStateException(); + + toSend.clear(); + sending.clear(); + + for(TIntIterator it = sended.iterator(); it.hasNext();) + { + int key = it.next(); + PlayerManager.PlayerInstance pi = manager.getOrCreateChunkWatcher(ChunkHash.keyToX(key), ChunkHash.keyToZ(key), false); + if (pi != null) pi.removePlayer(player); + } + + sended.clear(); + this.manager = null; + } + + public void update() + { + if(!toSend.isEmpty()) + { + int queueSize = sendingQueueSize.get(); + + if(queueSize == 0) + { + rate += 0.14; + } + else if(queueSize > lastQueueSize) + { + if(queueSize > MAX_QUEUE_SIZE) + rate -= 0.14; + else + rate -= 0.07; + } + if(rate < MIN_RATE) rate = MIN_RATE; + else if(rate > MAX_RATE) rate = MAX_RATE; + + if(queueSize == 0 || (queueSize != lastQueueSize && queueSize <= MAX_QUEUE_SIZE)) + { + lastQueueSize = queueSize; + + if(rate >= 1) + { + sendChunks((int)rate); + } + else + { + int interval = Math.max(1, (int)(1/rate)); + if(intervalCounter++ >= interval) + { + intervalCounter = 1; + sendChunks(1); + } + } + + } + } + + while(!toUpdate.isEmpty()) + { + Chunk chunk = toUpdate.poll(); + int key = ChunkHash.chunkToKey(chunk.xPosition, chunk.zPosition); + + if(sending.contains(key)) + { + manager.getOrCreateChunkWatcher(chunk.xPosition, chunk.zPosition, true).addPlayer(player); + + List tes = manager.getWorldServer().func_147486_a(chunk.xPosition * 16, 0, chunk.zPosition * 16, chunk.xPosition * 16 + 15, 256, chunk.zPosition * 16 + 15); + for(Object o : tes) + { + TileEntity te = (TileEntity)o; + Packet packet = te.getDescriptionPacket(); + + if (packet != null) + { + player.playerNetServerHandler.sendPacket(packet); + } + } + + manager.getWorldServer().getEntityTracker().func_85172_a(player, chunk); + MinecraftForge.EVENT_BUS.post(new ChunkWatchEvent.Watch(chunk.getChunkCoordIntPair(), player)); + + sended.add(key); + sending.remove(key); + } + else + { + player.playerNetServerHandler.sendPacket(S21PacketChunkData.makeForUnload(chunk)); + + PlayerManager.PlayerInstance pi = manager.getOrCreateChunkWatcher(chunk.xPosition, chunk.zPosition, false); + if (pi == null) + ((WorldServer)chunk.worldObj).theChunkProviderServer.unloadChunksIfNotNearSpawn(chunk.xPosition, chunk.zPosition); + } + } + + while(!toUnload.isEmpty()) + { + Chunk chunk = toUnload.poll(); + + PlayerManager.PlayerInstance pi = manager.getOrCreateChunkWatcher(chunk.xPosition, chunk.zPosition, false); + if (pi == null) + ((WorldServer)chunk.worldObj).theChunkProviderServer.unloadChunksIfNotNearSpawn(chunk.xPosition, chunk.zPosition); + } + } + + private void sendChunks(int count) + { + for(int i = 0, s = Math.min(count, toSend.size()); i < s; i++) + { + int key = toSend.removeAt(0); + sending.add(key); + sendingQueueSize.incrementAndGet(); + int ncx = ChunkHash.keyToX(key); + int ncz = ChunkHash.keyToZ(key); + manager.getWorldServer().theChunkProviderServer.loadAsync(ncx, ncz, chunkLoadCallback); + } + } + + public void updatePlayerPertinentChunks() + { + int cx = MathHelper.floor_double(player.posX) >> 4; + int cz = MathHelper.floor_double(player.posZ) >> 4; + double d0 = player.managedPosX - player.posX; + double d1 = player.managedPosZ - player.posZ; + double square = d0 * d0 + d1 * d1; + + boolean sorted = false; + + if (square >= 64.0D) + { + int lastX = MathHelper.floor_double(player.managedPosX) >> 4; + int lastZ = MathHelper.floor_double(player.managedPosZ) >> 4; + int view = manager.getWorldServer().getConfig().chunkLoading.viewDistance; + int movX = cx - lastX; + int movZ = cz - lastZ; + + if (movX != 0 || movZ != 0) + { + for (int x = cx - view; x <= cx + view; ++x) + { + for (int z = cz - view; z <= cz + view; ++z) + { + if (!overlaps(x, z, lastX, lastZ, view)) + { + toSend.add(ChunkHash.chunkToKey(x, z)); + } + + if (!overlaps(x - movX, z - movZ, cx, cz, view)) + { + int key = ChunkHash.chunkToKey(x - movX, z - movZ); + if(!toSend.remove(key)) + { + if(sended.contains(key)) + { + PlayerManager.PlayerInstance pi = manager.getOrCreateChunkWatcher(x - movX, z - movZ, false); + if(pi != null) pi.removePlayer(player); + sended.remove(key); + } + else + { + sending.remove(key); + } + } + } + } + } + + sortSendQueue(); + sorted = true; + player.managedPosX = player.posX; + player.managedPosZ = player.posZ; + } + } + + if(!sorted) + { + BlockFace face = BlockFace.yawToFace(player.rotationYaw); + if(face != lastFace) + { + sortSendQueue(); + } + } + } + + private boolean overlaps(int x, int z, int lastX, int lastZ, int radius) + { + int movX = x - lastX; + int movZ = z - lastZ; + return movX >= -radius && movX <= radius ? movZ >= -radius && movZ <= radius : false; + } + + + + + private IChunkLoadCallback chunkLoadCallback = new IChunkLoadCallback() + { + @Override + public void onChunkLoaded(Chunk chunk) + { + executor.execute(new CompressAndSendChunkTask(chunk)); + } + }; + + private class CompressAndSendChunkTask implements Runnable + { + private final Chunk chunk; + + public CompressAndSendChunkTask(Chunk chunk) + { + this.chunk = chunk; + } + + @Override + public void run() + { + if(sending.contains(ChunkHash.chunkToKey(chunk.xPosition, chunk.zPosition))) + { + player.playerNetServerHandler.netManager.scheduleOutboundPacket(S21PacketChunkData.makeDeflated(chunk), + new GenericFutureListener>() + { + @Override + public void operationComplete(Future future) throws Exception + { + sendingQueueSize.decrementAndGet(); + } + }); + + toUpdate.add(chunk); + } + else + { + toUnload.add(chunk); + } + } + } +}