diff --git a/client/src/client/Client.java b/client/src/client/Client.java index cfa961b..c3c6e18 100755 --- a/client/src/client/Client.java +++ b/client/src/client/Client.java @@ -70,6 +70,9 @@ import client.renderer.texture.ColormapLoader; import client.renderer.texture.EntityTexManager; import client.renderer.texture.TextureManager; import client.renderer.texture.TextureMap; +import client.util.FileUtils; +import client.util.PerfSection; +import client.util.PlayerController; import client.vars.BoolVar; import client.vars.CVar; import client.vars.CVarCategory; @@ -152,7 +155,6 @@ 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; @@ -316,6 +318,33 @@ public class Client implements IThreadListener { public float moveForward; public float zoomLevel; public float gravity = 1.0f; + + private long tmr_timer; + private long tmr_start; + private long tmr_current; + private long tmr_last; + + private long tmr_delta; + private long tmr_update; + private long tmr_frames; + private long tmr_iters; + + private long tick_torun; + private long tick_done; + private long tick_total; + private long tick_time; + private long tick_stime; + private long tick_ftime; + + private long tick_ttime; + private long tick_update; + + private double tick_fraction; + private float framerate; + private float tickrate; + private float fdelta; + private int tickTarget; + private int tickFrame; private TextureManager textureManager; private RenderManager renderManager; @@ -784,14 +813,14 @@ public class Client implements IThreadListener { this.deltaX = this.deltaY = 0.0f; } if(this.player != null) - this.soundManager.setListener(this.player, (float)Timing.tick_fraction); + this.soundManager.setListener(this.player, (float)this.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); + this.entityRenderer.renderWorld((float)this.tick_fraction, System.nanoTime() - this.tickStart); GL11.glPopMatrix(); GlState.disableTexture2D(); @@ -824,7 +853,7 @@ public class Client implements IThreadListener { this.setupOverlay(); if(this.world != null && this.open == null && this.thirdPersonView == 0 && this.viewEntity != null) { if(this.drawDebug) { - this.renderWorldDirections((float)Timing.tick_fraction); + this.renderWorldDirections((float)this.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); @@ -1025,7 +1054,7 @@ public class Client implements IThreadListener { this.renderLagometer(); } else { - Drawing.drawText(String.format("%s%.2f", framecode(), Timing.framerate), 0, 0, 0xffffffff); + Drawing.drawText(String.format("%s%.2f", framecode(), this.framerate), 0, 0, 0xffffffff); } } GlState.enableBlend(); @@ -1053,13 +1082,13 @@ public class Client implements IThreadListener { , 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.framecode(), this.framerate < 1.0f ? 1.0f / this.framerate : this.framerate, this.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, + this.tpscode(), this.tickrate < 1.0f ? 1.0f / this.tickrate : this.tickrate, + this.tickrate < 1.0f ? "SPT" : "TPS", (float)this.tickTarget / 1000.0f, + (float)this.tick_time / 1000.0f, this.tickTimeout, str != null ? "\n" : "", str != null ? str : "" ); // if(str) @@ -2165,14 +2194,14 @@ public class Client implements IThreadListener { 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.tmr_current = Util.rtime(); + this.tmr_delta = this.tmr_current - this.tmr_last; + this.tmr_last = this.tmr_current; + this.fdelta = ((float)this.tmr_delta) / 1000000.0f; + if((this.tmr_current - this.tmr_update) >= 1000000L) { + this.framerate = ((float)this.tmr_frames) * 1000000.0f / ((float)(long)(this.tmr_current - this.tmr_update)); + this.tmr_frames = 0L; + this.tmr_update = this.tmr_current; } this.start(); PerfSection.INPUT.enter(); @@ -2205,10 +2234,10 @@ public class Client implements IThreadListener { long now = System.nanoTime(); this.addFrame(now - this.startNanoTime); this.startNanoTime = now; - while(this.syncLimited && (Util.rtime() - Timing.tmr_current) < (1000000L / this.syncLimit)) { + while(this.syncLimited && (Util.rtime() - this.tmr_current) < (1000000L / this.syncLimit)) { ; } - Timing.tmr_frames += 1L; + this.tmr_frames += 1L; } Log.SYSTEM.info("Beende ..."); @@ -2348,46 +2377,46 @@ public class Client implements IThreadListener { } public TextColor framecode() { - return (Timing.framerate >= 59.0f) ? TextColor.GREEN : ((Timing.framerate >= 29.0f) ? TextColor.YELLOW : ((Timing.framerate >= 14.0f) ? TextColor.ORANGE : TextColor.RED)); + return (this.framerate >= 59.0f) ? TextColor.GREEN : ((this.framerate >= 29.0f) ? TextColor.YELLOW : ((this.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)); + return (this.tickrate >= (((float)this.tickTarget / 1000.0f) - 1.0f)) ? TextColor.GREEN : ((this.tickrate >= (((float)this.tickTarget / 1000.0f) / 2.0f - 1.0f)) ? TextColor.YELLOW : + ((this.tickrate >= (((float)this.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; + this.tick_stime = Util.rtime(); + if((this.tick_stime - this.tick_update) >= 1000000L) { + this.tickrate = ((float)this.tick_done) * 1000000.0f / ((float)(long)(this.tick_stime - this.tick_update)); + this.tick_done = 0; + this.tick_update = this.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_torun += (((long)this.tickTarget) * this.tmr_delta) / 1000L; + this.tickFrame = 0; + this.tick_torun = this.tick_torun > 2000000L ? 1000000L : this.tick_torun; + while(this.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; + this.tick_done += 1L; + this.tickFrame += 1; + this.tick_total += 1L; + this.tick_torun -= 1000000L; + if((this.tick_ftime = (Util.rtime() - this.tick_stime)) >= (((long)this.tickTimeout) * 1000L)) { + Log.TICK.warn("Ticks benötigten %d ms dieses Frame (maximal %d ms), überspringe %d Ticks", this.tick_ftime / 1000L, this.tickTimeout, this.tick_torun / 1000000L); + this.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; + this.tick_fraction = ((double)this.tick_torun) / 1000000.0; + this.tick_ttime += this.tick_ftime; + this.tick_time = this.tickFrame != 0 ? (this.tick_ftime / (long)this.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(); + this.tickTarget = (int)(tps * 1000.0f); + this.tick_torun = 0L; + this.tick_done = 0L; + this.tick_update = Util.rtime(); } public void unload(boolean loading) { @@ -2748,6 +2777,14 @@ public class Client implements IThreadListener { return buffer; } + public float getTickFraction() { + return (float)this.tick_fraction; + } + + public long getPassedTime() { + return this.tmr_delta; + } + private void regVar(CVar cv) { if(cvars.containsKey(cv.getCVarName())) throw new IllegalArgumentException("Variable " + cv.getCVarName() + " existiert bereits!"); @@ -2963,7 +3000,7 @@ public class Client implements IThreadListener { Log.CONSOLE.user(msg); if(size > 0) { for(String line : msg.split("\n")) { - Message lmsg = new Message(line, Timing.tmr_current); + Message lmsg = new Message(line, this.tmr_current); while(log.size() >= size) { log.remove(log.size() - 1); } @@ -3011,7 +3048,7 @@ public class Client implements IThreadListener { 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((this.tmr_current - msg.time) <= fade || (log == this.chat && this.chatPermanent)) { if(align > 0) Drawing.drawTextbox(msg.message, x, y, bg); else if(align < 0) diff --git a/client/src/client/Timing.java b/client/src/client/Timing.java deleted file mode 100644 index 96094f3..0000000 --- a/client/src/client/Timing.java +++ /dev/null @@ -1,30 +0,0 @@ -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/client/audio/SoundManager.java b/client/src/client/audio/SoundManager.java index 6942153..8886b95 100755 --- a/client/src/client/audio/SoundManager.java +++ b/client/src/client/audio/SoundManager.java @@ -11,6 +11,7 @@ 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; @@ -22,7 +23,6 @@ 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 { diff --git a/client/src/client/gui/Font.java b/client/src/client/gui/Font.java index 51fa18b..302ebb6 100644 --- a/client/src/client/gui/Font.java +++ b/client/src/client/gui/Font.java @@ -8,8 +8,8 @@ import org.lwjgl.opengl.GL11; import client.renderer.GlState; import client.renderer.texture.TextureUtil; +import client.util.FileUtils; import common.log.Log; -import common.util.FileUtils; public class Font { public static final FontChar[] SIZES = new FontChar[256]; diff --git a/client/src/client/gui/GuiConnect.java b/client/src/client/gui/GuiConnect.java index 789fcf0..67135c0 100644 --- a/client/src/client/gui/GuiConnect.java +++ b/client/src/client/gui/GuiConnect.java @@ -12,11 +12,11 @@ import client.gui.element.ListEntry; import client.gui.element.NavButton; import client.gui.element.PressType; import client.renderer.Drawing; +import client.util.FileUtils; 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; diff --git a/client/src/client/gui/GuiMenu.java b/client/src/client/gui/GuiMenu.java index fd2093b..398d962 100644 --- a/client/src/client/gui/GuiMenu.java +++ b/client/src/client/gui/GuiMenu.java @@ -1,6 +1,5 @@ package client.gui; -import client.Timing; import client.gui.character.GuiChar; import client.gui.character.GuiCharacters; import client.gui.element.ActButton; @@ -26,7 +25,7 @@ public class GuiMenu extends Gui { 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); + this.gm.renderGlobal.renderStarField(this.gm.fb_x, this.gm.fb_y, 0x000000, 0xffffff, (float)this.ticks + this.gm.getTickFraction(), this.rand); } private final Random rand = new Random(); @@ -84,9 +83,9 @@ public class GuiMenu extends Gui { 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), + (int)(ExtMath.sin(((float)(GuiMenu.this.ticks + GuiMenu.this.rand.zrange(256)) + this.gm.getTickFraction()) / 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), + (int)(ExtMath.sin(((float)(GuiMenu.this.ticks + GuiMenu.this.rand.zrange(256)) + this.gm.getTickFraction()) / 100.0f * (float)Math.PI * 2.0f) * 16.0f), 0xff0000ff | (GuiMenu.this.rand.zrange(256) << 16)); } } diff --git a/client/src/client/gui/character/GuiChar.java b/client/src/client/gui/character/GuiChar.java index 01117c0..7ed4397 100755 --- a/client/src/client/gui/character/GuiChar.java +++ b/client/src/client/gui/character/GuiChar.java @@ -16,7 +16,6 @@ import org.lwjgl.opengl.GL13; import client.Client; import client.Client.FileMode; -import client.SkinConverter; import client.gui.FileCallback; import client.gui.GuiLoading; import client.gui.element.ActButton; @@ -39,6 +38,8 @@ 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; @@ -65,7 +66,6 @@ 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; diff --git a/client/src/client/gui/element/Textbox.java b/client/src/client/gui/element/Textbox.java index fa82c1a..c4e3506 100644 --- a/client/src/client/gui/element/Textbox.java +++ b/client/src/client/gui/element/Textbox.java @@ -2,7 +2,6 @@ package client.gui.element; import org.lwjgl.opengl.GL11; -import client.Timing; import client.gui.Font; import client.renderer.Drawing; import client.window.Button; @@ -63,14 +62,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 && ((Timing.tmr_current - this.tmr_leftmb) <= (((long)this.gm.dclickDelay) * 1000L))) { + if(!shift && ((System.currentTimeMillis() - this.tmr_leftmb) <= (long)this.gm.dclickDelay)) { this.sel_start = this.sel_drag = 0; this.sel_end = this.text.length(); } else { gui_text_select(x, y, shift); } - this.tmr_leftmb = Timing.tmr_current; + this.tmr_leftmb = System.currentTimeMillis(); } else if((btn == Button.MOUSE_MIDDLE) && this.func != null) { this.func.use(this, FieldAction.FUNCTION); @@ -177,7 +176,7 @@ abstract class Textbox extends Element { this.tmr_scroll -= ((long)n) * 1000000L; else this.tmr_scroll = 0L; - this.tmr_scroll += Timing.tmr_delta; + this.tmr_scroll += this.gm.getPassedTime(); return n; } return 0; diff --git a/client/src/client/network/ClientPlayer.java b/client/src/client/network/ClientPlayer.java index 167b8ae..2fbf084 100755 --- a/client/src/client/network/ClientPlayer.java +++ b/client/src/client/network/ClientPlayer.java @@ -7,7 +7,6 @@ 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; @@ -28,6 +27,7 @@ import client.gui.ingame.GuiSign; import client.gui.ingame.GuiForm; import client.renderer.particle.EntityPickupFX; import client.renderer.texture.EntityTexManager; +import client.util.PlayerController; import client.world.ChunkClient; import client.world.WorldClient; import common.attributes.Attribute; diff --git a/client/src/client/renderer/texture/ColormapLoader.java b/client/src/client/renderer/texture/ColormapLoader.java index 7566500..96ff88c 100644 --- a/client/src/client/renderer/texture/ColormapLoader.java +++ b/client/src/client/renderer/texture/ColormapLoader.java @@ -2,8 +2,8 @@ package client.renderer.texture; import java.awt.image.BufferedImage; +import client.util.FileUtils; import common.color.Colorizer; -import common.util.FileUtils; public abstract class ColormapLoader { private static final String GRASS_TEX = "textures/world/grass.png"; diff --git a/client/src/client/renderer/texture/EntityTexManager.java b/client/src/client/renderer/texture/EntityTexManager.java index b273901..1c0dcc6 100755 --- a/client/src/client/renderer/texture/EntityTexManager.java +++ b/client/src/client/renderer/texture/EntityTexManager.java @@ -13,6 +13,7 @@ import java.util.Set; import client.Client; import client.renderer.entity.RenderNpc; import client.renderer.layers.LayerExtra; +import client.util.FileUtils; import common.collect.Lists; import common.collect.Maps; import common.collect.Sets; @@ -20,7 +21,6 @@ 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 { diff --git a/client/src/client/renderer/texture/LayeredColorMaskTexture.java b/client/src/client/renderer/texture/LayeredColorMaskTexture.java index 654e960..93e2a2c 100755 --- a/client/src/client/renderer/texture/LayeredColorMaskTexture.java +++ b/client/src/client/renderer/texture/LayeredColorMaskTexture.java @@ -7,9 +7,9 @@ import java.io.IOException; import java.io.InputStream; import java.util.List; +import client.util.FileUtils; import common.color.DyeColor; import common.log.Log; -import common.util.FileUtils; public class LayeredColorMaskTexture extends Texture { diff --git a/client/src/client/renderer/texture/LayeredTexture.java b/client/src/client/renderer/texture/LayeredTexture.java index 5339db5..a6e29a3 100755 --- a/client/src/client/renderer/texture/LayeredTexture.java +++ b/client/src/client/renderer/texture/LayeredTexture.java @@ -6,9 +6,9 @@ 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 { diff --git a/client/src/client/renderer/texture/SimpleTexture.java b/client/src/client/renderer/texture/SimpleTexture.java index 43c4629..c4aa0ed 100755 --- a/client/src/client/renderer/texture/SimpleTexture.java +++ b/client/src/client/renderer/texture/SimpleTexture.java @@ -4,7 +4,7 @@ import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; -import common.util.FileUtils; +import client.util.FileUtils; public class SimpleTexture extends Texture { private final String location; diff --git a/client/src/client/renderer/texture/TextureMap.java b/client/src/client/renderer/texture/TextureMap.java index 5e5c2ee..b975ff7 100755 --- a/client/src/client/renderer/texture/TextureMap.java +++ b/client/src/client/renderer/texture/TextureMap.java @@ -9,13 +9,13 @@ import java.util.Map.Entry; import client.init.RenderRegistry; import client.renderer.GlState; +import client.util.FileUtils; 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 { diff --git a/client/src/client/renderer/texture/TextureUtil.java b/client/src/client/renderer/texture/TextureUtil.java index 71bced9..5fb705e 100755 --- a/client/src/client/renderer/texture/TextureUtil.java +++ b/client/src/client/renderer/texture/TextureUtil.java @@ -15,7 +15,7 @@ import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import client.renderer.GlState; -import common.util.FileUtils; +import client.util.FileUtils; public class TextureUtil { diff --git a/client/src/client/util/FileUtils.java b/client/src/client/util/FileUtils.java new file mode 100644 index 0000000..86f2731 --- /dev/null +++ b/client/src/client/util/FileUtils.java @@ -0,0 +1,65 @@ +package client.util; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.Charset; + +public class FileUtils { + private static final Charset UTF_8 = Charset.forName("UTF-8"); + + public static String read(File file) throws IOException { + FileInputStream in = null; + String s; + try { + in = new FileInputStream(file); + ByteArrayOutputStream output = new ByteArrayOutputStream(); + byte[] buffer = new byte[4096]; + long count = 0L; + int n; + for(boolean u = false; -1 != (n = in.read(buffer)); count += (long)n) { + output.write(buffer, 0, n); + } + s = new String(output.toByteArray(), UTF_8); + } + finally { + try { + if(in != null) + in.close(); + } + catch(IOException e) { + } + } + return s; + } + + public static void write(File file, String data) throws IOException { + FileOutputStream out = null; + try { + out = new FileOutputStream(file); + if(out != null) { + out.write(data.getBytes(UTF_8)); + out.close(); + } + } + finally { + try { + if(out != null) + out.close(); + } + catch(IOException e) { + } + } + } + + public static InputStream getResource(String path) throws FileNotFoundException { + InputStream in = FileUtils.class.getResourceAsStream("/" + path); + if(in == null) + throw new FileNotFoundException(path); + return in; + } +} diff --git a/client/src/client/PerfSection.java b/client/src/client/util/PerfSection.java similarity index 97% rename from client/src/client/PerfSection.java rename to client/src/client/util/PerfSection.java index ba9599f..9938445 100644 --- a/client/src/client/PerfSection.java +++ b/client/src/client/util/PerfSection.java @@ -1,4 +1,4 @@ -package client; +package client.util; import common.util.Util; diff --git a/client/src/client/PlayerController.java b/client/src/client/util/PlayerController.java similarity index 99% rename from client/src/client/PlayerController.java rename to client/src/client/util/PlayerController.java index a06986e..f23337f 100755 --- a/client/src/client/PlayerController.java +++ b/client/src/client/util/PlayerController.java @@ -1,5 +1,6 @@ -package client; +package client.util; +import client.Client; import client.network.ClientPlayer; import client.world.WorldClient; import common.block.Block; diff --git a/client/src/client/SkinConverter.java b/client/src/client/util/SkinConverter.java similarity index 99% rename from client/src/client/SkinConverter.java rename to client/src/client/util/SkinConverter.java index 6c7695e..037b0ea 100755 --- a/client/src/client/SkinConverter.java +++ b/client/src/client/util/SkinConverter.java @@ -1,4 +1,4 @@ -package client; +package client.util; import java.awt.Color; import java.awt.Graphics; diff --git a/common/src/common/ai/EntityAIEatGrass.java b/common/src/common/ai/EntityAIEatGrass.java index f04e8fd..0cd3820 100755 --- a/common/src/common/ai/EntityAIEatGrass.java +++ b/common/src/common/ai/EntityAIEatGrass.java @@ -1,22 +1,16 @@ package common.ai; -import java.util.function.Predicate; - import common.block.BlockTallGrass; import common.entity.animal.EntitySheep; import common.init.BlockRegistry; import common.init.Blocks; import common.init.Config; -import common.pattern.BlockStateHelper; import common.util.BlockPos; -import common.util.Predicates; import common.world.State; import common.world.World; public class EntityAIEatGrass extends EntityAIBase { - private static final Predicate field_179505_b = BlockStateHelper.forBlock(Blocks.tallgrass).where(BlockTallGrass.TYPE, Predicates.equalTo(BlockTallGrass.EnumType.GRASS)); - private EntitySheep grassEaterEntity; private World entityWorld; int eatingGrassTimer; @@ -40,7 +34,9 @@ public class EntityAIEatGrass extends EntityAIBase else { BlockPos blockpos = new BlockPos(this.grassEaterEntity.posX, this.grassEaterEntity.posY, this.grassEaterEntity.posZ); - return field_179505_b.test(this.entityWorld.getState(blockpos)) ? true : this.entityWorld.getState(blockpos.down()).getBlock() == Blocks.grass; + State state = this.entityWorld.getState(blockpos); + return (state.getBlock() == Blocks.tallgrass && state.getValue(BlockTallGrass.TYPE) == BlockTallGrass.EnumType.GRASS) || + this.entityWorld.getState(blockpos.down()).getBlock() == Blocks.grass; } } @@ -89,14 +85,15 @@ public class EntityAIEatGrass extends EntityAIBase { BlockPos blockpos = new BlockPos(this.grassEaterEntity.posX, this.grassEaterEntity.posY, this.grassEaterEntity.posZ); - if (field_179505_b.test(this.entityWorld.getState(blockpos))) + State state = this.entityWorld.getState(blockpos); + if (state.getBlock() == Blocks.tallgrass && state.getValue(BlockTallGrass.TYPE) == BlockTallGrass.EnumType.GRASS) { if (Config.mobGrief) { this.entityWorld.destroyBlock(blockpos, false); } - this.grassEaterEntity.eatGrassBonus(); + this.grassEaterEntity.eatGrass(); } else { @@ -110,7 +107,7 @@ public class EntityAIEatGrass extends EntityAIBase this.entityWorld.setState(blockpos1, Blocks.dirt.getState(), 2); } - this.grassEaterEntity.eatGrassBonus(); + this.grassEaterEntity.eatGrass(); } } } diff --git a/common/src/common/entity/animal/EntitySheep.java b/common/src/common/entity/animal/EntitySheep.java index dae424c..2ef3341 100755 --- a/common/src/common/entity/animal/EntitySheep.java +++ b/common/src/common/entity/animal/EntitySheep.java @@ -330,7 +330,7 @@ public class EntitySheep extends EntityAnimal * This function applies the benefits of growing back wool and faster growing up to the acting entity. (This * function is used in the AIEatGrass) */ - public void eatGrassBonus() + public void eatGrass() { this.setSheared(false); diff --git a/common/src/common/pattern/BlockStateHelper.java b/common/src/common/pattern/BlockStateHelper.java deleted file mode 100755 index df47558..0000000 --- a/common/src/common/pattern/BlockStateHelper.java +++ /dev/null @@ -1,61 +0,0 @@ -package common.pattern; - -import java.util.Map; -import java.util.Map.Entry; -import java.util.function.Predicate; - -import common.block.Block; -import common.collect.Maps; -import common.properties.IProperty; -import common.world.State; - -public class BlockStateHelper implements Predicate -{ - private final Block block; - private final Map predicates = Maps.newHashMap(); - - private BlockStateHelper(Block blockStateIn) - { - this.block = blockStateIn; - } - - public static BlockStateHelper forBlock(Block blockIn) - { - return new BlockStateHelper(blockIn); - } - - public boolean test(State p_apply_1_) - { - if (p_apply_1_ != null && p_apply_1_.getBlock().equals(this.block)) - { - for (Entry entry : this.predicates.entrySet()) - { - Object object = p_apply_1_.getValue((IProperty)entry.getKey()); - - if (!((Predicate)entry.getValue()).test(object)) - { - return false; - } - } - - return true; - } - else - { - return false; - } - } - - public > BlockStateHelper where(IProperty property, Predicate is) - { - if (!this.block.getPropertyMap().contains(property)) - { - throw new IllegalArgumentException(this.block + " cannot support property " + property); - } - else - { - this.predicates.put(property, is); - return this; - } - } -} diff --git a/common/src/common/util/FileUtils.java b/common/src/common/util/FileUtils.java deleted file mode 100644 index 5c01c4b..0000000 --- a/common/src/common/util/FileUtils.java +++ /dev/null @@ -1,97 +0,0 @@ -package common.util; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; - -import common.log.Log; -import io.netty.util.CharsetUtil; - -public class FileUtils { - public static String read(InputStream input) throws IOException { - return new String(readBytes(input), CharsetUtil.UTF_8); - } - - public static byte[] readBytes(InputStream input) throws IOException { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - byte[] buffer = new byte[4096]; - long count = 0L; - int n; - for(boolean u = false; -1 != (n = input.read(buffer)); count += (long)n) { - output.write(buffer, 0, n); - } - return output.toByteArray(); - } - - public static String read(File file) throws IOException { - FileInputStream in = null; - String s; - try { - in = new FileInputStream(file); - s = FileUtils.read(in); - } - finally { - try { - if(in != null) - in.close(); - } - catch(IOException e) { - } - } - return s; - } - - public static void write(File file, String data) throws IOException { - FileOutputStream out = null; - try { - out = new FileOutputStream(file); - if(out != null) { - out.write(data.getBytes(CharsetUtil.UTF_8)); - out.close(); - } - } - finally { - try { - if(out != null) - out.close(); - } - catch(IOException e) { - } - } - } - - public static InputStream getResource(String path) throws FileNotFoundException { - InputStream in = FileUtils.class.getResourceAsStream("/" + path); - if(in == null) - throw new FileNotFoundException(path); - return in; - } - - public static boolean deleteFiles(File[] files) { - if(files == null) { - Log.JNI.warn("Konnte Ordner nicht löschen"); - return false; - } - - for(int i = 0; i < files.length; ++i) { - File file = files[i]; - Log.JNI.info("Lösche " + file); - - if(file.isDirectory() && !deleteFiles(file.listFiles())) { - Log.JNI.warn("Konnte Ordner " + file + " nicht löschen"); - return false; - } - - if(!file.delete()) { - Log.JNI.warn("Konnte Datei " + file + " nicht löschen"); - return false; - } - } - - return true; - } -} diff --git a/server/src/server/world/WorldServer.java b/server/src/server/world/WorldServer.java index ee652d8..7808ed8 100755 --- a/server/src/server/world/WorldServer.java +++ b/server/src/server/world/WorldServer.java @@ -66,7 +66,6 @@ import common.util.BlockPos; import common.util.BoundingBox; import common.util.ChunkPos; import common.util.ExtMath; -import common.util.FileUtils; import common.util.IntHashMap; import common.util.LongHashMap; import common.util.NextTickListEntry; @@ -1002,6 +1001,30 @@ public final class WorldServer extends AWorldServer { map.clear(); } + private static boolean deleteFiles(File[] files) { + if(files == null) { + Log.JNI.warn("Konnte Ordner nicht löschen"); + return false; + } + + for(int i = 0; i < files.length; ++i) { + File file = files[i]; + Log.JNI.info("Lösche " + file); + + if(file.isDirectory() && !deleteFiles(file.listFiles())) { + Log.JNI.warn("Konnte Ordner " + file + " nicht löschen"); + return false; + } + + if(!file.delete()) { + Log.JNI.warn("Konnte Datei " + file + " nicht löschen"); + return false; + } + } + + return true; + } + public void saveAllChunks() { if(/* (force || !this.disableSaving) && */ !this.debug) { // if(this.primary) { @@ -1667,7 +1690,7 @@ public final class WorldServer extends AWorldServer { iter.remove(); } Region.finishWrite(); - FileUtils.deleteFiles(this.chunkDir.listFiles(new FileFilter() { + deleteFiles(this.chunkDir.listFiles(new FileFilter() { public boolean accept(File file) { return file.isDirectory(); } diff --git a/server/src/server/worldgen/feature/WorldGenDesertWells.java b/server/src/server/worldgen/feature/WorldGenDesertWells.java index f54c1e0..2fbe7f9 100755 --- a/server/src/server/worldgen/feature/WorldGenDesertWells.java +++ b/server/src/server/worldgen/feature/WorldGenDesertWells.java @@ -3,18 +3,15 @@ package server.worldgen.feature; import common.block.BlockSand; import common.block.BlockSlab; import common.init.Blocks; -import common.pattern.BlockStateHelper; import common.rng.Random; import common.util.BlockPos; import common.util.Facing; -import common.util.Predicates; import common.world.State; import server.world.WorldServer; import server.worldgen.FeatureGenerator; public class WorldGenDesertWells extends FeatureGenerator { - private static final BlockStateHelper field_175913_a = BlockStateHelper.forBlock(Blocks.sand).where(BlockSand.VARIANT, Predicates.equalTo(BlockSand.EnumType.SAND)); private final State field_175911_b = Blocks.sandstone_slab.getState().withProperty(BlockSlab.FACING, Facing.DOWN); private final State field_175912_c = Blocks.sandstone.getState(); private final State field_175910_d = Blocks.flowing_water.getState(); @@ -26,7 +23,8 @@ public class WorldGenDesertWells extends FeatureGenerator position = position.down(); } - if (!field_175913_a.test(worldIn.getState(position))) + State state = worldIn.getState(position); + if (state.getBlock() != Blocks.sand || state.getValue(BlockSand.VARIANT) != BlockSand.EnumType.SAND) { return false; }