From a774131e3672fbd6565f9d3e072172fddf98ae34 Mon Sep 17 00:00:00 2001 From: ProfMobius Date: Sun, 11 May 2014 16:22:37 +0200 Subject: [PATCH] Readded most of the profiler hooks --- .../cpw/mods/fml/common/FMLCommonHandler.java | 606 +++++++++ .../panels/timingclient/PanelEventClient.java | 8 +- .../client/renderer/entity/RenderManager.java | 413 ++++++ .../TileEntityRendererDispatcher.java | 181 +++ src/main/java/net/minecraft/world/World.java | 8 +- .../java/net/minecraft/world/WorldServer.java | 1152 +++++++++++++++++ 6 files changed, 2363 insertions(+), 5 deletions(-) create mode 100644 src/main/java/cpw/mods/fml/common/FMLCommonHandler.java create mode 100644 src/main/java/net/minecraft/client/renderer/entity/RenderManager.java create mode 100644 src/main/java/net/minecraft/client/renderer/tileentity/TileEntityRendererDispatcher.java create mode 100644 src/main/java/net/minecraft/world/WorldServer.java diff --git a/src/main/java/cpw/mods/fml/common/FMLCommonHandler.java b/src/main/java/cpw/mods/fml/common/FMLCommonHandler.java new file mode 100644 index 0000000..909a93e --- /dev/null +++ b/src/main/java/cpw/mods/fml/common/FMLCommonHandler.java @@ -0,0 +1,606 @@ +/* + * Forge Mod Loader + * Copyright (c) 2012-2013 cpw. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v2.1 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * Contributors: + * cpw - implementation + */ + +package cpw.mods.fml.common; + +import java.io.File; +import java.lang.ref.WeakReference; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import mcp.mobius.mobiuscore.profiler.ProfilerSection; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.INetHandler; +import net.minecraft.network.NetworkManager; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.World; +import net.minecraft.world.storage.SaveHandler; +import net.minecraft.world.storage.WorldInfo; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Logger; + +import com.google.common.base.Joiner; +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; +import com.google.common.collect.Lists; +import com.google.common.collect.MapMaker; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; + +import cpw.mods.fml.common.eventhandler.EventBus; +import cpw.mods.fml.common.gameevent.InputEvent; +import cpw.mods.fml.common.gameevent.PlayerEvent; +import cpw.mods.fml.common.gameevent.TickEvent; +import cpw.mods.fml.common.gameevent.TickEvent.Phase; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.server.FMLServerHandler; + + +/** + * The main class for non-obfuscated hook handling code + * + * Anything that doesn't require obfuscated or client/server specific code should + * go in this handler + * + * It also contains a reference to the sided handler instance that is valid + * allowing for common code to access specific properties from the obfuscated world + * without a direct dependency + * + * @author cpw + * + */ +public class FMLCommonHandler +{ + /** + * The singleton + */ + private static final FMLCommonHandler INSTANCE = new FMLCommonHandler(); + /** + * The delegate for side specific data and functions + */ + private IFMLSidedHandler sidedDelegate; + + private Class forge; + private boolean noForge; + private List brandings; + private List brandingsNoMC; + private List crashCallables = Lists.newArrayList(Loader.instance().getCallableCrashInformation()); + private Set handlerSet = Sets.newSetFromMap(new MapMaker().weakKeys().makeMap()); + private WeakReference handlerToCheck; + private EventBus eventBus = new EventBus(); + private volatile CountDownLatch exitLatch = null; + /** + * The FML event bus. Subscribe here for FML related events + * + * @return the event bus + */ + public EventBus bus() + { + return eventBus; + } + + public void beginLoading(IFMLSidedHandler handler) + { + sidedDelegate = handler; + FMLLog.log("MinecraftForge", Level.INFO, "Attempting early MinecraftForge initialization"); + callForgeMethod("initialize"); + callForgeMethod("registerCrashCallable"); + FMLLog.log("MinecraftForge", Level.INFO, "Completed early MinecraftForge initialization"); + } + + /** + * @return the instance + */ + public static FMLCommonHandler instance() + { + return INSTANCE; + } + /** + * Find the container that associates with the supplied mod object + * @param mod + */ + public ModContainer findContainerFor(Object mod) + { + if (mod instanceof String) + { + return Loader.instance().getIndexedModList().get(mod); + } + else + { + return Loader.instance().getReversedModObjectList().get(mod); + } + } + /** + * Get the forge mod loader logging instance (goes to the forgemodloader log file) + * @return The log instance for the FML log file + */ + public Logger getFMLLogger() + { + return FMLLog.getLogger(); + } + + public Side getSide() + { + return sidedDelegate.getSide(); + } + + /** + * Return the effective side for the context in the game. This is dependent + * on thread analysis to try and determine whether the code is running in the + * server or not. Use at your own risk + */ + public Side getEffectiveSide() + { + Thread thr = Thread.currentThread(); + if ((thr.getName().equals("Server thread"))) + { + return Side.SERVER; + } + + return Side.CLIENT; + } + /** + * Raise an exception + */ + public void raiseException(Throwable exception, String message, boolean stopGame) + { + FMLLog.log(Level.ERROR, exception, "Something raised an exception. The message was '%s'. 'stopGame' is %b", message, stopGame); + if (stopGame) + { + getSidedDelegate().haltGame(message,exception); + } + } + + + private Class findMinecraftForge() + { + if (forge==null && !noForge) + { + try { + forge = Class.forName("net.minecraftforge.common.MinecraftForge"); + } catch (Exception ex) { + noForge = true; + } + } + return forge; + } + + private Object callForgeMethod(String method) + { + if (noForge) + return null; + try + { + return findMinecraftForge().getMethod(method).invoke(null); + } + catch (Exception e) + { + // No Forge installation + return null; + } + } + + public void computeBranding() + { + if (brandings == null) + { + Builder brd = ImmutableList.builder(); + brd.add(Loader.instance().getMCVersionString()); + brd.add(Loader.instance().getMCPVersionString()); + brd.add("FML v"+Loader.instance().getFMLVersionString()); + String forgeBranding = (String) callForgeMethod("getBrandingVersion"); + if (!Strings.isNullOrEmpty(forgeBranding)) + { + brd.add(forgeBranding); + } + if (sidedDelegate!=null) + { + brd.addAll(sidedDelegate.getAdditionalBrandingInformation()); + } + if (Loader.instance().getFMLBrandingProperties().containsKey("fmlbranding")) + { + brd.add(Loader.instance().getFMLBrandingProperties().get("fmlbranding")); + } + int tModCount = Loader.instance().getModList().size(); + int aModCount = Loader.instance().getActiveModList().size(); + brd.add(String.format("%d mod%s loaded, %d mod%s active", tModCount, tModCount!=1 ? "s" :"", aModCount, aModCount!=1 ? "s" :"" )); + brandings = brd.build(); + brandingsNoMC = brandings.subList(1, brandings.size()); + } + } + public List getBrandings(boolean includeMC) + { + if (brandings == null) + { + computeBranding(); + } + return includeMC ? ImmutableList.copyOf(brandings) : ImmutableList.copyOf(brandingsNoMC); + } + + public IFMLSidedHandler getSidedDelegate() + { + return sidedDelegate; + } + + public void onPostServerTick() + { + bus().post(new TickEvent.ServerTickEvent(Phase.END)); + ProfilerSection.TICK.stop(); + } + + /** + * Every tick just after world and other ticks occur + */ + public void onPostWorldTick(World world) + { + bus().post(new TickEvent.WorldTickEvent(Side.SERVER, Phase.END, world)); + ProfilerSection.DIMENSION_TICK.stop(world); + } + + public void onPreServerTick() + { + ProfilerSection.TICK.start(); + bus().post(new TickEvent.ServerTickEvent(Phase.START)); + } + + /** + * Every tick just before world and other ticks occur + */ + public void onPreWorldTick(World world) + { + ProfilerSection.DIMENSION_TICK.start(world); + bus().post(new TickEvent.WorldTickEvent(Side.SERVER, Phase.START, world)); + } + + public boolean handleServerAboutToStart(MinecraftServer server) + { + return Loader.instance().serverAboutToStart(server); + } + + public boolean handleServerStarting(MinecraftServer server) + { + return Loader.instance().serverStarting(server); + } + + public void handleServerStarted() + { + Loader.instance().serverStarted(); + } + + public void handleServerStopping() + { + Loader.instance().serverStopping(); + } + + public File getSavesDirectory() { + return sidedDelegate.getSavesDirectory(); + } + + public MinecraftServer getMinecraftServerInstance() + { + return sidedDelegate.getServer(); + } + + public void showGuiScreen(Object clientGuiElement) + { + sidedDelegate.showGuiScreen(clientGuiElement); + } + + public void queryUser(StartupQuery query) throws InterruptedException + { + sidedDelegate.queryUser(query); + } + + public void onServerStart(MinecraftServer dedicatedServer) + { + FMLServerHandler.instance(); + sidedDelegate.beginServerLoading(dedicatedServer); + } + + public void onServerStarted() + { + sidedDelegate.finishServerLoading(); + } + + + public void onPreClientTick() + { + bus().post(new TickEvent.ClientTickEvent(Phase.START)); + } + + public void onPostClientTick() + { + bus().post(new TickEvent.ClientTickEvent(Phase.END)); + } + + public void onRenderTickStart(float timer) + { + bus().post(new TickEvent.RenderTickEvent(Phase.START, timer)); + } + + public void onRenderTickEnd(float timer) + { + bus().post(new TickEvent.RenderTickEvent(Phase.END, timer)); + } + + public void onPlayerPreTick(EntityPlayer player) + { + bus().post(new TickEvent.PlayerTickEvent(Phase.START, player)); + } + + public void onPlayerPostTick(EntityPlayer player) + { + bus().post(new TickEvent.PlayerTickEvent(Phase.END, player)); + } + + public void registerCrashCallable(ICrashCallable callable) + { + crashCallables.add(callable); + } + + public void enhanceCrashReport(CrashReport crashReport, CrashReportCategory category) + { + for (ICrashCallable call: crashCallables) + { + category.addCrashSectionCallable(call.getLabel(), call); + } + } + + public void handleWorldDataSave(SaveHandler handler, WorldInfo worldInfo, NBTTagCompound tagCompound) + { + for (ModContainer mc : Loader.instance().getModList()) + { + if (mc instanceof InjectedModContainer) + { + WorldAccessContainer wac = ((InjectedModContainer)mc).getWrappedWorldAccessContainer(); + if (wac != null) + { + NBTTagCompound dataForWriting = wac.getDataForWriting(handler, worldInfo); + tagCompound.setTag(mc.getModId(), dataForWriting); + } + } + } + } + + public void handleWorldDataLoad(SaveHandler handler, WorldInfo worldInfo, NBTTagCompound tagCompound) + { + if (getEffectiveSide()!=Side.SERVER) + { + return; + } + if (handlerSet.contains(handler)) + { + return; + } + handlerSet.add(handler); + handlerToCheck = new WeakReference(handler); // for confirmBackupLevelDatUse + Map additionalProperties = Maps.newHashMap(); + worldInfo.setAdditionalProperties(additionalProperties); + for (ModContainer mc : Loader.instance().getModList()) + { + if (mc instanceof InjectedModContainer) + { + WorldAccessContainer wac = ((InjectedModContainer)mc).getWrappedWorldAccessContainer(); + if (wac != null) + { + wac.readData(handler, worldInfo, additionalProperties, tagCompound.getCompoundTag(mc.getModId())); + } + } + } + } + + public void confirmBackupLevelDatUse(SaveHandler handler) + { + if (handlerToCheck == null || handlerToCheck.get() != handler) { + // only run if the save has been initially loaded + handlerToCheck = null; + return; + } + + String text = "Forge Mod Loader detected that the backup level.dat is being used.\n\n" + + "This may happen due to a bug or corruption, continuing can damage\n" + + "your world beyond repair or lose data / progress.\n\n" + + "It's recommended to create a world backup before continuing."; + + boolean confirmed = StartupQuery.confirm(text); + if (!confirmed) StartupQuery.abort(); + } + + public boolean shouldServerBeKilledQuietly() + { + if (sidedDelegate == null) + { + return false; + } + return sidedDelegate.shouldServerShouldBeKilledQuietly(); + } + + /** + * Make handleExit() wait for handleServerStopped(). + * + * For internal use only! + */ + public void expectServerStopped() + { + exitLatch = new CountDownLatch(1); + } + + /** + * Delayed System.exit() until the server is actually stopped/done saving. + * + * For internal use only! + * + * @param retVal Exit code for System.exit() + */ + public void handleExit(int retVal) + { + CountDownLatch latch = exitLatch; + + if (latch != null) + { + try + { + FMLLog.info("Waiting for the server to terminate/save."); + if (!latch.await(10, TimeUnit.SECONDS)) + { + FMLLog.warning("The server didn't stop within 10 seconds, exiting anyway."); + } + else + { + FMLLog.info("Server terminated."); + } + } + catch (InterruptedException e) + { + FMLLog.warning("Interrupted wait, exiting."); + } + } + + System.exit(retVal); + } + + public void handleServerStopped() + { + sidedDelegate.serverStopped(); + MinecraftServer server = getMinecraftServerInstance(); + Loader.instance().serverStopped(); + // FORCE the internal server to stop: hello optifine workaround! + if (server!=null) ObfuscationReflectionHelper.setPrivateValue(MinecraftServer.class, server, false, "field_71316"+"_v", "u", "serverStopped"); + + // allow any pending exit to continue, clear exitLatch + CountDownLatch latch = exitLatch; + + if (latch != null) + { + latch.countDown(); + exitLatch = null; + } + } + + public String getModName() + { + List modNames = Lists.newArrayListWithExpectedSize(3); + modNames.add("fml"); + if (!noForge) + { + modNames.add("forge"); + } + + if (Loader.instance().getFMLBrandingProperties().containsKey("snooperbranding")) + { + modNames.add(Loader.instance().getFMLBrandingProperties().get("snooperbranding")); + } + return Joiner.on(',').join(modNames); + } + + public void addModToResourcePack(ModContainer container) + { + sidedDelegate.addModAsResource(container); + } + + public void updateResourcePackList() + { + sidedDelegate.updateResourcePackList(); + } + + public String getCurrentLanguage() + { + + return sidedDelegate.getCurrentLanguage(); + } + + public void bootstrap() + { + } + + public NetworkManager getClientToServerNetworkManager() + { + return sidedDelegate.getClientToServerNetworkManager(); + } + + public void fireMouseInput() + { + bus().post(new InputEvent.MouseInputEvent()); + } + + public void fireKeyInput() + { + bus().post(new InputEvent.KeyInputEvent()); + } + + public void firePlayerChangedDimensionEvent(EntityPlayer player, int fromDim, int toDim) + { + bus().post(new PlayerEvent.PlayerChangedDimensionEvent(player, fromDim, toDim)); + } + + public void firePlayerLoggedIn(EntityPlayer player) + { + bus().post(new PlayerEvent.PlayerLoggedInEvent(player)); + } + + public void firePlayerLoggedOut(EntityPlayer player) + { + bus().post(new PlayerEvent.PlayerLoggedOutEvent(player)); + } + + public void firePlayerRespawnEvent(EntityPlayer player) + { + bus().post(new PlayerEvent.PlayerRespawnEvent(player)); + } + + public void firePlayerItemPickupEvent(EntityPlayer player, EntityItem item) + { + bus().post(new PlayerEvent.ItemPickupEvent(player, item)); + } + + public void firePlayerCraftingEvent(EntityPlayer player, ItemStack crafted, IInventory craftMatrix) + { + bus().post(new PlayerEvent.ItemCraftedEvent(player, crafted, craftMatrix)); + } + + public void firePlayerSmeltedEvent(EntityPlayer player, ItemStack smelted) + { + bus().post(new PlayerEvent.ItemSmeltedEvent(player, smelted)); + } + + public INetHandler getClientPlayHandler() + { + return sidedDelegate.getClientPlayHandler(); + } + + public void waitForPlayClient() + { + sidedDelegate.waitForPlayClient(); + } + + public void fireNetRegistrationEvent(NetworkManager manager, Set channelSet, String channel, Side side) + { + sidedDelegate.fireNetRegistrationEvent(bus(), manager, channelSet, channel, side); + } + + public boolean shouldAllowPlayerLogins() + { + return sidedDelegate.shouldAllowPlayerLogins(); + } +} \ No newline at end of file diff --git a/src/main/java/mcp/mobius/opis/swing/panels/timingclient/PanelEventClient.java b/src/main/java/mcp/mobius/opis/swing/panels/timingclient/PanelEventClient.java index da86553..c83ad43 100644 --- a/src/main/java/mcp/mobius/opis/swing/panels/timingclient/PanelEventClient.java +++ b/src/main/java/mcp/mobius/opis/swing/panels/timingclient/PanelEventClient.java @@ -46,9 +46,9 @@ public class PanelEventClient extends JPanel implements ITabPanel, IMessageHandl add(scrollPane, "cell 0 1 3 1,grow"); table = new JTableStats( - new String[] {"Event", "Class", "Handler", "Calls", "Timing"}, - new Class[] {CachedString.class, CachedString.class, CachedString.class, Long.class, DataTiming.class}, - new int[] {SwingConstants.LEFT, SwingConstants.LEFT, SwingConstants.LEFT, SwingConstants.CENTER, SwingConstants.CENTER} + new String[] {"Event", "Mod", "Class", "Handler", "Calls", "Timing"}, + new Class[] {CachedString.class, CachedString.class, CachedString.class, CachedString.class, Long.class, DataTiming.class}, + new int[] {SwingConstants.LEFT, SwingConstants.LEFT, SwingConstants.LEFT, SwingConstants.LEFT, SwingConstants.CENTER, SwingConstants.CENTER} ); scrollPane.setViewportView(table); @@ -60,7 +60,7 @@ public class PanelEventClient extends JPanel implements ITabPanel, IMessageHandl int row = this.updateData(table, model, DataEvent.class); for (DataEvent o : data){ - model.addRow(new Object[] {o.event, o.package_, o.handler, o.nCalls, o.update}); + model.addRow(new Object[] {o.event, o.mod, o.package_, o.handler, o.nCalls, o.update}); } this.dataUpdated(table, model, row); diff --git a/src/main/java/net/minecraft/client/renderer/entity/RenderManager.java b/src/main/java/net/minecraft/client/renderer/entity/RenderManager.java new file mode 100644 index 0000000..36dbe45 --- /dev/null +++ b/src/main/java/net/minecraft/client/renderer/entity/RenderManager.java @@ -0,0 +1,413 @@ +package net.minecraft.client.renderer.entity; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import mcp.mobius.mobiuscore.profiler.ProfilerSection; +import net.minecraft.block.Block; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.model.ModelChicken; +import net.minecraft.client.model.ModelCow; +import net.minecraft.client.model.ModelHorse; +import net.minecraft.client.model.ModelOcelot; +import net.minecraft.client.model.ModelPig; +import net.minecraft.client.model.ModelSheep1; +import net.minecraft.client.model.ModelSheep2; +import net.minecraft.client.model.ModelSlime; +import net.minecraft.client.model.ModelSquid; +import net.minecraft.client.model.ModelWolf; +import net.minecraft.client.model.ModelZombie; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderGlobal; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.renderer.tileentity.RenderEnderCrystal; +import net.minecraft.client.renderer.tileentity.RenderItemFrame; +import net.minecraft.client.renderer.tileentity.RenderWitherSkull; +import net.minecraft.client.settings.GameSettings; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLeashKnot; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.ai.EntityMinecartMobSpawner; +import net.minecraft.entity.boss.EntityDragon; +import net.minecraft.entity.boss.EntityWither; +import net.minecraft.entity.effect.EntityLightningBolt; +import net.minecraft.entity.item.EntityBoat; +import net.minecraft.entity.item.EntityEnderCrystal; +import net.minecraft.entity.item.EntityEnderEye; +import net.minecraft.entity.item.EntityEnderPearl; +import net.minecraft.entity.item.EntityExpBottle; +import net.minecraft.entity.item.EntityFallingBlock; +import net.minecraft.entity.item.EntityFireworkRocket; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.item.EntityItemFrame; +import net.minecraft.entity.item.EntityMinecart; +import net.minecraft.entity.item.EntityMinecartTNT; +import net.minecraft.entity.item.EntityPainting; +import net.minecraft.entity.item.EntityTNTPrimed; +import net.minecraft.entity.item.EntityXPOrb; +import net.minecraft.entity.monster.EntityBlaze; +import net.minecraft.entity.monster.EntityCaveSpider; +import net.minecraft.entity.monster.EntityCreeper; +import net.minecraft.entity.monster.EntityEnderman; +import net.minecraft.entity.monster.EntityGhast; +import net.minecraft.entity.monster.EntityGiantZombie; +import net.minecraft.entity.monster.EntityIronGolem; +import net.minecraft.entity.monster.EntityMagmaCube; +import net.minecraft.entity.monster.EntitySilverfish; +import net.minecraft.entity.monster.EntitySkeleton; +import net.minecraft.entity.monster.EntitySlime; +import net.minecraft.entity.monster.EntitySnowman; +import net.minecraft.entity.monster.EntitySpider; +import net.minecraft.entity.monster.EntityWitch; +import net.minecraft.entity.monster.EntityZombie; +import net.minecraft.entity.passive.EntityBat; +import net.minecraft.entity.passive.EntityChicken; +import net.minecraft.entity.passive.EntityCow; +import net.minecraft.entity.passive.EntityHorse; +import net.minecraft.entity.passive.EntityMooshroom; +import net.minecraft.entity.passive.EntityOcelot; +import net.minecraft.entity.passive.EntityPig; +import net.minecraft.entity.passive.EntitySheep; +import net.minecraft.entity.passive.EntitySquid; +import net.minecraft.entity.passive.EntityVillager; +import net.minecraft.entity.passive.EntityWolf; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.entity.projectile.EntityEgg; +import net.minecraft.entity.projectile.EntityFishHook; +import net.minecraft.entity.projectile.EntityLargeFireball; +import net.minecraft.entity.projectile.EntityPotion; +import net.minecraft.entity.projectile.EntitySmallFireball; +import net.minecraft.entity.projectile.EntitySnowball; +import net.minecraft.entity.projectile.EntityWitherSkull; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ReportedException; +import net.minecraft.world.World; + +import org.lwjgl.opengl.GL11; + +@SideOnly(Side.CLIENT) +public class RenderManager +{ + /** A map of entity classes and the associated renderer. */ + public Map entityRenderMap = new HashMap(); + /** The static instance of RenderManager. */ + public static RenderManager instance = new RenderManager(); + /** Renders fonts */ + private FontRenderer fontRenderer; + public static double renderPosX; + public static double renderPosY; + public static double renderPosZ; + public TextureManager renderEngine; + public ItemRenderer itemRenderer; + /** Reference to the World object. */ + public World worldObj; + /** Rendermanager's variable for the player */ + public EntityLivingBase livingPlayer; + public Entity field_147941_i; + public float playerViewY; + public float playerViewX; + /** Reference to the GameSettings object. */ + public GameSettings options; + public double viewerPosX; + public double viewerPosY; + public double viewerPosZ; + /** whether bounding box should be rendered or not */ + public static boolean debugBoundingBox; + private static final String __OBFID = "CL_00000991"; + + private RenderManager() + { + this.entityRenderMap.put(EntityCaveSpider.class, new RenderCaveSpider()); + this.entityRenderMap.put(EntitySpider.class, new RenderSpider()); + this.entityRenderMap.put(EntityPig.class, new RenderPig(new ModelPig(), new ModelPig(0.5F), 0.7F)); + this.entityRenderMap.put(EntitySheep.class, new RenderSheep(new ModelSheep2(), new ModelSheep1(), 0.7F)); + this.entityRenderMap.put(EntityCow.class, new RenderCow(new ModelCow(), 0.7F)); + this.entityRenderMap.put(EntityMooshroom.class, new RenderMooshroom(new ModelCow(), 0.7F)); + this.entityRenderMap.put(EntityWolf.class, new RenderWolf(new ModelWolf(), new ModelWolf(), 0.5F)); + this.entityRenderMap.put(EntityChicken.class, new RenderChicken(new ModelChicken(), 0.3F)); + this.entityRenderMap.put(EntityOcelot.class, new RenderOcelot(new ModelOcelot(), 0.4F)); + this.entityRenderMap.put(EntitySilverfish.class, new RenderSilverfish()); + this.entityRenderMap.put(EntityCreeper.class, new RenderCreeper()); + this.entityRenderMap.put(EntityEnderman.class, new RenderEnderman()); + this.entityRenderMap.put(EntitySnowman.class, new RenderSnowMan()); + this.entityRenderMap.put(EntitySkeleton.class, new RenderSkeleton()); + this.entityRenderMap.put(EntityWitch.class, new RenderWitch()); + this.entityRenderMap.put(EntityBlaze.class, new RenderBlaze()); + this.entityRenderMap.put(EntityZombie.class, new RenderZombie()); + this.entityRenderMap.put(EntitySlime.class, new RenderSlime(new ModelSlime(16), new ModelSlime(0), 0.25F)); + this.entityRenderMap.put(EntityMagmaCube.class, new RenderMagmaCube()); + this.entityRenderMap.put(EntityPlayer.class, new RenderPlayer()); + this.entityRenderMap.put(EntityGiantZombie.class, new RenderGiantZombie(new ModelZombie(), 0.5F, 6.0F)); + this.entityRenderMap.put(EntityGhast.class, new RenderGhast()); + this.entityRenderMap.put(EntitySquid.class, new RenderSquid(new ModelSquid(), 0.7F)); + this.entityRenderMap.put(EntityVillager.class, new RenderVillager()); + this.entityRenderMap.put(EntityIronGolem.class, new RenderIronGolem()); + this.entityRenderMap.put(EntityBat.class, new RenderBat()); + this.entityRenderMap.put(EntityDragon.class, new RenderDragon()); + this.entityRenderMap.put(EntityEnderCrystal.class, new RenderEnderCrystal()); + this.entityRenderMap.put(EntityWither.class, new RenderWither()); + this.entityRenderMap.put(Entity.class, new RenderEntity()); + this.entityRenderMap.put(EntityPainting.class, new RenderPainting()); + this.entityRenderMap.put(EntityItemFrame.class, new RenderItemFrame()); + this.entityRenderMap.put(EntityLeashKnot.class, new RenderLeashKnot()); + this.entityRenderMap.put(EntityArrow.class, new RenderArrow()); + this.entityRenderMap.put(EntitySnowball.class, new RenderSnowball(Items.snowball)); + this.entityRenderMap.put(EntityEnderPearl.class, new RenderSnowball(Items.ender_pearl)); + this.entityRenderMap.put(EntityEnderEye.class, new RenderSnowball(Items.ender_eye)); + this.entityRenderMap.put(EntityEgg.class, new RenderSnowball(Items.egg)); + this.entityRenderMap.put(EntityPotion.class, new RenderSnowball(Items.potionitem, 16384)); + this.entityRenderMap.put(EntityExpBottle.class, new RenderSnowball(Items.experience_bottle)); + this.entityRenderMap.put(EntityFireworkRocket.class, new RenderSnowball(Items.fireworks)); + this.entityRenderMap.put(EntityLargeFireball.class, new RenderFireball(2.0F)); + this.entityRenderMap.put(EntitySmallFireball.class, new RenderFireball(0.5F)); + this.entityRenderMap.put(EntityWitherSkull.class, new RenderWitherSkull()); + this.entityRenderMap.put(EntityItem.class, new RenderItem()); + this.entityRenderMap.put(EntityXPOrb.class, new RenderXPOrb()); + this.entityRenderMap.put(EntityTNTPrimed.class, new RenderTNTPrimed()); + this.entityRenderMap.put(EntityFallingBlock.class, new RenderFallingBlock()); + this.entityRenderMap.put(EntityMinecartTNT.class, new RenderTntMinecart()); + this.entityRenderMap.put(EntityMinecartMobSpawner.class, new RenderMinecartMobSpawner()); + this.entityRenderMap.put(EntityMinecart.class, new RenderMinecart()); + this.entityRenderMap.put(EntityBoat.class, new RenderBoat()); + this.entityRenderMap.put(EntityFishHook.class, new RenderFish()); + this.entityRenderMap.put(EntityHorse.class, new RenderHorse(new ModelHorse(), 0.75F)); + this.entityRenderMap.put(EntityLightningBolt.class, new RenderLightningBolt()); + Iterator iterator = this.entityRenderMap.values().iterator(); + + while (iterator.hasNext()) + { + Render render = (Render)iterator.next(); + render.setRenderManager(this); + } + } + + public Render getEntityClassRenderObject(Class par1Class) + { + Render render = (Render)this.entityRenderMap.get(par1Class); + + if (render == null && par1Class != Entity.class) + { + render = this.getEntityClassRenderObject(par1Class.getSuperclass()); + this.entityRenderMap.put(par1Class, render); + } + + return render; + } + + public Render getEntityRenderObject(Entity par1Entity) + { + return this.getEntityClassRenderObject(par1Entity.getClass()); + } + + public void cacheActiveRenderInfo(World p_147938_1_, TextureManager p_147938_2_, FontRenderer p_147938_3_, EntityLivingBase p_147938_4_, Entity p_147938_5_, GameSettings p_147938_6_, float p_147938_7_) + { + this.worldObj = p_147938_1_; + this.renderEngine = p_147938_2_; + this.options = p_147938_6_; + this.livingPlayer = p_147938_4_; + this.field_147941_i = p_147938_5_; + this.fontRenderer = p_147938_3_; + + if (p_147938_4_.isPlayerSleeping()) + { + Block block = p_147938_1_.getBlock(MathHelper.floor_double(p_147938_4_.posX), MathHelper.floor_double(p_147938_4_.posY), MathHelper.floor_double(p_147938_4_.posZ)); + int x = MathHelper.floor_double(p_147938_4_.posX); + int y = MathHelper.floor_double(p_147938_4_.posY); + int z = MathHelper.floor_double(p_147938_4_.posZ); + + if (block.isBed(p_147938_1_, x, y, z, p_147938_4_)) + { + int j = block.getBedDirection(p_147938_1_, x, y, z); + this.playerViewY = (float)(j * 90 + 180); + this.playerViewX = 0.0F; + } + } + else + { + this.playerViewY = p_147938_4_.prevRotationYaw + (p_147938_4_.rotationYaw - p_147938_4_.prevRotationYaw) * p_147938_7_; + this.playerViewX = p_147938_4_.prevRotationPitch + (p_147938_4_.rotationPitch - p_147938_4_.prevRotationPitch) * p_147938_7_; + } + + if (p_147938_6_.thirdPersonView == 2) + { + this.playerViewY += 180.0F; + } + + this.viewerPosX = p_147938_4_.lastTickPosX + (p_147938_4_.posX - p_147938_4_.lastTickPosX) * (double)p_147938_7_; + this.viewerPosY = p_147938_4_.lastTickPosY + (p_147938_4_.posY - p_147938_4_.lastTickPosY) * (double)p_147938_7_; + this.viewerPosZ = p_147938_4_.lastTickPosZ + (p_147938_4_.posZ - p_147938_4_.lastTickPosZ) * (double)p_147938_7_; + } + + public boolean renderEntitySimple(Entity p_147937_1_, float p_147937_2_) + { + return this.renderEntityStatic(p_147937_1_, p_147937_2_, false); + } + + public boolean renderEntityStatic(Entity p_147936_1_, float p_147936_2_, boolean p_147936_3_) + { + ProfilerSection.RENDER_ENTITY.start(p_147936_1_); + + if (p_147936_1_.ticksExisted == 0) + { + p_147936_1_.lastTickPosX = p_147936_1_.posX; + p_147936_1_.lastTickPosY = p_147936_1_.posY; + p_147936_1_.lastTickPosZ = p_147936_1_.posZ; + } + + double d0 = p_147936_1_.lastTickPosX + (p_147936_1_.posX - p_147936_1_.lastTickPosX) * (double)p_147936_2_; + double d1 = p_147936_1_.lastTickPosY + (p_147936_1_.posY - p_147936_1_.lastTickPosY) * (double)p_147936_2_; + double d2 = p_147936_1_.lastTickPosZ + (p_147936_1_.posZ - p_147936_1_.lastTickPosZ) * (double)p_147936_2_; + float f1 = p_147936_1_.prevRotationYaw + (p_147936_1_.rotationYaw - p_147936_1_.prevRotationYaw) * p_147936_2_; + int i = p_147936_1_.getBrightnessForRender(p_147936_2_); + + if (p_147936_1_.isBurning()) + { + i = 15728880; + } + + int j = i % 65536; + int k = i / 65536; + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)j / 1.0F, (float)k / 1.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + boolean retVal = this.func_147939_a(p_147936_1_, d0 - renderPosX, d1 - renderPosY, d2 - renderPosZ, f1, p_147936_2_, p_147936_3_); + + ProfilerSection.RENDER_ENTITY.stop(p_147936_1_); + return retVal; + } + + public boolean renderEntityWithPosYaw(Entity p_147940_1_, double p_147940_2_, double p_147940_4_, double p_147940_6_, float p_147940_8_, float p_147940_9_) + { + return this.func_147939_a(p_147940_1_, p_147940_2_, p_147940_4_, p_147940_6_, p_147940_8_, p_147940_9_, false); + } + + public boolean func_147939_a(Entity p_147939_1_, double p_147939_2_, double p_147939_4_, double p_147939_6_, float p_147939_8_, float p_147939_9_, boolean p_147939_10_) + { + Render render = null; + + try + { + render = this.getEntityRenderObject(p_147939_1_); + + if (render != null && this.renderEngine != null) + { + if (!render.isStaticEntity() || p_147939_10_) + { + try + { + render.doRender(p_147939_1_, p_147939_2_, p_147939_4_, p_147939_6_, p_147939_8_, p_147939_9_); + } + catch (Throwable throwable2) + { + throw new ReportedException(CrashReport.makeCrashReport(throwable2, "Rendering entity in world")); + } + + try + { + render.doRenderShadowAndFire(p_147939_1_, p_147939_2_, p_147939_4_, p_147939_6_, p_147939_8_, p_147939_9_); + } + catch (Throwable throwable1) + { + throw new ReportedException(CrashReport.makeCrashReport(throwable1, "Post-rendering entity in world")); + } + + if (debugBoundingBox && !p_147939_1_.isInvisible() && !p_147939_10_) + { + try + { + this.renderDebugBoundingBox(p_147939_1_, p_147939_2_, p_147939_4_, p_147939_6_, p_147939_8_, p_147939_9_); + } + catch (Throwable throwable) + { + throw new ReportedException(CrashReport.makeCrashReport(throwable, "Rendering entity hitbox in world")); + } + } + } + } + else if (this.renderEngine != null) + { + return false; + } + + return true; + } + catch (Throwable throwable3) + { + CrashReport crashreport = CrashReport.makeCrashReport(throwable3, "Rendering entity in world"); + CrashReportCategory crashreportcategory = crashreport.makeCategory("Entity being rendered"); + p_147939_1_.addEntityCrashInfo(crashreportcategory); + CrashReportCategory crashreportcategory1 = crashreport.makeCategory("Renderer details"); + crashreportcategory1.addCrashSection("Assigned renderer", render); + crashreportcategory1.addCrashSection("Location", CrashReportCategory.func_85074_a(p_147939_2_, p_147939_4_, p_147939_6_)); + crashreportcategory1.addCrashSection("Rotation", Float.valueOf(p_147939_8_)); + crashreportcategory1.addCrashSection("Delta", Float.valueOf(p_147939_9_)); + throw new ReportedException(crashreport); + } + } + + /** + * Renders the bounding box around an entity when F3+B is pressed + */ + private void renderDebugBoundingBox(Entity par1Entity, double par2, double par4, double par6, float par8, float par9) + { + GL11.glDepthMask(false); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_CULL_FACE); + GL11.glDisable(GL11.GL_BLEND); + float f2 = par1Entity.width / 2.0F; + AxisAlignedBB axisalignedbb = AxisAlignedBB.getAABBPool().getAABB(par2 - (double)f2, par4, par6 - (double)f2, par2 + (double)f2, par4 + (double)par1Entity.height, par6 + (double)f2); + RenderGlobal.drawOutlinedBoundingBox(axisalignedbb, 16777215); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_CULL_FACE); + GL11.glDisable(GL11.GL_BLEND); + GL11.glDepthMask(true); + } + + /** + * World sets this RenderManager's worldObj to the world provided + */ + public void set(World par1World) + { + this.worldObj = par1World; + } + + public double getDistanceToCamera(double par1, double par3, double par5) + { + double d3 = par1 - this.viewerPosX; + double d4 = par3 - this.viewerPosY; + double d5 = par5 - this.viewerPosZ; + return d3 * d3 + d4 * d4 + d5 * d5; + } + + /** + * Returns the font renderer + */ + public FontRenderer getFontRenderer() + { + return this.fontRenderer; + } + + public void updateIcons(IIconRegister par1IconRegister) + { + Iterator iterator = this.entityRenderMap.values().iterator(); + + while (iterator.hasNext()) + { + Render render = (Render)iterator.next(); + render.updateIcons(par1IconRegister); + } + } +} \ No newline at end of file diff --git a/src/main/java/net/minecraft/client/renderer/tileentity/TileEntityRendererDispatcher.java b/src/main/java/net/minecraft/client/renderer/tileentity/TileEntityRendererDispatcher.java new file mode 100644 index 0000000..e9b82aa --- /dev/null +++ b/src/main/java/net/minecraft/client/renderer/tileentity/TileEntityRendererDispatcher.java @@ -0,0 +1,181 @@ +package net.minecraft.client.renderer.tileentity; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import mcp.mobius.mobiuscore.profiler.ProfilerSection; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.entity.RenderEnchantmentTable; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityBeacon; +import net.minecraft.tileentity.TileEntityChest; +import net.minecraft.tileentity.TileEntityEnchantmentTable; +import net.minecraft.tileentity.TileEntityEndPortal; +import net.minecraft.tileentity.TileEntityEnderChest; +import net.minecraft.tileentity.TileEntityMobSpawner; +import net.minecraft.tileentity.TileEntityPiston; +import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.tileentity.TileEntitySkull; +import net.minecraft.util.ReportedException; +import net.minecraft.world.World; + +import org.lwjgl.opengl.GL11; + +@SideOnly(Side.CLIENT) +public class TileEntityRendererDispatcher +{ + public Map mapSpecialRenderers = new HashMap(); + public static TileEntityRendererDispatcher instance = new TileEntityRendererDispatcher(); + private FontRenderer field_147557_n; + /** The player's current X position (same as playerX) */ + public static double staticPlayerX; + /** The player's current Y position (same as playerY) */ + public static double staticPlayerY; + /** The player's current Z position (same as playerZ) */ + public static double staticPlayerZ; + public TextureManager field_147553_e; + public World field_147550_f; + public EntityLivingBase field_147551_g; + public float field_147562_h; + public float field_147563_i; + public double field_147560_j; + public double field_147561_k; + public double field_147558_l; + private static final String __OBFID = "CL_00000963"; + + private TileEntityRendererDispatcher() + { + this.mapSpecialRenderers.put(TileEntitySign.class, new TileEntitySignRenderer()); + this.mapSpecialRenderers.put(TileEntityMobSpawner.class, new TileEntityMobSpawnerRenderer()); + this.mapSpecialRenderers.put(TileEntityPiston.class, new TileEntityRendererPiston()); + this.mapSpecialRenderers.put(TileEntityChest.class, new TileEntityChestRenderer()); + this.mapSpecialRenderers.put(TileEntityEnderChest.class, new TileEntityEnderChestRenderer()); + this.mapSpecialRenderers.put(TileEntityEnchantmentTable.class, new RenderEnchantmentTable()); + this.mapSpecialRenderers.put(TileEntityEndPortal.class, new RenderEndPortal()); + this.mapSpecialRenderers.put(TileEntityBeacon.class, new TileEntityBeaconRenderer()); + this.mapSpecialRenderers.put(TileEntitySkull.class, new TileEntitySkullRenderer()); + Iterator iterator = this.mapSpecialRenderers.values().iterator(); + + while (iterator.hasNext()) + { + TileEntitySpecialRenderer tileentityspecialrenderer = (TileEntitySpecialRenderer)iterator.next(); + tileentityspecialrenderer.func_147497_a(this); + } + } + + public TileEntitySpecialRenderer getSpecialRendererByClass(Class p_147546_1_) + { + TileEntitySpecialRenderer tileentityspecialrenderer = (TileEntitySpecialRenderer)this.mapSpecialRenderers.get(p_147546_1_); + + if (tileentityspecialrenderer == null && p_147546_1_ != TileEntity.class) + { + tileentityspecialrenderer = this.getSpecialRendererByClass(p_147546_1_.getSuperclass()); + this.mapSpecialRenderers.put(p_147546_1_, tileentityspecialrenderer); + } + + return tileentityspecialrenderer; + } + + /** + * Returns true if this TileEntity instance has a TileEntitySpecialRenderer associated with it, false otherwise. + */ + public boolean hasSpecialRenderer(TileEntity p_147545_1_) + { + return this.getSpecialRenderer(p_147545_1_) != null; + } + + public TileEntitySpecialRenderer getSpecialRenderer(TileEntity p_147547_1_) + { + return p_147547_1_ == null ? null : this.getSpecialRendererByClass(p_147547_1_.getClass()); + } + + public void cacheActiveRenderInfo(World p_147542_1_, TextureManager p_147542_2_, FontRenderer p_147542_3_, EntityLivingBase p_147542_4_, float p_147542_5_) + { + if (this.field_147550_f != p_147542_1_) + { + this.func_147543_a(p_147542_1_); + } + + this.field_147553_e = p_147542_2_; + this.field_147551_g = p_147542_4_; + this.field_147557_n = p_147542_3_; + this.field_147562_h = p_147542_4_.prevRotationYaw + (p_147542_4_.rotationYaw - p_147542_4_.prevRotationYaw) * p_147542_5_; + this.field_147563_i = p_147542_4_.prevRotationPitch + (p_147542_4_.rotationPitch - p_147542_4_.prevRotationPitch) * p_147542_5_; + this.field_147560_j = p_147542_4_.lastTickPosX + (p_147542_4_.posX - p_147542_4_.lastTickPosX) * (double)p_147542_5_; + this.field_147561_k = p_147542_4_.lastTickPosY + (p_147542_4_.posY - p_147542_4_.lastTickPosY) * (double)p_147542_5_; + this.field_147558_l = p_147542_4_.lastTickPosZ + (p_147542_4_.posZ - p_147542_4_.lastTickPosZ) * (double)p_147542_5_; + } + + /** + * Render this TileEntity at its current position from the player + */ + public void renderTileEntity(TileEntity p_147544_1_, float p_147544_2_) + { + if (p_147544_1_.getDistanceFrom(this.field_147560_j, this.field_147561_k, this.field_147558_l) < p_147544_1_.getMaxRenderDistanceSquared()) + { + int i = this.field_147550_f.getLightBrightnessForSkyBlocks(p_147544_1_.xCoord, p_147544_1_.yCoord, p_147544_1_.zCoord, 0); + int j = i % 65536; + int k = i / 65536; + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)j / 1.0F, (float)k / 1.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.renderTileEntityAt(p_147544_1_, (double)p_147544_1_.xCoord - staticPlayerX, (double)p_147544_1_.yCoord - staticPlayerY, (double)p_147544_1_.zCoord - staticPlayerZ, p_147544_2_); + } + } + + /** + * Render this TileEntity at a given set of coordinates + */ + public void renderTileEntityAt(TileEntity p_147549_1_, double p_147549_2_, double p_147549_4_, double p_147549_6_, float p_147549_8_) + { + ProfilerSection.RENDER_TILEENTITY.start(p_147549_1_); + + TileEntitySpecialRenderer tileentityspecialrenderer = this.getSpecialRenderer(p_147549_1_); + + if (tileentityspecialrenderer != null) + { + try + { + tileentityspecialrenderer.renderTileEntityAt(p_147549_1_, p_147549_2_, p_147549_4_, p_147549_6_, p_147549_8_); + } + catch (Throwable throwable) + { + CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Rendering Block Entity"); + CrashReportCategory crashreportcategory = crashreport.makeCategory("Block Entity Details"); + p_147549_1_.func_145828_a(crashreportcategory); + throw new ReportedException(crashreport); + } + } + + ProfilerSection.RENDER_TILEENTITY.stop(p_147549_1_); + } + + public void func_147543_a(World p_147543_1_) + { + this.field_147550_f = p_147543_1_; + Iterator iterator = this.mapSpecialRenderers.values().iterator(); + + while (iterator.hasNext()) + { + TileEntitySpecialRenderer tileentityspecialrenderer = (TileEntitySpecialRenderer)iterator.next(); + + if (tileentityspecialrenderer != null) + { + tileentityspecialrenderer.func_147496_a(p_147543_1_); + } + } + } + + public FontRenderer getFontRenderer() + { + return this.field_147557_n; + } +} \ 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 bc22bd2..489c8bd 100644 --- a/src/main/java/net/minecraft/world/World.java +++ b/src/main/java/net/minecraft/world/World.java @@ -2,6 +2,7 @@ package net.minecraft.world; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; + import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -11,6 +12,8 @@ import java.util.List; import java.util.Random; import java.util.Set; import java.util.concurrent.Callable; + +import mcp.mobius.mobiuscore.profiler.ProfilerSection; import net.minecraft.block.Block; import net.minecraft.block.BlockHopper; import net.minecraft.block.BlockLiquid; @@ -51,7 +54,6 @@ 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; @@ -2061,7 +2063,9 @@ public abstract class World implements IBlockAccess { try { + ProfilerSection.ENTITY_UPDATETIME.start(entity); this.updateEntity(entity); + ProfilerSection.ENTITY_UPDATETIME.stop(entity); } catch (Throwable throwable1) { @@ -2113,7 +2117,9 @@ public abstract class World implements IBlockAccess { try { + ProfilerSection.TILEENT_UPDATETIME.start(tileentity); tileentity.updateEntity(); + ProfilerSection.TILEENT_UPDATETIME.stop(tileentity); } catch (Throwable throwable) { diff --git a/src/main/java/net/minecraft/world/WorldServer.java b/src/main/java/net/minecraft/world/WorldServer.java new file mode 100644 index 0000000..3ada194 --- /dev/null +++ b/src/main/java/net/minecraft/world/WorldServer.java @@ -0,0 +1,1152 @@ +package net.minecraft.world; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +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 mcp.mobius.mobiuscore.profiler.ProfilerSection; +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; + +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; + /** All work to do in future ticks. */ + private TreeSet pendingTickListEntriesTreeSet; + public ChunkProviderServer theChunkProviderServer; + /** Whether or not level saving is enabled */ + public boolean levelSaving; + /** is false if there are no players */ + private boolean allPlayersSleeping; + private int updateEntityTick; + /** + * the teleporter to use when the entity is being transferred into the dimension + */ + 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(); + /** An IntHashMap of entity IDs (integers) to their Entity objects. */ + private IntHashMap entityIdMap; + private static final String __OBFID = "CL_00001437"; + + /** Stores the recently processed (lighting) chunks */ + protected Set doneChunks = new HashSet(); + 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); + } + + /** + * Runs a single tick for the world + */ + public void tick() + { + ProfilerSection.DIMENSION_BLOCKTICK.start(this.provider.dimensionId); + 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(); + ProfilerSection.DIMENSION_BLOCKTICK.stop(this.provider.dimensionId); + } + + /** + * only spawns creatures allowed by the chunkProvider + */ + 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; + } + + /** + * Updates the flag that indicates whether or not all players in the world are sleeping. + */ + 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; + } + } + + /** + * Sets a new spawn location by finding an uncovered block at a random (x,z) location in the chunk. + */ + @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; + Iterator iterator = this.activeChunkSet.iterator(); + + doneChunks.retainAll(activeChunkSet); + if (doneChunks.size() == activeChunkSet.size()) + { + doneChunks.clear(); + } + + final long startTime = System.nanoTime(); + + while (iterator.hasNext()) + { + ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair)iterator.next(); + int k = chunkcoordintpair.chunkXPos * 16; + int l = chunkcoordintpair.chunkZPos * 16; + this.theProfiler.startSection("getChunk"); + Chunk chunk = this.getChunkFromChunkCoords(chunkcoordintpair.chunkXPos, chunkcoordintpair.chunkZPos); + 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(chunkcoordintpair)) + { + 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(); + } + } + + /** + * Returns true if the given block will receive a scheduled tick in this tick. Args: X, Y, Z, Block + */ + public boolean isBlockTickScheduledThisTick(int p_147477_1_, int p_147477_2_, int p_147477_3_, Block p_147477_4_) + { + NextTickListEntry nextticklistentry = new NextTickListEntry(p_147477_1_, p_147477_2_, p_147477_3_, p_147477_4_); + return this.pendingTickListEntriesThisTick.contains(nextticklistentry); + } + + /** + * Schedules a tick to a block with a delay (Most commonly the tick rate) + */ + 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 p_147454_1_, int p_147454_2_, int p_147454_3_, Block p_147454_4_, int p_147454_5_, int p_147454_6_) + { + NextTickListEntry nextticklistentry = new NextTickListEntry(p_147454_1_, p_147454_2_, p_147454_3_, p_147454_4_); + //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 && p_147454_4_.getMaterial() != Material.air) + { + if (p_147454_4_.func_149698_L()) + { + b0 = 8; + + if (this.checkChunksExist(nextticklistentry.xCoord - b0, nextticklistentry.yCoord - b0, nextticklistentry.zCoord - b0, nextticklistentry.xCoord + b0, nextticklistentry.yCoord + b0, nextticklistentry.zCoord + b0)) + { + Block block1 = this.getBlock(nextticklistentry.xCoord, nextticklistentry.yCoord, nextticklistentry.zCoord); + + if (block1.getMaterial() != Material.air && block1 == nextticklistentry.func_151351_a()) + { + block1.updateTick(this, nextticklistentry.xCoord, nextticklistentry.yCoord, nextticklistentry.zCoord, this.rand); + } + } + + return; + } + + p_147454_5_ = 1; + } + + if (this.checkChunksExist(p_147454_1_ - b0, p_147454_2_ - b0, p_147454_3_ - b0, p_147454_1_ + b0, p_147454_2_ + b0, p_147454_3_ + b0)) + { + if (p_147454_4_.getMaterial() != Material.air) + { + nextticklistentry.setScheduledTime((long)p_147454_5_ + this.worldInfo.getWorldTotalTime()); + nextticklistentry.setPriority(p_147454_6_); + } + + if (!this.pendingTickListEntriesHashSet.contains(nextticklistentry)) + { + this.pendingTickListEntriesHashSet.add(nextticklistentry); + this.pendingTickListEntriesTreeSet.add(nextticklistentry); + } + } + } + + 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_) + { + NextTickListEntry nextticklistentry = new NextTickListEntry(p_147446_1_, p_147446_2_, p_147446_3_, p_147446_4_); + nextticklistentry.setPriority(p_147446_6_); + + if (p_147446_4_.getMaterial() != Material.air) + { + nextticklistentry.setScheduledTime((long)p_147446_5_ + this.worldInfo.getWorldTotalTime()); + } + + if (!this.pendingTickListEntriesHashSet.contains(nextticklistentry)) + { + this.pendingTickListEntriesHashSet.add(nextticklistentry); + this.pendingTickListEntriesTreeSet.add(nextticklistentry); + } + } + + /** + * Updates (and cleans up) entities and tile entities + */ + public void updateEntities() + { + if (this.playerEntities.isEmpty() && getPersistentChunks().isEmpty()) + { + if (this.updateEntityTick++ >= 1200) + { + return; + } + } + else + { + this.resetUpdateEntityTick(); + } + + super.updateEntities(); + } + + /** + * Resets the updateEntityTick field to 0 + */ + public void resetUpdateEntityTick() + { + this.updateEntityTick = 0; + } + + /** + * Runs through the list of updates to run and ticks them + */ + public boolean tickUpdates(boolean par1) + { + int i = this.pendingTickListEntriesTreeSet.size(); + + if (i != this.pendingTickListEntriesHashSet.size()) + { + throw new IllegalStateException("TickNextTick list out of synch"); + } + else + { + if (i > 1000) + { + i = 1000; + } + + this.theProfiler.startSection("cleaning"); + NextTickListEntry nextticklistentry; + + for (int j = 0; j < i; ++j) + { + nextticklistentry = (NextTickListEntry)this.pendingTickListEntriesTreeSet.first(); + + if (!par1 && nextticklistentry.scheduledTime > this.worldInfo.getWorldTotalTime()) + { + break; + } + + this.pendingTickListEntriesTreeSet.remove(nextticklistentry); + this.pendingTickListEntriesHashSet.remove(nextticklistentry); + this.pendingTickListEntriesThisTick.add(nextticklistentry); + } + + this.theProfiler.endSection(); + this.theProfiler.startSection("ticking"); + Iterator iterator = this.pendingTickListEntriesThisTick.iterator(); + + while (iterator.hasNext()) + { + nextticklistentry = (NextTickListEntry)iterator.next(); + iterator.remove(); + //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.checkChunksExist(nextticklistentry.xCoord - b0, nextticklistentry.yCoord - b0, nextticklistentry.zCoord - b0, nextticklistentry.xCoord + b0, nextticklistentry.yCoord + b0, nextticklistentry.zCoord + b0)) + { + Block block = this.getBlock(nextticklistentry.xCoord, nextticklistentry.yCoord, nextticklistentry.zCoord); + + if (block.getMaterial() != Material.air && Block.isEqualTo(block, nextticklistentry.func_151351_a())) + { + try + { + block.updateTick(this, nextticklistentry.xCoord, nextticklistentry.yCoord, nextticklistentry.zCoord, 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(nextticklistentry.xCoord, nextticklistentry.yCoord, nextticklistentry.zCoord); + } + catch (Throwable throwable) + { + k = -1; + } + + CrashReportCategory.func_147153_a(crashreportcategory, nextticklistentry.xCoord, nextticklistentry.yCoord, nextticklistentry.zCoord, block, k); + throw new ReportedException(crashreport); + } + } + } + else + { + this.scheduleBlockUpdate(nextticklistentry.xCoord, nextticklistentry.yCoord, nextticklistentry.zCoord, nextticklistentry.func_151351_a(), 0); + } + } + + this.theProfiler.endSection(); + this.pendingTickListEntriesThisTick.clear(); + return !this.pendingTickListEntriesTreeSet.isEmpty(); + } + } + + public List getPendingBlockUpdates(Chunk par1Chunk, boolean par2) + { + ArrayList arraylist = null; + ChunkCoordIntPair chunkcoordintpair = par1Chunk.getChunkCoordIntPair(); + int i = (chunkcoordintpair.chunkXPos << 4) - 2; + int j = i + 16 + 2; + int k = (chunkcoordintpair.chunkZPos << 4) - 2; + int l = k + 16 + 2; + + for (int i1 = 0; i1 < 2; ++i1) + { + Iterator iterator; + + if (i1 == 0) + { + iterator = this.pendingTickListEntriesTreeSet.iterator(); + } + else + { + iterator = this.pendingTickListEntriesThisTick.iterator(); + + if (!this.pendingTickListEntriesThisTick.isEmpty()) + { + logger.debug("toBeTicked = " + this.pendingTickListEntriesThisTick.size()); + } + } + + while (iterator.hasNext()) + { + NextTickListEntry nextticklistentry = (NextTickListEntry)iterator.next(); + + if (nextticklistentry.xCoord >= i && nextticklistentry.xCoord < j && nextticklistentry.zCoord >= k && nextticklistentry.zCoord < l) + { + if (par2) + { + this.pendingTickListEntriesHashSet.remove(nextticklistentry); + iterator.remove(); + } + + if (arraylist == null) + { + arraylist = new ArrayList(); + } + + arraylist.add(nextticklistentry); + } + } + } + + return arraylist; + } + + /** + * Will update the entity in the world if the chunk the entity is in is currently loaded or its forced to update. + * Args: entity, forceUpdate + */ + 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); + } + + /** + * Creates the chunk provider for this world. Called in the constructor. Retrieves provider from worldProvider? + */ + 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; + } + + /** + * Called when checking if a certain block can be mined or not. The 'spawn safe zone' check is located here. + */ + 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); + } + + /** + * creates a spawn position at random within 256 blocks of 0,0 + */ + 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(); + } + } + } + + /** + * Creates the bonus chest in the world. + */ + 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; + } + } + } + + /** + * Gets the hard-coded portal location to use when entering this dimension. + */ + public ChunkCoordinates getEntrancePortalLocation() + { + return this.provider.getEntrancePortalLocation(); + } + + /** + * Saves all chunks to disk while updating progress bar. + */ + 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)); + } + } + + /** + * saves chunk data - currently only called during execution of the Save All command + */ + public void saveChunkData() + { + if (this.chunkProvider.canSave()) + { + this.chunkProvider.saveExtraData(); + } + } + + /** + * Saves the chunks to disk. + */ + 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()); + } + } + } + + /** + * Returns the Entity with the given ID, or null if it doesn't exist in this World. + */ + public Entity getEntityByID(int par1) + { + return (Entity)this.entityIdMap.lookup(par1); + } + + /** + * adds a lightning bolt to the list of lightning bolts in this world. + */ + 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; + } + } + + /** + * sends a Packet 38 (Entity Status) to all tracked players of that entity + */ + public void setEntityState(Entity par1Entity, byte par2) + { + this.getEntityTracker().func_151248_b(par1Entity, new S19PacketEntityStatus(par1Entity, par2)); + } + + /** + * returns a new explosion. Does initiation (at time of writing Explosion is not finished) + */ + 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; + } + + /** + * Adds a block event with the given Args to the blockEventCache. During the next tick(), the block specified will + * have its onBlockEvent handler called with the given parameters. Args: X,Y,Z, Block, EventID, EventParameter + */ + 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; + } + + /** + * Syncs all changes to disk and wait for completion. + */ + public void flush() + { + this.saveHandler.flush(); + } + + /** + * Updates all weather states. + */ + 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; + } + + /** + * Gets the EntityTracker + */ + 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(); + } + } +} \ No newline at end of file