split client and server 3

This commit is contained in:
Sen 2025-05-05 18:51:52 +02:00
parent b17efb5b07
commit d37bb7f6cc
7 changed files with 118 additions and 41 deletions

View file

@ -65,6 +65,7 @@ import client.renderer.chunk.RenderChunk;
import client.renderer.entity.RenderItem; import client.renderer.entity.RenderItem;
import client.renderer.entity.RenderManager; import client.renderer.entity.RenderManager;
import client.renderer.particle.EffectRenderer; import client.renderer.particle.EffectRenderer;
import client.renderer.particle.EntityFirework;
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;
@ -76,6 +77,7 @@ import client.window.Keysym;
import client.window.Wheel; import client.window.Wheel;
import client.window.Window; import client.window.Window;
import client.window.WindowEvent; import client.window.WindowEvent;
import game.IClient;
import game.biome.Biome; import game.biome.Biome;
import game.block.Block; import game.block.Block;
import game.collect.Lists; import game.collect.Lists;
@ -87,6 +89,7 @@ import game.entity.animal.EntityHorse;
import game.entity.npc.Energy; import game.entity.npc.Energy;
import game.entity.npc.EntityNPC; import game.entity.npc.EntityNPC;
import game.entity.types.EntityLiving; import game.entity.types.EntityLiving;
import game.entity.types.IEntityFX;
import game.future.Futures; import game.future.Futures;
import game.future.ListenableFuture; import game.future.ListenableFuture;
import game.future.ListenableFutureTask; import game.future.ListenableFutureTask;
@ -106,6 +109,7 @@ import game.log.Log;
import game.log.LogLevel; import game.log.LogLevel;
import game.log.Message; import game.log.Message;
import game.material.Material; import game.material.Material;
import game.nbt.NBTTagCompound;
import game.network.IThreadListener; import game.network.IThreadListener;
import game.network.NetConnection; import game.network.NetConnection;
import game.network.NetHandler.ThreadQuickExitException; import game.network.NetHandler.ThreadQuickExitException;
@ -122,6 +126,7 @@ import game.properties.IProperty;
import game.rng.Random; import game.rng.Random;
import game.sound.EventType; import game.sound.EventType;
import game.sound.PositionedSound; import game.sound.PositionedSound;
import game.sound.Sound;
import game.util.CharValidator; import game.util.CharValidator;
import game.util.ExtMath; import game.util.ExtMath;
import game.util.FileUtils; import game.util.FileUtils;
@ -175,7 +180,7 @@ import game.world.WorldClient;
[[oder einfach einen Toaster mit nem LCD und Maus]] [[oder einfach einen Toaster mit nem LCD und Maus]]
*/ */
public class Game implements IThreadListener { public class Game implements IThreadListener, IClient {
public static class SyncFunction implements IntFunction { public static class SyncFunction implements IntFunction {
public void apply(IntVar cv, int value) { public void apply(IntVar cv, int value) {
Game.getGame().sync(value); Game.getGame().sync(value);
@ -3275,4 +3280,50 @@ public class Game implements IThreadListener {
} }
}, "Zenity listener").start(); }, "Zenity listener").start();
} }
public void makeFireworks(double x, double y, double z, double motionX, double motionY, double motionZ, NBTTagCompound compund)
{
this.effectRenderer.addEffect(new EntityFirework.StarterFX(this.theWorld, x, y, z, motionX, motionY, motionZ, this.effectRenderer, compund));
}
public int getRenderDistance() {
return this.renderDistance;
}
public float getGravity() {
return this.gravity;
}
public int getTimeFactor() {
return this.timeFactor;
}
public boolean hasDayCycle() {
return this.dayCycle;
}
public void playSound(Sound sound) {
this.soundManager.playSound(sound);
}
public EntityNPC getPlayer() {
return this.thePlayer;
}
public IEntityFX spawnEffectParticle(int particleId, double xCoord, double yCoord, double zCoord, double xSpeed, double ySpeed, double zSpeed,
int[] parameters) {
return this.effectRenderer.spawnEffectParticle(particleId, xCoord, yCoord, zCoord, xSpeed, ySpeed, zSpeed, parameters);
}
public void addBlockDestroyEffects(BlockPos pos, State state) {
this.effectRenderer.addBlockDestroyEffects(pos, state);
}
public void sendBlockBreakProgress(int breakerId, BlockPos pos, int progress) {
this.renderGlobal.sendBlockBreakProgress(breakerId, pos, progress);
}
public void markBlocksForUpdate(int x1, int y1, int z1, int x2, int y2, int z2) {
this.renderGlobal.markBlocksForUpdate(x1, y1, z1, x2, y2, z2);
}
} }

View file

@ -184,7 +184,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer
NetHandler.checkThread(packetIn, this, this.gameController); NetHandler.checkThread(packetIn, this, this.gameController);
this.gameController.charEditor = packetIn.isInEditor(); this.gameController.charEditor = packetIn.isInEditor();
this.gameController.controller = new PlayerController(this.gameController, this); this.gameController.controller = new PlayerController(this.gameController, this);
this.clientWorldController = new WorldClient(this.gameController.debugWorld, packetIn.getDimension()); this.clientWorldController = new WorldClient(this.gameController, this.gameController.debugWorld, packetIn.getDimension());
// this.gameController.gameSettings.difficulty = packetIn.getDifficulty(); // this.gameController.gameSettings.difficulty = packetIn.getDifficulty();
this.gameController.loadWorld(this.clientWorldController, packetIn.getEntityType()); this.gameController.loadWorld(this.clientWorldController, packetIn.getEntityType());
// this.gameController.thePlayer.dimension = this.clientWorldController.dimension.getDimensionId(); // this.gameController.thePlayer.dimension = this.clientWorldController.dimension.getDimensionId();
@ -1046,7 +1046,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer
// this.travelSound = "portal.travel"; // this.travelSound = "portal.travel";
// } // }
// Scoreboard scoreboard = this.clientWorldController.getScoreboard(); // Scoreboard scoreboard = this.clientWorldController.getScoreboard();
this.clientWorldController = new WorldClient(this.gameController.debugWorld, dim); this.clientWorldController = new WorldClient(this.gameController, this.gameController.debugWorld, dim);
// this.clientWorldController.setWorldScoreboard(scoreboard); // this.clientWorldController.setWorldScoreboard(scoreboard);
this.gameController.loadWorld(this.clientWorldController, packetIn.getEntityType()); this.gameController.loadWorld(this.clientWorldController, packetIn.getEntityType());
// this.gameController.thePlayer.dimension = dim.getDimensionId(); // this.gameController.thePlayer.dimension = dim.getDimensionId();

View file

@ -5,11 +5,12 @@ import client.renderer.RenderBuffer;
import client.renderer.texture.TextureAtlasSprite; import client.renderer.texture.TextureAtlasSprite;
import game.entity.Entity; import game.entity.Entity;
import game.entity.EntityType; import game.entity.EntityType;
import game.entity.types.IEntityFX;
import game.nbt.NBTTagCompound; import game.nbt.NBTTagCompound;
import game.util.ExtMath; import game.util.ExtMath;
import game.world.World; import game.world.World;
public class EntityFX extends Entity public class EntityFX extends Entity implements IEntityFX
{ {
protected int particleTextureIndexX; protected int particleTextureIndexX;
protected int particleTextureIndexY; protected int particleTextureIndexY;

View file

@ -0,0 +1,24 @@
package game;
import game.entity.Entity;
import game.entity.npc.EntityNPC;
import game.entity.types.IEntityFX;
import game.nbt.NBTTagCompound;
import game.sound.Sound;
import game.world.BlockPos;
import game.world.State;
public interface IClient {
int getRenderDistance();
float getGravity();
int getTimeFactor();
boolean hasDayCycle();
void playSound(Sound sound);
EntityNPC getPlayer();
Entity getRenderViewEntity();
void makeFireworks(double x, double y, double z, double motionX, double motionY, double motionZ, NBTTagCompound compund);
IEntityFX spawnEffectParticle(int particleId, double xCoord, double yCoord, double zCoord, double xSpeed, double ySpeed, double zSpeed, int[] parameters);
void addBlockDestroyEffects(BlockPos pos, State state);
void sendBlockBreakProgress(int breakerId, BlockPos pos, int progress);
void markBlocksForUpdate(int x1, int y1, int z1, int x2, int y2, int z2);
}

View file

@ -14,20 +14,12 @@ import game.world.WorldServer;
public interface IServer { public interface IServer {
List<IPlayer> getIPlayers(); List<IPlayer> getIPlayers();
void sendPacket(Packet packet); void sendPacket(Packet packet);
void sendPacket(Packet packet, int dimension); void sendPacket(Packet packet, int dimension);
void sendNear(double x, double y, double z, double radius, int dimension, Packet packet); void sendNear(double x, double y, double z, double radius, int dimension, Packet packet);
void sendNearExcept(EntityNPC except, double x, double y, double z, double radius, int dimension, Packet packet); void sendNearExcept(EntityNPC except, double x, double y, double z, double radius, int dimension, Packet packet);
Map<String, Position> getWarps(); Map<String, Position> getWarps();
List<WorldServer> getWorlds(); List<WorldServer> getWorlds();
WorldServer getWorld(int dimension); WorldServer getWorld(int dimension);
void placeInDimension(Entity entity, WorldServer oldWorld, WorldServer world, BlockPos pos, PortalType portal); void placeInDimension(Entity entity, WorldServer oldWorld, WorldServer world, BlockPos pos, PortalType portal);
} }

View file

@ -0,0 +1,11 @@
package game.entity.types;
import client.renderer.particle.EntityFX;
public interface IEntityFX {
EntityFX multiplyVelocity(float multiplier);
void setRBGColorF(float particleRedIn, float particleGreenIn, float particleBlueIn);
}

View file

@ -3,9 +3,7 @@ package game.world;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import client.Game; import game.IClient;
import client.renderer.particle.EntityFX;
import client.renderer.particle.EntityFirework;
import game.biome.Biome; import game.biome.Biome;
import game.block.Block; import game.block.Block;
import game.collect.Lists; import game.collect.Lists;
@ -14,6 +12,7 @@ import game.dimension.Dimension;
import game.entity.Entity; import game.entity.Entity;
import game.entity.item.EntityCart; import game.entity.item.EntityCart;
import game.entity.npc.EntityNPC; import game.entity.npc.EntityNPC;
import game.entity.types.IEntityFX;
import game.init.BlockRegistry; import game.init.BlockRegistry;
import game.init.ItemRegistry; import game.init.ItemRegistry;
import game.init.Items; import game.init.Items;
@ -34,7 +33,7 @@ public class WorldClient extends World
{ {
private static final int DISPLAY_RANGE = 16; private static final int DISPLAY_RANGE = 16;
private final Game gm = Game.getGame(); private final IClient gm;
private final Set<Entity> entityList = Sets.<Entity>newHashSet(); private final Set<Entity> entityList = Sets.<Entity>newHashSet();
private final Set<Entity> spawnQueue = Sets.<Entity>newHashSet(); private final Set<Entity> spawnQueue = Sets.<Entity>newHashSet();
private final Set<ChunkPos> previousActive = Sets.<ChunkPos>newHashSet(); private final Set<ChunkPos> previousActive = Sets.<ChunkPos>newHashSet();
@ -45,14 +44,14 @@ public class WorldClient extends World
protected int lastLightning; protected int lastLightning;
protected Vec3 lightColor = new Vec3(0xffffff); protected Vec3 lightColor = new Vec3(0xffffff);
public WorldClient(boolean debug, Dimension dim) public WorldClient(IClient gm, boolean debug, Dimension dim)
{ {
super(dim, true, debug); super(dim, true, debug);
// this.gm = profiler; this.gm = gm;
this.calculateInitialSkylight(); this.calculateInitialSkylight();
this.calculateInitialWeather(); this.calculateInitialWeather();
this.setGravity(this.gm.gravity); this.setGravity(this.gm.getGravity());
this.setTimeFactor(this.gm.timeFactor); this.setTimeFactor(this.gm.getTimeFactor());
// this.setDifficulty(this.gm.difficulty); // this.setDifficulty(this.gm.difficulty);
} }
@ -60,7 +59,7 @@ public class WorldClient extends World
{ {
// this.info.tick(); // this.info.tick();
if (this.gm.dayCycle) if (this.gm.hasDayCycle())
{ {
this.daytime += this.timeFactor; this.daytime += this.timeFactor;
} }
@ -89,7 +88,7 @@ public class WorldClient extends World
protected void updateBlocks() protected void updateBlocks()
{ {
this.setActivePlayerChunksAndCheckLight(this.gm.renderDistance); this.setActivePlayerChunksAndCheckLight(this.gm.getRenderDistance());
this.previousActive.retainAll(this.active); this.previousActive.retainAll(this.active);
if (this.previousActive.size() == this.active.size()) if (this.previousActive.size() == this.active.size())
@ -157,7 +156,7 @@ public class WorldClient extends World
} }
else if (entityIn instanceof EntityCart) else if (entityIn instanceof EntityCart)
{ {
this.gm.getSoundManager().playSound(new MovingSoundMinecart((EntityCart)entityIn)); this.gm.playSound(new MovingSoundMinecart((EntityCart)entityIn));
} }
return flag; return flag;
@ -217,7 +216,7 @@ public class WorldClient extends World
public Entity getEntityByID(int id) public Entity getEntityByID(int id)
{ {
return (Entity)(id == this.gm.thePlayer.getId() ? this.gm.thePlayer : super.getEntityByID(id)); return (Entity)(id == this.gm.getPlayer().getId() ? this.gm.getPlayer() : super.getEntityByID(id));
} }
public Entity removeEntityFromWorld(int entityID) public Entity removeEntityFromWorld(int entityID)
@ -335,13 +334,13 @@ public class WorldClient extends World
// } // }
// else // else
// { // {
this.gm.getSoundManager().playSound(positionedsoundrecord); this.gm.playSound(positionedsoundrecord);
// } // }
} }
public void makeFireworks(double x, double y, double z, double motionX, double motionY, double motionZ, NBTTagCompound compund) 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, x, y, z, motionX, motionY, motionZ, this.gm.effectRenderer, compund)); this.gm.makeFireworks(x, y, z, motionX, motionY, motionZ, compund);
} }
public Chunk getChunk(int x, int z) public Chunk getChunk(int x, int z)
@ -370,9 +369,9 @@ public class WorldClient extends World
this.spawnEntityFX(particleType, particleType.getShouldIgnoreRange(), xCoord, yCoord, zCoord, xOffset, yOffset, zOffset, 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) public IEntityFX spawnEntityFX(ParticleType particle, boolean ignoreRange, double xCoord, double yCoord, double zCoord, double xOffset, double yOffset, double zOffset, int[] parameters)
{ {
if (this.gm != null && this.gm.getRenderViewEntity() != null && this.gm.effectRenderer != null) if (this.gm.getRenderViewEntity() != null)
{ {
int particleID = particle.getParticleID(); int particleID = particle.getParticleID();
// int i = this.gm.particleSetting; // int i = this.gm.particleSetting;
@ -388,18 +387,17 @@ public class WorldClient extends World
if (ignoreRange) if (ignoreRange)
{ {
return this.gm.effectRenderer.spawnEffectParticle(particleID, xCoord, yCoord, zCoord, xOffset, yOffset, zOffset, parameters); return this.gm.spawnEffectParticle(particleID, xCoord, yCoord, zCoord, xOffset, yOffset, zOffset, parameters);
} }
else else
{ {
double d3 = 16.0D; double d3 = 16.0D;
return d0 * d0 + d1 * d1 + d2 * d2 > 256.0D ? null : (/* i > 1 ? null : */ this.gm.effectRenderer.spawnEffectParticle(particleID, xCoord, yCoord, zCoord, xOffset, yOffset, zOffset, parameters)); if(d0 * d0 + d1 * d1 + d2 * d2 > 256.0D)
return null;
return this.gm.spawnEffectParticle(particleID, xCoord, yCoord, zCoord, xOffset, yOffset, zOffset, parameters);
} }
} }
else return null;
{
return null;
}
} }
// public void broadcastSound(int soundID, BlockPos pos, int data) // public void broadcastSound(int soundID, BlockPos pos, int data)
@ -583,10 +581,10 @@ public class WorldClient extends World
if (block.getMaterial() != Material.air) 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.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)); this.gm.addBlockDestroyEffects(blockPosIn, block.getStateFromMeta(data >> 12 & 255));
break; break;
case 2002: case 2002:
@ -623,7 +621,7 @@ public class WorldClient extends World
double d24 = Math.cos(d23) * d22; double d24 = Math.cos(d23) * d22;
double d9 = 0.01D + this.rand.doublev() * 0.5D; double d9 = 0.01D + this.rand.doublev() * 0.5D;
double d11 = Math.sin(d23) * d22; 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]); IEntityFX 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 (entityfx != null)
{ {
@ -660,7 +658,7 @@ public class WorldClient extends World
int i = pos.getX(); int i = pos.getX();
int j = pos.getY(); int j = pos.getY();
int k = pos.getZ(); int k = pos.getZ();
this.gm.renderGlobal.markBlocksForUpdate(i - 1, j - 1, k - 1, i + 1, j + 1, k + 1); this.gm.markBlocksForUpdate(i - 1, j - 1, k - 1, i + 1, j + 1, k + 1);
} }
public void notifyLightSet(BlockPos pos) public void notifyLightSet(BlockPos pos)
@ -668,17 +666,17 @@ public class WorldClient extends World
int i = pos.getX(); int i = pos.getX();
int j = pos.getY(); int j = pos.getY();
int k = pos.getZ(); int k = pos.getZ();
this.gm.renderGlobal.markBlocksForUpdate(i - 1, j - 1, k - 1, i + 1, j + 1, k + 1); this.gm.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) 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); this.gm.markBlocksForUpdate(x1 - 1, y1 - 1, z1 - 1, x2 + 1, y2 + 1, z2 + 1);
} }
public void sendBlockBreakProgress(int breakerId, BlockPos pos, int progress) public void sendBlockBreakProgress(int breakerId, BlockPos pos, int progress)
{ {
this.gm.renderGlobal.sendBlockBreakProgress(breakerId, pos, progress); this.gm.sendBlockBreakProgress(breakerId, pos, progress);
} }
public float getSunBrightness(float p_72971_1_) { public float getSunBrightness(float p_72971_1_) {