code cleanup

This commit is contained in:
Sen 2025-05-24 21:24:13 +02:00
parent d6d934f1f3
commit aa0ff6cf96
26 changed files with 207 additions and 276 deletions

View file

@ -70,6 +70,9 @@ import client.renderer.texture.ColormapLoader;
import client.renderer.texture.EntityTexManager; import client.renderer.texture.EntityTexManager;
import client.renderer.texture.TextureManager; import client.renderer.texture.TextureManager;
import client.renderer.texture.TextureMap; import client.renderer.texture.TextureMap;
import client.util.FileUtils;
import client.util.PerfSection;
import client.util.PlayerController;
import client.vars.BoolVar; import client.vars.BoolVar;
import client.vars.CVar; import client.vars.CVar;
import client.vars.CVarCategory; import client.vars.CVarCategory;
@ -152,7 +155,6 @@ import common.util.BoundingBox;
import common.util.CharValidator; import common.util.CharValidator;
import common.util.ExtMath; import common.util.ExtMath;
import common.util.Facing; import common.util.Facing;
import common.util.FileUtils;
import common.util.HitPosition; import common.util.HitPosition;
import common.util.LazyLoadBase; import common.util.LazyLoadBase;
import common.util.Util; import common.util.Util;
@ -317,6 +319,33 @@ public class Client implements IThreadListener {
public float zoomLevel; public float zoomLevel;
public float gravity = 1.0f; 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 TextureManager textureManager;
private RenderManager renderManager; private RenderManager renderManager;
private RenderItem renderItem; private RenderItem renderItem;
@ -784,14 +813,14 @@ public class Client implements IThreadListener {
this.deltaX = this.deltaY = 0.0f; this.deltaX = this.deltaY = 0.0f;
} }
if(this.player != null) 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()) if(this.player != null && this.player.isEntityInsideOpaqueBlock())
this.thirdPersonView = 0; this.thirdPersonView = 0;
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glClear(16640); GL11.glClear(16640);
GlState.enableTexture2D(); GlState.enableTexture2D();
if(this.world != null) 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(); GL11.glPopMatrix();
GlState.disableTexture2D(); GlState.disableTexture2D();
@ -824,7 +853,7 @@ public class Client implements IThreadListener {
this.setupOverlay(); this.setupOverlay();
if(this.world != null && this.open == null && this.thirdPersonView == 0 && this.viewEntity != null) { if(this.world != null && this.open == null && this.thirdPersonView == 0 && this.viewEntity != null) {
if(this.drawDebug) { if(this.drawDebug) {
this.renderWorldDirections((float)Timing.tick_fraction); this.renderWorldDirections((float)this.tick_fraction);
} }
else { 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 - 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(); this.renderLagometer();
} }
else { 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(); 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_VERSION), // WCF.glGetString(WCF.GL_SHADING_LANGUAGE_VERSION),
GL11.glGetString(GL11.GL_RENDERER), GL11.glGetString(GL11.GL_VENDOR), 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"), 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, (float)PerfSection.getTotal(false) / 1000.0f, this.fb_x, this.fb_y,
this.fullscreen ? " @ " + (this.vidMode == null ? "?" : this.vidMode.refresh) + " Hz" : "", this.fullscreen ? " @ " + (this.vidMode == null ? "?" : this.vidMode.refresh) + " Hz" : "",
this.tpscode(), Timing.tickrate < 1.0f ? 1.0f / Timing.tickrate : Timing.tickrate, this.tpscode(), this.tickrate < 1.0f ? 1.0f / this.tickrate : this.tickrate,
Timing.tickrate < 1.0f ? "SPT" : "TPS", (float)Timing.tickTarget / 1000.0f, this.tickrate < 1.0f ? "SPT" : "TPS", (float)this.tickTarget / 1000.0f,
(float)Timing.tick_time / 1000.0f, this.tickTimeout, (float)this.tick_time / 1000.0f, this.tickTimeout,
str != null ? "\n" : "", str != null ? str : "" str != null ? "\n" : "", str != null ? str : ""
); );
// if(str) // if(str)
@ -2165,14 +2194,14 @@ public class Client implements IThreadListener {
while(!this.interrupted) { while(!this.interrupted) {
PerfSection.swap(); PerfSection.swap();
PerfSection.TIMING.enter(); PerfSection.TIMING.enter();
Timing.tmr_current = Util.rtime(); this.tmr_current = Util.rtime();
Timing.tmr_delta = Timing.tmr_current - Timing.tmr_last; this.tmr_delta = this.tmr_current - this.tmr_last;
Timing.tmr_last = Timing.tmr_current; this.tmr_last = this.tmr_current;
Timing.fdelta = ((float)Timing.tmr_delta) / 1000000.0f; this.fdelta = ((float)this.tmr_delta) / 1000000.0f;
if((Timing.tmr_current - Timing.tmr_update) >= 1000000L) { if((this.tmr_current - this.tmr_update) >= 1000000L) {
Timing.framerate = ((float)Timing.tmr_frames) * 1000000.0f / ((float)(long)(Timing.tmr_current - Timing.tmr_update)); this.framerate = ((float)this.tmr_frames) * 1000000.0f / ((float)(long)(this.tmr_current - this.tmr_update));
Timing.tmr_frames = 0L; this.tmr_frames = 0L;
Timing.tmr_update = Timing.tmr_current; this.tmr_update = this.tmr_current;
} }
this.start(); this.start();
PerfSection.INPUT.enter(); PerfSection.INPUT.enter();
@ -2205,10 +2234,10 @@ public class Client implements IThreadListener {
long now = System.nanoTime(); long now = System.nanoTime();
this.addFrame(now - this.startNanoTime); this.addFrame(now - this.startNanoTime);
this.startNanoTime = now; 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 ..."); Log.SYSTEM.info("Beende ...");
@ -2348,46 +2377,46 @@ public class Client implements IThreadListener {
} }
public TextColor framecode() { 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() { 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 : 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 :
((Timing.tickrate >= (((float)Timing.tickTarget / 1000.0f) / 4.0f - 1.0f)) ? TextColor.ORANGE : TextColor.RED)); ((this.tickrate >= (((float)this.tickTarget / 1000.0f) / 4.0f - 1.0f)) ? TextColor.ORANGE : TextColor.RED));
} }
private void doTicks() { private void doTicks() {
Timing.tick_stime = Util.rtime(); this.tick_stime = Util.rtime();
if((Timing.tick_stime - Timing.tick_update) >= 1000000L) { if((this.tick_stime - this.tick_update) >= 1000000L) {
Timing.tickrate = ((float)Timing.tick_done) * 1000000.0f / ((float)(long)(Timing.tick_stime - Timing.tick_update)); this.tickrate = ((float)this.tick_done) * 1000000.0f / ((float)(long)(this.tick_stime - this.tick_update));
Timing.tick_done = 0; this.tick_done = 0;
Timing.tick_update = Timing.tick_stime; this.tick_update = this.tick_stime;
} }
Timing.tick_torun += (((long)Timing.tickTarget) * Timing.tmr_delta) / 1000L; this.tick_torun += (((long)this.tickTarget) * this.tmr_delta) / 1000L;
Timing.tickFrame = 0; this.tickFrame = 0;
Timing.tick_torun = Timing.tick_torun > 2000000L ? 1000000L : Timing.tick_torun; this.tick_torun = this.tick_torun > 2000000L ? 1000000L : this.tick_torun;
while(Timing.tick_torun >= 1000000L) { while(this.tick_torun >= 1000000L) {
this.tick(); this.tick();
Timing.tick_done += 1L; this.tick_done += 1L;
Timing.tickFrame += 1; this.tickFrame += 1;
Timing.tick_total += 1L; this.tick_total += 1L;
Timing.tick_torun -= 1000000L; this.tick_torun -= 1000000L;
if((Timing.tick_ftime = (Util.rtime() - Timing.tick_stime)) >= (((long)this.tickTimeout) * 1000L)) { 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", Timing.tick_ftime / 1000L, this.tickTimeout, Timing.tick_torun / 1000000L); 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);
Timing.tick_torun = 0L; this.tick_torun = 0L;
break; break;
} }
} }
Timing.tick_fraction = ((double)Timing.tick_torun) / 1000000.0; this.tick_fraction = ((double)this.tick_torun) / 1000000.0;
Timing.tick_ttime += Timing.tick_ftime; this.tick_ttime += this.tick_ftime;
Timing.tick_time = Timing.tickFrame != 0 ? (Timing.tick_ftime / (long)Timing.tickFrame) : 0L; this.tick_time = this.tickFrame != 0 ? (this.tick_ftime / (long)this.tickFrame) : 0L;
} }
public void tick_target(float tps) { public void tick_target(float tps) {
Timing.tickTarget = (int)(tps * 1000.0f); this.tickTarget = (int)(tps * 1000.0f);
Timing.tick_torun = 0L; this.tick_torun = 0L;
Timing.tick_done = 0L; this.tick_done = 0L;
Timing.tick_update = Util.rtime(); this.tick_update = Util.rtime();
} }
public void unload(boolean loading) { public void unload(boolean loading) {
@ -2748,6 +2777,14 @@ public class Client implements IThreadListener {
return buffer; return buffer;
} }
public float getTickFraction() {
return (float)this.tick_fraction;
}
public long getPassedTime() {
return this.tmr_delta;
}
private void regVar(CVar cv) { private void regVar(CVar cv) {
if(cvars.containsKey(cv.getCVarName())) if(cvars.containsKey(cv.getCVarName()))
throw new IllegalArgumentException("Variable " + cv.getCVarName() + " existiert bereits!"); throw new IllegalArgumentException("Variable " + cv.getCVarName() + " existiert bereits!");
@ -2963,7 +3000,7 @@ public class Client implements IThreadListener {
Log.CONSOLE.user(msg); Log.CONSOLE.user(msg);
if(size > 0) { if(size > 0) {
for(String line : msg.split("\n")) { 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) { while(log.size() >= size) {
log.remove(log.size() - 1); log.remove(log.size() - 1);
} }
@ -3011,7 +3048,7 @@ public class Client implements IThreadListener {
y = up ? y - Font.YGLYPH : y; y = up ? y - Font.YGLYPH : y;
for(Iterator<Message> iter = log.iterator(); iter.hasNext();) { for(Iterator<Message> iter = log.iterator(); iter.hasNext();) {
Message msg = iter.next(); 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) if(align > 0)
Drawing.drawTextbox(msg.message, x, y, bg); Drawing.drawTextbox(msg.message, x, y, bg);
else if(align < 0) else if(align < 0)

View file

@ -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;
}

View file

@ -11,6 +11,7 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import client.Client; import client.Client;
import client.util.FileUtils;
import common.collect.BiMap; import common.collect.BiMap;
import common.collect.HashBiMap; import common.collect.HashBiMap;
import common.collect.Lists; import common.collect.Lists;
@ -22,7 +23,6 @@ import common.rng.Random;
import common.sound.MovingSound; import common.sound.MovingSound;
import common.sound.Sound; import common.sound.Sound;
import common.util.ExtMath; import common.util.ExtMath;
import common.util.FileUtils;
public class SoundManager { public class SoundManager {
private class Source { private class Source {

View file

@ -8,8 +8,8 @@ import org.lwjgl.opengl.GL11;
import client.renderer.GlState; import client.renderer.GlState;
import client.renderer.texture.TextureUtil; import client.renderer.texture.TextureUtil;
import client.util.FileUtils;
import common.log.Log; import common.log.Log;
import common.util.FileUtils;
public class Font { public class Font {
public static final FontChar[] SIZES = new FontChar[256]; public static final FontChar[] SIZES = new FontChar[256];

View file

@ -12,11 +12,11 @@ import client.gui.element.ListEntry;
import client.gui.element.NavButton; import client.gui.element.NavButton;
import client.gui.element.PressType; import client.gui.element.PressType;
import client.renderer.Drawing; import client.renderer.Drawing;
import client.util.FileUtils;
import common.color.TextColor; import common.color.TextColor;
import common.init.Config; import common.init.Config;
import common.log.Log; import common.log.Log;
import common.network.IPlayer; import common.network.IPlayer;
import common.util.FileUtils;
import common.util.Tuple; import common.util.Tuple;
import common.util.Util; import common.util.Util;

View file

@ -1,6 +1,5 @@
package client.gui; package client.gui;
import client.Timing;
import client.gui.character.GuiChar; import client.gui.character.GuiChar;
import client.gui.character.GuiCharacters; import client.gui.character.GuiCharacters;
import client.gui.element.ActButton; import client.gui.element.ActButton;
@ -26,7 +25,7 @@ public class GuiMenu extends Gui {
if(this.gm.world != null) if(this.gm.world != null)
super.drawMainBackground(); super.drawMainBackground();
else 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(); private final Random rand = new Random();
@ -84,9 +83,9 @@ public class GuiMenu extends Gui {
int width = Drawing.getWidth("Hax!"); int width = Drawing.getWidth("Hax!");
for(int z = 0; z < 64; z++) { for(int z = 0; z < 64; z++) {
Drawing.drawText("Hax!", GuiMenu.this.rand.zrange(Math.max(1, this.gm.fb_x - width)) + 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)) + 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)); 0xff0000ff | (GuiMenu.this.rand.zrange(256) << 16));
} }
} }

View file

@ -16,7 +16,6 @@ import org.lwjgl.opengl.GL13;
import client.Client; import client.Client;
import client.Client.FileMode; import client.Client.FileMode;
import client.SkinConverter;
import client.gui.FileCallback; import client.gui.FileCallback;
import client.gui.GuiLoading; import client.gui.GuiLoading;
import client.gui.element.ActButton; import client.gui.element.ActButton;
@ -39,6 +38,8 @@ import client.renderer.GlState;
import client.renderer.ItemRenderer; import client.renderer.ItemRenderer;
import client.renderer.entity.RenderManager; import client.renderer.entity.RenderManager;
import client.renderer.texture.EntityTexManager; import client.renderer.texture.EntityTexManager;
import client.util.FileUtils;
import client.util.SkinConverter;
import client.vars.CVarCategory; import client.vars.CVarCategory;
import client.vars.EnumVar; import client.vars.EnumVar;
import client.vars.Variable; import client.vars.Variable;
@ -65,7 +66,6 @@ import common.packet.CPacketMessage;
import common.packet.CPacketSkin; import common.packet.CPacketSkin;
import common.rng.Random; import common.rng.Random;
import common.util.Displayable; import common.util.Displayable;
import common.util.FileUtils;
import common.util.Identifyable; import common.util.Identifyable;
import common.util.Util; import common.util.Util;

View file

@ -2,7 +2,6 @@ package client.gui.element;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import client.Timing;
import client.gui.Font; import client.gui.Font;
import client.renderer.Drawing; import client.renderer.Drawing;
import client.window.Button; 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) { public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
if(btn == Button.MOUSE_LEFT) { 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_start = this.sel_drag = 0;
this.sel_end = this.text.length(); this.sel_end = this.text.length();
} }
else { else {
gui_text_select(x, y, shift); 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) { else if((btn == Button.MOUSE_MIDDLE) && this.func != null) {
this.func.use(this, FieldAction.FUNCTION); this.func.use(this, FieldAction.FUNCTION);
@ -177,7 +176,7 @@ abstract class Textbox extends Element {
this.tmr_scroll -= ((long)n) * 1000000L; this.tmr_scroll -= ((long)n) * 1000000L;
else else
this.tmr_scroll = 0L; this.tmr_scroll = 0L;
this.tmr_scroll += Timing.tmr_delta; this.tmr_scroll += this.gm.getPassedTime();
return n; return n;
} }
return 0; return 0;

View file

@ -7,7 +7,6 @@ import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import client.Client; import client.Client;
import client.PlayerController;
import client.gui.Gui; import client.gui.Gui;
import client.gui.GuiConsole; import client.gui.GuiConsole;
import client.gui.GuiLoading; import client.gui.GuiLoading;
@ -28,6 +27,7 @@ import client.gui.ingame.GuiSign;
import client.gui.ingame.GuiForm; import client.gui.ingame.GuiForm;
import client.renderer.particle.EntityPickupFX; import client.renderer.particle.EntityPickupFX;
import client.renderer.texture.EntityTexManager; import client.renderer.texture.EntityTexManager;
import client.util.PlayerController;
import client.world.ChunkClient; import client.world.ChunkClient;
import client.world.WorldClient; import client.world.WorldClient;
import common.attributes.Attribute; import common.attributes.Attribute;

View file

@ -2,8 +2,8 @@ package client.renderer.texture;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import client.util.FileUtils;
import common.color.Colorizer; import common.color.Colorizer;
import common.util.FileUtils;
public abstract class ColormapLoader { public abstract class ColormapLoader {
private static final String GRASS_TEX = "textures/world/grass.png"; private static final String GRASS_TEX = "textures/world/grass.png";

View file

@ -13,6 +13,7 @@ import java.util.Set;
import client.Client; import client.Client;
import client.renderer.entity.RenderNpc; import client.renderer.entity.RenderNpc;
import client.renderer.layers.LayerExtra; import client.renderer.layers.LayerExtra;
import client.util.FileUtils;
import common.collect.Lists; import common.collect.Lists;
import common.collect.Maps; import common.collect.Maps;
import common.collect.Sets; import common.collect.Sets;
@ -20,7 +21,6 @@ import common.entity.npc.EntityNPC;
import common.init.SpeciesRegistry; import common.init.SpeciesRegistry;
import common.init.SpeciesRegistry.ModelType; import common.init.SpeciesRegistry.ModelType;
import common.log.Log; import common.log.Log;
import common.util.FileUtils;
public abstract class EntityTexManager public abstract class EntityTexManager
{ {

View file

@ -7,9 +7,9 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import client.util.FileUtils;
import common.color.DyeColor; import common.color.DyeColor;
import common.log.Log; import common.log.Log;
import common.util.FileUtils;
public class LayeredColorMaskTexture extends Texture public class LayeredColorMaskTexture extends Texture
{ {

View file

@ -6,9 +6,9 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import client.util.FileUtils;
import common.collect.Lists; import common.collect.Lists;
import common.log.Log; import common.log.Log;
import common.util.FileUtils;
public class LayeredTexture extends Texture public class LayeredTexture extends Texture
{ {

View file

@ -4,7 +4,7 @@ import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import common.util.FileUtils; import client.util.FileUtils;
public class SimpleTexture extends Texture { public class SimpleTexture extends Texture {
private final String location; private final String location;

View file

@ -9,13 +9,13 @@ import java.util.Map.Entry;
import client.init.RenderRegistry; import client.init.RenderRegistry;
import client.renderer.GlState; import client.renderer.GlState;
import client.util.FileUtils;
import common.block.Block; import common.block.Block;
import common.collect.Lists; import common.collect.Lists;
import common.collect.Maps; import common.collect.Maps;
import common.init.BlockRegistry; import common.init.BlockRegistry;
import common.init.FluidRegistry; import common.init.FluidRegistry;
import common.log.Log; import common.log.Log;
import common.util.FileUtils;
public class TextureMap extends Texture public class TextureMap extends Texture
{ {

View file

@ -15,7 +15,7 @@ import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12; import org.lwjgl.opengl.GL12;
import client.renderer.GlState; import client.renderer.GlState;
import common.util.FileUtils; import client.util.FileUtils;
public class TextureUtil public class TextureUtil
{ {

View file

@ -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;
}
}

View file

@ -1,4 +1,4 @@
package client; package client.util;
import common.util.Util; import common.util.Util;

View file

@ -1,5 +1,6 @@
package client; package client.util;
import client.Client;
import client.network.ClientPlayer; import client.network.ClientPlayer;
import client.world.WorldClient; import client.world.WorldClient;
import common.block.Block; import common.block.Block;

View file

@ -1,4 +1,4 @@
package client; package client.util;
import java.awt.Color; import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;

View file

@ -1,22 +1,16 @@
package common.ai; package common.ai;
import java.util.function.Predicate;
import common.block.BlockTallGrass; import common.block.BlockTallGrass;
import common.entity.animal.EntitySheep; import common.entity.animal.EntitySheep;
import common.init.BlockRegistry; import common.init.BlockRegistry;
import common.init.Blocks; import common.init.Blocks;
import common.init.Config; import common.init.Config;
import common.pattern.BlockStateHelper;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.Predicates;
import common.world.State; import common.world.State;
import common.world.World; import common.world.World;
public class EntityAIEatGrass extends EntityAIBase public class EntityAIEatGrass extends EntityAIBase
{ {
private static final Predicate<State> field_179505_b = BlockStateHelper.forBlock(Blocks.tallgrass).where(BlockTallGrass.TYPE, Predicates.equalTo(BlockTallGrass.EnumType.GRASS));
private EntitySheep grassEaterEntity; private EntitySheep grassEaterEntity;
private World entityWorld; private World entityWorld;
int eatingGrassTimer; int eatingGrassTimer;
@ -40,7 +34,9 @@ public class EntityAIEatGrass extends EntityAIBase
else else
{ {
BlockPos blockpos = new BlockPos(this.grassEaterEntity.posX, this.grassEaterEntity.posY, this.grassEaterEntity.posZ); 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); 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) if (Config.mobGrief)
{ {
this.entityWorld.destroyBlock(blockpos, false); this.entityWorld.destroyBlock(blockpos, false);
} }
this.grassEaterEntity.eatGrassBonus(); this.grassEaterEntity.eatGrass();
} }
else else
{ {
@ -110,7 +107,7 @@ public class EntityAIEatGrass extends EntityAIBase
this.entityWorld.setState(blockpos1, Blocks.dirt.getState(), 2); this.entityWorld.setState(blockpos1, Blocks.dirt.getState(), 2);
} }
this.grassEaterEntity.eatGrassBonus(); this.grassEaterEntity.eatGrass();
} }
} }
} }

View file

@ -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 * This function applies the benefits of growing back wool and faster growing up to the acting entity. (This
* function is used in the AIEatGrass) * function is used in the AIEatGrass)
*/ */
public void eatGrassBonus() public void eatGrass()
{ {
this.setSheared(false); this.setSheared(false);

View file

@ -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<State>
{
private final Block block;
private final Map<IProperty, Predicate> predicates = Maps.<IProperty, Predicate>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<IProperty, Predicate> 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 <V extends Comparable<V>> BlockStateHelper where(IProperty<V> property, Predicate <? extends V > is)
{
if (!this.block.getPropertyMap().contains(property))
{
throw new IllegalArgumentException(this.block + " cannot support property " + property);
}
else
{
this.predicates.put(property, is);
return this;
}
}
}

View file

@ -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;
}
}

View file

@ -66,7 +66,6 @@ import common.util.BlockPos;
import common.util.BoundingBox; import common.util.BoundingBox;
import common.util.ChunkPos; import common.util.ChunkPos;
import common.util.ExtMath; import common.util.ExtMath;
import common.util.FileUtils;
import common.util.IntHashMap; import common.util.IntHashMap;
import common.util.LongHashMap; import common.util.LongHashMap;
import common.util.NextTickListEntry; import common.util.NextTickListEntry;
@ -1002,6 +1001,30 @@ public final class WorldServer extends AWorldServer {
map.clear(); 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() { public void saveAllChunks() {
if(/* (force || !this.disableSaving) && */ !this.debug) { if(/* (force || !this.disableSaving) && */ !this.debug) {
// if(this.primary) { // if(this.primary) {
@ -1667,7 +1690,7 @@ public final class WorldServer extends AWorldServer {
iter.remove(); iter.remove();
} }
Region.finishWrite(); Region.finishWrite();
FileUtils.deleteFiles(this.chunkDir.listFiles(new FileFilter() { deleteFiles(this.chunkDir.listFiles(new FileFilter() {
public boolean accept(File file) { public boolean accept(File file) {
return file.isDirectory(); return file.isDirectory();
} }

View file

@ -3,18 +3,15 @@ package server.worldgen.feature;
import common.block.BlockSand; import common.block.BlockSand;
import common.block.BlockSlab; import common.block.BlockSlab;
import common.init.Blocks; import common.init.Blocks;
import common.pattern.BlockStateHelper;
import common.rng.Random; import common.rng.Random;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.Facing; import common.util.Facing;
import common.util.Predicates;
import common.world.State; import common.world.State;
import server.world.WorldServer; import server.world.WorldServer;
import server.worldgen.FeatureGenerator; import server.worldgen.FeatureGenerator;
public class WorldGenDesertWells extends 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_175911_b = Blocks.sandstone_slab.getState().withProperty(BlockSlab.FACING, Facing.DOWN);
private final State field_175912_c = Blocks.sandstone.getState(); private final State field_175912_c = Blocks.sandstone.getState();
private final State field_175910_d = Blocks.flowing_water.getState(); private final State field_175910_d = Blocks.flowing_water.getState();
@ -26,7 +23,8 @@ public class WorldGenDesertWells extends FeatureGenerator
position = position.down(); 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; return false;
} }