diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index f91f6460..00000000 --- a/.gitattributes +++ /dev/null @@ -1,12 +0,0 @@ -# -# https://help.github.com/articles/dealing-with-line-endings/ -# -# Linux start script should use lf -/gradlew text eol=lf - -# These are Windows script files and should use crlf -*.bat text eol=crlf - -# Binary files should be left untouched -*.jar binary - diff --git a/.gitignore b/.gitignore index 0f51950f..0da720f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ -/dev -.metadata -.classpath -.project -.settings -.gradle -bin -build +/common/dev +/common/bin +/client/bin +/client/run +/server/bin +/server/run +/export +/.metadata diff --git a/README.md b/README.md index 6e35be52..58d9bbb1 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,3 @@ -# TCR - That Cube Rocks +# TCR -Ein Block-basiertes Open-World-Spiel mit vielen Dimensionen und RPG-Elementen. - -**Projekt ist in der frühen Entwicklungsphase / Alpha** - -Dieses Projekt ist Public Domain, siehe UNLICENSE. -Der Client verwendet LWJGL für GLFW und OpenGL, für dessen Lizenz siehe [Die LWJGL Website](https://www.lwjgl.org/license). +Ein Minecraft®™ 1.8.9 "Fork" diff --git a/client/build.gradle.kts b/client/build.gradle.kts deleted file mode 100644 index 78abd8cb..00000000 --- a/client/build.gradle.kts +++ /dev/null @@ -1,47 +0,0 @@ - -plugins { - application - id("com.gradleup.shadow") version "8.3.6" -} - -repositories { - mavenCentral() -} - -dependencies { - implementation(project(":common")) - - implementation(platform("org.lwjgl:lwjgl-bom:3.3.6")) - - implementation("org.lwjgl", "lwjgl") - implementation("org.lwjgl", "lwjgl-glfw") - implementation("org.lwjgl", "lwjgl-opengl") - - runtimeOnly("org.lwjgl", "lwjgl", classifier = "natives-linux") - runtimeOnly("org.lwjgl", "lwjgl", classifier = "natives-freebsd") - runtimeOnly("org.lwjgl", "lwjgl", classifier = "natives-windows") - runtimeOnly("org.lwjgl", "lwjgl-glfw", classifier = "natives-linux") - runtimeOnly("org.lwjgl", "lwjgl-glfw", classifier = "natives-freebsd") - runtimeOnly("org.lwjgl", "lwjgl-glfw", classifier = "natives-windows") - runtimeOnly("org.lwjgl", "lwjgl-opengl", classifier = "natives-linux") - runtimeOnly("org.lwjgl", "lwjgl-opengl", classifier = "natives-freebsd") - runtimeOnly("org.lwjgl", "lwjgl-opengl", classifier = "natives-windows") -} - -java { - toolchain { - languageVersion = JavaLanguageVersion.of(21) - } -} - -application { - mainClass = "client.Client" - tasks.run.get().workingDir = rootProject.file("dev/client") - tasks.run.get().workingDir.mkdirs() - tasks.run.get().systemProperties.put("runtime.devmode", "") -} - -tasks.shadowJar { - destinationDirectory = rootProject.file("dev") - archiveFileName = "tcr_client.jar" -} diff --git a/client/src/client/Client.java b/client/src/client/Client.java new file mode 100755 index 00000000..3ac6dda0 --- /dev/null +++ b/client/src/client/Client.java @@ -0,0 +1,3330 @@ +package client; + +import java.awt.image.BufferedImage; +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Modifier; +import java.net.IDN; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.text.SimpleDateFormat; +import java.util.ArrayDeque; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Queue; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executors; +import java.util.concurrent.FutureTask; +import java.util.function.Function; + +import javax.imageio.ImageIO; +import javax.swing.JFileChooser; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL13; + +import client.audio.AudioInterface; +import client.audio.SoundManager; +import client.audio.Volume; +import client.gui.FileCallback; +import client.gui.Font; +import client.gui.Gui; +import client.gui.GuiConsole; +import client.gui.GuiInfo; +import client.gui.GuiLoading; +import client.gui.GuiMenu; +import client.gui.GuiServer; +import client.gui.Style; +import client.gui.character.GuiChar; +import client.gui.container.GuiContainer; +import client.gui.container.GuiInventory; +import client.gui.element.Area; +import client.gui.ingame.GuiGameOver; +import client.network.ClientLoginHandler; +import client.network.ClientPlayer; +import client.renderer.BlockRenderer; +import client.renderer.Drawing; +import client.renderer.EntityRenderer; +import client.renderer.GlState; +import client.renderer.ItemRenderer; +import client.renderer.RenderGlobal; +import client.renderer.blockmodel.ModelBlock; +import client.renderer.blockmodel.ModelManager; +import client.renderer.chunk.RenderChunk; +import client.renderer.entity.RenderItem; +import client.renderer.entity.RenderManager; +import client.renderer.particle.EffectRenderer; +import client.renderer.texture.ColormapLoader; +import client.renderer.texture.EntityTexManager; +import client.renderer.texture.TextureManager; +import client.renderer.texture.TextureMap; +import client.vars.BoolVar; +import client.vars.CVar; +import client.vars.CVarCategory; +import client.vars.ColorVar; +import client.vars.EnumVar; +import client.vars.FloatVar; +import client.vars.IntVar; +import client.vars.StringVar; +import client.vars.Variable; +import client.vars.BaseVar.VarFunction; +import client.vars.BoolVar.BoolFunction; +import client.vars.EnumVar.EnumFunction; +import client.vars.FloatVar.FloatFunction; +import client.vars.IntVar.IntFunction; +import client.vars.StringVar.StringFunction; +import client.vars.Variable.IntType; +import client.window.Bind; +import client.window.Button; +import client.window.DisplayMode; +import client.window.KeyEvent; +import client.window.Keysym; +import client.window.Wheel; +import client.window.Window; +import client.window.WindowEvent; +import client.world.WorldClient; +import common.block.Block; +import common.collect.Lists; +import common.collect.Maps; +import common.color.TextColor; +import common.entity.Entity; +import common.entity.animal.EntityHorse; +import common.entity.npc.Energy; +import common.entity.npc.EntityNPC; +import common.entity.types.EntityLiving; +import common.future.Futures; +import common.future.ListenableFuture; +import common.future.ListenableFutureTask; +import common.future.ThreadFactoryBuilder; +import common.init.BlockRegistry; +import common.init.Config; +import common.init.EntityRegistry; +import common.init.ItemRegistry; +import common.init.Items; +import common.init.Registry; +import common.init.SoundEvent; +import common.init.UniverseRegistry; +import common.inventory.InventoryPlayer; +import common.item.Item; +import common.item.ItemBlock; +import common.item.ItemControl; +import common.item.ItemStack; +import common.log.Log; +import common.log.LogLevel; +import common.log.Message; +import common.material.Material; +import common.network.IThreadListener; +import common.network.NetConnection; +import common.network.PacketDecoder; +import common.network.PacketEncoder; +import common.network.PacketPrepender; +import common.network.PacketSplitter; +import common.network.NetHandler.ThreadQuickExitException; +import common.packet.CPacketAction; +import common.packet.CPacketCheat; +import common.packet.CPacketMessage; +import common.packet.HPacketHandshake; +import common.packet.LPacketLogin; +import common.packet.CPacketAction.Action; +import common.potion.Potion; +import common.potion.PotionEffect; +import common.potion.PotionHelper; +import common.properties.IProperty; +import common.rng.Random; +import common.sound.EventType; +import common.sound.PositionedSound; +import common.util.BlockPos; +import common.util.BoundingBox; +import common.util.CharValidator; +import common.util.ExtMath; +import common.util.Facing; +import common.util.FileUtils; +import common.util.HitPosition; +import common.util.LazyLoadBase; +import common.util.Util; +import common.util.HitPosition.ObjectType; +import common.world.Chunk; +import common.world.State; +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.Channel; +import io.netty.channel.ChannelException; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.handler.timeout.ReadTimeoutHandler; + +/* + Een net ganz funktionierndes Programm ... + + Absolute Mindestanforderungen: + + Prozessor : Intel Core i3 530 oder AMD Phenom 2 X2 545 + Grafikkarte : NVIDIA GeForce GTS 450 oder AMD Radeon HD 7730 + Arbeitsspeicher : Etwa 512 MB ~ 1 GB, 2 - 4 GB empfohlen + Mainboard : Was gerade passt (auch mit Hammer) + Kühler : Ne Klimaanlage oder ordentlich Pusten + Festplatte : Richtet sich nach der Geduld des Nutzers + Netzteil : Atomkraftwerk oder stabiler Energiekern + Gehäuse : Pappkarton, Bierkasten oder auch gar keins + Tastatur : Hlb fktonrnd odr bsr + Maus : Aus Plastik oder mit extra Quietsch-Effekt + Monitor : Olle Röhre oder gebrochener Flachbild (Mindestens 1280x800) + Stuhl : Interessiert niemanden (sonst siehe Gehäuse) + + [[oder einfach einen Toaster mit nem LCD und Maus]] +*/ + +public class Client implements IThreadListener { + public static class SyncFunction implements IntFunction { + public void apply(IntVar cv, int value) { + Client.CLIENT.sync(value); + } + } + + public static class TickFunction implements FloatFunction { + public void apply(FloatVar cv, float value) { + Client.CLIENT.tick_target(value); + } + } + + public static class ConsoleFunction implements IntFunction { + public void apply(IntVar cv, int value) { + Client.CLIENT.resizeConsole(); + } + } + + public static class ChatFunction implements IntFunction { + public void apply(IntVar cv, int value) { + Client.CLIENT.resizeChat(); + } + } + + public static class FeedFunction implements IntFunction { + public void apply(IntVar cv, int value) { + Client.CLIENT.resizeFeed(); + } + } + + public static class HotbarFunction implements IntFunction { + public void apply(IntVar cv, int value) { + Client.CLIENT.resizeHotbar(); + } + } + + public static class DistanceFunction implements IntFunction { + public void apply(IntVar cv, int value) { + Client.CLIENT.distance(value); + } + } + + public static class LevelFunction implements EnumFunction { + public void apply(EnumVar cv, LogLevel value) { + Log.setLevel(value); + } + } + + private interface DebugRunner { + void execute(Keysym key); + } + + private class DebugFunction { + public final DebugRunner runner; + public final Keysym key; + public final String help; + + public DebugFunction(Keysym key, DebugRunner runner, String help) { + this.key = key; + this.runner = runner; + this.help = help; + } + } + + public static final int LOG_BUFFER = 32768; + private static final LazyLoadBase CLIENT_NIO_EVENTLOOP = new LazyLoadBase() + { + protected NioEventLoopGroup load() + { + return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Client IO #%d").setDaemon(true).build()); + } + }; + + private final Queue> tasks = new ArrayDeque>(); + private final Map bars = Maps.newTreeMap(); + private final Thread clThread = Thread.currentThread(); + private final Map cvars = Maps.newTreeMap(); + private final Map debug = Maps.newTreeMap(); + private final List console = Lists.newArrayList(); + private final List chat = Lists.newArrayList(); + private final List feed = Lists.newArrayList(); + private final List hotbar = Lists.newArrayList(); + private final File config = new File(System.getProperty("config.file", "client.cfg")); + + private boolean primary; + private boolean secondary; + private boolean tertiary; + private boolean quarternary; + private boolean showHud = true; + public boolean jump; + public boolean sneak; + public boolean debugCamEnable; + public boolean debugWorld; + public boolean zooming; + public boolean sprint; + public boolean renderOutlines; + public boolean setGamma; + public boolean nickChanged; + public boolean xrayActive; + public boolean tileOverlay; + public boolean itemCheat; + public boolean dayCycle = true; + public boolean debugPlayer; + public boolean cameraUsed; + public boolean charEditor; + + private int leftClickCounter; + private int rightClickTimer; + private int chunkLoadTimer; + + public int thirdPersonView; + public int timeFactor = 1; + public int chunksUpdated; + + private long lastTicked = 0L; + private long debugUpdateTime = System.currentTimeMillis(); + private long tickStart; + + private float deltaX; + private float deltaY; + public float moveStrafe; + public float moveForward; + public float zoomLevel; + public float gravity = 1.0f; + + private TextureManager textureManager; + private RenderManager renderManager; + private RenderItem renderItem; + private ItemRenderer itemRenderer; + public RenderGlobal renderGlobal; + public EffectRenderer effectRenderer; + public EntityRenderer entityRenderer; + private TextureMap textureMap; + private ModelManager modelManager; + private BlockRenderer blockRenderer; + public Gui open; + + private SoundManager soundManager; + + private NetConnection connection; + private Entity viewEntity; + private Entity pointedEntity; + private BufferedImage skin; + private Object popupTarget; + public PlayerController controller; + public WorldClient world; + public EntityNPC player; + public HitPosition pointed; + + @Variable(name = "chunk_view_distance", category = CVarCategory.RENDER, min = 2, max = 16 /* 128 */, callback = DistanceFunction.class, display = "Sichtweite", unit = "Chunks") + public int renderDistance = 8; + @Variable(name = "chunk_build_time", category = CVarCategory.RENDER, min = 1, max = 100, display = "Max. Zeit für Chunk-Bau pro Frame", unit = "ms") + public int maxBuildTime = 8; + @Variable(name = "gl_fov", category = CVarCategory.RENDER, min = 1.0f, max = 179.0f, display = "Sichtfeld (FOV)", unit = "°", precision = 1) + public float fov = 70.0f; + @Variable(name = "gl_wireframe", category = CVarCategory.RENDER, display = "Gitter-Render-Modus") + public boolean wireframe = false; + + @Variable(name = "con_timestamps", category = CVarCategory.CONSOLE, display = "Zeiten") + public boolean conTimestamps = false; + @Variable(name = "con_loglevel", category = CVarCategory.CONSOLE, display = "Ausgabe", callback = LevelFunction.class) + public LogLevel level = LogLevel.INFO; + + @Variable(name = "win_sync", category = CVarCategory.WINDOW, min = -1, max = 16384, callback = SyncFunction.class, display = "Maximale Bildrate") + public int sync = 0; + + public int width; + public int height; + public int mouse_x; + public int mouse_y; + @Variable(name = "win_width", category = CVarCategory.WINDOW, min = 1, max = 65536, display = "Fensterbreite") + public int xsize = 1280; + @Variable(name = "win_height", category = CVarCategory.WINDOW, min = 1, max = 65536, display = "Fensterhöhe") + public int ysize = 800; + @Variable(name = "win_pos_x", category = CVarCategory.WINDOW, min = -65536, max = 65536, display = "Fenster X-Position") + public int saved_xpos = 0x80000000; + @Variable(name = "win_pos_y", category = CVarCategory.WINDOW, min = -65536, max = 65536, display = "Fenster Y-Position") + public int saved_ypos = 0x80000000; + public int fb_x; + public int fb_y; + + @Variable(name = "phy_sensitivity", category = CVarCategory.INPUT, min = 0.01f, max = 10.0f, display = "Mausempfindlichkeit", precision = 2, unit = "%") + public float sensitivity = 1.0f; + public boolean fullscreen; + public long syncLimit; + public boolean mouseFirst; + public boolean nograb = System.getProperty("mouse.nograb") != null; + public DisplayMode vidMode; + @Variable(name = "gui_dclick_delay", category = CVarCategory.INPUT, min = 150, max = 750, display = "Doppelklick bei", unit = "ms") + public int dclickDelay = 250; + @Variable(name = "console_size", category = CVarCategory.CONSOLE, min = 0, max = 128, callback = ConsoleFunction.class, display = "Nachrichten in der Konsole") + public int consoleSize = 32; + @Variable(name = "chat_size", category = CVarCategory.CONSOLE, min = 0, max = 128, callback = ChatFunction.class, display = "Nachrichten im Chat") + public int chatSize = 32; + @Variable(name = "feed_size", category = CVarCategory.CONSOLE, min = 0, max = 128, callback = FeedFunction.class, display = "Nachrichten im Feed") + public int feedSize = 8; + @Variable(name = "hotbar_size", category = CVarCategory.CONSOLE, min = 0, max = 16, callback = HotbarFunction.class, display = "Nachrichten in der Hotbar") + public int hotbarSize = 2; + @Variable(name = "overlay_fadeout", category = CVarCategory.CONSOLE, min = 1, max = 60, display = "Dauer bis zum Ausblenden", unit = "s") + public int hudFadeout = 8; + @Variable(name = "overlay_enabled", category = CVarCategory.CONSOLE, display = "Nachrichten-Overlay") + public boolean hudOverlay = true; + @Variable(name = "chat_permanent", category = CVarCategory.CONSOLE, display = "Nachrichten im Chat immer einblenden") + public boolean chatPermanent = false; + @Variable(name = "overlay_opacity", category = CVarCategory.CONSOLE, min = 0x00, max = 0xff, display = "Deckkraft Hintergrund") + public int hudOpacity = 0x40; + public boolean syncLimited; + public boolean vsync; + public boolean screenshot; + public boolean saving; + public boolean drawFps; + public boolean drawDebug; + @Variable(name = "gl_vsync_flush", category = CVarCategory.RENDER, display = "Puffer vor Synch. leeren") + public boolean glFlush = false; + @Variable(name = "con_autoclose", category = CVarCategory.CONSOLE, display = "Schließen") + public boolean conAutoclose = true; + public boolean interrupted; + @Variable(name = "gui_theme", category = CVarCategory.GUI, display = "Oberflächen-Design") + public Style style = Style.DEFAULT; + @Variable(name = "gui_scroll_lines", category = CVarCategory.GUI, min = 1, max = 10, display = "Scrollbreite", unit = "Zeilen") + public int scrollLines = 3; + + + + @Variable(name = "tic_target", category = CVarCategory.SYSTEM, min = 1.0f, max = 1200.0f, callback = TickFunction.class, display = "Tickrate") + public float tpsTarget = 20.0f; + @Variable(name = "tic_timeout", category = CVarCategory.SYSTEM, min = 1, max = 60000, display = "Tick-Timeout-Zeit") + public int tickTimeout = 2000; + + @Variable(name = "snd_enabled", category = CVarCategory.SOUND, display = "Tonausgabe") + public boolean soundEnabled = true; + @Variable(name = "snd_buffer_size", category = CVarCategory.SOUND, min = 0, max = 1048576, display = "Puffergröße") + public int soundBufferSize = 2048; + @Variable(name = "snd_frame_size", category = CVarCategory.SOUND, min = 2, max = 8192, display = "PCM-Intervall") + public int soundFrameSize = 32; + + private String serverInfo; + private String tickInfo; + private int lastTickTime = -1; + private AudioInterface audio; + private boolean cfgDirty; + private String buffer = ""; + private boolean waitingForFile; + private boolean refreshing; + + public String message; + public int total; + public int progress = -1; + + private final int[] tickTimes = new int[240]; + private final long[] frames = new long[240]; + private int tickIndex; + private int lastIndex; + private int frameCounter; + private int frameIndex; + private long frameLast; + private long frameWait; + private long startNanoTime = System.nanoTime(); + + public static final Client CLIENT = new Client(); + + private final Bind[] keyBindsHotbar = new Bind[] { + Bind.SELECT1, Bind.SELECT2, Bind.SELECT3, Bind.SELECT4, Bind.SELECT5, Bind.SELECT6, Bind.SELECT7, Bind.SELECT8, Bind.SELECT9 + }; + + private Client() { + } + + private static NetConnection createNetworkManagerAndConnect(InetAddress address, int serverPort) + { + final NetConnection networkmanager = new NetConnection(); + ((Bootstrap)((Bootstrap)((Bootstrap)(new Bootstrap()).group(CLIENT_NIO_EVENTLOOP.getValue())).handler(new ChannelInitializer() + { + protected void initChannel(Channel p_initChannel_1_) throws Exception + { + try + { + p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true)); + } + catch (ChannelException var3) + { + ; + } + + p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"splitter", (ChannelHandler)(new PacketSplitter())).addLast((String)"decoder", (ChannelHandler)(new PacketDecoder(false))).addLast((String)"prepender", (ChannelHandler)(new PacketPrepender())).addLast((String)"encoder", (ChannelHandler)(new PacketEncoder(true))).addLast((String)"packet_handler", (ChannelHandler)networkmanager); + } + })).channel(NioSocketChannel.class)).connect(address, serverPort).syncUninterruptibly(); + return networkmanager; + } + + public void connect(String address, int port, String user, String pass, String access) { + this.displayGuiScreen(GuiLoading.makeWaitTask("Verbinde zu " + (address == null ? "localhost" : address) + ":" + port + " ...")); + Log.JNI.info("Verbinde zu " + (address == null ? "localhost" : address) + ":" + port); + NetConnection connection = null; + try + { + connection = createNetworkManagerAndConnect(address == null ? InetAddress.getLoopbackAddress() : InetAddress.getByName(IDN.toASCII(address)), port); + connection.setNetHandler(new ClientLoginHandler(connection, this, user, access, pass)); + connection.sendPacket(new HPacketHandshake(Config.PROTOCOL)); + connection.sendPacket(new LPacketLogin()); + } + catch (UnknownHostException u) + { + Log.JNI.error(u, "Konnte nicht zu Server verbinden"); + this.disconnected("Unbekannter Hostname: " + (address == null ? "localhost" : address)); + return; + } + catch (Exception e) + { + Log.JNI.error(e, "Konnte nicht zu Server verbinden"); + this.disconnected(e.toString()); + return; + } + this.connection = connection; + } + + public void unloadWorld() { + ClientPlayer netHandler = this.getNetHandler(); + if(netHandler != null) + netHandler.cleanup(); + this.debugWorld = false; + this.charEditor = false; + this.viewEntity = null; + this.connection = null; + this.world = null; + this.player = null; + this.serverInfo = null; + this.lastTickTime = -1; + this.soundManager.stopSounds(); + } + + public void refreshResources() + { + this.textureManager.onReload(); + ColormapLoader.reload(); + this.modelManager.onReload(); + this.renderItem.onReload(); + this.blockRenderer.onReload(); + this.renderGlobal.onReload(); + EntityTexManager.loadNpcTextures(); + this.renderGlobal.loadRenderers(); + } + + public void init() + { + this.textureManager = new TextureManager(); + this.textureManager.onReload(); + this.soundManager = new SoundManager(this); + ColormapLoader.reload(); + GlState.enableTexture2D(); + GlState.shadeModel(GL11.GL_SMOOTH); + GL11.glClearDepth(1.0D); + GlState.enableDepth(); + GlState.depthFunc(GL11.GL_LEQUAL); + GlState.enableAlpha(); + GlState.alphaFunc(GL11.GL_GREATER, 0.1F); + GlState.cullFace(GL11.GL_BACK); + GlState.enableCull(); + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glLoadIdentity(); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + this.textureMap = new TextureMap(); + this.textureManager.loadTexture(TextureMap.locationBlocksTexture, this.textureMap); + this.textureManager.bindTexture(TextureMap.locationBlocksTexture); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + this.modelManager = new ModelManager(this.textureMap); + this.modelManager.onReload(); + this.renderItem = new RenderItem(this.textureManager, this.modelManager); + this.renderManager = new RenderManager(this.textureManager, this.renderItem); + this.itemRenderer = new ItemRenderer(this); + this.renderItem.onReload(); + this.entityRenderer = new EntityRenderer(this); + this.blockRenderer = new BlockRenderer(this.modelManager, this); + this.blockRenderer.onReload(); + this.renderGlobal = new RenderGlobal(this); + this.renderGlobal.onReload(); + EntityTexManager.loadNpcTextures(); + this.effectRenderer = new EffectRenderer(this.world, this.textureManager); + } + + public void start() + { + this.tickStart = System.nanoTime(); + synchronized (this.tasks) + { + while (!this.tasks.isEmpty()) + { + FutureTask task = this.tasks.poll(); + try { + task.run(); + task.get(); + } + catch(ExecutionException e1) { + if(!(e1.getCause() instanceof ThreadQuickExitException)) + Log.JNI.error(e1, "Fehler beim Ausführen von Render-Task " + task); + } + catch(InterruptedException e2) { + Log.JNI.error(e2, "Fehler beim Ausführen von Render-Task " + task); + } + } + } + } + + public void inputGui() { + if (this.open != null) + { + if(Bind.THROW.isPressed()) + this.open.dropItem(); + for(int z = 0; z < this.keyBindsHotbar.length; z++) { + if(this.keyBindsHotbar[z].isPressed()) + this.open.useHotbar(z); + } + + this.primary = this.secondary = this.tertiary = this.quarternary = false; + this.zooming = false; + } + + else + { + if (Bind.PERSPECTIVE.isPressed()) + { + ++this.thirdPersonView; + + if (this.thirdPersonView > 2) + { + this.thirdPersonView = 0; + } + if (this.debugCamEnable && this.thirdPersonView == 2) + { + this.thirdPersonView = 0; + } + + this.renderGlobal.setDisplayListEntitiesDirty(); + } + + boolean hadZoom = this.zooming; + this.zooming = Bind.ZOOM.isDown(); + if(this.zooming && !hadZoom) { + this.zoomLevel = 2.0f; + } +// this.overlay = this.keyBindPlayerList.isKeyDown(); + + for (int l = 0; l < 9; ++l) + { + if (this.keyBindsHotbar[l].isPressed()) + { +// if(!this.showDebugProfilerChart) { + this.player.inventory.currentItem = l; +// } + } + } + +// if (SKC.isBindPressed(SKC.KEY_INVENTORY)) +// { +// } + + if (Bind.THROW.isPressed()) + { + this.player.dropOneItem(this.ctrl()); + } + + this.primary |= Bind.PRIMARY.isPressed(); + this.secondary |= Bind.SECONDARY.isPressed(); + this.tertiary |= Bind.TERTIARY.isPressed(); + this.quarternary |= Bind.QUARTERNARY.isPressed(); + } + } + + public void tick() { + if (this.rightClickTimer > 0) + { + --this.rightClickTimer; + } +// this.ingameGui.updateTick(); + this.entityRenderer.getMouseOver(1.0F); + if (/* !this.paused && */ this.world != null) + { + this.controller.updateController(); + } + this.textureMap.updateAnimations(); + if (this.open != null) + { + this.open.updateScreen(); + } + + if (this.open == null && this.player != null) + { + if (this.player.getHealth() <= 0) + { + this.displayGuiScreen(null); + } + } + + if (this.open != null) + { + this.leftClickCounter = 10000; + } + else if (this.leftClickCounter > 0) + { + --this.leftClickCounter; + } + + if (this.open == null && this.player != null) { + if (this.player.isUsingItem()) + { + if (!Bind.SECONDARY.isDown()) + { + this.controller.onStoppedUsingItem(this.player); + } + } + else + { + if (this.primary) + { + this.primary(); + } + + if (this.secondary) + { + this.secondary(); + } + + if (this.tertiary) + { + this.tertiary(); + } + + if (this.quarternary) + { + this.quarternary(); + } + } + + if (Bind.SECONDARY.isDown() && this.rightClickTimer == 0 && !this.player.isUsingItem()) + { + this.secondary(); + } + + this.sendClickBlockToController(this.open == null && Bind.PRIMARY.isDown()); + } + + this.primary = this.secondary = this.tertiary = this.quarternary = false; + + if (this.world != null) + { + if (this.player != null) + { + ++this.chunkLoadTimer; + + if (this.chunkLoadTimer == 30) + { + this.chunkLoadTimer = 0; + this.world.ensureAreaLoaded(this.player); + } + } + this.entityRenderer.updateRenderer(); + this.renderGlobal.updateClouds(); + this.world.decrLightning(); + this.world.updateEntities(); + } + this.soundManager.update(); + if (this.world != null) + { + this.world.tick(); + if (/* !this.paused && */ this.world != null) + { + this.world.displayTick(ExtMath.floord(this.player.posX), ExtMath.floord(this.player.posY), ExtMath.floord(this.player.posZ)); + } + this.effectRenderer.updateEffects(); + } + else if (this.connection != null) + { + this.connection.processReceivedPackets(); + this.connection.checkDisconnected(); + } + } + + public void render() { + GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlState.enableDepth(); + GlState.clearColor(0.0f, 0.0f, 0.0f, 1.0f); + GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); + if(this.wireframe) { + GL11.glLineWidth(1.0f); + GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); // GL_FRONT_AND_BACK, GL_LINE + } + if(this.open == null) { + if(this.player != null) + this.player.setAngles(this.deltaX, this.deltaY); + this.deltaX = this.deltaY = 0.0f; + } + if(this.player != null) + this.soundManager.setListener(this.player, (float)Timing.tick_fraction); + if(this.player != null && this.player.isEntityInsideOpaqueBlock()) + this.thirdPersonView = 0; + GL11.glPushMatrix(); + GL11.glClear(16640); + GlState.enableTexture2D(); + if(this.world != null) + this.entityRenderer.renderWorld((float)Timing.tick_fraction, System.nanoTime() - this.tickStart); + GL11.glPopMatrix(); + + GlState.disableTexture2D(); + GlState.disableCull(); + GlState.enableBlend(); + if(this.wireframe) + GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL); // GL_FRONT_AND_BACK, GL_FILL + } + + private static int stats(int x, int y, String name, int value, int max, int color) { + int w = (int)(246.0f * (float)value / (float)max); + Drawing.drawTextboxRight(name, x + 250, y, 0x3f000000); + Drawing.drawTextbox(String.format(TextColor.GREEN + "%d " + TextColor.GRAY + "/ " + TextColor.NEON + "%d", value, max), x, y, 0x3f000000); +// Drawing.drawRectColor(x, y + 20, 250, 10, 0xff000000); + Drawing.drawRectBorder(x, y + 20, 250, 10, 0xff000000, 0xff202020, 0xffcfcfcf, 0xff6f6f6f); + Drawing.drawGradient(x + 2 + 246 - w, y + 20 + 2, w, 6, color | 0xff000000, Util.mixColor(color | 0xff000000, 0xff000000)); + return y + 40; + } + + private static int bar(int x, int y, String name, float fill, int color) { + Drawing.drawTextbox(name, x, y, 0x3f000000); +// Drawing.drawRectColor(x, y + 20, 250, 10, 0xff000000); +// Drawing.drawRectColor(x, y + 20, (int)(250.0f * fill), 10, color | 0xff000000); + Drawing.drawRectBorder(x, y + 20, 250, 10, 0xff000000, 0xff202020, 0xffcfcfcf, 0xff6f6f6f); + Drawing.drawGradient(x + 2, y + 20 + 2, (int)(246.0f * fill), 6, color | 0xff000000, Util.mixColor(color | 0xff000000, 0xff000000)); + return y + 40; + } + + public void renderHud() { + this.setupOverlay(); + if(this.world != null && this.open == null && this.thirdPersonView == 0 && this.viewEntity != null) { + if(this.drawDebug) { + this.renderWorldDirections((float)Timing.tick_fraction); + } + else { + Drawing.drawRect(this.fb_x / 2 - 1, this.fb_y / 2 - 16, 2, 32, this.pointed != null && this.pointed.type != ObjectType.MISS ? 0xffffffff : 0xffcfcfcf); + Drawing.drawRect(this.fb_x / 2 - 16, this.fb_y / 2 - 1, 32, 2, this.pointed != null && this.pointed.type != ObjectType.MISS ? 0xffffffff : 0xffcfcfcf); + } + } + if(this.world != null && this.open == null) { + int selected = // this.getRenderViewEntity() != null && this.getRenderViewEntity().isPlayer() ? 9 : 0, + this.getRenderViewEntity() != null && this.getRenderViewEntity().isPlayer() ? + ((EntityNPC)this.getRenderViewEntity()).inventory.currentItem : -1; + for(int n = 0; n < 9; n++) { + int x = this.fb_x / 2 - 180 + n * 40 + 4; + int y = this.fb_y - 40; +// Drawing.drawRect2Border(x - 1, y - 1, 36, 36, 0xff6f6f6f, selected == n ? 0xffffffff : 0xffafafaf); + Drawing.drawRectBorder(x - 1, y - 1, 36, 36, 0xff6f6f6f, selected == n ? 0xffffffff : 0xff000000, 0xffafafaf, 0xff4f4f4f); + } + + ItemStack itemstack = this.player != null ? this.player.inventory.getCurrentItem() : null; + String current = itemstack != null ? itemstack.getItem().getHotbarText(this.player, itemstack) : ""; + if(!current.isEmpty()) + Drawing.drawTextUpward(current, this.fb_x / 2, this.fb_y - 60, 0xffffffff); + } + if(this.world != null && !(this.open instanceof GuiConsole)) { + int x = this.fb_x / 2; + int y = 0; + Iterator> iter = this.bars.entrySet().iterator(); + long now = System.currentTimeMillis(); + while(iter.hasNext()) { + Entry status = iter.next(); + Entity ent; + if(this.player != null && now - status.getValue() < 10000L && (ent = this.player.worldObj.getEntityByID(status.getKey())) instanceof EntityLiving) { + EntityLiving entity = (EntityLiving)ent; + String s = entity.getName() + TextColor.GRAY + " [" + + EntityLiving.getHealthColor(entity.getHealth(), entity.getMaxHealth()) + + entity.getHealth() + TextColor.GRAY + " / " + EntityLiving.getMaxHpColor(entity.getMaxHealth()) + + entity.getMaxHealth() + TextColor.GRAY + "]"; + Drawing.drawTextboxCentered(s, x, y, 0x3f000000); + Drawing.drawRectBorder(x - 200, y + 20, 400, 10, 0xff000000, 0xff202020, 0xffcfcfcf, 0xff6f6f6f); + Drawing.drawGradient(x - 200 + 2, y + 20 + 2, (int)(396.0f * ((float)entity.getHealth() / (float)entity.getMaxHealth())), 6, entity.getColor() | 0xff000000, Util.mixColor(entity.getColor() | 0xff000000, 0xff000000)); +// Drawing.drawRectColor(x - 200, y + 20, 400, 10, 0xff000000); +// Drawing.drawRectColor(x - 200, y + 20, , 0xff000000 | ); + y += 40; + } + else { + iter.remove(); + } + } + + if(this.player != null && (!this.drawDebug || this.open != null)) { + x = 40; + y = 40; + for(PotionEffect effect : this.player.getEffects()) { + Potion potion = effect.getPotion(); + int color = potion.getColor(); + String name = (potion.isBadEffect() ? TextColor.ORANGE : TextColor.ACID) + potion.getDisplay() + PotionHelper.getPotionPotency(effect.getAmplifier()); + String desc = TextColor.NEON + effect.getDurationString(); +// Drawing.drawRectColor(x, y, 250, Font.DEFAULT.yglyph + 2, color | 0xff000000); + Drawing.drawRectBorder(x, y, 250, Font.YGLYPH + 4, 0xff000000, 0xff202020, 0xffcfcfcf, 0xff6f6f6f); + Drawing.drawGradient(x + 2, y + 2, effect.isInfinite() ? 246 : ((int)(246.0f * ((float)effect.getRemaining() / (float)effect.getDuration()))), Font.YGLYPH, color | 0xff000000, Util.mixColor(color | 0xff000000, 0xff000000)); + Drawing.drawText(name, x + 4, y + 2, 0xffffffff); + Drawing.drawTextRight(desc, x + 250 - 4, y + 2, 0xffffffff); + y += 24; + } + } + + if(this.getRenderViewEntity() instanceof EntityLiving) { + EntityLiving entity = (EntityLiving)this.getRenderViewEntity(); + int absorb = entity.getAbsorptionAmount(); + int armor = entity.getTotalArmorValue(); + int stats = 1 + (absorb > 0 ? 1 : 0) + (armor > 0 ? 1 : 0) + (entity.vehicle instanceof EntityLiving ? 1 : 0) + + (entity instanceof EntityNPC && ((EntityNPC)entity).canUseMagic() ? 1 : 0); + for(Energy energy : Energy.values()) { + if(entity.getEnergy(energy) > 0) + stats += 1; + } + x = this.fb_x - 40 - 250; + y = this.fb_y - 40 - stats * 40; + int hp = entity.getHealth(); + int max = entity.getMaxHealth(); + y = stats(x, y, TextColor.RED + "Schaden", hp, max, 0xff0000); + if(absorb > 0) + y = stats(x, y, TextColor.YELLOW + "Schadenspuffer", absorb, 1024, 0xffff00); + if(armor > 0) + y = stats(x, y, TextColor.GRAY + "Rüstung", armor, 1024, 0x707070); + if(entity.vehicle instanceof EntityLiving) { + EntityLiving living = (EntityLiving)entity.vehicle; + int vh = living.getHealth(); + int vhMax = living.getMaxHealth(); + y = stats(x, y, living.getDisplayName() /* + " (Reittier)" */, vh, vhMax, 0xff6060); + } + if(entity instanceof EntityNPC && ((EntityNPC)entity).canUseMagic()) { + int mana = entity.getManaPoints(); + int maxm = entity.getMaxMana(); + y = stats(x, y, TextColor.CYAN + "Mana", mana, maxm, 0x0000ff); + } + for(int z = 0; z < Energy.values().length; z++) { + Energy type = Energy.values()[z]; + int energy = entity.getEnergy(type); + if(energy > 0) { + int emax = entity.getEnergyCap(type); + y = stats(x, y, TextColor.LGRAY + type.display, energy, emax, entity.hasEnergyEffect(type) ? type.effect : type.color); + } + } + } + + if(this.player != null) { + x = 40; + y = this.fb_y - 40 - (this.player.isRidingHorse() && this.player.getHorseJumpPower() != 0.0f ? 2 : 1) * 40; + if(this.player.isRidingHorse() && this.player.getHorseJumpPower() != 0.0f) // { + y = bar(x, y, String.format(TextColor.NEON + "Sprungkraft: " + TextColor.CYAN + "%d %%", (int)(this.player.getHorseJumpPower() * 100.0f)), + this.player.getHorseJumpPower(), 0x4040ff); + // } + // else { + y = bar(x, y, String.format(TextColor.ACID + "EXP: " + TextColor.GREEN + "Level %d, %d/%d", this.player.experienceLevel, (int)((float)this.player.xpBarCap() * this.player.experience), this.player.xpBarCap()), this.player.experience, 0x40ff40); + // } + } + + +// SKC.pointed(this.pointed != null && this.pointed.type != ObjectType.MISS); +// SKC.crosshair(this.thirdPersonView == 0); + } + +// gdr.shader = 0; +// glUseProgram(0); +// glBindVertexArray(0); +// glActiveTexture(GL_TEXTURE0); +// GlState.setActiveTexture(WCF.GL_TEXTURE0); +// glBindTexture(GL_TEXTURE_2D, 0); + GlState.bindTexture(0); +// jsys.tooltip[0] = 0; +// this.tooltip = null; +// GlState.resetTextures(); + GlState.setActiveTexture(GL13.GL_TEXTURE0); + GlState.enableTexture2D(); +// GlState.disableDepth(); + if(this.open == null && this.getRenderViewEntity() != null && this.getRenderViewEntity().isPlayer()) { + EntityNPC player = (EntityNPC)this.getRenderViewEntity(); + GlState.enableRescaleNormal(); + GlState.enableBlend(); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + // GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); + ItemRenderer.enableGUIStandardItemLighting(); +// this.getTextureManager().bindTexture("textures/gui/inventory.png"); + GL11.glPushMatrix(); + GL11.glTranslatef((float)(this.fb_x / 2 - 180 + 4 + 1), (float)(this.fb_y - 40 + 1), 0.0f); + GL11.glScalef(2.0f, 2.0f, 2.0f); + + for(int index = 0; index < 9; ++index) { + int xPos = index * 20; +// int yPos = this.fb_y - 40; + ItemStack itemstack = player.inventory.mainInventory[index]; + if(itemstack != null) { + GlState.enableDepth(); + this.renderItem.renderItemAndEffectIntoGUI(itemstack, xPos, 0); +// this.renderItem.renderItemOverlayIntoGUI(itemstack, xPos, 0, null); + } + } + + GL11.glPopMatrix(); + ItemRenderer.disableStandardItemLighting(); + GlState.disableRescaleNormal(); + GlState.disableBlend(); + } + + GlState.disableTexture2D(); + GlState.disableCull(); + GlState.enableBlend(); +// SKC.gui(); +// java_callv(gui, (sys.console->mouse_x - jsys.container_x) / 2, (sys.console->mouse_y - jsys.container_y) / 2); +// java_check_exc(); + GlState.disableDepth(); +// SKC.foreground(); + if(this.open == null && this.getRenderViewEntity() != null && this.getRenderViewEntity().isPlayer()) { + EntityNPC player = (EntityNPC)this.getRenderViewEntity(); + for(int index = 0; index < 9; ++index) { + ItemStack itemstack = player.inventory.mainInventory[index]; + if(itemstack != null) { + GuiContainer.renderItemOverlay(itemstack, + this.fb_x / 2 - 180 + 4 + 1 + index * 40, this.fb_y - 40 + 1, null); + } + } + } + if(this.open != null) + this.open.render(); + else if(this.world == null || this.world.hasNoChunks() || this.charEditor) + Drawing.drawScaled(this, Gui.DIRT_BACKGROUND); + if(Bind.INFO.isDown() && (this.open == null || !(this.open.selected instanceof client.gui.element.Field || this.open.selected instanceof Area))) + this.drawInfo(); + if(this.hudOverlay && !(this.open instanceof GuiConsole)) { + this.drawOverlay(this.feed, this.feedSize, false, 1, 0, 0); + this.drawOverlay(this.console, this.consoleSize, true, 1, 0, this.fb_y); + this.drawOverlay(this.hotbar, this.hotbarSize, true, 0, this.fb_x / 2, this.fb_y - 120); + this.drawOverlay(this.chat, this.chatSize, true, -1, this.fb_x, this.fb_y); + } + if(this.drawFps) { // && !(this.open instanceof GuiConsole) + if(this.drawDebug && this.open == null) { + this.renderStats(); + this.renderLagometer(); + } + else { + Drawing.drawText(String.format("%s%.2f", framecode(), Timing.framerate), 0, 0, 0xffffffff); + } + } + GlState.enableBlend(); + } + + public void renderStats() { + int offset = 5; + int x1 = this.fb_x - 320; + int y1 = 0; + int y2 = this.fb_y; +// int pos = 0; + String str = this.getLeft(); +// if(jstr) +// str = (*jsys.env)->GetStringUTFChars(jsys.env, jstr, NULL); + // elem->r_dirty = 1; + // if(!value) + // return; + offset += str != null ? 18 : 0; + String draw = String.format( + "OpenGL: %s\n" + + "Renderer: %s (%s)\n" + + "Bildrate: %s%.2f" + TextColor.RESET + " %s [%s" + TextColor.RESET + "], %.3f ms, W %d x %d%s\n" + + "Tickrate: %s%.2f" + TextColor.RESET + " %s [" + TextColor.GREEN + "%.1f" + TextColor.RESET + "], %.3f ms, E %d ms" + + "%s%s" + , + GL11.glGetString(GL11.GL_VERSION), // WCF.glGetString(WCF.GL_SHADING_LANGUAGE_VERSION), + GL11.glGetString(GL11.GL_RENDERER), GL11.glGetString(GL11.GL_VENDOR), + this.framecode(), Timing.framerate < 1.0f ? 1.0f / Timing.framerate : Timing.framerate, Timing.framerate < 1.0f ? "SPF" : "FPS", + this.vsync ? TextColor.DGRAY + "VSYNC" : (this.syncLimited ? TextColor.GREEN + "" + this.syncLimit : TextColor.RED + "UNL"), + (float)PerfSection.getTotal(false) / 1000.0f, this.fb_x, this.fb_y, + this.fullscreen ? " @ " + (this.vidMode == null ? "?" : this.vidMode.refresh) + " Hz" : "", + this.tpscode(), Timing.tickrate < 1.0f ? 1.0f / Timing.tickrate : Timing.tickrate, + Timing.tickrate < 1.0f ? "SPT" : "TPS", (float)Timing.tickTarget / 1000.0f, + (float)Timing.tick_time / 1000.0f, this.tickTimeout, + str != null ? "\n" : "", str != null ? str : "" + ); +// if(str) +// (*jsys.env)->ReleaseStringUTFChars(jsys.env, jstr, str); + // gui_render_text(elem, 0, 0, sys.style.text_label, sys.work_buf); + Drawing.drawText(draw, 0, 0, 0xffffffff); + + str = this.getRight(this.debugPlayer); +// str = jstr ? (*jsys.env)->GetStringUTFChars(jsys.env, jstr, NULL) : NULL; + // offset = 10 + (str ? 10 : 0); + StringBuilder sb = new StringBuilder(); + for(PerfSection perf : PerfSection.values()) { + if(sb.length() > 0) + sb.append('\n'); + sb.append(perf.getName()); + } + Drawing.drawText(sb.toString(), x1 + 0, y1, 0xffffffff); +// pos = 0; + sb.setLength(0); + for(PerfSection perf : PerfSection.values()) { + if(sb.length() > 0) + sb.append('\n'); + sb.append(String.format("%.3f ms", (float)perf.getLast() / 1000.0f)); + } + Drawing.drawText(sb.toString(), x1 + 120, y1, 0xffffffff); +// pos = 0; + sb.setLength(0); + long total = PerfSection.getTotal(true); + for(PerfSection perf : PerfSection.values()) { + if(sb.length() > 0) + sb.append('\n'); + sb.append(String.format("%.2f %%", ((float)perf.getLast() / (float)total) * 100.0f)); + } + Drawing.drawText(sb.toString(), x1 + 240, y1, 0xffffffff); + if(str != null) { + y1 = Font.YGLYPH * 10; + Drawing.drawText(str, x1, y1, 0xffffffff); +// (*jsys.env)->ReleaseStringUTFChars(jsys.env, jstr, str); + } + } + + public void finish() { + if(this.screenshot) { + this.screenshot = false; + screenshot(); + } + if(this.cameraUsed) { + this.cameraUsed = false; + if(this.world != null) + this.world.setLastLightning(1, 0xffffff); + } + if(this.isDirty()) + this.save(); + Thread.yield(); + while(System.currentTimeMillis() >= this.debugUpdateTime + 1000L) { + this.chunksUpdated = RenderChunk.renderChunksUpdated; + RenderChunk.renderChunksUpdated = 0; + this.debugUpdateTime += 1000L; + } + } + +// public void action(int btn) { +// if(this.open != null) { +// this.soundManager.playSound(new PositionedSound(SoundEvent.CLICK, 1.0F)); +// this.open.actionPerformed(btn); +// } +// } + + public void scroll(int dir) { +// if(this.open != null) // { +// return; +// if(this.open instanceof GuiCheat) +// ((GuiCheat)this.open).scroll(dir); +// } + if(this.zooming) + this.zoomLevel = ExtMath.clampf(this.zoomLevel + (dir < 0 ? -0.25f : 0.25f), 2.0f, 16.0f); + else if(this.player != null) + this.player.inventory.changeCurrentItem(dir); + } + +// public void resize(int width, int height) +// { +// this.fb_x = width; +// this.fb_y = height; +// // if(this.open != null) +// // this.open.initialize(this, this.fb_x, this.fb_y); +// } + +// public void distance(int distance) +// { +// this.renderDistance = distance; +// this.updateViewDistance(); +// } + +// public void buildTime(int time) +// { +// this.maxBuildTime = time; +// } + + public void moveCamera(float x, float y) { + this.deltaX += x; + this.deltaY += y; + } + +// public void closeScreen() { +// if(this.open != null) { +// if(this.thePlayer != null) +// this.thePlayer.setScreenClosed(); +// this.displayGuiScreen(null); +// } +// } + + public void displayGuiScreen(Gui gui) + { + if(!this.refreshing) + this.waitingForFile = false; + if(this.player != null) + this.player.setScreenClosed(); + if (this.open != null) + { + this.open.onGuiClosed(); + } +// if(this.thePlayer != null && this.thePlayer.getHealth() <= 0 && this.open instanceof GuiGameOver) +// this.thePlayer.respawnPlayer(); + +// if (guiScreenIn == null && this.theWorld == null) +// { +// guiScreenIn = new GuiMainMenu(); +// } +// else + if (gui == null && this.world != null && this.player.getHealth() <= 0) + { + gui = GuiGameOver.INSTANCE; + } +// else if(gui == null && this.open instanceof GuiInventory && this.itemCheat) { +// gui = new GuiCheat(); +// } + + this.open = gui; + if (gui != null) + { + this.menu(true); +// if(this.open != null) { +// this.open.init(); +// } +// else { +// } + gui.init(); +// if(gui instanceof GuiEmpty) +// SKC.setGuiMenu(); +// else +// SKC.setGuiAny(); + Window.setTitle(String.format("%s - %s", Config.CLIENT_VERSION, gui.getTitle())); + } + else + { + this.menu(false); + this.leftClickCounter = 10000; + Bind.disableMouse(); + Window.setTitle(String.format("%s - %s%s", Config.CLIENT_VERSION, "Welt / Render", this.nograb ? "" : " (Maus gefangen)")); +// SKC.setGuiNone(); + } + } + + private void sendClickBlockToController(boolean leftClick) + { + if (!leftClick) + { + this.leftClickCounter = 0; + this.controller.resetInteraction(); + } + + if (this.leftClickCounter <= 0 && !this.player.isUsingItem()) + { + if (leftClick && this.pointed != null && this.pointed.type == HitPosition.ObjectType.BLOCK) + { + BlockPos blockpos = this.pointed.block; + + if (this.world.getState(blockpos).getBlock().getMaterial() != Material.air && this.controller.onPlayerDamageBlock(blockpos, this.pointed.side)) + { + this.effectRenderer.addBlockHitEffects(blockpos, this.pointed.side); + this.player.swingItem(); + } + } + else + { + this.controller.resetBlockRemoving(); + } + } + } + + private void primary() + { + if (this.leftClickCounter <= 0) + { + if (this.pointed == null) + { + this.player.swingItem(); + Log.JNI.warn("Null zurückgegeben als 'hitResult', das sollte niemals passieren!"); + this.leftClickCounter = 10; + } + else + { + ItemStack itemstack = this.player.inventory.getCurrentItem(); + if ((this.pointed.type != ObjectType.BLOCK || this.world.getState(this.pointed.block).getBlock().getMaterial() == Material.air) && itemstack != null && itemstack.getItem().onAction(itemstack, this.player, this.world, ItemControl.PRIMARY, null)) + { + this.player.swingItem(); + this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.PRIMARY.ordinal())); + this.leftClickCounter = 10; + return; + } + + switch (this.pointed.type) + { + case ENTITY: + this.player.swingItem(); + this.controller.attackEntity(this.player, this.pointed.entity); + break; + case BLOCK: + this.player.swingItem(); + BlockPos blockpos = this.pointed.block; + if (this.world.getState(blockpos).getBlock().getMaterial() != Material.air) + { + this.controller.clickBlock(blockpos, this.pointed.side); + break; + } + this.leftClickCounter = 10; + break; + case MISS: + default: + this.player.swingItem(); + this.leftClickCounter = 10; + } + } + } + } + + private void secondary() + { + if (!this.controller.getIsHittingBlock()) + { + this.rightClickTimer = 4; + boolean flag = true; + ItemStack itemstack = this.player.inventory.getCurrentItem(); + + if (itemstack != null && itemstack.getItem() == Items.camera && !this.saving) + { + this.screenshot = this.cameraUsed = true; + } + + if (this.pointed == null) + { + Log.JNI.warn("Null zurückgegeben als 'hitResult', das sollte niemals passieren!"); + } + else + { + if ((this.pointed.type != ObjectType.BLOCK || this.world.getState(this.pointed.block).getBlock().getMaterial() == Material.air) && itemstack != null && itemstack.getItem().onAction(itemstack, this.player, this.world, ItemControl.SECONDARY, null)) + { + this.player.swingItem(); + this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.SECONDARY.ordinal())); + return; + } + + switch (this.pointed.type) + { + case ENTITY: +// if (this.controller.isPlayerRightClickingOnEntity(this.thePlayer, this.pointed.entityHit, this.pointed)) +// { +// flag = false; +// } +// else + if (this.controller.interactWithEntitySendPacket(this.player, this.pointed.entity)) + { + flag = false; + } + + break; + + case BLOCK: + BlockPos blockpos = this.pointed.block; + + if (this.world.getState(blockpos).getBlock().getMaterial() != Material.air) + { + int i = itemstack != null ? itemstack.stackSize : 0; + + if (this.controller.onPlayerRightClick(this.player, this.world, itemstack, blockpos, this.pointed.side, this.pointed.vec)) + { + flag = false; + this.player.swingItem(); + } + + if (itemstack == null) + { + return; + } + + if (itemstack.stackSize == 0) + { + this.player.inventory.mainInventory[this.player.inventory.currentItem] = null; + } + else if (itemstack.stackSize != i) // || this.controller.isCreative()) + { + this.entityRenderer.itemRenderer.resetEquippedProgress(); + } + } + } + } + + if (flag) + { + ItemStack itemstack1 = this.player.inventory.getCurrentItem(); + + if (itemstack1 != null && this.controller.sendUseItem(this.player, this.world, itemstack1)) + { + this.entityRenderer.itemRenderer.resetEquippedProgress2(); + } + } + } + } + + private void tertiary() + { + if (this.pointed != null) + { + if(this.player.getHeldItem() != null && this.player.getHeldItem().getItem().onAction(this.player.getHeldItem(), this.player, this.world, ItemControl.TERTIARY, null)) { + this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.TERTIARY.ordinal())); + return; + } + +// boolean flag = this.thePlayer.creative; + int meta = 0; + boolean flag1 = false; +// TileEntity tileentity = null; + Item item = null; +// NBTTagCompound tag = null; + + if (this.pointed.type == HitPosition.ObjectType.BLOCK) + { + BlockPos blockpos = this.pointed.block; + Block block = this.world.getState(blockpos).getBlock(); + + if (block.getMaterial() == Material.air) + { + return; + } + + item = block.getItem(this.world, blockpos); + + if (item == null) + { + return; + } + + Block block1 = item instanceof ItemBlock && !block.isPickStrict() ? item.getBlock() : block; + meta = block1.getDamageValue(this.world, blockpos); + flag1 = item.getHasSubtypes(); + } + else + { + if (this.pointed.type != HitPosition.ObjectType.ENTITY || this.pointed.entity == null || !this.itemCheat) + { + return; + } + item = this.pointed.entity.getItem(); + if(item == null) + return; + } + + InventoryPlayer inventoryplayer = this.player.inventory; + + inventoryplayer.setCurrentItem(item, meta, flag1); + if(this.itemCheat) { + this.player.client.addToSendQueue(new CPacketCheat(new ItemStack(item, 1, meta), inventoryplayer.currentItem, this.ctrl())); + } + } + } + + private void quarternary() + { + if (this.pointed != null) + { + if(this.player.getHeldItem() != null && this.player.getHeldItem().getItem().onAction(this.player.getHeldItem(), this.player, this.world, ItemControl.QUARTERNARY, null)) { + this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.QUARTERNARY.ordinal())); + return; + } + } + } + +// private void printDebugMessage(String text) { +// this.printDebugMessage(text, null); +// } +// +// private void printDebugMessage(String text, String desc) { +// SKC.notify(text, desc); +// this.soundManager.playSound(new PositionedSound(SoundEvent.CLICK)); +// } + + public void loadWorld(WorldClient world, int type) + { + this.viewEntity = null; + this.connection = null; + this.soundManager.stopSounds(); + this.world = world; + + if (this.renderGlobal != null) + { + this.renderGlobal.setWorldAndLoadRenderers(world); + } + + if (this.effectRenderer != null) + { + this.effectRenderer.clearEffects(world); + } + + if (this.player == null) + { + this.player = this.controller.createPlayerEntity(world, type); + this.player.rotYaw = -180.0F; + } + + this.player.preparePlayerToSpawn(); + world.spawnEntityInWorld(this.player); + this.viewEntity = this.player; + + System.gc(); +// SKC.loaded(true); + } + + public void setDimensionAndSpawnPlayer(int dimension, int type) + { + this.world.removeAllEntities(); + int i = 0; + + if (this.player != null) + { + i = this.player.getId(); + this.world.removeEntity(this.player); + } + + this.viewEntity = null; + EntityNPC entityplayersp = this.player; + this.player = this.controller.createPlayerEntity(this.world, type); + this.player.getDataWatcher().updateWatchedObjectsFromList(entityplayersp.getDataWatcher().getAllWatched()); + this.viewEntity = this.player; + this.player.preparePlayerToSpawn(); + this.world.spawnEntityInWorld(this.player); + this.player.rotYaw = -180.0F; + this.player.setId(i); + +// if (this.open instanceof GuiGameOver) +// { +// if(!this.charEditor) +// this.displayGuiScreen(null); +// } + } + + public ClientPlayer getNetHandler() + { + return this.player != null ? (ClientPlayer)this.player.client : null; + } + +// public void setSkin(BufferedImage skin, String id, ModelType model, boolean slim) +// { +// this.skinSet = id == null ? "" : id; +// this.skinSlim = slim; +// if(this.getNetHandler() != null) { +// this.getNetHandler().addToSendQueue(new CPacketSkin(skin, model)); +// } +// else { +// this.confirmSkin(true); +// } +// } + +// public void confirmSkin(boolean changed) { +// if(changed && this.skinSet != null) { +// this.skinId = this.skinSet; +// if(this.thePlayer != null) +// this.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_MODELPARTS, +// (this.thePlayer.getModelParts() & ~ModelPart.ARMS_SLIM.getMask()) | +// (this.skinSlim ? ModelPart.ARMS_SLIM.getMask() : 0))); +// } +// else if(changed) { +// this.skinId = ""; +// } +// this.skinSet = null; +// this.skinSlim = false; +// } + + public TextureManager getTextureManager() + { + return this.textureManager; + } + + public TextureMap getTextureMapBlocks() + { + return this.textureMap; + } + + public SoundManager getSoundManager() + { + return this.soundManager; + } + + public void performAction(Action action) { + if(this.player != null) + this.player.client.addToSendQueue(new CPacketAction(action)); + } + + public void setBossStatus(EntityLiving entity) { + if(this.bars.size() < 5 || this.bars.containsKey(entity.getId())) + this.bars.put(entity.getId(), System.currentTimeMillis()); + } + + public Entity getRenderViewEntity() + { + return this.viewEntity; + } + + public Entity getPointedEntity() + { + return this.pointedEntity; + } + + public void setPointedEntity(Entity entity) + { + this.pointedEntity = entity; + } + + public void setRenderViewEntity(Entity viewingEntity) + { + this.viewEntity = viewingEntity; + } + + private ListenableFuture addScheduledTask(Callable callableToSchedule) + { + if (!this.isMainThread()) + { + ListenableFutureTask listenablefuturetask = ListenableFutureTask.create(callableToSchedule); + + synchronized (this.tasks) + { + this.tasks.add(listenablefuturetask); + return listenablefuturetask; + } + } + else + { + try + { + return Futures.immediateFuture(callableToSchedule.call()); + } + catch (Exception exception) + { + return Futures.immediateFailedFuture(exception); + } + } + } + + public ListenableFuture schedule(Runnable runnableToSchedule) + { + return this.addScheduledTask(Executors.callable(runnableToSchedule)); + } + + public boolean isMainThread() + { + return Thread.currentThread() == this.clThread; + } + + public BlockRenderer getBlockRendererDispatcher() + { + return this.blockRenderer; + } + + public RenderManager getRenderManager() + { + return this.renderManager; + } + + public RenderItem getRenderItem() + { + return this.renderItem; + } + + public ItemRenderer getItemRenderer() + { + return this.itemRenderer; + } + + public void setTicked(String info) { + this.lastTicked = System.currentTimeMillis(); + this.serverInfo = info; + } + + public void setLastTick(int time, String info) { + if(this.lastTickTime >= 0) { + this.lastTicked = System.currentTimeMillis(); + this.lastTickTime = time; + this.tickInfo = info; + } + } + + public void updatePlayerMoveState() + { + this.moveStrafe = 0.0F; + this.moveForward = 0.0F; + + if (this.open == null && Bind.FORWARD.isDown()) + { + ++this.moveForward; + } + + if (this.open == null && Bind.BACKWARD.isDown()) + { + --this.moveForward; + } + + if (this.open == null && Bind.LEFT.isDown()) + { + ++this.moveStrafe; + } + + if (this.open == null && Bind.RIGHT.isDown()) + { + --this.moveStrafe; + } + + this.jump = this.open == null && Bind.UP.isDown(); + this.sneak = this.open == null && Bind.DOWN.isDown(); + this.sprint = this.open == null && Bind.FAST.isDown(); + + if (this.sneak) + { + this.moveStrafe = (float)((double)this.moveStrafe * 0.3D); + this.moveForward = (float)((double)this.moveForward * 0.3D); + } + } + + public String getLeft() { + long maxMem = Runtime.getRuntime().maxMemory(); + long totalMem = Runtime.getRuntime().totalMemory(); + long freeMem = Runtime.getRuntime().freeMemory(); + long usedMem = totalMem - freeMem; + + String mem = String.format("JVM-Speicher: %d%% %d/%dMB", usedMem * 100L / maxMem, usedMem / 1024L / 1024L, maxMem / 1024L / 1024L) + + "\n" + + String.format("JVM-Reserviert: %d%% %dMB", totalMem * 100L / maxMem, totalMem / 1024L / 1024L); + if(this.world == null) { + return mem; + } + + BlockPos blockpos = new BlockPos(this.viewEntity.posX, this.viewEntity.getEntityBoundingBox().minY, + this.viewEntity.posZ); + + Entity entity = this.viewEntity; + Facing facing = entity.getHorizontalFacing(); + String dirStr = "Ungültig"; + switch(facing) { + case NORTH: + dirStr = "Norden (Nach negativer Z)"; + break; + case SOUTH: + dirStr = "Süden (Nach positiver Z)"; + break; + case WEST: + dirStr = "Westen (Nach negativer X)"; + break; + case EAST: + dirStr = "Osten (Nach positiver X)"; + break; + } + + String light; + if(this.world.isBlockLoaded(blockpos)) { + Chunk chunk = this.world.getChunk(blockpos); + light = "Licht: " + chunk.getLightSub(blockpos, 0) + " (" + + chunk.getLight(blockpos) + " Blöcke, " + String.format( + "%.1f", this.world.getSunBrightness(1.0f) * 15.0f) + " Welt), A: " + + String.format("%.3f", this.world.getCelestialAngle(1.0f)); + } + else { + light = "Licht: " + String.format( + "%.1f", this.world.getSunBrightness(1.0f) * 15.0f) + " Welt, A: " + + String.format("%.3f", this.world.getCelestialAngle(1.0f)); + } + + long ticked = System.currentTimeMillis() - this.lastTicked; + + return + mem + "\n" + +// (this.debugWorld ? "Debug-Welt" : +// (this.isServer() ? "ES: " + this.server.getFolderName() : +// "MS: " + ( +// this.connected != null ? this.connected : "[???]"))), + this.renderGlobal.getDebugInfoRenders() + "\n" + + this.renderGlobal.getDebugInfoEntities() + "\n" + + "Partikel: " + this.effectRenderer.getStatistics() + ". O: " + this.world.getDebugLoadedEntities() + "\n" + + this.world.getInfo() + "\n" + + // "", + String.format("XYZ: %.3f / %.3f / %.3f", this.viewEntity.posX, + this.viewEntity.getEntityBoundingBox().minY, this.viewEntity.posZ) + "\n" + + String.format("Block: %d %d %d, R: '%s/%s'", blockpos.getX(), blockpos.getY(), blockpos.getZ(), + Util.getRegionFolder(blockpos.getX() >> 4, blockpos.getZ() >> 4), + Util.getRegionName(blockpos.getX() >> 4, blockpos.getZ() >> 4)) + "\n" + + String.format("Chunk: %d %d %d + %d %d %d, FOV: %.1f °%s", blockpos.getX() >> 4, blockpos.getY() >> 4, blockpos.getZ() >> 4, + blockpos.getX() & 15, blockpos.getY() & 15, blockpos.getZ() & 15, this.zooming ? + (this.fov / this.zoomLevel) : this.fov, this.zooming ? + String.format(" (Zoom x%.1f)", this.zoomLevel) : "") + "\n" + + String.format("Richtung: %s (%.1f / %.1f)", dirStr, + ExtMath.wrapf(entity.rotYaw), ExtMath.wrapf(entity.rotPitch)) + "\n" + + "Dimension: " + (this.world.isExterminated() ? "[zerstört] " : "") + + TextColor.stripCodes(this.world.dimension.getFormattedName(false)) + + " (" + this.world.dimension.getDimensionId() + ")" + "\n" + + light + "\n" + + String.format("Zeit: %d T, R %d / %d T, U %d / %d T", + this.world.getDayTime(), + this.world.getDayTime() % this.world.dimension.getRotationalPeriod(), + this.world.dimension.getRotationalPeriod(), + this.world.getDayTime() % this.world.dimension.getOrbitalPeriod(), + this.world.dimension.getOrbitalPeriod() + ) + "\n" + + String.format("Wetter: %s (R %.1f, %.1f)", + this.world.getWeather().getDisplay(), this.world.getRainStrength(), + this.world.getDarkness() + ) + "\n" + + String.format("Zeitfaktor: %dx, Schwerkraft: %.2f m/s²", + this.timeFactor, this.world.gravity * 10.0 + ) + "\n" + + String.format("Letzte Zeitsynch.: + %d.%d s", + ticked / 1000L, (ticked / 100L) % 10L + ) + + (this.serverInfo != null ? "\n" + this.serverInfo : "") + + (this.tickInfo != null ? "\n" + this.tickInfo : "") +// IWorldServer world = this.server.getWorld(this.theWorld.dimension.getDimensionId()); +// if(world != null) +// list.add("Seed: " + world.getSeed()); + ; + } + + public String getRight(boolean showPlayerInfo) { + if(this.world == null) { + return null; + } + + if(!showPlayerInfo && this.pointed != null && this.pointed.type == HitPosition.ObjectType.BLOCK + && this.pointed.block != null) { + BlockPos pos = this.pointed.block; + State block = this.world.getState(pos); + + if(!this.debugWorld) { + block = block.getBlock().getActualState(block, this.world, pos); + } + + StringBuilder str = new StringBuilder( + "Schaue auf: " + BlockRegistry.REGISTRY.getNameForObject(block.getBlock()) + " [" + BlockRegistry.getIdFromBlock(block.getBlock()) + + ":" + block.getBlock().getMetaFromState(block) + "]" + "\n" + + String.format("Position: %d %d %d", pos.getX(), pos.getY(), pos.getZ()) + ); +// int off = 2; + for(Entry entry : block.getProperties().entrySet()) { + str.append("\n" + entry.getKey().getName() + ": " + entry.getValue().toString()); + } + + return str.toString(); // new String[] { +// list.add(""); +// list.add(); +// }; + } + else if((this.pointed != null && this.pointed.type == HitPosition.ObjectType.ENTITY + && this.pointed.entity != null) || showPlayerInfo) { + Entity entity = showPlayerInfo ? this.player : this.pointed.entity; + ItemStack held = entity instanceof EntityLiving && ((EntityLiving)entity).getHeldItem() != null ? ((EntityLiving)entity).getHeldItem() : null; + + return +// list.add(""); + (showPlayerInfo ? "Charakter: " : "Schaue auf: ") + (entity.isPlayer() ? "Player/" : "") + EntityRegistry.getEntityString(entity) + // " [" + (entity.isPlayer() ? "player" : + /* (EntityRegistry.getEntityID(entity) + "/" + EntityRegistry.getObjectID(entity))) + "]" */ " (" + entity.getId() + ")" + + "\n" + + String.format("Position: %.3f %.3f %.3f", entity.posX, entity.posY, entity.posZ) + "\n" + + // list.add("Name: '" + entity.getName() + "'"); + "Geladen: " + entity.ticksExisted + "t" + (entity instanceof EntityLiving ? (", Alter: " + ((EntityLiving)entity).getGrowingAge()) + "t" : "") + "\n" + + String.format("Größe: %.2fx%.2f, A: %.2f", entity.width, entity.height, entity.getEyeHeight()) + "\n" + + // if(!this.debugHideInfo) { + String.format("Bewegung: %.3f %.3f %.3f", entity.motionX, entity.motionY, entity.motionZ) + "\n" + + String.format("Drehung: %.1f %.1f, K: %.1f", entity.rotYaw, entity.rotPitch, entity.getRotationYawHead()) + "\n" + + // } + (entity instanceof EntityLiving + ? String.format("Leben: %d/%d, A: %d", ((EntityLiving)entity).getHealth(), ((EntityLiving)entity).getMaxHealth(), + ((EntityLiving)entity).getAbsorptionAmount()) : "Leben: n/a") + "\n" + + "Schaden: " + entity.hurtResistance + "t" + (showPlayerInfo ? String.format(", Fallh.: %.3f", entity.fallDistance) : "") + "\n" + // + ", Luft: " + entity.getAir()); + (entity instanceof EntityLiving ? + (((EntityLiving)entity).deathTime != 0 ? "Tod: " + ((EntityLiving)entity).deathTime + "t, " : "") + "Rüstung: " + ((EntityLiving)entity).getTotalArmorValue() + ", Pfeile: " + ((EntityLiving)entity).getArrowCountInEntity() + : "Rüstung: n/a, Pfeile: n/a") + "\n" + +// ItemStack held = ((EntityLiving)entity).getHeldItem(); + (held != null ? + "Gegens.: " + ItemRegistry.REGISTRY.getNameForObject(held.getItem()) + " x" + held.stackSize + " (" + held.getMetadata() + ")" : "Gegens.: n/a") + "\n" + + "Eigens.: " + (entity.dead ? "D" : " ") + (entity.noClip ? "N" : " ") + (entity.onGround ? "G" : " ") + + (entity.canBeCollidedWith() ? "C" : " ") + (entity.canBePushed() ? "P" : " ") + + (entity.isBurning() ? "B" : " ") // + (entity.isInvisible() ? "I" : " ") // + (entity.isSilent() ? "S" : " ") + + (entity.canAttackWithItem() ? "A" : " ") + + (entity.passenger != null ? "H" : " ") + (entity.vehicle != null ? "R" : " ") + (entity instanceof EntityLiving ? + ("+" /* + (((EntityLivingBase)entity).isEntityUndead() ? "U" : " ") */ // + (((EntityLivingBase)entity).isChild() ? "C" : " ") + + (((EntityLiving)entity).doesEntityNotTriggerPressurePlate() ? "P" : " ")) : "") + "\n" + + // list.add("UUID: " + entity.getUniqueID().toString()); + (entity.hasCustomName() ? "Name: '" + TextColor.stripCodes(entity.getCustomNameTag()) + "'" : "Name: n/a") + ; + } + + return null; + } + + public boolean canRenderHud() { + return (this.showHud || this.open != null) && !this.cameraUsed; + } + + public boolean shift() { + return Bind.isWindowActive() && (Keysym.LEFT_SHIFT.read() || Keysym.RIGHT_SHIFT.read()); + } + + public boolean ctrl() { + return Bind.isWindowActive() && (Keysym.LEFT_CONTROL.read() || Keysym.RIGHT_CONTROL.read()); + } + + private void fbsize(int x, int y) { + GL11.glViewport(0, 0, x, y); + fb_x = x; + fb_y = y; + if(this.open != null) { + this.refreshing = true; + this.displayGuiScreen(this.open); + this.refreshing = false; + } + if(!fullscreen) { + xsize = x; + ysize = y; + } + } + + private void pos(int x, int y) { + if(!fullscreen) { + saved_xpos = x; + saved_ypos = y; + } + } + + private void mouse(int x, int y) { + if(!mouseFirst && open == null) + this.moveCamera((float)(x - mouse_x) * sensitivity, (float)(mouse_y - y) * sensitivity); + mouse_x = x; + mouse_y = y; + mouseFirst = false; + if(open != null && Bind.isInputEnabled() && Button.isMouseDown() /* && !(win->mouse & 0xfc) */ && !ctrl()) { +// if(mouse_clickx < 0 || mouse_clicky < 0) { +// return; +// } + +// SKC.drag(mouse_x, mouse_y); + open.drag(mouse_x, mouse_y); + } + } + + private void scroll(int x, int y) { + x *= -1; + if(open != null && Bind.isInputEnabled()) { +// if(y != 0) +// this.scroll(ExtMath.clampi(y, -1, 1)); + open.scroll(x, y, mouse_x, mouse_y, ctrl(), shift()); + } + else if(open != null) { + if((x != 0) || (y != 0)) + Bind.setBind((x < 0) ? Wheel.SCROLL_LEFT : ((x > 0) ? Wheel.SCROLL_RIGHT : ((y < 0) ? Wheel.SCROLL_DOWN : Wheel.SCROLL_UP)), false); + } + else if(Bind.isInputEnabled()) { + if(y != 0) + this.scroll(ExtMath.clampi(y, -1, 1)); + } + else { + if(x < 0) + Wheel.SCROLL_LEFT.setUsed(); + else if(x > 0) + Wheel.SCROLL_RIGHT.setUsed(); + if(y < 0) + Wheel.SCROLL_DOWN.setUsed(); + else if(y > 0) + Wheel.SCROLL_UP.setUsed(); + } + } + + private void button(Button btn, boolean press) { +// if(btn < 0 || btn >= 8) { +// return; +// } +// byte press = act == KEY_PRESS; + boolean prev = btn.isDown(); + if(open != null && prev != press && Bind.isInputEnabled() && !Button.isMouseDown()) { +// SKC.press(btn, mouse_x, mouse_y); + open.mouse(btn, mouse_x, mouse_y, ctrl(), shift()); + } + else if(open != null && press) { + Bind.setBind(btn, false); + } + btn.setDown(press); + if(open != null && prev != press && Bind.isInputEnabled() && !Button.isMouseDown()) { +// SKC.release(btn, mouse_x, mouse_y); + open.mouserel(btn, mouse_x, mouse_y); + } + } + + private void key(Keysym key, KeyEvent act) { + if((act == KeyEvent.PRESS) && Bind.isInputEnabled() && Bind.CHEAT.isDown() && this.handleDebugKey(key)) + return; + if(open != null && (act != KeyEvent.RELEASE) && Bind.isInputEnabled()) { + open.key(key, ctrl(), shift()); + } + else if(open != null && (act != KeyEvent.REPEAT)) { + Bind.setBind(key, act == KeyEvent.RELEASE); + } + } + + private void character(char code) { + if(open != null && Bind.isInputEnabled()) { + open.character(code); + } + } + + private void focus(boolean focus) { + Bind.setWindowActive(focus); + if(open != null) + open.mouse(Button.MOUSE_LEFT, -1, -1, false, false); +// open.restyle(); + } + + private void redraw() { + if(this.open != null) { + this.refreshing = true; + this.displayGuiScreen(this.open); + this.refreshing = false; + } + } + + private void closed() { + interrupted = true; + } + + public void poll() { + for(WindowEvent event : Window.poll()) { + switch(event.action) { + case BUTTON: + if(event.param1 >= 0 && event.param1 < Button.values().length) + button(Button.values()[event.param1], event.param2 != 0); + break; + case CHARACTER: + if(event.param1 >= (int)Log.CHR_SPC && event.param1 <= (int)Character.MAX_VALUE) + character((char)event.param1); + break; + case CLOSED: + closed(); + break; + case CURSOR: + mouse(event.param1, event.param2); + break; + case FOCUS: + focus(event.param1 != 0); + break; + case KEY: + if(event.param1 >= 0 && event.param1 < Keysym.values().length) + key(Keysym.values()[event.param1], KeyEvent.values()[event.param2 % KeyEvent.values().length]); + break; + case POSITION: + pos(event.param1, event.param2); + break; + case REDRAW: + redraw(); + break; + case RESIZE: + fbsize(event.param1, event.param2); + break; + case SCROLL: + if(event.param1 != 0 || event.param2 != 0) + scroll(event.param1, event.param2); + break; + } + } + } + + + + public void menu(boolean menu) { + Window.grabCursor(!menu && !nograb); + mouseFirst = true; + } + + public void full(boolean full) { + if((full != fullscreen || full) && (!full || vidMode != null)) { + if(full) { + Window.setFullscreen(vidMode.width, vidMode.height, vidMode.refresh); + } + else { + Window.setWindowed(saved_xpos, saved_ypos, xsize, ysize); + } + Window.setVSync(vsync); + fullscreen = full; + } + } + + public void sync(int sync) { + vsync = sync == 0; + syncLimited = sync > 0; + if(sync > 0) { + syncLimit = sync; + } + else { + DisplayMode mode = Window.getDisplayMode(); + syncLimit = mode != null ? mode.refresh : 60; + } + Window.setVSync(vsync); + } + + public void setupOverlay() { + GlState.disableDepth(); + GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlState.setActiveTexture(GL13.GL_TEXTURE0); + GlState.color(1.0f, 1.0f, 1.0f, 1.0f); + GL11.glClear(256); + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glLoadIdentity(); + GL11.glOrtho(0.0D, (double)this.fb_x, (double)this.fb_y, 0.0D, 1000.0D, 3000.0D); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glLoadIdentity(); + GL11.glTranslatef(0.0F, 0.0F, -2000.0F); + } + + private void addFrame(long runningTime) + { + this.frames[this.frameIndex] = runningTime; + ++this.frameIndex; + + if (this.frameIndex == 240) + { + this.frameIndex = 0; + } + + if (this.frameCounter < 240) + { + this.lastIndex = 0; + ++this.frameCounter; + } + else + { + this.lastIndex = (this.frameIndex + 1) % 240; + } + } + + private void updateTick() { + long n = System.nanoTime(); + if(n < this.frameLast + this.frameWait) + return; + this.frameWait = 50000000L - ((n - (this.frameLast + this.frameWait)) < 50000000L ? (n - (this.frameLast + this.frameWait)) : 0L); + this.frameLast = n; + this.tickTimes[this.tickIndex++] = this.lastTickTime; + if(this.tickIndex == 240) { + this.tickIndex = 0; + } + } + + public void run() { + Log.SYSTEM.info("Java " + System.getProperty("java.version")); + Log.SYSTEM.info(Config.CLIENT_VERSION); + if(!Window.createWindow(Config.CLIENT_VERSION, System.getProperty("opengl.debug") != null)) + System.exit(1); + Log.SYSTEM.info("OpenGL %s", GL11.glGetString(GL11.GL_VERSION)); + Log.SYSTEM.info("GL_VENDOR: %s", GL11.glGetString(GL11.GL_VENDOR)); + Log.SYSTEM.info("GL_RENDERER: %s", GL11.glGetString(GL11.GL_RENDERER)); + Log.SYSTEM.info("Starte ..."); + + this.init(); + this.registerDebug(); + System.gc(); + System.gc(); + Font.load(); + GlState.enableBlend(); + GlState.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + this.initConsole(); + this.startSound(true); + this.vidMode = Window.getDisplayMode(); + Window.initWindow(this.saved_xpos, this.saved_ypos, this.xsize, this.ysize); + Window.setIcon(genTriwave(64, 64, 0x00000000, 0xffff0000, 0xff00ff00, 0xff0000ff, 0xff7f00ff, 0xff000000), 64, 64); + this.sync(this.sync); +// this.startSound(true); + this.getVar("tic_target").setDefault(); + this.displayGuiScreen(GuiMenu.INSTANCE); + + while(!this.interrupted) { + PerfSection.swap(); + PerfSection.TIMING.enter(); + Timing.tmr_current = Util.rtime(); + Timing.tmr_delta = Timing.tmr_current - Timing.tmr_last; + Timing.tmr_last = Timing.tmr_current; + Timing.fdelta = ((float)Timing.tmr_delta) / 1000000.0f; + if((Timing.tmr_current - Timing.tmr_update) >= 1000000L) { + Timing.framerate = ((float)Timing.tmr_frames) * 1000000.0f / ((float)(long)(Timing.tmr_current - Timing.tmr_update)); + Timing.tmr_frames = 0L; + Timing.tmr_update = Timing.tmr_current; + } + this.start(); + PerfSection.INPUT.enter(); + Bind.updateBinds(); + this.input(); + Bind.enableInput(); + GlState.setActiveTexture(GL13.GL_TEXTURE0); + GlState.bindTexture(0); + this.inputGui(); + if(this.open != null) + this.open.update(); + PerfSection.TICK.enter(); + this.doTicks(); + PerfSection.UPDATE.enter(); + PerfSection.RENDER.enter(); + this.render(); + PerfSection.GUI.enter(); + if(this.canRenderHud()) + this.renderHud(); + PerfSection.REST.enter(); + this.finish(); + PerfSection.SWAP.enter(); + if(this.glFlush) + GL11.glFlush(); + Window.swapBuffers(); + PerfSection.EVENTS.enter(); + Log.flushLog(); + this.poll(); + PerfSection.WAIT.enter(); + long now = System.nanoTime(); + this.addFrame(now - this.startNanoTime); + this.startNanoTime = now; + while(this.syncLimited && (Util.rtime() - Timing.tmr_current) < (1000000L / this.syncLimit)) { + ; + } + Timing.tmr_frames += 1L; + } + + Log.SYSTEM.info("Beende ..."); + unload(false); + this.getSoundManager().unload(); + this.renderGlobal.stopChunkBuilders(); + if(audio.end()) + Log.SOUND.info("Audiogerät geschlossen"); + Log.flushLog(); + this.save(); + Font.unload(); + Window.destroyWindow(); + Log.SYSTEM.info("Beendet."); + } + + + +// public void complete(String[] comp) { +// +// } +// public void infolist(String[] list, int[] data) { +// +// } + + public void disconnected(String msg) { + Log.SYSTEM.info("Getrennt: %s", msg); + this.unload(true); + this.displayGuiScreen(new GuiInfo("Von Server getrennt", TextColor.RED + "Verbindung zum Server wurde getrennt\n\n" + TextColor.RESET + msg)); + } + + + + private void input() { + if(!this.saving && Bind.SCREENSHOT.isPressed()) { + this.screenshot = true; + } + if(Bind.isWindowActive()) { + if(Bind.FULLSCREEN.isPressed()) { + this.full(!this.fullscreen); + } + if(!(this.open instanceof GuiLoading)) { + if(!(this.open instanceof GuiConsole) && Bind.CONSOLE.isPressed()) { + this.displayGuiScreen(GuiConsole.INSTANCE.setFull(true)); + } + else if(this.open == null && Bind.COMMAND.isPressed()) { + this.displayGuiScreen(GuiConsole.INSTANCE.setFull(false)); + } + // if(this.theWorld != null && this.open == null && Bind.COMMAND.isPressed()) { + // this.displayGuiScreen(GuiChat.INSTANCE); + // } + if(this.world != null && Bind.MENU.isPressed()) { + if(this.open != (this.charEditor ? GuiChar.INSTANCE : null)) + this.displayGuiScreen(this.charEditor ? GuiChar.INSTANCE : null); + else + this.displayGuiScreen(GuiMenu.INSTANCE); + } + else if(this.world == null && !(this.open instanceof GuiMenu) && Bind.MENU.isPressed()) { + this.displayGuiScreen(GuiMenu.INSTANCE); + } + if(this.world != null && !this.charEditor && Bind.INVENTORY.isPressed()) { + if(this.open instanceof GuiContainer) { + this.displayGuiScreen(null); + } + else if(this.open == null) { + if(this.player.isRiding() && this.player.vehicle instanceof EntityHorse) + this.player.sendHorseInventory(); + else + this.displayGuiScreen(/* this.itemCheat ? new GuiCheat() : */ new GuiInventory(this.player)); + } + } + } + if(Bind.SHOW.isPressed()) { + if(this.drawDebug) { + this.drawDebug = this.drawFps = false; + } + else { + this.drawDebug = this.drawFps; + this.drawFps = true; + } + } + } + } + + private void screenshot() { + if(this.saving) + return; + this.saving = true; + final int stride = ((this.fb_x * 3) & 3) != 0 ? 4 + ((this.fb_x * 3) & ~3) : (this.fb_x * 3); + final ByteBuffer data = ByteBuffer.allocateDirect(stride * this.fb_y).order(ByteOrder.nativeOrder()); + GL11.glReadPixels(0, 0, this.fb_x, this.fb_y, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, data); + new Thread(new Runnable() { + public void run() { + byte[] pixels = new byte[stride * Client.this.fb_y]; + data.get(pixels); + byte[] conv = new byte[Client.this.fb_x * Client.this.fb_y * 3]; + for(int l = 0; l < Client.this.fb_y; l++) { + System.arraycopy(pixels, l * stride, conv, (Client.this.fb_y - 1 - l) * Client.this.fb_x * 3, Client.this.fb_x * 3); + } + BufferedImage image = new BufferedImage(Client.this.fb_x, Client.this.fb_y, BufferedImage.TYPE_INT_ARGB); + int[] img = new int[Client.this.fb_x * Client.this.fb_y]; + for(int z = 0; z < img.length; z++) { + img[z] = (int)(conv[(z * 3) + 2] & 0xff) | ((int)(conv[(z * 3) + 1] & 0xff) << 8) | ((int)(conv[(z * 3) + 0] & 0xff) << 16) | 0xff000000; + } + image.setRGB(0, 0, Client.this.fb_x, Client.this.fb_y, img, 0, Client.this.fb_x); + + File dir = new File("screenshots"); + dir.mkdirs(); + int n = 0; + File file; + Date date = new Date(); + do { + file = new File(dir, "screen_" + new SimpleDateFormat("dd-MM-yyyy_HH-mm-ss").format(date) + (n != 0 ? "_" + n : "") + ".png"); + n++; + } + while(file.exists()); + final File saved = file; + try { + ImageIO.write(image, "png", file); + } + catch(IOException e) { + Client.this.schedule(new Runnable() { + public void run() { + Client.this.saving = false; + Log.IO.error(e, "Konnte Textur '" + saved + "' nicht speichern"); + } + }); + return; + } + Client.this.schedule(new Runnable() { + public void run() { + Client.this.saving = false; + Client.this.logFeed("Bildschirmfoto als '%s' gespeichert", saved.getName()); + } + }); + } + }, "Screenshot writer").start(); + } + + public TextColor framecode() { + return (Timing.framerate >= 59.0f) ? TextColor.GREEN : ((Timing.framerate >= 29.0f) ? TextColor.YELLOW : ((Timing.framerate >= 14.0f) ? TextColor.ORANGE : TextColor.RED)); + } + + public TextColor tpscode() { + return (Timing.tickrate >= (((float)Timing.tickTarget / 1000.0f) - 1.0f)) ? TextColor.GREEN : ((Timing.tickrate >= (((float)Timing.tickTarget / 1000.0f) / 2.0f - 1.0f)) ? TextColor.YELLOW : + ((Timing.tickrate >= (((float)Timing.tickTarget / 1000.0f) / 4.0f - 1.0f)) ? TextColor.ORANGE : TextColor.RED)); + } + + private void doTicks() { + Timing.tick_stime = Util.rtime(); + if((Timing.tick_stime - Timing.tick_update) >= 1000000L) { + Timing.tickrate = ((float)Timing.tick_done) * 1000000.0f / ((float)(long)(Timing.tick_stime - Timing.tick_update)); + Timing.tick_done = 0; + Timing.tick_update = Timing.tick_stime; + } + Timing.tick_torun += (((long)Timing.tickTarget) * Timing.tmr_delta) / 1000L; + Timing.tickFrame = 0; + Timing.tick_torun = Timing.tick_torun > 2000000L ? 1000000L : Timing.tick_torun; + while(Timing.tick_torun >= 1000000L) { + this.tick(); + Timing.tick_done += 1L; + Timing.tickFrame += 1; + Timing.tick_total += 1L; + Timing.tick_torun -= 1000000L; + if((Timing.tick_ftime = (Util.rtime() - Timing.tick_stime)) >= (((long)this.tickTimeout) * 1000L)) { + Log.TICK.warn("Ticks benötigten %d ms dieses Frame (maximal %d ms), überspringe %d Ticks", Timing.tick_ftime / 1000L, this.tickTimeout, Timing.tick_torun / 1000000L); + Timing.tick_torun = 0L; + break; + } + } + Timing.tick_fraction = ((double)Timing.tick_torun) / 1000000.0; + Timing.tick_ttime += Timing.tick_ftime; + Timing.tick_time = Timing.tickFrame != 0 ? (Timing.tick_ftime / (long)Timing.tickFrame) : 0L; + } + + public void tick_target(float tps) { + Timing.tickTarget = (int)(tps * 1000.0f); + Timing.tick_torun = 0L; + Timing.tick_done = 0L; + Timing.tick_update = Util.rtime(); + } + + public void unload(boolean loading) { + if(this.world != null && this.getNetHandler() != null) + this.getNetHandler().getNetworkManager().closeChannel("Quitting"); + this.unloadWorld(); + this.displayGuiScreen(GuiMenu.INSTANCE); + } + + private void startSound(boolean load) { + if(load) + SoundManager.loadSounds(); + audio = new AudioInterface(this.soundFrameSize, this.soundBufferSize, !this.soundEnabled); + boolean started = audio.start(); + Log.flushLog(); + if(started) + Log.SOUND.info("Audiogerät geöffnet"); + else if(this.soundEnabled) + Log.SOUND.info("Audiogerät konnte nicht geöffnet werden"); + for(Volume volume : Volume.values()) { + volume.apply(); + } + } + + public void restartSound(boolean load) { + Client.this.logFeed("Lade Sound-System neu"); + this.soundManager.unload(); + if(audio.end()) + Log.SOUND.info("Audiogerät geschlossen"); + this.startSound(load); + Client.this.logFeed("Das Sound-System wurde neu geladen"); + } + + public AudioInterface getAudioInterface() { + return audio; + } + + public void distance(int distance) { + if(this.renderGlobal != null) + this.renderGlobal.setDisplayListEntitiesDirty(); + } + + private void registerDebug(Keysym key, String help, DebugRunner runner) { + if(this.debug.containsKey(key)) + throw new IllegalStateException("Debug-Taste " + key.getDisplay() + " ist bereits registriert"); + this.debug.put(key, new DebugFunction(key, runner, help)); + } + + private void registerDebug() { + this.registerDebug(Keysym.H, "Hilfe zu Tastenkombinationen anzeigen", new DebugRunner() { + public void execute(Keysym key) { + String bind = Bind.CHEAT.getInput() == null ? "n/a" : Bind.CHEAT.getInput().getDisplay(); + Client.this.displayGuiScreen(new GuiInfo("Hilfe zu Tastenkombinationen", TextColor.DGREEN + "" + Client.this.debug.size() + " Tastenkombinationen stehen zur Verfügung:\n" + + Util.buildLines(new Function() { + public String apply(DebugFunction func) { + return TextColor.CYAN + bind + TextColor.RED + "+" + TextColor.GREEN + func.key.getDisplay() + TextColor.GRAY + " - " + TextColor.YELLOW + func.help; + } + }, Client.this.debug.values()))); + } + }); + this.registerDebug(Keysym.N, "NoClip umschalten", new DebugRunner() { + public void execute(Keysym key) { + Client.this.performAction(Action.NOCLIP); + } + }); + this.registerDebug(Keysym.G, "Unsterblichkeit umschalten", new DebugRunner() { + public void execute(Keysym key) { + Client.this.performAction(Action.GOD); + } + }); + this.registerDebug(Keysym.F, "Geschwindigkeit umschalten", new DebugRunner() { + public void execute(Keysym key) { + Client.this.performAction(Action.SPEED); + } + }); + this.registerDebug(Keysym.R, "Gegenstand reparieren und Stapel auffüllen", new DebugRunner() { + public void execute(Keysym key) { + Client.this.performAction(Action.REPAIR); + } + }); + this.registerDebug(Keysym.E, "Gegenstands-Cheat-Menü umschalten", new DebugRunner() { + public void execute(Keysym key) { + Client.this.logFeed("Cheat-Menü: %s", (Client.this.itemCheat ^= true) ? "an" : "aus"); + if(Client.this.open instanceof GuiContainer) + Client.this.open.init(); + } + }); + this.registerDebug(Keysym.L, "Maximale Helligkeit umschalten", new DebugRunner() { + public void execute(Keysym key) { + Client.this.logFeed("Maximale Helligkeit: %s", (Client.this.setGamma ^= true) ? "an" : "aus"); + } + }); + this.registerDebug(Keysym.J, "JVM GC ausführen", new DebugRunner() { + public void execute(Keysym key) { + Client.this.logFeed("Führe JVM GC aus"); + long mem = Runtime.getRuntime().freeMemory(); + System.gc(); + System.gc(); + mem = Runtime.getRuntime().freeMemory() - mem; + mem = mem < 0L ? 0L : mem; + Client.this.logFeed("JVM GC ausgeführt: %d MB freigegeben", (int)(mem / 1024L / 1024L)); + } + }); + this.registerDebug(Keysym.B, "Hitbox-Overlay umschalten", new DebugRunner() { + public void execute(Keysym key) { + Client.this.getRenderManager().setDebugBoundingBox(!Client.this.getRenderManager().isDebugBoundingBox()); + Client.this.logFeed("Objekt-Grenzen: %s", Client.this.getRenderManager().isDebugBoundingBox() ? "an" : "aus"); + } + }); + this.registerDebug(Keysym.K, "Debug-Kamera in 3. Person umschalten", new DebugRunner() { + public void execute(Keysym key) { + Client.this.logFeed("Debug-Kamera 3. Person: %s", (Client.this.debugCamEnable ^= true) ? "an" : "aus"); + } + }); + this.registerDebug(Keysym.X, "Röntgenblick umschalten", new DebugRunner() { + public void execute(Keysym key) { + Client.this.xrayActive ^= true; + Client.this.renderGlobal.loadRenderers(); + Client.this.logFeed("Röntgenblick: %s", Client.this.xrayActive ? "an" : "aus"); + } + }); + this.registerDebug(Keysym.O, "Objekt-Overlay umschalten", new DebugRunner() { + public void execute(Keysym key) { + Client.this.logFeed("Objekt-Umrahmung: %s", (Client.this.renderOutlines ^= true) ? "an" : "aus"); + } + }); + this.registerDebug(Keysym.I, "Block-Objekt-Overlay umschalten", new DebugRunner() { + public void execute(Keysym key) { + Client.this.logFeed("Block-Objekte anzeigen: %s", (Client.this.tileOverlay ^= true) ? "an" : "aus"); + } + }); + this.registerDebug(Keysym.Y, "Alle Chunks neu kompilieren", new DebugRunner() { + public void execute(Keysym key) { + Client.this.logFeed("Kompiliere alle Chunks neu"); + Client.this.renderGlobal.loadRenderers(); + Client.this.logFeed("Alle Chunks wurden neu kompiliert"); + } + }); + this.registerDebug(Keysym.T, "Alle Texturen neu laden", new DebugRunner() { + public void execute(Keysym key) { + Client.this.logFeed("Lade Texturen neu"); + Client.this.refreshResources(); + Client.this.logFeed("Texturen wurden neu geladen"); + } + }); + this.registerDebug(Keysym.S, "Alle Sounds neu laden", new DebugRunner() { + public void execute(Keysym key) { + Client.this.logFeed("Lade Sounds neu"); + Client.this.restartSound(true); + Client.this.logFeed("Sounds wurden neu geladen"); + } + }); + this.registerDebug(Keysym.W, "Server-Tick-Limit umschalten (Welt beschleunigen / Warpmodus)", new DebugRunner() { + public void execute(Keysym key) { + Client.this.performAction(Action.WARP_MODE); + } + }); + this.registerDebug(Keysym.M, "Alle Gegenstände herbei ziehen (Magnetmodus)", new DebugRunner() { + public void execute(Keysym key) { + Client.this.performAction(Action.MAGNET); + } + }); + this.registerDebug(Keysym.Z, "Den Spieler heilen", new DebugRunner() { + public void execute(Keysym key) { + Client.this.performAction(Action.HEAL); + } + }); + this.registerDebug(Keysym.P, "Server Performance-Anfrage senden", new DebugRunner() { + public void execute(Keysym key) { + Client.this.performAction(Action.PERF); + } + }); + this.registerDebug(Keysym.C, "Debug-Crash auslösen (2x schnell hintereinander)", new DebugRunner() { + long lastUsed; + + public void execute(Keysym key) { + if(System.currentTimeMillis() - this.lastUsed <= 1000L) { + throw new RuntimeException("Manuell herbeigerufener Debugging-Absturz"); + } + else { + this.lastUsed = System.currentTimeMillis(); + Client.this.logFeed(TextColor.RED + "VORSICHT: Debug-Absturz nach mehrmaligem Drücken innerhalb einer Sekunde"); + } + } + }); + this.registerDebug(Keysym.V, "Alle Sounds stoppen", new DebugRunner() { + public void execute(Keysym key) { + Client.this.soundManager.stopSounds(); + } + }); + this.registerDebug(Keysym.Q, "Programm sofort beenden und speichern", new DebugRunner() { + public void execute(Keysym key) { + Client.this.interrupted = true; + } + }); + this.registerDebug(Keysym.A, "Bild-Synchonisation umschalten (VSync - begrenzt - unbegrenzt)", new DebugRunner() { + public void execute(Keysym key) { + Client.this.getVar("win_sync").parse("" + (Client.this.vsync ? Client.this.syncLimit : (Client.this.syncLimited ? -1 : 0))); + Client.this.setDirty(); + } + }); + this.registerDebug(Keysym.D, "Konsole und Chat leeren", new DebugRunner() { + public void execute(Keysym key) { + GuiConsole.INSTANCE.reset(); + if(Client.this.open instanceof GuiConsole) + ((GuiConsole)Client.this.open).setLog(Client.this.buffer); + } + }); + this.registerDebug(Keysym.U, "HUD umschalten", new DebugRunner() { + public void execute(Keysym key) { + Client.this.showHud ^= true; + } + }); + this.registerDebug(Keysym.UE, "Spieler in Overlay umschalten", new DebugRunner() { + public void execute(Keysym key) { + Client.this.logFeed("Spieler-Info in Overlay: %s", (Client.this.debugPlayer ^= true) ? "an" : "aus"); + } + }); + this.registerDebug(Keysym.OE, "Tick-Profiler umschalten", new DebugRunner() { + public void execute(Keysym key) { + if(Client.this.lastTickTime >= 0) { + Client.this.performAction(Action.STOP_PROFILING); + Client.this.lastTickTime = -1; + Client.this.tickInfo = null; + } + else { + Client.this.performAction(Action.START_PROFILING); + Client.this.lastTickTime = 0; + } + } + }); + } + + private boolean handleDebugKey(Keysym key) { + DebugFunction func = this.debug.get(key); + if(func != null) { + Bind.disableInput(key); + if(!(this.open instanceof GuiLoading)) { + this.soundManager.playSound(new PositionedSound(SoundEvent.CLICK, EventType.UI_INTERFACE)); + func.runner.execute(key); + } + } + return func != null; + } + + + + public static void main(String[] args) { + Util.checkOs(); + Log.init(CLIENT); + Window.init(); + ModelBlock.setAsProvider(); + Registry.setup("Render thread"); + UniverseRegistry.register(); + CLIENT.run(); + Window.end(); + } + + + + private static float tri(float x, float p, float a) { + return ((4.0f * a) / p) * ExtMath.absf(((x - p / 4.0f) % p) - p / 2.0f) - a; + } + + private static void memcpy(byte[] dest, int doff, byte[] src, int soff, int len) { + System.arraycopy(src, soff, dest, doff, len); + } + + private static byte[] genTriwave(int w, int h, int color1, int color2, int color3, int color4, int color5, int color6) { + byte[] data = new byte[w * h * 4]; + byte[] color = new byte[24]; + color1 = (color1 << 8) | (color1 >> 24); + color2 = (color2 << 8) | (color2 >> 24); + color3 = (color3 << 8) | (color3 >> 24); + color4 = (color4 << 8) | (color4 >> 24); + color5 = (color5 << 8) | (color5 >> 24); + color6 = (color6 << 8) | (color6 >> 24); + for(int z = 0; z < 4; z++) { + color[z] = (byte)((color1 >> ((3 - z) * 8)) & 0xff); + color[z+4] = (byte)((color2 >> ((3 - z) * 8)) & 0xff); + color[z+8] = (byte)((color3 >> ((3 - z) * 8)) & 0xff); + color[z+12] = (byte)((color4 >> ((3 - z) * 8)) & 0xff); + color[z+16] = (byte)((color5 >> ((3 - z) * 8)) & 0xff); + color[z+20] = (byte)((color6 >> ((3 - z) * 8)) & 0xff); + } + for(int y = 0; y < h; y++) { + int offs = ((y / 2 == h / 16) || (y / 2 == (h / 2 - h / 16) - 1)) ? 16 : (((y / 2 == h / 16 + 1) || (y / 2 == (h / 2 - h / 16) - 2)) ? 20 : 0); + for(int x = 0; x < w; x++) { + memcpy(data, (y*w+x) << 2, color, offs, 4); + } + } + for(int x = 0; x < w; x++) { + int y = ((x < w / 8) || (x >= w - w / 8)) ? (h / 2) : (h / 2 + (int)tri((float)(w / 4 + x), (float)((w * 3) / 4), (float)(((h * 3) / 4) / 2))); + // sys_assert(y - 8 >= 0 && y + 7 < h) + memcpy(data, ((y-8)*w+x) << 2, color, 0, 4); + memcpy(data, ((y-7)*w+x) << 2, color, 0, 4); + memcpy(data, ((y-6)*w+x) << 2, color, 0, 4); + memcpy(data, ((y-5)*w+x) << 2, color, 4, 4); + memcpy(data, ((y-4)*w+x) << 2, color, 4, 4); + memcpy(data, ((y-3)*w+x) << 2, color, 0, 4); + memcpy(data, ((y-2)*w+x) << 2, color, 0, 4); + memcpy(data, ((y-1)*w+x) << 2, color, 8, 4); + memcpy(data, ((y+0)*w+x) << 2, color, 8, 4); + memcpy(data, ((y+1)*w+x) << 2, color, 0, 4); + memcpy(data, ((y+2)*w+x) << 2, color, 0, 4); + memcpy(data, ((y+3)*w+x) << 2, color, 12, 4); + memcpy(data, ((y+4)*w+x) << 2, color, 12, 4); + memcpy(data, ((y+5)*w+x) << 2, color, 0, 4); + memcpy(data, ((y+6)*w+x) << 2, color, 0, 4); + memcpy(data, ((y+7)*w+x) << 2, color, 0, 4); + } + return data; + } + + // plr_play("/home/sen/Musik/midi50k/Video_Games/ff/ff2cecil.mid", 0); + public static void meltdown() { + Random rand = new Random(); + Log.SYSTEM.error("CORE_MELTDOWN: Nuclear processor core meltdown imminent\n\n" + + " ************************ CAUTION ************************\n" + + " KCTL: Processor core #%02d has reached a critical\n" + + " temperature, system explosion is imminent! \n" + + " According to the general core density \n" + + " calculation routine defined by the SKC \n" + + " (Hard) Warfare Testing Facility (SKC-WTF) \n" + + " your processor will cause a detonation with \n" + + " a radius of (roughly) %d.%d kilometers. \n" + + " In addition, it will release appoximately \n" + + " %d megajoules of ionizing radiation. \n" + + " You have an estimate time of %d minutes and \n" + + " %d seconds left to clear the detonation area. \n" + + " ************************ CAUTION ************************\n" + , rand.range(1, 64), rand.range(1, 9), rand.range(0, 9), rand.range(10000, 39999), rand.range(3, 9), rand.range(2, 59)); + } + + public T getVar(String name) { + return (T)cvars.get(name); + } + + public Iterable getVars() { + return this.cvars.keySet(); + } + + public void setDirty() { + cfgDirty = true; + } + + public boolean isDirty() { + return cfgDirty; + } + + public String getBuffer() { + return buffer; + } + + private void regVar(CVar cv) { + if(cvars.containsKey(cv.getCVarName())) + throw new IllegalArgumentException("Variable " + cv.getCVarName() + " existiert bereits!"); + cvars.put(cv.getCVarName(), cv); + } + + private void regVars(Class clazz, Object object) { + for(Field field : clazz.getDeclaredFields()) { + if(field.isAnnotationPresent(Variable.class)) { + if(Modifier.isStatic(field.getModifiers()) != (object == null)) + continue; + if(Modifier.isFinal(field.getModifiers())) + throw new IllegalArgumentException("Feld für Variable " + field + " muss änderbar sein!"); + Variable value = field.getAnnotation(Variable.class); + if(value.name().isEmpty()) + throw new IllegalArgumentException("Variablenname von " + field + " kann nicht leer sein!"); + field.setAccessible(true); + CVar cv; + VarFunction func = null; + if(value.callback() != VarFunction.class) { + try { + func = value.callback().getConstructor().newInstance(); + } + catch(InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException + | NoSuchMethodException e) { + throw new RuntimeException(e); + } + } + CharValidator validator = null; + if(value.validator() != CharValidator.class) { + try { + validator = value.validator().getConstructor().newInstance(); + } + catch(InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException + | NoSuchMethodException e) { + throw new RuntimeException(e); + } + } + if(field.getType() == int.class) + cv = value.type() != IntType.INT ? new ColorVar(value.name(), value.display(), field, object, value.category(), value.type() == IntType.ALPHA, (IntFunction)func) : + new IntVar(value.name(), value.display(), field, object, value.category(), (int)value.min(), (int)value.max(), (IntFunction)func, value.unit(), value.precision()); + else if(field.getType() == float.class) + cv = new FloatVar(value.name(), value.display(), field, object, value.category(), value.min(), value.max(), (FloatFunction)func, value.unit(), value.precision()); + else if(field.getType() == boolean.class) + cv = new BoolVar(value.name(), value.display(), field, object, value.category(), (BoolFunction)func); + else if(field.getType() == String.class) + cv = new StringVar(value.name(), value.display(), field, object, value.category(), (int)value.max(), (StringFunction)func, validator, (int)value.min() <= 0); + else if(field.getType().isEnum()) + cv = new EnumVar(value.name(), value.display(), field, object, value.category(), (EnumFunction)func, value.switched()); + else + throw new IllegalArgumentException(value.name() + ": Unbekannter Variablen-Typ - " + field.getType()); + regVar(cv); + } + } + } + + private void regVars(Object object) { + regVars(object.getClass(), object); + } + + private void regVars(Class clazz) { + regVars(clazz, null); + } + + public void initConsole() { + reset(); + for(Bind bind : Bind.values()) { + regVar(bind); + } + for(Volume volume : Volume.values()) { + regVar(volume); + } + regVars(this); + regVars(Style.CUSTOM); + regVars(GuiServer.INSTANCE); + regVars(GuiChar.INSTANCE); + + if(!config.exists()) + return; + String data; + try { + data = FileUtils.read(config); + } + catch(IOException e) { + Log.CONSOLE.error(e, "Konnte Konfigurationsdatei nicht laden"); + return; + } + if(data == null) + return; + for(String line : data.split("\n")) { // new String(data, CharsetUtil.UTF_8).split("\n") + if(line.startsWith("#")) + continue; + String[] tok = line.split("=", 2); + if(tok.length != 2) + continue; + CVar cv = getVar(tok[0]); + if(cv == null) { + Log.CONSOLE.error("CVAR '%s' existiert nicht", tok[0]); + continue; + } + if(cv.parse(tok[1])) { + Log.CONSOLE.trace("%s = %s", cv.getCVarName(), cv.format()); + } + else { + Log.CONSOLE.error("Kann CVAR '%s' nicht auf '%s' setzen", cv.getCVarName(), tok[1]); + } + } + } + + public void save() { + cfgDirty = false; + StringBuilder sb = new StringBuilder(); + for(CVar cv : cvars.values()) { + if(sb.length() > 0) + sb.append('\n'); + sb.append(cv.getCVarName() + "=" + cv.format()); + } + try { + FileUtils.write(config, sb.toString()); + } + catch(IOException e) { + Log.CONSOLE.error(e, "Konnte Konfigurationsdatei nicht speichern"); + } + } + + private void printVar(CVar cv) { + String values = cv.getValues(); + this.logConsole("%s " + TextColor.NEON + "%s " + TextColor.DGRAY + "[%s" + TextColor.DGRAY + "]" + TextColor.GRAY + " = " + TextColor.WHITE + "%s " + TextColor.DGRAY + + "[" + TextColor.GRAY + "D " + TextColor.CRIMSON + "%s" + TextColor.DGRAY + "]%s", cv.getType(), cv.getCVarName(), cv.getCategory(), cv.format(), cv.getDefault(), + values != null ? " [" + TextColor.LGRAY + values + TextColor.DGRAY + "]" : ""); + } + + public void exec(String line) { + if(line.equals("#")) { + for(CVar cv : cvars.values()) { + printVar(cv); + } + this.logConsole(TextColor.GREEN + "CVARs insgesamt registriert: %d", cvars.size()); +// this.command(line); + return; + } + else if(line.startsWith("#")) { + String tok = line.substring(1); + int space = tok.indexOf(' '); + CVar cv = getVar(space >= 0 ? tok.substring(0, space) : tok); + if(cv != null) { + if(space < 0 || space >= tok.trim().length()) { + this.logConsole("%s = %s", cv.getCVarName(), cv.format()); + return; + } + String value = tok.substring(space + 1).trim(); + if(cv.parse(value)) { + cfgDirty = true; + this.logConsole("%s -> %s", cv.getCVarName(), cv.format()); + } + else { + this.logConsole(TextColor.RED + "Kann CVAR '%s' nicht auf '%s' setzen", cv.getCVarName(), value); + } + return; + } + } + if(this.player != null && this.getNetHandler() != null) + this.getNetHandler().addToSendQueue(new CPacketMessage(line.startsWith("/") ? CPacketMessage.Type.COMMAND : CPacketMessage.Type.CHAT, line.startsWith("/") ? line.substring(1) : line)); +// Log.CONSOLE.user("%s", line); +// this.command(line); + } + + public void reset() { + this.buffer = TextColor.NEON + "*** " + Config.CLIENT_VERSION + " ***"; + this.console.clear(); + this.chat.clear(); + this.feed.clear(); + this.hotbar.clear(); + } + + private void resize(List log, int size) { + while(log.size() > size) { + log.remove(log.size() - 1); + } + } + + public void resizeConsole() { + this.resize(this.console, this.consoleSize); + } + + public void resizeChat() { + this.resize(this.chat, this.chatSize); + } + + public void resizeFeed() { + this.resize(this.feed, this.feedSize); + } + + public void resizeHotbar() { + this.resize(this.hotbar, this.hotbarSize); + } + + public void log(String prefixed, String line) { + String msg = this.conTimestamps ? prefixed : line; +// this.addMessage(msg); + if((buffer.length() + msg.length() + 1) > LOG_BUFFER) { + int offset = (msg.length() + 1) > 1024 ? (msg.length() + 1) : 1024; + int nl = buffer.indexOf('\n', offset); + buffer = nl >= 0 ? buffer.substring(nl + 1) : ""; + } + buffer = buffer + "\n" + msg; + if(this.open instanceof GuiConsole) { + ((GuiConsole)this.open).setLog(buffer); + } + } + + private void addMessage(List log, int size, String msg) { + Log.CONSOLE.user(msg); + if(size > 0) { + for(String line : msg.split("\n")) { + Message lmsg = new Message(line, Timing.tmr_current); + while(log.size() >= size) { + log.remove(log.size() - 1); + } + log.add(0, lmsg); + } + } + } + + public void logConsole(String line) { + this.addMessage(this.console, this.consoleSize, line); + } + + public void logConsole(String fmt, Object ... args) { + this.logConsole(String.format(fmt, args)); + } + + public void logChat(String line) { + this.addMessage(this.chat, this.chatSize, line); + } + + public void logChat(String fmt, Object ... args) { + this.logChat(String.format(fmt, args)); + } + + public void logFeed(String line) { + this.addMessage(this.feed, this.feedSize, line); + } + + public void logFeed(String fmt, Object ... args) { + this.logFeed(String.format(fmt, args)); + } + + public void logHotbar(String line) { + this.addMessage(this.hotbar, this.hotbarSize, line); + } + + public void logHotbar(String fmt, Object ... args) { + this.logHotbar(String.format(fmt, args)); + } + + private void drawOverlay(List log, int size, boolean up, int align, int x, int y) { + if(size > 0) { + long fade = 1000000L * (long)this.hudFadeout; + int bg = (this.hudOpacity << 24) | 0x000000; + y = up ? y - Font.YGLYPH : y; + for(Iterator iter = log.iterator(); iter.hasNext();) { + Message msg = iter.next(); + if((Timing.tmr_current - msg.time) <= fade || (log == this.chat && this.chatPermanent)) { + if(align > 0) + Drawing.drawTextbox(msg.message, x, y, bg); + else if(align < 0) + Drawing.drawTextboxRight(msg.message, x, y, bg); + else + Drawing.drawTextboxCentered(msg.message, x, y, bg); + y += up ? -(Font.YGLYPH) : Font.YGLYPH; + } + else { + iter.remove(); + } + } + } + else { + log.clear(); + } + } + + private static String formatPing(int ping) { + TextColor base; + if(ping < 0) { + base = TextColor.GRAY; + } + else if(ping < 80) { + base = TextColor.DGREEN; + } + else if(ping < 160) { + base = TextColor.GREEN; + } + else if(ping < 350) { + base = TextColor.YELLOW; + } + else if(ping < 700) { + base = TextColor.RED; + } + else { + base = TextColor.DRED; + } + return base + (ping < 10000 ? String.format("%d", ping) + "ms" : String.format("%.1f", ((float)ping) / 1000.0f) + "s"); + } + +/* + private void drawPing(int width, int xPos, int yPos, int ping) { + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + this.gm.getTextureManager().bindTexture(icons); + int rectX = 0; + int rectWidth = 0; + if(ping < 0 || ping >= 20000) { + rectWidth = 5; + } + else if(ping < 150) { + rectWidth = 0; + } + else if(ping < 300) { + rectWidth = 1; + } + else if(ping < 600) { + rectWidth = 2; + } + else if(ping < 1000) { + rectWidth = 3; + } + else { + rectWidth = 4; + } + + String str = this.formatPing(ping); + + this.zLevel += 100.0F; + this.drawTexturedModalRect(xPos + width - 11, yPos, 0 + rectX * 10, 176 + rectWidth * 8, 10, 8); + SKC.drawString(str, xPos + width - (11 + 1 + SKC.getStringWidth(str)), yPos, -1); + this.zLevel -= 100.0F; + } +*/ + + public void drawInfo() { + ClientPlayer netHandler = this.getNetHandler(); + if(netHandler != null) { + Set> list = netHandler.getPlayerList(); + int size = list.size(); + int w = size > 80 ? 4 : (size > 40 ? 3 : (size > 10 ? 2 : 1)); + w = Math.min(w, Math.max(1, this.fb_x / 300)); + int bx = 0; + int by = 0; + for(Entry elem : list) { + int x = this.fb_x / 2 - (w * 300) / 2 + bx * 300; + int y = 10 + by * Font.YGLYPH; + Drawing.drawGradient(x, y, 300, Font.YGLYPH, 0x7f404040, 0x7f000000); + Drawing.drawText(elem.getKey(), x + 4, y, 0xffffffff); + Drawing.drawTextRight(formatPing(elem.getValue()), x + 300 - 4, y, 0xffffffff); + if(++bx >= w) { + bx = 0; + ++by; + } + } + } + } + + private void renderWorldDirections(float partialTicks) { + GlState.enableBlend(); + GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); + GL11.glLineWidth(1.0F); + GlState.disableTexture2D(); + GlState.depthMask(false); +// GlState.color(1.0f, 1.0f, 1.0f, 1.0f); + GL11.glPushMatrix(); +// WCF.glMatrixMode(5888); +// WCF.glLoadIdentity(); + GL11.glTranslatef((float)(this.fb_x / 2), (float)(this.fb_y / 2), 0.0F); + this.entityRenderer.rotateCamera(this.viewEntity, partialTicks); +// WCF.glScalef(-1.0f, -1.0f, -1.0f); +// Drawing.drawRectColor(0, 0, 10, 2, 0xff00ff00); + RenderGlobal.drawOutlinedBoundingBox(new BoundingBox(0.0D, 0.0D, 0.0D, 24D, 1D, 1D), 255, 0, 0, 255); + RenderGlobal.drawOutlinedBoundingBox(new BoundingBox(0.0D, 0.0D, 0.0D, 1D, 1D, 24D), 0, 0, 255, 255); + RenderGlobal.drawOutlinedBoundingBox(new BoundingBox(0.0D, 0.0D, 0.0D, 1D, -20D, 1D), 0, 255, 0, 255); + GL11.glPopMatrix(); + GlState.depthMask(true); + GlState.enableTexture2D(); + GlState.disableBlend(); + } + + private int blendColors(int color1, int color2, float value) { + int i = color1 >> 24 & 255; + int j = color1 >> 16 & 255; + int k = color1 >> 8 & 255; + int l = color1 & 255; + int i1 = color2 >> 24 & 255; + int j1 = color2 >> 16 & 255; + int k1 = color2 >> 8 & 255; + int l1 = color2 & 255; + int i2 = ExtMath.clampi((int)((float)i + (float)(i1 - i) * value), 0, 255); + int j2 = ExtMath.clampi((int)((float)j + (float)(j1 - j) * value), 0, 255); + int k2 = ExtMath.clampi((int)((float)k + (float)(k1 - k) * value), 0, 255); + int l2 = ExtMath.clampi((int)((float)l + (float)(l1 - l) * value), 0, 255); + return i2 << 24 | j2 << 16 | k2 << 8 | l2; + } + + private int getFrameColor(int value, int base, int mid, int high) { + value = ExtMath.clampi(value, base, high); + return value < mid ? this.blendColors(-16711936, -256, (float)value / (float)mid) + : this.blendColors(-256, -65536, (float)(value - mid) / (float)(high - mid)); + } + + private void renderLagometer() { +// GlState.disableDepth(); + int w = this.fb_x; + int h = this.fb_y; + int shifted = this.lastIndex; + int x = 0; + Drawing.drawRect(0, h - 74, 240, 60, 0x90505050); + + Drawing.drawRect(0, h - 44, 240, 1, 0x5fffffff); + Drawing.drawRect(0, h - 74, 240, 1, 0x5fffffff); + + while(shifted != this.frameIndex) { + int value = (int) (this.frames[shifted] / 1000000L); // , 30); + int color = this.getFrameColor(value, 0, 17, 67); + if(value > 0) + Drawing.drawRect(x, h - 14 - value, 1, value, color & 0xc0ffffff); + ++x; + shifted = (shifted + 1) % 240; + } + + Drawing.drawText("30ms", 2, h - 30 - 14, 0xffE0E0E0); + Drawing.drawText("60ms", 2, h - 60 - 14, 0xffE0E0E0); + Drawing.drawTextRight("ms/Frame", 238, h - 60 - 14, 0xffE0E0E0); + + if(this.lastTickTime >= 0) { + this.updateTick(); + Drawing.drawRect(w - 240, h - 74, 240, 60, 0x90505050); + x = w - 240; + + Drawing.drawRect(w - 240, h - 44, 240, 1, 0x5fffffff); + Drawing.drawRect(w - 240, h - 74, 240, 1, 0x5fffffff); + + for (int n = 0; n < 240; ++n) + { + int value = this.tickTimes[(n + this.tickIndex) % 240]; + int color = this.getFrameColor(value, 0, 50, 250); + if(value > 0) + Drawing.drawRect(x, h - 14 - value, 1, value, color & 0xc0ffffff); + ++x; + shifted = (shifted + 1) % 240; + } + + Drawing.drawText("30ms", w - 240 + 2, h - 30 - 14, 0xffE0E0E0); + Drawing.drawText("60ms", w - 240 + 2, h - 60 - 14, 0xffE0E0E0); + Drawing.drawTextRight("ms/Tick", w - 2, h - 60 - 14, 0xffE0E0E0); + } + +// GlState.enableDepth(); + } + + public static enum FileMode { + DIRECTORY_LOAD, + DIRECTORY_SAVE, + FILE_LOAD, + FILE_LOAD_MULTI, + FILE_SAVE; + } + + public void showFileDialog(final FileMode mode, final String title, final File def, final FileCallback callback) { + if(this.waitingForFile) + return; + this.waitingForFile = true; + new Thread(new Runnable() { + public void run() { + String output = null; + JFileChooser chooser = null; + try { + if(Util.WINDOWS) + throw new RuntimeException("Windows wird von Zenity nicht unterstützt"); + List list = Lists.newArrayList("zenity", "--file-selection"); + switch(mode) { + case DIRECTORY_SAVE: + list.add("--save"); + case DIRECTORY_LOAD: + list.add("--directory"); + break; + case FILE_SAVE: + list.add("--save"); + break; + case FILE_LOAD_MULTI: + list.add("--multiple"); + list.add("--separator"); + list.add(":"); + break; + } + list.add("--title"); + list.add(title); + if(def != null) { + list.add("--filename"); + list.add(def.isDirectory() ? def.getAbsolutePath() + File.separator + "__THISFILEDOESNOTEXIST__" : def.getAbsolutePath()); + } + Process proc = Runtime.getRuntime().exec(list.toArray(new String[list.size()])); + BufferedReader buf = new BufferedReader(new InputStreamReader(new BufferedInputStream(proc.getInputStream()))); + proc.waitFor(); + output = buf.readLine(); + try { + buf.close(); + } + catch(Throwable e) { + } + } + catch(Throwable e) { + Log.SYSTEM.error(e, "Konnte Dateibrowser nicht starten"); + chooser = new JFileChooser(def.isDirectory() ? def : def.getParentFile()); + chooser.setDialogTitle(title); + chooser.setMultiSelectionEnabled(mode == FileMode.FILE_LOAD_MULTI); + chooser.setFileSelectionMode(mode == FileMode.DIRECTORY_LOAD || mode == FileMode.DIRECTORY_SAVE ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY); + int result; + if(mode == FileMode.FILE_SAVE || mode == FileMode.DIRECTORY_SAVE) + result = chooser.showSaveDialog(null); + else + result = chooser.showOpenDialog(null); + if(result != JFileChooser.APPROVE_OPTION) { +// Client.this.logFeed(TextColor.RED + "Konnte Dateibrowser nicht öffnen"); + Client.this.waitingForFile = false; + return; + } + } + if(output == null && chooser == null) { + Client.this.waitingForFile = false; + return; + } + if(mode == FileMode.FILE_LOAD_MULTI) { + final List files = Lists.newArrayList(); + if(chooser != null) { + for(File file : chooser.getSelectedFiles()) { + if(file.isFile()) + files.add(file); + } + } + else { + for(String out : output.split(":")) { + File file = new File(out); + if(file.isFile()) + files.add(file); + } + } + if(files.isEmpty()) { + Client.this.waitingForFile = false; + return; + } + Client.this.schedule(new Runnable() { + public void run() { + if(Client.this.waitingForFile) { + for(File file : files) { + callback.selected(file); + } + } + Client.this.waitingForFile = false; + } + }); + } + else { + File file = chooser != null ? chooser.getSelectedFile() : new File(output); + switch(mode) { + case DIRECTORY_LOAD: + if(!file.isDirectory()) { + Client.this.waitingForFile = false; + return; + } + break; + case DIRECTORY_SAVE: + if(file.exists() && !file.isDirectory()) { + Client.this.waitingForFile = false; + return; + } + break; + case FILE_LOAD: + if(!file.isFile()) { + Client.this.waitingForFile = false; + return; + } + break; + case FILE_SAVE: + if(file.exists() && !file.isFile()) { + Client.this.waitingForFile = false; + return; + } + break; + } + Client.this.schedule(new Runnable() { + public void run() { + if(Client.this.waitingForFile) + callback.selected(file); + Client.this.waitingForFile = false; + } + }); + } + } + }, "File Browser listener").start(); + } +} diff --git a/client/src/main/java/client/util/PerfSection.java b/client/src/client/PerfSection.java similarity index 97% rename from client/src/main/java/client/util/PerfSection.java rename to client/src/client/PerfSection.java index 9938445f..ba9599f8 100644 --- a/client/src/main/java/client/util/PerfSection.java +++ b/client/src/client/PerfSection.java @@ -1,4 +1,4 @@ -package client.util; +package client; import common.util.Util; diff --git a/client/src/client/PlayerController.java b/client/src/client/PlayerController.java new file mode 100755 index 00000000..a06986e5 --- /dev/null +++ b/client/src/client/PlayerController.java @@ -0,0 +1,603 @@ +package client; + +import client.network.ClientPlayer; +import client.world.WorldClient; +import common.block.Block; +import common.entity.Entity; +import common.entity.npc.EntityNPC; +import common.init.BlockRegistry; +import common.init.EntityRegistry; +import common.item.ItemBlock; +import common.item.ItemControl; +import common.item.ItemStack; +import common.material.Material; +import common.packet.CPacketAction; +import common.packet.CPacketBreak; +import common.packet.CPacketClick; +import common.packet.CPacketPlace; +import common.sound.PositionedSound; +import common.util.BlockPos; +import common.util.Facing; +import common.util.Vec3; +import common.world.State; +import common.world.World; + +public class PlayerController +{ + private final Client gm; + private final ClientPlayer netClientHandler; + private BlockPos currentBlock = new BlockPos(-1, -1, -1); + private ItemStack currentItemHittingBlock; + private float curBlockDamageMP; + private float stepSoundTickCounter; + private int blockHitDelay; + private boolean isHittingBlock; + private boolean noclip; + private int currentPlayerItem; + private boolean interacting; + + public PlayerController(Client gmIn, ClientPlayer netHandler) + { + this.gm = gmIn; + this.netClientHandler = netHandler; + } + +// public static void clickBlockCreative(Game gmIn, PlayerController playerController, BlockPos pos, Facing facing) +// { +// if (!gmIn.theWorld.extinguishFire(gmIn.thePlayer, pos, facing)) +// { +// playerController.onPlayerDestroyBlock(pos, facing); +// } +// } + +// public void setPlayerCapabilities() +// { +// this.gm.thePlayer.flying &= this.gm.thePlayer.hasEffect(Potion.flying) || this.gm.thePlayer.noclip; +// } + +// public boolean isNoclip() +// { +// return this.gm.thePlayer.capabilities.noClip; +// } + +// public void setNoclip(boolean noclip) +// { +// this.noclip = noclip; +// } + +// public void setCheat(boolean cheat) +// { +// this.cheat = cheat; +// this.setPlayerCapabilities(); +// } + + + +// public boolean shouldDrawHUD() +// { +// return !this.creative; +// } + + /** + * Called when a player completes the destruction of a block + */ + public boolean onPlayerDestroyBlock(BlockPos pos, Facing side) + { +// if (this.gamemode.isAdventure()) +// { +// if (this.gamemode == Gamemode.SPECTATOR) +// { +// return false; +// } + +// if (!this.gm.thePlayer.isAllowEdit()) +// { +// Block block = this.gm.theWorld.getBlockState(pos).getBlock(); +// ItemStack itemstack = this.gm.thePlayer.getCurrentEquippedItem(); +// +// if (itemstack == null) +// { +// return false; +// } +// +// if (!itemstack.canDestroy(block)) +// { +// return false; +// } +// } +// } + +// if (this.gm.thePlayer.getHeldItem() != null && !this.gm.thePlayer.getHeldItem().getItem().canBreakBlocks()) +// { +// return false; +// } +// else +// { + World world = this.gm.world; + State iblockstate = world.getState(pos); + Block block1 = iblockstate.getBlock(); + + if (block1.getMaterial() == Material.air) + { + return false; + } + else + { + world.playAuxSFX(2001, pos, BlockRegistry.getStateId(iblockstate)); + boolean flag = world.setBlockToAir(pos); + + if (flag) + { + block1.onBlockDestroyedByPlayer(world, pos, iblockstate); + } + + this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ()); + +// if (!this.creative) +// { + ItemStack itemstack1 = this.gm.player.getCurrentEquippedItem(); + + if (itemstack1 != null) + { + itemstack1.onBlockDestroyed(world, block1, pos, this.gm.player); + + if (itemstack1.stackSize == 0) + { + this.gm.player.destroyCurrentEquippedItem(); + } + } +// } + + return flag; + } +// } + } + + /** + * Called when the player is hitting a block with an item. + */ + public boolean clickBlock(BlockPos loc, Facing face) + { +// if (this.gamemode.isAdventure()) +// { +// if (this.gamemode == Gamemode.SPECTATOR) +// { +// return false; +// } + +// if (!this.gm.thePlayer.isAllowEdit()) +// { +// Block block = this.gm.theWorld.getBlockState(loc).getBlock(); +// ItemStack itemstack = this.gm.thePlayer.getCurrentEquippedItem(); +// +// if (itemstack == null) +// { +// return false; +// } +// +// if (!itemstack.canDestroy(block)) +// { +// return false; +// } +// } +// } + + if (!World.isValidXZ(loc)) + { + return false; + } + else + { + ItemStack stack = this.gm.player.getHeldItem(); + if(stack != null && stack.getItem().onAction(stack, this.gm.player, this.gm.world, ItemControl.PRIMARY, loc)) { + this.interacting = true; + this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, loc, face)); + return true; + } +// if (this.creative) +// { +// this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, loc, face)); +// clickBlockCreative(this.gm, this, loc, face); +// this.blockHitDelay = 5; +// } +// else + if (!this.isHittingBlock || !this.isHittingPosition(loc)) + { + if (this.isHittingBlock) + { + this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.ABORT_DESTROY_BLOCK, this.currentBlock, face)); + } + + this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, loc, face)); + Block block1 = this.gm.world.getState(loc).getBlock(); + boolean flag = block1.getMaterial() != Material.air; + + if (flag && this.curBlockDamageMP == 0.0F) + { + block1.onBlockClicked(this.gm.world, loc, this.gm.player); + } + + if (flag && block1.getPlayerRelativeBlockHardness(this.gm.player, this.gm.player.worldObj, loc) >= 1.0F) + { + this.onPlayerDestroyBlock(loc, face); +// if(this.cheat && block1.getPlayerRelativeBlockHardness(this.gm.thePlayer, this.gm.thePlayer.worldObj, loc) < 1.0F) + this.blockHitDelay = 3; + } + else + { + this.isHittingBlock = true; + this.currentBlock = loc; + this.currentItemHittingBlock = this.gm.player.getHeldItem(); + this.curBlockDamageMP = 0.0F; + this.stepSoundTickCounter = 0.0F; + this.gm.world.sendBlockBreakProgress(this.gm.player.getId(), this.currentBlock, (int)(this.curBlockDamageMP * 10.0F) - 1); + } + } + + return true; + } + } + + /** + * Resets current block damage and isHittingBlock + */ + public void resetBlockRemoving() + { + if (this.isHittingBlock) + { + this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.ABORT_DESTROY_BLOCK, this.currentBlock, Facing.DOWN)); + this.isHittingBlock = false; + this.curBlockDamageMP = 0.0F; + this.gm.world.sendBlockBreakProgress(this.gm.player.getId(), this.currentBlock, -1); + } + } + + public void resetInteraction() + { + this.interacting = false; + } + + public boolean onPlayerDamageBlock(BlockPos posBlock, Facing directionFacing) + { + if(this.interacting) + return false; + this.syncCurrentPlayItem(); + + if (this.blockHitDelay > 0) + { + --this.blockHitDelay; + return true; + } +// else if (this.creative && World.isValidXZ(posBlock)) +// { +// this.blockHitDelay = 5; +// this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, posBlock, directionFacing)); +// clickBlockCreative(this.gm, this, posBlock, directionFacing); +// return true; +// } + else if (this.isHittingPosition(posBlock)) + { + Block block = this.gm.world.getState(posBlock).getBlock(); + + if (block.getMaterial() == Material.air) + { + this.isHittingBlock = false; + return false; + } + else + { + this.curBlockDamageMP += block.getPlayerRelativeBlockHardness(this.gm.player, this.gm.player.worldObj, posBlock); + + if (this.stepSoundTickCounter % 4.0F == 0.0F && block.sound.getStepSound() != null) + { + this.gm.getSoundManager().playSound(new PositionedSound(block.sound.getStepSound(), 0.25F, /* block.sound.getFrequency() * 0.5F, */ (float)posBlock.getX() + 0.5F, (float)posBlock.getY() + 0.5F, (float)posBlock.getZ() + 0.5F)); + } + + ++this.stepSoundTickCounter; + + if (this.curBlockDamageMP >= 1.0F) + { + this.isHittingBlock = false; + this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.STOP_DESTROY_BLOCK, posBlock, directionFacing)); + this.onPlayerDestroyBlock(posBlock, directionFacing); + this.curBlockDamageMP = 0.0F; + this.stepSoundTickCounter = 0.0F; + this.blockHitDelay = 5; + } + + this.gm.world.sendBlockBreakProgress(this.gm.player.getId(), this.currentBlock, (int)(this.curBlockDamageMP * 10.0F) - 1); + return true; + } + } + else + { + return this.clickBlock(posBlock, directionFacing); + } + } + +// /** +// * player reach distance = 4F +// */ +// public float getBlockReachDistance() +// { +// return ; +// } + + public void updateController() + { + this.syncCurrentPlayItem(); + + if (this.netClientHandler.getNetworkManager().isChannelOpen()) + { + this.netClientHandler.getNetworkManager().processReceivedPackets(); + } + else + { + this.netClientHandler.getNetworkManager().checkDisconnected(); + } + } + + private boolean isHittingPosition(BlockPos pos) + { + ItemStack itemstack = this.gm.player.getHeldItem(); + boolean flag = this.currentItemHittingBlock == null && itemstack == null; + + if (this.currentItemHittingBlock != null && itemstack != null) + { + flag = itemstack.getItem() == this.currentItemHittingBlock.getItem() && ItemStack.areItemStackTagsEqual(itemstack, this.currentItemHittingBlock) && (itemstack.isItemStackDamageable() || itemstack.getMetadata() == this.currentItemHittingBlock.getMetadata()); + } + + return pos.equals(this.currentBlock) && flag; + } + + /** + * Syncs the current player item with the server + */ + private void syncCurrentPlayItem() + { + int i = this.gm.player.inventory.currentItem; + + if (i != this.currentPlayerItem) + { + this.currentPlayerItem = i; + this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_ITEMSLOT, this.currentPlayerItem)); + } + } + + public boolean onPlayerRightClick(EntityNPC player, WorldClient worldIn, ItemStack heldStack, BlockPos hitPos, Facing side, Vec3 hitVec) + { + this.syncCurrentPlayItem(); + float f = (float)(hitVec.xCoord - (double)hitPos.getX()); + float f1 = (float)(hitVec.yCoord - (double)hitPos.getY()); + float f2 = (float)(hitVec.zCoord - (double)hitPos.getZ()); + boolean flag = false; + + if (!World.isValidXZ(hitPos)) + { + return false; + } + else + { + if(heldStack == null || !heldStack.getItem().onAction(heldStack, player, worldIn, ItemControl.SECONDARY, hitPos)) { +// if (this.gamemode != Gamemode.SPECTATOR) +// { + State iblockstate = worldIn.getState(hitPos); + + if ((!player.isSneaking() || player.getHeldItem() == null) // && (player.getHeldItem() == null || !player.getHeldItem().getItem().ignoresBlocks()) + && iblockstate.getBlock().onBlockActivated(worldIn, hitPos, iblockstate, player, side, f, f1, f2)) + { + flag = true; + } + + if (!flag && heldStack != null && heldStack.getItem() instanceof ItemBlock) + { + ItemBlock itemblock = (ItemBlock)heldStack.getItem(); + + if (!itemblock.canPlaceBlockOnSide(worldIn, hitPos, side, player, heldStack)) + { + return false; + } + } +// } + } + else { + heldStack.getItem().onItemUse(heldStack, player, worldIn, hitPos, side, f, f1, f2); + flag = true; + } + + this.netClientHandler.addToSendQueue(new CPacketPlace(hitPos, side.getIndex(), player.inventory.getCurrentItem(), f, f1, f2)); + + if (!flag) // && this.gamemode != Gamemode.SPECTATOR) + { + if (heldStack == null) + { + return false; + } +// else if (this.creative) +// { +// int i = heldStack.getMetadata(); +// int j = heldStack.stackSize; +// boolean flag1 = heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2); +// heldStack.setItemDamage(i); +// heldStack.stackSize = j; +// return flag1; +// } + else + { + return heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2); + } + } + else + { + return true; + } + } + } + + /** + * Notifies the server of things like consuming food, etc... + */ + public boolean sendUseItem(EntityNPC playerIn, World worldIn, ItemStack itemStackIn) + { +// if (this.gamemode == Gamemode.SPECTATOR) +// { +// return false; +// } +// else +// { + this.syncCurrentPlayItem(); + this.netClientHandler.addToSendQueue(new CPacketPlace(playerIn.inventory.getCurrentItem())); + int i = itemStackIn.stackSize; + ItemStack itemstack = itemStackIn.useItemRightClick(worldIn, playerIn); + + if (itemstack != itemStackIn || itemstack != null && itemstack.stackSize != i) + { + playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = itemstack; + + if (itemstack.stackSize == 0) + { + playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = null; + } + + return true; + } + else + { + return false; + } +// } + } + + public EntityNPC createPlayerEntity(WorldClient worldIn, int type) + { + EntityNPC player = (EntityNPC)EntityRegistry.createEntityByID(type, worldIn); + player.setClientPlayer(this.netClientHandler); + return player; + } + + /** + * Attacks an entity + */ + public void attackEntity(EntityNPC playerIn, Entity targetEntity) + { + this.syncCurrentPlayItem(); + this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.ATTACK, targetEntity.getId())); + +// if (this.gamemode != Gamemode.SPECTATOR) +// { + playerIn.attackTargetEntityWithCurrentItem(targetEntity); +// } + } + + /** + * Send packet to server - player is interacting with another entity (left click) + */ + public boolean interactWithEntitySendPacket(EntityNPC playerIn, Entity targetEntity) + { + this.syncCurrentPlayItem(); + this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.INTERACT, targetEntity.getId())); + return /* this.gamemode != Gamemode.SPECTATOR && */ playerIn.interactWith(targetEntity); + } + +// /** +// * Return true when the player rightclick on an entity +// * +// * @param player The player's instance +// * @param entityIn The entity clicked +// * @param movingObject The object clicked +// */ +// public boolean isPlayerRightClickingOnEntity(EntityNPC player, Entity entityIn, MovingObjectPosition movingObject) +// { +// this.syncCurrentPlayItem(); +// Vec3 vec3 = new Vec3(movingObject.hitVec.xCoord - entityIn.posX, movingObject.hitVec.yCoord - entityIn.posY, movingObject.hitVec.zCoord - entityIn.posZ); +// this.netClientHandler.addToSendQueue(new C02PacketUseEntity(entityIn, vec3)); +// return this.gamemode != Gamemode.SPECTATOR && entityIn.interactAt(player, vec3); +// } + + /** + * Handles slot clicks sends a packet to the server. + */ + public ItemStack windowClick(int windowId, int slotId, int mouseButtonClicked, int mode, EntityNPC playerIn) + { + short short1 = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack itemstack = playerIn.openContainer.slotClick(slotId, mouseButtonClicked, mode, playerIn); + this.netClientHandler.addToSendQueue(new CPacketClick(windowId, slotId, mouseButtonClicked, mode, itemstack, short1)); + return itemstack; + } + + /** + * GuiEnchantment uses this during multiplayer to tell PlayerControllerMP to send a packet indicating the + * enchantment action the player has taken. + * + * @param windowID The ID of the current window + * @param button The button id (enchantment selected) + */ + public void sendEnchantPacket(int windowID, int button) + { + this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.ENCHANT_ITEM, windowID | (button << 8))); + } + +// /** +// * Used in PlayerControllerMP to update the server with an ItemStack in a slot. +// */ +// public void sendCheatPacket(ItemStack itemStackIn, boolean full) +// { +// } + +// /** +// * Sends a Packet107 to the server to drop the item on the ground +// */ +// public void sendPacketDropItem(ItemStack itemStackIn) +// { +// if (this.creative && itemStackIn != null) +// { +// this.netClientHandler.addToSendQueue(new CPacketCreative(-1, itemStackIn)); +// } +// } + + public void onStoppedUsingItem(EntityNPC playerIn) + { + this.syncCurrentPlayItem(); + this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, Facing.DOWN)); + playerIn.stopUsingItem(); + } + + + +// /** +// * Checks if the player is not creative, used for checking if it should break a block instantly +// */ +// public boolean isNotCreative() +// { +// return !this.creative; +// } + +// /** +// * returns true if player is in creative mode +// */ +// public boolean isCreative() +// { +// return this.creative; +// } + +// /** +// * Checks if the player is riding a horse, used to chose the GUI to open +// */ +// public boolean isRidingHorse() +// { +// return ; +// } + +// public Gamemode getGamemode() +// { +// return this.gamemode; +// } + + /** + * Return isHittingBlock + */ + public boolean getIsHittingBlock() + { + return this.isHittingBlock; + } +} diff --git a/client/src/main/java/client/util/SkinConverter.java b/client/src/client/SkinConverter.java similarity index 95% rename from client/src/main/java/client/util/SkinConverter.java rename to client/src/client/SkinConverter.java index dffc0493..6c7695e8 100755 --- a/client/src/main/java/client/util/SkinConverter.java +++ b/client/src/client/SkinConverter.java @@ -1,4 +1,4 @@ -package client.util; +package client; import java.awt.Color; import java.awt.Graphics; @@ -171,20 +171,20 @@ public abstract class SkinConverter { img = ImageIO.read(source); } catch(IOException e) { - Log.IO.error(e, "Konnte kein Bild von " + source + " laden"); + Log.JNI.error(e, "Konnte kein Bild von " + source + " laden"); return false; } if(img == null) { - Log.IO.warn("Konnte kein Bild von " + source + " laden"); + Log.JNI.warn("Konnte kein Bild von " + source + " laden"); return false; } - Log.IO.info("Bild von " + source + " geladen"); + Log.JNI.info("Bild von " + source + " geladen"); if(img.getWidth() == 64 && img.getHeight() == 32) { img = convertSkin(img); - Log.IO.info("Skin " + source + " konvertiert"); + Log.JNI.info("Skin " + source + " konvertiert"); } else if(img.getWidth() != 64 || img.getHeight() != 64) { - Log.IO.warn("Falsche Bildgröße von " + source + ": " + img.getWidth() + "x" + img.getHeight()); + Log.JNI.warn("Falsche Bildgröße von " + source + ": " + img.getWidth() + "x" + img.getHeight()); return false; } String name = source.getName(); @@ -195,7 +195,7 @@ public abstract class SkinConverter { name = "skin"; if(slim) { img = convertSlim(img); - Log.IO.info("Skin " + source + " von 'Slim' konvertiert"); + Log.JNI.info("Skin " + source + " von 'Slim' konvertiert"); if(!name.startsWith("slim_")) name = "slim_" + name; } @@ -217,10 +217,10 @@ public abstract class SkinConverter { ImageIO.write(img, "png", file); } catch(Exception e) { - Log.IO.error(e, "Konnte Bild nicht speichern"); + Log.JNI.error(e, "Konnte Bild nicht speichern"); return false; } - Log.IO.info("Skin " + source + " gespeichert als " + file.getName()); + Log.JNI.info("Skin " + source + " gespeichert als " + file.getName()); return true; } diff --git a/client/src/client/Timing.java b/client/src/client/Timing.java new file mode 100644 index 00000000..96094f3d --- /dev/null +++ b/client/src/client/Timing.java @@ -0,0 +1,30 @@ +package client; + +public class Timing { + public static long tmr_timer; + public static long tmr_start; + public static long tmr_current; + public static long tmr_last; + + public static long tmr_delta; + public static long tmr_update; + public static long tmr_frames; + public static long tmr_iters; + + public static long tick_torun; + public static long tick_done; + public static long tick_total; + public static long tick_time; + public static long tick_stime; + public static long tick_ftime; + + public static long tick_ttime; + public static long tick_update; + + public static double tick_fraction; + public static float framerate; + public static float tickrate; + public static float fdelta; + public static int tickTarget; + public static int tickFrame; +} diff --git a/client/src/main/java/client/audio/AudioInterface.java b/client/src/client/audio/AudioInterface.java similarity index 97% rename from client/src/main/java/client/audio/AudioInterface.java rename to client/src/client/audio/AudioInterface.java index 47dbefd6..2e7c1056 100644 --- a/client/src/main/java/client/audio/AudioInterface.java +++ b/client/src/client/audio/AudioInterface.java @@ -11,6 +11,7 @@ import javax.sound.sampled.DataLine.Info; import common.collect.Lists; import common.log.Log; +import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.SourceDataLine; public class AudioInterface implements Runnable { @@ -137,12 +138,12 @@ public class AudioInterface implements Runnable { public void run() { AudioFormat format = new AudioFormat(Encoding.PCM_SIGNED, 48000, 16, 2, 2 * 2, 48000, false); - Info info = new Info(SourceDataLine.class, format, this.devbufsize == 0 ? AudioSystem.NOT_SPECIFIED : this.devbufsize); + Info info = new Info(SourceDataLine.class, format, this.devbufsize); try { this.line = (SourceDataLine)AudioSystem.getLine(info); - this.line.open(format, this.devbufsize == 0 ? AudioSystem.NOT_SPECIFIED : this.devbufsize); + this.line.open(format, this.devbufsize); } - catch(Exception e) { + catch(LineUnavailableException e) { this.line = null; Log.SOUND.error(e, "Konnte Audiogerät nicht öffnen"); } diff --git a/client/src/main/java/client/audio/CodecJOrbis.java b/client/src/client/audio/CodecJOrbis.java similarity index 100% rename from client/src/main/java/client/audio/CodecJOrbis.java rename to client/src/client/audio/CodecJOrbis.java diff --git a/client/src/main/java/client/audio/SoundManager.java b/client/src/client/audio/SoundManager.java similarity index 98% rename from client/src/main/java/client/audio/SoundManager.java rename to client/src/client/audio/SoundManager.java index b37eb87a..69421539 100755 --- a/client/src/main/java/client/audio/SoundManager.java +++ b/client/src/client/audio/SoundManager.java @@ -11,7 +11,6 @@ import java.util.Map; import java.util.Map.Entry; import client.Client; -import client.util.FileUtils; import common.collect.BiMap; import common.collect.HashBiMap; import common.collect.Lists; @@ -23,6 +22,7 @@ import common.rng.Random; import common.sound.MovingSound; import common.sound.Sound; import common.util.ExtMath; +import common.util.FileUtils; public class SoundManager { private class Source { @@ -238,8 +238,8 @@ public class SoundManager { this.sources.put(s, new Source(getBuffer(sound.getSoundLocation()), Volume.getByType(sound.getChannelType()), sound.canRepeat(), s, sound.getXPosF(), sound.getYPosF(), sound.getZPosF(), sound.getAttenuationType(), attn, volume)); this.playingSoundsStopTime.put(s, this.playTime + 20); this.playingSounds.put(s, sound); - if (sound instanceof MovingSound moving) - this.tickableSounds.add(moving); + if (sound instanceof MovingSound) + this.tickableSounds.add((MovingSound)sound); } } diff --git a/client/src/main/java/client/audio/Volume.java b/client/src/client/audio/Volume.java similarity index 96% rename from client/src/main/java/client/audio/Volume.java rename to client/src/client/audio/Volume.java index 1058079a..5d400b79 100644 --- a/client/src/main/java/client/audio/Volume.java +++ b/client/src/client/audio/Volume.java @@ -5,8 +5,8 @@ import client.gui.element.Slider; import client.gui.element.SliderCallback; import client.vars.CVar; import client.vars.CVarCategory; +import common.color.TextColor; import common.sound.EventType; -import common.util.Color; public enum Volume implements CVar { MASTER("master", "Gesamt"), @@ -52,7 +52,7 @@ public enum Volume implements CVar { } public String getType() { - return Color.DARK_GREEN + "volume"; + return TextColor.DGREEN + "volume"; } public CVarCategory getCategory() { diff --git a/client/src/main/java/client/audio/jogg/Buffer.java b/client/src/client/audio/jogg/Buffer.java similarity index 100% rename from client/src/main/java/client/audio/jogg/Buffer.java rename to client/src/client/audio/jogg/Buffer.java diff --git a/client/src/main/java/client/audio/jogg/Packet.java b/client/src/client/audio/jogg/Packet.java similarity index 100% rename from client/src/main/java/client/audio/jogg/Packet.java rename to client/src/client/audio/jogg/Packet.java diff --git a/client/src/main/java/client/audio/jogg/Page.java b/client/src/client/audio/jogg/Page.java similarity index 100% rename from client/src/main/java/client/audio/jogg/Page.java rename to client/src/client/audio/jogg/Page.java diff --git a/client/src/main/java/client/audio/jogg/StreamState.java b/client/src/client/audio/jogg/StreamState.java similarity index 100% rename from client/src/main/java/client/audio/jogg/StreamState.java rename to client/src/client/audio/jogg/StreamState.java diff --git a/client/src/main/java/client/audio/jogg/SyncState.java b/client/src/client/audio/jogg/SyncState.java similarity index 100% rename from client/src/main/java/client/audio/jogg/SyncState.java rename to client/src/client/audio/jogg/SyncState.java diff --git a/client/src/main/java/client/audio/jorbis/Block.java b/client/src/client/audio/jorbis/Block.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/Block.java rename to client/src/client/audio/jorbis/Block.java diff --git a/client/src/main/java/client/audio/jorbis/ChainingExample.java b/client/src/client/audio/jorbis/ChainingExample.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/ChainingExample.java rename to client/src/client/audio/jorbis/ChainingExample.java diff --git a/client/src/main/java/client/audio/jorbis/CodeBook.java b/client/src/client/audio/jorbis/CodeBook.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/CodeBook.java rename to client/src/client/audio/jorbis/CodeBook.java diff --git a/client/src/main/java/client/audio/jorbis/Comment.java b/client/src/client/audio/jorbis/Comment.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/Comment.java rename to client/src/client/audio/jorbis/Comment.java diff --git a/client/src/main/java/client/audio/jorbis/DecodeExample.java b/client/src/client/audio/jorbis/DecodeExample.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/DecodeExample.java rename to client/src/client/audio/jorbis/DecodeExample.java diff --git a/client/src/main/java/client/audio/jorbis/Drft.java b/client/src/client/audio/jorbis/Drft.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/Drft.java rename to client/src/client/audio/jorbis/Drft.java diff --git a/client/src/main/java/client/audio/jorbis/DspState.java b/client/src/client/audio/jorbis/DspState.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/DspState.java rename to client/src/client/audio/jorbis/DspState.java diff --git a/client/src/main/java/client/audio/jorbis/Floor0.java b/client/src/client/audio/jorbis/Floor0.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/Floor0.java rename to client/src/client/audio/jorbis/Floor0.java diff --git a/client/src/main/java/client/audio/jorbis/Floor1.java b/client/src/client/audio/jorbis/Floor1.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/Floor1.java rename to client/src/client/audio/jorbis/Floor1.java diff --git a/client/src/main/java/client/audio/jorbis/FuncFloor.java b/client/src/client/audio/jorbis/FuncFloor.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/FuncFloor.java rename to client/src/client/audio/jorbis/FuncFloor.java diff --git a/client/src/main/java/client/audio/jorbis/FuncMapping.java b/client/src/client/audio/jorbis/FuncMapping.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/FuncMapping.java rename to client/src/client/audio/jorbis/FuncMapping.java diff --git a/client/src/main/java/client/audio/jorbis/FuncResidue.java b/client/src/client/audio/jorbis/FuncResidue.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/FuncResidue.java rename to client/src/client/audio/jorbis/FuncResidue.java diff --git a/client/src/main/java/client/audio/jorbis/FuncTime.java b/client/src/client/audio/jorbis/FuncTime.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/FuncTime.java rename to client/src/client/audio/jorbis/FuncTime.java diff --git a/client/src/main/java/client/audio/jorbis/Info.java b/client/src/client/audio/jorbis/Info.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/Info.java rename to client/src/client/audio/jorbis/Info.java diff --git a/client/src/main/java/client/audio/jorbis/InfoMode.java b/client/src/client/audio/jorbis/InfoMode.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/InfoMode.java rename to client/src/client/audio/jorbis/InfoMode.java diff --git a/client/src/main/java/client/audio/jorbis/JOrbisException.java b/client/src/client/audio/jorbis/JOrbisException.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/JOrbisException.java rename to client/src/client/audio/jorbis/JOrbisException.java diff --git a/client/src/main/java/client/audio/jorbis/Lookup.java b/client/src/client/audio/jorbis/Lookup.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/Lookup.java rename to client/src/client/audio/jorbis/Lookup.java diff --git a/client/src/main/java/client/audio/jorbis/Lpc.java b/client/src/client/audio/jorbis/Lpc.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/Lpc.java rename to client/src/client/audio/jorbis/Lpc.java diff --git a/client/src/main/java/client/audio/jorbis/Lsp.java b/client/src/client/audio/jorbis/Lsp.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/Lsp.java rename to client/src/client/audio/jorbis/Lsp.java diff --git a/client/src/main/java/client/audio/jorbis/Mapping0.java b/client/src/client/audio/jorbis/Mapping0.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/Mapping0.java rename to client/src/client/audio/jorbis/Mapping0.java diff --git a/client/src/main/java/client/audio/jorbis/Mdct.java b/client/src/client/audio/jorbis/Mdct.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/Mdct.java rename to client/src/client/audio/jorbis/Mdct.java diff --git a/client/src/main/java/client/audio/jorbis/PsyInfo.java b/client/src/client/audio/jorbis/PsyInfo.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/PsyInfo.java rename to client/src/client/audio/jorbis/PsyInfo.java diff --git a/client/src/main/java/client/audio/jorbis/PsyLook.java b/client/src/client/audio/jorbis/PsyLook.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/PsyLook.java rename to client/src/client/audio/jorbis/PsyLook.java diff --git a/client/src/main/java/client/audio/jorbis/Residue0.java b/client/src/client/audio/jorbis/Residue0.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/Residue0.java rename to client/src/client/audio/jorbis/Residue0.java diff --git a/client/src/main/java/client/audio/jorbis/Residue1.java b/client/src/client/audio/jorbis/Residue1.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/Residue1.java rename to client/src/client/audio/jorbis/Residue1.java diff --git a/client/src/main/java/client/audio/jorbis/Residue2.java b/client/src/client/audio/jorbis/Residue2.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/Residue2.java rename to client/src/client/audio/jorbis/Residue2.java diff --git a/client/src/main/java/client/audio/jorbis/StaticCodeBook.java b/client/src/client/audio/jorbis/StaticCodeBook.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/StaticCodeBook.java rename to client/src/client/audio/jorbis/StaticCodeBook.java diff --git a/client/src/main/java/client/audio/jorbis/Time0.java b/client/src/client/audio/jorbis/Time0.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/Time0.java rename to client/src/client/audio/jorbis/Time0.java diff --git a/client/src/main/java/client/audio/jorbis/Util.java b/client/src/client/audio/jorbis/Util.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/Util.java rename to client/src/client/audio/jorbis/Util.java diff --git a/client/src/main/java/client/audio/jorbis/VorbisFile.java b/client/src/client/audio/jorbis/VorbisFile.java similarity index 100% rename from client/src/main/java/client/audio/jorbis/VorbisFile.java rename to client/src/client/audio/jorbis/VorbisFile.java diff --git a/client/src/main/java/client/gui/FileCallback.java b/client/src/client/gui/FileCallback.java similarity index 100% rename from client/src/main/java/client/gui/FileCallback.java rename to client/src/client/gui/FileCallback.java diff --git a/client/src/client/gui/Font.java b/client/src/client/gui/Font.java new file mode 100644 index 00000000..51fa18bb --- /dev/null +++ b/client/src/client/gui/Font.java @@ -0,0 +1,107 @@ +package client.gui; + +import java.awt.image.BufferedImage; +import java.io.FileNotFoundException; +import java.io.IOException; + +import org.lwjgl.opengl.GL11; + +import client.renderer.GlState; +import client.renderer.texture.TextureUtil; +import common.log.Log; +import common.util.FileUtils; + +public class Font { + public static final FontChar[] SIZES = new FontChar[256]; + public static final int XGLYPH = 12; + public static final int YGLYPH = 18; + + private static int texture; + + public static void bindTexture() { + GlState.bindTexture(texture); + } + + private static int stride(int width, int height, int x, int y, int c) { + return ((c & 15) * width + x) + (((c >> 4) & 15) * height + y) * (width << 4); // << 2; + } + + private static byte specialChar(int width, int ch) { + return (byte)((ch == Log.CHR_UNK) ? width : ((ch == Log.CHR_SPC) ? (width / 6) : 127)); + } + + private static void calculate(int[] data, FontChar[] glyphs, int width, int height, int page) { + int off; + for(int z = 0; z < 256; z++) { + byte s, t, u, v; + if((u = specialChar(width, (page << 8) + z)) != 127) { + s = t = 0; + v = (byte)(((int)u) * height / width); + if(((page << 8) + z) != Log.CHR_UNK) { + for(int x = 0; x < width; x++) { + for(int y = 0; y < height; y++) { + off = stride(width, height, x, y, z); + data[off/*+3*/] = 0; + } + } + } + glyphs[z] = new FontChar(s, t, u, v); + continue; + } + s = t = 127; + u = v = 0; + for(int x = 0; x < width; x++) { + for(int y = 0; y < height; y++) { + off = stride(width, height, x, y, z); + if((data[off/*+3*/] & 0xff000000) != 0) { + s = x < s ? (byte)x : s; + t = y < t ? (byte)y : t; + u = x > u ? (byte)x : u; + v = y > v ? (byte)y : v; + } + } + } + if(s == 127 && t == 127 && u == 0 && v == 0) { + s = t = 0; + } + else { + u += 1; + v += 1; + } + glyphs[z] = new FontChar(s, t, u, v); + } + } + + public static void load() { + BufferedImage img = null; + try { + img = TextureUtil.readImage(FileUtils.getResource("textures/font.png")); + } + catch(FileNotFoundException e) { + Log.IO.error("Konnte Font-Textur nicht laden: Datei nicht vorhanden"); + } + catch(IOException e) { + Log.IO.error(e, "Konnte Font-Textur nicht laden"); + } + if(img != null && (img.getWidth() != XGLYPH * 16 || img.getHeight() != YGLYPH * 16)) { + Log.IO.error("Konnte Font-Textur nicht laden: Größe ist nicht %dx%d", XGLYPH * 16, YGLYPH * 16); + img = null; + } + if(img == null) + throw new IllegalStateException("Konnte erforderliche Schriftart nicht laden"); + int[] data = new int[XGLYPH * 16 * YGLYPH * 16]; + img.getRGB(0, 0, XGLYPH * 16, YGLYPH * 16, data, 0, XGLYPH * 16); + calculate(data, SIZES, XGLYPH, YGLYPH, 0); + texture = GL11.glGenTextures(); + TextureUtil.uploadImage(texture, img); + Log.RENDER.debug("Font-Textur wurde mit ID #%d geladen", texture); + } + + public static void unload() { + if(texture != 0) { + GL11.glDeleteTextures(texture); + Log.RENDER.debug("Font-Textur mit ID #%d wurde gelöscht", texture); + texture = 0; + } + } +} diff --git a/client/src/main/java/client/gui/FontChar.java b/client/src/client/gui/FontChar.java similarity index 100% rename from client/src/main/java/client/gui/FontChar.java rename to client/src/client/gui/FontChar.java diff --git a/client/src/main/java/client/gui/Formatter.java b/client/src/client/gui/Formatter.java similarity index 100% rename from client/src/main/java/client/gui/Formatter.java rename to client/src/client/gui/Formatter.java diff --git a/client/src/client/gui/Gui.java b/client/src/client/gui/Gui.java new file mode 100644 index 00000000..73628a84 --- /dev/null +++ b/client/src/client/gui/Gui.java @@ -0,0 +1,329 @@ +package client.gui; + +import java.util.List; + +import org.lwjgl.opengl.GL13; + +import client.Client; +import client.gui.element.Dropdown; +import client.gui.element.Dropdown.Handle; +import client.gui.element.Element; +import client.renderer.Drawing; +import client.renderer.GlState; +import client.window.Bind; +import client.window.Button; +import client.window.Keysym; +import common.collect.Lists; + +public abstract class Gui { + public static final String DIRT_BACKGROUND = "textures/background.png"; + public static final int HOVER_COLOR = 0x288080ff; + public static final int PRESS_COLOR = 0x30afafff; + + protected final Client gm = Client.CLIENT; + + public Element selected; + private int min_x; + private int min_y; + private int max_x; + private int max_y; + public final List elems = Lists.newArrayList(); + + public abstract void init(int width, int height); + public abstract String getTitle(); + + public void updateScreen() { + } + + public void onGuiClosed() { + } + + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + } + + public void mouseReleased(int mouseX, int mouseY, int state) { + } + + public void mouseDragged(int mouseX, int mouseY) { + } + + public void drawPost() { + } + +// public void drawGuiContainerForegroundLayer() { +// } +// +// public void drawGuiContainerBackgroundLayer() { +// } + + public void drawOverlays() { + } + + public void useHotbar(int slot) { + } + + public void dropItem() { + } + + public void drawBackground() { + + } + + public Element clicked(int x, int y) { + if(this.selected != null && this.selected.visible && (this.selected instanceof Handle) && this.selected.inside(x, y)) + return this.selected; // fix (?) + for(Element elem : this.elems) { + if(elem.visible && elem.enabled && elem.inside(x, y)) + return elem; + } + return null; + } + + public void reformat() { + for(Element elem : this.elems) { + elem.reformat(); + } + } + + public void deselect() { + if(this.selected != null && !(this.selected instanceof Handle)) { + this.selected.deselect(); + this.selected = null; + } + } + + public void select(Element elem) { + if(this.selected != elem && !(this.selected instanceof Handle) && !(elem instanceof Handle)) { + if(this.selected != null) + this.selected.deselect(); + if(elem != null) + elem.select(); + this.selected = elem; + } + } + + public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) { + int prev; + Element elem = this.clicked(x, y); + if(this.selected != null && this.selected != elem && this.selected instanceof Handle) { + this.selected.deselect(); + return; + } + else if(this.selected != elem) { + if(this.selected != null) + this.selected.deselect(); + if(elem != null) + elem.select(); + this.selected = elem; + } + if(elem != null) + elem.mouse(btn, x, y, ctrl, shift); + } + + public void mouserel(Button btn, int x, int y) { + if(this.selected != null) + this.selected.mouserel(); + } + + public void drag(int x, int y) { + if(this.selected != null && (Button.MOUSE_LEFT.isDown() || Button.MOUSE_RIGHT.isDown())) + this.selected.drag(x, y); + } + + public void scroll(int scr_x, int scr_y, int x, int y, boolean ctrl, boolean shift) { + Element elem = this.clicked(x, y); + if(elem != null) + elem.scroll(scr_x, scr_y, x, y, ctrl, shift); + } + + public void key(Keysym key, boolean ctrl, boolean shift) { + if(this.selected != null) + this.selected.key(key, ctrl, shift); + } + + public void character(char code) { + if(this.selected != null) + this.selected.character(code); + } + + protected void shift() { + if(this.gm.fb_x != 0 && this.gm.fb_y != 0) { + int shift_x = (this.gm.fb_x - (this.max_x - this.min_x)) / 2 - this.min_x; + int shift_y = (this.gm.fb_y - (this.max_y - this.min_y)) / 2 - this.min_y; + for(Element elem : this.elems) { + elem.shift(shift_x, shift_y); + } + } + } + + public void init() { + this.selected = null; + this.min_x = this.min_y = Integer.MAX_VALUE; + this.max_x = this.max_y = Integer.MIN_VALUE; + this.elems.clear(); + this.init(this.gm.fb_x, this.gm.fb_y); + } + + public void update() { + if(this.selected != null) + this.selected.update(); + } + + protected T add(T elem) { + this.elems.add(elem); + elem.setGui(this); + this.min_x = Math.min(this.min_x, elem.getX()); + this.min_y = Math.min(this.min_y, elem.getY()); + this.max_x = Math.max(this.max_x, elem.getX() + elem.getWidth()); + this.max_y = Math.max(this.max_y, elem.getY() + elem.getHeight()); + if(elem instanceof Dropdown) + this.add(((Dropdown)elem).getHandle()); + return elem; + } + + protected Element addSelector(String cvar, int x, int y, int w, int h) { + return this.add(this.gm.getVar(cvar).selector(x, y, w, h)); + } + + public void draw() { + if(this.selected != null && /* this.selected.r_dirty && */ this.selected instanceof Handle && !this.selected.visible) { + this.selected = null; + } + for(Element elem : this.elems) { + if(/* this.selected != e || */ !(elem instanceof Handle)) // || !e.visible) + elem.draw(); + } + if(this.selected != null && /* elem.r_dirty && */ this.selected instanceof Handle && this.selected.visible) { + this.selected.draw(); + } + } + + public void drawOverlay() { + Element elem = this.selected; + if(Button.isMouseDown() && elem != null && elem.enabled && elem.visible && elem.canClick()) { + elem.drawPress(); + return; + } + if(elem != null && elem.enabled && elem.visible) + elem.drawOverlay(); + elem = this.clicked(this.gm.mouse_x, this.gm.mouse_y); + if(elem != null && elem.enabled && elem.visible && elem.canHover()) + elem.drawHover(); + } + +// public static void drawRect(int left, int top, int right, int bottom, int color) +// { +// if (left < right) +// { +// int i = left; +// left = right; +// right = i; +// } +// +// if (top < bottom) +// { +// int j = top; +// top = bottom; +// bottom = j; +// } +// +// float f3 = (float)(color >> 24 & 255) / 255.0F; +// float f = (float)(color >> 16 & 255) / 255.0F; +// float f1 = (float)(color >> 8 & 255) / 255.0F; +// float f2 = (float)(color & 255) / 255.0F; +// RenderBuffer worldrenderer = Tessellator.getBuffer(); +// GlState.enableBlend(); +// GlState.disableTexture2D(); +// GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); +// GlState.color(f, f1, f2, f3); +// worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); +// worldrenderer.pos((double)left, (double)bottom, 0.0D).endVertex(); +// worldrenderer.pos((double)right, (double)bottom, 0.0D).endVertex(); +// worldrenderer.pos((double)right, (double)top, 0.0D).endVertex(); +// worldrenderer.pos((double)left, (double)top, 0.0D).endVertex(); +// Tessellator.draw(); +// GlState.enableTexture2D(); +// GlState.disableBlend(); +// } + +// public static void drawTexturedModalRect(int x, int y, int textureX, int textureY, int width, int height) +// { +// float f = 0.00390625F; +// float f1 = 0.00390625F; +// RenderBuffer worldrenderer = Tessellator.getBuffer(); +// worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); +// worldrenderer.pos((double)(x + 0), (double)(y + height), 0.0D).tex((double)((float)(textureX + 0) * f), (double)((float)(textureY + height) * f1)).endVertex(); +// worldrenderer.pos((double)(x + width), (double)(y + height), 0.0D).tex((double)((float)(textureX + width) * f), (double)((float)(textureY + height) * f1)).endVertex(); +// worldrenderer.pos((double)(x + width), (double)(y + 0), 0.0D).tex((double)((float)(textureX + width) * f), (double)((float)(textureY + 0) * f1)).endVertex(); +// worldrenderer.pos((double)(x + 0), (double)(y + 0), 0.0D).tex((double)((float)(textureX + 0) * f), (double)((float)(textureY + 0) * f1)).endVertex(); +// Tessellator.draw(); +// } +// +// public static void drawScaledCustomSizeModalRect(int x, int y, float u, float v, int uWidth, int vHeight, int width, int height, float tileWidth, float tileHeight) +// { +// float f = 1.0F / tileWidth; +// float f1 = 1.0F / tileHeight; +// RenderBuffer worldrenderer = Tessellator.getBuffer(); +// worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); +// worldrenderer.pos((double)x, (double)(y + height), 0.0D).tex((double)(u * f), (double)((v + (float)vHeight) * f1)).endVertex(); +// worldrenderer.pos((double)(x + width), (double)(y + height), 0.0D).tex((double)((u + (float)uWidth) * f), (double)((v + (float)vHeight) * f1)).endVertex(); +// worldrenderer.pos((double)(x + width), (double)y, 0.0D).tex((double)((u + (float)uWidth) * f), (double)(v * f1)).endVertex(); +// worldrenderer.pos((double)x, (double)y, 0.0D).tex((double)(u * f), (double)(v * f1)).endVertex(); +// Tessellator.draw(); +// } +// +// public static void drawGradientRect(int left, int top, int right, int bottom, int startColor, int endColor) +// { +// float f = (float)(startColor >> 24 & 255) / 255.0F; +// float f1 = (float)(startColor >> 16 & 255) / 255.0F; +// float f2 = (float)(startColor >> 8 & 255) / 255.0F; +// float f3 = (float)(startColor & 255) / 255.0F; +// float f4 = (float)(endColor >> 24 & 255) / 255.0F; +// float f5 = (float)(endColor >> 16 & 255) / 255.0F; +// float f6 = (float)(endColor >> 8 & 255) / 255.0F; +// float f7 = (float)(endColor & 255) / 255.0F; +// GlState.disableTexture2D(); +// GlState.enableBlend(); +// GlState.disableAlpha(); +// GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); +// GlState.shadeModel(GL11.GL_SMOOTH); +// RenderBuffer worldrenderer = Tessellator.getBuffer(); +// worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); +// worldrenderer.pos((double)right, (double)top, 0.0).color(f1, f2, f3, f).endVertex(); +// worldrenderer.pos((double)left, (double)top, 0.0).color(f1, f2, f3, f).endVertex(); +// worldrenderer.pos((double)left, (double)bottom, 0.0).color(f5, f6, f7, f4).endVertex(); +// worldrenderer.pos((double)right, (double)bottom, 0.0).color(f5, f6, f7, f4).endVertex(); +// Tessellator.draw(); +// GlState.shadeModel(GL11.GL_FLAT); +// GlState.disableBlend(); +// GlState.enableAlpha(); +// GlState.enableTexture2D(); +// } + + public void drawMainBackground() { + if(this.gm.world != null && !this.gm.charEditor) { +// Drawing.drawGradient(0, 0, this.fb_x, this.fb_y, this.theWorld == null ? this.style.bg_top : 0x3f202020, +// this.theWorld == null ? this.style.bg_btm : 0x3f000000); + Drawing.drawGradient(0, 0, this.gm.fb_x, this.gm.fb_y, 0xc0101010, 0xd0101010); + } + else { + Drawing.drawScaled(this.gm, DIRT_BACKGROUND); + } + } + + public void render() { + this.drawMainBackground(); + this.drawBackground(); + if(this.gm.fb_x != 0 && this.gm.fb_y != 0) + this.draw(); + GlState.bindTexture(0); + GlState.setActiveTexture(GL13.GL_TEXTURE0); + GlState.enableTexture2D(); + GlState.disableDepth(); + this.drawPost(); + GlState.disableDepth(); + this.drawOverlays(); + if(Bind.isWindowActive()) + this.drawOverlay(); + } +} diff --git a/client/src/client/gui/GuiConfirm.java b/client/src/client/gui/GuiConfirm.java new file mode 100755 index 00000000..901117cf --- /dev/null +++ b/client/src/client/gui/GuiConfirm.java @@ -0,0 +1,45 @@ +package client.gui; + +import client.gui.element.ActButton; +import client.gui.element.ButtonCallback; +import client.gui.element.Label; +import client.gui.element.PressType; +import client.gui.element.TransparentArea; + +public class GuiConfirm extends Gui implements ButtonCallback { + public static interface Callback { + void confirm(boolean confirmed); + } + + protected Callback callback; + protected String messageLine1; + private String messageLine2; + protected String confirmButtonText; + protected String cancelButtonText; + private ActButton confirmBtn; + private ActButton cancelBtn; + + public GuiConfirm(Callback callback, String msg1, String msg2, String msgConfirm, String msgCancel) { + this.callback = callback; + this.messageLine1 = msg1; + this.messageLine2 = msg2; + this.confirmButtonText = msgConfirm; + this.cancelButtonText = msgCancel; + } + + public void init(int width, int height) { + this.add(new Label(0, 0, 500, 24, this.messageLine1, true)); + this.add(new TransparentArea(0, 80, 500, 300, this.messageLine2, this.gm.world != null && !this.gm.charEditor)); + this.confirmBtn = this.add(new ActButton(48, 500, 200, 24, this, this.confirmButtonText)); + this.cancelBtn = this.add(new ActButton(252, 500, 200, 24, this, this.cancelButtonText)); + this.shift(); + } + + public String getTitle() { + return "Aktion bestätigen"; + } + + public void use(ActButton btn, PressType mode) { + this.callback.confirm(btn == this.confirmBtn); + } +} diff --git a/client/src/client/gui/GuiConnect.java b/client/src/client/gui/GuiConnect.java new file mode 100644 index 00000000..789fcf0f --- /dev/null +++ b/client/src/client/gui/GuiConnect.java @@ -0,0 +1,268 @@ +package client.gui; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Collections; +import java.util.Date; + +import client.gui.element.ActButton; +import client.gui.element.ButtonCallback; +import client.gui.element.GuiList; +import client.gui.element.ListEntry; +import client.gui.element.NavButton; +import client.gui.element.PressType; +import client.renderer.Drawing; +import common.color.TextColor; +import common.init.Config; +import common.log.Log; +import common.network.IPlayer; +import common.util.FileUtils; +import common.util.Tuple; +import common.util.Util; + +public class GuiConnect extends GuiList implements ButtonCallback { + public class ServerInfo implements Comparable, ListEntry { + private String name; + private String address; + private int port; + private String user; + private String password; + private String access; + private long lastConnected; + + public ServerInfo(String name, String address, int port, String user, String password, String access, long lastConnected) { + this.name = name; + this.address = address; + this.port = port; + this.user = user; + this.password = password; + this.access = access; + this.lastConnected = lastConnected; + } + + public String getName() { + return this.name; + } + + public String getAddress() { + return this.address; + } + + public int getPort() { + return this.port; + } + + public String getUser() { + return this.user; + } + + public String getPassword() { + return this.password; + } + + public String getAccess() { + return this.access; + } + + public long getLastConnected() { + return this.lastConnected; + } + + public void setData(String name, String address, int port, String user, String password, String access) { + this.name = name; + this.address = address; + this.port = port; + this.user = user; + this.password = password; + this.access = access; + } + + public void setLastConnected() { + this.lastConnected = System.currentTimeMillis(); + } + + public int compareTo(ServerInfo comp) { + return this.lastConnected < comp.lastConnected ? 1 : (this.lastConnected > comp.lastConnected ? -1 : this.name.compareTo(comp.name)); + } + + public void select(boolean isDoubleClick, int mouseX, int mouseY) { + GuiConnect.this.selectButton.enabled = true; + GuiConnect.this.deleteButton.enabled = true; + GuiConnect.this.editButton.enabled = true; + GuiConnect.this.copyButton.enabled = true; + + if(isDoubleClick) { + GuiConnect.this.use(GuiConnect.this.selectButton, PressType.PRIMARY); + } + } + + public void draw(int x, int y, int mouseXIn, int mouseYIn, boolean hover) { + Drawing.drawText(this.name + TextColor.GRAY + " - " + TextColor.RESET + this.user, x + 2, y, 0xffffffff); + Drawing.drawText(this.address + TextColor.GRAY + " Port " + TextColor.RESET + this.port, x + 2, y + 18, 0xff808080); + Drawing.drawText("Zuletzt verbunden: " + (this.lastConnected == -1L ? "nie" : DATE_FORMAT.format(new Date(this.lastConnected))), x + 2, y + 18 + 16, 0xff808080); + } + } + + public static final GuiConnect INSTANCE = new GuiConnect(); + private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); + private static final File SERVERS_FILE = new File("servers.cfg"); + + private ActButton deleteButton; + private ActButton selectButton; + private ActButton copyButton; + private ActButton editButton; + private ActButton createButton; + + private GuiConnect() { + } + + public void init(int width, int height) { + super.init(width, height); + this.setDimensions(width, height, 32, height - 32); + this.elements.clear(); + if(SERVERS_FILE.exists()) { + try { + String[] lines = FileUtils.read(SERVERS_FILE).split("\n"); + String name = ""; + String address = ""; + int port = -1; + String user = ""; + String password = ""; + String access = ""; + long time = -1L; + for(int z = 0; z <= lines.length; z++) { + String line = z == lines.length ? null : lines[z]; + if(line == null || (line.startsWith("[") && line.endsWith("]"))) { + if(!name.isEmpty() && !address.isEmpty() && !user.isEmpty() && user.length() < IPlayer.MAX_USER_LENGTH && IPlayer.isValidUser(user) && password.length() < IPlayer.MAX_PASS_LENGTH && access.length() < IPlayer.MAX_PASS_LENGTH && address.length() < 128 && name.length() < 128 && port >= 0 && port < 65536) + this.elements.add(new ServerInfo(name, address, port, user, password, access, time)); + if(line != null) { + address = ""; + port = -1; + user = ""; + password = ""; + access = ""; + time = -1L; + name = line.substring(1, line.length() - 1); + } + } + else { + Tuple value = Util.getKeyValue(line); + if(value.first.equals("address")) + address = value.second; + else if(value.first.equals("port")) + try { + port = Integer.parseInt(value.second); + } + catch(NumberFormatException e) { + } + else if(value.first.equals("user")) + user = value.second; + else if(value.first.equals("password")) + password = value.second; + else if(value.first.equals("access")) + access = value.second; + else if(value.first.equals("connected")) + try { + time = Long.parseLong(value.second); + } + catch(NumberFormatException e) { + } + } + } + Collections.sort(this.elements); + } + catch(Exception e) { + Log.IO.error("Konnte Serverliste nicht laden", e); + this.elements.clear(); + } + } + + this.add(this.selectButton = new ActButton(width / 2 - 383, height - 28, 150, 24, this, "Verbinden")); + this.add(this.createButton = new ActButton(width - 204, 4, 200, 24, this, "Server hinzufügen ...")); + this.add(this.deleteButton = new ActButton(width / 2 - 75, height - 28, 150, 24, this, "Löschen")); + this.add(this.editButton = new ActButton(width / 2 + 79, height - 28, 150, 24, this, "Bearbeiten")); + this.add(this.copyButton = new ActButton(width / 2 - 229, height - 28, 150, 24, this, "Kopieren")); + this.add(new NavButton(width / 2 + 233, height - 28, 150, 24, GuiMenu.INSTANCE, "Abbrechen")); + + this.selectButton.enabled = false; + this.deleteButton.enabled = false; + this.editButton.enabled = false; + this.copyButton.enabled = false; + } + + public void onGuiClosed() { + this.save(); + } + + public void applyServer(ServerInfo server) { + if(this.selectedElement < 0) + this.elements.add(server); + this.save(); + this.gm.displayGuiScreen(this); + } + + private void save() { + try { + StringBuilder sb = new StringBuilder(); + for(ServerInfo server : this.elements) { + if(sb.length() > 0) + sb.append("\n"); + sb.append("[" + server.getName() + "]\n"); + sb.append("address " + server.getAddress() + "\n"); + sb.append("port " + server.getPort() + "\n"); + sb.append("user " + server.getUser() + "\n"); + sb.append("password " + server.getPassword() + "\n"); + sb.append("access " + server.getAccess() + "\n"); + sb.append("connected " + server.getLastConnected()); + } + FileUtils.write(SERVERS_FILE, sb.toString()); + } + catch(Exception e) { + Log.IO.error("Konnte Serverliste nicht speichern", e); + } + } + + public String getTitle() { + return "Server auswählen"; + } + + public int getListWidth() { + return 660; + } + + public int getSlotHeight() { + return 56; + } + + public void use(ActButton button, PressType mode) { + if(button == this.deleteButton) { + if(this.selectedElement >= 0) { + this.elements.remove(this.selectedElement); + this.gm.displayGuiScreen(this); + } + } + else if(button == this.selectButton) { + ServerInfo server = this.getSelected(); + if(server != null) { + server.setLastConnected(); + this.gm.connect(server.address, server.port, server.user, server.password, server.access); + } + } + else if(button == this.createButton) { + this.setSelected(-1); + this.gm.displayGuiScreen(new GuiServer(new ServerInfo("", "", Config.PORT, "", "", "", -1L))); + } + else if(button == this.editButton) { + ServerInfo server = this.getSelected(); + if(server != null) + this.gm.displayGuiScreen(new GuiServer(server)); + } + else if(button == this.copyButton) { + ServerInfo server = this.getSelected(); + if(server != null) { + this.setSelected(-1); + this.gm.displayGuiScreen(new GuiServer(new ServerInfo(server.name, server.address, server.port, server.user, server.password, server.access, -1L))); + } + } + } +} diff --git a/client/src/main/java/client/gui/GuiConsole.java b/client/src/client/gui/GuiConsole.java similarity index 82% rename from client/src/main/java/client/gui/GuiConsole.java rename to client/src/client/gui/GuiConsole.java index 5d46f2e1..d3c6aca3 100644 --- a/client/src/main/java/client/gui/GuiConsole.java +++ b/client/src/client/gui/GuiConsole.java @@ -4,63 +4,26 @@ import java.util.List; import client.Client; import client.gui.element.ActButton; -import client.gui.element.Area; import client.gui.element.ButtonCallback; -import client.gui.element.Element; import client.gui.element.Fill; import client.gui.element.PressType; -import client.renderer.Drawing; import client.gui.element.FieldAction; import client.gui.element.Field; import client.gui.element.FieldCallback; +import client.network.ClientPlayer; import client.vars.BoolVar; import client.vars.CVar; +import client.gui.element.TransparentArea; import client.window.Keysym; import common.collect.Lists; +import common.color.TextColor; import common.network.IPlayer; import common.packet.CPacketComplete; import common.util.BlockPos; import common.util.ExtMath; import common.util.HitPosition; -import common.util.Color; public class GuiConsole extends Gui implements FieldCallback { - private class ConsoleArea extends Area { - private final boolean background; - - public ConsoleArea(int x, int y, int w, int h, String text, boolean background) { - super(x, y, w, h, text); - this.background = background; - } - - protected void drawBackground() { - if(this.background) - Drawing.drawRect(this.pos_x, this.pos_y, this.size_x, this.size_y, 0x3f000000); - } - - protected void onDoubleClick() { - if(this.sel_start >= 0 && this.sel_end == this.sel_start) { - for(int z = this.sel_start; z >= 0; z--) { - char c = this.text.charAt(z); - if(c == Color.COMMAND) { - for(int n = z + 1; n < this.text.length(); n++) { - c = this.text.charAt(n); - if(c < 0x20) { - GuiConsole.this.send("/" + this.text.substring(z + 1, n), false); - return; - } - } - break; - } - else if(c < 0x20) { - break; - } - } - } - super.onDoubleClick(); - } - } - public static final GuiConsole INSTANCE = new GuiConsole(); private final List sentMessages = Lists.newArrayList(); @@ -76,7 +39,7 @@ public class GuiConsole extends Gui implements FieldCallback { private int autocompleteIndex; private List foundPlayerNames = Lists.newArrayList(); private Field inputField; - private ConsoleArea logBox; + private TransparentArea logBox; public GuiConsole setFull(boolean full) { this.full = full; @@ -85,20 +48,20 @@ public class GuiConsole extends Gui implements FieldCallback { public void init(int width, int height) { if(this.full) { - this.addSelector("con_autoclose", 0, 0, 160, 0); - this.addSelector("con_timestamps", 160, 0, 160, 0); - this.addSelector("con_loglevel", 320, 0, 160, 0); - this.add(new ActButton(480, 0, 160, 0, new ButtonCallback() { + this.addSelector("con_autoclose", 0, 0, 160, 24); + this.addSelector("con_timestamps", 160, 0, 160, 24); + this.addSelector("con_loglevel", 320, 0, 160, 24); + this.add(new ActButton(480, 0, 160, 24, new ButtonCallback() { public void use(ActButton elem, PressType action) { GuiConsole.this.reset(); GuiConsole.this.setLog(GuiConsole.this.gm.getBuffer()); } }, "Löschen")); } - this.logBox = this.add(new ConsoleArea(0, this.full ? Element.BASE_HEIGHT : 0, width, height - Element.BASE_HEIGHT * (this.full ? 2 : 1), this.gm.getBuffer(), this.gm.world != null && !this.gm.charEditor)); + this.logBox = this.add(new TransparentArea(0, this.full ? 24 : 0, width, height - (this.full ? 48 : 24), this.gm.getBuffer(), this.gm.world != null && !this.gm.charEditor)); if(this.full) - this.add(new Fill(640, 0, width - 640, 0)); - this.inputField = this.add(new Field(0, height - Element.BASE_HEIGHT, width, 0, IPlayer.MAX_CMD_LENGTH, this, "")); + this.add(new Fill(640, 0, width - 640, 24)); + this.inputField = this.add(new Field(0, height - 24, width, 24, IPlayer.MAX_CMD_LENGTH, this, "")); this.inputField.setSelected(); this.sentHistoryCursor = this.sentMessages.size(); } @@ -152,24 +115,22 @@ public class GuiConsole extends Gui implements FieldCallback { { String s = this.inputField.getText().trim(); - this.send(s, true); + if (s.length() > 0) + { + if(this.sentMessages.isEmpty() || !((String)this.sentMessages.get(this.sentMessages.size() - 1)).equals(s)) + this.sentMessages.add(s); + this.sentHistoryCursor = this.sentMessages.size(); + this.gm.exec(s); +// if(this.gm.thePlayer != null) +// this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketMessage(CPacketMessage.Type.CHAT, s)); + } + + this.inputField.setText(""); + if((this.gm.conAutoclose || !this.full) && this.gm.world != null) + this.gm.displayGuiScreen(null); } } - protected void send(String text, boolean clear) { - if(!text.isEmpty()) { - if(this.sentMessages.isEmpty() || !((String)this.sentMessages.get(this.sentMessages.size() - 1)).equals(text)) - this.sentMessages.add(text); - this.sentHistoryCursor = this.sentMessages.size(); - this.gm.exec(text); - } - - if(clear) - this.inputField.setText(""); - if((this.gm.conAutoclose || !this.full) && this.gm.world != null) - this.gm.show(null); - } - protected void setText(String newChatText, boolean shouldOverwrite) { if (shouldOverwrite) @@ -189,7 +150,7 @@ public class GuiConsole extends Gui implements FieldCallback { int nl = buffer.indexOf('\n', offset); buffer = nl >= 0 ? buffer.substring(nl + 1) : ""; } - this.setLog(buffer + "\n" + Color.RESET + msg); + this.setLog(buffer + "\n" + TextColor.RESET + msg); } public void autocompletePlayerNames() @@ -257,7 +218,7 @@ public class GuiConsole extends Gui implements FieldCallback { s = argv[argv.length - 1]; Iterable res = pre.startsWith("#") ? (argv.length == 1 ? this.gm.getVars() : (argv.length == 2 ? getVarCompletion(argv[0].substring(1)) : Lists.newArrayList())) : - (this.gm.player == null ? Lists.newArrayList() : this.gm.playerList.keySet()); + (this.gm.player == null ? Lists.newArrayList() : ((ClientPlayer)this.gm.player.client).getPlayerNames()); if(argv.length == 1 && pre.startsWith("#")) s = s.substring(1); for(String s1 : res) { diff --git a/client/src/client/gui/GuiInfo.java b/client/src/client/gui/GuiInfo.java new file mode 100644 index 00000000..5653efb9 --- /dev/null +++ b/client/src/client/gui/GuiInfo.java @@ -0,0 +1,135 @@ +package client.gui; + +import client.gui.element.NavButton; +import client.gui.element.TransparentArea; +import common.color.TextColor; +import common.init.Config; +import common.log.Log; + +public class GuiInfo extends Gui { + private static final String VER = + TextColor.GREEN + "" + TextColor.BUG + "" + TextColor.BUG + "" + TextColor.BUG + " " + TextColor.VIOLET + "" + Config.CLIENT_VERSION + "" + + TextColor.GREEN + " " + TextColor.BUG + "" + TextColor.BUG + "" + TextColor.BUG; + + private static final String INFO = "Ein Spiel zur Simulation, zum Testen, für Rollenspiele, Mehrspieler und vieles mehr." + "\n" + + "Optimiert für Geschwindigkeit, Stabilität und" + TextColor.UNKNOWN + "" + TextColor.UNKNOWN + " [Speicherzugriffsfehler]"; + private static final String HACKED = "Ein weiterer Release von WAAAAAAAAAAAAAAAAAAAAAAAAAAAAGHDRIVE!!!1!!!ONEoneOnetyone!1!!!" + "\n" + + "Update 0.2 - Läuft jetzt auch mit nur 512KB Fast-RAM!"; + + private static final String[] LIBRARIES = { + "LWJGL 3.3.6+1 (GLFW + OpenGL)", + "Netty 4.1.119-Final" + }; + private static final String[] CODE = { + "Albert Pham - WorldEdit (Snippets)", + "Joonas Vali - NameGenerator", + "LWJGL 2.9.4-nightly-20150209 - Project, Vector*, Matrix*", + "Guava 17.0 - collect, future, Predicates", + "JOrbis 20101023 (JCraft) - jogg, jorbis, CodecJOrbis", + "MC 1.8.9" + }; + + public static final GuiInfo INSTANCE = new GuiInfo("Über dieses Programm", getFormat(false)); + public static final GuiInfo HAX = new GuiInfo("Üb3r d1es3n Cr4ck", getFormat(true)); + + private final String header; + private final String info; + + private static String getFormat(boolean hax) { + return getInfo(hax) + "\n\n" + getCredits(hax) + "\n\n" + getLibraries(hax) + "\n\n" + getCode(hax) + "\n\n" + getOldCredits(hax) + "\n\n" + getColors(); + } + + private static String getHeader(boolean hax, String normal, String hacked) { + return (hax ? TextColor.RED : TextColor.YELLOW) + (hax ? hacked : normal) + "\n" + + (hax ? TextColor.CYAN : TextColor.WHITE) + "==========================================+=========================================="; + } + + private static void addLines(StringBuilder sb, boolean hax, String alternate, String category, String... authors) { + sb.append("\n" + (hax ? TextColor.BLUE : TextColor.GRAY) + + (hax ? alternate : category) + "\n "); + for(int z = 0; z < authors.length; z++) { + if(z > 0) + sb.append((hax ? TextColor.VIOLET : TextColor.GRAY) + ", "); + sb.append((hax ? TextColor.DVIOLET : TextColor.WHITE) + authors[z]); + } + } + + private static String getInfo(boolean hax) { + return getHeader(hax, VER, VER) + "\n" + (hax ? (TextColor.VIOLET + HACKED) : (TextColor.LGRAY + INFO)); + } + + private static String getLibraries(boolean hax) { + StringBuilder sb = new StringBuilder(getHeader(hax, "Verwendete Programmbibliotheken", "U$3d 3xpl0its")); + for(String lib : LIBRARIES) { + sb.append("\n" + TextColor.LGRAY + "-> " + TextColor.NEON + lib); + } + return sb.toString(); + } + + private static String getCode(boolean hax) { + StringBuilder sb = new StringBuilder(getHeader(hax, "Zusätzlicher Quellcode", "M0ar 3xpl01ts")); + for(String lib : CODE) { + sb.append("\n" + TextColor.LGRAY + "-> " + TextColor.NEON + lib); + } + return sb.toString(); + } + + private static String getColors() { + StringBuilder sb = new StringBuilder(); + int num = 0; + for(TextColor color : TextColor.values()) { + if(num > 0) + sb.append(' '); + if((color.code >= Log.CHR_COLORS1 && color.code <= Log.CHR_COLORE1) || (color.code >= Log.CHR_COLORS2 && color.code <= Log.CHR_COLORE2)) { + sb.append(color + "#" + (char)(num < 10 ? ('0' + num) : ('A' + (num - 10)))); + num++; + } + } + return sb.toString(); + } + + private static String getOldCredits(boolean hax) { + StringBuilder sb = new StringBuilder(getHeader(hax, "Ursprüngliche Mitwirkende", "Das Team -- Nicht TCQ")); + + addLines(sb, hax, "Absolut größter Lamer des Universums", "Spielidee und ursprüngliche Umsetzung", + "Markus Persson"); + addLines(sb, hax, "Crack und weitere Programmierung", "Spiel-Design, Programmierung und Grafiken", + "Jens Bergensten", "Nathan Adams", "Ryan Holtz", "Michael Stoyke"); + addLines(sb, hax, "Entschlüsselung von Ressourcen", "Programmierung", + "Erik Broes", "Paul Spooner", "Ryan Hitchman", "Elliot Segal"); + addLines(sb, hax, "Cracktro, Grafiken und Intromusik", "Töne und Geräusche", + "Daniel Rosenfeld", "freesound.org"); + addLines(sb, hax, "Packing und Verbreitung", "Management, Administration und Spaß", + "Carl Manneh", "Daniel Kaplan", "Lydia Winters"); + addLines(sb, hax, "Server und Hosting", "Zahlen und Statistiken", + "Patrick Geuder"); + addLines(sb, hax, "Weiterer Dank und Grüße", "Entwickler von Mo' Creatures (Pferde usw.)", + "John Olarte", "Kent Christian Jensen", "Dan Roque"); + + return sb.toString(); + } + + private static String getCredits(boolean hax) { + StringBuilder sb = new StringBuilder(getHeader(hax, "Mitwirkende dieses Programms", "Das Team -- TCQ")); + + addLines(sb, hax, "Die dunklen Herrscher", "Quellcode, Design, Grafiken, Refactoring und Code-Cleanup", + TextColor.CYAN + "Sen der \"kleine\" Dämon " + TextColor.CRIMSON + TextColor.DEMON + TextColor.BLACK + TextColor.BLKHEART, + TextColor.RED + "Shen, Herrscher des Schattenlandes " + TextColor.CRIMSON + TextColor.IMP); + + return sb.toString(); + } + + public GuiInfo(String header, String info) { + this.header = header; + this.info = info; + } + + public void init(int width, int height) { + this.add(new TransparentArea(10, 10, width - 20, height - 44, this.info, this.gm.world != null && !this.gm.charEditor)); + this.add(new NavButton(0, height - 24, width, 24, GuiMenu.INSTANCE, "Zurück")); + } + + public String getTitle() { + return this.header; + } +} diff --git a/client/src/main/java/client/gui/GuiLoading.java b/client/src/client/gui/GuiLoading.java similarity index 91% rename from client/src/main/java/client/gui/GuiLoading.java rename to client/src/client/gui/GuiLoading.java index 26f5b8a6..f51592b8 100644 --- a/client/src/main/java/client/gui/GuiLoading.java +++ b/client/src/client/gui/GuiLoading.java @@ -46,11 +46,11 @@ public class GuiLoading extends Gui { } public void init(int width, int height) { - this.taskLabel = this.add(new Label(0, 40, 500, 0, "")); - this.progressBar1 = this.add(new Bar(0, 80, 500, 0)); - this.progressBar2 = this.add(new Bar(0, 120, 500, 0)); + this.taskLabel = this.add(new Label(0, 40, 500, 20, "")); + this.progressBar1 = this.add(new Bar(0, 80, 500, 24)); + this.progressBar2 = this.add(new Bar(0, 120, 500, 24)); this.shift(); - this.headerLabel = this.add(new Label(0, 40, width, 0, this.message)); + this.headerLabel = this.add(new Label(0, 40, width, 20, this.message)); this.progressBar1.visible = false; this.progressBar2.visible = false; } diff --git a/client/src/client/gui/GuiMenu.java b/client/src/client/gui/GuiMenu.java new file mode 100644 index 00000000..fd2093b4 --- /dev/null +++ b/client/src/client/gui/GuiMenu.java @@ -0,0 +1,301 @@ +package client.gui; + +import client.Timing; +import client.gui.character.GuiChar; +import client.gui.character.GuiCharacters; +import client.gui.element.ActButton; +import client.gui.element.ButtonCallback; +import client.gui.element.Label; +import client.gui.element.NavButton; +import client.gui.element.PressType; +import client.gui.options.GuiOptions; +import client.renderer.Drawing; +import client.window.Keysym; +import common.color.TextColor; +import common.init.Config; +import common.rng.Random; +import common.util.ExtMath; + +public class GuiMenu extends Gui { + public static final GuiMenu INSTANCE = new GuiMenu(); + + private GuiMenu() { + } + + public void drawMainBackground() { + if(this.gm.world != null) + super.drawMainBackground(); + else + this.gm.renderGlobal.renderStarField(this.gm.fb_x, this.gm.fb_y, 0x000000, 0xffffff, (float)this.ticks + (float)Timing.tick_fraction, this.rand); + } + + private final Random rand = new Random(); + + private Label splashLabel; + private ActButton infoButton; + + private int ticks; + private int hacked; + + private int animWidth = 32; + private int animGrowth = 10; + private int[] animGrow = new int[this.animWidth]; + private String animStr = ""; + private String animBack = ""; + private int animPos; + private int animLen; + private int animDir; + private boolean animStep; + + public void init(int width, int height) { + if(this.gm.world == null) { + this.ticks = 0; + this.hacked = 0; + this.resetAnimation(); + this.add(new ActButton(0, -28, 400, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { + if(GuiMenu.this.hacked == 9) { + GuiMenu.this.hacked++; + GuiMenu.this.splashLabel.setText(TextColor.VIOLET + "Hax!"); + } + else { + GuiMenu.this.gm.displayGuiScreen(GuiConnect.INSTANCE); + } + } + }, "Server beitreten")); + this.add(new NavButton(0, 0, 400, 24, GuiServer.INSTANCE, "Schnellverbindung")); + this.add(new ActButton(0, 28, 400, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { + if(GuiMenu.this.hacked == 8) + GuiMenu.this.hacked++; + else + GuiMenu.this.gm.displayGuiScreen(GuiOptions.getPage()); + } + }, "Einstellungen")); + this.infoButton = this.add(new ActButton(0, 56, 400, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { + GuiMenu.this.gm.displayGuiScreen(GuiMenu.this.hacked == 10 ? GuiInfo.HAX : GuiInfo.INSTANCE); + } + }, "Info / Über / Mitwirkende") { + public void drawHover() { + if(GuiMenu.this.hacked == 10) { + Drawing.drawRect(this.pos_x, this.pos_y, this.size_x, this.size_y, 0x287f00ff); + GuiMenu.this.rand.setSeed(((long)this.gm.mouse_x * 7652657L) ^ ((long)this.gm.mouse_y * 87262826276L)); + int width = Drawing.getWidth("Hax!"); + for(int z = 0; z < 64; z++) { + Drawing.drawText("Hax!", GuiMenu.this.rand.zrange(Math.max(1, this.gm.fb_x - width)) + + (int)(ExtMath.sin(((float)(GuiMenu.this.ticks + GuiMenu.this.rand.zrange(256)) + (float)Timing.tick_fraction) / 100.0f * (float)Math.PI * 2.0f) * 16.0f), + GuiMenu.this.rand.zrange(Math.max(1, this.gm.fb_y - Font.YGLYPH)) + + (int)(ExtMath.sin(((float)(GuiMenu.this.ticks + GuiMenu.this.rand.zrange(256)) + (float)Timing.tick_fraction) / 100.0f * (float)Math.PI * 2.0f) * 16.0f), + 0xff0000ff | (GuiMenu.this.rand.zrange(256) << 16)); + } + } + else { + super.drawHover(); + } + } + }); + this.add(new ActButton(0, 102, 400, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { + GuiMenu.this.gm.interrupted = true; + } + }, "Client schließen")); + this.shift(); + this.add(new Label(4, /* this.gm.fb_y - 2 */ 0, 200, 20, TextColor.VIOLET + Config.CLIENT_VERSION, true)); + this.splashLabel = this.add(new Label(0, 160, width, 24, "")); + this.pickSplash(); + } + else { + this.add(new NavButton(0, 0, 400, 24, this.gm.charEditor ? GuiChar.INSTANCE : null, this.gm.charEditor ? "Zurück zum Charakter-Editor" : "Zurück zum Spiel")); + this.add(new NavButton(0, 28, this.gm.charEditor ? 400 : 198, 24, GuiOptions.getPage(), "Einstellungen")); + if(!this.gm.charEditor) + this.add(new NavButton(202, 28, 198, 24, GuiCharacters.INSTANCE, "Charakter")); + this.add(new ActButton(0, 102, 400, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { + GuiMenu.this.gm.unload(true); +// GuiMenu.this.gm.displayGuiScreen(INSTANCE); + } + }, "Server verlassen und Verbindung trennen")); + this.shift(); + } + } + + public String getTitle() { + return this.gm.world == null ? "Hauptmenü" : "Menü"; + } + + private void pickSplash() { + this.splashLabel.setText(TextColor.VIOLET + this.rand.pick(Splashes.SPLASHES)); + } + + private void resetAnimation() { + this.animStr = ""; + this.animBack = ""; + this.animPos = 0; + this.animLen = 0; + this.animDir = 0; + this.animStep = false; + this.animWidth = Math.max(5, (this.gm.fb_x - 5) / 10); + this.animGrowth = this.animWidth / 15; + this.animGrow = new int[this.animWidth]; + } + + private void updateAnimation() { + if(this.animLen == 0) { + this.animDir = this.rand.zrange(3) - 1; + this.animLen = this.animDir == 0 ? (2 + this.rand.zrange(2)) : (8 + this.rand.zrange(96)); + } + else { + this.animPos += this.animDir; + if(this.animPos == -1) { + this.animPos = 0; + this.animDir = 1; + } + else if(this.animPos == this.animWidth - 3) { + this.animPos = this.animWidth - 4; + this.animDir = -1; + } + this.animLen--; + } + this.animStep = !this.animStep; + StringBuilder sb = new StringBuilder(11); + sb.append(TextColor.GRAY); + sb.append("["); + sb.append(TextColor.YELLOW); + switch(this.animDir) { + case -1: + sb.append((this.animStep ? '>' : '-') + "' "); + break; + case 0: + sb.append("`" + (this.animStep ? 'O' : 'o') + "'"); + break; + case 1: + sb.append(" `" + (this.animStep ? '<' : '-')); + break; + } + sb.append(TextColor.GRAY); + sb.append("]"); + this.animStr = sb.toString(); + for(int z = this.animPos; z < this.animPos + 4; z++) { + this.animGrow[z] = 0; + } + for(int z = 0; z < this.animGrowth; z++) { + this.animGrow[this.rand.zrange(this.animWidth)] += 1; + } + sb = new StringBuilder(this.animWidth + 2); + sb.append(TextColor.DGREEN); + for(int z = 0; z < this.animWidth; z++) { + switch(this.animGrow[z] / 5) { + case 0: + sb.append(TextColor.BLACK); + break; + case 1: + sb.append(TextColor.GRAY); + break; + case 2: + case 3: + sb.append(TextColor.LGRAY); + break; + case 4: + case 5: + case 6: + sb.append(TextColor.WHITE); + break; + case 7: + case 8: + case 9: + case 10: + sb.append(TextColor.MAGENTA); + break; + case 11: + case 12: + case 13: + case 14: + case 15: + sb.append(TextColor.DVIOLET); + break; + default: + sb.append(TextColor.VIOLET); + break; + } + sb.append(",."); + } + this.animBack = sb.toString(); + } + + public void updateScreen() { + if(this.gm.world == null) { + this.ticks++; + if(this.gm.shift()) + this.pickSplash(); + this.updateAnimation(); + } + } + + public void key(Keysym key, boolean ctrl, boolean shift) { + super.key(key, ctrl, shift); + if(this.gm.world == null) { + if((key == Keysym.UP || key == Keysym.W) && (this.hacked == 0 || this.hacked == 1)) + this.hacked++; + else if((key == Keysym.DOWN || key == Keysym.S) && (this.hacked == 2 || this.hacked == 3)) + this.hacked++; + else if((key == Keysym.LEFT || key == Keysym.A) && (this.hacked == 4 || this.hacked == 6)) + this.hacked++; + else if((key == Keysym.RIGHT || key == Keysym.D) && (this.hacked == 5 || this.hacked == 7)) + this.hacked++; + else + this.hacked = 0; + } + } + + /* + protected void actionPerformed(Button button) throws IOException { + if(button.id == 2 && this.hacked == 8) { + this.hacked++; + return; + } + else if(button.id == 1 && this.hacked == 9) { + this.hacked++; + return; + } + if(button.id != 3 || this.hacked != 10) + this.hacked = 0; + switch(button.id) { + case 0: + this.gm.displayGuiScreen(new GuiOptions(this)); + break; + case 1: + this.gm.displayGuiScreen(new GuiWorlds(this)); + break; + case 2: + this.gm.displayGuiScreen(new GuiMultiplayer(this)); + break; + case 3: + if(this.hacked == 10) + Log.info("Hax!"); + this.gm.displayGuiScreen(new GuiCredits(this.hacked == 10)); + this.hacked = 0; + break; +// case 4: +// this.gm.displayGuiScreen(new GuiLanguage()); +// break; + case 4: + this.gm.shutdown(); + break; + } + } + */ + + public void drawOverlays() { + super.drawOverlays(); + if(this.gm.world == null) { + int y = 164; + int h = 16; + int n = Drawing.getWidth(this.splashLabel.getText()); + Drawing.drawRect(0, y, this.gm.fb_x / 2 - n / 2 - 10, h, 0x7f7f00ff); + Drawing.drawRect(this.gm.fb_x / 2 + n / 2 + 10, y, this.gm.fb_x - (this.gm.fb_x / 2 + n / 2 + 10), h, 0x7f7f00ff); + Drawing.drawText(this.animBack, this.gm.fb_x - Drawing.getWidth(this.animBack), this.gm.fb_y - 18, 0xffffffff); + Drawing.drawText(this.animStr, this.gm.fb_x - Drawing.getWidth(this.animStr) - 3 - ((this.animWidth - this.animPos - 4) * 10), this.gm.fb_y - 20, 0xffffffff); + } + } +} diff --git a/client/src/client/gui/GuiServer.java b/client/src/client/gui/GuiServer.java new file mode 100644 index 00000000..3cb509e2 --- /dev/null +++ b/client/src/client/gui/GuiServer.java @@ -0,0 +1,149 @@ +package client.gui; + +import client.gui.GuiConnect.ServerInfo; +import client.gui.element.ActButton; +import client.gui.element.ButtonCallback; +import client.gui.element.Label; +import client.gui.element.NavButton; +import client.gui.element.PressType; +import client.gui.element.FieldAction; +import client.gui.element.Field; +import client.gui.element.FieldCallback; +import client.vars.CVarCategory; +import client.vars.Variable; +import common.color.TextColor; +import common.init.Config; +import common.network.IPlayer; + +public class GuiServer extends Gui implements FieldCallback { + public static final GuiServer INSTANCE = new GuiServer(null); + + private final ServerInfo server; + + private Field nameBox; + private Field addrBox; + private Field portBox; + private Field userBox; + private Field passBox; + private Field accBox; + private Label nameLabel; + private Label addrLabel; + private Label portLabel; + private Label userLabel; + private Label passLabel; + private Label accLabel; + + public GuiServer(ServerInfo server) { + this.server = server; + } + + @Variable(name = "srv_last_address", category = CVarCategory.SYSTEM, min = 1, max = 128, display = "Letzte Server-Adresse") + private String lastAddr = ""; + @Variable(name = "srv_last_port", category = CVarCategory.SYSTEM, min = 0, max = 65535, display = "Letzter Server-Port") + private int lastPort = Config.PORT; + @Variable(name = "srv_last_user", category = CVarCategory.SYSTEM, max = IPlayer.MAX_USER_LENGTH, display = "Letzter Server-Nutzer", validator = IPlayer.UserValidator.class) + private String lastUser = ""; + @Variable(name = "srv_last_password", category = CVarCategory.SYSTEM, max = IPlayer.MAX_PASS_LENGTH, display = "Letztes Server-Passwort") + private String lastPass = ""; + @Variable(name = "srv_last_access", category = CVarCategory.SYSTEM, max = IPlayer.MAX_PASS_LENGTH, display = "Letzter Server-Zugang") + private String lastAcc = ""; + + public void init(int width, int height) { + if(this.server != null) + this.nameBox = this.add(new Field(0, -50, 400, 24, 128, this, this.server.getName())); + this.addrBox = this.add(new Field(0, 20, 400, 24, 128, this, this.server == null ? this.lastAddr : this.server.getAddress())); + this.portBox = this.add(new Field(404, 20, 76, 24, 5, this, "" + (this.server == null ? this.lastPort : this.server.getPort()))); + this.userBox = this.add(new Field(0, 70, 220, 24, IPlayer.MAX_USER_LENGTH, this, IPlayer.VALID_USER, this.server == null ? this.lastUser : this.server.getUser())); + this.passBox = this.add(new Field(0, 120, 480, 24, IPlayer.MAX_PASS_LENGTH, this, this.server == null ? this.lastPass : this.server.getPassword())); + this.accBox = this.add(new Field(0, 170, 480, 24, IPlayer.MAX_PASS_LENGTH, this, this.server == null ? this.lastAcc : this.server.getAccess())); + this.add(new ActButton(0, 220, 480, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { + GuiServer.this.connect(); + } + }, this.server == null ? "Verbinden" : (this.server.getName().isEmpty() ? "Hinzufügen" : "Übernehmen"))); + this.add(new NavButton(0, 250, 480, 24, this.server != null ? GuiConnect.INSTANCE : GuiMenu.INSTANCE, "Zurück")); + if(this.server != null) + this.nameLabel = this.add(new Label(0, -70, 410, 20, "Name", true)); + this.addrLabel = this.add(new Label(0, 0, 410, 20, "Adresse", true)); + this.portLabel = this.add(new Label(414, 0, 66, 20, "Port", true)); + this.userLabel = this.add(new Label(0, 50, 220, 20, "Nutzer", true)); + this.passLabel = this.add(new Label(0, 100, 480, 20, "Passwort", true)); + this.accLabel = this.add(new Label(0, 150, 480, 20, "Zugang", true)); + this.shift(); + } + + public String getTitle() { + return this.server == null ? "Mit Server verbinden" : (this.server.getName().isEmpty() ? "Server hinzufügen" : "Server bearbeiten"); + } + + private void connect() { + if(this.gm.world != null) + return; + String name = null; + if(this.server != null) { + name = this.nameBox.getText(); + if(name.isEmpty()) { + this.nameLabel.setText(TextColor.RED + "Name"); + return; + } + } + String addr = this.addrBox.getText(); + if(addr.isEmpty()) { + this.addrLabel.setText(TextColor.RED + "Adresse"); + return; + } + int port = -1; + if(this.portBox.getText().isEmpty()) { + this.portLabel.setText(TextColor.RED + "Port"); + return; + } + else { + try { + port = Integer.parseInt(this.portBox.getText()); + } + catch(NumberFormatException e) { + } + if(port < 0 || port > 65535) { + this.portLabel.setText(TextColor.RED + "Port"); + return; + } + } + String user = this.userBox.getText(); + if(user.isEmpty()) { + this.userLabel.setText(TextColor.RED + "Nutzer"); + return; + } + String pass = this.passBox.getText(); + String acc = this.accBox.getText(); + if(this.server == null) { + this.lastAddr = addr; + this.lastPort = port; + this.lastUser = user; + this.lastPass = pass; + this.lastAcc = acc; + this.gm.setDirty(); + this.gm.connect(addr, port, user, pass, acc); + } + else { + this.server.setData(name, addr, port, user, pass, acc); + GuiConnect.INSTANCE.applyServer(this.server); + } + } + + public void use(Field elem, FieldAction value) { + if(value == FieldAction.SEND) { + elem.setDeselected(); + this.connect(); + } + else if(value == FieldAction.FOCUS) { + if(elem == this.addrBox) + this.addrLabel.setText("Adresse"); + else if(elem == this.portBox) + this.portLabel.setText("Port"); + else if(elem == this.userBox) + this.userLabel.setText("Nutzer"); + else if(this.server != null && elem == this.nameBox) + this.nameLabel.setText("Name"); + } + } +} diff --git a/client/src/main/java/client/gui/Splashes.java b/client/src/client/gui/Splashes.java similarity index 75% rename from client/src/main/java/client/gui/Splashes.java rename to client/src/client/gui/Splashes.java index de6257e0..78711ab1 100644 --- a/client/src/main/java/client/gui/Splashes.java +++ b/client/src/client/gui/Splashes.java @@ -2,34 +2,35 @@ package client.gui; public abstract class Splashes { public static final String[] SPLASHES = { - "Aus der Toiletten-Werbung!", + "Aus der TV-Werbung!", + "Toll!", "0% pur!", "Kann Nüsse enthalten!", - "Kann *.,-#+~ enthalten!", + "Besser als Crysis!", "Mehr Polygone!", "Sexy!", "Limitierte Edition!", "Blinkende Buchstaben!", - "Erstellt von Satan!", - "Er ist hier!", - "Das Schlimmste seiner Klasse!", - "Es ist vollendet (nicht)!", + "Erstellt von Notch!", + "Es ist hier!", + "Das Beste seiner Klasse!", + "Es ist vollendet!", "Mehr oder weniger frei von Drachen!", "Aufregung!", "Weniger als -5 verkauft!", "Einzigartig!", "Einen Haufen Scheiße auf YouTube!", - "Dev!", - "Alpha!", - "Beta!", + "Indev!", "Spinnen überall!", "Schau es dir an!", "Heilige Kuh, mann!", "Es ist ein Spiel!", - "Hergestellt im Schattenland!", + "Hergestellt in Schweden!", "Benutzt LWJGL!", "Retikulierende Splinen!", + "Meine Kraft!", "Hurraaa!", + "Einzelspieler!", "Tastatur ist kompatibel!", "Undokumentiert!", "Barren!", @@ -40,14 +41,17 @@ public abstract class Splashes { "Überlebe!", "Verlies!", "Exklusiv!", + "Die Knie der Biene!", + "Weg mit O.P.P.!", "Mit Quellcode (mehr oder weniger)!", "Mit Klasse(n)!", "Wow!", - "Niemals auf Steam - und das ist auch gut so!", + "Immer noch nicht auf Steam - und das ist auch gut so!", "Oh, mann!", "Grauenvolle Community!", "Pixel!", - "Garfiiieeeeeeeld!", + "Teetsuuuuoooo!", + "Kaaneeeedaaaa!", "Jetzt ohne Schwierigkeit!", "Verbessert!", "9% frei von Bugs!", @@ -55,26 +59,31 @@ public abstract class Splashes { "13 Kräuter und Gewürze!", "Fettfrei!", "Absolut keine Memes!", - "Kostenlose Vampirzähne!", + "Kostenlose Zähne!", "Fragen Sie Ihnen Arzt oder Apotheker!", "Alle Bergleute sind willkommen!", "Cloud-Computing!", - "Frei von \"\"KI\"\"!", - "Legal in Norwegen!", - "Illegal in China!", + "Legal in Finnland!", "Schwer zu beschreiben!", "Technisch gesehen gut!", + "Bringe den Speck nach Hause!", "Indie!", + "GOTY!", + "Ceci n'est pas une title screen!", "Euklidisch!", - "Jetzt in 4D?!", + "Jetzt in 3D!", "Bietet Inspiration!", + "Herregud!", + "Komplexe Zellvorgänge!", "Ja, Sir!", - "Ja, Miss!", - "Von Trollen gespielt!", + "Von Cowboys gespielt!", "OpenGL 1.5 oder höher!", - "Millionen von Farben!", + "Tausende von Farben!", "Probiere es!", + "Age of Wonders ist besser!", + "Probiere die Pilzsuppe!", "Sensationell!", + "Heiße Tamale, heiße heiße Tamale!", "Spiele ihn runter, Klavierkatze!", "Garantiert!", "Makroskopisch!", @@ -85,22 +94,27 @@ public abstract class Splashes { "Von Melonen geliebt!", "Ultimative Edition!", "Merkwürdig!", + "Du hast einen nagelneuen Schlüssel bekommen!", "Wasserfest!", "Nicht brennbar!", "Oha, du!", "Alles inklusive!", "Sag es deinen Freunden!", "NP ist nicht in P!", + "Musik von C418 (DLC)!", + "Viel zu oft live gestreamt!", "Heimgesucht!", "Polynomial!", "Terrestrisch!", "Alles ist voller Zerstörung!", "Voll mit Sternen, Planeten und Monden!", "Wissenschaftlich!", + "Nicht so cool wie Spock!", "Trage nix bei und höre weg!", "Grabe niemals nach unten, wenn du keine Erze brauchst!", "Mache nie Pause!", "Nicht linear!", + "Han hat zuerst geschossen!", "Schön dich zu sehen!", "Eimer mit Lava!", "Reite auf dem Schwein!", @@ -110,18 +124,25 @@ public abstract class Splashes { "Holz schlagen!", "Von Klippen fallen!", "0% Zucker!", - "180% Alkohol!", + "150% hyperbol!", + "Synecdoche!", "Lasst uns tanzne!", + "Geheeimes Freitags-Update!", "Referenz-Implementation!", "Frei mit zwei.. äähhh fünf Typen mit Essen!", "Küsse den Himmel!", "20 GOTO 10!", + "Verlet-Intregration!", + "Peter Griffin!", "Verteile die Erde gut!", - "8263273626252622872652 Zeilen Quellcode (287228 am 30.7.)!", + "Cogito ergo sum!", + "4815162342 Zeilen Quellcode (287228 am 30.7.)!", "Ein Skelett fiel heraus!", - "Das Werk von Luzifer!", + "Das Werk von Notch!", "Die Summe seiner Teile!", - "mureh srednA!", + "BTAF war mal gut!", + "Ich vermisse ADOM!", + "umop-apisdn!", "GTX750Ti!", "Bringe mir Mentos und Cola!", "Finger-leckend!", @@ -141,16 +162,25 @@ public abstract class Splashes { "Doppelt gepuffert!", "Fan-Fiction!", "Flaxkikare!", + "Jason! Jason! Jason!", "Heißer als die Sonne!", "Internet-Funktionalität!", "Autonom!", "Engagiere!", "Fantasie!", - "Mau! Mau! Mau!", + "DRR! DRR! DRR!", "Stoß es Wurzel runter!", "Regionale Ressourcen!", + "Jaa, facepunch!", + "Jaa, somethingawful!", + "Jaa, /v/!", + "Jaa, tigsource!", + "Jaa, weinkraftforum!", + "Jaa, worldofweinkraft!", + "Buu, reddit!", + "Jaa, 2pp!", "Goggle anllyticsed:DD :DDD:D!", - "Unterstützt jetzt äöüß!", + "Unterstützt jetzt äöü!", "Gebt uns Gordon!", "Gib deinem Kellner Trinkgeld!", "Macht viel Spaß!", @@ -161,12 +191,15 @@ public abstract class Splashes { "Allmächtig!", "Huch!", "...!", - "Bienen, Mienen, Minen, W-!", + "Bienen, Bienen, Bienen, Bienen!", + "Jag känner en bot!", "Dieser Text ist schwer bei der Standard-Auflösung zu lesen, aber auf 1080p ist es in Ordnung!", "Haha, LOL!", "Hampsterdance!", "Schalter und Erze!", "Menger-Schwamm!", + "idspispopd!", + "Eple (originale Version)!", "So frisch, so sauber!", "Schnell reagierende Portale!", "Probiere den Warp aus!", @@ -174,9 +207,10 @@ public abstract class Splashes { "Oh, ok, NPCs!", "Endlich mit Leitern!", "Gruselig!", + "Spiele Minenkraft, schaue Topgear, bekomme Schwein!", "Darüber gewittert!", "Spring hoch, spring hoch, und komme runter!", - "Strahlung ist klasse!", + "Joel ist klasse!", "Ein Rätsel, in einen Mythos verwoben!", "Riesige Landeszüge voll mit TNT!", "Willkommen zu deinem Ende! Muahahahahahaha!", @@ -188,21 +222,23 @@ public abstract class Splashes { "\"Fast nie\" ist ein interessantes Konzept!", "Eine Menge Wahrheitigkeit!", "Der TNT-Block ist ein Spion!", - "Turing-unvollständig!", + "Turing-vollständig!", "Es ist bahnbrechend!", "Lasst unsere Schlachten beginnen!", "Der Himmel ist die Grenze - oder auch nicht!", - "Dein PC hat tolle Haare, mach das Ding mal sauber!", - "Shen hat auch tolle Haare!", + "Jeb hat tolle Haare!", + "Ryan hat auch tolle Haare!", "Gelegentliches Spielen!", "Unbesiegt!", "Ein Bisschen wie Lemmings!", "Folge dem Zug, CJ!", "Macht von Synergie Verwendung!", - "Diese Nachricht sollte niemals als Splash-Text erscheinen, oder etwa doch? Trololololol!", + "Diese Nachricht wird niemals als Splash-Text erscheinen, ist das nicht komisch?", + "DungeonQuest ist unfair!", "0815!", "666!", "Geh zu den fernen Ländern und weiter!", + "Tyrion würde es lieben!", "Probiere auch Stellaris!", "Probiere auch Garry's Mod!", "Probiere auch GZDoom!", @@ -216,43 +252,52 @@ public abstract class Splashes { "Brot ist Schmerz!", "Lese mehr Bücher!", "Khaaaaaaaaan!", - "Weniger süchtig machend als [zensiert da NSFW]!", + "Weniger süchtig machend als TV Tropes!", "Mehr süchtig machend als Limonade!", "Größer als eine Brotkiste!", "Millionen von Pfirsichen!", + "Fnord!", "Dies ist meine echte Gestalt! Muahahahaha!", - "Verschwende keine Zeit mit \"\"KI\"\"!", - "Erstellt von einer Katze!", + "Habe Dre vollkommen vergessen!", + "Verschwende keine Zeit mit den Klonen!", + "Kürbiskopf!", + "Hobo humping slobo babe!", + "Erstellt von Jeb!", "Hat kein Ende!", "Endlich vollständig!", "Voll mit Features!", "Stiefel mit dem Fell!", "Stop, hammertime!", - "Test!", + "Testificates!", "Nicht konventionell!", - "Nicht kommerziell!", + "Homeomorphisch zu einer 3-Kugel!", "Vermeidet nicht doppelte Verneinung!", "Platziere ALL die Blöcke!", "Macht Walzen!", "Erfüllt Erwartungen!", - "Spielen am PC seit 1992!", + "Spielen am PC seit 1873!", + "Ghoughpteighbteau tchoghs!", "Deja vu!", "Deja vu!", "Hab deine Nase!", + "Haley liebt Elan!", "Hat keine Angst vor der großen, schwarzen Fledermaus!", "Benutzt nicht das U-Wort!", "Nicht wirklich leicht!", "Bis nächsten Freitag oder so!", - "Von den Straßen von Nibelheim!", + "Von den Straßen von Södermalm!", + "150 BPM für 400000 Minuten!", "Technologisch!", - "Hallo Japan!", + "Funk Soul Bruder!", + "Pumpa kungen!", + "Hallo Japan!", "Hallo Korea!", "Hallo Wales!", "Hallo Polen!", - "Hallo China!", + "Hallo China!", "Hallo Russland!", "Hallo Griechenland!", - "Mein Leben für Aiur (warte mal..)!", + "Mein Leben für Aiur!", "Lenny lenny = new Lenny(\"(°^°)\");", "Ich sehe dein Wortschatz hat sich verbessert!", "Wer hat es dort hin getan?", @@ -260,14 +305,14 @@ public abstract class Splashes { "if not ok then return end", "Mehrfarbig!", "FUNKY LOL", - "Copyright bedeutet LOSER in allen Sprachen!", + "SOPA bedeutet LOSER in Schwedisch!", "Große Spitze Zähne!", "Mein Shizun bewacht das Tor!", "Mmmph, mmph!", - "Füttere keine Landminen an Piranhas!", + "Füttere keine Avocados an Papageien!", "Schwerter für alle!", "Bitteee antworte meinem Tweet! (Nutzer wurde gebannt)", - ".party().crash().commitWarcrimes().forTheEmperor()!", + ".party()!", "Nehme ihr Kissen!", "Lege diesen Keks weg!", "Extrem gruselig!", @@ -275,21 +320,26 @@ public abstract class Splashes { "Jetzt mit extra Sprengstoff!", "Nicht kompatibel zu Java 6!", "Oha.", + "HURNERJSGER?", "Was'n los, Doc?", "Enthält jetzt 0 zufällige tägliche Katzen!", + "Das ist Numberwang!", "((pls rt)) -- Der Vogel ist tot!", "Willst du meinem Server beitreten?", "Mach einen großen Zaun drum herum! Oder du wirst v-", "Lege eine Landmine drüber!", - "Eines Tages, irgendwann in der Zukunft, wird mein Werk r3- ÄÄHHH kopiert werden!", + "Eines Tages, irgendwann in der Zukunft, wird mein Werk zitiert werden!", "Jetzt mit zusätzlichem Zeug!", "Zusätzliche Dinge!", "Hurra, Atombomben für alle!", - "So süß, wie ein schöner ****!", + "So süß, wie ein schöner Bon-Bon!", + "Poppende Tags!", "Sehr einflussreich in seinem Kreis!", "Jetzt mit Mehrspieler!", "Stehe aus deinem Grab auf!", "Warnung! Ein großes Kampfschiff \"SHEN\" nähert sich schnell!", + "Der blaue Krieger hat das Essen beschossen!", + "Renn, Feigling! Ich hunger!", "Geschmack ohne Würze!", "Seltsam, aber nicht fremd!", "Härter als Diamanten, Reich wie Creme!", @@ -305,13 +355,14 @@ public abstract class Splashes { "Bau mir einen Tisch, einen funkigen Tisch!", "Nehm den Aufzug in die Hölle!", "Hör auf vernünftig zu sein, das hier ist das Internet!", - "/give * tnt 67108864 7", + "/give @a tnt 67108864 7", "Das ist gut für 3D Realms.", "Jeder Computer ist ein Laptop, wenn du tapfer genug bist!", "Mach es alles, jede Sache!", "Wo ist kein Licht, da kann Spinne!", "GNU Terry Pratchett", - "Jetzt Java 21!", + "Jetzt Java 8!", + "MeinKraft!", "Immer noch zu viele Bugs!", "Wird nicht laggen!", "Er hat es ruiniert!", @@ -319,6 +370,7 @@ public abstract class Splashes { "OpenGL 2.0+ (definitiv nicht unterstützt)!", "Keine Segfaults (nicht) möglich!", "Keine Abstürze (un)möglich!", + "Alpha!", "Enthält Bugs!", "Enthält Mäuse!", "Enthält Gewalt!", @@ -327,7 +379,6 @@ public abstract class Splashes { "Du hattest eine. aufgabe.", "Spinnen können TNT1 A 0 sein!", "RTFM!", - "Hex, nur mit mehr Ameisen!", "Vorherrschaft des Imperiums!", "Vorherrschaft der Eldar!", "Vorherrschaft der Drukhari!", @@ -358,11 +409,6 @@ public abstract class Splashes { "Eimer mit Wasser!", "Hergestellt in Deutschland!", "Hergestellt in China!", - "Jetzt ohne Einzelspieler!", - "Jetzt mit tieferen Schluchten!", - "Was bist du denn für ein hübsches Ding?", - "[TEXT ZENSIERT]", - "Mehr Energie!", - "Maximale Energie!" + "Jetzt mit Einzelspieler!" }; } diff --git a/client/src/main/java/client/gui/Style.java b/client/src/client/gui/Style.java similarity index 91% rename from client/src/main/java/client/gui/Style.java rename to client/src/client/gui/Style.java index 367ae626..db7435f4 100644 --- a/client/src/main/java/client/gui/Style.java +++ b/client/src/client/gui/Style.java @@ -17,25 +17,25 @@ public enum Style implements Identifyable, Displayable { this.name = name; } - @Variable(type = IntType.COLOR, name = "color_border_top", category = CVarCategory.GUI, display = "Umrahmung A") + @Variable(type = IntType.COLOR, name = "color_border_top", category = CVarCategory.GUI, display = "Umrahmung oben / l.") public int brdr_top; - @Variable(type = IntType.COLOR, name = "color_border_btm", category = CVarCategory.GUI, display = "Umrahmung B") + @Variable(type = IntType.COLOR, name = "color_border_btm", category = CVarCategory.GUI, display = "Umrahmung unten / r.") public int brdr_btm; @Variable(type = IntType.COLOR, name = "color_button_top", category = CVarCategory.GUI, display = "Knopf oben") public int fill_top; @Variable(type = IntType.COLOR, name = "color_button_btm", category = CVarCategory.GUI, display = "Knopf unten") public int fill_btm; - @Variable(type = IntType.COLOR, name = "color_textbox_top", category = CVarCategory.GUI, display = "Eingabe oben") + @Variable(type = IntType.COLOR, name = "color_textbox_top", category = CVarCategory.GUI, display = "Textfeld oben") public int field_top; - @Variable(type = IntType.COLOR, name = "color_textbox_btm", category = CVarCategory.GUI, display = "Eingabe unten") + @Variable(type = IntType.COLOR, name = "color_textbox_btm", category = CVarCategory.GUI, display = "Textfeld unten") public int field_btm; @Variable(type = IntType.COLOR, name = "color_label_text", category = CVarCategory.GUI, display = "Beschriftung") public int text_label; @Variable(type = IntType.COLOR, name = "color_button_text", category = CVarCategory.GUI, display = "Knopf Text") public int text_base; - @Variable(type = IntType.COLOR, name = "color_textbox_text", category = CVarCategory.GUI, display = "Eingabe Text") + @Variable(type = IntType.COLOR, name = "color_textbox_text", category = CVarCategory.GUI, display = "Textfeld Text") public int text_field; static { diff --git a/client/src/main/java/client/gui/character/GuiChar.java b/client/src/client/gui/character/GuiChar.java similarity index 78% rename from client/src/main/java/client/gui/character/GuiChar.java rename to client/src/client/gui/character/GuiChar.java index 888bbac0..01117c01 100755 --- a/client/src/main/java/client/gui/character/GuiChar.java +++ b/client/src/client/gui/character/GuiChar.java @@ -8,7 +8,6 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.util.Arrays; -import java.util.List; import javax.imageio.ImageIO; @@ -17,32 +16,29 @@ import org.lwjgl.opengl.GL13; import client.Client; import client.Client.FileMode; +import client.SkinConverter; import client.gui.FileCallback; -import client.gui.Font; import client.gui.GuiLoading; import client.gui.element.ActButton; import client.gui.element.Element; import client.gui.element.GuiList; import client.gui.element.Label; import client.gui.element.ListEntry; -import client.gui.element.MultiLabel; import client.gui.element.NavButton; import client.gui.element.PressType; import client.gui.element.Slider; import client.gui.element.SliderCallback; -import client.init.DimensionMapping; import client.gui.element.FieldAction; import client.gui.element.Area; import client.gui.element.ButtonCallback; import client.gui.element.Field; import client.gui.element.FieldCallback; +import client.gui.element.TransparentArea; import client.renderer.Drawing; import client.renderer.GlState; import client.renderer.ItemRenderer; import client.renderer.entity.RenderManager; import client.renderer.texture.EntityTexManager; -import client.util.FileUtils; -import client.util.SkinConverter; import client.vars.CVarCategory; import client.vars.EnumVar; import client.vars.Variable; @@ -51,16 +47,16 @@ import client.window.Button; import common.collect.Lists; import common.dimension.DimType; import common.dimension.Dimension; -import common.dimension.Space; import common.entity.npc.Alignment; import common.entity.npc.CharacterInfo; import common.entity.npc.EntityHuman; import common.entity.npc.EntityNPC; import common.entity.npc.SpeciesInfo; import common.entity.types.EntityLiving; -import common.init.EntityInfo; +import common.init.EntityEggInfo; import common.init.EntityRegistry; import common.init.SpeciesRegistry; +import common.init.UniverseRegistry; import common.init.SpeciesRegistry.ModelType; import common.log.Log; import common.network.IPlayer; @@ -69,6 +65,7 @@ import common.packet.CPacketMessage; import common.packet.CPacketSkin; import common.rng.Random; import common.util.Displayable; +import common.util.FileUtils; import common.util.Identifyable; import common.util.Util; @@ -104,7 +101,7 @@ public class GuiChar extends GuiList } } - public void draw(int x, int y, int width, int height, int mouseX, int mouseY, boolean hovered) + public void draw(int x, int y, int mouseX, int mouseY, boolean hovered) { String str = (this.skinFile != null ? this.skinFile.getName() : ( @@ -116,7 +113,7 @@ public class GuiChar extends GuiList Drawing.drawText(str, x + 64 + 3, y, 0xff000000 | (this.charinfo == null ? 0xffffff : this.charinfo.color1 | this.charinfo.color2)); if(this.charinfo != null) - Drawing.drawTextRight(this.charinfo.skin, x + width - 2, y + height - Font.HEIGHT, 0xffc0c0c0); + Drawing.drawText(this.charinfo.skin, x + 64 + 3, y + 18, 0xffc0c0c0); GlState.color(1.0F, 1.0F, 1.0F, 1.0F); @@ -245,20 +242,17 @@ public class GuiChar extends GuiList public static class FilterFunction implements EnumFunction { public void apply(EnumVar cv, FilterType value) { if(Client.CLIENT.open instanceof GuiChar) - Client.CLIENT.show(Client.CLIENT.open); + Client.CLIENT.displayGuiScreen(Client.CLIENT.open); } } public static final GuiChar INSTANCE = new GuiChar(); private static final File TEXTURE_FOLDER = new File("skins"); - - private final List dimensions = Lists.newArrayList(); private ActButton templateButton; private DragAdjust adjust; private ActButton dimButton; - private MultiLabel descLines; - private ActButton cancelButton; + private TransparentArea descLines; private float yaw = -15.0f; private float pitch = -15.0f; private boolean waiting = true; @@ -274,12 +268,8 @@ public class GuiChar extends GuiList public void init(int width, int height) { super.init(width, height); - this.dimensions.clear(); - for(Dimension dim : DimensionMapping.getDimensions()) { - this.dimensions.add(dim); - } this.waiting = true; - this.setDimensions(390, height, 32, height - 32); + this.setDimensions(400, height, 32, height - 32); if(this.gm.getRenderManager().gm == null) { this.unload(); this.adjust = null; @@ -287,33 +277,33 @@ public class GuiChar extends GuiList } this.currentSkin = this.gm.player != null && !EntityTexManager.hasCustomSkin(this.gm.player.getId()) ? this.gm.player.getChar() : null; this.load(this.gm.player == null ? ModelType.HUMANOID : this.gm.player.getModel(), this.gm.player != null ? this.gm.player.getSpecies() : SpeciesRegistry.CLASSES.get(EntityHuman.class)); - this.add(new ActButton(2, 12, 193, 0, new ButtonCallback() { + this.add(new ActButton(4, 4, 194, 24, new ButtonCallback() { public void use(ActButton elem, PressType action) { GuiChar.this.gm.showFileDialog(FileMode.FILE_LOAD_MULTI, "Skin konvertieren", TEXTURE_FOLDER, new FileCallback() { public void selected(File file) { if(SkinConverter.convertSkin(file, TEXTURE_FOLDER, false)) - GuiChar.this.gm.show(GuiChar.this); + GuiChar.this.gm.displayGuiScreen(GuiChar.this); } }); } }, "Importieren: Standard")); - this.add(new ActButton(197, 12, 193, 0, new ButtonCallback() { + this.add(new ActButton(202, 4, 194, 24, new ButtonCallback() { public void use(ActButton elem, PressType action) { GuiChar.this.gm.showFileDialog(FileMode.FILE_LOAD_MULTI, "Skin konvertieren (schlank)", TEXTURE_FOLDER, new FileCallback() { public void selected(File file) { if(SkinConverter.convertSkin(file, TEXTURE_FOLDER, true)) - GuiChar.this.gm.show(GuiChar.this); + GuiChar.this.gm.displayGuiScreen(GuiChar.this); } }); } }, "Importieren: Schlank")); - this.addSelector("char_filter_species", 392, 12, 250, 0); - this.add(new ActButton(2, height - 30, 193, 0, new ButtonCallback() { + this.addSelector("char_filter_species", 400, 4, 300, 24); + this.add(new ActButton(4, height - 28, 194, 24, new ButtonCallback() { public void use(ActButton elem, PressType action) { - GuiChar.this.gm.show(GuiChar.this); + GuiChar.this.gm.displayGuiScreen(GuiChar.this); } }, "Neu laden")); - this.templateButton = this.add(new ActButton(197, height - 30, 193, 0, new ButtonCallback() { + this.templateButton = this.add(new ActButton(202, height - 28, 194, 24, new ButtonCallback() { public void use(ActButton elem, PressType action) { SkinEntry skin = GuiChar.this.getSelected(); if(skin != null && skin.getLocation() != null) { @@ -330,9 +320,9 @@ public class GuiChar extends GuiList } catch(Exception e) { if(e instanceof FileNotFoundException) - Log.IO.warn("Textur ist nicht zum Kopieren vorhanden: " + EntityNPC.getSkinTexture(loc)); + Log.JNI.warn("Textur ist nicht zum Kopieren vorhanden: " + EntityNPC.getSkinTexture(loc)); else - Log.IO.error(e, "Konnte Textur nicht kopieren"); + Log.JNI.error(e, "Konnte Textur nicht kopieren"); } finally { if(in != null) { @@ -343,27 +333,24 @@ public class GuiChar extends GuiList } } } - GuiChar.this.gm.show(GuiChar.this); + GuiChar.this.gm.displayGuiScreen(GuiChar.this); } } }, "Vorlage kopieren")); - if(width >= 784 + 460 && height >= 128 + 640) - this.adjust = this.add(new DragAdjust(width / 2 - 230, height - 64 - 640, 460, 640)); - else - this.adjust = this.add(new DragAdjust(390 - 115 - 4, height - 32 - 160 - 4, 115, 160)); + this.adjust = this.add(new DragAdjust(width / 2 - 230, height - 64 - 640, 460, 640)); - this.add(new Label(width - 390, 48, 388, "Spezies: " + (this.gm.player == null ? "" : this.gm.player.getSpecies().name), true)); - this.add(new NavButton(width - 390, 48, 388, 0, GuiSpecies.INSTANCE, "Spezies ändern")); - this.add(new Label(width - 390, 82, 388, "Klasse: " + (this.gm.player == null || this.gm.player.getSpecies().classEnum == null || this.gm.player.getNpcClass() == null || this.gm.player.getNpcClass().toString().isEmpty() ? "" : this.gm.player.getNpcClass().toString()), true)) + this.add(new Label(width - 396, 36, 392, 20, "Spezies: " + (this.gm.player == null ? "" : this.gm.player.getSpecies().name), true)); + this.add(new NavButton(width - 396, 56, 392, 24, GuiSpecies.INSTANCE, "Spezies ändern")); + this.add(new Label(width - 396, 36 + 92, 392, 20, "Klasse: " + (this.gm.player == null || this.gm.player.getSpecies().classEnum == null || this.gm.player.getNpcClass() == null || this.gm.player.getNpcClass().toString().isEmpty() ? "" : this.gm.player.getNpcClass().toString()), true)) .enabled = this.gm.player != null && this.gm.player.getSpecies().classEnum != null; - this.add(new NavButton(width - 390, 82, 388, 0, GuiClass.INSTANCE, "Klasse ändern")) + this.add(new NavButton(width - 396, 56 + 92, 392, 24, GuiClass.INSTANCE, "Klasse ändern")) .enabled = this.gm.player != null && this.gm.player.getSpecies().classEnum != null; final ActButton[] alignBtns = new ActButton[Alignment.values().length]; for (int z = 0; z < Alignment.values().length; z++) { final Alignment align = Alignment.values()[z]; - alignBtns[z] = this.add(new ActButton(width - 390 + (z % 3) * 130, height - 32 - 20 * 3 + 20 * (z / 3), 128, 0, new ButtonCallback() { + alignBtns[z] = this.add(new ActButton(width - 396 + (z % 3) * 132, height - 32 - 28 * 3 + 28 * (z / 3), 128, 24, new ButtonCallback() { public void use(ActButton elem, PressType action) { if(GuiChar.this.gm.player != null) { GuiChar.this.waiting = false; @@ -376,7 +363,7 @@ public class GuiChar extends GuiList }, align.color + align.display)); alignBtns[z].enabled = this.gm.player == null || this.gm.player.getAlignment() != align; } - this.add(new Slider(width - 390, 136, 388, 0, 1, this.gm.player == null ? 120 : this.gm.player.getMinSize(), this.gm.player == null ? 320 : this.gm.player.getMaxSize(), this.gm.player == null ? 180 : this.gm.player.getDefaultSize(), this.gm.player == null ? 180 : this.gm.player.getCurrentSize(), new SliderCallback() { + this.add(new Slider(width / 2 - 200, height - 28, 400, 24, 1, this.gm.player == null ? 120 : this.gm.player.getMinSize(), this.gm.player == null ? 320 : this.gm.player.getMaxSize(), this.gm.player == null ? 180 : this.gm.player.getDefaultSize(), this.gm.player == null ? 180 : this.gm.player.getCurrentSize(), new SliderCallback() { public void use(Slider elem, int value) { if(GuiChar.this.gm.player != null) { GuiChar.this.waiting = false; @@ -384,27 +371,20 @@ public class GuiChar extends GuiList } } }, "Spieler-Größe", "cm")).enabled = this.gm.player == null || this.gm.player.getMinSize() != this.gm.player.getMaxSize(); - this.add(new Label(width - 390, 116, 388, "Name", true)); - this.add(new Label(width - 390, 170, 388, "Beschreibung", true)); - final Area descField = this.add(new Area(width - 390, 170, 388, height - 328, IPlayer.MAX_INFO_LENGTH, "")); - this.add(new ActButton(width - 195, height - 30, 193, 0, new ButtonCallback() { + this.add(new Label(width / 2 - 200, 36, 400, 20, "Name", true)); + this.add(new Label(width - 396, height - 384, 392, 20, "Beschreibung", true)); + final Area descField = this.add(new Area(width - 396, height - 364, 392, 130, IPlayer.MAX_INFO_LENGTH, "")); + this.add(new ActButton(width - 198, height - 28, 194, 24, new ButtonCallback() { public void use(ActButton elem, PressType action) { if(GuiChar.this.gm.player != null) { - GuiChar.this.gm.show(GuiLoading.makeWaitTask("Lade Welt ...")); - Dimension dim = GuiChar.this.dimensions.get(GuiChar.this.dimension); + GuiChar.this.gm.displayGuiScreen(GuiLoading.makeWaitTask("Lade Welt ...")); + Dimension dim = UniverseRegistry.getBaseDimensions().get(GuiChar.this.dimension); GuiChar.this.gm.player.client.addToSendQueue(new CPacketMessage(CPacketMessage.Type.INFO, descField.getText())); - GuiChar.this.gm.player.client.addToSendQueue(new CPacketAction(CPacketAction.Action.CLOSE_EDITOR, DimensionMapping.getId(dim))); + GuiChar.this.gm.player.client.addToSendQueue(new CPacketAction(CPacketAction.Action.CLOSE_EDITOR, dim.getDimensionId())); } } }, "Charakter erstellen")); - this.cancelButton = this.add(new ActButton(width - 390, height - 30, 193, 0, new ButtonCallback() { - public void use(ActButton elem, PressType action) { - if(GuiChar.this.gm.player != null) - GuiChar.this.gm.show(GuiCharacters.INSTANCE); - } - }, "Abbrechen")); - this.setCharsAvailable(); - this.add(new Field(width - 390, 116, 388, 0, IPlayer.MAX_NICK_LENGTH, new FieldCallback() { + this.add(new Field(width / 2 - 200, 36 + 20, 400, 24, IPlayer.MAX_NICK_LENGTH, new FieldCallback() { public void use(Field elem, FieldAction value) { if(value == FieldAction.SEND || value == FieldAction.UNFOCUS) { String name = elem.getText(); @@ -418,43 +398,45 @@ public class GuiChar extends GuiList } }, IPlayer.VALID_NICK, this.gm.player == null ? "" : this.gm.player.getCustomNameTag())); this.templateButton.enabled = false; - this.dimension = new Random().zrange(this.dimensions.size()); - EntityInfo info = EntityRegistry.DNA.get(this.gm.player == null ? EntityRegistry.getEntityString(EntityHuman.class) : EntityRegistry.getEntityString(this.gm.player)); - if(info != null && info.origin() != null) { - Dimension dim = DimensionMapping.getDimension(info.origin()); + this.dimension = new Random().zrange(UniverseRegistry.getBaseDimensions().size()); + EntityEggInfo egg = EntityRegistry.SPAWN_EGGS.get(this.gm.player == null ? EntityRegistry.getEntityString(EntityHuman.class) : EntityRegistry.getEntityString(this.gm.player)); + if(egg != null && egg.origin != null) { + Dimension dim = UniverseRegistry.getDimension(egg.origin); if(dim != null) { - for(int z = 0; z < this.dimensions.size(); z++) { - if(this.dimensions.get(z) == dim) { + for(int z = 0; z < UniverseRegistry.getBaseDimensions().size(); z++) { + if(UniverseRegistry.getBaseDimensions().get(z).getDimensionId() == dim.getDimensionId()) { this.dimension = z; break; } } } } - this.dimButton = this.add(new ActButton(width - 390, height - 156, 388, 0, new ButtonCallback() { + this.dimButton = this.add(new ActButton(width - 396, height - 220, 392, 24, new ButtonCallback() { public void use(ActButton elem, PressType mode) { if(mode == PressType.TERTIARY) { - GuiChar.this.dimension = new Random().zrange(GuiChar.this.dimensions.size()); + GuiChar.this.dimension = new Random().zrange(UniverseRegistry.getBaseDimensions().size()); } else if(mode == PressType.SECONDARY) { if(--GuiChar.this.dimension < 0) - GuiChar.this.dimension = GuiChar.this.dimensions.size() - 1; + GuiChar.this.dimension = UniverseRegistry.getBaseDimensions().size() - 1; } else { - if(++GuiChar.this.dimension >= GuiChar.this.dimensions.size()) + if(++GuiChar.this.dimension >= UniverseRegistry.getBaseDimensions().size()) GuiChar.this.dimension = 0; } GuiChar.this.setDimButton(); } }, "")); - this.descLines = this.add(new MultiLabel(width - 390, height - 156 + Element.BASE_HEIGHT, 388, 42, "", true)); + this.descLines = this.add(new TransparentArea(width - 396, height - 220 + 24, 392, 66, "", false)); this.setDimButton(); } private void setDimButton() { - Dimension dim = this.dimensions.get(this.dimension); - this.dimButton.setText((dim.getType() == DimType.PLANET ? "Heimplanet" : (dim.getType() == DimType.MOON ? "Heimmond" : (dim.getType() == DimType.STAR ? "Heimstern" : "Heimdimension"))) + ": " + (dim == Space.INSTANCE ? "*unbekannt*" : dim.getDisplay())); - this.descLines.setText(Util.buildLines(dim.getBaseNames())); + Dimension dim = UniverseRegistry.getBaseDimensions().get(this.dimension); + this.dimButton.setText((dim.getType() == DimType.PLANET ? "Heimplanet" : "Heimdimension") + ": " + dim.getFormattedName(false)); + String name = dim.getFormattedName(true); + int index = name.indexOf(" / "); + this.descLines.setText(index >= 0 ? Util.buildLines(name.substring(index + " / ".length()).split(" / ")) : ""); } public void onGuiClosed() @@ -467,22 +449,20 @@ public class GuiChar extends GuiList if(this.adjust != null) { float factor = this.gm.player.width > 2.15f ? 2.15f / this.gm.player.width : 1.0f; factor = this.gm.player.height > 3.0f && 3.0f / this.gm.player.height < factor ? 3.0f / this.gm.player.height : factor; - if(this.gm.fbX >= 784 + 460 && this.gm.fbY >= 128 + 640) - drawEntity(400 + (this.gm.fbX - 400 - 400) / 2, this.gm.fbY - 160, 160.0f * factor, this.yaw, this.pitch, this.gm.player); - else - drawEntity(390 - 4 - 115 / 2, this.gm.fbY - 60, 40.0f * factor, this.yaw, this.pitch, this.gm.player); + drawEntity(400 + (this.gm.fb_x - 400 - 400) / 2, this.gm.fb_y - 160, 160.0f * factor + , this.yaw, this.pitch, this.gm.player); } } public void updateScreen() { if(this.adjust == null && this.gm.getRenderManager().gm != null) - this.gm.show(this); + this.gm.displayGuiScreen(this); } public void checkReopen() { if(this.adjust != null && this.waiting) { this.waiting = false; - this.gm.show(this); + this.gm.displayGuiScreen(this); } } @@ -490,11 +470,6 @@ public class GuiChar extends GuiList return "Charakter anpassen"; } - public void setCharsAvailable() { - if(this.cancelButton != null) - this.cancelButton.enabled = !this.gm.characterList.isEmpty(); - } - public static BufferedImage loadSkin(File file) { BufferedImage img = null; @@ -562,6 +537,11 @@ public class GuiChar extends GuiList this.elements.clear(); } + + public int getListWidth() + { + return 400 - 20; + } public int getSlotHeight() { diff --git a/client/src/client/gui/character/GuiCharacters.java b/client/src/client/gui/character/GuiCharacters.java new file mode 100644 index 00000000..46e99d85 --- /dev/null +++ b/client/src/client/gui/character/GuiCharacters.java @@ -0,0 +1,123 @@ +package client.gui.character; + +import client.gui.GuiConfirm; +import client.gui.GuiMenu; +import client.gui.element.ActButton; +import client.gui.element.ButtonCallback; +import client.gui.element.GuiList; +import client.gui.element.ListEntry; +import client.gui.element.NavButton; +import client.gui.element.PressType; +import client.gui.element.TransparentArea; +import client.renderer.Drawing; +import common.color.TextColor; +import common.entity.npc.PlayerCharacter; +import common.packet.CPacketAction; + +public class GuiCharacters extends GuiList implements ButtonCallback +{ + protected class CharacterEntry implements ListEntry + { + private final PlayerCharacter character; + private final boolean initial; + + protected CharacterEntry(PlayerCharacter character, boolean initial) + { + this.character = character; + this.initial = initial; + } + + public void draw(int x, int y, int mouseX, int mouseY, boolean hovered) + { + if(this.initial) + Drawing.drawRect(x, y, 1, 36, 0xffaf0000); + String str = this.character == null ? TextColor.BLUE + "[" + TextColor.CYAN + "+" + TextColor.BLUE + "]" : + String.format(TextColor.GREEN + "Level " + TextColor.DGREEN + "%d " + TextColor.YELLOW + "%s " + TextColor.VIOLET + "%s" + TextColor.GRAY + " [%s%s" + TextColor.GRAY + "]", + character.level, character.type, character.name, character.align.color, character.align.display); + String pos = this.character == null ? TextColor.BROWN + "Neuen Charakter erstellen" : + String.format(TextColor.NEON + "%s " + TextColor.GRAY + "bei " + TextColor.ACID + "%d" + TextColor.GRAY + ", " + TextColor.ACID + "%d" + TextColor.GRAY + ", " + TextColor.ACID + "%d", + character.dim, character.pos.getX(), character.pos.getY(), character.pos.getZ()); + Drawing.drawText(str, x + 3, y, 0xffffffff); + Drawing.drawText(pos, x + 3, y + 16, 0xffffffff); + } + + public void select(boolean dclick, int mx, int my) + { + if(dclick) + GuiCharacters.this.use(GuiCharacters.this.actionButtom, PressType.PRIMARY); + GuiCharacters.this.updateButtons(); + } + } + + public static final GuiCharacters INSTANCE = new GuiCharacters(); + + private TransparentArea descField; + private ActButton actionButtom; + private ActButton deleteButtom; + + private GuiCharacters() { + } + + private void updateButtons() { + CharacterEntry entry = this.getSelected(); + this.descField.setText(entry == null ? "" : (entry.character == null ? "*neuer Charakter*" : (entry.character.info == null ? "*keine Beschreibung vorhanden*" : this.getSelected().character.info))); + this.actionButtom.setText(entry != null && entry.character == null ? "Charakter erstellen" : "Charakter spielen"); + this.actionButtom.enabled = entry != null && !entry.initial; + this.deleteButtom.enabled = entry != null && entry.character != null && !entry.initial; + } + + public void init(int width, int height) + { + super.init(width, height); + this.setDimensions(600, height, 32, height - 32); + this.elements.clear(); + if(this.gm.getNetHandler() != null) { + int initialSelection = this.gm.getNetHandler().getSelectedCharacter(); + for(PlayerCharacter character : this.gm.getNetHandler().getCharacterList()) { + this.elements.add(new CharacterEntry(initialSelection == this.elements.size() ? new PlayerCharacter(character.name, character.info, character.align, this.gm.player.worldObj.dimension.getFormattedName(false), this.gm.player.getPosition(), character.type, this.gm.player.experienceLevel) : character, initialSelection == this.elements.size())); + } + this.elements.add(new CharacterEntry(null, false)); + this.setSelected(initialSelection); + } + this.descField = this.add(new TransparentArea(width - 390, 62, 380, height - 124, "", false)); + this.deleteButtom = this.add(new ActButton(width / 2 - 304, height - 28, 200, 24, this, "Charakter löschen")); + this.actionButtom = this.add(new ActButton(width / 2 - 100, height - 28, 200, 24, this, "")); + this.add(new NavButton(width / 2 + 104, height - 28, 200, 24, GuiMenu.INSTANCE, "Abbrechen")); + this.updateButtons(); + } + + public String getTitle() { + return "Charakter anpassen"; + } + + public int getListWidth() + { + return 560; + } + + public int getSlotHeight() + { + return 36 + 4; + } + + public void use(ActButton elem, PressType action) { + CharacterEntry entry = GuiCharacters.this.getSelected(); + if(entry != null && GuiCharacters.this.gm.getNetHandler() != null) { + if(elem == this.actionButtom) { + if(entry.character == null) + this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.OPEN_EDITOR)); + else + this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.SELECT_CHARACTER, this.selectedElement)); + } + else if(elem == this.deleteButtom && entry.character != null) { + this.gm.displayGuiScreen(new GuiConfirm(new GuiConfirm.Callback() { + public void confirm(boolean confirmed) { + if(confirmed) + GuiCharacters.this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.DELETE_CHARACTER, GuiCharacters.this.selectedElement)); + GuiCharacters.this.gm.displayGuiScreen(GuiCharacters.this); + } + }, "Möchtest du diesen Charakter wirklich löschen?", "Der Fortschritt, die Gegenstände und die Historie von \"" + entry.character.name + "\" werden für imer verloren sein!", "Löschen", "Abbrechen")); + } + } + } +} diff --git a/client/src/main/java/client/gui/character/GuiClass.java b/client/src/client/gui/character/GuiClass.java similarity index 81% rename from client/src/main/java/client/gui/character/GuiClass.java rename to client/src/client/gui/character/GuiClass.java index 16aa52ed..9b838718 100644 --- a/client/src/main/java/client/gui/character/GuiClass.java +++ b/client/src/client/gui/character/GuiClass.java @@ -20,7 +20,7 @@ public class GuiClass extends GuiList implements ButtonCall this.clazz = clazz; } - public void draw(int x, int y, int width, int height, int mouseX, int mouseY, boolean hovered) + public void draw(int x, int y, int mouseX, int mouseY, boolean hovered) { if(GuiClass.this.gm.player != null && this.clazz == GuiClass.this.gm.player.getNpcClass()) Drawing.drawRect(x, y, 1, 44, 0xffaf0000); @@ -44,19 +44,24 @@ public class GuiClass extends GuiList implements ButtonCall public void init(int width, int height) { super.init(width, height); - this.setDimensions(width, height, 32, height - 32); + this.setDimensions(400, height, 32, height - 32); this.elements.clear(); if(this.gm.player != null && this.gm.player.getSpecies().classEnum != null) for(Enum clazz : this.gm.player.getSpecies().classEnum.getEnumConstants()) { this.elements.add(new ClassEntry(clazz)); } - this.add(new NavButton(width / 2 - 195, height - 30, 194, 0, GuiChar.INSTANCE, "Zurück")); - this.selectButton = this.add(new ActButton(width / 2 + 1, height - 30, 194, 0, this, "Klasse ändern")); + this.add(new NavButton(width - 198 * 2, height - 28, 194, 24, GuiChar.INSTANCE, "Zurück")); + this.selectButton = this.add(new ActButton(width - 198, height - 28, 194, 24, this, "Klasse ändern")); } public String getTitle() { return "Klasse wählen"; } + + public int getListWidth() + { + return 400 - 20; + } public int getSlotHeight() { @@ -67,7 +72,7 @@ public class GuiClass extends GuiList implements ButtonCall ClassEntry entry = this.getSelected(); if(entry != null && GuiClass.this.gm.player != null) { GuiClass.this.gm.player.client.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_CLASS, entry.clazz.ordinal())); - this.gm.show(GuiChar.INSTANCE); + this.gm.displayGuiScreen(GuiChar.INSTANCE); } } } diff --git a/client/src/main/java/client/gui/character/GuiSpecies.java b/client/src/client/gui/character/GuiSpecies.java similarity index 84% rename from client/src/main/java/client/gui/character/GuiSpecies.java rename to client/src/client/gui/character/GuiSpecies.java index 6f190db8..10e8c016 100644 --- a/client/src/main/java/client/gui/character/GuiSpecies.java +++ b/client/src/client/gui/character/GuiSpecies.java @@ -23,7 +23,7 @@ public class GuiSpecies extends GuiList implements Butt this.species = species; } - public void draw(int x, int y, int width, int height, int mouseX, int mouseY, boolean hovered) + public void draw(int x, int y, int mouseX, int mouseY, boolean hovered) { if(GuiSpecies.this.gm.player != null && this.species == GuiSpecies.this.gm.player.getSpecies()) Drawing.drawRect(x, y, 1, 44, 0xffaf0000); @@ -49,18 +49,23 @@ public class GuiSpecies extends GuiList implements Butt public void init(int width, int height) { super.init(width, height); - this.setDimensions(width, height, 32, height - 32); + this.setDimensions(400, height, 32, height - 32); this.elements.clear(); for(SpeciesInfo species : SpeciesRegistry.SPECIMEN) { this.elements.add(new SpeciesEntry(species)); } - this.add(new NavButton(width / 2 - 195, height - 30, 194, 0, GuiChar.INSTANCE, "Zurück")); - this.selectButton = this.add(new ActButton(width / 2 + 1, height - 30, 194, 0, this, "Spezies ändern")); + this.add(new NavButton(width - 198 * 2, height - 28, 194, 24, GuiChar.INSTANCE, "Zurück")); + this.selectButton = this.add(new ActButton(width - 198, height - 28, 194, 24, this, "Spezies ändern")); } public String getTitle() { return "Spezies wählen"; } + + public int getListWidth() + { + return 400 - 20; + } public int getSlotHeight() { diff --git a/client/src/client/gui/container/GuiBrewing.java b/client/src/client/gui/container/GuiBrewing.java new file mode 100755 index 00000000..45690d6e --- /dev/null +++ b/client/src/client/gui/container/GuiBrewing.java @@ -0,0 +1,50 @@ +package client.gui.container; + +import common.inventory.ContainerBrewingStand; +import common.inventory.IInventory; +import common.inventory.InventoryPlayer; + + +public class GuiBrewing extends GuiContainer +{ +// private static final String brewingStandGuiTextures = "textures/gui/brewing_stand.png"; + + /** The player inventory bound to this GUI. */ + private final InventoryPlayer playerInventory; + private IInventory tileBrewingStand; + + public GuiBrewing(InventoryPlayer playerInv, IInventory p_i45506_2_) + { + super(new ContainerBrewingStand(playerInv, p_i45506_2_)); + this.playerInventory = playerInv; + this.tileBrewingStand = p_i45506_2_; + } + + /** + * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY + */ + public void drawGuiContainerForegroundLayer() + { + String s = this.tileBrewingStand.getCommandName(); + this.drawString(s, 8, 6); + this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2); + } + + /** + * Args : renderPartialTicks, mouseX, mouseY + */ + public void drawGuiContainerBackgroundLayer() + { + int k = this.tileBrewingStand.getField(0); + + if (k > 0) + { + int l = (int)(28.0F * (1.0F - (float)k / 400.0F)); + + if (l > 0) + { + this.rect(97, 16, 9, l, 0xffff20); + } + } + } +} diff --git a/client/src/client/gui/container/GuiChest.java b/client/src/client/gui/container/GuiChest.java new file mode 100755 index 00000000..c9a56be9 --- /dev/null +++ b/client/src/client/gui/container/GuiChest.java @@ -0,0 +1,53 @@ +package client.gui.container; + +import client.Client; +import common.inventory.ContainerChest; +import common.inventory.IInventory; + + +public class GuiChest extends GuiContainer +{ +// /** The ResourceLocation containing the chest GUI texture. */ +// private static final String CHEST_GUI_TEXTURE = "textures/gui/generic_54.png"; + private IInventory upperChestInventory; + private IInventory lowerChestInventory; + + /** + * window height is calculated with these values; the more rows, the heigher + */ + private int inventoryRows; + + public GuiChest(IInventory upperInv, IInventory lowerInv) + { + super(new ContainerChest(upperInv, lowerInv, Client.CLIENT.player)); + this.upperChestInventory = upperInv; + this.lowerChestInventory = lowerInv; +// this.allowUserInput = false; + int i = 222; + int j = i - 108; + this.inventoryRows = lowerInv.getSizeInventory() / 9; + this.ySize = j + this.inventoryRows * 18; + } + + /** + * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY + */ + public void drawGuiContainerForegroundLayer() + { + this.drawString(this.lowerChestInventory.getCommandName(), 8, 6); + this.drawString(this.upperChestInventory.getCommandName(), 8, this.ySize - 96 + 2); + } + + /** + * Args : renderPartialTicks, mouseX, mouseY + */ +// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY) +// { +// GlState.color(1.0F, 1.0F, 1.0F, 1.0F); +// this.gm.getTextureManager().bindTexture(CHEST_GUI_TEXTURE); +// int i = (this.width - this.xSize) / 2; +// int j = (this.height - this.ySize) / 2; +//// this.rect(i, j, 0, 0, this.xSize, this.inventoryRows * 18 + 17); +//// this.rect(i, j + this.inventoryRows * 18 + 17, 0, 126, this.xSize, 96); +// } +} diff --git a/client/src/client/gui/container/GuiContainer.java b/client/src/client/gui/container/GuiContainer.java new file mode 100755 index 00000000..7ae0eb8a --- /dev/null +++ b/client/src/client/gui/container/GuiContainer.java @@ -0,0 +1,1211 @@ +package client.gui.container; + +import java.util.List; +import java.util.Set; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL13; + +import client.gui.Gui; +import client.gui.element.InventoryButton; +import client.renderer.Drawing; +import client.renderer.GlState; +import client.renderer.ItemRenderer; +import client.renderer.entity.RenderItem; +import client.window.Button; +import common.collect.Lists; +import common.collect.Sets; +import common.color.TextColor; +import common.inventory.Container; +import common.inventory.InventoryPlayer; +import common.inventory.Slot; +import common.item.CheatTab; +import common.item.ItemStack; +import common.packet.CPacketCheat; +import common.util.ExtMath; + +public abstract class GuiContainer extends Gui +{ + private class Overlay { + private final ItemStack stack; + private final int x; + private final int y; + private final String alt; + + private Overlay(ItemStack stack, int x, int y, String alt) { + this.stack = stack; + this.x = x; + this.y = y; + this.alt = alt; + } + } + + private static final List ITEM_LIST = Lists.newArrayList(); + + private static CheatTab selectedTab = CheatTab.tabBlocks; +// /** The location of the inventory background texture */ +// protected static final String inventoryBackground = "textures/gui/inventory.png"; + + protected RenderItem itemRender; +// public int width; +// public int height; + + /** The X size of the inventory window in pixels. */ + protected int xSize = 176; + + /** The Y size of the inventory window in pixels. */ + protected int ySize = 166; + + /** A list of the players inventory slots */ + public Container inventorySlots; + +// /** +// * Starting X position for the Gui. Inconsistent use for Gui backgrounds. +// */ +// protected int guiLeft; +// +// /** +// * Starting Y position for the Gui. Inconsistent use for Gui backgrounds. +// */ +// protected int guiTop; + + /** holds the slot currently hovered */ + private Slot theSlot; + + /** Used when touchscreen is enabled. */ + private Slot clickedSlot; + + /** Used when touchscreen is enabled. */ + private boolean isRightMouseClick; + + /** Used when touchscreen is enabled */ + private ItemStack draggedStack; + private int touchUpX; + private int touchUpY; + private Slot returningStackDestSlot; + private long returningStackTime; + + /** Used when touchscreen is enabled */ + private ItemStack returningStack; + private Slot currentDragTargetSlot; + private long dragItemDropDelay; + protected final Set dragSplittingSlots = Sets.newHashSet(); + protected final List drawnOverlays = Lists.newArrayList(); + protected boolean dragSplitting; + private int dragSplittingLimit; + private int dragSplittingButton; + private boolean ignoreMouseUp; + private int dragSplittingRemnant; + private long lastClickTime; + private Slot lastClickSlot; + private int lastClickButton; + private boolean doubleClick; + private ItemStack shiftClickedSlot; + + protected int container_x; + protected int container_y; + protected int container_w; + protected int container_h; + + private int hover_x; + private int hover_y; + private String tooltip; + + private float currentScroll; + private boolean isScrolling; + private boolean wasClicking; + private ItemStack cheatStack; + + public void drawString(String text, int x, int y) { + x = x * 2 + this.container_x; + y = y * 2 + this.container_y; + Drawing.drawText(text, x, y, 0xffffffff); + } + + public int getStringWidth(String text) { + return Drawing.getSize(text).xpos / 2; + } + + public void rect(int x, int y, int width, int height, int color) { + Drawing.drawRect(this.container_x + x * 2, this.container_y + y * 2, width * 2, height * 2, 0xff000000 | color); + } + + public InventoryButton button(int x, int y, int w, int h) { + return this.add(new InventoryButton(this.container_x + x * 2, this.container_y + y * 2, w * 2, h * 2)); + } + +// public void uidims(int w, int h) { +// } + + public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) { + super.mouse(btn, x, y, ctrl, shift); +// public void click(Button btn, int x, int y) { +// if(this.openGui != null) { +// int x = SKC.getMouseX() * this.openGui.width / this.gm.fb_x; +// int y = this.openGui.height - SKC.getMouseY() * this.openGui.height / this.gm.fb_y - 1; + this.mouseClicked((x - this.container_x) / 2, (y - this.container_y) / 2, btn.ordinal()); //TODO: enum +// } + } + + public void mouserel(Button btn, int x, int y) { + super.mouserel(btn, x, y); +// if(this.openGui != null) { +// int x = SKC.getMouseX() * this.openGui.width / this.gm.fb_x; +// int y = this.openGui.height - SKC.getMouseY() * this.openGui.height / this.gm.fb_y - 1; + this.mouseReleased((x - this.container_x) / 2, (y - this.container_y) / 2, btn.ordinal()); //TODO: enum +// } + } + + public void drag(int x, int y) { + super.drag(x, y); +// if(this.openGui != null) { +// int x = SKC.getMouseX() * this.openGui.width / this.gm.fb_x; +// int y = this.openGui.height - SKC.getMouseY() * this.openGui.height / this.gm.fb_y - 1; + if(Button.MOUSE_LEFT.isDown() || Button.MOUSE_RIGHT.isDown() || Button.MOUSE_MIDDLE.isDown()) + this.mouseDragged((x - this.container_x) / 2, (y - this.container_y) / 2); +// } + } + + public GuiContainer(Container inventorySlotsIn) + { + this.inventorySlots = inventorySlotsIn; + this.ignoreMouseUp = true; + } + + public void init(int width, int height) { + this.itemRender = this.gm.getRenderItem(); + this.tooltip = null; + this.cheatStack = null; +// this.width = width; +// this.height = height; +// this.initialize(this.gm.getGame()); +// this.container_x = this.container_y = this.container_w = this.container_h = 0; + this.container_x = (width - (this.container_w = (this.xSize * 2))) / 2; + this.container_y = (height - (this.container_h = (this.ySize * 2))) / 2; + this.initGui(); + this.addButtons(); + } + + public void hover(String text, int x, int y) { + this.tooltip = text; + this.hover_x = x * 2 + this.container_x + 16; + this.hover_y = y * 2 + this.container_y + 16; + } + + public String getTitle() { + return "Inventar"; + } + +// public int getXSize() { +// return this.xSize; +// } +// +// public int getYSize() { +// return this.ySize; +// } + +// public final void initialize(Game gm) { +// } + + /** + * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the + * window resizes, the buttonList is cleared beforehand. + */ + public void initGui() + { + this.gm.player.openContainer = this.inventorySlots; +// this.guiLeft = (this.width - this.xSize) / 2; +// this.guiTop = (this.height - this.ySize) / 2; +// this.addButtons(); + if(this.gm.itemCheat) { +// CheatTab i = selectedTab; +// selectedTab = null; + this.setCurrentTab(selectedTab); + } + } + + public void addButtons() { +// this.uidims(this.xSize, this.ySize); + if(this.inventorySlots != null) { + for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1) { + Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i1); + this.button(slot.xDisplayPosition - 1, slot.yDisplayPosition - 1, 18, 18); + } + } + if(this.gm.itemCheat) { + for (int k = 0; k < 9; ++k) + { + for (int l = 0; l < 12; ++l) { + this.button(this.xSize + 2 + 18 * l, k * 18, 18, 18); + } + } + for(CheatTab tab : CheatTab.values()) { + this.button(this.xSize + 2 + 18 * tab.getHorizontal(), 9 * 18 + 4 + 20 * tab.getVertical(), 18, 18); + } + } + } + + protected void drawSlots(int mouseX, int mouseY) { + for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1) + { + Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i1); + this.drawSlot(slot); + + if (this.isMouseOverSlot(slot, mouseX, mouseY) && slot.canBeHovered()) + { + this.theSlot = slot; + } + } + + if(this.gm.itemCheat) { + int i = (ITEM_LIST.size() + 12 - 1) / 12 - 9; + int j = (int)((double)(this.currentScroll * (float)i) + 0.5D); + + if (j < 0) + { + j = 0; + } + + for (int k = 0; k < 9; ++k) + { + for (int l = 0; l < 12; ++l) + { + int i1 = l + (k + j) * 12; + + if (i1 >= 0 && i1 < ITEM_LIST.size()) { + + this.itemRender.zLevel = 100.0F; + GlState.enableDepth(); + this.itemRender.renderItemAndEffectIntoGUI(ITEM_LIST.get(i1), this.xSize + 2 + 18 * l + 1, k * 18 + 1); + this.itemRender.zLevel = 0.0F; + if(this.isPointInRegion(this.xSize + 2 + 18 * l + 1, k * 18 + 1, 16, 16, mouseX, mouseY)) + this.renderToolTip(ITEM_LIST.get(i1), mouseX, mouseY); + } + } + } + + for (CheatTab tabs : CheatTab.values()) + { + this.drawTab(tabs); + } + } + } + + public void drawOverlays() { + for(Overlay overlay : this.drawnOverlays) { + this.renderItemOverlayIntoGUI(overlay.stack, overlay.x, overlay.y, overlay.alt); + } + this.drawnOverlays.clear(); + if(this.tooltip != null) { + int width = Drawing.getBoxWidth(this.tooltip); + Drawing.drawTextbox(this.tooltip, this.hover_x + width > this.gm.fb_x ? this.hover_x - width - 32 : this.hover_x, this.hover_y, 0xaf000000); + } + this.tooltip = null; + } + + /** + * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks + */ + public void drawScreen(int mouseX, int mouseY) + { + if(this.gm == null) + return; + if(this.gm.itemCheat) { + boolean flag = Button.MOUSE_LEFT.isDown(); //TODO: remove? + int x1 = this.xSize + 2 + 12 * 18 + 1; + int y1 = 1; + int x2 = x1 + 10; + int y2 = y1 + 112 + 18 * 4; + + if (!this.wasClicking && flag && mouseX >= x1 && mouseY >= y1 && mouseX < x2 && mouseY < y2) + { + this.isScrolling = this.needsScrollBars(); + } + + if (!flag) + { + this.isScrolling = false; + } + + this.wasClicking = flag; + + if (this.isScrolling) + { + this.currentScroll = ((float)(mouseY - y1) - 7.5F) / ((float)(y2 - y1) - 15.0F); + this.currentScroll = ExtMath.clampf(this.currentScroll, 0.0F, 1.0F); + } + } +// this.drawGradientRect(0, 0, this.width, this.height, -1072689136, -804253680); +// int i = this.guiLeft; +// int j = this.guiTop; +// this.drawGuiContainerBackgroundLayer(mouseX, mouseY); + GlState.disableRescaleNormal(); + ItemRenderer.disableStandardItemLighting(); + GlState.disableLighting(); + GlState.disableDepth(); +// super.drawScreen(mouseX, mouseY, partialTicks); + ItemRenderer.enableGUIStandardItemLighting(); +// SKC.glPushMatrix(); +// SKC.glTranslatef((float)i, (float)j, 0.0F); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + GlState.enableRescaleNormal(); + this.theSlot = null; + int k = 240; + int l = 240; + GL13.glMultiTexCoord2f(GL13.GL_TEXTURE1, (float)k / 1.0F, (float)l / 1.0F); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + + this.drawSlots(mouseX, mouseY); + + ItemRenderer.disableStandardItemLighting(); +// this.drawGuiContainerForegroundLayer(mouseX, mouseY); + ItemRenderer.enableGUIStandardItemLighting(); + InventoryPlayer inventoryplayer = this.gm.player.inventory; + ItemStack itemstack = this.draggedStack == null ? inventoryplayer.getItemStack() : this.draggedStack; + if(this.gm.itemCheat) + itemstack = itemstack == null ? this.cheatStack : itemstack; + + if (itemstack != null) + { + int j2 = 8; + int k2 = this.draggedStack == null ? 8 : 16; + String s = null; + + if (this.draggedStack != null && this.isRightMouseClick) + { + itemstack = itemstack.copy(); + itemstack.stackSize = ExtMath.ceilf((float)itemstack.stackSize / 2.0F); + } + else if (this.dragSplitting && this.dragSplittingSlots.size() > 1) + { + itemstack = itemstack.copy(); + itemstack.stackSize = this.dragSplittingRemnant; + + if (itemstack.stackSize == 0) + { + s = "" + TextColor.YELLOW + "0"; + } + } + else if(itemstack == this.cheatStack) { + s = TextColor.DGREEN + "+" + TextColor.GREEN + ItemStack.formatAmount(itemstack.stackSize); + } + + this.drawItemStack(itemstack, mouseX - j2, mouseY - k2, s); + } + + if (this.returningStack != null) + { + float f = (float)(System.currentTimeMillis() - this.returningStackTime) / 100.0F; + + if (f >= 1.0F) + { + f = 1.0F; + this.returningStack = null; + } + + int l2 = this.returningStackDestSlot.xDisplayPosition - this.touchUpX; + int i3 = this.returningStackDestSlot.yDisplayPosition - this.touchUpY; + int l1 = this.touchUpX + (int)((float)l2 * f); + int i2 = this.touchUpY + (int)((float)i3 * f); + this.drawItemStack(this.returningStack, l1, i2, (String)null); + } + +// SKC.glPopMatrix(); + + if (inventoryplayer.getItemStack() == null && this.cheatStack == null && this.theSlot != null && this.theSlot.getHasStack()) + { + ItemStack itemstack1 = this.theSlot.getStack(); + this.renderToolTip(itemstack1, mouseX, mouseY); + } + + GlState.enableLighting(); + GlState.enableDepth(); + ItemRenderer.enableStandardItemLighting(); + + if(this.gm.itemCheat) { + for (CheatTab tab : CheatTab.values()) + { + if (this.renderInventoryHoveringText(tab, mouseX, mouseY)) + { + break; + } + } + + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + GlState.disableLighting(); + } + } + + /** + * Render an ItemStack. Args : stack, x, y, format + */ + private void drawItemStack(ItemStack stack, int x, int y, String altText) + { + GL11.glTranslatef(0.0F, 0.0F, 32.0F); +// this.zLevel = 200.0F; + this.itemRender.zLevel = 200.0F; + this.itemRender.renderItemAndEffectIntoGUI(stack, x, y); + this.drawnOverlays.add(new Overlay(stack, x, y - (this.draggedStack == null ? 0 : 8), altText)); +// this.zLevel = 0.0F; + this.itemRender.zLevel = 0.0F; + } + + protected void renderToolTip(ItemStack stack, int x, int y) { + List list = stack.getTooltip(this.gm.player); + StringBuilder sb = new StringBuilder(); + for(int i = 0; i < list.size(); ++i) { + if(i != 0) + sb.append("\n" + TextColor.LGRAY + (String)list.get(i)); + else + sb.append((String)list.get(i)); + } + this.hover(sb.toString(), x, y); + } + + /** + * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY + */ + public void drawGuiContainerForegroundLayer() + { + } + + public void drawGuiContainerBackgroundLayer() { + } + + public void draw() { + super.draw(); + if(this.gm.itemCheat) { + int i = this.xSize + 2 + 12 * 18 + 1; + int j = 1; + int k = j + 184; + this.rect(i, j, 8, 182, this.needsScrollBars() ? 0x303030 : 0x202020); + this.rect(i, j + (int)((float)(k - j - 17) * this.currentScroll), 8, 15, this.needsScrollBars() ? 0x808080 : 0x606060); +// CheatTab tab = CheatTab.TABS[selectedTab]; + this.rect(this.xSize + 2 + 18 * selectedTab.getHorizontal(), 9 * 18 + 4 + 20 * selectedTab.getVertical() - 2, 18, 2, 0xffffff); + } + this.drawGuiContainerBackgroundLayer(); + if(this.gm.itemCheat) { +// CheatTab tab = CheatTab.TABS[selectedTab]; + this.drawString(selectedTab.getName(), this.xSize + 2 + 4, -10); + this.drawString("Vorsicht: Schummeln wird mit Keule bestraft", this.xSize + 2 + 4, 18 * (9 + (CheatTab.values().length + 11) / 12) + 10); + this.drawString("(Halte Strg beim Klick für vollen Stapel)", this.xSize + 2 + 4, 18 * (9 + (CheatTab.values().length + 11) / 12) + 20); + } + this.drawGuiContainerForegroundLayer(); + } + + public void drawPost() { + GL11.glPushMatrix(); + GL11.glTranslatef((float)((this.gm.fb_x - this.xSize * 2) / 2), (float)((this.gm.fb_y - this.ySize * 2) / 2), 0.0f); +// int k1 = SKC.getMouseX(); +// int l1 = this.gm.fb_y - SKC.getMouseY() - 1; + GL11.glScalef(2.0f, 2.0f, 2.0f); + this.drawScreen((this.gm.mouse_x - this.container_x) / 2, (this.gm.mouse_y - this.container_y) / 2); + GL11.glPopMatrix(); + ItemRenderer.disableStandardItemLighting(); +// GlState.color(1.0f, 1.0f, 1.0f, 1.0f); + } + + private void drawSlot(Slot slotIn) + { + int i = slotIn.xDisplayPosition; + int j = slotIn.yDisplayPosition; + ItemStack itemstack = slotIn.getStack(); + boolean flag = false; + boolean flag1 = slotIn == this.clickedSlot && this.draggedStack != null && !this.isRightMouseClick; + ItemStack itemstack1 = this.gm.player.inventory.getItemStack(); + String s = null; + + if (slotIn == this.clickedSlot && this.draggedStack != null && this.isRightMouseClick && itemstack != null) + { + itemstack = itemstack.copy(); + itemstack.stackSize /= 2; + } + else if (this.dragSplitting && this.dragSplittingSlots.contains(slotIn) && itemstack1 != null) + { + if (this.dragSplittingSlots.size() == 1) + { + return; + } + + if (Container.canAddItemToSlot(slotIn, itemstack1, true) && this.inventorySlots.canDragIntoSlot(slotIn)) + { + itemstack = itemstack1.copy(); + flag = true; + Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, itemstack, slotIn.getStack() == null ? 0 : slotIn.getStack().stackSize); + + if (itemstack.stackSize > itemstack.getMaxStackSize()) + { + s = TextColor.YELLOW + ItemStack.formatAmount(itemstack.getMaxStackSize()); + itemstack.stackSize = itemstack.getMaxStackSize(); + } + + if (itemstack.stackSize > slotIn.getItemStackLimit(itemstack)) + { + s = TextColor.YELLOW + ItemStack.formatAmount(slotIn.getItemStackLimit(itemstack)); + itemstack.stackSize = slotIn.getItemStackLimit(itemstack); + } + } + else + { + this.dragSplittingSlots.remove(slotIn); + this.updateDragSplitting(); + } + } + +// this.zLevel = 100.0F; + this.itemRender.zLevel = 100.0F; + +// if (itemstack == null) +// { +// String s1 = slotIn.getSlotTexture(); +// +// if (s1 != null) +// { +// TextureAtlasSprite sprite = this.gm.getTextureMapBlocks().getAtlasSprite(s1); +// GlState.disableLighting(); +// this.gm.getTextureManager().bindTexture(TextureMap.locationBlocksTexture); +// this.rectuv(i, j, 16, 16, sprite.getMinU(), sprite.getMinV(), sprite.getMaxU(), sprite.getMaxV()); +// GlState.enableLighting(); +// flag1 = true; +// } +// } + + if (!flag1) + { +// if (flag) +// { +// drawRect(i, j, i + 16, j + 16, -2130706433); +// SKC.highlight(i, j, 16, 16); +// } + + GlState.enableDepth(); + this.itemRender.renderItemAndEffectIntoGUI(itemstack, i, j); + this.drawnOverlays.add(new Overlay(itemstack, i, j, s)); + } + + this.itemRender.zLevel = 0.0F; +// this.zLevel = 0.0F; + } + + private void updateDragSplitting() + { + ItemStack itemstack = this.gm.player.inventory.getItemStack(); + + if (itemstack != null && this.dragSplitting) + { + this.dragSplittingRemnant = itemstack.stackSize; + + for (Slot slot : this.dragSplittingSlots) + { + ItemStack itemstack1 = itemstack.copy(); + int i = slot.getStack() == null ? 0 : slot.getStack().stackSize; + Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, itemstack1, i); + + if (itemstack1.stackSize > itemstack1.getMaxStackSize()) + { + itemstack1.stackSize = itemstack1.getMaxStackSize(); + } + + if (itemstack1.stackSize > slot.getItemStackLimit(itemstack1)) + { + itemstack1.stackSize = slot.getItemStackLimit(itemstack1); + } + + this.dragSplittingRemnant -= itemstack1.stackSize - i; + } + } + } + + /** + * Returns the slot at the given coordinates or null if there is none. + */ + private Slot getSlotAtPosition(int x, int y) + { + for (int i = 0; i < this.inventorySlots.inventorySlots.size(); ++i) + { + Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i); + + if (this.isMouseOverSlot(slot, x, y)) + { + return slot; + } + } + + return null; + } + + /** + * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton + */ + public void mouseClicked(int mouseX, int mouseY, int mouseButton) + { + if(this.gm == null) + return; + if(this.cheatStack != null) { + Slot slot = this.getSlotAtPosition(mouseX, mouseY); + if((mouseButton == 0 || mouseButton == 1) && slot != null && this.gm.player != null && slot.inventory == this.gm.player.inventory) + this.gm.player.client.addToSendQueue(new CPacketCheat(this.cheatStack, slot.getIndex(), mouseButton == 0 && this.cheatStack.stackSize > 1)); + if(mouseButton != 1 && !this.gm.ctrl()) + this.cheatStack = null; + return; + } + if((mouseButton == 0 || mouseButton == 1 || mouseButton == 2) && this.clickSide(mouseX, mouseY, -1, this.gm.shift() || mouseButton == 1, this.gm.ctrl() || mouseButton == 2)) + return; + if(mouseButton == 0) { + if(this.gm.itemCheat && this.gm.player != null && this.gm.player.inventory.getItemStack() == null) { + for (CheatTab tab : CheatTab.values()) + { + if (this.isInsideTab(tab, mouseX, mouseY)) + { + this.setCurrentTab(tab); + return; + } + } + } + } +// super.mouseClicked(mouseX, mouseY, mouseButton); +// boolean flag = mouseButton == this.gm.bindTertiary.getKeyCode() + 100; + Slot slot = this.getSlotAtPosition(mouseX, mouseY); + long i = System.currentTimeMillis(); + this.doubleClick = this.lastClickSlot == slot && i - this.lastClickTime < 250L && this.lastClickButton == mouseButton; + this.ignoreMouseUp = false; + + if (mouseButton == 0 || mouseButton == 1) // || flag) + { +// int j = this.guiLeft; +// int k = this.guiTop; + boolean flag1 = mouseX < 0 || mouseY < 0 || mouseX >= this.xSize || mouseY >= this.ySize; + int l = -1; + + if (slot != null) + { + l = slot.slotNumber; + } + + if (flag1) + { + l = -999; + } + +// if (this.gm.touchscreen && flag1 && this.gm.thePlayer.inventory.getItemStack() == null) +// { +// this.gm.displayGuiScreen((GuiScreen)null); +// return; +// } + + if (l != -1) + { +// if (this.gm.touchscreen) +// { +// if (slot != null && slot.getHasStack()) +// { +// this.clickedSlot = slot; +// this.draggedStack = null; +// this.isRightMouseClick = mouseButton == 1; +// } +// else +// { +// this.clickedSlot = null; +// } +// } +// else + if (!this.dragSplitting) + { + if (this.gm.player.inventory.getItemStack() == null) + { +// if (mouseButton == this.gm.bindTertiary.getKeyCode() + 100) +// { +// this.handleMouseClick(slot, l, mouseButton, 3); +// } +// else +// { + boolean flag2 = l != -999 && this.gm.shift(); + int i1 = 0; + + if (flag2) + { + this.shiftClickedSlot = slot != null && slot.getHasStack() ? slot.getStack() : null; + i1 = 1; + } + else if (l == -999) + { + i1 = 4; + } + + this.handleMouseClick(slot, l, mouseButton, i1); +// } + + this.ignoreMouseUp = true; + } + else + { + this.dragSplitting = true; + this.dragSplittingButton = mouseButton; + this.dragSplittingSlots.clear(); + + if (mouseButton == 0) + { + this.dragSplittingLimit = 0; + } + else if (mouseButton == 1) + { + this.dragSplittingLimit = 1; + } +// else if (mouseButton == this.gm.bindTertiary.getKeyCode() + 100) +// { +// this.dragSplittingLimit = 2; +// } + } + } + } + } + + this.lastClickSlot = slot; + this.lastClickTime = i; + this.lastClickButton = mouseButton; + } + + /** + * Called when a mouse button is pressed and the mouse is moved around. Parameters are : mouseX, mouseY, + * lastButtonClicked & timeSinceMouseClick. + */ + public void mouseDragged(int mouseX, int mouseY) + { + if(this.gm == null || this.cheatStack != null) + return; + Slot slot = this.getSlotAtPosition(mouseX, mouseY); + ItemStack itemstack = this.gm.player.inventory.getItemStack(); + +// if (this.clickedSlot != null && this.gm.touchscreen) +// { +// if (clickedMouseButton == 0 || clickedMouseButton == 1) +// { +// if (this.draggedStack == null) +// { +// if (slot != this.clickedSlot && this.clickedSlot.getStack() != null) +// { +// this.draggedStack = this.clickedSlot.getStack().copy(); +// } +// } +// else if (this.draggedStack.stackSize > 1 && slot != null && Container.canAddItemToSlot(slot, this.draggedStack, false)) +// { +// long i = this.gm.getSystemTime(); +// +// if (this.currentDragTargetSlot == slot) +// { +// if (i - this.dragItemDropDelay > 500L) +// { +// this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, 0); +// this.handleMouseClick(slot, slot.slotNumber, 1, 0); +// this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, 0); +// this.dragItemDropDelay = i + 750L; +// --this.draggedStack.stackSize; +// } +// } +// else +// { +// this.currentDragTargetSlot = slot; +// this.dragItemDropDelay = i; +// } +// } +// } +// } +// else + if (this.dragSplitting && slot != null && itemstack != null && itemstack.stackSize > this.dragSplittingSlots.size() && Container.canAddItemToSlot(slot, itemstack, true) && slot.isItemValid(itemstack) && this.inventorySlots.canDragIntoSlot(slot)) + { + this.dragSplittingSlots.add(slot); + this.updateDragSplitting(); + } + } + + /** + * Called when a mouse button is released. Args : mouseX, mouseY, releaseButton + */ + public void mouseReleased(int mouseX, int mouseY, int state) + { + if(this.gm == null || this.cheatStack != null) + return; + Slot slot = this.getSlotAtPosition(mouseX, mouseY); +// int i = this.guiLeft; +// int j = this.guiTop; + boolean flag = mouseX < 0 || mouseY < 0 || mouseX >= this.xSize || mouseY >= this.ySize; + int k = -1; + + if (slot != null) + { + k = slot.slotNumber; + } + + if (flag) + { + k = -999; + } + + if (this.doubleClick && slot != null && state == 0 && this.inventorySlots.canMergeSlot((ItemStack)null, slot)) + { + if (this.gm.shift()) + { + if (slot != null && slot.inventory != null && this.shiftClickedSlot != null) + { + for (Slot slot2 : this.inventorySlots.inventorySlots) + { + if (slot2 != null && slot2.canTakeStack(this.gm.player) && slot2.getHasStack() && slot2.inventory == slot.inventory && Container.canAddItemToSlot(slot2, this.shiftClickedSlot, true)) + { + this.handleMouseClick(slot2, slot2.slotNumber, state, 1); + } + } + } + } + else + { + this.handleMouseClick(slot, k, state, 6); + } + + this.doubleClick = false; + this.lastClickTime = 0L; + } + else + { + if (this.dragSplitting && this.dragSplittingButton != state) + { + this.dragSplitting = false; + this.dragSplittingSlots.clear(); + this.ignoreMouseUp = true; + return; + } + + if (this.ignoreMouseUp) + { + this.ignoreMouseUp = false; + return; + } + +// if (this.clickedSlot != null && this.gm.touchscreen) +// { +// if (state == 0 || state == 1) +// { +// if (this.draggedStack == null && slot != this.clickedSlot) +// { +// this.draggedStack = this.clickedSlot.getStack(); +// } +// +// boolean flag2 = Container.canAddItemToSlot(slot, this.draggedStack, false); +// +// if (k != -1 && this.draggedStack != null && flag2) +// { +// this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, state, 0); +// this.handleMouseClick(slot, k, 0, 0); +// +// if (this.gm.thePlayer.inventory.getItemStack() != null) +// { +// this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, state, 0); +// this.touchUpX = mouseX - i; +// this.touchUpY = mouseY - j; +// this.returningStackDestSlot = this.clickedSlot; +// this.returningStack = this.draggedStack; +// this.returningStackTime = this.gm.getSystemTime(); +// } +// else +// { +// this.returningStack = null; +// } +// } +// else if (this.draggedStack != null) +// { +// this.touchUpX = mouseX - i; +// this.touchUpY = mouseY - j; +// this.returningStackDestSlot = this.clickedSlot; +// this.returningStack = this.draggedStack; +// this.returningStackTime = this.gm.getSystemTime(); +// } +// +// this.draggedStack = null; +// this.clickedSlot = null; +// } +// } +// else + if (this.dragSplitting && !this.dragSplittingSlots.isEmpty()) + { + this.handleMouseClick((Slot)null, -999, Container.getDragCode(0, this.dragSplittingLimit), 5); + + for (Slot slot1 : this.dragSplittingSlots) + { + this.handleMouseClick(slot1, slot1.slotNumber, Container.getDragCode(1, this.dragSplittingLimit), 5); + } + + this.handleMouseClick((Slot)null, -999, Container.getDragCode(2, this.dragSplittingLimit), 5); + } + else if (this.gm.player.inventory.getItemStack() != null) + { +// if (state == this.gm.bindTertiary.getKeyCode() + 100) +// { +// this.handleMouseClick(slot, k, state, 3); +// } +// else +// { + boolean flag1 = k != -999 && this.gm.shift(); + + if (flag1) + { + this.shiftClickedSlot = slot != null && slot.getHasStack() ? slot.getStack() : null; + } + + this.handleMouseClick(slot, k, state, flag1 ? 1 : 0); +// } + } + } + + if (this.gm.player.inventory.getItemStack() == null) + { + this.lastClickTime = 0L; + } + + this.dragSplitting = false; + } + + /** + * Returns if the passed mouse position is over the specified slot. Args : slot, mouseX, mouseY + */ + private boolean isMouseOverSlot(Slot slotIn, int mouseX, int mouseY) + { + return this.isPointInRegion(slotIn.xDisplayPosition, slotIn.yDisplayPosition, 16, 16, mouseX, mouseY); + } + + /** + * Test if the 2D point is in a rectangle (relative to the GUI). Args : rectX, rectY, rectWidth, rectHeight, pointX, + * pointY + */ + protected boolean isPointInRegion(int left, int top, int right, int bottom, int pointX, int pointY) + { +// int i = this.guiLeft; +// int j = this.guiTop; +// pointX = pointX - i; +// pointY = pointY - j; + return pointX >= left - 1 && pointX < left + right + 1 && pointY >= top - 1 && pointY < top + bottom + 1; + } + + /** + * Called when the mouse is clicked over a slot or outside the gui. + */ + protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) + { + if (slotIn != null) + { + slotId = slotIn.slotNumber; + } + + this.gm.controller.windowClick(this.inventorySlots.windowId, slotId, clickedButton, clickType, this.gm.player); + } + + public void dropItem() { + if (this.gm != null && this.gm.player != null && this.theSlot != null && this.theSlot.getHasStack()) + { +// if (keyCode == this.gm.bindTertiary.getKeyCode()) +// { +// this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, 0, 3); +// } +// else +// if (keyCode == this.gm.keyBindDrop.getKeyCode()) +// { + this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, this.gm.ctrl() ? 1 : 0, 4); +// } + } + } + +// /** +// * Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of +// * KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code) +// */ +// protected void keyTyped(char typedChar, int keyCode) +// { +//// if (keyCode == 1 || keyCode == this.gm.keyBindInventory.getKeyCode()) +//// { +//// this.gm.thePlayer.closeScreen(); +//// } +// +// this.checkHotbarKeys(keyCode); +// +// +// } + + /** + * This function is what controls the hotbar shortcut check when you press a number key when hovering a stack. Args + * : keyCode, Returns true if a Hotbar key is pressed, else false + */ + public void useHotbar(int slot) + { + if (!this.clickSide((this.gm.mouse_x - this.container_x) / 2, (this.gm.mouse_y - this.container_y) / 2, slot, this.gm.shift(), this.gm.ctrl()) && this.gm != null && this.gm.player != null && this.gm.player.inventory.getItemStack() == null && this.cheatStack == null && this.theSlot != null) + { +// for (int i = 0; i < 9; ++i) +// { +// if (keyCode == this.gm.keyBindsHotbar[i].getKeyCode()) +// { + this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, slot, 2); +// return true; +// } +// } + } + +// return false; + } + + /** + * Called when the screen is unloaded. Used to disable keyboard repeat events + */ + public void onGuiClosed() + { + if (this.gm != null && this.gm.player != null) + { + this.inventorySlots.onContainerClosed(this.gm.player); + } + } + + /** + * Returns true if this GUI should pause the game when it is displayed in single-player + */ +// public boolean doesGuiPauseGame() +// { +// return false; +// } + + /** + * Called from the main game loop to update the screen. + */ + public void updateScreen() + { +// super.updateScreen(); + + if (this.gm != null && this.gm.player != null && (!this.gm.player.isEntityAlive() || this.gm.player.dead)) + { + this.gm.player.closeScreen(); + } + } + + public void renderItemOverlayIntoGUI(ItemStack stack, int xPosition, int yPosition, String text) + { + renderItemOverlay(stack, this.container_x + xPosition * 2, this.container_y + yPosition * 2, text); + } + + public static void renderItemOverlay(ItemStack stack, int xPosition, int yPosition, String text) + { + if (stack != null) + { + if (stack.stackSize != 1 || text != null) + { + String s = text == null ? ItemStack.formatAmount(stack.stackSize) : text; + + if (text == null && stack.stackSize < 1) + { + s = TextColor.RED + ItemStack.formatAmount(stack.stackSize); + } +// this.drawString(s, , ); +// Vec2i size = Drawing.txt_size(0, 0, 0, 0, 65536, 65536, s); +// int x = - size.xpos; // this.getStringWidth(s); +// int y = ; +// x = x * 2 + this.container_x; +// y = y * 2 + this.container_y; + Drawing.drawTextRight(s, xPosition + 32, yPosition + 17, 0xffffffff); + } + + if (stack.isItemDamaged()) + { + int j = (int)Math.round(28.0D - (double)stack.getItemDamage() * 28.0D / (double)stack.getMaxDamage()); + int i = (int)Math.round(255.0D - (double)stack.getItemDamage() * 255.0D / (double)stack.getMaxDamage()); + draw(xPosition + 2, yPosition + 26, 28, 4, 0, 0, 0); + draw(xPosition + 2, yPosition + 26, 26, 2, (255 - i) / 4, 64, 0); + draw(xPosition + 2, yPosition + 26, j, 2, 255 - i, i, 0); + } + } + } + + private static void draw(int x, int y, int width, int height, int red, int green, int blue) + { +// Drawing.gfx_draw_rect_color(this.container_x + x * 2, this.container_y + y * 2, width * 2, height * 2, 0xff000000 | (red << 16) | (green << 8) | blue); + Drawing.drawRect(x, y, width, height, 0xff000000 | (red << 16) | (green << 8) | blue); + } + + public void drawBackground() { + Drawing.drawRectBorder(this.container_x, this.container_y, this.container_w, this.container_h, 0xff3f3f3f, 0xff000000, 0xff7f7f7f, 0xff1f1f1f); + } + + + protected boolean isInsideTab(CheatTab tab, int x, int y) + { + return x >= this.xSize + 2 + 18 * tab.getHorizontal() && x < this.xSize + 2 + 18 * tab.getHorizontal() + 18 && + y >= 9 * 18 + 4 + 20 * tab.getVertical() && y < 9 * 18 + 4 + 20 * tab.getVertical() + 18; + } + + protected boolean renderInventoryHoveringText(CheatTab tab, int x, int z) + { + if (this.isPointInRegion(this.xSize + 2 + 18 * tab.getHorizontal(), 9 * 18 + 4 + 20 * tab.getVertical(), 18, 18, x, z)) + { + this.hover(tab.getName(), x, z); + return true; + } + else + { + return false; + } + } + + protected void drawTab(CheatTab tab) + { + this.itemRender.zLevel = 100.0F; + ItemStack itemstack = tab.getIconItemStack(); + GlState.enableDepth(); + this.itemRender.renderItemAndEffectIntoGUI(itemstack, this.xSize + 2 + 18 * tab.getHorizontal() + 1, 9 * 18 + 4 + 20 * tab.getVertical() + 1); + this.itemRender.zLevel = 0.0F; + } + + public void scroll(int scr_x, int scr_y, int x, int y, boolean ctrl, boolean shift) { + super.scroll(scr_x, scr_y, x, y, ctrl, shift); + if(this.gm.itemCheat && scr_y != 0 && this.needsScrollBars()) { + int len = ITEM_LIST.size() / 12 - 5; + this.currentScroll = (float)((double)this.currentScroll - (double)scr_y / (double)len); + this.currentScroll = ExtMath.clampf(this.currentScroll, 0.0F, 1.0F); + } + } + + private boolean needsScrollBars() + { + return ITEM_LIST.size() > 12 * 9; + } + + private void setCurrentTab(CheatTab tab) + { + selectedTab = tab; + this.dragSplittingSlots.clear(); + ITEM_LIST.clear(); + tab.displayAllReleventItems(ITEM_LIST); + + this.currentScroll = 0.0F; + } + + private boolean clickSide(int mouseX, int mouseY, int slot, boolean instant, boolean full) { + if(this.gm.itemCheat && this.isPointInRegion(this.xSize + 2, 0, 18 * 12, 18 * 9, mouseX, mouseY) && this.gm.player != null && this.gm.player.inventory.getItemStack() == null && this.cheatStack == null) { + int i = (ITEM_LIST.size() + 12 - 1) / 12 - 9; + int j = (int)((double)(this.currentScroll * (float)i) + 0.5D); + + if (j < 0) + { + j = 0; + } + + int sx = (mouseX - (this.xSize + 2)) / 18; + int sy = mouseY / 18; + int i1 = sx + (sy + j) * 12; + + if(i1 >= 0 && i1 < ITEM_LIST.size()) { + if(slot >= 0 || instant) { + this.gm.player.client.addToSendQueue(new CPacketCheat(ITEM_LIST.get(i1), slot, full)); + } + else { + this.cheatStack = ITEM_LIST.get(i1).copy(); + this.cheatStack.stackSize = full ? this.cheatStack.getMaxStackSize() : 1; + } + return true; + } + } + return false; + } +} diff --git a/client/src/client/gui/container/GuiCrafting.java b/client/src/client/gui/container/GuiCrafting.java new file mode 100755 index 00000000..d38e9137 --- /dev/null +++ b/client/src/client/gui/container/GuiCrafting.java @@ -0,0 +1,42 @@ +package client.gui.container; + +import common.inventory.ContainerWorkbench; +import common.inventory.InventoryPlayer; +import common.util.BlockPos; +import common.world.World; + +public class GuiCrafting extends GuiContainer +{ +// private static final String craftingTableGuiTextures = "textures/gui/crafting_table.png"; + + public GuiCrafting(InventoryPlayer playerInv, World worldIn) + { + this(playerInv, worldIn, BlockPos.ORIGIN); + } + + public GuiCrafting(InventoryPlayer playerInv, World worldIn, BlockPos blockPosition) + { + super(new ContainerWorkbench(playerInv, worldIn, blockPosition)); + } + + /** + * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY + */ + public void drawGuiContainerForegroundLayer() + { + this.drawString("Handwerk", 28, 6); + this.drawString("Inventar", 8, this.ySize - 96 + 2); + } + +// /** +// * Args : renderPartialTicks, mouseX, mouseY +// */ +// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY) +// { +// GlState.color(1.0F, 1.0F, 1.0F, 1.0F); +// this.gm.getTextureManager().bindTexture(craftingTableGuiTextures); +// int i = (this.width - this.xSize) / 2; +// int j = (this.height - this.ySize) / 2; +//// this.rect(i, j, 0, 0, this.xSize, this.ySize); +// } +} diff --git a/client/src/client/gui/container/GuiDispenser.java b/client/src/client/gui/container/GuiDispenser.java new file mode 100755 index 00000000..00184b50 --- /dev/null +++ b/client/src/client/gui/container/GuiDispenser.java @@ -0,0 +1,46 @@ +package client.gui.container; + +import common.inventory.ContainerDispenser; +import common.inventory.IInventory; +import common.inventory.InventoryPlayer; + + +public class GuiDispenser extends GuiContainer +{ +// private static final String dispenserGuiTextures = "textures/gui/dispenser.png"; + + /** The player inventory bound to this GUI. */ + private final InventoryPlayer playerInventory; + + /** The inventory contained within the corresponding Dispenser. */ + public IInventory dispenserInventory; + + public GuiDispenser(InventoryPlayer playerInv, IInventory dispenserInv) + { + super(new ContainerDispenser(playerInv, dispenserInv)); + this.playerInventory = playerInv; + this.dispenserInventory = dispenserInv; + } + + /** + * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY + */ + public void drawGuiContainerForegroundLayer() + { + String s = this.dispenserInventory.getCommandName(); + this.drawString(s, 8, 6); + this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2); + } + +// /** +// * Args : renderPartialTicks, mouseX, mouseY +// */ +// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY) +// { +// GlState.color(1.0F, 1.0F, 1.0F, 1.0F); +// this.gm.getTextureManager().bindTexture(dispenserGuiTextures); +// int i = (this.width - this.xSize) / 2; +// int j = (this.height - this.ySize) / 2; +//// this.rect(i, j, 0, 0, this.xSize, this.ySize); +// } +} diff --git a/client/src/client/gui/container/GuiEnchant.java b/client/src/client/gui/container/GuiEnchant.java new file mode 100755 index 00000000..0b25ef37 --- /dev/null +++ b/client/src/client/gui/container/GuiEnchant.java @@ -0,0 +1,288 @@ +package client.gui.container; + +import common.color.TextColor; +import common.enchantment.Enchantment; +import common.inventory.ContainerEnchantment; +import common.inventory.InventoryPlayer; +import common.rng.Random; +import common.tileentity.IWorldNameable; +import common.world.World; + +public class GuiEnchant extends GuiContainer +{ + /** The ResourceLocation containing the Enchantment GUI texture location */ +// private static final String ENCHANTMENT_TABLE_GUI_TEXTURE = "textures/gui/enchanting_table.png"; + private static final String[] NAMES = "the elder scrolls klaatu berata niktu xyzzy bless curse light darkness fire air earth water hot dry cold wet ignite snuff embiggen twist shorten stretch fiddle destroy imbue galvanize enchant free limited range of towards inside sphere cube self other ball mental physical grow shrink demon elemental spirit animal creature beast humanoid undead fresh stale ".split(" "); + + /** The player inventory currently bound to this GuiEnchantment instance. */ + private final InventoryPlayer playerInventory; + private final Random nameRand = new Random(); + private final Random random = new Random(); + private final ContainerEnchantment container; + private final IWorldNameable table; + +// public int field_147073_u; +// public float field_147071_v; +// public float field_147069_w; +// public float field_147082_x; +// public float field_147081_y; +// public float field_147080_z; +// public float field_147076_A; +// ItemStack field_147077_B; + + public GuiEnchant(InventoryPlayer inventory, World worldIn, IWorldNameable table) + { + super(new ContainerEnchantment(inventory, worldIn)); + this.playerInventory = inventory; + this.container = (ContainerEnchantment)this.inventorySlots; + this.table = table; + } + + /** + * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY + */ + public void drawGuiContainerForegroundLayer() + { + this.drawString(this.table.getCommandName(), 12, 5); + this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2); + } + +// /** +// * Called from the main game loop to update the screen. +// */ +// public void updateScreen() +// { +// super.updateScreen(); +// this.updateAnimation(); +// } + + /** + * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton + */ + public void mouseClicked(int mouseX, int mouseY, int mouseButton) + { + super.mouseClicked(mouseX, mouseY, mouseButton); +// int i = (this.width - this.xSize) / 2; +// int j = (this.height - this.ySize) / 2; + + for (int k = 0; k < 3; ++k) + { + int l = mouseX - 60; + int i1 = mouseY - (14 + 19 * k); + + if (l >= 0 && i1 >= 0 && l < 108 && i1 < 19 && this.container.enchantItem(this.gm.player, k)) + { + this.gm.controller.sendEnchantPacket(this.container.windowId, k); + } + } + } + + public void addButtons() { + super.addButtons(); + this.button(60, 14 + 19 * 0, 108, 19); + this.button(60, 14 + 19 * 1, 108, 19); + this.button(60, 14 + 19 * 2, 108, 19); + } + + /** + * Args : renderPartialTicks, mouseX, mouseY + */ + public void drawGuiContainerBackgroundLayer() + { + this.nameRand.setSeed((long)this.container.xpSeed); + + for (int l = 0; l < 3; ++l) + { + int i1 = 60; + int j1 = i1 + 20; + String s = this.getRandomName(); + int l1 = this.container.enchantLevels[l]; + + if (l1 == 0) + { + this.rect(i1, 14 + 19 * l, 108, 19, 0x404040); + } + else + { + String s1 = "" + l1; + int i2 = 6839882; + + if (/* (k < l + 1 || */ this.gm.player.experienceLevel < l1) // && !this.gm.thePlayer.creative) + { + this.rect(i1, 14 + 19 * l, 108, 19, 0x400000); + this.rect(i1 + 1, 15 + 19 * l, 16, 16, 0x200000); + this.drawString(s, j1, 16 + 19 * l); // , /*k1,*/ (i2 & 16711422) >> 1); + i2 = 4226832; + } + else + { +// int j2 = SKC.getMouseX() - this.guiLeft - 60; +// int k2 = SKC.getMouseY() - this.guiTop - (14 + 19 * l); + +// if (j2 >= 0 && k2 >= 0 && j2 < 108 && k2 < 19) +// { +// this.rect(i1, 14 + 19 * l, 108, 19, 0x20ff20); +// i2 = 16777088; +// } +// else +// { + this.rect(i1, 14 + 19 * l, 108, 19, 0x20ff20); +// } + + this.rect(i1 + 1, 15 + 19 * l, 16, 16, 0x008000); + this.drawString(s, j1, 16 + 19 * l); + i2 = 8453920; + } + + this.drawString(s1, j1 + 86 - this.getStringWidth(s1), 16 + 19 * l + 7); + } + } + } + + /** + * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks + */ + public void drawScreen(int mouseX, int mouseY) + { + super.drawScreen(mouseX, mouseY); +// boolean flag = this.gm.thePlayer.creative; +// int i = this.container.getLapisAmount(); + + for (int j = 0; j < 3; ++j) + { + int k = this.container.enchantLevels[j]; + int l = this.container.enchantmentIds[j]; + int i1 = j + 1; + + if (this.isPointInRegion(60, 14 + 19 * j, 108, 17, mouseX, mouseY) && k > 0 && l >= 0) + { + StringBuilder sb = new StringBuilder(); + + if (l >= 0 && Enchantment.getEnchantmentById(l & 255) != null) + { + String s = Enchantment.getEnchantmentById(l & 255).getFormattedName((l & 65280) >> 8); + sb.append(TextColor.WHITE + s + " . . . ?"); + } + +// if (!flag) +// { +// if (l >= 0 && sb.length() != 0) +// { +// sb.append("\n"); +// } + + if (this.gm.player.experienceLevel < k) + { + sb.append((sb.length() != 0 ? "\n" : "") + TextColor.RED + String.format("Erfahrungsstufe %d erforderlich", this.container.enchantLevels[j])); + } + else + { + String s1 = ""; + +// if (i1 == 1) +// { +// s1 = I18n.format("container.enchant.lapis.one"); +// } +// else +// { +// s1 = I18n.format("container.enchant.lapis.many", i1); +// } +// +// if (i >= i1) +// { +// list.add(ChatFormat.GRAY.toString() + "" + s1); +// } +// else +// { +// list.add(ChatFormat.RED.toString() + "" + s1); +// } + + if (i1 == 1) + { + s1 = "1 Erfahrungsstufe"; + } + else + { + s1 = String.format("%d Erfahrungsstufen", i1); + } + + sb.append((sb.length() != 0 ? "\n" : "") + TextColor.LGRAY.toString() + "" + s1); + } +// } + + this.hover(sb.toString(), mouseX, mouseY); + break; + } + } + } + + private String getRandomName() + { + int i = this.nameRand.zrange(2) + 3; + String s = ""; + + for (int j = 0; j < i; ++j) + { + if (j > 0) + { + s = s + " "; + } + + String name = NAMES[this.nameRand.zrange(NAMES.length)]; + for(int z = 0; z < name.length(); z++) { + s += (char)(name.charAt(z) - 0x61 + 0x80); + } + } + + return s; + } + +// private void updateAnimation() +// { +// ItemStack itemstack = this.inventorySlots.getSlot(0).getStack(); +// +// if (!ItemStack.areItemStacksEqual(itemstack, this.field_147077_B)) +// { +// this.field_147077_B = itemstack; +// +// while (true) +// { +// this.field_147082_x += (float)(this.random.zrange(4) - this.random.zrange(4)); +// +// if (this.field_147071_v > this.field_147082_x + 1.0F || this.field_147071_v < this.field_147082_x - 1.0F) +// { +// break; +// } +// } +// } +// +// ++this.field_147073_u; +// this.field_147069_w = this.field_147071_v; +// this.field_147076_A = this.field_147080_z; +// boolean flag = false; +// +// for (int i = 0; i < 3; ++i) +// { +// if (this.container.enchantLevels[i] != 0) +// { +// flag = true; +// } +// } +// +// if (flag) +// { +// this.field_147080_z += 0.2F; +// } +// else +// { +// this.field_147080_z -= 0.2F; +// } +// +// this.field_147080_z = ExtMath.clampf(this.field_147080_z, 0.0F, 1.0F); +// float f1 = (this.field_147082_x - this.field_147071_v) * 0.4F; +// float f = 0.2F; +// f1 = ExtMath.clampf(f1, -f, f); +// this.field_147081_y += (f1 - this.field_147081_y) * 0.9F; +// this.field_147071_v += this.field_147081_y; +// } +} diff --git a/client/src/client/gui/container/GuiFurnace.java b/client/src/client/gui/container/GuiFurnace.java new file mode 100755 index 00000000..c3aad9ad --- /dev/null +++ b/client/src/client/gui/container/GuiFurnace.java @@ -0,0 +1,71 @@ +package client.gui.container; + +import common.inventory.ContainerFurnace; +import common.inventory.IInventory; +import common.inventory.InventoryPlayer; +import common.tileentity.TileEntityFurnace; + + +public class GuiFurnace extends GuiContainer +{ +// private static final String furnaceGuiTextures = "textures/gui/furnace.png"; + + /** The player inventory bound to this GUI. */ + private final InventoryPlayer playerInventory; + private IInventory tileFurnace; + + public GuiFurnace(InventoryPlayer playerInv, IInventory furnaceInv) + { + super(new ContainerFurnace(playerInv, furnaceInv)); + this.playerInventory = playerInv; + this.tileFurnace = furnaceInv; + } + + /** + * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY + */ + public void drawGuiContainerForegroundLayer() + { + String s = this.tileFurnace.getCommandName(); + this.drawString(s, 8, 6); + this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2); + } + + /** + * Args : renderPartialTicks, mouseX, mouseY + */ + public void drawGuiContainerBackgroundLayer() + { + this.rect(58, 36, 12, 14, 0x202020); + if (TileEntityFurnace.isBurning(this.tileFurnace)) + { + int k = this.getBurnLeftScaled(13); + k = Math.min(k, 13); + this.rect(58, 36 + 13 - k, 12, k + 1, 0xff7f00); + } + + int l = this.getCookProgressScaled(24); + this.rect(79, 39, 24, 8, 0x606060); + if(l > 0) + this.rect(79, 39, l + 1, 8, 0xffaf00); + } + + private int getCookProgressScaled(int pixels) + { + int i = this.tileFurnace.getField(2); + int j = this.tileFurnace.getField(3); + return j != 0 && i != 0 ? i * pixels / j : 0; + } + + private int getBurnLeftScaled(int pixels) + { + int i = this.tileFurnace.getField(1); + + if (i == 0) + { + i = 200; + } + + return this.tileFurnace.getField(0) * pixels / i; + } +} diff --git a/client/src/client/gui/container/GuiHopper.java b/client/src/client/gui/container/GuiHopper.java new file mode 100755 index 00000000..c11362a1 --- /dev/null +++ b/client/src/client/gui/container/GuiHopper.java @@ -0,0 +1,49 @@ +package client.gui.container; + +import client.Client; +import common.inventory.ContainerHopper; +import common.inventory.IInventory; +import common.inventory.InventoryPlayer; + + +public class GuiHopper extends GuiContainer +{ +// /** The ResourceLocation containing the gui texture for the hopper */ +// private static final String HOPPER_GUI_TEXTURE = "textures/gui/hopper.png"; + + /** The player inventory currently bound to this GUI instance */ + private IInventory playerInventory; + + /** The hopper inventory bound to this GUI instance */ + private IInventory hopperInventory; + + public GuiHopper(InventoryPlayer playerInv, IInventory hopperInv) + { + super(new ContainerHopper(playerInv, hopperInv, Client.CLIENT.player)); + this.playerInventory = playerInv; + this.hopperInventory = hopperInv; +// this.allowUserInput = false; + this.ySize = 133; + } + + /** + * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY + */ + public void drawGuiContainerForegroundLayer() + { + this.drawString(this.hopperInventory.getCommandName(), 8, 6); + this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2); + } + +// /** +// * Args : renderPartialTicks, mouseX, mouseY +// */ +// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY) +// { +// GlState.color(1.0F, 1.0F, 1.0F, 1.0F); +// this.gm.getTextureManager().bindTexture(HOPPER_GUI_TEXTURE); +// int i = (this.width - this.xSize) / 2; +// int j = (this.height - this.ySize) / 2; +//// this.rect(i, j, 0, 0, this.xSize, this.ySize); +// } +} diff --git a/client/src/client/gui/container/GuiHorse.java b/client/src/client/gui/container/GuiHorse.java new file mode 100755 index 00000000..ad5cf541 --- /dev/null +++ b/client/src/client/gui/container/GuiHorse.java @@ -0,0 +1,79 @@ +package client.gui.container; + +import client.Client; +import common.entity.animal.EntityHorse; +import common.inventory.ContainerHorseInventory; +import common.inventory.IInventory; + + +public class GuiHorse extends GuiContainer +{ +// private static final String horseGuiTextures = "textures/gui/horse.png"; + + /** The player inventory bound to this GUI. */ + private IInventory playerInventory; + + /** The horse inventory bound to this GUI. */ + private IInventory horseInventory; + +// /** The EntityHorse whose inventory is currently being accessed. */ +// private EntityHorse horseEntity; + +// /** The mouse x-position recorded during the last rendered frame. */ +// private float mousePosx; +// +// /** The mouse y-position recorded during the last renderered frame. */ +// private float mousePosY; + + public GuiHorse(IInventory playerInv, IInventory horseInv, EntityHorse horse) + { + super(new ContainerHorseInventory(playerInv, horseInv, horse, Client.CLIENT.player)); + this.playerInventory = playerInv; + this.horseInventory = horseInv; +// this.horseEntity = horse; +// this.allowUserInput = false; + } + + /** + * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY + */ + public void drawGuiContainerForegroundLayer() + { + this.drawString(this.horseInventory.getCommandName(), 8, 6); + this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2); + } + +// /** +// * Args : renderPartialTicks, mouseX, mouseY +// */ +// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY) +// { +// GlState.color(1.0F, 1.0F, 1.0F, 1.0F); +// this.gm.getTextureManager().bindTexture(horseGuiTextures); +// int i = (this.width - this.xSize) / 2; +// int j = (this.height - this.ySize) / 2; +//// this.rect(i, j, 0, 0, this.xSize, this.ySize); +// +//// if (this.horseEntity.isChested()) +//// { +//// this.rect(i + 79, j + 17, 0, this.ySize, 90, 54); +//// } +// +//// if (this.horseEntity.canWearArmor()) +//// { +//// this.rect(i + 7, j + 35, 0, this.ySize + 54, 18, 18); +//// } +// +//// GuiInventory.drawEntityOnScreen(i + 51, j + 60, 17, (float)(i + 51) - this.mousePosx, (float)(j + 75 - 50) - this.mousePosY, this.horseEntity); +// } + +// /** +// * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks +// */ +// public void drawScreen(int mouseX, int mouseY) +// { +// this.mousePosx = (float)mouseX; +// this.mousePosY = (float)mouseY; +// super.drawScreen(mouseX, mouseY); +// } +} diff --git a/client/src/client/gui/container/GuiInventory.java b/client/src/client/gui/container/GuiInventory.java new file mode 100755 index 00000000..3dd33f07 --- /dev/null +++ b/client/src/client/gui/container/GuiInventory.java @@ -0,0 +1,58 @@ +package client.gui.container; + +import common.entity.npc.EntityNPC; + +public class GuiInventory extends GuiContainer +{ +// private final GuiCheat cheat; +// private float oldMouseX; +// private float oldMouseY; + + public GuiInventory(EntityNPC player) + { + super(player.inventoryContainer); +// this.allowUserInput = true; +// this.cheat = cheat; + } + +// public void updateScreen() +// { +// this.updateActivePotionEffects(); +// } + +// public void initGui() +// { +//// this.buttonList.clear(); +// super.initGui(); +// if(this.cheat != null) +// this.buttonList.add(new Button(1, this.guiLeft + this.xSize - 16, this.guiTop + 4, 12, 12, "X")); +// } + + public void drawGuiContainerForegroundLayer() + { + this.drawString("Handwerk", 86, 16); + } + +// public void drawScreen(int mouseX, int mouseY, float partialTicks) +// { +// super.drawScreen(mouseX, mouseY, partialTicks); +// this.oldMouseX = (float)mouseX; +// this.oldMouseY = (float)mouseY; +// } + +// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY) +// { +// GlState.color(1.0F, 1.0F, 1.0F, 1.0F); +// this.gm.getTextureManager().bindTexture(inventoryBackground); +// int i = this.guiLeft; +// int j = this.guiTop; +//// this.rect(i, j, 0, 0, this.xSize, this.ySize); +//// drawEntityOnScreen(i + 51, j + 75, 30, (float)(i + 51) - this.oldMouseX, (float)(j + 75 - 50) - this.oldMouseY, this.gm.thePlayer); +// } + +// public void actionPerformed(int button) +// { +// if(button == 1 && this.cheat != null && this.gm.thePlayer.inventory.getItemStack() == null) +// this.gm.displayGuiScreen(this.cheat); +// } +} diff --git a/client/src/client/gui/container/GuiMachine.java b/client/src/client/gui/container/GuiMachine.java new file mode 100755 index 00000000..2467e180 --- /dev/null +++ b/client/src/client/gui/container/GuiMachine.java @@ -0,0 +1,44 @@ +package client.gui.container; + +import client.Client; +import common.inventory.ContainerMachine; +import common.inventory.IInventory; +import common.inventory.InventoryPlayer; +import common.tileentity.TileEntityMachine; + + +public class GuiMachine extends GuiContainer +{ +// private final String texture; + private final IInventory playerInv; + private final IInventory machineInv; + private final TileEntityMachine machine; + + public GuiMachine(InventoryPlayer player, IInventory inv, TileEntityMachine machine) + { + super(new ContainerMachine(player, machine, inv, Client.CLIENT.player)); + this.playerInv = player; + this.machineInv = machine; +// this.allowUserInput = false; + this.ySize = 153; +// this.texture = "textures/gui/" + texture + ".png"; + this.machine = machine; + } + + public void drawGuiContainerForegroundLayer() + { + this.drawString(this.machine.getStatus().color + this.machineInv.getCommandName() + " - " + this.machine.getStatus().name, 8, 6); + this.drawString(this.playerInv.getCommandName(), 8, this.ySize - 96 + 2); + this.drawString(String.format("Temperatur: %d °", this.machine.getTemperature()), 8, 18); + this.drawString(this.machine.formatDisplay(), 8, 28); + } + +// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY) +// { +// GlState.color(1.0F, 1.0F, 1.0F, 1.0F); +// this.gm.getTextureManager().bindTexture(this.texture); +// int i = (this.width - this.xSize) / 2; +// int j = (this.height - this.ySize) / 2; +//// this.rect(i, j, 0, 0, this.xSize, this.ySize); +// } +} diff --git a/client/src/client/gui/container/GuiMerchant.java b/client/src/client/gui/container/GuiMerchant.java new file mode 100755 index 00000000..0b1543ed --- /dev/null +++ b/client/src/client/gui/container/GuiMerchant.java @@ -0,0 +1,287 @@ +package client.gui.container; + +import org.lwjgl.opengl.GL11; + +import client.renderer.GlState; +import client.renderer.ItemRenderer; +import common.inventory.ContainerMerchant; +import common.inventory.InventoryPlayer; +import common.item.ItemStack; +import common.packet.CPacketAction; +import common.village.MerchantRecipe; +import common.village.MerchantRecipeList; +import common.world.World; + +public class GuiMerchant extends GuiContainer +{ +// private static final String MERCHANT_GUI_TEXTURE = "textures/gui/trading.png"; + + private int selectedMerchantRecipe; + private String chatComponent; + + public GuiMerchant(InventoryPlayer inv, String name, World worldIn) + { + super(new ContainerMerchant(inv, null, worldIn)); + this.chatComponent = name != null ? name : "NSC"; + } + + /** + * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the + * window resizes, the buttonList is cleared beforehand. + */ +// public void initGui() +// { +// super.initGui(); +// } + + public void addButtons() { + super.addButtons(); + this.button(120 + 27, 24, 12, 16); + this.button(36 - 19, 24, 12, 16); + this.button(36 - 1, 24 - 1, 18, 18); + this.button(62 - 1, 24 - 1, 18, 18); + this.button(120 - 1, 24 - 1, 18, 18); + } + + public void mouseClicked(int mouseX, int mouseY, int mouseButton) + { + if (mouseButton == 0) + { +// int i = (this.width - this.xSize) / 2; +// int j = (this.height - this.ySize) / 2; + if(mouseX >= 147 && mouseX < 147 + 12 && mouseY >= 24 && mouseY < 24 + 16) { + this.switchTrade(true); + return; + } + else if(mouseX >= 17 && mouseX < 17 + 12 && mouseY >= 24 && mouseY < 24 + 16) { + this.switchTrade(false); + return; + } +// this.buttonList.add(new Button(1, i + 120 + 27, j + 24 - 1, 12, 19, ">")); +// this.buttonList.add(new Button(2, i + 36 - 19, j + 24 - 1, 12, 19, "<")); + + } + + super.mouseClicked(mouseX, mouseY, mouseButton); + } + + /** + * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY + */ + public void drawGuiContainerForegroundLayer() + { + String s = this.chatComponent; + this.drawString(s, 8, 6); + this.drawString("Inventar", 8, this.ySize - 96 + 2); + } + + public void drawOverlays() { + super.drawOverlays(); + MerchantRecipeList merchantrecipelist = this.getRecipes(); + if (merchantrecipelist != null && !merchantrecipelist.isEmpty()) { + int k = this.selectedMerchantRecipe; + MerchantRecipe merchantrecipe = (MerchantRecipe)merchantrecipelist.get(k); + ItemStack itemstack = merchantrecipe.getItemToBuy(); + ItemStack itemstack1 = merchantrecipe.getSecondItemToBuy(); + ItemStack itemstack2 = merchantrecipe.getItemToSell(); + this.renderItemOverlayIntoGUI(itemstack, 36, 24, null); + if(itemstack1 != null) + this.renderItemOverlayIntoGUI(itemstack1, 62, 24, null); + this.renderItemOverlayIntoGUI(itemstack2, 120, 24, null); + } + } + + /** + * Called by the controls from the buttonList when activated. (Mouse pressed for buttons) + */ + public void switchTrade(boolean forward) + { + boolean flag = false; + + if (forward) + { + ++this.selectedMerchantRecipe; + MerchantRecipeList merchantrecipelist = this.getRecipes(); + + if (merchantrecipelist != null && this.selectedMerchantRecipe >= merchantrecipelist.size()) + { + this.selectedMerchantRecipe = merchantrecipelist.size() - 1; + } + + flag = true; + } + else + { + --this.selectedMerchantRecipe; + + if (this.selectedMerchantRecipe < 0) + { + this.selectedMerchantRecipe = 0; + } + + flag = true; + } + + if (flag) + { + ((ContainerMerchant)this.inventorySlots).setCurrentRecipeIndex(this.selectedMerchantRecipe); +// PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer()); +// packetbuffer.writeInt(this.selectedMerchantRecipe); + this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.SELECT_TRADE, + this.selectedMerchantRecipe)); + } + } + +// /** +// * Args : renderPartialTicks, mouseX, mouseY +// */ +// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY) +// { +// GlState.color(1.0F, 1.0F, 1.0F, 1.0F); +// this.gm.getTextureManager().bindTexture(MERCHANT_GUI_TEXTURE); +// int i = (this.width - this.xSize) / 2; +// int j = (this.height - this.ySize) / 2; +//// this.rect(i, j, 0, 0, this.xSize, this.ySize); +//// MerchantRecipeList merchantrecipelist = this.merchant.getRecipes(this.gm.thePlayer); +// +//// if (merchantrecipelist != null && !merchantrecipelist.isEmpty()) +//// { +//// int k = this.selectedMerchantRecipe; +//// +//// if (k < 0 || k >= merchantrecipelist.size()) +//// { +//// return; +//// } +// +//// MerchantRecipe merchantrecipe = (MerchantRecipe)merchantrecipelist.get(k); +// +//// if (merchantrecipe.isRecipeDisabled()) +//// { +//// this.gm.getTextureManager().bindTexture(MERCHANT_GUI_TEXTURE); +//// GlState.color(1.0F, 1.0F, 1.0F, 1.0F); +//// GlState.disableLighting(); +//// this.rect(this.guiLeft + 83, this.guiTop + 21, 212, 0, 28, 21); +//// this.rect(this.guiLeft + 83, this.guiTop + 51, 212, 0, 28, 21); +//// } +//// } +// } + + /** + * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks + */ + public void drawScreen(int mouseX, int mouseY) + { + super.drawScreen(mouseX, mouseY); + MerchantRecipeList merchantrecipelist = this.getRecipes(); + + if (merchantrecipelist != null && !merchantrecipelist.isEmpty()) + { +// int i = (this.width - this.xSize) / 2; +// int j = (this.height - this.ySize) / 2; + int k = this.selectedMerchantRecipe; + MerchantRecipe merchantrecipe = (MerchantRecipe)merchantrecipelist.get(k); + ItemStack itemstack = merchantrecipe.getItemToBuy(); + ItemStack itemstack1 = merchantrecipe.getSecondItemToBuy(); + ItemStack itemstack2 = merchantrecipe.getItemToSell(); + GL11.glPushMatrix(); + ItemRenderer.enableGUIStandardItemLighting(); + GlState.disableLighting(); + GlState.enableRescaleNormal(); + GlState.enableColorMaterial(); + GlState.enableLighting(); + this.itemRender.zLevel = 100.0F; + this.itemRender.renderItemAndEffectIntoGUI(itemstack, 36, 24); +// this.itemRender.renderItemOverlays(itemstack, 36, 24); + + if (itemstack1 != null) + { + this.itemRender.renderItemAndEffectIntoGUI(itemstack1, 62, 24); +// this.itemRender.renderItemOverlays(itemstack1, 62, 24); + } + + this.itemRender.renderItemAndEffectIntoGUI(itemstack2, 120, 24); +// this.itemRender.renderItemOverlays(itemstack2, 120, 24); + this.itemRender.zLevel = 0.0F; + GlState.disableLighting(); + + if (this.isPointInRegion(36, 24, 16, 16, mouseX, mouseY) && itemstack != null) + { + this.renderToolTip(itemstack, mouseX, mouseY); + } + else if (itemstack1 != null && this.isPointInRegion(62, 24, 16, 16, mouseX, mouseY) && itemstack1 != null) + { + this.renderToolTip(itemstack1, mouseX, mouseY); + } + else if (itemstack2 != null && this.isPointInRegion(120, 24, 16, 16, mouseX, mouseY) && itemstack2 != null) + { + this.renderToolTip(itemstack2, mouseX, mouseY); + } +// else if (merchantrecipe.isRecipeDisabled() && (this.isPointInRegion(83, 21, 28, 21, mouseX, mouseY) || this.isPointInRegion(83, 51, 28, 21, mouseX, mouseY))) +// { +// this.drawCreativeTabHoveringText(I18n.format("merchant.deprecated"), mouseX, mouseY); +// } + + GL11.glPopMatrix(); + GlState.enableLighting(); + GlState.enableDepth(); + ItemRenderer.enableStandardItemLighting(); +// int i = (this.width - this.xSize) / 2; +// int j = (this.height - this.ySize) / 2; +// if(mouseX >= i + 147 && mouseX < i + 147 + 12 && mouseY >= j + 23 && mouseX < j + 23 + 19) { +// SKC.highlight(i + 147, j + 23, 12, 19); +// } +// else if(mouseX >= i + 17 && mouseX < i + 17 + 12 && mouseY >= j + 23 && mouseX < j + 23 + 19) { +// SKC.highlight(i + 17, j + 23, 12, 19); +// } + } + } + + public void setRecipes(MerchantRecipeList recipes) + { + ((ContainerMerchant)this.inventorySlots).getMerchantInventory().setRecipes(recipes); + } + + private MerchantRecipeList getRecipes() + { + return ((ContainerMerchant)this.inventorySlots).getMerchantInventory().getRecipes(); + } + +// static class MerchantButton extends Button +// { +// private final boolean next; +// +// public MerchantButton(int buttonID, int x, int y, boolean isNext) +// { +// super(buttonID, x, y, 12, 19, ""); +// this.next = isNext; +// } +// +// public void drawButton(Game gm, int mouseX, int mouseY) +// { +// if (this.visible) +// { +// gm.getTextureManager().bindTexture(GuiMerchant.MERCHANT_GUI_TEXTURE); +// GlState.color(1.0F, 1.0F, 1.0F, 1.0F); +// boolean flag = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; +// int i = 0; +// int j = 176; +// +// if (!this.enabled) +// { +// j += this.width * 2; +// } +// else if (flag) +// { +// j += this.width; +// } +// +// if (!this.next) +// { +// i += this.height; +// } +// +// this.rect(this.xPosition, this.yPosition, j, i, this.width, this.height); +// } +// } +// } +} diff --git a/client/src/client/gui/container/GuiRepair.java b/client/src/client/gui/container/GuiRepair.java new file mode 100755 index 00000000..2d7dfb70 --- /dev/null +++ b/client/src/client/gui/container/GuiRepair.java @@ -0,0 +1,218 @@ +package client.gui.container; + +import java.util.List; + +import client.Client; +import common.inventory.Container; +import common.inventory.ContainerRepair; +import common.inventory.ICrafting; +import common.inventory.IInventory; +import common.inventory.InventoryPlayer; +import common.item.ItemStack; +import common.world.World; + +public class GuiRepair extends GuiContainer implements ICrafting +{ +// private static final String anvilResource = "textures/gui/anvil.png"; + + private ContainerRepair anvil; +// private TextField nameField; + private InventoryPlayer playerInventory; + + public GuiRepair(InventoryPlayer inventoryIn, World worldIn) + { + super(new ContainerRepair(inventoryIn, worldIn, Client.CLIENT.player)); + this.playerInventory = inventoryIn; + this.anvil = (ContainerRepair)this.inventorySlots; + } + + /** + * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the + * window resizes, the buttonList is cleared beforehand. + */ + public void initGui() + { + super.initGui(); +// Keyboard.enableRepeatEvents(true); +// int i = (this.width - this.xSize) / 2; +// int j = (this.height - this.ySize) / 2; +// this.nameField = new TextField(i + 62, j + 24, 103, 12); +// this.nameField.setTextColor(-1); +// this.nameField.setDisabledTextColour(-1); +// this.nameField.setEnableBackgroundDrawing(false); +// this.nameField.setMaxStringLength(30); + this.inventorySlots.removeCraftingFromCrafters(this); + this.inventorySlots.onCraftGuiOpened(this); + } + + /** + * Called when the screen is unloaded. Used to disable keyboard repeat events + */ + public void onGuiClosed() + { + super.onGuiClosed(); +// Keyboard.enableRepeatEvents(false); + this.inventorySlots.removeCraftingFromCrafters(this); + } + + /** + * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY + */ + public void drawGuiContainerForegroundLayer() + { +// GlState.disableLighting(); +// GlState.disableBlend(); + this.drawString("Amboss", 60, 6); + + if (this.anvil.maximumCost > 0) + { + int i = 8453920; + boolean flag = true; + String s = String.format("Erfahrungskosten: %d", this.anvil.maximumCost); + + if (this.anvil.maximumCost >= 40) // && !this.gm.thePlayer.creative) + { + s = "Zu teuer!"; + i = 16736352; + } + else if (!this.anvil.getSlot(2).getHasStack()) + { + flag = false; + } + else if (!this.anvil.getSlot(2).canTakeStack(this.playerInventory.player)) + { + i = 16736352; + } + + if (flag) + { + int j = -16777216 | (i & 16579836) >> 2 | i & -16777216; + int k = this.xSize - 8 - this.getStringWidth(s); + int l = 67; + +// if (FontRenderer.getUnicodeFlag()) +// { +// drawRect(k - 3, l - 2, this.xSize - 7, l + 10, -16777216); +// drawRect(k - 2, l - 1, this.xSize - 8, l + 9, -12895429); +// } +// else +// { + this.drawString(s, k, l + 1); + this.drawString(s, k + 1, l); + this.drawString(s, k + 1, l + 1); +// } + + this.drawString(s, k, l); + } + } + +// GlState.enableLighting(); + } + + /** + * Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of + * KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code) + */ +// protected void keyTyped(char typedChar, int keyCode) +// { +// if (this.nameField.textboxKeyTyped(typedChar, keyCode)) +//// { +// this.renameItem(); +//// } +//// else +//// { +//// super.keyTyped(typedChar, keyCode); +//// } +// } +// +// private void renameItem() +// { +// String s = this.nameField.getText(); +// Slot slot = this.anvil.getSlot(0); +// +// if (slot != null && slot.getHasStack() && !slot.getStack().hasDisplayName() && s.equals(slot.getStack().getDisplayName())) +// { +// s = ""; +// } +// +// this.anvil.updateItemName(s); +// this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketMessage(CPacketMessage.Type.ITEM, s)); +// } +// +// /** +// * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton +// */ +// protected void mouseClicked(int mouseX, int mouseY, int mouseButton) +// { +// super.mouseClicked(mouseX, mouseY, mouseButton); +// this.nameField.mouseClicked(mouseX, mouseY, mouseButton); +// } + + /** + * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks + */ +// public void drawScreen(int mouseX, int mouseY, float partialTicks) +// { +// super.drawScreen(mouseX, mouseY, partialTicks); +// GlState.disableLighting(); +// GlState.disableBlend(); +// this.nameField.drawTextBox(); +// } + +// /** +// * Args : renderPartialTicks, mouseX, mouseY +// */ +// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY) +// { +// GlState.color(1.0F, 1.0F, 1.0F, 1.0F); +// this.gm.getTextureManager().bindTexture(anvilResource); +// int i = (this.width - this.xSize) / 2; +// int j = (this.height - this.ySize) / 2; +//// this.rect(i, j, 0, 0, this.xSize, this.ySize); +//// this.rect(i + 59, j + 20, 0, this.ySize + (this.anvil.getSlot(0).getHasStack() ? 0 : 16), 110, 16); +// +//// if ((this.anvil.getSlot(0).getHasStack() || this.anvil.getSlot(1).getHasStack()) && !this.anvil.getSlot(2).getHasStack()) +//// { +//// this.rect(i + 99, j + 45, this.xSize, 0, 28, 21); +//// } +// } + + /** + * update the crafting window inventory with the items in the list + */ + public void updateCraftingInventory(Container containerToSend, List itemsList) + { + this.sendSlotContents(containerToSend, 0, containerToSend.getSlot(0).getStack()); + } + + /** + * Sends the contents of an inventory slot to the client-side Container. This doesn't have to match the actual + * contents of that slot. Args: Container, slot number, slot contents + */ + public void sendSlotContents(Container containerToSend, int slotInd, ItemStack stack) + { +// if (slotInd == 0) +// { +// this.nameField.setText(stack == null ? "" : stack.getDisplayName()); +// this.nameField.setEnabled(stack != null); +// +// if (stack != null) +// { +// this.renameItem(); +// } +// } + } + + /** + * Sends two ints to the client-side Container. Used for furnace burning time, smelting progress, brewing progress, + * and enchanting level. Normally the first int identifies which variable to update, and the second contains the new + * value. Both are truncated to shorts in non-local SMP. + */ + public void sendProgressBarUpdate(Container containerIn, int varToUpdate, int newValue) + { + } + + public void sendAllWindowProperties(Container p_175173_1_, IInventory p_175173_2_) + { + } +} diff --git a/client/src/main/java/client/gui/element/ActButton.java b/client/src/client/gui/element/ActButton.java similarity index 100% rename from client/src/main/java/client/gui/element/ActButton.java rename to client/src/client/gui/element/ActButton.java diff --git a/client/src/client/gui/element/Area.java b/client/src/client/gui/element/Area.java new file mode 100644 index 00000000..d93c6b73 --- /dev/null +++ b/client/src/client/gui/element/Area.java @@ -0,0 +1,159 @@ +package client.gui.element; + +import client.gui.Font; +import client.renderer.Drawing; +import client.renderer.Drawing.Offset; +import client.renderer.Drawing.Vec2i; +import common.util.CharValidator; +import common.util.ExtMath; +import common.util.Util; + +public class Area extends Textbox { + private int textHeight; + private int scrollPos; + private int cursorX; + private int cursorY; + + private Area(int x, int y, int w, int h, int cap, boolean editable, CharValidator validator, String text) { + super(x, y, w, h, cap, editable, null, validator); + this.setText(text); + } + + public Area(int x, int y, int w, int h, int cap, CharValidator validator, String text) { + this(x, y, w, h, cap, true, validator, text); + } + + public Area(int x, int y, int w, int h, int cap, String text) { + this(x, y, w, h, cap, true, null, text); + } + + public Area(int x, int y, int w, int h, String text) { + this(x, y, w, h, Integer.MAX_VALUE, false, null, text); + } + + public void updateText() { + this.textHeight = Drawing.txt_size(this.pos_x + this.margin_x1, this.pos_y + this.margin_y1, + this.pos_x + this.margin_x1, this.pos_y + this.margin_y1, + this.pos_x + (this.size_x - (this.margin_x1 + this.margin_x2)), Integer.MAX_VALUE, this.text).ypos; + } + + public void scroll(int scr_x, int scr_y, int x, int y, boolean ctrl, boolean shift) { + if(scr_y != 0) { + int limit = Font.YGLYPH + this.textHeight - (this.size_y - (this.margin_y1 + this.margin_y2)); + limit = ExtMath.clampi(limit, 0, 0x7fffffff); + int prev = this.text_y; + this.text_y += (scr_y < 0 ? -1 : 1) * (ctrl ? 1 : Font.YGLYPH) * this.gm.scrollLines * (shift ? 10 : 1); + this.text_y = ExtMath.clampi(this.text_y, -limit, 0); + if(this.sel_start >= 0) + this.cursorY += (this.text_y - prev); + } + } + + public void mouserel() { + this.scrollPos = 0; + } + + public void onReturn(boolean shift) { + insertText("\n"); + } + + public void onSelection(boolean up) { + if(!up && this.sel_start != this.sel_end) { + this.sel_start = this.sel_drag = this.sel_end; + } + else if(up && this.sel_start != this.sel_end) { + this.sel_end = this.sel_drag = this.sel_start; + } + if(!up && this.sel_start >= 0) { + if(this.sel_end < this.text.length()) { + int nl = this.text.indexOf('\n', this.sel_end); + this.sel_end = nl >= 0 ? nl + 1 : this.text.length(); + this.sel_start = this.sel_drag = this.sel_end; + } + else { + this.sel_end = this.sel_drag = this.sel_start; + } + gui_text_update_cur(this.sel_end, true); + } + else if(up && this.sel_start >= 0) { + if(this.sel_start > 0) { + int nl = this.text.lastIndexOf('\n', this.sel_start); + this.sel_start = nl >= 0 ? nl : 0; + } + this.sel_end = this.sel_drag = this.sel_start; + gui_text_update_cur(this.sel_end, true); + } + } + + public void update() { + if(this.scrollPos != 0) { + int n = this.updateScroll(this.scrollPos); + this.text_y += n; + if(n != 0) + gui_text_clamp_scroll(); + } + } + + public void shift(int shift_x, int shift_y) { + super.shift(shift_x, shift_y); + this.cursorX += shift_x; + this.cursorY += shift_y; + } + + protected void gui_text_clamp_scroll() { + int limit = Font.YGLYPH + this.textHeight - (this.size_y - (this.margin_y1 + this.margin_y2)); + limit = ExtMath.clampi(limit, 0, 0x7fffffff); + this.text_y = ExtMath.clampi(this.text_y, -limit, 0); + } + + protected void updateCursor(int offset, boolean shift, int x1, int y1, int x2, int y2) { + Vec2i coord = Drawing.txt_coord(offset, x1, y1 + this.text_y, + x1 + this.text_x, y1 + this.text_y, this.pos_x + x2, 0x7fffffff, this.text); + this.cursorX = coord.xpos; + this.cursorY = coord.ypos; + if(shift) { + if(this.cursorY < y1) + this.text_y += y1 - this.cursorY; + else if((this.cursorY + Font.YGLYPH) >= (y1 + y2)) + this.text_y -= (this.cursorY + Font.YGLYPH) - (y1 + y2); + gui_text_update_cur(offset, false); + } + } + + protected int onCursorOffset(int x, int y, int x1, int y1, int x2, int y2) { + Offset off = Drawing.txt_offset(x, y, x1, y1 + this.text_y, + x1 + this.text_x, y1 + this.text_y, this.pos_x + x2, 0x7fffffff, this.text); + if(off != null) { + this.cursorX = off.xpos; + this.cursorY = off.ypos; + } + int offset = off == null ? 0 : off.offset; + if(y < y1) + this.scrollPos = y1 - y; + else if(y >= (y1 + y2)) + this.scrollPos = -(y - (y1 + y2)); + return offset; + } + + protected void drawForeground(int x1, int y1, int x2, int y2) { + Drawing.txt_draw(x1, y1 + this.text_y, + x1 + this.text_x, y1 + this.text_y, + this.pos_x + x2, Integer.MAX_VALUE, this.enabled ? this.gm.style.text_field : Util.mulColor(this.gm.style.text_field, 0.5f), this.text); + if(this.sel_start >= 0 && this.sel_end != this.sel_start) + Drawing.txt_overlay(this.sel_start, this.sel_end, x1, y1 + this.text_y, + x1 + this.text_x, y1 + this.text_y, + this.pos_x + x2, Integer.MAX_VALUE, this.enabled ? 0x808080ff : 0x80404040, this.text); + } + + protected char getNewline() { + return '\n'; + } + + protected int getCursorX(int x1, int x2) { + return this.cursorX; + } + + protected int getCursorY(int y1, int y2) { + return this.cursorY; + } +} diff --git a/client/src/main/java/client/gui/element/Bar.java b/client/src/client/gui/element/Bar.java similarity index 100% rename from client/src/main/java/client/gui/element/Bar.java rename to client/src/client/gui/element/Bar.java diff --git a/client/src/main/java/client/gui/element/ButtonCallback.java b/client/src/client/gui/element/ButtonCallback.java similarity index 100% rename from client/src/main/java/client/gui/element/ButtonCallback.java rename to client/src/client/gui/element/ButtonCallback.java diff --git a/client/src/main/java/client/gui/element/Dropdown.java b/client/src/client/gui/element/Dropdown.java similarity index 82% rename from client/src/main/java/client/gui/element/Dropdown.java rename to client/src/client/gui/element/Dropdown.java index 854b3c45..a49b0534 100644 --- a/client/src/main/java/client/gui/element/Dropdown.java +++ b/client/src/client/gui/element/Dropdown.java @@ -12,12 +12,12 @@ import common.util.Util; public class Dropdown extends Element { public class Handle extends Element { private Handle(boolean up) { - super(Dropdown.this.pos_x, Dropdown.this.pos_y + (up ? -(Font.HEIGHT * Dropdown.this.values.length + 2) : Dropdown.this.size_y), Dropdown.this.size_x, Font.HEIGHT * Dropdown.this.values.length + 2, null); + super(Dropdown.this.pos_x, Dropdown.this.pos_y + (up ? -(Font.YGLYPH * Dropdown.this.values.length + 2) : Dropdown.this.size_y), Dropdown.this.size_x, Font.YGLYPH * Dropdown.this.values.length + 2, null); StringBuilder sb = new StringBuilder(); for(T value : Dropdown.this.values) { if(sb.length() > 0) sb.append('\n'); - sb.append(value instanceof Displayable disp ? disp.getDisplay() : value.toString()); + sb.append(value instanceof Displayable ? ((Displayable)value).getDisplay() : value.toString()); } this.setText(sb.toString()); this.visible = /* this.r_dirty = */ false; @@ -58,7 +58,7 @@ public class Dropdown extends Element { } public void drawHover() { - int m = ((this.gm.mouseY - (this.pos_y + this.margin_y1)) * Dropdown.this.values.length / (this.size_y - (this.margin_y1 + this.margin_y2))); + int m = ((this.gm.mouse_y - (this.pos_y + this.margin_y1)) * Dropdown.this.values.length / (this.size_y - (this.margin_y1 + this.margin_y2))); // if((sys.mouse_y - this.pos_y) < (this.size_y - this.margin_y2)) Drawing.drawRect(this.pos_x + this.margin_x1, this.pos_y + this.margin_y1 + ExtMath.clampi(m, 0, Dropdown.this.values.length - 1) * ((this.size_y - (this.margin_y1 + this.margin_y2)) / Dropdown.this.values.length), this.size_x - (this.margin_x1 + this.margin_x2), (this.size_y - (this.margin_y1 + this.margin_y2)) / Dropdown.this.values.length, Gui.HOVER_COLOR); } @@ -82,15 +82,10 @@ public class Dropdown extends Element { } public Dropdown(int x, int y, int w, int h, boolean up, T[] values, T def, T init, DropdownCallback callback, final String text) { - this(x, y, w, h, up, values, def, init, callback, text == null ? new Formatter>() { + this(x, y, w, h, up, values, def, init, callback, new Formatter>() { public String use(Dropdown elem) { T value = elem.getValue(); - return value instanceof Displayable disp ? disp.getDisplay() : value.toString(); - } - } : new Formatter>() { - public String use(Dropdown elem) { - T value = elem.getValue(); - return String.format("%s: %s", text, value instanceof Displayable disp ? disp.getDisplay() : value.toString()); + return String.format("%s: %s", text, value instanceof Displayable ? ((Displayable)value).getDisplay() : value.toString()); } }); } diff --git a/client/src/main/java/client/gui/element/DropdownCallback.java b/client/src/client/gui/element/DropdownCallback.java similarity index 100% rename from client/src/main/java/client/gui/element/DropdownCallback.java rename to client/src/client/gui/element/DropdownCallback.java diff --git a/client/src/main/java/client/gui/element/Element.java b/client/src/client/gui/element/Element.java similarity index 94% rename from client/src/main/java/client/gui/element/Element.java rename to client/src/client/gui/element/Element.java index 966c7970..f5f8b885 100644 --- a/client/src/main/java/client/gui/element/Element.java +++ b/client/src/client/gui/element/Element.java @@ -15,8 +15,6 @@ import common.sound.PositionedSound; import common.util.Util; public abstract class Element { - public static final int BASE_HEIGHT = 18; - protected final Client gm = Client.CLIENT; protected Gui gui; @@ -38,11 +36,12 @@ public abstract class Element { public boolean visible = true; public boolean enabled = true; + public Element(int x, int y, int w, int h, Formatter formatter) { this.pos_x = x; this.pos_y = y; this.size_x = w; - this.size_y = h <= 0 ? BASE_HEIGHT : h; + this.size_y = h; this.format = formatter; // gui_update_style(this, 1); // if(type != ElemType.SLIDER) { @@ -113,8 +112,8 @@ public abstract class Element { public void updateText() { Vec2i size = Drawing.getSize(this.text); - this.text_x = ((this.size_x - (this.margin_x1 + this.margin_x2)) - size.xpos) / 2; - this.text_y = ((this.size_y - (this.margin_y1 + this.margin_y2)) - size.ypos + 1) / 2; + this.text_x = (this.size_x - size.xpos) / 2; + this.text_y = (this.size_y - size.ypos) / 2; } public void setText(String str) { @@ -221,7 +220,7 @@ public abstract class Element { int x2 = this.size_x - (this.margin_x1 + this.margin_x2); int y2 = this.size_y - (this.margin_y1 + this.margin_y2); // if(elem.type == ElemType.FIELD) { - this.gm.scissor(x1 < 0 ? 0 : x1, (this.gm.fbY - (y1 + y2)) < 0 ? 0 : (this.gm.fbY - (y1 + y2)), x2 < 0 ? 0 : x2, y2 < 0 ? 0 : y2); + GL11.glScissor(x1 < 0 ? 0 : x1, (this.gm.fb_y - (y1 + y2)) < 0 ? 0 : (this.gm.fb_y - (y1 + y2)), x2 < 0 ? 0 : x2, y2 < 0 ? 0 : y2); GL11.glEnable(GL11.GL_SCISSOR_TEST); // } // if(this.type == ElemType.CUSTOM) diff --git a/client/src/main/java/client/gui/element/Field.java b/client/src/client/gui/element/Field.java similarity index 89% rename from client/src/main/java/client/gui/element/Field.java rename to client/src/client/gui/element/Field.java index 53099b64..bd82813e 100644 --- a/client/src/main/java/client/gui/element/Field.java +++ b/client/src/client/gui/element/Field.java @@ -15,7 +15,7 @@ public class Field extends Textbox { private Field(int x, int y, int w, int h, int cap, boolean editable, FieldCallback callback, CharValidator validator, String text) { super(x, y, w, h, cap, editable, callback, validator); - this.text_y = (this.size_y - (this.margin_y1 + this.margin_y2 + Font.HEIGHT)) / 2; + this.text_y = (this.size_y - (this.margin_y1 + this.margin_y2 + Font.YGLYPH)) / 2; this.setText(text); } @@ -34,7 +34,7 @@ public class Field extends Textbox { public void updateText() { this.textWidth = Drawing.txt_size(this.pos_x + this.margin_x1, this.pos_y + this.margin_y1, this.pos_x + this.margin_x1, this.pos_y + this.margin_y1, - Integer.MAX_VALUE, Integer.MAX_VALUE, this.getDrawnText()).xpos; + Integer.MAX_VALUE, Integer.MAX_VALUE, this.text).xpos; } public void mouserel() { @@ -69,10 +69,10 @@ public class Field extends Textbox { public void scroll(int scr_x, int scr_y, int x, int y, boolean ctrl, boolean shift) { if(scr_y != 0 || scr_x != 0) { - int limit = Font.WIDTH + this.textWidth - (this.size_x - (this.margin_x1 + this.margin_x2)); + int limit = Font.XGLYPH + this.textWidth - (this.size_x - (this.margin_x1 + this.margin_x2)); limit = ExtMath.clampi(limit, 0, 0x7fffffff); int prev = this.text_x; - this.text_x += ((scr_y != 0 ? scr_y : (-scr_x)) < 0 ? -1 : 1) * (ctrl ? 1 : Font.WIDTH) * this.gm.scrollLines * (shift ? 10 : 1); + this.text_x += ((scr_y != 0 ? scr_y : (-scr_x)) < 0 ? -1 : 1) * (ctrl ? 1 : Font.XGLYPH) * this.gm.scrollLines * (shift ? 10 : 1); this.text_x = ExtMath.clampi(this.text_x, -limit, 0); if(this.sel_start >= 0) this.cursorPos += (this.text_x - prev); @@ -84,31 +84,31 @@ public class Field extends Textbox { } protected int getCursorY(int y1, int y2) { - return y1 + (y2 - Font.HEIGHT) / 2; + return y1 + (y2 - Font.YGLYPH) / 2; } protected void gui_text_clamp_scroll() { - int limit = Font.WIDTH + this.textWidth - (this.size_x - (this.margin_x1 + this.margin_x2)); + int limit = Font.XGLYPH + this.textWidth - (this.size_x - (this.margin_x1 + this.margin_x2)); limit = ExtMath.clampi(limit, 0, 0x7fffffff); this.text_x = ExtMath.clampi(this.text_x, -limit, 0); } protected void updateCursor(int offset, boolean shift, int x1, int y1, int x2, int y2) { Vec2i coord = Drawing.txt_coord(offset, x1 + this.text_x, y1 + this.text_y, - x1 + this.text_x, y1 + this.text_y, 0x7fffffff, 0x7fffffff, this.getDrawnText()); + x1 + this.text_x, y1 + this.text_y, 0x7fffffff, 0x7fffffff, this.text); this.cursorPos = coord.xpos; if(shift) { if(this.cursorPos < x1) this.text_x += x1 - this.cursorPos; - else if((this.cursorPos + Font.WIDTH) >= (x1 + x2)) - this.text_x -= (this.cursorPos + Font.WIDTH) - (x1 + x2); + else if((this.cursorPos + Font.XGLYPH) >= (x1 + x2)) + this.text_x -= (this.cursorPos + Font.XGLYPH) - (x1 + x2); gui_text_update_cur(offset, false); } } protected int onCursorOffset(int x, int y, int x1, int y1, int x2, int y2) { Offset off = Drawing.txt_offset(x, y, x1 + this.text_x, y1 + this.text_y, - x1 + this.text_x, y1 + this.text_y, 0x7fffffff, 0x7fffffff, this.getDrawnText()); + x1 + this.text_x, y1 + this.text_y, 0x7fffffff, 0x7fffffff, this.text); if(off != null) { this.cursorPos = off.xpos; } @@ -130,21 +130,17 @@ public class Field extends Textbox { protected void drawForeground(int x1, int y1, int x2, int y2) { Drawing.txt_draw(x1 + this.text_x, y1 + this.text_y, x1 + this.text_x, y1 + this.text_y, - Integer.MAX_VALUE, Integer.MAX_VALUE, this.enabled ? this.gm.style.text_field : Util.mulColor(this.gm.style.text_field, 0.5f), this.getDrawnText()); + Integer.MAX_VALUE, Integer.MAX_VALUE, this.enabled ? this.gm.style.text_field : Util.mulColor(this.gm.style.text_field, 0.5f), this.text); if(this.sel_start >= 0 && this.sel_end != this.sel_start) Drawing.txt_overlay(this.sel_start, this.sel_end, x1 + this.text_x, y1 + this.text_y, x1 + this.text_x, y1 + this.text_y, - Integer.MAX_VALUE, Integer.MAX_VALUE, this.enabled ? 0x808080ff : 0x80404040, this.getDrawnText()); + Integer.MAX_VALUE, Integer.MAX_VALUE, this.enabled ? 0x808080ff : 0x80404040, this.text); } protected char getNewline() { return ' '; } - protected String getDrawnText() { - return this.text; - } - diff --git a/client/src/main/java/client/gui/element/FieldAction.java b/client/src/client/gui/element/FieldAction.java similarity index 100% rename from client/src/main/java/client/gui/element/FieldAction.java rename to client/src/client/gui/element/FieldAction.java diff --git a/client/src/main/java/client/gui/element/FieldCallback.java b/client/src/client/gui/element/FieldCallback.java similarity index 100% rename from client/src/main/java/client/gui/element/FieldCallback.java rename to client/src/client/gui/element/FieldCallback.java diff --git a/client/src/main/java/client/gui/element/Fill.java b/client/src/client/gui/element/Fill.java similarity index 87% rename from client/src/main/java/client/gui/element/Fill.java rename to client/src/client/gui/element/Fill.java index 7067dcf9..5fecb124 100644 --- a/client/src/main/java/client/gui/element/Fill.java +++ b/client/src/client/gui/element/Fill.java @@ -50,8 +50,8 @@ public class Fill extends Element { public void updateText() { Vec2i size = Drawing.getSize(this.text); if(!this.left) - this.text_x = ((this.size_x - (this.margin_x1 + this.margin_x2)) - size.xpos) / 2; + this.text_x = (this.size_x - size.xpos) / 2; if(!this.top) - this.text_y = ((this.size_y - (this.margin_y1 + this.margin_y2)) - size.ypos + 1) / 2; + this.text_y = (this.size_y - size.ypos) / 2; } } diff --git a/client/src/client/gui/element/GuiList.java b/client/src/client/gui/element/GuiList.java new file mode 100755 index 00000000..1f4ac012 --- /dev/null +++ b/client/src/client/gui/element/GuiList.java @@ -0,0 +1,413 @@ +package client.gui.element; + +import java.util.List; + +import org.lwjgl.opengl.GL11; + +import client.gui.Gui; +import client.renderer.DefaultVertexFormats; +import client.renderer.Drawing; +import client.renderer.GlState; +import client.renderer.RenderBuffer; +import client.renderer.Tessellator; +import client.window.Button; +import common.collect.Lists; +import common.util.ExtMath; + +public abstract class GuiList extends Gui +{ + protected final List elements = Lists.newArrayList(); + + protected int width; + protected int height; + + protected int top; + protected int bottom; + protected int right; + protected int left; + protected int mouseX; + protected int mouseY; + protected int initialClickY = -2; + protected float scrollMultiplier; + protected float amountScrolled; + protected int selectedElement = -1; + protected long lastClicked; + + public abstract int getListWidth(); // 220 + + public abstract int getSlotHeight(); + + protected int getScrollBarX() + { + return 0; + } + + public void setDimensions(int widthIn, int heightIn, int topIn, int bottomIn) + { + this.width = widthIn; + this.height = heightIn; + this.top = topIn; + this.bottom = bottomIn; + this.left = 0; + this.right = widthIn; + } + + public void init(int width, int height) { + + this.selectedElement = -1; + } + + public void setSlotXBoundsFromLeft(int leftIn) + { + this.left = leftIn; + this.right = leftIn + this.width; + } + + public final T getListEntry(int index) { + return this.elements.get(index); + } + + public final T getSelected() { + return this.selectedElement < 0 ? null : this.elements.get(this.selectedElement); + } + + public final int getSize() { + return this.elements.size(); + } + + public final void setSelected(int index) { + this.selectedElement = index; + } + + protected int getContentHeight() + { + return this.getSize() * this.getSlotHeight(); + } + + public int getSlotIndexFromScreenCoords(int x, int y) + { + int i = this.left + this.width / 2 - this.getListWidth() / 2; + int j = this.left + this.width / 2 + this.getListWidth() / 2; + int k = y - this.top + (int)this.amountScrolled - 4; + int l = k / this.getSlotHeight(); + return this.isInList(x, y) && x >= i && x <= j && l >= 0 && k >= 0 && l < this.getSize() ? l : -1; + } + + protected boolean isInList(int x, int y) + { + return x >= this.getScrollBarX() + 6; // x < this.getScrollBarX(); + } + + protected final boolean isSelected(int slotIndex) + { + return slotIndex == this.selectedElement; + } + + protected void bindAmountScrolled() + { + this.amountScrolled = ExtMath.clampf(this.amountScrolled, 0.0F, (float)this.getMaxScroll()); + } + + public int getMaxScroll() + { + return Math.max(0, this.getContentHeight() - (this.bottom - this.top - 4)); + } + + public int getAmountScrolled() + { + return (int)this.amountScrolled; + } + + public boolean isMouseYWithinSlotBounds(int p_148141_1_) + { + return p_148141_1_ >= this.top && p_148141_1_ <= this.bottom && this.mouseX >= this.left && this.mouseX <= this.right; + } + + public void scrollBy(int amount) + { + this.amountScrolled += (float)amount; + this.bindAmountScrolled(); + this.initialClickY = -2; + } + +// public void actionPerformed(Button button) +// { +// if (button.enabled) +// { +// if (button.id == this.scrollUpButtonID) +// { +// this.amountScrolled -= (float)(this.slotHeight * 2 / 3); +// this.initialClickY = -2; +// this.bindAmountScrolled(); +// } +// else if (button.id == this.scrollDownButtonID) +// { +// this.amountScrolled += (float)(this.slotHeight * 2 / 3); +// this.initialClickY = -2; +// this.bindAmountScrolled(); +// } +// } +// } + + public void draw() + { + int mouseXIn = this.gm.mouse_x; + int mouseYIn = this.gm.mouse_y; + this.mouseX = mouseXIn; + this.mouseY = mouseYIn; + this.drawBackground(); + int i = this.getScrollBarX(); + int j = i + 6; + this.bindAmountScrolled(); + GlState.disableLighting(); + GlState.disableFog(); + GlState.enableTexture2D(); + RenderBuffer worldrenderer = Tessellator.getBuffer(); + this.gm.getTextureManager().bindTexture(Gui.DIRT_BACKGROUND); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + + float f = 32.0F; + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + worldrenderer.pos((double)0, (double)this.bottom, 0.0D).tex((double)((float)0 / f), (double)((float)(this.bottom + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex(); + worldrenderer.pos((double)this.gm.fb_x, (double)this.bottom, 0.0D).tex((double)((float)this.gm.fb_x / f), (double)((float)(this.bottom + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex(); + worldrenderer.pos((double)this.gm.fb_x, (double)this.top, 0.0D).tex((double)((float)this.gm.fb_x / f), (double)((float)(this.top + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex(); + worldrenderer.pos((double)0, (double)this.top, 0.0D).tex((double)((float)0 / f), (double)((float)(this.top + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex(); + Tessellator.draw(); + + int x = this.left + this.width / 2 - this.getListWidth() / 2 + 2; + int y = this.top + 4 - (int)this.amountScrolled; + + this.drawSelectionBox(x, y, mouseXIn, mouseYIn); + GlState.disableDepth(); + + this.overlayBackground(0, this.top, 255, 255); + this.overlayBackground(this.bottom, this.height, 255, 255); + + GlState.enableBlend(); + GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ZERO, GL11.GL_ONE); + GlState.disableAlpha(); + GlState.shadeModel(GL11.GL_SMOOTH); + GlState.disableTexture2D(); + + int i1 = 4; + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + worldrenderer.pos((double)0, (double)(this.top + i1), 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 0).endVertex(); + worldrenderer.pos((double)this.gm.fb_x, (double)(this.top + i1), 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 0).endVertex(); + worldrenderer.pos((double)this.gm.fb_x, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex(); + worldrenderer.pos((double)0, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex(); + Tessellator.draw(); + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + worldrenderer.pos((double)0, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex(); + worldrenderer.pos((double)this.gm.fb_x, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex(); + worldrenderer.pos((double)this.gm.fb_x, (double)(this.bottom - i1), 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 0).endVertex(); + worldrenderer.pos((double)0, (double)(this.bottom - i1), 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 0).endVertex(); + Tessellator.draw(); + + int j1 = this.getMaxScroll(); + + if (j1 > 0) + { + int k1 = (this.bottom - this.top) * (this.bottom - this.top) / this.getContentHeight(); + k1 = ExtMath.clampi(k1, 32, this.bottom - this.top - 8); + int l1 = (int)this.amountScrolled * (this.bottom - this.top - k1) / j1 + this.top; + + if (l1 < this.top) + { + l1 = this.top; + } + + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + worldrenderer.pos((double)i, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex(); + worldrenderer.pos((double)j, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex(); + worldrenderer.pos((double)j, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex(); + worldrenderer.pos((double)i, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex(); + Tessellator.draw(); + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + worldrenderer.pos((double)i, (double)(l1 + k1), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex(); + worldrenderer.pos((double)j, (double)(l1 + k1), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex(); + worldrenderer.pos((double)j, (double)l1, 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex(); + worldrenderer.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex(); + Tessellator.draw(); + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + worldrenderer.pos((double)i, (double)(l1 + k1 - 1), 0.0D).tex(0.0D, 1.0D).color(192, 192, 192, 255).endVertex(); + worldrenderer.pos((double)(j - 1), (double)(l1 + k1 - 1), 0.0D).tex(1.0D, 1.0D).color(192, 192, 192, 255).endVertex(); + worldrenderer.pos((double)(j - 1), (double)l1, 0.0D).tex(1.0D, 0.0D).color(192, 192, 192, 255).endVertex(); + worldrenderer.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(192, 192, 192, 255).endVertex(); + Tessellator.draw(); + } + + GlState.enableTexture2D(); + GlState.shadeModel(GL11.GL_FLAT); + GlState.enableAlpha(); + GlState.disableBlend(); + + super.draw(); + } + + public void handleMouseInput() + { + if (this.isMouseYWithinSlotBounds(this.mouseY)) + { +// if (Button.MOUSE_LEFT.isDown() && this.getEnabled()) +// { + if (this.initialClickY == -1) + { + boolean flag1 = true; + + if (this.mouseY >= this.top && this.mouseY <= this.bottom) + { + int j2 = (this.width - this.getListWidth()) / 2; + int k2 = (this.width + this.getListWidth()) / 2; + int l2 = this.mouseY - this.top + (int)this.amountScrolled - 4; + int i1 = l2 / this.getSlotHeight(); + + if (i1 < this.getSize() && this.mouseX >= j2 && this.mouseX <= k2 && i1 >= 0 && l2 >= 0) + { + } + else if (this.mouseX >= j2 && this.mouseX <= k2 && l2 < 0) + { + flag1 = false; + } + + int i3 = this.getScrollBarX(); + int j1 = i3 + 6; + + if (this.mouseX >= i3 && this.mouseX <= j1) + { + this.scrollMultiplier = -1.0F; + int k1 = this.getMaxScroll(); + + if (k1 < 1) + { + k1 = 1; + } + + int l1 = (int)((float)((this.bottom - this.top) * (this.bottom - this.top)) / (float)this.getContentHeight()); + l1 = ExtMath.clampi(l1, 32, this.bottom - this.top - 8); + this.scrollMultiplier /= (float)(this.bottom - this.top - l1) / (float)k1; + } + else + { + this.scrollMultiplier = 1.0F; + } + + if (flag1) + { + this.initialClickY = this.mouseY; + } + else + { + this.initialClickY = -2; + } + } + else + { + this.initialClickY = -2; + } + } + else if (this.initialClickY >= 0) + { + this.amountScrolled -= (float)(this.mouseY - this.initialClickY) * this.scrollMultiplier; + this.initialClickY = this.mouseY; + } +// } +// else +// { +// this.initialClickY = -1; +// } + } + } + + protected void drawSelectionBox(int x, int y, int mouseXIn, int mouseYIn) + { + int size = this.getSize(); + RenderBuffer rb = Tessellator.getBuffer(); + + for (int z = 0; z < size; z++) + { + int y1 = y + z * this.getSlotHeight(); + int h = this.getSlotHeight() - 4; + + if (this.isSelected(z)) + { + int x1 = this.left + (this.width / 2 - this.getListWidth() / 2); + int x2 = this.left + this.width / 2 + this.getListWidth() / 2; + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + GlState.disableTexture2D(); + rb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + rb.pos((double)x1, (double)(y1 + h + 2), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex(); + rb.pos((double)x2, (double)(y1 + h + 2), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex(); + rb.pos((double)x2, (double)(y1 - 2), 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex(); + rb.pos((double)x1, (double)(y1 - 2), 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex(); + rb.pos((double)(x1 + 1), (double)(y1 + h + 1), 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex(); + rb.pos((double)(x2 - 1), (double)(y1 + h + 1), 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex(); + rb.pos((double)(x2 - 1), (double)(y1 - 1), 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex(); + rb.pos((double)(x1 + 1), (double)(y1 - 1), 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex(); + Tessellator.draw(); + GlState.enableTexture2D(); + } + + boolean hover = this.getSlotIndexFromScreenCoords(mouseXIn, mouseYIn) == z; + this.getListEntry(z).draw(x, y1, mouseXIn - x, mouseYIn - y1, hover); + if(hover) + Drawing.drawRect(x - 2, y1 - 2, this.getListWidth(), this.getSlotHeight(), Gui.HOVER_COLOR); + } + } + + protected void overlayBackground(int startY, int endY, int startAlpha, int endAlpha) + { + RenderBuffer rb = Tessellator.getBuffer(); + this.gm.getTextureManager().bindTexture(Gui.DIRT_BACKGROUND); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + float f = 32.0F; + rb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + rb.pos((double)0, (double)endY, 0.0D).tex(0.0D, (double)((float)endY / 32.0F)).color(64, 64, 64, endAlpha).endVertex(); + rb.pos((double)this.gm.fb_x, (double)endY, 0.0D).tex((double)((float)this.gm.fb_x / 32.0F), (double)((float)endY / 32.0F)).color(64, 64, 64, endAlpha).endVertex(); + rb.pos((double)this.gm.fb_x, (double)startY, 0.0D).tex((double)((float)this.gm.fb_x / 32.0F), (double)((float)startY / 32.0F)).color(64, 64, 64, startAlpha).endVertex(); + rb.pos((double)0, (double)startY, 0.0D).tex(0.0D, (double)((float)startY / 32.0F)).color(64, 64, 64, startAlpha).endVertex(); + Tessellator.draw(); + } + + public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) + { + super.mouse(btn, x, y, ctrl, shift); + if (this.isMouseYWithinSlotBounds(y)) + { + int i = this.getSlotIndexFromScreenCoords(x, y); + + if (i >= 0) + { + int j = this.left + this.width / 2 - this.getListWidth() / 2 + 2; + int k = this.top + 4 - this.getAmountScrolled() + i * this.getSlotHeight(); + int l = x - j; + int i1 = y - k; + + boolean flag = i == this.selectedElement && System.currentTimeMillis() - this.lastClicked < (long)this.gm.dclickDelay; + this.selectedElement = i; + this.lastClicked = System.currentTimeMillis(); + + this.getListEntry(i).select(flag, l, i1); + } + } + if(btn == Button.MOUSE_LEFT && this.clicked(x, y) == null) + this.handleMouseInput(); + } + + public void mouserel(Button btn, int x, int y) { + super.mouserel(btn, x, y); + if(btn == Button.MOUSE_LEFT) + this.initialClickY = -1; + } + + public void scroll(int scr_x, int scr_y, int x, int y, boolean ctrl, boolean shift) { + super.scroll(scr_x, scr_y, x, y, ctrl, shift); + if(scr_y != 0 && this.clicked(x, y) == null) + this.amountScrolled -= (float)(ExtMath.clampi(scr_y, -1, 1) * this.getSlotHeight() / 2); + } + + public void drag(int x, int y) { + super.drag(x, y); + if(this.selected == null && Button.MOUSE_LEFT.isDown()) + this.handleMouseInput(); + } +} diff --git a/client/src/client/gui/element/InventoryButton.java b/client/src/client/gui/element/InventoryButton.java new file mode 100644 index 00000000..7a714644 --- /dev/null +++ b/client/src/client/gui/element/InventoryButton.java @@ -0,0 +1,17 @@ +package client.gui.element; + +import client.renderer.Drawing; + +public class InventoryButton extends Element { + public InventoryButton(int x, int y, int w, int h) { + super(x, y, w, h, null); + } + + protected void drawBackground() { +// Drawing.drawRect2Border(this.pos_x, this.pos_y, this.size_x, this.size_y, 0xff6f6f6f, 0xffafafaf); + Drawing.drawRectBorder(this.pos_x, this.pos_y, this.size_x, this.size_y, 0xff6f6f6f, 0xff000000, 0xffafafaf, 0xff4f4f4f); + } + + protected void drawForeground(int x1, int y1, int x2, int y2) { + } +} diff --git a/client/src/client/gui/element/Label.java b/client/src/client/gui/element/Label.java new file mode 100644 index 00000000..7420a1d9 --- /dev/null +++ b/client/src/client/gui/element/Label.java @@ -0,0 +1,33 @@ +package client.gui.element; + +import client.renderer.Drawing; +import common.util.Util; + +public class Label extends Fill { + public Label(int x, int y, int w, int h, String text, boolean top, boolean left) { + super(x, y, w, h, text, top, left); + } + + public Label(int x, int y, int w, int h, String text, boolean left) { + super(x, y, w, h, text, left); + } + + public Label(int x, int y, int w, int h, String text) { + super(x, y, w, h, text); + } + + protected void drawBackground() { + } + + protected void drawForeground(int x1, int y1, int x2, int y2) { + Drawing.drawText(this.text, x1 + this.text_x, y1 + this.text_y, this.enabled ? this.gm.style.text_label : Util.mulColor(this.gm.style.text_label, 0.5f)); + } + + protected int getMarginX() { + return 0; + } + + protected int getMarginY() { + return 0; + } +} diff --git a/client/src/client/gui/element/ListEntry.java b/client/src/client/gui/element/ListEntry.java new file mode 100644 index 00000000..76236d19 --- /dev/null +++ b/client/src/client/gui/element/ListEntry.java @@ -0,0 +1,7 @@ +package client.gui.element; + +public interface ListEntry +{ + void draw(int x, int y, int mouseX, int mouseY, boolean hovered); + void select(boolean dclick, int mx, int my); +} \ No newline at end of file diff --git a/client/src/main/java/client/gui/element/NavButton.java b/client/src/client/gui/element/NavButton.java similarity index 96% rename from client/src/main/java/client/gui/element/NavButton.java rename to client/src/client/gui/element/NavButton.java index 7d3b423d..a80d9c4d 100644 --- a/client/src/main/java/client/gui/element/NavButton.java +++ b/client/src/client/gui/element/NavButton.java @@ -11,7 +11,7 @@ public class NavButton extends ActButton { public NavButton(int x, int y, int w, int h, Gui gui, String text) { super(x, y, w, h, new ButtonCallback() { public void use(ActButton elem, PressType action) { - Client.CLIENT.show(gui); + Client.CLIENT.displayGuiScreen(gui); } }, text); this.navGui = gui; diff --git a/client/src/client/gui/element/PasswordField.java b/client/src/client/gui/element/PasswordField.java new file mode 100644 index 00000000..efd3d9a5 --- /dev/null +++ b/client/src/client/gui/element/PasswordField.java @@ -0,0 +1,20 @@ +package client.gui.element; + +import client.renderer.Drawing; +import common.util.Util; + +public class PasswordField extends Field { + public PasswordField(int x, int y, int w, int h, int cap, FieldCallback callback, String text) { + super(x, y, w, h, cap, callback, text); + } + + protected void drawForeground(int x1, int y1, int x2, int y2) { + Drawing.txt_draw(x1 + this.text_x, y1 + this.text_y, + x1 + this.text_x, y1 + this.text_y, + Integer.MAX_VALUE, Integer.MAX_VALUE, this.enabled ? this.gm.style.text_field : Util.mulColor(this.gm.style.text_field, 0.5f), this.text.isEmpty() ? "" : "****"); + } + + protected int getCursorX(int x1, int x2) { + return x1; + } +} diff --git a/client/src/main/java/client/gui/element/PressType.java b/client/src/client/gui/element/PressType.java similarity index 100% rename from client/src/main/java/client/gui/element/PressType.java rename to client/src/client/gui/element/PressType.java diff --git a/client/src/main/java/client/gui/element/SelectableButton.java b/client/src/client/gui/element/SelectableButton.java similarity index 100% rename from client/src/main/java/client/gui/element/SelectableButton.java rename to client/src/client/gui/element/SelectableButton.java diff --git a/client/src/main/java/client/gui/element/Slider.java b/client/src/client/gui/element/Slider.java similarity index 98% rename from client/src/main/java/client/gui/element/Slider.java rename to client/src/client/gui/element/Slider.java index 5df5d991..347cef97 100644 --- a/client/src/main/java/client/gui/element/Slider.java +++ b/client/src/client/gui/element/Slider.java @@ -7,7 +7,7 @@ import common.util.ExtMath; import common.util.Util; public class Slider extends Element { - private static final int SLIDER_WIDTH = 8; + private static final int SLIDER_WIDTH = 10; private final SliderCallback func; private final int def; @@ -21,7 +21,7 @@ public class Slider extends Element { public Slider(int x, int y, int w, int h, int prec, int min, int max, int def, int init, SliderCallback callback, Formatter formatter) { super(x, y, w, h, formatter); - this.handle = ((this.size_y * SLIDER_WIDTH) / BASE_HEIGHT) & ~1; + this.handle = ((this.size_y * SLIDER_WIDTH) / 24) & ~1; this.func = callback; this.precision = prec; this.min = min; diff --git a/client/src/main/java/client/gui/element/SliderCallback.java b/client/src/client/gui/element/SliderCallback.java similarity index 100% rename from client/src/main/java/client/gui/element/SliderCallback.java rename to client/src/client/gui/element/SliderCallback.java diff --git a/client/src/main/java/client/gui/element/SliderFloatCallback.java b/client/src/client/gui/element/SliderFloatCallback.java similarity index 100% rename from client/src/main/java/client/gui/element/SliderFloatCallback.java rename to client/src/client/gui/element/SliderFloatCallback.java diff --git a/client/src/main/java/client/gui/element/Switch.java b/client/src/client/gui/element/Switch.java similarity index 96% rename from client/src/main/java/client/gui/element/Switch.java rename to client/src/client/gui/element/Switch.java index 02449a83..878ebcc9 100644 --- a/client/src/main/java/client/gui/element/Switch.java +++ b/client/src/client/gui/element/Switch.java @@ -25,7 +25,7 @@ public class Switch extends Element { this(x, y, w, h, values, def, init, callback, new Formatter>() { public String use(Switch elem) { T value = elem.getValue(); - return String.format("%s: %s", text, value instanceof Displayable disp ? disp.getDisplay() : value.toString()); + return String.format("%s: %s", text, value instanceof Displayable ? ((Displayable)value).getDisplay() : value.toString()); } }); } diff --git a/client/src/main/java/client/gui/element/SwitchCallback.java b/client/src/client/gui/element/SwitchCallback.java similarity index 100% rename from client/src/main/java/client/gui/element/SwitchCallback.java rename to client/src/client/gui/element/SwitchCallback.java diff --git a/client/src/main/java/client/gui/element/TextCallback.java b/client/src/client/gui/element/TextCallback.java similarity index 100% rename from client/src/main/java/client/gui/element/TextCallback.java rename to client/src/client/gui/element/TextCallback.java diff --git a/client/src/main/java/client/gui/element/Textbox.java b/client/src/client/gui/element/Textbox.java similarity index 91% rename from client/src/main/java/client/gui/element/Textbox.java rename to client/src/client/gui/element/Textbox.java index 7dc94f69..fa82c1ae 100644 --- a/client/src/main/java/client/gui/element/Textbox.java +++ b/client/src/client/gui/element/Textbox.java @@ -2,6 +2,7 @@ package client.gui.element; import org.lwjgl.opengl.GL11; +import client.Timing; import client.gui.Font; import client.renderer.Drawing; import client.window.Button; @@ -51,10 +52,6 @@ abstract class Textbox extends Element { return 4; } - protected boolean canCopy() { - return true; - } - public void setText(String str) { if(this.validator != null) str = this.validator.filter(str); @@ -66,13 +63,14 @@ abstract class Textbox extends Element { public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) { if(btn == Button.MOUSE_LEFT) { - if(!shift && ((System.currentTimeMillis() - this.tmr_leftmb) <= (long)this.gm.dclickDelay)) { - this.onDoubleClick(); + if(!shift && ((Timing.tmr_current - this.tmr_leftmb) <= (((long)this.gm.dclickDelay) * 1000L))) { + this.sel_start = this.sel_drag = 0; + this.sel_end = this.text.length(); } else { - this.gui_text_select(x, y, shift); + gui_text_select(x, y, shift); } - this.tmr_leftmb = System.currentTimeMillis(); + this.tmr_leftmb = Timing.tmr_current; } else if((btn == Button.MOUSE_MIDDLE) && this.func != null) { this.func.use(this, FieldAction.FUNCTION); @@ -80,7 +78,7 @@ abstract class Textbox extends Element { } public void drag(int x, int y) { - this.gui_text_select(x, y, true); + gui_text_select(x, y, true); } public void character(char code) { @@ -94,7 +92,7 @@ abstract class Textbox extends Element { this.sel_end = this.text.length(); } else if(ctrl && (key == Keysym.C) || (this.editable && (key == Keysym.X))) { - if(this.canCopy() && this.sel_start >= 0 && this.sel_start != this.sel_end) { // fix empty + if(this.sel_start >= 0 && this.sel_start != this.sel_end) { // fix empty String str = Util.strip(this.text, this.sel_start, this.sel_end - this.sel_start, '\n', (char)0, '?'); Window.setClipboard(str); if(key == Keysym.X) @@ -179,7 +177,7 @@ abstract class Textbox extends Element { this.tmr_scroll -= ((long)n) * 1000000L; else this.tmr_scroll = 0L; - this.tmr_scroll += this.gm.getPassedTime(); + this.tmr_scroll += Timing.tmr_delta; return n; } return 0; @@ -241,15 +239,10 @@ abstract class Textbox extends Element { int y1 = this.pos_y + this.margin_y1; int x2 = this.size_x - (this.margin_x1 + this.margin_x2); int y2 = this.size_y - (this.margin_y1 + this.margin_y2); - this.gm.scissor(x1 < 0 ? 0 : x1, (this.gm.fbY - (y1 + y2)) < 0 ? 0 : (this.gm.fbY - (y1 + y2)), x2 < 0 ? 0 : x2, y2 < 0 ? 0 : y2); + GL11.glScissor(x1 < 0 ? 0 : x1, (this.gm.fb_y - (y1 + y2)) < 0 ? 0 : (this.gm.fb_y - (y1 + y2)), x2 < 0 ? 0 : x2, y2 < 0 ? 0 : y2); GL11.glEnable(GL11.GL_SCISSOR_TEST); - Drawing.drawRect(this.getCursorX(x1, x2), this.getCursorY(y1, y2), 1, Font.HEIGHT, 0xff000000 | (~Util.mixColor(this.gm.style.field_top, this.gm.style.field_btm))); + Drawing.drawRect(this.getCursorX(x1, x2), this.getCursorY(y1, y2), 1, Font.YGLYPH, 0xff000000 | (~Util.mixColor(this.gm.style.field_top, this.gm.style.field_btm))); GL11.glDisable(GL11.GL_SCISSOR_TEST); } } - - protected void onDoubleClick() { - this.sel_start = this.sel_drag = 0; - this.sel_end = this.text.length(); - } } diff --git a/client/src/main/java/client/gui/element/Toggle.java b/client/src/client/gui/element/Toggle.java similarity index 88% rename from client/src/main/java/client/gui/element/Toggle.java rename to client/src/client/gui/element/Toggle.java index ea0467d8..b020dd5e 100644 --- a/client/src/main/java/client/gui/element/Toggle.java +++ b/client/src/client/gui/element/Toggle.java @@ -34,8 +34,7 @@ public class Toggle extends Element { // this.type = this.value != 0 ? ElemType.TOGGLE_ON : ElemType.TOGGLE_OFF; // gui_update_style(this, 1); // this.r_dirty = true; - if(this.func != null) - this.func.use(this, this.value); + this.func.use(this, this.value); this.formatText(); this.playSound(); } @@ -51,15 +50,4 @@ public class Toggle extends Element { else super.drawBackground(); } - - public void setValue(boolean value) { - if(this.value != value) { - this.value = value; - this.formatText(); - } - } - - public boolean getValue() { - return this.value; - } } diff --git a/client/src/main/java/client/gui/element/ToggleCallback.java b/client/src/client/gui/element/ToggleCallback.java similarity index 100% rename from client/src/main/java/client/gui/element/ToggleCallback.java rename to client/src/client/gui/element/ToggleCallback.java diff --git a/client/src/client/gui/element/TransparentArea.java b/client/src/client/gui/element/TransparentArea.java new file mode 100644 index 00000000..d9da8222 --- /dev/null +++ b/client/src/client/gui/element/TransparentArea.java @@ -0,0 +1,17 @@ +package client.gui.element; + +import client.renderer.Drawing; + +public class TransparentArea extends Area { + private final boolean background; + + public TransparentArea(int x, int y, int w, int h, String text, boolean background) { + super(x, y, w, h, text); + this.background = background; + } + + protected void drawBackground() { + if(this.background) + Drawing.drawRect(this.pos_x, this.pos_y, this.size_x, this.size_y, 0x3f000000); + } +} diff --git a/client/src/client/gui/ingame/GuiForm.java b/client/src/client/gui/ingame/GuiForm.java new file mode 100644 index 00000000..35332427 --- /dev/null +++ b/client/src/client/gui/ingame/GuiForm.java @@ -0,0 +1,125 @@ +package client.gui.ingame; + +import client.gui.Gui; +import client.gui.element.ActButton; +import client.gui.element.ButtonCallback; +import client.gui.element.Element; +import client.gui.element.Label; +import client.gui.element.NavButton; +import client.gui.element.PasswordField; +import client.gui.element.PressType; +import client.gui.element.Switch; +import client.gui.element.SwitchCallback; +import client.gui.element.FieldAction; +import client.gui.element.Field; +import client.gui.element.FieldCallback; +import client.gui.element.Toggle; +import client.gui.element.ToggleCallback; +import client.network.ClientPlayer; +import common.color.TextColor; +import common.packet.CPacketForm; +import common.util.ExtMath; +import common.util.Triplet; + +public class GuiForm extends Gui implements ButtonCallback { + private final int id; + private final String title; + private final Element[] inputs; + private final Label[] labels; + private final Triplet[] inputData; + private final Object[] outputData; + + private boolean sent; + + public void init(int width, int height) { + this.add(new Label(0, -100, 300, 20, this.title)); + for(int z = 0; z < this.inputs.length; z++) { + final int index = z; + final String name = this.inputData[z].first; + Object obj = this.inputData[z].second; + int param = this.inputData[z].third; + if(obj instanceof Boolean) { + this.inputs[z] = this.add(new Toggle(0, 50 * z, 300, 24, (Boolean)obj, (Boolean)obj, new ToggleCallback() { + public void use(Toggle elem, boolean value) { + GuiForm.this.outputData[index] = value; + } + }, name)); + } + else if(obj instanceof String[]) { + final String[] strs = (String[])obj; + param = ExtMath.clampi(param, 0, strs.length - 1); + this.inputs[z] = this.add(new Switch(0, 50 * z, 300, 24, strs, strs[param], strs[param], new SwitchCallback() { + public void use(Switch elem, String value) { + for(int n = 0; n < strs.length; n++) { + if(value == strs[n]) { + GuiForm.this.outputData[index] = n; + break; + } + } + } + }, name)); + } + else { + this.labels[z] = this.add(new Label(0, 50 * z - 20, 300, 20, name, true)); + FieldCallback callback = new FieldCallback() { + public void use(Field elem, FieldAction value) { + if(value == FieldAction.FOCUS) + GuiForm.this.labels[index].setText(name); + } + }; + this.inputs[z] = this.add((param & 0x80000000) != 0 ? new PasswordField(0, 50 * z, 300, 24, Math.min(param & 0xffff, 256), callback, (String)obj) : + new Field(0, 50 * z, 300, 24, Math.min(param & 0xffff, 256), callback, (String)obj)); + } + } + this.add(new NavButton(0, 50 * (this.inputs.length + 1), 148, 24, null, "Abbrechen")); + this.add(new ActButton(152, 50 * (this.inputs.length + 1), 148, 24, this, "Senden")); + this.shift(); + } + + public String getTitle() { + return this.title; + } + + public void onGuiClosed() { + if(!this.sent) { + ClientPlayer nethandler = this.gm.getNetHandler(); + if(nethandler != null) { + nethandler.addToSendQueue(new CPacketForm(this.id, null)); + } + } + } + + public GuiForm(int id, String title, Triplet[] data) { + this.id = id; + this.title = title; + this.inputs = new Element[data.length]; + this.labels = new Label[data.length]; + this.inputData = data; + this.outputData = new Object[data.length]; + for(int z = 0; z < data.length; z++) { + Object obj = data[z].second; + this.outputData[z] = obj instanceof String[] ? data[z].third : obj; + } + } + + public void use(ActButton elem, PressType action) { + for(int z = 0; z < this.inputs.length; z++) { + if(this.inputs[z] instanceof Field) { + int min = (this.inputData[z].third & 0x7fffffff) >> 16; + String text = this.inputs[z].getText(); + if(text.length() < min) { + if(!GuiForm.this.labels[z].getText().startsWith("" + TextColor.RED)) + GuiForm.this.labels[z].setText(TextColor.RED + GuiForm.this.labels[z].getText()); + return; + } + this.outputData[z] = text; + } + } + this.sent = true; + ClientPlayer nethandler = this.gm.getNetHandler(); + if(nethandler != null) { + nethandler.addToSendQueue(new CPacketForm(this.id, this.outputData)); + } + this.gm.displayGuiScreen(null); + } +} diff --git a/client/src/client/gui/ingame/GuiGameOver.java b/client/src/client/gui/ingame/GuiGameOver.java new file mode 100755 index 00000000..ce3f7abf --- /dev/null +++ b/client/src/client/gui/ingame/GuiGameOver.java @@ -0,0 +1,41 @@ +package client.gui.ingame; + +import client.gui.Gui; +import client.gui.element.ActButton; +import client.gui.element.ButtonCallback; +import common.color.TextColor; +import client.gui.element.Label; +import client.gui.element.PressType; + +public class GuiGameOver extends Gui { + public static final GuiGameOver INSTANCE = new GuiGameOver(); + + private ActButton button; + private int timer; + + private GuiGameOver() { + } + + public void init(int width, int height) { + this.timer = 0; + this.add(new Label(0, 0, 200, 20, "Du bist gestorben!")); + this.add(new Label(0, 32, 200, 20, "Punktestand: " + TextColor.YELLOW + this.gm.player.experienceLevel)); + this.button = this.add(new ActButton(0, 100, 200, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { + GuiGameOver.this.gm.player.respawnPlayer(); + GuiGameOver.this.gm.displayGuiScreen(null); + } + }, "Wiederbeleben")); + this.shift(); + this.button.enabled = false; + } + + public String getTitle() { + return "Game over"; + } + + public void updateScreen() { + if(++this.timer >= 20) + this.button.enabled = true; + } +} diff --git a/client/src/client/gui/ingame/GuiSign.java b/client/src/client/gui/ingame/GuiSign.java new file mode 100644 index 00000000..c5530fd4 --- /dev/null +++ b/client/src/client/gui/ingame/GuiSign.java @@ -0,0 +1,54 @@ +package client.gui.ingame; + +import client.gui.Gui; +import client.gui.element.Label; +import client.gui.element.NavButton; +import client.gui.element.FieldAction; +import client.gui.element.Field; +import client.gui.element.FieldCallback; +import client.network.ClientPlayer; +import common.packet.CPacketSign; +import common.util.BlockPos; + +public class GuiSign extends Gui implements FieldCallback { + private final BlockPos position; + private final Field[] lines; + private final String[] tempLines; + + public void init(int width, int height) { + this.add(new Label(0, -140, 300, 20, "Bearbeite Schild")); + this.add(new Label(0, -80, 300, 20, String.format("%d, %d, %d", this.position.getX(), this.position.getY(), this.position.getZ()))); + this.add(new Label(0, -50, 300, 20, this.gm.world == null ? "" : this.gm.world.dimension.getFormattedName(false))); + for(int z = 0; z < this.lines.length; z++) { + this.lines[z] = this.add(new Field(0, 40 * z, 300, 24, 50, this, this.tempLines[z] == null ? "" : this.tempLines[z])); + } + this.add(new NavButton(0, 40 * (this.lines.length + 1), 300, 24, null, "Fertig")); + this.shift(); + } + + public String getTitle() { + return "Schild bearbeiten"; + } + + public void onGuiClosed() { + ClientPlayer nethandler = this.gm.getNetHandler(); + if(nethandler != null) { + for(int z = 0; z < this.lines.length; z++) { + this.tempLines[z] = this.lines[z].getText(); + } + nethandler.addToSendQueue(new CPacketSign(this.position, this.tempLines)); + } + } + + public GuiSign(BlockPos sign, String[] lines) { + this.position = sign; + this.lines = new Field[lines.length]; + this.tempLines = new String[lines.length]; + System.arraycopy(lines, 0, this.tempLines, 0, lines.length); + } + + public void use(Field elem, FieldAction value) { + if(value == FieldAction.SEND) + this.gm.displayGuiScreen(null); + } +} diff --git a/client/src/client/gui/options/GuiBinds.java b/client/src/client/gui/options/GuiBinds.java new file mode 100644 index 00000000..ffc62621 --- /dev/null +++ b/client/src/client/gui/options/GuiBinds.java @@ -0,0 +1,75 @@ +package client.gui.options; + +import client.gui.Formatter; +import client.gui.element.ActButton; +import client.gui.element.ButtonCallback; +import client.gui.element.Label; +import client.gui.element.PressType; +import client.window.Bind; +import common.color.TextColor; + +public class GuiBinds extends GuiOptions { + protected GuiBinds() { + } + + public void init(int width, int height) { + int y = 0; + int x = 0; + for(Bind bind : Bind.values()) { + this.add(new Label(10 + x * 190, 80 + y * 50, 180, 20, bind.getDisplay())); + this.add(new ActButton(10 + x * 190, 100 + y * 50, 180, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { + if(action == PressType.SECONDARY) { + if(!bind.isDefault()) { + bind.setDefault(); + GuiBinds.this.gm.setDirty(); + GuiBinds.this.reformat(); + } + } + else if(action == PressType.TERTIARY) { + if(bind.getInput() != null) { + bind.setInput(null); + GuiBinds.this.gm.setDirty(); + GuiBinds.this.reformat(); + } + } + else { + Bind.disableInput(bind); + } + } + }, new Formatter() { + public String use(ActButton elem) { + if(bind == Bind.getWaiting()) + return /* TextColor.BLINK + "" + */ TextColor.BLUE + "***"; + else + return (bind.isDupe() ? TextColor.RED : TextColor.YELLOW) + (bind.getInput() == null ? "---" : bind.getInput().getDisplay()); + } + })); + if(++x == 5) { + x = 0; + y++; + } + } + y += x != 0 ? 1 : 0; + this.add(new ActButton(200, 100 + y * 50, 560, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { + boolean flag = false; + for(Bind bind : Bind.values()) { + flag |= !bind.isDefault(); + bind.setDefault(); + } + if(flag) { + GuiBinds.this.gm.setDirty(); + GuiBinds.this.reformat(); + } + } + }, "Zurücksetzen")); + this.addSelector("phy_sensitivity", 30, 160 + y * 50, 440, 24); + this.addSelector("gui_dclick_delay", 490, 160 + y * 50, 440, 24); + super.init(width, height); + } + + public String getTitle() { + return "Tastenbelegung und Maus"; + } +} diff --git a/client/src/client/gui/options/GuiDisplay.java b/client/src/client/gui/options/GuiDisplay.java new file mode 100644 index 00000000..22262d08 --- /dev/null +++ b/client/src/client/gui/options/GuiDisplay.java @@ -0,0 +1,106 @@ +package client.gui.options; + +import client.gui.Formatter; +import client.gui.element.Dropdown; +import client.gui.element.DropdownCallback; +import client.gui.element.Element; +import client.gui.element.Fill; +import client.gui.element.Slider; +import client.gui.element.SliderCallback; +import client.gui.element.Toggle; +import client.gui.element.ToggleCallback; +import client.window.Button; +import client.window.DisplayMode; +import client.window.Window; +import common.color.TextColor; + +public class GuiDisplay extends GuiOptions { + private static final String[] DISTANCES = new String[] {"Gruselig", "Winzig", "Gering", "Normal", "Weit"}; + + private Element distanceSlider; + + protected GuiDisplay() { + } + + public void init(int width, int height) { + DisplayMode[] dmodes = Window.getDisplayModes(); + if(dmodes != null && dmodes.length > 0) { + int offset = 0; + int pos = 0; + int num = dmodes.length; + if(dmodes.length > DisplayMode.VID_MODES) { + offset = dmodes.length - DisplayMode.VID_MODES; + num = DisplayMode.VID_MODES; + } + DisplayMode[] modes = new DisplayMode[num]; + DisplayMode selected = dmodes[num + offset - 1]; + for(int z = 0; z < num; z++) { + modes[z] = dmodes[z + offset]; + if(modes[z].equals(this.gm.vidMode)) + selected = modes[z]; + } + this.add(new Dropdown(30, 80, 440, 24, false, modes, modes[modes.length - 1], selected, new DropdownCallback() { + public void use(Dropdown elem, DisplayMode value) { + GuiDisplay.this.gm.vidMode = value; + GuiDisplay.this.gm.full(true); + } + }, "Auflösung")); + } + else { + this.add(new Fill(30, 80, 440, 24, TextColor.RED + "Auflösung: ")); + } + + this.add(new Toggle(490, 80, 440, 24, false, GuiDisplay.this.gm.fullscreen, new ToggleCallback() { + public void use(Toggle elem, boolean value) { + GuiDisplay.this.gm.full(value); + } + }, "Vollbild")); + this.add(new Slider(30, 120, 440, 24, 0, 0, 360 - 8, 0, (this.gm.sync < 0) ? (360 - 8) : (this.gm.sync != 0 ? ((this.gm.sync < 10) ? 1 : (this.gm.sync - 9)) : 0), new SliderCallback() { + public void use(Slider elem, int value) { + GuiDisplay.this.gm.getVar("win_sync").parse("" + ((value > 0 && value < 360 - 8) ? (value + 9) : (value != 0 ? -1 : 0))); + GuiDisplay.this.gm.setDirty(); + } + }, new Formatter() { + public String use(Slider elem) { + int value = elem.getValue(); + return "Max. Bildrate: " + (value > 0 && value < (360 - 8) ? (value + 9) + " FPS" : (value != 0 ? "Unbegrenzt" : "VSync")); + } + })); + this.addSelector("gl_vsync_flush", 490, 120, 440, 24); + + this.addSelector("overlay_enabled", 30, 200, 440, 24); + this.addSelector("overlay_opacity", 490, 200, 440, 24); + + this.addSelector("overlay_fadeout", 30, 240, 440, 24); + this.addSelector("chat_permanent", 490, 240, 440, 24); + + this.addSelector("console_size", 30, 280, 440, 24); + this.addSelector("chat_size", 490, 280, 440, 24); + + this.addSelector("feed_size", 30, 320, 440, 24); + this.addSelector("hotbar_size", 490, 320, 440, 24); + + this.addSelector("gl_fov", 30, 400, 440, 24); + this.distanceSlider = this.addSelector("chunk_view_distance", 30, 440, 440, 24); + this.addSelector("chunk_build_time", 490, 440, 440, 24); + super.init(width, height); + } + + public String getTitle() { + return "Grafik und Anzeige"; + } + + private String getDistanceName() { + int distance = this.gm.renderDistance; + distance = distance > 16 ? 16 : distance; + String str = distance < 0 ? DISTANCES[0] : DISTANCES[(distance + 1) / 4]; + if(distance > 2 && (((distance + 1) / 2) & 1) == 1) + str = str + "+"; + return String.format("Sichtweite: %d Chunks [%d Blöcke, %s]", this.gm.renderDistance, this.gm.renderDistance * 16, str); + } + + public void updateScreen() { + if(!Button.isMouseDown()) + this.distanceSlider.setText(this.getDistanceName()); + } +} diff --git a/client/src/client/gui/options/GuiOptions.java b/client/src/client/gui/options/GuiOptions.java new file mode 100644 index 00000000..51258d80 --- /dev/null +++ b/client/src/client/gui/options/GuiOptions.java @@ -0,0 +1,31 @@ +package client.gui.options; + +import client.gui.Gui; +import client.gui.GuiMenu; +import client.gui.element.NavButton; + +public abstract class GuiOptions extends Gui { + private static final GuiOptions[] PAGES = {lastPage = new GuiBinds(), new GuiStyle(), new GuiDisplay(), new GuiSound()}; + + private static GuiOptions lastPage; + + public static GuiOptions getPage() { + return lastPage; + } + + public void init(int width, int height) { + lastPage = this; + this.shift(); + int x = 0; + int y = 0; + for(GuiOptions gui : PAGES) { + this.add( // gui == this ? new SelectedButton(240 * x, 24 * y, 240, 24, gui, gui.getTitle()) : + new NavButton(240 * x, 24 * y, 240, 24, gui, gui.getTitle())); + if(++x == 4) { + x = 0; + ++y; + } + } + this.add(new NavButton(width - 240, 0, 240, 24, GuiMenu.INSTANCE, "Zurück")); + } +} diff --git a/client/src/client/gui/options/GuiSound.java b/client/src/client/gui/options/GuiSound.java new file mode 100644 index 00000000..29a38141 --- /dev/null +++ b/client/src/client/gui/options/GuiSound.java @@ -0,0 +1,38 @@ +package client.gui.options; + +import client.audio.Volume; +import client.gui.element.ActButton; +import client.gui.element.ButtonCallback; +import client.gui.element.PressType; + +public class GuiSound extends GuiOptions { + protected GuiSound() { + } + + public void init(int width, int height) { + this.addSelector("snd_enabled", 30, 380, 440, 24); + + this.addSelector("snd_buffer_size", 30, 420, 440, 24); + this.addSelector("snd_frame_size", 490, 420, 440, 24); + + this.add(new ActButton(30, 480, 900, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { + GuiSound.this.gm.restartSound(false); + } + }, "Übernehmen und Audio-Thread neu starten")); + + int x = 30; + int y = 220; + for(Volume volume : Volume.values()) { + this.addSelector(volume.getCVarName(), x, y, 440, 24); + x = (x == 30) ? 490 : 30; + if(x == 30) + y += 40; + } + super.init(width, height); + } + + public String getTitle() { + return "Audio und Ton"; + } +} diff --git a/client/src/client/gui/options/GuiStyle.java b/client/src/client/gui/options/GuiStyle.java new file mode 100644 index 00000000..79055913 --- /dev/null +++ b/client/src/client/gui/options/GuiStyle.java @@ -0,0 +1,129 @@ +package client.gui.options; + +import client.gui.Style; +import client.gui.element.ActButton; +import client.gui.element.ButtonCallback; +import client.gui.element.Dropdown; +import client.gui.element.DropdownCallback; +import client.gui.element.Element; +import client.gui.element.SelectableButton; +import client.gui.element.Slider; +import client.gui.element.SliderCallback; +import client.gui.element.Switch; +import client.gui.element.SwitchCallback; +import client.gui.element.FieldAction; +import client.gui.element.Field; +import client.gui.element.FieldCallback; +import client.gui.element.PressType; +import client.vars.CVar; +import client.vars.ColorVar; +import client.gui.element.Toggle; +import client.gui.element.ToggleCallback; + +public class GuiStyle extends GuiOptions implements DropdownCallback, ButtonCallback, ToggleCallback, SwitchCallback, SliderCallback, FieldCallback { + private static final String[] STYLE_CVARS = { + "color_button_top", + "color_textbox_top", + "color_border_top", + + "color_button_btm", + "color_textbox_btm", + "color_border_btm", + + "color_button_text", + "color_textbox_text", + "color_label_text" + }; + + protected GuiStyle() { + } + + protected Element addSelector(String cvar, int x, int y, int w, int h) { + CVar cv = this.gm.getVar(cvar); + if(cv instanceof ColorVar) { + ColorVar color = (ColorVar)cv; + if(!color.getDisplay().isEmpty()) + this.add(color.label(x, y - 20, w, 20)); + if(this.gm.style != Style.CUSTOM) + return this.add(new Field(x, y, w, h, color.getFieldValue(this.gm.style))); + else + return this.add(color.editor(x, y, w, h)); + } + return super.addSelector(cvar, x, y, w, h); + } + + public void init(int width, int height) { + int z; + for(z = 0; z < STYLE_CVARS.length; z++) { + this.addSelector(STYLE_CVARS[z], 10 + ((z % 3) + 1) * 190, 100 + z / 3 * 50, 180, 24); + } + z = 0; + for(Style theme : Style.values()) { + ButtonCallback callback = new ButtonCallback() { + public void use(ActButton elem, PressType action) { + if(GuiStyle.this.gm.style != theme) { + GuiStyle.this.gm.style = theme; + GuiStyle.this.gm.setDirty(); + GuiStyle.this.gm.displayGuiScreen(GuiStyle.this); + } + } + }; + this.add( // theme == this.gm.style ? new SelectedButton(10 + (z % 3) * 320, 360 + (z / 3) * 40, 300, 24, callback, theme.name) : + new SelectableButton(10 + (z % 3) * 320, 360 + (z / 3) * 40, 300, 24, callback, theme.name, theme == this.gm.style)); + z++; + } + + String[] values = new String[] {"VALUE 1", "VALUE 2"}; + this.add(new Dropdown(10, height - 74, 300, 24, false, values, values[1], values[0], this, "DROPDOWN")); + this.add(new ActButton(330, height - 74, 300, 24, this, "BUTTON")); + this.add(new Toggle(650, height - 74, 140, 24, false, true, this, "TOGGLE")); + this.add(new Toggle(810, height - 74, 140, 24, true, false, this, "TOGGLE")); + values = new String[] {"VALUE 1", "VALUE 2", "VALUE 3", "VALUE 4"}; + this.add(new Switch(10, height - 34, 300, 24, values, values[2], values[0], this, "ENUM")); + this.add(new Slider(330, height - 34, 300, 24, 0, -20, 827, 60, 120, this, "SLIDER")); + this.add(new Field(650, height - 34, 300, 24, 128, this, "FIELD")); + + if(this.gm.style != Style.CUSTOM) { + this.add(new ActButton(200, 100 + 3 * 50, 560, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { + if(GuiStyle.this.gm.style != Style.CUSTOM) { + GuiStyle.this.gm.style.copyToCustom(); + GuiStyle.this.gm.style = Style.CUSTOM; + GuiStyle.this.gm.setDirty(); + GuiStyle.this.gm.displayGuiScreen(GuiStyle.this); + } + } + }, "In angepasstes Design kopieren")); + } + else { + this.add(new ActButton(200, 100 + 3 * 50, 560, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { + GuiStyle.this.gm.style = Style.CUSTOM; + for(String cvar : STYLE_CVARS) { + GuiStyle.this.gm.getVar(cvar).setDefault(); + } + GuiStyle.this.gm.setDirty(); + GuiStyle.this.gm.displayGuiScreen(GuiStyle.this); + } + }, "Angepasstes Design zurücksetzen")); + } + super.init(width, height); + } + + public String getTitle() { + return "Benutzeroberfläche"; + } + + public void use(Field elem, FieldAction value) { + } + public void use(Slider elem, int value) { + } + public void use(Switch elem, String value) { + } + public void use(Toggle elem, boolean value) { + } + public void use(ActButton elem, PressType action) { + } + public void use(Dropdown elem, String value) { + } +} diff --git a/client/src/main/java/client/init/RenderRegistry.java b/client/src/client/init/RenderRegistry.java similarity index 75% rename from client/src/main/java/client/init/RenderRegistry.java rename to client/src/client/init/RenderRegistry.java index bbf175d9..d57d7947 100644 --- a/client/src/main/java/client/init/RenderRegistry.java +++ b/client/src/client/init/RenderRegistry.java @@ -21,7 +21,6 @@ import client.renderer.entity.RenderFallingBlock; import client.renderer.entity.RenderFireball; import client.renderer.entity.RenderFish; import client.renderer.entity.RenderFlyingBox; -import client.renderer.entity.RenderFox; import client.renderer.entity.RenderHorse; import client.renderer.entity.RenderHumanoid; import client.renderer.entity.RenderItem; @@ -30,54 +29,58 @@ import client.renderer.entity.RenderLeashKnot; import client.renderer.entity.RenderLightning; import client.renderer.entity.RenderManager; import client.renderer.entity.RenderMinecart; -import client.renderer.entity.RenderMissile; +import client.renderer.entity.RenderMooshroom; import client.renderer.entity.RenderMouse; import client.renderer.entity.RenderNpc; -import client.renderer.entity.RenderCat; +import client.renderer.entity.RenderOcelot; import client.renderer.entity.RenderPig; import client.renderer.entity.RenderPotion; import client.renderer.entity.RenderRabbit; import client.renderer.entity.RenderSheep; import client.renderer.entity.RenderSlime; import client.renderer.entity.RenderSpaceMarine; +import client.renderer.entity.RenderSquid; import client.renderer.entity.RenderTntMinecart; import client.renderer.entity.RenderTntPrimed; import client.renderer.entity.RenderWolf; -import client.renderer.entity.RenderXp; +import client.renderer.entity.RenderXpOrb; import client.renderer.model.ModelChicken; import client.renderer.model.ModelCow; -import client.renderer.model.ModelFox; import client.renderer.model.ModelHorse; import client.renderer.model.ModelMouse; -import client.renderer.model.ModelCat; +import client.renderer.model.ModelOcelot; import client.renderer.model.ModelPig; import client.renderer.model.ModelRabbit; import client.renderer.model.ModelSheep2; +import client.renderer.model.ModelSquid; import client.renderer.model.ModelWolf; -import client.renderer.texture.TextureTicked.TextureCreator; -import client.renderer.ticked.TextureFlame; -import client.renderer.ticked.TextureMagma; -import client.renderer.ticked.TextureMagmaFlow; -import client.renderer.ticked.TextureWater; -import client.renderer.ticked.TextureWaterFlow; +import client.renderer.texture.TextureTicked; +import client.renderer.ticked.TextureFlamesFX1; +import client.renderer.ticked.TextureFlamesFX2; +import client.renderer.ticked.TextureLavaFX; +import client.renderer.ticked.TextureLavaFlowFX; +import client.renderer.ticked.TextureWaterFX; +import client.renderer.ticked.TextureWaterFlowFX; import common.entity.Entity; import common.entity.animal.EntityBat; import common.entity.animal.EntityChicken; import common.entity.animal.EntityCow; import common.entity.animal.EntityDragon; -import common.entity.animal.EntityFox; import common.entity.animal.EntityHorse; +import common.entity.animal.EntityMooshroom; import common.entity.animal.EntityMouse; -import common.entity.animal.EntityCat; +import common.entity.animal.EntityOcelot; import common.entity.animal.EntityPig; import common.entity.animal.EntityRabbit; import common.entity.animal.EntitySheep; +import common.entity.animal.EntitySquid; import common.entity.animal.EntityWolf; import common.entity.effect.EntityLightning; import common.entity.item.EntityBoat; import common.entity.item.EntityCart; import common.entity.item.EntityCrystal; import common.entity.item.EntityFalling; +import common.entity.item.EntityFireworks; import common.entity.item.EntityItem; import common.entity.item.EntityLeashKnot; import common.entity.item.EntityNuke; @@ -85,6 +88,7 @@ import common.entity.item.EntityOrb; import common.entity.item.EntityTnt; import common.entity.item.EntityTntCart; import common.entity.item.EntityXp; +import common.entity.item.EntityXpBottle; import common.entity.npc.SpeciesInfo; import common.entity.projectile.EntityArrow; import common.entity.projectile.EntityBox; @@ -95,14 +99,12 @@ import common.entity.projectile.EntityEgg; import common.entity.projectile.EntityFireCharge; import common.entity.projectile.EntityFireball; import common.entity.projectile.EntityHook; -import common.entity.projectile.EntityMissile; import common.entity.projectile.EntityPotion; import common.entity.projectile.EntitySnowball; import common.init.Blocks; import common.init.Items; import common.init.SpeciesRegistry; import common.init.SpeciesRegistry.ModelType; -import common.model.TextureAnimation; public abstract class RenderRegistry { public static void registerRenderers(Map, Render> map, @@ -110,26 +112,31 @@ public abstract class RenderRegistry { map.put(EntityPig.class, new RenderPig(mgr, new ModelPig())); map.put(EntitySheep.class, new RenderSheep(mgr, new ModelSheep2())); map.put(EntityCow.class, new RenderCow(mgr, new ModelCow())); + map.put(EntityMooshroom.class, new RenderMooshroom(mgr, new ModelCow())); map.put(EntityWolf.class, new RenderWolf(mgr, new ModelWolf())); - map.put(EntityFox.class, new RenderFox(mgr, new ModelFox())); map.put(EntityChicken.class, new RenderChicken(mgr, new ModelChicken())); - map.put(EntityCat.class, new RenderCat(mgr, new ModelCat())); + map.put(EntityOcelot.class, new RenderOcelot(mgr, new ModelOcelot())); map.put(EntityRabbit.class, new RenderRabbit(mgr, new ModelRabbit())); + map.put(EntitySquid.class, new RenderSquid(mgr, new ModelSquid())); map.put(EntityBat.class, new RenderBat(mgr)); map.put(EntityDragon.class, new RenderDragon(mgr)); map.put(EntityCrystal.class, new RenderCrystal(mgr)); map.put(Entity.class, new RenderEntity(mgr)); +// map.put(EntityPainting.class, new RenderPainting(mgr)); +// map.put(EntityFrame.class, new RenderItemFrame(mgr, ritem)); map.put(EntityLeashKnot.class, new RenderLeashKnot(mgr)); map.put(EntityArrow.class, new RenderArrow(mgr)); map.put(EntitySnowball.class, new RenderItemEntity(mgr, Items.snowball, ritem)); map.put(EntityOrb.class, new RenderItemEntity(mgr, Items.charged_orb, ritem)); map.put(EntityEgg.class, new RenderItemEntity(mgr, Items.egg, ritem)); map.put(EntityPotion.class, new RenderPotion(mgr, ritem)); + map.put(EntityXpBottle.class, new RenderItemEntity(mgr, Items.experience_bottle, ritem)); + map.put(EntityFireworks.class, new RenderItemEntity(mgr, Items.fireworks, ritem)); map.put(EntityFireball.class, new RenderFireball(mgr, 0.75F)); map.put(EntityFireCharge.class, new RenderFireball(mgr, 0.5F)); map.put(EntityBox.class, new RenderFlyingBox(mgr)); map.put(EntityItem.class, new RenderEntityItem(mgr, ritem)); - map.put(EntityXp.class, new RenderXp(mgr)); + map.put(EntityXp.class, new RenderXpOrb(mgr)); map.put(EntityTnt.class, new RenderTntPrimed(mgr)); map.put(EntityFalling.class, new RenderFallingBlock(mgr)); map.put(EntityTntCart.class, new RenderTntMinecart(mgr)); @@ -137,18 +144,17 @@ public abstract class RenderRegistry { map.put(EntityBoat.class, new RenderBoat(mgr)); map.put(EntityHook.class, new RenderFish(mgr)); map.put(EntityHorse.class, new RenderHorse(mgr, new ModelHorse())); - map.put(EntityDynamite.class, new RenderDynamite(mgr, ritem)); + map.put(EntityDynamite.class, new RenderDynamite(mgr, Items.dynamite, ritem)); map.put(EntityNuke.class, new RenderBlockEntity(mgr, Blocks.nuke.getState())); map.put(EntityMouse.class, new RenderMouse(mgr, new ModelMouse())); map.put(EntityDie.class, new RenderDie(mgr)); map.put(EntityBullet.class, new RenderBullet(mgr)); - map.put(EntityMissile.class, new RenderMissile(mgr)); map.put(EntityLightning.class, new RenderLightning(mgr)); - models.put(ModelType.HUMANOID, new RenderHumanoid(mgr, 12, 12, "textures/npc/knight_1.png")); + models.put(ModelType.HUMANOID, new RenderHumanoid(mgr, 12, 12, "textures/entity/char.png")); models.put(ModelType.ARACHNOID, new RenderArachnoid(mgr)); models.put(ModelType.SLIME, new RenderSlime(mgr)); - models.put(ModelType.DWARF, new RenderHumanoid(mgr, 10, 10, "textures/npc/dwarf.png")); - models.put(ModelType.HALFLING, new RenderHumanoid(mgr, 8, 8, "textures/npc/goblin.png")); + models.put(ModelType.DWARF, new RenderHumanoid(mgr, 10, 10, "textures/entity/dwarf.png")); + models.put(ModelType.HALFLING, new RenderHumanoid(mgr, 8, 8, "textures/entity/goblin.png")); models.put(ModelType.SPACE_MARINE, new RenderSpaceMarine(mgr)); for(int z = 0; z < SpeciesRegistry.SPECIMEN.size(); z++) { SpeciesInfo info = SpeciesRegistry.SPECIMEN.get(z); @@ -156,18 +162,12 @@ public abstract class RenderRegistry { } } - public static void registerAnimations(Map anim) { - anim.put(TextureAnimation.FLAME_BASE, () -> new TextureFlame(0xffffffff, 0)); - anim.put(TextureAnimation.FLAME_OFFSET, () -> new TextureFlame(0xffffffff, 160)); - anim.put(TextureAnimation.BLACK_FLAME_BASE, () -> new TextureFlame(0xff202020, 0)); - anim.put(TextureAnimation.BLACK_FLAME_OFFSET, () -> new TextureFlame(0xff202020, 160)); - anim.put(TextureAnimation.BLUE_FLAME_BASE, () -> new TextureFlame(0xff4010ff, 0)); - anim.put(TextureAnimation.BLUE_FLAME_OFFSET, () -> new TextureFlame(0xff4010ff, 160)); - anim.put(TextureAnimation.MAGMA_FLOW, () -> new TextureMagmaFlow()); - anim.put(TextureAnimation.MAGMA_STILL, () -> new TextureMagma()); - anim.put(TextureAnimation.WATER_FLOW, () -> new TextureWaterFlow(0xffffffff)); - anim.put(TextureAnimation.WATER_STILL, () -> new TextureWater(0xffffffff)); - anim.put(TextureAnimation.SWAMP_WATER_FLOW, () -> new TextureWaterFlow(0xffe0ffae)); - anim.put(TextureAnimation.SWAMP_WATER_STILL, () -> new TextureWater(0xffe0ffae)); + public static void registerAnimations(Map> anim) { + anim.put("fire1", TextureFlamesFX1.class); + anim.put("fire2", TextureFlamesFX2.class); + anim.put("lavaflow", TextureLavaFlowFX.class); + anim.put("lava", TextureLavaFX.class); + anim.put("waterflow", TextureWaterFlowFX.class); + anim.put("water", TextureWaterFX.class); } } diff --git a/client/src/client/network/ClientLoginHandler.java b/client/src/client/network/ClientLoginHandler.java new file mode 100755 index 00000000..cfda5c69 --- /dev/null +++ b/client/src/client/network/ClientLoginHandler.java @@ -0,0 +1,69 @@ +package client.network; + +import java.security.PublicKey; + +import javax.crypto.SecretKey; + +import client.Client; +import common.network.IClientLoginHandler; +import common.network.NetConnection; +import common.network.NetHandler; +import common.network.PacketRegistry; +import common.packet.LPacketPasswordResponse; +import common.packet.LPacketStartEncrypt; +import common.packet.RPacketDisconnect; +import common.packet.RPacketEnableCompression; +import common.packet.RPacketLoginSuccess; +import common.packet.RPacketRequestEncrypt; +import common.util.EncryptUtil; +import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.GenericFutureListener; + +public class ClientLoginHandler extends NetHandler implements IClientLoginHandler { + private final Client gm; + private final NetConnection networkManager; + private final String user; + private final String access; + private final String password; + + public ClientLoginHandler(NetConnection conn, Client gmIn, String userIn, String accessIn, String passwordIn) { + this.networkManager = conn; + this.gm = gmIn; + this.user = userIn; + this.access = accessIn; + this.password = passwordIn; + } + + public void onDisconnect(String reason) + { + this.gm.disconnected(reason); + } + + public void handleDisconnect(RPacketDisconnect packetIn) + { + this.networkManager.closeChannel(packetIn.getReason()); + } + + public void handleEncrypt(RPacketRequestEncrypt packet) { + final SecretKey secret = EncryptUtil.createNewSharedKey(); + PublicKey pubkey = packet.getKey(); + this.networkManager.sendPacket(new LPacketStartEncrypt(secret, pubkey, packet.getToken()), new GenericFutureListener < Future > () { + public void operationComplete(Future u) throws Exception { + ClientLoginHandler.this.networkManager.startEncryption(secret); + ClientLoginHandler.this.networkManager.sendPacket(new LPacketPasswordResponse(ClientLoginHandler.this.user, ClientLoginHandler.this.access, ClientLoginHandler.this.password)); + } + }); + } + + public void handleLoginSuccess(RPacketLoginSuccess packetIn) + { + this.gm.debugWorld = packetIn.isDebug(); + this.networkManager.setConnectionState(PacketRegistry.PLAY); + this.networkManager.setNetHandler(new ClientPlayer(this.gm, this.networkManager)); + } + + public void handleEnableCompression(RPacketEnableCompression packetIn) + { + this.networkManager.setCompressionTreshold(packetIn.getValue()); + } +} diff --git a/client/src/client/network/ClientPlayer.java b/client/src/client/network/ClientPlayer.java new file mode 100755 index 00000000..fd0f6560 --- /dev/null +++ b/client/src/client/network/ClientPlayer.java @@ -0,0 +1,2066 @@ +package client.network; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import client.Client; +import client.PlayerController; +import client.gui.Gui; +import client.gui.GuiConsole; +import client.gui.GuiLoading; +import client.gui.character.GuiChar; +import client.gui.character.GuiCharacters; +import client.gui.container.GuiBrewing; +import client.gui.container.GuiChest; +import client.gui.container.GuiCrafting; +import client.gui.container.GuiDispenser; +import client.gui.container.GuiEnchant; +import client.gui.container.GuiFurnace; +import client.gui.container.GuiHopper; +import client.gui.container.GuiHorse; +import client.gui.container.GuiMachine; +import client.gui.container.GuiMerchant; +import client.gui.container.GuiRepair; +import client.gui.ingame.GuiSign; +import client.gui.ingame.GuiForm; +import client.renderer.particle.EntityPickupFX; +import client.renderer.texture.EntityTexManager; +import client.world.WorldClient; +import common.attributes.Attribute; +import common.attributes.AttributeInstance; +import common.attributes.AttributeMap; +import common.attributes.AttributeModifier; +import common.collect.Lists; +import common.collect.Maps; +import common.dimension.Dimension; +import common.entity.DataWatcher; +import common.entity.Entity; +import common.entity.animal.EntityHorse; +import common.entity.effect.EntityLightning; +import common.entity.item.EntityBoat; +import common.entity.item.EntityXp; +import common.entity.npc.EntityNPC; +import common.entity.npc.PlayerCharacter; +import common.entity.projectile.EntityProjectile; +import common.entity.types.EntityLiving; +import common.init.EntityRegistry; +import common.init.ItemRegistry; +import common.init.SoundEvent; +import common.inventory.AnimalChest; +import common.inventory.Container; +import common.inventory.ContainerLocalMenu; +import common.inventory.IInventory; +import common.inventory.InventoryBasic; +import common.inventory.InventoryPlayer; +import common.item.ItemStack; +import common.log.Log; +import common.model.ParticleType; +import common.network.IClientPlayer; +import common.network.NetConnection; +import common.network.NetHandler; +import common.network.Packet; +import common.packet.CPacketAction; +import common.packet.CPacketKeepAlive; +import common.packet.CPacketPlayer; +import common.packet.S14PacketEntity; +import common.packet.S18PacketEntityTeleport; +import common.packet.S19PacketEntityHeadLook; +import common.packet.S1APacketEntityStatus; +import common.packet.S1BPacketEntityAttach; +import common.packet.S1CPacketEntityMetadata; +import common.packet.S1DPacketEntityEffect; +import common.packet.S1EPacketRemoveEntityEffect; +import common.packet.S20PacketEntityProperties; +import common.packet.S27PacketExplosion; +import common.packet.S28PacketEffect; +import common.packet.S29PacketSoundEffect; +import common.packet.S2APacketParticles; +import common.packet.S2BPacketChangeGameState; +import common.packet.S2CPacketSpawnGlobalEntity; +import common.packet.S2DPacketOpenWindow; +import common.packet.S2EPacketCloseWindow; +import common.packet.S2FPacketSetSlot; +import common.packet.S30PacketWindowItems; +import common.packet.S31PacketWindowProperty; +import common.packet.S32PacketConfirmTransaction; +import common.packet.S33PacketUpdateSign; +import common.packet.S35PacketUpdateTileEntity; +import common.packet.S36PacketSignEditorOpen; +import common.packet.S38PacketPlayerListItem; +import common.packet.S39PacketPlayerAbilities; +import common.packet.S3APacketTabComplete; +import common.packet.S43PacketUpdateEntityNBT; +import common.packet.SPacketAnimation; +import common.packet.SPacketBlockAction; +import common.packet.SPacketBlockBreakAnim; +import common.packet.SPacketBlockChange; +import common.packet.SPacketCamera; +import common.packet.SPacketCharacterList; +import common.packet.SPacketChunkData; +import common.packet.SPacketCollectItem; +import common.packet.SPacketDestroyEntities; +import common.packet.SPacketDimensionName; +import common.packet.SPacketDisconnect; +import common.packet.SPacketDisplayForm; +import common.packet.SPacketEntityEquipment; +import common.packet.SPacketEntityVelocity; +import common.packet.SPacketHeldItemChange; +import common.packet.SPacketJoinGame; +import common.packet.SPacketKeepAlive; +import common.packet.SPacketLoading; +import common.packet.SPacketMapChunkBulk; +import common.packet.SPacketMessage; +import common.packet.SPacketMultiBlockChange; +import common.packet.SPacketPlayerPosLook; +import common.packet.SPacketRespawn; +import common.packet.SPacketServerTick; +import common.packet.SPacketSetExperience; +import common.packet.SPacketSkin; +import common.packet.SPacketSpawnMob; +import common.packet.SPacketSpawnObject; +import common.packet.SPacketSpawnPlayer; +import common.packet.SPacketTimeUpdate; +import common.packet.SPacketTrades; +import common.packet.SPacketUpdateHealth; +import common.packet.SPacketWorld; +import common.potion.PotionEffect; +import common.rng.Random; +import common.sound.Sound; +import common.tileentity.IInteractionObject; +import common.tileentity.LocalBlockIntercommunication; +import common.tileentity.TileEntity; +import common.tileentity.TileEntityMachine; +import common.tileentity.TileEntitySign; +import common.util.BlockPos; +import common.village.MerchantRecipeList; +import common.world.Chunk; +import common.world.Explosion; +import common.world.Weather; +import common.world.World; + +public class ClientPlayer extends NetHandler implements IClientPlayer +{ + /** + * The NetworkManager instance used to communicate with the server (used only by handlePlayerPosLook to update + * positioning and handleJoinGame to inform the server of the client distribution/mods) + */ + private final NetConnection netManager; + + /** + * Reference to the Game instance, which many handler methods operate on + */ + private Client gameController; + + /** + * Reference to the current ClientWorld instance, which many handler methods operate on + */ + private WorldClient clientWorldController; + + /** + * True if the client has finished downloading terrain and may spawn. Set upon receipt of S08PacketPlayerPosLook, + * reset upon respawning + */ + private boolean doneLoadingTerrain; +// private boolean travelSound; + private final Map playerList = Maps.newTreeMap(); + private final List characterList = Lists.newArrayList(); +// private final List> players = Lists.newArrayList(); + private int selectedCharacter = -1; + + /** + * Just an ordinary random number generator, used to randomize audio pitch of item/orb pickup and randomize both + * particlespawn offset and velocity + */ + private final Random avRandomizer = new Random(); + + public ClientPlayer(Client gmIn, NetConnection p_i46300_3_) + { + this.gameController = gmIn; + this.netManager = p_i46300_3_; + } + + + public void playSound(Sound sound) { + this.gameController.getSoundManager().playSound(sound); + } + + public void emitParticleAtEntity(Entity entityIn, ParticleType particleTypes) { + this.gameController.effectRenderer.emitParticleAtEntity(entityIn, particleTypes); + } + + public boolean isJumping() { + return this.gameController.jump; + } + + public boolean isSprinting() { + return this.gameController.sprint; + } + + public boolean isSneaking() { + return this.gameController.sneak; + } + + public float getMoveForward() { + return this.gameController.moveForward; + } + + public float getMoveStrafe() { + return this.gameController.moveStrafe; + } + + public void setMoveForward(float value) { + this.gameController.moveForward = value; + } + + public void setMoveStrafe(float value) { + this.gameController.moveStrafe = value; + } + + public boolean isRenderViewEntity(Entity entity) { + return this.gameController.getRenderViewEntity() == entity; + } + + public void updatePlayerMoveState() { + this.gameController.updatePlayerMoveState(); + } + + + /** + * Clears the WorldClient instance associated with this NetHandlerPlayClient + */ + public void cleanup() + { + this.clientWorldController = null; +// for(String user : this.playerInfoMap.keySet()) { +// DefaultPlayerSkin.setTexture(user, null); +// } + EntityTexManager.clearTextures(); +// this.gameController.confirmSkin(false); + } + + public void handleJoinGame(SPacketJoinGame packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController); + this.gameController.charEditor = packetIn.isInEditor(); + this.gameController.controller = new PlayerController(this.gameController, this); + this.clientWorldController = new WorldClient(this.gameController, this.gameController.debugWorld, packetIn.getDimension()); + // this.gameController.gameSettings.difficulty = packetIn.getDifficulty(); + this.gameController.loadWorld(this.clientWorldController, packetIn.getEntityType()); +// this.gameController.thePlayer.dimension = this.clientWorldController.dimension.getDimensionId(); + this.gameController.player.setId(packetIn.getEntityId()); + this.gameController.displayGuiScreen(this.gameController.charEditor ? GuiChar.INSTANCE : null); +// this.currentServerMaxPlayers = packetIn.getMaxPlayers(); +// this.gameController.controller.setCheat(packetIn.getCheat()); +// this.gameController.updateViewDistance(); +// this.gameController.sendPartsToServer(); +// this.gameController.sendHeightToServer(); + // this.netManager.sendPacket(new C25PacketBrand(Version.NAME)); +// this.netManager.sendPacket(new CPacketSkin(this.gameController.getSkin())); +// if(this.gameController.getConnected() == null) +// this.netManager.sendPacket(new CPacketMessage(CPacketMessage.Type.DISPLAY, +// ChatFormat.replaceCodes(this.gameController.localName))); + } + + /** + * Spawns an instance of the objecttype indicated by the packet and sets its position and momentum + */ + public void handleSpawnObject(SPacketSpawnObject packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + double d0 = (double)packetIn.getX() / 32.0D; + double d1 = (double)packetIn.getY() / 32.0D; + double d2 = (double)packetIn.getZ() / 32.0D; + + Entity // entity = null; +// if (packetIn.getType() == 10) +// { +// entity = EntityMinecart.getMinecart(this.clientWorldController, d0, d1, d2, EntityMinecart.EnumMinecartType.byNetworkID(packetIn.getData())); +// } +// else +// if(packetIn.getType() == EntityRegistry.FISH_HOOK_OID) +// { +// Entity entity1 = this.clientWorldController.getEntityByID(packetIn.getData()); +// +// if (entity1.isPlayer()) +// { +// entity = new EntityFishHook(this.clientWorldController, d0, d1, d2, (EntityNPC)entity1); +// } +// +// packetIn.setData(0); +// } +// else { + entity = EntityRegistry.createEntityByID(packetIn.getType(), this.clientWorldController, d0, d1, d2, packetIn.getData()); +// } + if(entity != null && entity.dead) { + entity = null; + } + +// else if (packetIn.getType() == 60) +// { +// entity = new EntityArrow(this.clientWorldController, d0, d1, d2); +// } +// else if (packetIn.getType() == 61) +// { +// entity = new EntitySnowball(this.clientWorldController, d0, d1, d2); +// } +// else if (packetIn.getType() == 71) +// { +// entity = new EntityItemFrame(this.clientWorldController, new BlockPos(MathHelper.floor_double(d0), MathHelper.floor_double(d1), MathHelper.floor_double(d2)), EnumFacing.getHorizontal(packetIn.getData())); +// packetIn.setData(0); +// } +// else if (packetIn.getType() == 77) +// { +// entity = new EntityLeashKnot(this.clientWorldController, new BlockPos(MathHelper.floor_double(d0), MathHelper.floor_double(d1), MathHelper.floor_double(d2))); +// packetIn.setData(0); +// } +// else if (packetIn.getType() == 65) +// { +// entity = new EntityEnderPearl(this.clientWorldController, d0, d1, d2); +// } +// else if (packetIn.getType() == 72) +// { +// entity = new EntityEnderEye(this.clientWorldController, d0, d1, d2); +// } +// else if (packetIn.getType() == 76) +// { +// entity = new EntityFireworkRocket(this.clientWorldController, d0, d1, d2, (ItemStack)null); +// } +// else if (packetIn.getType() == 63) +// { +// entity = new EntityLargeFireball(this.clientWorldController, d0, d1, d2, (double)packetIn.getSpeedX() / 8000.0D, (double)packetIn.getSpeedY() / 8000.0D, (double)packetIn.getSpeedZ() / 8000.0D); +// packetIn.setData(0); +// } +// else if (packetIn.getType() == 64) +// { +// entity = new EntitySmallFireball(this.clientWorldController, d0, d1, d2, (double)packetIn.getSpeedX() / 8000.0D, (double)packetIn.getSpeedY() / 8000.0D, (double)packetIn.getSpeedZ() / 8000.0D); +// packetIn.setData(0); +// } +// else if (packetIn.getType() == 66) +// { +// entity = new EntityWitherSkull(this.clientWorldController, d0, d1, d2, (double)packetIn.getSpeedX() / 8000.0D, (double)packetIn.getSpeedY() / 8000.0D, (double)packetIn.getSpeedZ() / 8000.0D); +// packetIn.setData(0); +// } +// else if (packetIn.getType() == 62) +// { +// entity = new EntityEgg(this.clientWorldController, d0, d1, d2); +// } +// else if (packetIn.getType() == 73) +// { +// entity = new EntityPotion(this.clientWorldController, d0, d1, d2, packetIn.getData()); +// packetIn.setData(0); +// } +// else if (packetIn.getType() == 75) +// { +// entity = new EntityExpBottle(this.clientWorldController, d0, d1, d2); +// packetIn.setData(0); +// } +// else if (packetIn.getType() == 1) +// { +// entity = new EntityBoat(this.clientWorldController, d0, d1, d2); +// } +// else if (packetIn.getType() == 50) +// { +// entity = new EntityTNTPrimed(this.clientWorldController, d0, d1, d2, (EntityLivingBase)null, packetIn.getData()); +// packetIn.setData(0); +// } +// else if (packetIn.getType() == 78) +// { +// entity = new EntityArmorStand(this.clientWorldController, d0, d1, d2); +// } +// else if (packetIn.getType() == 51) +// { +// entity = new EntityEnderCrystal(this.clientWorldController, d0, d1, d2); +// } +// else if (packetIn.getType() == 2) +// { +// entity = new EntityItem(this.clientWorldController, d0, d1, d2); +// } +// else if (packetIn.getType() == 70) +// { +// entity = new EntityFallingBlock(this.clientWorldController, d0, d1, d2, BlockRegistry.getStateById(packetIn.getData() & 65535)); +// packetIn.setData(0); +// } +// +// else if (packetIn.getType() == 100) +// { +// entity = new EntityDynamite(this.clientWorldController, d0, d1, d2, packetIn.getData()); +// packetIn.setData(0); +// } + + if (entity != null) + { + entity.serverPosX = packetIn.getX(); + entity.serverPosY = packetIn.getY(); + entity.serverPosZ = packetIn.getZ(); + entity.rotPitch = (float)(packetIn.getPitch() * 360) / 256.0F; + entity.rotYaw = (float)(packetIn.getYaw() * 360) / 256.0F; + Entity[] aentity = entity.getParts(); + + if (aentity != null) + { + int i = packetIn.getEntityID() - entity.getId(); + + for (int j = 0; j < aentity.length; ++j) + { + aentity[j].setId(aentity[j].getId() + i); + } + } + + entity.setId(packetIn.getEntityID()); + this.clientWorldController.addEntityToWorld(packetIn.getEntityID(), entity); + + if(entity instanceof EntityProjectile) { + ((EntityProjectile)entity).setAcceleration((double)packetIn.getSpeedX() / 8000.0D, (double)packetIn.getSpeedY() / 8000.0D, (double)packetIn.getSpeedZ() / 8000.0D); + } + else if (entity.hasSpawnVelocity()) // packetIn.getData() > 0) + { +// if (packetIn.getType() == 60) +// { +// Entity entity2 = this.clientWorldController.getEntityByID(packetIn.getData()); +// +// if (entity2 instanceof EntityLivingBase && entity instanceof EntityArrow) +// { +// ((EntityArrow)entity).shootingEntity = entity2; +// } +// } + + entity.setVelocity((double)packetIn.getSpeedX() / 8000.0D, (double)packetIn.getSpeedY() / 8000.0D, (double)packetIn.getSpeedZ() / 8000.0D); + } + } + } + +// /** +// * Spawns an experience orb and sets its value (amount of XP) +// */ +// public void handleSpawnExperienceOrb(SPacketSpawnExperienceOrb packetIn) +// { +// NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); +// Entity entity = new EntityXPOrb(this.clientWorldController, (double)packetIn.getX() / 32.0D, (double)packetIn.getY() / 32.0D, (double)packetIn.getZ() / 32.0D, packetIn.getXPValue()); +// entity.serverPosX = packetIn.getX(); +// entity.serverPosY = packetIn.getY(); +// entity.serverPosZ = packetIn.getZ(); +// entity.rotYaw = 0.0F; +// entity.rotPitch = 0.0F; +// entity.setId(packetIn.getEntityID()); +// this.clientWorldController.addEntityToWorld(packetIn.getEntityID(), entity); +// } + + /** + * Handles globally visible entities. Used in vanilla for lightning bolts + */ + public void handleSpawnGlobalEntity(S2CPacketSpawnGlobalEntity packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + double d0 = (double)packetIn.getEncodedX() / 32.0D; + double d1 = (double)packetIn.getEncodedY() / 32.0D; + double d2 = (double)packetIn.getEncodedZ() / 32.0D; + Entity entity = null; + + if (packetIn.getType() == 1) + { + entity = new EntityLightning(this.clientWorldController, d0, d1, d2, packetIn.getData(), 0, false, null); + } + + if (entity != null) + { + entity.serverPosX = packetIn.getEncodedX(); + entity.serverPosY = packetIn.getEncodedY(); + entity.serverPosZ = packetIn.getEncodedZ(); + entity.rotYaw = 0.0F; + entity.rotPitch = 0.0F; + entity.setId(packetIn.getEntityId()); + this.clientWorldController.effects.add(entity); + } + } + +// /** +// * Handles the spawning of a painting object +// */ +// public void handleSpawnPainting(SPacketSpawnPainting packetIn) +// { +// NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); +// EntityPainting entitypainting = new EntityPainting(this.clientWorldController, packetIn.getPosition(), packetIn.getFacing(), packetIn.getTitle()); +// this.clientWorldController.addEntityToWorld(packetIn.getEntityID(), entitypainting); +// } + + /** + * Sets the velocity of the specified entity to the specified value + */ + public void handleEntityVelocity(SPacketEntityVelocity packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityID()); + + if (entity != null) + { + entity.setVelocity((double)packetIn.getMotionX() / 8000.0D, (double)packetIn.getMotionY() / 8000.0D, (double)packetIn.getMotionZ() / 8000.0D); + } + } + + /** + * Invoked when the server registers new proximate objects in your watchlist or when objects in your watchlist have + * changed -> Registers any changes locally + */ + public void handleEntityMetadata(S1CPacketEntityMetadata packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId()); + + if (entity != null && packetIn.func_149376_c() != null) + { + entity.getDataWatcher().updateWatchedObjectsFromList(packetIn.func_149376_c()); + + if(entity == this.gameController.player && this.gameController.open instanceof GuiChar) + ((GuiChar)this.gameController.open).checkReopen(); + } + } + + /** + * Handles the creation of a nearby player entity, sets the position and held item + */ + public void handleSpawnPlayer(SPacketSpawnPlayer packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + double x = (double)packetIn.getX() / 32.0D; + double y = (double)packetIn.getY() / 32.0D; + double z = (double)packetIn.getZ() / 32.0D; + float yaw = packetIn.getYaw(); + float pitch = packetIn.getPitch(); + EntityNPC player = (EntityNPC)EntityRegistry.createEntityByID(packetIn.getEntityType(), this.gameController.world); // new EntityNPC(this.gameController.theWorld); // , /* this.getPlayerInfo( */ packetIn.getUser()); // ).getUser()); + player.setOtherPlayer(); + player.prevX = player.lastTickPosX = (double)(player.serverPosX = packetIn.getX()); + player.prevY = player.lastTickPosY = (double)(player.serverPosY = packetIn.getY()); + player.prevZ = player.lastTickPosZ = (double)(player.serverPosZ = packetIn.getZ()); + player.yawOffset = player.headYaw = yaw; + int i = packetIn.getCurrentItemID(); + + if (i == 0) + { + player.inventory.mainInventory[player.inventory.currentItem] = null; + } + else + { + player.inventory.mainInventory[player.inventory.currentItem] = new ItemStack(ItemRegistry.getItemById(i), 1, 0); + } + + player.setPositionAndRotation(x, y, z, yaw, pitch); + this.clientWorldController.addEntityToWorld(packetIn.getEntityID(), player); + List list = packetIn.getData(); + + if (list != null) + { + player.getDataWatcher().updateWatchedObjectsFromList(list); + } + + EntityTexManager.setTexture(packetIn.getEntityID(), packetIn.getTexture(), player.getModel()); + } + + /** + * Updates an entity's position and rotation as specified by the packet + */ + public void handleEntityTeleport(S18PacketEntityTeleport packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId()); + + if (entity != null) + { + entity.serverPosX = packetIn.getX(); + entity.serverPosY = packetIn.getY(); + entity.serverPosZ = packetIn.getZ(); + double d0 = (double)entity.serverPosX / 32.0D; + double d1 = (double)entity.serverPosY / 32.0D; + double d2 = (double)entity.serverPosZ / 32.0D; + float f = (float)(packetIn.getYaw() * 360) / 256.0F; + float f1 = (float)(packetIn.getPitch() * 360) / 256.0F; + + if (Math.abs(entity.posX - d0) < 0.03125D && Math.abs(entity.posY - d1) < 0.015625D && Math.abs(entity.posZ - d2) < 0.03125D) + { + entity.setPositionAndRotation2(entity.posX, entity.posY, entity.posZ, f, f1, 3, true); + } + else + { + entity.setPositionAndRotation2(d0, d1, d2, f, f1, 3, true); + } + + entity.onGround = packetIn.getOnGround(); + } + } + + /** + * Updates which hotbar slot of the player is currently selected + */ + public void handleHeldItemChange(SPacketHeldItemChange packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + + if (packetIn.getHeldItemHotbarIndex() >= 0 && packetIn.getHeldItemHotbarIndex() < InventoryPlayer.getHotbarSize()) + { + this.gameController.player.inventory.currentItem = packetIn.getHeldItemHotbarIndex(); + } + } + + /** + * Updates the specified entity's position by the specified relative moment and absolute rotation. Note that + * subclassing of the packet allows for the specification of a subset of this data (e.g. only rel. position, abs. + * rotation or both). + */ + public void handleEntityMovement(S14PacketEntity packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + Entity entity = packetIn.getEntity(this.clientWorldController); + + if (entity != null) + { + entity.serverPosX += packetIn.getPosX(); + entity.serverPosY += packetIn.getPosY(); + entity.serverPosZ += packetIn.getPosZ(); + double d0 = (double)entity.serverPosX / 32.0D; + double d1 = (double)entity.serverPosY / 32.0D; + double d2 = (double)entity.serverPosZ / 32.0D; + float f = packetIn.hasRotations() ? (float)(packetIn.getYaw() * 360) / 256.0F : entity.rotYaw; + float f1 = packetIn.hasRotations() ? (float)(packetIn.getPitch() * 360) / 256.0F : entity.rotPitch; + entity.setPositionAndRotation2(d0, d1, d2, f, f1, 3, false); + entity.onGround = packetIn.getOnGround(); + } + } + + /** + * Updates the direction in which the specified entity is looking, normally this head rotation is independent of the + * rotation of the entity itself + */ + public void handleEntityHeadLook(S19PacketEntityHeadLook packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + Entity entity = packetIn.getEntity(this.clientWorldController); + + if (entity != null) + { + float f = (float)(packetIn.getYaw() * 360) / 256.0F; + entity.setRotationYawHead(f); + } + } + + /** + * Locally eliminates the entities. Invoked by the server when the items are in fact destroyed, or the player is no + * longer registered as required to monitor them. The latter happens when distance between the player and item + * increases beyond a certain treshold (typically the viewing distance) + */ + public void handleDestroyEntities(SPacketDestroyEntities packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + + for (int i = 0; i < packetIn.getEntityIDs().length; ++i) + { + this.clientWorldController.removeEntityFromWorld(packetIn.getEntityIDs()[i]); + EntityTexManager.setTexture(packetIn.getEntityIDs()[i], null, null); + } + } + + /** + * Handles changes in player positioning and rotation such as when travelling to a new dimension, (re)spawning, + * mounting horses etc. Seems to immediately reply to the server with the clients post-processing perspective on the + * player positioning + */ + public void handlePlayerPosLook(SPacketPlayerPosLook packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + EntityNPC entityplayer = this.gameController.player; + double d0 = packetIn.getX(); + double d1 = packetIn.getY(); + double d2 = packetIn.getZ(); + float f = packetIn.getYaw(); + float f1 = packetIn.getPitch(); + + if (packetIn.func_179834_f().contains(SPacketPlayerPosLook.EnumFlags.X)) + { + d0 += entityplayer.posX; + } + else + { + entityplayer.motionX = 0.0D; + } + + if (packetIn.func_179834_f().contains(SPacketPlayerPosLook.EnumFlags.Y)) + { + d1 += entityplayer.posY; + } + else + { + entityplayer.motionY = 0.0D; + } + + if (packetIn.func_179834_f().contains(SPacketPlayerPosLook.EnumFlags.Z)) + { + d2 += entityplayer.posZ; + } + else + { + entityplayer.motionZ = 0.0D; + } + + if (packetIn.func_179834_f().contains(SPacketPlayerPosLook.EnumFlags.X_ROT)) + { + f1 += entityplayer.rotPitch; + } + + if (packetIn.func_179834_f().contains(SPacketPlayerPosLook.EnumFlags.Y_ROT)) + { + f += entityplayer.rotYaw; + } + + entityplayer.setPositionAndRotation(d0, d1, d2, f, f1); + this.netManager.sendPacket(new CPacketPlayer.C06PacketPlayerPosLook(entityplayer.posX, entityplayer.getEntityBoundingBox().minY, entityplayer.posZ, entityplayer.rotYaw, entityplayer.rotPitch, false)); + + if (!this.doneLoadingTerrain) + { + this.gameController.player.prevX = this.gameController.player.posX; + this.gameController.player.prevY = this.gameController.player.posY; + this.gameController.player.prevZ = this.gameController.player.posZ; + this.doneLoadingTerrain = true; +// this.gameController.displayGuiScreen(null); +// if(this.travelSound) { +// this.gameController.getSoundManager().playSound(new PositionedSound(SoundEvent.TELEPORT)); +//// this.clientWorldController.playSound(entityplayer.posX, entityplayer.posY + (double)entityplayer.getEyeHeight(), entityplayer.posZ, this.travelSound, 1.0F, 1.0F, false); +// this.travelSound = false; +// } + } + } + + /** + * Received from the servers PlayerManager if between 1 and 64 blocks in a chunk are changed. If only one block + * requires an update, the server sends S23PacketBlockChange and if 64 or more blocks are changed, the server sends + * S21PacketChunkData + */ + public void handleMultiBlockChange(SPacketMultiBlockChange packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + + for (SPacketMultiBlockChange.BlockUpdateData s22packetmultiblockchange$blockupdatedata : packetIn.getChangedBlocks()) + { + this.clientWorldController.invalidateRegionAndSetBlock(s22packetmultiblockchange$blockupdatedata.getPos(), s22packetmultiblockchange$blockupdatedata.getBlockState()); + } + } + + /** + * Updates the specified chunk with the supplied data, marks it for re-rendering and lighting recalculation + */ + public void handleChunkData(SPacketChunkData packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + + if (packetIn.isResend()) + { + if (packetIn.getExtractedSize() == 0) + { + this.clientWorldController.doPreChunk(packetIn.getChunkX(), packetIn.getChunkZ(), false); + return; + } + + this.clientWorldController.doPreChunk(packetIn.getChunkX(), packetIn.getChunkZ(), true); + } + +// this.clientWorldController.invalidateBlockReceiveRegion(packetIn.getChunkX() << 4, 0, packetIn.getChunkZ() << 4, (packetIn.getChunkX() << 4) + 15, 512, (packetIn.getChunkZ() << 4) + 15); + Chunk chunk = this.clientWorldController.getChunk(packetIn.getChunkX(), packetIn.getChunkZ()); + chunk.setData(packetIn.getExtractedDataBytes(), packetIn.getExtractedSize(), packetIn.isResend()); + this.clientWorldController.markBlockRangeForRenderUpdate(packetIn.getChunkX() << 4, 0, packetIn.getChunkZ() << 4, (packetIn.getChunkX() << 4) + 15, 512, (packetIn.getChunkZ() << 4) + 15); + + if (!packetIn.isResend() || this.clientWorldController.dimension.hasNoLight()) // TODO: check + { + chunk.resetRelight(); + } + } + + /** + * Updates the block and metadata and generates a blockupdate (and notify the clients) + */ + public void handleBlockChange(SPacketBlockChange packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + this.clientWorldController.invalidateRegionAndSetBlock(packetIn.getBlockPosition(), packetIn.getBlockState()); + } + + /** + * Closes the network channel + */ + public void handleDisconnect(SPacketDisconnect packetIn) + { + this.netManager.closeChannel(packetIn.getMessage()); + } + + public void onDisconnect(String reason) + { + this.gameController.disconnected(reason); + } + + public void addToSendQueue(Packet p_147297_1_) + { + this.netManager.sendPacket(p_147297_1_); + } + + public void handleCollectItem(SPacketCollectItem packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + Entity entity = this.clientWorldController.getEntityByID(packetIn.getCollectedItemEntityID()); + EntityLiving entitylivingbase = (EntityLiving)this.clientWorldController.getEntityByID(packetIn.getEntityID()); + + if (entitylivingbase == null) + { + entitylivingbase = this.gameController.player; + } + + if (entity != null) + { + if (entity instanceof EntityXp) + { + this.clientWorldController.playSoundAtEntity(entity, SoundEvent.ORB, 0.2F); + } + else + { + this.clientWorldController.playSoundAtEntity(entity, SoundEvent.POP, 0.2F); + } + + this.gameController.effectRenderer.addEffect(new EntityPickupFX(this.clientWorldController, entity, entitylivingbase, 0.5F)); + this.clientWorldController.removeEntityFromWorld(packetIn.getCollectedItemEntityID()); + } + } + + /** + * Prints a chatmessage in the chat GUI + */ + public void handleMessage(SPacketMessage packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController); + +// if(this.gameController.chatVisibility == EnumChatVisibility.FULL || +// (this.gameController.chatVisibility == EnumChatVisibility.SYSTEM && packetIn.isSystem())) +// { + switch(packetIn.getType()) { + case CONSOLE: + this.gameController.logConsole(packetIn.getMessage()); + break; + case CHAT: + this.gameController.logChat(packetIn.getMessage()); + break; + case FEED: + this.gameController.logFeed(packetIn.getMessage()); + break; + case HOTBAR: + this.gameController.logHotbar(packetIn.getMessage()); + break; + } +// } + } + + public void handleLoading(SPacketLoading packet) { + NetHandler.checkThread(packet, this, this.gameController); + + if(packet.getMessage() == null) { + if(packet.getTask() != null) + this.gameController.message = packet.getTask(); + if(packet.getTotal() >= 0) + this.gameController.total = packet.getTotal(); + if(packet.getProgress() >= -1) + this.gameController.progress = packet.getProgress(); + } + else { + this.gameController.message = ""; + this.gameController.total = 0; + this.gameController.progress = -1; + this.gameController.displayGuiScreen(GuiLoading.makeServerTask(packet.getMessage())); + } + } + +// public void handleMessage(SPacketMessage packetIn) +// { +// NetHandler.checkThread(packetIn, this, this.gameController); +// this.gameController.ingameGui.printFeed(packetIn.getMessage()); +// } + +// public void handleNotify(SPacketNotify packetIn) +// { +// NetHandler.checkThread(packetIn, this, this.gameController); +// +// if(this.gameController.showNotifications) +// this.gameController.getNotifier().notify(packetIn.getStack(), packetIn.getMessage().getFormattedText(), +// packetIn.getDesciption().getFormattedText(), packetIn.getSound()); +// } + + /** + * Renders a specified animation: Waking up a player, a living entity swinging its currently held item, being hurt + * or receiving a critical hit by normal or magical means + */ + public void handleAnimation(SPacketAnimation packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityID()); + + if (entity != null) + { + if (packetIn.getAnimationType() == 0) + { + EntityLiving entitylivingbase = (EntityLiving)entity; + entitylivingbase.swingItem(); + } + else if (packetIn.getAnimationType() == 1) + { + entity.performHurtAnimation(); + } +// else if (packetIn.getAnimationType() == 2) +// { +// EntityNPC entityplayer = (EntityNPC)entity; +// entityplayer.wakeUpPlayer(); +// } + else if (packetIn.getAnimationType() == 4) + { + this.gameController.effectRenderer.emitParticleAtEntity(entity, ParticleType.CRIT); + } + else if (packetIn.getAnimationType() == 5) + { + this.gameController.effectRenderer.emitParticleAtEntity(entity, ParticleType.CRIT_MAGIC); + } + } + } + +// /** +// * Retrieves the player identified by the packet, puts him to sleep if possible (and flags whether all players are +// * asleep) +// */ +// public void handleUseBed(SPacketUseBed packetIn) +// { +// NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); +// packetIn.getPlayer(this.clientWorldController).trySetSpawn(packetIn.getBedPosition()); +// } + + /** + * Spawns the mob entity at the specified location, with the specified rotation, momentum and type. Updates the + * entities Datawatchers with the entity metadata specified in the packet + */ + public void handleSpawnMob(SPacketSpawnMob packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + double d0 = (double)packetIn.getX() / 32.0D; + double d1 = (double)packetIn.getY() / 32.0D; + double d2 = (double)packetIn.getZ() / 32.0D; + float f = (float)(packetIn.getYaw() * 360) / 256.0F; + float f1 = (float)(packetIn.getPitch() * 360) / 256.0F; + EntityLiving entitylivingbase = (EntityLiving)EntityRegistry.createEntityByID(packetIn.getEntityType(), this.gameController.world); + entitylivingbase.serverPosX = packetIn.getX(); + entitylivingbase.serverPosY = packetIn.getY(); + entitylivingbase.serverPosZ = packetIn.getZ(); + entitylivingbase.yawOffset = entitylivingbase.headYaw = (float)(packetIn.getHeadPitch() * 360) / 256.0F; + Entity[] aentity = entitylivingbase.getParts(); + + if (aentity != null) + { + int i = packetIn.getEntityID() - entitylivingbase.getId(); + + for (int j = 0; j < aentity.length; ++j) + { + aentity[j].setId(aentity[j].getId() + i); + } + } + + entitylivingbase.setId(packetIn.getEntityID()); + entitylivingbase.setPositionAndRotation(d0, d1, d2, f, f1); + entitylivingbase.motionX = (double)((float)packetIn.getVelocityX() / 8000.0F); + entitylivingbase.motionY = (double)((float)packetIn.getVelocityY() / 8000.0F); + entitylivingbase.motionZ = (double)((float)packetIn.getVelocityZ() / 8000.0F); + this.clientWorldController.addEntityToWorld(packetIn.getEntityID(), entitylivingbase); + List list = packetIn.getMetadata(); + + if (list != null) + { + entitylivingbase.getDataWatcher().updateWatchedObjectsFromList(list); + } + } + + public void handleTimeUpdate(SPacketTimeUpdate packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); +// this.gameController.theWorld.getWorldInfo().setTime(packetIn.getTotalWorldTime()); + this.gameController.world.setDayTime(packetIn.getWorldTime()); + this.gameController.setTicked(packetIn.getServerinfo()); + } + + public void handleServerTick(SPacketServerTick packet) + { + NetHandler.checkThread(packet, this, this.gameController); + this.gameController.setLastTick(packet.getTime(), packet.getServerinfo()); + } + +// public void handleCompass(SPacketCompass packetIn) +// { +// NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); +// this.gameController.thePlayer.setSpawnPoint(packetIn.getSpawnPos(), true); +// } + + public void handleEntityAttach(S1BPacketEntityAttach packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId()); + Entity entity1 = this.clientWorldController.getEntityByID(packetIn.getVehicleEntityId()); + + if (packetIn.getLeash() == 0) + { +// boolean flag = false; + + if (packetIn.getEntityId() == this.gameController.player.getId()) + { + entity = this.gameController.player; + + if (entity1 instanceof EntityBoat) + { + ((EntityBoat)entity1).setIsBoatEmpty(false); + } + +// flag = entity.vehicle == null && entity1 != null; + } + else if (entity1 instanceof EntityBoat) + { + ((EntityBoat)entity1).setIsBoatEmpty(true); + } + + if (entity == null) + { + return; + } + + entity.mountEntity(entity1); + +// if (flag) +// { +// this.gameController.ingameGui.displayHotbar(TextColor.LIGHT_GRAY + String.format("Drücke %s zum Verlassen", this.gameController.keyBindSneak.getKeyDisplay())); +// } + } + else if (packetIn.getLeash() == 1 && entity instanceof EntityLiving) + { + if (entity1 != null) + { + ((EntityLiving)entity).setLeashedTo(entity1, false); + } + else + { + ((EntityLiving)entity).clearLeashed(false, false); + } + } + } + + /** + * Invokes the entities' handleUpdateHealth method which is implemented in LivingBase (hurt/death), + * MinecartMobSpawner (spawn delay), FireworkRocket & MinecartTNT (explosion), IronGolem (throwing,...), Witch + * (spawn particles), Zombie (villager transformation), Animal (breeding mode particles), Horse (breeding/smoke + * particles), Sheep (...), Tameable (...), Villager (particles for breeding mode, angry and happy), Wolf (...) + */ + public void handleEntityStatus(S1APacketEntityStatus packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + Entity entity = packetIn.getEntity(this.clientWorldController); + + if (entity != null) + { +// if (packetIn.getOpCode() == 21) +// { +// this.gameController.getSoundHandler().playSound(new GuardianSound((EntityGuardian)entity)); +// } +// else +// { + entity.handleStatusUpdate(packetIn.getOpCode()); +// } + } + } + + public void handleUpdateHealth(SPacketUpdateHealth packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + this.gameController.player.setPlayerSPHealth(packetIn.getHealth()); +// this.gameController.thePlayer.getFoodStats().setFoodLevel(packetIn.getFoodLevel()); +// this.gameController.thePlayer.getFoodStats().setFoodSaturationLevel(packetIn.getSaturationLevel()); + } + + public void handleSetExperience(SPacketSetExperience packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + this.gameController.player.setXPStats(packetIn.getProgress(), packetIn.getTotalExperience(), packetIn.getLevel()); + } + + public void handleRespawn(SPacketRespawn packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + this.gameController.charEditor = packetIn.isInEditor(); + + Dimension dim = packetIn.getDimension(); + if (dim.getDimensionId() != this.clientWorldController.dimension.getDimensionId()) // this.gameController.thePlayer.dimension) + { + this.doneLoadingTerrain = false; +// if(dim.getDimensionId() < 0 && this.gameController.thePlayer.dimension >= 0) { +// this.travelSound = "portal.travel"; +// } +// Scoreboard scoreboard = this.clientWorldController.getScoreboard(); + this.clientWorldController = new WorldClient(this.gameController, this.gameController.debugWorld, dim); +// this.clientWorldController.setWorldScoreboard(scoreboard); + this.gameController.loadWorld(this.clientWorldController, packetIn.getEntityType()); +// this.gameController.thePlayer.dimension = dim.getDimensionId(); + } +// else if(this.gameController.charEditor) { +// this.gameController.displayGuiScreen(GuiSkin.INSTANCE); +// } + + this.gameController.setDimensionAndSpawnPlayer(dim.getDimensionId(), packetIn.getEntityType()); + this.gameController.displayGuiScreen(this.gameController.charEditor ? GuiChar.INSTANCE : null); +// this.gameController.controller.setCheat(packetIn.getCheat()); + } + + /** + * Initiates a new explosion (sound, particles, drop spawn) for the affected blocks indicated by the packet. + */ + public void handleExplosion(S27PacketExplosion packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + Explosion explosion = new Explosion(this.gameController.world, (Entity)null, packetIn.getX(), packetIn.getY(), packetIn.getZ(), packetIn.getStrength(), packetIn.getAffectedBlockPositions()); + explosion.doExplosionB(true, packetIn.hasAltSound()); + this.gameController.player.motionX += (double)packetIn.func_149149_c(); + this.gameController.player.motionY += (double)packetIn.func_149144_d(); + this.gameController.player.motionZ += (double)packetIn.func_149147_e(); + } + + /** + * Displays a GUI by ID. In order starting from id 0: Chest, Workbench, Furnace, Dispenser, Enchanting table, + * Brewing stand, Villager merchant, Beacon, Anvil, Hopper, Dropper, Horse + */ + public void handleOpenWindow(S2DPacketOpenWindow packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + EntityNPC entityplayersp = this.gameController.player; + + if ("container".equals(packetIn.getGuiId())) + { + entityplayersp.displayGUIChest(new InventoryBasic(packetIn.getWindowTitle(), packetIn.getSlotCount())); + entityplayersp.openContainer.windowId = packetIn.getWindowId(); + } + else if ("trade".equals(packetIn.getGuiId())) + { + entityplayersp.displayTradeGui(packetIn.getWindowTitle()); + entityplayersp.openContainer.windowId = packetIn.getWindowId(); + } + else if ("EntityHorse".equals(packetIn.getGuiId())) + { + Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId()); + + if (entity instanceof EntityHorse) + { + entityplayersp.displayGUIHorse((EntityHorse)entity, new AnimalChest(packetIn.getWindowTitle(), true, packetIn.getSlotCount())); + entityplayersp.openContainer.windowId = packetIn.getWindowId(); + } + } + else if (!packetIn.hasSlots()) + { + entityplayersp.displayGui(new LocalBlockIntercommunication(packetIn.getGuiId(), packetIn.getWindowTitle())); + entityplayersp.openContainer.windowId = packetIn.getWindowId(); + } + else + { + ContainerLocalMenu containerlocalmenu = new ContainerLocalMenu(packetIn.getGuiId(), packetIn.getWindowTitle(), packetIn.getSlotCount()); + if (packetIn.getGuiId().startsWith("machine_")) + { + TileEntity machine = this.clientWorldController.getTileEntity(packetIn.getTilePos()); + if(machine instanceof TileEntityMachine) + this.gameController.displayGuiScreen(new GuiMachine(this.gameController.player.inventory, containerlocalmenu, (TileEntityMachine)machine)); + } + else { + entityplayersp.displayGUIChest(containerlocalmenu); + } + entityplayersp.openContainer.windowId = packetIn.getWindowId(); + } + } + + /** + * Handles pickin up an ItemStack or dropping one in your inventory or an open container + */ + public void handleSetSlot(S2FPacketSetSlot packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + EntityNPC entityplayer = this.gameController.player; + + if (packetIn.getWindowId() == -1) + { + entityplayer.inventory.setItemStack(packetIn.getStack()); + } + else + { +// boolean flag = false; +// +// if (this.gameController.openGui instanceof GuiCheat) +// { +//// GuiCheat guicontainercreative = (GuiCheat)this.gameController.openGui; +// flag = true; // guicontainercreative.getSelectedTabIndex() != CheatTab.tabInventory.getIndex(); +// } + + if (packetIn.getWindowId() == 0 && packetIn.getSlot() >= 36 && packetIn.getSlot() < 45) + { + ItemStack itemstack = entityplayer.inventoryContainer.getSlot(packetIn.getSlot()).getStack(); + +// if (packetIn.getStack() != null && (itemstack == null || itemstack.stackSize < packetIn.getStack().stackSize)) +// { +// packetIn.getStack().animationsToGo = 5; +// } + + entityplayer.inventoryContainer.putStackInSlot(packetIn.getSlot(), packetIn.getStack()); + } + else if (packetIn.getWindowId() == entityplayer.openContainer.windowId) // && (packetIn.getWindowId() != 0 || !flag)) + { + entityplayer.openContainer.putStackInSlot(packetIn.getSlot(), packetIn.getStack()); + } + } + } + + /** + * Verifies that the server and client are synchronized with respect to the inventory/container opened by the player + * and confirms if it is the case. + */ + public void handleConfirmTransaction(S32PacketConfirmTransaction packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + Container container = null; + EntityNPC entityplayer = this.gameController.player; + + if (packetIn.getWindowId() == 0) + { + container = entityplayer.inventoryContainer; + } + else if (packetIn.getWindowId() == entityplayer.openContainer.windowId) + { + container = entityplayer.openContainer; + } + + if (container != null && !packetIn.isMatching()) + { + this.addToSendQueue(new CPacketAction(CPacketAction.Action.CONFIRM_TRANSACTION, packetIn.getWindowId() | ((packetIn.getActionNumber() & 65535) << 8))); + } + } + + /** + * Handles the placement of a specified ItemStack in a specified container/inventory slot + */ + public void handleWindowItems(S30PacketWindowItems packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + EntityNPC entityplayer = this.gameController.player; + + if (packetIn.func_148911_c() == 0) + { + entityplayer.inventoryContainer.putStacksInSlots(packetIn.getItemStacks()); + } + else if (packetIn.func_148911_c() == entityplayer.openContainer.windowId) + { + entityplayer.openContainer.putStacksInSlots(packetIn.getItemStacks()); + } + } + + /** + * Creates a sign in the specified location if it didn't exist and opens the GUI to edit its text + */ + public void handleSignEditorOpen(S36PacketSignEditorOpen packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + TileEntity tileentity = this.clientWorldController.getTileEntity(packetIn.getSignPosition()); + + if (!(tileentity instanceof TileEntitySign)) + { + tileentity = new TileEntitySign(); + tileentity.setWorldObj(this.clientWorldController); + tileentity.setPos(packetIn.getSignPosition()); + } + + this.gameController.player.openEditSign((TileEntitySign)tileentity); + } + + public void handleForm(SPacketDisplayForm packet) { + NetHandler.checkThread(packet, this, this.gameController, this.clientWorldController); + this.gameController.displayGuiScreen(new GuiForm(packet.getId(), packet.getTitle(), packet.getData())); + } + + /** + * Updates a specified sign with the specified text lines + */ + public void handleUpdateSign(S33PacketUpdateSign packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); +// boolean flag = false; + + if (this.gameController.world.isBlockLoaded(packetIn.getPos())) + { + TileEntity tileentity = this.gameController.world.getTileEntity(packetIn.getPos()); + + if (tileentity instanceof TileEntitySign) + { + TileEntitySign tileentitysign = (TileEntitySign)tileentity; + +// if (tileentitysign.getIsEditable()) +// { + System.arraycopy(packetIn.getLines(), 0, tileentitysign.signText, 0, 4); +// tileentitysign.command = packetIn.getCommand(); + tileentitysign.markDirty(); +// } + +// flag = true; + } + } + +// if (!flag) // && this.gameController.thePlayer != null) +// { +// Log.warn("Konnte kein Schild bei " + packetIn.getPos().getX() + ", " + +// packetIn.getPos().getY() + ", " + packetIn.getPos().getZ() + " finden"); +// } + } + + /** + * Updates the NBTTagCompound metadata of instances of the following entitytypes: Mob spawners, command blocks, + * beacons, skulls, flowerpot + */ + public void handleUpdateTileEntity(S35PacketUpdateTileEntity packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + + if (this.gameController.world.isBlockLoaded(packetIn.getPos())) + { + TileEntity tileentity = this.gameController.world.getTileEntity(packetIn.getPos()); +// int i = packetIn.getTileEntityType(); + + if (tileentity != null && packetIn.isTileEntityType(tileentity)) // i == 1 && tileentity instanceof TileEntityMobSpawner || /* i == 2 && tileentity instanceof TileEntityCommandBlock || */ i == 3 && tileentity instanceof TileEntityBeacon || i == 4 && tileentity instanceof TileEntitySkull || /* i == 5 && tileentity instanceof TileEntityFlowerPot || */ i == 6 && tileentity instanceof TileEntityBanner || i == 7 && tileentity instanceof TileEntityMachine) + { + tileentity.readFromNBT(packetIn.getNbtCompound()); + } + } + } + + /** + * Sets the progressbar of the opened window to the specified value + */ + public void handleWindowProperty(S31PacketWindowProperty packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + EntityNPC entityplayer = this.gameController.player; + + if (entityplayer.openContainer != null && entityplayer.openContainer.windowId == packetIn.getWindowId()) + { + entityplayer.openContainer.updateProgressBar(packetIn.getVarIndex(), packetIn.getVarValue()); + } + } + + public void handleEntityEquipment(SPacketEntityEquipment packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityID()); + + if (entity != null) + { + entity.setItem(packetIn.getEquipmentSlot(), packetIn.getItemStack()); + } + } + + /** + * Resets the ItemStack held in hand and closes the window that is opened + */ + public void handleCloseWindow(S2EPacketCloseWindow packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); +// this.gameController.thePlayer.closeScreenAndDropStack(); + this.gameController.displayGuiScreen(null); + } + + /** + * Triggers Block.onBlockEventReceived, which is implemented in BlockPistonBase for extension/retraction, BlockNote + * for setting the instrument (including audiovisual feedback) and in BlockContainer to set the number of players + * accessing a (Ender)Chest + */ + public void handleBlockAction(SPacketBlockAction packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + this.gameController.world.addBlockEvent(packetIn.getBlockPosition(), packetIn.getBlockType(), packetIn.getData1(), packetIn.getData2()); + } + + /** + * Updates all registered IWorldAccess instances with destroyBlockInWorldPartially + */ + public void handleBlockBreakAnim(SPacketBlockBreakAnim packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + this.gameController.world.sendBlockBreakProgress(packetIn.getBreakerId(), packetIn.getPosition(), packetIn.getProgress()); + } + + public void handleMapChunkBulk(SPacketMapChunkBulk packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + + for (int i = 0; i < packetIn.getChunkCount(); ++i) + { + int j = packetIn.getChunkX(i); + int k = packetIn.getChunkZ(i); + this.clientWorldController.doPreChunk(j, k, true); +// this.clientWorldController.invalidateBlockReceiveRegion(j << 4, 0, k << 4, (j << 4) + 15, 512, (k << 4) + 15); + Chunk chunk = this.clientWorldController.getChunk(j, k); + chunk.setData(packetIn.getChunkBytes(i), packetIn.getChunkSize(i), true); + this.clientWorldController.markBlockRangeForRenderUpdate(j << 4, 0, k << 4, (j << 4) + 15, 512, (k << 4) + 15); + + if (this.clientWorldController.dimension.hasNoLight()) // TODO: check + { + chunk.resetRelight(); + } + } + } + + public void handleChangeGameState(S2BPacketChangeGameState packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + switch(packetIn.getAction()) { +// case SET_CHEAT: +// this.gameController.controller.setCheat(packetIn.getInt() == 1); +// break; + case SET_WEATHER: + this.clientWorldController.setWeather(Weather.getByID(packetIn.getInt())); + break; + case RAIN_STRENGTH: + this.clientWorldController.setRainStrength(packetIn.getFloat(true)); + break; + case DARKNESS: + this.clientWorldController.setDarkness(packetIn.getFloat(true)); + break; + case FOG_STRENGTH: + this.clientWorldController.setFogStrength(packetIn.getFloat(true)); + break; + } + } + + public void handleEffect(S28PacketEffect packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + +// if (packetIn.isSoundServerwide()) +// { +// this.gameController.theWorld.broadcastSound(packetIn.getSoundType(), packetIn.getSoundPos(), packetIn.getSoundData()); +// } +// else +// { + this.gameController.world.playAuxSFX(packetIn.getSoundType(), packetIn.getSoundPos(), packetIn.getSoundData()); +// } + } + +// /** +// * Updates the players statistics or achievements +// */ +// public void handleStatistics(S37PacketStatistics packetIn) +// { +// NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); +// boolean flag = false; +// +// for (Entry entry : packetIn.getStats().entrySet()) +// { +// StatBase statbase = (StatBase)entry.getKey(); +// int i = ((Integer)entry.getValue()).intValue(); +// +//// if (statbase.isAchievement() && i > 0) +//// { +//// if (this.field_147308_k && this.gameController.thePlayer.getStatFileWriter().readStat(statbase) == 0) +//// { +//// Achievement achievement = (Achievement)statbase; +//// this.gameController.getNotifier().displayAchievement(achievement); +//// +////// if (statbase == AchievementList.openInventory) +////// { +////// this.gameController.showInventoryAchievementHint = false; +////// this.gameController.saveOptions(); +////// } +//// } +//// +//// flag = true; +//// } +// +// this.gameController.stats.put(statbase, i); +// } +// +//// if (!this.field_147308_k && !flag && this.gameController.showInventoryAchievementHint) +//// { +//// this.gameController.getNotifier().displayUnformattedAchievement(AchievementList.openInventory); +//// } +// +//// this.field_147308_k = true; +// +//// if (this.gameController.openGui instanceof GuiAchievements) +//// { +//// ((GuiAchievements)this.gameController.openGui).doneLoading(); +//// } +//// else +// if (this.gameController.openGui instanceof GuiStats) +// { +// ((GuiStats)this.gameController.openGui).doneLoading(); +// } +// } + + public void handleEntityEffect(S1DPacketEntityEffect packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId()); + + if (entity instanceof EntityLiving) + { + PotionEffect potioneffect = new PotionEffect(packetIn.getEffectId(), packetIn.getDuration(), packetIn.getAmplifier(), false, packetIn.hasParticles()) + .setRemaining(packetIn.getRemaining()); + ((EntityLiving)entity).addEffect(potioneffect); + } + } + +// public void handleCombatEvent(S42PacketCombatEvent packetIn) +// { +// PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController); +// +// } + +// public void handleServerDifficulty(S3EPacketServerDifficulty packetIn) +// { +// NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); +//// this.gameController.theWorld.setHardcore(packetIn.isHardcore()); +//// this.gameController.theWorld.getWorldInfo().setLocked(packetIn.isDifficultyLocked()); +// } + + public void handleCamera(SPacketCamera packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + Entity entity = packetIn.getEntity(this.clientWorldController); + + if (entity != null) + { + this.gameController.setRenderViewEntity(entity); + } + } + + +// public void handleTitle(S42PacketTitle packetIn) +// { +// NetHandler.checkThread(packetIn, this, this.gameController); +// this.gameController.ingameGui.displayTitle(packetIn.getTitle(), packetIn.getSubtitle()); +// } + +// public void handleSetCompressionLevel(S46PacketSetCompressionLevel packetIn) +// { +// if (!this.netManager.isLocalChannel()) +// { +// this.netManager.setCompressionTreshold(packetIn.getThreshold()); +// } +// } + +// public void handlePlayerListHeaderFooter(S47PacketPlayerListHeaderFooter packetIn) +// { +// } + +// public void handleDisplay(SPacketDisplay packetIn) +// { +//// switch(packetIn.getType()) { +//// case DISPLAY: +// this.gameController.nickname = packetIn.getName() == null ? "" : (packetIn.getName().length() > 48 ? packetIn.getName().substring(0, 48) : packetIn.getName()); +//// this.gameController.nickChanged = true; +//// break; +//// case HEADER: +//// this.gameController.ingameGui.setHeader(packetIn.getList() == null ? null : +//// packetIn.getList().replace("${user}", this.gameController.getUser())); +//// break; +//// case FOOTER: +//// this.gameController.ingameGui.setFooter(packetIn.getList() == null ? null : +//// packetIn.getList().replace("${user}", this.gameController.getUser())); +//// break; +//// case SIDEBAR: +//// this.gameController.ingameGui.displaySidebar(packetIn.getList()); +//// break; +//// } +// } + + public void handleRemoveEntityEffect(S1EPacketRemoveEntityEffect packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId()); + + if (entity instanceof EntityLiving) + { + ((EntityLiving)entity).removeEffectClient(packetIn.getEffectId()); + } + } + + + public void handlePlayerListItem(S38PacketPlayerListItem packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController); + + for(Entry data : packetIn.getEntries()) { + if(data.getValue() < 0) + this.playerList.remove(data.getKey()); + else + this.playerList.put(data.getKey(), data.getValue()); + } +// String[] list = new String[this.playerList.size()]; +// int[] data = new int[this.playerList.size()]; +// int pos = 0; +// for(Entry entry : this.playerList.entrySet()) { +// list[pos] = entry.getKey(); +// data[pos++] = entry.getValue(); +// } +// this.gameController.infolist(list, data); + } + + public void handleCharacterList(SPacketCharacterList packet) + { + NetHandler.checkThread(packet, this, this.gameController); + + for(Entry data : packet.getEntries()) { + if(data.getValue() == null) + this.characterList.remove(data.getKey().intValue()); + else if(data.getKey() < this.characterList.size()) + this.characterList.set(data.getKey(), data.getValue()); + else + this.characterList.add(data.getKey(), data.getValue()); + } + this.selectedCharacter = packet.getSelected(); + if(this.gameController.charEditor && this.selectedCharacter >= 0) { + this.gameController.charEditor = false; + this.gameController.displayGuiScreen(null); + } + else if(this.gameController.open instanceof GuiCharacters) { + this.gameController.displayGuiScreen(this.gameController.open); + } + } + + public void handleKeepAlive(SPacketKeepAlive packetIn) + { + this.addToSendQueue(new CPacketKeepAlive(packetIn.getValue())); + } + + public void handlePlayerAbilities(S39PacketPlayerAbilities packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + EntityNPC entityplayer = this.gameController.player; + entityplayer.flying = packetIn.isFlying(); + entityplayer.noclip = packetIn.isNoclip(); +// entityplayer.speed = packetIn.getSpeed(); +// entityplayer.capabilities.setWalkSpeed(packetIn.getWalkSpeed()); + } + + /** + * Displays the available command-completion options the server knows of + */ + public void handleTabComplete(S3APacketTabComplete packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + String[] astring = packetIn.func_149630_c(); +// this.gameController.complete(astring); + if (this.gameController.open instanceof GuiConsole) + { + GuiConsole guichat = (GuiConsole)this.gameController.open; + guichat.onAutocompleteResponse(astring); + } + } + + public void handleSoundEffect(S29PacketSoundEffect packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + if(packetIn.getSound() == null) { + this.gameController.getSoundManager().stopSounds(); + return; + } +// else if(packetIn.getSoundName().startsWith("music#")) { +// return; +// } + this.gameController.world.playSound(packetIn.getX(), packetIn.getY(), packetIn.getZ(), packetIn.getSound(), packetIn.getVolume()); + } + +// public void handleDisplay(S48PacketDisplay packetIn) +// { +//// if(this.gameController.getConnected() == null) +//// { +//// File file1 = new File("saves"); +//// File file2 = new File(file1, "resources.zip"); +//// +//// if (file2.isFile()) +//// { +//// Futures.addCallback(this.gameController.getResourcePackRepository().setResourcePackInstance(file2), new FutureCallback() +//// { +//// public void onSuccess(Object p_onSuccess_1_) +//// { +//// +//// } +//// public void onFailure(Throwable p_onFailure_1_) +//// { +//// +//// } +//// }); +//// } +//// } +// } + + public void handleEntityNBT(S43PacketUpdateEntityNBT packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + Entity entity = packetIn.getEntity(this.clientWorldController); + + if (entity != null) + { + entity.clientUpdateEntityNBT(packetIn.getTagCompound()); + } + } + +// public void handleDisplayList(S3BPacketDisplayList packetIn) +// { +// NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); +// +// } + +// /** +// * Either updates the score with a specified value or removes the score for an objective +// */ +// public void handleUpdateScore(S3CPacketUpdateScore packetIn) +// { +// NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); +// Scoreboard scoreboard = this.clientWorldController.getScoreboard(); +// ScoreObjective scoreobjective = scoreboard.getObjective(packetIn.getObjectiveName()); +// +// if (packetIn.getScoreAction() == S3CPacketUpdateScore.Action.CHANGE) +// { +// Score score = scoreboard.getValueFromObjective(packetIn.getPlayerName(), scoreobjective); +// score.setScorePoints(packetIn.getScoreValue()); +// } +// else if (packetIn.getScoreAction() == S3CPacketUpdateScore.Action.REMOVE) +// { +// if (packetIn.getObjectiveName() == null || packetIn.getObjectiveName().isEmpty()) +// { +// scoreboard.removeObjectiveFromEntity(packetIn.getPlayerName(), (ScoreObjective)null); +// } +// else if (scoreobjective != null) +// { +// scoreboard.removeObjectiveFromEntity(packetIn.getPlayerName(), scoreobjective); +// } +// } +// } +// +// /** +// * Removes or sets the ScoreObjective to be displayed at a particular scoreboard position (list, sidebar, below +// * name) +// */ +// public void handleDisplayScoreboard(S3DPacketDisplayScoreboard packetIn) +// { +// NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); +// Scoreboard scoreboard = this.clientWorldController.getScoreboard(); +// +// if (packetIn.func_149370_d().length() == 0) +// { +// scoreboard.setObjectiveInDisplaySlot(packetIn.func_149371_c(), (ScoreObjective)null); +// } +// else +// { +// ScoreObjective scoreobjective = scoreboard.getObjective(packetIn.func_149370_d()); +// scoreboard.setObjectiveInDisplaySlot(packetIn.func_149371_c(), scoreobjective); +// } +// } + +// /** +// * Updates a team managed by the scoreboard: Create/Remove the team registration, Register/Remove the player-team- +// * memberships, Set team displayname/prefix/suffix and/or whether friendly fire is enabled +// */ +// public void handleTeams(S3EPacketTeams packetIn) +// { +// NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); +// Scoreboard scoreboard = this.clientWorldController.getScoreboard(); +// Team scoreplayerteam; +// +// if (packetIn.getAction() == 0) +// { +// scoreplayerteam = scoreboard.createTeam(packetIn.getName()); +// } +// else +// { +// scoreplayerteam = scoreboard.getTeam(packetIn.getName()); +// } +// +//// if (packetIn.getAction() == 0 || packetIn.getAction() == 2) +//// { +//// scoreplayerteam.setTeamName(packetIn.getDisplayName()); +//// scoreplayerteam.setNamePrefix(packetIn.getPrefix()); +//// scoreplayerteam.setNameSuffix(packetIn.getSuffix()); +//// scoreplayerteam.setChatFormat(ChatFormat.getByIndex(packetIn.getColor())); +//// scoreplayerteam.func_98298_a(packetIn.getFriendlyFlags()); +//// Team.EnumVisible team$enumvisible = Team.EnumVisible.func_178824_a(packetIn.getNameTagVisibility()); +//// +//// if (team$enumvisible != null) +//// { +//// scoreplayerteam.setNameTagVisibility(team$enumvisible); +//// } +//// } +// +// if (packetIn.getAction() == 0 || packetIn.getAction() == 3) +// { +// for (String s : packetIn.getPlayers()) +// { +// scoreboard.addPlayerToTeam(s, packetIn.getName()); +// } +// } +// +// if (packetIn.getAction() == 4) +// { +// for (String s1 : packetIn.getPlayers()) +// { +// scoreboard.removePlayerFromTeam(s1, scoreplayerteam); +// } +// } +// +// if (packetIn.getAction() == 1) +// { +// scoreboard.removeTeam(scoreplayerteam); +// } +// } + + /** + * Spawns a specified number of particles at the specified location with a randomized displacement according to + * specified bounds + */ + public void handleParticles(S2APacketParticles packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + + if (packetIn.getParticleCount() == 0) + { + double d0 = (double)(packetIn.getParticleSpeed() * packetIn.getXOffset()); + double d2 = (double)(packetIn.getParticleSpeed() * packetIn.getYOffset()); + double d4 = (double)(packetIn.getParticleSpeed() * packetIn.getZOffset()); + + try + { + ParticleType particle = packetIn.getParticleType(); + this.clientWorldController.spawnEntityFX(particle, particle.getShouldIgnoreRange() | packetIn.isLongDistance(), packetIn.getXCoordinate(), packetIn.getYCoordinate(), packetIn.getZCoordinate(), d0, d2, d4, packetIn.getParticleArgs()); + } + catch (Throwable var17) + { + Log.JNI.warn("Konnte Partikel-Effekt " + packetIn.getParticleType() + " nicht erzeugen"); + } + } + else + { + for (int i = 0; i < packetIn.getParticleCount(); ++i) + { + double d1 = this.avRandomizer.gaussian() * (double)packetIn.getXOffset(); + double d3 = this.avRandomizer.gaussian() * (double)packetIn.getYOffset(); + double d5 = this.avRandomizer.gaussian() * (double)packetIn.getZOffset(); + double d6 = this.avRandomizer.gaussian() * (double)packetIn.getParticleSpeed(); + double d7 = this.avRandomizer.gaussian() * (double)packetIn.getParticleSpeed(); + double d8 = this.avRandomizer.gaussian() * (double)packetIn.getParticleSpeed(); + + try + { + ParticleType particle = packetIn.getParticleType(); + this.clientWorldController.spawnEntityFX(particle, particle.getShouldIgnoreRange() | packetIn.isLongDistance(), packetIn.getXCoordinate() + d1, packetIn.getYCoordinate() + d3, packetIn.getZCoordinate() + d5, d6, d7, d8, packetIn.getParticleArgs()); + } + catch (Throwable var16) + { + Log.JNI.warn("Konnte Partikel-Effekt " + packetIn.getParticleType() + " nicht erzeugen"); + return; + } + } + } + } + + /** + * Updates en entity's attributes and their respective modifiers, which are used for speed bonusses (player + * sprinting, animals fleeing, baby speed), weapon/tool attackDamage, hostiles followRange randomization, zombie + * maxHealth and knockback resistance as well as reinforcement spawning chance. + */ + public void handleEntityProperties(S20PacketEntityProperties packetIn) + { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId()); + + if (entity != null) + { + if (!(entity instanceof EntityLiving)) + { + throw new IllegalStateException("Server tried to update attributes of a non-living entity (actually: " + entity + ")"); + } + else + { + AttributeMap baseattributemap = ((EntityLiving)entity).getAttributeMap(); + + for (S20PacketEntityProperties.Snapshot s20packetentityproperties$snapshot : packetIn.func_149441_d()) + { + AttributeInstance iattributeinstance = baseattributemap.getAttributeInstanceByName(s20packetentityproperties$snapshot.func_151409_a()); + + if (iattributeinstance == null) + { + iattributeinstance = baseattributemap.registerAttribute(Attribute.getAttribute(s20packetentityproperties$snapshot.func_151409_a())); + } + + iattributeinstance.setBaseValue(s20packetentityproperties$snapshot.func_151410_b()); + iattributeinstance.removeAllModifiers(); + + for (AttributeModifier attributemodifier : s20packetentityproperties$snapshot.func_151408_c()) + { + iattributeinstance.applyModifier(attributemodifier); + } + } + } + } + } + + public void handleSkin(SPacketSkin packetIn) { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + + Entity entity = packetIn.getEntity(this.clientWorldController); + if(entity != null && entity.isPlayer()) // { + EntityTexManager.setTexture(entity.getId(), packetIn.getTexture(), ((EntityNPC)entity).getModel()); +// if(entity == this.gameController.thePlayer) +// this.gameController.confirmSkin(true); +// } + } + +// public void handleCapes(SPacketCapes packetIn) { +// NetHandler.checkThread(packetIn, this, this.gameController); +// EntityTexManager.setCapeTextures(packetIn.getCapes()); +// } + +// public void handleBook(SPacketBook packetIn) { +// NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); +// +// ItemStack itemstack = this.gameController.thePlayer.getCurrentEquippedItem(); +// +// if (itemstack != null && itemstack.getItem() == Items.writable_book) +// { +// this.gameController.displayGuiScreen(new GuiBook(itemstack)); +// } +// } + + public void handleTrades(SPacketTrades packetIn) { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + + try + { + int i = packetIn.getWindowId(); + Gui gui = this.gameController.open; + + if (gui != null && gui instanceof GuiMerchant && i == this.gameController.player.openContainer.windowId) + { +// NpcMerchant imerchant = ((GuiMerchant)guiscreen).getMerchant(); + MerchantRecipeList merchantrecipelist = packetIn.getTrades(); + ((GuiMerchant)gui).setRecipes(merchantrecipelist); + } + } + catch (Exception exception) + { + Log.JNI.error((Throwable)exception, (String)"Konnte Handel nicht laden"); + } + } + + public void handleWorld(SPacketWorld packetIn) { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + this.clientWorldController.setGravity(this.gameController.gravity = packetIn.getGravity()); + this.clientWorldController.setTimeFactor(this.gameController.timeFactor = packetIn.getTimeFactor()); +// this.clientWorldController.setDifficulty(this.gameController.difficulty = packetIn.getDifficulty()); + this.gameController.dayCycle = packetIn.hasDayCycle(); + } + + public void handleDimName(SPacketDimensionName packetIn) { + NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); + this.clientWorldController.dimension.setFullName(packetIn.getFullName()); + this.clientWorldController.dimension.setCustomName(packetIn.getCustomName()); + } + + /** + * Returns this the NetworkManager instance registered with this NetworkHandlerPlayClient + */ + public NetConnection getNetworkManager() + { + return this.netManager; + } + + public Set> getPlayerList() + { + return this.playerList.entrySet(); + } + + public Collection getCharacterList() + { + return this.characterList; + } + + public int getSelectedCharacter() + { + return this.selectedCharacter; + } + + public Iterable getPlayerNames() + { + return this.playerList.keySet(); + } + + public void displayGUIChest(IInventory chestInventory, InventoryPlayer inventory) { + String s = chestInventory instanceof IInteractionObject ? ((IInteractionObject)chestInventory).getGuiID() : "container"; + + if ("chest".equals(s)) + { + this.gameController.displayGuiScreen(new GuiChest(inventory, chestInventory)); + } + else if ("hopper".equals(s)) + { + this.gameController.displayGuiScreen(new GuiHopper(inventory, chestInventory)); + } + else if ("furnace".equals(s)) + { + this.gameController.displayGuiScreen(new GuiFurnace(inventory, chestInventory)); + } + else if ("brewing_stand".equals(s)) + { + this.gameController.displayGuiScreen(new GuiBrewing(inventory, chestInventory)); + } +// else if ("beacon".equals(s)) +// { +// this.gm.displayGuiScreen(new GuiBeacon(this.inventory, chestInventory)); +// } + else if (!"dispenser".equals(s) && !"dropper".equals(s)) + { + this.gameController.displayGuiScreen(new GuiChest(inventory, chestInventory)); + } + else + { + this.gameController.displayGuiScreen(new GuiDispenser(inventory, chestInventory)); + } + } + + public void displayGui(IInteractionObject guiOwner, InventoryPlayer inventory, World worldObj) { + String s = guiOwner.getGuiID(); + + if ("crafting_table".equals(s)) + { + this.gameController.displayGuiScreen(new GuiCrafting(inventory, worldObj)); + } + else if ("enchanting_table".equals(s)) + { + this.gameController.displayGuiScreen(new GuiEnchant(inventory, worldObj, guiOwner)); + } + else if ("anvil".equals(s)) + { + this.gameController.displayGuiScreen(new GuiRepair(inventory, worldObj)); + } + } + + public void displayGuiHorse(EntityHorse horse, InventoryPlayer inventory, IInventory horseInventory) { + this.gameController.displayGuiScreen(new GuiHorse(inventory, horseInventory, horse)); + } + + public void displayGuiMerchant(String title, InventoryPlayer inventory, World worldObj) { + this.gameController.displayGuiScreen(new GuiMerchant(inventory, title, worldObj)); + } + + public void displayGuiSign(BlockPos pos, String[] text) { + this.gameController.displayGuiScreen(new GuiSign(pos, text)); + } + + public void closeGui() { + this.gameController.displayGuiScreen(null); + } +} diff --git a/client/src/client/renderer/ActiveRenderInfo.java b/client/src/client/renderer/ActiveRenderInfo.java new file mode 100755 index 00000000..653eff6b --- /dev/null +++ b/client/src/client/renderer/ActiveRenderInfo.java @@ -0,0 +1,150 @@ +package client.renderer; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; + +import org.lwjgl.opengl.GL11; + +import common.block.Block; +import common.block.BlockLiquid; +import common.entity.Entity; +import common.entity.npc.EntityNPC; +import common.util.BlockPos; +import common.util.ExtMath; +import common.util.Vec3; +import common.world.State; +import common.world.World; + +public class ActiveRenderInfo +{ + /** The current GL viewport */ + private static final IntBuffer VIEWPORT = ByteBuffer.allocateDirect(16 << 2).order(ByteOrder.nativeOrder()).asIntBuffer(); + + /** The current GL modelview matrix */ + private static final FloatBuffer MODELVIEW = ByteBuffer.allocateDirect(16 << 2).order(ByteOrder.nativeOrder()).asFloatBuffer(); + + /** The current GL projection matrix */ + private static final FloatBuffer PROJECTION = ByteBuffer.allocateDirect(16 << 2).order(ByteOrder.nativeOrder()).asFloatBuffer(); + + /** The computed view object coordinates */ + private static final FloatBuffer OBJECTCOORDS = ByteBuffer.allocateDirect(3 << 2).order(ByteOrder.nativeOrder()).asFloatBuffer(); + private static Vec3 position = new Vec3(0.0D, 0.0D, 0.0D); + + private static final FloatBuffer SCREENCOORDS = ByteBuffer.allocateDirect(3 << 2).order(ByteOrder.nativeOrder()).asFloatBuffer(); + + /** The X component of the entity's yaw rotation */ + private static float rotationX; + + /** The combined X and Z components of the entity's pitch rotation */ + private static float rotationXZ; + + /** The Z component of the entity's yaw rotation */ + private static float rotationZ; + + /** + * The Y component (scaled along the Z axis) of the entity's pitch rotation + */ + private static float rotationYZ; + + /** + * The Y component (scaled along the X axis) of the entity's pitch rotation + */ + private static float rotationXY; + + /** + * Updates the current render info and camera location based on entity look angles and 1st/3rd person view mode + */ + public static void updateRenderInfo(EntityNPC entityplayerIn, boolean p_74583_1_) + { + GL11.glGetFloatv(2982, MODELVIEW); + GL11.glGetFloatv(2983, PROJECTION); + GL11.glGetIntegerv(GL11.GL_VIEWPORT, VIEWPORT); + float f = (float)((VIEWPORT.get(0) + VIEWPORT.get(2)) / 2); + float f1 = (float)((VIEWPORT.get(1) + VIEWPORT.get(3)) / 2); + Project.gluUnProject(f, f1, 0.0F, MODELVIEW, PROJECTION, VIEWPORT, OBJECTCOORDS); + position = new Vec3((double)OBJECTCOORDS.get(0), (double)OBJECTCOORDS.get(1), (double)OBJECTCOORDS.get(2)); + int i = p_74583_1_ ? 1 : 0; + float f2 = entityplayerIn.rotPitch; + float f3 = entityplayerIn.rotYaw; + rotationX = ExtMath.cos(f3 * (float)Math.PI / 180.0F) * (float)(1 - i * 2); + rotationZ = ExtMath.sin(f3 * (float)Math.PI / 180.0F) * (float)(1 - i * 2); + rotationYZ = -rotationZ * ExtMath.sin(f2 * (float)Math.PI / 180.0F) * (float)(1 - i * 2); + rotationXY = rotationX * ExtMath.sin(f2 * (float)Math.PI / 180.0F) * (float)(1 - i * 2); + rotationXZ = ExtMath.cos(f2 * (float)Math.PI / 180.0F); + } + + public static Vec3 getDisplayCoords(float x, float y, float z) { + Project.gluProject(x, y, z, MODELVIEW, PROJECTION, VIEWPORT, SCREENCOORDS); + return new Vec3((double)SCREENCOORDS.get(0), (double)SCREENCOORDS.get(1), (double)SCREENCOORDS.get(2)); + } + + public static Vec3 projectViewFromEntity(Entity p_178806_0_, double p_178806_1_) + { + double d0 = p_178806_0_.prevX + (p_178806_0_.posX - p_178806_0_.prevX) * p_178806_1_; + double d1 = p_178806_0_.prevY + (p_178806_0_.posY - p_178806_0_.prevY) * p_178806_1_; + double d2 = p_178806_0_.prevZ + (p_178806_0_.posZ - p_178806_0_.prevZ) * p_178806_1_; + double d3 = d0 + position.xCoord; + double d4 = d1 + position.yCoord; + double d5 = d2 + position.zCoord; + return new Vec3(d3, d4, d5); + } + + public static Block getBlockAtEntityViewpoint(World worldIn, Entity p_180786_1_, float p_180786_2_) + { + Vec3 vec3 = projectViewFromEntity(p_180786_1_, (double)p_180786_2_); + BlockPos blockpos = new BlockPos(vec3); + State iblockstate = worldIn.getState(blockpos); + Block block = iblockstate.getBlock(); + + if (block.getMaterial().isLiquid()) + { + float f = 0.0F; + + if (iblockstate.getBlock() instanceof BlockLiquid) + { + f = BlockLiquid.getLiquidHeightPercent(((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue()) - 0.11111111F; + } + + float f1 = (float)(blockpos.getY() + 1) - f; + + if (vec3.yCoord >= (double)f1) + { + block = worldIn.getState(blockpos.up()).getBlock(); + } + } + + return block; + } + + public static Vec3 getPosition() + { + return position; + } + + public static float getRotationX() + { + return rotationX; + } + + public static float getRotationXZ() + { + return rotationXZ; + } + + public static float getRotationZ() + { + return rotationZ; + } + + public static float getRotationYZ() + { + return rotationYZ; + } + + public static float getRotationXY() + { + return rotationXY; + } +} diff --git a/client/src/client/renderer/BlockRenderer.java b/client/src/client/renderer/BlockRenderer.java new file mode 100755 index 00000000..0288aaf7 --- /dev/null +++ b/client/src/client/renderer/BlockRenderer.java @@ -0,0 +1,682 @@ +package client.renderer; + +import java.util.BitSet; +import java.util.List; +import java.util.Map; + +import org.lwjgl.opengl.GL11; + +import client.Client; +import client.renderer.blockmodel.BakedModel; +import client.renderer.blockmodel.BakedQuad; +import client.renderer.blockmodel.IBakedModel; +import client.renderer.blockmodel.ModelManager; +import client.renderer.texture.TextureAtlasSprite; +import client.renderer.texture.TextureMap; +import client.renderer.tileentity.TileEntityItemStackRenderer; +import common.block.Block; +import common.block.BlockLiquid; +import common.collect.Maps; +import common.init.BlockRegistry; +import common.init.FluidRegistry; +import common.item.ItemStack; +import common.material.Material; +import common.util.BlockPos; +import common.util.ExtMath; +import common.util.Facing; +import common.util.Vec3i; +import common.world.IBlockAccess; +import common.world.IWorldAccess; +import common.world.State; + +public class BlockRenderer +{ + private ModelManager manager; + private final Client gm; + private final Map fluids = Maps.newHashMap(); + + public BlockRenderer(ModelManager manager, Client gm) + { + this.manager = manager; + this.gm = gm; + this.initAtlasSprites(); + } + + public ModelManager getModelManager() + { + return this.manager; + } + + public void renderBlockDamage(State state, BlockPos pos, TextureAtlasSprite texture, IWorldAccess blockAccess) + { + Block block = state.getBlock(); + int i = block.getRenderType(); + + if (i == 3) + { + state = block.getActualState(state, blockAccess, pos); + IBakedModel ibakedmodel = this.manager.getModelForState(state); + IBakedModel ibakedmodel1 = (new BakedModel.Builder(ibakedmodel, texture)).makeBakedModel(); +// Tessellator.getInstance(); + this.renderModel(blockAccess, ibakedmodel1, state, pos, Tessellator.getBuffer()); + } + } + + public boolean renderBlock(State state, BlockPos pos, IWorldAccess blockAccess, RenderBuffer worldRendererIn) + { + if(this.gm.xrayActive && !state.getBlock().isXrayVisible()) + return false; + int i = state.getBlock().getRenderType(); + + if (i == -1) + { + return false; + } + else + { + switch (i) + { + case 1: + return this.renderFluid(blockAccess, state, pos, worldRendererIn); + + case 2: + return false; + + case 3: + IBakedModel ibakedmodel = this.getModelFromBlockState(state, blockAccess, pos); + return this.renderBase(blockAccess, ibakedmodel, state, pos, worldRendererIn, !this.gm.xrayActive); + + default: + return false; + } + } + } + + public IBakedModel getModelFromBlockState(State state, IWorldAccess worldIn, BlockPos pos) + { + Block block = state.getBlock(); + + if (!this.gm.debugWorld) + { + try + { + state = block.getActualState(state, worldIn, pos); + } + catch (Exception var6) + { + ; + } + } + + return this.manager.getModelForState(state); + +// if (pos != null && this.gameSettings.allowBlockAlternatives && ibakedmodel instanceof WeightedBakedModel) +// { +// ibakedmodel = ((WeightedBakedModel)ibakedmodel).getAlternativeModel(MathHelper.getPositionRandom(pos)); +// } +// +// return ibakedmodel; + } + + public void renderBlockBrightness(State state, float brightness) + { + int i = state.getBlock().getRenderType(); + + if (i != -1) + { + switch (i) + { + case 1: + default: + break; + + case 2: +// this.chestRenderer.renderChestBrightness(state.getBlock(), brightness); + GlState.color(brightness, brightness, brightness, 1.0F); + GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); + TileEntityItemStackRenderer.instance.renderByItem(new ItemStack(state.getBlock())); + break; + + case 3: + IBakedModel ibakedmodel = this.manager.getModelForState(state); + this.renderModelBrightness(ibakedmodel, state, brightness, true); + } + } + } + +// public boolean isRenderTypeChest(Block p_175021_1_, int p_175021_2_) +// { +// if (p_175021_1_ == null) +// { +// return false; +// } +// else +// { +// int i = p_175021_1_.getRenderType(); +// return i == 3 ? false : i == 2; +// } +// } + + public void onReload() + { + this.initAtlasSprites(); + } + + private boolean renderBase(IWorldAccess blockAccessIn, IBakedModel modelIn, State blockStateIn, BlockPos blockPosIn, RenderBuffer worldRendererIn, boolean checkSides) + { + Block block = blockStateIn.getBlock(); + block.setBlockBoundsBasedOnState(blockAccessIn, blockPosIn); + return this.renderModel(blockAccessIn, modelIn, blockStateIn, blockPosIn, worldRendererIn, checkSides); + } + + private boolean renderModel(IWorldAccess blockAccessIn, IBakedModel modelIn, State blockStateIn, BlockPos blockPosIn, RenderBuffer worldRendererIn) + { + Block block = blockStateIn.getBlock(); + block.setBlockBoundsBasedOnState(blockAccessIn, blockPosIn); + return this.renderModel(blockAccessIn, modelIn, blockStateIn, blockPosIn, worldRendererIn, true); + } + + public boolean renderModel(IWorldAccess blockAccessIn, IBakedModel modelIn, State blockStateIn, BlockPos blockPosIn, RenderBuffer worldRendererIn, boolean checkSides) + { +// return this.renderModelStandard(blockAccessIn, modelIn, , blockPosIn, worldRendererIn, checkSides); +// } +// +// public boolean renderModelStandard(IWorldAccess blockAccessIn, IBakedModel modelIn, Block blockIn, BlockPos blockPosIn, RenderBuffer worldRendererIn, boolean checkSides) +// { + Block blockIn = blockStateIn.getBlock(); + boolean flag = false; + BitSet bitset = new BitSet(3); + + for (Facing enumfacing : Facing.values()) + { + List list = modelIn.getFaceQuads(enumfacing); + + if (!list.isEmpty()) + { + BlockPos blockpos = blockPosIn.offset(enumfacing); + + if (!checkSides || blockIn.shouldSideBeRendered(blockAccessIn, blockpos, enumfacing)) + { + int i = blockIn.getMixedBrightnessForBlock(blockAccessIn, blockpos); + this.renderModelStandardQuads(blockAccessIn, blockIn, blockPosIn, enumfacing, i, false, worldRendererIn, list, bitset); + flag = true; + } + } + } + + List list1 = modelIn.getGeneralQuads(); + + if (list1.size() > 0) + { + this.renderModelStandardQuads(blockAccessIn, blockIn, blockPosIn, (Facing)null, -1, true, worldRendererIn, list1, bitset); + flag = true; + } + + return flag; + } + + private void fillQuadBounds(Block blockIn, int[] vertexData, Facing facingIn, float[] quadBounds, BitSet boundsFlags) + { + float f = 32.0F; + float f1 = 32.0F; + float f2 = 32.0F; + float f3 = -32.0F; + float f4 = -32.0F; + float f5 = -32.0F; + + for (int i = 0; i < 4; ++i) + { + float f6 = Float.intBitsToFloat(vertexData[i * 7]); + float f7 = Float.intBitsToFloat(vertexData[i * 7 + 1]); + float f8 = Float.intBitsToFloat(vertexData[i * 7 + 2]); + f = Math.min(f, f6); + f1 = Math.min(f1, f7); + f2 = Math.min(f2, f8); + f3 = Math.max(f3, f6); + f4 = Math.max(f4, f7); + f5 = Math.max(f5, f8); + } + + if (quadBounds != null) + { + quadBounds[Facing.WEST.getIndex()] = f; + quadBounds[Facing.EAST.getIndex()] = f3; + quadBounds[Facing.DOWN.getIndex()] = f1; + quadBounds[Facing.UP.getIndex()] = f4; + quadBounds[Facing.NORTH.getIndex()] = f2; + quadBounds[Facing.SOUTH.getIndex()] = f5; + quadBounds[Facing.WEST.getIndex() + Facing.values().length] = 1.0F - f; + quadBounds[Facing.EAST.getIndex() + Facing.values().length] = 1.0F - f3; + quadBounds[Facing.DOWN.getIndex() + Facing.values().length] = 1.0F - f1; + quadBounds[Facing.UP.getIndex() + Facing.values().length] = 1.0F - f4; + quadBounds[Facing.NORTH.getIndex() + Facing.values().length] = 1.0F - f2; + quadBounds[Facing.SOUTH.getIndex() + Facing.values().length] = 1.0F - f5; + } + + float f9 = 1.0E-4F; + float f10 = 0.9999F; + + switch (facingIn) + { + case DOWN: + boundsFlags.set(1, f >= 1.0E-4F || f2 >= 1.0E-4F || f3 <= 0.9999F || f5 <= 0.9999F); + boundsFlags.set(0, (f1 < 1.0E-4F || blockIn.isFullCube()) && f1 == f4); + break; + + case UP: + boundsFlags.set(1, f >= 1.0E-4F || f2 >= 1.0E-4F || f3 <= 0.9999F || f5 <= 0.9999F); + boundsFlags.set(0, (f4 > 0.9999F || blockIn.isFullCube()) && f1 == f4); + break; + + case NORTH: + boundsFlags.set(1, f >= 1.0E-4F || f1 >= 1.0E-4F || f3 <= 0.9999F || f4 <= 0.9999F); + boundsFlags.set(0, (f2 < 1.0E-4F || blockIn.isFullCube()) && f2 == f5); + break; + + case SOUTH: + boundsFlags.set(1, f >= 1.0E-4F || f1 >= 1.0E-4F || f3 <= 0.9999F || f4 <= 0.9999F); + boundsFlags.set(0, (f5 > 0.9999F || blockIn.isFullCube()) && f2 == f5); + break; + + case WEST: + boundsFlags.set(1, f1 >= 1.0E-4F || f2 >= 1.0E-4F || f4 <= 0.9999F || f5 <= 0.9999F); + boundsFlags.set(0, (f < 1.0E-4F || blockIn.isFullCube()) && f == f3); + break; + + case EAST: + boundsFlags.set(1, f1 >= 1.0E-4F || f2 >= 1.0E-4F || f4 <= 0.9999F || f5 <= 0.9999F); + boundsFlags.set(0, (f3 > 0.9999F || blockIn.isFullCube()) && f == f3); + } + } + + private void renderModelStandardQuads(IWorldAccess blockAccessIn, Block blockIn, BlockPos blockPosIn, Facing faceIn, int brightnessIn, boolean ownBrightness, RenderBuffer worldRendererIn, List listQuadsIn, BitSet boundsFlags) + { + double d0 = (double)blockPosIn.getX(); + double d1 = (double)blockPosIn.getY(); + double d2 = (double)blockPosIn.getZ(); +// EnumOffsetType block$enumoffsettype = blockIn.getOffsetType(); +// +// if (block$enumoffsettype != EnumOffsetType.NONE) +// { +// int i = blockPosIn.getX(); +// int j = blockPosIn.getZ(); +// long k = (long)(i * 3129871) ^ (long)j * 116129781L; +// k = k * k * 42317861L + k * 11L; +// d0 += ((double)((float)(k >> 16 & 15L) / 15.0F) - 0.5D) * 0.5D; +// d2 += ((double)((float)(k >> 24 & 15L) / 15.0F) - 0.5D) * 0.5D; +// +// if (block$enumoffsettype == EnumOffsetType.XYZ) +// { +// d1 += ((double)((float)(k >> 20 & 15L) / 15.0F) - 1.0D) * 0.2D; +// } +// } + + for (BakedQuad bakedquad : listQuadsIn) + { + if (ownBrightness) + { + this.fillQuadBounds(blockIn, bakedquad.getVertexData(), bakedquad.getFace(), (float[])null, boundsFlags); + brightnessIn = boundsFlags.get(0) ? blockIn.getMixedBrightnessForBlock(blockAccessIn, blockPosIn.offset(bakedquad.getFace())) : blockIn.getMixedBrightnessForBlock(blockAccessIn, blockPosIn); + } + + worldRendererIn.addVertexData(bakedquad.getVertexData()); + worldRendererIn.putBrightness4(brightnessIn, brightnessIn, brightnessIn, brightnessIn); + + if (bakedquad.hasTintIndex()) + { + int l = blockIn.colorMultiplier(blockAccessIn, blockPosIn, bakedquad.getTintIndex()); + +// if (EntityRenderer.anaglyphEnable) +// { +// l = TextureUtil.anaglyphColor(l); +// } + + float f = (float)(l >> 16 & 255) / 255.0F; + float f1 = (float)(l >> 8 & 255) / 255.0F; + float f2 = (float)(l & 255) / 255.0F; + worldRendererIn.putColorMultiplier(f, f1, f2, 4); + worldRendererIn.putColorMultiplier(f, f1, f2, 3); + worldRendererIn.putColorMultiplier(f, f1, f2, 2); + worldRendererIn.putColorMultiplier(f, f1, f2, 1); + } + + worldRendererIn.putPosition(d0, d1, d2); + } + } + + public void renderModelBrightnessColor(IBakedModel bakedModel, float p_178262_2_, float red, float green, float blue) + { + for (Facing enumfacing : Facing.values()) + { + this.renderModelBrightnessColorQuads(p_178262_2_, red, green, blue, bakedModel.getFaceQuads(enumfacing)); + } + + this.renderModelBrightnessColorQuads(p_178262_2_, red, green, blue, bakedModel.getGeneralQuads()); + } + + private void renderModelBrightness(IBakedModel model, State p_178266_2_, float brightness, boolean p_178266_4_) + { + Block block = p_178266_2_.getBlock(); + block.setBlockBoundsForItemRender(); + GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); + int i = block.getRenderColor(block.getStateForEntityRender(p_178266_2_)); + +// if (EntityRenderer.anaglyphEnable) +// { +// i = TextureUtil.anaglyphColor(i); +// } + + float f = (float)(i >> 16 & 255) / 255.0F; + float f1 = (float)(i >> 8 & 255) / 255.0F; + float f2 = (float)(i & 255) / 255.0F; + + if (!p_178266_4_) + { + GlState.color(brightness, brightness, brightness, 1.0F); + } + + this.renderModelBrightnessColor(model, brightness, f, f1, f2); + } + + private void renderModelBrightnessColorQuads(float brightness, float red, float green, float blue, List listQuads) + { +// Tessellator tessellator = Tessellator.getInstance(); + RenderBuffer worldrenderer = Tessellator.getBuffer(); + + for (BakedQuad bakedquad : listQuads) + { + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM); + worldrenderer.addVertexData(bakedquad.getVertexData()); + + if (bakedquad.hasTintIndex()) + { + worldrenderer.putColorRGB_F4(red * brightness, green * brightness, blue * brightness); + } + else + { + worldrenderer.putColorRGB_F4(brightness, brightness, brightness); + } + + Vec3i vec3i = bakedquad.getFace().getDirectionVec(); + worldrenderer.putNormal((float)vec3i.getX(), (float)vec3i.getY(), (float)vec3i.getZ()); + Tessellator.draw(); + } + } + + private void initAtlasSprites() + { + TextureMap texturemap = Client.CLIENT.getTextureMapBlocks(); + for(int z = 0; z < FluidRegistry.getNumFluids(); z++) { + BlockLiquid block = FluidRegistry.getStaticBlock(z); + String name = BlockRegistry.REGISTRY.getNameForObject(block).toString(); + TextureAtlasSprite[] sprites = new TextureAtlasSprite[] {texturemap.getAtlasSprite("blocks/" + name + "_still"), texturemap.getAtlasSprite("blocks/" + name + "_flow")}; + this.fluids.put(FluidRegistry.getFluidBlock(z), sprites); + this.fluids.put(block, sprites); + } + } + + private boolean renderFluid(IWorldAccess blockAccess, State blockStateIn, BlockPos blockPosIn, RenderBuffer worldRendererIn) + { + BlockLiquid blockliquid = (BlockLiquid)blockStateIn.getBlock(); + blockliquid.setBlockBoundsBasedOnState(blockAccess, blockPosIn); + TextureAtlasSprite[] atextureatlassprite = this.fluids.get(blockliquid); + int i = blockliquid.colorMultiplier(blockAccess, blockPosIn); + float f = (float)(i >> 16 & 255) / 255.0F; + float f1 = (float)(i >> 8 & 255) / 255.0F; + float f2 = (float)(i & 255) / 255.0F; + boolean flag = blockliquid.shouldSideBeRendered(blockAccess, blockPosIn.up(), Facing.UP); + boolean flag1 = blockliquid.shouldSideBeRendered(blockAccess, blockPosIn.down(), Facing.DOWN); + boolean[] aboolean = new boolean[] {blockliquid.shouldSideBeRendered(blockAccess, blockPosIn.north(), Facing.NORTH), blockliquid.shouldSideBeRendered(blockAccess, blockPosIn.south(), Facing.SOUTH), blockliquid.shouldSideBeRendered(blockAccess, blockPosIn.west(), Facing.WEST), blockliquid.shouldSideBeRendered(blockAccess, blockPosIn.east(), Facing.EAST)}; + + if (!flag && !flag1 && !aboolean[0] && !aboolean[1] && !aboolean[2] && !aboolean[3]) + { + return false; + } + else + { + boolean flag2 = false; + float f3 = 0.5F; + float f4 = 1.0F; + float f5 = 0.8F; + float f6 = 0.6F; + Material material = blockliquid.getMaterial(); + float f7 = this.getFluidHeight(blockAccess, blockPosIn, material); + float f8 = this.getFluidHeight(blockAccess, blockPosIn.south(), material); + float f9 = this.getFluidHeight(blockAccess, blockPosIn.east().south(), material); + float f10 = this.getFluidHeight(blockAccess, blockPosIn.east(), material); + double d0 = (double)blockPosIn.getX(); + double d1 = (double)blockPosIn.getY(); + double d2 = (double)blockPosIn.getZ(); + float f11 = 0.001F; + + if (flag) + { + flag2 = true; + TextureAtlasSprite textureatlassprite = atextureatlassprite[0]; + float f12 = (float)BlockLiquid.getFlowDirection(blockAccess, blockPosIn, blockliquid); + + if (f12 > -999.0F) + { + textureatlassprite = atextureatlassprite[1]; + } + + f7 -= f11; + f8 -= f11; + f9 -= f11; + f10 -= f11; + float f13; + float f14; + float f15; + float f16; + float f17; + float f18; + float f19; + float f20; + + if (f12 < -999.0F) + { + f13 = textureatlassprite.getInterpolatedU(0.0D); + f17 = textureatlassprite.getInterpolatedV(0.0D); + f14 = f13; + f18 = textureatlassprite.getInterpolatedV(16.0D); + f15 = textureatlassprite.getInterpolatedU(16.0D); + f19 = f18; + f16 = f15; + f20 = f17; + } + else + { + float f21 = ExtMath.sin(f12) * 0.25F; + float f22 = ExtMath.cos(f12) * 0.25F; + float f23 = 8.0F; + f13 = textureatlassprite.getInterpolatedU((double)(8.0F + (-f22 - f21) * 16.0F)); + f17 = textureatlassprite.getInterpolatedV((double)(8.0F + (-f22 + f21) * 16.0F)); + f14 = textureatlassprite.getInterpolatedU((double)(8.0F + (-f22 + f21) * 16.0F)); + f18 = textureatlassprite.getInterpolatedV((double)(8.0F + (f22 + f21) * 16.0F)); + f15 = textureatlassprite.getInterpolatedU((double)(8.0F + (f22 + f21) * 16.0F)); + f19 = textureatlassprite.getInterpolatedV((double)(8.0F + (f22 - f21) * 16.0F)); + f16 = textureatlassprite.getInterpolatedU((double)(8.0F + (f22 - f21) * 16.0F)); + f20 = textureatlassprite.getInterpolatedV((double)(8.0F + (-f22 - f21) * 16.0F)); + } + + int k2 = blockliquid.getMixedBrightnessForBlock(blockAccess, blockPosIn); + int l2 = k2 >> 16 & 65535; + int i3 = k2 & 65535; + float f24 = f4 * f; + float f25 = f4 * f1; + float f26 = f4 * f2; + worldRendererIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).color(f24, f25, f26, 1.0F).tex((double)f13, (double)f17).lightmap(l2, i3).endVertex(); + worldRendererIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).color(f24, f25, f26, 1.0F).tex((double)f14, (double)f18).lightmap(l2, i3).endVertex(); + worldRendererIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).color(f24, f25, f26, 1.0F).tex((double)f15, (double)f19).lightmap(l2, i3).endVertex(); + worldRendererIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).color(f24, f25, f26, 1.0F).tex((double)f16, (double)f20).lightmap(l2, i3).endVertex(); + + if (blockliquid.shouldRenderSides(blockAccess, blockPosIn.up())) + { + worldRendererIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).color(f24, f25, f26, 1.0F).tex((double)f13, (double)f17).lightmap(l2, i3).endVertex(); + worldRendererIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).color(f24, f25, f26, 1.0F).tex((double)f16, (double)f20).lightmap(l2, i3).endVertex(); + worldRendererIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).color(f24, f25, f26, 1.0F).tex((double)f15, (double)f19).lightmap(l2, i3).endVertex(); + worldRendererIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).color(f24, f25, f26, 1.0F).tex((double)f14, (double)f18).lightmap(l2, i3).endVertex(); + } + } + + if (flag1) + { + float f35 = atextureatlassprite[0].getMinU(); + float f36 = atextureatlassprite[0].getMaxU(); + float f37 = atextureatlassprite[0].getMinV(); + float f38 = atextureatlassprite[0].getMaxV(); + int l1 = blockliquid.getMixedBrightnessForBlock(blockAccess, blockPosIn.down()); + int i2 = l1 >> 16 & 65535; + int j2 = l1 & 65535; + worldRendererIn.pos(d0, d1, d2 + 1.0D).color(f3, f3, f3, 1.0F).tex((double)f35, (double)f38).lightmap(i2, j2).endVertex(); + worldRendererIn.pos(d0, d1, d2).color(f3, f3, f3, 1.0F).tex((double)f35, (double)f37).lightmap(i2, j2).endVertex(); + worldRendererIn.pos(d0 + 1.0D, d1, d2).color(f3, f3, f3, 1.0F).tex((double)f36, (double)f37).lightmap(i2, j2).endVertex(); + worldRendererIn.pos(d0 + 1.0D, d1, d2 + 1.0D).color(f3, f3, f3, 1.0F).tex((double)f36, (double)f38).lightmap(i2, j2).endVertex(); + flag2 = true; + } + + for (int i1 = 0; i1 < 4; ++i1) + { + int j1 = 0; + int k1 = 0; + + if (i1 == 0) + { + --k1; + } + + if (i1 == 1) + { + ++k1; + } + + if (i1 == 2) + { + --j1; + } + + if (i1 == 3) + { + ++j1; + } + + BlockPos blockpos = blockPosIn.add(j1, 0, k1); + TextureAtlasSprite textureatlassprite1 = atextureatlassprite[1]; + + if (aboolean[i1]) + { + float f39; + float f40; + double d3; + double d4; + double d5; + double d6; + + if (i1 == 0) + { + f39 = f7; + f40 = f10; + d3 = d0; + d5 = d0 + 1.0D; + d4 = d2 + (double)f11; + d6 = d2 + (double)f11; + } + else if (i1 == 1) + { + f39 = f9; + f40 = f8; + d3 = d0 + 1.0D; + d5 = d0; + d4 = d2 + 1.0D - (double)f11; + d6 = d2 + 1.0D - (double)f11; + } + else if (i1 == 2) + { + f39 = f8; + f40 = f7; + d3 = d0 + (double)f11; + d5 = d0 + (double)f11; + d4 = d2 + 1.0D; + d6 = d2; + } + else + { + f39 = f10; + f40 = f9; + d3 = d0 + 1.0D - (double)f11; + d5 = d0 + 1.0D - (double)f11; + d4 = d2; + d6 = d2 + 1.0D; + } + + flag2 = true; + float f41 = textureatlassprite1.getInterpolatedU(0.0D); + float f27 = textureatlassprite1.getInterpolatedU(8.0D); + float f28 = textureatlassprite1.getInterpolatedV((double)((1.0F - f39) * 16.0F * 0.5F)); + float f29 = textureatlassprite1.getInterpolatedV((double)((1.0F - f40) * 16.0F * 0.5F)); + float f30 = textureatlassprite1.getInterpolatedV(8.0D); + int j = blockliquid.getMixedBrightnessForBlock(blockAccess, blockpos); + int k = j >> 16 & 65535; + int l = j & 65535; + float f31 = i1 < 2 ? f5 : f6; + float f32 = f4 * f31 * f; + float f33 = f4 * f31 * f1; + float f34 = f4 * f31 * f2; + worldRendererIn.pos(d3, d1 + (double)f39, d4).color(f32, f33, f34, 1.0F).tex((double)f41, (double)f28).lightmap(k, l).endVertex(); + worldRendererIn.pos(d5, d1 + (double)f40, d6).color(f32, f33, f34, 1.0F).tex((double)f27, (double)f29).lightmap(k, l).endVertex(); + worldRendererIn.pos(d5, d1 + 0.0D, d6).color(f32, f33, f34, 1.0F).tex((double)f27, (double)f30).lightmap(k, l).endVertex(); + worldRendererIn.pos(d3, d1 + 0.0D, d4).color(f32, f33, f34, 1.0F).tex((double)f41, (double)f30).lightmap(k, l).endVertex(); + worldRendererIn.pos(d3, d1 + 0.0D, d4).color(f32, f33, f34, 1.0F).tex((double)f41, (double)f30).lightmap(k, l).endVertex(); + worldRendererIn.pos(d5, d1 + 0.0D, d6).color(f32, f33, f34, 1.0F).tex((double)f27, (double)f30).lightmap(k, l).endVertex(); + worldRendererIn.pos(d5, d1 + (double)f40, d6).color(f32, f33, f34, 1.0F).tex((double)f27, (double)f29).lightmap(k, l).endVertex(); + worldRendererIn.pos(d3, d1 + (double)f39, d4).color(f32, f33, f34, 1.0F).tex((double)f41, (double)f28).lightmap(k, l).endVertex(); + } + } + + return flag2; + } + } + + private float getFluidHeight(IBlockAccess blockAccess, BlockPos blockPosIn, Material blockMaterial) + { + int i = 0; + float f = 0.0F; + + for (int j = 0; j < 4; ++j) + { + BlockPos blockpos = blockPosIn.add(-(j & 1), 0, -(j >> 1 & 1)); + + if (blockAccess.getState(blockpos.up()).getBlock().getMaterial() == blockMaterial) + { + return 1.0F; + } + + State iblockstate = blockAccess.getState(blockpos); + Material material = iblockstate.getBlock().getMaterial(); + + if (material != blockMaterial) + { + if (!material.isSolid()) + { + ++f; + ++i; + } + } + else + { + int k = ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue(); + + if (k >= 8 || k == 0) + { + f += BlockLiquid.getLiquidHeightPercent(k) * 10.0F; + i += 10; + } + + f += BlockLiquid.getLiquidHeightPercent(k); + ++i; + } + } + + return 1.0F - f / (float)i; + } +} diff --git a/client/src/main/java/client/renderer/DefaultVertexFormats.java b/client/src/client/renderer/DefaultVertexFormats.java similarity index 92% rename from client/src/main/java/client/renderer/DefaultVertexFormats.java rename to client/src/client/renderer/DefaultVertexFormats.java index 60ade6a6..ab287a52 100755 --- a/client/src/main/java/client/renderer/DefaultVertexFormats.java +++ b/client/src/client/renderer/DefaultVertexFormats.java @@ -12,6 +12,7 @@ public class DefaultVertexFormats public static final VertexFormat POSITION_NORMAL = new VertexFormat(); public static final VertexFormat POSITION_TEX_COLOR = new VertexFormat(); public static final VertexFormat POSITION_TEX_NORMAL = new VertexFormat(); +// public static final VertexFormat POSITION_TEX_LMAP_COLOR = new VertexFormat(); public static final VertexFormat POSITION_TEX_COLOR_NORMAL = new VertexFormat(); public static final VertexFormatElement POSITION_3F = new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.POSITION, 3); public static final VertexFormatElement COLOR_4UB = new VertexFormatElement(0, VertexFormatElement.EnumType.UBYTE, VertexFormatElement.EnumUsage.COLOR, 4); @@ -54,6 +55,10 @@ public class DefaultVertexFormats POSITION_TEX_NORMAL.addElement(TEX_2F); POSITION_TEX_NORMAL.addElement(NORMAL_3B); POSITION_TEX_NORMAL.addElement(PADDING_1B); +// POSITION_TEX_LMAP_COLOR.addElement(POSITION_3F); +// POSITION_TEX_LMAP_COLOR.addElement(TEX_2F); +// POSITION_TEX_LMAP_COLOR.addElement(TEX_2S); +// POSITION_TEX_LMAP_COLOR.addElement(COLOR_4UB); POSITION_TEX_COLOR_NORMAL.addElement(POSITION_3F); POSITION_TEX_COLOR_NORMAL.addElement(TEX_2F); POSITION_TEX_COLOR_NORMAL.addElement(COLOR_4UB); diff --git a/client/src/main/java/client/renderer/Drawing.java b/client/src/client/renderer/Drawing.java similarity index 76% rename from client/src/main/java/client/renderer/Drawing.java rename to client/src/client/renderer/Drawing.java index 0d44105a..16c99620 100644 --- a/client/src/main/java/client/renderer/Drawing.java +++ b/client/src/client/renderer/Drawing.java @@ -5,8 +5,8 @@ import org.lwjgl.opengl.GL11; import client.Client; import client.gui.Font; import client.gui.FontChar; +import common.color.TextColor; import common.log.Log; -import common.util.Color; import common.util.Util; public abstract class Drawing { @@ -28,6 +28,19 @@ public abstract class Drawing { this.offset = off; } } + +// public static void drawTexturedModalRect(int tw, int th, int x, int y, int textureX, int textureY, int width, int height) +// { +// float xs = 1.0f / (float)tw; // 0.00390625F; +// float ys = 1.0f / (float)th; // 0.00390625F; +// RenderBuffer rb = Tessellator.getBuffer(); +// rb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); +// rb.pos((double)(x + 0), (double)(y + height), 0.0).tex((double)((float)(textureX + 0) * xs), (double)((float)(textureY + height) * ys)).endVertex(); +// rb.pos((double)(x + width), (double)(y + height), 0.0).tex((double)((float)(textureX + width) * xs), (double)((float)(textureY + height) * ys)).endVertex(); +// rb.pos((double)(x + width), (double)(y + 0), 0.0).tex((double)((float)(textureX + width) * xs), (double)((float)(textureY + 0) * ys)).endVertex(); +// rb.pos((double)(x + 0), (double)(y + 0), 0.0).tex((double)((float)(textureX + 0) * xs), (double)((float)(textureY + 0) * ys)).endVertex(); +// Tessellator.draw(); +// } public static void txt_draw(int x, int y, int x1, int y1, int x2, int y2, int color, String str) { GlState.enableTexture2D(); @@ -39,7 +52,7 @@ public abstract class Drawing { Font.bindTexture(); RenderBuffer rb = Tessellator.getBuffer(); rb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); - int h = Font.HEIGHT; + int h = Font.YGLYPH; int tx, ty, u, v; FontChar glyph; char ch; @@ -52,7 +65,7 @@ public abstract class Drawing { continue; } else if((ch >= Log.CHR_COLORS1 && ch <= Log.CHR_COLORE1) || (ch >= Log.CHR_COLORS2 && ch <= Log.CHR_COLORE2)) { - ncolor = Color.getColor(ch) | (color & 0xff000000); + ncolor = TextColor.getColor(ch) | (color & 0xff000000); continue; } else if(ch == Log.CHR_CRESET) { @@ -75,7 +88,7 @@ public abstract class Drawing { if(x < x1 || y < y1 || x > x2 || y > y2) { break; } - putGlyph(rb, Font.WIDTH * 16, Font.HEIGHT * 16, x, y, (ch & 0x0f) * Font.WIDTH + glyph.s, ((ch & 0xf0) >> 4) * Font.HEIGHT, glyph.u, h, ncolor, 0.0); + putGlyph(rb, Font.XGLYPH * 16, Font.YGLYPH * 16, x, y, (ch & 0x0f) * Font.XGLYPH + glyph.s, ((ch & 0xf0) >> 4) * Font.YGLYPH, glyph.u, h, ncolor, 0.0); x += u; } Tessellator.draw(); @@ -86,7 +99,7 @@ public abstract class Drawing { } public static void txt_overlay(int start, int end, int x, int y, int x1, int y1, int x2, int y2, int back, String str) { - int h = Font.HEIGHT; + int h = Font.YGLYPH; int tx, ty, u, v; FontChar glyph; char ch; @@ -141,7 +154,7 @@ public abstract class Drawing { } public static Vec2i txt_size(int x, int y, int x1, int y1, int x2, int y2, String str) { - int h = Font.HEIGHT; + int h = Font.YGLYPH; int ix = x; int iy = y; int tx, ty, u, v; @@ -179,7 +192,7 @@ public abstract class Drawing { } public static Vec2i txt_coord(int offset, int x, int y, int x1, int y1, int x2, int y2, String str) { - int h = Font.HEIGHT; + int h = Font.YGLYPH; int tx, ty, u, v; FontChar glyph; char ch; @@ -223,7 +236,7 @@ public abstract class Drawing { } public static Offset txt_offset(int ox, int oy, int x, int y, int x1, int y1, int x2, int y2, String str) { - int h = Font.HEIGHT; + int h = Font.YGLYPH; int tx, ty, u, v; FontChar glyph; char ch; @@ -311,11 +324,11 @@ public abstract class Drawing { ch = str.charAt(z); if(ch == Log.CHR_NLN) { x = ox; - y += Font.HEIGHT; + y += Font.YGLYPH; continue; } else if((ch >= Log.CHR_COLORS1 && ch <= Log.CHR_COLORE1) || (ch >= Log.CHR_COLORS2 && ch <= Log.CHR_COLORE2)) { - bcolor = Color.getShadow(ch) | (scolor & 0xff000000); + bcolor = TextColor.getShadow(ch) | (scolor & 0xff000000); continue; } else if(ch == Log.CHR_CRESET) { @@ -329,7 +342,7 @@ public abstract class Drawing { continue; else if(glyph.u == 0) glyph = Font.SIZES[Log.CHR_UNK]; - putGlyph(rb, Font.WIDTH * 16, Font.HEIGHT * 16, x + 1, y + 1, (ch & 0x0f) * Font.WIDTH + glyph.s, ((ch & 0xf0) >> 4) * Font.HEIGHT, glyph.u, Font.HEIGHT, bcolor, -0.01); + putGlyph(rb, Font.XGLYPH * 16, Font.YGLYPH * 16, x + 1, y + 1, (ch & 0x0f) * Font.XGLYPH + glyph.s, ((ch & 0xf0) >> 4) * Font.YGLYPH, glyph.u, Font.YGLYPH, bcolor, -0.01); x += glyph.u + 3 - glyph.s; } x = ox; @@ -339,11 +352,11 @@ public abstract class Drawing { ch = str.charAt(z); if(ch == Log.CHR_NLN) { x = ox; - y += Font.HEIGHT; + y += Font.YGLYPH; continue; } else if((ch >= Log.CHR_COLORS1 && ch <= Log.CHR_COLORE1) || (ch >= Log.CHR_COLORS2 && ch <= Log.CHR_COLORE2)) { - ncolor = Color.getColor(ch) | (color & 0xff000000); + ncolor = TextColor.getColor(ch) | (color & 0xff000000); continue; } else if(ch == Log.CHR_CRESET) { @@ -357,7 +370,7 @@ public abstract class Drawing { continue; else if(glyph.u == 0) glyph = Font.SIZES[Log.CHR_UNK]; - putGlyph(rb, Font.WIDTH * 16, Font.HEIGHT * 16, x, y, (ch & 0x0f) * Font.WIDTH + glyph.s, ((ch & 0xf0) >> 4) * Font.HEIGHT, glyph.u, Font.HEIGHT, ncolor, -0.02); + putGlyph(rb, Font.XGLYPH * 16, Font.YGLYPH * 16, x, y, (ch & 0x0f) * Font.XGLYPH + glyph.s, ((ch & 0xf0) >> 4) * Font.YGLYPH, glyph.u, Font.YGLYPH, ncolor, -0.02); x += glyph.u + 3 - glyph.s; } Tessellator.draw(); @@ -378,7 +391,7 @@ public abstract class Drawing { if(ch == Log.CHR_NLN) { ix = x > ix ? x : ix; x = 0; - y += Font.HEIGHT; + y += Font.YGLYPH; continue; } else if(ch < Log.CHR_SPC) { @@ -394,7 +407,7 @@ public abstract class Drawing { x += glyph.u + 3 - glyph.s; ix = x > ix ? x : ix; } - return new Vec2i(ix - 3, y + Font.HEIGHT); + return new Vec2i(ix - 3, y + Font.YGLYPH); } @@ -484,39 +497,6 @@ public abstract class Drawing { drawGradient(x + 2, y + 2, w - 4, h - 4, top, bottom); } - public static void drawRect(int x, int y, int w, int h, int color, int topleft, int btmright) { - int corner = Util.mixColor(topleft, btmright); - drawRect(x, y, w - 1, 1, topleft); - drawRect(x, y + 1, 1, h - 1, topleft); - drawRect(x + w - 1, y, 1, 1, corner); - drawRect(x, y + h - 1, 1, 1, corner); - drawRect(x + w - 1, y + 1, 1, h - 1, btmright); - drawRect(x + 1, y + h - 1, w - 2, 1, btmright); - drawRect(x + 1, y + 1, w - 2, h - 2, color); - } - - public static void drawDoubleRect(int x, int y, int w, int h, int color, int topleft, int btmright) { - int corner = Util.mixColor(topleft, btmright); - drawRect(x, y, w - 2, 2, topleft); - drawRect(x, y + 2, 2, h - 2, topleft); - drawRect(x + w - 2, y, 2, 2, corner); - drawRect(x, y + h - 2, 2, 2, corner); - drawRect(x + w - 2, y + 2, 2, h - 2, btmright); - drawRect(x + 2, y + h - 2, w - 4, 2, btmright); - drawRect(x + 2, y + 2, w - 4, h - 4, color); - } - - public static void drawGradient(int x, int y, int w, int h, int top, int bottom, int topleft, int btmright) { - int corner = Util.mixColor(topleft, btmright); - drawRect(x, y, w - 1, 1, topleft); - drawRect(x, y + 1, 1, h - 1, topleft); - drawRect(x + w - 1, y, 1, 1, corner); - drawRect(x, y + h - 1, 1, 1, corner); - drawRect(x + w - 1, y + 1, 1, h - 1, btmright); - drawRect(x + 1, y + h - 1, w - 2, 1, btmright); - drawGradient(x + 1, y + 1, w - 2, h - 2, top, bottom); - } - public static int getWidth(String str) { return getSize(str).xpos; } @@ -527,8 +507,8 @@ public abstract class Drawing { public static void drawTextbox(String str, int x, int y, int back) { Vec2i size = getSize(str); - drawRect(x, y, size.xpos + 4, size.ypos + 2, back); - drawText(str, x + 2, y + 1, 0xffffffff); + drawRect(x, y, size.xpos + 4, size.ypos, back); + drawText(str, x + 2, y, 0xffffffff); } public static void drawTextboxRight(String str, int x, int y, int back) { @@ -564,49 +544,28 @@ public abstract class Drawing { } public static void drawScaled(Client gm, String texture) { - drawScaled(gm, texture, 0, 0, gm.fbX, gm.fbY, 0xffffffff); + drawScaled(gm, texture, 0, 0, gm.fb_x, gm.fb_y); } - public static void drawScaled(Client gm, String texture, int x, int y, int width, int height, int color) { + public static void drawScaled(Client gm, String texture, double x, double y, double width, double height) { GlState.enableTexture2D(); GlState.disableLighting(); GlState.disableFog(); RenderBuffer buf = Tessellator.getBuffer(); gm.getTextureManager().bindTexture(texture); - GlState.color(color); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); double scale = 32.0; - buf.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); - buf.pos((double)x, (double)y + (double)height, 0.0D).tex(0.0D, (double)height / scale).endVertex(); - buf.pos((double)x + (double)width, (double)y + (double)height, 0.0D).tex((double)width / scale, (double)height / scale).endVertex(); - buf.pos((double)x + (double)width, (double)y, 0.0D).tex((double)width / scale, 0.0).endVertex(); - buf.pos((double)x, (double)y, 0.0D).tex(0.0D, 0.0).endVertex(); + buf.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + buf.pos(x, y + height, 0.0D).tex(0.0D, height / scale) + .color(64, 64, 64, 255).endVertex(); + buf.pos(x + width, y + height, 0.0D) + .tex(width / scale, height / scale) + .color(64, 64, 64, 255).endVertex(); + buf.pos(x + width, y, 0.0D).tex(width / scale, 0.0) + .color(64, 64, 64, 255).endVertex(); + buf.pos(x, y, 0.0D).tex(0.0D, 0.0) + .color(64, 64, 64, 255).endVertex(); Tessellator.draw(); GlState.disableTexture2D(); - GlState.color(1.0F, 1.0F, 1.0F, 1.0F); } - - public static void drawTexturedRect(Client gm, String texture, int texWidth, int texHeight, int x, int y, int u, int v, int width, int height) - { - GlState.enableTexture2D(); -// GlState.disableFog(); - RenderBuffer buf = Tessellator.getBuffer(); - gm.getTextureManager().bindTexture(texture); -// GlState.color(color); - float xs = 1.0f / (float)texWidth; // 0.00390625F; - float ys = 1.0f / (float)texHeight; // 0.00390625F; - buf.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); - buf.pos((double)(x + 0), (double)(y + height), 0.0).tex((double)((float)(u + 0) * xs), (double)((float)(v + height) * ys)).endVertex(); - buf.pos((double)(x + width), (double)(y + height), 0.0).tex((double)((float)(u + width) * xs), (double)((float)(v + height) * ys)).endVertex(); - buf.pos((double)(x + width), (double)(y + 0), 0.0).tex((double)((float)(u + width) * xs), (double)((float)(v + 0) * ys)).endVertex(); - buf.pos((double)(x + 0), (double)(y + 0), 0.0).tex((double)((float)(u + 0) * xs), (double)((float)(v + 0) * ys)).endVertex(); -// double scale = 32.0; -// buf.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); -// buf.pos((double)x, (double)y + (double)height, 0.0D).tex(0.0D, (double)height / scale).endVertex(); -// buf.pos((double)x + (double)width, (double)y + (double)height, 0.0D).tex((double)width / scale, (double)height / scale).endVertex(); -// buf.pos((double)x + (double)width, (double)y, 0.0D).tex((double)width / scale, 0.0).endVertex(); -// buf.pos((double)x, (double)y, 0.0D).tex(0.0D, 0.0).endVertex(); - Tessellator.draw(); -// GlState.disableTexture2D(); - GlState.color(1.0F, 1.0F, 1.0F, 1.0F); - } } diff --git a/client/src/client/renderer/EntityRenderer.java b/client/src/client/renderer/EntityRenderer.java new file mode 100755 index 00000000..36a30027 --- /dev/null +++ b/client/src/client/renderer/EntityRenderer.java @@ -0,0 +1,1703 @@ +package client.renderer; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; +import java.util.List; +import java.util.function.Predicate; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL13; + +import client.Client; +import client.renderer.particle.EffectRenderer; +import client.renderer.texture.DynamicTexture; +import client.renderer.texture.TextureMap; +import client.world.WorldClient; +import common.block.Block; +import common.entity.Entity; +import common.entity.npc.EntityNPC; +import common.entity.types.EntityAnimal; +import common.entity.types.EntityLiving; +import common.init.Items; +import common.init.SoundEvent; +import common.material.Material; +import common.model.BlockLayer; +import common.model.ParticleType; +import common.potion.Potion; +import common.rng.Random; +import common.util.BlockPos; +import common.util.BoundingBox; +import common.util.ExtMath; +import common.util.HitPosition; +import common.util.Vec3; +import common.world.World; + +public class EntityRenderer { + private static final String locationMoltenPng = "textures/world/molten.png"; + private static final String locationRainPng = "textures/world/rain.png"; + private static final String locationHailPng = "textures/world/hail.png"; + private static final String locationSnowPng = "textures/world/snow.png"; + private static final String locationLightMap = "dynamic/lightmap"; + private static final float FOG_DENSITY = 0.05f; + private static final float FOG_DISTANCE = 0.4f; + private static final float SQRT_2 = ExtMath.sqrtf(2.0F); + + private Client gm; + private Random random = new Random(); + private float farPlaneDistance; + public final ItemRenderer itemRenderer; + private int rendererUpdateCount; + private Entity pointedEntity; + private float thirdPersonDistance = 4.0F; + private float thirdPersonDistanceTemp = 4.0F; + private float fovModifierHand; + private float fovModifierHandPrev; + private final DynamicTexture lightmapTexture; + private final int[] lightmapColors; + private boolean lightmapUpdateNeeded; + private float torchFlickerX; + private float torchFlickerDX; + private int rainSoundCounter; + private float[] rainXCoords = new float[1024]; + private float[] rainYCoords = new float[1024]; + private FloatBuffer fogColorBuffer = ByteBuffer.allocateDirect(16 << 2).order(ByteOrder.nativeOrder()).asFloatBuffer(); + private float fogColorRed; + private float fogColorGreen; + private float fogColorBlue; + private float lastFogMult; + private float fogMult; + private double cameraYaw; + private double cameraPitch; + private int frameCount; + + public EntityRenderer(Client gmIn) + { + this.frameCount = 0; + this.gm = gmIn; + this.itemRenderer = gmIn.getItemRenderer(); + this.lightmapTexture = new DynamicTexture(16, 16); + gmIn.getTextureManager().loadTexture(locationLightMap, this.lightmapTexture); + this.lightmapColors = this.lightmapTexture.getTextureData(); + + for (int i = 0; i < 32; ++i) + { + for (int j = 0; j < 32; ++j) + { + float f = (float)(j - 16); + float f1 = (float)(i - 16); + float f2 = ExtMath.sqrtf(f * f + f1 * f1); + this.rainXCoords[i << 5 | j] = -f1 / f2; + this.rainYCoords[i << 5 | j] = f / f2; + } + } + } + + /** + * Updates the entity renderer + */ + public void updateRenderer() + { +// if (/* OpenGl.SHADERS_SUPPORTED && */ ShaderLinkHelper.getStaticShaderLinkHelper() == null) +// { +// ShaderLinkHelper.setNewStaticShaderLinkHelper(); +// } + + this.updateFovModifierHand(); + this.updateTorchFlicker(); + this.lastFogMult = this.fogMult; + this.thirdPersonDistanceTemp = this.thirdPersonDistance; + +// if (this.gm.smoothCamera) +// { +// float f = this.gm.mouseSensitivity * 0.6F + 0.2F; +// float f1 = f * f * f * 8.0F; +// this.smoothCamFilterX = this.mouseFilterXAxis.smooth(this.smoothCamYaw, 0.05F * f1); +// this.smoothCamFilterY = this.mouseFilterYAxis.smooth(this.smoothCamPitch, 0.05F * f1); +// this.smoothCamPartialTicks = 0.0F; +// this.smoothCamYaw = 0.0F; +// this.smoothCamPitch = 0.0F; +// } +// else +// { +// this.smoothCamFilterX = 0.0F; +// this.smoothCamFilterY = 0.0F; +// this.mouseFilterXAxis.reset(); +// this.mouseFilterYAxis.reset(); +// } + + if (this.gm.getRenderViewEntity() == null) + { + this.gm.setRenderViewEntity(this.gm.player); + } + + float light = this.gm.world.getLightBrightness(new BlockPos(this.gm.getRenderViewEntity())); +// Log.info(String.format("%.3f", light)); + float dist = (float)this.gm.renderDistance / 32.0F; + float shift = light * (1.0F - dist) + dist; + this.fogMult += (shift - this.fogMult) * 0.1F; + ++this.rendererUpdateCount; + this.itemRenderer.updateEquippedItem(); + this.addRainParticles(); +// this.bossColorModifierPrev = this.bossColorModifier; +// +// if (BossStatus.hasColorModifier) +// { +// this.bossColorModifier += 0.05F; +// +// if (this.bossColorModifier > 1.0F) +// { +// this.bossColorModifier = 1.0F; +// } +// +// BossStatus.hasColorModifier = false; +// } +// else if (this.bossColorModifier > 0.0F) +// { +// this.bossColorModifier -= 0.0125F; +// } + } + +// public ShaderGroup getShaderGroup() +// { +// return this.theShaderGroup; +// } + +// public void updateShaderGroupSize(int width, int height) +// { +//// if (OpenGl.SHADERS_SUPPORTED) +//// { +//// if (this.theShaderGroup != null) +//// { +//// this.theShaderGroup.createBindFramebuffers(width, height); +//// } +// +// this.gm.renderGlobal.createBindEntityOutlineFbs(width, height); +//// } +// } + + /** + * Finds what block or object the mouse is over at the specified partial tick time. Args: partialTickTime + */ + public void getMouseOver(float partialTicks) + { + Entity entity = this.gm.getRenderViewEntity(); + + if (entity != null) + { + if (this.gm.world != null) + { + this.gm.setPointedEntity(null); + double max = this.gm.player != null ? this.gm.player.getReachDistance() : 5.0; + this.gm.pointed = entity.rayTrace(max, partialTicks); + double dist = max; + Vec3 eye = entity.getPositionEyes(partialTicks); +// boolean far = false; + int i = 3; + +// if (this.gm.controller.extendedReach()) +// { + max += 1.0D; + dist += 1.0D; +// } +// else +// { +// if (max > 3.0D) +// { +// far = true; +// } +// } + + if (this.gm.pointed != null) + { + dist = this.gm.pointed.vec.distanceTo(eye); + } + + Vec3 look = entity.getLook(partialTicks); + Vec3 eyelook = eye.addVector(look.xCoord * max, look.yCoord * max, look.zCoord * max); + this.pointedEntity = null; + Vec3 hit = null; + float exp = 1.0F; + List list = this.gm.world.getEntitiesInAABBexcluding(entity, entity.getEntityBoundingBox().addCoord(look.xCoord * max, look.yCoord * max, look.zCoord * max).expand((double)exp, (double)exp, (double)exp), new Predicate() + { + public boolean test(Entity p_apply_1_) + { + return p_apply_1_.canBeCollidedWith(); + } + }); + double edist = dist; + + for (int j = 0; j < list.size(); ++j) + { + Entity entity1 = (Entity)list.get(j); + float f1 = entity1.getCollisionBorderSize(); + BoundingBox axisalignedbb = entity1.getEntityBoundingBox().expand((double)f1, (double)f1, (double)f1); + HitPosition objpos = axisalignedbb.calculateIntercept(eye, eyelook); + + if (axisalignedbb.isVecInside(eye)) + { + if (edist >= 0.0D) + { + this.pointedEntity = entity1; + hit = objpos == null ? eye : objpos.vec; + edist = 0.0D; + } + } + else if (objpos != null) + { + double eyehit = eye.distanceTo(objpos.vec); + + if (eyehit < edist || edist == 0.0D) + { + if (entity1 == entity.vehicle) + { + if (edist == 0.0D) + { + this.pointedEntity = entity1; + hit = objpos.vec; + } + } + else + { + this.pointedEntity = entity1; + hit = objpos.vec; + edist = eyehit; + } + } + } + } + +// if (this.pointedEntity != null && far && eye.distanceTo(hit) > 3.0D) +// { +// this.pointedEntity = null; +// this.gm.pointed = new MovingObjectPosition(MovingObjectPosition.MovingObjectType.MISS, hit, (EnumFacing)null, new BlockPos(hit)); +// } + + if (this.pointedEntity != null && (edist < dist || this.gm.pointed == null)) + { + this.gm.pointed = new HitPosition(this.pointedEntity, hit); + + if (this.pointedEntity instanceof EntityLiving) // || this.pointedEntity instanceof EntityFrame) + { + this.gm.setPointedEntity(this.pointedEntity); + } + } + } + } + } + + /** + * Update FOV modifier hand + */ + private void updateFovModifierHand() + { + float f = 1.0F; + + if (this.gm.getRenderViewEntity() != null && this.gm.getRenderViewEntity().isPlayer()) + { + EntityNPC player = (EntityNPC)this.gm.getRenderViewEntity(); + f = getFovModifier(player); + } + + this.fovModifierHandPrev = this.fovModifierHand; + this.fovModifierHand += (f - this.fovModifierHand) * 0.5F; + + if (this.fovModifierHand > 1.5F) + { + this.fovModifierHand = 1.5F; + } + + if (this.fovModifierHand < 0.1F) + { + this.fovModifierHand = 0.1F; + } + } + + private static float getFovModifier(EntityNPC player) + { + float f = 1.0F; + +// if (player.flying) +// { +// f *= 1.1F; +// } + +// AttributeInstance iattributeinstance = player.getEntityAttribute(Attributes.MOVEMENT_SPEED); +// f = (float)((double)f * ((iattributeinstance.getAttributeValue() / 0.1D + 1.0D) / 2.0D)); + +// if (Float.isNaN(f) || Float.isInfinite(f)) +// { +// f = 1.0F; +// } + + if (player.isUsingItem() && player.getItemInUse().getItem() == Items.bow) + { + int i = player.getItemInUseDuration(); + float f1 = (float)i / 20.0F; + + if (f1 > 1.0F) + { + f1 = 1.0F; + } + else + { + f1 = f1 * f1; + } + + f *= 1.0F - f1 * 0.15F; + } + + return f; + } + + /** + * Changes the field of view of the player depending on if they are underwater or not + * + * @param useFOVSetting If true the FOV set in the settings will be use in the calculation + */ + private float getFOVModifier(float partialTicks, boolean useFOVSetting) + { +// if (this.debugView) +// { +// return 90.0F; +// } +// else +// { + Entity entity = this.gm.getRenderViewEntity(); + float f = 70.0F; + + if (useFOVSetting) + { + f = this.gm.fov; + if(this.gm.zooming) { + f /= this.gm.zoomLevel; + } + f = f * (this.fovModifierHandPrev + (this.fovModifierHand - this.fovModifierHandPrev) * partialTicks); + } + + if (entity instanceof EntityLiving && ((EntityLiving)entity).getHealth() <= 0) + { + float f1 = (float)((EntityLiving)entity).deathTime + partialTicks; + f /= (1.0F - 500.0F / (f1 + 500.0F)) * 2.0F + 1.0F; + } + +// Block block = ActiveRenderInfo.getBlockAtEntityViewpoint(this.gm.theWorld, entity, partialTicks); +// +// if (block.getMaterial().isColdLiquid()) +// { +// f = f * 60.0F / 70.0F; +// } + + return f; +// } + } + + private void hurtCameraEffect(float partialTicks) + { + if (this.gm.getRenderViewEntity() instanceof EntityLiving) + { + EntityLiving entitylivingbase = (EntityLiving)this.gm.getRenderViewEntity(); + float f = (float)entitylivingbase.hurtTime - partialTicks; + + if (entitylivingbase.getHealth() <= 0) + { + float f1 = (float)entitylivingbase.deathTime + partialTicks; + GL11.glRotatef(40.0F - 8000.0F / (f1 + 200.0F), 0.0F, 0.0F, 1.0F); + } + + if (f < 0.0F || entitylivingbase.hasEffect(Potion.STABILITY)) + { + return; + } + + f = f / (float)entitylivingbase.maxHurtTime; + f = ExtMath.sin(f * f * f * f * (float)Math.PI); + float f2 = entitylivingbase.attackedYaw; + GL11.glRotatef(-f2, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(-f * 14.0F, 0.0F, 0.0F, 1.0F); + GL11.glRotatef(f2, 0.0F, 1.0F, 0.0F); + } + } + + /** + * Setups all the GL settings for view bobbing. Args: partialTickTime + */ + private void setupViewBobbing(float partialTicks) + { + if (this.gm.getRenderViewEntity() != null && this.gm.getRenderViewEntity().isPlayer()) + { + EntityNPC entityplayer = (EntityNPC)this.gm.getRenderViewEntity(); + float f = entityplayer.walkDistMod - entityplayer.prevWalkDistMod; + float f1 = -(entityplayer.walkDistMod + f * partialTicks); + float f2 = entityplayer.prevCameraYaw + (entityplayer.cameraYaw - entityplayer.prevCameraYaw) * partialTicks; + float f3 = entityplayer.prevCamPitch + (entityplayer.camPitch - entityplayer.prevCamPitch) * partialTicks; + GL11.glTranslatef(ExtMath.sin(f1 * (float)Math.PI) * f2 * 0.5F, -Math.abs(ExtMath.cos(f1 * (float)Math.PI) * f2), 0.0F); + GL11.glRotatef(ExtMath.sin(f1 * (float)Math.PI) * f2 * 3.0F, 0.0F, 0.0F, 1.0F); + GL11.glRotatef(Math.abs(ExtMath.cos(f1 * (float)Math.PI - 0.2F) * f2) * 5.0F, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(f3, 1.0F, 0.0F, 0.0F); + } + } + + /** + * sets up player's eye (or camera in third person mode) + */ + private void orientCamera(float partialTicks) + { + Entity entity = this.gm.getRenderViewEntity(); + float f = entity.getEyeHeight(); + double d0 = entity.prevX + (entity.posX - entity.prevX) * (double)partialTicks; + double d1 = entity.prevY + (entity.posY - entity.prevY) * (double)partialTicks + (double)f; + double d2 = entity.prevZ + (entity.posZ - entity.prevZ) * (double)partialTicks; + +// if (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).isPlayerSleeping()) +// { +// f = (float)((double)f + 1.0D); +// SKC.glTranslatef(0.0F, 0.3F, 0.0F); +// +// if (!this.gm.debugCamEnable) +// { +// BlockPos blockpos = new BlockPos(entity); +// IBlockState iblockstate = this.gm.theWorld.getBlockState(blockpos); +// Block block = iblockstate.getBlock(); +// +// if (block instanceof BlockBed) +// { +// int j = ((EnumFacing)iblockstate.getValue(BlockBed.FACING)).getHorizontalIndex(); +// SKC.glRotatef((float)(j * 90), 0.0F, 1.0F, 0.0F); +// } +// +// SKC.glRotatef(entity.prevYaw + (entity.rotYaw - entity.prevYaw) * partialTicks + 180.0F, 0.0F, -1.0F, 0.0F); +// SKC.glRotatef(entity.prevPitch + (entity.rotPitch - entity.prevPitch) * partialTicks, -1.0F, 0.0F, 0.0F); +// } +// } +// else + if (this.gm.thirdPersonView > 0) + { + double d3 = (double)(this.thirdPersonDistanceTemp + (this.thirdPersonDistance - this.thirdPersonDistanceTemp) * partialTicks); + + if (this.gm.debugCamEnable) + { + GL11.glTranslatef(0.0F, 0.0F, (float)(-d3)); + } + else + { + float f1 = entity.rotYaw; + float f2 = entity.rotPitch; + + if (this.gm.thirdPersonView == 2) + { + f2 += 180.0F; + } + + double d4 = (double)(-ExtMath.sin(f1 / 180.0F * (float)Math.PI) * ExtMath.cos(f2 / 180.0F * (float)Math.PI)) * d3; + double d5 = (double)(ExtMath.cos(f1 / 180.0F * (float)Math.PI) * ExtMath.cos(f2 / 180.0F * (float)Math.PI)) * d3; + double d6 = (double)(-ExtMath.sin(f2 / 180.0F * (float)Math.PI)) * d3; + + for (int i = 0; i < 8; ++i) + { + float f3 = (float)((i & 1) * 2 - 1); + float f4 = (float)((i >> 1 & 1) * 2 - 1); + float f5 = (float)((i >> 2 & 1) * 2 - 1); + f3 = f3 * 0.1F; + f4 = f4 * 0.1F; + f5 = f5 * 0.1F; + HitPosition movingobjectposition = this.gm.world.rayTraceBlocks(new Vec3(d0 + (double)f3, d1 + (double)f4, d2 + (double)f5), new Vec3(d0 - d4 + (double)f3 + (double)f5, d1 - d6 + (double)f4, d2 - d5 + (double)f5)); + + if (movingobjectposition != null) + { + double d7 = movingobjectposition.vec.distanceTo(new Vec3(d0, d1, d2)); + + if (d7 < d3) + { + d3 = d7; + } + } + } + + if (this.gm.thirdPersonView == 2) + { + GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F); + } + + GL11.glRotatef(entity.rotPitch - f2, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(entity.rotYaw - f1, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(0.0F, 0.0F, (float)(-d3)); + GL11.glRotatef(f1 - entity.rotYaw, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(f2 - entity.rotPitch, 1.0F, 0.0F, 0.0F); + } + } + else + { + GL11.glTranslatef(0.0F, 0.0F, -0.1F); + } + + if (!this.gm.debugCamEnable || this.gm.thirdPersonView == 0) + { + GL11.glRotatef(entity.prevPitch + (entity.rotPitch - entity.prevPitch) * partialTicks, 1.0F, 0.0F, 0.0F); + + if (entity instanceof EntityAnimal) + { + EntityAnimal entityanimal = (EntityAnimal)entity; + GL11.glRotatef(entityanimal.prevHeadYaw + (entityanimal.headYaw - entityanimal.prevHeadYaw) * partialTicks + 180.0F, 0.0F, 1.0F, 0.0F); + } + else + { + GL11.glRotatef(entity.prevYaw + (entity.rotYaw - entity.prevYaw) * partialTicks + 180.0F, 0.0F, 1.0F, 0.0F); + } + } + + GL11.glTranslatef(0.0F, -f, 0.0F); + d0 = entity.prevX + (entity.posX - entity.prevX) * (double)partialTicks; + d1 = entity.prevY + (entity.posY - entity.prevY) * (double)partialTicks + (double)f; + d2 = entity.prevZ + (entity.posZ - entity.prevZ) * (double)partialTicks; +// this.cloudFog = this.gm.renderGlobal.hasCloudFog(d0, d1, d2, partialTicks); + } + + public void rotateCamera(Entity entity, float partialTicks) { + GL11.glRotatef(360.0f - (entity.prevPitch + (entity.rotPitch - entity.prevPitch) * partialTicks), 1.0F, 0.0F, 0.0F); + + if (entity instanceof EntityAnimal) + { + EntityAnimal entityanimal = (EntityAnimal)entity; + GL11.glRotatef(entityanimal.prevHeadYaw + (entityanimal.headYaw - entityanimal.prevHeadYaw) * partialTicks + 180.0F, 0.0F, 1.0F, 0.0F); + } + else + { + GL11.glRotatef(entity.prevYaw + (entity.rotYaw - entity.prevYaw) * partialTicks + 180.0F, 0.0F, 1.0F, 0.0F); + } + } + + /** + * sets up projection, view effects, camera position/rotation + */ + private void setupCameraTransform(float partialTicks) + { + this.farPlaneDistance = (float)(this.gm.renderDistance * 16); + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glLoadIdentity(); + float f = 0.07F; + +// if (this.gm.anaglyph) +// { +// SKC.glTranslatef((float)(-(pass * 2 - 1)) * f, 0.0F, 0.0F); +// } + +// if (this.cameraZoom != 1.0D) +// { +// SKC.glTranslatef((float)this.cameraYaw, (float)(-this.cameraPitch), 0.0F); +// SKC.glScaled(this.cameraZoom, this.cameraZoom, 1.0D); +// } + + Project.gluPerspective(this.getFOVModifier(partialTicks, true), (float)this.gm.fb_x / (float)this.gm.fb_y, 0.05F, this.farPlaneDistance * SQRT_2); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glLoadIdentity(); + +// if (this.gm.anaglyph) +// { +// SKC.glTranslatef((float)(pass * 2 - 1) * 0.1F, 0.0F, 0.0F); +// } + + this.hurtCameraEffect(partialTicks); + +// if (this.gm.viewBobbing) +// { + this.setupViewBobbing(partialTicks); +// } + +// float f1 = this.gm.thePlayer.prevNausea + (this.gm.thePlayer.nausea - this.gm.thePlayer.prevNausea) * partialTicks; +// +// if (f1 > 0.0F) +// { +// int i = 7; +// +//// if (this.gm.thePlayer.hasEffect(Potion.confusion)) +//// { +//// i = 7; +//// } +// +// float f2 = 5.0F / (f1 * f1 + 5.0F) - f1 * 0.04F; +// f2 = f2 * f2; +// SKC.glRotatef(((float)this.rendererUpdateCount + partialTicks) * (float)i, 0.0F, 1.0F, 1.0F); +// SKC.glScalef(1.0F / f2, 1.0F, 1.0F); +// SKC.glRotatef(-((float)this.rendererUpdateCount + partialTicks) * (float)i, 0.0F, 1.0F, 1.0F); +// } + + this.orientCamera(partialTicks); + +// if (this.debugView) +// { +// switch (this.debugViewDirection) +// { +// case 0: +// SKC.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); +// break; +// +// case 1: +// SKC.glRotatef(180.0F, 0.0F, 1.0F, 0.0F); +// break; +// +// case 2: +// SKC.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F); +// break; +// +// case 3: +// SKC.glRotatef(90.0F, 1.0F, 0.0F, 0.0F); +// break; +// +// case 4: +// SKC.glRotatef(-90.0F, 1.0F, 0.0F, 0.0F); +// } +// } + } + + /** + * Render player hand + */ + private void renderHand(float partialTicks) + { +// if (!this.debugView) +// { + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glLoadIdentity(); + float f = 0.07F; + +// if (this.gm.anaglyph) +// { +// SKC.glTranslatef((float)(-(xOffset * 2 - 1)) * f, 0.0F, 0.0F); +// } + + Project.gluPerspective(this.getFOVModifier(partialTicks, false), (float)this.gm.fb_x / (float)this.gm.fb_y, 0.05F, this.farPlaneDistance * 2.0F); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glLoadIdentity(); + +// if (this.gm.anaglyph) +// { +// SKC.glTranslatef((float)(xOffset * 2 - 1) * 0.1F, 0.0F, 0.0F); +// } + + GL11.glPushMatrix(); + this.hurtCameraEffect(partialTicks); + +// if (this.gm.viewBobbing) +// { + this.setupViewBobbing(partialTicks); +// } + +// boolean flag = this.gm.getRenderViewEntity() instanceof EntityLivingBase && ((EntityLivingBase)this.gm.getRenderViewEntity()).isPlayerSleeping(); + + if (this.gm.thirdPersonView == 0) // && /* !flag && */ !this.gm.hideGUI) // && !this.gm.controller.isSpectator()) + { + this.enableLightmap(); + this.itemRenderer.renderItemInFirstPerson(partialTicks); + this.disableLightmap(); + } + + GL11.glPopMatrix(); + + if (this.gm.thirdPersonView == 0) // && !flag) + { + this.itemRenderer.renderOverlays(partialTicks); + this.hurtCameraEffect(partialTicks); + } + +// if (this.gm.viewBobbing) +// { + this.setupViewBobbing(partialTicks); +// } +// } + } + + public void disableLightmap() + { + GlState.setActiveTexture(GL13.GL_TEXTURE1); + GlState.disableTexture2D(); + GlState.setActiveTexture(GL13.GL_TEXTURE0); + } + + public void enableLightmap() + { + GlState.setActiveTexture(GL13.GL_TEXTURE1); + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glLoadIdentity(); + float f = 0.00390625F; + GL11.glScalef(f, f, f); + GL11.glTranslatef(8.0F, 8.0F, 8.0F); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + this.gm.getTextureManager().bindTexture(locationLightMap); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + GlState.enableTexture2D(); + GlState.setActiveTexture(GL13.GL_TEXTURE0); + } + + /** + * Recompute a random value that is applied to block color in updateLightmap() + */ + private void updateTorchFlicker() + { + this.torchFlickerDX = (float)((double)this.torchFlickerDX + (Math.random() - Math.random()) * Math.random() * Math.random()); + this.torchFlickerDX = (float)((double)this.torchFlickerDX * 0.9D); + this.torchFlickerX += (this.torchFlickerDX - this.torchFlickerX) * 1.0F; + this.lightmapUpdateNeeded = true; + } + + private void updateLightmap(float partialTicks) + { + if (this.lightmapUpdateNeeded) + { + WorldClient world = this.gm.world; + + if (world != null) + { + float sun = world.getSunBrightness(1.0F); + float msun = sun * 0.95F + 0.05F; + + for (int n = 0; n < 256; ++n) + { + float sky = World.BRIGHTNESS[world.dimension.getBrightness()][n / 16] * msun; + float block = World.BRIGHTNESS[world.dimension.getBrightness()][n % 16] * (this.torchFlickerX * 0.1F + 1.5F); + + if (world.getLastLightning() > 0) + { + sky = World.BRIGHTNESS[world.dimension.getBrightness()][n / 16]; + } + + float sred = sky * (sun * 0.65F + 0.35F); + float sgreen = sky * (sun * 0.65F + 0.35F); + float bgreen = block * ((block * 0.6F + 0.4F) * 0.6F + 0.4F); + float bblue = block * (block * block * 0.6F + 0.4F); + float red = sred + block; + float green = sgreen + bgreen; + float blue = sky + bblue; + red = red * 0.96F + 0.03F; + green = green * 0.96F + 0.03F; + blue = blue * 0.96F + 0.03F; + +// if (this.bossColorModifier > 0.0F) +// { +// float f11 = this.bossColorModifierPrev + (this.bossColorModifier - this.bossColorModifierPrev) * partialTicks; +// f8 = f8 * (1.0F - f11) + f8 * 0.7F * f11; +// f9 = f9 * (1.0F - f11) + f9 * 0.6F * f11; +// f10 = f10 * (1.0F - f11) + f10 * 0.6F * f11; +// } + +// if (world.dimension.getDimensionId() == 1) +// { +// f8 = 0.22F + f3 * 0.75F; +// f9 = 0.28F + f6 * 0.75F; +// f10 = 0.25F + f7 * 0.75F; +// } + + if (this.gm.player.hasEffect(Potion.NIGHT_VISION)) + { + float vis = this.getNightVisionBrightness(this.gm.player, partialTicks); + float mult = 1.0F / red; + + if (mult > 1.0F / green) + { + mult = 1.0F / green; + } + + if (mult > 1.0F / blue) + { + mult = 1.0F / blue; + } + + red = red * (1.0F - vis) + red * mult * vis; + green = green * (1.0F - vis) + green * mult * vis; + blue = blue * (1.0F - vis) + blue * mult * vis; + } + + if (red > 1.0F) + { + red = 1.0F; + } + + if (green > 1.0F) + { + green = 1.0F; + } + + if (blue > 1.0F) + { + blue = 1.0F; + } + + float bright = this.gm.setGamma || this.gm.xrayActive ? 100.0f : 0.1f; + float ri = 1.0F - red; + float gi = 1.0F - green; + float bi = 1.0F - blue; + ri = 1.0F - ri * ri * ri * ri; + gi = 1.0F - gi * gi * gi * gi; + bi = 1.0F - bi * bi * bi * bi; + red = red * (1.0F - bright) + ri * bright; + green = green * (1.0F - bright) + gi * bright; + blue = blue * (1.0F - bright) + bi * bright; + red = red * 0.96F + 0.03F; + green = green * 0.96F + 0.03F; + blue = blue * 0.96F + 0.03F; + + if (red > 1.0F) + { + red = 1.0F; + } + + if (green > 1.0F) + { + green = 1.0F; + } + + if (blue > 1.0F) + { + blue = 1.0F; + } + + if (red < 0.0F) + { + red = 0.0F; + } + + if (green < 0.0F) + { + green = 0.0F; + } + + if (blue < 0.0F) + { + blue = 0.0F; + } + + int a = 255; + int r = (int)(red * 255.0F); + int g = (int)(green * 255.0F); + int b = (int)(blue * 255.0F); + this.lightmapColors[n] = a << 24 | r << 16 | g << 8 | b; + } + + this.lightmapTexture.updateDynamicTexture(); + this.lightmapUpdateNeeded = false; + } + } + } + + private float getNightVisionBrightness(EntityLiving entitylivingbaseIn, float partialTicks) + { + int i = entitylivingbaseIn.getEffect(Potion.NIGHT_VISION).getRemaining(); + return i > 200 ? 1.0F : 0.7F + ExtMath.sin(((float)i - partialTicks) * (float)Math.PI * 0.2F) * 0.3F; + } + +// public void updateCameraAndRender(float partialTicks, long nanoTime) +// { +// if (this.gm.theWorld != null) +// { +// this.renderWorld(partialTicks, ); + +// this.renderEndNanoTime = System.nanoTime(); +// if (!this.gm.hideGUI || this.gm.openGui != null) +// { +// this.gm.ingameGui.renderGameOverlay(partialTicks); +// } +// } +// else +// { +// SKC.glMatrixMode(5889); +// SKC.glLoadIdentity(); +// SKC.glMatrixMode(5888); +// SKC.glLoadIdentity(); +// this.setupOverlayRendering(); +// this.renderEndNanoTime = System.nanoTime(); +// } +// } + +// public void renderMainOverlay(float partialTicks) +// { +// this.setupOverlayRendering(); +// +// } + + public void renderWorld(float partialTicks, long finishTimeNano) + { + finishTimeNano = System.nanoTime() + Math.max((long)this.gm.maxBuildTime * 1000000L - finishTimeNano, 0L); + this.updateLightmap(partialTicks); + + if (this.gm.getRenderViewEntity() == null) + { + this.gm.setRenderViewEntity(this.gm.player); + } + + this.getMouseOver(partialTicks); + GlState.enableDepth(); + GlState.enableAlpha(); + GlState.alphaFunc(GL11.GL_GREATER, 0.5F); + +// if (this.gm.anaglyph) +// { +// anaglyphField = 0; +// GlState.colorMask(false, true, true, false); +// this.renderWorldPass(0, partialTicks, finishTimeNano); +// anaglyphField = 1; +// GlState.colorMask(true, false, false, false); +// this.renderWorldPass(1, partialTicks, finishTimeNano); +// GlState.colorMask(true, true, true, false); +// } +// else +// { +// this.renderWorldPass(partialTicks, finishTimeNano); +// } +// +// private void renderWorldPass(float partialTicks, long finishTimeNano) +// { + RenderGlobal renderglobal = this.gm.renderGlobal; + EffectRenderer effectrenderer = this.gm.effectRenderer; + boolean flag = this.gm.getRenderViewEntity() != null && this.gm.getRenderViewEntity().isPlayer(); + GlState.enableCull(); + this.updateFogColor(partialTicks); + GL11.glClear(16640); + this.setupCameraTransform(partialTicks); + ActiveRenderInfo.updateRenderInfo(this.gm.player, this.gm.thirdPersonView == 2); + Entity entity = this.gm.getRenderViewEntity(); + double d0 = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double)partialTicks; + double d1 = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)partialTicks; + double d2 = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double)partialTicks; + Frustum.setPosition(d0, d1, d2); + if (this.gm.renderDistance >= 4) + { + this.setupFog(-1, partialTicks); + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glLoadIdentity(); + Project.gluPerspective(this.getFOVModifier(partialTicks, true), (float)this.gm.fb_x / (float)this.gm.fb_y, 0.05F, this.farPlaneDistance * 2.0F); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + renderglobal.renderSky(partialTicks); + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glLoadIdentity(); + Project.gluPerspective(this.getFOVModifier(partialTicks, true), (float)this.gm.fb_x / (float)this.gm.fb_y, 0.05F, this.farPlaneDistance * SQRT_2); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + } + + this.setupFog(0, partialTicks); + GlState.shadeModel(GL11.GL_SMOOTH); + + if (entity.posY + (double)entity.getEyeHeight() < (double)this.gm.world.dimension.getCloudHeight()) + { + this.renderCloudsCheck(renderglobal, partialTicks); + } + this.setupFog(0, partialTicks); + this.gm.getTextureManager().bindTexture(TextureMap.locationBlocksTexture); + ItemRenderer.disableStandardItemLighting(); + renderglobal.setupTerrain(entity, (double)partialTicks, this.frameCount++, this.gm.player.noclip); + this.gm.renderGlobal.updateChunks(finishTimeNano); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glPushMatrix(); + GlState.disableAlpha(); + renderglobal.renderBlockLayer(BlockLayer.SOLID, (double)partialTicks, entity); + GlState.enableAlpha(); + renderglobal.renderBlockLayer(BlockLayer.CUTOUT_MIPPED, (double)partialTicks, entity); +// this.gm.getTextureManager().getTexture(TextureMap.locationBlocksTexture).unsetMipmap(); + renderglobal.renderBlockLayer(BlockLayer.CUTOUT, (double)partialTicks, entity); +// this.gm.getTextureManager().getTexture(TextureMap.locationBlocksTexture).restoreLastMipmap(); + GlState.shadeModel(GL11.GL_FLAT); + GlState.alphaFunc(GL11.GL_GREATER, 0.1F); + +// if (!this.debugView) +// { + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glPopMatrix(); + GL11.glPushMatrix(); + ItemRenderer.enableStandardItemLighting(); + renderglobal.renderEntities(entity, partialTicks); + ItemRenderer.disableStandardItemLighting(); + this.disableLightmap(); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glPopMatrix(); + GL11.glPushMatrix(); + + if (this.gm.pointed != null && entity.isInsideOfLiquid() && flag) + { + EntityNPC entityplayer = (EntityNPC)entity; + GlState.disableAlpha(); + renderglobal.drawSelectionBox(entityplayer, this.gm.pointed, partialTicks); + GlState.enableAlpha(); + } +// } + + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glPopMatrix(); + + if (flag && this.gm.pointed != null && !entity.isInsideOfLiquid()) + { + EntityNPC entityplayer1 = (EntityNPC)entity; + GlState.disableAlpha(); + renderglobal.drawSelectionBox(entityplayer1, this.gm.pointed, partialTicks); + GlState.enableAlpha(); + } + GlState.enableBlend(); + GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE, GL11.GL_ZERO); +// this.gm.getTextureManager().getTexture(TextureMap.locationBlocksTexture).unsetMipmap(); +// Tessellator.getInstance(); + renderglobal.drawBlockDamageTexture(Tessellator.getBuffer(), entity, partialTicks); +// this.gm.getTextureManager().getTexture(TextureMap.locationBlocksTexture).restoreLastMipmap(); + GlState.disableBlend(); + +// if (!this.debugView) +// { + this.enableLightmap(); + effectrenderer.renderLitParticles(entity, partialTicks); + ItemRenderer.disableStandardItemLighting(); + this.setupFog(0, partialTicks); + effectrenderer.renderParticles(entity, partialTicks); + this.disableLightmap(); +// } + + GlState.depthMask(false); + GlState.enableCull(); + this.renderRainSnow(partialTicks); + GlState.depthMask(true); +// renderglobal.renderWorldBorder(entity, partialTicks); + GlState.disableBlend(); + GlState.enableCull(); + GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); + GlState.alphaFunc(GL11.GL_GREATER, 0.1F); + this.setupFog(0, partialTicks); + GlState.enableBlend(); + GlState.depthMask(false); + this.gm.getTextureManager().bindTexture(TextureMap.locationBlocksTexture); + GlState.shadeModel(GL11.GL_SMOOTH); + renderglobal.renderBlockLayer(BlockLayer.TRANSLUCENT, (double)partialTicks, entity); + GlState.shadeModel(GL11.GL_FLAT); + GlState.depthMask(true); + GlState.enableCull(); + GlState.disableBlend(); + GlState.disableFog(); + + if (entity.posY + (double)entity.getEyeHeight() >= (double)this.gm.world.dimension.getCloudHeight()) + { + this.renderCloudsCheck(renderglobal, partialTicks); + } + +// if (this.renderHand) +// { + GL11.glClear(256); + this.renderHand(partialTicks); +// } + } + + private void renderCloudsCheck(RenderGlobal renderGlobalIn, float partialTicks) + { + if (this.gm.renderDistance >= 4) + { + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glLoadIdentity(); + Project.gluPerspective(this.getFOVModifier(partialTicks, true), (float)this.gm.fb_x / (float)this.gm.fb_y, 0.05F, this.farPlaneDistance * 4.0F); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glPushMatrix(); + this.setupFog(0, partialTicks); +// renderGlobalIn.renderClouds(partialTicks); + if(this.gm.world.dimension.getType().clouds) + renderGlobalIn.renderClouds(partialTicks); + GlState.disableFog(); + GL11.glPopMatrix(); + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glLoadIdentity(); + Project.gluPerspective(this.getFOVModifier(partialTicks, true), (float)this.gm.fb_x / (float)this.gm.fb_y, 0.05F, this.farPlaneDistance * SQRT_2); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + } + } + + private void addRainParticles() + { + float f = this.gm.world.getRainStrength(); + +// if (this.gm.downfallSetting != 0) +// { +// f /= 2.0F; +// } + + if (f != 0.0F) // && this.gm.downfallSetting < 2) + { + this.random.setSeed((long)this.rendererUpdateCount * 312987231L); + Entity entity = this.gm.getRenderViewEntity(); + World world = this.gm.world; + BlockPos blockpos = new BlockPos(entity); + int i = 10; + double d0 = 0.0D; + double d1 = 0.0D; + double d2 = 0.0D; + int j = 0; + int n = 0; + int k = (int)(100.0F * f * f); + +// if (this.gm.particleSetting == 1) +// { +// k >>= 1; +// } +// else if (this.gm.particleSetting == 2) +// { +// k = 0; +// } + +// boolean hail = !world.getWeather().isWet() && world.getWeather().hasDownfall(); + + for (int l = 0; l < k; ++l) + { + BlockPos blockpos1 = world.getPrecipitationHeight(blockpos.add(this.random.zrange(i) - this.random.zrange(i), 0, this.random.zrange(i) - this.random.zrange(i)), blockpos.getY() + 48, 64); + BlockPos blockpos2 = blockpos1.down(); + Block block = world.getState(blockpos2).getBlock(); + float temp = 10.0f; // world.getTemperatureC(blockpos1); TODO: fix particles + + if (blockpos1.getY() <= blockpos.getY() + i && blockpos1.getY() >= blockpos.getY() - i && /* biomegenbase.canRain() && */ temp > 0.0F) + { + double d3 = this.random.doublev(); + double d4 = this.random.doublev(); + + if (temp >= 194.0f || block.getMaterial() == Material.lava) + { + if(temp >= 194.0f) { + ++n; + if (this.random.zrange(n) == 0) + { + d0 = (double)blockpos2.getX() + d3; + d1 = (double)((float)blockpos2.getY() + 0.1F) + block.getBlockBoundsMaxY() - 1.0D; + d2 = (double)blockpos2.getZ() + d4; + } + } + if(temp < 194.0f || this.random.chance(5)) + this.gm.world.spawnParticle(temp >= 194.0f && this.random.chance(10) ? ParticleType.LAVA : ParticleType.SMOKE_NORMAL, (double)blockpos1.getX() + d3, (double)((float)blockpos1.getY() + 0.1F) - block.getBlockBoundsMinY(), (double)blockpos1.getZ() + d4, 0.0D, 0.0D, 0.0D); + } + else if (block.getMaterial() != Material.air) + { + block.setBlockBoundsBasedOnState(world, blockpos2); + ++j; + + if (this.random.zrange(j) == 0) + { + d0 = (double)blockpos2.getX() + d3; + d1 = (double)((float)blockpos2.getY() + 0.1F) + block.getBlockBoundsMaxY() - 1.0D; + d2 = (double)blockpos2.getZ() + d4; + } + + this.gm.world.spawnParticle(temp <= 5.0f ? ParticleType.HAIL_CORN : ParticleType.WATER_DROP, (double)blockpos2.getX() + d3, (double)((float)blockpos2.getY() + 0.1F) + block.getBlockBoundsMaxY(), (double)blockpos2.getZ() + d4, 0.0D, 0.0D, 0.0D); + } + } + } + + if ((j > 0 || n > 0) && this.random.zrange(3) < this.rainSoundCounter++) + { + this.rainSoundCounter = 0; + + if (d1 > (double)(blockpos.getY() + 1) && world.getPrecipitationHeight(blockpos, blockpos.getY() + 46, 48).getY() > ExtMath.floorf((float)blockpos.getY())) + { + this.gm.world.playSound(d0, d1, d2, n >= j ? this.pickMoltenSound() : SoundEvent.RAIN, n >= j ? 0.2f : 0.1F); + } + else + { + this.gm.world.playSound(d0, d1, d2, n >= j ? this.pickMoltenSound() : SoundEvent.RAIN, n >= j ? 0.4f : 0.2F); + } + } + } + } + + private SoundEvent pickMoltenSound() { + return this.random.chance(28) ? this.random.pick(SoundEvent.MOLTEN, SoundEvent.MOLTEN_POP) : SoundEvent.FIRE; + } + + /** + * Render rain and snow + */ + protected void renderRainSnow(float partialTicks) + { + float f = this.gm.world.getRainStrength(); + + if (f > 0.0F) // && this.gm.downfallSetting < 2) + { + this.enableLightmap(); + Entity entity = this.gm.getRenderViewEntity(); + World world = this.gm.world; + int i = ExtMath.floord(entity.posX); + int j = ExtMath.floord(entity.posY); + int k = ExtMath.floord(entity.posZ); +// Tessellator tessellator = Tessellator.getInstance(); + RenderBuffer worldrenderer = Tessellator.getBuffer(); + GlState.disableCull(); + GL11.glNormal3f(0.0F, 1.0F, 0.0F); + GlState.enableBlend(); + GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); + GlState.alphaFunc(GL11.GL_GREATER, 0.1F); + double d0 = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double)partialTicks; + double d1 = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)partialTicks; + double d2 = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double)partialTicks; + int l = ExtMath.floord(d1); + int i1 = 10; + +// if (this.gm.downfallSetting == 0) +// { +// i1 *= 2; +// } + + int mode = -1; + float f1 = (float)this.rendererUpdateCount + partialTicks; + worldrenderer.setTranslation(-d0, -d1, -d2); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); +// boolean hail = !world.getWeather().isWet() && world.getWeather().hasDownfall(); + + for (int k1 = k - i1; k1 <= k + i1; ++k1) + { + for (int l1 = i - i1; l1 <= i + i1; ++l1) + { + int i2 = (k1 - k + 16) * 32 + l1 - i + 16; + double d3 = (double)this.rainXCoords[i2] * 0.5D; + double d4 = (double)this.rainYCoords[i2] * 0.5D; + blockpos$mutableblockpos.set(l1, 0, k1); + +// if (biomegenbase.canRain() || biomegenbase.isSnowyBiome()) +// { + int j2 = world.getPrecipitationHeight(blockpos$mutableblockpos, ExtMath.floord(d1) + 48, 64).getY(); + int k2 = j - i1; + int l2 = j + i1; + + if (k2 < j2) + { + k2 = j2; + } + + if (l2 < j2) + { + l2 = j2; + } + + int i3 = j2; + + if (j2 < l) + { + i3 = l; + } + + if (k2 != l2) + { + this.random.setSeed((long)(l1 * l1 * 3121 + l1 * 45238971 ^ k1 * k1 * 418711 + k1 * 13761)); + blockpos$mutableblockpos.set(l1, k2, k1); + float f2 = 10.0f; // world.getTemperatureC(blockpos$mutableblockpos); TODO: fix particles + + if(f2 >= 194.0f) + { + if (mode != 2) + { + if (mode >= 0) + { + Tessellator.draw(); + } + + mode = 2; + this.gm.getTextureManager().bindTexture(locationMoltenPng); + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP); + } + + double d5 = ((double)(this.rendererUpdateCount + l1 * l1 * 3121 + l1 * 45238971 + k1 * k1 * 418711 + k1 * 13761 & 63) + (double)partialTicks) / 64.0D * (3.0D + this.random.doublev()); + double d6 = (double)((float)l1 + 0.5F) - entity.posX; + double d7 = (double)((float)k1 + 0.5F) - entity.posZ; + float f3 = ExtMath.sqrtd(d6 * d6 + d7 * d7) / (float)i1; + float f4 = ((1.0F - f3 * f3) * 0.5F + 0.5F) * f; + blockpos$mutableblockpos.set(l1, i3, k1); + int j3 = world.getCombinedLight(blockpos$mutableblockpos, 15); + int k3 = j3 >> 16 & 65535; + int l3 = j3 & 65535; + worldrenderer.pos((double)l1 - d3 + 0.5D, (double)k2, (double)k1 - d4 + 0.5D).tex(0.0D, (double)k2 * 0.25D + d5).color(1.0F, 1.0F, 1.0F, f4).lightmap(k3, l3).endVertex(); + worldrenderer.pos((double)l1 + d3 + 0.5D, (double)k2, (double)k1 + d4 + 0.5D).tex(1.0D, (double)k2 * 0.25D + d5).color(1.0F, 1.0F, 1.0F, f4).lightmap(k3, l3).endVertex(); + worldrenderer.pos((double)l1 + d3 + 0.5D, (double)l2, (double)k1 + d4 + 0.5D).tex(1.0D, (double)l2 * 0.25D + d5).color(1.0F, 1.0F, 1.0F, f4).lightmap(k3, l3).endVertex(); + worldrenderer.pos((double)l1 - d3 + 0.5D, (double)l2, (double)k1 - d4 + 0.5D).tex(0.0D, (double)l2 * 0.25D + d5).color(1.0F, 1.0F, 1.0F, f4).lightmap(k3, l3).endVertex(); + } + else if (/* world.getBiomeGenerator().getTemperatureAtHeight( */ f2 /* , j2) */ > 0.0F) + { + if (mode != 0) + { + if (mode >= 0) + { + Tessellator.draw(); + } + + mode = 0; + this.gm.getTextureManager().bindTexture(f2 <= 5.0f ? locationHailPng : locationRainPng); + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP); + } + + double d5 = ((double)(this.rendererUpdateCount + l1 * l1 * 3121 + l1 * 45238971 + k1 * k1 * 418711 + k1 * 13761 & 31) + (double)partialTicks) / 32.0D * (3.0D + this.random.doublev()); + double d6 = (double)((float)l1 + 0.5F) - entity.posX; + double d7 = (double)((float)k1 + 0.5F) - entity.posZ; + float f3 = ExtMath.sqrtd(d6 * d6 + d7 * d7) / (float)i1; + float f4 = ((1.0F - f3 * f3) * 0.5F + 0.5F) * f; + blockpos$mutableblockpos.set(l1, i3, k1); + int j3 = world.getCombinedLight(blockpos$mutableblockpos, 0); + int k3 = j3 >> 16 & 65535; + int l3 = j3 & 65535; + worldrenderer.pos((double)l1 - d3 + 0.5D, (double)k2, (double)k1 - d4 + 0.5D).tex(0.0D, (double)k2 * 0.25D + d5).color(1.0F, 1.0F, 1.0F, f4).lightmap(k3, l3).endVertex(); + worldrenderer.pos((double)l1 + d3 + 0.5D, (double)k2, (double)k1 + d4 + 0.5D).tex(1.0D, (double)k2 * 0.25D + d5).color(1.0F, 1.0F, 1.0F, f4).lightmap(k3, l3).endVertex(); + worldrenderer.pos((double)l1 + d3 + 0.5D, (double)l2, (double)k1 + d4 + 0.5D).tex(1.0D, (double)l2 * 0.25D + d5).color(1.0F, 1.0F, 1.0F, f4).lightmap(k3, l3).endVertex(); + worldrenderer.pos((double)l1 - d3 + 0.5D, (double)l2, (double)k1 - d4 + 0.5D).tex(0.0D, (double)l2 * 0.25D + d5).color(1.0F, 1.0F, 1.0F, f4).lightmap(k3, l3).endVertex(); + } + else + { + if (mode != 1) + { + if (mode >= 0) + { + Tessellator.draw(); + } + + mode = 1; + this.gm.getTextureManager().bindTexture(locationSnowPng); + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP); + } + + double d8 = (double)(((float)(this.rendererUpdateCount & 511) + partialTicks) / 512.0F); + double d9 = this.random.doublev() + (double)f1 * 0.01D * (double)((float)this.random.gaussian()); + double d10 = this.random.doublev() + (double)(f1 * (float)this.random.gaussian()) * 0.001D; + double d11 = (double)((float)l1 + 0.5F) - entity.posX; + double d12 = (double)((float)k1 + 0.5F) - entity.posZ; + float f6 = ExtMath.sqrtd(d11 * d11 + d12 * d12) / (float)i1; + float f5 = ((1.0F - f6 * f6) * 0.3F + 0.5F) * f; + blockpos$mutableblockpos.set(l1, i3, k1); + int i4 = (world.getCombinedLight(blockpos$mutableblockpos, 0) * 3 + 15728880) / 4; + int j4 = i4 >> 16 & 65535; + int k4 = i4 & 65535; + worldrenderer.pos((double)l1 - d3 + 0.5D, (double)k2, (double)k1 - d4 + 0.5D).tex(0.0D + d9, (double)k2 * 0.25D + d8 + d10).color(1.0F, 1.0F, 1.0F, f5).lightmap(j4, k4).endVertex(); + worldrenderer.pos((double)l1 + d3 + 0.5D, (double)k2, (double)k1 + d4 + 0.5D).tex(1.0D + d9, (double)k2 * 0.25D + d8 + d10).color(1.0F, 1.0F, 1.0F, f5).lightmap(j4, k4).endVertex(); + worldrenderer.pos((double)l1 + d3 + 0.5D, (double)l2, (double)k1 + d4 + 0.5D).tex(1.0D + d9, (double)l2 * 0.25D + d8 + d10).color(1.0F, 1.0F, 1.0F, f5).lightmap(j4, k4).endVertex(); + worldrenderer.pos((double)l1 - d3 + 0.5D, (double)l2, (double)k1 - d4 + 0.5D).tex(0.0D + d9, (double)l2 * 0.25D + d8 + d10).color(1.0F, 1.0F, 1.0F, f5).lightmap(j4, k4).endVertex(); + } + } +// } + } + } + + if (mode >= 0) + { + Tessellator.draw(); + } + + worldrenderer.setTranslation(0.0D, 0.0D, 0.0D); + GlState.enableCull(); + GlState.disableBlend(); + GlState.alphaFunc(GL11.GL_GREATER, 0.1F); + this.disableLightmap(); + } + } + + /** + * Setup orthogonal projection for rendering GUI screen overlays + */ +// public void setupOverlayRendering() +// { +//// Scaler scaledresolution = new Scaler(this.gm); +// } + +// /** +// * Returns a double value representing the Y value relative to the top of the +// * map at which void fog is at its maximum. The default factor of 0.03125 +// * relative to 256, for example, means the void fog will be at its maximum at +// * (256*0.03125), or 8. +// */ +// public double getVoidFogYFactor() { +// return 1.0D; // 0.03125D * 2.5D / (((double)this.worldObj.getSeaLevel() + 1) / 64.0); +// } + + /** + * calculates fog and calls glClearColor + */ + private void updateFogColor(float partial) + { + WorldClient world = this.gm.world; + Entity entity = this.gm.getRenderViewEntity(); + float dist = 0.25F + 0.75F * (float)this.gm.renderDistance / 32.0F; + dist = 1.0F - (float)Math.pow((double)dist, 0.25D); + Vec3 sky = world.getSkyColor(this.gm.getRenderViewEntity(), partial); + float sr = (float)sky.xCoord; + float sg = (float)sky.yCoord; + float sb = (float)sky.zCoord; + Vec3 fog = world.getFogColor(this.gm.getRenderViewEntity(), partial); + this.fogColorRed = (float)fog.xCoord; + this.fogColorGreen = (float)fog.yCoord; + this.fogColorBlue = (float)fog.zCoord; + + if (this.gm.renderDistance >= 4) + { + double neg = -1.0D; + Vec3 pos = ExtMath.sin(world.getCelestialAngleRadians(partial)) > 0.0F ? new Vec3(neg, 0.0D, 0.0D) : new Vec3(1.0D, 0.0D, 0.0D); + float shift = (float)entity.getLook(partial).dotProduct(pos); + + if (shift < 0.0F) + { + shift = 0.0F; + } + + if (shift > 0.0F) + { + float[] sun = world.dimension.getType().days ? + RenderGlobal.calcSunriseSunsetColors(world.getCelestialAngle(partial), partial) : null; + if (sun != null) + { + shift = shift * sun[3]; + this.fogColorRed = this.fogColorRed * (1.0F - shift) + sun[0] * shift; + this.fogColorGreen = this.fogColorGreen * (1.0F - shift) + sun[1] * shift; + this.fogColorBlue = this.fogColorBlue * (1.0F - shift) + sun[2] * shift; + } + } + } + + this.fogColorRed += (sr - this.fogColorRed) * dist; + this.fogColorGreen += (sg - this.fogColorGreen) * dist; + this.fogColorBlue += (sb - this.fogColorBlue) * dist; + float rain = world.getRainStrength(); + + if (rain > 0.0F) + { + float rg = 1.0F - rain * 0.5F; + float b = 1.0F - rain * 0.4F; + this.fogColorRed *= rg; + this.fogColorGreen *= rg; + this.fogColorBlue *= b; + } + + float dark = world.getDarkness(); + + if (dark > 0.0F) + { + float mul = 1.0F - dark * 0.5F; + this.fogColorRed *= mul; + this.fogColorGreen *= mul; + this.fogColorBlue *= mul; + } + + Block block = ActiveRenderInfo.getBlockAtEntityViewpoint(this.gm.world, entity, partial); + +// if (this.cloudFog) +// { +// Vec3 cloud = world.getCloudColour(this.gm.getRenderViewEntity(), partial); +// this.fogColorRed = (float)cloud.xCoord; +// this.fogColorGreen = (float)cloud.yCoord; +// this.fogColorBlue = (float)cloud.zCoord; +// } +// else + if (block.getMaterial().isColdLiquid()) + { + float cn = 0.4f; // (float)EnchantmentHelper.getRespiration(entity) * 0.2F; + +// if (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).hasEffect(Potion.waterBreathing)) +// { +// f12 = f12 * 0.3F + 0.6F; +// } + + this.fogColorRed = 0.02F + cn; + this.fogColorGreen = 0.02F + cn; + this.fogColorBlue = 0.2F + cn; + } + else if (block.getMaterial().isHotLiquid()) + { + this.fogColorRed = 0.6F; + this.fogColorGreen = 0.1F; + this.fogColorBlue = 0.0F; + } + + float mult = this.lastFogMult + (this.fogMult - this.lastFogMult) * partial; + this.fogColorRed *= mult; + this.fogColorGreen *= mult; + this.fogColorBlue *= mult; + double vfog = (entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)partial); // * world.dimension.getVoidFogYFactor(); + + if (entity instanceof EntityLiving && ((EntityLiving)entity).hasEffect(Potion.BLINDNESS)) + { + int blind = ((EntityLiving)entity).getEffect(Potion.BLINDNESS).getRemaining(); + + if (blind < 20) + { + vfog *= (double)(1.0F - (float)blind / 20.0F); + } + else + { + vfog = 0.0D; + } + } + + if (vfog < 1.0D) + { + if (vfog < 0.0D) + { + vfog = 0.0D; + } + + vfog = vfog * vfog; + this.fogColorRed = (float)((double)this.fogColorRed * vfog); + this.fogColorGreen = (float)((double)this.fogColorGreen * vfog); + this.fogColorBlue = (float)((double)this.fogColorBlue * vfog); + } + +// if (this.bossColorModifier > 0.0F) +// { +// float shift = this.bossColorModifierPrev + (this.bossColorModifier - this.bossColorModifierPrev) * partial; +// this.fogColorRed = this.fogColorRed * (1.0F - shift) + this.fogColorRed * 0.7F * shift; +// this.fogColorGreen = this.fogColorGreen * (1.0F - shift) + this.fogColorGreen * 0.6F * shift; +// this.fogColorBlue = this.fogColorBlue * (1.0F - shift) + this.fogColorBlue * 0.6F * shift; +// } + + if (entity instanceof EntityLiving && ((EntityLiving)entity).hasEffect(Potion.NIGHT_VISION)) + { + float vis = this.getNightVisionBrightness((EntityLiving)entity, partial); + float mul = 1.0F / this.fogColorRed; + + if (mul > 1.0F / this.fogColorGreen) + { + mul = 1.0F / this.fogColorGreen; + } + + if (mul > 1.0F / this.fogColorBlue) + { + mul = 1.0F / this.fogColorBlue; + } + + this.fogColorRed = this.fogColorRed * (1.0F - vis) + this.fogColorRed * mul * vis; + this.fogColorGreen = this.fogColorGreen * (1.0F - vis) + this.fogColorGreen * mul * vis; + this.fogColorBlue = this.fogColorBlue * (1.0F - vis) + this.fogColorBlue * mul * vis; + } + +// if (this.gm.anaglyph) +// { +// float f16 = (this.fogColorRed * 30.0F + this.fogColorGreen * 59.0F + this.fogColorBlue * 11.0F) / 100.0F; +// float f17 = (this.fogColorRed * 30.0F + this.fogColorGreen * 70.0F) / 100.0F; +// float f7 = (this.fogColorRed * 30.0F + this.fogColorBlue * 70.0F) / 100.0F; +// this.fogColorRed = f16; +// this.fogColorGreen = f17; +// this.fogColorBlue = f7; +// } + + GlState.clearColor(this.fogColorRed, this.fogColorGreen, this.fogColorBlue, 0.0F); + } + + /** + * Sets up the fog to be rendered. If the arg passed in is -1 the fog starts at 0 and goes to 80% of far plane + * distance and is used for sky rendering. + * + * @param start If is -1 the fog start at 0.0 + */ + private void setupFog(int start, float partial) + { + Entity entity = this.gm.getRenderViewEntity(); + float fog = this.gm.world.getFogStrength(); + float distance = Math.min(0.995f, Math.max(0.005f, FOG_DISTANCE - (0.3f * fog))); + float density = 1.0f - Math.min(1.0f, FOG_DENSITY * (1.0f - fog * 0.1f)); +// boolean flag = false; +// +// if (entity.isPlayer()) +// { +// flag = ((EntityNPC)entity).capabilities.isCreativeMode; +// } + + GL11.glFogfv(GL11.GL_FOG_COLOR, (FloatBuffer)this.setFogColorBuffer(this.fogColorRed, this.fogColorGreen, this.fogColorBlue, 1.0F)); + GL11.glNormal3f(0.0F, -1.0F, 0.0F); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + Block block = ActiveRenderInfo.getBlockAtEntityViewpoint(this.gm.world, entity, partial); + + if(distance >= 1.0f) { + ; + } + else if (entity instanceof EntityLiving && ((EntityLiving)entity).hasEffect(Potion.BLINDNESS)) + { + float far = 5.0F; + int effect = ((EntityLiving)entity).getEffect(Potion.BLINDNESS).getRemaining(); + + if (effect < 20) + { + far = 5.0F + (this.farPlaneDistance - 5.0F) * (1.0F - (float)effect / 20.0F); + } + + GlState.setFog(GL11.GL_LINEAR); + + if (start == -1) + { + GlState.setFogStart(0.0F); + GlState.setFogEnd(far * 0.8F); + } + else + { + GlState.setFogStart(far * 0.25F); + GlState.setFogEnd(far); + } + +// if (GLContext.getCapabilities().GL_NV_fog_distance) +// { +// SKC.glFogi(NVFogDistance.GL_FOG_DISTANCE_MODE_NV, NVFogDistance.GL_EYE_RADIAL_NV); +// } + } +// else if (this.cloudFog) +// { +// GlState.setFog(SKC.GL_EXP); +// GlState.setFogDensity(0.1F); +// } + else if (block.getMaterial().isColdLiquid()) + { + GlState.setFog(GL11.GL_EXP); + +// if (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).hasEffect(Potion.waterBreathing)) +// { +// GlState.setFogDensity(0.01F); +// } +// else +// { + GlState.setFogDensity(0.04F); // - (float)EnchantmentHelper.getRespiration(entity) * 0.03F); +// } + } + else if (block.getMaterial().isHotLiquid()) + { + GlState.setFog(GL11.GL_EXP); + GlState.setFogDensity(2.0F); + } + else + { + float far = this.farPlaneDistance; + GlState.setFog(GL11.GL_LINEAR); + + if (start == -1) + { + GlState.setFogStart(0.0F); + GlState.setFogEnd(far * Math.max(density * 2.0f, 0.01f)); + } + else + { + GlState.setFogStart(far * distance); + GlState.setFogEnd(far * Math.max(density * (distance / 0.75f) * 2.0f, distance + 0.01f)); + } + +// if (GLContext.getCapabilities().GL_NV_fog_distance) +// { +// SKC.glFogi(NVFogDistance.GL_FOG_DISTANCE_MODE_NV, NVFogDistance.GL_EYE_RADIAL_NV); +// } + + if (this.gm.world.dimension.hasDenseFog()) + { + GlState.setFogStart(far * ((distance / 0.75f) * 0.05F)); + GlState.setFogEnd(Math.min(far, 192.0F) * Math.max(density * (distance / 0.75f), (distance / 0.75f) * 0.05F + 0.01f)); + } + } + + GlState.enableColorMaterial(); + GlState.setFogEnabled(distance < 1.0f); + GlState.colorMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT); + } + + /** + * Update and return fogColorBuffer with the RGBA values passed as arguments + */ + private FloatBuffer setFogColorBuffer(float red, float green, float blue, float alpha) + { + this.fogColorBuffer.clear(); + this.fogColorBuffer.put(red).put(green).put(blue).put(alpha); + this.fogColorBuffer.flip(); + return this.fogColorBuffer; + } + +// public MapItemRenderer getMapItemRenderer() +// { +// return this.theMapItemRenderer; +// } +} diff --git a/client/src/main/java/client/renderer/Frustum.java b/client/src/client/renderer/Frustum.java similarity index 100% rename from client/src/main/java/client/renderer/Frustum.java rename to client/src/client/renderer/Frustum.java diff --git a/client/src/main/java/client/renderer/GlState.java b/client/src/client/renderer/GlState.java similarity index 100% rename from client/src/main/java/client/renderer/GlState.java rename to client/src/client/renderer/GlState.java diff --git a/client/src/client/renderer/ItemModelMesher.java b/client/src/client/renderer/ItemModelMesher.java new file mode 100755 index 00000000..b242df14 --- /dev/null +++ b/client/src/client/renderer/ItemModelMesher.java @@ -0,0 +1,137 @@ +package client.renderer; + +import java.util.List; +import java.util.Map; + +import client.renderer.blockmodel.IBakedModel; +import client.renderer.blockmodel.ModelManager; +import client.renderer.texture.TextureAtlasSprite; +import common.collect.Lists; +import common.collect.Maps; +import common.init.ItemRegistry; +import common.item.Item; +import common.item.ItemStack; +import common.model.ItemMeshDefinition; + +public class ItemModelMesher +{ +// private final Map simpleShapes = Maps.newHashMap(); + private final Map simpleShapesCache = Maps.newHashMap(); + private final Map shapers = Maps.newHashMap(); + private final ModelManager modelManager; + + public ItemModelMesher(ModelManager modelManager) + { + this.modelManager = modelManager; + for(Item item : ItemRegistry.REGISTRY) { + ItemMeshDefinition mesher = item.getMesher(); + if(mesher != null) + this.shapers.put(item, mesher); + } + } + + public TextureAtlasSprite getParticleIcon(Item item) + { + return this.getParticleIcon(item, 0); + } + + public TextureAtlasSprite getParticleIcon(Item item, int meta) + { + return this.getItemModel(new ItemStack(item, 1, meta)).getParticleTexture(); + } + + public IBakedModel getItemModel(ItemStack stack) + { + Item item = stack.getItem(); + IBakedModel ibakedmodel = this.simpleShapesCache.get(Integer.valueOf(this.getIndex(item, + stack.isItemStackDamageable() ? 0 : stack.getMetadata()))); + + if (ibakedmodel == null) + { + ItemMeshDefinition itemmeshdefinition = this.shapers.get(item); + + if (itemmeshdefinition != null) + { + ibakedmodel = this.modelManager.getModel(itemmeshdefinition.getModelLocation(stack)); + } + } + + if (ibakedmodel == null) + { + ibakedmodel = this.modelManager.getMissingModel(); + } + + return ibakedmodel; + } + + private int getIndex(Item item, int meta) + { + return ItemRegistry.getIdFromItem(item) << 16 | meta; + } + +// public void register(Item item, int meta, ResourceLocation location) +// { +// this.simpleShapes.put(Integer.valueOf(this.getIndex(item, meta)), location); +// this.simpleShapesCache.put(Integer.valueOf(this.getIndex(item, meta)), this.modelManager.getModel(location)); +// } + +// public void register(Item item, ItemMeshDefinition definition) +// { +// this.shapers.put(item, definition); +// } + +// public void registerItem(Item itm, int subType, String identifier) +// { +// this.register(itm, subType, new ResourceLocation(identifier, "inventory")); +//// String id = ItemRegistry.REGISTRY.getNameForObject(itm).toString(); +//// if(id.equals(identifier)) { +////// throw new IllegalArgumentException("Duplikat: " + identifier); +//// Log.DATA.info("MATCHING: " + ItemRegistry.REGISTRY.getNameForObject(itm) + ":" + subType); +//// } +//// else { +//// Log.DATA.info("MISMATCH: " + ItemRegistry.REGISTRY.getNameForObject(itm) + ":" + subType + ": " + identifier); +//// } +// } + +// public void registerBlock(Block blk, int subType, String identifier) +// { +// this.registerItem(ItemRegistry.getItemFromBlock(blk), subType, identifier); +// } +// +// public void registerBlock(Block blk, String identifier) +// { +// this.registerBlock(blk, 0, identifier); +// } +// +// public void registerItem(Item itm, String identifier) +// { +// this.registerItem(itm, 0, identifier); +// } + + public ModelManager getModelManager() + { + return this.modelManager; + } + + public void rebuildCache() + { + this.simpleShapesCache.clear(); + List stacks = Lists.newArrayList(); + for(Item item : ItemRegistry.REGISTRY) { + if(this.shapers.containsKey(item)) + continue; + item.getRenderItems(item, stacks); + for(ItemStack stack : stacks) { + this.simpleShapesCache.put(this.getIndex(item, stack.getMetadata()), + this.modelManager.getModel("item/" + + ItemRegistry.REGISTRY.getNameForObject(item).toString() + "#" + stack.getMetadata() + '#' + "inventory")); + } + stacks.clear(); + } + +// for (Entry entry : this.simpleShapes.entrySet()) +// { +// this.simpleShapesCache.put(entry.getKey(), this.modelManager.getModel((ResourceLocation)entry.getValue())); +// } + } +} diff --git a/client/src/main/java/client/renderer/ItemRenderer.java b/client/src/client/renderer/ItemRenderer.java similarity index 77% rename from client/src/main/java/client/renderer/ItemRenderer.java rename to client/src/client/renderer/ItemRenderer.java index 6a1a1296..0c310a61 100755 --- a/client/src/main/java/client/renderer/ItemRenderer.java +++ b/client/src/client/renderer/ItemRenderer.java @@ -12,15 +12,16 @@ import client.renderer.entity.RenderItem; import client.renderer.entity.RenderManager; import client.renderer.entity.RenderNpc; import client.renderer.texture.EntityTexManager; -import client.renderer.texture.Sprite; +import client.renderer.texture.TextureAtlasSprite; import client.renderer.texture.TextureMap; import common.block.Block; import common.entity.npc.EntityNPC; import common.entity.types.EntityLiving; -import common.init.Blocks; import common.item.Item; import common.item.ItemAction; import common.item.ItemStack; +import common.model.BlockLayer; +import common.model.Transforms; import common.util.BlockPos; import common.util.ExtMath; import common.util.Vec3; @@ -33,13 +34,20 @@ public class ItemRenderer private static final Vec3 LIGHT0_POS = (new Vec3(0.20000000298023224D, 1.0D, -0.699999988079071D)).normalize(); private static final Vec3 LIGHT1_POS = (new Vec3(-0.20000000298023224D, 1.0D, 0.699999988079071D)).normalize(); + /** A reference to the Game object. */ private final Client gm; - private final RenderManager renderManager; - private final RenderItem itemRenderer; - private ItemStack itemToRender; + + /** + * How far the current item has been equipped (0 disequipped and 1 fully up) + */ private float equippedProgress; private float prevEquippedProgress; + private final RenderManager renderManager; + private final RenderItem itemRenderer; + + /** The index of the currently held item (0-8, or -1 if not yet updated) */ + private int equippedItemSlot = -1; private static FloatBuffer setColorBuffer(float r, float g, float b, float a) { @@ -97,25 +105,50 @@ public class ItemRenderer this.itemRenderer = gmIn.getRenderItem(); } - public void renderItem(EntityLiving entityIn, ItemStack heldStack, boolean third) + public void renderItem(EntityLiving entityIn, ItemStack heldStack, Transforms.Camera transform) { if (heldStack != null) { Item item = heldStack.getItem(); - Block block = item.getBlock(); - GL11.glPushMatrix(); - - if (this.itemRenderer.shouldRenderItemIn3D(heldStack)) - { - GL11.glScalef(2.0F, 2.0F, 2.0F); + if(item.isFirstPerson() || transform != Transforms.Camera.FIRST_PERSON) { + Block block = item.getBlock(); + GL11.glPushMatrix(); + + if (this.itemRenderer.shouldRenderItemIn3D(heldStack)) + { + GL11.glScalef(2.0F, 2.0F, 2.0F); + + if (this.isBlockTranslucent(block)) + { + GlState.depthMask(false); + } + } + + this.itemRenderer.renderItemModelForEntity(heldStack, entityIn, transform); + + if (this.isBlockTranslucent(block)) + { + GlState.depthMask(true); + } + + GL11.glPopMatrix(); } - - this.itemRenderer.renderItemForEntity(heldStack, entityIn, third); - - GL11.glPopMatrix(); } } + /** + * Returns true if given block is translucent + */ + private boolean isBlockTranslucent(Block blockIn) + { + return blockIn != null && blockIn.getBlockLayer() == BlockLayer.TRANSLUCENT; + } + + /** + * Rotate the render around X and Y + * + * @param angleY The angle for the rotation arround Y + */ private void rotateArroundXAndY(float angle, float angleY) { GL11.glPushMatrix(); @@ -125,6 +158,9 @@ public class ItemRenderer GL11.glPopMatrix(); } + /** + * Set the OpenGL LightMapTextureCoords based on the EntityNPCClient + */ private void setLightMapFromPlayer(EntityNPC clientPlayer) { int i = this.gm.world.getCombinedLight(new BlockPos(clientPlayer.posX, clientPlayer.posY + (double)clientPlayer.getEyeHeight(), clientPlayer.posZ), 0); @@ -133,6 +169,9 @@ public class ItemRenderer GL13.glMultiTexCoord2f(GL13.GL_TEXTURE1, f, f1); } + /** + * Rotate the render according to the player's yaw and pitch + */ private void rotateWithPlayerRotations(EntityNPC entityplayerspIn, float partialTicks) { float f = entityplayerspIn.prevRenderArmPitch + (entityplayerspIn.renderArmPitch - entityplayerspIn.prevRenderArmPitch) * partialTicks; @@ -141,6 +180,11 @@ public class ItemRenderer GL11.glRotatef((entityplayerspIn.rotYaw - f1) * 0.1F, 0.0F, 1.0F, 0.0F); } + /** + * Return the angle to render the Map + * + * @param pitch The player's pitch + */ private float getMapAngleFromPitch(float pitch) { float f = 1.0F - pitch / 45.0F + 0.1F; @@ -229,6 +273,12 @@ public class ItemRenderer // } // } + /** + * Render the player's arm + * + * @param equipProgress The progress of equiping the item + * @param swingProgress The swing movement progression + */ private void renderPlayerArm(EntityNPC clientPlayer, float equipProgress, float swingProgress) { float f = -0.3F * ExtMath.sin(ExtMath.sqrtf(swingProgress) * (float)Math.PI); @@ -255,6 +305,11 @@ public class ItemRenderer GlState.enableCull(); } + /** + * Rotate and translate render to show item consumption + * + * @param swingProgress The swing movement progress + */ private void doItemUsedTransformations(float swingProgress) { float f = -0.4F * ExtMath.sin(ExtMath.sqrtf(swingProgress) * (float)Math.PI); @@ -263,25 +318,33 @@ public class ItemRenderer GL11.glTranslatef(f, f1, f2); } - private void performDrinking(EntityNPC clientPlayer, float partialTicks) - { - float f = (float)clientPlayer.getItemInUseCount() - partialTicks + 1.0F; - float f1 = f / (float)this.itemToRender.getMaxItemUseDuration(); - float f2 = ExtMath.absf(ExtMath.cos(f / 4.0F * (float)Math.PI) * 0.1F); - - if (f1 >= 0.8F) - { - f2 = 0.0F; - } - - GL11.glTranslatef(0.0F, f2, 0.0F); - float f3 = 1.0F - (float)Math.pow((double)f1, 27.0D); - GL11.glTranslatef(f3 * 0.6F, f3 * -0.5F, f3 * 0.0F); - GL11.glRotatef(f3 * 90.0F, 0.0F, 1.0F, 0.0F); - GL11.glRotatef(f3 * 10.0F, 1.0F, 0.0F, 0.0F); - GL11.glRotatef(f3 * 30.0F, 0.0F, 0.0F, 1.0F); - } +// /** +// * Perform the drinking animation movement +// * +// * @param partialTicks Partials ticks +// */ +// private void performDrinking(EntityNPCSP clientPlayer, float partialTicks) +// { +// float f = (float)clientPlayer.getItemInUseCount() - partialTicks + 1.0F; +// float f1 = f / (float)this.itemToRender.getMaxItemUseDuration(); +// float f2 = ExtMath.absf(ExtMath.cos(f / 4.0F * (float)Math.PI) * 0.1F); +// +// if (f1 >= 0.8F) +// { +// f2 = 0.0F; +// } +// +// SKC.glTranslatef(0.0F, f2, 0.0F); +// float f3 = 1.0F - (float)Math.pow((double)f1, 27.0D); +// SKC.glTranslatef(f3 * 0.6F, f3 * -0.5F, f3 * 0.0F); +// SKC.glRotatef(f3 * 90.0F, 0.0F, 1.0F, 0.0F); +// SKC.glRotatef(f3 * 10.0F, 1.0F, 0.0F, 0.0F); +// SKC.glRotatef(f3 * 30.0F, 0.0F, 0.0F, 1.0F); +// } + /** + * Performs transformations prior to the rendering of a held item in first person. + */ private void transformFirstPersonItem(float equipProgress, float swingProgress) { GL11.glTranslatef(0.56F, -0.52F, -0.71999997F); @@ -295,6 +358,11 @@ public class ItemRenderer GL11.glScalef(0.4F, 0.4F, 0.4F); } + /** + * Translate and rotate the render to look like holding a bow + * + * @param partialTicks Partial ticks + */ private void doBowTransformations(float partialTicks, EntityNPC clientPlayer) { GL11.glRotatef(-18.0F, 0.0F, 0.0F, 1.0F); @@ -322,6 +390,9 @@ public class ItemRenderer GL11.glScalef(1.0F, 1.0F, 1.0F + f1 * 0.2F); } + /** + * Translate and rotate the render for holding a block + */ private void doBlockTransformations() { GL11.glTranslatef(-0.5F, 0.2F, 0.0F); @@ -330,6 +401,9 @@ public class ItemRenderer GL11.glRotatef(60.0F, 0.0F, 1.0F, 0.0F); } + /** + * Renders the active item in the player's hand when in first person mode. Args: partialTickTime + */ public void renderItemInFirstPerson(float partialTicks) { float f = 1.0F - (this.prevEquippedProgress + (this.equippedProgress - this.prevEquippedProgress) * partialTicks); @@ -343,8 +417,13 @@ public class ItemRenderer GlState.enableRescaleNormal(); GL11.glPushMatrix(); - if (this.itemToRender != null && (this.itemToRender.getItem().getWieldType() != null || (clientplayer.getItemInUseCount() > 0 && this.itemToRender.getItemUseAction() != ItemAction.NONE))) + if (this.itemToRender != null) { +// if (this.itemToRender.getItem() == Items.filled_map) +// { +// this.renderItemMap(clientplayer, f2, f, f1); +// } +// else if (clientplayer.getItemInUseCount() > 0) { ItemAction enumaction = this.itemToRender.getItemUseAction(); @@ -357,9 +436,9 @@ public class ItemRenderer case EAT: case DRINK: - this.performDrinking(clientplayer, partialTicks); - this.transformFirstPersonItem(f, 0.0F); - break; +// this.performDrinking(clientplayer, partialTicks); +// this.transformFirstPersonItem(f, 0.0F); +// break; case BLOCK: this.transformFirstPersonItem(f, 0.0F); @@ -377,9 +456,9 @@ public class ItemRenderer this.transformFirstPersonItem(f, f1); } - this.renderItem(clientplayer, this.itemToRender, false); + this.renderItem(clientplayer, this.itemToRender, Transforms.Camera.FIRST_PERSON); } - else if(this.itemToRender == null || this.itemToRender.getItem().canRenderHand()) + else // if (!clientplayer.isInvisible()) { this.renderPlayerArm(clientplayer, f, f1); } @@ -389,6 +468,9 @@ public class ItemRenderer ItemRenderer.disableStandardItemLighting(); } + /** + * Renders all the overlays that are in first person mode. Args: partialTickTime + */ public void renderOverlays(float partialTicks) { GlState.disableAlpha(); @@ -412,22 +494,29 @@ public class ItemRenderer } } - if (iblockstate.getBlock() != Blocks.air) + if (iblockstate.getBlock().getRenderType() != -1) { - this.renderBlockInside(partialTicks, this.gm.getBlockRendererDispatcher().getModelManager().getTexture(iblockstate)); + this.renderBlockInHand(partialTicks, this.gm.getBlockRendererDispatcher().getModelManager().getTexture(iblockstate)); } } if(this.gm.player.isBurning()) { - this.renderFireOverlay(partialTicks); + this.renderFireInFirstPerson(partialTicks); } GlState.enableAlpha(); } - private void renderBlockInside(float partialTicks, Sprite atlas) + /** + * Render the block in the player's hand + * + * @param partialTicks Partial ticks + * @param atlas The TextureAtlasSprite to render + */ + private void renderBlockInHand(float partialTicks, TextureAtlasSprite atlas) { - this.gm.getTextureManager().bindTexture(TextureMap.BLOCKS); + this.gm.getTextureManager().bindTexture(TextureMap.locationBlocksTexture); +// Tessellator tessellator = Tessellator.getInstance(); RenderBuffer worldrenderer = Tessellator.getBuffer(); float f = 0.1F; GlState.color(0.1F, 0.1F, 0.1F, 0.5F); @@ -451,8 +540,14 @@ public class ItemRenderer GlState.color(1.0F, 1.0F, 1.0F, 1.0F); } - private void renderFireOverlay(float partialTicks) + /** + * Renders the fire on the screen for first person mode. Arg: partialTickTime + * + * @param partialTicks Partial ticks + */ + private void renderFireInFirstPerson(float partialTicks) { +// Tessellator tessellator = Tessellator.getInstance(); RenderBuffer worldrenderer = Tessellator.getBuffer(); GlState.color(1.0F, 1.0F, 1.0F, 0.9F); GlState.depthFunc(GL11.GL_ALWAYS); @@ -464,8 +559,8 @@ public class ItemRenderer for (int i = 0; i < 2; ++i) { GL11.glPushMatrix(); - Sprite textureatlassprite = this.gm.getTextureMapBlocks().getAtlasSprite("blocks/fire_layer_1"); - this.gm.getTextureManager().bindTexture(TextureMap.BLOCKS); + TextureAtlasSprite textureatlassprite = this.gm.getTextureMapBlocks().getAtlasSprite("blocks/fire_layer_1"); + this.gm.getTextureManager().bindTexture(TextureMap.locationBlocksTexture); float f1 = textureatlassprite.getMinU(); float f2 = textureatlassprite.getMaxU(); float f3 = textureatlassprite.getMinV(); @@ -492,16 +587,16 @@ public class ItemRenderer GlState.depthFunc(GL11.GL_LEQUAL); } - public void update() + public void updateEquippedItem() { this.prevEquippedProgress = this.equippedProgress; EntityNPC entityplayer = this.gm.player; - ItemStack itemstack = entityplayer.getHeldItem(); + ItemStack itemstack = entityplayer.inventory.getCurrentItem(); boolean flag = false; if (this.itemToRender != null && itemstack != null) { - if (!this.itemToRender.allEquals(itemstack)) + if (!this.itemToRender.getIsItemStackEqual(itemstack)) { flag = true; } @@ -523,10 +618,22 @@ public class ItemRenderer if (this.equippedProgress < 0.1F) { this.itemToRender = itemstack; + this.equippedItemSlot = entityplayer.inventory.currentItem; } } - public void resetProgress() + /** + * Resets equippedProgress + */ + public void resetEquippedProgress() + { + this.equippedProgress = 0.0F; + } + + /** + * Resets equippedProgress + */ + public void resetEquippedProgress2() { this.equippedProgress = 0.0F; } diff --git a/client/src/main/java/client/renderer/Project.java b/client/src/client/renderer/Project.java similarity index 82% rename from client/src/main/java/client/renderer/Project.java rename to client/src/client/renderer/Project.java index 83f07597..ce0b8a8b 100644 --- a/client/src/main/java/client/renderer/Project.java +++ b/client/src/client/renderer/Project.java @@ -38,7 +38,14 @@ import java.nio.IntBuffer; import org.lwjgl.opengl.GL11; -// 11-jan-2004 Erik Duijs +/** + * Project.java + *

+ *

+ * Created 11-jan-2004 + * + * @author Erik Duijs + */ public class Project { static final float PI = (float)Math.PI; @@ -60,6 +67,13 @@ public class Project { private static final float[] side = new float[3]; private static final float[] up = new float[3]; + /** + * Normalize vector + * + * @param v + * + * @return float[] + */ protected static float[] normalize(float[] v) { float r; @@ -76,18 +90,35 @@ public class Project { return v; } + /** + * Calculate cross-product + * + * @param v1 + * @param v2 + * @param result + */ protected static void cross(float[] v1, float[] v2, float[] result) { result[0] = v1[1] * v2[2] - v1[2] * v2[1]; result[1] = v1[2] * v2[0] - v1[0] * v2[2]; result[2] = v1[0] * v2[1] - v1[1] * v2[0]; } + /** + * Make matrix an identity matrix + */ private static void __gluMakeIdentityf(FloatBuffer m) { int oldPos = m.position(); m.put(IDENTITY_MATRIX); m.position(oldPos); } + /** + * Method __gluMultMatrixVecf + * + * @param finalMatrix + * @param in + * @param out + */ private static void __gluMultMatrixVecf(FloatBuffer m, float[] in, float[] out) { for (int i = 0; i < 4; i++) { out[i] = @@ -99,6 +130,12 @@ public class Project { } } + /** + * @param src + * @param inverse + * + * @return true if the matrix was succesfully inverted + */ private static boolean __gluInvertMatrixf(FloatBuffer src, FloatBuffer inverse) { int i, j, k, swap; float t; @@ -170,6 +207,11 @@ public class Project { return true; } + /** + * @param a + * @param b + * @param r + */ private static void __gluMultMatricesf(FloatBuffer a, FloatBuffer b, FloatBuffer r) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { @@ -179,6 +221,14 @@ public class Project { } } + /** + * Method gluPerspective. + * + * @param fovy + * @param aspect + * @param zNear + * @param zFar + */ public static void gluPerspective(float fovy, float aspect, float zNear, float zFar) { float sine, cotangent, deltaZ; float radians = fovy / 2 * PI / 180; @@ -204,6 +254,19 @@ public class Project { GL11.glMultMatrixf(matrix); } + /** + * Method gluLookAt + * + * @param eyex + * @param eyey + * @param eyez + * @param centerx + * @param centery + * @param centerz + * @param upx + * @param upy + * @param upz + */ public static void gluLookAt( float eyex, float eyey, @@ -252,6 +315,17 @@ public class Project { GL11.glTranslatef(-eyex, -eyey, -eyez); } + /** + * Method gluProject + * + * @param objx + * @param objy + * @param objz + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param win_pos + */ public static boolean gluProject( float objx, float objy, @@ -290,6 +364,17 @@ public class Project { return true; } + /** + * Method gluUnproject + * + * @param winx + * @param winy + * @param winz + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param obj_pos + */ public static boolean gluUnProject( float winx, float winy, @@ -333,4 +418,31 @@ public class Project { return true; } + +// /** +// * Method gluPickMatrix +// * +// * @param x +// * @param y +// * @param deltaX +// * @param deltaY +// * @param viewport +// */ +// public static void gluPickMatrix( +// float x, +// float y, +// float deltaX, +// float deltaY, +// IntBuffer viewport) { +// if (deltaX <= 0 || deltaY <= 0) { +// return; +// } +// +// /* Translate and scale the picked region to the entire window */ +// SKC.glTranslatef( +// (viewport.get(viewport.position() + 2) - 2 * (x - viewport.get(viewport.position() + 0))) / deltaX, +// (viewport.get(viewport.position() + 3) - 2 * (y - viewport.get(viewport.position() + 1))) / deltaY, +// 0); +// SKC.glScalef(viewport.get(viewport.position() + 2) / deltaX, viewport.get(viewport.position() + 3) / deltaY, 1.0f); +// } } diff --git a/client/src/client/renderer/RegionRenderCache.java b/client/src/client/renderer/RegionRenderCache.java new file mode 100755 index 00000000..4ea94178 --- /dev/null +++ b/client/src/client/renderer/RegionRenderCache.java @@ -0,0 +1,191 @@ +package client.renderer; + +import java.util.Arrays; + +import common.init.Blocks; +import common.tileentity.TileEntity; +import common.util.BlockPos; +import common.util.Facing; +import common.util.Vec3i; +import common.world.Chunk; +import common.world.ChunkCache; +import common.world.IWorldAccess; +import common.world.State; +import common.world.World; + +public class RegionRenderCache extends ChunkCache implements IWorldAccess +{ + private static final State DEFAULT_STATE = Blocks.air.getState(); + + private final World worldObj; + private final BlockPos position; + private final boolean empty; + private int[] combinedLights; + private State[] blockStates; + + public RegionRenderCache(World worldIn, BlockPos posFromIn, BlockPos posToIn, int subIn) + { + super(worldIn, posFromIn, posToIn, subIn); + this.worldObj = worldIn; + boolean empty = true; + for (int i1 = posFromIn.getX() >> 4; i1 <= posToIn.getX() >> 4; ++i1) + { + for (int j1 = posFromIn.getZ() >> 4; j1 <= posToIn.getZ() >> 4; ++j1) + { + Chunk chunk = this.chunkArray[i1 - this.chunkX][j1 - this.chunkZ]; + + if (chunk != null && !chunk.isEmpty(posFromIn.getY(), posToIn.getY())) + { + empty = false; + } + } + } + this.empty = empty; + this.position = posFromIn.subtract(new Vec3i(subIn, subIn, subIn)); + int i = 16000; + this.combinedLights = new int[16000]; + Arrays.fill((int[])this.combinedLights, (int) - 1); + this.blockStates = new State[16000]; + } + + public TileEntity getTileEntity(BlockPos pos) + { + int i = (pos.getX() >> 4) - this.chunkX; + int j = (pos.getZ() >> 4) - this.chunkZ; + return this.chunkArray[i][j].getTileEntity(pos, TileEntity.EnumCreateEntityType.QUEUED); + } + + public int getCombinedLight(BlockPos pos, int lightValue) + { + int i = this.getPositionIndex(pos); + int j = this.combinedLights[i]; + + if (j == -1) + { + j = this.getLight(pos, lightValue); + this.combinedLights[i] = j; + } + + return j; + } + + public State getState(BlockPos pos) + { + int i = this.getPositionIndex(pos); + State iblockstate = this.blockStates[i]; + + if (iblockstate == null) + { + iblockstate = this.getBlockStateRaw(pos); + this.blockStates[i] = iblockstate; + } + + return iblockstate; + } + + private State getBlockStateRaw(BlockPos pos) + { + if (pos.getY() >= 0 && pos.getY() < 512) + { + int i = (pos.getX() >> 4) - this.chunkX; + int j = (pos.getZ() >> 4) - this.chunkZ; + return this.chunkArray[i][j].getState(pos); + } + else + { + return DEFAULT_STATE; + } + } + + private int getPositionIndex(BlockPos p_175630_1_) + { + int i = p_175630_1_.getX() - this.position.getX(); + int j = p_175630_1_.getY() - this.position.getY(); + int k = p_175630_1_.getZ() - this.position.getZ(); + return i * 800 + k * 40 + j; + } + + public boolean isEmpty() + { + return this.empty; + } + + public int getLight(BlockPos pos, int lightValue) + { + int j = this.getLightForExt(pos); + + if (j < lightValue) + { + j = lightValue; + } + + return 15 << 20 | j << 4; + } + + private int getLightForExt(BlockPos pos) + { + if (pos.getY() >= 0 && pos.getY() < 512) + { + if (this.getState(pos).getBlock().getSumBrightness()) + { + int l = 0; + + for (Facing enumfacing : Facing.values()) + { + int k = this.getLightFor(pos.offset(enumfacing)); + + if (k > l) + { + l = k; + } + + if (l >= 15) + { + return l; + } + } + + return l; + } + else + { + int i = (pos.getX() >> 4) - this.chunkX; + int j = (pos.getZ() >> 4) - this.chunkZ; + return this.chunkArray[i][j].getLight(pos); + } + } + else + { + return 0; + } + } + +// /** +// * Checks to see if an air block exists at the provided location. Note that this only checks to see if the blocks +// * material is set to air, meaning it is possible for non-vanilla blocks to still pass this check. +// */ +// public boolean isAirBlock(BlockPos pos) +// { +// return this.getBlockState(pos).getBlock().getMaterial() == Material.air; +// } + + public int getLightFor(BlockPos pos) + { + if (pos.getY() >= 0 && pos.getY() < 512) + { + int i = (pos.getX() >> 4) - this.chunkX; + int j = (pos.getZ() >> 4) - this.chunkZ; + return this.chunkArray[i][j].getLight(pos); + } + else + { + return 0; + } + } + +// public int getStrongPower(BlockPos pos, EnumFacing direction) +// { +// IBlockState iblockstate = this.getBlockState(pos); +// return iblockstate.getBlock().getStrongPower(this, pos, iblockstate, direction); +// } +} diff --git a/client/src/main/java/client/renderer/RegionRenderCacheBuilder.java b/client/src/client/renderer/RegionRenderCacheBuilder.java similarity index 83% rename from client/src/main/java/client/renderer/RegionRenderCacheBuilder.java rename to client/src/client/renderer/RegionRenderCacheBuilder.java index e2d8edba..7318dc33 100755 --- a/client/src/main/java/client/renderer/RegionRenderCacheBuilder.java +++ b/client/src/client/renderer/RegionRenderCacheBuilder.java @@ -1,6 +1,6 @@ package client.renderer; -import client.renderer.chunk.BlockLayer; +import common.model.BlockLayer; public class RegionRenderCacheBuilder { @@ -9,7 +9,8 @@ public class RegionRenderCacheBuilder public RegionRenderCacheBuilder() { this.buffers[BlockLayer.SOLID.ordinal()] = new RenderBuffer(2097152); - this.buffers[BlockLayer.CUTOUT.ordinal()] = new RenderBuffer(262144); + this.buffers[BlockLayer.CUTOUT.ordinal()] = new RenderBuffer(131072); + this.buffers[BlockLayer.CUTOUT_MIPPED.ordinal()] = new RenderBuffer(131072); this.buffers[BlockLayer.TRANSLUCENT.ordinal()] = new RenderBuffer(262144); } diff --git a/client/src/main/java/client/renderer/RenderBuffer.java b/client/src/client/renderer/RenderBuffer.java similarity index 92% rename from client/src/main/java/client/renderer/RenderBuffer.java rename to client/src/client/renderer/RenderBuffer.java index 60ac2b84..b5cb077a 100755 --- a/client/src/main/java/client/renderer/RenderBuffer.java +++ b/client/src/client/renderer/RenderBuffer.java @@ -21,6 +21,8 @@ public class RenderBuffer private int vertexCount; private VertexFormatElement vertexFormatElement; private int vertexFormatIndex; + + /** None */ private boolean noColor; private int drawMode; private double xOffset; @@ -44,7 +46,7 @@ public class RenderBuffer int i = this.byteBuffer.capacity(); int j = i % 2097152; int k = j + (((this.rawIntBuffer.position() + p_181670_1_) * 4 - j) / 2097152 + 1) * 2097152; - Log.RENDER.warn("Musste Puffer vergrößern: Alte Größe " + i + " Bytes, neue Größe " + k + " Bytes."); + Log.JNI.warn("Musste Puffer vergrößern: Alte Größe " + i + " Bytes, neue Größe " + k + " Bytes."); int l = this.rawIntBuffer.position(); ByteBuffer bytebuffer = ByteBuffer.allocateDirect(k).order(ByteOrder.nativeOrder()); this.byteBuffer.position(0); @@ -194,7 +196,7 @@ public class RenderBuffer { int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex); - switch (this.vertexFormatElement.type()) + switch (this.vertexFormatElement.getType()) { case FLOAT: this.byteBuffer.putFloat(i, (float)u); @@ -227,7 +229,7 @@ public class RenderBuffer { int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex); - switch (this.vertexFormatElement.type()) + switch (this.vertexFormatElement.getType()) { case FLOAT: this.byteBuffer.putFloat(i, (float)p_181671_1_); @@ -282,11 +284,44 @@ public class RenderBuffer } } + /** + * Takes in the pass the call list is being requested for. Args: renderPass + */ private int getColorIndex(int p_78909_1_) { return ((this.vertexCount - p_78909_1_) * this.vertexFormat.getNextOffset() + this.vertexFormat.getColorOffset()) / 4; } + public void putColorMultiplier(float red, float green, float blue, int p_178978_4_) + { + int i = this.getColorIndex(p_178978_4_); + int j = -1; + + if (!this.noColor) + { + j = this.rawIntBuffer.get(i); + + if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) + { + int k = (int)((float)(j & 255) * red); + int l = (int)((float)(j >> 8 & 255) * green); + int i1 = (int)((float)(j >> 16 & 255) * blue); + j = j & -16777216; + j = j | i1 << 16 | l << 8 | k; + } + else + { + int j1 = (int)((float)(j >> 24 & 255) * red); + int k1 = (int)((float)(j >> 16 & 255) * green); + int l1 = (int)((float)(j >> 8 & 255) * blue); + j = j & 255; + j = j | j1 << 24 | k1 << 16 | l1 << 8; + } + } + + this.rawIntBuffer.put(i, j); + } + private void putColor(int argb, int p_178988_2_) { int i = this.getColorIndex(p_178988_2_); @@ -318,6 +353,9 @@ public class RenderBuffer } } + /** + * Disabels color processing. + */ public void noColor() { this.noColor = true; @@ -343,7 +381,7 @@ public class RenderBuffer { int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex); - switch (this.vertexFormatElement.type()) + switch (this.vertexFormatElement.getType()) { case FLOAT: this.byteBuffer.putFloat(i, (float)red / 255.0F); @@ -409,7 +447,7 @@ public class RenderBuffer { int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex); - switch (this.vertexFormatElement.type()) + switch (this.vertexFormatElement.getType()) { case FLOAT: this.byteBuffer.putFloat(i, (float)(x + this.xOffset)); @@ -462,7 +500,7 @@ public class RenderBuffer this.vertexFormatIndex %= this.vertexFormat.getElementCount(); this.vertexFormatElement = this.vertexFormat.getElement(this.vertexFormatIndex); - if (this.vertexFormatElement.usage() == VertexFormatElement.EnumUsage.PADDING) + if (this.vertexFormatElement.getUsage() == VertexFormatElement.EnumUsage.PADDING) { this.nextVertexFormatIndex(); } @@ -472,7 +510,7 @@ public class RenderBuffer { int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex); - switch (this.vertexFormatElement.type()) + switch (this.vertexFormatElement.getType()) { case FLOAT: this.byteBuffer.putFloat(i, p_181663_1_); diff --git a/client/src/main/java/client/renderer/RenderGlobal.java b/client/src/client/renderer/RenderGlobal.java similarity index 87% rename from client/src/main/java/client/renderer/RenderGlobal.java rename to client/src/client/renderer/RenderGlobal.java index 9c8a8e5c..f1ad4b36 100755 --- a/client/src/main/java/client/renderer/RenderGlobal.java +++ b/client/src/client/renderer/RenderGlobal.java @@ -16,39 +16,43 @@ import org.lwjgl.opengl.GL13; import org.lwjgl.opengl.GL15; import client.Client; -import client.renderer.chunk.BlockLayer; import client.renderer.chunk.ChunkRenderDispatcher; import client.renderer.chunk.CompiledChunk; import client.renderer.chunk.RenderChunk; import client.renderer.chunk.VisGraph; import client.renderer.entity.RenderManager; -import client.renderer.texture.Sprite; +import client.renderer.texture.TextureAtlasSprite; import client.renderer.texture.TextureManager; import client.renderer.texture.TextureMap; -import client.renderer.tileentity.SpecialRenderer; -import client.world.ChunkClient; +import client.renderer.tileentity.TileEntityRendererDispatcher; +import client.world.WorldClient; import common.block.Block; +import common.block.BlockChest; +import common.block.BlockSign; +import common.block.BlockSkull; import common.collect.Lists; import common.collect.Maps; import common.collect.Sets; -import common.dimension.DimType; import common.entity.Entity; import common.entity.npc.EntityNPC; +import common.entity.projectile.EntityBox; import common.entity.types.EntityLiving; -import common.init.Blocks; +import common.material.Material; +import common.model.BlockLayer; import common.rng.Random; import common.sound.Sound; import common.tileentity.TileEntity; +import common.tileentity.TileEntityChest; import common.util.BlockPos; import common.util.BoundingBox; -import common.util.InheritanceMultiMap; +import common.util.ClassInheritanceMultiMap; import common.util.ExtMath; import common.util.Facing; import common.util.HitPosition; import common.util.Vec3; import common.util.Vector3f; +import common.world.Chunk; import common.world.State; -import common.world.World; public class RenderGlobal { @@ -104,18 +108,15 @@ public class RenderGlobal return this.time; } } - + private static final String MOON_TEX = "textures/world/moon_phases.png"; - private static final String PLANET_TEX = "textures/world/planet_phases.png"; private static final String SUN_TEX = "textures/world/sun.png"; - private static final String EXTERMINATED_TEX = "textures/world/destroyed.png"; private static final float[] SUN_COLOR = new float[4]; private final Client gm; private final TextureManager renderEngine; private final RenderManager renderManager; - private final Random rand = new Random(); - private World theWorld; + private WorldClient theWorld; private Set chunksToUpdate = new LinkedHashSet(); private List renderInfos = new ArrayList(69696); private final Set setTileEntities = Sets.newHashSet(); @@ -128,7 +129,7 @@ public class RenderGlobal private int cloudTickCounter; private final Map damagedBlocks = Maps.newHashMap(); private final Map mapSoundPositions = Maps.newHashMap(); - private final Sprite[] destroyBlockIcons = new Sprite[10]; + private final TextureAtlasSprite[] destroyBlockIcons = new TextureAtlasSprite[10]; private double frustumUpdatePosX = Double.MIN_VALUE; private double frustumUpdatePosY = Double.MIN_VALUE; private double frustumUpdatePosZ = Double.MIN_VALUE; @@ -408,7 +409,7 @@ public class RenderGlobal /** * set null to clear */ - public void setWorldAndLoadRenderers(World worldClientIn) + public void setWorldAndLoadRenderers(WorldClient worldClientIn) { // if (this.theWorld != null) // { @@ -454,7 +455,7 @@ public class RenderGlobal this.setTileEntities.clear(); } - this.viewFrustum = new ViewFrustum(this.gm, this.gm.renderDistance, this); + this.viewFrustum = new ViewFrustum(this.theWorld, this.gm.renderDistance, this); if (this.theWorld != null) { @@ -462,7 +463,7 @@ public class RenderGlobal if (entity != null) { - this.viewFrustum.updateChunkPositions(entity.posX, entity.posY, entity.posZ); + this.viewFrustum.updateChunkPositions(entity.posX, entity.posZ); } } @@ -491,7 +492,7 @@ public class RenderGlobal double d0 = renderViewEntity.prevX + (renderViewEntity.posX - renderViewEntity.prevX) * (double)partialTicks; double d1 = renderViewEntity.prevY + (renderViewEntity.posY - renderViewEntity.prevY) * (double)partialTicks; double d2 = renderViewEntity.prevZ + (renderViewEntity.posZ - renderViewEntity.prevZ) * (double)partialTicks; - SpecialRenderer.instance.setPosition(this.theWorld, this.gm.getRenderViewEntity(), partialTicks); + TileEntityRendererDispatcher.instance.cacheActiveRenderInfo(this.theWorld, this.gm.getTextureManager(), this.gm.getRenderViewEntity(), partialTicks); this.renderManager.cacheActiveRenderInfo(this.theWorld, this.gm.getRenderViewEntity(), this.gm.getPointedEntity(), this.gm, partialTicks); this.countEntitiesTotal = 0; this.countEntitiesRendered = 0; @@ -500,12 +501,12 @@ public class RenderGlobal double d3 = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double)partialTicks; double d4 = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)partialTicks; double d5 = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double)partialTicks; - SpecialRenderer.entityX = d3; - SpecialRenderer.entityY = d4; - SpecialRenderer.entityZ = d5; + TileEntityRendererDispatcher.staticPlayerX = d3; + TileEntityRendererDispatcher.staticPlayerY = d4; + TileEntityRendererDispatcher.staticPlayerZ = d5; this.renderManager.setRenderPosition(d3, d4, d5); this.gm.entityRenderer.enableLightmap(); - List list = this.gm.getEntities(); + List list = this.theWorld.getLoadedEntityList(); this.countEntitiesTotal = list.size(); for (int i = 0; i < this.theWorld.effects.size(); ++i) @@ -530,7 +531,7 @@ public class RenderGlobal GlState.disableTexture2D(); GlState.depthMask(false); - List tiles = this.gm.getTiles(); + List tiles = this.theWorld.getLoadedTileList(); for (int j = 0; j < tiles.size(); ++j) { @@ -573,7 +574,7 @@ public class RenderGlobal for (int j = 0; j < list.size(); ++j) { Entity entity3 = list.get(j); - if ((entity3 != this.gm.getRenderViewEntity() || this.gm.thirdPersonView != 0 || this.gm.showPlayerFirstPerson) && + if ((entity3 != this.gm.getRenderViewEntity() || this.gm.thirdPersonView != 0) && entity3 instanceof EntityLiving && entity3.isInRangeToRender3d(d0, d1, d2) && (entity3.noFrustumCheck || Frustum.isInFrustum(entity3.getEntityBoundingBox()) || entity3.passenger == this.gm.player)) { // this.renderManager.renderEntity(entity3, partialTicks); @@ -600,10 +601,10 @@ public class RenderGlobal label738: - for (RenderGlobal.ContainerLocalRenderInformation render : this.renderInfos) + for (RenderGlobal.ContainerLocalRenderInformation renderglobal$containerlocalrenderinformation : this.renderInfos) { - ChunkClient chunk = this.gm.getChunk(render.renderChunk.getPosition().getX() >> 4, render.renderChunk.getPosition().getZ() >> 4); - InheritanceMultiMap classinheritancemultimap = chunk.getEntities()[ExtMath.clampi(render.renderChunk.getPosition().getY() / 16, 0, 31)]; + Chunk chunk = this.theWorld.getChunk(renderglobal$containerlocalrenderinformation.renderChunk.getPosition()); + ClassInheritanceMultiMap classinheritancemultimap = chunk.getEntities()[renderglobal$containerlocalrenderinformation.renderChunk.getPosition().getY() / 16]; if (!classinheritancemultimap.isEmpty()) { @@ -631,9 +632,9 @@ public class RenderGlobal // boolean flag3 = this.gm.getRenderViewEntity() instanceof EntityLivingBase ? ((EntityLivingBase)this.gm.getRenderViewEntity()).isPlayerSleeping() : false; - if (entity2.posY < (double)(-World.MAX_SIZE_Y) || entity2.posY >= (double)World.MAX_SIZE_Y || this.theWorld.isBlockLoaded(new BlockPos(entity2))) + if (entity2.posY < 0.0D || entity2.posY >= 512.0D || this.theWorld.isBlockLoaded(new BlockPos(entity2))) { - if((entity2 != this.gm.getRenderViewEntity() || this.gm.thirdPersonView != 0 || this.gm.showPlayerFirstPerson)) { + if((entity2 != this.gm.getRenderViewEntity() || this.gm.thirdPersonView != 0 /* || flag3 */)) { ++this.countEntitiesRendered; this.renderManager.renderEntity(entity2, partialTicks); } @@ -643,6 +644,11 @@ public class RenderGlobal break; } } + + if (!flag2 && entity2 instanceof EntityBox) + { + this.gm.getRenderManager().renderFloatingBox(entity2, partialTicks); + } } } } @@ -657,7 +663,7 @@ public class RenderGlobal { for (TileEntity tileentity2 : list1) { - SpecialRenderer.instance.renderTile(tileentity2, partialTicks); + TileEntityRendererDispatcher.instance.renderTileEntity(tileentity2, partialTicks, -1); } } } @@ -666,10 +672,42 @@ public class RenderGlobal { for (TileEntity tileentity : this.setTileEntities) { - SpecialRenderer.instance.renderTile(tileentity, partialTicks); + TileEntityRendererDispatcher.instance.renderTileEntity(tileentity, partialTicks, -1); } } + this.preRenderDamagedBlocks(); + + for (DestroyBlockProgress destroyblockprogress : this.damagedBlocks.values()) + { + BlockPos blockpos = destroyblockprogress.getPosition(); + TileEntity tileentity1 = this.theWorld.getTileEntity(blockpos); + + if (tileentity1 instanceof TileEntityChest) + { + TileEntityChest tileentitychest = (TileEntityChest)tileentity1; + + if (tileentitychest.adjacentChestXNeg != null) + { + blockpos = blockpos.offset(Facing.WEST); + tileentity1 = this.theWorld.getTileEntity(blockpos); + } + else if (tileentitychest.adjacentChestZNeg != null) + { + blockpos = blockpos.offset(Facing.NORTH); + tileentity1 = this.theWorld.getTileEntity(blockpos); + } + } + + Block block = this.theWorld.getState(blockpos).getBlock(); + + if (tileentity1 != null && (block instanceof BlockChest || /* block instanceof BlockWarpChest || */ block instanceof BlockSign || block instanceof BlockSkull)) + { + TileEntityRendererDispatcher.instance.renderTileEntity(tileentity1, partialTicks, destroyblockprogress.getPartialBlockDamage()); + } + } + + this.postRenderDamagedBlocks(); this.gm.entityRenderer.disableLightmap(); } } @@ -713,7 +751,6 @@ public class RenderGlobal double d0 = viewEntity.posX - this.frustumUpdatePosX; double d1 = viewEntity.posY - this.frustumUpdatePosY; double d2 = viewEntity.posZ - this.frustumUpdatePosZ; - int prev = this.frustumUpdatePosChunkY; if (this.frustumUpdatePosChunkX != viewEntity.chunkCoordX || this.frustumUpdatePosChunkY != viewEntity.chunkCoordY || this.frustumUpdatePosChunkZ != viewEntity.chunkCoordZ || d0 * d0 + d1 * d1 + d2 * d2 > 16.0D) { @@ -723,7 +760,7 @@ public class RenderGlobal this.frustumUpdatePosChunkX = viewEntity.chunkCoordX; this.frustumUpdatePosChunkY = viewEntity.chunkCoordY; this.frustumUpdatePosChunkZ = viewEntity.chunkCoordZ; - this.viewFrustum.updateChunkPositions(viewEntity.posX, viewEntity.posY, viewEntity.posZ); + this.viewFrustum.updateChunkPositions(viewEntity.posX, viewEntity.posZ); } double d3 = viewEntity.lastTickPosX + (viewEntity.posX - viewEntity.lastTickPosX) * partialTicks; double d4 = viewEntity.lastTickPosY + (viewEntity.posY - viewEntity.lastTickPosY) * partialTicks; @@ -783,21 +820,18 @@ public class RenderGlobal else { // int i = blockpos1.getY() > 0 ? 248 : 8; -// int i = blockpos1.getY() > 0 ? 504 : 8; + int i = blockpos1.getY() > 0 ? 504 : 8; for (int j = -this.renderDistanceChunks; j <= this.renderDistanceChunks; ++j) { for (int k = -this.renderDistanceChunks; k <= this.renderDistanceChunks; ++k) { - for (int i = -this.renderDistanceChunks; i <= this.renderDistanceChunks; ++i) + RenderChunk renderchunk1 = this.viewFrustum.getRenderChunk(new BlockPos((j << 4) + 8, i, (k << 4) + 8)); + + if (renderchunk1 != null && Frustum.isInFrustum(renderchunk1.boundingBox)) { - RenderChunk renderchunk1 = this.viewFrustum.getRenderChunk(new BlockPos((j << 4) + 8, (i << 4) + 8, (k << 4) + 8)); - - if (renderchunk1 != null && Frustum.isInFrustum(renderchunk1.boundingBox)) - { - renderchunk1.setFrameIndex(frameCount); - queue.add(new RenderGlobal.ContainerLocalRenderInformation(renderchunk1, (Facing)null, 0)); - } + renderchunk1.setFrameIndex(frameCount); + queue.add(new RenderGlobal.ContainerLocalRenderInformation(renderchunk1, (Facing)null, 0)); } } } @@ -866,24 +900,6 @@ public class RenderGlobal } this.chunksToUpdate.addAll(set); - - if(prev != Integer.MIN_VALUE && viewEntity.chunkCoordY != prev) { - for (int j = -this.renderDistanceChunks; j <= this.renderDistanceChunks; ++j) - { - for (int k = -this.renderDistanceChunks; k <= this.renderDistanceChunks; ++k) - { - for (int i = -this.renderDistanceChunks; i <= this.renderDistanceChunks; ++i) - { - RenderChunk renderchunk1 = this.viewFrustum.getRenderChunk(new BlockPos((j << 4) + 8, (i << 4) + 8, (k << 4) + 8)); - - if (renderchunk1 != null) - { - renderchunk1.setNeedsUpdate(true); - } - } - } - } - } } private boolean isPositionInRenderChunk(BlockPos pos, RenderChunk renderChunkIn) @@ -896,7 +912,7 @@ public class RenderGlobal { VisGraph visgraph = new VisGraph(); BlockPos blockpos = new BlockPos(pos.getX() >> 4 << 4, pos.getY() >> 4 << 4, pos.getZ() >> 4 << 4); - ChunkClient chunk = this.gm.getChunk(blockpos.getX() >> 4, blockpos.getZ() >> 4); + Chunk chunk = this.theWorld.getChunk(blockpos); for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(blockpos, blockpos.add(15, 15, 15))) { @@ -915,7 +931,7 @@ public class RenderGlobal private RenderChunk getRenderChunkOffset(BlockPos playerPos, RenderChunk renderChunkBase, Facing facing) { BlockPos blockpos = renderChunkBase.getBlockPosOffset16(facing); - return ExtMath.absi(playerPos.getX() - blockpos.getX()) > this.renderDistanceChunks * 16 ? null : (ExtMath.absi(playerPos.getY() - blockpos.getY()) <= this.renderDistanceChunks * 16 ? (ExtMath.absi(playerPos.getZ() - blockpos.getZ()) > this.renderDistanceChunks * 16 ? null : this.viewFrustum.getRenderChunk(blockpos)) : null); + return ExtMath.absi(playerPos.getX() - blockpos.getX()) > this.renderDistanceChunks * 16 ? null : (blockpos.getY() >= 0 && blockpos.getY() < 512 ? (ExtMath.absi(playerPos.getZ() - blockpos.getZ()) > this.renderDistanceChunks * 16 ? null : this.viewFrustum.getRenderChunk(blockpos)) : null); } protected Vector3f getViewVector(Entity entityIn, double partialTicks) @@ -1003,8 +1019,8 @@ public class RenderGlobal // { for (VertexFormatElement vertexformatelement : DefaultVertexFormats.BLOCK.getElements()) { - VertexFormatElement.EnumUsage vertexformatelement$enumusage = vertexformatelement.usage(); - int i = vertexformatelement.index(); + VertexFormatElement.EnumUsage vertexformatelement$enumusage = vertexformatelement.getUsage(); + int i = vertexformatelement.getIndex(); switch (vertexformatelement$enumusage) { @@ -1113,10 +1129,10 @@ public class RenderGlobal { this.renderSkyBox(this.gm.world.dimension.getSkyBoxTexture()); } - else if (this.gm.world.dimension.hasSky()) + else if (this.gm.world.dimension.getType().sky) { GlState.disableTexture2D(); - Vec3 vec3 = this.gm.entityRenderer.getSkyColor(this.gm.getRenderViewEntity(), partialTicks); + Vec3 vec3 = this.theWorld.getSkyColor(this.gm.getRenderViewEntity(), partialTicks); float f = (float)vec3.xCoord; float f1 = (float)vec3.yCoord; float f2 = (float)vec3.zCoord; @@ -1159,15 +1175,15 @@ public class RenderGlobal GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); ItemRenderer.disableStandardItemLighting(); - float[] afloat = this.theWorld.dimension.hasDaylight() && !this.theWorld.dimension.isBaseDestroyed() ? - RenderGlobal.calcSunriseSunsetColors(this.theWorld.getDayPhase(partialTicks), partialTicks) : null; + float[] afloat = this.theWorld.dimension.getType().days ? + RenderGlobal.calcSunriseSunsetColors(this.theWorld.getCelestialAngle(partialTicks), partialTicks) : null; if (afloat != null) { GlState.disableTexture2D(); GlState.shadeModel(GL11.GL_SMOOTH); GL11.glPushMatrix(); GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F); - GL11.glRotatef(ExtMath.sin(this.theWorld.getDayPhase(partialTicks)) < 0.0F ? 180.0F : 0.0F, 0.0F, 0.0F, 1.0F); + GL11.glRotatef(ExtMath.sin(this.theWorld.getCelestialAngleRadians(partialTicks)) < 0.0F ? 180.0F : 0.0F, 0.0F, 0.0F, 1.0F); GL11.glRotatef(90.0F, 0.0F, 0.0F, 1.0F); float f6 = afloat[0]; float f7 = afloat[1]; @@ -1204,57 +1220,42 @@ public class RenderGlobal GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE, GL11.GL_ZERO); GL11.glPushMatrix(); float f16 = 1.0F - Math.max(this.theWorld.getRainStrength(), this.theWorld.getFogStrength()); + GlState.color(1.0F, 1.0F, 1.0F, f16); GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F); - GL11.glRotatef(this.theWorld.getCelestialAngle(partialTicks), 1.0F, 0.0F, 0.0F); - if(this.gm.world.dimension.getType() == DimType.PLANET || this.gm.world.dimension.getType() == DimType.MOON) { + GL11.glRotatef(this.theWorld.getCelestialAngle(partialTicks) * 360.0F, 1.0F, 0.0F, 0.0F); + if(this.gm.world.dimension.getType().sun) { float size = 30.0F; - int color = this.gm.world.dimension.getSunColor(); - if(color != 0xffffffff) { - this.renderEngine.bindTexture((color & 0xff000000) != 0 ? EXTERMINATED_TEX : SUN_TEX); - Vec3 ncolor = new Vec3(color); - float mul = Math.min(1.0f / (float)ncolor.xCoord, Math.min(1.0f / (float)ncolor.yCoord, 1.0f / (float)ncolor.zCoord)); - GlState.color((float)ncolor.xCoord * mul, (float)ncolor.yCoord * mul, (float)ncolor.zCoord * mul, f16); - worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); - worldrenderer.pos((double)(-size), 100.0D, (double)(-size)).tex(0.0D, 0.0D).endVertex(); - worldrenderer.pos((double)size, 100.0D, (double)(-size)).tex(1.0D, 0.0D).endVertex(); - worldrenderer.pos((double)size, 100.0D, (double)size).tex(1.0D, 1.0D).endVertex(); - worldrenderer.pos((double)(-size), 100.0D, (double)size).tex(0.0D, 1.0D).endVertex(); - Tessellator.draw(); - } - size = 20.0F; - int[] colors = this.gm.world.dimension.getMoonColors(); - this.rand.setSeed(this.gm.world.dimension.getSeed()); - int mx = 0; - int mz = 0; - for(int z = 0; z < colors.length; z++) { - boolean destroyed = (colors[z] & 0xff000000) != 0; - this.renderEngine.bindTexture(destroyed ? EXTERMINATED_TEX : (this.gm.world.dimension.getType() == DimType.MOON ? PLANET_TEX : MOON_TEX)); - Vec3 ncolor = new Vec3(colors[z]); - float mul = Math.min(1.0f / (float)ncolor.xCoord, Math.min(1.0f / (float)ncolor.yCoord, 1.0f / (float)ncolor.zCoord)); - GlState.color((float)ncolor.xCoord * mul, (float)ncolor.yCoord * mul, (float)ncolor.zCoord * mul, f16); - int phase = this.theWorld.getMoonPhase(z); - int tx = phase % 4; - int ty = phase / 4 % 2; - float u1 = destroyed ? 0.0f : (float)(tx + 0) / 4.0F; - float v1 = destroyed ? 0.0f : (float)(ty + 0) / 2.0F; - float u2 = destroyed ? 1.0f : (float)(tx + 1) / 4.0F; - float v2 = destroyed ? 1.0f : (float)(ty + 1) / 2.0F; - worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); - worldrenderer.pos((double)(-size + mx), -100.0D, (double)(size + mz)).tex((double)u2, (double)v2).endVertex(); - worldrenderer.pos((double)(size + mx), -100.0D, (double)(size + mz)).tex((double)u1, (double)v2).endVertex(); - worldrenderer.pos((double)(size + mx), -100.0D, (double)(-size + mz)).tex((double)u1, (double)v1).endVertex(); - worldrenderer.pos((double)(-size + mx), -100.0D, (double)(-size + mz)).tex((double)u2, (double)v1).endVertex(); - Tessellator.draw(); - mx = this.rand.range(-60, 60); - mz = this.rand.range(-80, 80); - } + this.renderEngine.bindTexture(SUN_TEX); + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); + worldrenderer.pos((double)(-size), 100.0D, (double)(-size)).tex(0.0D, 0.0D).endVertex(); + worldrenderer.pos((double)size, 100.0D, (double)(-size)).tex(1.0D, 0.0D).endVertex(); + worldrenderer.pos((double)size, 100.0D, (double)size).tex(1.0D, 1.0D).endVertex(); + worldrenderer.pos((double)(-size), 100.0D, (double)size).tex(0.0D, 1.0D).endVertex(); + Tessellator.draw(); + } + if(this.gm.world.dimension.getType().moon) { + float size = 20.0F; + this.renderEngine.bindTexture(MOON_TEX); + int i = this.theWorld.getMoonPhase(); + int k = i % 4; + int i1 = i / 4 % 2; + float f22 = (float)(k + 0) / 4.0F; + float f23 = (float)(i1 + 0) / 2.0F; + float f24 = (float)(k + 1) / 4.0F; + float f14 = (float)(i1 + 1) / 2.0F; + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); + worldrenderer.pos((double)(-size), -100.0D, (double)size).tex((double)f24, (double)f14).endVertex(); + worldrenderer.pos((double)size, -100.0D, (double)size).tex((double)f22, (double)f14).endVertex(); + worldrenderer.pos((double)size, -100.0D, (double)(-size)).tex((double)f22, (double)f23).endVertex(); + worldrenderer.pos((double)(-size), -100.0D, (double)(-size)).tex((double)f24, (double)f23).endVertex(); + Tessellator.draw(); } GlState.disableTexture2D(); - float f15 = this.gm.entityRenderer.getStarBrightness(partialTicks) * f16; + float f15 = this.theWorld.getStarBrightness(partialTicks) * f16; if (f15 > 0.0F) { - int stars = this.theWorld.dimension.getStarColor(this.theWorld.getRotation()); + int stars = this.theWorld.dimension.getStarColor(this.theWorld.getDayTime()); if(stars == 0xffffffff) { GlState.color(f15, f15, f15, f15); } @@ -1278,10 +1279,10 @@ public class RenderGlobal // } } - f15 = this.gm.entityRenderer.getDeepStarBrightness(partialTicks) * f16; + f15 = this.theWorld.getDeepStarBrightness(partialTicks) * f16; if (f15 > 0.0F) { - int stars = this.theWorld.dimension.getDeepStarColor(this.theWorld.getRotation()); + int stars = this.theWorld.dimension.getDeepStarColor(this.theWorld.getDayTime()); if(stars == 0xffffffff) { GlState.color(f15, f15, f15, f15); } @@ -1315,7 +1316,7 @@ public class RenderGlobal } } - public void renderClouds(float alpha, float partialTicks) + public void renderClouds(float partialTicks) { GlState.disableCull(); float f = (float)(this.gm.getRenderViewEntity().lastTickPosY + (this.gm.getRenderViewEntity().posY - this.gm.getRenderViewEntity().lastTickPosY) * (double)partialTicks); @@ -1334,7 +1335,7 @@ public class RenderGlobal this.renderEngine.bindTexture(this.gm.world.dimension.getCloudTexture()); GlState.enableBlend(); GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); - Vec3 vec3 = this.gm.entityRenderer.getCloudColor(this.gm.getRenderViewEntity(), partialTicks); + Vec3 vec3 = this.theWorld.getCloudColour(this.gm.getRenderViewEntity(), partialTicks); float f4 = (float)vec3.xCoord; float f5 = (float)vec3.yCoord; float f6 = (float)vec3.zCoord; @@ -1403,28 +1404,28 @@ public class RenderGlobal if (f3 > -5.0F) { - worldrenderer.pos((double)(f24 + 0.0F), (double)(f3 + 0.0F), (double)(f25 + 8.0F)).tex((double)((f22 + 0.0F) * 0.00390625F + f17), (double)((f23 + 8.0F) * 0.00390625F + f18)).color(f10, f11, f12, alpha).normal(0.0F, -1.0F, 0.0F).endVertex(); - worldrenderer.pos((double)(f24 + 8.0F), (double)(f3 + 0.0F), (double)(f25 + 8.0F)).tex((double)((f22 + 8.0F) * 0.00390625F + f17), (double)((f23 + 8.0F) * 0.00390625F + f18)).color(f10, f11, f12, alpha).normal(0.0F, -1.0F, 0.0F).endVertex(); - worldrenderer.pos((double)(f24 + 8.0F), (double)(f3 + 0.0F), (double)(f25 + 0.0F)).tex((double)((f22 + 8.0F) * 0.00390625F + f17), (double)((f23 + 0.0F) * 0.00390625F + f18)).color(f10, f11, f12, alpha).normal(0.0F, -1.0F, 0.0F).endVertex(); - worldrenderer.pos((double)(f24 + 0.0F), (double)(f3 + 0.0F), (double)(f25 + 0.0F)).tex((double)((f22 + 0.0F) * 0.00390625F + f17), (double)((f23 + 0.0F) * 0.00390625F + f18)).color(f10, f11, f12, alpha).normal(0.0F, -1.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f24 + 0.0F), (double)(f3 + 0.0F), (double)(f25 + 8.0F)).tex((double)((f22 + 0.0F) * 0.00390625F + f17), (double)((f23 + 8.0F) * 0.00390625F + f18)).color(f10, f11, f12, 0.8F).normal(0.0F, -1.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f24 + 8.0F), (double)(f3 + 0.0F), (double)(f25 + 8.0F)).tex((double)((f22 + 8.0F) * 0.00390625F + f17), (double)((f23 + 8.0F) * 0.00390625F + f18)).color(f10, f11, f12, 0.8F).normal(0.0F, -1.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f24 + 8.0F), (double)(f3 + 0.0F), (double)(f25 + 0.0F)).tex((double)((f22 + 8.0F) * 0.00390625F + f17), (double)((f23 + 0.0F) * 0.00390625F + f18)).color(f10, f11, f12, 0.8F).normal(0.0F, -1.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f24 + 0.0F), (double)(f3 + 0.0F), (double)(f25 + 0.0F)).tex((double)((f22 + 0.0F) * 0.00390625F + f17), (double)((f23 + 0.0F) * 0.00390625F + f18)).color(f10, f11, f12, 0.8F).normal(0.0F, -1.0F, 0.0F).endVertex(); } if (f3 <= 5.0F) { - worldrenderer.pos((double)(f24 + 0.0F), (double)(f3 + 4.0F - 9.765625E-4F), (double)(f25 + 8.0F)).tex((double)((f22 + 0.0F) * 0.00390625F + f17), (double)((f23 + 8.0F) * 0.00390625F + f18)).color(f4, f5, f6, alpha).normal(0.0F, 1.0F, 0.0F).endVertex(); - worldrenderer.pos((double)(f24 + 8.0F), (double)(f3 + 4.0F - 9.765625E-4F), (double)(f25 + 8.0F)).tex((double)((f22 + 8.0F) * 0.00390625F + f17), (double)((f23 + 8.0F) * 0.00390625F + f18)).color(f4, f5, f6, alpha).normal(0.0F, 1.0F, 0.0F).endVertex(); - worldrenderer.pos((double)(f24 + 8.0F), (double)(f3 + 4.0F - 9.765625E-4F), (double)(f25 + 0.0F)).tex((double)((f22 + 8.0F) * 0.00390625F + f17), (double)((f23 + 0.0F) * 0.00390625F + f18)).color(f4, f5, f6, alpha).normal(0.0F, 1.0F, 0.0F).endVertex(); - worldrenderer.pos((double)(f24 + 0.0F), (double)(f3 + 4.0F - 9.765625E-4F), (double)(f25 + 0.0F)).tex((double)((f22 + 0.0F) * 0.00390625F + f17), (double)((f23 + 0.0F) * 0.00390625F + f18)).color(f4, f5, f6, alpha).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f24 + 0.0F), (double)(f3 + 4.0F - 9.765625E-4F), (double)(f25 + 8.0F)).tex((double)((f22 + 0.0F) * 0.00390625F + f17), (double)((f23 + 8.0F) * 0.00390625F + f18)).color(f4, f5, f6, 0.8F).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f24 + 8.0F), (double)(f3 + 4.0F - 9.765625E-4F), (double)(f25 + 8.0F)).tex((double)((f22 + 8.0F) * 0.00390625F + f17), (double)((f23 + 8.0F) * 0.00390625F + f18)).color(f4, f5, f6, 0.8F).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f24 + 8.0F), (double)(f3 + 4.0F - 9.765625E-4F), (double)(f25 + 0.0F)).tex((double)((f22 + 8.0F) * 0.00390625F + f17), (double)((f23 + 0.0F) * 0.00390625F + f18)).color(f4, f5, f6, 0.8F).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f24 + 0.0F), (double)(f3 + 4.0F - 9.765625E-4F), (double)(f25 + 0.0F)).tex((double)((f22 + 0.0F) * 0.00390625F + f17), (double)((f23 + 0.0F) * 0.00390625F + f18)).color(f4, f5, f6, 0.8F).normal(0.0F, 1.0F, 0.0F).endVertex(); } if (j1 > -1) { for (int l1 = 0; l1 < 8; ++l1) { - worldrenderer.pos((double)(f24 + (float)l1 + 0.0F), (double)(f3 + 0.0F), (double)(f25 + 8.0F)).tex((double)((f22 + (float)l1 + 0.5F) * 0.00390625F + f17), (double)((f23 + 8.0F) * 0.00390625F + f18)).color(f26, f27, f28, alpha).normal(-1.0F, 0.0F, 0.0F).endVertex(); - worldrenderer.pos((double)(f24 + (float)l1 + 0.0F), (double)(f3 + 4.0F), (double)(f25 + 8.0F)).tex((double)((f22 + (float)l1 + 0.5F) * 0.00390625F + f17), (double)((f23 + 8.0F) * 0.00390625F + f18)).color(f26, f27, f28, alpha).normal(-1.0F, 0.0F, 0.0F).endVertex(); - worldrenderer.pos((double)(f24 + (float)l1 + 0.0F), (double)(f3 + 4.0F), (double)(f25 + 0.0F)).tex((double)((f22 + (float)l1 + 0.5F) * 0.00390625F + f17), (double)((f23 + 0.0F) * 0.00390625F + f18)).color(f26, f27, f28, alpha).normal(-1.0F, 0.0F, 0.0F).endVertex(); - worldrenderer.pos((double)(f24 + (float)l1 + 0.0F), (double)(f3 + 0.0F), (double)(f25 + 0.0F)).tex((double)((f22 + (float)l1 + 0.5F) * 0.00390625F + f17), (double)((f23 + 0.0F) * 0.00390625F + f18)).color(f26, f27, f28, alpha).normal(-1.0F, 0.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f24 + (float)l1 + 0.0F), (double)(f3 + 0.0F), (double)(f25 + 8.0F)).tex((double)((f22 + (float)l1 + 0.5F) * 0.00390625F + f17), (double)((f23 + 8.0F) * 0.00390625F + f18)).color(f26, f27, f28, 0.8F).normal(-1.0F, 0.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f24 + (float)l1 + 0.0F), (double)(f3 + 4.0F), (double)(f25 + 8.0F)).tex((double)((f22 + (float)l1 + 0.5F) * 0.00390625F + f17), (double)((f23 + 8.0F) * 0.00390625F + f18)).color(f26, f27, f28, 0.8F).normal(-1.0F, 0.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f24 + (float)l1 + 0.0F), (double)(f3 + 4.0F), (double)(f25 + 0.0F)).tex((double)((f22 + (float)l1 + 0.5F) * 0.00390625F + f17), (double)((f23 + 0.0F) * 0.00390625F + f18)).color(f26, f27, f28, 0.8F).normal(-1.0F, 0.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f24 + (float)l1 + 0.0F), (double)(f3 + 0.0F), (double)(f25 + 0.0F)).tex((double)((f22 + (float)l1 + 0.5F) * 0.00390625F + f17), (double)((f23 + 0.0F) * 0.00390625F + f18)).color(f26, f27, f28, 0.8F).normal(-1.0F, 0.0F, 0.0F).endVertex(); } } @@ -1432,10 +1433,10 @@ public class RenderGlobal { for (int i2 = 0; i2 < 8; ++i2) { - worldrenderer.pos((double)(f24 + (float)i2 + 1.0F - 9.765625E-4F), (double)(f3 + 0.0F), (double)(f25 + 8.0F)).tex((double)((f22 + (float)i2 + 0.5F) * 0.00390625F + f17), (double)((f23 + 8.0F) * 0.00390625F + f18)).color(f26, f27, f28, alpha).normal(1.0F, 0.0F, 0.0F).endVertex(); - worldrenderer.pos((double)(f24 + (float)i2 + 1.0F - 9.765625E-4F), (double)(f3 + 4.0F), (double)(f25 + 8.0F)).tex((double)((f22 + (float)i2 + 0.5F) * 0.00390625F + f17), (double)((f23 + 8.0F) * 0.00390625F + f18)).color(f26, f27, f28, alpha).normal(1.0F, 0.0F, 0.0F).endVertex(); - worldrenderer.pos((double)(f24 + (float)i2 + 1.0F - 9.765625E-4F), (double)(f3 + 4.0F), (double)(f25 + 0.0F)).tex((double)((f22 + (float)i2 + 0.5F) * 0.00390625F + f17), (double)((f23 + 0.0F) * 0.00390625F + f18)).color(f26, f27, f28, alpha).normal(1.0F, 0.0F, 0.0F).endVertex(); - worldrenderer.pos((double)(f24 + (float)i2 + 1.0F - 9.765625E-4F), (double)(f3 + 0.0F), (double)(f25 + 0.0F)).tex((double)((f22 + (float)i2 + 0.5F) * 0.00390625F + f17), (double)((f23 + 0.0F) * 0.00390625F + f18)).color(f26, f27, f28, alpha).normal(1.0F, 0.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f24 + (float)i2 + 1.0F - 9.765625E-4F), (double)(f3 + 0.0F), (double)(f25 + 8.0F)).tex((double)((f22 + (float)i2 + 0.5F) * 0.00390625F + f17), (double)((f23 + 8.0F) * 0.00390625F + f18)).color(f26, f27, f28, 0.8F).normal(1.0F, 0.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f24 + (float)i2 + 1.0F - 9.765625E-4F), (double)(f3 + 4.0F), (double)(f25 + 8.0F)).tex((double)((f22 + (float)i2 + 0.5F) * 0.00390625F + f17), (double)((f23 + 8.0F) * 0.00390625F + f18)).color(f26, f27, f28, 0.8F).normal(1.0F, 0.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f24 + (float)i2 + 1.0F - 9.765625E-4F), (double)(f3 + 4.0F), (double)(f25 + 0.0F)).tex((double)((f22 + (float)i2 + 0.5F) * 0.00390625F + f17), (double)((f23 + 0.0F) * 0.00390625F + f18)).color(f26, f27, f28, 0.8F).normal(1.0F, 0.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f24 + (float)i2 + 1.0F - 9.765625E-4F), (double)(f3 + 0.0F), (double)(f25 + 0.0F)).tex((double)((f22 + (float)i2 + 0.5F) * 0.00390625F + f17), (double)((f23 + 0.0F) * 0.00390625F + f18)).color(f26, f27, f28, 0.8F).normal(1.0F, 0.0F, 0.0F).endVertex(); } } @@ -1443,10 +1444,10 @@ public class RenderGlobal { for (int j2 = 0; j2 < 8; ++j2) { - worldrenderer.pos((double)(f24 + 0.0F), (double)(f3 + 4.0F), (double)(f25 + (float)j2 + 0.0F)).tex((double)((f22 + 0.0F) * 0.00390625F + f17), (double)((f23 + (float)j2 + 0.5F) * 0.00390625F + f18)).color(f13, f14, f15, alpha).normal(0.0F, 0.0F, -1.0F).endVertex(); - worldrenderer.pos((double)(f24 + 8.0F), (double)(f3 + 4.0F), (double)(f25 + (float)j2 + 0.0F)).tex((double)((f22 + 8.0F) * 0.00390625F + f17), (double)((f23 + (float)j2 + 0.5F) * 0.00390625F + f18)).color(f13, f14, f15, alpha).normal(0.0F, 0.0F, -1.0F).endVertex(); - worldrenderer.pos((double)(f24 + 8.0F), (double)(f3 + 0.0F), (double)(f25 + (float)j2 + 0.0F)).tex((double)((f22 + 8.0F) * 0.00390625F + f17), (double)((f23 + (float)j2 + 0.5F) * 0.00390625F + f18)).color(f13, f14, f15, alpha).normal(0.0F, 0.0F, -1.0F).endVertex(); - worldrenderer.pos((double)(f24 + 0.0F), (double)(f3 + 0.0F), (double)(f25 + (float)j2 + 0.0F)).tex((double)((f22 + 0.0F) * 0.00390625F + f17), (double)((f23 + (float)j2 + 0.5F) * 0.00390625F + f18)).color(f13, f14, f15, alpha).normal(0.0F, 0.0F, -1.0F).endVertex(); + worldrenderer.pos((double)(f24 + 0.0F), (double)(f3 + 4.0F), (double)(f25 + (float)j2 + 0.0F)).tex((double)((f22 + 0.0F) * 0.00390625F + f17), (double)((f23 + (float)j2 + 0.5F) * 0.00390625F + f18)).color(f13, f14, f15, 0.8F).normal(0.0F, 0.0F, -1.0F).endVertex(); + worldrenderer.pos((double)(f24 + 8.0F), (double)(f3 + 4.0F), (double)(f25 + (float)j2 + 0.0F)).tex((double)((f22 + 8.0F) * 0.00390625F + f17), (double)((f23 + (float)j2 + 0.5F) * 0.00390625F + f18)).color(f13, f14, f15, 0.8F).normal(0.0F, 0.0F, -1.0F).endVertex(); + worldrenderer.pos((double)(f24 + 8.0F), (double)(f3 + 0.0F), (double)(f25 + (float)j2 + 0.0F)).tex((double)((f22 + 8.0F) * 0.00390625F + f17), (double)((f23 + (float)j2 + 0.5F) * 0.00390625F + f18)).color(f13, f14, f15, 0.8F).normal(0.0F, 0.0F, -1.0F).endVertex(); + worldrenderer.pos((double)(f24 + 0.0F), (double)(f3 + 0.0F), (double)(f25 + (float)j2 + 0.0F)).tex((double)((f22 + 0.0F) * 0.00390625F + f17), (double)((f23 + (float)j2 + 0.5F) * 0.00390625F + f18)).color(f13, f14, f15, 0.8F).normal(0.0F, 0.0F, -1.0F).endVertex(); } } @@ -1454,10 +1455,10 @@ public class RenderGlobal { for (int k2 = 0; k2 < 8; ++k2) { - worldrenderer.pos((double)(f24 + 0.0F), (double)(f3 + 4.0F), (double)(f25 + (float)k2 + 1.0F - 9.765625E-4F)).tex((double)((f22 + 0.0F) * 0.00390625F + f17), (double)((f23 + (float)k2 + 0.5F) * 0.00390625F + f18)).color(f13, f14, f15, alpha).normal(0.0F, 0.0F, 1.0F).endVertex(); - worldrenderer.pos((double)(f24 + 8.0F), (double)(f3 + 4.0F), (double)(f25 + (float)k2 + 1.0F - 9.765625E-4F)).tex((double)((f22 + 8.0F) * 0.00390625F + f17), (double)((f23 + (float)k2 + 0.5F) * 0.00390625F + f18)).color(f13, f14, f15, alpha).normal(0.0F, 0.0F, 1.0F).endVertex(); - worldrenderer.pos((double)(f24 + 8.0F), (double)(f3 + 0.0F), (double)(f25 + (float)k2 + 1.0F - 9.765625E-4F)).tex((double)((f22 + 8.0F) * 0.00390625F + f17), (double)((f23 + (float)k2 + 0.5F) * 0.00390625F + f18)).color(f13, f14, f15, alpha).normal(0.0F, 0.0F, 1.0F).endVertex(); - worldrenderer.pos((double)(f24 + 0.0F), (double)(f3 + 0.0F), (double)(f25 + (float)k2 + 1.0F - 9.765625E-4F)).tex((double)((f22 + 0.0F) * 0.00390625F + f17), (double)((f23 + (float)k2 + 0.5F) * 0.00390625F + f18)).color(f13, f14, f15, alpha).normal(0.0F, 0.0F, 1.0F).endVertex(); + worldrenderer.pos((double)(f24 + 0.0F), (double)(f3 + 4.0F), (double)(f25 + (float)k2 + 1.0F - 9.765625E-4F)).tex((double)((f22 + 0.0F) * 0.00390625F + f17), (double)((f23 + (float)k2 + 0.5F) * 0.00390625F + f18)).color(f13, f14, f15, 0.8F).normal(0.0F, 0.0F, 1.0F).endVertex(); + worldrenderer.pos((double)(f24 + 8.0F), (double)(f3 + 4.0F), (double)(f25 + (float)k2 + 1.0F - 9.765625E-4F)).tex((double)((f22 + 8.0F) * 0.00390625F + f17), (double)((f23 + (float)k2 + 0.5F) * 0.00390625F + f18)).color(f13, f14, f15, 0.8F).normal(0.0F, 0.0F, 1.0F).endVertex(); + worldrenderer.pos((double)(f24 + 8.0F), (double)(f3 + 0.0F), (double)(f25 + (float)k2 + 1.0F - 9.765625E-4F)).tex((double)((f22 + 8.0F) * 0.00390625F + f17), (double)((f23 + (float)k2 + 0.5F) * 0.00390625F + f18)).color(f13, f14, f15, 0.8F).normal(0.0F, 0.0F, 1.0F).endVertex(); + worldrenderer.pos((double)(f24 + 0.0F), (double)(f3 + 0.0F), (double)(f25 + (float)k2 + 1.0F - 9.765625E-4F)).tex((double)((f22 + 0.0F) * 0.00390625F + f17), (double)((f23 + (float)k2 + 0.5F) * 0.00390625F + f18)).color(f13, f14, f15, 0.8F).normal(0.0F, 0.0F, 1.0F).endVertex(); } } @@ -1530,7 +1531,7 @@ public class RenderGlobal if (!this.damagedBlocks.isEmpty()) { - this.renderEngine.bindTexture(TextureMap.BLOCKS); + this.renderEngine.bindTexture(TextureMap.locationBlocksTexture); this.preRenderDamagedBlocks(); worldRendererIn.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); worldRendererIn.setTranslation(-d0, -d1, -d2); @@ -1546,20 +1547,23 @@ public class RenderGlobal double d5 = (double)blockpos.getZ() - d2; Block block = this.theWorld.getState(blockpos).getBlock(); - if (d3 * d3 + d4 * d4 + d5 * d5 > 1024.0D) + if (!(block instanceof BlockChest) && /* !(block instanceof BlockWarpChest) && */ !(block instanceof BlockSign) && !(block instanceof BlockSkull)) { - iterator.remove(); - } - else - { - State iblockstate = this.theWorld.getState(blockpos); - - if (iblockstate.getBlock() != Blocks.air) + if (d3 * d3 + d4 * d4 + d5 * d5 > 1024.0D) { - int i = destroyblockprogress.getPartialBlockDamage(); - Sprite textureatlassprite = this.destroyBlockIcons[i]; - BlockRenderer blockrendererdispatcher = this.gm.getBlockRendererDispatcher(); - blockrendererdispatcher.renderBlockDamage(iblockstate, blockpos, textureatlassprite, this.theWorld); + iterator.remove(); + } + else + { + State iblockstate = this.theWorld.getState(blockpos); + + if (iblockstate.getBlock().getMaterial() != Material.air) + { + int i = destroyblockprogress.getPartialBlockDamage(); + TextureAtlasSprite textureatlassprite = this.destroyBlockIcons[i]; + BlockRenderer blockrendererdispatcher = this.gm.getBlockRendererDispatcher(); + blockrendererdispatcher.renderBlockDamage(iblockstate, blockpos, textureatlassprite, this.theWorld); + } } } } @@ -1589,13 +1593,13 @@ public class RenderGlobal BlockPos blockpos = movingObjectPositionIn.block; Block block = this.theWorld.getState(blockpos).getBlock(); - if (block != Blocks.air) // && this.theWorld.getWorldBorder().contains(blockpos)) + if (block.getMaterial() != Material.air) // && this.theWorld.getWorldBorder().contains(blockpos)) { - block.setBlockBounds(this.theWorld, blockpos); + block.setBlockBoundsBasedOnState(this.theWorld, blockpos); double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double)partialTicks; double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double)partialTicks; double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double)partialTicks; - drawSelectionBoundingBox(block.getSelectionBox(this.theWorld, blockpos).expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D).offset(-d0, -d1, -d2)); + drawSelectionBoundingBox(block.getSelectedBoundingBox(this.theWorld, blockpos).expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D).offset(-d0, -d1, -d2)); } GlState.depthMask(true); @@ -1820,9 +1824,9 @@ public class RenderGlobal rand.setSeed(seed); } - public static float[] calcSunriseSunsetColors(float radians, float partial) { + public static float[] calcSunriseSunsetColors(float celestialAngle, float partialTicks) { float f = 0.4F; - float f1 = ExtMath.cos(radians) - 0.0F; + float f1 = ExtMath.cos(celestialAngle * (float)Math.PI * 2.0F) - 0.0F; float f2 = -0.0F; if(f1 >= f2 - f && f1 <= f2 + f) { diff --git a/client/src/main/java/client/renderer/Tessellator.java b/client/src/client/renderer/Tessellator.java similarity index 83% rename from client/src/main/java/client/renderer/Tessellator.java rename to client/src/client/renderer/Tessellator.java index c7d69b99..014e6582 100755 --- a/client/src/main/java/client/renderer/Tessellator.java +++ b/client/src/client/renderer/Tessellator.java @@ -28,27 +28,27 @@ public abstract class Tessellator for (int j = 0; j < list.size(); ++j) { VertexFormatElement vertexformatelement = (VertexFormatElement)list.get(j); - VertexFormatElement.EnumUsage vertexformatelement$enumusage = vertexformatelement.usage(); - int k = vertexformatelement.type().getGlConstant(); - int l = vertexformatelement.index(); + VertexFormatElement.EnumUsage vertexformatelement$enumusage = vertexformatelement.getUsage(); + int k = vertexformatelement.getType().getGlConstant(); + int l = vertexformatelement.getIndex(); bytebuffer.position(vertexformat.getOffset(j)); switch (vertexformatelement$enumusage) { case POSITION: - GL11.glVertexPointer(vertexformatelement.count(), k, i, bytebuffer); + GL11.glVertexPointer(vertexformatelement.getElementCount(), k, i, bytebuffer); GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); break; case UV: GL13.glClientActiveTexture(GL13.GL_TEXTURE0 + l); - GL11.glTexCoordPointer(vertexformatelement.count(), k, i, bytebuffer); + GL11.glTexCoordPointer(vertexformatelement.getElementCount(), k, i, bytebuffer); GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY); GL13.glClientActiveTexture(GL13.GL_TEXTURE0); break; case COLOR: - GL11.glColorPointer(vertexformatelement.count(), k, i, bytebuffer); + GL11.glColorPointer(vertexformatelement.getElementCount(), k, i, bytebuffer); GL11.glEnableClientState(GL11.GL_COLOR_ARRAY); break; @@ -64,8 +64,8 @@ public abstract class Tessellator for (int j1 = list.size(); i1 < j1; ++i1) { VertexFormatElement vertexformatelement1 = (VertexFormatElement)list.get(i1); - VertexFormatElement.EnumUsage vertexformatelement$enumusage1 = vertexformatelement1.usage(); - int k1 = vertexformatelement1.index(); + VertexFormatElement.EnumUsage vertexformatelement$enumusage1 = vertexformatelement1.getUsage(); + int k1 = vertexformatelement1.getIndex(); switch (vertexformatelement$enumusage1) { diff --git a/client/src/client/renderer/VertexBuffer.java b/client/src/client/renderer/VertexBuffer.java new file mode 100755 index 00000000..ee8a33e7 --- /dev/null +++ b/client/src/client/renderer/VertexBuffer.java @@ -0,0 +1,51 @@ +package client.renderer; + +import java.nio.ByteBuffer; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL15; + +public class VertexBuffer +{ + private int glBufferId; + private final VertexFormat vertexFormat; + private int count; + + public VertexBuffer(VertexFormat vertexFormatIn) + { + this.vertexFormat = vertexFormatIn; + this.glBufferId = GL15.glGenBuffers(); + } + + public void bindBuffer() + { + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.glBufferId); + } + + public void bufferData(ByteBuffer buffer) + { + this.bindBuffer(); + GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); + this.unbindBuffer(); + this.count = buffer.limit() / this.vertexFormat.getNextOffset(); + } + + public void drawArrays(int mode) + { + GL11.glDrawArrays(mode, 0, this.count); + } + + public void unbindBuffer() + { + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + } + + public void deleteGlBuffers() + { + if (this.glBufferId >= 0) + { + GL15.glDeleteBuffers(this.glBufferId); + this.glBufferId = -1; + } + } +} diff --git a/client/src/main/java/client/renderer/VertexFormat.java b/client/src/client/renderer/VertexFormat.java similarity index 89% rename from client/src/main/java/client/renderer/VertexFormat.java rename to client/src/client/renderer/VertexFormat.java index 35717324..d8c6e93d 100755 --- a/client/src/main/java/client/renderer/VertexFormat.java +++ b/client/src/client/renderer/VertexFormat.java @@ -10,6 +10,7 @@ public class VertexFormat private final List elements; private final List offsets; + /** The next available offset in this vertex format */ private int nextOffset; private int colorElementOffset; private List uvOffsetsById; @@ -50,9 +51,9 @@ public class VertexFormat public VertexFormat addElement(VertexFormatElement element) { - if (element.isPosition() && this.hasPosition()) + if (element.isPositionElement() && this.hasPosition()) { - Log.RENDER.warn("VertexFormat-Fehler: Versuche eine Position vom Typ VertexFormatElement hinzuzufügen, während eine bereits existiert, ignoriere."); + Log.JNI.warn("VertexFormat-Fehler: Versuche eine Position vom Typ VertexFormatElement hinzuzufügen, während eine bereits existiert, ignoriere."); return this; } else @@ -60,7 +61,7 @@ public class VertexFormat this.elements.add(element); this.offsets.add(Integer.valueOf(this.nextOffset)); - switch (element.usage()) + switch (element.getUsage()) { case NORMAL: this.normalElementOffset = this.nextOffset; @@ -71,10 +72,10 @@ public class VertexFormat break; case UV: - this.uvOffsetsById.add(element.index(), Integer.valueOf(this.nextOffset)); + this.uvOffsetsById.add(element.getIndex(), Integer.valueOf(this.nextOffset)); } - this.nextOffset += element.size(); + this.nextOffset += element.getSize(); return this; } } @@ -134,7 +135,7 @@ public class VertexFormat { VertexFormatElement vertexformatelement = (VertexFormatElement)this.elements.get(i); - if (vertexformatelement.isPosition()) + if (vertexformatelement.isPositionElement()) { return true; } diff --git a/client/src/client/renderer/VertexFormatElement.java b/client/src/client/renderer/VertexFormatElement.java new file mode 100755 index 00000000..4ff21165 --- /dev/null +++ b/client/src/client/renderer/VertexFormatElement.java @@ -0,0 +1,156 @@ +package client.renderer; + +import org.lwjgl.opengl.GL11; + +import common.log.Log; + +public class VertexFormatElement +{ + private final VertexFormatElement.EnumType type; + private final VertexFormatElement.EnumUsage usage; + private int index; + private int elementCount; + + public VertexFormatElement(int indexIn, VertexFormatElement.EnumType typeIn, VertexFormatElement.EnumUsage usageIn, int count) + { + if (!this.isValid(indexIn, usageIn)) + { + Log.JNI.warn("Mehrere Vertex-Elemente des gleichen Typs außer UVs sind nicht unterstützt. Erzwinge Typ UV."); + this.usage = VertexFormatElement.EnumUsage.UV; + } + else + { + this.usage = usageIn; + } + + this.type = typeIn; + this.index = indexIn; + this.elementCount = count; + } + + private final boolean isValid(int index, VertexFormatElement.EnumUsage usage) + { + return index == 0 || usage == VertexFormatElement.EnumUsage.UV; + } + + public final VertexFormatElement.EnumType getType() + { + return this.type; + } + + public final VertexFormatElement.EnumUsage getUsage() + { + return this.usage; + } + + public final int getElementCount() + { + return this.elementCount; + } + + public final int getIndex() + { + return this.index; + } + + public String toString() + { + return this.elementCount + "," + this.usage.getDisplayName() + "," + this.type.getDisplayName(); + } + + public final int getSize() + { + return this.type.getSize() * this.elementCount; + } + + public final boolean isPositionElement() + { + return this.usage == VertexFormatElement.EnumUsage.POSITION; + } + + public boolean equals(Object p_equals_1_) + { + if (this == p_equals_1_) + { + return true; + } + else if (p_equals_1_ != null && this.getClass() == p_equals_1_.getClass()) + { + VertexFormatElement vertexformatelement = (VertexFormatElement)p_equals_1_; + return this.elementCount != vertexformatelement.elementCount ? false : (this.index != vertexformatelement.index ? false : (this.type != vertexformatelement.type ? false : this.usage == vertexformatelement.usage)); + } + else + { + return false; + } + } + + public int hashCode() + { + int i = this.type.hashCode(); + i = 31 * i + this.usage.hashCode(); + i = 31 * i + this.index; + i = 31 * i + this.elementCount; + return i; + } + + public static enum EnumType + { + FLOAT(4, "Float", GL11.GL_FLOAT), + UBYTE(1, "Unsigned Byte", GL11.GL_UNSIGNED_BYTE), + BYTE(1, "Byte", GL11.GL_BYTE), + USHORT(2, "Unsigned Short", GL11.GL_UNSIGNED_SHORT), + SHORT(2, "Short", GL11.GL_SHORT), + UINT(4, "Unsigned Int", GL11.GL_UNSIGNED_INT), + INT(4, "Int", GL11.GL_INT); + + private final int size; + private final String displayName; + private final int glConstant; + + private EnumType(int sizeIn, String displayNameIn, int glConstantIn) + { + this.size = sizeIn; + this.displayName = displayNameIn; + this.glConstant = glConstantIn; + } + + public int getSize() + { + return this.size; + } + + public String getDisplayName() + { + return this.displayName; + } + + public int getGlConstant() + { + return this.glConstant; + } + } + + public static enum EnumUsage + { + POSITION("Position"), + NORMAL("Normal"), + COLOR("Vertex Color"), + UV("UV"), +// MATRIX("Bone Matrix"), +// BLEND_WEIGHT("Blend Weight"), + PADDING("Padding"); + + private final String displayName; + + private EnumUsage(String displayNameIn) + { + this.displayName = displayNameIn; + } + + public String getDisplayName() + { + return this.displayName; + } + } +} diff --git a/client/src/main/java/client/renderer/ViewFrustum.java b/client/src/client/renderer/ViewFrustum.java similarity index 84% rename from client/src/main/java/client/renderer/ViewFrustum.java rename to client/src/client/renderer/ViewFrustum.java index 0a71fc9b..df65bd65 100755 --- a/client/src/main/java/client/renderer/ViewFrustum.java +++ b/client/src/client/renderer/ViewFrustum.java @@ -1,14 +1,14 @@ package client.renderer; import client.renderer.chunk.RenderChunk; -import client.Client; import common.util.BlockPos; import common.util.ExtMath; +import common.world.World; public class ViewFrustum { protected final RenderGlobal renderGlobal; - protected final Client gm; + protected final World world; protected int countChunksY; protected int countChunksX; protected int countChunksZ; @@ -18,10 +18,10 @@ public class ViewFrustum return i < 0 ? -((-i - 1) / 16) - 1 : i / 16; } - public ViewFrustum(Client worldIn, int renderDistanceChunks, RenderGlobal p_i46246_3_) + public ViewFrustum(World worldIn, int renderDistanceChunks, RenderGlobal p_i46246_3_) { this.renderGlobal = p_i46246_3_; - this.gm = worldIn; + this.world = worldIn; this.setCountChunksXYZ(renderDistanceChunks); this.createRenderChunks(); } @@ -40,7 +40,7 @@ public class ViewFrustum { int j1 = (i1 * this.countChunksY + l) * this.countChunksX + k; BlockPos blockpos = new BlockPos(k * 16, l * 16, i1 * 16); - this.renderChunks[j1] = new RenderChunk(this.gm, this.renderGlobal, blockpos, j++); + this.renderChunks[j1] = new RenderChunk(this.world, this.renderGlobal, blockpos, j++); } } } @@ -58,14 +58,13 @@ public class ViewFrustum { int i = renderDistanceChunks * 2 + 1; this.countChunksX = i; - this.countChunksY = i; + this.countChunksY = 32; this.countChunksZ = i; } - public void updateChunkPositions(double viewEntityX, double viewEntityY, double viewEntityZ) + public void updateChunkPositions(double viewEntityX, double viewEntityZ) { int i = ExtMath.floord(viewEntityX) - 8; - int n = ExtMath.floord(viewEntityY) - 8; int j = ExtMath.floord(viewEntityZ) - 8; int k = this.countChunksX * 16; @@ -79,7 +78,7 @@ public class ViewFrustum for (int l1 = 0; l1 < this.countChunksY; ++l1) { - int i2 = this.func_178157_a(n, k, l1); + int i2 = l1 * 16; RenderChunk renderchunk = this.renderChunks[(j1 * this.countChunksY + l1) * this.countChunksX + l]; BlockPos blockpos = new BlockPos(i1, i2, k1); @@ -155,28 +154,28 @@ public class ViewFrustum int y = bucketInt(pos.getY()); int z = bucketInt(pos.getZ()); - x = x % this.countChunksX; - - if (x < 0) + if (y >= 0 && y < this.countChunksY) { - x += this.countChunksX; + x = x % this.countChunksX; + + if (x < 0) + { + x += this.countChunksX; + } + + z = z % this.countChunksZ; + + if (z < 0) + { + z += this.countChunksZ; + } + + int p = (z * this.countChunksY + y) * this.countChunksX + x; + return this.renderChunks[p]; } - - y = y % this.countChunksY; - - if (y < 0) + else { - y += this.countChunksY; + return null; } - - z = z % this.countChunksZ; - - if (z < 0) - { - z += this.countChunksZ; - } - - int p = (z * this.countChunksY + y) * this.countChunksX + x; - return this.renderChunks[p]; } } diff --git a/client/src/client/renderer/blockmodel/BakedModel.java b/client/src/client/renderer/blockmodel/BakedModel.java new file mode 100755 index 00000000..d3835231 --- /dev/null +++ b/client/src/client/renderer/blockmodel/BakedModel.java @@ -0,0 +1,153 @@ +package client.renderer.blockmodel; + +import java.util.ArrayList; +import java.util.List; + +import client.renderer.texture.TextureAtlasSprite; +import common.collect.Lists; +import common.model.Transforms; +import common.util.Facing; + +public class BakedModel implements IBakedModel +{ + protected final List generalQuads; + protected final List> faceQuads; + protected final boolean ambientOcclusion; + protected final boolean gui3d; + protected final TextureAtlasSprite texture; + protected final Transforms cameraTransforms; + + public BakedModel(List generalQuadsIn, List> faceQuadsIn, boolean ambientOcclusionIn, boolean gui3dIn, TextureAtlasSprite textureIn, Transforms cameraTransformsIn) + { + this.generalQuads = generalQuadsIn; + this.faceQuads = faceQuadsIn; + this.ambientOcclusion = ambientOcclusionIn; + this.gui3d = gui3dIn; + this.texture = textureIn; + this.cameraTransforms = cameraTransformsIn; + } + + public List getFaceQuads(Facing facing) + { + return this.faceQuads.get(facing.ordinal()); + } + + public List getGeneralQuads() + { + return this.generalQuads; + } + + public boolean isAmbientOcclusion() + { + return this.ambientOcclusion; + } + + public boolean isGui3d() + { + return this.gui3d; + } + + public boolean isBuiltInRenderer() + { + return false; + } + + public TextureAtlasSprite getParticleTexture() + { + return this.texture; + } + + public Transforms getItemCameraTransforms() + { + return this.cameraTransforms; + } + + public static class Builder + { + private final List builderGeneralQuads; + private final List> builderFaceQuads; + private final boolean builderAmbientOcclusion; + private TextureAtlasSprite builderTexture; + private boolean builderGui3d; + private Transforms builderCameraTransforms; + + public Builder(ModelBlock model) + { + this(model.isAmbientOcclusion(), model.isGui3d(), model.getTransform()); + } + + public Builder(IBakedModel bakedModel, TextureAtlasSprite texture) + { + this(bakedModel.isAmbientOcclusion(), bakedModel.isGui3d(), bakedModel.getItemCameraTransforms()); + this.builderTexture = bakedModel.getParticleTexture(); + + for (Facing enumfacing : Facing.values()) + { + this.addFaceBreakingFours(bakedModel, texture, enumfacing); + } + + this.addGeneralBreakingFours(bakedModel, texture); + } + + private void addFaceBreakingFours(IBakedModel bakedModel, TextureAtlasSprite texture, Facing facing) + { + for (BakedQuad bakedquad : bakedModel.getFaceQuads(facing)) + { + this.addFaceQuad(facing, new BreakingFour(bakedquad, texture)); + } + } + + private void addGeneralBreakingFours(IBakedModel p_177647_1_, TextureAtlasSprite texture) + { + for (BakedQuad bakedquad : p_177647_1_.getGeneralQuads()) + { + this.addGeneralQuad(new BreakingFour(bakedquad, texture)); + } + } + + private Builder(boolean ambientOcclusion, boolean gui3d, Transforms cameraTransforms) + { + this.builderGeneralQuads = Lists.newArrayList(); + this.builderFaceQuads = new ArrayList>(6); + + for (Facing enumfacing : Facing.values()) + { + this.builderFaceQuads.add(Lists.newArrayList()); + } + + this.builderAmbientOcclusion = ambientOcclusion; + this.builderGui3d = gui3d; + this.builderCameraTransforms = cameraTransforms; + } + + public BakedModel.Builder addFaceQuad(Facing facing, BakedQuad quad) + { + ((List)this.builderFaceQuads.get(facing.ordinal())).add(quad); + return this; + } + + public BakedModel.Builder addGeneralQuad(BakedQuad quad) + { + this.builderGeneralQuads.add(quad); + return this; + } + + public BakedModel.Builder setTexture(TextureAtlasSprite texture) + { + this.builderTexture = texture; + return this; + } + + public BakedModel makeBakedModel() + { + if (this.builderTexture == null) + { + throw new RuntimeException("Missing particle!"); + } + else + { + return new BakedModel(this.builderGeneralQuads, this.builderFaceQuads, this.builderAmbientOcclusion, this.builderGui3d, this.builderTexture, this.builderCameraTransforms); + } + } + } +} diff --git a/client/src/main/java/client/renderer/blockmodel/BakedQuad.java b/client/src/client/renderer/blockmodel/BakedQuad.java similarity index 100% rename from client/src/main/java/client/renderer/blockmodel/BakedQuad.java rename to client/src/client/renderer/blockmodel/BakedQuad.java diff --git a/client/src/main/java/client/renderer/blockmodel/BlockFaceUV.java b/client/src/client/renderer/blockmodel/BlockFaceUV.java similarity index 100% rename from client/src/main/java/client/renderer/blockmodel/BlockFaceUV.java rename to client/src/client/renderer/blockmodel/BlockFaceUV.java diff --git a/client/src/main/java/client/renderer/blockmodel/BlockPart.java b/client/src/client/renderer/blockmodel/BlockPart.java similarity index 100% rename from client/src/main/java/client/renderer/blockmodel/BlockPart.java rename to client/src/client/renderer/blockmodel/BlockPart.java diff --git a/client/src/main/java/client/renderer/blockmodel/BlockPartFace.java b/client/src/client/renderer/blockmodel/BlockPartFace.java similarity index 81% rename from client/src/main/java/client/renderer/blockmodel/BlockPartFace.java rename to client/src/client/renderer/blockmodel/BlockPartFace.java index b5867c9c..03791d7b 100755 --- a/client/src/main/java/client/renderer/blockmodel/BlockPartFace.java +++ b/client/src/client/renderer/blockmodel/BlockPartFace.java @@ -12,7 +12,7 @@ public class BlockPartFace { public BlockPartFace(Facing cull, int tint, String texture, BlockFaceUV uv) { this.cull = cull; this.tint = tint; - this.texture = texture == null ? TextureMap.MISSING : texture; + this.texture = texture == null ? TextureMap.LOCATION_MISSING_TEXTURE : texture; this.uv = uv; } } diff --git a/client/src/main/java/client/renderer/blockmodel/BlockPartRotation.java b/client/src/client/renderer/blockmodel/BlockPartRotation.java similarity index 100% rename from client/src/main/java/client/renderer/blockmodel/BlockPartRotation.java rename to client/src/client/renderer/blockmodel/BlockPartRotation.java diff --git a/client/src/main/java/client/renderer/blockmodel/BreakingFour.java b/client/src/client/renderer/blockmodel/BreakingFour.java similarity index 90% rename from client/src/main/java/client/renderer/blockmodel/BreakingFour.java rename to client/src/client/renderer/blockmodel/BreakingFour.java index 7e4d04eb..ec2cbc97 100755 --- a/client/src/main/java/client/renderer/blockmodel/BreakingFour.java +++ b/client/src/client/renderer/blockmodel/BreakingFour.java @@ -2,13 +2,13 @@ package client.renderer.blockmodel; import java.util.Arrays; -import client.renderer.texture.Sprite; +import client.renderer.texture.TextureAtlasSprite; public class BreakingFour extends BakedQuad { - private final Sprite texture; + private final TextureAtlasSprite texture; - public BreakingFour(BakedQuad quad, Sprite texture) { + public BreakingFour(BakedQuad quad, TextureAtlasSprite texture) { super(Arrays.copyOf(quad.getVertexData(), quad.getVertexData().length), quad.tint, FaceBakery.getFacingFromVertexData(quad.getVertexData())); this.texture = texture; diff --git a/client/src/client/renderer/blockmodel/BuiltInModel.java b/client/src/client/renderer/blockmodel/BuiltInModel.java new file mode 100755 index 00000000..802fcc9a --- /dev/null +++ b/client/src/client/renderer/blockmodel/BuiltInModel.java @@ -0,0 +1,52 @@ +package client.renderer.blockmodel; + +import java.util.List; + +import client.renderer.texture.TextureAtlasSprite; +import common.model.Transforms; +import common.util.Facing; + +public class BuiltInModel implements IBakedModel +{ + private Transforms cameraTransforms; + + public BuiltInModel(Transforms p_i46086_1_) + { + this.cameraTransforms = p_i46086_1_; + } + + public List getFaceQuads(Facing facing) + { + return null; + } + + public List getGeneralQuads() + { + return null; + } + + public boolean isAmbientOcclusion() + { + return false; + } + + public boolean isGui3d() + { + return true; + } + + public boolean isBuiltInRenderer() + { + return true; + } + + public TextureAtlasSprite getParticleTexture() + { + return null; + } + + public Transforms getItemCameraTransforms() + { + return this.cameraTransforms; + } +} diff --git a/client/src/main/java/client/renderer/blockmodel/FaceBakery.java b/client/src/client/renderer/blockmodel/FaceBakery.java similarity index 95% rename from client/src/main/java/client/renderer/blockmodel/FaceBakery.java rename to client/src/client/renderer/blockmodel/FaceBakery.java index 68808bb8..cb73b49e 100755 --- a/client/src/main/java/client/renderer/blockmodel/FaceBakery.java +++ b/client/src/client/renderer/blockmodel/FaceBakery.java @@ -1,6 +1,6 @@ package client.renderer.blockmodel; -import client.renderer.texture.Sprite; +import client.renderer.texture.TextureAtlasSprite; import common.model.ModelRotation; import common.util.ExtMath; import common.util.Facing; @@ -73,7 +73,7 @@ public class FaceBakery FACINGS[Constants.EAST_INDEX] = EnumFaceDirection.EAST; } - public BakedQuad makeBakedQuad(Vector3f posFrom, Vector3f posTo, BlockPartFace face, Sprite sprite, Facing facing, ModelRotation modelRotationIn, BlockPartRotation partRotation, boolean uvLocked, boolean shade) + public BakedQuad makeBakedQuad(Vector3f posFrom, Vector3f posTo, BlockPartFace face, TextureAtlasSprite sprite, Facing facing, ModelRotation modelRotationIn, BlockPartRotation partRotation, boolean uvLocked, boolean shade) { int[] aint = this.makeQuadVertexData(face, sprite, facing, this.getPositionsDiv16(posFrom, posTo), modelRotationIn, partRotation, uvLocked, shade); Facing enumfacing = getFacingFromVertexData(aint); @@ -91,7 +91,7 @@ public class FaceBakery return new BakedQuad(aint, face.tint, enumfacing); } - private int[] makeQuadVertexData(BlockPartFace partFace, Sprite sprite, Facing facing, float[] p_178405_4_, ModelRotation modelRotationIn, BlockPartRotation partRotation, boolean uvLocked, boolean shade) + private int[] makeQuadVertexData(BlockPartFace partFace, TextureAtlasSprite sprite, Facing facing, float[] p_178405_4_, ModelRotation modelRotationIn, BlockPartRotation partRotation, boolean uvLocked, boolean shade) { int[] aint = new int[28]; @@ -145,7 +145,7 @@ public class FaceBakery return afloat; } - private void fillVertexData(int[] faceData, int vertexIndex, Facing facing, BlockPartFace partFace, float[] p_178402_5_, Sprite sprite, ModelRotation modelRotationIn, BlockPartRotation partRotation, boolean uvLocked, boolean shade) + private void fillVertexData(int[] faceData, int vertexIndex, Facing facing, BlockPartFace partFace, float[] p_178402_5_, TextureAtlasSprite sprite, ModelRotation modelRotationIn, BlockPartRotation partRotation, boolean uvLocked, boolean shade) { Facing enumfacing = modelRotationIn.rotateFace(facing); int i = shade ? this.getFaceShadeColor(enumfacing) : -1; @@ -156,7 +156,7 @@ public class FaceBakery this.storeVertexData(faceData, j, vertexIndex, vector3f, i, sprite, partFace.uv); } - private void storeVertexData(int[] faceData, int storeIndex, int vertexIndex, Vector3f position, int shadeColor, Sprite sprite, BlockFaceUV faceUV) + private void storeVertexData(int[] faceData, int storeIndex, int vertexIndex, Vector3f position, int shadeColor, TextureAtlasSprite sprite, BlockFaceUV faceUV) { int i = storeIndex * 7; faceData[i] = Float.floatToRawIntBits(position.x); @@ -284,7 +284,7 @@ public class FaceBakery } } - public void lockUv(int[] p_178409_1_, Facing facing, BlockFaceUV p_178409_3_, Sprite p_178409_4_) + public void lockUv(int[] p_178409_1_, Facing facing, BlockFaceUV p_178409_3_, TextureAtlasSprite p_178409_4_) { for (int i = 0; i < 4; ++i) { @@ -371,7 +371,7 @@ public class FaceBakery } } - private void lockVertexUv(int p_178401_1_, int[] p_178401_2_, Facing facing, BlockFaceUV p_178401_4_, Sprite p_178401_5_) + private void lockVertexUv(int p_178401_1_, int[] p_178401_2_, Facing facing, BlockFaceUV p_178401_4_, TextureAtlasSprite p_178401_5_) { int i = 7 * p_178401_1_; float f = Float.intBitsToFloat(p_178401_2_[i]); diff --git a/client/src/client/renderer/blockmodel/IBakedModel.java b/client/src/client/renderer/blockmodel/IBakedModel.java new file mode 100755 index 00000000..490f71ba --- /dev/null +++ b/client/src/client/renderer/blockmodel/IBakedModel.java @@ -0,0 +1,24 @@ +package client.renderer.blockmodel; + +import java.util.List; + +import client.renderer.texture.TextureAtlasSprite; +import common.model.Transforms; +import common.util.Facing; + +public interface IBakedModel +{ + List getFaceQuads(Facing facing); + + List getGeneralQuads(); + + boolean isAmbientOcclusion(); + + boolean isGui3d(); + + boolean isBuiltInRenderer(); + + TextureAtlasSprite getParticleTexture(); + + Transforms getItemCameraTransforms(); +} diff --git a/client/src/client/renderer/blockmodel/ModelBakery.java b/client/src/client/renderer/blockmodel/ModelBakery.java new file mode 100755 index 00000000..5b58a45c --- /dev/null +++ b/client/src/client/renderer/blockmodel/ModelBakery.java @@ -0,0 +1,321 @@ +package client.renderer.blockmodel; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import client.renderer.texture.IIconCreator; +import client.renderer.texture.TextureAtlasSprite; +import client.renderer.texture.TextureMap; +import common.collect.Lists; +import common.collect.Maps; +import common.collect.Sets; +import common.init.BlockRegistry; +import common.init.FluidRegistry; +import common.init.ItemRegistry; +import common.item.Item; +import common.item.ItemStack; +import common.model.ModelRotation; +import common.util.Facing; +import common.util.IRegistry; +import common.util.RegistrySimple; +import common.world.State; + +public abstract class ModelBakery +{ + private static final Set LOCATIONS_BUILTIN_TEXTURES = Sets.newHashSet( +// "blocks/water_flow", "blocks/water_still", +// "blocks/lava_flow", "blocks/lava_still", + "blocks/destroy_stage_0", "blocks/destroy_stage_1", + "blocks/destroy_stage_2", "blocks/destroy_stage_3", + "blocks/destroy_stage_4", "blocks/destroy_stage_5", + "blocks/destroy_stage_6", "blocks/destroy_stage_7", + "blocks/destroy_stage_8", "blocks/destroy_stage_9", + "items/empty_armor_slot_helmet", "items/empty_armor_slot_chestplate", + "items/empty_armor_slot_leggings", "items/empty_armor_slot_boots"); + protected static final String MISSING = "builtin/missing" + '#' + "missing"; + public static final ModelBlock MODEL_GENERATED = (ModelBlock)new ModelBlock(null).add().d(""); + public static final ModelBlock MODEL_ENTITY = (ModelBlock)new ModelBlock(null).add().d(""); + + static { + for(int z = 0; z < FluidRegistry.getNumFluids(); z++) { + String name = BlockRegistry.REGISTRY.getNameForObject(FluidRegistry.getStaticBlock(z)).toString(); + LOCATIONS_BUILTIN_TEXTURES.add("blocks/" + name + "_flow"); + LOCATIONS_BUILTIN_TEXTURES.add("blocks/" + name + "_still"); + } + } + + public static IRegistry setupModelRegistry(TextureMap textureMap, + Map map) + { + final Map sprites = Maps.newHashMap(); + Map models = Maps.newLinkedHashMap(); + List variants = Lists.newArrayList(); + FaceBakery faceBakery = new FaceBakery(); + RegistrySimple bakedRegistry = new RegistrySimple(); + List itemLocations = Lists.newArrayList(); +// Map> variantNames = Maps.>newIdentityHashMap(); +// variants.clear(); +// Map map = blockModelShapes.getMap(); + models.put(MISSING, (ModelBlock)new ModelBlock(null).add().all()); + variants.add(MISSING); + for(Entry entry : map.entrySet()) { + ModelBlock model = (ModelBlock)entry.getKey().getBlock().getModel(ModelBlock.PROVIDER, BlockRegistry.REGISTRY.getNameForObject(entry.getKey().getBlock()) + .toString(), entry.getKey()); +// ResourceLocation blk = new ResourceLocation(entry.getValue().getName()); + models.put(entry.getValue(), model); + variants.add(entry.getValue()); + } +// ResourceLocation loc = new ResourceLocation("item_frame"); +// String res = "item_frame" + '#' + "normal"; +// ModelBlock model = new ModelBlock("birch_planks") +// .add(3, 3, 15.5f, 13, 13, 16) +// .n("itemframe_background").uv(3, 3, 13, 13).noCull() +// .s("itemframe_background").uv(3, 3, 13, 13).noCull() +// .add(2, 2, 15, 14, 3, 16) +// .d().uv(2, 0, 14, 1).noCull() +// .u().uv(2, 15, 14, 16).noCull() +// .n().uv(2, 13, 14, 14).noCull() +// .s().uv(2, 13, 14, 14).noCull() +// .w().uv(15, 13, 16, 14).noCull() +// .e().uv(0, 13, 1, 14).noCull() +// .add(2, 13, 15, 14, 14, 16) +// .d().uv(2, 0, 14, 1).noCull() +// .u().uv(2, 15, 14, 16).noCull() +// .n().uv(2, 2, 14, 3).noCull() +// .s().uv(2, 2, 14, 3).noCull() +// .w().uv(15, 2, 16, 3).noCull() +// .e().uv(0, 2, 1, 3).noCull() +// .add(2, 3, 15, 3, 13, 16) +// .n().uv(13, 3, 14, 13).noCull() +// .s().uv(2, 3, 3, 13).noCull() +// .w().uv(15, 3, 16, 13).noCull() +// .e().uv(0, 3, 1, 13).noCull() +// .add(13, 3, 15, 14, 13, 16) +// .n().uv(2, 3, 3, 13).noCull() +// .s().uv(13, 3, 14, 13).noCull() +// .w().uv(15, 3, 16, 13).noCull() +// .e().uv(0, 3, 1, 13).noCull(); +// models.put(res, model); +// variants.add(res); +// res = "item_frame" + '#' + "map"; +// model = new ModelBlock("birch_planks") +// .add(1, 1, 15.001f, 15, 15, 16) +// .n("itemframe_background").uv(1, 1, 15, 15).noCull() +// .s("itemframe_background").uv(1, 1, 15, 15).noCull() +// .add(0, 0, 15.001f, 16, 1, 16) +// .d().uv(0, 0, 16, 1).noCull() +// .u().uv(0, 15, 16, 16).noCull() +// .n().uv(0, 15, 16, 16).noCull() +// .s().uv(0, 15, 16, 16).noCull() +// .w().uv(15, 15, 16, 16).noCull() +// .e().uv(0, 15, 1, 16).noCull() +// .add(0, 15, 15.001f, 16, 16, 16) +// .d().uv(0, 0, 16, 1).noCull() +// .u().uv(0, 15, 16, 16).noCull() +// .n().uv(0, 0, 16, 1).noCull() +// .s().uv(0, 0, 16, 1).noCull() +// .w().uv(15, 0, 16, 1).noCull() +// .e().uv(0, 0, 1, 1).noCull() +// .add(0, 1, 15.001f, 1, 15, 16) +// .n().uv(15, 1, 16, 15).noCull() +// .s().uv(0, 1, 1, 15).noCull() +// .w().uv(15, 1, 16, 15).noCull() +// .e().uv(0, 1, 1, 15).noCull() +// .add(15, 1, 15.001f, 16, 15, 16) +// .n().uv(0, 1, 1, 15).noCull() +// .s().uv(15, 1, 16, 15).noCull() +// .w().uv(15, 1, 16, 15).noCull() +// .e().uv(0, 1, 1, 15).noCull(); +// models.put(res, model); +// variants.add(res); + +// RenderRegistry.registerVariants(variantNames); + List stacks = Lists.newArrayList(); + for (Item item : ItemRegistry.REGISTRY) + { +// List list = variantNames.get(item); +// if(list == null) +// list = Collections.singletonList(0); +// for(Integer s : list) +// { + item.getRenderItems(item, stacks); + for(ItemStack stack : stacks) { + String resourcelocation = "item/" + ItemRegistry.REGISTRY.getNameForObject(item).toString() + "#" + stack.getMetadata() + '#' + "inventory"; + models.put(resourcelocation, (ModelBlock)item.getModel(ModelBlock.PROVIDER, ItemRegistry.REGISTRY.getNameForObject(item).toString(), stack.getMetadata())); + itemLocations.add(resourcelocation); + } + stacks.clear(); + } + + final Set set = Sets.newHashSet(); + List list = Lists.newArrayList(variants); + Collections.sort(list, new Comparator() + { + public int compare(String p_compare_1_, String p_compare_2_) + { + return p_compare_1_.compareTo(p_compare_2_); + } + }); + + for (String modelresourcelocation : list) + { + ModelBlock modelblock = models.get(modelresourcelocation); + + if (modelblock == null) + { + throw new RuntimeException("Fehlendes Modell für: " + modelresourcelocation); + } + else + { + + for (BlockPart blockpart : modelblock.getElements()) + { + for (BlockPartFace blockpartface : blockpart.mapFaces.values()) + { + set.add(blockpartface.texture); + } + } + + set.add(modelblock.getPrimary()); +// return set; +// set.addAll(getTextureLocations(modelblock)); + } + } + + set.addAll(LOCATIONS_BUILTIN_TEXTURES); +// final Set set = getVariantsTextureLocations(); + for (String resourcelocation : itemLocations) // .values()) + { + ModelBlock modelblock = (ModelBlock)models.get(resourcelocation); + + if (modelblock != null) + { + set.add(modelblock.getPrimary()); + + if (modelblock.getParent() == MODEL_GENERATED) + { + for (int n = 0; n < modelblock.getNumTextures(); n++) + { + set.add(modelblock.getTexture(n)); + } + } + else if (modelblock.getParent() != MODEL_ENTITY) + { + for (BlockPart blockpart : modelblock.getElements()) + { + for (BlockPartFace blockpartface : blockpart.mapFaces.values()) + { + set.add(blockpartface.texture); + } + } + } + } + } +// set.addAll(getItemsTextureLocations()); + set.remove(TextureMap.LOCATION_MISSING_TEXTURE); + IIconCreator iiconcreator = new IIconCreator() + { + public void registerSprites(TextureMap iconRegistry) + { + for (String resourcelocation : set) + { + TextureAtlasSprite textureatlassprite = iconRegistry.registerSprite(resourcelocation); + sprites.put(resourcelocation, textureatlassprite); + } + } + }; + textureMap.loadSprites(iiconcreator); + sprites.put(TextureMap.LOCATION_MISSING_TEXTURE, textureMap.getMissingSprite()); + + for (String resourcelocation : itemLocations) // .values()) + { + ModelBlock modelblock = models.get(resourcelocation); + + if (modelblock != null && modelblock.getParent() == MODEL_GENERATED) + { + ModelBlock modelblock1 = ModelGenerator.makeItemModel(textureMap, modelblock); + models.put(resourcelocation, modelblock1); + } + else if (modelblock != null && modelblock.getParent() == MODEL_ENTITY) + { + models.put(resourcelocation, modelblock); + } + } + + for (TextureAtlasSprite textureatlassprite : sprites.values()) + { + if (!textureatlassprite.isAnimated()) + { + textureatlassprite.clearFramesTextureData(); + } + } + + for (String modelresourcelocation : variants) + { + ModelBlock modelblock = models.get(modelresourcelocation); + + if (modelblock != null) + { + bakedRegistry.putObject(modelresourcelocation, bakeModel(sprites, faceBakery, textureMap.getMissingSprite(), + modelblock, modelblock.getRotation(), modelblock.isUvLocked())); + } + else + { + throw new RuntimeException("Fehlendes Modell für: " + modelresourcelocation); + } + } + +// for (Entry entry : itemLocations.entrySet()) + for (String entry : itemLocations) + { +// ResourceLocation resourcelocation = (ResourceLocation)entry.getValue(); +// ResourceLocation inventory = new ResourceLocation((String)entry.getKey(), "inventory"); + ModelBlock modelblock1 = (ModelBlock)models.get(entry) ; // resourcelocation); + + if (modelblock1 != null) + { + if (modelblock1.getParent() == MODEL_ENTITY) + { + bakedRegistry.putObject(entry /* inventory */, new BuiltInModel(modelblock1.getTransform())); + } + else + { + bakedRegistry.putObject(entry /* inventory */, bakeModel(sprites, faceBakery, textureMap.getMissingSprite(), + modelblock1, ModelRotation.X0_Y0, false)); + } + } + else + { + throw new RuntimeException("Fehlendes Modell für: " + entry); // resourcelocation); + } + } + + return bakedRegistry; + } + + private static IBakedModel bakeModel(Map sprites, FaceBakery faceBakery, + TextureAtlasSprite fallback, ModelBlock modelBlockIn, ModelRotation modelRotationIn, boolean uvLocked) + { + TextureAtlasSprite particle = sprites.get(modelBlockIn.getPrimary()); + BakedModel.Builder builder = new BakedModel.Builder(modelBlockIn).setTexture(particle == null ? fallback : particle); + for (BlockPart blockpart : modelBlockIn.getElements()) + { + for (Facing enumfacing : blockpart.mapFaces.keySet()) + { + BlockPartFace face = blockpart.mapFaces.get(enumfacing); + TextureAtlasSprite sprite = sprites.get(face.texture); + sprite = sprite == null ? fallback : sprite; + + if (face.cull == null) + builder.addGeneralQuad(faceBakery.makeBakedQuad(blockpart.positionFrom, blockpart.positionTo, face, sprite, enumfacing, modelRotationIn, blockpart.partRotation, uvLocked, blockpart.shade)); + else + builder.addFaceQuad(modelRotationIn.rotateFace(face.cull), faceBakery.makeBakedQuad(blockpart.positionFrom, blockpart.positionTo, face, sprite, enumfacing, modelRotationIn, blockpart.partRotation, uvLocked, blockpart.shade)); + } + } + return builder.makeBakedModel(); + } +} diff --git a/client/src/client/renderer/blockmodel/ModelBlock.java b/client/src/client/renderer/blockmodel/ModelBlock.java new file mode 100755 index 00000000..69504fa1 --- /dev/null +++ b/client/src/client/renderer/blockmodel/ModelBlock.java @@ -0,0 +1,203 @@ +package client.renderer.blockmodel; + +import java.util.List; + +import client.renderer.texture.TextureMap; +import common.collect.Lists; +import common.collect.Maps; +import common.model.Model; +import common.model.ModelProvider; +import common.model.ModelRotation; +import common.model.Transforms; +import common.util.Facing; +import common.util.Vector3f; + +public class ModelBlock extends Model { + static final ModelProvider PROVIDER = new ModelProvider() { + public Model getModel(String primary) { + return new ModelBlock(primary); + } + + public Model getModel(Transforms transform, String... layers) { + return new ModelBlock(transform, layers); + } + + public Model getModel(Model parent, Transforms transform) { + return new ModelBlock((ModelBlock)parent, transform); + } + + public Model getEntityModel() { + return ModelBakery.MODEL_ENTITY; + } + }; + + private final List elements; + private final boolean gui3d; + private final String primary; + private final String[] layers; + private final ModelBlock parent; + + private boolean occlusion; + private ModelRotation rotation; + private boolean uvLock; + private Transforms transform; + + private BlockPart lastPart; + private BlockPartFace[] last; + + public static void setAsProvider() { + ModelProvider.setProvider(PROVIDER); + } + + public ModelBlock noOcclude() { + this.occlusion = false; + return this; + } + + public ModelBlock uvLock() { + this.uvLock = true; + return this; + } + + public ModelBlock rotate(ModelRotation rot) { + this.rotation = rot; + return this; + } + + public ModelBlock add(float x1, float y1, float z1, float x2, float y2, float z2) { + this.elements.add(this.lastPart = new BlockPart(new Vector3f(x1, y1, z1), new Vector3f(x2, y2, z2), + Maps.newEnumMap(Facing.class), null, true)); + return this; + } + + public ModelBlock noShade() { + this.lastPart.shade = false; + return this; + } + + public ModelBlock rotate(float x, float y, float z, Facing.Axis axisIn, float angleIn, boolean rescaleIn) { + this.lastPart.partRotation = new BlockPartRotation(x, y, z, axisIn, angleIn, rescaleIn); + return this; + } + + public ModelBlock face(String texture, Facing ... faces) { + texture = !texture.equals(TextureMap.LOCATION_MISSING_TEXTURE) && texture.indexOf('/') == -1 ? "blocks/" + texture : texture; + this.last = new BlockPartFace[faces.length]; + for(int z = 0; z < faces.length; z++) { + this.lastPart.mapFaces.put(faces[z], this.last[z] = + new BlockPartFace(faces[z], -1, texture, new BlockFaceUV(this.lastPart.getFaceUvs(faces[z]), 0))); + } + return this; + } + + public ModelBlock cull(Facing cull) { + for(BlockPartFace last : this.last) { + last.cull = cull; + } + return this; + } + + public ModelBlock tint() { + for(BlockPartFace last : this.last) { + last.tint = 0; + } + return this; + } + + public ModelBlock rot(int rot) { + for(BlockPartFace last : this.last) { + last.uv = new BlockFaceUV(last.uv.uvs, rot); + } + return this; + } + + public ModelBlock uv(float x1, float y1, float x2, float y2) { + for(BlockPartFace last : this.last) { + last.uv = new BlockFaceUV(new float[] {x1, y1, x2, y2}, last.uv.rotation); + } + return this; + } + + public String getPrimary() { + return this.primary; + } + + + public ModelBlock(String primary) { + this(null, Lists.newArrayList(), primary != null && primary.indexOf('/') == -1 ? "blocks/" + primary : primary, true, true, Transforms.DEFAULT, null); + } + + public ModelBlock(Transforms transform, String ... layers) { + this(ModelBakery.MODEL_GENERATED, ModelBakery.MODEL_GENERATED.elements, + layers[0].indexOf('/') == -1 ? "items/" + layers[0] : layers[0], false, false, transform, layers); + } + + public ModelBlock(ModelBlock parent, Transforms transform) { + this(parent, Lists.newArrayList(), parent.getPrimary(), false, true, transform, null); + } + + public ModelBlock(String primary, Transforms transform, String ... layers) { + this(ModelBakery.MODEL_GENERATED, ModelBakery.MODEL_GENERATED.elements, + primary.indexOf('/') == -1 ? "items/" + primary : primary, false, false, transform, layers); + } + + public ModelBlock(String primary, List elements, Transforms transform, String ... layers) { + this(null, elements, primary, false, false, transform, layers); + } + + private ModelBlock(ModelBlock parent, List elements, String primary, boolean occlude, boolean gui3d, + Transforms transform, String[] layers) { + for(int z = 0; layers != null && z < layers.length; z++) { + layers[z] = layers[z].indexOf('/') == -1 ? "items/" + layers[z] : layers[z]; + } + this.elements = parent == null ? elements : parent.getElements(); + this.occlusion = parent == null ? occlude : parent.isAmbientOcclusion(); + this.gui3d = gui3d; + this.primary = primary == null ? TextureMap.LOCATION_MISSING_TEXTURE : primary; + this.parent = parent; + this.transform = transform; + this.uvLock = false; + this.rotation = ModelRotation.X0_Y0; + this.layers = layers; + } + + public List getElements() { + return this.elements; + } + + public boolean isAmbientOcclusion() { + return this.occlusion; + } + + public boolean isGui3d() { + return this.gui3d; + } + + public String[] getTextures() { + return this.layers; + } + + public int getNumTextures() { + return this.layers == null ? 0 : this.layers.length; + } + + public String getTexture(int layer) { + return this.layers == null || this.layers[layer] == null ? TextureMap.LOCATION_MISSING_TEXTURE : this.layers[layer]; + } + + public ModelBlock getParent() { + return this.parent; + } + + public Transforms getTransform() { + return this.transform; + } + + public ModelRotation getRotation() { + return this.rotation; + } + + public boolean isUvLocked() { + return this.uvLock; + } +} diff --git a/client/src/main/java/client/renderer/blockmodel/ModelGenerator.java b/client/src/client/renderer/blockmodel/ModelGenerator.java similarity index 89% rename from client/src/main/java/client/renderer/blockmodel/ModelGenerator.java rename to client/src/client/renderer/blockmodel/ModelGenerator.java index 2fefcfa6..9e4ccc61 100755 --- a/client/src/main/java/client/renderer/blockmodel/ModelGenerator.java +++ b/client/src/client/renderer/blockmodel/ModelGenerator.java @@ -5,7 +5,7 @@ import java.util.List; import java.util.Map; import client.renderer.model.ModelBox; -import client.renderer.texture.Sprite; +import client.renderer.texture.TextureAtlasSprite; import client.renderer.texture.TextureMap; import client.renderer.texture.TextureUtil; import common.collect.Lists; @@ -15,6 +15,8 @@ import common.util.Facing; import common.util.Vector3f; public abstract class ModelGenerator { +// public static final List LAYERS = Lists.newArrayList("layer0", "layer1", "layer2", "layer3", "layer4"); + public static List bakeModel(String textureLocation, int tx, int ty, int tw, int th, float x, float y, float z, int w, int h, int d) { int[] img; @@ -24,13 +26,13 @@ public abstract class ModelGenerator { } catch(Throwable e) { if(e instanceof FileNotFoundException) - Log.IO.warn("Textur ist nicht zum Zusammenstellen vorhanden: " + textureLocation); + Log.JNI.warn("Textur ist nicht zum Zusammenstellen vorhanden: " + textureLocation); else - Log.IO.error(e, "Konnte Textur '" + textureLocation + "' nicht zum Zusammenstellen laden"); + Log.JNI.error(e, "Konnte Textur '" + textureLocation + "' nicht zum Zusammenstellen laden"); return Lists.newArrayList(); } if(img.length < tw * th) { - Log.IO.warn("Konnte Textur '" + textureLocation.toString() + "' nicht zum Zusammenstellen laden weil sie zu klein ist " + + Log.JNI.warn("Konnte Textur '" + textureLocation.toString() + "' nicht zum Zusammenstellen laden weil sie zu klein ist " + "(benötige " + (tw*th) + " [" + tw + "x" + th + "], habe " + img.length + ")"); return Lists.newArrayList(); } @@ -122,7 +124,7 @@ public abstract class ModelGenerator { } } - private static List compileParts(int layer, String tex, Sprite sprite) { + private static List compileParts(int layer, String tex, TextureAtlasSprite sprite) { Map map = Maps.newHashMap(); map.put(Facing.SOUTH, new BlockPartFace(null, layer, tex, new BlockFaceUV(new float[] {0.0F, 0.0F, 16.0F, 16.0F}, 0))); map.put(Facing.NORTH, new BlockPartFace(null, layer, tex, new BlockFaceUV(new float[] {16.0F, 0.0F, 0.0F, 16.0F}, 0))); @@ -132,7 +134,7 @@ public abstract class ModelGenerator { return parts; } - private static List bakeParts(Sprite sprite, String tex, int layer) { + private static List bakeParts(TextureAtlasSprite sprite, String tex, int layer) { float w = (float)sprite.getIconWidth(); float h = (float)sprite.getIconHeight(); List parts = Lists.newArrayList(); @@ -229,12 +231,23 @@ public abstract class ModelGenerator { return parts; } - private static List compileSpans(Sprite sprite) { + private static List compileSpans(TextureAtlasSprite sprite) { int w = sprite.getIconWidth(); int h = sprite.getIconHeight(); List spans = Lists.newArrayList(); for(int f = 0; f < sprite.getFrameCount(); ++f) { compileSpans(spans, sprite.getFrameTextureData(f), 0, 0, w, h, w, h); +// int[] data = sprite.getFrameTextureData(f)[0]; +// for(int y = 0; y < h; ++y) { +// for(int x = 0; x < w; ++x) { +// if(!isTransparent(data, x, y, w, h)) { +// checkAdd(SpanFacing.UP, spans, data, x, y, w, h); +// checkAdd(SpanFacing.DOWN, spans, data, x, y, w, h); +// checkAdd(SpanFacing.LEFT, spans, data, x, y, w, h); +// checkAdd(SpanFacing.RIGHT, spans, data, x, y, w, h); +// } +// } +// } } return spans; } diff --git a/client/src/client/renderer/blockmodel/ModelManager.java b/client/src/client/renderer/blockmodel/ModelManager.java new file mode 100755 index 00000000..5984f9a6 --- /dev/null +++ b/client/src/client/renderer/blockmodel/ModelManager.java @@ -0,0 +1,165 @@ +package client.renderer.blockmodel; + +import java.util.Collections; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import client.renderer.texture.TextureAtlasSprite; +import client.renderer.texture.TextureMap; +import common.block.Block; +import common.block.BlockLiquid; +import common.collect.Maps; +import common.init.BlockRegistry; +import common.init.Blocks; +import common.init.FluidRegistry; +import common.properties.IProperty; +import common.util.IRegistry; +import common.world.State; + +public class ModelManager +{ + private IRegistry modelRegistry; + private final TextureMap texMap; + private final Map bakedModelStore = Maps.newIdentityHashMap(); + private final Map liquidMap = Maps.newIdentityHashMap(); + private final Map mappers = Maps.newIdentityHashMap(); + private final Set builtin = Collections.newSetFromMap(Maps.newIdentityHashMap()); + private IBakedModel defaultModel; + + public ModelManager(TextureMap textures) + { + this.texMap = textures; + for(Block block : BlockRegistry.REGISTRY) { + if(block.getRenderType() != 3) { + this.builtin.add(block); + // Log.info("Builtin: " + BlockRegistry.REGISTRY.getNameForObject(block)); + } + else { + IProperty[] ignored = block.getIgnoredProperties(); + if(ignored != null) + this.mappers.put(block, new MultiStateMap.Builder().ignore(ignored).build()); + } + } + } + + public void onReload() + { + this.modelRegistry = ModelBakery.setupModelRegistry(this.texMap, this.getMap()); + this.defaultModel = this.modelRegistry.getObject(ModelBakery.MISSING); + this.reloadModels(); + } + + public IBakedModel getModel(String modelLocation) + { + if (modelLocation == null) + { + return this.defaultModel; + } + else + { + IBakedModel ibakedmodel = this.modelRegistry.getObject(modelLocation); + return ibakedmodel == null ? this.defaultModel : ibakedmodel; + } + } + + public IBakedModel getMissingModel() + { + return this.defaultModel; + } + + public TextureMap getTextureMap() + { + return this.texMap; + } + + public TextureAtlasSprite getTexture(State state) + { + Block block = state.getBlock(); + IBakedModel ibakedmodel = this.getModelForState(state); + + if (ibakedmodel == null || ibakedmodel == this.defaultModel) + { + if (block == Blocks.wall_sign || block == Blocks.sign || block == Blocks.chest || block == Blocks.trapped_chest || block == Blocks.banner || block == Blocks.wall_banner) + { + return this.texMap.getAtlasSprite("blocks/oak_planks"); + } + + if (block == Blocks.floor_portal) + { + return this.texMap.getAtlasSprite("blocks/obsidian"); + } + + if (block == Blocks.flowing_lava || block == Blocks.lava) + { + return this.texMap.getAtlasSprite("blocks/lava_still"); + } + + if (block == Blocks.flowing_water || block == Blocks.water) + { + return this.texMap.getAtlasSprite("blocks/water_still"); + } + + if (block == Blocks.skull) + { + return this.texMap.getAtlasSprite("blocks/soul_sand"); + } + +// if (block == Blocks.barrier) +// { +// return this.modelManager.getTextureMap().getAtlasSprite("items/barrier"); +// } + + if (block.getMaterial().isLiquid()) + { + String texture = this.liquidMap.get(block); + if(texture == null) + this.liquidMap.put(block, texture = "blocks/" + BlockRegistry.REGISTRY.getNameForObject(FluidRegistry.getStaticBlock(FluidRegistry.getFluidMeta((BlockLiquid)block))) + "_still"); + return this.texMap.getAtlasSprite(texture); + } + } + + if (ibakedmodel == null) + { + ibakedmodel = this.defaultModel; + } + + return ibakedmodel.getParticleTexture(); + } + + public IBakedModel getModelForState(State state) + { + IBakedModel ibakedmodel = (IBakedModel)this.bakedModelStore.get(state); + + if (ibakedmodel == null) + { + ibakedmodel = this.defaultModel; + } + + return ibakedmodel; + } + + public void reloadModels() + { + this.bakedModelStore.clear(); + + for (Entry entry : this.getMap().entrySet()) + { + this.bakedModelStore.put(entry.getKey(), this.getModel(entry.getValue())); + } + } + + public Map getMap() { + Map map = Maps.newIdentityHashMap(); + for(Block block : BlockRegistry.REGISTRY) { + if(!this.builtin.contains(block)) { + StateMap mapper = this.mappers.get(block); + if(mapper == null) + mapper = new SingleStateMap(); + map.putAll( // (Objects.firstNonNull(, )) + mapper.putStateModelLocations(block)); + } + } + return map; + } +} diff --git a/client/src/client/renderer/blockmodel/MultiStateMap.java b/client/src/client/renderer/blockmodel/MultiStateMap.java new file mode 100755 index 00000000..1461f837 --- /dev/null +++ b/client/src/client/renderer/blockmodel/MultiStateMap.java @@ -0,0 +1,82 @@ +package client.renderer.blockmodel; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import common.collect.Lists; +import common.collect.Maps; +import common.init.BlockRegistry; +import common.properties.IProperty; +import common.world.State; + +public class MultiStateMap extends StateMap +{ + private final IProperty name; + private final String suffix; + private final List < IProperty> ignored; + + private MultiStateMap(IProperty name, String suffix, List < IProperty> ignored) + { + this.name = name; + this.suffix = suffix; + this.ignored = ignored; + } + + protected String getResourceLocation(State state) + { + Map map = Maps.newLinkedHashMap(state.getProperties()); + String s; + + if (this.name == null) + { + s = BlockRegistry.REGISTRY.getNameForObject(state.getBlock()); + } + else + { + s = ((IProperty)this.name).getName((Comparable)map.remove(this.name)); + } + + if (this.suffix != null) + { + s = s + this.suffix; + } + + for (IProperty iproperty : this.ignored) + { + map.remove(iproperty); + } + + return s + '#' + this.getPropertyString(map); + } + + public static class Builder + { + private IProperty name; + private String suffix; + private final List < IProperty> ignored = Lists. < IProperty> newArrayList(); + + public MultiStateMap.Builder withName(IProperty builderPropertyIn) + { + this.name = builderPropertyIn; + return this; + } + + public MultiStateMap.Builder withSuffix(String builderSuffixIn) + { + this.suffix = builderSuffixIn; + return this; + } + + public MultiStateMap.Builder ignore(IProperty... p_178442_1_) + { + Collections.addAll(this.ignored, p_178442_1_); + return this; + } + + public MultiStateMap build() + { + return new MultiStateMap(this.name, this.suffix, this.ignored); + } + } +} diff --git a/client/src/client/renderer/blockmodel/SingleStateMap.java b/client/src/client/renderer/blockmodel/SingleStateMap.java new file mode 100755 index 00000000..6ad21d9e --- /dev/null +++ b/client/src/client/renderer/blockmodel/SingleStateMap.java @@ -0,0 +1,13 @@ +package client.renderer.blockmodel; + +import common.init.BlockRegistry; +import common.world.State; + + +public class SingleStateMap extends StateMap +{ + protected String getResourceLocation(State state) + { + return BlockRegistry.REGISTRY.getNameForObject(state.getBlock()).toString() + '#' + this.getPropertyString(state.getProperties()); + } +} diff --git a/client/src/main/java/client/renderer/blockmodel/StateMap.java b/client/src/client/renderer/blockmodel/StateMap.java similarity index 83% rename from client/src/main/java/client/renderer/blockmodel/StateMap.java rename to client/src/client/renderer/blockmodel/StateMap.java index 155c9b8b..d85f8a1d 100755 --- a/client/src/main/java/client/renderer/blockmodel/StateMap.java +++ b/client/src/client/renderer/blockmodel/StateMap.java @@ -5,25 +5,25 @@ import java.util.Map.Entry; import common.block.Block; import common.collect.Maps; -import common.properties.Property; +import common.properties.IProperty; import common.world.State; public abstract class StateMap { protected Map mapStateModelLocations = Maps.newLinkedHashMap(); - public String getPropertyString(Map p_178131_1_) + public String getPropertyString(Map p_178131_1_) { StringBuilder stringbuilder = new StringBuilder(); - for (Entry entry : p_178131_1_.entrySet()) + for (Entry entry : p_178131_1_.entrySet()) { if (stringbuilder.length() != 0) { stringbuilder.append(","); } - Property iproperty = (Property)entry.getKey(); + IProperty iproperty = (IProperty)entry.getKey(); Comparable comparable = (Comparable)entry.getValue(); stringbuilder.append(iproperty.getName()); stringbuilder.append("="); diff --git a/client/src/main/java/client/renderer/chunk/ChunkCompileTaskGenerator.java b/client/src/client/renderer/chunk/ChunkCompileTaskGenerator.java similarity index 100% rename from client/src/main/java/client/renderer/chunk/ChunkCompileTaskGenerator.java rename to client/src/client/renderer/chunk/ChunkCompileTaskGenerator.java diff --git a/client/src/main/java/client/renderer/chunk/ChunkRenderDispatcher.java b/client/src/client/renderer/chunk/ChunkRenderDispatcher.java similarity index 88% rename from client/src/main/java/client/renderer/chunk/ChunkRenderDispatcher.java rename to client/src/client/renderer/chunk/ChunkRenderDispatcher.java index 64524bed..735cadbc 100755 --- a/client/src/main/java/client/renderer/chunk/ChunkRenderDispatcher.java +++ b/client/src/client/renderer/chunk/ChunkRenderDispatcher.java @@ -5,17 +5,22 @@ import java.util.List; import java.util.Queue; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ThreadFactory; + import client.Client; import client.renderer.RegionRenderCacheBuilder; import client.renderer.RenderBuffer; import client.renderer.VertexBuffer; -import client.renderer.chunk.ChunkBuilder.ImmediateFuture; -import client.renderer.chunk.ChunkBuilder.ListenableFuture; -import client.renderer.chunk.ChunkBuilder.ListenableFutureTask; import common.collect.Lists; +import common.future.Futures; +import common.future.ListenableFuture; +import common.future.ListenableFutureTask; +import common.future.ThreadFactoryBuilder; +import common.model.BlockLayer; public class ChunkRenderDispatcher { + private static final ThreadFactory threadFactory = (new ThreadFactoryBuilder()).setNameFormat("Chunk Batcher %d").setDaemon(true).build(); private final List listThreadedWorkers = Lists.newArrayList(); private final BlockingQueue queueChunkUpdates = new ArrayBlockingQueue(100); private final BlockingQueue queueFreeRenderBuilders = new ArrayBlockingQueue(5); @@ -29,8 +34,7 @@ public class ChunkRenderDispatcher for (int i = 0; i < 2; ++i) { ChunkRenderWorker chunkrenderworker = new ChunkRenderWorker(this); - Thread thread = new Thread(chunkrenderworker, "Chunk Batcher #" + (i + 1)); - thread.setDaemon(true); + Thread thread = threadFactory.newThread(chunkrenderworker); thread.start(); this.listThreadedWorkers.add(chunkrenderworker); } @@ -221,15 +225,15 @@ public class ChunkRenderDispatcher return flag; } - public ListenableFuture uploadChunk(final BlockLayer layer, final RenderBuffer buf, final RenderChunk renderer, final CompiledChunk compiled) + public ListenableFuture uploadChunk(final BlockLayer player, final RenderBuffer p_178503_2_, final RenderChunk chunkRenderer, final CompiledChunk compiledChunkIn) { if (Client.CLIENT.isMainThread()) { - buf.reset(); - renderer.getVertexBufferByLayer(layer.ordinal()).bufferData(buf.getByteBuffer()); + p_178503_2_.reset(); + chunkRenderer.getVertexBufferByLayer(player.ordinal()).bufferData(p_178503_2_.getByteBuffer()); - buf.setTranslation(0.0D, 0.0D, 0.0D); - return new ImmediateFuture(); + p_178503_2_.setTranslation(0.0D, 0.0D, 0.0D); + return Futures.immediateFuture((Object)null); } else { @@ -237,7 +241,7 @@ public class ChunkRenderDispatcher { public void run() { - ChunkRenderDispatcher.this.uploadChunk(layer, buf, renderer, compiled); + ChunkRenderDispatcher.this.uploadChunk(player, p_178503_2_, chunkRenderer, compiledChunkIn); } }, (Object)null); diff --git a/client/src/client/renderer/chunk/ChunkRenderWorker.java b/client/src/client/renderer/chunk/ChunkRenderWorker.java new file mode 100755 index 00000000..d685f684 --- /dev/null +++ b/client/src/client/renderer/chunk/ChunkRenderWorker.java @@ -0,0 +1,204 @@ +package client.renderer.chunk; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CancellationException; + +import client.Client; +import client.renderer.RegionRenderCacheBuilder; +import common.collect.Lists; +import common.entity.Entity; +import common.future.FutureCallback; +import common.future.Futures; +import common.future.ListenableFuture; +import common.log.Log; +import common.model.BlockLayer; + +public class ChunkRenderWorker implements Runnable +{ + private final ChunkRenderDispatcher chunkRenderDispatcher; + private final RegionRenderCacheBuilder regionRenderCacheBuilder; + + private boolean running = true; + + public ChunkRenderWorker(ChunkRenderDispatcher p_i46201_1_) + { + this(p_i46201_1_, (RegionRenderCacheBuilder)null); + } + + public ChunkRenderWorker(ChunkRenderDispatcher chunkRenderDispatcherIn, RegionRenderCacheBuilder regionRenderCacheBuilderIn) + { + this.chunkRenderDispatcher = chunkRenderDispatcherIn; + this.regionRenderCacheBuilder = regionRenderCacheBuilderIn; + } + + public void run() + { + while (this.running) + { + try + { + this.processTask(this.chunkRenderDispatcher.getNextChunkUpdate()); + } + catch (InterruptedException var3) + { +// Log.debug("Stoppe wegen Unterbrechung"); + return; + } + } + } + + public void end() { + this.running = false; + } + + protected void processTask(final ChunkCompileTaskGenerator generator) throws InterruptedException + { + generator.getLock().lock(); + + try + { + if (generator.getStatus() != ChunkCompileTaskGenerator.Status.PENDING) + { + if (!generator.isFinished()) + { + Log.JNI.warn("Chunk-Rendering-Aufgabe war " + generator.getStatus() + " wenn PENDING erwartet war; ignoriere Aufgabe"); + } + + return; + } + + generator.setStatus(ChunkCompileTaskGenerator.Status.COMPILING); + } + finally + { + generator.getLock().unlock(); + } + + Entity lvt_2_1_ = Client.CLIENT.getRenderViewEntity(); + + if (lvt_2_1_ == null) + { + generator.finish(); + } + else + { + generator.setRegionRenderCacheBuilder(this.getRegionRenderCacheBuilder()); + float f = (float)lvt_2_1_.posX; + float f1 = (float)lvt_2_1_.posY + lvt_2_1_.getEyeHeight(); + float f2 = (float)lvt_2_1_.posZ; + ChunkCompileTaskGenerator.Type chunkcompiletaskgenerator$type = generator.getType(); + + if (chunkcompiletaskgenerator$type == ChunkCompileTaskGenerator.Type.REBUILD_CHUNK) + { + generator.getRenderChunk().rebuildChunk(f, f1, f2, generator); + } + else if (chunkcompiletaskgenerator$type == ChunkCompileTaskGenerator.Type.RESORT_TRANSPARENCY) + { + generator.getRenderChunk().resortTransparency(f, f1, f2, generator); + } + + generator.getLock().lock(); + + try + { + if (generator.getStatus() != ChunkCompileTaskGenerator.Status.COMPILING) + { + if (!generator.isFinished()) + { + Log.JNI.warn("Chunk-Rendering-Aufgabe war " + generator.getStatus() + " wenn COMPILING erwartet war; breche Aufgabe ab"); + } + + this.freeRenderBuilder(generator); + return; + } + + generator.setStatus(ChunkCompileTaskGenerator.Status.UPLOADING); + } + finally + { + generator.getLock().unlock(); + } + + final CompiledChunk lvt_7_1_ = generator.getCompiledChunk(); + ArrayList lvt_8_1_ = Lists.newArrayList(); + + if (chunkcompiletaskgenerator$type == ChunkCompileTaskGenerator.Type.REBUILD_CHUNK) + { + for (BlockLayer enumworldblocklayer : BlockLayer.values()) + { + if (lvt_7_1_.isLayerStarted(enumworldblocklayer)) + { + lvt_8_1_.add(this.chunkRenderDispatcher.uploadChunk(enumworldblocklayer, generator.getRegionRenderCacheBuilder().getWorldRendererByLayer(enumworldblocklayer), generator.getRenderChunk(), lvt_7_1_)); + } + } + } + else if (chunkcompiletaskgenerator$type == ChunkCompileTaskGenerator.Type.RESORT_TRANSPARENCY) + { + lvt_8_1_.add(this.chunkRenderDispatcher.uploadChunk(BlockLayer.TRANSLUCENT, generator.getRegionRenderCacheBuilder().getWorldRendererByLayer(BlockLayer.TRANSLUCENT), generator.getRenderChunk(), lvt_7_1_)); + } + + final ListenableFuture> listenablefuture = Futures.allAsList(lvt_8_1_); + generator.addFinishRunnable(new Runnable() + { + public void run() + { + listenablefuture.cancel(false); + } + }); + Futures.addCallback(listenablefuture, new FutureCallback>() + { + public void onSuccess(List p_onSuccess_1_) + { + ChunkRenderWorker.this.freeRenderBuilder(generator); + generator.getLock().lock(); + label21: + { + try + { + if (generator.getStatus() == ChunkCompileTaskGenerator.Status.UPLOADING) + { + generator.setStatus(ChunkCompileTaskGenerator.Status.DONE); + break label21; + } + + if (!generator.isFinished()) + { + Log.JNI.warn("Chunk-Rendering-Aufgabe war " + generator.getStatus() + " wenn UPLOADING erwartet war; breche Aufgabe ab"); + } + } + finally + { + generator.getLock().unlock(); + } + + return; + } + generator.getRenderChunk().setCompiledChunk(lvt_7_1_); + } + public void onFailure(Throwable p_onFailure_1_) + { + ChunkRenderWorker.this.freeRenderBuilder(generator); + + if (!(p_onFailure_1_ instanceof CancellationException) && !(p_onFailure_1_ instanceof InterruptedException)) + { + Log.JNI.error(p_onFailure_1_, "Fehler beim Rendern des Chunks"); + } + } + }); + } + } + + private RegionRenderCacheBuilder getRegionRenderCacheBuilder() throws InterruptedException + { + return this.regionRenderCacheBuilder != null ? this.regionRenderCacheBuilder : this.chunkRenderDispatcher.allocateRenderBuilder(); + } + + private void freeRenderBuilder(ChunkCompileTaskGenerator taskGenerator) + { + if (this.regionRenderCacheBuilder == null) + { + this.chunkRenderDispatcher.freeRenderBuilder(taskGenerator.getRegionRenderCacheBuilder()); + } + } +} diff --git a/client/src/main/java/client/renderer/chunk/CompiledChunk.java b/client/src/client/renderer/chunk/CompiledChunk.java similarity index 98% rename from client/src/main/java/client/renderer/chunk/CompiledChunk.java rename to client/src/client/renderer/chunk/CompiledChunk.java index 481e7c9f..71559156 100755 --- a/client/src/main/java/client/renderer/chunk/CompiledChunk.java +++ b/client/src/client/renderer/chunk/CompiledChunk.java @@ -4,6 +4,7 @@ import java.util.List; import client.renderer.RenderBuffer; import common.collect.Lists; +import common.model.BlockLayer; import common.tileentity.TileEntity; import common.util.Facing; diff --git a/client/src/main/java/client/renderer/chunk/RenderChunk.java b/client/src/client/renderer/chunk/RenderChunk.java similarity index 86% rename from client/src/main/java/client/renderer/chunk/RenderChunk.java rename to client/src/client/renderer/chunk/RenderChunk.java index f7ded46c..8667584f 100755 --- a/client/src/main/java/client/renderer/chunk/RenderChunk.java +++ b/client/src/client/renderer/chunk/RenderChunk.java @@ -17,22 +17,22 @@ import client.renderer.RegionRenderCache; import client.renderer.RenderBuffer; import client.renderer.RenderGlobal; import client.renderer.VertexBuffer; -import client.renderer.tileentity.SpecialRenderer; -import client.renderer.tileentity.ElementRenderer; +import client.renderer.tileentity.TileEntityRendererDispatcher; +import client.renderer.tileentity.TileEntitySpecialRenderer; import common.block.Block; -import common.block.ITileEntityProvider; import common.collect.Maps; import common.collect.Sets; -import common.init.Blocks; +import common.model.BlockLayer; import common.tileentity.TileEntity; import common.util.BlockPos; import common.util.BoundingBox; import common.util.Facing; import common.world.State; +import common.world.World; public class RenderChunk { - private Client gm; + private World world; private final RenderGlobal renderGlobal; public static int renderChunksUpdated; private BlockPos position; @@ -49,9 +49,9 @@ public class RenderChunk private boolean needsUpdate = true; private EnumMap mapEnumFacing = Maps.newEnumMap(Facing.class); - public RenderChunk(Client worldIn, RenderGlobal renderGlobalIn, BlockPos blockPosIn, int indexIn) + public RenderChunk(World worldIn, RenderGlobal renderGlobalIn, BlockPos blockPosIn, int indexIn) { - this.gm = worldIn; + this.world = worldIn; this.renderGlobal = renderGlobalIn; this.index = indexIn; @@ -126,7 +126,7 @@ public class RenderChunk return; } - iblockaccess = new RegionRenderCache(this.gm, blockpos.add(-1, -1, -1), blockpos1.add(1, 1, 1), 1); + iblockaccess = new RegionRenderCache(this.world, blockpos.add(-1, -1, -1), blockpos1.add(1, 1, 1), 1); generator.setCompiledChunk(compiledchunk); } finally @@ -135,13 +135,13 @@ public class RenderChunk } VisGraph lvt_10_1_ = new VisGraph(); - HashSet forced = Sets.newHashSet(); + HashSet lvt_11_1_ = Sets.newHashSet(); if (!iblockaccess.isEmpty()) { ++renderChunksUpdated; boolean[] aboolean = new boolean[BlockLayer.values().length]; - BlockRenderer blockrendererdispatcher = this.gm.getBlockRendererDispatcher(); + BlockRenderer blockrendererdispatcher = Client.CLIENT.getBlockRendererDispatcher(); for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(blockpos, blockpos1)) { @@ -153,35 +153,36 @@ public class RenderChunk lvt_10_1_.func_178606_a(blockpos$mutableblockpos); } - if (block instanceof ITileEntityProvider) + if (block.hasTileEntity()) { TileEntity tileentity = iblockaccess.getTileEntity(new BlockPos(blockpos$mutableblockpos)); - ElementRenderer tileentityspecialrenderer = SpecialRenderer.instance.getRenderer(tileentity); + TileEntitySpecialRenderer tileentityspecialrenderer = TileEntityRendererDispatcher.instance.getSpecialRenderer(tileentity); if (tileentity != null && tileentityspecialrenderer != null) { compiledchunk.addTileEntity(tileentity); - if (tileentityspecialrenderer.isAlwaysRendered()) + if (tileentityspecialrenderer.forceTileEntityRender()) { - forced.add(tileentity); + lvt_11_1_.add(tileentity); } } } - if (block != Blocks.air) - { - BlockLayer layer = block.hasTransparency() ? (block.getMaterial().isLiquid() ? BlockLayer.TRANSLUCENT : BlockLayer.CUTOUT) : BlockLayer.SOLID; - int idx = layer.ordinal(); - RenderBuffer worldrenderer = generator.getRegionRenderCacheBuilder().getWorldRendererByLayerId(idx); + BlockLayer enumworldblocklayer1 = block.getBlockLayer(); + int j = enumworldblocklayer1.ordinal(); - if (!compiledchunk.isLayerStarted(layer)) + if (block.getRenderType() != -1) + { + RenderBuffer worldrenderer = generator.getRegionRenderCacheBuilder().getWorldRendererByLayerId(j); + + if (!compiledchunk.isLayerStarted(enumworldblocklayer1)) { - compiledchunk.setLayerStarted(layer); + compiledchunk.setLayerStarted(enumworldblocklayer1); this.preRenderBlocks(worldrenderer, blockpos); } - aboolean[idx] |= blockrendererdispatcher.renderBlock(iblockstate, blockpos$mutableblockpos, iblockaccess, worldrenderer); + aboolean[j] |= blockrendererdispatcher.renderBlock(iblockstate, blockpos$mutableblockpos, iblockaccess, worldrenderer); } } @@ -204,12 +205,12 @@ public class RenderChunk try { - Set set = Sets.newHashSet(forced); + Set set = Sets.newHashSet(lvt_11_1_); Set set1 = Sets.newHashSet(this.setTileEntities); set.removeAll(this.setTileEntities); - set1.removeAll(forced); + set1.removeAll(lvt_11_1_); this.setTileEntities.clear(); - this.setTileEntities.addAll(forced); + this.setTileEntities.addAll(lvt_11_1_); this.renderGlobal.updateTileEntities(set1, set); } finally @@ -353,7 +354,7 @@ public class RenderChunk public void deleteGlResources() { this.stopCompileTask(); - this.gm = null; + this.world = null; for (int i = 0; i < BlockLayer.values().length; ++i) { diff --git a/client/src/main/java/client/renderer/chunk/SetVisibility.java b/client/src/client/renderer/chunk/SetVisibility.java similarity index 100% rename from client/src/main/java/client/renderer/chunk/SetVisibility.java rename to client/src/client/renderer/chunk/SetVisibility.java diff --git a/client/src/main/java/client/renderer/chunk/VisGraph.java b/client/src/client/renderer/chunk/VisGraph.java similarity index 100% rename from client/src/main/java/client/renderer/chunk/VisGraph.java rename to client/src/client/renderer/chunk/VisGraph.java diff --git a/client/src/client/renderer/entity/Render.java b/client/src/client/renderer/entity/Render.java new file mode 100755 index 00000000..4f29cae6 --- /dev/null +++ b/client/src/client/renderer/entity/Render.java @@ -0,0 +1,378 @@ +package client.renderer.entity; + +import org.lwjgl.opengl.GL11; + +import client.Client; +import client.renderer.DefaultVertexFormats; +import client.renderer.Drawing; +import client.renderer.Frustum; +import client.renderer.GlState; +import client.renderer.RenderBuffer; +import client.renderer.Tessellator; +import client.renderer.texture.TextureAtlasSprite; +import client.renderer.texture.TextureMap; +import common.block.Block; +import common.entity.Entity; +import common.util.BlockPos; +import common.util.BoundingBox; +import common.world.World; + +public abstract class Render +{ +// public static boolean drawNames = true; +// private static final String shadowTextures = "textures/world/shadow.png"; + + protected final RenderManager renderManager; +// protected float shadowSize; +// +// /** +// * Determines the darkness of the object's shadow. Higher value makes a darker shadow. +// */ +// protected float shadowOpaque = 1.0F; + + protected Render(RenderManager renderManager) + { + this.renderManager = renderManager; + } + + public boolean shouldRender(T livingEntity, double camX, double camY, double camZ) + { + BoundingBox axisalignedbb = livingEntity.getEntityBoundingBox(); + + if (axisalignedbb.hasNaN() || axisalignedbb.getAverageEdgeLength() == 0.0D) + { + axisalignedbb = new BoundingBox(livingEntity.posX - 2.0D, livingEntity.posY - 2.0D, livingEntity.posZ - 2.0D, livingEntity.posX + 2.0D, livingEntity.posY + 2.0D, livingEntity.posZ + 2.0D); + } + + return livingEntity.isInRangeToRender3d(camX, camY, camZ) && (livingEntity.noFrustumCheck || Frustum.isInFrustum(axisalignedbb)); + } + + /** + * Renders the desired {@code T} type Entity. + */ + public void doRender(T entity, double x, double y, double z, float partialTicks) + { + this.renderName(entity, x, y, z); + } + + protected void renderName(T entity, double x, double y, double z) + { + String name = entity.getDisplayName(); + if(name != null && !name.isEmpty()) + this.renderLivingLabel(entity, name, x, y, z, 64); + } + +// protected boolean canRenderName(T entity) +// { +// return entity.hasCustomName(); +// } + + /** + * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. + */ + protected abstract String getEntityTexture(T entity); + + public boolean bindEntityTexture(T entity) + { + String resourcelocation = this.getEntityTexture(entity); + + if (resourcelocation == null) + { + return false; + } + else + { + this.bindTexture(resourcelocation); + return true; + } + } + + public void bindTexture(String location) + { + this.renderManager.renderEngine.bindTexture(location); + } + + /** + * Renders fire on top of the entity. Args: entity, x, y, z, partialTickTime + */ + private void renderEntityOnFire(Entity entity, double x, double y, double z, float partialTicks) + { + GlState.disableLighting(); + TextureMap texturemap = Client.CLIENT.getTextureMapBlocks(); + TextureAtlasSprite textureatlassprite = texturemap.getAtlasSprite("blocks/fire_layer_0"); + TextureAtlasSprite textureatlassprite1 = texturemap.getAtlasSprite("blocks/fire_layer_1"); + GL11.glPushMatrix(); + GL11.glTranslatef((float)x, (float)y, (float)z); + float f = entity.width * 1.4F; + GL11.glScalef(f, f, f); +// Tessellator tessellator = Tessellator.getInstance(); + RenderBuffer worldrenderer = Tessellator.getBuffer(); + float f1 = 0.5F; + float f2 = 0.0F; + float f3 = entity.height / f; + float f4 = (float)(entity.posY - entity.getEntityBoundingBox().minY); + GL11.glRotatef(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(0.0F, 0.0F, -0.3F + (float)((int)f3) * 0.02F); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + float f5 = 0.0F; + int i = 0; + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); + + while (f3 > 0.0F) + { + TextureAtlasSprite textureatlassprite2 = i % 2 == 0 ? textureatlassprite : textureatlassprite1; + this.bindTexture(TextureMap.locationBlocksTexture); + float f6 = textureatlassprite2.getMinU(); + float f7 = textureatlassprite2.getMinV(); + float f8 = textureatlassprite2.getMaxU(); + float f9 = textureatlassprite2.getMaxV(); + + if (i / 2 % 2 == 0) + { + float f10 = f8; + f8 = f6; + f6 = f10; + } + + worldrenderer.pos((double)(f1 - f2), (double)(0.0F - f4), (double)f5).tex((double)f8, (double)f9).endVertex(); + worldrenderer.pos((double)(-f1 - f2), (double)(0.0F - f4), (double)f5).tex((double)f6, (double)f9).endVertex(); + worldrenderer.pos((double)(-f1 - f2), (double)(1.4F - f4), (double)f5).tex((double)f6, (double)f7).endVertex(); + worldrenderer.pos((double)(f1 - f2), (double)(1.4F - f4), (double)f5).tex((double)f8, (double)f7).endVertex(); + f3 -= 0.45F; + f4 -= 0.45F; + f1 *= 0.9F; + f5 += 0.03F; + ++i; + } + + Tessellator.draw(); + GL11.glPopMatrix(); + GlState.enableLighting(); + } + +// /** +// * Renders the entity shadows at the position, shadow alpha and partialTickTime. Args: entity, x, y, z, shadowAlpha, +// * partialTickTime +// */ +// private void renderShadow(Entity entityIn, double x, double y, double z, float shadowAlpha, float partialTicks) +// { +// GlState.enableBlend(); +// GlState.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); +// this.renderManager.renderEngine.bindTexture(shadowTextures); +// World world = this.getWorldFromRenderManager(); +// GlState.depthMask(false); +// float f = this.shadowSize; +// +// if (entityIn instanceof EntityLiving) +// { +// EntityLiving entityliving = (EntityLiving)entityIn; +// f *= entityliving.getShadowSize(); +// +// if (entityliving.isChild()) +// { +// f *= 0.5F; +// } +// } +// +// double d5 = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * (double)partialTicks; +// double d0 = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * (double)partialTicks; +// double d1 = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * (double)partialTicks; +// int i = MathHelper.floor_double(d5 - (double)f); +// int j = MathHelper.floor_double(d5 + (double)f); +// int k = MathHelper.floor_double(d0 - (double)f); +// int l = MathHelper.floor_double(d0); +// int i1 = MathHelper.floor_double(d1 - (double)f); +// int j1 = MathHelper.floor_double(d1 + (double)f); +// double d2 = x - d5; +// double d3 = y - d0; +// double d4 = z - d1; +//// Tessellator tessellator = Tessellator.getInstance(); +// RenderBuffer worldrenderer = Tessellator.getBuffer(); +// worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); +// +// for (BlockPos blockpos : BlockPos.getAllInBoxMutable(new BlockPos(i, k, i1), new BlockPos(j, l, j1))) +// { +// Block block = world.getBlockState(blockpos.down()).getBlock(); +// +// if (block.getRenderType() != -1 && world.getLightFromNeighbors(blockpos) > 3) +// { +// this.renderShadowBlock(block, x, y, z, blockpos, shadowAlpha, f, d2, d3, d4); +// } +// } +// +// Tessellator.draw(); +// GlState.color(1.0F, 1.0F, 1.0F, 1.0F); +// GlState.disableBlend(); +// GlState.depthMask(true); +// } + + /** + * Returns the render manager's world object + */ + private World getWorldFromRenderManager() + { + return this.renderManager.worldObj; + } + + private void renderShadowBlock(Block blockIn, double p_180549_2_, double p_180549_4_, double p_180549_6_, BlockPos pos, float p_180549_9_, float p_180549_10_, double p_180549_11_, double p_180549_13_, double p_180549_15_) + { + if (blockIn.isFullCube()) + { +// Tessellator tessellator = Tessellator.getInstance(); + RenderBuffer worldrenderer = Tessellator.getBuffer(); + double d0 = ((double)p_180549_9_ - (p_180549_4_ - ((double)pos.getY() + p_180549_13_)) / 2.0D) * 0.5D * (double)this.getWorldFromRenderManager().getLightBrightness(pos); + + if (d0 >= 0.0D) + { + if (d0 > 1.0D) + { + d0 = 1.0D; + } + + double d1 = (double)pos.getX() + blockIn.getBlockBoundsMinX() + p_180549_11_; + double d2 = (double)pos.getX() + blockIn.getBlockBoundsMaxX() + p_180549_11_; + double d3 = (double)pos.getY() + blockIn.getBlockBoundsMinY() + p_180549_13_ + 0.015625D; + double d4 = (double)pos.getZ() + blockIn.getBlockBoundsMinZ() + p_180549_15_; + double d5 = (double)pos.getZ() + blockIn.getBlockBoundsMaxZ() + p_180549_15_; + float f = (float)((p_180549_2_ - d1) / 2.0D / (double)p_180549_10_ + 0.5D); + float f1 = (float)((p_180549_2_ - d2) / 2.0D / (double)p_180549_10_ + 0.5D); + float f2 = (float)((p_180549_6_ - d4) / 2.0D / (double)p_180549_10_ + 0.5D); + float f3 = (float)((p_180549_6_ - d5) / 2.0D / (double)p_180549_10_ + 0.5D); + worldrenderer.pos(d1, d3, d4).tex((double)f, (double)f2).color(1.0F, 1.0F, 1.0F, (float)d0).endVertex(); + worldrenderer.pos(d1, d3, d5).tex((double)f, (double)f3).color(1.0F, 1.0F, 1.0F, (float)d0).endVertex(); + worldrenderer.pos(d2, d3, d5).tex((double)f1, (double)f3).color(1.0F, 1.0F, 1.0F, (float)d0).endVertex(); + worldrenderer.pos(d2, d3, d4).tex((double)f1, (double)f2).color(1.0F, 1.0F, 1.0F, (float)d0).endVertex(); + } + } + } + + /** + * Renders a white box with the bounds of the AABB translated by the offset. Args: aabb, x, y, z + */ + public static void renderOffsetAABB(BoundingBox boundingBox, double x, double y, double z) + { + GlState.disableTexture2D(); +// Tessellator tessellator = Tessellator.getInstance(); + RenderBuffer worldrenderer = Tessellator.getBuffer(); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + worldrenderer.setTranslation(x, y, z); + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_NORMAL); + worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.minZ).normal(0.0F, 0.0F, -1.0F).endVertex(); + worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.minZ).normal(0.0F, 0.0F, -1.0F).endVertex(); + worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.minZ).normal(0.0F, 0.0F, -1.0F).endVertex(); + worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.minZ).normal(0.0F, 0.0F, -1.0F).endVertex(); + worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.maxZ).normal(0.0F, 0.0F, 1.0F).endVertex(); + worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.maxZ).normal(0.0F, 0.0F, 1.0F).endVertex(); + worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ).normal(0.0F, 0.0F, 1.0F).endVertex(); + worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.maxZ).normal(0.0F, 0.0F, 1.0F).endVertex(); + worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.minZ).normal(0.0F, -1.0F, 0.0F).endVertex(); + worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.minZ).normal(0.0F, -1.0F, 0.0F).endVertex(); + worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.maxZ).normal(0.0F, -1.0F, 0.0F).endVertex(); + worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.maxZ).normal(0.0F, -1.0F, 0.0F).endVertex(); + worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.maxZ).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.minZ).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.minZ).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.maxZ).normal(-1.0F, 0.0F, 0.0F).endVertex(); + worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.maxZ).normal(-1.0F, 0.0F, 0.0F).endVertex(); + worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.minZ).normal(-1.0F, 0.0F, 0.0F).endVertex(); + worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.minZ).normal(-1.0F, 0.0F, 0.0F).endVertex(); + worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.minZ).normal(1.0F, 0.0F, 0.0F).endVertex(); + worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.minZ).normal(1.0F, 0.0F, 0.0F).endVertex(); + worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ).normal(1.0F, 0.0F, 0.0F).endVertex(); + worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.maxZ).normal(1.0F, 0.0F, 0.0F).endVertex(); + Tessellator.draw(); + worldrenderer.setTranslation(0.0D, 0.0D, 0.0D); + GlState.enableTexture2D(); + } + + public void doRenderShadowAndFire(Entity entityIn, double x, double y, double z, float partialTicks) + { + if (this.renderManager.gm != null) + { +// if (this.renderManager.options.entityShadows && this.shadowSize > 0.0F && !entityIn.isInvisible() && this.renderManager.isRenderShadow()) +// { +// double d0 = this.renderManager.getDistanceToCamera(entityIn.posX, entityIn.posY, entityIn.posZ); +// float f = (float)((1.0D - d0 / 256.0D) * (double)this.shadowOpaque); +// +// if (f > 0.0F) +// { +// this.renderShadow(entityIn, x, y, z, f, partialTicks); +// } +// } + + if (entityIn.canRenderOnFire()) // && (!(entityIn.isPlayer()) || !((EntityNPC)entityIn).isSpectator())) + { + this.renderEntityOnFire(entityIn, x, y, z, partialTicks); + } + } + } + + protected void renderLivingLabel(T entityIn, String str, double x, double y, double z, int maxDistance) { + double d0 = entityIn.getDistanceSqToEntity(this.renderManager.livingPlayer); + if (d0 <= (double)(maxDistance * maxDistance) && this.renderManager.gm.canRenderHud()) { +// WCF.glPushMatrix(); +// WCF.glTranslatef((float)x, (float)y + entityIn.height + 0.5f, (float)z); +// float f = 1.0f / 64.0f; +// WCF.glScalef(f, f, f); +// int w, h; +// Vec2i size = Drawing.txt_size(0, 0, 0, 0, 65536, 65536, Font.DEFAULT, str); +// int tx = - size.xpos / 2; +// int ty = - size.ypos; +// Drawing.txt_draw(tx, ty, tx, ty, tx + 440, ty + 260, 0xffffffff, 0x3f000000, Font.DEFAULT, str); +//// this.renderManager.addOverlay(x, y + (double)entityIn.height + 0.5, z, str); +// WCF.glPopMatrix(); + +// FontRenderer fontrenderer = this.getFontRendererFromRenderManager(); + float f = 1.0f; // 1.6F; + float f1 = 0.016666668F * f; + GL11.glPushMatrix(); + GL11.glTranslatef((float)x + 0.0F, (float)y + entityIn.height + 0.5F, (float)z); + GL11.glNormal3f(0.0F, 1.0F, 0.0F); + GL11.glRotatef(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F); + GL11.glScalef(-f1, -f1, f1); + GlState.disableLighting(); + GlState.depthMask(false); +// GlState.disableDepth(); + GlState.enableBlend(); + GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); +// Tessellator tessellator = Tessellator.getInstance(); + RenderBuffer worldrenderer = Tessellator.getBuffer(); +// int i = 0; + +// if (str.equals("deadmau5")) +// { +// i = -10; +// } + +// Vec2i size = Drawing.txt_size(0, 0, 0, 0, 65536, 65536, str); +// int j = size.xpos / 2; +// GlState.disableTexture2D(); +// worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); +// worldrenderer.pos((double)(-j - 1), (double)(-1 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); +// worldrenderer.pos((double)(-j - 1), (double)(8 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); +// worldrenderer.pos((double)(j + 1), (double)(8 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); +// worldrenderer.pos((double)(j + 1), (double)(-1 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); +// Tessellator.draw(); +// GlState.enableTexture2D(); +// int tx = -size.xpos / 2; // j; +// int ty = 0; // i; +// Drawing.txt_draw(tx, ty, tx, ty, tx + 440, ty + 260, /* 0xffffffff */ 553648127, 0x3f000000, Font.DEFAULT, str); +// FontRenderer.drawString(str, -FontRenderer.getStringWidth(str) / 2, i, 553648127); +// GlState.enableDepth(); + GlState.depthMask(true); + Drawing.drawTextboxCentered(str, 0, 0, 0x3f000000); +// FontRenderer.drawString(str, -FontRenderer.getStringWidth(str) / 2, i, -1); + GlState.enableLighting(); + GlState.disableBlend(); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glPopMatrix(); + } + } + + public RenderManager getRenderManager() + { + return this.renderManager; + } +} diff --git a/client/src/main/java/client/renderer/entity/RenderArachnoid.java b/client/src/client/renderer/entity/RenderArachnoid.java similarity index 93% rename from client/src/main/java/client/renderer/entity/RenderArachnoid.java rename to client/src/client/renderer/entity/RenderArachnoid.java index c34656dc..1a356522 100755 --- a/client/src/main/java/client/renderer/entity/RenderArachnoid.java +++ b/client/src/client/renderer/entity/RenderArachnoid.java @@ -11,7 +11,7 @@ public class RenderArachnoid extends RenderHumanoid { public RenderArachnoid(RenderManager renderManagerIn) { - super(renderManagerIn, new ModelArachnoid(), 12, 12, false, "textures/npc/arachnoid.png"); + super(renderManagerIn, new ModelArachnoid(), 12, 12, false, "textures/entity/arachnoid.png"); this.addLayer(new LayerArachnoidArmor(this)); // this.addLayer(new LayerSpiderEyes(this)); } @@ -36,6 +36,11 @@ public class RenderArachnoid extends RenderHumanoid // public boolean canSneak() { // return false; // } + +// public String getDefaultTexture() +// { +// return "textures/entity/npc/arachnoid.png"; +// } // public int getCompressedSize() { // return super.getCompressedSize() + 2616; diff --git a/client/src/main/java/client/renderer/entity/RenderArrow.java b/client/src/client/renderer/entity/RenderArrow.java similarity index 98% rename from client/src/main/java/client/renderer/entity/RenderArrow.java rename to client/src/client/renderer/entity/RenderArrow.java index 9e816fc7..59b26ab0 100755 --- a/client/src/main/java/client/renderer/entity/RenderArrow.java +++ b/client/src/client/renderer/entity/RenderArrow.java @@ -12,7 +12,7 @@ import common.util.ExtMath; public class RenderArrow extends Render { - private static final String arrowTextures = "textures/object/arrow.png"; + private static final String arrowTextures = "textures/entity/arrow.png"; public RenderArrow(RenderManager renderManagerIn) { diff --git a/client/src/main/java/client/renderer/entity/RenderBat.java b/client/src/client/renderer/entity/RenderBat.java similarity index 94% rename from client/src/main/java/client/renderer/entity/RenderBat.java rename to client/src/client/renderer/entity/RenderBat.java index 0e621efe..0aa6c4a0 100755 --- a/client/src/main/java/client/renderer/entity/RenderBat.java +++ b/client/src/client/renderer/entity/RenderBat.java @@ -9,7 +9,7 @@ import common.util.ExtMath; public class RenderBat extends RenderLiving { - private static final String batTextures = "textures/creature/bat.png"; + private static final String batTextures = "textures/entity/bat.png"; public RenderBat(RenderManager renderManagerIn) { diff --git a/client/src/main/java/client/renderer/entity/RenderBlockEntity.java b/client/src/client/renderer/entity/RenderBlockEntity.java similarity index 94% rename from client/src/main/java/client/renderer/entity/RenderBlockEntity.java rename to client/src/client/renderer/entity/RenderBlockEntity.java index 60a4f397..8d40d113 100755 --- a/client/src/main/java/client/renderer/entity/RenderBlockEntity.java +++ b/client/src/client/renderer/entity/RenderBlockEntity.java @@ -45,7 +45,7 @@ public class RenderBlockEntity extends Render // float f2 = (1.0F - ((float)entity.fuse - partialTicks + 1.0F) / 100.0F) * 0.8F; this.bindEntityTexture(entity); GL11.glTranslatef(-0.5F, -0.5F, 0.5F); - blockrendererdispatcher.renderBlockEntity(state, entity.getBrightness(partialTicks)); + blockrendererdispatcher.renderBlockBrightness(state, entity.getBrightness(partialTicks)); GL11.glTranslatef(0.0F, 0.0F, 1.0F); // if (entity.fuse / 5 % 2 == 0) @@ -75,6 +75,6 @@ public class RenderBlockEntity extends Render */ protected String getEntityTexture(Entity entity) { - return TextureMap.BLOCKS; + return TextureMap.locationBlocksTexture; } } diff --git a/client/src/main/java/client/renderer/entity/RenderBoat.java b/client/src/client/renderer/entity/RenderBoat.java similarity index 96% rename from client/src/main/java/client/renderer/entity/RenderBoat.java rename to client/src/client/renderer/entity/RenderBoat.java index 4bb7c7fe..a9fafcae 100755 --- a/client/src/main/java/client/renderer/entity/RenderBoat.java +++ b/client/src/client/renderer/entity/RenderBoat.java @@ -10,7 +10,7 @@ import common.util.ExtMath; public class RenderBoat extends Render { - private static final String boatTextures = "textures/object/boat.png"; + private static final String boatTextures = "textures/entity/boat.png"; /** instance of ModelBoat for rendering */ protected ModelBase modelBoat = new ModelBoat(); diff --git a/client/src/main/java/client/renderer/entity/RenderBullet.java b/client/src/client/renderer/entity/RenderBullet.java similarity index 97% rename from client/src/main/java/client/renderer/entity/RenderBullet.java rename to client/src/client/renderer/entity/RenderBullet.java index 6fe7ad2e..c1433122 100755 --- a/client/src/main/java/client/renderer/entity/RenderBullet.java +++ b/client/src/client/renderer/entity/RenderBullet.java @@ -11,7 +11,7 @@ import common.entity.projectile.EntityBullet; public class RenderBullet extends Render { - private static final String bulletTextures = "textures/object/bullet.png"; + private static final String bulletTextures = "textures/entity/bullet.png"; public RenderBullet(RenderManager renderManagerIn) { diff --git a/client/src/client/renderer/entity/RenderChicken.java b/client/src/client/renderer/entity/RenderChicken.java new file mode 100755 index 00000000..9afeff9c --- /dev/null +++ b/client/src/client/renderer/entity/RenderChicken.java @@ -0,0 +1,34 @@ +package client.renderer.entity; + +import client.renderer.model.ModelBase; +import common.entity.animal.EntityChicken; +import common.util.ExtMath; + + +public class RenderChicken extends RenderLiving +{ + private static final String chickenTextures = "textures/entity/chicken.png"; + + public RenderChicken(RenderManager renderManagerIn, ModelBase modelBaseIn) + { + super(renderManagerIn, modelBaseIn); + } + + /** + * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. + */ + protected String getEntityTexture(EntityChicken entity) + { + return chickenTextures; + } + + /** + * Defines what float the third param in setRotationAngles of ModelBase is + */ + protected float handleRotationFloat(EntityChicken livingBase, float partialTicks) + { + float f = livingBase.field_70888_h + (livingBase.wingRotation - livingBase.field_70888_h) * partialTicks; + float f1 = livingBase.field_70884_g + (livingBase.destPos - livingBase.field_70884_g) * partialTicks; + return (ExtMath.sin(f) + 1.0F) * f1; + } +} diff --git a/client/src/main/java/client/renderer/entity/RenderCow.java b/client/src/client/renderer/entity/RenderCow.java similarity index 87% rename from client/src/main/java/client/renderer/entity/RenderCow.java rename to client/src/client/renderer/entity/RenderCow.java index c46711f0..b6280ab4 100755 --- a/client/src/main/java/client/renderer/entity/RenderCow.java +++ b/client/src/client/renderer/entity/RenderCow.java @@ -6,7 +6,7 @@ import common.entity.animal.EntityCow; public class RenderCow extends RenderLiving { - private static final String cowTextures = "textures/creature/cow.png"; + private static final String cowTextures = "textures/entity/cow.png"; public RenderCow(RenderManager renderManagerIn, ModelBase modelBaseIn) { diff --git a/client/src/main/java/client/renderer/entity/RenderCrystal.java b/client/src/client/renderer/entity/RenderCrystal.java similarity index 94% rename from client/src/main/java/client/renderer/entity/RenderCrystal.java rename to client/src/client/renderer/entity/RenderCrystal.java index bdaa469d..d5642b17 100755 --- a/client/src/main/java/client/renderer/entity/RenderCrystal.java +++ b/client/src/client/renderer/entity/RenderCrystal.java @@ -10,7 +10,7 @@ import common.util.ExtMath; public class RenderCrystal extends Render { - private static final String crystalTextures = "textures/object/crystal.png"; + private static final String crystalTextures = "textures/entity/crystal.png"; private ModelBase modelCrystal = new ModelCrystal(0.0F, false); diff --git a/client/src/main/java/client/renderer/entity/RenderDie.java b/client/src/client/renderer/entity/RenderDie.java similarity index 89% rename from client/src/main/java/client/renderer/entity/RenderDie.java rename to client/src/client/renderer/entity/RenderDie.java index 976325af..38be9de0 100755 --- a/client/src/main/java/client/renderer/entity/RenderDie.java +++ b/client/src/client/renderer/entity/RenderDie.java @@ -6,6 +6,7 @@ import client.Client; import client.renderer.model.ModelDie; import client.renderer.texture.TextureMap; import common.entity.projectile.EntityDie; +import common.model.Transforms.Camera; public class RenderDie extends Render { @@ -19,7 +20,7 @@ public class RenderDie extends Render protected String getEntityTexture(EntityDie entity) { - return TextureMap.BLOCKS; + return TextureMap.locationBlocksTexture; } public void doRender(EntityDie entity, double x, double y, double z, float partialTicks) @@ -32,7 +33,7 @@ public class RenderDie extends Render GL11.glRotatef((float)((entity.ticksExisted % 10) * (360 / 10)), 0.3f, 0.4f, 0.1f); // GlState.translate(-0.05F, -0.05F, 0.05F); GL11.glScalef(0.5f, 0.5f, 0.5f); - Client.CLIENT.getRenderItem().renderItemAsGround(entity.getStack()); + Client.CLIENT.getRenderItem().renderItem(entity.getStack(), Camera.GROUND); // blockrendererdispatcher.renderBlockBrightness(Blocks.planks.getDefaultState(), entity.getBrightness(partialTicks)); GL11.glPopMatrix(); super.doRender(entity, x, y, z, partialTicks); diff --git a/client/src/client/renderer/entity/RenderDragon.java b/client/src/client/renderer/entity/RenderDragon.java new file mode 100755 index 00000000..e76f6363 --- /dev/null +++ b/client/src/client/renderer/entity/RenderDragon.java @@ -0,0 +1,104 @@ +package client.renderer.entity; + +import org.lwjgl.opengl.GL11; + +import client.renderer.GlState; +import client.renderer.layers.LayerEnderDragonEyes; +import client.renderer.model.ModelDragon; +import common.entity.animal.EntityDragon; +import common.util.ExtMath; + + +public class RenderDragon extends RenderLiving +{ + private static final String enderDragonTextures = "textures/entity/dragon.png"; + + /** An instance of the dragon model in RenderDragon */ + protected ModelDragon modelDragon; + + public RenderDragon(RenderManager renderManagerIn) + { + super(renderManagerIn, new ModelDragon(0.0F)); + this.modelDragon = (ModelDragon)this.mainModel; + this.addLayer(new LayerEnderDragonEyes(this)); +// this.addLayer(new LayerEntityBreak()); + } + + protected void rotateCorpse(EntityDragon bat, float p_77043_2_, float p_77043_3_, float partialTicks) + { + float f = (float)bat.getMovementOffsets(7, partialTicks)[0]; + float f1 = (float)(bat.getMovementOffsets(5, partialTicks)[1] - bat.getMovementOffsets(10, partialTicks)[1]); + GL11.glRotatef(-f, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(f1 * 10.0F, 1.0F, 0.0F, 0.0F); + GL11.glTranslatef(0.0F, 0.0F, 1.0F); + + if (bat.deathTime > 0) + { + float f2 = ((float)bat.deathTime + partialTicks - 1.0F) / 20.0F * 1.6F; + f2 = ExtMath.sqrtf(f2); + + if (f2 > 1.0F) + { + f2 = 1.0F; + } + + GL11.glRotatef(f2 * this.getDeathMaxRotation(bat), 0.0F, 0.0F, 1.0F); + } + } + + /** + * Renders the model in RenderLiving + */ + protected void renderModel(EntityDragon entitylivingbaseIn, float p_77036_2_, float p_77036_3_, float p_77036_4_, float p_77036_5_, float p_77036_6_, float scaleFactor) + { +// if (entitylivingbaseIn.deathTicks > 0) +// { +// float f = (float)entitylivingbaseIn.deathTicks / 200.0F; +// GlState.depthFunc(GL11.GL_LEQUAL); +// GlState.enableAlpha(); +// GlState.alphaFunc(GL11.GL_GREATER, f); +// this.bindTexture(enderDragonExplodingTextures); +// this.mainModel.render(entitylivingbaseIn, p_77036_2_, p_77036_3_, p_77036_4_, p_77036_5_, p_77036_6_, scaleFactor); +// GlState.alphaFunc(GL11.GL_GREATER, 0.1F); +// GlState.depthFunc(GL11.GL_EQUAL); +// } + + this.bindEntityTexture(entitylivingbaseIn); + this.mainModel.render(entitylivingbaseIn, p_77036_2_, p_77036_3_, p_77036_4_, p_77036_5_, p_77036_6_, scaleFactor); + + if (entitylivingbaseIn.hurtTime > 0) + { + GlState.depthFunc(GL11.GL_EQUAL); + GlState.disableTexture2D(); + GlState.enableBlend(); + GlState.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlState.color(1.0F, 0.0F, 0.0F, 0.5F); + this.mainModel.render(entitylivingbaseIn, p_77036_2_, p_77036_3_, p_77036_4_, p_77036_5_, p_77036_6_, scaleFactor); + GlState.enableTexture2D(); + GlState.disableBlend(); + GlState.depthFunc(GL11.GL_LEQUAL); + } + } + +// /** +// * Renders the desired {@code T} type Entity. +// */ +// public void doRender(EntityDragon entity, double x, double y, double z, float entityYaw, float partialTicks) +// { +// BossStatus.setBossStatus(entity); +// super.doRender(entity, x, y, z, entityYaw, partialTicks); +// +//// if (entity.healingEnderCrystal != null) +//// { +//// this.drawRechargeRay(entity, x, y, z, partialTicks); +//// } +// } + + /** + * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. + */ + protected String getEntityTexture(EntityDragon entity) + { + return enderDragonTextures; + } +} diff --git a/client/src/client/renderer/entity/RenderDynamite.java b/client/src/client/renderer/entity/RenderDynamite.java new file mode 100755 index 00000000..376e2aeb --- /dev/null +++ b/client/src/client/renderer/entity/RenderDynamite.java @@ -0,0 +1,16 @@ +package client.renderer.entity; + +import common.entity.projectile.EntityDynamite; +import common.item.Item; +import common.item.ItemStack; + +public class RenderDynamite extends RenderItemEntity { + public RenderDynamite(RenderManager renderManagerIn, Item itemIn, RenderItem renderItemIn) { + super(renderManagerIn, itemIn, renderItemIn); + } + + public ItemStack getStack(EntityDynamite entityIn) + { + return new ItemStack(this.item, 1, entityIn.explosionSize); + } +} diff --git a/client/src/client/renderer/entity/RenderEntity.java b/client/src/client/renderer/entity/RenderEntity.java new file mode 100755 index 00000000..40f7baa5 --- /dev/null +++ b/client/src/client/renderer/entity/RenderEntity.java @@ -0,0 +1,33 @@ +package client.renderer.entity; + +import org.lwjgl.opengl.GL11; + +import common.entity.Entity; + + +public class RenderEntity extends Render +{ + public RenderEntity(RenderManager renderManagerIn) + { + super(renderManagerIn); + } + + /** + * Renders the desired {@code T} type Entity. + */ + public void doRender(Entity entity, double x, double y, double z, float partialTicks) + { + GL11.glPushMatrix(); + renderOffsetAABB(entity.getEntityBoundingBox(), x - entity.lastTickPosX, y - entity.lastTickPosY, z - entity.lastTickPosZ); + GL11.glPopMatrix(); + super.doRender(entity, x, y, z, partialTicks); + } + + /** + * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. + */ + protected String getEntityTexture(Entity entity) + { + return null; + } +} diff --git a/client/src/main/java/client/renderer/entity/RenderEntityItem.java b/client/src/client/renderer/entity/RenderEntityItem.java similarity index 81% rename from client/src/main/java/client/renderer/entity/RenderEntityItem.java rename to client/src/client/renderer/entity/RenderEntityItem.java index 167fc1ae..21e8fd50 100755 --- a/client/src/main/java/client/renderer/entity/RenderEntityItem.java +++ b/client/src/client/renderer/entity/RenderEntityItem.java @@ -8,6 +8,7 @@ import client.renderer.texture.TextureMap; import common.entity.item.EntityItem; import common.item.Item; import common.item.ItemStack; +import common.model.Transforms; import common.rng.Random; import common.util.ExtMath; @@ -36,12 +37,13 @@ public class RenderEntityItem extends Render else { boolean flag = p_177077_9_.isGui3d(); - int i = this.getMultiplier(itemstack); + int i = this.func_177078_a(itemstack); float f = 0.25F; float f1 = ExtMath.sin(((float)itemIn.getAge() + p_177077_8_) / 10.0F + itemIn.hoverStart) * 0.1F + 0.1F; - GL11.glTranslatef((float)p_177077_2_, (float)p_177077_4_ + f1 + 0.25F, (float)p_177077_6_); + float f2 = p_177077_9_.getItemCameraTransforms().get(Transforms.Camera.GROUND).scale.y; + GL11.glTranslatef((float)p_177077_2_, (float)p_177077_4_ + f1 + 0.25F * f2, (float)p_177077_6_); - if (flag || this.manager.gm != null) + if (flag || this.renderManager.gm != null) { float f3 = (((float)itemIn.getAge() + p_177077_8_) / 20.0F + itemIn.hoverStart) * (180F / (float)Math.PI); GL11.glRotatef(f3, 0.0F, 1.0F, 0.0F); @@ -60,23 +62,23 @@ public class RenderEntityItem extends Render } } - private int getMultiplier(ItemStack stack) + private int func_177078_a(ItemStack stack) { int i = 1; - if (stack.getSize() > 48) + if (stack.stackSize > 48) { i = 5; } - else if (stack.getSize() > 32) + else if (stack.stackSize > 32) { i = 4; } - else if (stack.getSize() > 16) + else if (stack.stackSize > 16) { i = 3; } - else if (stack.getSize() > 1) + else if (stack.stackSize > 1) { i = 2; } @@ -124,15 +126,20 @@ public class RenderEntityItem extends Render } GL11.glScalef(0.5F, 0.5F, 0.5F); + RenderItem.apply(ibakedmodel.getItemCameraTransforms(), Transforms.Camera.GROUND); this.itemRenderer.renderItem(itemstack, ibakedmodel); GL11.glPopMatrix(); } else { GL11.glPushMatrix(); + RenderItem.apply(ibakedmodel.getItemCameraTransforms(), Transforms.Camera.GROUND); this.itemRenderer.renderItem(itemstack, ibakedmodel); GL11.glPopMatrix(); - GL11.glTranslatef(0.0F, 0.0F, 0.046875F); + float f3 = ibakedmodel.getItemCameraTransforms().ground.scale.x; + float f4 = ibakedmodel.getItemCameraTransforms().ground.scale.y; + float f5 = ibakedmodel.getItemCameraTransforms().ground.scale.z; + GL11.glTranslatef(0.0F * f3, 0.0F * f4, 0.046875F * f5); } } @@ -154,7 +161,7 @@ public class RenderEntityItem extends Render */ protected String getEntityTexture(EntityItem entity) { - return TextureMap.BLOCKS; + return TextureMap.locationBlocksTexture; } // protected boolean canRenderName(EntityItem entity) diff --git a/client/src/client/renderer/entity/RenderFallingBlock.java b/client/src/client/renderer/entity/RenderFallingBlock.java new file mode 100755 index 00000000..c004df8c --- /dev/null +++ b/client/src/client/renderer/entity/RenderFallingBlock.java @@ -0,0 +1,74 @@ +package client.renderer.entity; + +import org.lwjgl.opengl.GL11; + +import client.Client; +import client.renderer.BlockRenderer; +import client.renderer.DefaultVertexFormats; +import client.renderer.GlState; +import client.renderer.RenderBuffer; +import client.renderer.Tessellator; +import client.renderer.blockmodel.IBakedModel; +import client.renderer.texture.TextureMap; +import common.block.Block; +import common.entity.item.EntityFalling; +import common.util.BlockPos; +import common.world.State; +import common.world.World; + +public class RenderFallingBlock extends Render +{ + public RenderFallingBlock(RenderManager renderManagerIn) + { + super(renderManagerIn); +// this.shadowSize = 0.5F; + } + + /** + * Renders the desired {@code T} type Entity. + */ + public void doRender(EntityFalling entity, double x, double y, double z, float partialTicks) + { + if (entity.getBlock() != null) + { + this.bindTexture(TextureMap.locationBlocksTexture); + State iblockstate = entity.getBlock(); + Block block = iblockstate.getBlock(); + BlockPos blockpos = new BlockPos(entity); + World world = entity.getWorldObj(); + + if (iblockstate != world.getState(blockpos) && block.getRenderType() != -1) + { + if (block.getRenderType() == 3) + { + GL11.glPushMatrix(); + GL11.glTranslatef((float)x, (float)y, (float)z); + GlState.disableLighting(); +// Tessellator tessellator = Tessellator.getInstance(); + RenderBuffer worldrenderer = Tessellator.getBuffer(); + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); + int i = blockpos.getX(); + int j = blockpos.getY(); + int k = blockpos.getZ(); + worldrenderer.setTranslation((double)((float)(-i) - 0.5F), (double)(-j), (double)((float)(-k) - 0.5F)); + BlockRenderer blockrendererdispatcher = Client.CLIENT.getBlockRendererDispatcher(); + IBakedModel ibakedmodel = blockrendererdispatcher.getModelFromBlockState(iblockstate, world, (BlockPos)null); + blockrendererdispatcher.renderModel(world, ibakedmodel, iblockstate, blockpos, worldrenderer, false); + worldrenderer.setTranslation(0.0D, 0.0D, 0.0D); + Tessellator.draw(); + GlState.enableLighting(); + GL11.glPopMatrix(); + super.doRender(entity, x, y, z, partialTicks); + } + } + } + } + + /** + * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. + */ + protected String getEntityTexture(EntityFalling entity) + { + return TextureMap.locationBlocksTexture; + } +} diff --git a/client/src/main/java/client/renderer/entity/RenderFireball.java b/client/src/client/renderer/entity/RenderFireball.java similarity index 85% rename from client/src/main/java/client/renderer/entity/RenderFireball.java rename to client/src/client/renderer/entity/RenderFireball.java index cdc1caa2..0e68614c 100755 --- a/client/src/main/java/client/renderer/entity/RenderFireball.java +++ b/client/src/client/renderer/entity/RenderFireball.java @@ -7,7 +7,7 @@ import client.renderer.DefaultVertexFormats; import client.renderer.GlState; import client.renderer.RenderBuffer; import client.renderer.Tessellator; -import client.renderer.texture.Sprite; +import client.renderer.texture.TextureAtlasSprite; import client.renderer.texture.TextureMap; import common.entity.projectile.EntityProjectile; import common.init.Items; @@ -33,7 +33,7 @@ public class RenderFireball extends Render GL11.glTranslatef((float)x, (float)y, (float)z); GlState.enableRescaleNormal(); GL11.glScalef(this.scale, this.scale, this.scale); - Sprite textureatlassprite = Client.CLIENT.getRenderItem().getItemModelMesher().getParticleIcon(Items.fireball); + TextureAtlasSprite textureatlassprite = Client.CLIENT.getRenderItem().getItemModelMesher().getParticleIcon(Items.fire_charge); // Tessellator tessellator = Tessellator.getInstance(); RenderBuffer worldrenderer = Tessellator.getBuffer(); float f = textureatlassprite.getMinU(); @@ -43,8 +43,8 @@ public class RenderFireball extends Render float f4 = 1.0F; float f5 = 0.5F; float f6 = 0.25F; - GL11.glRotatef(180.0F - this.manager.playerViewY, 0.0F, 1.0F, 0.0F); - GL11.glRotatef(-this.manager.playerViewX, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F); worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_NORMAL); worldrenderer.pos(-0.5D, -0.25D, 0.0D).tex((double)f, (double)f3).normal(0.0F, 1.0F, 0.0F).endVertex(); worldrenderer.pos(0.5D, -0.25D, 0.0D).tex((double)f1, (double)f3).normal(0.0F, 1.0F, 0.0F).endVertex(); @@ -61,6 +61,6 @@ public class RenderFireball extends Render */ protected String getEntityTexture(EntityProjectile entity) { - return TextureMap.BLOCKS; + return TextureMap.locationBlocksTexture; } } diff --git a/client/src/main/java/client/renderer/entity/RenderFish.java b/client/src/client/renderer/entity/RenderFish.java similarity index 84% rename from client/src/main/java/client/renderer/entity/RenderFish.java rename to client/src/client/renderer/entity/RenderFish.java index a5bbacbc..6782994a 100755 --- a/client/src/main/java/client/renderer/entity/RenderFish.java +++ b/client/src/client/renderer/entity/RenderFish.java @@ -7,14 +7,13 @@ import client.renderer.DefaultVertexFormats; import client.renderer.GlState; import client.renderer.RenderBuffer; import client.renderer.Tessellator; +import client.renderer.particle.EffectRenderer; import common.entity.projectile.EntityHook; import common.util.ExtMath; import common.util.Vec3; public class RenderFish extends Render { - private static final String TEXTURE = "textures/object/hook.png"; - public RenderFish(RenderManager renderManagerIn) { super(renderManagerIn); @@ -41,13 +40,13 @@ public class RenderFish extends Render float f4 = 1.0F; float f5 = 0.5F; float f6 = 0.5F; - GL11.glRotatef(180.0F - this.manager.playerViewY, 0.0F, 1.0F, 0.0F); - GL11.glRotatef(-this.manager.playerViewX, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F); worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_NORMAL); - worldrenderer.pos(-0.5D, -0.5D, 0.0D).tex(0.0D, 0.25D).normal(0.0F, 1.0F, 0.0F).endVertex(); - worldrenderer.pos(0.5D, -0.5D, 0.0D).tex(0.25D, 0.25D).normal(0.0F, 1.0F, 0.0F).endVertex(); - worldrenderer.pos(0.5D, 0.5D, 0.0D).tex(0.25D, 0.0D).normal(0.0F, 1.0F, 0.0F).endVertex(); - worldrenderer.pos(-0.5D, 0.5D, 0.0D).tex(0.0D, 0.0D).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldrenderer.pos(-0.5D, -0.5D, 0.0D).tex(0.0625D, 0.1875D).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldrenderer.pos(0.5D, -0.5D, 0.0D).tex(0.125D, 0.1875D).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldrenderer.pos(0.5D, 0.5D, 0.0D).tex(0.125D, 0.125D).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldrenderer.pos(-0.5D, 0.5D, 0.0D).tex(0.0625D, 0.125D).normal(0.0F, 1.0F, 0.0F).endVertex(); Tessellator.draw(); GlState.disableRescaleNormal(); GL11.glPopMatrix(); @@ -66,7 +65,7 @@ public class RenderFish extends Render double d2 = entity.angler.prevZ + (entity.angler.posZ - entity.angler.prevZ) * (double)partialTicks + vec3.zCoord; double d3 = (double)entity.angler.getEyeHeight(); - if (this.manager.gm != null && this.manager.gm.thirdPersonView > 0 || entity.angler != Client.CLIENT.player || this.manager.gm != null && this.manager.gm.showPlayerFirstPerson) + if (this.renderManager.gm != null && this.renderManager.gm.thirdPersonView > 0 || entity.angler != Client.CLIENT.player) { float f9 = (entity.angler.prevYawOffset + (entity.angler.yawOffset - entity.angler.prevYawOffset) * partialTicks) * (float)Math.PI / 180.0F; double d4 = (double)ExtMath.sin(f9); @@ -108,6 +107,6 @@ public class RenderFish extends Render */ protected String getEntityTexture(EntityHook entity) { - return TEXTURE; + return EffectRenderer.particleTextures; } } diff --git a/client/src/main/java/client/renderer/entity/RenderFlyingBox.java b/client/src/client/renderer/entity/RenderFlyingBox.java similarity index 93% rename from client/src/main/java/client/renderer/entity/RenderFlyingBox.java rename to client/src/client/renderer/entity/RenderFlyingBox.java index b1ad0e8d..a8518c5c 100755 --- a/client/src/main/java/client/renderer/entity/RenderFlyingBox.java +++ b/client/src/client/renderer/entity/RenderFlyingBox.java @@ -9,8 +9,8 @@ import common.entity.projectile.EntityBox; public class RenderFlyingBox extends Render { - private static final String BOX_TEX = "textures/object/box.png"; - private static final String BRITTLE_TEX = "textures/object/box_brittle.png"; + private static final String BOX_TEX = "textures/entity/box.png"; + private static final String BRITTLE_TEX = "textures/entity/box_brittle.png"; private final ModelHead boxModel = new ModelHead(); public RenderFlyingBox(RenderManager renderManagerIn) diff --git a/client/src/client/renderer/entity/RenderHorse.java b/client/src/client/renderer/entity/RenderHorse.java new file mode 100755 index 00000000..36656ebc --- /dev/null +++ b/client/src/client/renderer/entity/RenderHorse.java @@ -0,0 +1,100 @@ +package client.renderer.entity; + +import java.util.Set; + +import org.lwjgl.opengl.GL11; + +import client.Client; +import client.renderer.model.ModelHorse; +import client.renderer.texture.LayeredTexture; +import common.collect.Sets; +import common.entity.animal.EntityHorse; + +public class RenderHorse extends RenderLiving +{ + private static final Set loaded = Sets.newHashSet(); + private static final String whiteHorseTextures = "textures/entity/horse_white.png"; + private static final String muleTextures = "textures/entity/mule.png"; + private static final String donkeyTextures = "textures/entity/donkey.png"; + private static final String zombieHorseTextures = "textures/entity/horse_zombie.png"; + private static final String skeletonHorseTextures = "textures/entity/horse_skeleton.png"; + + public RenderHorse(RenderManager rendermanagerIn, ModelHorse model) + { + super(rendermanagerIn, model); + } + + /** + * Allows the render to do any OpenGL state modifications necessary before the model is rendered. Args: + * entityLiving, partialTickTime + */ + protected void preRenderCallback(EntityHorse entitylivingbaseIn, float partialTickTime) + { + float f = 1.0F; + int i = entitylivingbaseIn.getHorseType(); + + if (i == 1) + { + f *= 0.87F; + } + else if (i == 2) + { + f *= 0.92F; + } + + GL11.glScalef(f, f, f); + super.preRenderCallback(entitylivingbaseIn, partialTickTime); + } + + /** + * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. + */ + protected String getEntityTexture(EntityHorse entity) + { + if (!entity.func_110239_cn()) + { + switch (entity.getHorseType()) + { + case 0: + default: + return whiteHorseTextures; + + case 1: + return donkeyTextures; + + case 2: + return muleTextures; + + case 3: + return zombieHorseTextures; + + case 4: + return skeletonHorseTextures; + } + } + else + { + return this.func_110848_b(entity); + } + } + + private String func_110848_b(EntityHorse horse) + { + String s = horse.getHorseTexture(); + + if (!horse.func_175507_cI()) + { + return null; + } + else + { + if (!loaded.contains(s)) + { + Client.CLIENT.getTextureManager().loadTexture(s, new LayeredTexture(horse.getVariantTexturePaths())); + loaded.add(s); + } + + return s; + } + } +} diff --git a/client/src/main/java/client/renderer/entity/RenderHumanoid.java b/client/src/client/renderer/entity/RenderHumanoid.java similarity index 93% rename from client/src/main/java/client/renderer/entity/RenderHumanoid.java rename to client/src/client/renderer/entity/RenderHumanoid.java index c201b658..42660a5d 100755 --- a/client/src/main/java/client/renderer/entity/RenderHumanoid.java +++ b/client/src/client/renderer/entity/RenderHumanoid.java @@ -69,12 +69,12 @@ public class RenderHumanoid extends RenderNpc public void doRender(EntityNPC entity, double x, double y, double z, float partialTicks) { - if (entity != this.manager.gm.player || this.manager.livingPlayer == entity) + if (entity != this.renderManager.gm.player || this.renderManager.livingPlayer == entity) { // if(entity.isBoss()) // BossStatus.setBossStatus(entity); double d0 = y; - if(/* this.canSneak() && */ entity.isSneakingVisually() && entity != this.manager.gm.player) + if(/* this.canSneak() && */ entity.isSneakingVisually() && entity != this.renderManager.gm.player) d0 = y - 0.125D; this.setModelVisibilities(entity); super.doRender(entity, x, d0, z, partialTicks); @@ -112,9 +112,6 @@ public class RenderHumanoid extends RenderNpc ItemStack itemstack = npc.getHeldItem(); modelplayer.setSlim(npc.hasSlimArms()); // .hasSlimSkin()); modelplayer.setVisible(true); - boolean third = this.manager.gm == null || npc != this.manager.gm.getRenderViewEntity() || this.manager.gm.thirdPersonView != 0 || !this.manager.gm.showPlayerFirstPerson || this.manager.gm.charEditor; - modelplayer.bipedHead.showModel &= third; - modelplayer.bipedHeadwear.showModel &= third; // if(npc.isPlayer()) { // modelplayer.bipedHeadwear.showModel &= npc.isWearing(ModelPart.HEAD); // modelplayer.bipedBodyWear.showModel &= npc.isWearing(ModelPart.JACKET); @@ -131,7 +128,7 @@ public class RenderHumanoid extends RenderNpc modelplayer.raisedArms = npc.hasArmsRaised(); // modelplayer.sticks = npc.hasPowerRods(); - if (itemstack == null || itemstack.getItem().getWieldType() == null) + if (itemstack == null) { modelplayer.heldItemRight = 0; } @@ -142,7 +139,7 @@ public class RenderHumanoid extends RenderNpc if (npc.isUsingItem()) { ItemAction enumaction = itemstack.getItemUseAction(); - enumaction = enumaction == ItemAction.NONE ? itemstack.getItem().getItemPosition() : enumaction; + enumaction = enumaction == ItemAction.NONE ? itemstack.getItemPosition() : enumaction; if (enumaction == ItemAction.BLOCK) { @@ -154,7 +151,7 @@ public class RenderHumanoid extends RenderNpc } } else { - ItemAction enumaction = itemstack.getItem().getItemPosition(); + ItemAction enumaction = itemstack.getItemPosition(); if(enumaction == ItemAction.AIM) { modelplayer.aimedBow = true; @@ -213,11 +210,6 @@ public class RenderHumanoid extends RenderNpc this.setModelVisibilities(entity); modelplayer.swingProgress = 0.0F; modelplayer.isSneak = false; - modelplayer.heldItemRight = 0; - modelplayer.heldItemLeft = 0; - modelplayer.aimedBow = false; - modelplayer.isRiding = false; - modelplayer.raisedArms = false; modelplayer.setRotationAngles(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F, entity); modelplayer.renderRightArm((float)this.arms - 12.0f); } diff --git a/client/src/client/renderer/entity/RenderItem.java b/client/src/client/renderer/entity/RenderItem.java new file mode 100755 index 00000000..d1ab920a --- /dev/null +++ b/client/src/client/renderer/entity/RenderItem.java @@ -0,0 +1,372 @@ +package client.renderer.entity; + +import java.util.List; + +import org.lwjgl.opengl.GL11; + +import client.renderer.DefaultVertexFormats; +import client.renderer.GlState; +import client.renderer.ItemModelMesher; +import client.renderer.RenderBuffer; +import client.renderer.Tessellator; +import client.renderer.blockmodel.BakedQuad; +import client.renderer.blockmodel.IBakedModel; +import client.renderer.blockmodel.ModelManager; +import client.renderer.texture.TextureManager; +import client.renderer.texture.TextureMap; +import client.renderer.tileentity.TileEntityItemStackRenderer; +import common.entity.npc.EntityNPC; +import common.entity.types.EntityLiving; +import common.init.Items; +import common.item.Item; +import common.item.ItemStack; +import common.model.Transform; +import common.model.Transforms; +import common.util.Facing; +import common.util.Vec3i; + +public class RenderItem +{ + private static final String RES_ITEM_GLINT = "textures/glint.png"; + + /** False when the renderer is rendering the item's effects into a GUI */ +// private boolean notRenderingEffectsInGUI = true; + + /** Defines the zLevel of rendering of item on GUI. */ + public float zLevel; + private final ItemModelMesher itemModelMesher; + private final TextureManager textureManager; + + public RenderItem(TextureManager textureManager, ModelManager modelManager) + { + this.textureManager = textureManager; + this.itemModelMesher = new ItemModelMesher(modelManager); +// RenderRegistry.registerItems(this.itemModelMesher); + } + + /** + * False when the renderer is rendering the item's effects into a GUI + * + * @param isNot If the renderer is not rendering the effects in a GUI + */ +// public void isNotRenderingEffectsInGUI(boolean isNot) +// { +// this.notRenderingEffectsInGUI = isNot; +// } + + public ItemModelMesher getItemModelMesher() + { + return this.itemModelMesher; + } + + private void renderModel(IBakedModel model, ItemStack stack) + { + this.renderModel(model, -1, stack); + } + + private void renderModel(IBakedModel model, int color) + { + this.renderModel(model, color, (ItemStack)null); + } + + private void renderModel(IBakedModel model, int color, ItemStack stack) + { +// Tessellator tessellator = Tessellator.getInstance(); + RenderBuffer worldrenderer = Tessellator.getBuffer(); + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM); + + for (Facing enumfacing : Facing.values()) + { + this.renderQuads(worldrenderer, model.getFaceQuads(enumfacing), color, stack); + } + + this.renderQuads(worldrenderer, model.getGeneralQuads(), color, stack); + Tessellator.draw(); + } + + public void renderItem(ItemStack stack, IBakedModel model) + { + if (stack != null) + { + GL11.glPushMatrix(); + GL11.glScalef(0.5F, 0.5F, 0.5F); + + if (model.isBuiltInRenderer()) + { + GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + GlState.enableRescaleNormal(); + TileEntityItemStackRenderer.instance.renderByItem(stack); + } + else + { + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + this.renderModel(model, stack); + + if (stack.hasEffect()) + { + this.renderEffect(model); + } + } + + GL11.glPopMatrix(); + } + } + + private void renderEffect(IBakedModel model) + { + GlState.depthMask(false); + GlState.depthFunc(GL11.GL_EQUAL); + GlState.disableLighting(); + GlState.blendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); + this.textureManager.bindTexture(RES_ITEM_GLINT); + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glPushMatrix(); + GL11.glScalef(8.0F, 8.0F, 8.0F); + float f = (float)(System.currentTimeMillis() % 3000L) / 3000.0F / 8.0F; + GL11.glTranslatef(f, 0.0F, 0.0F); + GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F); + this.renderModel(model, -8372020); + GL11.glPopMatrix(); + GL11.glPushMatrix(); + GL11.glScalef(8.0F, 8.0F, 8.0F); + float f1 = (float)(System.currentTimeMillis() % 4873L) / 4873.0F / 8.0F; + GL11.glTranslatef(-f1, 0.0F, 0.0F); + GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F); + this.renderModel(model, -8372020); + GL11.glPopMatrix(); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GlState.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlState.enableLighting(); + GlState.depthFunc(GL11.GL_LEQUAL); + GlState.depthMask(true); + this.textureManager.bindTexture(TextureMap.locationBlocksTexture); + } + + private void putQuadNormal(RenderBuffer renderer, BakedQuad quad) + { + Vec3i vec3i = quad.getFace().getDirectionVec(); + renderer.putNormal((float)vec3i.getX(), (float)vec3i.getY(), (float)vec3i.getZ()); + } + + private void renderQuad(RenderBuffer renderer, BakedQuad quad, int color) + { + renderer.addVertexData(quad.getVertexData()); + renderer.putColor4(color); + this.putQuadNormal(renderer, quad); + } + + private void renderQuads(RenderBuffer renderer, List quads, int color, ItemStack stack) + { + boolean flag = color == -1 && stack != null; + int i = 0; + + for (int j = quads.size(); i < j; ++i) + { + BakedQuad bakedquad = (BakedQuad)quads.get(i); + int k = color; + + if (flag && bakedquad.hasTintIndex()) + { + k = stack.getItem().getColorFromItemStack(stack, bakedquad.getTintIndex()); + +// if (EntityRenderer.anaglyphEnable) +// { +// k = TextureUtil.anaglyphColor(k); +// } + + k = k | -16777216; + } + + this.renderQuad(renderer, bakedquad, k); + } + } + + public boolean shouldRenderItemIn3D(ItemStack stack) + { + IBakedModel ibakedmodel = this.itemModelMesher.getItemModel(stack); + return ibakedmodel == null ? false : ibakedmodel.isGui3d(); + } + + private void preTransform(ItemStack stack) + { + IBakedModel ibakedmodel = this.itemModelMesher.getItemModel(stack); + Item item = stack.getItem(); + + if (item != null) + { + boolean flag = ibakedmodel.isGui3d(); + + if (!flag) + { + GL11.glScalef(2.0F, 2.0F, 2.0F); + } + + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + } + } + + public void renderItem(ItemStack stack, Transforms.Camera cameraTransformType) + { + if (stack != null) + { + IBakedModel ibakedmodel = this.itemModelMesher.getItemModel(stack); + this.renderItemModelTransform(stack, ibakedmodel, cameraTransformType); + } + } + + public void renderItemModelForEntity(ItemStack stack, EntityLiving entityToRenderFor, Transforms.Camera cameraTransformType) + { + if (stack != null && entityToRenderFor != null) + { + IBakedModel ibakedmodel = this.itemModelMesher.getItemModel(stack); + + if (entityToRenderFor.isPlayer()) + { + EntityNPC entityplayer = (EntityNPC)entityToRenderFor; + Item item = stack.getItem(); + String modelresourcelocation = null; + + if (item == Items.fishing_rod && entityplayer.fishEntity != null) + { + modelresourcelocation = "item/fishing_rod#1" + '#' + "inventory"; + } + else if (item == Items.bow && entityplayer.getItemInUse() != null) + { + int i = stack.getMaxItemUseDuration() - entityplayer.getItemInUseCount(); + + if (i >= 18) + { + modelresourcelocation = "item/bow#3" + '#' + "inventory"; + } + else if (i > 13) + { + modelresourcelocation = "item/bow#2" + '#' + "inventory"; + } + else if (i > 0) + { + modelresourcelocation = "item/bow#1" + '#' + "inventory"; + } + } + + if (modelresourcelocation != null) + { + ibakedmodel = this.itemModelMesher.getModelManager().getModel(modelresourcelocation); + } + } + + this.renderItemModelTransform(stack, ibakedmodel, cameraTransformType); + } + } + + protected void renderItemModelTransform(ItemStack stack, IBakedModel model, Transforms.Camera cameraTransformType) + { + this.textureManager.bindTexture(TextureMap.locationBlocksTexture); +// this.textureManager.getTexture(TextureMap.locationBlocksTexture).unsetMipmap(); + this.preTransform(stack); + GlState.enableRescaleNormal(); + GlState.alphaFunc(GL11.GL_GREATER, 0.1F); + GlState.enableBlend(); + GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); + GL11.glPushMatrix(); + Transforms itemcameratransforms = model.getItemCameraTransforms(); + RenderItem.apply(itemcameratransforms, cameraTransformType); + + if (this.isThereOneNegativeScale(itemcameratransforms.get(cameraTransformType))) + { + GlState.cullFace(GL11.GL_FRONT); + } + + this.renderItem(stack, model); + GlState.cullFace(GL11.GL_BACK); + GL11.glPopMatrix(); + GlState.disableRescaleNormal(); + GlState.disableBlend(); + this.textureManager.bindTexture(TextureMap.locationBlocksTexture); +// this.textureManager.getTexture(TextureMap.locationBlocksTexture).restoreLastMipmap(); + } + + /** + * Return true if only one scale is negative + * + * @param itemTranformVec The ItemTransformVec3f instance + */ + private boolean isThereOneNegativeScale(Transform itemTranformVec) + { + return itemTranformVec.scale.x < 0.0F ^ itemTranformVec.scale.y < 0.0F ^ itemTranformVec.scale.z < 0.0F; + } + + private void renderItemIntoGUI(ItemStack stack, int x, int y) + { + IBakedModel ibakedmodel = this.itemModelMesher.getItemModel(stack); + GL11.glPushMatrix(); + this.textureManager.bindTexture(TextureMap.locationBlocksTexture); +// this.textureManager.getTexture(TextureMap.locationBlocksTexture).unsetMipmap(); + GlState.enableRescaleNormal(); + GlState.enableAlpha(); + GlState.alphaFunc(GL11.GL_GREATER, 0.1F); + GlState.enableBlend(); + GlState.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + this.setupGuiTransform(x, y, ibakedmodel.isGui3d()); + RenderItem.apply(ibakedmodel.getItemCameraTransforms(), Transforms.Camera.GUI); + this.renderItem(stack, ibakedmodel); + GlState.disableAlpha(); + GlState.disableRescaleNormal(); + GlState.disableLighting(); + GL11.glPopMatrix(); + this.textureManager.bindTexture(TextureMap.locationBlocksTexture); +// this.textureManager.getTexture(TextureMap.locationBlocksTexture).restoreLastMipmap(); + } + + private void setupGuiTransform(int xPosition, int yPosition, boolean isGui3d) + { + GL11.glTranslatef((float)xPosition, (float)yPosition, 100.0F + this.zLevel); + GL11.glTranslatef(8.0F, 8.0F, 0.0F); + GL11.glScalef(1.0F, 1.0F, -1.0F); + GL11.glScalef(0.5F, 0.5F, 0.5F); + + if (isGui3d) + { + GL11.glScalef(40.0F, 40.0F, 40.0F); + GL11.glRotatef(210.0F, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F); + GlState.enableLighting(); + } + else + { + GL11.glScalef(64.0F, 64.0F, 64.0F); + GL11.glRotatef(180.0F, 1.0F, 0.0F, 0.0F); + GlState.disableLighting(); + } + } + + public void renderItemAndEffectIntoGUI(final ItemStack stack, int xPosition, int yPosition) + { + if (stack != null && stack.getItem() != null) + { + this.zLevel += 50.0F; + + this.renderItemIntoGUI(stack, xPosition, yPosition); + + this.zLevel -= 50.0F; + } + } + + public void onReload() + { + this.itemModelMesher.rebuildCache(); + } + + public static void apply(Transforms trans, Transforms.Camera type) { + Transform vec = trans.get(type); + if(vec != Transform.IDENTITY) { + GL11.glTranslatef(vec.translation.x, vec.translation.y, vec.translation.z); + GL11.glRotatef(vec.rotation.y, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(vec.rotation.x, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(vec.rotation.z, 0.0F, 0.0F, 1.0F); + GL11.glScalef(vec.scale.x, vec.scale.y, vec.scale.z); + } + } +} diff --git a/client/src/client/renderer/entity/RenderItemEntity.java b/client/src/client/renderer/entity/RenderItemEntity.java new file mode 100755 index 00000000..41da3446 --- /dev/null +++ b/client/src/client/renderer/entity/RenderItemEntity.java @@ -0,0 +1,49 @@ +package client.renderer.entity; + +import org.lwjgl.opengl.GL11; + +import client.renderer.GlState; +import client.renderer.texture.TextureMap; +import common.entity.Entity; +import common.item.Item; +import common.item.ItemStack; +import common.model.Transforms; + + +public class RenderItemEntity extends Render +{ + protected final Item item; + private final RenderItem itemRenderer; + + public RenderItemEntity(RenderManager renderManagerIn, Item itemIn, RenderItem renderItemIn) + { + super(renderManagerIn); + this.item = itemIn; + this.itemRenderer = renderItemIn; + } + + public void doRender(T entity, double x, double y, double z, float partialTicks) + { + GL11.glPushMatrix(); + GL11.glTranslatef((float)x, (float)y, (float)z); + GlState.enableRescaleNormal(); + GL11.glScalef(0.5F, 0.5F, 0.5F); + GL11.glRotatef(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F); + this.bindTexture(TextureMap.locationBlocksTexture); + this.itemRenderer.renderItem(this.getStack(entity), Transforms.Camera.GROUND); + GlState.disableRescaleNormal(); + GL11.glPopMatrix(); + super.doRender(entity, x, y, z, partialTicks); + } + + public ItemStack getStack(T entityIn) + { + return new ItemStack(this.item, 1, 0); + } + + protected String getEntityTexture(Entity entity) + { + return TextureMap.locationBlocksTexture; + } +} diff --git a/client/src/main/java/client/renderer/entity/RenderLeashKnot.java b/client/src/client/renderer/entity/RenderLeashKnot.java similarity index 93% rename from client/src/main/java/client/renderer/entity/RenderLeashKnot.java rename to client/src/client/renderer/entity/RenderLeashKnot.java index 722fd80e..9a03683b 100755 --- a/client/src/main/java/client/renderer/entity/RenderLeashKnot.java +++ b/client/src/client/renderer/entity/RenderLeashKnot.java @@ -9,7 +9,7 @@ import common.entity.item.EntityLeashKnot; public class RenderLeashKnot extends Render { - private static final String leashKnotTextures = "textures/object/lead_knot.png"; + private static final String leashKnotTextures = "textures/entity/lead_knot.png"; private ModelLeashKnot leashKnotModel = new ModelLeashKnot(); public RenderLeashKnot(RenderManager renderManagerIn) diff --git a/client/src/main/java/client/renderer/entity/RenderLightning.java b/client/src/client/renderer/entity/RenderLightning.java similarity index 100% rename from client/src/main/java/client/renderer/entity/RenderLightning.java rename to client/src/client/renderer/entity/RenderLightning.java diff --git a/client/src/main/java/client/renderer/entity/RenderLiving.java b/client/src/client/renderer/entity/RenderLiving.java similarity index 99% rename from client/src/main/java/client/renderer/entity/RenderLiving.java rename to client/src/client/renderer/entity/RenderLiving.java index 6b744bcf..4e308dd7 100755 --- a/client/src/main/java/client/renderer/entity/RenderLiving.java +++ b/client/src/client/renderer/entity/RenderLiving.java @@ -38,7 +38,7 @@ public abstract class RenderLiving extends RendererLivin public void doRender(T entity, double x, double y, double z, float partial) { if(entity.isBoss()) - this.manager.gm.setBossStatus(entity); + this.renderManager.gm.setBossStatus(entity); super.doRender(entity, x, y, z, partial); this.renderLeash(entity, x, y, z, partial); } diff --git a/client/src/main/java/client/renderer/entity/RenderManager.java b/client/src/client/renderer/entity/RenderManager.java similarity index 79% rename from client/src/main/java/client/renderer/entity/RenderManager.java rename to client/src/client/renderer/entity/RenderManager.java index 887b728a..6a373ce5 100755 --- a/client/src/main/java/client/renderer/entity/RenderManager.java +++ b/client/src/client/renderer/entity/RenderManager.java @@ -8,14 +8,11 @@ import org.lwjgl.opengl.GL13; import client.Client; import client.init.RenderRegistry; import client.renderer.DefaultVertexFormats; -import client.renderer.Drawing; import client.renderer.GlState; import client.renderer.RenderBuffer; import client.renderer.RenderGlobal; import client.renderer.Tessellator; -import client.renderer.texture.Sprite; import client.renderer.texture.TextureManager; -import client.renderer.texture.TextureMap; import common.collect.Maps; import common.entity.Entity; import common.entity.types.EntityLiving; @@ -242,6 +239,24 @@ public class RenderManager return this.renderEntity(entity, d0 - this.renderPosX, d1 - this.renderPosY, d2 - this.renderPosZ, partialTicks); } + public void renderFloatingBox(Entity entityIn, float partialTicks) + { + double d0 = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * (double)partialTicks; + double d1 = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * (double)partialTicks; + double d2 = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * (double)partialTicks; + Render render = this.getEntityRenderObject(entityIn); + + if (render != null && this.renderEngine != null) + { + int i = entityIn.getBrightnessForRender(partialTicks); + int j = i % 65536; + int k = i / 65536; + GL13.glMultiTexCoord2f(GL13.GL_TEXTURE1, (float)j / 1.0F, (float)k / 1.0F); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + render.renderName(entityIn, d0 - this.renderPosX, d1 - this.renderPosY, d2 - this.renderPosZ); + } + } + public boolean renderEntity(Entity entity, double x, double y, double z, float partialTicks) { Render render = this.getEntityRenderObject(entity); @@ -255,9 +270,9 @@ public class RenderManager render.doRender(entity, x, y, z, partialTicks); - if (!this.renderOutlines && this.gm != null && entity.canRenderOnFire()) + if (!this.renderOutlines) { - this.renderEntityFire(entity, x, y, z); + render.doRenderShadowAndFire(entity, x, y, z, partialTicks); } if (this.debugBoundingBox) // && !entity.isInvisible()) // && !hideDebugBox) @@ -272,85 +287,6 @@ public class RenderManager return true; } - - public void renderLabel(Entity entity, String str, double x, double y, double z, int maxDistance) { - if(this.gm == null) - return; - double dist = entity.getDistanceSqToEntity(this.livingPlayer); - if(dist > (double)(maxDistance * maxDistance) || !this.gm.canRenderHud()) - return; - float scale = 0.016666668F; - GL11.glPushMatrix(); - GL11.glTranslatef((float)x + 0.0F, (float)y + entity.height + 0.5F, (float)z); - GL11.glNormal3f(0.0F, 1.0F, 0.0F); - GL11.glRotatef(-this.playerViewY, 0.0F, 1.0F, 0.0F); - GL11.glRotatef(this.playerViewX, 1.0F, 0.0F, 0.0F); - GL11.glScalef(-scale, -scale, scale); - GlState.disableLighting(); - GlState.depthMask(false); - GlState.enableBlend(); - GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); - GlState.depthMask(true); - Drawing.drawTextboxCentered(str, 0, 0, 0x3f000000); - GlState.enableLighting(); - GlState.disableBlend(); - GlState.color(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glPopMatrix(); - } - - private void renderEntityFire(Entity entity, double x, double y, double z) - { - GlState.disableLighting(); - TextureMap map = this.gm.getTextureMapBlocks(); - Sprite layer0 = map.getAtlasSprite("blocks/fire_layer_0"); - Sprite layer1 = map.getAtlasSprite("blocks/fire_layer_1"); - GL11.glPushMatrix(); - GL11.glTranslatef((float)x, (float)y, (float)z); - float scale = entity.width * 1.4F; - GL11.glScalef(scale, scale, scale); - RenderBuffer rb = Tessellator.getBuffer(); - float f1 = 0.5F; - float f2 = 0.0F; - float f3 = entity.height / scale; - float f4 = (float)(entity.posY - entity.getEntityBoundingBox().minY); - GL11.glRotatef(-this.playerViewY, 0.0F, 1.0F, 0.0F); - GL11.glTranslatef(0.0F, 0.0F, -0.3F + (float)((int)f3) * 0.02F); - GlState.color(1.0F, 1.0F, 1.0F, 1.0F); - float f5 = 0.0F; - int i = 0; - rb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); - - while (f3 > 0.0F) - { - Sprite layer = i % 2 == 0 ? layer0 : layer1; - this.renderEngine.bindTexture(TextureMap.BLOCKS); - float f6 = layer.getMinU(); - float f7 = layer.getMinV(); - float f8 = layer.getMaxU(); - float f9 = layer.getMaxV(); - - if (i / 2 % 2 == 0) - { - float f10 = f8; - f8 = f6; - f6 = f10; - } - - rb.pos((double)(f1 - f2), (double)(0.0F - f4), (double)f5).tex((double)f8, (double)f9).endVertex(); - rb.pos((double)(-f1 - f2), (double)(0.0F - f4), (double)f5).tex((double)f6, (double)f9).endVertex(); - rb.pos((double)(-f1 - f2), (double)(1.4F - f4), (double)f5).tex((double)f6, (double)f7).endVertex(); - rb.pos((double)(f1 - f2), (double)(1.4F - f4), (double)f5).tex((double)f8, (double)f7).endVertex(); - f3 -= 0.45F; - f4 -= 0.45F; - f1 *= 0.9F; - f5 += 0.03F; - ++i; - } - - Tessellator.draw(); - GL11.glPopMatrix(); - GlState.enableLighting(); - } private void renderDebugBoundingBox(Entity entityIn, double x, double y, double z, float partialTicks) { diff --git a/client/src/main/java/client/renderer/entity/RenderMinecart.java b/client/src/client/renderer/entity/RenderMinecart.java similarity index 91% rename from client/src/main/java/client/renderer/entity/RenderMinecart.java rename to client/src/client/renderer/entity/RenderMinecart.java index 2cdf5cf9..6844f89e 100755 --- a/client/src/main/java/client/renderer/entity/RenderMinecart.java +++ b/client/src/client/renderer/entity/RenderMinecart.java @@ -8,14 +8,13 @@ import client.renderer.model.ModelBase; import client.renderer.model.ModelMinecart; import client.renderer.texture.TextureMap; import common.entity.item.EntityCart; -import common.init.Blocks; import common.util.ExtMath; import common.util.Vec3; import common.world.State; public class RenderMinecart extends Render { - private static final String minecartTextures = "textures/object/minecart.png"; + private static final String minecartTextures = "textures/entity/minecart.png"; /** instance of ModelMinecart for rendering */ protected ModelBase modelMinecart = new ModelMinecart(); @@ -94,10 +93,10 @@ public class RenderMinecart extends Render int j = entity.getDisplayTileOffset(); State iblockstate = entity.getDisplayTile(); - if (iblockstate.getBlock() != Blocks.air && !iblockstate.getBlock().getMaterial().isLiquid()) + if (iblockstate.getBlock().getRenderType() != -1) { GL11.glPushMatrix(); - this.bindTexture(TextureMap.BLOCKS); + this.bindTexture(TextureMap.locationBlocksTexture); float f4 = 0.75F; GL11.glScalef(f4, f4, f4); GL11.glTranslatef(-0.5F, (float)(j - 8) / 16.0F, 0.5F); @@ -124,7 +123,7 @@ public class RenderMinecart extends Render protected void func_180560_a(T minecart, float partialTicks, State state) { GL11.glPushMatrix(); - Client.CLIENT.getBlockRendererDispatcher().renderBlockEntity(state, minecart.getBrightness(partialTicks)); + Client.CLIENT.getBlockRendererDispatcher().renderBlockBrightness(state, minecart.getBrightness(partialTicks)); GL11.glPopMatrix(); } } diff --git a/client/src/client/renderer/entity/RenderMooshroom.java b/client/src/client/renderer/entity/RenderMooshroom.java new file mode 100755 index 00000000..28793f39 --- /dev/null +++ b/client/src/client/renderer/entity/RenderMooshroom.java @@ -0,0 +1,25 @@ +package client.renderer.entity; + +import client.renderer.layers.LayerMooshroomMushroom; +import client.renderer.model.ModelBase; +import common.entity.animal.EntityMooshroom; + + +public class RenderMooshroom extends RenderLiving +{ + private static final String mooshroomTextures = "textures/entity/mooshroom.png"; + + public RenderMooshroom(RenderManager renderManagerIn, ModelBase modelBaseIn) + { + super(renderManagerIn, modelBaseIn); + this.addLayer(new LayerMooshroomMushroom(this)); + } + + /** + * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. + */ + protected String getEntityTexture(EntityMooshroom entity) + { + return mooshroomTextures; + } +} diff --git a/client/src/main/java/client/renderer/entity/RenderMouse.java b/client/src/client/renderer/entity/RenderMouse.java similarity index 84% rename from client/src/main/java/client/renderer/entity/RenderMouse.java rename to client/src/client/renderer/entity/RenderMouse.java index 5a04314c..5c266ddb 100755 --- a/client/src/main/java/client/renderer/entity/RenderMouse.java +++ b/client/src/client/renderer/entity/RenderMouse.java @@ -6,7 +6,7 @@ import common.entity.animal.EntityMouse; public class RenderMouse extends RenderLiving { - private static final String mouseTextures = "textures/creature/mouse.png"; + private static final String mouseTextures = "textures/entity/mouse.png"; public RenderMouse(RenderManager renderManagerIn, ModelBase modelBaseIn) { diff --git a/client/src/main/java/client/renderer/entity/RenderNpc.java b/client/src/client/renderer/entity/RenderNpc.java similarity index 100% rename from client/src/main/java/client/renderer/entity/RenderNpc.java rename to client/src/client/renderer/entity/RenderNpc.java diff --git a/client/src/client/renderer/entity/RenderOcelot.java b/client/src/client/renderer/entity/RenderOcelot.java new file mode 100755 index 00000000..09edb567 --- /dev/null +++ b/client/src/client/renderer/entity/RenderOcelot.java @@ -0,0 +1,56 @@ +package client.renderer.entity; + +import org.lwjgl.opengl.GL11; + +import client.renderer.model.ModelBase; +import common.entity.animal.EntityOcelot; + + +public class RenderOcelot extends RenderLiving +{ + private static final String blackOcelotTextures = "textures/entity/cat_black.png"; + private static final String ocelotTextures = "textures/entity/cat_ocelot.png"; + private static final String redOcelotTextures = "textures/entity/cat_red.png"; + private static final String siameseOcelotTextures = "textures/entity/cat_siamese.png"; + + public RenderOcelot(RenderManager renderManagerIn, ModelBase modelBaseIn) + { + super(renderManagerIn, modelBaseIn); + } + + /** + * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. + */ + protected String getEntityTexture(EntityOcelot entity) + { + switch (entity.getTameSkin()) + { + case 0: + default: + return ocelotTextures; + + case 1: + return blackOcelotTextures; + + case 2: + return redOcelotTextures; + + case 3: + return siameseOcelotTextures; + } + } + + /** + * Allows the render to do any OpenGL state modifications necessary before the model is rendered. Args: + * entityLiving, partialTickTime + */ + protected void preRenderCallback(EntityOcelot entitylivingbaseIn, float partialTickTime) + { + super.preRenderCallback(entitylivingbaseIn, partialTickTime); + + if (entitylivingbaseIn.isTamed()) + { + GL11.glScalef(0.8F, 0.8F, 0.8F); + } + } +} diff --git a/client/src/main/java/client/renderer/entity/RenderPig.java b/client/src/client/renderer/entity/RenderPig.java similarity index 89% rename from client/src/main/java/client/renderer/entity/RenderPig.java rename to client/src/client/renderer/entity/RenderPig.java index e36954be..be614ee3 100755 --- a/client/src/main/java/client/renderer/entity/RenderPig.java +++ b/client/src/client/renderer/entity/RenderPig.java @@ -7,7 +7,7 @@ import common.entity.animal.EntityPig; public class RenderPig extends RenderLiving { - private static final String pigTextures = "textures/creature/pig.png"; + private static final String pigTextures = "textures/entity/pig.png"; public RenderPig(RenderManager renderManagerIn, ModelBase modelBaseIn) { diff --git a/client/src/client/renderer/entity/RenderPotion.java b/client/src/client/renderer/entity/RenderPotion.java new file mode 100755 index 00000000..42567832 --- /dev/null +++ b/client/src/client/renderer/entity/RenderPotion.java @@ -0,0 +1,18 @@ +package client.renderer.entity; + +import common.entity.projectile.EntityPotion; +import common.init.Items; +import common.item.ItemStack; + +public class RenderPotion extends RenderItemEntity +{ + public RenderPotion(RenderManager renderManagerIn, RenderItem itemRendererIn) + { + super(renderManagerIn, Items.potion, itemRendererIn); + } + + public ItemStack getStack(EntityPotion entityIn) + { + return new ItemStack(this.item, 1, entityIn.getPotionDamage()); + } +} diff --git a/client/src/client/renderer/entity/RenderRabbit.java b/client/src/client/renderer/entity/RenderRabbit.java new file mode 100755 index 00000000..7527e5a7 --- /dev/null +++ b/client/src/client/renderer/entity/RenderRabbit.java @@ -0,0 +1,37 @@ +package client.renderer.entity; + +import client.renderer.model.ModelBase; +import common.color.TextColor; +import common.entity.animal.EntityRabbit; + + +public class RenderRabbit extends RenderLiving { + private static final String[] TYPES = new String[] { + "textures/entity/rabbit_brown.png", + "textures/entity/rabbit_white.png", + "textures/entity/rabbit_black.png", + "textures/entity/rabbit_white_splotched.png", + "textures/entity/rabbit_gold.png", + "textures/entity/rabbit_salt.png", + "textures/entity/rabbit_gray.png", + "textures/entity/rabbit_dark_gray.png", + "textures/entity/rabbit_dark.png", + "textures/entity/rabbit_black_splotched.png" + }; + private static final String TOAST = "textures/entity/rabbit_toast.png"; + private static final String CAERBANNOG = "textures/entity/rabbit_caerbannog.png"; + + public RenderRabbit(RenderManager manager, ModelBase model) { + super(manager, model); + } + + protected String getEntityTexture(EntityRabbit entity) { + String name = TextColor.stripCodes(entity.getCustomNameTag()); + if(name != null && name.equals("Toast")) + return TOAST; + int type = entity.getRabbitType(); + if(type == 99) + return CAERBANNOG; + return type >= 0 && type < TYPES.length ? TYPES[type] : TOAST; + } +} diff --git a/client/src/main/java/client/renderer/entity/RenderSheep.java b/client/src/client/renderer/entity/RenderSheep.java similarity index 97% rename from client/src/main/java/client/renderer/entity/RenderSheep.java rename to client/src/client/renderer/entity/RenderSheep.java index 4f63cdcb..c9277db3 100755 --- a/client/src/main/java/client/renderer/entity/RenderSheep.java +++ b/client/src/client/renderer/entity/RenderSheep.java @@ -7,7 +7,7 @@ import common.entity.animal.EntitySheep; public class RenderSheep extends RenderLiving { - private static final String shearedSheepTextures = "textures/creature/sheep.png"; + private static final String shearedSheepTextures = "textures/entity/sheep.png"; public RenderSheep(RenderManager renderManagerIn, ModelBase modelBaseIn) { diff --git a/client/src/main/java/client/renderer/entity/RenderSlime.java b/client/src/client/renderer/entity/RenderSlime.java similarity index 89% rename from client/src/main/java/client/renderer/entity/RenderSlime.java rename to client/src/client/renderer/entity/RenderSlime.java index 9efa0415..e76df433 100755 --- a/client/src/main/java/client/renderer/entity/RenderSlime.java +++ b/client/src/client/renderer/entity/RenderSlime.java @@ -28,12 +28,6 @@ public class RenderSlime extends RenderNpc GL11.glScalef(f2 * f, 1.0F / f2 * f, f2 * f); } - public void doRender(EntityNPC entity, double x, double y, double z, float partialTicks) - { - if(this.manager.gm == null || entity != this.manager.gm.getRenderViewEntity() || this.manager.gm.thirdPersonView != 0 || !this.manager.gm.showPlayerFirstPerson || this.manager.gm.charEditor) - super.doRender(entity, x, y, z, partialTicks); - } - // protected String getEntityTexture(EntityNPC entity) // { // return entity.getLocationSkin(); @@ -41,7 +35,7 @@ public class RenderSlime extends RenderNpc public String getDefaultTexture() { - return "textures/npc/slime.png"; + return "textures/entity/slime.png"; } // public int getCompressedSize() { diff --git a/client/src/main/java/client/renderer/entity/RenderSpaceMarine.java b/client/src/client/renderer/entity/RenderSpaceMarine.java similarity index 87% rename from client/src/main/java/client/renderer/entity/RenderSpaceMarine.java rename to client/src/client/renderer/entity/RenderSpaceMarine.java index 7692453c..864b24cb 100755 --- a/client/src/main/java/client/renderer/entity/RenderSpaceMarine.java +++ b/client/src/client/renderer/entity/RenderSpaceMarine.java @@ -43,12 +43,11 @@ public class RenderSpaceMarine extends RenderNpc ModelSpaceMarine modelplayer = this.getMainModel(); ItemStack itemstack = npc.getHeldItem(); modelplayer.setVisible(true); - modelplayer.bipedHead.showModel &= this.manager.gm == null || npc != this.manager.gm.getRenderViewEntity() || this.manager.gm.thirdPersonView != 0 || !this.manager.gm.showPlayerFirstPerson || this.manager.gm.charEditor; modelplayer.heldItemLeft = 0; modelplayer.aimedBow = false; modelplayer.isSneak = false; - if (itemstack == null || itemstack.getItem().getWieldType() == null) + if (itemstack == null) { modelplayer.heldItemRight = 0; } @@ -59,7 +58,7 @@ public class RenderSpaceMarine extends RenderNpc if (npc.isUsingItem()) { ItemAction enumaction = itemstack.getItemUseAction(); - enumaction = enumaction == ItemAction.NONE ? itemstack.getItem().getItemPosition() : enumaction; + enumaction = enumaction == ItemAction.NONE ? itemstack.getItemPosition() : enumaction; if (enumaction == ItemAction.BLOCK) { @@ -71,7 +70,7 @@ public class RenderSpaceMarine extends RenderNpc } } else { - ItemAction enumaction = itemstack.getItem().getItemPosition(); + ItemAction enumaction = itemstack.getItemPosition(); if(enumaction == ItemAction.AIM) { modelplayer.aimedBow = true; @@ -100,7 +99,7 @@ public class RenderSpaceMarine extends RenderNpc public final String getDefaultTexture() { - return "textures/npc/marine.png"; + return "textures/entity/marine.png"; } public void getSegments(TexList opaque, TexList alpha) { diff --git a/client/src/client/renderer/entity/RenderSquid.java b/client/src/client/renderer/entity/RenderSquid.java new file mode 100755 index 00000000..15f3c96a --- /dev/null +++ b/client/src/client/renderer/entity/RenderSquid.java @@ -0,0 +1,44 @@ +package client.renderer.entity; + +import org.lwjgl.opengl.GL11; + +import client.renderer.model.ModelBase; +import common.entity.animal.EntitySquid; + + +public class RenderSquid extends RenderLiving +{ + private static final String squidTextures = "textures/entity/squid.png"; + + public RenderSquid(RenderManager renderManagerIn, ModelBase modelBaseIn) + { + super(renderManagerIn, modelBaseIn); + } + + /** + * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. + */ + protected String getEntityTexture(EntitySquid entity) + { + return squidTextures; + } + + protected void rotateCorpse(EntitySquid bat, float p_77043_2_, float p_77043_3_, float partialTicks) + { + float f = bat.prevSquidPitch + (bat.squidPitch - bat.prevSquidPitch) * partialTicks; + float f1 = bat.prevSquidYaw + (bat.squidYaw - bat.prevSquidYaw) * partialTicks; + GL11.glTranslatef(0.0F, 0.5F, 0.0F); + GL11.glRotatef(180.0F - p_77043_3_, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(f, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(f1, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(0.0F, -1.2F, 0.0F); + } + + /** + * Defines what float the third param in setRotationAngles of ModelBase is + */ + protected float handleRotationFloat(EntitySquid livingBase, float partialTicks) + { + return livingBase.lastTentacleAngle + (livingBase.tentacleAngle - livingBase.lastTentacleAngle) * partialTicks; + } +} diff --git a/client/src/main/java/client/renderer/entity/RenderTntMinecart.java b/client/src/client/renderer/entity/RenderTntMinecart.java similarity index 94% rename from client/src/main/java/client/renderer/entity/RenderTntMinecart.java rename to client/src/client/renderer/entity/RenderTntMinecart.java index 84da4f0b..9e48e448 100755 --- a/client/src/main/java/client/renderer/entity/RenderTntMinecart.java +++ b/client/src/client/renderer/entity/RenderTntMinecart.java @@ -42,7 +42,7 @@ public class RenderTntMinecart extends RenderMinecart GlState.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_DST_ALPHA); GlState.color(1.0F, 1.0F, 1.0F, (1.0F - ((float)i - partialTicks + 1.0F) / 100.0F) * 0.8F); GL11.glPushMatrix(); - blockrendererdispatcher.renderBlockEntity(Blocks.tnt.getState(), 1.0F); + blockrendererdispatcher.renderBlockBrightness(Blocks.tnt.getState(), 1.0F); GL11.glPopMatrix(); GlState.color(1.0F, 1.0F, 1.0F, 1.0F); GlState.disableBlend(); diff --git a/client/src/main/java/client/renderer/entity/RenderTntPrimed.java b/client/src/client/renderer/entity/RenderTntPrimed.java similarity index 75% rename from client/src/main/java/client/renderer/entity/RenderTntPrimed.java rename to client/src/client/renderer/entity/RenderTntPrimed.java index 07fcd41d..85aa3f87 100755 --- a/client/src/main/java/client/renderer/entity/RenderTntPrimed.java +++ b/client/src/client/renderer/entity/RenderTntPrimed.java @@ -6,9 +6,9 @@ import client.Client; import client.renderer.BlockRenderer; import client.renderer.GlState; import client.renderer.texture.TextureMap; -import common.block.Block; +import common.block.BlockTNT; import common.entity.item.EntityTnt; -import common.init.BlockRegistry; +import common.init.Blocks; import common.util.ExtMath; @@ -17,8 +17,12 @@ public class RenderTntPrimed extends Render public RenderTntPrimed(RenderManager renderManagerIn) { super(renderManagerIn); +// this.shadowSize = 0.5F; } + /** + * Renders the desired {@code T} type Entity. + */ public void doRender(EntityTnt entity, double x, double y, double z, float partialTicks) { BlockRenderer blockrendererdispatcher = Client.CLIENT.getBlockRendererDispatcher(); @@ -38,8 +42,7 @@ public class RenderTntPrimed extends Render float f2 = (1.0F - ((float)entity.fuse - partialTicks + 1.0F) / 100.0F) * 0.8F; this.bindEntityTexture(entity); GL11.glTranslatef(-0.5F, -0.5F, 0.5F); - Block tnt = BlockRegistry.byName("tnt" + (entity.explosionSize <= 0 || entity.explosionSize >= 8 ? "" : "_" + entity.explosionSize)); - blockrendererdispatcher.renderBlockEntity(tnt.getState(), entity.getBrightness(partialTicks)); + blockrendererdispatcher.renderBlockBrightness(Blocks.tnt.getState().withProperty(BlockTNT.POWER, Integer.valueOf(entity.explosionSize)), entity.getBrightness(partialTicks)); GL11.glTranslatef(0.0F, 0.0F, 1.0F); if (entity.fuse / 5 % 2 == 0) @@ -51,7 +54,7 @@ public class RenderTntPrimed extends Render GlState.color(1.0F, 1.0F, 1.0F, f2); GlState.doPolygonOffset(-3.0F, -3.0F); GlState.enablePolygonOffset(); - blockrendererdispatcher.renderBlockEntity(tnt.getState(), 1.0F); + blockrendererdispatcher.renderBlockBrightness(Blocks.tnt.getState().withProperty(BlockTNT.POWER, Integer.valueOf(entity.explosionSize)), 1.0F); GlState.doPolygonOffset(0.0F, 0.0F); GlState.disablePolygonOffset(); GlState.color(1.0F, 1.0F, 1.0F, 1.0F); @@ -64,8 +67,11 @@ public class RenderTntPrimed extends Render super.doRender(entity, x, y, z, partialTicks); } + /** + * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. + */ protected String getEntityTexture(EntityTnt entity) { - return TextureMap.BLOCKS; + return TextureMap.locationBlocksTexture; } } diff --git a/client/src/client/renderer/entity/RenderWolf.java b/client/src/client/renderer/entity/RenderWolf.java new file mode 100755 index 00000000..66ae7d74 --- /dev/null +++ b/client/src/client/renderer/entity/RenderWolf.java @@ -0,0 +1,35 @@ +package client.renderer.entity; + +import client.renderer.layers.LayerWolfCollar; +import client.renderer.model.ModelBase; +import common.entity.animal.EntityWolf; + + +public class RenderWolf extends RenderLiving +{ + private static final String wolfTextures = "textures/entity/wolf.png"; + private static final String tamedWolfTextures = "textures/entity/wolf_tame.png"; + private static final String anrgyWolfTextures = "textures/entity/wolf_angry.png"; + + public RenderWolf(RenderManager renderManagerIn, ModelBase modelBaseIn) + { + super(renderManagerIn, modelBaseIn); + this.addLayer(new LayerWolfCollar(this)); + } + + /** + * Defines what float the third param in setRotationAngles of ModelBase is + */ + protected float handleRotationFloat(EntityWolf livingBase, float partialTicks) + { + return livingBase.getTailRotation(); + } + + /** + * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. + */ + protected String getEntityTexture(EntityWolf entity) + { + return entity.isTamed() ? tamedWolfTextures : (entity.isAngry() ? anrgyWolfTextures : wolfTextures); + } +} diff --git a/client/src/client/renderer/entity/RenderXpOrb.java b/client/src/client/renderer/entity/RenderXpOrb.java new file mode 100755 index 00000000..815456dd --- /dev/null +++ b/client/src/client/renderer/entity/RenderXpOrb.java @@ -0,0 +1,85 @@ +package client.renderer.entity; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL13; + +import client.renderer.DefaultVertexFormats; +import client.renderer.GlState; +import client.renderer.RenderBuffer; +import client.renderer.Tessellator; +import common.entity.item.EntityXp; +import common.util.ExtMath; + + +public class RenderXpOrb extends Render +{ + private static final String experienceOrbTextures = "textures/entity/experience_orb.png"; + + public RenderXpOrb(RenderManager renderManagerIn) + { + super(renderManagerIn); +// this.shadowSize = 0.15F; +// this.shadowOpaque = 0.75F; + } + + /** + * Renders the desired {@code T} type Entity. + */ + public void doRender(EntityXp entity, double x, double y, double z, float partialTicks) + { + GL11.glPushMatrix(); + GL11.glTranslatef((float)x, (float)y, (float)z); + this.bindEntityTexture(entity); + int i = entity.getXpValue(); + float f = (float)(i % 4 * 16 + 0) / 64.0F; + float f1 = (float)(i % 4 * 16 + 16) / 64.0F; + float f2 = (float)(i / 4 * 16 + 0) / 64.0F; + float f3 = (float)(i / 4 * 16 + 16) / 64.0F; + float f4 = 1.0F; + float f5 = 0.5F; + float f6 = 0.25F; + int j = entity.getBrightnessForRender(partialTicks); + int k = j % 65536; + int l = j / 65536; + GL13.glMultiTexCoord2f(GL13.GL_TEXTURE1, (float)k / 1.0F, (float)l / 1.0F); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + float f8 = 255.0F; + float f9 = ((float)entity.xpColor + partialTicks) / 2.0F; + l = (int)((ExtMath.sin(f9 + 0.0F) + 1.0F) * 0.5F * 255.0F); + int i1 = 255; + int j1 = (int)((ExtMath.sin(f9 + 4.1887903F) + 1.0F) * 0.1F * 255.0F); + GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F); + float f7 = 0.3F; + GL11.glScalef(0.3F, 0.3F, 0.3F); +// Tessellator tessellator = Tessellator.getInstance(); + RenderBuffer worldrenderer = Tessellator.getBuffer(); + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR_NORMAL); + worldrenderer.pos((double)(0.0F - f5), (double)(0.0F - f6), 0.0D).tex((double)f, (double)f3).color(l, 255, j1, 128).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f4 - f5), (double)(0.0F - f6), 0.0D).tex((double)f1, (double)f3).color(l, 255, j1, 128).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(f4 - f5), (double)(1.0F - f6), 0.0D).tex((double)f1, (double)f2).color(l, 255, j1, 128).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldrenderer.pos((double)(0.0F - f5), (double)(1.0F - f6), 0.0D).tex((double)f, (double)f2).color(l, 255, j1, 128).normal(0.0F, 1.0F, 0.0F).endVertex(); + Tessellator.draw(); + GlState.disableBlend(); + GlState.disableRescaleNormal(); + GL11.glPopMatrix(); + super.doRender(entity, x, y, z, partialTicks); + } + + /** + * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. + */ + protected String getEntityTexture(EntityXp entity) + { + return experienceOrbTextures; + } + +// protected boolean canRenderName(EntityXp entity) +// { +// return entity.hasCustomName() || super.canRenderName(entity); +// } + + protected void renderLivingLabel(EntityXp entityIn, String str, double x, double y, double z, int maxDistance) { + super.renderLivingLabel(entityIn, str, x, y - 0.5, z, maxDistance); + } +} diff --git a/client/src/main/java/client/renderer/entity/RendererLivingEntity.java b/client/src/client/renderer/entity/RendererLivingEntity.java similarity index 97% rename from client/src/main/java/client/renderer/entity/RendererLivingEntity.java rename to client/src/client/renderer/entity/RendererLivingEntity.java index 05abf9fe..e8df4894 100755 --- a/client/src/main/java/client/renderer/entity/RendererLivingEntity.java +++ b/client/src/client/renderer/entity/RendererLivingEntity.java @@ -17,18 +17,18 @@ import client.renderer.layers.LayerRenderer; import client.renderer.model.ModelBase; import client.renderer.texture.DynamicTexture; import common.collect.Lists; +import common.color.TextColor; import common.entity.Entity; import common.entity.item.EntityCrystal; import common.entity.types.EntityAnimal; import common.entity.types.EntityLiving; import common.log.Log; import common.util.ExtMath; -import common.util.Color; public abstract class RendererLivingEntity extends Render { private static final DynamicTexture textureBrightness = new DynamicTexture(16, 16); - private static final String crystalBeamTextures = "textures/world/beam.png"; + private static final String crystalBeamTextures = "textures/entity/crystal_beam.png"; protected ModelBase mainModel; protected FloatBuffer brightnessBuffer = ByteBuffer.allocateDirect(4 << 2).order(ByteOrder.nativeOrder()).asFloatBuffer(); protected List> layerRenderers = Lists.>newArrayList(); @@ -182,7 +182,7 @@ public abstract class RendererLivingEntity extends Rende } catch (Exception exception) { - Log.RENDER.error((Throwable)exception, (String)"Konnte Objekt nicht rendern"); + Log.JNI.error((Throwable)exception, (String)"Konnte Objekt nicht rendern"); } GlState.setActiveTexture(GL13.GL_TEXTURE1); @@ -436,7 +436,7 @@ public abstract class RendererLivingEntity extends Rende } else { - String s = Color.stripCodes(bat.getCustomNameTag()); + String s = TextColor.stripCodes(bat.getCustomNameTag()); if (s != null && (s.startsWith("Australia") || s.startsWith("Australien"))) // && (!(bat.isPlayer()) || ((EntityNPC)bat).isWearing(ModelPart.CAPE))) { @@ -500,11 +500,11 @@ public abstract class RendererLivingEntity extends Rende public void renderName(T entity, double x, double y, double z) { - String name = entity.getLabel(); + String name = entity.getDisplayName(); if(name != null && !name.isEmpty()) - this.manager.renderLabel(entity, name, x, entity.isSneakingVisually() ? y - 0.25 : y, z, 64); + this.renderLivingLabel(entity, name, x, entity.isSneakingVisually() ? y - 0.25 : y, z, 64); if(entity.isEntityAlive()) - this.manager.renderLabel(entity, entity.formatStats(), x, (entity.isSneakingVisually() ? y - 0.25 : y) + 0.3, z, 32); + this.renderLivingLabel(entity, entity.formatStats(), x, (entity.isSneakingVisually() ? y - 0.25 : y) + 0.3, z, 32); } // protected boolean canRenderName(T entity) @@ -560,13 +560,13 @@ public abstract class RendererLivingEntity extends Rende static { - int[] aint = textureBrightness.getData(); + int[] aint = textureBrightness.getTextureData(); for (int i = 0; i < 256; ++i) { aint[i] = -1; } - textureBrightness.updateTexture(); + textureBrightness.updateDynamicTexture(); } } diff --git a/client/src/client/renderer/layers/LayerArachnoidArmor.java b/client/src/client/renderer/layers/LayerArachnoidArmor.java new file mode 100755 index 00000000..52e8ef53 --- /dev/null +++ b/client/src/client/renderer/layers/LayerArachnoidArmor.java @@ -0,0 +1,28 @@ +package client.renderer.layers; + +import client.renderer.entity.RendererLivingEntity; +import client.renderer.model.ModelBiped; + +public class LayerArachnoidArmor extends LayerArmor +{ + public LayerArachnoidArmor(RendererLivingEntity rendererIn) + { + super(rendererIn, 12, 12); + } + + protected void setModelPartVisible(ModelBiped model, int armorSlot) + { + + switch (armorSlot) + { + case 1: + case 2: + model.setVisible(false); + break; + + case 3: + case 4: + super.setModelPartVisible(model, armorSlot); + } + } +} diff --git a/client/src/client/renderer/layers/LayerArmor.java b/client/src/client/renderer/layers/LayerArmor.java new file mode 100755 index 00000000..35f1280d --- /dev/null +++ b/client/src/client/renderer/layers/LayerArmor.java @@ -0,0 +1,203 @@ +package client.renderer.layers; + +import org.lwjgl.opengl.GL11; + +import client.renderer.GlState; +import client.renderer.entity.RendererLivingEntity; +import client.renderer.model.ModelArmor; +import client.renderer.model.ModelBiped; +import common.entity.types.EntityLiving; +import common.item.ItemArmor; +import common.item.ItemStack; + +public class LayerArmor implements LayerRenderer +{ + protected static final String ENCHANTED_ITEM_GLINT_RES = "textures/glint.png"; + + protected ModelBiped modelLeggings; + protected ModelBiped modelArmor; + private final RendererLivingEntity renderer; + private float alpha = 1.0F; + private float colorR = 1.0F; + private float colorG = 1.0F; + private float colorB = 1.0F; + private boolean skipRenderGlint; +// private static final Map ARMOR_TEXTURE_RES_MAP = Maps.newHashMap(); + + public LayerArmor(RendererLivingEntity rendererIn, int arms, int legs) + { + this.renderer = rendererIn; +// this.initArmor(); + this.modelLeggings = new ModelArmor(0.5F, arms, legs); + this.modelArmor = new ModelArmor(1.0F, arms, legs); + } + + public void doRenderLayer(EntityLiving entitylivingbaseIn, float p_177141_2_, float p_177141_3_, float partialTicks, float p_177141_5_, float p_177141_6_, float p_177141_7_, float scale) + { + this.renderLayer(entitylivingbaseIn, p_177141_2_, p_177141_3_, partialTicks, p_177141_5_, p_177141_6_, p_177141_7_, scale, 4); + this.renderLayer(entitylivingbaseIn, p_177141_2_, p_177141_3_, partialTicks, p_177141_5_, p_177141_6_, p_177141_7_, scale, 3); + this.renderLayer(entitylivingbaseIn, p_177141_2_, p_177141_3_, partialTicks, p_177141_5_, p_177141_6_, p_177141_7_, scale, 2); + this.renderLayer(entitylivingbaseIn, p_177141_2_, p_177141_3_, partialTicks, p_177141_5_, p_177141_6_, p_177141_7_, scale, 1); + } + + public boolean shouldCombineTextures() + { + return false; + } + + private void renderLayer(EntityLiving entitylivingbaseIn, float p_177182_2_, float p_177182_3_, float partialTicks, float p_177182_5_, float p_177182_6_, float p_177182_7_, float scale, int armorSlot) + { + ItemStack itemstack = this.getCurrentArmor(entitylivingbaseIn, armorSlot); + + if (itemstack != null && itemstack.getItem() instanceof ItemArmor) + { + ItemArmor itemarmor = (ItemArmor)itemstack.getItem(); + ModelBiped t = this.getArmorModel(armorSlot); + t.setModelAttributes(this.renderer.getMainModel()); + t.setLivingAnimations(entitylivingbaseIn, p_177182_2_, p_177182_3_, partialTicks); + this.setModelPartVisible(t, armorSlot); + boolean flag = this.isSlotForLeggings(armorSlot); + this.renderer.bindTexture(this.getArmorResource(itemarmor, flag, null)); + + if (itemarmor.getArmorMaterial().canBeDyed()) + { + int i = itemarmor.getArmorColor(itemstack); + float f = (float)(i >> 16 & 255) / 255.0F; + float f1 = (float)(i >> 8 & 255) / 255.0F; + float f2 = (float)(i & 255) / 255.0F; + GlState.color(this.colorR * f, this.colorG * f1, this.colorB * f2, this.alpha); + t.render(entitylivingbaseIn, p_177182_2_, p_177182_3_, p_177182_5_, p_177182_6_, p_177182_7_, scale); + this.renderer.bindTexture(this.getArmorResource(itemarmor, flag, "overlay")); + } + +// case CHAIN: +// case IRON: +// case GOLD: +// case DIAMOND: + if(itemarmor.getArmorMaterial().hasArmor()) { + GlState.color(this.colorR, this.colorG, this.colorB, this.alpha); + t.render(entitylivingbaseIn, p_177182_2_, p_177182_3_, p_177182_5_, p_177182_6_, p_177182_7_, scale); + } + +// default: + if (!this.skipRenderGlint && itemstack.isItemEnchanted()) + { + this.renderGlint(entitylivingbaseIn, t, p_177182_2_, p_177182_3_, partialTicks, p_177182_5_, p_177182_6_, p_177182_7_, scale); + } + } + } + + public ItemStack getCurrentArmor(EntityLiving entitylivingbaseIn, int armorSlot) + { + return entitylivingbaseIn.getArmor(armorSlot - 1); + } + + public ModelBiped getArmorModel(int armorSlot) + { + return this.isSlotForLeggings(armorSlot) ? this.modelLeggings : this.modelArmor; + } + + private boolean isSlotForLeggings(int armorSlot) + { + return armorSlot == 2; + } + + private void renderGlint(EntityLiving entitylivingbaseIn, ModelBiped modelbaseIn, float p_177183_3_, float p_177183_4_, float partialTicks, float p_177183_6_, float p_177183_7_, float p_177183_8_, float scale) + { + float f = (float)entitylivingbaseIn.ticksExisted + partialTicks; + this.renderer.bindTexture(ENCHANTED_ITEM_GLINT_RES); + GlState.enableBlend(); + GlState.depthFunc(GL11.GL_EQUAL); + GlState.depthMask(false); + float f1 = 0.5F; + GlState.color(f1, f1, f1, 1.0F); + + for (int i = 0; i < 2; ++i) + { + GlState.disableLighting(); + GlState.blendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); + float f2 = 0.76F; + GlState.color(0.5F * f2, 0.25F * f2, 0.8F * f2, 1.0F); + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glLoadIdentity(); + float f3 = 0.33333334F; + GL11.glScalef(f3, f3, f3); + GL11.glRotatef(30.0F - (float)i * 60.0F, 0.0F, 0.0F, 1.0F); + GL11.glTranslatef(0.0F, f * (0.001F + (float)i * 0.003F) * 20.0F, 0.0F); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + modelbaseIn.render(entitylivingbaseIn, p_177183_3_, p_177183_4_, p_177183_6_, p_177183_7_, p_177183_8_, scale); + } + + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glLoadIdentity(); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GlState.enableLighting(); + GlState.depthMask(true); + GlState.depthFunc(GL11.GL_LEQUAL); + GlState.disableBlend(); + } + +// private String getArmorResource(ItemArmor item, boolean legs) +// { +// return this.getArmorResource(item, legs, null); +// } + + private String getArmorResource(ItemArmor item, boolean legs, String layer) + { + return String.format("textures/armor/%s_layer_%d%s.png", item.getArmorTexture(), legs ? 2 : 1, + layer == null ? "" : ("_" + layer)); +// ResourceLocation resourcelocation = (ResourceLocation)ARMOR_TEXTURE_RES_MAP.get(s); +// +// if (resourcelocation == null) +// { +// resourcelocation = new ResourceLocation(s); +// ARMOR_TEXTURE_RES_MAP.put(s, resourcelocation); +// } +// +// return s; + } + +// protected abstract void initArmor(); + +// protected abstract void setModelPartVisible(T model, int armorSlot); + +// protected void initArmor() +// { +// this.modelLeggings = new ModelBiped(0.5F); +// this.modelArmor = new ModelBiped(1.0F); +// } + + protected void setModelPartVisible(ModelBiped model, int armorSlot) + { + model.setVisible(false); + + switch (armorSlot) + { + case 1: + model.bipedRightLeg.showModel = true; + model.bipedLeftLeg.showModel = true; + break; + + case 2: + model.bipedBody.showModel = true; + model.bipedRightLeg.showModel = true; + model.bipedLeftLeg.showModel = true; + break; + + case 3: + model.bipedBody.showModel = true; + model.bipedRightArm.showModel = true; + model.bipedLeftArm.showModel = true; + break; + + case 4: + model.bipedHead.showModel = true; + model.bipedHeadwear.showModel = true; + } + } + +// protected void setModelVisible(ModelBiped model) +// { +// model.setVisible(false); +// } +} diff --git a/client/src/main/java/client/renderer/layers/LayerArrow.java b/client/src/client/renderer/layers/LayerArrow.java similarity index 100% rename from client/src/main/java/client/renderer/layers/LayerArrow.java rename to client/src/client/renderer/layers/LayerArrow.java diff --git a/client/src/main/java/client/renderer/layers/LayerCape.java b/client/src/client/renderer/layers/LayerCape.java similarity index 95% rename from client/src/main/java/client/renderer/layers/LayerCape.java rename to client/src/client/renderer/layers/LayerCape.java index 9e79b88f..495e6781 100755 --- a/client/src/main/java/client/renderer/layers/LayerCape.java +++ b/client/src/client/renderer/layers/LayerCape.java @@ -5,6 +5,7 @@ import org.lwjgl.opengl.GL11; import client.renderer.GlState; import client.renderer.entity.RenderHumanoid; import client.renderer.model.ModelRenderer; +import client.renderer.texture.EntityTexManager; import common.entity.npc.EntityNPC; import common.util.ExtMath; @@ -28,9 +29,9 @@ public class LayerCape implements LayerRenderer { if(/* !entitylivingbaseIn.isInvisible() && */ // entitylivingbaseIn.isWearing(ModelPart.CAPE) // && - entitylivingbaseIn.getCape() != null) { + EntityTexManager.getCape(entitylivingbaseIn) != null) { GlState.color(1.0F, 1.0F, 1.0F, 1.0F); - this.renderer.bindTexture("textures/npc/cape_" + entitylivingbaseIn.getCape() + ".png"); + this.renderer.bindTexture(EntityTexManager.getCape(entitylivingbaseIn)); GL11.glPushMatrix(); GL11.glTranslatef(0.0F, 0.0F, 0.125F); if(entitylivingbaseIn.isPlayer()) { diff --git a/client/src/main/java/client/renderer/layers/LayerCharge.java b/client/src/client/renderer/layers/LayerCharge.java similarity index 96% rename from client/src/main/java/client/renderer/layers/LayerCharge.java rename to client/src/client/renderer/layers/LayerCharge.java index 033b9368..2bc65785 100755 --- a/client/src/main/java/client/renderer/layers/LayerCharge.java +++ b/client/src/client/renderer/layers/LayerCharge.java @@ -10,7 +10,7 @@ import common.entity.npc.EntityNPC; public class LayerCharge implements LayerRenderer { - private static final String LIGHTNING_TEXTURE = "textures/npc/charge.png"; + private static final String LIGHTNING_TEXTURE = "textures/entity/charge.png"; private final RenderHumanoid main; private final ModelCharge charge = new ModelCharge(2.0F); diff --git a/client/src/client/renderer/layers/LayerEnderDragonEyes.java b/client/src/client/renderer/layers/LayerEnderDragonEyes.java new file mode 100755 index 00000000..7fb6b277 --- /dev/null +++ b/client/src/client/renderer/layers/LayerEnderDragonEyes.java @@ -0,0 +1,46 @@ +package client.renderer.layers; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL13; + +import client.renderer.GlState; +import client.renderer.entity.RenderDragon; +import common.entity.animal.EntityDragon; + + +public class LayerEnderDragonEyes implements LayerRenderer +{ + private static final String TEXTURE = "textures/entity/dragon_eyes.png"; + private final RenderDragon dragonRenderer; + + public LayerEnderDragonEyes(RenderDragon dragonRendererIn) + { + this.dragonRenderer = dragonRendererIn; + } + + public void doRenderLayer(EntityDragon entitylivingbaseIn, float p_177141_2_, float p_177141_3_, float partialTicks, float p_177141_5_, float p_177141_6_, float p_177141_7_, float scale) + { + this.dragonRenderer.bindTexture(TEXTURE); + GlState.enableBlend(); + GlState.disableAlpha(); + GlState.blendFunc(GL11.GL_ONE, GL11.GL_ONE); + GlState.disableLighting(); + GlState.depthFunc(GL11.GL_EQUAL); + int i = 61680; + int j = i % 65536; + int k = i / 65536; + GL13.glMultiTexCoord2f(GL13.GL_TEXTURE1, (float)j / 1.0F, (float)k / 1.0F); + GlState.enableLighting(); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + this.dragonRenderer.getMainModel().render(entitylivingbaseIn, p_177141_2_, p_177141_3_, p_177141_5_, p_177141_6_, p_177141_7_, scale); + this.dragonRenderer.setLightmap(entitylivingbaseIn, partialTicks); + GlState.disableBlend(); + GlState.enableAlpha(); + GlState.depthFunc(GL11.GL_LEQUAL); + } + + public boolean shouldCombineTextures() + { + return false; + } +} diff --git a/client/src/main/java/client/renderer/layers/LayerEntityBreak.java b/client/src/client/renderer/layers/LayerEntityBreak.java similarity index 100% rename from client/src/main/java/client/renderer/layers/LayerEntityBreak.java rename to client/src/client/renderer/layers/LayerEntityBreak.java diff --git a/client/src/main/java/client/renderer/layers/LayerExtra.java b/client/src/client/renderer/layers/LayerExtra.java similarity index 98% rename from client/src/main/java/client/renderer/layers/LayerExtra.java rename to client/src/client/renderer/layers/LayerExtra.java index 40bd8dac..ebfe2bb9 100755 --- a/client/src/main/java/client/renderer/layers/LayerExtra.java +++ b/client/src/client/renderer/layers/LayerExtra.java @@ -58,10 +58,11 @@ public class LayerExtra implements LayerRenderer public void doRenderLayer(EntityNPC entity, float p_177141_2_, float p_177141_3_, float partialTicks, float p_177141_5_, float p_177141_6_, float p_177141_7_, float scale) { + EntityNPC extended = entity; // if (!entity.isInvisible()) // { GlState.color(1.0F, 1.0F, 1.0F, 1.0F); - Client.CLIENT.getTextureManager().bindTexture(EntityTexManager.getSkin(entity)); + Client.CLIENT.getTextureManager().bindTexture(EntityTexManager.getSkin(extended)); GL11.glPushMatrix(); if (entity.isSneakingVisually()) @@ -80,7 +81,7 @@ public class LayerExtra implements LayerRenderer GL11.glPushMatrix(); this.model.bipedBody.postRender(0.0625F); for(ModelRenderer model : this.wing) { - if(entity.hasDualWings()) { + if(extended.hasDualWings()) { GL11.glPushMatrix(); GL11.glRotatef(model.rotateAngleY < 0.0f ? -10.0f : 10.0f, 0.0f, 1.0f, 0.0f); GL11.glTranslatef(0.0f, 0.125f, -0.0625f); diff --git a/client/src/client/renderer/layers/LayerHeldItem.java b/client/src/client/renderer/layers/LayerHeldItem.java new file mode 100755 index 00000000..00927e66 --- /dev/null +++ b/client/src/client/renderer/layers/LayerHeldItem.java @@ -0,0 +1,81 @@ +package client.renderer.layers; + +import org.lwjgl.opengl.GL11; + +import client.Client; +import client.renderer.entity.RendererLivingEntity; +import client.renderer.model.ModelBiped; +import common.entity.npc.EntityNPC; +import common.entity.types.EntityLiving; +import common.init.Items; +import common.item.Item; +import common.item.ItemBlock; +import common.item.ItemStack; +import common.model.Transforms; + +public class LayerHeldItem implements LayerRenderer +{ + private final RendererLivingEntity livingEntityRenderer; + private final float xshift; + private final float yshift; + + public LayerHeldItem(RendererLivingEntity livingEntityRendererIn, float xshift, float yshift) + { + this.livingEntityRenderer = livingEntityRendererIn; + this.xshift = xshift * 0.0625F; // -0.0625F + this.yshift = yshift * 0.0625F; // 0.4375F + } + + public void doRenderLayer(EntityLiving entitylivingbaseIn, float p_177141_2_, float p_177141_3_, float partialTicks, float p_177141_5_, float p_177141_6_, float p_177141_7_, float scale) + { + ItemStack itemstack = entitylivingbaseIn.getHeldItem(); + + if (itemstack != null) + { + GL11.glPushMatrix(); + +// if (this.livingEntityRenderer.getMainModel().isChild) +// { +// float f = 0.5F; +// SKC.glTranslatef(0.0F, 0.625F, 0.0F); +// if(this.rotate) { +// SKC.glRotatef(-20.0F, -1.0F, 0.0F, 0.0F); +// } +// SKC.glScalef(f, f, f); +// } + + ((ModelBiped)this.livingEntityRenderer.getMainModel()).postRenderArm(0.0625F); + GL11.glTranslatef(this.xshift, this.yshift, 0.0625F); + + if (entitylivingbaseIn.isPlayer() && ((EntityNPC)entitylivingbaseIn).fishEntity != null) + { + itemstack = new ItemStack(Items.fishing_rod, 0); + } + + Item item = itemstack.getItem(); + Client gm = Client.CLIENT; + + if (item instanceof ItemBlock && item.getBlock().getRenderType() == 2) + { + GL11.glTranslatef(0.0F, 0.1875F, -0.3125F); + GL11.glRotatef(20.0F, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F); + float f1 = 0.375F; + GL11.glScalef(-f1, -f1, f1); + } + + if (entitylivingbaseIn.isSneakingVisually()) + { + GL11.glTranslatef(0.0F, 0.203125F, 0.0F); + } + + gm.getItemRenderer().renderItem(entitylivingbaseIn, itemstack, Transforms.Camera.THIRD_PERSON); + GL11.glPopMatrix(); + } + } + + public boolean shouldCombineTextures() + { + return false; + } +} diff --git a/client/src/client/renderer/layers/LayerMooshroomMushroom.java b/client/src/client/renderer/layers/LayerMooshroomMushroom.java new file mode 100755 index 00000000..424b2948 --- /dev/null +++ b/client/src/client/renderer/layers/LayerMooshroomMushroom.java @@ -0,0 +1,63 @@ +package client.renderer.layers; + +import org.lwjgl.opengl.GL11; + +import client.Client; +import client.renderer.BlockRenderer; +import client.renderer.GlState; +import client.renderer.entity.RenderMooshroom; +import client.renderer.model.ModelQuadruped; +import client.renderer.texture.TextureMap; +import common.entity.animal.EntityMooshroom; +import common.init.Blocks; + +public class LayerMooshroomMushroom implements LayerRenderer +{ + private final RenderMooshroom mooshroomRenderer; + + public LayerMooshroomMushroom(RenderMooshroom mooshroomRendererIn) + { + this.mooshroomRenderer = mooshroomRendererIn; + } + + public void doRenderLayer(EntityMooshroom entitylivingbaseIn, float p_177141_2_, float p_177141_3_, float partialTicks, float p_177141_5_, float p_177141_6_, float p_177141_7_, float scale) + { + if (!entitylivingbaseIn.isChild()) // && !entitylivingbaseIn.isInvisible()) + { + BlockRenderer blockrendererdispatcher = Client.CLIENT.getBlockRendererDispatcher(); + this.mooshroomRenderer.bindTexture(TextureMap.locationBlocksTexture); + GlState.enableCull(); + GlState.cullFace(GL11.GL_FRONT); + GL11.glPushMatrix(); + GL11.glScalef(1.0F, -1.0F, 1.0F); + GL11.glTranslatef(0.2F, 0.35F, 0.5F); + GL11.glRotatef(42.0F, 0.0F, 1.0F, 0.0F); + GL11.glPushMatrix(); + GL11.glTranslatef(-0.5F, -0.5F, 0.5F); + blockrendererdispatcher.renderBlockBrightness(Blocks.red_mushroom.getState(), 1.0F); + GL11.glPopMatrix(); + GL11.glPushMatrix(); + GL11.glTranslatef(0.1F, 0.0F, -0.6F); + GL11.glRotatef(42.0F, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(-0.5F, -0.5F, 0.5F); + blockrendererdispatcher.renderBlockBrightness(Blocks.red_mushroom.getState(), 1.0F); + GL11.glPopMatrix(); + GL11.glPopMatrix(); + GL11.glPushMatrix(); + ((ModelQuadruped)this.mooshroomRenderer.getMainModel()).head.postRender(0.0625F); + GL11.glScalef(1.0F, -1.0F, 1.0F); + GL11.glTranslatef(0.0F, 0.7F, -0.2F); + GL11.glRotatef(12.0F, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(-0.5F, -0.5F, 0.5F); + blockrendererdispatcher.renderBlockBrightness(Blocks.red_mushroom.getState(), 1.0F); + GL11.glPopMatrix(); + GlState.cullFace(GL11.GL_BACK); + GlState.disableCull(); + } + } + + public boolean shouldCombineTextures() + { + return true; + } +} diff --git a/client/src/main/java/client/renderer/layers/LayerPowerRods.java b/client/src/client/renderer/layers/LayerPowerRods.java similarity index 97% rename from client/src/main/java/client/renderer/layers/LayerPowerRods.java rename to client/src/client/renderer/layers/LayerPowerRods.java index 1c800c56..54b45a4b 100755 --- a/client/src/main/java/client/renderer/layers/LayerPowerRods.java +++ b/client/src/client/renderer/layers/LayerPowerRods.java @@ -8,7 +8,7 @@ import common.util.ExtMath; public class LayerPowerRods implements LayerRenderer { - private static final String ROD_TEXTURE = "textures/npc/power_rod.png"; + private static final String ROD_TEXTURE = "textures/entity/power_rod.png"; private final RenderHumanoid renderer; private ModelRenderer powerRod; diff --git a/client/src/main/java/client/renderer/layers/LayerRenderer.java b/client/src/client/renderer/layers/LayerRenderer.java similarity index 100% rename from client/src/main/java/client/renderer/layers/LayerRenderer.java rename to client/src/client/renderer/layers/LayerRenderer.java diff --git a/client/src/main/java/client/renderer/layers/LayerSaddle.java b/client/src/client/renderer/layers/LayerSaddle.java similarity index 92% rename from client/src/main/java/client/renderer/layers/LayerSaddle.java rename to client/src/client/renderer/layers/LayerSaddle.java index cdd49aac..ce30c6b3 100755 --- a/client/src/main/java/client/renderer/layers/LayerSaddle.java +++ b/client/src/client/renderer/layers/LayerSaddle.java @@ -7,7 +7,7 @@ import common.entity.animal.EntityPig; public class LayerSaddle implements LayerRenderer { - private static final String TEXTURE = "textures/creature/pig_saddle.png"; + private static final String TEXTURE = "textures/entity/pig_saddle.png"; private final RenderPig pigRenderer; private final ModelPig pigModel = new ModelPig(0.5F); diff --git a/client/src/main/java/client/renderer/layers/LayerSheepWool.java b/client/src/client/renderer/layers/LayerSheepWool.java similarity index 89% rename from client/src/main/java/client/renderer/layers/LayerSheepWool.java rename to client/src/client/renderer/layers/LayerSheepWool.java index 160295e4..dd1022cf 100755 --- a/client/src/main/java/client/renderer/layers/LayerSheepWool.java +++ b/client/src/client/renderer/layers/LayerSheepWool.java @@ -8,7 +8,7 @@ import common.entity.animal.EntitySheep; public class LayerSheepWool implements LayerRenderer { - private static final String TEXTURE = "textures/creature/sheep_fur.png"; + private static final String TEXTURE = "textures/entity/sheep_fur.png"; private final RenderSheep sheepRenderer; private final ModelSheep1 sheepModel = new ModelSheep1(); @@ -38,7 +38,8 @@ public class LayerSheepWool implements LayerRenderer } else { - GlState.color(entitylivingbaseIn.getFleeceColor().getColor() | 0xff000000); + float[] afloat = EntitySheep.getDyeRgb(entitylivingbaseIn.getFleeceColor()); + GlState.color(afloat[0], afloat[1], afloat[2], 1.0F); } this.sheepModel.setModelAttributes(this.sheepRenderer.getMainModel()); diff --git a/client/src/main/java/client/renderer/layers/LayerSlimeGel.java b/client/src/client/renderer/layers/LayerSlimeGel.java similarity index 100% rename from client/src/main/java/client/renderer/layers/LayerSlimeGel.java rename to client/src/client/renderer/layers/LayerSlimeGel.java diff --git a/client/src/client/renderer/layers/LayerWolfCollar.java b/client/src/client/renderer/layers/LayerWolfCollar.java new file mode 100755 index 00000000..7d07d878 --- /dev/null +++ b/client/src/client/renderer/layers/LayerWolfCollar.java @@ -0,0 +1,36 @@ +package client.renderer.layers; + +import client.renderer.GlState; +import client.renderer.entity.RenderWolf; +import common.color.DyeColor; +import common.entity.animal.EntitySheep; +import common.entity.animal.EntityWolf; + + +public class LayerWolfCollar implements LayerRenderer +{ + private static final String WOLF_COLLAR = "textures/entity/wolf_collar.png"; + private final RenderWolf wolfRenderer; + + public LayerWolfCollar(RenderWolf wolfRendererIn) + { + this.wolfRenderer = wolfRendererIn; + } + + public void doRenderLayer(EntityWolf entitylivingbaseIn, float p_177141_2_, float p_177141_3_, float partialTicks, float p_177141_5_, float p_177141_6_, float p_177141_7_, float scale) + { + if (entitylivingbaseIn.isTamed()) // && !entitylivingbaseIn.isInvisible()) + { + this.wolfRenderer.bindTexture(WOLF_COLLAR); + DyeColor enumdyecolor = DyeColor.byMetadata(entitylivingbaseIn.getCollarColor().getMetadata()); + float[] afloat = EntitySheep.getDyeRgb(enumdyecolor); + GlState.color(afloat[0], afloat[1], afloat[2], 1.0F); + this.wolfRenderer.getMainModel().render(entitylivingbaseIn, p_177141_2_, p_177141_3_, p_177141_5_, p_177141_6_, p_177141_7_, scale); + } + } + + public boolean shouldCombineTextures() + { + return true; + } +} diff --git a/client/src/main/java/client/renderer/model/ModelArachnoid.java b/client/src/client/renderer/model/ModelArachnoid.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelArachnoid.java rename to client/src/client/renderer/model/ModelArachnoid.java diff --git a/client/src/main/java/client/renderer/model/ModelArmor.java b/client/src/client/renderer/model/ModelArmor.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelArmor.java rename to client/src/client/renderer/model/ModelArmor.java diff --git a/client/src/client/renderer/model/ModelBanner.java b/client/src/client/renderer/model/ModelBanner.java new file mode 100755 index 00000000..bd7157e1 --- /dev/null +++ b/client/src/client/renderer/model/ModelBanner.java @@ -0,0 +1,31 @@ +package client.renderer.model; + +public class ModelBanner extends ModelBase +{ + public ModelRenderer bannerSlate; + public ModelRenderer bannerStand; + public ModelRenderer bannerTop; + + public ModelBanner() + { + this.textureWidth = 64; + this.textureHeight = 64; + this.bannerSlate = new ModelRenderer(this, 0, 0); + this.bannerSlate.addBox(-10.0F, 0.0F, -2.0F, 20, 40, 1, 0.0F); + this.bannerStand = new ModelRenderer(this, 44, 0); + this.bannerStand.addBox(-1.0F, -30.0F, -1.0F, 2, 42, 2, 0.0F); + this.bannerTop = new ModelRenderer(this, 0, 42); + this.bannerTop.addBox(-10.0F, -32.0F, -1.0F, 20, 2, 2, 0.0F); + } + + /** + * Renders the banner model in. + */ + public void renderBanner() + { + this.bannerSlate.rotationPointY = -32.0F; + this.bannerSlate.render(0.0625F); + this.bannerStand.render(0.0625F); + this.bannerTop.render(0.0625F); + } +} diff --git a/client/src/main/java/client/renderer/model/ModelBase.java b/client/src/client/renderer/model/ModelBase.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelBase.java rename to client/src/client/renderer/model/ModelBase.java diff --git a/client/src/main/java/client/renderer/model/ModelBat.java b/client/src/client/renderer/model/ModelBat.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelBat.java rename to client/src/client/renderer/model/ModelBat.java diff --git a/client/src/main/java/client/renderer/model/ModelBiped.java b/client/src/client/renderer/model/ModelBiped.java similarity index 92% rename from client/src/main/java/client/renderer/model/ModelBiped.java rename to client/src/client/renderer/model/ModelBiped.java index fee7e02e..32801ca4 100755 --- a/client/src/main/java/client/renderer/model/ModelBiped.java +++ b/client/src/client/renderer/model/ModelBiped.java @@ -114,12 +114,12 @@ public abstract class ModelBiped extends ModelBase { this.bipedHead.rotateAngleY = netHeadYaw / (180F / (float)Math.PI); this.bipedHead.rotateAngleX = headPitch / (180F / (float)Math.PI); - this.bipedRightArm.rotateAngleX = (entityIn == null ? 1.0f : ((EntityLiving)entityIn).getArmRotation()) * ExtMath.cos(limbSwing * 0.6662F + (float)Math.PI) * /* 2.0F * */ limbSwingAmount; // * 0.5F; - this.bipedLeftArm.rotateAngleX = (entityIn == null ? 1.0f : ((EntityLiving)entityIn).getArmRotation()) * ExtMath.cos(limbSwing * 0.6662F) * /* 2.0F * */ limbSwingAmount; // * 0.5F; + this.bipedRightArm.rotateAngleX = ((EntityLiving)entityIn).getArmRotation() * ExtMath.cos(limbSwing * 0.6662F + (float)Math.PI) * /* 2.0F * */ limbSwingAmount; // * 0.5F; + this.bipedLeftArm.rotateAngleX = ((EntityLiving)entityIn).getArmRotation() * ExtMath.cos(limbSwing * 0.6662F) * /* 2.0F * */ limbSwingAmount; // * 0.5F; this.bipedRightArm.rotateAngleZ = 0.0F; this.bipedLeftArm.rotateAngleZ = 0.0F; - this.bipedRightLeg.rotateAngleX = (entityIn == null ? 1.4f : ((EntityLiving)entityIn).getLegRotation()) * ExtMath.cos(limbSwing * 0.6662F) /* * 1.4F */ * limbSwingAmount; - this.bipedLeftLeg.rotateAngleX = (entityIn == null ? 1.4f : ((EntityLiving)entityIn).getLegRotation()) * ExtMath.cos(limbSwing * 0.6662F + (float)Math.PI) /* * 1.4F */ * limbSwingAmount; + this.bipedRightLeg.rotateAngleX = ((EntityLiving)entityIn).getLegRotation() * ExtMath.cos(limbSwing * 0.6662F) /* * 1.4F */ * limbSwingAmount; + this.bipedLeftLeg.rotateAngleX = ((EntityLiving)entityIn).getLegRotation() * ExtMath.cos(limbSwing * 0.6662F + (float)Math.PI) /* * 1.4F */ * limbSwingAmount; this.bipedRightLeg.rotateAngleY = 0.0F; this.bipedLeftLeg.rotateAngleY = 0.0F; @@ -231,8 +231,7 @@ public abstract class ModelBiped extends ModelBase public void setModelAttributes(ModelBase model) { - if(model != null) - super.setModelAttributes(model); + super.setModelAttributes(model); if (model instanceof ModelBiped) { diff --git a/client/src/main/java/client/renderer/model/ModelBoat.java b/client/src/client/renderer/model/ModelBoat.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelBoat.java rename to client/src/client/renderer/model/ModelBoat.java diff --git a/client/src/main/java/client/renderer/model/ModelBox.java b/client/src/client/renderer/model/ModelBox.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelBox.java rename to client/src/client/renderer/model/ModelBox.java diff --git a/client/src/main/java/client/renderer/model/ModelCharge.java b/client/src/client/renderer/model/ModelCharge.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelCharge.java rename to client/src/client/renderer/model/ModelCharge.java diff --git a/client/src/client/renderer/model/ModelChest.java b/client/src/client/renderer/model/ModelChest.java new file mode 100755 index 00000000..bfb5ffee --- /dev/null +++ b/client/src/client/renderer/model/ModelChest.java @@ -0,0 +1,42 @@ +package client.renderer.model; + +public class ModelChest extends ModelBase +{ + /** The chest lid in the chest's model. */ + public ModelRenderer chestLid = (new ModelRenderer(this, 0, 0)).setTextureSize(64, 64); + + /** The model of the bottom of the chest. */ + public ModelRenderer chestBelow; + + /** The chest's knob in the chest model. */ + public ModelRenderer chestKnob; + + public ModelChest() + { + this.chestLid.addBox(0.0F, -5.0F, -14.0F, 14, 5, 14, 0.0F); + this.chestLid.rotationPointX = 1.0F; + this.chestLid.rotationPointY = 7.0F; + this.chestLid.rotationPointZ = 15.0F; + this.chestKnob = (new ModelRenderer(this, 0, 0)).setTextureSize(64, 64); + this.chestKnob.addBox(-1.0F, -2.0F, -15.0F, 2, 4, 1, 0.0F); + this.chestKnob.rotationPointX = 8.0F; + this.chestKnob.rotationPointY = 7.0F; + this.chestKnob.rotationPointZ = 15.0F; + this.chestBelow = (new ModelRenderer(this, 0, 19)).setTextureSize(64, 64); + this.chestBelow.addBox(0.0F, 0.0F, 0.0F, 14, 10, 14, 0.0F); + this.chestBelow.rotationPointX = 1.0F; + this.chestBelow.rotationPointY = 6.0F; + this.chestBelow.rotationPointZ = 1.0F; + } + + /** + * This method renders out all parts of the chest model. + */ + public void renderAll() + { + this.chestKnob.rotateAngleX = this.chestLid.rotateAngleX; + this.chestLid.render(0.0625F); + this.chestKnob.render(0.0625F); + this.chestBelow.render(0.0625F); + } +} diff --git a/client/src/main/java/client/renderer/model/ModelChicken.java b/client/src/client/renderer/model/ModelChicken.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelChicken.java rename to client/src/client/renderer/model/ModelChicken.java diff --git a/client/src/main/java/client/renderer/model/ModelCow.java b/client/src/client/renderer/model/ModelCow.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelCow.java rename to client/src/client/renderer/model/ModelCow.java diff --git a/client/src/main/java/client/renderer/model/ModelCrystal.java b/client/src/client/renderer/model/ModelCrystal.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelCrystal.java rename to client/src/client/renderer/model/ModelCrystal.java diff --git a/client/src/main/java/client/renderer/model/ModelDie.java b/client/src/client/renderer/model/ModelDie.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelDie.java rename to client/src/client/renderer/model/ModelDie.java diff --git a/client/src/main/java/client/renderer/model/ModelDragon.java b/client/src/client/renderer/model/ModelDragon.java similarity index 86% rename from client/src/main/java/client/renderer/model/ModelDragon.java rename to client/src/client/renderer/model/ModelDragon.java index 990c1df7..a4d0f76c 100755 --- a/client/src/main/java/client/renderer/model/ModelDragon.java +++ b/client/src/client/renderer/model/ModelDragon.java @@ -139,9 +139,6 @@ public class ModelDragon extends ModelBase */ public void render(Entity entityIn, float p_78088_2_, float p_78088_3_, float p_78088_4_, float p_78088_5_, float p_78088_6_, float scale) { - GL11.glPushMatrix(); - GL11.glTranslatef(0.0F, 0.5F, 0.0F); - GL11.glScalef(0.35f, 0.35f, 0.35f); GL11.glPushMatrix(); EntityDragon entitydragon = (EntityDragon)entityIn; float f = entitydragon.prevAnimTime + (entitydragon.animTime - entitydragon.prevAnimTime) * this.partialTicks; @@ -153,8 +150,9 @@ public class ModelDragon extends ModelBase float f2 = -30.0F; float f4 = 0.0F; float f5 = 1.5F; - float f6 = 0.0f; - float f7 = this.updateRotations(p_78088_5_ + (double)(f6 / 2.0F)); + double[] adouble = entitydragon.getMovementOffsets(6, this.partialTicks); + float f6 = this.updateRotations(entitydragon.getMovementOffsets(5, this.partialTicks)[0] - entitydragon.getMovementOffsets(10, this.partialTicks)[0]); + float f7 = this.updateRotations(entitydragon.getMovementOffsets(5, this.partialTicks)[0] + (double)(f6 / 2.0F)); f2 = f2 + 2.0F; float f8 = f * (float)Math.PI * 2.0F; f2 = 20.0F; @@ -162,10 +160,11 @@ public class ModelDragon extends ModelBase for (int i = 0; i < 5; ++i) { + double[] adouble1 = entitydragon.getMovementOffsets(5 - i, this.partialTicks); float f9 = (float)Math.cos((double)((float)i * 0.45F + f8)) * 0.15F; - this.spine.rotateAngleY = 0.0f * (float)Math.PI / 180.0F * f5; - this.spine.rotateAngleX = f9 + (float)(0.0f) * (float)Math.PI / 180.0F * f5 * 5.0F; - this.spine.rotateAngleZ = -this.updateRotations(p_78088_5_ - (double)f7) * (float)Math.PI / 180.0F * f5; + this.spine.rotateAngleY = this.updateRotations(adouble1[0] - adouble[0]) * (float)Math.PI / 180.0F * f5; + this.spine.rotateAngleX = f9 + (float)(adouble1[1] - adouble[1]) * (float)Math.PI / 180.0F * f5 * 5.0F; + this.spine.rotateAngleZ = -this.updateRotations(adouble1[0] - (double)f7) * (float)Math.PI / 180.0F * f5; this.spine.rotationPointY = f2; this.spine.rotationPointZ = f3; this.spine.rotationPointX = f4; @@ -178,8 +177,9 @@ public class ModelDragon extends ModelBase this.head.rotationPointY = f2; this.head.rotationPointZ = f3; this.head.rotationPointX = f4; - this.head.rotateAngleY = 0.0f * (float)Math.PI / 180.0F * 1.0F; - this.head.rotateAngleZ = -this.updateRotations(p_78088_5_ - (double)f7) * (float)Math.PI / 180.0F * 1.0F; + double[] adouble2 = entitydragon.getMovementOffsets(0, this.partialTicks); + this.head.rotateAngleY = this.updateRotations(adouble2[0] - adouble[0]) * (float)Math.PI / 180.0F * 1.0F; + this.head.rotateAngleZ = -this.updateRotations(adouble2[0] - (double)f7) * (float)Math.PI / 180.0F * 1.0F; this.head.render(scale); GL11.glPushMatrix(); GL11.glTranslatef(0.0F, 1.0F, 0.0F); @@ -221,13 +221,15 @@ public class ModelDragon extends ModelBase f2 = 10.0F; f3 = 60.0F; f4 = 0.0F; + adouble = entitydragon.getMovementOffsets(11, this.partialTicks); for (int k = 0; k < 12; ++k) { + adouble2 = entitydragon.getMovementOffsets(12 + k, this.partialTicks); f10 = (float)((double)f10 + Math.sin((double)((float)k * 0.45F + f8)) * 0.05000000074505806D); - this.spine.rotateAngleY = (0.0f * f5 + 180.0F) * (float)Math.PI / 180.0F; - this.spine.rotateAngleX = f10 + (float)0.0f * (float)Math.PI / 180.0F * f5 * 5.0F; - this.spine.rotateAngleZ = this.updateRotations(p_78088_5_ - (double)f7) * (float)Math.PI / 180.0F * f5; + this.spine.rotateAngleY = (this.updateRotations(adouble2[0] - adouble[0]) * f5 + 180.0F) * (float)Math.PI / 180.0F; + this.spine.rotateAngleX = f10 + (float)(adouble2[1] - adouble[1]) * (float)Math.PI / 180.0F * f5 * 5.0F; + this.spine.rotateAngleZ = this.updateRotations(adouble2[0] - (double)f7) * (float)Math.PI / 180.0F * f5; this.spine.rotationPointY = f2; this.spine.rotationPointZ = f3; this.spine.rotationPointX = f4; @@ -238,7 +240,6 @@ public class ModelDragon extends ModelBase } GL11.glPopMatrix(); - GL11.glPopMatrix(); } /** diff --git a/client/src/main/java/client/renderer/model/ModelHead.java b/client/src/client/renderer/model/ModelHead.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelHead.java rename to client/src/client/renderer/model/ModelHead.java diff --git a/client/src/main/java/client/renderer/model/ModelHorse.java b/client/src/client/renderer/model/ModelHorse.java similarity index 97% rename from client/src/main/java/client/renderer/model/ModelHorse.java rename to client/src/client/renderer/model/ModelHorse.java index bea368f0..9dc1003c 100755 --- a/client/src/main/java/client/renderer/model/ModelHorse.java +++ b/client/src/client/renderer/model/ModelHorse.java @@ -124,12 +124,12 @@ public class ModelHorse extends ModelBase this.setBoxRotation(this.head, 0.5235988F, 0.0F, 0.0F); this.field_178711_b = new ModelRenderer(this, 24, 18); this.field_178711_b.addBox(-2.0F, -10.0F, -7.0F, 4, 3, 6); - this.field_178711_b.setRotationPoint(0.0F, 0.02F, 0.02F); - this.setBoxRotation(this.field_178711_b, 0.0F, 0.0F, 0.0F); + this.field_178711_b.setRotationPoint(0.0F, 3.95F, -10.0F); + this.setBoxRotation(this.field_178711_b, 0.5235988F, 0.0F, 0.0F); this.field_178712_c = new ModelRenderer(this, 24, 27); this.field_178712_c.addBox(-2.0F, -7.0F, -6.5F, 4, 2, 5); - this.field_178712_c.setRotationPoint(0.0F, 0.0F, 0.0F); - this.setBoxRotation(this.field_178712_c, 0.0F, 0.0F, 0.0F); + this.field_178712_c.setRotationPoint(0.0F, 4.0F, -10.0F); + this.setBoxRotation(this.field_178712_c, 0.5235988F, 0.0F, 0.0F); this.head.addChild(this.field_178711_b); this.head.addChild(this.field_178712_c); this.horseLeftEar = new ModelRenderer(this, 0, 0); @@ -211,14 +211,14 @@ public class ModelHorse extends ModelBase public void render(Entity entityIn, float p_78088_2_, float p_78088_3_, float p_78088_4_, float p_78088_5_, float p_78088_6_, float scale) { EntityHorse entityhorse = (EntityHorse)entityIn; - int i = entityhorse == null ? 0 : entityhorse.getHorseType(); - float f = entityhorse == null ? 0.0f :entityhorse.getGrassEatingAmount(0.0F); - boolean flag = entityhorse == null || entityhorse.isAdultHorse(); - boolean flag1 = flag && (entityhorse == null || entityhorse.isHorseSaddled()); - boolean flag2 = flag && entityhorse != null && entityhorse.isChested(); + int i = entityhorse.getHorseType(); + float f = entityhorse.getGrassEatingAmount(0.0F); + boolean flag = entityhorse.isAdultHorse(); + boolean flag1 = flag && entityhorse.isHorseSaddled(); + boolean flag2 = flag && entityhorse.isChested(); boolean flag3 = i == 1 || i == 2; - float f1 = entityhorse == null ? 0.5f : entityhorse.getHorseSize(); - boolean flag4 = entityhorse != null && entityhorse.passenger != null; + float f1 = entityhorse.getHorseSize(); + boolean flag4 = entityhorse.passenger != null; if (flag1) { diff --git a/client/src/main/java/client/renderer/model/ModelHumanoid.java b/client/src/client/renderer/model/ModelHumanoid.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelHumanoid.java rename to client/src/client/renderer/model/ModelHumanoid.java diff --git a/client/src/client/renderer/model/ModelHumanoidHead.java b/client/src/client/renderer/model/ModelHumanoidHead.java new file mode 100755 index 00000000..6e787e5b --- /dev/null +++ b/client/src/client/renderer/model/ModelHumanoidHead.java @@ -0,0 +1,36 @@ +package client.renderer.model; + +import common.entity.Entity; + +public class ModelHumanoidHead extends ModelHead +{ + private final ModelRenderer head = new ModelRenderer(this, 32, 0); + + public ModelHumanoidHead() + { + super(0, 0, 64, 64); + this.head.addBox(-4.0F, -8.0F, -4.0F, 8, 8, 8, 0.25F); + this.head.setRotationPoint(0.0F, 0.0F, 0.0F); + } + + /** + * Sets the models various rotation angles then renders the model. + */ + public void render(Entity entityIn, float p_78088_2_, float p_78088_3_, float p_78088_4_, float p_78088_5_, float p_78088_6_, float scale) + { + super.render(entityIn, p_78088_2_, p_78088_3_, p_78088_4_, p_78088_5_, p_78088_6_, scale); + this.head.render(scale); + } + + /** + * Sets the model's various rotation angles. For bipeds, par1 and par2 are used for animating the movement of arms + * and legs, where par1 represents the time(so that arms and legs swing back and forth) and par2 represents how + * "far" arms and legs can swing at most. + */ + public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) + { + super.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scaleFactor, entityIn); + this.head.rotateAngleY = this.mainHead.rotateAngleY; + this.head.rotateAngleX = this.mainHead.rotateAngleX; + } +} diff --git a/client/src/client/renderer/model/ModelLargeChest.java b/client/src/client/renderer/model/ModelLargeChest.java new file mode 100755 index 00000000..0c585ac8 --- /dev/null +++ b/client/src/client/renderer/model/ModelLargeChest.java @@ -0,0 +1,23 @@ +package client.renderer.model; + +public class ModelLargeChest extends ModelChest +{ + public ModelLargeChest() + { + this.chestLid = (new ModelRenderer(this, 0, 0)).setTextureSize(128, 64); + this.chestLid.addBox(0.0F, -5.0F, -14.0F, 30, 5, 14, 0.0F); + this.chestLid.rotationPointX = 1.0F; + this.chestLid.rotationPointY = 7.0F; + this.chestLid.rotationPointZ = 15.0F; + this.chestKnob = (new ModelRenderer(this, 0, 0)).setTextureSize(128, 64); + this.chestKnob.addBox(-1.0F, -2.0F, -15.0F, 2, 4, 1, 0.0F); + this.chestKnob.rotationPointX = 16.0F; + this.chestKnob.rotationPointY = 7.0F; + this.chestKnob.rotationPointZ = 15.0F; + this.chestBelow = (new ModelRenderer(this, 0, 19)).setTextureSize(128, 64); + this.chestBelow.addBox(0.0F, 0.0F, 0.0F, 30, 10, 14, 0.0F); + this.chestBelow.rotationPointX = 1.0F; + this.chestBelow.rotationPointY = 6.0F; + this.chestBelow.rotationPointZ = 1.0F; + } +} diff --git a/client/src/main/java/client/renderer/model/ModelLeashKnot.java b/client/src/client/renderer/model/ModelLeashKnot.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelLeashKnot.java rename to client/src/client/renderer/model/ModelLeashKnot.java diff --git a/client/src/main/java/client/renderer/model/ModelMinecart.java b/client/src/client/renderer/model/ModelMinecart.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelMinecart.java rename to client/src/client/renderer/model/ModelMinecart.java diff --git a/client/src/main/java/client/renderer/model/ModelMouse.java b/client/src/client/renderer/model/ModelMouse.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelMouse.java rename to client/src/client/renderer/model/ModelMouse.java diff --git a/client/src/client/renderer/model/ModelOcelot.java b/client/src/client/renderer/model/ModelOcelot.java new file mode 100755 index 00000000..e7765ca0 --- /dev/null +++ b/client/src/client/renderer/model/ModelOcelot.java @@ -0,0 +1,220 @@ +package client.renderer.model; + +import org.lwjgl.opengl.GL11; + +import common.entity.Entity; +import common.entity.animal.EntityOcelot; +import common.entity.types.EntityLiving; +import common.util.ExtMath; + +public class ModelOcelot extends ModelBase +{ + /** The back left leg model for the Ocelot. */ + ModelRenderer ocelotBackLeftLeg; + + /** The back right leg model for the Ocelot. */ + ModelRenderer ocelotBackRightLeg; + + /** The front left leg model for the Ocelot. */ + ModelRenderer ocelotFrontLeftLeg; + + /** The front right leg model for the Ocelot. */ + ModelRenderer ocelotFrontRightLeg; + + /** The tail model for the Ocelot. */ + ModelRenderer ocelotTail; + + /** The second part of tail model for the Ocelot. */ + ModelRenderer ocelotTail2; + + /** The head model for the Ocelot. */ + ModelRenderer ocelotHead; + + /** The body model for the Ocelot. */ + ModelRenderer ocelotBody; + int field_78163_i = 1; + + public ModelOcelot() + { + this.setTextureOffset("head.main", 0, 0); + this.setTextureOffset("head.nose", 0, 24); + this.setTextureOffset("head.ear1", 0, 10); + this.setTextureOffset("head.ear2", 6, 10); + this.ocelotHead = new ModelRenderer(this, "head"); + this.ocelotHead.addBox("main", -2.5F, -2.0F, -3.0F, 5, 4, 5); + this.ocelotHead.addBox("nose", -1.5F, 0.0F, -4.0F, 3, 2, 2); + this.ocelotHead.addBox("ear1", -2.0F, -3.0F, 0.0F, 1, 1, 2); + this.ocelotHead.addBox("ear2", 1.0F, -3.0F, 0.0F, 1, 1, 2); + this.ocelotHead.setRotationPoint(0.0F, 15.0F, -9.0F); + this.ocelotBody = new ModelRenderer(this, 20, 0); + this.ocelotBody.addBox(-2.0F, 3.0F, -8.0F, 4, 16, 6, 0.0F); + this.ocelotBody.setRotationPoint(0.0F, 12.0F, -10.0F); + this.ocelotTail = new ModelRenderer(this, 0, 15); + this.ocelotTail.addBox(-0.5F, 0.0F, 0.0F, 1, 8, 1); + this.ocelotTail.rotateAngleX = 0.9F; + this.ocelotTail.setRotationPoint(0.0F, 15.0F, 8.0F); + this.ocelotTail2 = new ModelRenderer(this, 4, 15); + this.ocelotTail2.addBox(-0.5F, 0.0F, 0.0F, 1, 8, 1); + this.ocelotTail2.setRotationPoint(0.0F, 20.0F, 14.0F); + this.ocelotBackLeftLeg = new ModelRenderer(this, 8, 13); + this.ocelotBackLeftLeg.addBox(-1.0F, 0.0F, 1.0F, 2, 6, 2); + this.ocelotBackLeftLeg.setRotationPoint(1.1F, 18.0F, 5.0F); + this.ocelotBackRightLeg = new ModelRenderer(this, 8, 13); + this.ocelotBackRightLeg.addBox(-1.0F, 0.0F, 1.0F, 2, 6, 2); + this.ocelotBackRightLeg.setRotationPoint(-1.1F, 18.0F, 5.0F); + this.ocelotFrontLeftLeg = new ModelRenderer(this, 40, 0); + this.ocelotFrontLeftLeg.addBox(-1.0F, 0.0F, 0.0F, 2, 10, 2); + this.ocelotFrontLeftLeg.setRotationPoint(1.2F, 13.8F, -5.0F); + this.ocelotFrontRightLeg = new ModelRenderer(this, 40, 0); + this.ocelotFrontRightLeg.addBox(-1.0F, 0.0F, 0.0F, 2, 10, 2); + this.ocelotFrontRightLeg.setRotationPoint(-1.2F, 13.8F, -5.0F); + } + + /** + * Sets the models various rotation angles then renders the model. + */ + public void render(Entity entityIn, float p_78088_2_, float p_78088_3_, float p_78088_4_, float p_78088_5_, float p_78088_6_, float scale) + { + this.setRotationAngles(p_78088_2_, p_78088_3_, p_78088_4_, p_78088_5_, p_78088_6_, scale, entityIn); + + if (this.isChild) + { + float f = 2.0F; + GL11.glPushMatrix(); + GL11.glScalef(1.5F / f, 1.5F / f, 1.5F / f); + GL11.glTranslatef(0.0F, 10.0F * scale, 4.0F * scale); + this.ocelotHead.render(scale); + GL11.glPopMatrix(); + GL11.glPushMatrix(); + GL11.glScalef(1.0F / f, 1.0F / f, 1.0F / f); + GL11.glTranslatef(0.0F, 24.0F * scale, 0.0F); + this.ocelotBody.render(scale); + this.ocelotBackLeftLeg.render(scale); + this.ocelotBackRightLeg.render(scale); + this.ocelotFrontLeftLeg.render(scale); + this.ocelotFrontRightLeg.render(scale); + this.ocelotTail.render(scale); + this.ocelotTail2.render(scale); + GL11.glPopMatrix(); + } + else + { + this.ocelotHead.render(scale); + this.ocelotBody.render(scale); + this.ocelotTail.render(scale); + this.ocelotTail2.render(scale); + this.ocelotBackLeftLeg.render(scale); + this.ocelotBackRightLeg.render(scale); + this.ocelotFrontLeftLeg.render(scale); + this.ocelotFrontRightLeg.render(scale); + } + } + + /** + * Sets the model's various rotation angles. For bipeds, par1 and par2 are used for animating the movement of arms + * and legs, where par1 represents the time(so that arms and legs swing back and forth) and par2 represents how + * "far" arms and legs can swing at most. + */ + public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) + { + this.ocelotHead.rotateAngleX = headPitch / (180F / (float)Math.PI); + this.ocelotHead.rotateAngleY = netHeadYaw / (180F / (float)Math.PI); + + if (this.field_78163_i != 3) + { + this.ocelotBody.rotateAngleX = ((float)Math.PI / 2F); + + if (this.field_78163_i == 2) + { + this.ocelotBackLeftLeg.rotateAngleX = ExtMath.cos(limbSwing * 0.6662F) * 1.0F * limbSwingAmount; + this.ocelotBackRightLeg.rotateAngleX = ExtMath.cos(limbSwing * 0.6662F + 0.3F) * 1.0F * limbSwingAmount; + this.ocelotFrontLeftLeg.rotateAngleX = ExtMath.cos(limbSwing * 0.6662F + (float)Math.PI + 0.3F) * 1.0F * limbSwingAmount; + this.ocelotFrontRightLeg.rotateAngleX = ExtMath.cos(limbSwing * 0.6662F + (float)Math.PI) * 1.0F * limbSwingAmount; + this.ocelotTail2.rotateAngleX = 1.7278761F + ((float)Math.PI / 10F) * ExtMath.cos(limbSwing) * limbSwingAmount; + } + else + { + this.ocelotBackLeftLeg.rotateAngleX = ExtMath.cos(limbSwing * 0.6662F) * 1.0F * limbSwingAmount; + this.ocelotBackRightLeg.rotateAngleX = ExtMath.cos(limbSwing * 0.6662F + (float)Math.PI) * 1.0F * limbSwingAmount; + this.ocelotFrontLeftLeg.rotateAngleX = ExtMath.cos(limbSwing * 0.6662F + (float)Math.PI) * 1.0F * limbSwingAmount; + this.ocelotFrontRightLeg.rotateAngleX = ExtMath.cos(limbSwing * 0.6662F) * 1.0F * limbSwingAmount; + + if (this.field_78163_i == 1) + { + this.ocelotTail2.rotateAngleX = 1.7278761F + ((float)Math.PI / 4F) * ExtMath.cos(limbSwing) * limbSwingAmount; + } + else + { + this.ocelotTail2.rotateAngleX = 1.7278761F + 0.47123894F * ExtMath.cos(limbSwing) * limbSwingAmount; + } + } + } + } + + /** + * Used for easily adding entity-dependent animations. The second and third float params here are the same second + * and third as in the setRotationAngles method. + */ + public void setLivingAnimations(EntityLiving entitylivingbaseIn, float p_78086_2_, float p_78086_3_, float partialTickTime) + { + EntityOcelot entityocelot = (EntityOcelot)entitylivingbaseIn; + this.ocelotBody.rotationPointY = 12.0F; + this.ocelotBody.rotationPointZ = -10.0F; + this.ocelotHead.rotationPointY = 15.0F; + this.ocelotHead.rotationPointZ = -9.0F; + this.ocelotTail.rotationPointY = 15.0F; + this.ocelotTail.rotationPointZ = 8.0F; + this.ocelotTail2.rotationPointY = 20.0F; + this.ocelotTail2.rotationPointZ = 14.0F; + this.ocelotFrontLeftLeg.rotationPointY = this.ocelotFrontRightLeg.rotationPointY = 13.8F; + this.ocelotFrontLeftLeg.rotationPointZ = this.ocelotFrontRightLeg.rotationPointZ = -5.0F; + this.ocelotBackLeftLeg.rotationPointY = this.ocelotBackRightLeg.rotationPointY = 18.0F; + this.ocelotBackLeftLeg.rotationPointZ = this.ocelotBackRightLeg.rotationPointZ = 5.0F; + this.ocelotTail.rotateAngleX = 0.9F; + + if (entityocelot.isSneakingVisually()) + { + ++this.ocelotBody.rotationPointY; + this.ocelotHead.rotationPointY += 2.0F; + ++this.ocelotTail.rotationPointY; + this.ocelotTail2.rotationPointY += -4.0F; + this.ocelotTail2.rotationPointZ += 2.0F; + this.ocelotTail.rotateAngleX = ((float)Math.PI / 2F); + this.ocelotTail2.rotateAngleX = ((float)Math.PI / 2F); + this.field_78163_i = 0; + } + else if (entityocelot.isSprinting()) + { + this.ocelotTail2.rotationPointY = this.ocelotTail.rotationPointY; + this.ocelotTail2.rotationPointZ += 2.0F; + this.ocelotTail.rotateAngleX = ((float)Math.PI / 2F); + this.ocelotTail2.rotateAngleX = ((float)Math.PI / 2F); + this.field_78163_i = 2; + } + else if (entityocelot.isSitting()) + { + this.ocelotBody.rotateAngleX = ((float)Math.PI / 4F); + this.ocelotBody.rotationPointY += -4.0F; + this.ocelotBody.rotationPointZ += 5.0F; + this.ocelotHead.rotationPointY += -3.3F; + ++this.ocelotHead.rotationPointZ; + this.ocelotTail.rotationPointY += 8.0F; + this.ocelotTail.rotationPointZ += -2.0F; + this.ocelotTail2.rotationPointY += 2.0F; + this.ocelotTail2.rotationPointZ += -0.8F; + this.ocelotTail.rotateAngleX = 1.7278761F; + this.ocelotTail2.rotateAngleX = 2.670354F; + this.ocelotFrontLeftLeg.rotateAngleX = this.ocelotFrontRightLeg.rotateAngleX = -0.15707964F; + this.ocelotFrontLeftLeg.rotationPointY = this.ocelotFrontRightLeg.rotationPointY = 15.8F; + this.ocelotFrontLeftLeg.rotationPointZ = this.ocelotFrontRightLeg.rotationPointZ = -7.0F; + this.ocelotBackLeftLeg.rotateAngleX = this.ocelotBackRightLeg.rotateAngleX = -((float)Math.PI / 2F); + this.ocelotBackLeftLeg.rotationPointY = this.ocelotBackRightLeg.rotationPointY = 21.0F; + this.ocelotBackLeftLeg.rotationPointZ = this.ocelotBackRightLeg.rotationPointZ = 1.0F; + this.field_78163_i = 3; + } + else + { + this.field_78163_i = 1; + } + } +} diff --git a/client/src/main/java/client/renderer/model/ModelPig.java b/client/src/client/renderer/model/ModelPig.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelPig.java rename to client/src/client/renderer/model/ModelPig.java diff --git a/client/src/main/java/client/renderer/model/ModelQuadruped.java b/client/src/client/renderer/model/ModelQuadruped.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelQuadruped.java rename to client/src/client/renderer/model/ModelQuadruped.java diff --git a/client/src/main/java/client/renderer/model/ModelRabbit.java b/client/src/client/renderer/model/ModelRabbit.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelRabbit.java rename to client/src/client/renderer/model/ModelRabbit.java diff --git a/client/src/main/java/client/renderer/model/ModelRenderer.java b/client/src/client/renderer/model/ModelRenderer.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelRenderer.java rename to client/src/client/renderer/model/ModelRenderer.java diff --git a/client/src/main/java/client/renderer/model/ModelSheep1.java b/client/src/client/renderer/model/ModelSheep1.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelSheep1.java rename to client/src/client/renderer/model/ModelSheep1.java diff --git a/client/src/main/java/client/renderer/model/ModelSheep2.java b/client/src/client/renderer/model/ModelSheep2.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelSheep2.java rename to client/src/client/renderer/model/ModelSheep2.java diff --git a/client/src/client/renderer/model/ModelSign.java b/client/src/client/renderer/model/ModelSign.java new file mode 100755 index 00000000..3685860a --- /dev/null +++ b/client/src/client/renderer/model/ModelSign.java @@ -0,0 +1,26 @@ +package client.renderer.model; + +public class ModelSign extends ModelBase +{ + /** The board on a sign that has the writing on it. */ + public ModelRenderer signBoard = new ModelRenderer(this, 0, 0); + + /** The stick a sign stands on. */ + public ModelRenderer signStick; + + public ModelSign() + { + this.signBoard.addBox(-12.0F, -14.0F, -1.0F, 24, 12, 2, 0.0F); + this.signStick = new ModelRenderer(this, 0, 14); + this.signStick.addBox(-1.0F, -2.0F, -1.0F, 2, 14, 2, 0.0F); + } + + /** + * Renders the sign model through TileEntitySignRenderer + */ + public void renderSign() + { + this.signBoard.render(0.0625F); + this.signStick.render(0.0625F); + } +} diff --git a/client/src/main/java/client/renderer/model/ModelSlime.java b/client/src/client/renderer/model/ModelSlime.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelSlime.java rename to client/src/client/renderer/model/ModelSlime.java diff --git a/client/src/main/java/client/renderer/model/ModelSpaceMarine.java b/client/src/client/renderer/model/ModelSpaceMarine.java similarity index 100% rename from client/src/main/java/client/renderer/model/ModelSpaceMarine.java rename to client/src/client/renderer/model/ModelSpaceMarine.java diff --git a/client/src/client/renderer/model/ModelSquid.java b/client/src/client/renderer/model/ModelSquid.java new file mode 100755 index 00000000..5db6680a --- /dev/null +++ b/client/src/client/renderer/model/ModelSquid.java @@ -0,0 +1,61 @@ +package client.renderer.model; + +import common.entity.Entity; + +public class ModelSquid extends ModelBase +{ + /** The squid's body */ + ModelRenderer squidBody; + + /** The squid's tentacles */ + ModelRenderer[] squidTentacles = new ModelRenderer[8]; + + public ModelSquid() + { + int i = -16; + this.squidBody = new ModelRenderer(this, 0, 0); + this.squidBody.addBox(-6.0F, -8.0F, -6.0F, 12, 16, 12); + this.squidBody.rotationPointY += (float)(24 + i); + + for (int j = 0; j < this.squidTentacles.length; ++j) + { + this.squidTentacles[j] = new ModelRenderer(this, 48, 0); + double d0 = (double)j * Math.PI * 2.0D / (double)this.squidTentacles.length; + float f = (float)Math.cos(d0) * 5.0F; + float f1 = (float)Math.sin(d0) * 5.0F; + this.squidTentacles[j].addBox(-1.0F, 0.0F, -1.0F, 2, 18, 2); + this.squidTentacles[j].rotationPointX = f; + this.squidTentacles[j].rotationPointZ = f1; + this.squidTentacles[j].rotationPointY = (float)(31 + i); + d0 = (double)j * Math.PI * -2.0D / (double)this.squidTentacles.length + (Math.PI / 2D); + this.squidTentacles[j].rotateAngleY = (float)d0; + } + } + + /** + * Sets the model's various rotation angles. For bipeds, par1 and par2 are used for animating the movement of arms + * and legs, where par1 represents the time(so that arms and legs swing back and forth) and par2 represents how + * "far" arms and legs can swing at most. + */ + public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) + { + for (ModelRenderer modelrenderer : this.squidTentacles) + { + modelrenderer.rotateAngleX = ageInTicks; + } + } + + /** + * Sets the models various rotation angles then renders the model. + */ + public void render(Entity entityIn, float p_78088_2_, float p_78088_3_, float p_78088_4_, float p_78088_5_, float p_78088_6_, float scale) + { + this.setRotationAngles(p_78088_2_, p_78088_3_, p_78088_4_, p_78088_5_, p_78088_6_, scale, entityIn); + this.squidBody.render(scale); + + for (int i = 0; i < this.squidTentacles.length; ++i) + { + this.squidTentacles[i].render(scale); + } + } +} diff --git a/client/src/main/java/client/renderer/model/ModelWolf.java b/client/src/client/renderer/model/ModelWolf.java similarity index 92% rename from client/src/main/java/client/renderer/model/ModelWolf.java rename to client/src/client/renderer/model/ModelWolf.java index 35d8eb2b..acc9ff40 100755 --- a/client/src/main/java/client/renderer/model/ModelWolf.java +++ b/client/src/client/renderer/model/ModelWolf.java @@ -110,11 +110,11 @@ public class ModelWolf extends ModelBase * Used for easily adding entity-dependent animations. The second and third float params here are the same second * and third as in the setRotationAngles method. */ - public void setLivingAnimations(EntityLiving living, float p_78086_2_, float p_78086_3_, float partialTickTime) + public void setLivingAnimations(EntityLiving entitylivingbaseIn, float p_78086_2_, float p_78086_3_, float partialTickTime) { - EntityWolf wolf = (EntityWolf)living; + EntityWolf entitywolf = (EntityWolf)entitylivingbaseIn; - if (wolf.isAngry()) + if (entitywolf.isAngry()) { this.wolfTail.rotateAngleY = 0.0F; } @@ -123,7 +123,7 @@ public class ModelWolf extends ModelBase this.wolfTail.rotateAngleY = ExtMath.cos(p_78086_2_ * 0.6662F) * 1.4F * p_78086_3_; } - if (wolf.isSitting()) + if (entitywolf.isSitting()) { this.wolfMane.setRotationPoint(-1.0F, 16.0F, -3.0F); this.wolfMane.rotateAngleX = ((float)Math.PI * 2F / 5F); @@ -157,10 +157,7 @@ public class ModelWolf extends ModelBase this.wolfLeg4.rotateAngleX = ExtMath.cos(p_78086_2_ * 0.6662F) * 1.4F * p_78086_3_; } - this.wolfHeadMain.rotateAngleZ = wolf.getInterestedAngle(partialTickTime) + wolf.getShakeAngle(partialTickTime, 0.0F); - this.wolfMane.rotateAngleZ = wolf.getShakeAngle(partialTickTime, -0.08F); - this.wolfBody.rotateAngleZ = wolf.getShakeAngle(partialTickTime, -0.16F); - this.wolfTail.rotateAngleZ = wolf.getShakeAngle(partialTickTime, -0.2F); + this.wolfHeadMain.rotateAngleZ = entitywolf.getInterestedAngle(partialTickTime); } /** diff --git a/client/src/main/java/client/renderer/model/PositionTextureVertex.java b/client/src/client/renderer/model/PositionTextureVertex.java similarity index 100% rename from client/src/main/java/client/renderer/model/PositionTextureVertex.java rename to client/src/client/renderer/model/PositionTextureVertex.java diff --git a/client/src/main/java/client/renderer/model/TextureOffset.java b/client/src/client/renderer/model/TextureOffset.java similarity index 100% rename from client/src/main/java/client/renderer/model/TextureOffset.java rename to client/src/client/renderer/model/TextureOffset.java diff --git a/client/src/main/java/client/renderer/model/TexturedQuad.java b/client/src/client/renderer/model/TexturedQuad.java similarity index 100% rename from client/src/main/java/client/renderer/model/TexturedQuad.java rename to client/src/client/renderer/model/TexturedQuad.java diff --git a/client/src/client/renderer/particle/EffectRenderer.java b/client/src/client/renderer/particle/EffectRenderer.java new file mode 100755 index 00000000..5d6ea5fd --- /dev/null +++ b/client/src/client/renderer/particle/EffectRenderer.java @@ -0,0 +1,431 @@ +package client.renderer.particle; + +import java.util.List; +import java.util.Map; + +import org.lwjgl.opengl.GL11; + +import client.renderer.ActiveRenderInfo; +import client.renderer.DefaultVertexFormats; +import client.renderer.GlState; +import client.renderer.RenderBuffer; +import client.renderer.Tessellator; +import client.renderer.texture.TextureManager; +import client.renderer.texture.TextureMap; +import common.block.Block; +import common.collect.Lists; +import common.collect.Maps; +import common.entity.Entity; +import common.material.Material; +import common.model.ParticleType; +import common.rng.Random; +import common.util.BlockPos; +import common.util.ExtMath; +import common.util.Facing; +import common.world.State; +import common.world.World; + +public class EffectRenderer +{ + public static final String particleTextures = "textures/world/particles.png"; + + /** Reference to the World object. */ + protected World worldObj; + private List[][] fxLayers = new List[4][]; + private List particleEmitters = Lists.newArrayList(); + private TextureManager renderer; + + /** RNG. */ + private Random rand = new Random(); + private Map particleTypes = Maps.newHashMap(); + + public EffectRenderer(World worldIn, TextureManager rendererIn) + { + this.worldObj = worldIn; + this.renderer = rendererIn; + + for (int i = 0; i < 4; ++i) + { + this.fxLayers[i] = new List[2]; + + for (int j = 0; j < 2; ++j) + { + this.fxLayers[i][j] = Lists.newArrayList(); + } + } + + this.registerVanillaParticles(); + } + + private void registerVanillaParticles() + { + this.registerParticle(ParticleType.EXPLOSION_NORMAL.getParticleID(), new EntityExplodeFX.Factory()); + this.registerParticle(ParticleType.WATER_BUBBLE.getParticleID(), new EntityBubbleFX.Factory()); + this.registerParticle(ParticleType.WATER_SPLASH.getParticleID(), new EntitySplashFX.Factory()); + this.registerParticle(ParticleType.WATER_WAKE.getParticleID(), new EntityFishWakeFX.Factory()); + this.registerParticle(ParticleType.WATER_DROP.getParticleID(), new EntityDownfallFX.RainFactory()); + this.registerParticle(ParticleType.SUSPENDED.getParticleID(), new EntitySuspendFX.Factory()); + this.registerParticle(ParticleType.SUSPENDED_DEPTH.getParticleID(), new EntityAuraFX.SuspendFactory()); + this.registerParticle(ParticleType.CRIT.getParticleID(), new EntityCrit2FX.Factory()); + this.registerParticle(ParticleType.CRIT_MAGIC.getParticleID(), new EntityCrit2FX.MagicFactory()); + this.registerParticle(ParticleType.SMOKE_NORMAL.getParticleID(), new EntitySmokeFX.Factory()); + this.registerParticle(ParticleType.SMOKE_LARGE.getParticleID(), new EntityCritFX.Factory()); + this.registerParticle(ParticleType.SPELL.getParticleID(), new EntitySpellParticleFX.Factory()); + this.registerParticle(ParticleType.SPELL_INSTANT.getParticleID(), new EntitySpellParticleFX.InstantFactory()); + this.registerParticle(ParticleType.SPELL_MOB.getParticleID(), new EntitySpellParticleFX.MobFactory()); + this.registerParticle(ParticleType.SPELL_MOB_AMBIENT.getParticleID(), new EntitySpellParticleFX.AmbientMobFactory()); + this.registerParticle(ParticleType.SPELL_WITCH.getParticleID(), new EntitySpellParticleFX.WitchFactory()); + this.registerParticle(ParticleType.DRIP_WATER.getParticleID(), new EntityDropParticleFX.WaterFactory()); + this.registerParticle(ParticleType.DRIP_LAVA.getParticleID(), new EntityDropParticleFX.LavaFactory()); +// this.registerParticle(EnumParticleTypes.VILLAGER_ANGRY.getParticleID(), new EntityHeartFX.AngryVillagerFactory()); + this.registerParticle(ParticleType.GROW.getParticleID(), new EntityAuraFX.GrowFactory()); + this.registerParticle(ParticleType.TOWN_AURA.getParticleID(), new EntityAuraFX.Factory()); + this.registerParticle(ParticleType.NOTE.getParticleID(), new EntityNoteFX.Factory()); + this.registerParticle(ParticleType.PORTAL.getParticleID(), new EntityPortalFX.Factory()); + this.registerParticle(ParticleType.ENCHANTMENT_TABLE.getParticleID(), new EntityEnchantmentTableParticleFX.EnchantmentTable()); + this.registerParticle(ParticleType.FLAME.getParticleID(), new EntityFlameFX.Factory()); + this.registerParticle(ParticleType.LAVA.getParticleID(), new EntityLavaFX.Factory()); + this.registerParticle(ParticleType.FOOTSTEP.getParticleID(), new EntityFootStepFX.Factory()); + this.registerParticle(ParticleType.CLOUD.getParticleID(), new EntityCloudFX.Factory()); + this.registerParticle(ParticleType.REDSTONE.getParticleID(), new EntityReddustFX.Factory()); + this.registerParticle(ParticleType.SNOWBALL.getParticleID(), new EntityBreakingFX.SnowballFactory()); + this.registerParticle(ParticleType.SNOW_SHOVEL.getParticleID(), new EntitySnowShovelFX.Factory()); + this.registerParticle(ParticleType.SLIME.getParticleID(), new EntityBreakingFX.SlimeFactory()); + this.registerParticle(ParticleType.HEART.getParticleID(), new EntityHeartFX.Factory()); +// this.registerParticle(EnumParticleTypes.BARRIER.getParticleID(), new Barrier.Factory()); + this.registerParticle(ParticleType.ITEM_CRACK.getParticleID(), new EntityBreakingFX.Factory()); + this.registerParticle(ParticleType.BLOCK_CRACK.getParticleID(), new EntityDiggingFX.Factory()); + this.registerParticle(ParticleType.BLOCK_DUST.getParticleID(), new EntityBlockDustFX.Factory()); + this.registerParticle(ParticleType.EXPLOSION_HUGE.getParticleID(), new EntityHugeExplodeFX.Factory()); + this.registerParticle(ParticleType.EXPLOSION_LARGE.getParticleID(), new EntityLargeExplodeFX.Factory()); + this.registerParticle(ParticleType.FIREWORKS_SPARK.getParticleID(), new EntityFirework.Factory()); + this.registerParticle(ParticleType.HAIL_CORN.getParticleID(), new EntityDownfallFX.HailFactory()); + } + + public void registerParticle(int id, IParticleFactory particleFactory) + { + this.particleTypes.put(Integer.valueOf(id), particleFactory); + } + + public void emitParticleAtEntity(Entity entityIn, ParticleType particleTypes) + { + this.particleEmitters.add(new EntityParticleEmitter(this.worldObj, entityIn, particleTypes)); + } + + /** + * Spawns the relevant particle according to the particle id. + * + * @param xCoord X position of the particle + * @param yCoord Y position of the particle + * @param zCoord Z position of the particle + * @param xSpeed X speed of the particle + * @param ySpeed Y speed of the particle + * @param zSpeed Z speed of the particle + * @param parameters Parameters for the particle (color for redstone, ...) + */ + public EntityFX spawnEffectParticle(int particleId, double xCoord, double yCoord, double zCoord, double xSpeed, double ySpeed, double zSpeed, int[] parameters) + { + IParticleFactory iparticlefactory = (IParticleFactory)this.particleTypes.get(Integer.valueOf(particleId)); + + if (iparticlefactory != null) + { + EntityFX entityfx = iparticlefactory.getEntityFX(particleId, this.worldObj, xCoord, yCoord, zCoord, xSpeed, ySpeed, zSpeed, parameters); + + if (entityfx != null) + { + this.addEffect(entityfx); + return entityfx; + } + } + + return null; + } + + public void addEffect(EntityFX effect) + { + int i = effect.getFXLayer(); + int j = effect.getAlpha() != 1.0F ? 0 : 1; + + if (this.fxLayers[i][j].size() >= 4000) + { + this.fxLayers[i][j].remove(0); + } + + this.fxLayers[i][j].add(effect); + } + + public void updateEffects() + { + for (int i = 0; i < 4; ++i) + { + this.updateEffectLayer(i); + } + + List list = Lists.newArrayList(); + + for (EntityParticleEmitter entityparticleemitter : this.particleEmitters) + { + entityparticleemitter.onUpdate(); + + if (entityparticleemitter.dead) + { + list.add(entityparticleemitter); + } + } + + this.particleEmitters.removeAll(list); + } + + private void updateEffectLayer(int layer) + { + for (int i = 0; i < 2; ++i) + { + this.updateEffectAlphaLayer(this.fxLayers[layer][i]); + } + } + + private void updateEffectAlphaLayer(List entitiesFX) + { + List list = Lists.newArrayList(); + + for (int i = 0; i < entitiesFX.size(); ++i) + { + EntityFX entityfx = (EntityFX)entitiesFX.get(i); + this.tickParticle(entityfx); + + if (entityfx.dead) + { + list.add(entityfx); + } + } + + entitiesFX.removeAll(list); + } + + private void tickParticle(final EntityFX particle) + { + particle.onUpdate(); + } + + /** + * Renders all current particles. Args player, partialTickTime + */ + public void renderParticles(Entity entityIn, float partialTicks) + { + float f = ActiveRenderInfo.getRotationX(); + float f1 = ActiveRenderInfo.getRotationZ(); + float f2 = ActiveRenderInfo.getRotationYZ(); + float f3 = ActiveRenderInfo.getRotationXY(); + float f4 = ActiveRenderInfo.getRotationXZ(); + EntityFX.interpPosX = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * (double)partialTicks; + EntityFX.interpPosY = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * (double)partialTicks; + EntityFX.interpPosZ = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * (double)partialTicks; + GlState.enableBlend(); + GlState.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlState.alphaFunc(GL11.GL_GREATER, 0.003921569F); + + for (int i = 0; i < 3; ++i) + { + for (int j = 0; j < 2; ++j) + { + final int i_f = i; + + if (!this.fxLayers[i][j].isEmpty()) + { + switch (j) + { + case 0: + GlState.depthMask(false); + break; + + case 1: + GlState.depthMask(true); + } + + switch (i) + { + case 0: + default: + this.renderer.bindTexture(particleTextures); + break; + + case 1: + this.renderer.bindTexture(TextureMap.locationBlocksTexture); + } + + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); +// Tessellator tessellator = Tessellator.getInstance(); + RenderBuffer worldrenderer = Tessellator.getBuffer(); + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP); + + for (int k = 0; k < this.fxLayers[i][j].size(); ++k) + { + final EntityFX entityfx = (EntityFX)this.fxLayers[i][j].get(k); + + entityfx.renderParticle(worldrenderer, entityIn, partialTicks, f, f4, f1, f2, f3); + } + + Tessellator.draw(); + } + } + } + + GlState.depthMask(true); + GlState.disableBlend(); + GlState.alphaFunc(GL11.GL_GREATER, 0.1F); + } + + public void renderLitParticles(Entity entityIn, float partialTick) + { + float f = 0.017453292F; + float f1 = ExtMath.cos(entityIn.rotYaw * 0.017453292F); + float f2 = ExtMath.sin(entityIn.rotYaw * 0.017453292F); + float f3 = -f2 * ExtMath.sin(entityIn.rotPitch * 0.017453292F); + float f4 = f1 * ExtMath.sin(entityIn.rotPitch * 0.017453292F); + float f5 = ExtMath.cos(entityIn.rotPitch * 0.017453292F); + + for (int i = 0; i < 2; ++i) + { + List list = this.fxLayers[3][i]; + + if (!list.isEmpty()) + { +// Tessellator tessellator = Tessellator.getInstance(); + RenderBuffer worldrenderer = Tessellator.getBuffer(); + + for (int j = 0; j < list.size(); ++j) + { + EntityFX entityfx = (EntityFX)list.get(j); + entityfx.renderParticle(worldrenderer, entityIn, partialTick, f1, f5, f2, f3, f4); + } + } + } + } + + public void clearEffects(World worldIn) + { + this.worldObj = worldIn; + + for (int i = 0; i < 4; ++i) + { + for (int j = 0; j < 2; ++j) + { + this.fxLayers[i][j].clear(); + } + } + + this.particleEmitters.clear(); + } + + public void addBlockDestroyEffects(BlockPos pos, State state) + { + if (state.getBlock().getMaterial() != Material.air) + { + state = state.getBlock().getActualState(state, this.worldObj, pos); + int i = 4; + + for (int j = 0; j < i; ++j) + { + for (int k = 0; k < i; ++k) + { + for (int l = 0; l < i; ++l) + { + double d0 = (double)pos.getX() + ((double)j + 0.5D) / (double)i; + double d1 = (double)pos.getY() + ((double)k + 0.5D) / (double)i; + double d2 = (double)pos.getZ() + ((double)l + 0.5D) / (double)i; + this.addEffect((new EntityDiggingFX(this.worldObj, d0, d1, d2, d0 - (double)pos.getX() - 0.5D, d1 - (double)pos.getY() - 0.5D, d2 - (double)pos.getZ() - 0.5D, state)).setBlockPos(pos)); + } + } + } + } + } + + /** + * Adds block hit particles for the specified block + */ + public void addBlockHitEffects(BlockPos pos, Facing side) + { + State iblockstate = this.worldObj.getState(pos); + Block block = iblockstate.getBlock(); + + if (block.getRenderType() != -1) + { + int i = pos.getX(); + int j = pos.getY(); + int k = pos.getZ(); + float f = 0.1F; + double d0 = (double)i + this.rand.doublev() * (block.getBlockBoundsMaxX() - block.getBlockBoundsMinX() - (double)(f * 2.0F)) + (double)f + block.getBlockBoundsMinX(); + double d1 = (double)j + this.rand.doublev() * (block.getBlockBoundsMaxY() - block.getBlockBoundsMinY() - (double)(f * 2.0F)) + (double)f + block.getBlockBoundsMinY(); + double d2 = (double)k + this.rand.doublev() * (block.getBlockBoundsMaxZ() - block.getBlockBoundsMinZ() - (double)(f * 2.0F)) + (double)f + block.getBlockBoundsMinZ(); + + if (side == Facing.DOWN) + { + d1 = (double)j + block.getBlockBoundsMinY() - (double)f; + } + + if (side == Facing.UP) + { + d1 = (double)j + block.getBlockBoundsMaxY() + (double)f; + } + + if (side == Facing.NORTH) + { + d2 = (double)k + block.getBlockBoundsMinZ() - (double)f; + } + + if (side == Facing.SOUTH) + { + d2 = (double)k + block.getBlockBoundsMaxZ() + (double)f; + } + + if (side == Facing.WEST) + { + d0 = (double)i + block.getBlockBoundsMinX() - (double)f; + } + + if (side == Facing.EAST) + { + d0 = (double)i + block.getBlockBoundsMaxX() + (double)f; + } + + this.addEffect((new EntityDiggingFX(this.worldObj, d0, d1, d2, 0.0D, 0.0D, 0.0D, iblockstate)).setBlockPos(pos).multiplyVelocity(0.2F).multipleParticleScaleBy(0.6F)); + } + } + + public void moveToAlphaLayer(EntityFX effect) + { + this.moveToLayer(effect, 1, 0); + } + + public void moveToNoAlphaLayer(EntityFX effect) + { + this.moveToLayer(effect, 0, 1); + } + + private void moveToLayer(EntityFX effect, int layerFrom, int layerTo) + { + for (int i = 0; i < 4; ++i) + { + if (this.fxLayers[i][layerFrom].contains(effect)) + { + this.fxLayers[i][layerFrom].remove(effect); + this.fxLayers[i][layerTo].add(effect); + } + } + } + + public String getStatistics() + { + int i = 0; + + for (int j = 0; j < 4; ++j) + { + for (int k = 0; k < 2; ++k) + { + i += this.fxLayers[j][k].size(); + } + } + + return "" + i; + } +} diff --git a/client/src/client/renderer/particle/EntityAuraFX.java b/client/src/client/renderer/particle/EntityAuraFX.java new file mode 100755 index 00000000..1240fb84 --- /dev/null +++ b/client/src/client/renderer/particle/EntityAuraFX.java @@ -0,0 +1,82 @@ +package client.renderer.particle; + +import common.world.World; + +public class EntityAuraFX extends EntityFX +{ + private final boolean fullBright; + + protected EntityAuraFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double speedIn, boolean fullBright) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, speedIn); + float f = this.rand.floatv() * 0.1F + 0.2F; + this.particleRed = f; + this.particleGreen = f; + this.particleBlue = f; + this.setParticleTextureIndex(0); + this.setSize(0.02F, 0.02F); + this.particleScale *= this.rand.floatv() * 0.6F + 0.5F; + this.motionX *= 0.019999999552965164D; + this.motionY *= 0.019999999552965164D; + this.motionZ *= 0.019999999552965164D; + this.particleMaxAge = (int)(20.0D / (Math.random() * 0.8D + 0.2D)); + this.noClip = true; + this.fullBright = fullBright; + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.99D; + this.motionY *= 0.99D; + this.motionZ *= 0.99D; + + if (this.particleMaxAge-- <= 0) + { + this.setDead(); + } + } + + public int getBrightnessForRender(float partialTicks) + { + return this.fullBright ? 15728880 : super.getBrightnessForRender(partialTicks); + } + + public float getBrightness(float partialTicks) + { + return this.fullBright ? 1.0F : super.getBrightness(partialTicks); + } + + public static class SuspendFactory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityAuraFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn, true); + } + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityAuraFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn, false); + } + } + + public static class GrowFactory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + EntityFX entityfx = new EntityAuraFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn, false); + entityfx.setParticleTextureIndex(82); + entityfx.setRBGColorF(1.0F, 1.0F, 1.0F); + return entityfx; + } + } +} diff --git a/client/src/client/renderer/particle/EntityBlockDustFX.java b/client/src/client/renderer/particle/EntityBlockDustFX.java new file mode 100755 index 00000000..cc6f8055 --- /dev/null +++ b/client/src/client/renderer/particle/EntityBlockDustFX.java @@ -0,0 +1,25 @@ +package client.renderer.particle; + +import common.init.BlockRegistry; +import common.world.State; +import common.world.World; + +public class EntityBlockDustFX extends EntityDiggingFX +{ + protected EntityBlockDustFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, State state) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn, state); + this.motionX = xSpeedIn; + this.motionY = ySpeedIn; + this.motionZ = zSpeedIn; + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + State iblockstate = BlockRegistry.getStateById(p_178902_15_[0]); + return iblockstate.getBlock().getRenderType() == -1 ? null : (new EntityBlockDustFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn, iblockstate)).calculateColor(); + } + } +} diff --git a/client/src/client/renderer/particle/EntityBreakingFX.java b/client/src/client/renderer/particle/EntityBreakingFX.java new file mode 100755 index 00000000..fb192367 --- /dev/null +++ b/client/src/client/renderer/particle/EntityBreakingFX.java @@ -0,0 +1,98 @@ +package client.renderer.particle; + +import client.Client; +import client.renderer.RenderBuffer; +import common.entity.Entity; +import common.init.ItemRegistry; +import common.init.Items; +import common.item.Item; +import common.world.World; + +public class EntityBreakingFX extends EntityFX +{ + protected EntityBreakingFX(World worldIn, double posXIn, double posYIn, double posZIn, Item p_i1195_8_) + { + this(worldIn, posXIn, posYIn, posZIn, p_i1195_8_, 0); + } + + protected EntityBreakingFX(World worldIn, double posXIn, double posYIn, double posZIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, Item p_i1197_14_, int p_i1197_15_) + { + this(worldIn, posXIn, posYIn, posZIn, p_i1197_14_, p_i1197_15_); + this.motionX *= 0.10000000149011612D; + this.motionY *= 0.10000000149011612D; + this.motionZ *= 0.10000000149011612D; + this.motionX += xSpeedIn; + this.motionY += ySpeedIn; + this.motionZ += zSpeedIn; + } + + protected EntityBreakingFX(World worldIn, double posXIn, double posYIn, double posZIn, Item p_i1196_8_, int p_i1196_9_) + { + super(worldIn, posXIn, posYIn, posZIn, 0.0D, 0.0D, 0.0D); + this.setParticleIcon(Client.CLIENT.getRenderItem().getItemModelMesher().getParticleIcon(p_i1196_8_, p_i1196_9_)); + this.particleRed = this.particleGreen = this.particleBlue = 1.0F; + this.particleGravity = 1.0F; // Blocks.snow.particleGravity; + this.particleScale /= 2.0F; + } + + public int getFXLayer() + { + return 1; + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + float f = ((float)this.particleTextureIndexX + this.particleTextureJitterX / 4.0F) / 16.0F; + float f1 = f + 0.015609375F; + float f2 = ((float)this.particleTextureIndexY + this.particleTextureJitterY / 4.0F) / 16.0F; + float f3 = f2 + 0.015609375F; + float f4 = 0.1F * this.particleScale; + + if (this.particleIcon != null) + { + f = this.particleIcon.getInterpolatedU((double)(this.particleTextureJitterX / 4.0F * 16.0F)); + f1 = this.particleIcon.getInterpolatedU((double)((this.particleTextureJitterX + 1.0F) / 4.0F * 16.0F)); + f2 = this.particleIcon.getInterpolatedV((double)(this.particleTextureJitterY / 4.0F * 16.0F)); + f3 = this.particleIcon.getInterpolatedV((double)((this.particleTextureJitterY + 1.0F) / 4.0F * 16.0F)); + } + + float f5 = (float)(this.prevX + (this.posX - this.prevX) * (double)partialTicks - interpPosX); + float f6 = (float)(this.prevY + (this.posY - this.prevY) * (double)partialTicks - interpPosY); + float f7 = (float)(this.prevZ + (this.posZ - this.prevZ) * (double)partialTicks - interpPosZ); + int i = this.getBrightnessForRender(partialTicks); + int j = i >> 16 & 65535; + int k = i & 65535; + worldRendererIn.pos((double)(f5 - rotationX * f4 - rotationXY * f4), (double)(f6 - rotationZ * f4), (double)(f7 - rotationYZ * f4 - rotationXZ * f4)).tex((double)f, (double)f3).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(j, k).endVertex(); + worldRendererIn.pos((double)(f5 - rotationX * f4 + rotationXY * f4), (double)(f6 + rotationZ * f4), (double)(f7 - rotationYZ * f4 + rotationXZ * f4)).tex((double)f, (double)f2).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(j, k).endVertex(); + worldRendererIn.pos((double)(f5 + rotationX * f4 + rotationXY * f4), (double)(f6 + rotationZ * f4), (double)(f7 + rotationYZ * f4 + rotationXZ * f4)).tex((double)f1, (double)f2).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(j, k).endVertex(); + worldRendererIn.pos((double)(f5 + rotationX * f4 - rotationXY * f4), (double)(f6 - rotationZ * f4), (double)(f7 + rotationYZ * f4 - rotationXZ * f4)).tex((double)f1, (double)f3).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(j, k).endVertex(); + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + int i = p_178902_15_.length > 1 ? p_178902_15_[1] : 0; + return new EntityBreakingFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn, ItemRegistry.getItemById(p_178902_15_[0]), i); + } + } + + public static class SlimeFactory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityBreakingFX(worldIn, xCoordIn, yCoordIn, zCoordIn, Items.slime_ball); + } + } + + public static class SnowballFactory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityBreakingFX(worldIn, xCoordIn, yCoordIn, zCoordIn, Items.snowball); + } + } +} diff --git a/client/src/client/renderer/particle/EntityBubbleFX.java b/client/src/client/renderer/particle/EntityBubbleFX.java new file mode 100755 index 00000000..44c03f7b --- /dev/null +++ b/client/src/client/renderer/particle/EntityBubbleFX.java @@ -0,0 +1,56 @@ +package client.renderer.particle; + +import common.material.Material; +import common.util.BlockPos; +import common.world.World; + +public class EntityBubbleFX extends EntityFX +{ + protected EntityBubbleFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + this.particleRed = 1.0F; + this.particleGreen = 1.0F; + this.particleBlue = 1.0F; + this.setParticleTextureIndex(32); + this.setSize(0.02F, 0.02F); + this.particleScale *= this.rand.floatv() * 0.6F + 0.2F; + this.motionX = xSpeedIn * 0.20000000298023224D + (Math.random() * 2.0D - 1.0D) * 0.019999999552965164D; + this.motionY = ySpeedIn * 0.20000000298023224D + (Math.random() * 2.0D - 1.0D) * 0.019999999552965164D; + this.motionZ = zSpeedIn * 0.20000000298023224D + (Math.random() * 2.0D - 1.0D) * 0.019999999552965164D; + this.particleMaxAge = (int)(8.0D / (Math.random() * 0.8D + 0.2D)); + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + this.motionY += 0.002D; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.8500000238418579D; + this.motionY *= 0.8500000238418579D; + this.motionZ *= 0.8500000238418579D; + + if (this.worldObj.getState(new BlockPos(this)).getBlock().getMaterial() != Material.water) + { + this.setDead(); + } + + if (this.particleMaxAge-- <= 0) + { + this.setDead(); + } + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityBubbleFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntityCloudFX.java b/client/src/client/renderer/particle/EntityCloudFX.java new file mode 100755 index 00000000..4b46bf94 --- /dev/null +++ b/client/src/client/renderer/particle/EntityCloudFX.java @@ -0,0 +1,85 @@ +package client.renderer.particle; + +import client.renderer.RenderBuffer; +import common.entity.Entity; +import common.entity.npc.EntityNPC; +import common.util.ExtMath; +import common.world.World; + +public class EntityCloudFX extends EntityFX +{ + float field_70569_a; + + protected EntityCloudFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double p_i1221_8_, double p_i1221_10_, double p_i1221_12_) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, 0.0D, 0.0D, 0.0D); + float f = 2.5F; + this.motionX *= 0.10000000149011612D; + this.motionY *= 0.10000000149011612D; + this.motionZ *= 0.10000000149011612D; + this.motionX += p_i1221_8_; + this.motionY += p_i1221_10_; + this.motionZ += p_i1221_12_; + this.particleRed = this.particleGreen = this.particleBlue = 1.0F - (float)(Math.random() * 0.30000001192092896D); + this.particleScale *= 0.75F; + this.particleScale *= f; + this.field_70569_a = this.particleScale; + this.particleMaxAge = (int)(8.0D / (Math.random() * 0.8D + 0.3D)); + this.particleMaxAge = (int)((float)this.particleMaxAge * f); + this.noClip = false; + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge * 32.0F; + f = ExtMath.clampf(f, 0.0F, 1.0F); + this.particleScale = this.field_70569_a * f; + super.renderParticle(worldRendererIn, entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ); + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + + if (this.particleAge++ >= this.particleMaxAge) + { + this.setDead(); + } + + this.setParticleTextureIndex(7 - this.particleAge * 8 / this.particleMaxAge); + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.9599999785423279D; + this.motionY *= 0.9599999785423279D; + this.motionZ *= 0.9599999785423279D; + EntityNPC entityplayer = this.worldObj.getClosestPlayerToEntity(this, 2.0D); + + if (entityplayer != null && this.posY > entityplayer.getEntityBoundingBox().minY) + { + this.posY += (entityplayer.getEntityBoundingBox().minY - this.posY) * 0.2D; + this.motionY += (entityplayer.motionY - this.motionY) * 0.2D; + this.setPosition(this.posX, this.posY, this.posZ); + } + + if (this.onGround) + { + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityCloudFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntityCrit2FX.java b/client/src/client/renderer/particle/EntityCrit2FX.java new file mode 100755 index 00000000..e021842a --- /dev/null +++ b/client/src/client/renderer/particle/EntityCrit2FX.java @@ -0,0 +1,95 @@ +package client.renderer.particle; + +import client.renderer.RenderBuffer; +import common.entity.Entity; +import common.util.ExtMath; +import common.world.World; + +public class EntityCrit2FX extends EntityFX +{ + float field_174839_a; + + protected EntityCrit2FX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double p_i46284_8_, double p_i46284_10_, double p_i46284_12_) + { + this(worldIn, xCoordIn, yCoordIn, zCoordIn, p_i46284_8_, p_i46284_10_, p_i46284_12_, 1.0F); + } + + protected EntityCrit2FX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double p_i46285_8_, double p_i46285_10_, double p_i46285_12_, float p_i46285_14_) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, 0.0D, 0.0D, 0.0D); + this.motionX *= 0.10000000149011612D; + this.motionY *= 0.10000000149011612D; + this.motionZ *= 0.10000000149011612D; + this.motionX += p_i46285_8_ * 0.4D; + this.motionY += p_i46285_10_ * 0.4D; + this.motionZ += p_i46285_12_ * 0.4D; + this.particleRed = this.particleGreen = this.particleBlue = (float)(Math.random() * 0.30000001192092896D + 0.6000000238418579D); + this.particleScale *= 0.75F; + this.particleScale *= p_i46285_14_; + this.field_174839_a = this.particleScale; + this.particleMaxAge = (int)(6.0D / (Math.random() * 0.8D + 0.6D)); + this.particleMaxAge = (int)((float)this.particleMaxAge * p_i46285_14_); + this.noClip = false; + this.setParticleTextureIndex(65); + this.onUpdate(); + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge * 32.0F; + f = ExtMath.clampf(f, 0.0F, 1.0F); + this.particleScale = this.field_174839_a * f; + super.renderParticle(worldRendererIn, entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ); + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + + if (this.particleAge++ >= this.particleMaxAge) + { + this.setDead(); + } + + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.particleGreen = (float)((double)this.particleGreen * 0.96D); + this.particleBlue = (float)((double)this.particleBlue * 0.9D); + this.motionX *= 0.699999988079071D; + this.motionY *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + this.motionY -= 0.019999999552965164D; + + if (this.onGround) + { + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityCrit2FX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } + + public static class MagicFactory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + EntityFX entityfx = new EntityCrit2FX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + entityfx.setRBGColorF(entityfx.getRedColorF() * 0.3F, entityfx.getGreenColorF() * 0.8F, entityfx.getBlueColorF()); + entityfx.nextTextureIndexX(); + return entityfx; + } + } +} diff --git a/client/src/client/renderer/particle/EntityCritFX.java b/client/src/client/renderer/particle/EntityCritFX.java new file mode 100755 index 00000000..2e224ccf --- /dev/null +++ b/client/src/client/renderer/particle/EntityCritFX.java @@ -0,0 +1,19 @@ +package client.renderer.particle; + +import common.world.World; + +public class EntityCritFX extends EntitySmokeFX +{ + protected EntityCritFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double p_i1201_8_, double p_i1201_10_, double p_i1201_12_) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, p_i1201_8_, p_i1201_10_, p_i1201_12_, 2.5F); + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityCritFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntityDiggingFX.java b/client/src/client/renderer/particle/EntityDiggingFX.java new file mode 100755 index 00000000..9a6e7537 --- /dev/null +++ b/client/src/client/renderer/particle/EntityDiggingFX.java @@ -0,0 +1,124 @@ +package client.renderer.particle; + +import client.Client; +import client.renderer.RenderBuffer; +import common.block.Block; +import common.entity.Entity; +import common.init.BlockRegistry; +import common.init.Blocks; +import common.util.BlockPos; +import common.world.State; +import common.world.World; + +public class EntityDiggingFX extends EntityFX +{ + private State sourceState; + private BlockPos sourcePos; + + protected EntityDiggingFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, State state) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + this.sourceState = state; + this.setParticleIcon(Client.CLIENT.getBlockRendererDispatcher().getModelManager().getTexture(state)); + this.particleGravity = 1.0F; // state.getBlock().particleGravity; + this.particleRed = this.particleGreen = this.particleBlue = 0.6F; + this.particleScale /= 2.0F; + } + + /** + * Sets the position of the block that this particle came from. Used for calculating texture and color multiplier. + */ + public EntityDiggingFX setBlockPos(BlockPos pos) + { + this.sourcePos = pos; + + if (this.sourceState.getBlock() == Blocks.grass) + { + return this; + } + else + { + int i = this.sourceState.getBlock().colorMultiplier(this.worldObj, pos); + this.particleRed *= (float)(i >> 16 & 255) / 255.0F; + this.particleGreen *= (float)(i >> 8 & 255) / 255.0F; + this.particleBlue *= (float)(i & 255) / 255.0F; + return this; + } + } + + public EntityDiggingFX calculateColor() + { + this.sourcePos = new BlockPos(this.posX, this.posY, this.posZ); + Block block = this.sourceState.getBlock(); + + if (block == Blocks.grass) + { + return this; + } + else + { + int i = block.getRenderColor(this.sourceState); + this.particleRed *= (float)(i >> 16 & 255) / 255.0F; + this.particleGreen *= (float)(i >> 8 & 255) / 255.0F; + this.particleBlue *= (float)(i & 255) / 255.0F; + return this; + } + } + + public int getFXLayer() + { + return 1; + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + float f = ((float)this.particleTextureIndexX + this.particleTextureJitterX / 4.0F) / 16.0F; + float f1 = f + 0.015609375F; + float f2 = ((float)this.particleTextureIndexY + this.particleTextureJitterY / 4.0F) / 16.0F; + float f3 = f2 + 0.015609375F; + float f4 = 0.1F * this.particleScale; + + if (this.particleIcon != null) + { + f = this.particleIcon.getInterpolatedU((double)(this.particleTextureJitterX / 4.0F * 16.0F)); + f1 = this.particleIcon.getInterpolatedU((double)((this.particleTextureJitterX + 1.0F) / 4.0F * 16.0F)); + f2 = this.particleIcon.getInterpolatedV((double)(this.particleTextureJitterY / 4.0F * 16.0F)); + f3 = this.particleIcon.getInterpolatedV((double)((this.particleTextureJitterY + 1.0F) / 4.0F * 16.0F)); + } + + float f5 = (float)(this.prevX + (this.posX - this.prevX) * (double)partialTicks - interpPosX); + float f6 = (float)(this.prevY + (this.posY - this.prevY) * (double)partialTicks - interpPosY); + float f7 = (float)(this.prevZ + (this.posZ - this.prevZ) * (double)partialTicks - interpPosZ); + int i = this.getBrightnessForRender(partialTicks); + int j = i >> 16 & 65535; + int k = i & 65535; + worldRendererIn.pos((double)(f5 - rotationX * f4 - rotationXY * f4), (double)(f6 - rotationZ * f4), (double)(f7 - rotationYZ * f4 - rotationXZ * f4)).tex((double)f, (double)f3).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(j, k).endVertex(); + worldRendererIn.pos((double)(f5 - rotationX * f4 + rotationXY * f4), (double)(f6 + rotationZ * f4), (double)(f7 - rotationYZ * f4 + rotationXZ * f4)).tex((double)f, (double)f2).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(j, k).endVertex(); + worldRendererIn.pos((double)(f5 + rotationX * f4 + rotationXY * f4), (double)(f6 + rotationZ * f4), (double)(f7 + rotationYZ * f4 + rotationXZ * f4)).tex((double)f1, (double)f2).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(j, k).endVertex(); + worldRendererIn.pos((double)(f5 + rotationX * f4 - rotationXY * f4), (double)(f6 - rotationZ * f4), (double)(f7 + rotationYZ * f4 - rotationXZ * f4)).tex((double)f1, (double)f3).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(j, k).endVertex(); + } + + public int getBrightnessForRender(float partialTicks) + { + int i = super.getBrightnessForRender(partialTicks); + int j = 0; + + if (this.worldObj.isBlockLoaded(this.sourcePos)) + { + j = this.worldObj.getCombinedLight(this.sourcePos, 0); + } + + return i == 0 ? j : i; + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return (new EntityDiggingFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn, BlockRegistry.getStateById(p_178902_15_[0]))).calculateColor(); + } + } +} diff --git a/client/src/client/renderer/particle/EntityDownfallFX.java b/client/src/client/renderer/particle/EntityDownfallFX.java new file mode 100755 index 00000000..b2bd9517 --- /dev/null +++ b/client/src/client/renderer/particle/EntityDownfallFX.java @@ -0,0 +1,101 @@ +package client.renderer.particle; + +import common.block.Block; +import common.block.BlockLiquid; +import common.material.Material; +import common.util.BlockPos; +import common.util.ExtMath; +import common.world.State; +import common.world.World; + +public class EntityDownfallFX extends EntityFX +{ + protected EntityDownfallFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, int texture, int numTex) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, 0.0D, 0.0D, 0.0D); + this.motionX *= 0.30000001192092896D; + this.motionY = Math.random() * 0.20000000298023224D + 0.10000000149011612D; + this.motionZ *= 0.30000001192092896D; + this.particleRed = 1.0F; + this.particleGreen = 1.0F; + this.particleBlue = 1.0F; + this.setParticleTextureIndex(19 + texture * 4 + this.rand.zrange(numTex)); + this.setSize(0.01F, 0.01F); + this.particleGravity = 0.06F; + this.particleMaxAge = (int)(8.0D / (Math.random() * 0.8D + 0.2D)); + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + this.motionY -= (double)this.particleGravity; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.9800000190734863D; + this.motionY *= 0.9800000190734863D; + this.motionZ *= 0.9800000190734863D; + + if (this.particleMaxAge-- <= 0) + { + this.setDead(); + } + + if (this.onGround) + { + if (Math.random() < 0.5D) + { + this.setDead(); + } + + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } + + BlockPos blockpos = new BlockPos(this); + State iblockstate = this.worldObj.getState(blockpos); + Block block = iblockstate.getBlock(); + block.setBlockBoundsBasedOnState(this.worldObj, blockpos); + Material material = iblockstate.getBlock().getMaterial(); + + if (material.isLiquid() || material.isSolid()) + { + double d0 = 0.0D; + + if (iblockstate.getBlock() instanceof BlockLiquid) + { + d0 = (double)(1.0F - BlockLiquid.getLiquidHeightPercent(((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue())); + } + else + { + d0 = block.getBlockBoundsMaxY(); + } + + double d1 = (double)ExtMath.floord(this.posY) + d0; + + if (this.posY < d1) + { + this.setDead(); + } + } + } + + public static class RainFactory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityDownfallFX(worldIn, xCoordIn, yCoordIn, zCoordIn, 0, 4); + } + } + + public static class HailFactory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityDownfallFX(worldIn, xCoordIn, yCoordIn, zCoordIn, 1, 4); + } + } +} diff --git a/client/src/client/renderer/particle/EntityDropParticleFX.java b/client/src/client/renderer/particle/EntityDropParticleFX.java new file mode 100755 index 00000000..90542cdf --- /dev/null +++ b/client/src/client/renderer/particle/EntityDropParticleFX.java @@ -0,0 +1,158 @@ +package client.renderer.particle; + +import common.block.BlockLiquid; +import common.material.Material; +import common.model.ParticleType; +import common.util.BlockPos; +import common.util.ExtMath; +import common.world.State; +import common.world.World; + +public class EntityDropParticleFX extends EntityFX +{ + /** the material type for dropped items/blocks */ + private Material materialType; + + /** The height of the current bob */ + private int bobTimer; + + protected EntityDropParticleFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, Material p_i1203_8_) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, 0.0D, 0.0D, 0.0D); + this.motionX = this.motionY = this.motionZ = 0.0D; + + if (p_i1203_8_ == Material.water) + { + this.particleRed = 0.0F; + this.particleGreen = 0.0F; + this.particleBlue = 1.0F; + } + else + { + this.particleRed = 1.0F; + this.particleGreen = 0.0F; + this.particleBlue = 0.0F; + } + + this.setParticleTextureIndex(113); + this.setSize(0.01F, 0.01F); + this.particleGravity = 0.06F; + this.materialType = p_i1203_8_; + this.bobTimer = 40; + this.particleMaxAge = (int)(64.0D / (Math.random() * 0.8D + 0.2D)); + this.motionX = this.motionY = this.motionZ = 0.0D; + } + + public int getBrightnessForRender(float partialTicks) + { + return this.materialType == Material.water ? super.getBrightnessForRender(partialTicks) : 257; + } + + /** + * Gets how bright this entity is. + */ + public float getBrightness(float partialTicks) + { + return this.materialType == Material.water ? super.getBrightness(partialTicks) : 1.0F; + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + + if (this.materialType == Material.water) + { + this.particleRed = 0.2F; + this.particleGreen = 0.3F; + this.particleBlue = 1.0F; + } + else + { + this.particleRed = 1.0F; + this.particleGreen = 16.0F / (float)(40 - this.bobTimer + 16); + this.particleBlue = 4.0F / (float)(40 - this.bobTimer + 8); + } + + this.motionY -= (double)this.particleGravity; + + if (this.bobTimer-- > 0) + { + this.motionX *= 0.02D; + this.motionY *= 0.02D; + this.motionZ *= 0.02D; + this.setParticleTextureIndex(113); + } + else + { + this.setParticleTextureIndex(112); + } + + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.9800000190734863D; + this.motionY *= 0.9800000190734863D; + this.motionZ *= 0.9800000190734863D; + + if (this.particleMaxAge-- <= 0) + { + this.setDead(); + } + + if (this.onGround) + { + if (this.materialType == Material.water) + { + this.setDead(); + this.worldObj.spawnParticle(ParticleType.WATER_SPLASH, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D); + } + else + { + this.setParticleTextureIndex(114); + } + + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } + + BlockPos blockpos = new BlockPos(this); + State iblockstate = this.worldObj.getState(blockpos); + Material material = iblockstate.getBlock().getMaterial(); + + if (material.isLiquid() || material.isSolid()) + { + double d0 = 0.0D; + + if (iblockstate.getBlock() instanceof BlockLiquid) + { + d0 = (double)BlockLiquid.getLiquidHeightPercent(((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue()); + } + + double d1 = (double)(ExtMath.floord(this.posY) + 1) - d0; + + if (this.posY < d1) + { + this.setDead(); + } + } + } + + public static class LavaFactory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityDropParticleFX(worldIn, xCoordIn, yCoordIn, zCoordIn, Material.lava); + } + } + + public static class WaterFactory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityDropParticleFX(worldIn, xCoordIn, yCoordIn, zCoordIn, Material.water); + } + } +} diff --git a/client/src/client/renderer/particle/EntityEnchantmentTableParticleFX.java b/client/src/client/renderer/particle/EntityEnchantmentTableParticleFX.java new file mode 100755 index 00000000..b337bc0d --- /dev/null +++ b/client/src/client/renderer/particle/EntityEnchantmentTableParticleFX.java @@ -0,0 +1,94 @@ +package client.renderer.particle; + +import common.world.World; + +public class EntityEnchantmentTableParticleFX extends EntityFX +{ + private float field_70565_a; + private double coordX; + private double coordY; + private double coordZ; + + protected EntityEnchantmentTableParticleFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + this.motionX = xSpeedIn; + this.motionY = ySpeedIn; + this.motionZ = zSpeedIn; + this.coordX = xCoordIn; + this.coordY = yCoordIn; + this.coordZ = zCoordIn; + this.posX = this.prevX = xCoordIn + xSpeedIn; + this.posY = this.prevY = yCoordIn + ySpeedIn; + this.posZ = this.prevZ = zCoordIn + zSpeedIn; + float f = this.rand.floatv() * 0.6F + 0.4F; + this.field_70565_a = this.particleScale = this.rand.floatv() * 0.5F + 0.2F; + this.particleRed = this.particleGreen = this.particleBlue = 1.0F * f; + this.particleGreen *= 0.9F; + this.particleRed *= 0.9F; + this.particleMaxAge = (int)(Math.random() * 10.0D) + 30; + this.noClip = true; + this.setParticleTextureIndex((int)(Math.random() * 26.0D + 1.0D + 224.0D)); + } + + public int getBrightnessForRender(float partialTicks) + { + int i = super.getBrightnessForRender(partialTicks); + float f = (float)this.particleAge / (float)this.particleMaxAge; + f = f * f; + f = f * f; + int j = i & 255; + int k = i >> 16 & 255; + k = k + (int)(f * 15.0F * 16.0F); + + if (k > 240) + { + k = 240; + } + + return j | k << 16; + } + + /** + * Gets how bright this entity is. + */ + public float getBrightness(float partialTicks) + { + float f = super.getBrightness(partialTicks); + float f1 = (float)this.particleAge / (float)this.particleMaxAge; + f1 = f1 * f1; + f1 = f1 * f1; + return f * (1.0F - f1) + f1; + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + float f = (float)this.particleAge / (float)this.particleMaxAge; + f = 1.0F - f; + float f1 = 1.0F - f; + f1 = f1 * f1; + f1 = f1 * f1; + this.posX = this.coordX + this.motionX * (double)f; + this.posY = this.coordY + this.motionY * (double)f - (double)(f1 * 1.2F); + this.posZ = this.coordZ + this.motionZ * (double)f; + + if (this.particleAge++ >= this.particleMaxAge) + { + this.setDead(); + } + } + + public static class EnchantmentTable implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityEnchantmentTableParticleFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntityExplodeFX.java b/client/src/client/renderer/particle/EntityExplodeFX.java new file mode 100755 index 00000000..fcf1d11c --- /dev/null +++ b/client/src/client/renderer/particle/EntityExplodeFX.java @@ -0,0 +1,53 @@ +package client.renderer.particle; + +import common.world.World; + +public class EntityExplodeFX extends EntityFX +{ + protected EntityExplodeFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + this.motionX = xSpeedIn + (Math.random() * 2.0D - 1.0D) * 0.05000000074505806D; + this.motionY = ySpeedIn + (Math.random() * 2.0D - 1.0D) * 0.05000000074505806D; + this.motionZ = zSpeedIn + (Math.random() * 2.0D - 1.0D) * 0.05000000074505806D; + this.particleRed = this.particleGreen = this.particleBlue = this.rand.floatv() * 0.3F + 0.7F; + this.particleScale = this.rand.floatv() * this.rand.floatv() * 6.0F + 1.0F; + this.particleMaxAge = (int)(16.0D / ((double)this.rand.floatv() * 0.8D + 0.2D)) + 2; + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + + if (this.particleAge++ >= this.particleMaxAge) + { + this.setDead(); + } + + this.setParticleTextureIndex(7 - this.particleAge * 8 / this.particleMaxAge); + this.motionY += 0.004D; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.8999999761581421D; + this.motionY *= 0.8999999761581421D; + this.motionZ *= 0.8999999761581421D; + + if (this.onGround) + { + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityExplodeFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntityFX.java b/client/src/client/renderer/particle/EntityFX.java new file mode 100755 index 00000000..67c53bdb --- /dev/null +++ b/client/src/client/renderer/particle/EntityFX.java @@ -0,0 +1,290 @@ +package client.renderer.particle; + +import client.Client; +import client.renderer.RenderBuffer; +import client.renderer.texture.TextureAtlasSprite; +import common.entity.Entity; +import common.entity.EntityType; +import common.nbt.NBTTagCompound; +import common.util.ExtMath; +import common.world.World; + +public class EntityFX extends Entity +{ + protected int particleTextureIndexX; + protected int particleTextureIndexY; + protected float particleTextureJitterX; + protected float particleTextureJitterY; + protected int particleAge; + protected int particleMaxAge; + protected float particleScale; + protected float particleGravity; + + /** The red amount of color. Used as a percentage, 1.0 = 255 and 0.0 = 0. */ + protected float particleRed; + + /** + * The green amount of color. Used as a percentage, 1.0 = 255 and 0.0 = 0. + */ + protected float particleGreen; + + /** + * The blue amount of color. Used as a percentage, 1.0 = 255 and 0.0 = 0. + */ + protected float particleBlue; + + /** Particle alpha */ + protected float particleAlpha; + + /** The icon field from which the given particle pulls its texture. */ + protected TextureAtlasSprite particleIcon; + public static double interpPosX; + public static double interpPosY; + public static double interpPosZ; + + protected EntityFX(World worldIn, double posXIn, double posYIn, double posZIn) + { + super(worldIn); + this.particleAlpha = 1.0F; + this.setSize(0.2F, 0.2F); + this.setPosition(posXIn, posYIn, posZIn); + this.lastTickPosX = this.prevX = posXIn; + this.lastTickPosY = this.prevY = posYIn; + this.lastTickPosZ = this.prevZ = posZIn; + this.particleRed = this.particleGreen = this.particleBlue = 1.0F; + this.particleTextureJitterX = this.rand.floatv() * 3.0F; + this.particleTextureJitterY = this.rand.floatv() * 3.0F; + this.particleScale = (this.rand.floatv() * 0.5F + 0.5F) * 2.0F; + this.particleMaxAge = (int)(4.0F / (this.rand.floatv() * 0.9F + 0.1F)); + this.particleAge = 0; + } + + public EntityFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn) + { + this(worldIn, xCoordIn, yCoordIn, zCoordIn); + this.motionX = xSpeedIn + (Math.random() * 2.0D - 1.0D) * 0.4000000059604645D; + this.motionY = ySpeedIn + (Math.random() * 2.0D - 1.0D) * 0.4000000059604645D; + this.motionZ = zSpeedIn + (Math.random() * 2.0D - 1.0D) * 0.4000000059604645D; + float f = (float)(Math.random() + Math.random() + 1.0D) * 0.15F; + float f1 = ExtMath.sqrtd(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ); + this.motionX = this.motionX / (double)f1 * (double)f * 0.4000000059604645D; + this.motionY = this.motionY / (double)f1 * (double)f * 0.4000000059604645D + 0.10000000149011612D; + this.motionZ = this.motionZ / (double)f1 * (double)f * 0.4000000059604645D; + } + + public EntityFX multiplyVelocity(float multiplier) + { + this.motionX *= (double)multiplier; + this.motionY = (this.motionY - 0.10000000149011612D) * (double)multiplier + 0.10000000149011612D; + this.motionZ *= (double)multiplier; + return this; + } + + public EntityFX multipleParticleScaleBy(float scale) + { + this.setSize(0.2F * scale, 0.2F * scale); + this.particleScale *= scale; + return this; + } + + public void setRBGColorF(float particleRedIn, float particleGreenIn, float particleBlueIn) + { + this.particleRed = particleRedIn; + this.particleGreen = particleGreenIn; + this.particleBlue = particleBlueIn; + } + + /** + * Sets the particle alpha (float) + */ + public void setAlphaF(float alpha) + { + if (this.particleAlpha == 1.0F && alpha < 1.0F) + { + Client.CLIENT.effectRenderer.moveToAlphaLayer(this); + } + else if (this.particleAlpha < 1.0F && alpha == 1.0F) + { + Client.CLIENT.effectRenderer.moveToNoAlphaLayer(this); + } + + this.particleAlpha = alpha; + } + + public float getRedColorF() + { + return this.particleRed; + } + + public float getGreenColorF() + { + return this.particleGreen; + } + + public float getBlueColorF() + { + return this.particleBlue; + } + + public float getAlpha() + { + return this.particleAlpha; + } + + /** + * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to + * prevent them from trampling crops + */ + protected boolean canTriggerWalking() + { + return false; + } + + protected void entityInit() + { + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + + if (this.particleAge++ >= this.particleMaxAge) + { + this.setDead(); + } + + this.motionY -= 0.04D * (double)this.particleGravity; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.9800000190734863D; + this.motionY *= 0.9800000190734863D; + this.motionZ *= 0.9800000190734863D; + + if (this.onGround) + { + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + float f = (float)this.particleTextureIndexX / 16.0F; + float f1 = f + 0.0624375F; + float f2 = (float)this.particleTextureIndexY / 16.0F; + float f3 = f2 + 0.0624375F; + float f4 = 0.1F * this.particleScale; + + if (this.particleIcon != null) + { + f = this.particleIcon.getMinU(); + f1 = this.particleIcon.getMaxU(); + f2 = this.particleIcon.getMinV(); + f3 = this.particleIcon.getMaxV(); + } + + float f5 = (float)(this.prevX + (this.posX - this.prevX) * (double)partialTicks - interpPosX); + float f6 = (float)(this.prevY + (this.posY - this.prevY) * (double)partialTicks - interpPosY); + float f7 = (float)(this.prevZ + (this.posZ - this.prevZ) * (double)partialTicks - interpPosZ); + int i = this.getBrightnessForRender(partialTicks); + int j = i >> 16 & 65535; + int k = i & 65535; + worldRendererIn.pos((double)(f5 - rotationX * f4 - rotationXY * f4), (double)(f6 - rotationZ * f4), (double)(f7 - rotationYZ * f4 - rotationXZ * f4)).tex((double)f1, (double)f3).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex(); + worldRendererIn.pos((double)(f5 - rotationX * f4 + rotationXY * f4), (double)(f6 + rotationZ * f4), (double)(f7 - rotationYZ * f4 + rotationXZ * f4)).tex((double)f1, (double)f2).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex(); + worldRendererIn.pos((double)(f5 + rotationX * f4 + rotationXY * f4), (double)(f6 + rotationZ * f4), (double)(f7 + rotationYZ * f4 + rotationXZ * f4)).tex((double)f, (double)f2).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex(); + worldRendererIn.pos((double)(f5 + rotationX * f4 - rotationXY * f4), (double)(f6 - rotationZ * f4), (double)(f7 + rotationYZ * f4 - rotationXZ * f4)).tex((double)f, (double)f3).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex(); + } + + public int getFXLayer() + { + return 0; + } + + /** + * (abstract) Protected helper method to write subclass entity data to NBT. + */ + public void writeEntityToNBT(NBTTagCompound tagCompound) + { + } + + /** + * (abstract) Protected helper method to read subclass entity data from NBT. + */ + public void readEntityFromNBT(NBTTagCompound tagCompund) + { + } + + /** + * Sets the particle's icon. + */ + public void setParticleIcon(TextureAtlasSprite icon) + { + int i = this.getFXLayer(); + + if (i == 1) + { + this.particleIcon = icon; + } + else + { + throw new RuntimeException("Invalid call to Particle.setTex, use coordinate methods"); + } + } + + /** + * Public method to set private field particleTextureIndex. + */ + public void setParticleTextureIndex(int particleTextureIndex) + { + if (this.getFXLayer() != 0) + { + throw new RuntimeException("Invalid call to Particle.setMiscTex"); + } + else + { + this.particleTextureIndexX = particleTextureIndex % 16; + this.particleTextureIndexY = particleTextureIndex / 16; + } + } + + public void nextTextureIndexX() + { + ++this.particleTextureIndexX; + } + + /** + * If returns false, the item will not inflict any damage against entities. + */ + public boolean canAttackWithItem() + { + return false; + } + +// public String toString() +// { +// return this.getClass().getSimpleName() + ", Pos (" + this.posX + "," + this.posY + "," + this.posZ + "), RGBA (" + this.particleRed + "," + this.particleGreen + "," + this.particleBlue + "," + this.particleAlpha + "), Age " + this.particleAge; +// } + + public int getTrackingRange() { + return 0; + } + + public int getUpdateFrequency() { + return 0; + } + + public boolean isSendingVeloUpdates() { + return false; + } + + public EntityType getType() { + return EntityType.OBJECT; + } +} diff --git a/client/src/client/renderer/particle/EntityFirework.java b/client/src/client/renderer/particle/EntityFirework.java new file mode 100755 index 00000000..b3f3072b --- /dev/null +++ b/client/src/client/renderer/particle/EntityFirework.java @@ -0,0 +1,443 @@ +package client.renderer.particle; + +import client.Client; +import client.renderer.RenderBuffer; +import client.world.WorldClient; +import common.entity.Entity; +import common.init.SoundEvent; +import common.item.ItemDye; +import common.nbt.NBTTagCompound; +import common.nbt.NBTTagList; +import common.util.BoundingBox; +import common.util.ExtMath; +import common.world.World; + +public class EntityFirework +{ + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + EntityFirework.SparkFX entityfirework$sparkfx = new EntityFirework.SparkFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn, Client.CLIENT.effectRenderer); + entityfirework$sparkfx.setAlphaF(0.99F); + return entityfirework$sparkfx; + } + } + + public static class OverlayFX extends EntityFX + { + protected OverlayFX(World p_i46466_1_, double p_i46466_2_, double p_i46466_4_, double p_i46466_6_) + { + super(p_i46466_1_, p_i46466_2_, p_i46466_4_, p_i46466_6_); + this.particleMaxAge = 4; + } + + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + float f = 0.25F; + float f1 = 0.5F; + float f2 = 0.125F; + float f3 = 0.375F; + float f4 = 7.1F * ExtMath.sin(((float)this.particleAge + partialTicks - 1.0F) * 0.25F * (float)Math.PI); + this.particleAlpha = 0.6F - ((float)this.particleAge + partialTicks - 1.0F) * 0.25F * 0.5F; + float f5 = (float)(this.prevX + (this.posX - this.prevX) * (double)partialTicks - interpPosX); + float f6 = (float)(this.prevY + (this.posY - this.prevY) * (double)partialTicks - interpPosY); + float f7 = (float)(this.prevZ + (this.posZ - this.prevZ) * (double)partialTicks - interpPosZ); + int i = this.getBrightnessForRender(partialTicks); + int j = i >> 16 & 65535; + int k = i & 65535; + worldRendererIn.pos((double)(f5 - rotationX * f4 - rotationXY * f4), (double)(f6 - rotationZ * f4), (double)(f7 - rotationYZ * f4 - rotationXZ * f4)).tex(0.5D, 0.375D).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex(); + worldRendererIn.pos((double)(f5 - rotationX * f4 + rotationXY * f4), (double)(f6 + rotationZ * f4), (double)(f7 - rotationYZ * f4 + rotationXZ * f4)).tex(0.5D, 0.125D).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex(); + worldRendererIn.pos((double)(f5 + rotationX * f4 + rotationXY * f4), (double)(f6 + rotationZ * f4), (double)(f7 + rotationYZ * f4 + rotationXZ * f4)).tex(0.25D, 0.125D).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex(); + worldRendererIn.pos((double)(f5 + rotationX * f4 - rotationXY * f4), (double)(f6 - rotationZ * f4), (double)(f7 + rotationYZ * f4 - rotationXZ * f4)).tex(0.25D, 0.375D).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex(); + } + } + + public static class SparkFX extends EntityFX + { + private int baseTextureIndex = 160; + private boolean trail; + private boolean twinkle; + private final EffectRenderer field_92047_az; + private float fadeColourRed; + private float fadeColourGreen; + private float fadeColourBlue; + private boolean hasFadeColour; + + public SparkFX(World p_i46465_1_, double p_i46465_2_, double p_i46465_4_, double p_i46465_6_, double p_i46465_8_, double p_i46465_10_, double p_i46465_12_, EffectRenderer p_i46465_14_) + { + super(p_i46465_1_, p_i46465_2_, p_i46465_4_, p_i46465_6_); + this.motionX = p_i46465_8_; + this.motionY = p_i46465_10_; + this.motionZ = p_i46465_12_; + this.field_92047_az = p_i46465_14_; + this.particleScale *= 0.75F; + this.particleMaxAge = 48 + this.rand.zrange(12); + this.noClip = false; + } + + public void setTrail(boolean trailIn) + { + this.trail = trailIn; + } + + public void setTwinkle(boolean twinkleIn) + { + this.twinkle = twinkleIn; + } + + public void setColour(int colour) + { + float f = (float)((colour & 16711680) >> 16) / 255.0F; + float f1 = (float)((colour & 65280) >> 8) / 255.0F; + float f2 = (float)((colour & 255) >> 0) / 255.0F; + float f3 = 1.0F; + this.setRBGColorF(f * f3, f1 * f3, f2 * f3); + } + + public void setFadeColour(int faceColour) + { + this.fadeColourRed = (float)((faceColour & 16711680) >> 16) / 255.0F; + this.fadeColourGreen = (float)((faceColour & 65280) >> 8) / 255.0F; + this.fadeColourBlue = (float)((faceColour & 255) >> 0) / 255.0F; + this.hasFadeColour = true; + } + + public BoundingBox getCollisionBoundingBox() + { + return null; + } + + public boolean canBePushed() + { + return false; + } + + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + if (!this.twinkle || this.particleAge < this.particleMaxAge / 3 || (this.particleAge + this.particleMaxAge) / 3 % 2 == 0) + { + super.renderParticle(worldRendererIn, entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ); + } + } + + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + + if (this.particleAge++ >= this.particleMaxAge) + { + this.setDead(); + } + + if (this.particleAge > this.particleMaxAge / 2) + { + this.setAlphaF(1.0F - ((float)this.particleAge - (float)(this.particleMaxAge / 2)) / (float)this.particleMaxAge); + + if (this.hasFadeColour) + { + this.particleRed += (this.fadeColourRed - this.particleRed) * 0.2F; + this.particleGreen += (this.fadeColourGreen - this.particleGreen) * 0.2F; + this.particleBlue += (this.fadeColourBlue - this.particleBlue) * 0.2F; + } + } + + this.setParticleTextureIndex(this.baseTextureIndex + (7 - this.particleAge * 8 / this.particleMaxAge)); + this.motionY -= 0.004D; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.9100000262260437D; + this.motionY *= 0.9100000262260437D; + this.motionZ *= 0.9100000262260437D; + + if (this.onGround) + { + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } + + if (this.trail && this.particleAge < this.particleMaxAge / 2 && (this.particleAge + this.particleMaxAge) % 2 == 0) + { + EntityFirework.SparkFX entityfirework$sparkfx = new EntityFirework.SparkFX(this.worldObj, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, this.field_92047_az); + entityfirework$sparkfx.setAlphaF(0.99F); + entityfirework$sparkfx.setRBGColorF(this.particleRed, this.particleGreen, this.particleBlue); + entityfirework$sparkfx.particleAge = entityfirework$sparkfx.particleMaxAge / 2; + + if (this.hasFadeColour) + { + entityfirework$sparkfx.hasFadeColour = true; + entityfirework$sparkfx.fadeColourRed = this.fadeColourRed; + entityfirework$sparkfx.fadeColourGreen = this.fadeColourGreen; + entityfirework$sparkfx.fadeColourBlue = this.fadeColourBlue; + } + + entityfirework$sparkfx.twinkle = this.twinkle; + this.field_92047_az.addEffect(entityfirework$sparkfx); + } + } + + public int getBrightnessForRender(float partialTicks) + { + return 15728880; + } + + public float getBrightness(float partialTicks) + { + return 1.0F; + } + } + + public static class StarterFX extends EntityFX + { + private int fireworkAge; + private final EffectRenderer theEffectRenderer; + private NBTTagList fireworkExplosions; + boolean twinkle; + + public StarterFX(World p_i46464_1_, double p_i46464_2_, double p_i46464_4_, double p_i46464_6_, double p_i46464_8_, double p_i46464_10_, double p_i46464_12_, EffectRenderer p_i46464_14_, NBTTagCompound p_i46464_15_) + { + super(p_i46464_1_, p_i46464_2_, p_i46464_4_, p_i46464_6_, 0.0D, 0.0D, 0.0D); + this.motionX = p_i46464_8_; + this.motionY = p_i46464_10_; + this.motionZ = p_i46464_12_; + this.theEffectRenderer = p_i46464_14_; + this.particleMaxAge = 8; + + if (p_i46464_15_ != null) + { + this.fireworkExplosions = p_i46464_15_.getTagList("Explosions", 10); + + if (this.fireworkExplosions.tagCount() == 0) + { + this.fireworkExplosions = null; + } + else + { + this.particleMaxAge = this.fireworkExplosions.tagCount() * 2 - 1; + + for (int i = 0; i < this.fireworkExplosions.tagCount(); ++i) + { + NBTTagCompound nbttagcompound = this.fireworkExplosions.getCompoundTagAt(i); + + if (nbttagcompound.getBoolean("Flicker")) + { + this.twinkle = true; + this.particleMaxAge += 15; + break; + } + } + } + } + } + + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + } + + public void onUpdate() + { + if (this.fireworkAge == 0 && this.fireworkExplosions != null) + { + boolean flag = this.isFarAway(); + boolean flag1 = false; + + if (this.fireworkExplosions.tagCount() >= 3) + { + flag1 = true; + } + else + { + for (int i = 0; i < this.fireworkExplosions.tagCount(); ++i) + { + NBTTagCompound nbttagcompound = this.fireworkExplosions.getCompoundTagAt(i); + + if (nbttagcompound.getByte("Type") == 1) + { + flag1 = true; + break; + } + } + } + + SoundEvent s1 = flag1 ? (flag ? SoundEvent.BLAST_LARGE_FAR : SoundEvent.BLAST_LARGE) : + (flag ? SoundEvent.BLAST_SMALL_FAR : SoundEvent.BLAST_SMALL); + ((WorldClient)this.worldObj).playSound(this.posX, this.posY, this.posZ, s1, 20.0F); + } + + if (this.fireworkAge % 2 == 0 && this.fireworkExplosions != null && this.fireworkAge / 2 < this.fireworkExplosions.tagCount()) + { + int k = this.fireworkAge / 2; + NBTTagCompound nbttagcompound1 = this.fireworkExplosions.getCompoundTagAt(k); + int l = nbttagcompound1.getByte("Type"); + boolean flag4 = nbttagcompound1.getBoolean("Trail"); + boolean flag2 = nbttagcompound1.getBoolean("Flicker"); + int[] aint = nbttagcompound1.getIntArray("Colors"); + int[] aint1 = nbttagcompound1.getIntArray("FadeColors"); + + if (aint.length == 0) + { + aint = new int[] {ItemDye.dyeColors[0]}; + } + + if (l == 1) + { + this.createBall(0.5D, 4, aint, aint1, flag4, flag2); + } + else if (l == 2) + { + this.createShaped(0.5D, new double[][] { + {0.0D, 1.0D}, {0.3455D, 0.309D}, {0.9511D, 0.309D}, {0.3795918367346939D, -0.12653061224489795D}, + {0.6122448979591837D, -0.8040816326530612D}, {0.0D, -0.35918367346938773D} + }, aint, aint1, flag4, flag2, false, 4); + } + else if (l == 3) + { + this.createShaped(0.5D, new double[][] { + {0.187 - 0.5, 1.0 - 0.016}, {1.0 - 0.5, 1.0 - 0.625}, {0.0 - 0.5, 1.0 - 0.625}, + {0.812 - 0.5, 1.0 - 0.016}, {0.5 - 0.5, 1.0 - 1.0}, {0.187 - 0.5, 1.0 - 0.016} + }, aint, aint1, flag4, flag2, true, 8); + } + else if (l == 4) + { + this.createBurst(aint, aint1, flag4, flag2); + } + else + { + this.createBall(0.25D, 2, aint, aint1, flag4, flag2); + } + + int j = aint[0]; + float f = (float)((j & 16711680) >> 16) / 255.0F; + float f1 = (float)((j & 65280) >> 8) / 255.0F; + float f2 = (float)((j & 255) >> 0) / 255.0F; + EntityFirework.OverlayFX entityfirework$overlayfx = new EntityFirework.OverlayFX(this.worldObj, this.posX, this.posY, this.posZ); + entityfirework$overlayfx.setRBGColorF(f, f1, f2); + this.theEffectRenderer.addEffect(entityfirework$overlayfx); + } + + ++this.fireworkAge; + + if (this.fireworkAge > this.particleMaxAge) + { + if (this.twinkle) + { + boolean flag3 = this.isFarAway(); + SoundEvent s = flag3 ? SoundEvent.TWINKLE_FAR : SoundEvent.TWINKLE; + ((WorldClient)this.worldObj).playSound(this.posX, this.posY, this.posZ, s, 20.0F); + } + + this.setDead(); + } + } + + private boolean isFarAway() + { + Client gm = Client.CLIENT; + return gm == null || gm.getRenderViewEntity() == null || gm.getRenderViewEntity().getDistanceSq(this.posX, this.posY, this.posZ) >= 256.0D; + } + + private void createParticle(double p_92034_1_, double p_92034_3_, double p_92034_5_, double p_92034_7_, double p_92034_9_, double p_92034_11_, int[] p_92034_13_, int[] p_92034_14_, boolean p_92034_15_, boolean p_92034_16_) + { + EntityFirework.SparkFX entityfirework$sparkfx = new EntityFirework.SparkFX(this.worldObj, p_92034_1_, p_92034_3_, p_92034_5_, p_92034_7_, p_92034_9_, p_92034_11_, this.theEffectRenderer); + entityfirework$sparkfx.setAlphaF(0.99F); + entityfirework$sparkfx.setTrail(p_92034_15_); + entityfirework$sparkfx.setTwinkle(p_92034_16_); + int i = this.rand.zrange(p_92034_13_.length); + entityfirework$sparkfx.setColour(p_92034_13_[i]); + + if (p_92034_14_ != null && p_92034_14_.length > 0) + { + entityfirework$sparkfx.setFadeColour(p_92034_14_[this.rand.zrange(p_92034_14_.length)]); + } + + this.theEffectRenderer.addEffect(entityfirework$sparkfx); + } + + private void createBall(double speed, int size, int[] colours, int[] fadeColours, boolean trail, boolean twinkleIn) + { + double d0 = this.posX; + double d1 = this.posY; + double d2 = this.posZ; + + for (int i = -size; i <= size; ++i) + { + for (int j = -size; j <= size; ++j) + { + for (int k = -size; k <= size; ++k) + { + double d3 = (double)j + (this.rand.doublev() - this.rand.doublev()) * 0.5D; + double d4 = (double)i + (this.rand.doublev() - this.rand.doublev()) * 0.5D; + double d5 = (double)k + (this.rand.doublev() - this.rand.doublev()) * 0.5D; + double d6 = (double)ExtMath.sqrtd(d3 * d3 + d4 * d4 + d5 * d5) / speed + this.rand.gaussian() * 0.05D; + this.createParticle(d0, d1, d2, d3 / d6, d4 / d6, d5 / d6, colours, fadeColours, trail, twinkleIn); + + if (i != -size && i != size && j != -size && j != size) + { + k += size * 2 - 1; + } + } + } + } + } + + private void createShaped(double speed, double[][] shape, int[] colours, int[] fadeColours, boolean trail, boolean twinkleIn, + boolean p_92038_8_, int div) + { + double d0 = shape[0][0]; + double d1 = shape[0][1]; + this.createParticle(this.posX, this.posY, this.posZ, d0 * speed, d1 * speed, 0.0D, colours, fadeColours, trail, twinkleIn); + float f = this.rand.floatv() * (float)Math.PI; + double d2 = p_92038_8_ ? 0.034D : 0.34D; + double shift = 1.0 / (double)div; + + for (int i = 0; i < 3; ++i) + { + double d3 = (double)f + (double)((float)i * (float)Math.PI) * d2; + double d4 = d0; + double d5 = d1; + + for (int j = 1; j < shape.length; ++j) + { + double d6 = shape[j][0]; + double d7 = shape[j][1]; + + for (double d8 = shift; d8 <= 1.0D; d8 += shift) + { + double d9 = (d4 + (d6 - d4) * d8) * speed; + double d10 = (d5 + (d7 - d5) * d8) * speed; + double d11 = d9 * Math.sin(d3); + d9 = d9 * Math.cos(d3); + + for (double d12 = -1.0D; d12 <= 1.0D; d12 += 2.0D) + { + this.createParticle(this.posX, this.posY, this.posZ, d9 * d12, d10, d11 * d12, colours, fadeColours, trail, twinkleIn); + } + } + + d4 = d6; + d5 = d7; + } + } + } + + private void createBurst(int[] colours, int[] fadeColours, boolean trail, boolean twinkleIn) + { + double d0 = this.rand.gaussian() * 0.05D; + double d1 = this.rand.gaussian() * 0.05D; + + for (int i = 0; i < 70; ++i) + { + double d2 = this.motionX * 0.5D + this.rand.gaussian() * 0.15D + d0; + double d3 = this.motionZ * 0.5D + this.rand.gaussian() * 0.15D + d1; + double d4 = this.motionY * 0.5D + this.rand.doublev() * 0.5D; + this.createParticle(this.posX, this.posY, this.posZ, d2, d4, d3, colours, fadeColours, trail, twinkleIn); + } + } + + public int getFXLayer() + { + return 0; + } + } +} diff --git a/client/src/client/renderer/particle/EntityFishWakeFX.java b/client/src/client/renderer/particle/EntityFishWakeFX.java new file mode 100755 index 00000000..c120d5e7 --- /dev/null +++ b/client/src/client/renderer/particle/EntityFishWakeFX.java @@ -0,0 +1,56 @@ +package client.renderer.particle; + +import common.world.World; + +public class EntityFishWakeFX extends EntityFX +{ + protected EntityFishWakeFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double p_i45073_8_, double p_i45073_10_, double p_i45073_12_) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, 0.0D, 0.0D, 0.0D); + this.motionX *= 0.30000001192092896D; + this.motionY = Math.random() * 0.20000000298023224D + 0.10000000149011612D; + this.motionZ *= 0.30000001192092896D; + this.particleRed = 1.0F; + this.particleGreen = 1.0F; + this.particleBlue = 1.0F; + this.setParticleTextureIndex(19); + this.setSize(0.01F, 0.01F); + this.particleMaxAge = (int)(8.0D / (Math.random() * 0.8D + 0.2D)); + this.particleGravity = 0.0F; + this.motionX = p_i45073_8_; + this.motionY = p_i45073_10_; + this.motionZ = p_i45073_12_; + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + this.motionY -= (double)this.particleGravity; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.9800000190734863D; + this.motionY *= 0.9800000190734863D; + this.motionZ *= 0.9800000190734863D; + int i = 60 - this.particleMaxAge; + float f = (float)i * 0.001F; + this.setSize(f, f); + this.setParticleTextureIndex(19 + i % 4); + + if (this.particleMaxAge-- <= 0) + { + this.setDead(); + } + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityFishWakeFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntityFlameFX.java b/client/src/client/renderer/particle/EntityFlameFX.java new file mode 100755 index 00000000..462370d2 --- /dev/null +++ b/client/src/client/renderer/particle/EntityFlameFX.java @@ -0,0 +1,100 @@ +package client.renderer.particle; + +import client.renderer.RenderBuffer; +import common.entity.Entity; +import common.util.ExtMath; +import common.world.World; + +public class EntityFlameFX extends EntityFX +{ + /** the scale of the flame FX */ + private float flameScale; + + protected EntityFlameFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + this.motionX = this.motionX * 0.009999999776482582D + xSpeedIn; + this.motionY = this.motionY * 0.009999999776482582D + ySpeedIn; + this.motionZ = this.motionZ * 0.009999999776482582D + zSpeedIn; + this.posX += (double)((this.rand.floatv() - this.rand.floatv()) * 0.05F); + this.posY += (double)((this.rand.floatv() - this.rand.floatv()) * 0.05F); + this.posZ += (double)((this.rand.floatv() - this.rand.floatv()) * 0.05F); + this.flameScale = this.particleScale; + this.particleRed = this.particleGreen = this.particleBlue = 1.0F; + this.particleMaxAge = (int)(8.0D / (Math.random() * 0.8D + 0.2D)) + 4; + this.noClip = true; + this.setParticleTextureIndex(48); + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge; + this.particleScale = this.flameScale * (1.0F - f * f * 0.5F); + super.renderParticle(worldRendererIn, entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ); + } + + public int getBrightnessForRender(float partialTicks) + { + float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge; + f = ExtMath.clampf(f, 0.0F, 1.0F); + int i = super.getBrightnessForRender(partialTicks); + int j = i & 255; + int k = i >> 16 & 255; + j = j + (int)(f * 15.0F * 16.0F); + + if (j > 240) + { + j = 240; + } + + return j | k << 16; + } + + /** + * Gets how bright this entity is. + */ + public float getBrightness(float partialTicks) + { + float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge; + f = ExtMath.clampf(f, 0.0F, 1.0F); + float f1 = super.getBrightness(partialTicks); + return f1 * f + (1.0F - f); + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + + if (this.particleAge++ >= this.particleMaxAge) + { + this.setDead(); + } + + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.9599999785423279D; + this.motionY *= 0.9599999785423279D; + this.motionZ *= 0.9599999785423279D; + + if (this.onGround) + { + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityFlameFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntityFootStepFX.java b/client/src/client/renderer/particle/EntityFootStepFX.java new file mode 100755 index 00000000..2bad9a19 --- /dev/null +++ b/client/src/client/renderer/particle/EntityFootStepFX.java @@ -0,0 +1,94 @@ +package client.renderer.particle; + +import org.lwjgl.opengl.GL11; + +import client.Client; +import client.renderer.DefaultVertexFormats; +import client.renderer.GlState; +import client.renderer.RenderBuffer; +import client.renderer.Tessellator; +import client.renderer.texture.TextureManager; +import common.entity.Entity; +import common.util.BlockPos; +import common.world.World; + +public class EntityFootStepFX extends EntityFX +{ + private int footstepAge; + private int footstepMaxAge; + private TextureManager currentFootSteps; + + protected EntityFootStepFX(TextureManager currentFootStepsIn, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, 0.0D, 0.0D, 0.0D); + this.currentFootSteps = currentFootStepsIn; + this.motionX = this.motionY = this.motionZ = 0.0D; + this.footstepMaxAge = 200; + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + double u = 2.0F / 16.0F; + double u1 = u + 0.0624375F; + double u2 = 6.0F / 16.0F; + double u3 = u2 + 0.0624375F; + + float f = ((float)this.footstepAge + partialTicks) / (float)this.footstepMaxAge; + f = f * f; + float f1 = 2.0F - f * 2.0F; + + if (f1 > 1.0F) + { + f1 = 1.0F; + } + + f1 = f1 * 0.2F; + GlState.disableLighting(); + float f2 = 0.125F; + float f3 = (float)(this.posX - interpPosX); + float f4 = (float)(this.posY - interpPosY); + float f5 = (float)(this.posZ - interpPosZ); + float f6 = this.worldObj.getLightBrightness(new BlockPos(this)); + this.currentFootSteps.bindTexture(EffectRenderer.particleTextures); + GlState.enableBlend(); + GlState.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + worldRendererIn.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + worldRendererIn.pos((double)(f3 - 0.125F), (double)f4, (double)(f5 + 0.125F)).tex(u1, u3).color(f6, f6, f6, f1).endVertex(); + worldRendererIn.pos((double)(f3 + 0.125F), (double)f4, (double)(f5 + 0.125F)).tex(u1, u2).color(f6, f6, f6, f1).endVertex(); + worldRendererIn.pos((double)(f3 + 0.125F), (double)f4, (double)(f5 - 0.125F)).tex(u, u2).color(f6, f6, f6, f1).endVertex(); + worldRendererIn.pos((double)(f3 - 0.125F), (double)f4, (double)(f5 - 0.125F)).tex(u, u3).color(f6, f6, f6, f1).endVertex(); +// Tessellator.getInstance(); + Tessellator.draw(); + GlState.disableBlend(); + GlState.enableLighting(); + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + ++this.footstepAge; + + if (this.footstepAge == this.footstepMaxAge) + { + this.setDead(); + } + } + + public int getFXLayer() + { + return 3; + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityFootStepFX(Client.CLIENT.getTextureManager(), worldIn, xCoordIn, yCoordIn, zCoordIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntityHeartFX.java b/client/src/client/renderer/particle/EntityHeartFX.java new file mode 100755 index 00000000..f048950f --- /dev/null +++ b/client/src/client/renderer/particle/EntityHeartFX.java @@ -0,0 +1,94 @@ +package client.renderer.particle; + +import client.renderer.RenderBuffer; +import common.entity.Entity; +import common.util.ExtMath; +import common.world.World; + +public class EntityHeartFX extends EntityFX +{ + float particleScaleOverTime; + + protected EntityHeartFX(World worldIn, double p_i1211_2_, double p_i1211_4_, double p_i1211_6_, double p_i1211_8_, double p_i1211_10_, double p_i1211_12_) + { + this(worldIn, p_i1211_2_, p_i1211_4_, p_i1211_6_, p_i1211_8_, p_i1211_10_, p_i1211_12_, 2.0F); + } + + protected EntityHeartFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double p_i46354_8_, double p_i46354_10_, double p_i46354_12_, float scale) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, 0.0D, 0.0D, 0.0D); + this.motionX *= 0.009999999776482582D; + this.motionY *= 0.009999999776482582D; + this.motionZ *= 0.009999999776482582D; + this.motionY += 0.1D; + this.particleScale *= 0.75F; + this.particleScale *= scale; + this.particleScaleOverTime = this.particleScale; + this.particleMaxAge = 16; + this.noClip = false; + this.setParticleTextureIndex(80); + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge * 32.0F; + f = ExtMath.clampf(f, 0.0F, 1.0F); + this.particleScale = this.particleScaleOverTime * f; + super.renderParticle(worldRendererIn, entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ); + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + + if (this.particleAge++ >= this.particleMaxAge) + { + this.setDead(); + } + + this.moveEntity(this.motionX, this.motionY, this.motionZ); + + if (this.posY == this.prevY) + { + this.motionX *= 1.1D; + this.motionZ *= 1.1D; + } + + this.motionX *= 0.8600000143051147D; + this.motionY *= 0.8600000143051147D; + this.motionZ *= 0.8600000143051147D; + + if (this.onGround) + { + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } + } + +// public static class AngryVillagerFactory implements IParticleFactory +// { +// public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) +// { +// EntityFX entityfx = new EntityHeartFX(worldIn, xCoordIn, yCoordIn + 0.5D, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); +// entityfx.setParticleTextureIndex(81); +// entityfx.setRBGColorF(1.0F, 1.0F, 1.0F); +// return entityfx; +// } +// } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityHeartFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntityHugeExplodeFX.java b/client/src/client/renderer/particle/EntityHugeExplodeFX.java new file mode 100755 index 00000000..7f287b9a --- /dev/null +++ b/client/src/client/renderer/particle/EntityHugeExplodeFX.java @@ -0,0 +1,60 @@ +package client.renderer.particle; + +import client.renderer.RenderBuffer; +import common.entity.Entity; +import common.model.ParticleType; +import common.world.World; + +public class EntityHugeExplodeFX extends EntityFX +{ + private int timeSinceStart; + + /** the maximum time for the explosion */ + private int maximumTime = 8; + + protected EntityHugeExplodeFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double p_i1214_8_, double p_i1214_10_, double p_i1214_12_) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, 0.0D, 0.0D, 0.0D); + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + for (int i = 0; i < 6; ++i) + { + double d0 = this.posX + (this.rand.doublev() - this.rand.doublev()) * 4.0D; + double d1 = this.posY + (this.rand.doublev() - this.rand.doublev()) * 4.0D; + double d2 = this.posZ + (this.rand.doublev() - this.rand.doublev()) * 4.0D; + this.worldObj.spawnParticle(ParticleType.EXPLOSION_LARGE, d0, d1, d2, (double)((float)this.timeSinceStart / (float)this.maximumTime), 0.0D, 0.0D); + } + + ++this.timeSinceStart; + + if (this.timeSinceStart == this.maximumTime) + { + this.setDead(); + } + } + + public int getFXLayer() + { + return 1; + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityHugeExplodeFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntityLargeExplodeFX.java b/client/src/client/renderer/particle/EntityLargeExplodeFX.java new file mode 100755 index 00000000..9dfe3875 --- /dev/null +++ b/client/src/client/renderer/particle/EntityLargeExplodeFX.java @@ -0,0 +1,101 @@ +package client.renderer.particle; + +import org.lwjgl.opengl.GL11; + +import client.Client; +import client.renderer.DefaultVertexFormats; +import client.renderer.GlState; +import client.renderer.ItemRenderer; +import client.renderer.RenderBuffer; +import client.renderer.Tessellator; +import client.renderer.VertexFormat; +import client.renderer.texture.TextureManager; +import common.entity.Entity; +import common.world.World; + +public class EntityLargeExplodeFX extends EntityFX +{ + private static final String EXPLOSION_TEXTURE = "textures/entity/explosion.png"; + private static final VertexFormat VERTEX_FORMAT = (new VertexFormat()).addElement(DefaultVertexFormats.POSITION_3F).addElement(DefaultVertexFormats.TEX_2F).addElement(DefaultVertexFormats.COLOR_4UB).addElement(DefaultVertexFormats.TEX_2S).addElement(DefaultVertexFormats.NORMAL_3B).addElement(DefaultVertexFormats.PADDING_1B); + private int field_70581_a; + private int field_70584_aq; + + /** The Rendering Engine. */ + private TextureManager theRenderEngine; + private float field_70582_as; + + protected EntityLargeExplodeFX(TextureManager renderEngine, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double p_i1213_9_, double p_i1213_11_, double p_i1213_13_) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, 0.0D, 0.0D, 0.0D); + this.theRenderEngine = renderEngine; + this.field_70584_aq = 6 + this.rand.zrange(4); + this.particleRed = this.particleGreen = this.particleBlue = this.rand.floatv() * 0.6F + 0.4F; + this.field_70582_as = 1.0F - (float)p_i1213_9_ * 0.5F; + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + int i = (int)(((float)this.field_70581_a + partialTicks) * 15.0F / (float)this.field_70584_aq); + + if (i <= 15) + { + this.theRenderEngine.bindTexture(EXPLOSION_TEXTURE); + float f = (float)(i % 4) / 4.0F; + float f1 = f + 0.24975F; + float f2 = (float)(i / 4) / 4.0F; + float f3 = f2 + 0.24975F; + float f4 = 2.0F * this.field_70582_as; + float f5 = (float)(this.prevX + (this.posX - this.prevX) * (double)partialTicks - interpPosX); + float f6 = (float)(this.prevY + (this.posY - this.prevY) * (double)partialTicks - interpPosY); + float f7 = (float)(this.prevZ + (this.posZ - this.prevZ) * (double)partialTicks - interpPosZ); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + GlState.disableLighting(); + ItemRenderer.disableStandardItemLighting(); + worldRendererIn.begin(GL11.GL_QUADS, VERTEX_FORMAT); + worldRendererIn.pos((double)(f5 - rotationX * f4 - rotationXY * f4), (double)(f6 - rotationZ * f4), (double)(f7 - rotationYZ * f4 - rotationXZ * f4)).tex((double)f1, (double)f3).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(0, 240).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldRendererIn.pos((double)(f5 - rotationX * f4 + rotationXY * f4), (double)(f6 + rotationZ * f4), (double)(f7 - rotationYZ * f4 + rotationXZ * f4)).tex((double)f1, (double)f2).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(0, 240).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldRendererIn.pos((double)(f5 + rotationX * f4 + rotationXY * f4), (double)(f6 + rotationZ * f4), (double)(f7 + rotationYZ * f4 + rotationXZ * f4)).tex((double)f, (double)f2).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(0, 240).normal(0.0F, 1.0F, 0.0F).endVertex(); + worldRendererIn.pos((double)(f5 + rotationX * f4 - rotationXY * f4), (double)(f6 - rotationZ * f4), (double)(f7 + rotationYZ * f4 - rotationXZ * f4)).tex((double)f, (double)f3).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(0, 240).normal(0.0F, 1.0F, 0.0F).endVertex(); +// Tessellator.getInstance(); + Tessellator.draw(); + GlState.enableLighting(); + } + } + + public int getBrightnessForRender(float partialTicks) + { + return 61680; + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + ++this.field_70581_a; + + if (this.field_70581_a == this.field_70584_aq) + { + this.setDead(); + } + } + + public int getFXLayer() + { + return 3; + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityLargeExplodeFX(Client.CLIENT.getTextureManager(), worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntityLavaFX.java b/client/src/client/renderer/particle/EntityLavaFX.java new file mode 100755 index 00000000..bd823f03 --- /dev/null +++ b/client/src/client/renderer/particle/EntityLavaFX.java @@ -0,0 +1,97 @@ +package client.renderer.particle; + +import client.renderer.RenderBuffer; +import common.entity.Entity; +import common.model.ParticleType; +import common.util.ExtMath; +import common.world.World; + +public class EntityLavaFX extends EntityFX +{ + private float lavaParticleScale; + + protected EntityLavaFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, 0.0D, 0.0D, 0.0D); + this.motionX *= 0.800000011920929D; + this.motionY *= 0.800000011920929D; + this.motionZ *= 0.800000011920929D; + this.motionY = (double)(this.rand.floatv() * 0.4F + 0.05F); + this.particleRed = this.particleGreen = this.particleBlue = 1.0F; + this.particleScale *= this.rand.floatv() * 2.0F + 0.2F; + this.lavaParticleScale = this.particleScale; + this.particleMaxAge = (int)(16.0D / (Math.random() * 0.8D + 0.2D)); + this.noClip = false; + this.setParticleTextureIndex(49); + } + + public int getBrightnessForRender(float partialTicks) + { + float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge; + f = ExtMath.clampf(f, 0.0F, 1.0F); + int i = super.getBrightnessForRender(partialTicks); + int j = 240; + int k = i >> 16 & 255; + return j | k << 16; + } + + /** + * Gets how bright this entity is. + */ + public float getBrightness(float partialTicks) + { + return 1.0F; + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge; + this.particleScale = this.lavaParticleScale * (1.0F - f * f); + super.renderParticle(worldRendererIn, entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ); + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + + if (this.particleAge++ >= this.particleMaxAge) + { + this.setDead(); + } + + float f = (float)this.particleAge / (float)this.particleMaxAge; + + if (this.rand.floatv() > f) + { + this.worldObj.spawnParticle(ParticleType.SMOKE_NORMAL, this.posX, this.posY, this.posZ, this.motionX, this.motionY, this.motionZ); + } + + this.motionY -= 0.03D; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.9990000128746033D; + this.motionY *= 0.9990000128746033D; + this.motionZ *= 0.9990000128746033D; + + if (this.onGround) + { + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityLavaFX(worldIn, xCoordIn, yCoordIn, zCoordIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntityNoteFX.java b/client/src/client/renderer/particle/EntityNoteFX.java new file mode 100755 index 00000000..2bfa8501 --- /dev/null +++ b/client/src/client/renderer/particle/EntityNoteFX.java @@ -0,0 +1,86 @@ +package client.renderer.particle; + +import client.renderer.RenderBuffer; +import common.entity.Entity; +import common.util.ExtMath; +import common.world.World; + +public class EntityNoteFX extends EntityFX +{ + float noteParticleScale; + + protected EntityNoteFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double p_i46353_8_, double p_i46353_10_, double p_i46353_12_) + { + this(worldIn, xCoordIn, yCoordIn, zCoordIn, p_i46353_8_, p_i46353_10_, p_i46353_12_, 2.0F); + } + + protected EntityNoteFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double p_i1217_8_, double p_i1217_10_, double p_i1217_12_, float p_i1217_14_) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, 0.0D, 0.0D, 0.0D); + this.motionX *= 0.009999999776482582D; + this.motionY *= 0.009999999776482582D; + this.motionZ *= 0.009999999776482582D; + this.motionY += 0.2D; + this.particleRed = ExtMath.sin(((float)p_i1217_8_ + 0.0F) * (float)Math.PI * 2.0F) * 0.65F + 0.35F; + this.particleGreen = ExtMath.sin(((float)p_i1217_8_ + 0.33333334F) * (float)Math.PI * 2.0F) * 0.65F + 0.35F; + this.particleBlue = ExtMath.sin(((float)p_i1217_8_ + 0.6666667F) * (float)Math.PI * 2.0F) * 0.65F + 0.35F; + this.particleScale *= 0.75F; + this.particleScale *= p_i1217_14_; + this.noteParticleScale = this.particleScale; + this.particleMaxAge = 6; + this.noClip = false; + this.setParticleTextureIndex(64); + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge * 32.0F; + f = ExtMath.clampf(f, 0.0F, 1.0F); + this.particleScale = this.noteParticleScale * f; + super.renderParticle(worldRendererIn, entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ); + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + + if (this.particleAge++ >= this.particleMaxAge) + { + this.setDead(); + } + + this.moveEntity(this.motionX, this.motionY, this.motionZ); + + if (this.posY == this.prevY) + { + this.motionX *= 1.1D; + this.motionZ *= 1.1D; + } + + this.motionX *= 0.6600000262260437D; + this.motionY *= 0.6600000262260437D; + this.motionZ *= 0.6600000262260437D; + + if (this.onGround) + { + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityNoteFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntityParticleEmitter.java b/client/src/client/renderer/particle/EntityParticleEmitter.java new file mode 100755 index 00000000..42f18a8f --- /dev/null +++ b/client/src/client/renderer/particle/EntityParticleEmitter.java @@ -0,0 +1,67 @@ +package client.renderer.particle; + +import client.renderer.RenderBuffer; +import client.world.WorldClient; +import common.entity.Entity; +import common.model.ParticleType; +import common.world.World; + +public class EntityParticleEmitter extends EntityFX +{ + private Entity attachedEntity; + private int age; + private int lifetime; + private ParticleType particleTypes; + + public EntityParticleEmitter(World worldIn, Entity p_i46279_2_, ParticleType particleTypesIn) + { + super(worldIn, p_i46279_2_.posX, p_i46279_2_.getEntityBoundingBox().minY + (double)(p_i46279_2_.height / 2.0F), p_i46279_2_.posZ, p_i46279_2_.motionX, p_i46279_2_.motionY, p_i46279_2_.motionZ); + this.attachedEntity = p_i46279_2_; + this.lifetime = 3; + this.particleTypes = particleTypesIn; + this.onUpdate(); + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + for (int i = 0; i < 16; ++i) + { + double d0 = (double)(this.rand.floatv() * 2.0F - 1.0F); + double d1 = (double)(this.rand.floatv() * 2.0F - 1.0F); + double d2 = (double)(this.rand.floatv() * 2.0F - 1.0F); + + if (d0 * d0 + d1 * d1 + d2 * d2 <= 1.0D) + { + double d3 = this.attachedEntity.posX + d0 * (double)this.attachedEntity.width / 4.0D; + double d4 = this.attachedEntity.getEntityBoundingBox().minY + (double)(this.attachedEntity.height / 2.0F) + d1 * (double)this.attachedEntity.height / 4.0D; + double d5 = this.attachedEntity.posZ + d2 * (double)this.attachedEntity.width / 4.0D; + final double xCoord = d3; + final double yCoord = d4; + final double zCoord = d5; + ((WorldClient)this.worldObj).spawnEntityFX(this.particleTypes, this.particleTypes.getShouldIgnoreRange(), xCoord, yCoord, zCoord, d0, d1 + 0.2D, d2, new int[0]); + } + } + + ++this.age; + + if (this.age >= this.lifetime) + { + this.setDead(); + } + } + + public int getFXLayer() + { + return 3; + } +} diff --git a/client/src/client/renderer/particle/EntityPickupFX.java b/client/src/client/renderer/particle/EntityPickupFX.java new file mode 100755 index 00000000..67a4bd86 --- /dev/null +++ b/client/src/client/renderer/particle/EntityPickupFX.java @@ -0,0 +1,74 @@ +package client.renderer.particle; + +import org.lwjgl.opengl.GL13; + +import client.Client; +import client.renderer.GlState; +import client.renderer.RenderBuffer; +import client.renderer.entity.RenderManager; +import common.entity.Entity; +import common.world.World; + +public class EntityPickupFX extends EntityFX +{ + private Entity field_174840_a; + private Entity field_174843_ax; + private int age; + private int maxAge; + private float field_174841_aA; + private RenderManager field_174842_aB = Client.CLIENT.getRenderManager(); + + public EntityPickupFX(World worldIn, Entity p_i1233_2_, Entity p_i1233_3_, float p_i1233_4_) + { + super(worldIn, p_i1233_2_.posX, p_i1233_2_.posY, p_i1233_2_.posZ, p_i1233_2_.motionX, p_i1233_2_.motionY, p_i1233_2_.motionZ); + this.field_174840_a = p_i1233_2_; + this.field_174843_ax = p_i1233_3_; + this.maxAge = 3; + this.field_174841_aA = p_i1233_4_; + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + float f = ((float)this.age + partialTicks) / (float)this.maxAge; + f = f * f; + double d0 = this.field_174840_a.posX; + double d1 = this.field_174840_a.posY; + double d2 = this.field_174840_a.posZ; + double d3 = this.field_174843_ax.lastTickPosX + (this.field_174843_ax.posX - this.field_174843_ax.lastTickPosX) * (double)partialTicks; + double d4 = this.field_174843_ax.lastTickPosY + (this.field_174843_ax.posY - this.field_174843_ax.lastTickPosY) * (double)partialTicks + (double)this.field_174841_aA; + double d5 = this.field_174843_ax.lastTickPosZ + (this.field_174843_ax.posZ - this.field_174843_ax.lastTickPosZ) * (double)partialTicks; + double d6 = d0 + (d3 - d0) * (double)f; + double d7 = d1 + (d4 - d1) * (double)f; + double d8 = d2 + (d5 - d2) * (double)f; + int i = this.getBrightnessForRender(partialTicks); + int j = i % 65536; + int k = i / 65536; + GL13.glMultiTexCoord2f(GL13.GL_TEXTURE1, (float)j / 1.0F, (float)k / 1.0F); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + d6 = d6 - interpPosX; + d7 = d7 - interpPosY; + d8 = d8 - interpPosZ; + this.field_174842_aB.renderEntity(this.field_174840_a, (double)((float)d6), (double)((float)d7), (double)((float)d8), partialTicks); + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + ++this.age; + + if (this.age == this.maxAge) + { + this.setDead(); + } + } + + public int getFXLayer() + { + return 3; + } +} diff --git a/client/src/client/renderer/particle/EntityPortalFX.java b/client/src/client/renderer/particle/EntityPortalFX.java new file mode 100755 index 00000000..3c5dd594 --- /dev/null +++ b/client/src/client/renderer/particle/EntityPortalFX.java @@ -0,0 +1,104 @@ +package client.renderer.particle; + +import client.renderer.RenderBuffer; +import common.entity.Entity; +import common.world.World; + +public class EntityPortalFX extends EntityFX +{ + private float portalParticleScale; + private double portalPosX; + private double portalPosY; + private double portalPosZ; + + protected EntityPortalFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + this.motionX = xSpeedIn; + this.motionY = ySpeedIn; + this.motionZ = zSpeedIn; + this.portalPosX = this.posX = xCoordIn; + this.portalPosY = this.posY = yCoordIn; + this.portalPosZ = this.posZ = zCoordIn; + float f = this.rand.floatv() * 0.6F + 0.4F; + this.portalParticleScale = this.particleScale = this.rand.floatv() * 0.2F + 0.5F; + this.particleRed = this.particleGreen = this.particleBlue = 1.0F * f; + this.particleGreen *= 0.1F; + this.particleRed *= 0.2F; + this.particleBlue *= 0.25F; + this.particleMaxAge = (int)(Math.random() * 10.0D) + 40; + this.noClip = true; + this.setParticleTextureIndex((int)(Math.random() * 8.0D)); + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge; + f = 1.0F - f; + f = f * f; + f = 1.0F - f; + this.particleScale = this.portalParticleScale * f; + super.renderParticle(worldRendererIn, entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ); + } + + public int getBrightnessForRender(float partialTicks) + { + int i = super.getBrightnessForRender(partialTicks); + float f = (float)this.particleAge / (float)this.particleMaxAge; + f = f * f; + f = f * f; + int j = i & 255; + int k = i >> 16 & 255; + k = k + (int)(f * 15.0F * 16.0F); + + if (k > 240) + { + k = 240; + } + + return j | k << 16; + } + + /** + * Gets how bright this entity is. + */ + public float getBrightness(float partialTicks) + { + float f = super.getBrightness(partialTicks); + float f1 = (float)this.particleAge / (float)this.particleMaxAge; + f1 = f1 * f1 * f1 * f1; + return f * (1.0F - f1) + f1; + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + float f = (float)this.particleAge / (float)this.particleMaxAge; + f = -f + f * f * 2.0F; + f = 1.0F - f; + this.posX = this.portalPosX + this.motionX * (double)f; + this.posY = this.portalPosY + this.motionY * (double)f + (double)(1.0F - f); + this.posZ = this.portalPosZ + this.motionZ * (double)f; + + if (this.particleAge++ >= this.particleMaxAge) + { + this.setDead(); + } + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityPortalFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntityReddustFX.java b/client/src/client/renderer/particle/EntityReddustFX.java new file mode 100755 index 00000000..f89e164b --- /dev/null +++ b/client/src/client/renderer/particle/EntityReddustFX.java @@ -0,0 +1,93 @@ +package client.renderer.particle; + +import client.renderer.RenderBuffer; +import common.entity.Entity; +import common.util.ExtMath; +import common.world.World; + +public class EntityReddustFX extends EntityFX +{ + float reddustParticleScale; + + protected EntityReddustFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, float p_i46349_8_, float p_i46349_9_, float p_i46349_10_) + { + this(worldIn, xCoordIn, yCoordIn, zCoordIn, 1.0F, p_i46349_8_, p_i46349_9_, p_i46349_10_); + } + + protected EntityReddustFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, float p_i46350_8_, float p_i46350_9_, float p_i46350_10_, float p_i46350_11_) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, 0.0D, 0.0D, 0.0D); + this.motionX *= 0.10000000149011612D; + this.motionY *= 0.10000000149011612D; + this.motionZ *= 0.10000000149011612D; + + if (p_i46350_9_ == 0.0F) + { + p_i46350_9_ = 1.0F; + } + + float f = (float)Math.random() * 0.4F + 0.6F; + this.particleRed = ((float)(Math.random() * 0.20000000298023224D) + 0.8F) * p_i46350_9_ * f; + this.particleGreen = ((float)(Math.random() * 0.20000000298023224D) + 0.8F) * p_i46350_10_ * f; + this.particleBlue = ((float)(Math.random() * 0.20000000298023224D) + 0.8F) * p_i46350_11_ * f; + this.particleScale *= 0.75F; + this.particleScale *= p_i46350_8_; + this.reddustParticleScale = this.particleScale; + this.particleMaxAge = (int)(8.0D / (Math.random() * 0.8D + 0.2D)); + this.particleMaxAge = (int)((float)this.particleMaxAge * p_i46350_8_); + this.noClip = false; + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge * 32.0F; + f = ExtMath.clampf(f, 0.0F, 1.0F); + this.particleScale = this.reddustParticleScale * f; + super.renderParticle(worldRendererIn, entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ); + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + + if (this.particleAge++ >= this.particleMaxAge) + { + this.setDead(); + } + + this.setParticleTextureIndex(7 - this.particleAge * 8 / this.particleMaxAge); + this.moveEntity(this.motionX, this.motionY, this.motionZ); + + if (this.posY == this.prevY) + { + this.motionX *= 1.1D; + this.motionZ *= 1.1D; + } + + this.motionX *= 0.9599999785423279D; + this.motionY *= 0.9599999785423279D; + this.motionZ *= 0.9599999785423279D; + + if (this.onGround) + { + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntityReddustFX(worldIn, xCoordIn, yCoordIn, zCoordIn, (float)xSpeedIn, (float)ySpeedIn, (float)zSpeedIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntitySmokeFX.java b/client/src/client/renderer/particle/EntitySmokeFX.java new file mode 100755 index 00000000..5566bf2a --- /dev/null +++ b/client/src/client/renderer/particle/EntitySmokeFX.java @@ -0,0 +1,88 @@ +package client.renderer.particle; + +import client.renderer.RenderBuffer; +import common.entity.Entity; +import common.util.ExtMath; +import common.world.World; + +public class EntitySmokeFX extends EntityFX +{ + float smokeParticleScale; + + private EntitySmokeFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double p_i46347_8_, double p_i46347_10_, double p_i46347_12_) + { + this(worldIn, xCoordIn, yCoordIn, zCoordIn, p_i46347_8_, p_i46347_10_, p_i46347_12_, 1.0F); + } + + protected EntitySmokeFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double p_i46348_8_, double p_i46348_10_, double p_i46348_12_, float p_i46348_14_) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, 0.0D, 0.0D, 0.0D); + this.motionX *= 0.10000000149011612D; + this.motionY *= 0.10000000149011612D; + this.motionZ *= 0.10000000149011612D; + this.motionX += p_i46348_8_; + this.motionY += p_i46348_10_; + this.motionZ += p_i46348_12_; + this.particleRed = this.particleGreen = this.particleBlue = (float)(Math.random() * 0.30000001192092896D); + this.particleScale *= 0.75F; + this.particleScale *= p_i46348_14_; + this.smokeParticleScale = this.particleScale; + this.particleMaxAge = (int)(8.0D / (Math.random() * 0.8D + 0.2D)); + this.particleMaxAge = (int)((float)this.particleMaxAge * p_i46348_14_); + this.noClip = false; + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge * 32.0F; + f = ExtMath.clampf(f, 0.0F, 1.0F); + this.particleScale = this.smokeParticleScale * f; + super.renderParticle(worldRendererIn, entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ); + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + + if (this.particleAge++ >= this.particleMaxAge) + { + this.setDead(); + } + + this.setParticleTextureIndex(7 - this.particleAge * 8 / this.particleMaxAge); + this.motionY += 0.004D; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + + if (this.posY == this.prevY) + { + this.motionX *= 1.1D; + this.motionZ *= 1.1D; + } + + this.motionX *= 0.9599999785423279D; + this.motionY *= 0.9599999785423279D; + this.motionZ *= 0.9599999785423279D; + + if (this.onGround) + { + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntitySmokeFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntitySnowShovelFX.java b/client/src/client/renderer/particle/EntitySnowShovelFX.java new file mode 100755 index 00000000..ff9e9faf --- /dev/null +++ b/client/src/client/renderer/particle/EntitySnowShovelFX.java @@ -0,0 +1,81 @@ +package client.renderer.particle; + +import client.renderer.RenderBuffer; +import common.entity.Entity; +import common.util.ExtMath; +import common.world.World; + +public class EntitySnowShovelFX extends EntityFX +{ + float snowDigParticleScale; + + protected EntitySnowShovelFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn) + { + this(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn, 1.0F); + } + + protected EntitySnowShovelFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, float p_i1228_14_) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + this.motionX *= 0.10000000149011612D; + this.motionY *= 0.10000000149011612D; + this.motionZ *= 0.10000000149011612D; + this.motionX += xSpeedIn; + this.motionY += ySpeedIn; + this.motionZ += zSpeedIn; + this.particleRed = this.particleGreen = this.particleBlue = 1.0F - (float)(Math.random() * 0.30000001192092896D); + this.particleScale *= 0.75F; + this.particleScale *= p_i1228_14_; + this.snowDigParticleScale = this.particleScale; + this.particleMaxAge = (int)(8.0D / (Math.random() * 0.8D + 0.2D)); + this.particleMaxAge = (int)((float)this.particleMaxAge * p_i1228_14_); + this.noClip = false; + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge * 32.0F; + f = ExtMath.clampf(f, 0.0F, 1.0F); + this.particleScale = this.snowDigParticleScale * f; + super.renderParticle(worldRendererIn, entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ); + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + + if (this.particleAge++ >= this.particleMaxAge) + { + this.setDead(); + } + + this.setParticleTextureIndex(7 - this.particleAge * 8 / this.particleMaxAge); + this.motionY -= 0.03D; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.9900000095367432D; + this.motionY *= 0.9900000095367432D; + this.motionZ *= 0.9900000095367432D; + + if (this.onGround) + { + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntitySnowShovelFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntitySpellParticleFX.java b/client/src/client/renderer/particle/EntitySpellParticleFX.java new file mode 100755 index 00000000..4aaa0472 --- /dev/null +++ b/client/src/client/renderer/particle/EntitySpellParticleFX.java @@ -0,0 +1,135 @@ +package client.renderer.particle; + +import client.renderer.RenderBuffer; +import common.entity.Entity; +import common.rng.Random; +import common.util.ExtMath; +import common.world.World; + +public class EntitySpellParticleFX extends EntityFX +{ + private static final Random RANDOM = new Random(); + + /** Base spell texture index */ + private int baseSpellTextureIndex = 128; + + protected EntitySpellParticleFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double p_i1229_8_, double p_i1229_10_, double p_i1229_12_) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, 0.5D - RANDOM.doublev(), p_i1229_10_, 0.5D - RANDOM.doublev()); + this.motionY *= 0.20000000298023224D; + + if (p_i1229_8_ == 0.0D && p_i1229_12_ == 0.0D) + { + this.motionX *= 0.10000000149011612D; + this.motionZ *= 0.10000000149011612D; + } + + this.particleScale *= 0.75F; + this.particleMaxAge = (int)(8.0D / (Math.random() * 0.8D + 0.2D)); + this.noClip = false; + } + + /** + * Renders the particle + */ + public void renderParticle(RenderBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) + { + float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge * 32.0F; + f = ExtMath.clampf(f, 0.0F, 1.0F); + super.renderParticle(worldRendererIn, entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ); + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + + if (this.particleAge++ >= this.particleMaxAge) + { + this.setDead(); + } + + this.setParticleTextureIndex(this.baseSpellTextureIndex + (7 - this.particleAge * 8 / this.particleMaxAge)); + this.motionY += 0.004D; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + + if (this.posY == this.prevY) + { + this.motionX *= 1.1D; + this.motionZ *= 1.1D; + } + + this.motionX *= 0.9599999785423279D; + this.motionY *= 0.9599999785423279D; + this.motionZ *= 0.9599999785423279D; + + if (this.onGround) + { + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } + } + + /** + * Sets the base spell texture index + */ + public void setBaseSpellTextureIndex(int baseSpellTextureIndexIn) + { + this.baseSpellTextureIndex = baseSpellTextureIndexIn; + } + + public static class AmbientMobFactory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + EntityFX entityfx = new EntitySpellParticleFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + entityfx.setAlphaF(0.15F); + entityfx.setRBGColorF((float)xSpeedIn, (float)ySpeedIn, (float)zSpeedIn); + return entityfx; + } + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntitySpellParticleFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } + + public static class InstantFactory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + EntityFX entityfx = new EntitySpellParticleFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + ((EntitySpellParticleFX)entityfx).setBaseSpellTextureIndex(144); + return entityfx; + } + } + + public static class MobFactory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + EntityFX entityfx = new EntitySpellParticleFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + entityfx.setRBGColorF((float)xSpeedIn, (float)ySpeedIn, (float)zSpeedIn); + return entityfx; + } + } + + public static class WitchFactory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + EntityFX entityfx = new EntitySpellParticleFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + ((EntitySpellParticleFX)entityfx).setBaseSpellTextureIndex(144); + float f = worldIn.rand.floatv() * 0.5F + 0.35F; + entityfx.setRBGColorF(1.0F * f, 0.0F * f, 1.0F * f); + return entityfx; + } + } +} diff --git a/client/src/client/renderer/particle/EntitySplashFX.java b/client/src/client/renderer/particle/EntitySplashFX.java new file mode 100755 index 00000000..8c1f93ab --- /dev/null +++ b/client/src/client/renderer/particle/EntitySplashFX.java @@ -0,0 +1,28 @@ +package client.renderer.particle; + +import common.world.World; + +public class EntitySplashFX extends EntityDownfallFX +{ + protected EntitySplashFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn) + { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, 0, 3); + this.particleGravity = 0.04F; + this.nextTextureIndexX(); + + if (ySpeedIn == 0.0D && (xSpeedIn != 0.0D || zSpeedIn != 0.0D)) + { + this.motionX = xSpeedIn; + this.motionY = ySpeedIn + 0.1D; + this.motionZ = zSpeedIn; + } + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntitySplashFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } +} diff --git a/client/src/client/renderer/particle/EntitySuspendFX.java b/client/src/client/renderer/particle/EntitySuspendFX.java new file mode 100755 index 00000000..4047b03c --- /dev/null +++ b/client/src/client/renderer/particle/EntitySuspendFX.java @@ -0,0 +1,52 @@ +package client.renderer.particle; + +import common.material.Material; +import common.util.BlockPos; +import common.world.World; + +public class EntitySuspendFX extends EntityFX +{ + protected EntitySuspendFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn) + { + super(worldIn, xCoordIn, yCoordIn - 0.125D, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + this.particleRed = 0.4F; + this.particleGreen = 0.4F; + this.particleBlue = 0.7F; + this.setParticleTextureIndex(0); + this.setSize(0.01F, 0.01F); + this.particleScale *= this.rand.floatv() * 0.6F + 0.2F; + this.motionX = xSpeedIn * 0.0D; + this.motionY = ySpeedIn * 0.0D; + this.motionZ = zSpeedIn * 0.0D; + this.particleMaxAge = (int)(16.0D / (Math.random() * 0.8D + 0.2D)); + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + + if (this.worldObj.getState(new BlockPos(this)).getBlock().getMaterial() != Material.water) + { + this.setDead(); + } + + if (this.particleMaxAge-- <= 0) + { + this.setDead(); + } + } + + public static class Factory implements IParticleFactory + { + public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_) + { + return new EntitySuspendFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn); + } + } +} diff --git a/client/src/client/renderer/particle/IParticleFactory.java b/client/src/client/renderer/particle/IParticleFactory.java new file mode 100755 index 00000000..f018fda4 --- /dev/null +++ b/client/src/client/renderer/particle/IParticleFactory.java @@ -0,0 +1,8 @@ +package client.renderer.particle; + +import common.world.World; + +public interface IParticleFactory +{ + EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_); +} diff --git a/client/src/client/renderer/texture/ColormapLoader.java b/client/src/client/renderer/texture/ColormapLoader.java new file mode 100644 index 00000000..75665009 --- /dev/null +++ b/client/src/client/renderer/texture/ColormapLoader.java @@ -0,0 +1,27 @@ +package client.renderer.texture; + +import java.awt.image.BufferedImage; + +import common.color.Colorizer; +import common.util.FileUtils; + +public abstract class ColormapLoader { + private static final String GRASS_TEX = "textures/world/grass.png"; + private static final String FOLIAGE_TEX = "textures/world/foliage.png"; + + public static void reload() { + BufferedImage img; + try { + img = TextureUtil.readImage(FileUtils.getResource(GRASS_TEX)); + img.getRGB(0, 0, 256, 256, Colorizer.getGrassMap(), 0, 256); + } + catch(Exception e) { + } + try { + img = TextureUtil.readImage(FileUtils.getResource(FOLIAGE_TEX)); + img.getRGB(0, 0, 256, 256, Colorizer.getFoliageMap(), 0, 256); + } + catch(Exception e) { + } + } +} diff --git a/client/src/client/renderer/texture/DynamicTexture.java b/client/src/client/renderer/texture/DynamicTexture.java new file mode 100755 index 00000000..1d82fcdb --- /dev/null +++ b/client/src/client/renderer/texture/DynamicTexture.java @@ -0,0 +1,55 @@ +package client.renderer.texture; + +import java.awt.image.BufferedImage; +import java.io.IOException; + +import client.renderer.GlState; + +public class DynamicTexture extends Texture +{ + private final int[] dynamicTextureData; + + /** width of this icon in pixels */ + private final int width; + + /** height of this icon in pixels */ + private final int height; + + public DynamicTexture(BufferedImage bufferedImage) + { + this(bufferedImage.getWidth(), bufferedImage.getHeight()); + bufferedImage.getRGB(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(), this.dynamicTextureData, 0, bufferedImage.getWidth()); + this.updateDynamicTexture(); + } + + public DynamicTexture(int textureWidth, int textureHeight) + { + this.width = textureWidth; + this.height = textureHeight; + this.dynamicTextureData = new int[textureWidth * textureHeight]; + TextureUtil.allocateTexture(this.getGlTextureId(), textureWidth, textureHeight); + } + + public void loadTexture() throws IOException + { + } + + public void updateDynamicTexture() + { + GlState.bindTexture(this.getGlTextureId()); + TextureUtil.uploadTexture(this.dynamicTextureData, this.width, this.height, 0, 0); + } + + public int[] getTextureData() + { + return this.dynamicTextureData; + } + + public int getWidth() { + return this.width; + } + + public int getHeight() { + return this.height; + } +} diff --git a/client/src/client/renderer/texture/EntityTexManager.java b/client/src/client/renderer/texture/EntityTexManager.java new file mode 100755 index 00000000..b273901d --- /dev/null +++ b/client/src/client/renderer/texture/EntityTexManager.java @@ -0,0 +1,246 @@ +package client.renderer.texture; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import client.Client; +import client.renderer.entity.RenderNpc; +import client.renderer.layers.LayerExtra; +import common.collect.Lists; +import common.collect.Maps; +import common.collect.Sets; +import common.entity.npc.EntityNPC; +import common.init.SpeciesRegistry; +import common.init.SpeciesRegistry.ModelType; +import common.log.Log; +import common.util.FileUtils; + +public abstract class EntityTexManager +{ + public static String altTexture = null; + public static int altLayer = -1; + public static String altNpcLayer = null; + + private static final Set USER_TEXTURES = Sets.newHashSet(); + private static final Map USER_LAYERS = Maps.newHashMap(); + private static final Map NPC_LAYERS = Maps.newHashMap(); + private static final Map DEF_TEXTURES = Maps.newEnumMap(ModelType.class); + private static final Map DEF_LAYERS = Maps.newEnumMap(ModelType.class); + + public static void loadNpcTextures() { + TextureManager manager = Client.CLIENT.getTextureManager(); + for(Entry entry : SpeciesRegistry.SKINS.entrySet()) { + String skin = entry.getKey(); +// skin = skin.startsWith("~") ? skin.substring(1) : skin; + String loc = EntityNPC.getSkinTexture(skin); + BufferedImage image; + try { + image = TextureUtil.readImage(FileUtils.getResource(loc)); + } + catch(IOException e) { + if(e instanceof FileNotFoundException) + Log.JNI.warn("Textur ist nicht vorhanden: " + loc); + else + Log.JNI.error(e, "Konnte Textur nicht laden: " + loc); + try { + image = TextureUtil.readImage(FileUtils.getResource(getDefault(entry.getValue()))); + } + catch(IOException e2) { + if(e2 instanceof FileNotFoundException) + Log.JNI.warn("Textur ist nicht vorhanden: " + loc); + else + Log.JNI.error(e2, "Konnte Textur nicht laden: " + loc); + image = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB); + Graphics2D g = image.createGraphics(); + g.setColor(Color.BLACK); + g.fillRect(0, 0, 64, 64); + g.dispose(); + } + } + loc = getNpcSkinLocation(skin); + DynamicTexture dyntex = (DynamicTexture)manager.getTexture(loc); + if(dyntex == null || (dyntex.getWidth() != image.getWidth() || dyntex.getHeight() != image.getHeight())) { + if(dyntex != null) + manager.deleteTexture(loc); + dyntex = new DynamicTexture(image); + manager.loadTexture(loc, dyntex); + } + else { + image.getRGB(0, 0, image.getWidth(), image.getHeight(), dyntex.getTextureData(), 0, image.getWidth()); + } + dyntex.updateDynamicTexture(); + LayerExtra extra = LayerExtra.getLayer(dyntex.getTextureData(), dyntex.getWidth(), dyntex.getHeight(), entry.getValue()); + if(EntityNPC.getSkinTexture(skin).equals(getDefault(entry.getValue()))) { + DEF_LAYERS.put(entry.getValue(), extra); + } + if(extra != null) { + extra = NPC_LAYERS.put(skin, extra); + } + else { + extra = NPC_LAYERS.remove(skin); + } + if(extra != null) + extra.discard(); +// setTexture(skin, image, entry.getValue()); + } + for(String cape : SpeciesRegistry.CAPES) { + String loc = EntityNPC.getCapeTexture(cape); + BufferedImage image; + try { + image = TextureUtil.readImage(FileUtils.getResource(loc)); + } + catch(IOException e) { + if(e instanceof FileNotFoundException) + Log.JNI.warn("Textur ist nicht vorhanden: " + loc); + else + Log.JNI.error(e, "Konnte Textur nicht laden: " + loc); + image = new BufferedImage(64, 32, BufferedImage.TYPE_INT_ARGB); + Graphics2D g = image.createGraphics(); + g.setColor(Color.BLACK); + g.fillRect(0, 0, 64, 32); + g.dispose(); + } + loc = getCapeLocation(cape); + DynamicTexture dyntex = (DynamicTexture)manager.getTexture(loc); + if(dyntex == null || (dyntex.getWidth() != image.getWidth() || dyntex.getHeight() != image.getHeight())) { + if(dyntex != null) + manager.deleteTexture(loc); + dyntex = new DynamicTexture(image); + manager.loadTexture(loc, dyntex); + } + else { + image.getRGB(0, 0, image.getWidth(), image.getHeight(), dyntex.getTextureData(), 0, image.getWidth()); + } + dyntex.updateDynamicTexture(); +// setCape(cape, image); + } +// for(ModelType model : ModelType.values()) { +// if(DEF_TEXTURES.get(model) == null) +// Log.IO.warn(altNpcLayer); +// } + } + + public static String getDefault(ModelType model) { + String def = DEF_TEXTURES.get(model); + if(def == null) + DEF_TEXTURES.put(model, def = Client.CLIENT.getRenderManager().getRenderObject(model).getDefaultTexture()); + return def; + } + + private static String getSkinLocation(int id) { + return "skins/player" + id + "/dyn"; + } + + private static String getNpcSkinLocation(String user) { + return "npcs/" + user.toLowerCase() + "/dyn"; + } + + private static String getCapeLocation(String name) { + return "capes/" + name.toLowerCase() + "/dyn"; + } + + public static LayerExtra getLayer(int id, String skin, ModelType model) + { + if(id == -1) + return Client.CLIENT.getTextureManager().getTexture(getNpcSkinLocation(skin)) != null ? NPC_LAYERS.get(skin.toLowerCase()) : DEF_LAYERS.get(model); + return altNpcLayer != null ? Client.CLIENT.getTextureManager().getTexture(getNpcSkinLocation(altNpcLayer)) != null ? + NPC_LAYERS.get(altNpcLayer.toLowerCase()) : DEF_LAYERS.get(model) : (altLayer != -1 ? USER_LAYERS.get(altLayer) : (USER_TEXTURES.contains(id) ? USER_LAYERS.get(id) : (skin != null && Client.CLIENT.getTextureManager().getTexture(getNpcSkinLocation(skin)) != null ? NPC_LAYERS.get(skin.toLowerCase()) : DEF_LAYERS.get(model)))); + } + + public static String getSkin(int id, String skin, ModelType model) + { + String loc = id != -1 ? (altTexture != null ? altTexture : getSkinLocation(id)) : getNpcSkinLocation(skin); + if(id != -1 && skin != null && Client.CLIENT.getTextureManager().getTexture(loc) == null) + loc = getNpcSkinLocation(skin); + return Client.CLIENT.getTextureManager().getTexture(loc) != null ? loc : getDefault(model); + } + + public static boolean hasCustomSkin(int id) { + return Client.CLIENT.getTextureManager().getTexture(getSkinLocation(id)) != null; + } + + public static String getCape(String name) + { + if(name == null || name.isEmpty()) + return null; + String loc = getCapeLocation(name); + return Client.CLIENT.getTextureManager().getTexture(loc) != null ? loc : null; + } + + public static void clearTextures() { + List list = Lists.newArrayList(USER_TEXTURES); + for(Integer user : list) { + setTexture(user, null, null); + } + } + + public static void setTexture(int id, byte[] comp, ModelType model) { + if(comp == null && !USER_TEXTURES.contains(id)) + return; +// user = user.toLowerCase(); + TextureManager manager = Client.CLIENT.getTextureManager(); + String loc = getSkinLocation(id); + DynamicTexture dyntex = (DynamicTexture)manager.getTexture(loc); + if(comp == null) { + if(dyntex != null) + manager.deleteTexture(loc); + USER_TEXTURES.remove(id); + LayerExtra layer = USER_LAYERS.remove(id); + if(layer != null) + layer.discard(); + } + else { + if(dyntex == null || (dyntex.getWidth() != model.texWidth || dyntex.getHeight() != model.texHeight)) { + if(dyntex != null) + manager.deleteTexture(loc); + dyntex = new DynamicTexture(model.texWidth, model.texHeight); + manager.loadTexture(loc, dyntex); + } + EntityTexManager.compToImage(comp, dyntex.getTextureData(), model); + dyntex.updateDynamicTexture(); + USER_TEXTURES.add(id); + LayerExtra extra = LayerExtra.getLayer(dyntex.getTextureData(), dyntex.getWidth(), dyntex.getHeight(), model); + if(extra != null) { + extra = USER_LAYERS.put(id, extra); + } + else { + extra = USER_LAYERS.remove(id); + } + if(extra != null) + extra.discard(); + } + } + + public static void compToImage(byte[] comp, int[] img, ModelType model) { + RenderNpc render = Client.CLIENT.getRenderManager().getRenderObject(model); + if(comp.length < render.getCompressedSize()) + comp = new byte[render.getCompressedSize()]; + render.compToImage(comp, img, model.texWidth); + } + + public static byte[] imageToComp(int[] img, ModelType model) { + RenderNpc render = Client.CLIENT.getRenderManager().getRenderObject(model); + byte[] comp = new byte[render.getCompressedSize()]; + render.imageToComp(comp, img, model.texWidth); + return comp; + } + + public static String getSkin(EntityNPC entity) { + return getSkin(entity.isPlayer() ? entity.getId() : -1, entity.getChar(), entity.getSpecies().renderer); + } + + public static LayerExtra getLayer(EntityNPC entity) { + return getLayer(entity.isPlayer() ? entity.getId() : -1, entity.getChar(), entity.getSpecies().renderer); + } + + public static String getCape(EntityNPC entity) { + return !entity.getCape().isEmpty() ? EntityTexManager.getCape(entity.getCape()) : null; + } +} diff --git a/client/src/client/renderer/texture/IIconCreator.java b/client/src/client/renderer/texture/IIconCreator.java new file mode 100755 index 00000000..ed1f0aaf --- /dev/null +++ b/client/src/client/renderer/texture/IIconCreator.java @@ -0,0 +1,6 @@ +package client.renderer.texture; + +public interface IIconCreator +{ + void registerSprites(TextureMap iconRegistry); +} diff --git a/client/src/client/renderer/texture/LayeredColorMaskTexture.java b/client/src/client/renderer/texture/LayeredColorMaskTexture.java new file mode 100755 index 00000000..654e960d --- /dev/null +++ b/client/src/client/renderer/texture/LayeredColorMaskTexture.java @@ -0,0 +1,101 @@ +package client.renderer.texture; + +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.awt.image.ImageObserver; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +import common.color.DyeColor; +import common.log.Log; +import common.util.FileUtils; + +public class LayeredColorMaskTexture extends Texture +{ + /** The location of the texture. */ + private final String textureLocation; + private final List field_174949_h; + private final List field_174950_i; + + private static int applyTint(int color, int tint) { + int i = (color & 16711680) >> 16; + int j = (tint & 16711680) >> 16; + int k = (color & 65280) >> 8; + int l = (tint & 65280) >> 8; + int i1 = (color & 255) >> 0; + int j1 = (tint & 255) >> 0; + int k1 = (int)((float)i * (float)j / 255.0F); + int l1 = (int)((float)k * (float)l / 255.0F); + int i2 = (int)((float)i1 * (float)j1 / 255.0F); + return color & -16777216 | k1 << 16 | l1 << 8 | i2; + } + + public LayeredColorMaskTexture(String textureLocationIn, List p_i46101_2_, List p_i46101_3_) + { + this.textureLocation = textureLocationIn; + this.field_174949_h = p_i46101_2_; + this.field_174950_i = p_i46101_3_; + } + + public void loadTexture() throws IOException + { + this.deleteGlTexture(); + BufferedImage bufferedimage; + + try + { + BufferedImage bufferedimage1 = TextureUtil.readImage(FileUtils.getResource(this.textureLocation)); + int i = bufferedimage1.getType(); + + if (i == 0) + { + i = 6; + } + + bufferedimage = new BufferedImage(bufferedimage1.getWidth(), bufferedimage1.getHeight(), i); + Graphics graphics = bufferedimage.getGraphics(); + graphics.drawImage(bufferedimage1, 0, 0, (ImageObserver)null); + + for (int j = 0; j < 17 && j < this.field_174949_h.size() && j < this.field_174950_i.size(); ++j) + { + String s = (String)this.field_174949_h.get(j); + int color = this.field_174950_i.get(j).getColor(); + + if (s != null) + { + InputStream inputstream = FileUtils.getResource(s); + BufferedImage bufferedimage2 = TextureUtil.readImage(inputstream); + + if (bufferedimage2.getWidth() == bufferedimage.getWidth() && bufferedimage2.getHeight() == bufferedimage.getHeight() && bufferedimage2.getType() == 6) + { + for (int k = 0; k < bufferedimage2.getHeight(); ++k) + { + for (int l = 0; l < bufferedimage2.getWidth(); ++l) + { + int i1 = bufferedimage2.getRGB(l, k); + + if ((i1 & -16777216) != 0) + { + int j1 = (i1 & 16711680) << 8 & -16777216; + int k1 = bufferedimage1.getRGB(l, k); + int l1 = applyTint(k1, color) & 16777215; + bufferedimage2.setRGB(l, k, j1 | l1); + } + } + } + + bufferedimage.getGraphics().drawImage(bufferedimage2, 0, 0, (ImageObserver)null); + } + } + } + } + catch (IOException ioexception) + { + Log.JNI.error((Throwable)ioexception, (String)"Konnte Bild mit mehreren Schichten nicht laden"); + return; + } + + TextureUtil.uploadImage(this.getGlTextureId(), bufferedimage); + } +} diff --git a/client/src/main/java/client/renderer/texture/LayeredTexture.java b/client/src/client/renderer/texture/LayeredTexture.java similarity index 76% rename from client/src/main/java/client/renderer/texture/LayeredTexture.java rename to client/src/client/renderer/texture/LayeredTexture.java index 7485c005..5339db5c 100755 --- a/client/src/main/java/client/renderer/texture/LayeredTexture.java +++ b/client/src/client/renderer/texture/LayeredTexture.java @@ -6,17 +6,17 @@ import java.io.IOException; import java.io.InputStream; import java.util.List; -import client.util.FileUtils; import common.collect.Lists; import common.log.Log; +import common.util.FileUtils; public class LayeredTexture extends Texture { - public final List layers; + public final List layeredTextureNames; - public LayeredTexture(String[] layers) + public LayeredTexture(String[] textureNames) { - this.layers = Lists.newArrayList(layers); + this.layeredTextureNames = Lists.newArrayList(textureNames); } public void loadTexture() throws IOException @@ -26,7 +26,7 @@ public class LayeredTexture extends Texture try { - for (String s : this.layers) + for (String s : this.layeredTextureNames) { if (s != null) { @@ -44,7 +44,7 @@ public class LayeredTexture extends Texture } catch (IOException ioexception) { - Log.IO.error((Throwable)ioexception, (String)"Konnte Bild mit mehreren Schichten nicht laden"); + Log.JNI.error((Throwable)ioexception, (String)"Konnte Bild mit mehreren Schichten nicht laden"); return; } diff --git a/client/src/client/renderer/texture/SimpleTexture.java b/client/src/client/renderer/texture/SimpleTexture.java new file mode 100755 index 00000000..43c4629a --- /dev/null +++ b/client/src/client/renderer/texture/SimpleTexture.java @@ -0,0 +1,32 @@ +package client.renderer.texture; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; + +import common.util.FileUtils; + +public class SimpleTexture extends Texture { + private final String location; + + public SimpleTexture(String location) { + this.location = location; + } + + public void loadTexture() throws IOException { + this.deleteGlTexture(); + InputStream in = null; + try { + in = // this.location.startsWith("/") ? SimpleTexture.class.getResourceAsStream(this.location) : + FileUtils.getResource(this.location); +// if(in == null) +// throw new FileNotFoundException(this.location); + BufferedImage img = TextureUtil.readImage(in); + TextureUtil.uploadImage(this.getGlTextureId(), img); + } + finally { + if(in != null) + in.close(); + } + } +} diff --git a/client/src/client/renderer/texture/Stitcher.java b/client/src/client/renderer/texture/Stitcher.java new file mode 100755 index 00000000..f9cff3b1 --- /dev/null +++ b/client/src/client/renderer/texture/Stitcher.java @@ -0,0 +1,428 @@ +package client.renderer.texture; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; + +import common.collect.Lists; +import common.collect.Sets; + +public class Stitcher +{ +// private static final int MAX_SIZE; + + private final Set setStitchHolders = Sets.newHashSetWithExpectedSize(256); + private final List stitchSlots = new ArrayList(256); + + private int currentWidth; + private int currentHeight; + +// private static int getMaximumTextureSize() { +// for(int i = 16384; i > 0; i >>= 1) { +// SKC.glTexImage2D(SKC.GL_PROXY_TEXTURE_2D, 0, SKC.GL_RGBA, i, i, 0, SKC.GL_RGBA, SKC.GL_UNSIGNED_BYTE, +// (ByteBuffer)((ByteBuffer)null)); +// int j = SKC.glGetTexLevelParameteri(SKC.GL_PROXY_TEXTURE_2D, 0, SKC.GL_TEXTURE_WIDTH); +// +// if(j != 0) { +// return i; +// } +// } +// +// return -1; +// } + + private static int roundUpToPowerOfTwo(int value) { + int i = value - 1; + i = i | i >> 1; + i = i | i >> 2; + i = i | i >> 4; + i = i | i >> 8; + i = i | i >> 16; + return i + 1; + } + +// static { +// MAX_SIZE = getMaximumTextureSize(); +// } + + public int getCurrentWidth() + { + return this.currentWidth; + } + + public int getCurrentHeight() + { + return this.currentHeight; + } + + public void addSprite(TextureAtlasSprite p_110934_1_) + { + Stitcher.Holder stitcher$holder = new Stitcher.Holder(p_110934_1_); + +// if (this.maxTileDimension > 0) +// { +// stitcher$holder.setNewDimension(this.maxTileDimension); +// } + + this.setStitchHolders.add(stitcher$holder); + } + + public void doStitch() + { + Stitcher.Holder[] astitcher$holder = (Stitcher.Holder[])this.setStitchHolders.toArray(new Stitcher.Holder[this.setStitchHolders.size()]); + Arrays.sort((Object[])astitcher$holder); + + for (Stitcher.Holder stitcher$holder : astitcher$holder) + { + this.allocateSlot(stitcher$holder); +// { +// String s = String.format("Unable to fit: %s - size: %dx%d - Maybe try a lowerresolution resourcepack?", stitcher$holder.getAtlasSprite().getIconName(), Integer.valueOf(stitcher$holder.getAtlasSprite().getIconWidth()), Integer.valueOf(stitcher$holder.getAtlasSprite().getIconHeight())); +// throw new IndexOutOfBoundsException(s); +// } + } + +// if (this.forcePowerOf2) +// { + this.currentWidth = roundUpToPowerOfTwo(this.currentWidth); + this.currentHeight = roundUpToPowerOfTwo(this.currentHeight); +// } + } + + public List getStichSlots() + { + List list = Lists.newArrayList(); + + for (Stitcher.Slot stitcher$slot : this.stitchSlots) + { + stitcher$slot.getAllStitchSlots(list); + } + + List list1 = Lists.newArrayList(); + + for (Stitcher.Slot stitcher$slot1 : list) + { + Stitcher.Holder stitcher$holder = stitcher$slot1.getStitchHolder(); + TextureAtlasSprite textureatlassprite = stitcher$holder.getAtlasSprite(); + textureatlassprite.initSprite(this.currentWidth, this.currentHeight, stitcher$slot1.getOriginX(), stitcher$slot1.getOriginY(), stitcher$holder.isRotated()); + list1.add(textureatlassprite); + } + + return list1; + } + + /** + * Attempts to find space for specified tile + */ + private void allocateSlot(Stitcher.Holder p_94310_1_) + { + for (int i = 0; i < this.stitchSlots.size(); ++i) + { + if (((Stitcher.Slot)this.stitchSlots.get(i)).addSlot(p_94310_1_)) + { + return; + } + + p_94310_1_.rotate(); + + if (((Stitcher.Slot)this.stitchSlots.get(i)).addSlot(p_94310_1_)) + { + return; + } + + p_94310_1_.rotate(); + } + + this.expandAndAllocateSlot(p_94310_1_); + } + + /** + * Expand stitched texture in order to make space for specified tile + */ + private void expandAndAllocateSlot(Stitcher.Holder p_94311_1_) + { + int i = Math.min(p_94311_1_.getWidth(), p_94311_1_.getHeight()); + boolean flag = this.currentWidth == 0 && this.currentHeight == 0; + boolean flag1; + +// if (this.forcePowerOf2) +// { + int j = roundUpToPowerOfTwo(this.currentWidth); + int k = roundUpToPowerOfTwo(this.currentHeight); + int l = roundUpToPowerOfTwo(this.currentWidth + i); + int i1 = roundUpToPowerOfTwo(this.currentHeight + i); +// boolean flag2 = l <= MAX_SIZE; +// boolean flag3 = i1 <= MAX_SIZE; +// +// if (!flag2 && !flag3) +// { +// return false; +// } + + boolean flag4 = j != l; + boolean flag5 = k != i1; + + if (flag4 ^ flag5) + { + flag1 = !flag4; + } + else + { + flag1 = /* flag2 && */ j <= k; + } +// } +// else +// { +// boolean flag6 = this.currentWidth + i <= this.maxWidth; +// boolean flag7 = this.currentHeight + i <= this.maxHeight; +// +// if (!flag6 && !flag7) +// { +// return false; +// } +// +// flag1 = flag6 && (flag || this.currentWidth <= this.currentHeight); +// } + +// int j1 = Math.max(p_94311_1_.getWidth(), p_94311_1_.getHeight()); +// +// if (Stitcher.roundUpToPowerOfTwo((flag1 ? this.currentHeight : this.currentWidth) + j1) > MAX_SIZE) +// { +// return false; +// } +// else +// { + Stitcher.Slot stitcher$slot; + + if (flag1) + { + if (p_94311_1_.getWidth() > p_94311_1_.getHeight()) + { + p_94311_1_.rotate(); + } + + if (this.currentHeight == 0) + { + this.currentHeight = p_94311_1_.getHeight(); + } + + stitcher$slot = new Stitcher.Slot(this.currentWidth, 0, p_94311_1_.getWidth(), this.currentHeight); + this.currentWidth += p_94311_1_.getWidth(); + } + else + { + stitcher$slot = new Stitcher.Slot(0, this.currentHeight, this.currentWidth, p_94311_1_.getHeight()); + this.currentHeight += p_94311_1_.getHeight(); + } + + stitcher$slot.addSlot(p_94311_1_); + this.stitchSlots.add(stitcher$slot); +// return true; +// } + } + + public static class Holder implements Comparable + { + private final TextureAtlasSprite theTexture; + private final int width; + private final int height; + private boolean rotated; + private float scaleFactor = 1.0F; + + public Holder(TextureAtlasSprite p_i45094_1_) + { + this.theTexture = p_i45094_1_; + this.width = p_i45094_1_.getIconWidth(); + this.height = p_i45094_1_.getIconHeight(); + this.rotated = this.height > this.width; + } + + public TextureAtlasSprite getAtlasSprite() + { + return this.theTexture; + } + + public int getWidth() + { + return this.rotated ? (int)((float)this.height * this.scaleFactor) : (int)((float)this.width * this.scaleFactor); + } + + public int getHeight() + { + return this.rotated ? (int)((float)this.width * this.scaleFactor) : (int)((float)this.height * this.scaleFactor); + } + + public void rotate() + { + this.rotated = !this.rotated; + } + + public boolean isRotated() + { + return this.rotated; + } + + public void setNewDimension(int p_94196_1_) + { + if (this.width > p_94196_1_ && this.height > p_94196_1_) + { + this.scaleFactor = (float)p_94196_1_ / (float)Math.min(this.width, this.height); + } + } + + public String toString() + { + return "Holder{width=" + this.width + ", height=" + this.height + '}'; + } + + public int compareTo(Stitcher.Holder p_compareTo_1_) + { + int i; + + if (this.getHeight() == p_compareTo_1_.getHeight()) + { + if (this.getWidth() == p_compareTo_1_.getWidth()) + { + if (this.theTexture.getIconName() == null) + { + return p_compareTo_1_.theTexture.getIconName() == null ? 0 : -1; + } + + return this.theTexture.getIconName().compareTo(p_compareTo_1_.theTexture.getIconName()); + } + + i = this.getWidth() < p_compareTo_1_.getWidth() ? 1 : -1; + } + else + { + i = this.getHeight() < p_compareTo_1_.getHeight() ? 1 : -1; + } + + return i; + } + } + + public static class Slot + { + private final int originX; + private final int originY; + private final int width; + private final int height; + private List subSlots; + private Stitcher.Holder holder; + + public Slot(int p_i1277_1_, int p_i1277_2_, int widthIn, int heightIn) + { + this.originX = p_i1277_1_; + this.originY = p_i1277_2_; + this.width = widthIn; + this.height = heightIn; + } + + public Stitcher.Holder getStitchHolder() + { + return this.holder; + } + + public int getOriginX() + { + return this.originX; + } + + public int getOriginY() + { + return this.originY; + } + + public boolean addSlot(Stitcher.Holder holderIn) + { + if (this.holder != null) + { + return false; + } + else + { + int i = holderIn.getWidth(); + int j = holderIn.getHeight(); + + if (i <= this.width && j <= this.height) + { + if (i == this.width && j == this.height) + { + this.holder = holderIn; + return true; + } + else + { + if (this.subSlots == null) + { + this.subSlots = new ArrayList(1); + this.subSlots.add(new Stitcher.Slot(this.originX, this.originY, i, j)); + int k = this.width - i; + int l = this.height - j; + + if (l > 0 && k > 0) + { + int i1 = Math.max(this.height, k); + int j1 = Math.max(this.width, l); + + if (i1 >= j1) + { + this.subSlots.add(new Stitcher.Slot(this.originX, this.originY + j, i, l)); + this.subSlots.add(new Stitcher.Slot(this.originX + i, this.originY, k, this.height)); + } + else + { + this.subSlots.add(new Stitcher.Slot(this.originX + i, this.originY, k, j)); + this.subSlots.add(new Stitcher.Slot(this.originX, this.originY + j, this.width, l)); + } + } + else if (k == 0) + { + this.subSlots.add(new Stitcher.Slot(this.originX, this.originY + j, i, l)); + } + else if (l == 0) + { + this.subSlots.add(new Stitcher.Slot(this.originX + i, this.originY, k, j)); + } + } + + for (Stitcher.Slot stitcher$slot : this.subSlots) + { + if (stitcher$slot.addSlot(holderIn)) + { + return true; + } + } + + return false; + } + } + else + { + return false; + } + } + } + + public void getAllStitchSlots(List p_94184_1_) + { + if (this.holder != null) + { + p_94184_1_.add(this); + } + else if (this.subSlots != null) + { + for (Stitcher.Slot stitcher$slot : this.subSlots) + { + stitcher$slot.getAllStitchSlots(p_94184_1_); + } + } + } + + public String toString() + { + return "Slot{originX=" + this.originX + ", originY=" + this.originY + ", width=" + this.width + ", height=" + this.height + ", texture=" + this.holder + ", subSlots=" + this.subSlots + '}'; + } + } +} diff --git a/client/src/client/renderer/texture/Texture.java b/client/src/client/renderer/texture/Texture.java new file mode 100755 index 00000000..4c0ab84a --- /dev/null +++ b/client/src/client/renderer/texture/Texture.java @@ -0,0 +1,33 @@ +package client.renderer.texture; + +import java.io.IOException; + +import org.lwjgl.opengl.GL11; + +import client.renderer.GlState; + +public abstract class Texture +{ + protected int glTextureId = -1; + + public final int getGlTextureId() + { + if (this.glTextureId == -1) + { + this.glTextureId = GL11.glGenTextures(); + } + + return this.glTextureId; + } + + public final void deleteGlTexture() + { + if (this.glTextureId != -1) + { + GlState.deleteTexture(this.glTextureId); + this.glTextureId = -1; + } + } + + public abstract void loadTexture() throws IOException; +} diff --git a/client/src/client/renderer/texture/TextureAtlasSprite.java b/client/src/client/renderer/texture/TextureAtlasSprite.java new file mode 100755 index 00000000..4226a064 --- /dev/null +++ b/client/src/client/renderer/texture/TextureAtlasSprite.java @@ -0,0 +1,330 @@ +package client.renderer.texture; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.List; + +import common.collect.Lists; + +public class TextureAtlasSprite +{ + private final String iconName; + protected List framesTextureData = Lists.newArrayList(); + private int frameCount; + private int frametime; + protected boolean rotated; + protected int originX; + protected int originY; + protected int width; + protected int height; + private float minU; + private float maxU; + private float minV; + private float maxV; + protected int frameCounter; + protected int tickCounter; + private TextureTicked tickedTexture; + + protected TextureAtlasSprite(String spriteName) + { + this.iconName = spriteName; + } + + public void initSprite(int inX, int inY, int originInX, int originInY, boolean rotatedIn) + { + this.originX = originInX; + this.originY = originInY; + this.rotated = rotatedIn; + float f = (float)(0.009999999776482582D / (double)inX); + float f1 = (float)(0.009999999776482582D / (double)inY); + this.minU = (float)originInX / (float)((double)inX) + f; + this.maxU = (float)(originInX + this.width) / (float)((double)inX) - f; + this.minV = (float)originInY / (float)inY + f1; + this.maxV = (float)(originInY + this.height) / (float)inY - f1; + } + + public void copyFrom(TextureAtlasSprite atlasSpirit) + { + this.originX = atlasSpirit.originX; + this.originY = atlasSpirit.originY; + this.width = atlasSpirit.width; + this.height = atlasSpirit.height; + this.rotated = atlasSpirit.rotated; + this.minU = atlasSpirit.minU; + this.maxU = atlasSpirit.maxU; + this.minV = atlasSpirit.minV; + this.maxV = atlasSpirit.maxV; + } + + /** + * Returns the X position of this icon on its texture sheet, in pixels. + */ + public int getOriginX() + { + return this.originX; + } + + /** + * Returns the Y position of this icon on its texture sheet, in pixels. + */ + public int getOriginY() + { + return this.originY; + } + + /** + * Returns the width of the icon, in pixels. + */ + public int getIconWidth() + { + return this.width; + } + + /** + * Returns the height of the icon, in pixels. + */ + public int getIconHeight() + { + return this.height; + } + + /** + * Returns the minimum U coordinate to use when rendering with this icon. + */ + public float getMinU() + { + return this.minU; + } + + /** + * Returns the maximum U coordinate to use when rendering with this icon. + */ + public float getMaxU() + { + return this.maxU; + } + + /** + * Gets a U coordinate on the icon. 0 returns uMin and 16 returns uMax. Other arguments return in-between values. + */ + public float getInterpolatedU(double u) + { + float f = this.maxU - this.minU; + return this.minU + f * (float)u / 16.0F; + } + + /** + * Returns the minimum V coordinate to use when rendering with this icon. + */ + public float getMinV() + { + return this.minV; + } + + /** + * Returns the maximum V coordinate to use when rendering with this icon. + */ + public float getMaxV() + { + return this.maxV; + } + + /** + * Gets a V coordinate on the icon. 0 returns vMin and 16 returns vMax. Other arguments return in-between values. + */ + public float getInterpolatedV(double v) + { + float f = this.maxV - this.minV; + return this.minV + f * ((float)v / 16.0F); + } + + public String getIconName() + { + return this.iconName; + } + + public void updateAnimation() + { + ++this.tickCounter; + + if(this.tickedTexture != null) { + int[] data = this.framesTextureData.get(0); + this.tickedTexture.renderStep(data); +// this.framesTextureData.set(0, data = TextureUtil.generateMipmapData(this.mipmapLevels, this.width, data, true)); + TextureUtil.uploadTexture(data, this.width, this.height, this.originX, this.originY); + return; + } + + if (this.tickCounter >= this.frametime) + { + int i = this.frameCounter; + int j = this.frameCount == 0 ? this.framesTextureData.size() : this.frameCount; + this.frameCounter = (this.frameCounter + 1) % j; + this.tickCounter = 0; + int k = this.frameCounter; + + if (i != k && k >= 0 && k < this.framesTextureData.size()) + { + TextureUtil.uploadTexture(this.framesTextureData.get(k), this.width, this.height, this.originX, this.originY); + } + } + } + + public int[] getFrameTextureData(int index) + { + return this.framesTextureData.get(index); + } + + public int getFrameCount() + { + return this.framesTextureData.size(); + } + + public void setIconWidth(int newWidth) + { + this.width = newWidth; + } + + public void setIconHeight(int newHeight) + { + this.height = newHeight; + } + + public void loadSprite(BufferedImage image, int frametime) throws IOException + { + this.resetSprite(); + int i = image.getWidth(); + int j = image.getHeight(); + this.width = i; + this.height = j; + int[] aint = // new int[images.length][]; + +// for (int k = 0; k < images.length; ++k) +// { +// BufferedImage bufferedimage = images[k]; +// +// if (image != null) +// { +// if (k > 0 && (bufferedimage.getWidth() != i >> k || bufferedimage.getHeight() != j >> k)) +// { +// throw new RuntimeException(String.format("Unable to load miplevel: %d, image is size: %dx%d, expected %dx%d", k, bufferedimage.getWidth(), bufferedimage.getHeight(), i >> k, j >> k)); +// } + +// aint[k] = + new int[i * j]; + image.getRGB(0, 0, i, j, aint, 0, i); +// } +// } + + if (frametime == 0) + { + if (j != i) + { + throw new RuntimeException("Falsches Seitenverhältnis und keine Animation"); + } + + this.framesTextureData.add(aint); + } + else + { + int frames = j / i; + int k1 = i; + int l = i; + this.height = this.width; + + +// if (meta.getFrameCount() > 0) +// { +// Iterator iterator = meta.getFrameIndexSet().iterator(); +// +// while (iterator.hasNext()) +// { +// int i1 = ((Integer)iterator.next()).intValue(); +// +// if (i1 >= j1) +// { +// throw new RuntimeException("invalid frameindex " + i1); +// } +// +// this.allocateFrameTextureData(i1); +// this.framesTextureData.set(i1, getFrameTextureData(aint, k1, l, i1)); +// } +// +// this.animationMetadata = meta; +// } +// else +// { +// List list = Lists.newArrayList(); +// + for (int l1 = 0; l1 < frames; ++l1) + { + int[] aint2 = new int[k1 * l]; + System.arraycopy(aint, l1 * aint2.length, aint2, 0, aint2.length); + this.framesTextureData.add(aint2); +// list.add(new AnimationFrame(l1)); + } + + this.frameCount = frames; + this.frametime = frametime; +// } + } + } + + public void loadSprite(Class tex) + { + this.resetSprite(); + try { + this.tickedTexture = tex.getConstructor().newInstance(); + } + catch(Exception e) { + throw new RuntimeException(e); + } + this.height = this.width = this.tickedTexture.getSize(); +// for (int k = 0; k < aint.length; ++k) { + int[] aint = new int[this.height * this.width]; +// } + this.framesTextureData.add(aint); + this.frameCount = 0; + this.frametime = 1; + } + + private void allocateFrameTextureData(int index) + { + if (this.framesTextureData.size() <= index) + { + for (int i = this.framesTextureData.size(); i <= index; ++i) + { + this.framesTextureData.add(null); + } + } + } + + public void clearFramesTextureData() + { + this.framesTextureData.clear(); + } + + public boolean isAnimated() + { + return this.frametime != 0; + } + + public void setFramesTextureData(List newFramesTextureData) + { + this.framesTextureData = newFramesTextureData; + } + + private void resetSprite() + { + this.frameCount = 0; + this.frametime = 0; + this.setFramesTextureData(Lists.newArrayList()); + this.frameCounter = 0; + this.tickCounter = 0; + } + + public String toString() + { + return "TextureAtlasSprite{name=\'" + this.iconName + '\'' + ", frameCount=" + this.framesTextureData.size() + ", rotated=" + this.rotated + ", x=" + this.originX + ", y=" + this.originY + ", height=" + this.height + ", width=" + this.width + ", u0=" + this.minU + ", u1=" + this.maxU + ", v0=" + this.minV + ", v1=" + this.maxV + '}'; + } +} diff --git a/client/src/main/java/client/renderer/texture/TextureManager.java b/client/src/client/renderer/texture/TextureManager.java similarity index 91% rename from client/src/main/java/client/renderer/texture/TextureManager.java rename to client/src/client/renderer/texture/TextureManager.java index 66f45fb4..4bd6328c 100755 --- a/client/src/main/java/client/renderer/texture/TextureManager.java +++ b/client/src/client/renderer/texture/TextureManager.java @@ -28,9 +28,9 @@ public class TextureManager { } catch(IOException e) { if(e instanceof FileNotFoundException) - Log.IO.warn("Textur ist nicht vorhanden: " + res); + Log.JNI.warn("Textur ist nicht vorhanden: " + res); else - Log.IO.error(e, "Konnte Textur nicht laden: " + res); + Log.JNI.error(e, "Konnte Textur nicht laden: " + res); tex = TextureUtil.MISSING; this.textures.put(res, tex); flag = false; diff --git a/client/src/client/renderer/texture/TextureMap.java b/client/src/client/renderer/texture/TextureMap.java new file mode 100755 index 00000000..5e5c2eea --- /dev/null +++ b/client/src/client/renderer/texture/TextureMap.java @@ -0,0 +1,245 @@ +package client.renderer.texture; + +import java.awt.image.BufferedImage; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import client.init.RenderRegistry; +import client.renderer.GlState; +import common.block.Block; +import common.collect.Lists; +import common.collect.Maps; +import common.init.BlockRegistry; +import common.init.FluidRegistry; +import common.log.Log; +import common.util.FileUtils; + +public class TextureMap extends Texture +{ + public static final String LOCATION_MISSING_TEXTURE = "missingno"; + public static final String locationBlocksTexture = "textures/atlas/blocks.png"; + + private final List listAnimatedSprites; + private final Map mapRegisteredSprites; + private final Map mapUploadedSprites; + private final Map> tickedTextures; + private final Map animTextures; + private final TextureAtlasSprite missingImage; + + public TextureMap() + { + this.listAnimatedSprites = Lists.newArrayList(); + this.mapRegisteredSprites = Maps.newHashMap(); + this.mapUploadedSprites = Maps.newHashMap(); + this.tickedTextures = Maps.>newHashMap(); + this.animTextures = Maps.newHashMap(); + this.missingImage = new TextureAtlasSprite(LOCATION_MISSING_TEXTURE); +// RenderRegistry.registerAnimations(this); + Map map = Maps.newHashMap(); + Map> anim = Maps.newHashMap(); + RenderRegistry.registerAnimations(anim); + for(Block block : BlockRegistry.REGISTRY) { + block.getAnimatedTextures(map); + } + for(int z = 0; z < FluidRegistry.getNumFluids(); z++) { + map.put("blocks/" + BlockRegistry.REGISTRY.getNameForObject(FluidRegistry.getStaticBlock(z)) + "_still", + FluidRegistry.getStaticAnim(z)); + map.put("blocks/" + BlockRegistry.REGISTRY.getNameForObject(FluidRegistry.getStaticBlock(z)) + "_flow", + FluidRegistry.getFluidAnim(z)); + } + for(Entry entry : map.entrySet()) { + if(entry.getValue() instanceof Integer) { + this.animTextures.put(entry.getKey(), (Integer)entry.getValue()); + } + else { + Class clazz = anim.get((String)entry.getValue()); + if(clazz == null) + throw new RuntimeException("Animation '" + (String)entry.getValue() + "' existiert nicht"); + this.tickedTextures.put(entry.getKey(), clazz); + } + } + map.clear(); + anim.clear(); + } + + private void initMissingImage() + { + this.missingImage.setIconWidth(16); + this.missingImage.setIconHeight(16); + this.missingImage.setFramesTextureData(Lists.newArrayList(TextureUtil.MISSING_DATA)); + } + + public void loadTexture() throws IOException + { + } + + public void loadSprites(IIconCreator creator) + { + this.mapRegisteredSprites.clear(); + creator.registerSprites(this); + this.initMissingImage(); + this.deleteGlTexture(); + this.loadTextureAtlas(); + } + + public void loadTextureAtlas() + { + Stitcher stitcher = new Stitcher(); + this.mapUploadedSprites.clear(); + this.listAnimatedSprites.clear(); + int j = Integer.MAX_VALUE; +// int k = 1 << this.mipmapLevels; + + for (Entry entry : this.mapRegisteredSprites.entrySet()) + { + TextureAtlasSprite textureatlassprite = (TextureAtlasSprite)entry.getValue(); + String name = String.format("textures/%s.png", textureatlassprite.getIconName()); + + try + { + Class animationmetadatasection = this.tickedTextures.get(textureatlassprite.getIconName()); + + if(animationmetadatasection != null) { + textureatlassprite.loadSprite(animationmetadatasection); + } + else { + BufferedImage abufferedimage = // new BufferedImage[1 + this.mipmapLevels]; +// abufferedimage[0] = + TextureUtil.readImage(FileUtils.getResource(name)); + Integer frametime = this.animTextures.get(textureatlassprite.getIconName()); + textureatlassprite.loadSprite(abufferedimage, frametime == null ? 0 : frametime.intValue()); + } + } + catch (RuntimeException runtimeexception) + { + Log.JNI.error((Throwable)runtimeexception, (String)("Konnte Metadaten von " + name + " nicht laden")); + continue; + } + catch (FileNotFoundException f) + { + Log.JNI.warn("Textur ist nicht vorhanden: " + name); + continue; + } + catch (IOException ioexception1) + { + Log.JNI.error((Throwable)ioexception1, (String)("Benutze Ersatztextur, konnte " + name + " nicht laden")); + continue; + } + + j = Math.min(j, Math.min(textureatlassprite.getIconWidth(), textureatlassprite.getIconHeight())); + int l1 = Math.min(Integer.lowestOneBit(textureatlassprite.getIconWidth()), Integer.lowestOneBit(textureatlassprite.getIconHeight())); + +// if (l1 < k) +// { +// Log.warn("Textur " + name + " mit Größe " + textureatlassprite.getIconWidth() + "x" + textureatlassprite.getIconHeight() + " begrenzt Mipmap-Level von " + MathHelper.calculateLogBaseTwo(k) + " auf " + MathHelper.calculateLogBaseTwo(l1)); +// k = l1; +// } + + stitcher.addSprite(textureatlassprite); + } + +// int j1 = Math.min(j, k); +// int k1 = MathHelper.calculateLogBaseTwo(j1); +// +// if (k1 < this.mipmapLevels) +// { +// Log.warn(this.basePath + ": setze Mipmap-Level von " + this.mipmapLevels + " auf " + k1 + " herab, wegen der kleinsten Größe mit Potenz von zwei: " + j1); +// this.mipmapLevels = k1; +// } + +// for (final TextureAtlasSprite textureatlassprite1 : this.mapRegisteredSprites.values()) +// { +// textureatlassprite1.generateMipmaps(this.mipmapLevels); +// } +// +// this.missingImage.generateMipmaps(this.mipmapLevels); + stitcher.addSprite(this.missingImage); + + try + { + stitcher.doStitch(); + } + catch (IndexOutOfBoundsException stitcherexception) + { + throw stitcherexception; + } + + Log.JNI.info("Textur-Atlas in Größe " + stitcher.getCurrentWidth() + "x" + stitcher.getCurrentHeight() + " erstellt"); + TextureUtil.allocateTexture(this.getGlTextureId(), stitcher.getCurrentWidth(), stitcher.getCurrentHeight()); + Map map = Maps.newHashMap(this.mapRegisteredSprites); + + for (TextureAtlasSprite textureatlassprite2 : stitcher.getStichSlots()) + { + String s = textureatlassprite2.getIconName(); + map.remove(s); + this.mapUploadedSprites.put(s, textureatlassprite2); + + TextureUtil.uploadTexture(textureatlassprite2.getFrameTextureData(0), textureatlassprite2.getIconWidth(), textureatlassprite2.getIconHeight(), textureatlassprite2.getOriginX(), textureatlassprite2.getOriginY()); + + if (textureatlassprite2.isAnimated()) + { + this.listAnimatedSprites.add(textureatlassprite2); + } + } + + for (TextureAtlasSprite textureatlassprite3 : map.values()) + { + textureatlassprite3.copyFrom(this.missingImage); + } + } + + public TextureAtlasSprite getAtlasSprite(String iconName) + { + TextureAtlasSprite textureatlassprite = (TextureAtlasSprite)this.mapUploadedSprites.get(iconName); + + if (textureatlassprite == null) + { + textureatlassprite = this.missingImage; + } + + return textureatlassprite; + } + + public void updateAnimations() + { + GlState.bindTexture(this.getGlTextureId()); + + for (TextureAtlasSprite textureatlassprite : this.listAnimatedSprites) + { + textureatlassprite.updateAnimation(); + } + } + + public TextureAtlasSprite registerSprite(String location) + { + if (location == null) + { + throw new IllegalArgumentException("Location kann nicht Null sein!"); + } + else + { + TextureAtlasSprite textureatlassprite = (TextureAtlasSprite)this.mapRegisteredSprites.get(location.toString()); + + if (textureatlassprite == null) + { + textureatlassprite = new TextureAtlasSprite(location); + this.mapRegisteredSprites.put(location.toString(), textureatlassprite); + } + + return textureatlassprite; + } + } + +// public void tick() +// { +// this.updateAnimations(); +// } + + public TextureAtlasSprite getMissingSprite() + { + return this.missingImage; + } +} diff --git a/client/src/client/renderer/texture/TextureTicked.java b/client/src/client/renderer/texture/TextureTicked.java new file mode 100755 index 00000000..b2f0fa68 --- /dev/null +++ b/client/src/client/renderer/texture/TextureTicked.java @@ -0,0 +1,9 @@ +package client.renderer.texture; + +public abstract class TextureTicked { + public abstract void renderStep(int[] data); + + public int getSize() { + return 16; + } +} diff --git a/client/src/main/java/client/renderer/texture/TextureUtil.java b/client/src/client/renderer/texture/TextureUtil.java similarity index 89% rename from client/src/main/java/client/renderer/texture/TextureUtil.java rename to client/src/client/renderer/texture/TextureUtil.java index c50703e3..71bced92 100755 --- a/client/src/main/java/client/renderer/texture/TextureUtil.java +++ b/client/src/client/renderer/texture/TextureUtil.java @@ -15,13 +15,13 @@ import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import client.renderer.GlState; -import client.util.FileUtils; +import common.util.FileUtils; public class TextureUtil { private static final IntBuffer BUFFER = ByteBuffer.allocateDirect(4194304 << 2).order(ByteOrder.nativeOrder()).asIntBuffer(); public static final DynamicTexture MISSING = new DynamicTexture(16, 16); - public static final int[] MISSING_DATA = MISSING.getData(); + public static final int[] MISSING_DATA = MISSING.getTextureData(); public static void uploadTexture(int[] data, int w, int h, int x, int y) { @@ -75,6 +75,12 @@ public class TextureUtil { // GlState.deleteTexture(id); //TODO: check needed GlState.bindTexture(id); + +// SKC.glTexParameteri(SKC.GL_TEXTURE_2D, SKC.GL_TEXTURE_MAX_LEVEL, 0); +// SKC.glTexParameterf(SKC.GL_TEXTURE_2D, SKC.GL_TEXTURE_MIN_LOD, 0.0F); +// SKC.glTexParameterf(SKC.GL_TEXTURE_2D, SKC.GL_TEXTURE_MAX_LOD, 0.0F); +// SKC.glTexParameterf(SKC.GL_TEXTURE_2D, SKC.GL_TEXTURE_LOD_BIAS, 0.0F); + GL11.nglTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, NULL); } @@ -124,6 +130,6 @@ public class TextureUtil System.arraycopy(l < k ? aint1 : aint, 0, MISSING_DATA, 16 * l + k, k); } - MISSING.updateTexture(); + MISSING.updateDynamicTexture(); } } diff --git a/client/src/client/renderer/ticked/TextureFlamesFX1.java b/client/src/client/renderer/ticked/TextureFlamesFX1.java new file mode 100755 index 00000000..6b070935 --- /dev/null +++ b/client/src/client/renderer/ticked/TextureFlamesFX1.java @@ -0,0 +1,87 @@ +package client.renderer.ticked; + +import client.renderer.texture.TextureTicked; + + +public class TextureFlamesFX1 extends TextureTicked +{ + + public TextureFlamesFX1() + { + field_1133_g = new float[320]; + field_1132_h = new float[320]; + } + + public void renderStep(int textureData[]) + { + for(int i = 0; i < 16; i++) + { + for(int j = 0; j < 20; j++) + { + int l = 18; + float f1 = field_1133_g[i + ((j + 1) % 20) * 16] * (float)l; + for(int i1 = i - 1; i1 <= i + 1; i1++) + { + for(int k1 = j; k1 <= j + 1; k1++) + { + int i2 = i1; + int k2 = k1; + if(i2 >= 0 && k2 >= 0 && i2 < 16 && k2 < 20) + { + f1 += field_1133_g[i2 + k2 * 16]; + } + l++; + } + + } + + field_1132_h[i + j * 16] = f1 / ((float)l * 1.06F); + if(j >= 19) + { + field_1132_h[i + j * 16] = (float)(Math.random() * Math.random() * Math.random() * 4D + Math.random() * 0.10000000149011612D + 0.20000000298023224D); + } + } + + } + + float af[] = field_1132_h; + field_1132_h = field_1133_g; + field_1133_g = af; + for(int k = 0; k < 256; k++) + { + float f = field_1133_g[k] * 1.8F; + if(f > 1.0F) + { + f = 1.0F; + } + if(f < 0.0F) + { + f = 0.0F; + } + float f2 = f; + int j1 = (int)(f2 * 155F + 100F); + int l1 = (int)(f2 * f2 * 255F); + int j2 = (int)(f2 * f2 * f2 * f2 * f2 * f2 * f2 * f2 * f2 * f2 * 255F); + int c = 255; + if(f2 < 0.5F) + { + c = 0; + } + f2 = (f2 - 0.5F) * 2.0F; +// if(flag) +// { +// int l2 = (j1 * 30 + l1 * 59 + j2 * 11) / 100; +// int i3 = (j1 * 30 + l1 * 70) / 100; +// int j3 = (j1 * 30 + j2 * 70) / 100; +// j1 = l2; +// l1 = i3; +// j2 = j3; +// } + textureData[k] = (c << 24) | (j1 << 16) | (l1 << 8) | j2; + } + + } + + protected float field_1133_g[]; + protected float field_1132_h[]; +} diff --git a/client/src/client/renderer/ticked/TextureFlamesFX2.java b/client/src/client/renderer/ticked/TextureFlamesFX2.java new file mode 100755 index 00000000..615af67e --- /dev/null +++ b/client/src/client/renderer/ticked/TextureFlamesFX2.java @@ -0,0 +1,11 @@ +package client.renderer.ticked; + +public class TextureFlamesFX2 extends TextureFlamesFX1 { + public TextureFlamesFX2() + { + int[] tex = new int[256]; + for(int z = 0; z < 160; z++) { + this.renderStep(tex); + } + } +} diff --git a/client/src/client/renderer/ticked/TextureLavaFX.java b/client/src/client/renderer/ticked/TextureLavaFX.java new file mode 100755 index 00000000..af7811d0 --- /dev/null +++ b/client/src/client/renderer/ticked/TextureLavaFX.java @@ -0,0 +1,88 @@ +package client.renderer.ticked; + +import client.renderer.texture.TextureTicked; +import common.util.ExtMath; + +public class TextureLavaFX extends TextureTicked +{ + + public TextureLavaFX() + { + field_1147_g = new float[256]; + field_1146_h = new float[256]; + field_1145_i = new float[256]; + field_1144_j = new float[256]; + } + + public void renderStep(int textureData[]) + { + for(int i = 0; i < 16; i++) + { + for(int j = 0; j < 16; j++) + { + float f = 0.0F; + int l = (int)(ExtMath.sin(((float)j * 3.141593F * 2.0F) / 16F) * 1.2F); + int i1 = (int)(ExtMath.sin(((float)i * 3.141593F * 2.0F) / 16F) * 1.2F); + for(int k1 = i - 1; k1 <= i + 1; k1++) + { + for(int i2 = j - 1; i2 <= j + 1; i2++) + { + int k2 = k1 + l & 0xf; + int i3 = i2 + i1 & 0xf; + f += field_1147_g[k2 + i3 * 16]; + } + + } + + field_1146_h[i + j * 16] = f / 10F + ((field_1145_i[(i + 0 & 0xf) + (j + 0 & 0xf) * 16] + field_1145_i[(i + 1 & 0xf) + (j + 0 & 0xf) * 16] + field_1145_i[(i + 1 & 0xf) + (j + 1 & 0xf) * 16] + field_1145_i[(i + 0 & 0xf) + (j + 1 & 0xf) * 16]) / 4F) * 0.8F; + field_1145_i[i + j * 16] += field_1144_j[i + j * 16] * 0.01F; + if(field_1145_i[i + j * 16] < 0.0F) + { + field_1145_i[i + j * 16] = 0.0F; + } + field_1144_j[i + j * 16] -= 0.06F; + if(Math.random() < 0.0050000000000000001D) + { + field_1144_j[i + j * 16] = 1.5F; + } + } + + } + + float af[] = field_1146_h; + field_1146_h = field_1147_g; + field_1147_g = af; + for(int k = 0; k < 256; k++) + { + float f1 = field_1147_g[k] * 2.0F; + if(f1 > 1.0F) + { + f1 = 1.0F; + } + if(f1 < 0.0F) + { + f1 = 0.0F; + } + float f2 = f1; + int j1 = (int)(f2 * 100F + 155F); + int l1 = (int)(f2 * f2 * 255F); + int j2 = (int)(f2 * f2 * f2 * f2 * 128F); +// if(flag) +// { +// int l2 = (j1 * 30 + l1 * 59 + j2 * 11) / 100; +// int j3 = (j1 * 30 + l1 * 70) / 100; +// int k3 = (j1 * 30 + j2 * 70) / 100; +// j1 = l2; +// l1 = j3; +// j2 = k3; +// } + textureData[k] = (255 << 24) | (j1 << 16) | (l1 << 8) | j2; + } + + } + + protected float field_1147_g[]; + protected float field_1146_h[]; + protected float field_1145_i[]; + protected float field_1144_j[]; +} diff --git a/client/src/client/renderer/ticked/TextureLavaFlowFX.java b/client/src/client/renderer/ticked/TextureLavaFlowFX.java new file mode 100755 index 00000000..2948f938 --- /dev/null +++ b/client/src/client/renderer/ticked/TextureLavaFlowFX.java @@ -0,0 +1,97 @@ +package client.renderer.ticked; + +import client.renderer.texture.TextureTicked; +import common.util.ExtMath; + +public class TextureLavaFlowFX extends TextureTicked +{ + + public TextureLavaFlowFX() + { + field_1143_g = new float[256]; + field_1142_h = new float[256]; + field_1141_i = new float[256]; + field_1140_j = new float[256]; + field_1139_k = 0; + } + + public void renderStep(int textureData[]) + { + field_1139_k++; + for(int i = 0; i < 16; i++) + { + for(int j = 0; j < 16; j++) + { + float f = 0.0F; + int l = (int)(ExtMath.sin(((float)j * 3.141593F * 2.0F) / 16F) * 1.2F); + int i1 = (int)(ExtMath.sin(((float)i * 3.141593F * 2.0F) / 16F) * 1.2F); + for(int k1 = i - 1; k1 <= i + 1; k1++) + { + for(int i2 = j - 1; i2 <= j + 1; i2++) + { + int k2 = k1 + l & 0xf; + int i3 = i2 + i1 & 0xf; + f += field_1143_g[k2 + i3 * 16]; + } + + } + + field_1142_h[i + j * 16] = f / 10F + ((field_1141_i[(i + 0 & 0xf) + (j + 0 & 0xf) * 16] + field_1141_i[(i + 1 & 0xf) + (j + 0 & 0xf) * 16] + field_1141_i[(i + 1 & 0xf) + (j + 1 & 0xf) * 16] + field_1141_i[(i + 0 & 0xf) + (j + 1 & 0xf) * 16]) / 4F) * 0.8F; + field_1141_i[i + j * 16] += field_1140_j[i + j * 16] * 0.01F; + if(field_1141_i[i + j * 16] < 0.0F) + { + field_1141_i[i + j * 16] = 0.0F; + } + field_1140_j[i + j * 16] -= 0.06F; + if(Math.random() < 0.0050000000000000001D) + { + field_1140_j[i + j * 16] = 1.5F; + } + } + + } + + float af[] = field_1142_h; + field_1142_h = field_1143_g; + field_1143_g = af; + for(int k = 0; k < 256; k++) + { + float f1 = field_1143_g[k - (field_1139_k / 3) * 16 & 0xff] * 2.0F; + if(f1 > 1.0F) + { + f1 = 1.0F; + } + if(f1 < 0.0F) + { + f1 = 0.0F; + } + float f2 = f1; + int j1 = (int)(f2 * 100F + 155F); + int l1 = (int)(f2 * f2 * 255F); + int j2 = (int)(f2 * f2 * f2 * f2 * 128F); +// if(flag) +// { +// int l2 = (j1 * 30 + l1 * 59 + j2 * 11) / 100; +// int j3 = (j1 * 30 + l1 * 70) / 100; +// int k3 = (j1 * 30 + j2 * 70) / 100; +// j1 = l2; +// l1 = j3; +// j2 = k3; +// } + textureData[(k & 0x0f) | ((k & 0xf0) * 2)] = textureData[((k & 0x0f) + 16) | ((k & 0xf0) * 2)] = + textureData[(k & 0x0f) | (((k & 0xf0) + 256) * 2)] = textureData[((k & 0x0f) + 16) | (((k & 0xf0) + 256) * 2)] = + (255 << 24) | (j1 << 16) | (l1 << 8) | j2; + } + + } + + public int getSize() { + return 32; + } + + protected float field_1143_g[]; + protected float field_1142_h[]; + protected float field_1141_i[]; + protected float field_1140_j[]; + int field_1139_k; +} diff --git a/client/src/client/renderer/ticked/TextureWaterFX.java b/client/src/client/renderer/ticked/TextureWaterFX.java new file mode 100755 index 00000000..be5a276f --- /dev/null +++ b/client/src/client/renderer/ticked/TextureWaterFX.java @@ -0,0 +1,94 @@ +package client.renderer.ticked; + +import client.renderer.texture.TextureTicked; + + +public class TextureWaterFX extends TextureTicked +{ + + public TextureWaterFX() + { + field_1158_g = new float[256]; + field_1157_h = new float[256]; + field_1156_i = new float[256]; + field_1155_j = new float[256]; + tickCounter = 0; + } + + public void renderStep(int textureData[]) + { + tickCounter++; + for(int i = 0; i < 16; i++) + { + for(int k = 0; k < 16; k++) + { + float f = 0.0F; + for(int j1 = i - 1; j1 <= i + 1; j1++) + { + int k1 = j1 & 0xf; + int i2 = k & 0xf; + f += field_1158_g[k1 + i2 * 16]; + } + + field_1157_h[i + k * 16] = f / 3.3F + field_1156_i[i + k * 16] * 0.8F; + } + + } + + for(int j = 0; j < 16; j++) + { + for(int l = 0; l < 16; l++) + { + field_1156_i[j + l * 16] += field_1155_j[j + l * 16] * 0.05F; + if(field_1156_i[j + l * 16] < 0.0F) + { + field_1156_i[j + l * 16] = 0.0F; + } + field_1155_j[j + l * 16] -= 0.1F; + if(Math.random() < 0.050000000000000003D) + { + field_1155_j[j + l * 16] = 0.5F; + } + } + + } + + float af[] = field_1157_h; + field_1157_h = field_1158_g; + field_1158_g = af; + for(int i1 = 0; i1 < 256; i1++) + { + float f1 = field_1158_g[i1]; + if(f1 > 1.0F) + { + f1 = 1.0F; + } + if(f1 < 0.0F) + { + f1 = 0.0F; + } + float f2 = f1 * f1; + int l1 = (int)(32F + f2 * 32F); + int j2 = (int)(50F + f2 * 64F); + int k2 = 255; + int l2 = (int)(146F + f2 * 50F); +// if(flag) +// { +// int i3 = (l1 * 30 + j2 * 59 + k2 * 11) / 100; +// int j3 = (l1 * 30 + j2 * 70) / 100; +// int k3 = (l1 * 30 + k2 * 70) / 100; +// l1 = i3; +// j2 = j3; +// k2 = k3; +// } + textureData[i1] = (l2 << 24) | (l1 << 16) | (j2 << 8) | k2; + } + + } + + protected float field_1158_g[]; + protected float field_1157_h[]; + protected float field_1156_i[]; + protected float field_1155_j[]; + private int tickCounter; +} diff --git a/client/src/client/renderer/ticked/TextureWaterFlowFX.java b/client/src/client/renderer/ticked/TextureWaterFlowFX.java new file mode 100755 index 00000000..ebf64ef2 --- /dev/null +++ b/client/src/client/renderer/ticked/TextureWaterFlowFX.java @@ -0,0 +1,100 @@ +package client.renderer.ticked; + +import client.renderer.texture.TextureTicked; + + +public class TextureWaterFlowFX extends TextureTicked +{ + + public TextureWaterFlowFX() + { + field_1138_g = new float[256]; + field_1137_h = new float[256]; + field_1136_i = new float[256]; + field_1135_j = new float[256]; + field_1134_k = 0; + } + + public void renderStep(int textureData[]) + { + field_1134_k++; + for(int i = 0; i < 16; i++) + { + for(int k = 0; k < 16; k++) + { + float f = 0.0F; + for(int j1 = k - 2; j1 <= k; j1++) + { + int k1 = i & 0xf; + int i2 = j1 & 0xf; + f += field_1138_g[k1 + i2 * 16]; + } + + field_1137_h[i + k * 16] = f / 3.2F + field_1136_i[i + k * 16] * 0.8F; + } + + } + + for(int j = 0; j < 16; j++) + { + for(int l = 0; l < 16; l++) + { + field_1136_i[j + l * 16] += field_1135_j[j + l * 16] * 0.05F; + if(field_1136_i[j + l * 16] < 0.0F) + { + field_1136_i[j + l * 16] = 0.0F; + } + field_1135_j[j + l * 16] -= 0.3F; + if(Math.random() < 0.20000000000000001D) + { + field_1135_j[j + l * 16] = 0.5F; + } + } + + } + + float af[] = field_1137_h; + field_1137_h = field_1138_g; + field_1138_g = af; + for(int i1 = 0; i1 < 256; i1++) + { + float f1 = field_1138_g[i1 - field_1134_k * 16 & 0xff]; + if(f1 > 1.0F) + { + f1 = 1.0F; + } + if(f1 < 0.0F) + { + f1 = 0.0F; + } + float f2 = f1 * f1; + int l1 = (int)(32F + f2 * 32F); + int j2 = (int)(50F + f2 * 64F); + int k2 = 255; + int l2 = (int)(146F + f2 * 50F); +// if(flag) +// { +// int i3 = (l1 * 30 + j2 * 59 + k2 * 11) / 100; +// int j3 = (l1 * 30 + j2 * 70) / 100; +// int k3 = (l1 * 30 + k2 * 70) / 100; +// l1 = i3; +// j2 = j3; +// k2 = k3; +// } + textureData[(i1 & 0x0f) | ((i1 & 0xf0) * 2)] = textureData[((i1 & 0x0f) + 16) | ((i1 & 0xf0) * 2)] = + textureData[(i1 & 0x0f) | (((i1 & 0xf0) + 256) * 2)] = textureData[((i1 & 0x0f) + 16) | (((i1 & 0xf0) + 256) * 2)] = + (l2 << 24) | (l1 << 16) | (j2 << 8) | k2; + } + + } + + public int getSize() { + return 32; + } + + protected float field_1138_g[]; + protected float field_1137_h[]; + protected float field_1136_i[]; + protected float field_1135_j[]; + private int field_1134_k; +} diff --git a/client/src/client/renderer/tileentity/TileEntityBannerRenderer.java b/client/src/client/renderer/tileentity/TileEntityBannerRenderer.java new file mode 100755 index 00000000..c5188929 --- /dev/null +++ b/client/src/client/renderer/tileentity/TileEntityBannerRenderer.java @@ -0,0 +1,154 @@ +package client.renderer.tileentity; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.lwjgl.opengl.GL11; + +import client.Client; +import client.renderer.GlState; +import client.renderer.model.ModelBanner; +import client.renderer.texture.LayeredColorMaskTexture; +import common.collect.Lists; +import common.collect.Maps; +import common.color.DyeColor; +import common.init.Blocks; +import common.tileentity.TileEntityBanner; +import common.util.BlockPos; +import common.util.ExtMath; + +public class TileEntityBannerRenderer extends TileEntitySpecialRenderer +{ + private static final Map DESIGNS = Maps.newHashMap(); + private static final String BANNERTEXTURES = "textures/blocks/banner.png"; + private ModelBanner bannerModel = new ModelBanner(); + + public void renderTileEntityAt(TileEntityBanner te, double x, double y, double z, float partialTicks, int destroyStage) + { + boolean flag = te.getWorld() != null; + boolean flag1 = !flag || te.getBlockType() == Blocks.banner; + int i = flag ? te.getBlockMetadata() : 0; +// long j = flag ? te.getWorld().getTime() : 0L; + double j = flag ? (double)(System.nanoTime() / 1000L) / 50000.0 /* te.getWorld().getTime() */ : (double)partialTicks; + GL11.glPushMatrix(); + float f = 0.6666667F; + + if (flag1) + { + GL11.glTranslatef((float)x + 0.5F, (float)y + 0.75F * f, (float)z + 0.5F); + float f1 = (float)(i * 360) / 16.0F; + GL11.glRotatef(-f1, 0.0F, 1.0F, 0.0F); + this.bannerModel.bannerStand.showModel = true; + } + else + { + float f2 = 0.0F; + + if (i == 2) + { + f2 = 180.0F; + } + + if (i == 4) + { + f2 = 90.0F; + } + + if (i == 5) + { + f2 = -90.0F; + } + + GL11.glTranslatef((float)x + 0.5F, (float)y - 0.25F * f, (float)z + 0.5F); + GL11.glRotatef(-f2, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(0.0F, -0.3125F, -0.4375F); + this.bannerModel.bannerStand.showModel = false; + } + + BlockPos blockpos = te.getPos(); + float f3 = (float)(blockpos.getX() * 7 + blockpos.getY() * 9 + blockpos.getZ() * 13) + (float)j; // + partialTicks; + this.bannerModel.bannerSlate.rotateAngleX = (-0.0125F + 0.01F * ExtMath.cos(f3 * (float)Math.PI * 0.02F)) * (float)Math.PI; + GlState.enableRescaleNormal(); + String resourcelocation = this.func_178463_a(te); + + if (resourcelocation != null) + { + this.bindTexture(resourcelocation); + GL11.glPushMatrix(); + GL11.glScalef(f, -f, -f); + this.bannerModel.renderBanner(); + GL11.glPopMatrix(); + } + + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glPopMatrix(); + } + + private String func_178463_a(TileEntityBanner bannerObj) + { + String s = bannerObj.getPatternResourceLocation(); + + if (s.isEmpty()) + { + return null; + } + else + { + TileEntityBannerRenderer.TimedBannerTexture tileentitybannerrenderer$timedbannertexture = (TileEntityBannerRenderer.TimedBannerTexture)DESIGNS.get(s); + + if (tileentitybannerrenderer$timedbannertexture == null) + { + if (DESIGNS.size() >= 256) + { + long i = System.currentTimeMillis(); + Iterator iterator = DESIGNS.keySet().iterator(); + + while (iterator.hasNext()) + { + String s1 = (String)iterator.next(); + TileEntityBannerRenderer.TimedBannerTexture tileentitybannerrenderer$timedbannertexture1 = (TileEntityBannerRenderer.TimedBannerTexture)DESIGNS.get(s1); + + if (i - tileentitybannerrenderer$timedbannertexture1.systemTime > 60000L) + { + Client.CLIENT.getTextureManager().deleteTexture(tileentitybannerrenderer$timedbannertexture1.bannerTexture); + iterator.remove(); + } + } + + if (DESIGNS.size() >= 256) + { + return null; + } + } + + List list1 = bannerObj.getPatternList(); + List list = bannerObj.getColorList(); + List list2 = Lists.newArrayList(); + + for (TileEntityBanner.EnumBannerPattern tileentitybanner$enumbannerpattern : list1) + { + list2.add("textures/blocks/banner_" + tileentitybanner$enumbannerpattern.getPatternName() + ".png"); + } + + tileentitybannerrenderer$timedbannertexture = new TileEntityBannerRenderer.TimedBannerTexture(); + tileentitybannerrenderer$timedbannertexture.bannerTexture = s; + Client.CLIENT.getTextureManager().loadTexture(tileentitybannerrenderer$timedbannertexture.bannerTexture, new LayeredColorMaskTexture(BANNERTEXTURES, list2, list)); + DESIGNS.put(s, tileentitybannerrenderer$timedbannertexture); + } + + tileentitybannerrenderer$timedbannertexture.systemTime = System.currentTimeMillis(); + return tileentitybannerrenderer$timedbannertexture.bannerTexture; + } + } + + static class TimedBannerTexture + { + public long systemTime; + public String bannerTexture; + + private TimedBannerTexture() + { + } + } +} diff --git a/client/src/client/renderer/tileentity/TileEntityChestRenderer.java b/client/src/client/renderer/tileentity/TileEntityChestRenderer.java new file mode 100755 index 00000000..4fbb70fe --- /dev/null +++ b/client/src/client/renderer/tileentity/TileEntityChestRenderer.java @@ -0,0 +1,207 @@ +package client.renderer.tileentity; + +import org.lwjgl.opengl.GL11; + +import client.renderer.GlState; +import client.renderer.model.ModelChest; +import client.renderer.model.ModelLargeChest; +import common.block.Block; +import common.block.BlockChest; +import common.tileentity.TileEntityChest; + + +public class TileEntityChestRenderer extends TileEntitySpecialRenderer +{ + private static final String textureTrappedDouble = "textures/blocks/chest_trapped_double.png"; +// private static final ResourceLocation textureChristmasDouble = new ResourceLocation("textures/tile/chest_christmas_double.png"); + private static final String textureNormalDouble = "textures/blocks/chest_normal_double.png"; + private static final String textureTrapped = "textures/blocks/chest_trapped.png"; +// private static final ResourceLocation textureChristmas = new ResourceLocation("textures/tile/chest_christmas.png"); + private static final String textureNormal = "textures/blocks/chest_normal.png"; + + private ModelChest simpleChest = new ModelChest(); + private ModelChest largeChest = new ModelLargeChest(); +// private boolean isChristmas; + +// public TileEntityChestRenderer() +// { +// this.setChristmas(true); +// } + +// public void setChristmas(boolean xmas) { +// if(!xmas) { +// this.isChristmas = false; +// } +// else { +// Calendar calendar = Calendar.getInstance(); +// if(calendar.get(2) + 1 == 12 && calendar.get(5) >= 24 && calendar.get(5) <= 26) +// this.isChristmas = true; +// } +// } + + public void renderTileEntityAt(TileEntityChest te, double x, double y, double z, float partialTicks, int destroyStage) + { + GlState.enableDepth(); + GlState.depthFunc(GL11.GL_LEQUAL); + GlState.depthMask(true); + int i; + + if (!te.hasWorldObj()) + { + i = 0; + } + else + { + Block block = te.getBlockType(); + i = te.getBlockMetadata(); + + if (block instanceof BlockChest && i == 0) + { + ((BlockChest)block).checkForSurroundingChests(te.getWorld(), te.getPos(), te.getWorld().getState(te.getPos())); + i = te.getBlockMetadata(); + } + + te.checkForAdjacentChests(); + } + + if (te.adjacentChestZNeg == null && te.adjacentChestXNeg == null) + { + ModelChest modelchest; + + if (te.adjacentChestXPos == null && te.adjacentChestZPos == null) + { + modelchest = this.simpleChest; + + if (destroyStage >= 0) + { + this.bindTexture(DESTROY_STAGES[destroyStage]); + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glPushMatrix(); + GL11.glScalef(4.0F, 4.0F, 1.0F); + GL11.glTranslatef(0.0625F, 0.0625F, 0.0625F); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + } +// else if (this.isChristmas) +// { +// this.bindTexture(textureChristmas); +// } + else if (te.getChestType() == 1) + { + this.bindTexture(textureTrapped); + } + else + { + this.bindTexture(textureNormal); + } + } + else + { + modelchest = this.largeChest; + + if (destroyStage >= 0) + { + this.bindTexture(DESTROY_STAGES[destroyStage]); + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glPushMatrix(); + GL11.glScalef(8.0F, 4.0F, 1.0F); + GL11.glTranslatef(0.0625F, 0.0625F, 0.0625F); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + } +// else if (this.isChristmas) +// { +// this.bindTexture(textureChristmasDouble); +// } + else if (te.getChestType() == 1) + { + this.bindTexture(textureTrappedDouble); + } + else + { + this.bindTexture(textureNormalDouble); + } + } + + GL11.glPushMatrix(); + GlState.enableRescaleNormal(); + + if (destroyStage < 0) + { + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + } + + GL11.glTranslatef((float)x, (float)y + 1.0F, (float)z + 1.0F); + GL11.glScalef(1.0F, -1.0F, -1.0F); + GL11.glTranslatef(0.5F, 0.5F, 0.5F); + int j = 0; + + if (i == 2) + { + j = 180; + } + + if (i == 3) + { + j = 0; + } + + if (i == 4) + { + j = 90; + } + + if (i == 5) + { + j = -90; + } + + if (i == 2 && te.adjacentChestXPos != null) + { + GL11.glTranslatef(1.0F, 0.0F, 0.0F); + } + + if (i == 5 && te.adjacentChestZPos != null) + { + GL11.glTranslatef(0.0F, 0.0F, -1.0F); + } + + GL11.glRotatef((float)j, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + float f = te.prevLidAngle + (te.lidAngle - te.prevLidAngle) * partialTicks; + + if (te.adjacentChestZNeg != null) + { + float f1 = te.adjacentChestZNeg.prevLidAngle + (te.adjacentChestZNeg.lidAngle - te.adjacentChestZNeg.prevLidAngle) * partialTicks; + + if (f1 > f) + { + f = f1; + } + } + + if (te.adjacentChestXNeg != null) + { + float f2 = te.adjacentChestXNeg.prevLidAngle + (te.adjacentChestXNeg.lidAngle - te.adjacentChestXNeg.prevLidAngle) * partialTicks; + + if (f2 > f) + { + f = f2; + } + } + + f = 1.0F - f; + f = 1.0F - f * f * f; + modelchest.chestLid.rotateAngleX = -(f * (float)Math.PI / 2.0F); + modelchest.renderAll(); + GlState.disableRescaleNormal(); + GL11.glPopMatrix(); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + + if (destroyStage >= 0) + { + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glPopMatrix(); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + } + } + } +} diff --git a/client/src/client/renderer/tileentity/TileEntityItemStackRenderer.java b/client/src/client/renderer/tileentity/TileEntityItemStackRenderer.java new file mode 100755 index 00000000..df617b08 --- /dev/null +++ b/client/src/client/renderer/tileentity/TileEntityItemStackRenderer.java @@ -0,0 +1,76 @@ +package client.renderer.tileentity; + +import org.lwjgl.opengl.GL11; + +import client.renderer.GlState; +import common.block.Block; +import common.init.Blocks; +import common.init.Items; +import common.item.ItemStack; +import common.tileentity.TileEntityBanner; +import common.tileentity.TileEntityChest; +import common.tileentity.TileEntitySkull; +import common.util.Facing; + +public class TileEntityItemStackRenderer +{ + public static TileEntityItemStackRenderer instance = new TileEntityItemStackRenderer(); + private TileEntityChest field_147717_b = new TileEntityChest(0); + private TileEntityChest field_147718_c = new TileEntityChest(1); +// private TileEntityWarpChest warpChest = new TileEntityWarpChest(); + private TileEntityBanner banner = new TileEntityBanner(); + private TileEntitySkull skull = new TileEntitySkull(); + + public void renderByItem(ItemStack itemStackIn) + { + if (itemStackIn.getItem() == Items.banner) + { + this.banner.setItemValues(itemStackIn); + TileEntityRendererDispatcher.instance.renderTileEntityAt(this.banner, 0.0D, 0.0D, 0.0D, 0.0F); + } + else if (itemStackIn.getItem() == Items.skull) + { +// String user = null; +// +// if (itemStackIn.hasTagCompound()) +// { +// NBTTagCompound nbttagcompound = itemStackIn.getTagCompound(); +// +// if (nbttagcompound.hasKey("SkullOwner", 8) && nbttagcompound.getString("SkullOwner").length() > 0) +// { +// user = nbttagcompound.getString("SkullOwner"); +// } +// } + + if (TileEntitySkullRenderer.instance != null) + { + GL11.glPushMatrix(); + GL11.glTranslatef(-0.5F, 0.0F, -0.5F); + GL11.glScalef(2.0F, 2.0F, 2.0F); + boolean flag = GlState.isCullEnabled(); + GlState.disableCull(); + TileEntitySkullRenderer.instance.renderSkull(0.0F, 0.0F, 0.0F, Facing.UP, 0.0F, -1); + if(flag) + GlState.enableCull(); + GL11.glPopMatrix(); + } + } + else + { + Block block = itemStackIn.getItem().getBlock(); + +// if (block == Blocks.warp_chest) +// { +// TileEntityRendererDispatcher.instance.renderTileEntityAt(this.warpChest, 0.0D, 0.0D, 0.0D, 0.0F); +// } + if (block == Blocks.trapped_chest) + { + TileEntityRendererDispatcher.instance.renderTileEntityAt(this.field_147718_c, 0.0D, 0.0D, 0.0D, 0.0F); + } + else + { + TileEntityRendererDispatcher.instance.renderTileEntityAt(this.field_147717_b, 0.0D, 0.0D, 0.0D, 0.0F); + } + } + } +} diff --git a/client/src/client/renderer/tileentity/TileEntityMobSpawnerRenderer.java b/client/src/client/renderer/tileentity/TileEntityMobSpawnerRenderer.java new file mode 100755 index 00000000..ae555c70 --- /dev/null +++ b/client/src/client/renderer/tileentity/TileEntityMobSpawnerRenderer.java @@ -0,0 +1,38 @@ +package client.renderer.tileentity; + +import org.lwjgl.opengl.GL11; + +import client.Client; +import common.entity.Entity; +import common.tileentity.TileEntityMobSpawner; + +public class TileEntityMobSpawnerRenderer extends TileEntitySpecialRenderer +{ + public void renderTileEntityAt(TileEntityMobSpawner te, double x, double y, double z, float partialTicks, int destroyStage) + { + GL11.glPushMatrix(); + GL11.glTranslatef((float)x + 0.5F, (float)y, (float)z + 0.5F); + renderMob(te, x, y, z, partialTicks); + GL11.glPopMatrix(); + } + + /** + * Render the mob inside the mob spawner. + */ + public static void renderMob(TileEntityMobSpawner mobSpawnerLogic, double posX, double posY, double posZ, float partialTicks) + { + Entity entity = mobSpawnerLogic.createRenderEntity(mobSpawnerLogic.getWorld()); + + if (entity != null) + { + float f = 0.4375F; + GL11.glTranslatef(0.0F, 0.4F, 0.0F); + GL11.glRotatef((float)(mobSpawnerLogic.getPrevMobRotation() + (mobSpawnerLogic.getMobRotation() - mobSpawnerLogic.getPrevMobRotation()) * (double)partialTicks) * 10.0F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(-30.0F, 1.0F, 0.0F, 0.0F); + GL11.glTranslatef(0.0F, -0.4F, 0.0F); + GL11.glScalef(f, f, f); + entity.setLocationAndAngles(posX, posY, posZ, 0.0F, 0.0F); + Client.CLIENT.getRenderManager().renderEntity(entity, 0.0D, 0.0D, 0.0D, partialTicks); + } + } +} diff --git a/client/src/client/renderer/tileentity/TileEntityPistonRenderer.java b/client/src/client/renderer/tileentity/TileEntityPistonRenderer.java new file mode 100755 index 00000000..ce055f10 --- /dev/null +++ b/client/src/client/renderer/tileentity/TileEntityPistonRenderer.java @@ -0,0 +1,81 @@ +package client.renderer.tileentity; + +import org.lwjgl.opengl.GL11; + +import client.Client; +import client.renderer.BlockRenderer; +import client.renderer.DefaultVertexFormats; +import client.renderer.GlState; +import client.renderer.ItemRenderer; +import client.renderer.RenderBuffer; +import client.renderer.Tessellator; +import client.renderer.texture.TextureMap; +import common.block.Block; +import common.block.BlockPistonBase; +import common.block.BlockPistonHead; +import common.init.Blocks; +import common.material.Material; +import common.tileentity.TileEntityPiston; +import common.util.BlockPos; +import common.world.State; +import common.world.World; + +public class TileEntityPistonRenderer extends TileEntitySpecialRenderer +{ + private final BlockRenderer blockRenderer = Client.CLIENT.getBlockRendererDispatcher(); + + public void renderTileEntityAt(TileEntityPiston te, double x, double y, double z, float partialTicks, int destroyStage) + { + BlockPos blockpos = te.getPos(); + State iblockstate = te.getPistonState(); + Block block = iblockstate.getBlock(); + + if (block.getMaterial() != Material.air && te.getProgress(partialTicks) < 1.0F) + { +// Tessellator tessellator = Tessellator.getInstance(); + RenderBuffer worldrenderer = Tessellator.getBuffer(); + this.bindTexture(TextureMap.locationBlocksTexture); + ItemRenderer.disableStandardItemLighting(); + GlState.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlState.enableBlend(); + GlState.disableCull(); + +// if (Game.getGame().isAmbientOcclusionEnabled()) +// { +// GlState.shadeModel(GL11.GL_SMOOTH); +// } +// else +// { + GlState.shadeModel(GL11.GL_FLAT); +// } + + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); + worldrenderer.setTranslation((double)((float)x - (float)blockpos.getX() + te.getOffsetX(partialTicks)), (double)((float)y - (float)blockpos.getY() + te.getOffsetY(partialTicks)), (double)((float)z - (float)blockpos.getZ() + te.getOffsetZ(partialTicks))); + World world = this.getWorld(); + + if (block == Blocks.piston_head && te.getProgress(partialTicks) < 0.5F) + { + iblockstate = iblockstate.withProperty(BlockPistonHead.SHORT, Boolean.valueOf(true)); + this.blockRenderer.renderModel(world, this.blockRenderer.getModelFromBlockState(iblockstate, world, blockpos), iblockstate, blockpos, worldrenderer, true); + } + else if (te.shouldPistonHeadBeRendered() && !te.isExtending()) + { + BlockPistonHead.EnumPistonType blockpistonextension$enumpistontype = block == Blocks.sticky_piston ? BlockPistonHead.EnumPistonType.STICKY : BlockPistonHead.EnumPistonType.DEFAULT; + State iblockstate1 = Blocks.piston_head.getState().withProperty(BlockPistonHead.TYPE, blockpistonextension$enumpistontype).withProperty(BlockPistonHead.FACING, iblockstate.getValue(BlockPistonBase.FACING)); + iblockstate1 = iblockstate1.withProperty(BlockPistonHead.SHORT, Boolean.valueOf(te.getProgress(partialTicks) >= 0.5F)); + this.blockRenderer.renderModel(world, this.blockRenderer.getModelFromBlockState(iblockstate1, world, blockpos), iblockstate1, blockpos, worldrenderer, true); + worldrenderer.setTranslation((double)((float)x - (float)blockpos.getX()), (double)((float)y - (float)blockpos.getY()), (double)((float)z - (float)blockpos.getZ())); + iblockstate.withProperty(BlockPistonBase.EXTENDED, Boolean.valueOf(true)); + this.blockRenderer.renderModel(world, this.blockRenderer.getModelFromBlockState(iblockstate, world, blockpos), iblockstate, blockpos, worldrenderer, true); + } + else + { + this.blockRenderer.renderModel(world, this.blockRenderer.getModelFromBlockState(iblockstate, world, blockpos), iblockstate, blockpos, worldrenderer, false); + } + + worldrenderer.setTranslation(0.0D, 0.0D, 0.0D); + Tessellator.draw(); + ItemRenderer.enableStandardItemLighting(); + } + } +} diff --git a/client/src/client/renderer/tileentity/TileEntityRendererDispatcher.java b/client/src/client/renderer/tileentity/TileEntityRendererDispatcher.java new file mode 100755 index 00000000..d491221a --- /dev/null +++ b/client/src/client/renderer/tileentity/TileEntityRendererDispatcher.java @@ -0,0 +1,143 @@ +package client.renderer.tileentity; + +import java.util.Map; + +import org.lwjgl.opengl.GL13; + +import client.renderer.GlState; +import client.renderer.texture.TextureManager; +import common.collect.Maps; +import common.entity.Entity; +import common.tileentity.TileEntity; +import common.tileentity.TileEntityBanner; +import common.tileentity.TileEntityChest; +import common.tileentity.TileEntityMobSpawner; +import common.tileentity.TileEntityPiston; +import common.tileentity.TileEntitySign; +import common.tileentity.TileEntitySkull; +import common.util.BlockPos; +import common.world.World; + +public class TileEntityRendererDispatcher +{ + private Map < Class , TileEntitySpecialRenderer > mapSpecialRenderers = Maps. < Class , TileEntitySpecialRenderer > newHashMap(); + public static TileEntityRendererDispatcher instance = new TileEntityRendererDispatcher(); +// private FontRenderer fontRenderer; + + /** 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 renderEngine; + public World worldObj; + public Entity entity; + public float entityYaw; + public float entityPitch; + public double entityX; + public double entityY; + public double entityZ; + +// public static void setChristmas(boolean xmas) { +// ((TileEntityChestRenderer)instance.mapSpecialRenderers.get(TileEntityChest.class)).setChristmas(xmas); +// } + + private TileEntityRendererDispatcher() + { + this.mapSpecialRenderers.put(TileEntitySign.class, new TileEntitySignRenderer()); + this.mapSpecialRenderers.put(TileEntityMobSpawner.class, new TileEntityMobSpawnerRenderer()); + this.mapSpecialRenderers.put(TileEntityPiston.class, new TileEntityPistonRenderer()); + this.mapSpecialRenderers.put(TileEntityChest.class, new TileEntityChestRenderer()); +// this.mapSpecialRenderers.put(TileEntityWarpChest.class, new TileEntityWarpChestRenderer()); +// this.mapSpecialRenderers.put(TileEntityEnchantmentTable.class, new TileEntityEnchantmentTableRenderer()); +// this.mapSpecialRenderers.put(TileEntityPortal.class, new TileEntityPortalRenderer()); +// this.mapSpecialRenderers.put(TileEntityBeacon.class, new TileEntityBeaconRenderer()); + this.mapSpecialRenderers.put(TileEntitySkull.class, new TileEntitySkullRenderer()); + this.mapSpecialRenderers.put(TileEntityBanner.class, new TileEntityBannerRenderer()); + + for (TileEntitySpecialRenderer tileentityspecialrenderer : this.mapSpecialRenderers.values()) + { + tileentityspecialrenderer.setRendererDispatcher(this); + } + } + + public TileEntitySpecialRenderer getSpecialRendererByClass(Class teClass) + { + TileEntitySpecialRenderer tileentityspecialrenderer = (TileEntitySpecialRenderer)this.mapSpecialRenderers.get(teClass); + + if (tileentityspecialrenderer == null && teClass != TileEntity.class) + { + tileentityspecialrenderer = this.getSpecialRendererByClass((Class )teClass.getSuperclass()); + this.mapSpecialRenderers.put(teClass, tileentityspecialrenderer); + } + + return (TileEntitySpecialRenderer)tileentityspecialrenderer; + } + + public TileEntitySpecialRenderer getSpecialRenderer(TileEntity tileEntityIn) + { + return (TileEntitySpecialRenderer)(tileEntityIn == null ? null : this.getSpecialRendererByClass(tileEntityIn.getClass())); + } + + public void cacheActiveRenderInfo(World worldIn, TextureManager textureManagerIn, Entity entityIn, float partialTicks) + { + if (this.worldObj != worldIn) + { + this.setWorld(worldIn); + } + + this.renderEngine = textureManagerIn; + this.entity = entityIn; +// this.fontRenderer = fontrendererIn; + this.entityYaw = entityIn.prevYaw + (entityIn.rotYaw - entityIn.prevYaw) * partialTicks; + this.entityPitch = entityIn.prevPitch + (entityIn.rotPitch - entityIn.prevPitch) * partialTicks; + this.entityX = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * (double)partialTicks; + this.entityY = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * (double)partialTicks; + this.entityZ = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * (double)partialTicks; + } + + public void renderTileEntity(TileEntity tileentityIn, float partialTicks, int destroyStage) + { + if (tileentityIn.getDistanceSq(this.entityX, this.entityY, this.entityZ) < tileentityIn.getMaxRenderDistanceSquared()) + { + int i = this.worldObj.getCombinedLight(tileentityIn.getPos(), 0); + int j = i % 65536; + int k = i / 65536; + GL13.glMultiTexCoord2f(GL13.GL_TEXTURE1, (float)j / 1.0F, (float)k / 1.0F); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + BlockPos blockpos = tileentityIn.getPos(); + this.renderTileEntityAt(tileentityIn, (double)blockpos.getX() - staticPlayerX, (double)blockpos.getY() - staticPlayerY, (double)blockpos.getZ() - staticPlayerZ, partialTicks, destroyStage); + } + } + + /** + * Render this TileEntity at a given set of coordinates + */ + public void renderTileEntityAt(TileEntity tileEntityIn, double x, double y, double z, float partialTicks) + { + this.renderTileEntityAt(tileEntityIn, x, y, z, partialTicks, -1); + } + + public void renderTileEntityAt(TileEntity tileEntityIn, double x, double y, double z, float partialTicks, int destroyStage) + { + TileEntitySpecialRenderer tileentityspecialrenderer = this.getSpecialRenderer(tileEntityIn); + + if (tileentityspecialrenderer != null) + { + tileentityspecialrenderer.renderTileEntityAt(tileEntityIn, x, y, z, partialTicks, destroyStage); + } + } + + public void setWorld(World worldIn) + { + this.worldObj = worldIn; + } + +// public FontRenderer getFontRenderer() +// { +// return this.fontRenderer; +// } +} diff --git a/client/src/client/renderer/tileentity/TileEntitySignRenderer.java b/client/src/client/renderer/tileentity/TileEntitySignRenderer.java new file mode 100755 index 00000000..22d543c8 --- /dev/null +++ b/client/src/client/renderer/tileentity/TileEntitySignRenderer.java @@ -0,0 +1,133 @@ +package client.renderer.tileentity; + +import org.lwjgl.opengl.GL11; + +import client.gui.Font; +import client.renderer.Drawing; +import client.renderer.GlState; +import client.renderer.model.ModelSign; +import common.block.Block; +import common.init.Blocks; +import common.tileentity.TileEntitySign; + + +public class TileEntitySignRenderer extends TileEntitySpecialRenderer +{ + private static final String SIGN_TEXTURE = "textures/blocks/sign.png"; + + /** The ModelSign instance for use in this renderer */ + private final ModelSign model = new ModelSign(); + + public void renderTileEntityAt(TileEntitySign te, double x, double y, double z, float partialTicks, int destroyStage) + { + Block block = te.getBlockType(); + GL11.glPushMatrix(); + float f = 0.6666667F; + + if (block == Blocks.sign) + { + GL11.glTranslatef((float)x + 0.5F, (float)y + 0.75F * f, (float)z + 0.5F); + float f1 = (float)(te.getBlockMetadata() * 360) / 16.0F; + GL11.glRotatef(-f1, 0.0F, 1.0F, 0.0F); + this.model.signStick.showModel = true; + } + else + { + int k = te.getBlockMetadata(); + float f2 = 0.0F; + + if (k == 2) + { + f2 = 180.0F; + } + + if (k == 4) + { + f2 = 90.0F; + } + + if (k == 5) + { + f2 = -90.0F; + } + + GL11.glTranslatef((float)x + 0.5F, (float)y + 0.75F * f, (float)z + 0.5F); + GL11.glRotatef(-f2, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(0.0F, -0.3125F, -0.4375F); + this.model.signStick.showModel = false; + } + + if (destroyStage >= 0) + { + this.bindTexture(DESTROY_STAGES[destroyStage]); + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glPushMatrix(); + GL11.glScalef(4.0F, 2.0F, 1.0F); + GL11.glTranslatef(0.0625F, 0.0625F, 0.0625F); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + } + else + { + this.bindTexture(SIGN_TEXTURE); + } + + GlState.enableRescaleNormal(); + GL11.glPushMatrix(); + GL11.glScalef(f, -f, -f); + this.model.renderSign(); + GL11.glPopMatrix(); +// FontRenderer fontrenderer = this.getFontRenderer(); + float f3 = 0.015625F * f; + GL11.glTranslatef(0.0F, 0.5F * f, 0.07F * f); + GL11.glScalef(f3, -f3, f3); + GL11.glNormal3f(0.0F, 0.0F, -1.0F * f3); + GlState.depthMask(false); + int i = 0; + + if (destroyStage < 0) + { + for (int j = 0; j < te.signText.length; ++j) + { + if (te.signText[j] != null) + { +// Text ichatcomponent = new Text(te.signText[j]); +// List list = ichatcomponent.split(90, false); + String s = te.signText[j].length() > 50 ? te.signText[j].substring(0, 50) : te.signText[j]; // list != null && list.size() > 0 ? ((Text)list.get(0)).getFormattedText() : ""; + +// if (j == te.lineBeingEdited) +// { +// s = "> " + s + " <"; +// SKC.drawString(s, -SKC.getStringWidth(s) / 2, j * 10 - te.signText.length * 5, i); +// } +// else +// { + GL11.glPushMatrix(); + GL11.glScalef(0.75f, 0.75f, 0.75f); + Drawing.drawTextCenteredN(s, 0, j * (Font.YGLYPH - 3) - 32, 0xff000000); + GL11.glPopMatrix(); +// } + } + } + } + + GlState.depthMask(true); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glPopMatrix(); + + if (destroyStage >= 0) + { + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glPopMatrix(); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + } + } + + +// private void drawdString(String text, int x, int y) { +// Drawing.drawText(text, x, y, 0xff000000, false); +// } +// private int getdStringWidth(String text) { +// Vec2i size = Drawing.getTextSize(text); +// return size.xpos; +// } +} diff --git a/client/src/client/renderer/tileentity/TileEntitySkullRenderer.java b/client/src/client/renderer/tileentity/TileEntitySkullRenderer.java new file mode 100755 index 00000000..9cd26286 --- /dev/null +++ b/client/src/client/renderer/tileentity/TileEntitySkullRenderer.java @@ -0,0 +1,124 @@ +package client.renderer.tileentity; + +import org.lwjgl.opengl.GL11; + +import client.renderer.GlState; +import client.renderer.model.ModelHumanoidHead; +import common.tileentity.TileEntitySkull; +import common.util.Facing; + + +public class TileEntitySkullRenderer extends TileEntitySpecialRenderer +{ + private static final String TEXTURE_SKULL = "textures/entity/skull.png"; + public static TileEntitySkullRenderer instance; + + private final ModelHumanoidHead humanoidHead = new ModelHumanoidHead(); + + public void renderTileEntityAt(TileEntitySkull te, double x, double y, double z, float partialTicks, int destroyStage) + { + Facing enumfacing = Facing.getFront(te.getBlockMetadata() & 7); + this.renderSkull((float)x, (float)y, (float)z, enumfacing, (float)(te.getSkullRotation() * 360) / 16.0F, destroyStage); + } + + public void setRendererDispatcher(TileEntityRendererDispatcher rendererDispatcherIn) + { + super.setRendererDispatcher(rendererDispatcherIn); + instance = this; + } + + public void renderSkull(float x, float y, float z, Facing dir, float rot, int destroyStage) + { +// ModelBase modelbase = this.skeletonHead; + + if (destroyStage >= 0) + { + this.bindTexture(DESTROY_STAGES[destroyStage]); + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glPushMatrix(); + GL11.glScalef(4.0F, 2.0F, 1.0F); + GL11.glTranslatef(0.0625F, 0.0625F, 0.0625F); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + } + else + { +// switch (p_180543_6_) +// { +// case 0: +// default: +// this.bindTexture(SKELETON_TEXTURES); +// break; +// +// case 1: +// this.bindTexture(WITHER_SKELETON_TEXTURES); +// break; +// +// case 2: +// this.bindTexture(ZOMBIE_TEXTURES); +// modelbase = this.humanoidHead; +// break; +// +// case 3: +// modelbase = this.humanoidHead; +// String tex = TEXTURE_SKULL; // EntitySkinManager.TEXTURE_DEF; + +// if (user != null && EntityTexManager.getModel(user) == ModelType.HUMANOID) +// { +// tex = EntityTexManager.getSkin(user, ModelType.HUMANOID); +// } + + this.bindTexture(TEXTURE_SKULL); +// break; +// +// case 4: +// this.bindTexture(CREEPER_TEXTURES); +// } + } + + GL11.glPushMatrix(); + GlState.disableCull(); + + if (dir != Facing.UP) + { + switch (dir) + { + case NORTH: + GL11.glTranslatef(x + 0.5F, y + 0.25F, z + 0.74F); + break; + + case SOUTH: + GL11.glTranslatef(x + 0.5F, y + 0.25F, z + 0.26F); + rot = 180.0F; + break; + + case WEST: + GL11.glTranslatef(x + 0.74F, y + 0.25F, z + 0.5F); + rot = 270.0F; + break; + + case EAST: + default: + GL11.glTranslatef(x + 0.26F, y + 0.25F, z + 0.5F); + rot = 90.0F; + } + } + else + { + GL11.glTranslatef(x + 0.5F, y, z + 0.5F); + } + + float f = 0.0625F; + GlState.enableRescaleNormal(); + GL11.glScalef(-1.0F, -1.0F, 1.0F); + GlState.enableAlpha(); + this.humanoidHead.render(null, 0.0F, 0.0F, 0.0F, rot, 0.0F, f); + GL11.glPopMatrix(); + + if (destroyStage >= 0) + { + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glPopMatrix(); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + } + } +} diff --git a/client/src/client/renderer/tileentity/TileEntitySpecialRenderer.java b/client/src/client/renderer/tileentity/TileEntitySpecialRenderer.java new file mode 100755 index 00000000..fa30d2ff --- /dev/null +++ b/client/src/client/renderer/tileentity/TileEntitySpecialRenderer.java @@ -0,0 +1,60 @@ +package client.renderer.tileentity; + +import client.renderer.texture.TextureManager; +import common.tileentity.TileEntity; +import common.world.World; + +public abstract class TileEntitySpecialRenderer +{ + protected static final String[] DESTROY_STAGES = new String[] { + "textures/blocks/destroy_stage_0.png", + "textures/blocks/destroy_stage_1.png", + "textures/blocks/destroy_stage_2.png", + "textures/blocks/destroy_stage_3.png", + "textures/blocks/destroy_stage_4.png", + "textures/blocks/destroy_stage_5.png", + "textures/blocks/destroy_stage_6.png", + "textures/blocks/destroy_stage_7.png", + "textures/blocks/destroy_stage_8.png", + "textures/blocks/destroy_stage_9.png" + }; + + protected TileEntityRendererDispatcher rendererDispatcher; + + public abstract void renderTileEntityAt(T te, double x, double y, double z, float partialTicks, int destroyStage); + + protected void bindTexture(String location) + { + TextureManager texturemanager = this.rendererDispatcher.renderEngine; + + if (texturemanager != null) + { + texturemanager.bindTexture(location); + } + } + + protected World getWorld() + { + return this.rendererDispatcher.worldObj; + } + + public void setRendererDispatcher(TileEntityRendererDispatcher rendererDispatcherIn) + { + this.rendererDispatcher = rendererDispatcherIn; + } + +// public FontRenderer getFontRenderer() +// { +// return this.rendererDispatcher.getFontRenderer(); +// } + + /** + * If true the {@link TileEntitySpecialRenderer} will always be rendered while the player is in the render bounding + * box {@link TileEntity#getRenderBoundingBox()} and his squared distance with the {@link TileEntity} is smaller + * than {@link TileEntity#getMaxRenderDistanceSquared()}. + */ + public boolean forceTileEntityRender() + { + return false; + } +} diff --git a/client/src/main/java/client/vars/BaseVar.java b/client/src/client/vars/BaseVar.java similarity index 100% rename from client/src/main/java/client/vars/BaseVar.java rename to client/src/client/vars/BaseVar.java diff --git a/client/src/main/java/client/vars/BoolVar.java b/client/src/client/vars/BoolVar.java similarity index 96% rename from client/src/main/java/client/vars/BoolVar.java rename to client/src/client/vars/BoolVar.java index 25922e27..103f1cad 100644 --- a/client/src/main/java/client/vars/BoolVar.java +++ b/client/src/client/vars/BoolVar.java @@ -4,7 +4,7 @@ import java.lang.reflect.Field; import client.gui.element.Toggle; import client.gui.element.ToggleCallback; -import common.util.Color; +import common.color.TextColor; import common.util.Util; public class BoolVar extends BaseVar { @@ -27,7 +27,7 @@ public class BoolVar extends BaseVar { } public String getType() { - return Color.MAGENTA + "bool"; + return TextColor.MAGENTA + "bool"; } public boolean parse(String str) { diff --git a/client/src/main/java/client/vars/CVar.java b/client/src/client/vars/CVar.java similarity index 100% rename from client/src/main/java/client/vars/CVar.java rename to client/src/client/vars/CVar.java diff --git a/client/src/client/vars/CVarCategory.java b/client/src/client/vars/CVarCategory.java new file mode 100644 index 00000000..aa40d07a --- /dev/null +++ b/client/src/client/vars/CVarCategory.java @@ -0,0 +1,23 @@ +package client.vars; + +import common.color.TextColor; + +public enum CVarCategory { + SYSTEM(TextColor.RED + "system"), + WINDOW(TextColor.BLUE + "window"), + GUI(TextColor.GREEN + "gui"), + RENDER(TextColor.NEON + "render"), + INPUT(TextColor.ORANGE + "input"), + CONSOLE(TextColor.YELLOW + "console"), + SOUND(TextColor.CRIMSON + "sound"); + + private final String name; + + private CVarCategory(String name) { + this.name = name; + } + + public String toString() { + return this.name; + } +} diff --git a/client/src/main/java/client/vars/ColorVar.java b/client/src/client/vars/ColorVar.java similarity index 79% rename from client/src/main/java/client/vars/ColorVar.java rename to client/src/client/vars/ColorVar.java index 307bf754..9f72dc6f 100644 --- a/client/src/main/java/client/vars/ColorVar.java +++ b/client/src/client/vars/ColorVar.java @@ -7,7 +7,7 @@ import client.gui.element.FieldCallback; import client.gui.element.Label; import client.gui.element.Slider; import client.gui.element.FieldAction; -import common.util.Color; +import common.color.TextColor; import common.util.Util; public class ColorVar extends IntVar { @@ -19,7 +19,7 @@ public class ColorVar extends IntVar { } public String getType() { - return this.alpha ? (Color.GRAY + "color32") : (Color.LIGHT_GRAY + "color"); + return this.alpha ? (TextColor.GRAY + "color32") : (TextColor.LGRAY + "color"); } protected Integer parseValue(String str) { @@ -39,21 +39,15 @@ public class ColorVar extends IntVar { throw new UnsupportedOperationException("Kann keinen Schieberegler für Farben erstellen"); } - public Label label(int x, int y, int w) { - return new Label(x, y, w, this.display); + public Label label(int x, int y, int w, int h) { + return new Label(x, y, w, h, this.display); } public client.gui.element.Field editor(int x, int y, int w, int h) { return new client.gui.element.Field(x, y, w, h, this.alpha ? 8 : 6, new FieldCallback() { public void use(client.gui.element.Field elem, FieldAction value) { - if(value == FieldAction.SEND || value == FieldAction.UNFOCUS) { - if(!ColorVar.this.parse(elem.getText())) - elem.setText(ColorVar.this.format()); - } - else if(value == FieldAction.FUNCTION) { - ColorVar.this.parse(ColorVar.this.getDefault()); - elem.setText(ColorVar.this.format()); - } + if(value == FieldAction.SEND || value == FieldAction.UNFOCUS) + ColorVar.this.parse(elem.getText()); } }, this.format()); } diff --git a/client/src/main/java/client/vars/EnumVar.java b/client/src/client/vars/EnumVar.java similarity index 98% rename from client/src/main/java/client/vars/EnumVar.java rename to client/src/client/vars/EnumVar.java index e46eee7f..5f8273f0 100644 --- a/client/src/main/java/client/vars/EnumVar.java +++ b/client/src/client/vars/EnumVar.java @@ -7,8 +7,8 @@ import client.gui.element.DropdownCallback; import client.gui.element.Element; import client.gui.element.Switch; import client.gui.element.SwitchCallback; +import common.color.TextColor; import common.util.Identifyable; -import common.util.Color; import common.util.Util; public class EnumVar extends BaseVar { @@ -41,7 +41,7 @@ public class EnumVar extends BaseVar { } public String getType() { - return Color.CYAN + "enum"; + return TextColor.CYAN + "enum"; } public boolean parse(String str) { diff --git a/client/src/main/java/client/vars/FloatVar.java b/client/src/client/vars/FloatVar.java similarity index 97% rename from client/src/main/java/client/vars/FloatVar.java rename to client/src/client/vars/FloatVar.java index 2fd87fc9..43c6a3fe 100644 --- a/client/src/main/java/client/vars/FloatVar.java +++ b/client/src/client/vars/FloatVar.java @@ -4,8 +4,8 @@ import java.lang.reflect.Field; import client.gui.element.Slider; import client.gui.element.SliderFloatCallback; +import common.color.TextColor; import common.util.ExtMath; -import common.util.Color; public class FloatVar extends BaseVar { public static interface FloatFunction extends VarFunction { @@ -47,7 +47,7 @@ public class FloatVar extends BaseVar { } public String getType() { - return Color.YELLOW + "float"; + return TextColor.YELLOW + "float"; } public boolean parse(String str) { diff --git a/client/src/main/java/client/vars/IntVar.java b/client/src/client/vars/IntVar.java similarity index 97% rename from client/src/main/java/client/vars/IntVar.java rename to client/src/client/vars/IntVar.java index 614dac69..312bd726 100644 --- a/client/src/main/java/client/vars/IntVar.java +++ b/client/src/client/vars/IntVar.java @@ -4,8 +4,8 @@ import java.lang.reflect.Field; import client.gui.element.Slider; import client.gui.element.SliderCallback; +import common.color.TextColor; import common.util.ExtMath; -import common.util.Color; import common.util.Util; public class IntVar extends BaseVar { @@ -36,7 +36,7 @@ public class IntVar extends BaseVar { } public String getType() { - return Color.GREEN + "int"; + return TextColor.GREEN + "int"; } protected Integer parseValue(String str) { diff --git a/client/src/main/java/client/vars/StringVar.java b/client/src/client/vars/StringVar.java similarity index 97% rename from client/src/main/java/client/vars/StringVar.java rename to client/src/client/vars/StringVar.java index 84bd4cd6..86549485 100644 --- a/client/src/main/java/client/vars/StringVar.java +++ b/client/src/client/vars/StringVar.java @@ -4,8 +4,8 @@ import java.lang.reflect.Field; import client.gui.element.FieldCallback; import client.gui.element.FieldAction; +import common.color.TextColor; import common.util.CharValidator; -import common.util.Color; public class StringVar extends BaseVar { public static interface StringFunction extends VarFunction { @@ -33,7 +33,7 @@ public class StringVar extends BaseVar { } public String getType() { - return Color.YELLOW + "float"; + return TextColor.YELLOW + "float"; } public boolean parse(String str) { diff --git a/client/src/main/java/client/vars/Variable.java b/client/src/client/vars/Variable.java similarity index 100% rename from client/src/main/java/client/vars/Variable.java rename to client/src/client/vars/Variable.java diff --git a/client/src/main/java/client/window/Bind.java b/client/src/client/window/Bind.java similarity index 95% rename from client/src/main/java/client/window/Bind.java rename to client/src/client/window/Bind.java index cb7d4085..1ab509f3 100644 --- a/client/src/main/java/client/window/Bind.java +++ b/client/src/client/window/Bind.java @@ -4,8 +4,8 @@ import client.Client; import client.gui.element.Element; import client.vars.CVar; import client.vars.CVarCategory; +import common.color.TextColor; import common.util.Identifyable; -import common.util.Color; import common.util.Util; public enum Bind implements Identifyable, CVar { @@ -13,7 +13,7 @@ public enum Bind implements Identifyable, CVar { LEFT("left", "Nach links", Keysym.A), BACKWARD("backward", "Rückwärts", Keysym.S), RIGHT("right", "Nach rechts", Keysym.D), - UP("up", "Aufwärts, Sprung", Keysym.SPACE), + UP("up", "Aufwärts, Springen", Keysym.SPACE), DOWN("down", "Abwärts, Langsam", Keysym.LEFT_CONTROL), FAST("fast", "Schneller", Keysym.LEFT_SHIFT), INVENTORY("inventory", "Inventar", Keysym.E), @@ -31,12 +31,10 @@ public enum Bind implements Identifyable, CVar { SELECT7("select7", "Auswahl #7", Keysym.N7), SELECT8("select8", "Auswahl #8", Keysym.N8), SELECT9("select9", "Auswahl #9", Keysym.N9), - CRAFT("craft", "Herstellen", Keysym.M), - RENAME("rename", "Umbenennen", Keysym.N), CONSOLE("console", "Konsole", Keysym.F1), COMMAND("command", "Befehl / Chat", Keysym.C), INFO("info", "Infos einblenden", Keysym.TAB), - PERSPECTIVE("perspective", "Perspektive", Keysym.F5), + PERSPECTIVE("perspective", "Perspektive ändern", Keysym.F5), ZOOM("zoom", "Kamera zoomen", Keysym.Y), MENU("menu", "Menü", Keysym.ESCAPE), SCREENSHOT("screenshot", "Bildschirmfoto", Keysym.F10), @@ -180,7 +178,7 @@ public enum Bind implements Identifyable, CVar { } public String getType() { - return Color.VIOLET + "key"; + return TextColor.VIOLET + "key"; } public CVarCategory getCategory() { diff --git a/client/src/main/java/client/window/Button.java b/client/src/client/window/Button.java similarity index 87% rename from client/src/main/java/client/window/Button.java rename to client/src/client/window/Button.java index a38c6964..52861963 100644 --- a/client/src/main/java/client/window/Button.java +++ b/client/src/client/window/Button.java @@ -5,9 +5,9 @@ import client.Client; public enum Button implements Input { MOUSE_LEFT("lmb", "Linke Maustaste"), MOUSE_RIGHT("rmb", "Rechte Maustaste"), - MOUSE_MIDDLE("mmb", "Mausrad-Taste"), - MOUSE_BTN_X("xmb", "Maus Seite 1"), - MOUSE_BTN_Y("ymb", "Maus Seite 2"), + MOUSE_MIDDLE("mmb", "Mittlere Maustaste"), + MOUSE_BTN_X("xmb", "Maustaste Seite 1"), + MOUSE_BTN_Y("ymb", "Maustaste Seite 2"), MOUSE_BTN_A("m6", "Maustaste 6"), MOUSE_BTN_B("m7", "Maustaste 7"), MOUSE_BTN_C("m8", "Maustaste 8"); diff --git a/client/src/client/window/DisplayMode.java b/client/src/client/window/DisplayMode.java new file mode 100644 index 00000000..9ab016fc --- /dev/null +++ b/client/src/client/window/DisplayMode.java @@ -0,0 +1,26 @@ +package client.window; + +public class DisplayMode { + public static final int VID_MODES = 28; + + public final int width; + public final int height; + public final int refresh; + + public DisplayMode(int width, int height, int refresh) { + this.width = width; + this.height = height; + this.refresh = refresh; + } + + public String toString() { + return String.format("%dx%d @ %d Hz", this.width, this.height, this.refresh); + } + + public boolean equals(Object obj) { + if(!(obj instanceof DisplayMode)) + return false; + DisplayMode other = (DisplayMode)obj; + return this.width == other.width && this.height == other.height && this.refresh == other.refresh; + } +} diff --git a/client/src/main/java/client/window/Input.java b/client/src/client/window/Input.java similarity index 100% rename from client/src/main/java/client/window/Input.java rename to client/src/client/window/Input.java diff --git a/client/src/main/java/client/window/KeyEvent.java b/client/src/client/window/KeyEvent.java similarity index 100% rename from client/src/main/java/client/window/KeyEvent.java rename to client/src/client/window/KeyEvent.java diff --git a/client/src/main/java/client/window/Keysym.java b/client/src/client/window/Keysym.java similarity index 100% rename from client/src/main/java/client/window/Keysym.java rename to client/src/client/window/Keysym.java diff --git a/client/src/main/java/client/window/Wheel.java b/client/src/client/window/Wheel.java similarity index 87% rename from client/src/main/java/client/window/Wheel.java rename to client/src/client/window/Wheel.java index 1fc5c26e..3c4b6bdf 100644 --- a/client/src/main/java/client/window/Wheel.java +++ b/client/src/client/window/Wheel.java @@ -3,8 +3,8 @@ package client.window; import client.Client; public enum Wheel implements Input { - SCROLL_UP("scrup", "Mausrad oben"), - SCROLL_DOWN("scrdn", "Mausrad unten"), + SCROLL_UP("scrup", "Mausrad aufwärts"), + SCROLL_DOWN("scrdn", "Mausrad abwärts"), SCROLL_LEFT("scrl", "Mausrad links"), SCROLL_RIGHT("scrr", "Mausrad rechts"); diff --git a/client/src/main/java/client/window/Window.java b/client/src/client/window/Window.java similarity index 95% rename from client/src/main/java/client/window/Window.java rename to client/src/client/window/Window.java index a0c5b903..515c79c8 100644 --- a/client/src/main/java/client/window/Window.java +++ b/client/src/client/window/Window.java @@ -43,7 +43,6 @@ import static org.lwjgl.glfw.GLFW.glfwSetWindowPos; import static org.lwjgl.glfw.GLFW.glfwSetWindowPosCallback; import static org.lwjgl.glfw.GLFW.glfwSetWindowRefreshCallback; import static org.lwjgl.glfw.GLFW.glfwSetWindowSize; -import static org.lwjgl.glfw.GLFW.glfwSetWindowSizeLimits; import static org.lwjgl.glfw.GLFW.glfwSetWindowTitle; import static org.lwjgl.glfw.GLFW.glfwShowWindow; import static org.lwjgl.glfw.GLFW.glfwSwapBuffers; @@ -213,7 +212,7 @@ public abstract class Window { window = NULL; } } - public static void initWindow(int sx, int sy, int wx, int wy, int mx, int my) { + public static void initWindow(int sx, int sy, int wx, int wy) { if(window == NULL) return; long monitor = glfwGetPrimaryMonitor(); @@ -222,8 +221,8 @@ public abstract class Window { int[] y = new int[1]; if(monitor != NULL) glfwGetMonitorPos(monitor, x, y); - int xsize = (mode != null && mode.width() >= mx && wx > mode.width()) ? mode.width() : wx; - int ysize = (mode != null && mode.height() >= my && wy > mode.height()) ? mode.height() : wy; + int xsize = (mode != null && wx > mode.width()) ? mode.width() : wx; + int ysize = (mode != null && wy > mode.height()) ? mode.height() : wy; int xpos = x[0] + (mode != null ? mode.width() / 2 - xsize / 2 : 0); int ypos = y[0] + (mode != null ? mode.height() / 2 - ysize / 2 : 0); xsize = xsize < 1 ? 1 : xsize; @@ -237,7 +236,6 @@ public abstract class Window { ysize = wy; } glfwSetWindowSize(window, xsize, ysize); - glfwSetWindowSizeLimits(window, mx, my, GLFW_DONT_CARE, GLFW_DONT_CARE); glfwSetWindowPos(window, xpos, ypos); // wcf_windowed(win, xpos, ypos, xsize, ysize); // wcf_fullscreen does not move while hidden ... @@ -245,7 +243,6 @@ public abstract class Window { glfwShowWindow(window); // wcf_show(win, 1); // wcf_limits(win, 1, 1, -1, -1); - glfwSetWindowMonitor(window, NULL, xpos, ypos, xsize, ysize, GLFW_DONT_CARE); // set position twice to work around bugs in some tiling window managers } public static WindowEvent[] poll() { diff --git a/client/src/main/java/client/window/WindowAction.java b/client/src/client/window/WindowAction.java similarity index 100% rename from client/src/main/java/client/window/WindowAction.java rename to client/src/client/window/WindowAction.java diff --git a/client/src/client/window/WindowEvent.java b/client/src/client/window/WindowEvent.java new file mode 100644 index 00000000..294b0053 --- /dev/null +++ b/client/src/client/window/WindowEvent.java @@ -0,0 +1,13 @@ +package client.window; + +public class WindowEvent { + public final WindowAction action; + public final int param1; + public final int param2; + + public WindowEvent(WindowAction action, int p1, int p2) { + this.action = action; + this.param1 = p1; + this.param2 = p2; + } +} diff --git a/client/src/client/world/EmptyChunk.java b/client/src/client/world/EmptyChunk.java new file mode 100755 index 00000000..6bec1b50 --- /dev/null +++ b/client/src/client/world/EmptyChunk.java @@ -0,0 +1,87 @@ +package client.world; + +import java.util.List; +import java.util.function.Predicate; + +import common.block.Block; +import common.entity.Entity; +import common.init.Blocks; +import common.tileentity.TileEntity; +import common.util.BlockPos; +import common.util.BoundingBox; +import common.world.Chunk; + +public class EmptyChunk extends Chunk { + public EmptyChunk(WorldClient world) { + super(world, 0, 0); + } + + public Block getBlock(BlockPos pos) { + return Blocks.air; + } + + public int getOpacity(BlockPos pos) { + return 255; + } + + public int getMeta(BlockPos pos) { + return 0; + } + + public int getLight(BlockPos pos) { + return 0; + } + + public void setLight(BlockPos pos, int value) { + } + + public int getLightSub(BlockPos pos, int amount) { + return 0; + } + + public void addEntity(Entity entity) { + } + + public void removeEntity(Entity entity) { + } + + public TileEntity getTileEntity(BlockPos pos, TileEntity.EnumCreateEntityType type) { + return null; + } + + public void addTileEntity(TileEntity tile) { + } + + public void addTileEntity(BlockPos pos, TileEntity tile) { + } + + public void removeTileEntity(BlockPos pos) { + } + + public void onChunkLoad() { + } + + public void onChunkUnload() { + } + + public void setModified() { + } + + public void getEntities(Entity exclude, BoundingBox bb, List list, Predicate pred) { + } + + public void getEntities(Class clazz, BoundingBox bb, List list, Predicate pred) { + } + + public boolean isDirty() { + return false; + } + + public boolean isEmpty() { + return true; + } + + public boolean isEmpty(int bottom, int top) { + return true; + } +} diff --git a/client/src/client/world/WorldClient.java b/client/src/client/world/WorldClient.java new file mode 100755 index 00000000..096ad5c7 --- /dev/null +++ b/client/src/client/world/WorldClient.java @@ -0,0 +1,936 @@ +package client.world; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import client.Client; +import client.renderer.particle.EntityFX; +import client.renderer.particle.EntityFirework; +import common.block.Block; +import common.collect.Lists; +import common.collect.Maps; +import common.collect.Sets; +import common.dimension.Dimension; +import common.entity.Entity; +import common.entity.item.EntityCart; +import common.entity.npc.EntityNPC; +import common.init.BlockRegistry; +import common.init.ItemRegistry; +import common.init.Items; +import common.init.SoundEvent; +import common.item.ItemDye; +import common.log.Log; +import common.material.Material; +import common.model.ParticleType; +import common.nbt.NBTTagCompound; +import common.rng.Random; +import common.sound.MovingSoundMinecart; +import common.sound.PositionedSound; +import common.tileentity.TileEntity; +import common.util.BlockPos; +import common.util.ChunkPos; +import common.util.ExtMath; +import common.util.Vec3; +import common.util.BlockPos.MutableBlockPos; +import common.world.Chunk; +import common.world.AWorldClient; +import common.world.State; + +public class WorldClient extends AWorldClient +{ + private static final int DISPLAY_RANGE = 16; + + private final Client gm; + private final Set entityList = Sets.newHashSet(); + private final Set spawnQueue = Sets.newHashSet(); + private final Set previousActive = Sets.newHashSet(); + private final Map chunkMapping = Maps.newHashMap(); + private final List chunkListing = Lists.newArrayList(); + private final Chunk blankChunk = new EmptyChunk(this); +// public final Profiler profiler; + protected int lastLightning; + protected Vec3 lightColor = new Vec3(0xffffff); + protected boolean exterminated; + + public WorldClient(Client gm, boolean debug, Dimension dim) + { + super(dim, debug); + this.gm = gm; + this.calculateInitialSkylight(); + this.calculateInitialWeather(); + this.setGravity(this.gm.gravity); + this.setTimeFactor(this.gm.timeFactor); +// this.setDifficulty(this.gm.difficulty); + } + + public void tick() + { +// this.info.tick(); + + if (this.gm.dayCycle) + { + this.daytime += this.timeFactor; + } + + for (int i = 0; i < 10 && !this.spawnQueue.isEmpty(); ++i) + { + Entity entity = (Entity)this.spawnQueue.iterator().next(); + this.spawnQueue.remove(entity); + + if (!this.entities.contains(entity)) + { + this.spawnEntityInWorld(entity); + } + } + long time = System.currentTimeMillis(); + for (Chunk chunk : this.chunkListing) + { + chunk.update(); + } + if (System.currentTimeMillis() - time > 100L) + { + Log.JNI.info("Warnung: Render-Chunk-Tick dauerte " + (System.currentTimeMillis() - time) + " ms"); + } + this.updateBlocks(); + } + + protected void updateBlocks() + { + this.setActivePlayerChunksAndCheckLight(this.gm.renderDistance); + this.previousActive.retainAll(this.active); + + if (this.previousActive.size() == this.active.size()) + { + this.previousActive.clear(); + } + + int i = 0; + + for (ChunkPos chunkcoordintpair : this.active) + { + if (!this.previousActive.contains(chunkcoordintpair)) + { + int j = chunkcoordintpair.x * 16; + int k = chunkcoordintpair.z * 16; + Chunk chunk = this.getChunk(chunkcoordintpair.x, chunkcoordintpair.z); + chunk.enqueueRelight(); + this.previousActive.add(chunkcoordintpair); + ++i; + + if (i >= 10) + { + return; + } + } + } + } + + public void doPreChunk(int x, int z, boolean load) + { + ChunkPos pos = new ChunkPos(x, z); + if (load) + { + if(this.chunkMapping.get(pos) != null) + this.doPreChunk(x, z, false); + Chunk chunk = new Chunk(this, x, z); + this.chunkMapping.put(pos, chunk); + this.chunkListing.add(chunk); + chunk.setLoaded(true); + } + else + { + Chunk chunk = this.getChunk(x, z); + if (!chunk.isEmpty()) + { + chunk.onChunkUnload(); + } + this.chunkMapping.remove(pos); + this.chunkListing.remove(chunk); + } + + if (!load) + { + this.markBlockRangeForRenderUpdate(x * 16, 0, z * 16, x * 16 + 15, 512, z * 16 + 15); + } + } + + public boolean spawnEntityInWorld(Entity entityIn) + { + boolean flag = super.spawnEntityInWorld(entityIn); + this.entityList.add(entityIn); + + if (!flag) + { + this.spawnQueue.add(entityIn); + } + else if (entityIn instanceof EntityCart) + { + this.gm.getSoundManager().playSound(new MovingSoundMinecart((EntityCart)entityIn)); + } + + return flag; + } + + public void removeEntity(Entity entityIn) + { + super.removeEntity(entityIn); + this.entityList.remove(entityIn); + } + + protected void onEntityAdded(Entity entityIn) + { + if (this.spawnQueue.contains(entityIn)) + { + this.spawnQueue.remove(entityIn); + } + } + + protected void onEntityRemoved(Entity entityIn) + { + boolean flag = false; + + if (this.entityList.contains(entityIn)) + { + if (entityIn.isEntityAlive()) + { + this.spawnQueue.add(entityIn); + flag = true; + } + else + { + this.entityList.remove(entityIn); + } + } + } + + public void addEntityToWorld(int entityID, Entity entityToSpawn) + { + Entity entity = this.getEntityByID(entityID); + + if (entity != null) + { + this.removeEntity(entity); + } + + this.entityList.add(entityToSpawn); + entityToSpawn.setId(entityID); + + if (!this.spawnEntityInWorld(entityToSpawn)) + { + this.spawnQueue.add(entityToSpawn); + } + + this.entityIds.addKey(entityID, entityToSpawn); + } + + public Entity getEntityByID(int id) + { + return (Entity)(id == this.gm.player.getId() ? this.gm.player : super.getEntityByID(id)); + } + + public Entity removeEntityFromWorld(int entityID) + { + Entity entity = (Entity)this.entityIds.removeObject(entityID); + + if (entity != null) + { + this.entityList.remove(entity); + this.removeEntity(entity); + } + + return entity; + } + + public boolean invalidateRegionAndSetBlock(BlockPos pos, State state) + { + return super.setState(pos, state, 3); + } + +// public boolean canShowVoidParticles() { +// return this.gm.voidParticles; // && this.dimension.getType().voidPortal; +// } + + public void displayTick(int posX, int posY, int posZ) { + Random rand = new Random(); + BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(); + for(int n = 0; n < 1000; n++) { + int x = posX + rand.zrange(DISPLAY_RANGE) - rand.zrange(DISPLAY_RANGE); + int y = posY + rand.zrange(DISPLAY_RANGE) - rand.zrange(DISPLAY_RANGE); + int z = posZ + rand.zrange(DISPLAY_RANGE) - rand.zrange(DISPLAY_RANGE); + pos.set(x, y, z); + State state = this.getState(pos); + state.getBlock().randomDisplayTick(this, pos, state, rand); + } +// if(this.canShowVoidParticles()) { + for(int n = 0; n < 1000; n++) { + float x = ((float)posX) + (rand.floatv() - rand.floatv() - 0.5f) * 32.0f; + float y = -64.0f + rand.floatv() * 65.0f; // * 68.0f; + float z = ((float)posZ) + (rand.floatv() - rand.floatv() - 0.5f) * 32.0f; + this.spawnParticle(ParticleType.SUSPENDED_DEPTH, (double)x, (double)y, (double)z, 0.0D, 0.0D, 0.0D); + } +// } + } + + public void removeAllEntities() + { + this.entities.removeAll(this.unloaded); + + for (int i = 0; i < this.unloaded.size(); ++i) + { + Entity entity = (Entity)this.unloaded.get(i); + int j = entity.chunkCoordX; + int k = entity.chunkCoordZ; + + if (entity.addedToChunk && this.isLoaded(j, k, true)) + { + this.getChunk(j, k).removeEntity(entity); + } + } + + for (int l = 0; l < this.unloaded.size(); ++l) + { + this.onEntityRemoved((Entity)this.unloaded.get(l)); + } + + this.unloaded.clear(); + + for (int i1 = 0; i1 < this.entities.size(); ++i1) + { + Entity entity1 = (Entity)this.entities.get(i1); + + if (entity1.vehicle != null) + { + if (!entity1.vehicle.dead && entity1.vehicle.passenger == entity1) + { + continue; + } + + entity1.vehicle.passenger = null; + entity1.vehicle = null; + } + + if (entity1.dead) + { + int j1 = entity1.chunkCoordX; + int k1 = entity1.chunkCoordZ; + + if (entity1.addedToChunk && this.isLoaded(j1, k1, true)) + { + this.getChunk(j1, k1).removeEntity(entity1); + } + + this.entities.remove(i1--); + this.onEntityRemoved(entity1); + } + } + } + + public void playSound(double x, double y, double z, SoundEvent sound, float volume) + { +// if(this.gm.oldStepSounds && (soundName.equals("random.swim") || soundName.equals("step.ladder"))) +// return; +// if(this.gm.oldStepSounds && soundName.startsWith("step.")) +// soundName = "dig." + soundName.substring(5); +// if(this.gm.oldStepSounds && soundName.equals("random.swim_splash")) +// soundName = "random.splash"; +// double d0 = this.gm.getRenderViewEntity().getDistanceSq(x, y, z); + PositionedSound positionedsoundrecord = new PositionedSound(sound, volume, /* pitch, */ (float)x, (float)y, (float)z); + +// if (distanceDelay && d0 > 100.0D) +// { +// double d1 = Math.sqrt(d0) / 40.0D; +// this.gm.getSoundHandler().playDelayedSound(positionedsoundrecord, (int)(d1 * 20.0D)); +// } +// else +// { + this.gm.getSoundManager().playSound(positionedsoundrecord); +// } + } + + public void makeFireworks(double x, double y, double z, double motionX, double motionY, double motionZ, NBTTagCompound compund) + { + this.gm.effectRenderer.addEffect(new EntityFirework.StarterFX(this.gm.world, x, y, z, motionX, motionY, motionZ, this.gm.effectRenderer, compund)); + } + + public Chunk getChunk(int x, int z) + { + Chunk chunk = this.chunkMapping.get(new ChunkPos(x, z)); + return chunk == null ? this.blankChunk : chunk; + } + + public String getInfo() + { + return "Chunk-Cache: M " + this.chunkMapping.size() + ", L " + this.chunkListing.size(); + } + + public void playSound(SoundEvent sound, double x, double y, double z, float volume) + { + } + +// public void spawnParticle(EnumParticleTypes particleType, boolean force, double xCoord, double yCoord, double zCoord, double xOffset, +// double yOffset, double zOffset, int... data) { +// this.spawnParticle(particleType.getParticleID(), particleType.getShouldIgnoreRange() | force, xCoord, yCoord, zCoord, xOffset, yOffset, +// zOffset, data); +// } + + public void spawnParticle(ParticleType particleType, double xCoord, double yCoord, double zCoord, double xOffset, double yOffset, + double zOffset, int... data) { + this.spawnEntityFX(particleType, particleType.getShouldIgnoreRange(), xCoord, yCoord, zCoord, xOffset, yOffset, zOffset, data); + } + + public EntityFX spawnEntityFX(ParticleType particle, boolean ignoreRange, double xCoord, double yCoord, double zCoord, double xOffset, double yOffset, double zOffset, int[] parameters) + { + if (this.gm.getRenderViewEntity() != null) + { + int particleID = particle.getParticleID(); +// int i = this.gm.particleSetting; +// +// if (i == 1 && this.rand.zrange(3) == 0) +// { +// i = 2; +// } + + double d0 = this.gm.getRenderViewEntity().posX - xCoord; + double d1 = this.gm.getRenderViewEntity().posY - yCoord; + double d2 = this.gm.getRenderViewEntity().posZ - zCoord; + + if (ignoreRange) + { + return this.gm.effectRenderer.spawnEffectParticle(particleID, xCoord, yCoord, zCoord, xOffset, yOffset, zOffset, parameters); + } + else + { + double d3 = 16.0D; + if(d0 * d0 + d1 * d1 + d2 * d2 > 256.0D) + return null; + return this.gm.effectRenderer.spawnEffectParticle(particleID, xCoord, yCoord, zCoord, xOffset, yOffset, zOffset, parameters); + } + } + return null; + } + +// public void broadcastSound(int soundID, BlockPos pos, int data) +// { +// switch (soundID) +// { +//// case 1013: +// case 1018: +// if (this.gm.getRenderViewEntity() != null) +// { +// double d0 = (double)pos.getX() - this.gm.getRenderViewEntity().posX; +// double d1 = (double)pos.getY() - this.gm.getRenderViewEntity().posY; +// double d2 = (double)pos.getZ() - this.gm.getRenderViewEntity().posZ; +// double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2); +// double d4 = this.gm.getRenderViewEntity().posX; +// double d5 = this.gm.getRenderViewEntity().posY; +// double d6 = this.gm.getRenderViewEntity().posZ; +// +// if (d3 > 0.0D) +// { +// d4 += d0 / d3 * 2.0D; +// d5 += d1 / d3 * 2.0D; +// d6 += d2 / d3 * 2.0D; +// } +// +//// if (soundID == 1013) +//// { +//// this.playSound(d4, d5, d6, "mob.wither.spawn", 1.0F, 1.0F); +//// } +//// else +//// { +// this.playSound(d4, d5, d6, "mob.dragon.end", 5.0F, 1.0F); +//// } +// } +// +// default: +// } +// } + + private void playSoundAtPos(BlockPos pos, SoundEvent sound, float volume) + { + this.playSound((double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, sound, volume); + } + + public void playAuxSFX(EntityNPC player, int sfxType, BlockPos blockPosIn, int data) + { + switch (sfxType) + { + case 1000: + this.playSoundAtPos(blockPosIn, SoundEvent.CLICK, 1.0F); + break; + + case 1001: + this.playSoundAtPos(blockPosIn, SoundEvent.CLICK, 1.0F); + break; + + case 1002: + this.playSoundAtPos(blockPosIn, SoundEvent.THROW, 1.0F); + break; + + case 1003: + this.playSoundAtPos(blockPosIn, SoundEvent.DOOR, 1.0F); + break; + + case 1004: + this.playSoundAtPos(blockPosIn, SoundEvent.FIZZ, 0.5F); + break; + + case 1005: + this.playSoundAtPos(blockPosIn, SoundEvent.TELEPORT, 10.0F); + break; + + case 1006: + this.playSoundAtPos(blockPosIn, SoundEvent.DOOR, 1.0F); + break; + + case 1007: + this.playSoundAtPos(blockPosIn, SoundEvent.SPELL, 10.0F); + break; + + case 1008: + this.playSoundAtPos(blockPosIn, SoundEvent.FIREBALL, 10.0F); + break; + + case 1009: + this.playSoundAtPos(blockPosIn, SoundEvent.FIREBALL, 2.0F); + break; + +// case 1010: +// this.playSoundAtPos(blockPosIn, "dig.wood", 0.6F, (random.floatv() - random.floatv()) * 0.2F + 1.0F); +// break; + +// case 1011: +// this.playSoundAtPos(blockPosIn, "random.metal", 2.0F, (random.floatv() - random.floatv()) * 0.2F + 1.0F); +// break; + +// case 1012: +// this.playSoundAtPos(blockPosIn, "dig.wood", 2.0F, (random.floatv() - random.floatv()) * 0.2F + 1.0F); +// break; + + case 1013: + this.playSoundAtPos(blockPosIn, SoundEvent.TELEPORT_REV, 0.5F); + break; + + case 1014: + this.playSoundAtPos(blockPosIn, SoundEvent.METAL, 2.0F); + break; + + case 1015: + this.playSoundAtPos(blockPosIn, SoundEvent.BAT_TAKEOFF, 0.05F); + break; + + case 1016: + this.playSoundAtPos(blockPosIn, SoundEvent.FIREBALL, 2.0F); + break; + + case 1017: + this.playSoundAtPos(blockPosIn, SoundEvent.EXPLODE, 20.0f); + break; + + case 1020: + this.playSoundAtPos(blockPosIn, SoundEvent.ANVIL_BREAK, 1.0F); + break; + + case 1021: + this.playSoundAtPos(blockPosIn, SoundEvent.ANVIL_USE, 1.0F); + break; + + case 1022: + this.playSoundAtPos(blockPosIn, SoundEvent.ANVIL_LAND, 0.3F); + break; + + case 1023: +// double d131 = (double)blockPosIn.getX(); +// double d141 = (double)blockPosIn.getY(); +// double d161 = (double)blockPosIn.getZ(); +// for (int i1 = 0; i1 < 8; ++i1) { +// this.spawnEntityFX(EnumParticleTypes.ITEM_CRACK, EnumParticleTypes.ITEM_CRACK.getShouldIgnoreRange(), +// d131, d141, d161, random.gaussian() * 0.15D, random.doublev() * 0.2D, random.gaussian() * 0.15D, +// new int[] {ItemRegistry.getIdFromItem(ItemRegistry.getItemFromBlock(Blocks.glass)), 0}); +// } + this.playSoundAtPos(blockPosIn, SoundEvent.GLASS, 1.0F); + break; + + case 1024: + this.playSoundAtPos(blockPosIn, SoundEvent.CLICK, 1.0F); + break; + + case 1025: + MutableBlockPos pos = new MutableBlockPos(blockPosIn.getX(), blockPosIn.getY(), blockPosIn.getZ()); + for(int z = 0; z < 30; z++) { + this.playSoundAtPos(pos.set(blockPosIn.getX() + this.rand.range(-128, 128), + blockPosIn.getY() + this.rand.range(-4, 4), blockPosIn.getZ() + this.rand.range(-128, 128)), + SoundEvent.EXPLODE, 30.0F); + } + break; + + case 2000: + int l = data % 3 - 1; + int i = data / 3 % 3 - 1; + double d15 = (double)blockPosIn.getX() + (double)l * 0.6D + 0.5D; + double d17 = (double)blockPosIn.getY() + 0.5D; + double d19 = (double)blockPosIn.getZ() + (double)i * 0.6D + 0.5D; + + for (int k1 = 0; k1 < 10; ++k1) + { + double d20 = this.rand.doublev() * 0.2D + 0.01D; + double d21 = d15 + (double)l * 0.01D + (this.rand.doublev() - 0.5D) * (double)i * 0.5D; + double d4 = d17 + (this.rand.doublev() - 0.5D) * 0.5D; + double d6 = d19 + (double)i * 0.01D + (this.rand.doublev() - 0.5D) * (double)l * 0.5D; + double d8 = (double)l * d20 + this.rand.gaussian() * 0.01D; + double d10 = -0.03D + this.rand.gaussian() * 0.01D; + double d12 = (double)i * d20 + this.rand.gaussian() * 0.01D; + this.spawnEntityFX(ParticleType.SMOKE_NORMAL, ParticleType.SMOKE_NORMAL.getShouldIgnoreRange(), d21, d4, d6, d8, d10, d12, new int[0]); + } + + return; + + case 2001: + Block block = BlockRegistry.getBlockById(data & 4095); + + if (block.getMaterial() != Material.air) + { + this.gm.getSoundManager().playSound(new PositionedSound(block.sound.getBreakSound(), 1.0F, /* block.sound.getFrequency() * 0.8F, */ (float)blockPosIn.getX() + 0.5F, (float)blockPosIn.getY() + 0.5F, (float)blockPosIn.getZ() + 0.5F)); + } + + this.gm.effectRenderer.addBlockDestroyEffects(blockPosIn, block.getStateFromMeta(data >> 12 & 255)); + break; + + case 2002: + double d13 = (double)blockPosIn.getX(); + double d14 = (double)blockPosIn.getY(); + double d16 = (double)blockPosIn.getZ(); + + for (int i1 = 0; i1 < 8; ++i1) + { + this.spawnEntityFX(ParticleType.ITEM_CRACK, ParticleType.ITEM_CRACK.getShouldIgnoreRange(), d13, d14, d16, this.rand.gaussian() * 0.15D, this.rand.doublev() * 0.2D, this.rand.gaussian() * 0.15D, new int[] {ItemRegistry.getIdFromItem(Items.potion), data}); + } + + ParticleType enumparticletypes = ParticleType.WATER_SPLASH; + float f = 1.0F; + float f1 = 1.0F; + float f2 = 1.0F; + if((data & 16383) != 0) { + int j1 = Items.potion.getColorFromDamage(data); + f = (float)(j1 >> 16 & 255) / 255.0F; + f1 = (float)(j1 >> 8 & 255) / 255.0F; + f2 = (float)(j1 >> 0 & 255) / 255.0F; + enumparticletypes = ParticleType.SPELL; + + if (Items.potion.isEffectInstant(data)) + { + enumparticletypes = ParticleType.SPELL_INSTANT; + } + } + + for (int l1 = 0; l1 < 100; ++l1) + { + double d22 = this.rand.doublev() * 4.0D; + double d23 = this.rand.doublev() * Math.PI * 2.0D; + double d24 = Math.cos(d23) * d22; + double d9 = 0.01D + this.rand.doublev() * 0.5D; + double d11 = Math.sin(d23) * d22; + EntityFX entityfx = this.spawnEntityFX(enumparticletypes, enumparticletypes.getShouldIgnoreRange(), d13 + d24 * 0.1D, d14 + 0.3D, d16 + d11 * 0.1D, d24, d9, d11, new int[0]); + + if (entityfx != null) + { + if(enumparticletypes != ParticleType.WATER_SPLASH) { + float f3 = 0.75F + this.rand.floatv() * 0.25F; + entityfx.setRBGColorF(f * f3, f1 * f3, f2 * f3); + } + entityfx.multiplyVelocity((float)d22); + } + } + + this.playSoundAtPos(blockPosIn, SoundEvent.GLASS, 1.0F); + break; + + case 2004: + for (int k = 0; k < 20; ++k) + { + double d3 = (double)blockPosIn.getX() + 0.5D + ((double)this.rand.floatv() - 0.5D) * 2.0D; + double d5 = (double)blockPosIn.getY() + 0.5D + ((double)this.rand.floatv() - 0.5D) * 2.0D; + double d7 = (double)blockPosIn.getZ() + 0.5D + ((double)this.rand.floatv() - 0.5D) * 2.0D; + this.spawnParticle(ParticleType.SMOKE_NORMAL, d3, d5, d7, 0.0D, 0.0D, 0.0D); + this.spawnParticle(ParticleType.FLAME, d3, d5, d7, 0.0D, 0.0D, 0.0D); + } + + return; + + case 2005: + ItemDye.spawnBonemealParticles(this, blockPosIn, data); + } + } + + public void markBlockForUpdate(BlockPos pos) + { + int i = pos.getX(); + int j = pos.getY(); + int k = pos.getZ(); + this.gm.renderGlobal.markBlocksForUpdate(i - 1, j - 1, k - 1, i + 1, j + 1, k + 1); + } + + public void notifyLightSet(BlockPos pos) + { + int i = pos.getX(); + int j = pos.getY(); + int k = pos.getZ(); + this.gm.renderGlobal.markBlocksForUpdate(i - 1, j - 1, k - 1, i + 1, j + 1, k + 1); + } + + public void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2) + { + this.gm.renderGlobal.markBlocksForUpdate(x1 - 1, y1 - 1, z1 - 1, x2 + 1, y2 + 1, z2 + 1); + } + + public void sendBlockBreakProgress(int breakerId, BlockPos pos, int progress) + { + this.gm.renderGlobal.sendBlockBreakProgress(breakerId, pos, progress); + } + + public float getSunBrightness(float p_72971_1_) { + float f = this.getCelestialAngle(p_72971_1_); + float f1 = 1.0F - (ExtMath.cos(f * (float)Math.PI * 2.0F) * 2.0F + 0.2F); + f1 = ExtMath.clampf(f1, 0.0F, 1.0F); + f1 = 1.0F - f1; + f1 = (float)((double)f1 * (1.0D - (double)(this.getRainStrength() * 5.0F) / 16.0D)); + f1 = (float)((double)f1 * (1.0D - (double)(this.getDarkness() * 5.0F) / 16.0D)); + return f1 * 0.8F + 0.2F; + } + + private static int hsvToRGB(float hue, float saturation, float value) + { + int i = (int)(hue * 6.0F) % 6; + float f = hue * 6.0F - (float)i; + float f1 = value * (1.0F - saturation); + float f2 = value * (1.0F - f * saturation); + float f3 = value * (1.0F - (1.0F - f) * saturation); + float f4; + float f5; + float f6; + + switch (i) + { + case 0: + f4 = value; + f5 = f3; + f6 = f1; + break; + + case 1: + f4 = f2; + f5 = value; + f6 = f1; + break; + + case 2: + f4 = f1; + f5 = value; + f6 = f3; + break; + + case 3: + f4 = f1; + f5 = f2; + f6 = value; + break; + + case 4: + f4 = f3; + f5 = f1; + f6 = value; + break; + + case 5: + f4 = value; + f5 = f1; + f6 = f2; + break; + + default: + throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + hue + ", " + saturation + ", " + value); + } + + int j = ExtMath.clampi((int)(f4 * 255.0F), 0, 255); + int k = ExtMath.clampi((int)(f5 * 255.0F), 0, 255); + int l = ExtMath.clampi((int)(f6 * 255.0F), 0, 255); + return j << 16 | k << 8 | l; + } + + public Vec3 getSkyColor(Entity entity, float partial) { + Vec3 vec; + if(this.exterminated) + vec = new Vec3(0x101010); + else + vec = new Vec3(this.dimension.getSkyColor()); + if(this.dimension.getType().days) { + float mult = ExtMath.clampf(ExtMath.cos(this.getCelestialAngle(partial) * (float)Math.PI * 2.0F) * 2.0F + 0.5F, + 0.0F, 1.0F); + if(this.dimension.getSkyColor() == 0xffffffff) { + float temp = ExtMath.clampf(((0.0f /* temp */ + 14.0f) / 40.0f + 0.15f) / 3.0F, + -1.0F, 1.0F); + Vec3 sky = new Vec3(hsvToRGB(0.62222224F - temp * 0.05F, 0.5F + temp * 0.1F, 1.0F)); + vec = new Vec3(vec.xCoord * sky.xCoord * mult, vec.yCoord * sky.yCoord * mult, vec.zCoord * sky.zCoord * mult); + } + else { + vec = new Vec3(vec.xCoord * mult, vec.yCoord * mult, vec.zCoord * mult); + } + } + float r = (float)vec.xCoord; + float g = (float)vec.yCoord; + float b = (float)vec.zCoord; + + float rain = this.getRainStrength(); + if(rain > 0.0F) { + float mul = (r * 0.3F + g * 0.59F + b * 0.11F) * 0.6F; + float shift = 1.0F - rain * 0.75F; + r = r * shift + mul * (1.0F - shift); + g = g * shift + mul * (1.0F - shift); + b = b * shift + mul * (1.0F - shift); + } + + float dark = this.getDarkness(); + if(dark > 0.0F) { + float mul = (r * 0.3F + g * 0.59F + b * 0.11F) * 0.2F; + float shift = 1.0F - dark * 0.75F; + r = r * shift + mul * (1.0F - shift); + g = g * shift + mul * (1.0F - shift); + b = b * shift + mul * (1.0F - shift); + } + + if(this.lastLightning > 0) { + float light = (float)this.lastLightning - partial; + if(light > 1.0F) + light = 1.0F; +// light = light * 0.45F; + r = r * (1.0F - light) + (float)this.lightColor.xCoord * light; + g = g * (1.0F - light) + (float)this.lightColor.yCoord * light; + b = b * (1.0F - light) + (float)this.lightColor.zCoord * light; + } + + return new Vec3((double)r, (double)g, (double)b); + } + + public Vec3 getCloudColour(Entity entity, float partialTicks) { + Vec3 color = new Vec3(this.dimension.getCloudColor()); + if(this.exterminated) + color = new Vec3(0x000000); + float r = (float)color.xCoord; + float g = (float)color.yCoord; + float b = (float)color.zCoord; + + float rain = this.getRainStrength(); + if(rain > 0.0F) { + float mul = (r * 0.3F + g * 0.59F + b * 0.11F) * 0.6F; + float shift = 1.0F - rain * 0.95F; + r = r * shift + mul * (1.0F - shift); + g = g * shift + mul * (1.0F - shift); + b = b * shift + mul * (1.0F - shift); + } + + if(this.dimension.getType().days) { + float sun = ExtMath.clampf(ExtMath.cos(this.getCelestialAngle(partialTicks) * (float)Math.PI * 2.0F) * 2.0F + 0.5F, + 0.0F, 1.0F); + r = r * (sun * 0.9F + 0.1F); + g = g * (sun * 0.9F + 0.1F); + b = b * (sun * 0.85F + 0.15F); + } + + float dark = this.getDarkness(); + if(dark > 0.0F) { + float mul = (r * 0.3F + g * 0.59F + b * 0.11F) * 0.2F; + float shift = 1.0F - dark * 0.95F; + r = r * shift + mul * (1.0F - shift); + g = g * shift + mul * (1.0F - shift); + b = b * shift + mul * (1.0F - shift); + } + + return new Vec3((double)r, (double)g, (double)b); + } + + public Vec3 getFogColor(Entity entity, float partialTicks) { + Vec3 color = new Vec3(this.dimension.getFogColor()); + if(this.exterminated) + color = new Vec3(0x303030); + if(!this.dimension.getType().days) + return color; + float sun = ExtMath.clampf(ExtMath.cos(this.getCelestialAngle(partialTicks) * (float)Math.PI * 2.0F) * 2.0F + 0.5F, + 0.0F, 1.0F); + float r = (float)color.xCoord; + float g = (float)color.yCoord; + float b = (float)color.zCoord; + r = r * (sun * 0.94F + 0.06F); + g = g * (sun * 0.94F + 0.06F); + b = b * (sun * 0.91F + 0.09F); + return new Vec3((double)r, (double)g, (double)b); + } + + public float getStarBrightness(float partialTicks) { + float f = this.getCelestialAngle(partialTicks); + float f1 = 1.0F - (ExtMath.cos(f * (float)Math.PI * 2.0F) * 2.0F + 0.25F); + f1 = ExtMath.clampf(f1, 0.0F, 1.0F); + return f1 * f1 * this.dimension.getStarBrightness(); + } + + public float getDeepStarBrightness(float partialTicks) { + float f = this.getCelestialAngle(partialTicks); + float f1 = 1.0F - (ExtMath.cos(f * (float)Math.PI * 2.0F) * 2.0F + 0.25F); + f1 = ExtMath.clampf(f1, 0.0F, 1.0F); + return f1 * f1 * this.dimension.getDeepStarBrightness(); + } + + public int getLastLightning() { + return this.lastLightning; + } + + public void decrLightning() { + if(this.lastLightning > 0) + this.lastLightning -= 1; + } + + public void setLastLightning(int last, int color) { + this.lastLightning = last; + this.lightColor = new Vec3(color); + } + + public void ensureAreaLoaded(Entity entityIn) { + int i = ExtMath.floord(entityIn.posX / 16.0D); + int j = ExtMath.floord(entityIn.posZ / 16.0D); + int k = 2; + + for(int l = i - k; l <= i + k; ++l) { + for(int i1 = j - k; i1 <= j + k; ++i1) { + this.getChunk(l, i1); + } + } + + if(!this.entities.contains(entityIn)) { + this.entities.add(entityIn); + } + } + + public List getLoadedEntityList() { + return this.entities; + } + + public List getLoadedTileList() { + return this.tiles; + } + + public String getDebugLoadedEntities() { + return "" + this.entities.size(); + } + + public boolean hasNoChunks() { + return this.chunkListing.isEmpty(); + } + + public void setExterminated(boolean exterminated) { + this.exterminated = exterminated; + } + + public boolean isExterminated() { + return this.exterminated; + } +} diff --git a/client/src/main/java/client/Client.java b/client/src/main/java/client/Client.java deleted file mode 100755 index f61eecef..00000000 --- a/client/src/main/java/client/Client.java +++ /dev/null @@ -1,3739 +0,0 @@ -package client; - -import java.awt.image.BufferedImage; -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Modifier; -import java.net.IDN; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.text.SimpleDateFormat; -import java.util.ArrayDeque; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Queue; -import java.util.Set; -import java.util.function.Function; - -import javax.imageio.ImageIO; -import javax.swing.JFileChooser; - -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL13; - -import client.audio.AudioInterface; -import client.audio.SoundManager; -import client.audio.Volume; -import client.gui.FileCallback; -import client.gui.Font; -import client.gui.Gui; -import client.gui.GuiConnect.ServerInfo; -import client.gui.GuiConsole; -import client.gui.GuiInfo; -import client.gui.GuiLoading; -import client.gui.GuiMenu; -import client.gui.GuiServer; -import client.gui.Style; -import client.gui.character.GuiChar; -import client.gui.container.GuiContainer; -import client.gui.container.GuiInventory; -import client.gui.element.Area; -import client.gui.element.InventoryButton; -import client.gui.ingame.GuiGameOver; -import client.gui.ingame.GuiRename; -import client.init.DimensionMapping; -import client.network.ClientLoginHandler; -import client.network.ClientPlayer; -import client.network.DummyConnection; -import client.renderer.BlockRenderer; -import client.renderer.Drawing; -import client.renderer.EffectRenderer; -import client.renderer.EntityRenderer; -import client.renderer.GlState; -import client.renderer.ItemRenderer; -import client.renderer.RenderGlobal; -import client.renderer.blockmodel.ModelManager; -import client.renderer.chunk.RenderChunk; -import client.renderer.entity.RenderItem; -import client.renderer.entity.RenderManager; -import client.renderer.texture.EntityTexManager; -import client.renderer.texture.TextureManager; -import client.renderer.texture.TextureMap; -import client.util.FileUtils; -import client.util.Message; -import client.util.PerfSection; -import client.util.PlayerController; -import client.vars.BoolVar; -import client.vars.CVar; -import client.vars.CVarCategory; -import client.vars.ColorVar; -import client.vars.EnumVar; -import client.vars.FloatVar; -import client.vars.IntVar; -import client.vars.StringVar; -import client.vars.Variable; -import client.vars.BaseVar.VarFunction; -import client.vars.BoolVar.BoolFunction; -import client.vars.EnumVar.EnumFunction; -import client.vars.FloatVar.FloatFunction; -import client.vars.IntVar.IntFunction; -import client.vars.StringVar.StringFunction; -import client.vars.Variable.IntType; -import client.window.Bind; -import client.window.Button; -import client.window.DisplayMode; -import client.window.KeyEvent; -import client.window.Keysym; -import client.window.Wheel; -import client.window.Window; -import client.window.WindowEvent; -import client.world.ChunkClient; -import client.world.ChunkEmpty; -import common.Version; -import common.block.Block; -import common.block.liquid.BlockLiquid; -import common.collect.Lists; -import common.collect.Maps; -import common.collect.Sets; -import common.dimension.Dimension; -import common.dimension.Space; -import common.effect.Effect; -import common.effect.StatusEffect; -import common.entity.Entity; -import common.entity.animal.EntityHorse; -import common.entity.item.EntityCart; -import common.entity.npc.Energy; -import common.entity.npc.EntityCpu; -import common.entity.npc.EntityNPC; -import common.entity.npc.EntityWaterNPC; -import common.entity.npc.PlayerCharacter; -import common.entity.types.EntityLiving; -import common.init.BlockRegistry; -import common.init.Blocks; -import common.init.EntityRegistry; -import common.init.ItemRegistry; -import common.init.Items; -import common.init.Registry; -import common.init.SoundEvent; -import common.item.Item; -import common.item.ItemControl; -import common.item.ItemStack; -import common.item.material.ItemBucket; -import common.log.Log; -import common.log.LogLevel; -import common.net.bootstrap.Bootstrap; -import common.net.channel.Channel; -import common.net.channel.ChannelException; -import common.net.channel.ChannelInitializer; -import common.net.channel.ChannelOption; -import common.net.channel.nio.NioEventLoopGroup; -import common.net.channel.socket.nio.NioSocketChannel; -import common.net.handler.timeout.ReadTimeoutHandler; -import common.net.util.concurrent.Future; -import common.net.util.concurrent.GenericFutureListener; -import common.network.IThreadListener; -import common.network.NetConnection; -import common.network.PacketDecoder; -import common.network.PacketEncoder; -import common.network.PacketPrepender; -import common.network.PacketRegistry; -import common.network.PacketSplitter; -import common.network.NetHandler.ThreadQuickExitException; -import common.packet.CPacketAction; -import common.packet.CPacketCheat; -import common.packet.CPacketMessage; -import common.packet.HPacketHandshake; -import common.packet.CPacketAction.Action; -import common.properties.Property; -import common.rng.Random; -import common.sound.EventType; -import common.sound.MovingSoundMinecart; -import common.sound.PositionedSound; -import common.tileentity.TileEntity; -import common.util.BlockPos; -import common.util.BoundingBox; -import common.util.CharValidator; -import common.util.ChunkPos; -import common.util.ExtMath; -import common.util.HitPosition; -import common.util.IntHashMap; -import common.util.LongHashMap; -import common.util.ParticleType; -import common.util.Color; -import common.util.Util; -import common.util.Var; -import common.util.HitPosition.ObjectType; -import common.vars.Vars; -import common.world.Chunk; -import common.world.LightType; -import common.world.State; -import common.world.Weather; -import common.world.World; - -/* - Een net ganz funktionierndes Programm ... - - Absolute Mindestanforderungen: - - Prozessor : Intel Core i3 530 oder AMD Phenom 2 X2 545 - Grafikkarte : NVIDIA GeForce GTS 450 oder AMD Radeon HD 7730 - Arbeitsspeicher : Etwa 512 MB ~ 1 GB, 2 - 4 GB empfohlen - Mainboard : Was gerade passt (auch mit Hammer) - Kühler : Ne Klimaanlage oder ordentlich Pusten - Festplatte : Richtet sich nach der Geduld des Nutzers - Netzteil : Atomkraftwerk oder stabiler Energiekern - Gehäuse : Pappkarton, Bierkasten oder auch gar keins - Tastatur : Hlb fktonrnd odr bsr - Maus : Aus Plastik oder mit extra Quietsch-Effekt - Monitor : Olle Röhre oder gebrochener Flachbild (Mindestens 1280x800) - Stuhl : Interessiert niemanden (sonst siehe Gehäuse) - - [[oder einfach einen Toaster mit nem LCD und Maus]] -*/ - -public class Client implements IThreadListener { - public static class SyncFunction implements IntFunction { - public void apply(IntVar cv, int value) { - Client.CLIENT.sync(value); - } - } - - public static class TickFunction implements FloatFunction { - public void apply(FloatVar cv, float value) { - Client.CLIENT.tick_target(value); - } - } - - public static class ConsoleFunction implements IntFunction { - public void apply(IntVar cv, int value) { - Client.CLIENT.resizeConsole(); - } - } - - public static class ChatFunction implements IntFunction { - public void apply(IntVar cv, int value) { - Client.CLIENT.resizeChat(); - } - } - - public static class FeedFunction implements IntFunction { - public void apply(IntVar cv, int value) { - Client.CLIENT.resizeFeed(); - } - } - - public static class HotbarFunction implements IntFunction { - public void apply(IntVar cv, int value) { - Client.CLIENT.resizeHotbar(); - } - } - - public static class DistanceFunction implements IntFunction { - public void apply(IntVar cv, int value) { - Client.CLIENT.distance(value); - } - } - - public static class RedrawFunction implements IntFunction { - public void apply(IntVar cv, int value) { - Client.CLIENT.rescale(); - } - } - - public static class ItemRedrawFunction implements BoolFunction { - public void apply(BoolVar cv, boolean value) { - Client.CLIENT.rescale(); - } - } - - public static class LevelFunction implements EnumFunction { - public void apply(EnumVar cv, LogLevel value) { - Log.setLevel(value); - } - } - - public static class FontFunction implements EnumFunction { - public void apply(EnumVar cv, Font value) { - Font.select(value); - Client.CLIENT.rescale(); - } - } - - public static class StyleFunction implements EnumFunction