From 76e018b4ede2ea5a4673017cf1470d1ba75a07a3 Mon Sep 17 00:00:00 2001 From: Sen Date: Wed, 23 Jul 2025 13:19:32 +0200 Subject: [PATCH] minimize client world class --- client/src/main/java/client/Client.java | 553 +++++++++-- .../java/client/network/ClientPlayer.java | 237 ++++- .../java/client/renderer/EffectRenderer.java | 19 +- .../java/client/renderer/EntityRenderer.java | 252 ++++- .../client/renderer/RegionRenderCache.java | 10 +- .../java/client/renderer/RenderGlobal.java | 27 +- .../java/client/renderer/ViewFrustum.java | 10 +- .../client/renderer/chunk/RenderChunk.java | 13 +- .../renderer/tileentity/SpecialRenderer.java | 6 +- .../java/client/util/PlayerController.java | 11 +- .../main/java/client/world/ChunkEmpty.java | 3 +- .../main/java/client/world/WorldClient.java | 930 ------------------ common/src/main/java/common/block/Block.java | 5 +- .../main/java/common/block/BlockFalling.java | 2 +- .../common/block/artificial/BlockBed.java | 3 +- .../common/block/artificial/BlockCake.java | 3 +- .../common/block/artificial/BlockCarpet.java | 3 +- .../common/block/artificial/BlockDoor.java | 9 +- .../block/artificial/BlockDragonEgg.java | 2 +- .../block/artificial/BlockFloorPortal.java | 3 +- .../block/artificial/BlockFlowerPot.java | 2 +- .../common/block/artificial/BlockLadder.java | 3 +- .../common/block/artificial/BlockPortal.java | 6 +- .../common/block/artificial/BlockStairs.java | 3 +- .../java/common/block/foliage/BlockBush.java | 2 +- .../common/block/foliage/BlockCactus.java | 2 +- .../common/block/foliage/BlockFarmland.java | 2 +- .../common/block/foliage/BlockMycelium.java | 4 +- .../java/common/block/foliage/BlockReed.java | 2 +- .../java/common/block/foliage/BlockVine.java | 2 +- .../java/common/block/liquid/BlockLiquid.java | 5 +- .../block/liquid/BlockStaticLiquid.java | 4 +- .../common/block/natural/BlockBedrock.java | 4 +- .../java/common/block/natural/BlockFire.java | 5 +- .../java/common/block/natural/BlockSnow.java | 2 +- .../block/tech/BlockBasePressurePlate.java | 8 +- .../common/block/tech/BlockBrewingStand.java | 3 +- .../java/common/block/tech/BlockButton.java | 14 +- .../java/common/block/tech/BlockFurnace.java | 3 +- .../java/common/block/tech/BlockLever.java | 6 +- .../java/common/block/tech/BlockLitTorch.java | 3 +- .../java/common/block/tech/BlockMachine.java | 2 +- .../common/block/tech/BlockPistonBase.java | 24 +- .../common/block/tech/BlockPistonHead.java | 2 +- .../java/common/block/tech/BlockRail.java | 2 +- .../java/common/block/tech/BlockTorch.java | 2 +- .../java/common/block/tech/BlockTripWire.java | 8 +- .../common/block/tech/BlockTripWireHook.java | 11 +- .../common/block/tech/BlockWarpChest.java | 3 +- .../common/block/tile/BlockStandingSign.java | 3 +- .../java/common/block/tile/BlockWallSign.java | 4 +- .../common/entity/animal/EntityDragon.java | 3 +- .../common/entity/effect/EntityLightning.java | 8 +- .../common/entity/npc/EntityDarkMage.java | 3 +- .../java/common/entity/npc/EntityNPC.java | 3 +- .../common/tileentity/TileEntityChest.java | 13 +- .../main/java/common/util/LongHashMap.java | 8 + .../main/java/common/world/AWorldClient.java | 13 - .../main/java/common/world/AWorldServer.java | 2 + common/src/main/java/common/world/World.java | 127 +-- .../src/main/java/server/network/Player.java | 32 +- .../main/java/server/world/WorldServer.java | 62 +- 62 files changed, 1183 insertions(+), 1338 deletions(-) delete mode 100755 client/src/main/java/client/world/WorldClient.java delete mode 100644 common/src/main/java/common/world/AWorldClient.java diff --git a/client/src/main/java/client/Client.java b/client/src/main/java/client/Client.java index 172dd0b7..1110af9b 100755 --- a/client/src/main/java/client/Client.java +++ b/client/src/main/java/client/Client.java @@ -23,6 +23,7 @@ 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; @@ -97,17 +98,20 @@ import client.window.Wheel; import client.window.Window; import client.window.WindowEvent; import client.world.ChunkClient; -import client.world.WorldClient; +import client.world.ChunkEmpty; import common.Version; import common.block.Block; import common.collect.Lists; import common.collect.Maps; +import common.collect.Sets; import common.color.TextColor; +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; @@ -152,18 +156,25 @@ 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.Facing; import common.util.HitPosition; +import common.util.IntHashMap; +import common.util.LongHashMap; +import common.util.ParticleType; 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.World; @@ -270,6 +281,92 @@ public class Client implements IThreadListener { private record DebugFunction(Keysym key, DebugRunner runner, String help) { } + + private final class WorldClient extends World { + public WorldClient(Dimension dim) { + super(dim, true); + this.calculateInitialSkylight(); + this.calculateInitialWeather(); + this.updatePhysics(); + } + + public boolean spawnEntityInWorld(Entity entityIn) { + boolean flag = super.spawnEntityInWorld(entityIn); + Client.this.spawnEntityInWorld(flag, entityIn); + return flag; + } + + public void removeEntity(Entity entityIn) { + super.removeEntity(entityIn); + Client.this.removeEntity(entityIn); + } + + protected void onEntityAdded(Entity entityIn) { + Client.this.onEntityAdded(entityIn); + } + + protected void onEntityRemoved(Entity entityIn) { + Client.this.onEntityRemoved(entityIn); + } + + public Entity getEntityByID(int id) { + return id == Client.this.player.getId() ? Client.this.player : super.getEntityByID(id); + } + + public void playSound(double x, double y, double z, SoundEvent sound, float volume) { + Client.this.getSoundManager().playSound(new PositionedSound(sound, volume, (float)x, (float)y, (float)z)); + } + + public Chunk getChunk(int x, int z) { + return Client.this.getChunk(x, z); + } + + public Chunk getChunk(BlockPos pos) { + return Client.this.getChunk(pos.getX() >> 4, pos.getZ() >> 4); + } + + protected float getTemperature(BlockPos pos) { + if(!isValid(pos)) + return 0.0f; + ChunkClient chunk = Client.this.getChunk(pos.getX() >> 4, pos.getZ() >> 4); + return pos.getY() > 64 ? chunk.getTemperature(pos) - (chunk.getOffset(pos) + (float)pos.getY() - 64.0F) / 15.0f : chunk.getTemperature(pos); + } + + protected boolean isLoaded(int x, int z, boolean allowEmpty) { + return allowEmpty || !Client.this.getChunk(x, z).isDummy(); + } + + public void spawnParticle(ParticleType particle, double xCoord, double yCoord, double zCoord, int data) { + Client.this.effectRenderer.spawnParticle(Client.this.getRenderViewEntity(), particle, xCoord, yCoord, zCoord, data); + } + + public void playAuxSFX(EntityNPC player, int sfxType, BlockPos blockPosIn, int data) { + if(Client.this.getNetHandler() != null) + Client.this.getNetHandler().playAuxSFX(sfxType, blockPosIn, data); + } + + public void markBlockForUpdate(BlockPos pos) { + int x = pos.getX(); + int y = pos.getY(); + int z = pos.getZ(); + Client.this.renderGlobal.markBlocksForUpdate(x - 1, y - 1, z - 1, x + 1, y + 1, z + 1); + } + + public void notifyLightSet(BlockPos pos) { + int x = pos.getX(); + int y = pos.getY(); + int z = pos.getZ(); + Client.this.renderGlobal.markBlocksForUpdate(x - 1, y - 1, z - 1, x + 1, y + 1, z + 1); + } + + public void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2) { + Client.this.renderGlobal.markBlocksForUpdate(x1 - 1, y1 - 1, z1 - 1, x2 + 1, y2 + 1, z2 + 1); + } + + public void setLastLightning(int last, int color) { + Client.this.entityRenderer.setLastLightning(last, color); + } + } public static final String VERSION = Version.NAME + " Client " + Util.VERSION; public static final int LOG_BUFFER = 32768; @@ -295,6 +392,13 @@ public class Client implements IThreadListener { private final long[] frames = new long[240]; public final Map playerList = Maps.newTreeMap(); public final List characterList = Lists.newArrayList(); + private final Set entityList = Sets.newHashSet(); + private final Set spawnQueue = Sets.newHashSet(); + private final Set previousActive = Sets.newHashSet(); + private final LongHashMap chunkMapping = new LongHashMap(); + private final List chunkListing = Lists.newArrayList(); + private final Set emptyChunkListing = Sets.newHashSet(); + private final Set nextEmptyChunkListing = Sets.newHashSet(); private boolean primary; private boolean secondary; @@ -410,12 +514,19 @@ public class Client implements IThreadListener { private AudioInterface audio; private String buffer = ""; public PlayerController controller; - public WorldClient world; + public World world; public EntityNPC player; public HitPosition pointed; public DisplayMode vidMode; public String dimensionName; public String message; + private ChunkClient emptyChunk; + private ChunkClient outsideChunk; + + private List entities; + private List unloaded; + private List tiles; + private IntHashMap entityIds; @Variable(name = "chunk_view_distance", category = CVarCategory.RENDER, min = 2, max = 16, callback = DistanceFunction.class, display = "Sichtweite", unit = "Chunks") @@ -484,7 +595,7 @@ public class Client implements IThreadListener { @Variable(name = "draw_rain_particle_range", category = CVarCategory.RENDER, min = 0, max = 25, display = "Regen-Partikel-Radius") public int rainParticleRange = 10; @Variable(name = "draw_void_particles", category = CVarCategory.RENDER, display = "Partikel in der Tiefe") - public boolean voidParticles = true; + private boolean voidParticles = true; @Variable(name = "draw_void_fog", category = CVarCategory.RENDER, display = "Nebel in der Tiefe") public boolean voidFog = true; @Variable(name = "crosshair_size", category = CVarCategory.GUI, min = 0, max = 32, display = "Größe des Fadenkreuzes") @@ -601,8 +712,7 @@ public class Client implements IThreadListener { this.debugWorld = true; this.charEditor = false; this.controller = new PlayerController(this, player); - WorldClient world = new WorldClient(this, Space.INSTANCE); - this.loadWorld(world, EntityRegistry.getEntityID(EntityCpu.class)); + this.loadWorld(Space.INSTANCE, EntityRegistry.getEntityID(EntityCpu.class)); this.player.setId(0); this.show(null); this.player.flying = true; @@ -620,6 +730,7 @@ public class Client implements IThreadListener { this.viewEntity = null; this.connection = null; this.world = null; + this.resetWorld(); this.player = null; this.serverInfo = null; this.lastTickTime = -1; @@ -865,21 +976,20 @@ public class Client implements IThreadListener { if (this.chunkLoadTimer == 30) { this.chunkLoadTimer = 0; - this.world.ensureAreaLoaded(this.player); + this.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(); + this.tickWorld(); if (this.world != null) { - this.world.displayTick(ExtMath.floord(this.player.posX), ExtMath.floord(this.player.posY), ExtMath.floord(this.player.posZ)); + this.displayTick(ExtMath.floord(this.player.posX), ExtMath.floord(this.player.posY), ExtMath.floord(this.player.posZ)); } this.effectRenderer.update(); } @@ -1209,7 +1319,7 @@ public class Client implements IThreadListener { if(this.cameraUsed) { this.cameraUsed = false; if(this.world != null) - this.world.setLastLightning(1, 0xffffff); + this.entityRenderer.setLastLightning(1, 0xffffff); } if(this.isDirty()) this.save(); @@ -1489,12 +1599,18 @@ public class Client implements IThreadListener { } } - public void loadWorld(WorldClient world, int type) + public World loadWorld(Dimension dim, int type) { + this.resetWorld(); this.viewEntity = null; this.connection = null; this.soundManager.stopSounds(); - this.world = world; + this.world = new WorldClient(dim); + this.entities = this.world.entities; + this.unloaded = this.world.unloaded; + this.tiles = this.world.tiles; + this.entityIds = this.world.entityIds; + this.initWorld(); if (this.renderGlobal != null) { @@ -1517,11 +1633,12 @@ public class Client implements IThreadListener { this.viewEntity = this.player; System.gc(); + return this.world; } public void setDimensionAndSpawnPlayer(int type) { - this.world.removeAllEntities(); + this.removeAllEntities(); int i = 0; if (this.player != null) @@ -1694,18 +1811,14 @@ public class Client implements IThreadListener { 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) { + 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) { + BlockPos pos = new BlockPos(this.viewEntity.posX, this.viewEntity.getEntityBoundingBox().minY, this.viewEntity.posZ); + String dirStr; + switch(this.viewEntity.getHorizontalFacing()) { case NORTH: + default: dirStr = "Norden (Nach negativer Z)"; break; case SOUTH: @@ -1718,28 +1831,7 @@ public class Client implements IThreadListener { dirStr = "Osten (Nach positiver X)"; break; } - - String bline; - String lline; - if(this.world.isBlockLoaded(blockpos)) { - ChunkClient chunk = this.world.getChunk(blockpos); - bline = String.format("Biom: %.2f K, N: %.2f K, D: %s (%s)", chunk.getTemperature(blockpos), chunk.getOffset(blockpos), - TextColor.stripCodes(this.world.dimension.getDisplay()), - this.dimensionName == null ? UniverseRegistry.getName(this.world.dimension) : this.dimensionName); - lline = "Licht: " + chunk.getLightSub(blockpos, 0) + " (" + chunk.getLight(LightType.SKY, blockpos) + " Himmel, " - + chunk.getLight(LightType.BLOCK, blockpos) + " Blöcke, " + String.format( - "%.1f", this.world.getSunBrightness(1.0f) * 15.0f) + " Welt), A: " - + String.format("%.1f °", this.world.getCelestialAngle(1.0f)); - } - else { - bline = "Biom: , D: " + - TextColor.stripCodes(this.world.dimension.getDisplay()) + - " (" + (this.dimensionName == null ? UniverseRegistry.getName(this.world.dimension) : this.dimensionName) + ")"; - lline = "Licht: " + String.format( - "%.1f", this.world.getSunBrightness(1.0f) * 15.0f) + " Welt, A: " - + String.format("%.1f °", this.world.getCelestialAngle(1.0f)); - } - + ChunkClient chunk = this.getChunk(pos.getX() >> 4, pos.getZ() >> 4); long ticked = System.currentTimeMillis() - this.lastTicked; return @@ -1750,21 +1842,26 @@ public class Client implements IThreadListener { // this.connected != null ? this.connected : "[???]"))), this.renderGlobal.getDebugInfoRenders() + "\n" + this.renderGlobal.getDebugInfoEntities() + "\n" + - "Partikel: " + this.effectRenderer.getParticleCount() + ". O: " + this.world.getDebugLoadedEntities() + "\n" + - this.world.getInfo() + "\n" + + "Partikel: " + this.effectRenderer.getParticleCount() + ". O: " + this.entities.size() + "\n" + + "Chunk-Cache: M " + this.chunkMapping.getNumHashElements() + ", L " + this.chunkListing.size() + "\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 ? + String.format("Block: %d %d %d, R: '%s/%s'", pos.getX(), pos.getY(), pos.getZ(), + Util.getRegionFolder(pos.getX() >> 4, pos.getZ() >> 4), + Util.getRegionName(pos.getX() >> 4, pos.getZ() >> 4)) + "\n" + + String.format("Chunk: %d %d %d + %d %d %d, FOV: %.1f °%s", pos.getX() >> 4, pos.getY() >> 4, pos.getZ() >> 4, + pos.getX() & 15, pos.getY() & 15, pos.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" + - bline + "\n" + - lline + "\n" + + ExtMath.wrapf(this.viewEntity.rotYaw), ExtMath.wrapf(this.viewEntity.rotPitch)) + "\n" + + String.format("Biom: %.2f K, N: %.2f K, D: %s (%s)", chunk.getTemperature(pos), chunk.getOffset(pos), + TextColor.stripCodes(this.world.dimension.getDisplay()), + this.dimensionName == null ? UniverseRegistry.getName(this.world.dimension) : this.dimensionName) + "\n" + + "Licht: " + chunk.getLightSub(pos, 0) + " (" + chunk.getLight(LightType.SKY, pos) + " Himmel, " + + chunk.getLight(LightType.BLOCK, pos) + " Blöcke, " + String.format( + "%.1f", this.entityRenderer.getSunBrightness(1.0f) * 15.0f) + " Welt), A: " + + String.format("%.1f °", this.world.getCelestialAngle(1.0f)) + "\n" + String.format("Zeit: %d T, R %d / %d T, U %d / %d T", this.world.getDayTime(), this.world.getDayTime() % this.world.dimension.getRotationalPeriod(), @@ -1774,8 +1871,8 @@ public class Client implements IThreadListener { ) + "\n" + String.format("Laub: %s%s, T: %.2f K / %.2f °C, %s (R %.1f, %.1f)", !this.world.dimension.hasSeasons() ? "*" : "", - this.world.getLeavesGen(blockpos).getDisplayName(), - this.world.getTemperatureK(blockpos), this.world.getTemperatureC(blockpos), + this.world.getLeavesGen(pos).getDisplayName(), + this.world.getTemperatureK(pos), this.world.getTemperatureC(pos), this.world.getWeather().getDisplay(), this.world.getRainStrength(), this.world.getDarkness() ) + "\n" + @@ -3225,6 +3322,348 @@ public class Client implements IThreadListener { } } + private void displayTick(int posX, int posY, int posZ) { + int range = 16; + Random rand = new Random(); + BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(); + for(int n = 0; n < 1000; n++) { + int x = posX + rand.zrange(range) - rand.zrange(range); + int y = posY + rand.zrange(range) - rand.zrange(range); + int z = posZ + rand.zrange(range) - rand.zrange(range); + pos.set(x, y, z); + State state = this.world.getState(pos); + state.getBlock().displayTick(this.world, pos, state, rand); + } + if(this.world.dimension.hasVoidFog() && this.voidParticles && posY < 32) { + for(int n = 0; n < 1000; n++) { + float x = ((float)posX) + (rand.floatv() - rand.floatv() - 0.5f) * 32.0f; + float y = (posY < -32 ? (float)posY - 32.0f : -64.0f) + rand.floatv() * 65.0f; + float z = ((float)posZ) + (rand.floatv() - rand.floatv() - 0.5f) * 32.0f; + if(y < -64.0f || rand.floatv() >= (64.0f + y) / 64.0f) + this.world.spawnParticle(ParticleType.DEPTH, (double)x, (double)y, (double)z); + } + } + } + + private void initWorld() { + this.emptyChunk = new ChunkEmpty(this.world, false, this.debugWorld); + this.outsideChunk = new ChunkEmpty(this.world, true, this.debugWorld); + } + + private void resetWorld() { + this.entityList.clear(); + this.spawnQueue.clear(); + this.previousActive.clear(); + this.chunkMapping.clear(); + this.chunkListing.clear(); + this.emptyChunkListing.clear(); + this.nextEmptyChunkListing.clear(); + this.emptyChunk = null; + this.outsideChunk = null; + this.entityRenderer.resetLightning(); + this.entities = null; + this.unloaded = null; + this.tiles = null; + this.entityIds = null; + } + + public ChunkClient getChunk(int x, int z) { + ChunkClient chunk = this.chunkMapping.getValueByKey(LongHashMap.packInt(x, z)); + return chunk == null ? this.getEmptyChunk(x, z) : chunk; + } + + private ChunkClient getEmptyChunk(int x, int z) { + int size = this.world.dimension.getSize() / 16; + return x < -size || z < -size || x >= size || z >= size ? this.outsideChunk : this.emptyChunk; + } + + public void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2) { + this.renderGlobal.markBlocksForUpdate(x1 - 1, y1 - 1, z1 - 1, x2 + 1, y2 + 1, z2 + 1); + } + + private void markReload(int cx, int cz, int range) { + this.nextEmptyChunkListing.clear(); + for(int x = cx - range; x <= cx + range; x++) { + for(int z = cz - range; z <= cz + range; z++) { + long id = LongHashMap.packInt(x, z); + if(this.chunkMapping.getValueByKey(id) != null) { + if(this.emptyChunkListing.contains(id)) { + this.emptyChunkListing.remove(id); + this.nextEmptyChunkListing.add(id); + } + continue; + } + this.chunkMapping.add(id, this.getEmptyChunk(x, z)); + this.emptyChunkListing.remove(id); + this.nextEmptyChunkListing.add(id); + this.markBlockRangeForRenderUpdate(x << 4, -World.MAX_SIZE_Y, z << 4, (x << 4) + 15, World.MAX_SIZE_Y, (z << 4) + 15); + } + } + for(Long id : this.emptyChunkListing) { + this.chunkMapping.remove(id); + int x = LongHashMap.getX(id); + int z = LongHashMap.getZ(id); + this.markBlockRangeForRenderUpdate(x << 4, -World.MAX_SIZE_Y, z << 4, (x << 4) + 15, World.MAX_SIZE_Y, (z << 4) + 15); + } + this.emptyChunkListing.clear(); + this.emptyChunkListing.addAll(this.nextEmptyChunkListing); + } + + public void markReload() { + if(this.player != null && !this.charEditor) + this.markReload((int)this.player.posX >> 4, (int)this.player.posZ >> 4, this.renderDistance + 4); + } + + public void setExterminated(boolean exterminated) { + this.world.dimension.setExterminated(exterminated); + this.initWorld(); + this.markReload(); + for(Long id : this.emptyChunkListing) { + int x = LongHashMap.getX(id); + int z = LongHashMap.getZ(id); + this.chunkMapping.add(id, this.getEmptyChunk(x, z)); + this.markBlockRangeForRenderUpdate(x << 4, -World.MAX_SIZE_Y, z << 4, (x << 4) + 15, World.MAX_SIZE_Y, (z << 4) + 15); + } + } + + private void tickWorld() + { + this.world.updatePhysics(); + this.markReload(); + + if (Vars.dayCycle) + { + this.world.setDayTime(this.world.getDayTime() + (long)Vars.timeFlow); + } + + 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.world.spawnEntityInWorld(entity); + } + } + long time = System.currentTimeMillis(); + for (ChunkClient chunk : this.chunkListing) + { + chunk.update(System.currentTimeMillis() - time > 5L); + } + if (System.currentTimeMillis() - time > 100L) + { + Log.TICK.warn("Render-Chunk-Tick dauerte " + (System.currentTimeMillis() - time) + " ms"); + } + + Set active = this.world.setActivePlayerChunksAndCheckLight(this.renderDistance); + this.previousActive.retainAll(active); + + if (this.previousActive.size() == active.size()) + { + this.previousActive.clear(); + } + + int i = 0; + + for (ChunkPos chunkcoordintpair : active) + { + if (!this.previousActive.contains(chunkcoordintpair)) + { + int j = chunkcoordintpair.x * 16; + int k = chunkcoordintpair.z * 16; + ChunkClient 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) + { + long id = LongHashMap.packInt(x, z); + if (load) + { + if(this.chunkMapping.getValueByKey(id) != null) + this.doPreChunk(x, z, false); + ChunkClient chunk = new ChunkClient(this.world, x, z); + this.chunkMapping.add(id, chunk); + this.chunkListing.add(chunk); + chunk.setLoaded(); + } + else + { + ChunkClient chunk = this.getChunk(x, z); + chunk.onChunkUnload(); + this.chunkMapping.remove(id); + this.chunkListing.remove(chunk); + this.emptyChunkListing.remove(id); + } + + if (!load) + { + this.markBlockRangeForRenderUpdate(x * 16, -World.MAX_SIZE_Y, z * 16, x * 16 + 15, World.MAX_SIZE_Y, z * 16 + 15); + } + } + + public void addEntityToWorld(int entityID, Entity entityToSpawn) + { + Entity entity = this.world.getEntityByID(entityID); + + if (entity != null) + { + this.world.removeEntity(entity); + } + + this.entityList.add(entityToSpawn); + entityToSpawn.setId(entityID); + + if (!this.world.spawnEntityInWorld(entityToSpawn)) + { + this.spawnQueue.add(entityToSpawn); + } + + this.entityIds.addKey(entityID, entityToSpawn); + } + + public Entity removeEntityFromWorld(int entityID) + { + Entity entity = this.entityIds.removeObject(entityID); + + if (entity != null) + { + this.entityList.remove(entity); + this.world.removeEntity(entity); + } + + return entity; + } + + private void removeAllEntities() + { + this.entities.removeAll(this.unloaded); + + for (int i = 0; i < this.unloaded.size(); ++i) + { + Entity entity = this.unloaded.get(i); + int j = entity.chunkCoordX; + int k = entity.chunkCoordZ; + + if (entity.addedToChunk) + { + this.getChunk(j, k).removeEntity(entity); + } + } + + for (int l = 0; l < this.unloaded.size(); ++l) + { + this.onEntityRemoved(this.unloaded.get(l)); + } + + this.unloaded.clear(); + + for (int i1 = 0; i1 < this.entities.size(); ++i1) + { + Entity entity1 = 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.getChunk(j1, k1).removeEntity(entity1); + } + + this.entities.remove(i1--); + this.onEntityRemoved(entity1); + } + } + } + + private void spawnEntityInWorld(boolean flag, Entity entityIn) + { + this.entityList.add(entityIn); + if (!flag) + { + this.spawnQueue.add(entityIn); + } + else if (entityIn instanceof EntityCart) + { + this.soundManager.playSound(new MovingSoundMinecart((EntityCart)entityIn)); + } + } + + private void removeEntity(Entity entityIn) + { + this.entityList.remove(entityIn); + } + + private void onEntityAdded(Entity entityIn) + { + if (this.spawnQueue.contains(entityIn)) + { + this.spawnQueue.remove(entityIn); + } + } + + private 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); + } + } + } + + private void ensureAreaLoaded(Entity entity) { + int x = ExtMath.floord(entity.posX / 16.0D); + int z = ExtMath.floord(entity.posZ / 16.0D); + int r = 2; + for(int cx = x - r; cx <= x + r; ++cx) { + for(int cz = z - r; cz <= z + r; ++cz) { + this.getChunk(cx, cz); + } + } + if(!this.entities.contains(entity)) + this.entities.add(entity); + } + + public List getEntities() { + return this.entities; + } + + public List getTiles() { + return this.tiles; + } + 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]; diff --git a/client/src/main/java/client/network/ClientPlayer.java b/client/src/main/java/client/network/ClientPlayer.java index 27524803..8a25a0e5 100755 --- a/client/src/main/java/client/network/ClientPlayer.java +++ b/client/src/main/java/client/network/ClientPlayer.java @@ -24,7 +24,6 @@ import client.gui.ingame.GuiForm; import client.renderer.texture.EntityTexManager; import client.util.PlayerController; import client.world.ChunkClient; -import client.world.WorldClient; import common.block.Block; import common.block.tech.BlockAnvil; import common.block.tech.BlockChest; @@ -44,9 +43,11 @@ import common.entity.npc.EntityNPC; import common.entity.npc.PlayerCharacter; import common.entity.projectile.EntityProjectile; 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.SoundEvent; import common.init.UniverseRegistry; import common.inventory.Container; @@ -54,6 +55,7 @@ import common.inventory.InventoryBasic; import common.inventory.InventoryPlayer; import common.inventory.InventoryWarpChest; import common.item.ItemStack; +import common.item.material.ItemDye; import common.log.Log; import common.network.IClientPlayer; import common.network.NetConnection; @@ -124,15 +126,21 @@ import common.packet.SPacketTrades; import common.packet.SPacketUpdateDisplay; import common.packet.SPacketUpdateHealth; import common.rng.Random; +import common.sound.PositionedSound; import common.sound.Sound; import common.tileentity.TileEntity; +import common.tileentity.TileEntityChest; import common.tileentity.Device; import common.tileentity.TileEntityDisplay; import common.tileentity.TileEntitySign; +import common.util.BlockPos; import common.util.Pair; +import common.util.ParticleType; import common.util.WorldPos; +import common.util.BlockPos.MutableBlockPos; import common.village.MerchantRecipeList; import common.world.Explosion; +import common.world.State; import common.world.Weather; import common.world.World; @@ -140,7 +148,7 @@ public class ClientPlayer implements IClientPlayer { protected final Client gm; private final NetConnection connection; - private WorldClient world; + private World world; private boolean loaded; private final Random rand = new Random(); @@ -236,9 +244,8 @@ public class ClientPlayer implements IClientPlayer this.gm.dimensionName = packetIn.getDimName(); this.gm.charEditor = packetIn.isInEditor(); this.gm.controller = new PlayerController(this.gm, this); - this.world = new WorldClient(this.gm, packetIn.getDimension()); // this.gameController.gameSettings.difficulty = packetIn.getDifficulty(); - this.gm.loadWorld(this.world, packetIn.getEntityType()); + this.world = this.gm.loadWorld(packetIn.getDimension(), packetIn.getEntityType()); // this.gameController.thePlayer.dimension = this.clientWorldController.dimension.getDimensionId(); this.gm.player.setId(packetIn.getEntityId()); this.gm.show(this.gm.charEditor ? GuiChar.INSTANCE : null); @@ -400,7 +407,7 @@ public class ClientPlayer implements IClientPlayer } entity.setId(packetIn.getEntityID()); - this.world.addEntityToWorld(packetIn.getEntityID(), entity); + this.gm.addEntityToWorld(packetIn.getEntityID(), entity); if(entity instanceof EntityProjectile projectile) { projectile.setAcceleration((double)packetIn.getSpeedX() / 8000.0D, (double)packetIn.getSpeedY() / 8000.0D, (double)packetIn.getSpeedZ() / 8000.0D); @@ -537,7 +544,7 @@ public class ClientPlayer implements IClientPlayer } player.setPositionAndRotation(x, y, z, yaw, pitch); - this.world.addEntityToWorld(packetIn.getEntityID(), player); + this.gm.addEntityToWorld(packetIn.getEntityID(), player); List list = packetIn.getData(); if (list != null) @@ -647,7 +654,7 @@ public class ClientPlayer implements IClientPlayer for (int i = 0; i < packetIn.getEntityIDs().length; ++i) { - this.world.removeEntityFromWorld(packetIn.getEntityIDs()[i]); + this.gm.removeEntityFromWorld(packetIn.getEntityIDs()[i]); EntityTexManager.setTexture(packetIn.getEntityIDs()[i], null, null); } } @@ -713,7 +720,7 @@ public class ClientPlayer implements IClientPlayer this.gm.player.prevY = this.gm.player.posY; this.gm.player.prevZ = this.gm.player.posZ; this.loaded = true; - this.world.markReload(); + this.gm.markReload(); // this.gameController.displayGuiScreen(null); // if(this.travelSound) { // this.gameController.getSoundManager().playSound(new PositionedSound(SoundEvent.TELEPORT)); @@ -734,7 +741,7 @@ public class ClientPlayer implements IClientPlayer for (SPacketMultiBlockChange.BlockUpdateData update : packetIn.getChangedBlocks()) { - this.world.invalidateRegionAndSetBlock(SPacketMultiBlockChange.getPos(packetIn.getChunkPos(), update.getRawPos()), update.getBlockState()); + this.world.setState(SPacketMultiBlockChange.getPos(packetIn.getChunkPos(), update.getRawPos()), update.getBlockState()); } } @@ -749,17 +756,17 @@ public class ClientPlayer implements IClientPlayer { if (packetIn.getExtractedExtend().length == 0) { - this.world.doPreChunk(packetIn.getChunkX(), packetIn.getChunkZ(), false); + this.gm.doPreChunk(packetIn.getChunkX(), packetIn.getChunkZ(), false); return; } - this.world.doPreChunk(packetIn.getChunkX(), packetIn.getChunkZ(), true); + this.gm.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); - ChunkClient chunk = this.world.getChunk(packetIn.getChunkX(), packetIn.getChunkZ()); + ChunkClient chunk = this.gm.getChunk(packetIn.getChunkX(), packetIn.getChunkZ()); chunk.setData(packetIn.getExtractedDataBytes(), packetIn.getExtractedExtend(), packetIn.hasBiomes()); - this.world.markBlockRangeForRenderUpdate(packetIn.getChunkX() << 4, -World.MAX_SIZE_Y, packetIn.getChunkZ() << 4, (packetIn.getChunkX() << 4) + 15, World.MAX_SIZE_Y, (packetIn.getChunkZ() << 4) + 15); + this.gm.markBlockRangeForRenderUpdate(packetIn.getChunkX() << 4, -World.MAX_SIZE_Y, packetIn.getChunkZ() << 4, (packetIn.getChunkX() << 4) + 15, World.MAX_SIZE_Y, (packetIn.getChunkZ() << 4) + 15); if (!packetIn.hasBiomes() || !this.world.dimension.hasSkyLight()) // TODO: check { @@ -773,7 +780,7 @@ public class ClientPlayer implements IClientPlayer public void handleBlockChange(SPacketBlockChange packetIn) { NetHandler.checkThread(packetIn, this, this.gm, this.world); - this.world.invalidateRegionAndSetBlock(packetIn.getBlockPosition(), packetIn.getBlockState()); + this.world.setState(packetIn.getBlockPosition(), packetIn.getBlockState()); } /** @@ -806,7 +813,7 @@ public class ClientPlayer implements IClientPlayer this.world.playSoundAtEntity(entity, SoundEvent.POP, 0.2F); } - this.world.removeEntityFromWorld(packetIn.getCollectedItemEntityID()); + this.gm.removeEntityFromWorld(packetIn.getCollectedItemEntityID()); } } @@ -952,7 +959,7 @@ public class ClientPlayer implements IClientPlayer 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.world.addEntityToWorld(packetIn.getEntityID(), entitylivingbase); + this.gm.addEntityToWorld(packetIn.getEntityID(), entitylivingbase); List list = packetIn.getMetadata(); if (list != null) @@ -1082,9 +1089,8 @@ public class ClientPlayer implements IClientPlayer // this.travelSound = "portal.travel"; // } // Scoreboard scoreboard = this.clientWorldController.getScoreboard(); - this.world = new WorldClient(this.gm, dim); // this.clientWorldController.setWorldScoreboard(scoreboard); - this.gm.loadWorld(this.world, packetIn.getEntityType()); + this.world = this.gm.loadWorld(dim, packetIn.getEntityType()); // this.gameController.thePlayer.dimension = dim.getDimensionId(); } // else if(this.gameController.charEditor) { @@ -1376,7 +1382,7 @@ public class ClientPlayer implements IClientPlayer public void handleBlockBreakAnim(SPacketBlockBreakAnim packetIn) { NetHandler.checkThread(packetIn, this, this.gm, this.world); - this.gm.world.sendBlockBreakProgress(packetIn.getBreakerId(), packetIn.getPosition(), packetIn.getProgress()); + this.gm.renderGlobal.sendBlockBreakProgress(packetIn.getBreakerId(), packetIn.getPosition(), packetIn.getProgress()); } public void handleMapChunkBulk(SPacketMapChunkBulk packetIn) @@ -1387,11 +1393,11 @@ public class ClientPlayer implements IClientPlayer { int j = packetIn.getChunkX(i); int k = packetIn.getChunkZ(i); - this.world.doPreChunk(j, k, true); + this.gm.doPreChunk(j, k, true); // this.clientWorldController.invalidateBlockReceiveRegion(j << 4, 0, k << 4, (j << 4) + 15, 512, (k << 4) + 15); - ChunkClient chunk = this.world.getChunk(j, k); + ChunkClient chunk = this.gm.getChunk(j, k); chunk.setData(packetIn.getChunkBytes(i), packetIn.getChunkExtend(i), true); - this.world.markBlockRangeForRenderUpdate(j << 4, -World.MAX_SIZE_Y, k << 4, (j << 4) + 15, World.MAX_SIZE_Y, (k << 4) + 15); + this.gm.markBlockRangeForRenderUpdate(j << 4, -World.MAX_SIZE_Y, k << 4, (j << 4) + 15, World.MAX_SIZE_Y, (k << 4) + 15); if (!this.world.dimension.hasSkyLight()) // TODO: check { @@ -1430,14 +1436,181 @@ public class ClientPlayer implements IClientPlayer { NetHandler.checkThread(packetIn, this, this.gm, this.world); -// if (packetIn.isSoundServerwide()) -// { -// this.gameController.theWorld.broadcastSound(packetIn.getSoundType(), packetIn.getSoundPos(), packetIn.getSoundData()); -// } -// else -// { - this.gm.world.playAuxSFX(packetIn.getSoundType(), packetIn.getSoundPos(), packetIn.getSoundData()); -// } + this.playAuxSFX(packetIn.getSoundType(), packetIn.getSoundPos(), packetIn.getSoundData()); + } + + private void spawnParticle(ParticleType particle, double xCoord, double yCoord, double zCoord, int data) { + this.gm.effectRenderer.spawnParticle(this.gm.getRenderViewEntity(), particle, xCoord, yCoord, zCoord, data); + } + + private void spawnParticle(ParticleType particle, double xCoord, double yCoord, double zCoord) { + this.gm.effectRenderer.spawnParticle(this.gm.getRenderViewEntity(), particle, xCoord, yCoord, zCoord, 0); + } + + private void playSoundAtPos(BlockPos pos, SoundEvent sound, float volume) + { + this.gm.getSoundManager().playSound(new PositionedSound(sound, volume, (float)pos.getX() + 0.5f, (float)pos.getY() + 0.5f, (float)pos.getZ() + 0.5f)); + } + + public void playAuxSFX(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 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: + 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 < 1000; z++) { + this.spawnParticle(ParticleType.EXPLOSION_HUGE, + (double)pos.getX() + this.rand.gaussian() * 128.0, (double)pos.getY() + this.rand.gaussian() * 2.0, (double)pos.getZ() + this.rand.gaussian() * 128.0); + } + for(int z = 0; z < 1000; z++) { + this.spawnParticle(ParticleType.EXPLOSION_NORMAL, + (double)pos.getX() + this.rand.gaussian() * 128.0, (double)pos.getY() + this.rand.gaussian() * 2.0, (double)pos.getZ() + this.rand.gaussian() * 128.0, 100); + } + 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; + this.spawnParticle(ParticleType.SMOKE, d21, d4, d6); + } + + return; + + case 2001: + State state = BlockRegistry.byId(data); + + if (state != null && state.getBlock() != Blocks.air) + { + this.gm.getSoundManager().playSound(new PositionedSound(state.getBlock().getSound().getBreakSound(), 1.0F, /* block.sound.getFrequency() * 0.8F, */ (float)blockPosIn.getX() + 0.5F, (float)blockPosIn.getY() + 0.5F, (float)blockPosIn.getZ() + 0.5F)); + } + if(state != null) + this.gm.effectRenderer.destroyBlock(blockPosIn, state); + 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.spawnParticle(ParticleType.ITEM_CRACK, d13, d14, d16, ItemRegistry.getId(Items.water_bottle)); + } + + for (int l1 = 0; l1 < 100; ++l1) + { + this.spawnParticle(ParticleType.POTION, d13, d14, d16, data); + } + + this.playSoundAtPos(blockPosIn, SoundEvent.GLASS, 1.0F); + break; + + case 2005: + ItemDye.spawnBonemealParticles(this.gm.world, blockPosIn, data); + break; + + case 2016: + TileEntity te = this.gm.world.getTileEntity(blockPosIn); + if(te instanceof TileEntityChest chest) { + chest.setUsing(data); + this.gm.world.markBlockForUpdate(blockPosIn); + } + } } // /** @@ -1668,7 +1841,7 @@ public class ClientPlayer implements IClientPlayer // else if(packetIn.getSoundName().startsWith("music#")) { // return; // } - this.gm.world.playSound(packetIn.getX(), packetIn.getY(), packetIn.getZ(), packetIn.getSound(), packetIn.getVolume()); + this.gm.getSoundManager().playSound(new PositionedSound(packetIn.getSound(), packetIn.getVolume(), (float)packetIn.getX(), (float)packetIn.getY(), (float)packetIn.getZ())); } // public void handleDisplay(S48PacketDisplay packetIn) @@ -1891,7 +2064,7 @@ public class ClientPlayer implements IClientPlayer public void handleCelestials(SPacketCelestials packet) { NetHandler.checkThread(packet, this, this.gm, this.world); - this.world.setExterminated(packet.getExterminated()); + this.gm.setExterminated(packet.getExterminated()); if(this.world.dimension.getType() == DimType.PLANET || this.world.dimension.getType() == DimType.MOON) { this.world.dimension.setSunColor(packet.getSunColor()); this.world.dimension.setMoonColors(packet.getMoonColors()); diff --git a/client/src/main/java/client/renderer/EffectRenderer.java b/client/src/main/java/client/renderer/EffectRenderer.java index 674e4cd7..06f0cfd9 100755 --- a/client/src/main/java/client/renderer/EffectRenderer.java +++ b/client/src/main/java/client/renderer/EffectRenderer.java @@ -1062,12 +1062,19 @@ public class EffectRenderer { this.layers[i].add(effect); } - public void spawnParticle(ParticleType type, double x, double y, double z, int data) { - Creator creator = this.types.get(type); - if(creator != null) { - Effect effect = creator.create(x, y, z, data); - if(effect != null) - this.add(effect); + public void spawnParticle(Entity entity, ParticleType type, double x, double y, double z, int data) { + if(entity != null) { + double dx = entity.posX - x; + double dy = entity.posY - y; + double dz = entity.posZ - z; + if(type.isUnlimited() || dx * dx + dy * dy + dz * dz <= 256.0D) { + Creator creator = this.types.get(type); + if(creator != null) { + Effect effect = creator.create(x, y, z, data); + if(effect != null) + this.add(effect); + } + } } } diff --git a/client/src/main/java/client/renderer/EntityRenderer.java b/client/src/main/java/client/renderer/EntityRenderer.java index 830b9eff..65422715 100755 --- a/client/src/main/java/client/renderer/EntityRenderer.java +++ b/client/src/main/java/client/renderer/EntityRenderer.java @@ -12,7 +12,6 @@ import org.lwjgl.opengl.GL13; import client.Client; import client.renderer.texture.DynamicTexture; import client.renderer.texture.TextureMap; -import client.world.WorldClient; import common.block.Block; import common.block.Material; import common.effect.Effect; @@ -25,6 +24,7 @@ import common.init.Items; import common.init.SoundEvent; import common.model.BlockLayer; import common.rng.Random; +import common.sound.PositionedSound; import common.util.BlockPos; import common.util.BoundingBox; import common.util.ExtMath; @@ -70,6 +70,8 @@ public class EntityRenderer { private double cameraYaw; private double cameraPitch; private int frameCount; + private int lastLightning; + private Vec3 lightColor = new Vec3(0xffffff); public EntityRenderer(Client gmIn) { @@ -139,6 +141,8 @@ public class EntityRenderer { ++this.rendererUpdateCount; this.itemRenderer.update(); this.addRainParticles(); + if(this.lastLightning > 0) + this.lastLightning -= 1; // this.bossColorModifierPrev = this.bossColorModifier; // // if (BossStatus.hasColorModifier) @@ -317,19 +321,6 @@ public class EntityRenderer { { 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(); @@ -349,6 +340,65 @@ public class EntityRenderer { return f; } + + public 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; + } /** * Changes the field of view of the player depending on if they are underwater or not @@ -737,18 +787,163 @@ public class EntityRenderer { this.torchFlickerX += (this.torchFlickerDX - this.torchFlickerX) * 1.0F; this.lightmapUpdateNeeded = true; } + + public void resetLightning() { + this.lastLightning = 0; + this.lightColor = new Vec3(0xffffff); + } + + public int getLastLightning() { + return this.lastLightning; + } + + public Vec3 getLightColor() { + return this.lightColor; + } + + public void setLastLightning(int last, int color) { + this.lastLightning = last; + this.lightColor = new Vec3(color); + } + + public float getSunBrightness(float partial) { + float f = this.gm.world.getDayPhase(partial); + float f1 = 1.0F - (ExtMath.cos(f) * 2.0F + 0.2F); + f1 = ExtMath.clampf(f1, 0.0F, 1.0F); + f1 = 1.0F - f1; + f1 = (float)((double)f1 * (1.0D - (double)(this.gm.world.getRainStrength() * 5.0F) / 16.0D)); + f1 = (float)((double)f1 * (1.0D - (double)(this.gm.world.getDarkness() * 5.0F) / 16.0D)); + return Math.max(f1 * 0.8F + 0.2F, this.getSpaceFactor()); + } + + public Vec3 getSkyColor(Entity entity, float partial) { + BlockPos pos = new BlockPos(ExtMath.floord(entity.posX), ExtMath.floord(entity.posY), + ExtMath.floord(entity.posZ)); + Vec3 vec; + if(this.gm.world.dimension.isExterminated()) + vec = new Vec3(0x101010); + else + vec = new Vec3(this.gm.world.dimension.getSkyColor()); + if(this.gm.world.dimension.hasDaylight()) { + float mult = ExtMath.clampf(ExtMath.cos(this.gm.world.getDayPhase(partial)) * 2.0F + 0.5F, 0.0F, 1.0F); + 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.gm.world.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.gm.world.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; + } + + float space = this.getSpaceFactor(); + if(space > 0.0f) { + r = r * (1.0F - space); + g = g * (1.0F - space); + b = b * (1.0F - space); + } + + return new Vec3((double)r, (double)g, (double)b); + } + + public Vec3 getCloudColor(Entity entity, float partialTicks) { + Vec3 color = new Vec3(this.gm.world.dimension.getCloudColor()); + if(this.gm.world.dimension.isExterminated()) + color = new Vec3(0x000000); + float r = (float)color.xCoord; + float g = (float)color.yCoord; + float b = (float)color.zCoord; + + float rain = this.gm.world.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.gm.world.dimension.hasDaylight()) { + float sun = ExtMath.clampf(ExtMath.cos(this.gm.world.getDayPhase(partialTicks)) * 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.gm.world.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); + } + + float space = this.getSpaceFactor(); + if(space > 0.0f) { + r = r * (1.0F - space); + g = g * (1.0F - space); + b = b * (1.0F - space); + } + + return new Vec3((double)r, (double)g, (double)b); + } + + public float getStarBrightness(float partialTicks) { + float f = this.gm.world.getDayPhase(partialTicks); + float f1 = 1.0F - (ExtMath.cos(f) * 2.0F + 0.25F); + f1 = ExtMath.clampf(f1, 0.0F, 1.0F); + return Math.max(f1 * f1 * this.gm.world.dimension.getStarBrightness(), this.getSpaceFactor()); + } + + public float getDeepStarBrightness(float partialTicks) { + float f = this.gm.world.getDayPhase(partialTicks); + float f1 = 1.0F - (ExtMath.cos(f) * 2.0F + 0.25F); + f1 = ExtMath.clampf(f1, 0.0F, 1.0F); + return Math.max(f1 * f1 * this.gm.world.dimension.getDeepStarBrightness(), this.getSpaceFactor()); + } + + public float getSpaceFactor() { + Entity entity = this.gm.getRenderViewEntity(); + return entity == null ? 0.0f : (float)this.gm.world.getSpaceFactor(entity.posX, entity.posY, entity.posZ); + } private void updateLightmap(float partialTicks) { if (this.lightmapUpdateNeeded) { - WorldClient world = this.gm.world; + World world = this.gm.world; if (world != null) { - float sun = world.getSunBrightness(1.0F); + float sun = this.getSunBrightness(1.0F); float msun = sun * 0.95F + 0.05F; - float space = world.getSpaceFactor(); + float space = this.getSpaceFactor(); float brightness = (float)world.dimension.getBrightness() / 15.0f; for (int n = 0; n < 256; ++n) @@ -774,16 +969,15 @@ public class EntityRenderer { sgreen = sgreen * (1.0F - space) + space; sblue = sblue * (1.0F - space) + space; } - if (world.getLastLightning() > 0) + if (this.lastLightning > 0) { - Vec3 lightColor = world.getLightColor(); - float intens = (float)world.getLastLightning() - partialTicks; + float intens = (float)this.lastLightning - partialTicks; if(intens > 1.0F) intens = 1.0F; float light = world.dimension.hasSkyLight() ? rsky : 1.0f; - sred = sred * (1.0F - intens) + (float)lightColor.xCoord * light * intens; - sgreen = sgreen * (1.0F - intens) + (float)lightColor.yCoord * light * intens; - sblue = sblue * (1.0F - intens) + (float)lightColor.zCoord * light * intens; + sred = sred * (1.0F - intens) + (float)this.lightColor.xCoord * light * intens; + sgreen = sgreen * (1.0F - intens) + (float)this.lightColor.yCoord * light * intens; + sblue = sblue * (1.0F - intens) + (float)this.lightColor.zCoord * light * intens; } float bred = block; @@ -1088,7 +1282,7 @@ public class EntityRenderer { GL11.glPushMatrix(); this.setupFog(0, partialTicks); // renderGlobalIn.renderClouds(partialTicks); - float alpha = 0.8F * (1.0f - this.gm.world.getSpaceFactor()); + float alpha = 0.8F * (1.0f - this.getSpaceFactor()); if(this.gm.world.dimension.hasWeather() && alpha > 0.5f) renderGlobalIn.renderClouds(alpha, partialTicks); GlState.disableFog(); @@ -1185,11 +1379,11 @@ public class EntityRenderer { if (d1 > (double)(blockpos.getY() + 1) && world.getPrecipitationHeight(blockpos).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); + this.gm.getSoundManager().playSound(new PositionedSound(n >= j ? this.pickMoltenSound() : SoundEvent.RAIN, n >= j ? 0.2f : 0.1F, (float)d0, (float)d1, (float)d2)); } else { - this.gm.world.playSound(d0, d1, d2, n >= j ? this.pickMoltenSound() : SoundEvent.RAIN, n >= j ? 0.4f : 0.2F); + this.gm.getSoundManager().playSound(new PositionedSound(n >= j ? this.pickMoltenSound() : SoundEvent.RAIN, n >= j ? 0.4f : 0.2F, (float)d0, (float)d1, (float)d2)); } } } @@ -1330,7 +1524,7 @@ public class EntityRenderer { private void updateFogColor(float partial) { - WorldClient world = this.gm.world; + World world = this.gm.world; Entity entity = this.gm.getRenderViewEntity(); Vec3 fog = new Vec3(world.dimension.getFogColor()); @@ -1351,7 +1545,7 @@ public class EntityRenderer { this.fogColorBlue = this.fogColorBlue * (sun * 0.91F + 0.09F); } - float space = world.getSpaceFactor(); + float space = this.getSpaceFactor(); if(space > 0.0f) { this.fogColorRed = this.fogColorRed * (1.0F - space); this.fogColorGreen = this.fogColorGreen * (1.0F - space); @@ -1378,7 +1572,7 @@ public class EntityRenderer { 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); + Vec3 sky = this.getSkyColor(this.gm.getRenderViewEntity(), partial); this.fogColorRed += ((float)sky.xCoord - this.fogColorRed) * dist; this.fogColorGreen += ((float)sky.yCoord - this.fogColorGreen) * dist; this.fogColorBlue += ((float)sky.zCoord - this.fogColorBlue) * dist; diff --git a/client/src/main/java/client/renderer/RegionRenderCache.java b/client/src/main/java/client/renderer/RegionRenderCache.java index 9d811e2a..74707314 100755 --- a/client/src/main/java/client/renderer/RegionRenderCache.java +++ b/client/src/main/java/client/renderer/RegionRenderCache.java @@ -3,7 +3,7 @@ package client.renderer; import java.util.Arrays; import client.world.ChunkClient; -import client.world.WorldClient; +import client.Client; import common.init.Blocks; import common.tileentity.TileEntity; import common.util.BlockPos; @@ -21,15 +21,15 @@ public class RegionRenderCache implements IWorldAccess private final int xPos; private final int zPos; private final ChunkClient[][] chunks; - private final World world; + private final boolean sky; private final BlockPos position; private final boolean empty; private int[] combinedLights; private State[] blockStates; - public RegionRenderCache(WorldClient world, BlockPos from, BlockPos to, int sub) + public RegionRenderCache(Client world, BlockPos from, BlockPos to, int sub) { - this.world = world; + this.sky = world.world.dimension.hasSkyLight(); this.xPos = from.getX() - sub >> 4; this.zPos = from.getZ() - sub >> 4; int x2 = to.getX() + sub >> 4; @@ -140,7 +140,7 @@ public class RegionRenderCache implements IWorldAccess private int getLightForExt(LightType p_175629_1_, BlockPos pos) { - if (p_175629_1_ == LightType.SKY && !this.world.dimension.hasSkyLight()) + if (p_175629_1_ == LightType.SKY && !this.sky) { return 0; } diff --git a/client/src/main/java/client/renderer/RenderGlobal.java b/client/src/main/java/client/renderer/RenderGlobal.java index 6fc93a80..4881eaf4 100755 --- a/client/src/main/java/client/renderer/RenderGlobal.java +++ b/client/src/main/java/client/renderer/RenderGlobal.java @@ -26,7 +26,6 @@ import client.renderer.texture.TextureManager; import client.renderer.texture.TextureMap; import client.renderer.tileentity.SpecialRenderer; import client.world.ChunkClient; -import client.world.WorldClient; import common.block.Block; import common.collect.Lists; import common.collect.Maps; @@ -116,7 +115,7 @@ public class RenderGlobal private final TextureManager renderEngine; private final RenderManager renderManager; private final Random rand = new Random(); - private WorldClient theWorld; + private World theWorld; private Set chunksToUpdate = new LinkedHashSet(); private List renderInfos = new ArrayList(69696); private final Set setTileEntities = Sets.newHashSet(); @@ -409,7 +408,7 @@ public class RenderGlobal /** * set null to clear */ - public void setWorldAndLoadRenderers(WorldClient worldClientIn) + public void setWorldAndLoadRenderers(World worldClientIn) { // if (this.theWorld != null) // { @@ -455,7 +454,7 @@ public class RenderGlobal this.setTileEntities.clear(); } - this.viewFrustum = new ViewFrustum(this.theWorld, this.gm.renderDistance, this); + this.viewFrustum = new ViewFrustum(this.gm, this.gm.renderDistance, this); if (this.theWorld != null) { @@ -506,7 +505,7 @@ public class RenderGlobal SpecialRenderer.entityZ = d5; this.renderManager.setRenderPosition(d3, d4, d5); this.gm.entityRenderer.enableLightmap(); - List list = this.theWorld.getLoadedEntityList(); + List list = this.gm.getEntities(); this.countEntitiesTotal = list.size(); for (int i = 0; i < this.theWorld.effects.size(); ++i) @@ -531,7 +530,7 @@ public class RenderGlobal GlState.disableTexture2D(); GlState.depthMask(false); - List tiles = this.theWorld.getLoadedTileList(); + List tiles = this.gm.getTiles(); for (int j = 0; j < tiles.size(); ++j) { @@ -601,10 +600,10 @@ public class RenderGlobal label738: - for (RenderGlobal.ContainerLocalRenderInformation renderglobal$containerlocalrenderinformation : this.renderInfos) + for (RenderGlobal.ContainerLocalRenderInformation render : this.renderInfos) { - ChunkClient chunk = this.theWorld.getChunk(renderglobal$containerlocalrenderinformation.renderChunk.getPosition()); - InheritanceMultiMap classinheritancemultimap = chunk.getEntities()[ExtMath.clampi(renderglobal$containerlocalrenderinformation.renderChunk.getPosition().getY() / 16, 0, 31)]; + 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)]; if (!classinheritancemultimap.isEmpty()) { @@ -897,7 +896,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.theWorld.getChunk(blockpos); + ChunkClient chunk = this.gm.getChunk(blockpos.getX() >> 4, blockpos.getZ() >> 4); for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(blockpos, blockpos.add(15, 15, 15))) { @@ -1117,7 +1116,7 @@ public class RenderGlobal else if (this.gm.world.dimension.hasSky()) { GlState.disableTexture2D(); - Vec3 vec3 = this.theWorld.getSkyColor(this.gm.getRenderViewEntity(), partialTicks); + Vec3 vec3 = this.gm.entityRenderer.getSkyColor(this.gm.getRenderViewEntity(), partialTicks); float f = (float)vec3.xCoord; float f1 = (float)vec3.yCoord; float f2 = (float)vec3.zCoord; @@ -1252,7 +1251,7 @@ public class RenderGlobal } GlState.disableTexture2D(); - float f15 = this.theWorld.getStarBrightness(partialTicks) * f16; + float f15 = this.gm.entityRenderer.getStarBrightness(partialTicks) * f16; if (f15 > 0.0F) { int stars = this.theWorld.dimension.getStarColor(this.theWorld.getDayTime()); @@ -1279,7 +1278,7 @@ public class RenderGlobal // } } - f15 = this.theWorld.getDeepStarBrightness(partialTicks) * f16; + f15 = this.gm.entityRenderer.getDeepStarBrightness(partialTicks) * f16; if (f15 > 0.0F) { int stars = this.theWorld.dimension.getDeepStarColor(this.theWorld.getDayTime()); @@ -1335,7 +1334,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.theWorld.getCloudColour(this.gm.getRenderViewEntity(), partialTicks); + Vec3 vec3 = this.gm.entityRenderer.getCloudColor(this.gm.getRenderViewEntity(), partialTicks); float f4 = (float)vec3.xCoord; float f5 = (float)vec3.yCoord; float f6 = (float)vec3.zCoord; diff --git a/client/src/main/java/client/renderer/ViewFrustum.java b/client/src/main/java/client/renderer/ViewFrustum.java index ede3e1cd..0a71fc9b 100755 --- a/client/src/main/java/client/renderer/ViewFrustum.java +++ b/client/src/main/java/client/renderer/ViewFrustum.java @@ -1,14 +1,14 @@ package client.renderer; import client.renderer.chunk.RenderChunk; -import client.world.WorldClient; +import client.Client; import common.util.BlockPos; import common.util.ExtMath; public class ViewFrustum { protected final RenderGlobal renderGlobal; - protected final WorldClient world; + protected final Client gm; 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(WorldClient worldIn, int renderDistanceChunks, RenderGlobal p_i46246_3_) + public ViewFrustum(Client worldIn, int renderDistanceChunks, RenderGlobal p_i46246_3_) { this.renderGlobal = p_i46246_3_; - this.world = worldIn; + this.gm = 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.world, this.renderGlobal, blockpos, j++); + this.renderChunks[j1] = new RenderChunk(this.gm, this.renderGlobal, blockpos, j++); } } } diff --git a/client/src/main/java/client/renderer/chunk/RenderChunk.java b/client/src/main/java/client/renderer/chunk/RenderChunk.java index 8213aeb2..5f143bc0 100755 --- a/client/src/main/java/client/renderer/chunk/RenderChunk.java +++ b/client/src/main/java/client/renderer/chunk/RenderChunk.java @@ -19,7 +19,6 @@ import client.renderer.RenderGlobal; import client.renderer.VertexBuffer; import client.renderer.tileentity.SpecialRenderer; import client.renderer.tileentity.ElementRenderer; -import client.world.WorldClient; import common.block.Block; import common.block.ITileEntityProvider; import common.collect.Maps; @@ -33,7 +32,7 @@ import common.world.State; public class RenderChunk { - private WorldClient world; + private Client gm; private final RenderGlobal renderGlobal; public static int renderChunksUpdated; private BlockPos position; @@ -50,9 +49,9 @@ public class RenderChunk private boolean needsUpdate = true; private EnumMap mapEnumFacing = Maps.newEnumMap(Facing.class); - public RenderChunk(WorldClient worldIn, RenderGlobal renderGlobalIn, BlockPos blockPosIn, int indexIn) + public RenderChunk(Client worldIn, RenderGlobal renderGlobalIn, BlockPos blockPosIn, int indexIn) { - this.world = worldIn; + this.gm = worldIn; this.renderGlobal = renderGlobalIn; this.index = indexIn; @@ -127,7 +126,7 @@ public class RenderChunk return; } - iblockaccess = new RegionRenderCache(this.world, blockpos.add(-1, -1, -1), blockpos1.add(1, 1, 1), 1); + iblockaccess = new RegionRenderCache(this.gm, blockpos.add(-1, -1, -1), blockpos1.add(1, 1, 1), 1); generator.setCompiledChunk(compiledchunk); } finally @@ -142,7 +141,7 @@ public class RenderChunk { ++renderChunksUpdated; boolean[] aboolean = new boolean[BlockLayer.values().length]; - BlockRenderer blockrendererdispatcher = Client.CLIENT.getBlockRendererDispatcher(); + BlockRenderer blockrendererdispatcher = this.gm.getBlockRendererDispatcher(); for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(blockpos, blockpos1)) { @@ -355,7 +354,7 @@ public class RenderChunk public void deleteGlResources() { this.stopCompileTask(); - this.world = null; + this.gm = null; for (int i = 0; i < BlockLayer.values().length; ++i) { diff --git a/client/src/main/java/client/renderer/tileentity/SpecialRenderer.java b/client/src/main/java/client/renderer/tileentity/SpecialRenderer.java index cfd0393c..ce9e4a64 100755 --- a/client/src/main/java/client/renderer/tileentity/SpecialRenderer.java +++ b/client/src/main/java/client/renderer/tileentity/SpecialRenderer.java @@ -5,13 +5,13 @@ import java.util.Map; import org.lwjgl.opengl.GL13; import client.renderer.GlState; -import client.world.WorldClient; import common.collect.Maps; import common.entity.Entity; import common.tileentity.TileEntity; import common.tileentity.TileEntityDisplay; import common.tileentity.TileEntitySign; import common.util.BlockPos; +import common.world.World; public class SpecialRenderer { public static SpecialRenderer instance = new SpecialRenderer(); @@ -21,7 +21,7 @@ public class SpecialRenderer { private final Map, ElementRenderer> renderers = Maps., ElementRenderer>newHashMap(); - private WorldClient world; + private World world; private double posX; private double posY; private double posZ; @@ -44,7 +44,7 @@ public class SpecialRenderer { return (ElementRenderer)(tile == null ? null : this.getRenderer(tile.getClass())); } - public void setPosition(WorldClient world, Entity entity, float partial) { + public void setPosition(World world, Entity entity, float partial) { this.world = world; this.posX = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double)partial; this.posY = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)partial; diff --git a/client/src/main/java/client/util/PlayerController.java b/client/src/main/java/client/util/PlayerController.java index ad98b1fa..485023ca 100755 --- a/client/src/main/java/client/util/PlayerController.java +++ b/client/src/main/java/client/util/PlayerController.java @@ -2,7 +2,6 @@ package client.util; import client.Client; import client.network.ClientPlayer; -import client.world.WorldClient; import common.block.Block; import common.dimension.Dimension; import common.dimension.Space; @@ -114,7 +113,7 @@ public class PlayerController { this.stack = this.gm.player.getHeldItem(); this.damage = 0.0F; this.stepCounter = 0.0F; - this.gm.world.sendBlockBreakProgress(this.gm.player.getId(), this.position, (int)(this.damage * 10.0F) - 1); + this.gm.renderGlobal.sendBlockBreakProgress(this.gm.player.getId(), this.position, (int)(this.damage * 10.0F) - 1); } } @@ -127,7 +126,7 @@ public class PlayerController { this.handler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.ABORT_DESTROY_BLOCK, this.position, Facing.DOWN)); this.hitting = false; this.damage = 0.0F; - this.gm.world.sendBlockBreakProgress(this.gm.player.getId(), this.position, -1); + this.gm.renderGlobal.sendBlockBreakProgress(this.gm.player.getId(), this.position, -1); } } @@ -170,7 +169,7 @@ public class PlayerController { this.delay = 5; } - this.gm.world.sendBlockBreakProgress(this.gm.player.getId(), this.position, (int)(this.damage * 10.0F) - 1); + this.gm.renderGlobal.sendBlockBreakProgress(this.gm.player.getId(), this.position, (int)(this.damage * 10.0F) - 1); return true; } } @@ -213,7 +212,7 @@ public class PlayerController { } } - public boolean clickRight(EntityNPC player, WorldClient world, ItemStack stack, BlockPos pos, Facing side, Vec3 hit) { + public boolean clickRight(EntityNPC player, World world, ItemStack stack, BlockPos pos, Facing side, Vec3 hit) { this.syncItem(); float f = (float)(hit.xCoord - (double)pos.getX()); float f1 = (float)(hit.yCoord - (double)pos.getY()); @@ -279,7 +278,7 @@ public class PlayerController { } } - public EntityNPC createPlayerEntity(WorldClient world, int type) { + public EntityNPC createPlayerEntity(World world, int type) { EntityNPC player = (EntityNPC)EntityRegistry.createEntityByID(type, world); player.setClientPlayer(this.handler); if(!this.gm.charEditor && this.gm.selectedCharacter >= 0 && this.gm.selectedCharacter < this.gm.characterList.size()) { diff --git a/client/src/main/java/client/world/ChunkEmpty.java b/client/src/main/java/client/world/ChunkEmpty.java index 102c9851..1f881757 100755 --- a/client/src/main/java/client/world/ChunkEmpty.java +++ b/client/src/main/java/client/world/ChunkEmpty.java @@ -15,6 +15,7 @@ import common.util.BoundingBox; import common.util.ExtMath; import common.world.LightType; import common.world.State; +import common.world.World; public class ChunkEmpty extends ChunkClient { private static final List STATES = Lists.newArrayList(); @@ -54,7 +55,7 @@ public class ChunkEmpty extends ChunkClient { return state; } - public ChunkEmpty(WorldClient world, boolean out, boolean debug) { + public ChunkEmpty(World world, boolean out, boolean debug) { super(world, out ? Integer.MAX_VALUE : 0, 0); this.debug = debug; this.liquidY = world.dimension.getSeaLevel() - 1; diff --git a/client/src/main/java/client/world/WorldClient.java b/client/src/main/java/client/world/WorldClient.java deleted file mode 100755 index adac6884..00000000 --- a/client/src/main/java/client/world/WorldClient.java +++ /dev/null @@ -1,930 +0,0 @@ -package client.world; - -import java.util.List; -import java.util.Set; - -import client.Client; -import common.collect.Lists; -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.Blocks; -import common.init.ItemRegistry; -import common.init.Items; -import common.init.SoundEvent; -import common.item.material.ItemDye; -import common.log.Log; -import common.rng.Random; -import common.sound.MovingSoundMinecart; -import common.sound.PositionedSound; -import common.tileentity.TileEntity; -import common.tileentity.TileEntityChest; -import common.util.BlockPos; -import common.util.ChunkPos; -import common.util.ExtMath; -import common.util.LongHashMap; -import common.util.ParticleType; -import common.util.Vec3; -import common.vars.Vars; -import common.util.BlockPos.MutableBlockPos; -import common.world.AWorldClient; -import common.world.State; -import common.world.World; - -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 LongHashMap chunkMapping = new LongHashMap(); - private final List chunkListing = Lists.newArrayList(); - private final Set emptyChunkListing = Sets.newHashSet(); - private final Set nextEmptyChunkListing = Sets.newHashSet(); - - private ChunkClient emptyChunk; - private ChunkClient outsideChunk; - protected int lastLightning; - protected Vec3 lightColor = new Vec3(0xffffff); - - public WorldClient(Client gm, Dimension dim) - { - super(dim); - this.gm = gm; - this.emptyChunk = new ChunkEmpty(this, false, this.gm.debugWorld); - this.outsideChunk = new ChunkEmpty(this, true, this.gm.debugWorld); - this.calculateInitialSkylight(); - this.calculateInitialWeather(); - this.updatePhysics(); -// this.setDifficulty(this.gm.difficulty); - } - - private ChunkClient getEmptyChunk(int x, int z) { - int size = this.dimension.getSize() / 16; - return x < -size || z < -size || x >= size || z >= size ? this.outsideChunk : this.emptyChunk; - } - - private void markReload(int cx, int cz, int range) { - this.nextEmptyChunkListing.clear(); - for(int x = cx - range; x <= cx + range; x++) { - for(int z = cz - range; z <= cz + range; z++) { - long id = LongHashMap.packInt(x, z); - if(this.chunkMapping.getValueByKey(id) != null) { - if(this.emptyChunkListing.contains(id)) { - this.emptyChunkListing.remove(id); - this.nextEmptyChunkListing.add(id); - } - continue; - } - this.chunkMapping.add(id, this.getEmptyChunk(x, z)); - this.emptyChunkListing.remove(id); - this.nextEmptyChunkListing.add(id); - this.markBlockRangeForRenderUpdate(x << 4, -World.MAX_SIZE_Y, z << 4, (x << 4) + 15, World.MAX_SIZE_Y, (z << 4) + 15); - } - } - for(Long id : this.emptyChunkListing) { - this.chunkMapping.remove(id); - int x = LongHashMap.getX(id); - int z = LongHashMap.getZ(id); - this.markBlockRangeForRenderUpdate(x << 4, -World.MAX_SIZE_Y, z << 4, (x << 4) + 15, World.MAX_SIZE_Y, (z << 4) + 15); - } - this.emptyChunkListing.clear(); - this.emptyChunkListing.addAll(this.nextEmptyChunkListing); - } - - public void markReload() { - if(this.gm.player != null && !this.gm.charEditor) - this.markReload((int)this.gm.player.posX >> 4, (int)this.gm.player.posZ >> 4, this.gm.renderDistance + 4); - } - - public void setExterminated(boolean exterminated) { - this.dimension.setExterminated(exterminated); - this.emptyChunk = new ChunkEmpty(this, false, this.gm.debugWorld); - this.outsideChunk = new ChunkEmpty(this, true, this.gm.debugWorld); - this.markReload(); - for(Long id : this.emptyChunkListing) { - int x = LongHashMap.getX(id); - int z = LongHashMap.getZ(id); - this.chunkMapping.add(id, this.getEmptyChunk(x, z)); - this.markBlockRangeForRenderUpdate(x << 4, -World.MAX_SIZE_Y, z << 4, (x << 4) + 15, World.MAX_SIZE_Y, (z << 4) + 15); - } - } - - public void tick() - { - this.updatePhysics(); - this.markReload(); -// this.info.tick(); - - if (Vars.dayCycle) - { - this.daytime += Vars.timeFlow; - } - - 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 (ChunkClient chunk : this.chunkListing) - { - chunk.update(System.currentTimeMillis() - time > 5L); - } - if (System.currentTimeMillis() - time > 100L) - { - Log.TICK.warn("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; - ChunkClient 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) - { - long id = LongHashMap.packInt(x, z); - if (load) - { - if(this.chunkMapping.getValueByKey(id) != null) - this.doPreChunk(x, z, false); - ChunkClient chunk = new ChunkClient(this, x, z); - this.chunkMapping.add(id, chunk); - this.chunkListing.add(chunk); - chunk.setLoaded(); - } - else - { - ChunkClient chunk = this.getChunk(x, z); - chunk.onChunkUnload(); - this.chunkMapping.remove(id); - this.chunkListing.remove(chunk); - this.emptyChunkListing.remove(id); - } - - if (!load) - { - this.markBlockRangeForRenderUpdate(x * 16, -World.MAX_SIZE_Y, z * 16, x * 16 + 15, World.MAX_SIZE_Y, 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().displayTick(this, pos, state, rand); - } - if(this.dimension.hasVoidFog() && this.gm.voidParticles && posY < 32) { - for(int n = 0; n < 1000; n++) { - float x = ((float)posX) + (rand.floatv() - rand.floatv() - 0.5f) * 32.0f; - float y = (posY < -32 ? (float)posY - 32.0f : -64.0f) + rand.floatv() * 65.0f; - float z = ((float)posZ) + (rand.floatv() - rand.floatv() - 0.5f) * 32.0f; - if(y < -64.0f || rand.floatv() >= (64.0f + y) / 64.0f) - this.spawnParticle(ParticleType.DEPTH, (double)x, (double)y, (double)z); - } - } - } - - 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 ChunkClient getChunk(int x, int z) - { - ChunkClient chunk = this.chunkMapping.getValueByKey(LongHashMap.packInt(x, z)); - return chunk == null ? this.getEmptyChunk(x, z) : chunk; - } - - public ChunkClient getChunk(BlockPos pos) { - return this.getChunk(pos.getX() >> 4, pos.getZ() >> 4); - } - - protected float getTemperature(BlockPos pos) { - if(!this.isBlockLoaded(pos)) - return 0.0f; - ChunkClient chunk = this.getChunk(pos); - return pos.getY() > 64 ? chunk.getTemperature(pos) - (chunk.getOffset(pos) + (float)pos.getY() - 64.0F) / 15.0f : chunk.getTemperature(pos); - } - - protected boolean isLoaded(int x, int z, boolean allowEmpty) { - return allowEmpty || !this.getChunk(x, z).isDummy(); - } - - public String getInfo() - { - return "Chunk-Cache: M " + this.chunkMapping.getNumHashElements() + ", 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 particle, double xCoord, double yCoord, double zCoord, int data) { - if (this.gm.getRenderViewEntity() != null) - { - double d0 = this.gm.getRenderViewEntity().posX - xCoord; - double d1 = this.gm.getRenderViewEntity().posY - yCoord; - double d2 = this.gm.getRenderViewEntity().posZ - zCoord; - if(particle.isUnlimited() || d0 * d0 + d1 * d1 + d2 * d2 <= 256.0D) - this.gm.effectRenderer.spawnParticle(particle, xCoord, yCoord, zCoord, data); - } - } - -// 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(Items.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 < 1000; z++) { - this.spawnParticle(ParticleType.EXPLOSION_HUGE, - (double)pos.getX() + this.rand.gaussian() * 128.0, (double)pos.getY() + this.rand.gaussian() * 2.0, (double)pos.getZ() + this.rand.gaussian() * 128.0); - } - for(int z = 0; z < 1000; z++) { - this.spawnParticle(ParticleType.EXPLOSION_NORMAL, - (double)pos.getX() + this.rand.gaussian() * 128.0, (double)pos.getY() + this.rand.gaussian() * 2.0, (double)pos.getZ() + this.rand.gaussian() * 128.0, 100); - } - 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; - this.spawnParticle(ParticleType.SMOKE, d21, d4, d6); - } - - return; - - case 2001: - State state = BlockRegistry.byId(data); - - if (state != null && state.getBlock() != Blocks.air) - { - this.gm.getSoundManager().playSound(new PositionedSound(state.getBlock().getSound().getBreakSound(), 1.0F, /* block.sound.getFrequency() * 0.8F, */ (float)blockPosIn.getX() + 0.5F, (float)blockPosIn.getY() + 0.5F, (float)blockPosIn.getZ() + 0.5F)); - } - if(state != null) - this.gm.effectRenderer.destroyBlock(blockPosIn, state); - 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.spawnParticle(ParticleType.ITEM_CRACK, d13, d14, d16, ItemRegistry.getId(Items.water_bottle)); - } - - for (int l1 = 0; l1 < 100; ++l1) - { - this.spawnParticle(ParticleType.POTION, d13, d14, d16, data); - } - - this.playSoundAtPos(blockPosIn, SoundEvent.GLASS, 1.0F); - break; - - case 2005: - ItemDye.spawnBonemealParticles(this, blockPosIn, data); - break; - - case 2016: - TileEntity te = this.getTileEntity(blockPosIn); - if(te instanceof TileEntityChest chest) { - chest.setUsing(data); - this.markBlockForUpdate(blockPosIn); - } - } - } - - 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.getDayPhase(p_72971_1_); - float f1 = 1.0F - (ExtMath.cos(f) * 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 Math.max(f1 * 0.8F + 0.2F, this.getSpaceFactor()); - } - - 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) { - BlockPos pos = new BlockPos(ExtMath.floord(entity.posX), ExtMath.floord(entity.posY), - ExtMath.floord(entity.posZ)); - Vec3 vec; - if(this.dimension.isExterminated()) - vec = new Vec3(0x101010); - else - vec = new Vec3(this.dimension.getSkyColor()); - if(this.dimension.hasDaylight()) { - float mult = ExtMath.clampf(ExtMath.cos(this.getDayPhase(partial)) * 2.0F + 0.5F, 0.0F, 1.0F); - 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; - } - - float space = this.getSpaceFactor(); - if(space > 0.0f) { - r = r * (1.0F - space); - g = g * (1.0F - space); - b = b * (1.0F - space); - } - - 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.dimension.isExterminated()) - 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.hasDaylight()) { - float sun = ExtMath.clampf(ExtMath.cos(this.getDayPhase(partialTicks)) * 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); - } - - float space = this.getSpaceFactor(); - if(space > 0.0f) { - r = r * (1.0F - space); - g = g * (1.0F - space); - b = b * (1.0F - space); - } - - return new Vec3((double)r, (double)g, (double)b); - } - - public float getStarBrightness(float partialTicks) { - float f = this.getDayPhase(partialTicks); - float f1 = 1.0F - (ExtMath.cos(f) * 2.0F + 0.25F); - f1 = ExtMath.clampf(f1, 0.0F, 1.0F); - return Math.max(f1 * f1 * this.dimension.getStarBrightness(), this.getSpaceFactor()); - } - - public float getDeepStarBrightness(float partialTicks) { - float f = this.getDayPhase(partialTicks); - float f1 = 1.0F - (ExtMath.cos(f) * 2.0F + 0.25F); - f1 = ExtMath.clampf(f1, 0.0F, 1.0F); - return Math.max(f1 * f1 * this.dimension.getDeepStarBrightness(), this.getSpaceFactor()); - } - - public float getSpaceFactor() { - Entity entity = this.gm.getRenderViewEntity(); - return entity == null ? 0.0f : (float)this.getSpaceFactor(entity.posX, entity.posY, entity.posZ); - } - - public int getLastLightning() { - return this.lastLightning; - } - - public Vec3 getLightColor() { - return this.lightColor; - } - - 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(); - } -} diff --git a/common/src/main/java/common/block/Block.java b/common/src/main/java/common/block/Block.java index 0fab7ccc..3ef4a3d2 100755 --- a/common/src/main/java/common/block/Block.java +++ b/common/src/main/java/common/block/Block.java @@ -54,7 +54,6 @@ import common.vars.Vars; import common.world.Explosion; import common.world.IBlockAccess; import common.world.IWorldAccess; -import common.world.AWorldClient; import common.world.State; import common.world.World; import common.world.AWorldServer; @@ -845,7 +844,7 @@ public class Block { public void tick(AWorldServer world, BlockPos pos, State state, Random rand) { } - public void displayTick(AWorldClient world, BlockPos pos, State state, Random rand) { + public void displayTick(World world, BlockPos pos, State state, Random rand) { } public void onStartBreak(World world, BlockPos pos, EntityNPC player) { @@ -896,7 +895,7 @@ public class Block { return false; } - public void onUpdate(World world, BlockPos pos, State state, Block neighbor) { + public void onUpdate(AWorldServer world, BlockPos pos, State state, Block neighbor) { } public void onAdded(AWorldServer world, BlockPos pos, State state) { diff --git a/common/src/main/java/common/block/BlockFalling.java b/common/src/main/java/common/block/BlockFalling.java index e9e50e44..15e28c28 100755 --- a/common/src/main/java/common/block/BlockFalling.java +++ b/common/src/main/java/common/block/BlockFalling.java @@ -26,7 +26,7 @@ public class BlockFalling extends Block { world.scheduleUpdate(pos, this, this.tickRate(world, pos)); } - public void onUpdate(World world, BlockPos pos, State state, Block neighbor) { + public void onUpdate(AWorldServer world, BlockPos pos, State state, Block neighbor) { world.scheduleUpdate(pos, this, this.tickRate(world, pos)); } diff --git a/common/src/main/java/common/block/artificial/BlockBed.java b/common/src/main/java/common/block/artificial/BlockBed.java index fe89b20f..084f1c57 100755 --- a/common/src/main/java/common/block/artificial/BlockBed.java +++ b/common/src/main/java/common/block/artificial/BlockBed.java @@ -22,6 +22,7 @@ import common.util.ExtMath; import common.util.Facing; import common.util.Identifyable; import common.util.WorldPos; +import common.world.AWorldServer; import common.world.IWorldAccess; import common.world.State; import common.world.World; @@ -102,7 +103,7 @@ public class BlockBed extends Block implements Rotatable { this.setBedBounds(); } - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) { + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { Facing enumfacing = (Facing)state.getValue(FACING); if(state.getValue(PART) == BlockBed.EnumPartType.HEAD) { if(worldIn.getState(pos.offset(enumfacing.getOpposite())).getBlock() != this) diff --git a/common/src/main/java/common/block/artificial/BlockCake.java b/common/src/main/java/common/block/artificial/BlockCake.java index bceb48ca..d19b028f 100755 --- a/common/src/main/java/common/block/artificial/BlockCake.java +++ b/common/src/main/java/common/block/artificial/BlockCake.java @@ -13,6 +13,7 @@ import common.rng.Random; import common.util.BlockPos; import common.util.BoundingBox; import common.util.Facing; +import common.world.AWorldServer; import common.world.IWorldAccess; import common.world.State; import common.world.World; @@ -162,7 +163,7 @@ public class BlockCake extends Block /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { if (!this.canBlockStay(worldIn, pos)) { diff --git a/common/src/main/java/common/block/artificial/BlockCarpet.java b/common/src/main/java/common/block/artificial/BlockCarpet.java index d1b4f308..93c16633 100755 --- a/common/src/main/java/common/block/artificial/BlockCarpet.java +++ b/common/src/main/java/common/block/artificial/BlockCarpet.java @@ -9,6 +9,7 @@ import common.model.ModelProvider; import common.model.GuiPosition; import common.util.BlockPos; import common.util.Facing; +import common.world.AWorldServer; import common.world.IWorldAccess; import common.world.State; import common.world.World; @@ -71,7 +72,7 @@ public class BlockCarpet extends Block /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { this.checkForDrop(worldIn, pos, state); } diff --git a/common/src/main/java/common/block/artificial/BlockDoor.java b/common/src/main/java/common/block/artificial/BlockDoor.java index 717ce025..d389ed56 100755 --- a/common/src/main/java/common/block/artificial/BlockDoor.java +++ b/common/src/main/java/common/block/artificial/BlockDoor.java @@ -28,6 +28,7 @@ import common.util.Facing; import common.util.HitPosition; import common.util.Identifyable; import common.util.Vec3; +import common.world.AWorldServer; import common.world.IBlockAccess; import common.world.IWorldAccess; import common.world.State; @@ -192,7 +193,7 @@ public class BlockDoor extends Block implements Rotatable { } } - public void onUpdate(World world, BlockPos pos, State state, Block neighbor) { + public void onUpdate(AWorldServer world, BlockPos pos, State state, Block neighbor) { if(state.getValue(HALF) == EnumDoorHalf.UPPER) { BlockPos lower = pos.down(); State bottom = world.getState(lower); @@ -358,9 +359,9 @@ public class BlockDoor extends Block implements Rotatable { State iblockstate = door.getState().withProperty(BlockDoor.FACING, facing).withProperty(BlockDoor.HINGE, flag2 ? BlockDoor.EnumHingePosition.RIGHT : BlockDoor.EnumHingePosition.LEFT); worldIn.setState(pos, iblockstate.withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.LOWER), 2); worldIn.setState(blockpos2, iblockstate.withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.UPPER), 2); - if(update) { - worldIn.notifyNeighborsOfStateChange(pos, door); - worldIn.notifyNeighborsOfStateChange(blockpos2, door); + if(update && !worldIn.client) { + ((AWorldServer)worldIn).notifyNeighborsOfStateChange(pos, door); + ((AWorldServer)worldIn).notifyNeighborsOfStateChange(blockpos2, door); } } } diff --git a/common/src/main/java/common/block/artificial/BlockDragonEgg.java b/common/src/main/java/common/block/artificial/BlockDragonEgg.java index 9cdde0ab..3ee1842f 100755 --- a/common/src/main/java/common/block/artificial/BlockDragonEgg.java +++ b/common/src/main/java/common/block/artificial/BlockDragonEgg.java @@ -93,7 +93,7 @@ public class BlockDragonEgg extends Block /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn, pos)); } diff --git a/common/src/main/java/common/block/artificial/BlockFloorPortal.java b/common/src/main/java/common/block/artificial/BlockFloorPortal.java index b227ad26..ad0729a1 100755 --- a/common/src/main/java/common/block/artificial/BlockFloorPortal.java +++ b/common/src/main/java/common/block/artificial/BlockFloorPortal.java @@ -18,7 +18,6 @@ import common.util.Facing; import common.util.ParticleType; import common.util.PortalType; import common.world.IWorldAccess; -import common.world.AWorldClient; import common.world.State; import common.world.World; @@ -92,7 +91,7 @@ public class BlockFloorPortal extends Block entityIn.setPortal(PortalType.FLOOR); } - public void displayTick(AWorldClient worldIn, BlockPos pos, State state, Random rand) + public void displayTick(World worldIn, BlockPos pos, State state, Random rand) { double d0 = (double)((float)pos.getX() + rand.floatv()); double d1 = (double)((float)pos.getY() + 0.8F); diff --git a/common/src/main/java/common/block/artificial/BlockFlowerPot.java b/common/src/main/java/common/block/artificial/BlockFlowerPot.java index 3bebf6aa..c7733d5c 100755 --- a/common/src/main/java/common/block/artificial/BlockFlowerPot.java +++ b/common/src/main/java/common/block/artificial/BlockFlowerPot.java @@ -177,7 +177,7 @@ public class BlockFlowerPot extends Block /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { if (!worldIn.isBlockSolid(pos.down())) { diff --git a/common/src/main/java/common/block/artificial/BlockLadder.java b/common/src/main/java/common/block/artificial/BlockLadder.java index 19f818f5..7d66fe13 100755 --- a/common/src/main/java/common/block/artificial/BlockLadder.java +++ b/common/src/main/java/common/block/artificial/BlockLadder.java @@ -14,6 +14,7 @@ import common.properties.Property; import common.util.BlockPos; import common.util.BoundingBox; import common.util.Facing; +import common.world.AWorldServer; import common.world.IWorldAccess; import common.world.State; import common.world.World; @@ -113,7 +114,7 @@ public class BlockLadder extends Block implements Rotatable /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { Facing enumfacing = (Facing)state.getValue(FACING); diff --git a/common/src/main/java/common/block/artificial/BlockPortal.java b/common/src/main/java/common/block/artificial/BlockPortal.java index 59c2ee16..1311db00 100755 --- a/common/src/main/java/common/block/artificial/BlockPortal.java +++ b/common/src/main/java/common/block/artificial/BlockPortal.java @@ -22,8 +22,8 @@ import common.util.BoundingBox; import common.util.Facing; import common.util.ParticleType; import common.util.PortalType; +import common.world.AWorldServer; import common.world.IWorldAccess; -import common.world.AWorldClient; import common.world.State; import common.world.World; @@ -147,7 +147,7 @@ public class BlockPortal extends Block /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { Facing.Axis enumfacing$axis = (Facing.Axis)state.getValue(AXIS); @@ -224,7 +224,7 @@ public class BlockPortal extends Block } } - public void displayTick(AWorldClient worldIn, BlockPos pos, State state, Random rand) + public void displayTick(World worldIn, BlockPos pos, State state, Random rand) { // if (rand.chance(100)) // { diff --git a/common/src/main/java/common/block/artificial/BlockStairs.java b/common/src/main/java/common/block/artificial/BlockStairs.java index 6818aead..b2b82006 100755 --- a/common/src/main/java/common/block/artificial/BlockStairs.java +++ b/common/src/main/java/common/block/artificial/BlockStairs.java @@ -28,7 +28,6 @@ import common.util.Vec3; import common.world.Explosion; import common.world.IBlockAccess; import common.world.IWorldAccess; -import common.world.AWorldClient; import common.world.State; import common.world.World; import common.world.AWorldServer; @@ -561,7 +560,7 @@ public class BlockStairs extends Block implements Rotatable this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } - public void displayTick(AWorldClient worldIn, BlockPos pos, State state, Random rand) + public void displayTick(World worldIn, BlockPos pos, State state, Random rand) { this.base.displayTick(worldIn, pos, state, rand); } diff --git a/common/src/main/java/common/block/foliage/BlockBush.java b/common/src/main/java/common/block/foliage/BlockBush.java index d09cad53..bad69087 100755 --- a/common/src/main/java/common/block/foliage/BlockBush.java +++ b/common/src/main/java/common/block/foliage/BlockBush.java @@ -44,7 +44,7 @@ public class BlockBush extends Block /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { super.onUpdate(worldIn, pos, state, neighborBlock); this.checkAndDropBlock(worldIn, pos, state); diff --git a/common/src/main/java/common/block/foliage/BlockCactus.java b/common/src/main/java/common/block/foliage/BlockCactus.java index 87fd57cd..5bca281a 100755 --- a/common/src/main/java/common/block/foliage/BlockCactus.java +++ b/common/src/main/java/common/block/foliage/BlockCactus.java @@ -109,7 +109,7 @@ public class BlockCactus extends Block /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { if (!this.canBlockStay(worldIn, pos)) { diff --git a/common/src/main/java/common/block/foliage/BlockFarmland.java b/common/src/main/java/common/block/foliage/BlockFarmland.java index 37861cb8..a30ab2f0 100755 --- a/common/src/main/java/common/block/foliage/BlockFarmland.java +++ b/common/src/main/java/common/block/foliage/BlockFarmland.java @@ -113,7 +113,7 @@ public class BlockFarmland extends Block /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { super.onUpdate(worldIn, pos, state, neighborBlock); diff --git a/common/src/main/java/common/block/foliage/BlockMycelium.java b/common/src/main/java/common/block/foliage/BlockMycelium.java index f0ccf10a..404b9b42 100755 --- a/common/src/main/java/common/block/foliage/BlockMycelium.java +++ b/common/src/main/java/common/block/foliage/BlockMycelium.java @@ -15,8 +15,8 @@ import common.util.BlockPos; import common.util.ParticleType; import common.vars.Vars; import common.world.IWorldAccess; -import common.world.AWorldClient; import common.world.State; +import common.world.World; import common.world.AWorldServer; public class BlockMycelium extends Block @@ -70,7 +70,7 @@ public class BlockMycelium extends Block // } } - public void displayTick(AWorldClient worldIn, BlockPos pos, State state, Random rand) + public void displayTick(World worldIn, BlockPos pos, State state, Random rand) { super.displayTick(worldIn, pos, state, rand); diff --git a/common/src/main/java/common/block/foliage/BlockReed.java b/common/src/main/java/common/block/foliage/BlockReed.java index 91d1c6f1..8cfbbaae 100755 --- a/common/src/main/java/common/block/foliage/BlockReed.java +++ b/common/src/main/java/common/block/foliage/BlockReed.java @@ -99,7 +99,7 @@ public class BlockReed extends Block /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { this.checkForDrop(worldIn, pos, state); } diff --git a/common/src/main/java/common/block/foliage/BlockVine.java b/common/src/main/java/common/block/foliage/BlockVine.java index fc7f7e76..593c4934 100755 --- a/common/src/main/java/common/block/foliage/BlockVine.java +++ b/common/src/main/java/common/block/foliage/BlockVine.java @@ -214,7 +214,7 @@ public class BlockVine extends Block /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { if (!worldIn.client && !this.recheckGrownSides(worldIn, pos, state)) { diff --git a/common/src/main/java/common/block/liquid/BlockLiquid.java b/common/src/main/java/common/block/liquid/BlockLiquid.java index ec16760f..0c37deba 100755 --- a/common/src/main/java/common/block/liquid/BlockLiquid.java +++ b/common/src/main/java/common/block/liquid/BlockLiquid.java @@ -23,7 +23,6 @@ import common.util.Vec3; import common.vars.Vars; import common.world.IBlockAccess; import common.world.IWorldAccess; -import common.world.AWorldClient; import common.world.State; import common.world.World; import common.world.AWorldServer; @@ -237,7 +236,7 @@ public abstract class BlockLiquid extends Block return this.opaque ? BlockLayer.SOLID : BlockLayer.TRANSLUCENT; } - public void displayTick(AWorldClient worldIn, BlockPos pos, State state, Random rand) + public void displayTick(World worldIn, BlockPos pos, State state, Random rand) { double d0 = (double)pos.getX(); double d1 = (double)pos.getY(); @@ -288,7 +287,7 @@ public abstract class BlockLiquid extends Block /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { this.checkForMixing(worldIn, pos, state); } diff --git a/common/src/main/java/common/block/liquid/BlockStaticLiquid.java b/common/src/main/java/common/block/liquid/BlockStaticLiquid.java index 35a5c3b7..ebfe51ba 100755 --- a/common/src/main/java/common/block/liquid/BlockStaticLiquid.java +++ b/common/src/main/java/common/block/liquid/BlockStaticLiquid.java @@ -34,7 +34,7 @@ public class BlockStaticLiquid extends BlockLiquid /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { if (!this.checkForMixing(worldIn, pos, state)) { @@ -42,7 +42,7 @@ public class BlockStaticLiquid extends BlockLiquid } } - private void updateLiquid(World worldIn, BlockPos pos, State state) + private void updateLiquid(AWorldServer worldIn, BlockPos pos, State state) { worldIn.setState(pos, this.dynamicBlock.getState().withProperty(LEVEL, state.getValue(LEVEL)), 2); worldIn.scheduleUpdate(pos, this.dynamicBlock, this.tickRate(worldIn, pos)); diff --git a/common/src/main/java/common/block/natural/BlockBedrock.java b/common/src/main/java/common/block/natural/BlockBedrock.java index f01d4d72..6460c1b4 100755 --- a/common/src/main/java/common/block/natural/BlockBedrock.java +++ b/common/src/main/java/common/block/natural/BlockBedrock.java @@ -5,15 +5,15 @@ import common.block.Material; import common.rng.Random; import common.util.BlockPos; import common.util.ParticleType; -import common.world.AWorldClient; import common.world.State; +import common.world.World; public class BlockBedrock extends Block { public BlockBedrock() { super(Material.SOLID); } - public void displayTick(AWorldClient worldIn, BlockPos pos, State state, Random rand) + public void displayTick(World worldIn, BlockPos pos, State state, Random rand) { if(/* worldIn.canShowVoidParticles() && */ pos.getY() <= 5 && rand.chance(8)) { worldIn.spawnParticle(ParticleType.DEPTH, (double)pos.getX() + rand.floatv(), (double)(pos.getY()+1) + (rand.floatv() * 0.5f), diff --git a/common/src/main/java/common/block/natural/BlockFire.java b/common/src/main/java/common/block/natural/BlockFire.java index ab987d56..38bbde70 100755 --- a/common/src/main/java/common/block/natural/BlockFire.java +++ b/common/src/main/java/common/block/natural/BlockFire.java @@ -25,7 +25,6 @@ import common.util.PortalType; import common.vars.Vars; import common.world.IBlockAccess; import common.world.IWorldAccess; -import common.world.AWorldClient; import common.world.State; import common.world.World; import common.world.AWorldServer; @@ -322,7 +321,7 @@ public class BlockFire extends Block /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { if (!worldIn.isBlockSolid(pos.down()) && !this.canNeighborCatchFire(worldIn, pos)) { @@ -346,7 +345,7 @@ public class BlockFire extends Block } } - public void displayTick(AWorldClient worldIn, BlockPos pos, State state, Random rand) + public void displayTick(World worldIn, BlockPos pos, State state, Random rand) { if (rand.chance(24)) { diff --git a/common/src/main/java/common/block/natural/BlockSnow.java b/common/src/main/java/common/block/natural/BlockSnow.java index cd7bbfec..fa92899d 100755 --- a/common/src/main/java/common/block/natural/BlockSnow.java +++ b/common/src/main/java/common/block/natural/BlockSnow.java @@ -88,7 +88,7 @@ public class BlockSnow extends Block /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { this.checkAndDropBlock(worldIn, pos, state); } diff --git a/common/src/main/java/common/block/tech/BlockBasePressurePlate.java b/common/src/main/java/common/block/tech/BlockBasePressurePlate.java index 6635bc1c..c2b71bc4 100755 --- a/common/src/main/java/common/block/tech/BlockBasePressurePlate.java +++ b/common/src/main/java/common/block/tech/BlockBasePressurePlate.java @@ -94,7 +94,7 @@ public abstract class BlockBasePressurePlate extends Block /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { if (!this.canBePlacedOn(worldIn, pos.down())) { @@ -132,7 +132,7 @@ public abstract class BlockBasePressurePlate extends Block if (i == 0) { - this.updateState(worldIn, pos, state, i); + this.updateState((AWorldServer)worldIn, pos, state, i); } } } @@ -140,7 +140,7 @@ public abstract class BlockBasePressurePlate extends Block /** * Updates the pressure plate when stepped on */ - protected void updateState(World worldIn, BlockPos pos, State state, int oldSignal) + protected void updateState(AWorldServer worldIn, BlockPos pos, State state, int oldSignal) { int i = this.computeSignalStrength(worldIn, pos); boolean flag = oldSignal > 0; @@ -191,7 +191,7 @@ public abstract class BlockBasePressurePlate extends Block /** * Notify block and block below of changes */ - protected void updateNeighbors(World worldIn, BlockPos pos) + protected void updateNeighbors(AWorldServer worldIn, BlockPos pos) { worldIn.notifyNeighborsOfStateChange(pos, this); worldIn.notifyNeighborsOfStateChange(pos.down(), this); diff --git a/common/src/main/java/common/block/tech/BlockBrewingStand.java b/common/src/main/java/common/block/tech/BlockBrewingStand.java index 09ca3d3d..64a408e8 100755 --- a/common/src/main/java/common/block/tech/BlockBrewingStand.java +++ b/common/src/main/java/common/block/tech/BlockBrewingStand.java @@ -20,7 +20,6 @@ import common.util.BlockPos; import common.util.BoundingBox; import common.util.Facing; import common.util.ParticleType; -import common.world.AWorldClient; import common.world.State; import common.world.World; import common.world.AWorldServer; @@ -415,7 +414,7 @@ public class BlockBrewingStand extends Block implements ITileEntityProvider } } - public void displayTick(AWorldClient worldIn, BlockPos pos, State state, Random rand) + public void displayTick(World worldIn, BlockPos pos, State state, Random rand) { double d0 = (double)((float)pos.getX() + 0.4F + rand.floatv() * 0.2F); double d1 = (double)((float)pos.getY() + 0.7F + rand.floatv() * 0.3F); diff --git a/common/src/main/java/common/block/tech/BlockButton.java b/common/src/main/java/common/block/tech/BlockButton.java index 8536a9c9..e90ff3d0 100755 --- a/common/src/main/java/common/block/tech/BlockButton.java +++ b/common/src/main/java/common/block/tech/BlockButton.java @@ -113,7 +113,7 @@ public class BlockButton extends Block implements Directional /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { if (this.checkForDrop(worldIn, pos, state) && !canPlaceButtonOn(worldIn, pos, ((Facing)state.getValue(FACING)).getOpposite())) { @@ -189,8 +189,10 @@ public class BlockButton extends Block implements Directional worldIn.setState(pos, state.withProperty(POWERED, Boolean.valueOf(true)), 3); worldIn.markBlockRangeForRenderUpdate(pos, pos); worldIn.playSound(SoundEvent.CLICK, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, 0.3F); - this.notifyNeighbors(worldIn, pos, (Facing)state.getValue(FACING)); - worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn, null)); + if(!worldIn.client) { + this.notifyNeighbors((AWorldServer)worldIn, pos, (Facing)state.getValue(FACING)); + ((AWorldServer)worldIn).scheduleUpdate(pos, this, this.tickRate(worldIn, null)); + } return true; } } @@ -249,13 +251,13 @@ public class BlockButton extends Block implements Directional { if (!((Boolean)state.getValue(POWERED)).booleanValue()) { - this.checkForArrows(worldIn, pos, state); + this.checkForArrows((AWorldServer)worldIn, pos, state); } } } } - private void checkForArrows(World worldIn, BlockPos pos, State state) + private void checkForArrows(AWorldServer worldIn, BlockPos pos, State state) { this.updateBlockBounds(state); List list = worldIn.getEntitiesWithinAABB(EntityArrow.class, new BoundingBox((double)pos.getX() + this.minX, (double)pos.getY() + this.minY, (double)pos.getZ() + this.minZ, (double)pos.getX() + this.maxX, (double)pos.getY() + this.maxY, (double)pos.getZ() + this.maxZ)); @@ -284,7 +286,7 @@ public class BlockButton extends Block implements Directional } } - private void notifyNeighbors(World worldIn, BlockPos pos, Facing facing) + private void notifyNeighbors(AWorldServer worldIn, BlockPos pos, Facing facing) { worldIn.notifyNeighborsOfStateChange(pos, this); worldIn.notifyNeighborsOfStateChange(pos.offset(facing.getOpposite()), this); diff --git a/common/src/main/java/common/block/tech/BlockFurnace.java b/common/src/main/java/common/block/tech/BlockFurnace.java index 162e1b3d..6cea0ab8 100755 --- a/common/src/main/java/common/block/tech/BlockFurnace.java +++ b/common/src/main/java/common/block/tech/BlockFurnace.java @@ -20,7 +20,6 @@ import common.tileentity.TileEntityFurnace; import common.util.BlockPos; import common.util.Facing; import common.util.ParticleType; -import common.world.AWorldClient; import common.world.State; import common.world.World; import common.world.AWorldServer; @@ -74,7 +73,7 @@ public class BlockFurnace extends Block implements ITileEntityProvider, Rotatabl } - public void displayTick(AWorldClient worldIn, BlockPos pos, State state, Random rand) + public void displayTick(World worldIn, BlockPos pos, State state, Random rand) { if (this.isBurning) { diff --git a/common/src/main/java/common/block/tech/BlockLever.java b/common/src/main/java/common/block/tech/BlockLever.java index f99e5dc0..6be4702d 100755 --- a/common/src/main/java/common/block/tech/BlockLever.java +++ b/common/src/main/java/common/block/tech/BlockLever.java @@ -143,7 +143,7 @@ public class BlockLever extends Block /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { if (this.checkDrop(worldIn, pos, state) && !canPlaceLeverOn(worldIn, pos, ((BlockLever.EnumOrientation)state.getValue(FACING)).getFacing().getOpposite())) { @@ -212,9 +212,9 @@ public class BlockLever extends Block state = state.cycleProperty(POWERED); worldIn.setState(pos, state, 3); worldIn.playSound(SoundEvent.CLICK, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, 0.3F); - worldIn.notifyNeighborsOfStateChange(pos, this); + ((AWorldServer)worldIn).notifyNeighborsOfStateChange(pos, this); Facing enumfacing = ((BlockLever.EnumOrientation)state.getValue(FACING)).getFacing(); - worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing.getOpposite()), this); + ((AWorldServer)worldIn).notifyNeighborsOfStateChange(pos.offset(enumfacing.getOpposite()), this); return true; } } diff --git a/common/src/main/java/common/block/tech/BlockLitTorch.java b/common/src/main/java/common/block/tech/BlockLitTorch.java index eba9050e..f00dc5e6 100755 --- a/common/src/main/java/common/block/tech/BlockLitTorch.java +++ b/common/src/main/java/common/block/tech/BlockLitTorch.java @@ -12,7 +12,6 @@ import common.util.BlockPos; import common.util.Facing; import common.util.ParticleType; import common.vars.Vars; -import common.world.AWorldClient; import common.world.State; import common.world.World; import common.world.AWorldServer; @@ -54,7 +53,7 @@ public class BlockLitTorch extends BlockTorch { } } - public void displayTick(AWorldClient worldIn, BlockPos pos, State state, Random rand) { + public void displayTick(World worldIn, BlockPos pos, State state, Random rand) { if(this.unlit.getParticleColor() == 0xffffffff) { Facing enumfacing = (Facing)state.getValue(FACING); double d0 = (double)pos.getX() + 0.5D; diff --git a/common/src/main/java/common/block/tech/BlockMachine.java b/common/src/main/java/common/block/tech/BlockMachine.java index 6505aed7..39146acf 100755 --- a/common/src/main/java/common/block/tech/BlockMachine.java +++ b/common/src/main/java/common/block/tech/BlockMachine.java @@ -44,7 +44,7 @@ public abstract class BlockMachine extends Block implements Rotatable, ITileEnti return true; } - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) { + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { this.updateState(worldIn, pos, state); } diff --git a/common/src/main/java/common/block/tech/BlockPistonBase.java b/common/src/main/java/common/block/tech/BlockPistonBase.java index 86082a7d..38899e2c 100755 --- a/common/src/main/java/common/block/tech/BlockPistonBase.java +++ b/common/src/main/java/common/block/tech/BlockPistonBase.java @@ -33,14 +33,14 @@ public class BlockPistonBase extends Block implements Directional { private static class BlockPistonStructureHelper { - private final World world; + private final AWorldServer world; private final BlockPos pistonPos; private final BlockPos blockToMove; private final Facing moveDirection; private final List toMove = Lists.newArrayList(); private final List toDestroy = Lists.newArrayList(); - public BlockPistonStructureHelper(World worldIn, BlockPos posIn, Facing pistonFacing, boolean extending) + public BlockPistonStructureHelper(AWorldServer worldIn, BlockPos posIn, Facing pistonFacing, boolean extending) { this.world = worldIn; this.pistonPos = posIn; @@ -277,14 +277,14 @@ public class BlockPistonBase extends Block implements Directional if (!worldIn.client) { - this.checkForMove(worldIn, pos, state); + this.checkForMove((AWorldServer)worldIn, pos, state); } } /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { if (!worldIn.client) { @@ -309,7 +309,7 @@ public class BlockPistonBase extends Block implements Directional return this.getState().withProperty(FACING, getFacingFromEntity(worldIn, pos, placer)).withProperty(EXTENDED, Boolean.valueOf(false)); } - private void checkForMove(World worldIn, BlockPos pos, State state) + private void checkForMove(AWorldServer worldIn, BlockPos pos, State state) { Facing enumfacing = (Facing)state.getValue(FACING); boolean flag = this.shouldBeExtended(worldIn, pos, enumfacing); @@ -349,7 +349,7 @@ public class BlockPistonBase extends Block implements Directional } } - private boolean shouldBeExtended(World worldIn, BlockPos pos, Facing facing) + private boolean shouldBeExtended(AWorldServer worldIn, BlockPos pos, Facing facing) { // for (Facing enumfacing : Facing.values()) // { @@ -443,12 +443,6 @@ public class BlockPistonBase extends Block implements Directional return false; } - public static Facing getFacing(int meta) - { - int i = meta & 7; - return i > 5 ? Facing.getFront(0) : Facing.getFront(i); - } - public static Facing getFacingFromEntity(World worldIn, BlockPos clickedBlock, EntityLiving entityIn) { if (ExtMath.absf((float)entityIn.posX - (float)clickedBlock.getX()) < 2.0F && ExtMath.absf((float)entityIn.posZ - (float)clickedBlock.getZ()) < 2.0F) @@ -469,7 +463,7 @@ public class BlockPistonBase extends Block implements Directional return entityIn.getHorizontalFacing().getOpposite(); } - public static boolean canPush(Block blockIn, World worldIn, BlockPos pos, Facing direction, boolean allowDestroy) + public static boolean canPush(Block blockIn, AWorldServer worldIn, BlockPos pos, Facing direction, boolean allowDestroy) { if (blockIn == Blocks.obsidian) { @@ -523,7 +517,7 @@ public class BlockPistonBase extends Block implements Directional } } - private boolean doMove(World worldIn, BlockPos pos, Facing direction, boolean extending) + private boolean doMove(AWorldServer worldIn, BlockPos pos, Facing direction, boolean extending) { if (!extending) { @@ -594,7 +588,7 @@ public class BlockPistonBase extends Block implements Directional } } - private void launchWithSlimeBlock(World world, BlockPos pos, Facing pistonFacing, boolean extending) + private void launchWithSlimeBlock(AWorldServer world, BlockPos pos, Facing pistonFacing, boolean extending) { float step = 0.25f; diff --git a/common/src/main/java/common/block/tech/BlockPistonHead.java b/common/src/main/java/common/block/tech/BlockPistonHead.java index 2428f4cf..43df8228 100755 --- a/common/src/main/java/common/block/tech/BlockPistonHead.java +++ b/common/src/main/java/common/block/tech/BlockPistonHead.java @@ -174,7 +174,7 @@ public class BlockPistonHead extends Block implements Directional /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { Facing enumfacing = (Facing)state.getValue(FACING); BlockPos blockpos = pos.offset(enumfacing.getOpposite()); diff --git a/common/src/main/java/common/block/tech/BlockRail.java b/common/src/main/java/common/block/tech/BlockRail.java index 07f0bb33..8eb3fbea 100755 --- a/common/src/main/java/common/block/tech/BlockRail.java +++ b/common/src/main/java/common/block/tech/BlockRail.java @@ -107,7 +107,7 @@ public class BlockRail extends Block /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { if (!worldIn.client) { diff --git a/common/src/main/java/common/block/tech/BlockTorch.java b/common/src/main/java/common/block/tech/BlockTorch.java index 6100bc4b..73af7481 100755 --- a/common/src/main/java/common/block/tech/BlockTorch.java +++ b/common/src/main/java/common/block/tech/BlockTorch.java @@ -123,7 +123,7 @@ public abstract class BlockTorch extends Block implements Directional /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { this.onNeighborChangeInternal(worldIn, pos, state); } diff --git a/common/src/main/java/common/block/tech/BlockTripWire.java b/common/src/main/java/common/block/tech/BlockTripWire.java index beb8af0f..9b935124 100755 --- a/common/src/main/java/common/block/tech/BlockTripWire.java +++ b/common/src/main/java/common/block/tech/BlockTripWire.java @@ -82,7 +82,7 @@ public class BlockTripWire extends Block /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { boolean flag = ((Boolean)state.getValue(SUSPENDED)).booleanValue(); boolean flag1 = !worldIn.isBlockSolid(pos.down()); @@ -137,7 +137,7 @@ public class BlockTripWire extends Block } } - private void notifyHook(World worldIn, BlockPos pos, State state) + private void notifyHook(AWorldServer worldIn, BlockPos pos, State state) { for (Facing enumfacing : new Facing[] {Facing.SOUTH, Facing.WEST}) { @@ -173,7 +173,7 @@ public class BlockTripWire extends Block { if (!((Boolean)state.getValue(POWERED)).booleanValue()) { - this.updateState(worldIn, pos); + this.updateState((AWorldServer)worldIn, pos); } } } @@ -189,7 +189,7 @@ public class BlockTripWire extends Block // } } - private void updateState(World worldIn, BlockPos pos) + private void updateState(AWorldServer worldIn, BlockPos pos) { State iblockstate = worldIn.getState(pos); boolean flag = ((Boolean)iblockstate.getValue(POWERED)).booleanValue(); diff --git a/common/src/main/java/common/block/tech/BlockTripWireHook.java b/common/src/main/java/common/block/tech/BlockTripWireHook.java index 6a84bf7c..8c81faf0 100755 --- a/common/src/main/java/common/block/tech/BlockTripWireHook.java +++ b/common/src/main/java/common/block/tech/BlockTripWireHook.java @@ -106,13 +106,14 @@ public class BlockTripWireHook extends Block implements Rotatable */ public void onPlace(World worldIn, BlockPos pos, State state, EntityLiving placer) { - this.triggerHookAt(worldIn, pos, state, false, false, -1, (State)null); + if(!worldIn.client) + this.triggerHookAt((AWorldServer)worldIn, pos, state, false, false, -1, (State)null); } /** * Called when a neighboring block changes. */ - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { if (neighborBlock != this) { @@ -129,7 +130,7 @@ public class BlockTripWireHook extends Block implements Rotatable } } - public void triggerHookAt(World worldIn, BlockPos pos, State hookState, boolean removed, boolean triggered, int wireDist, State wireState) + public void triggerHookAt(AWorldServer worldIn, BlockPos pos, State hookState, boolean removed, boolean triggered, int wireDist, State wireState) { Facing enumfacing = (Facing)hookState.getValue(FACING); boolean attached = ((Boolean)hookState.getValue(ATTACHED)).booleanValue(); @@ -227,7 +228,7 @@ public class BlockTripWireHook extends Block implements Rotatable this.triggerHookAt(worldIn, pos, state, false, true, -1, (State)null); } - private void playerTriggerSounds(World worldIn, BlockPos pos, boolean attached, boolean powered, boolean wasAttached, boolean wasPowered) + private void playerTriggerSounds(AWorldServer worldIn, BlockPos pos, boolean attached, boolean powered, boolean wasAttached, boolean wasPowered) { if (powered && !wasPowered) { @@ -247,7 +248,7 @@ public class BlockTripWireHook extends Block implements Rotatable } } - private void notifyTriggered(World worldIn, BlockPos pos, Facing face) + private void notifyTriggered(AWorldServer worldIn, BlockPos pos, Facing face) { worldIn.notifyNeighborsOfStateChange(pos, this); worldIn.notifyNeighborsOfStateChange(pos.offset(face.getOpposite()), this); diff --git a/common/src/main/java/common/block/tech/BlockWarpChest.java b/common/src/main/java/common/block/tech/BlockWarpChest.java index 6130a377..63dc4e69 100755 --- a/common/src/main/java/common/block/tech/BlockWarpChest.java +++ b/common/src/main/java/common/block/tech/BlockWarpChest.java @@ -19,7 +19,6 @@ import common.rng.Random; import common.util.BlockPos; import common.util.Facing; import common.util.ParticleType; -import common.world.AWorldClient; import common.world.State; import common.world.World; @@ -106,7 +105,7 @@ public class BlockWarpChest extends Block implements Rotatable // return new TileEntityWarpChest(); // } - public void displayTick(AWorldClient worldIn, BlockPos pos, State state, Random rand) + public void displayTick(World worldIn, BlockPos pos, State state, Random rand) { for (int i = 0; i < 3; ++i) { diff --git a/common/src/main/java/common/block/tile/BlockStandingSign.java b/common/src/main/java/common/block/tile/BlockStandingSign.java index d1d6caa6..ee90b768 100755 --- a/common/src/main/java/common/block/tile/BlockStandingSign.java +++ b/common/src/main/java/common/block/tile/BlockStandingSign.java @@ -15,6 +15,7 @@ import common.tileentity.TileEntitySign; import common.util.BlockPos; import common.util.ExtMath; import common.util.Facing; +import common.world.AWorldServer; import common.world.IWorldAccess; import common.world.State; import common.world.World; @@ -39,7 +40,7 @@ public class BlockStandingSign extends BlockSign implements Rotatable } } - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { if (!worldIn.getState(pos.down()).getBlock().getMaterial().isSolid()) { diff --git a/common/src/main/java/common/block/tile/BlockWallSign.java b/common/src/main/java/common/block/tile/BlockWallSign.java index a32cba78..6d965ad7 100755 --- a/common/src/main/java/common/block/tile/BlockWallSign.java +++ b/common/src/main/java/common/block/tile/BlockWallSign.java @@ -7,9 +7,9 @@ import common.model.ModelProvider; import common.model.ModelRotation; import common.util.BlockPos; import common.util.Facing; +import common.world.AWorldServer; import common.world.IWorldAccess; import common.world.State; -import common.world.World; public class BlockWallSign extends BlockSign implements Rotatable { @@ -42,7 +42,7 @@ public class BlockWallSign extends BlockSign implements Rotatable } } - public void onUpdate(World worldIn, BlockPos pos, State state, Block neighborBlock) + public void onUpdate(AWorldServer worldIn, BlockPos pos, State state, Block neighborBlock) { Facing enumfacing = (Facing)state.getValue(FACING); diff --git a/common/src/main/java/common/entity/animal/EntityDragon.java b/common/src/main/java/common/entity/animal/EntityDragon.java index 79c15072..1f0b17cd 100755 --- a/common/src/main/java/common/entity/animal/EntityDragon.java +++ b/common/src/main/java/common/entity/animal/EntityDragon.java @@ -16,7 +16,6 @@ import common.util.ExtMath; import common.util.ParticleType; import common.util.Vec3; import common.vars.Vars; -import common.world.AWorldClient; import common.world.World; public class EntityDragon extends EntityLiving implements IEntityMultiPart @@ -110,7 +109,7 @@ public class EntityDragon extends EntityLiving implements IEntityMultiPart if (f1 <= -0.3F && f >= -0.3F) // && !this.isSilent()) { - ((AWorldClient)this.worldObj).playSound(this.posX, this.posY, this.posZ, SoundEvent.DRAGON_WINGS, 5.0F); + this.worldObj.playSound(this.posX, this.posY, this.posZ, SoundEvent.DRAGON_WINGS, 5.0F); } } diff --git a/common/src/main/java/common/entity/effect/EntityLightning.java b/common/src/main/java/common/entity/effect/EntityLightning.java index 379fd02e..0e52f398 100755 --- a/common/src/main/java/common/entity/effect/EntityLightning.java +++ b/common/src/main/java/common/entity/effect/EntityLightning.java @@ -10,7 +10,6 @@ import common.init.SoundEvent; import common.util.BlockPos; import common.util.BoundingBox; import common.vars.Vars; -import common.world.AWorldClient; import common.world.World; public class EntityLightning extends EntityWeatherEffect @@ -74,11 +73,8 @@ public class EntityLightning extends EntityWeatherEffect if (this.lightningState >= 0) { - if (this.worldObj.client) - { - ((AWorldClient)this.worldObj).setLastLightning(2, this.color); - } - else // if(this.damage > 0) + this.worldObj.setLastLightning(2, this.color); + if (!this.worldObj.client) { double d0 = 3.0D; List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, new BoundingBox(this.posX - d0, this.posY - d0, this.posZ - d0, this.posX + d0, this.posY + 6.0D + d0, this.posZ + d0)); diff --git a/common/src/main/java/common/entity/npc/EntityDarkMage.java b/common/src/main/java/common/entity/npc/EntityDarkMage.java index 520ce6f1..1e6ffbc5 100755 --- a/common/src/main/java/common/entity/npc/EntityDarkMage.java +++ b/common/src/main/java/common/entity/npc/EntityDarkMage.java @@ -4,7 +4,6 @@ import common.ai.AISmallFireballAttack; import common.init.SoundEvent; import common.rng.Random; import common.util.ParticleType; -import common.world.AWorldClient; import common.world.World; public class EntityDarkMage extends EntityHoveringNPC { @@ -85,7 +84,7 @@ public class EntityDarkMage extends EntityHoveringNPC { { if(this.worldObj.client && this.isAttacking()) { if(this.rand.chance(24)) { // && !this.isSilent()) { - ((AWorldClient)this.worldObj).playSound(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D, SoundEvent.FIRE, + this.worldObj.playSound(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D, SoundEvent.FIRE, 1.0F + this.rand.floatv()); } for(int i = 0; i < 2; ++i) { diff --git a/common/src/main/java/common/entity/npc/EntityNPC.java b/common/src/main/java/common/entity/npc/EntityNPC.java index 24de5ad3..f6d076c1 100755 --- a/common/src/main/java/common/entity/npc/EntityNPC.java +++ b/common/src/main/java/common/entity/npc/EntityNPC.java @@ -96,7 +96,6 @@ import common.util.Vec3; import common.util.WorldPos; import common.vars.Vars; import common.village.MerchantRecipeList; -import common.world.AWorldClient; import common.world.World; import common.world.AWorldServer; @@ -2075,7 +2074,7 @@ public abstract class EntityNPC extends EntityLiving if(this.connection != null) this.connection.playSound(name, volume); else if(this.client != null) - ((AWorldClient)this.worldObj).playSound(this.posX, this.posY, this.posZ, name, volume); + this.worldObj.playSound(this.posX, this.posY, this.posZ, name, volume); else if(!this.slave) super.playSound(name, volume); } diff --git a/common/src/main/java/common/tileentity/TileEntityChest.java b/common/src/main/java/common/tileentity/TileEntityChest.java index 43ca126d..bd08f8a2 100755 --- a/common/src/main/java/common/tileentity/TileEntityChest.java +++ b/common/src/main/java/common/tileentity/TileEntityChest.java @@ -10,6 +10,7 @@ import common.item.ItemStack; import common.tags.TagObject; import java.util.List; import common.util.BoundingBox; +import common.world.AWorldServer; public class TileEntityChest extends TileEntity implements ITickable, IInventory { @@ -239,8 +240,10 @@ public class TileEntityChest extends TileEntity implements ITickable, IInventory ++this.numPlayersUsing; this.worldObj.playAuxSFX(2016, this.pos, this.numPlayersUsing); - this.worldObj.notifyNeighborsOfStateChange(this.pos, this.getBlockType()); - this.worldObj.notifyNeighborsOfStateChange(this.pos.down(), this.getBlockType()); + if(!this.worldObj.client) { + ((AWorldServer)this.worldObj).notifyNeighborsOfStateChange(this.pos, this.getBlockType()); + ((AWorldServer)this.worldObj).notifyNeighborsOfStateChange(this.pos.down(), this.getBlockType()); + } // } } @@ -250,8 +253,10 @@ public class TileEntityChest extends TileEntity implements ITickable, IInventory { --this.numPlayersUsing; this.worldObj.playAuxSFX(2016, this.pos, this.numPlayersUsing); - this.worldObj.notifyNeighborsOfStateChange(this.pos, this.getBlockType()); - this.worldObj.notifyNeighborsOfStateChange(this.pos.down(), this.getBlockType()); + if(!this.worldObj.client) { + ((AWorldServer)this.worldObj).notifyNeighborsOfStateChange(this.pos, this.getBlockType()); + ((AWorldServer)this.worldObj).notifyNeighborsOfStateChange(this.pos.down(), this.getBlockType()); + } } } diff --git a/common/src/main/java/common/util/LongHashMap.java b/common/src/main/java/common/util/LongHashMap.java index 65faf9b7..df620d1c 100755 --- a/common/src/main/java/common/util/LongHashMap.java +++ b/common/src/main/java/common/util/LongHashMap.java @@ -25,6 +25,14 @@ public class LongHashMap { this.mask = this.hashArray.length - 1; } + + public void clear() { + this.hashArray = new LongHashMap.Entry[4096]; + this.numHashElements = 0; + this.mask = this.hashArray.length - 1; + this.capacity = 3072; + this.modCount = 0; + } /** * returns the hashed key given the original key diff --git a/common/src/main/java/common/world/AWorldClient.java b/common/src/main/java/common/world/AWorldClient.java deleted file mode 100644 index 5f14b10a..00000000 --- a/common/src/main/java/common/world/AWorldClient.java +++ /dev/null @@ -1,13 +0,0 @@ -package common.world; - -import common.dimension.Dimension; -import common.init.SoundEvent; - -public abstract class AWorldClient extends World { - protected AWorldClient(Dimension dim) { - super(dim, true); - } - - public abstract void playSound(double x, double y, double z, SoundEvent sound, float volume); - public abstract void setLastLightning(int last, int color); -} diff --git a/common/src/main/java/common/world/AWorldServer.java b/common/src/main/java/common/world/AWorldServer.java index fcad3723..e7632bb6 100644 --- a/common/src/main/java/common/world/AWorldServer.java +++ b/common/src/main/java/common/world/AWorldServer.java @@ -52,4 +52,6 @@ public abstract class AWorldServer extends World { public abstract void generateTree(BlockPos pos, State state, Random rand); public abstract float getGenTemperature(int x, int z); public abstract float getGenHumidity(int x, int z); + public abstract void scheduleUpdate(BlockPos pos, Block blockIn, int delay); + public abstract void notifyNeighborsOfStateChange(BlockPos pos, Block blockType); } diff --git a/common/src/main/java/common/world/World.java b/common/src/main/java/common/world/World.java index 5f028982..897bdbd1 100755 --- a/common/src/main/java/common/world/World.java +++ b/common/src/main/java/common/world/World.java @@ -57,14 +57,14 @@ public abstract class World implements IWorldAccess { public final boolean client; public final Random rand = new Random(); public final List entities = Lists.newArrayList(); - protected final List unloaded = Lists.newArrayList(); - protected final List tiles = Lists.newArrayList(); + public final List unloaded = Lists.newArrayList(); + public final List tiles = Lists.newArrayList(); protected final List tickable = Lists.newArrayList(); protected final List addedTiles = Lists.newArrayList(); protected final List removeTiles = Lists.newArrayList(); public final List players = Lists.newArrayList(); public final List effects = Lists.newArrayList(); - protected final IntHashMap entityIds = new IntHashMap(); + public final IntHashMap entityIds = new IntHashMap(); protected final Set active = Sets.newHashSet(); protected final int[] lightUpdate = new int[32768]; public final Dimension dimension; @@ -187,8 +187,6 @@ public abstract class World implements IWorldAccess { return this.formatTime(player == null ? null : player.getOrigin().getDimension(), days); } - protected abstract float getTemperature(BlockPos pos); - public boolean isAirBlock(BlockPos pos) { return this.getState(pos).getBlock() == Blocks.air; } @@ -240,8 +238,6 @@ public abstract class World implements IWorldAccess { } } - protected abstract boolean isLoaded(int x, int z, boolean allowEmpty); - public Chunk getChunk(BlockPos pos) { return this.getChunk(pos.getX() >> 4, pos.getZ() >> 4); } @@ -251,37 +247,19 @@ public abstract class World implements IWorldAccess { * 4 prevents the block from being re-rendered on client worlds */ public boolean setState(BlockPos pos, State newState, int flags) { - if(!isValid(pos)) { + if(!isValid(pos)) return false; - } - else { - Chunk chunk = this.getChunk(pos); - Block block = newState.getBlock(); - State iblockstate = chunk.setState(pos, newState); - - if(iblockstate == null) { - return false; - } - else { - Block block1 = iblockstate.getBlock(); - - if(block.getLightOpacity() != block1.getLightOpacity() || block.getLight() != block1.getLight()) { -// this.profiler.start("checkLight"); - this.checkLight(pos); -// this.profiler.end(); - } - - if((flags & 2) != 0 && (!this.client || (flags & 4) == 0) && chunk.isPopulated()) { - this.markBlockForUpdate(pos); - } - - if(!this.client && (flags & 1) != 0) { - this.notifyNeighborsOfStateChange(pos, iblockstate.getBlock()); - } - - return true; - } - } + Chunk chunk = this.getChunk(pos); + Block block = newState.getBlock(); + State iblockstate = chunk.setState(pos, newState); + if(iblockstate == null) + return false; + Block block1 = iblockstate.getBlock(); + if(block.getLightOpacity() != block1.getLightOpacity() || block.getLight() != block1.getLight()) + this.checkLight(pos); + if((flags & 2) != 0 && (flags & 4) == 0 && chunk.isPopulated()) + this.markBlockForUpdate(pos); + return true; } public boolean setState(BlockPos pos, State state) { @@ -330,49 +308,6 @@ public abstract class World implements IWorldAccess { this.markBlockRangeForRenderUpdate(rangeMin.getX(), rangeMin.getY(), rangeMin.getZ(), rangeMax.getX(), rangeMax.getY(), rangeMax.getZ()); } - public void notifyNeighborsOfStateChange(BlockPos pos, Block blockType) { - this.notifyBlockOfStateChange(pos.west(), blockType); - this.notifyBlockOfStateChange(pos.east(), blockType); - this.notifyBlockOfStateChange(pos.down(), blockType); - this.notifyBlockOfStateChange(pos.up(), blockType); - this.notifyBlockOfStateChange(pos.north(), blockType); - this.notifyBlockOfStateChange(pos.south(), blockType); - } - - public void notifyNeighborsOfStateExcept(BlockPos pos, Block blockType, Facing skipSide) { - if(skipSide != Facing.WEST) { - this.notifyBlockOfStateChange(pos.west(), blockType); - } - - if(skipSide != Facing.EAST) { - this.notifyBlockOfStateChange(pos.east(), blockType); - } - - if(skipSide != Facing.DOWN) { - this.notifyBlockOfStateChange(pos.down(), blockType); - } - - if(skipSide != Facing.UP) { - this.notifyBlockOfStateChange(pos.up(), blockType); - } - - if(skipSide != Facing.NORTH) { - this.notifyBlockOfStateChange(pos.north(), blockType); - } - - if(skipSide != Facing.SOUTH) { - this.notifyBlockOfStateChange(pos.south(), blockType); - } - } - - public void notifyBlockOfStateChange(BlockPos pos, final Block blockIn) { - if(!this.client) { - State iblockstate = this.getState(pos); - - iblockstate.getBlock().onUpdate(this, pos, iblockstate, blockIn); - } - } - public boolean canSeeSky(BlockPos pos) { return this.getChunk(pos).canSeeSky(pos); } @@ -1546,7 +1481,7 @@ public abstract class World implements IWorldAccess { this.temp = this.getBaseTemperature() + this.weather.getTemperature(); } - protected void setActivePlayerChunksAndCheckLight(int l) { + public Set setActivePlayerChunksAndCheckLight(int l) { this.active.clear(); // this.profiler.start("buildList"); @@ -1575,6 +1510,8 @@ public abstract class World implements IWorldAccess { int j2 = ExtMath.floord(entityplayer1.posZ) + this.rand.zrange(11) - 5; this.checkLight(new BlockPos(l1, i2, j2)); } + + return this.active; // this.profiler.end(); } @@ -2029,23 +1966,35 @@ public abstract class World implements IWorldAccess { this.playAuxSFX(null, type, pos, data); } - public void scheduleUpdate(BlockPos pos, Block blockIn, int delay) { + public final void spawnParticle(ParticleType particleType, double xCoord, double yCoord, double zCoord) { + this.spawnParticle(particleType, xCoord, yCoord, zCoord, 0); + } + + + public void playSound(SoundEvent sound, double x, double y, double z, float volume) { + } + + + public void playSound(double x, double y, double z, SoundEvent sound, float volume) { + } + + public void setLastLightning(int last, int color) { } public void spawnParticle(ParticleType particleType, double xCoord, double yCoord, double zCoord, int data) { } - public final void spawnParticle(ParticleType particleType, double xCoord, double yCoord, double zCoord) { - this.spawnParticle(particleType, xCoord, yCoord, zCoord, 0); + public void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2) { } - + + protected void notifyLightSet(BlockPos pos) { + } + + protected abstract float getTemperature(BlockPos pos); + protected abstract boolean isLoaded(int x, int z, boolean allowEmpty); public abstract Chunk getChunk(int x, int z); public abstract void markBlockForUpdate(BlockPos pos); - protected abstract void notifyLightSet(BlockPos pos); - public abstract void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2); - public abstract void playSound(SoundEvent sound, double x, double y, double z, float volume); protected abstract void onEntityAdded(Entity entityIn); protected abstract void onEntityRemoved(Entity entityIn); public abstract void playAuxSFX(EntityNPC player, int sfxType, BlockPos blockPosIn, int data); - public abstract void sendBlockBreakProgress(int breakerId, BlockPos pos, int progress); } diff --git a/server/src/main/java/server/network/Player.java b/server/src/main/java/server/network/Player.java index 3537e519..da3d7c76 100755 --- a/server/src/main/java/server/network/Player.java +++ b/server/src/main/java/server/network/Player.java @@ -83,6 +83,7 @@ import common.packet.SPacketSignEditorOpen; import common.packet.SPacketPlayerAbilities; import common.packet.SPacketTabComplete; import common.packet.SPacketAnimation; +import common.packet.SPacketBlockBreakAnim; import common.packet.SPacketBlockChange; import common.packet.SPacketCharacterList; import common.packet.SPacketChunkData; @@ -933,6 +934,25 @@ public class Player extends User implements Executor, IPlayer return new SPacketMapChunkBulk(xPositions, zPositions, chunksData, sky); } + + private void sendBlockBreakProgress(BlockPos pos, int progress) + { + for (Player conn : this.server.getPlayers()) + { + EntityNPC player = conn.getPresentEntity(); + if (player != null && player.worldObj == this.entity.worldObj && player != this.entity) + { + double d0 = (double)pos.getX() - player.posX; + double d1 = (double)pos.getY() - player.posY; + double d2 = (double)pos.getZ() - player.posZ; + + if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) + { + conn.sendPacket(new SPacketBlockBreakAnim(this.entity.getId(), pos, progress)); + } + } + } + } public void updateEntity() { @@ -1045,7 +1065,7 @@ public class Player extends User implements Executor, IPlayer if (j != this.durabilityRemainingOnBlock) { - this.entity.worldObj.sendBlockBreakProgress(this.entity.getId(), this.removingPos, j); + this.sendBlockBreakProgress(this.removingPos, j); this.durabilityRemainingOnBlock = j; } @@ -1062,7 +1082,7 @@ public class Player extends User implements Executor, IPlayer if (block1 == Blocks.air) { - this.entity.worldObj.sendBlockBreakProgress(this.entity.getId(), this.startPos, -1); + this.sendBlockBreakProgress(this.startPos, -1); this.durabilityRemainingOnBlock = -1; this.isDestroyingBlock = false; } @@ -1074,7 +1094,7 @@ public class Player extends User implements Executor, IPlayer if (l != this.durabilityRemainingOnBlock) { - this.entity.worldObj.sendBlockBreakProgress(this.entity.getId(), this.startPos, l); + this.sendBlockBreakProgress(this.startPos, l); this.durabilityRemainingOnBlock = l; } } @@ -1121,7 +1141,7 @@ public class Player extends User implements Executor, IPlayer this.isDestroyingBlock = true; this.startPos = pos; int i = (int)(f * 10.0F); - this.entity.worldObj.sendBlockBreakProgress(this.entity.getId(), pos, i); + this.sendBlockBreakProgress(pos, i); this.durabilityRemainingOnBlock = i; } // } @@ -1141,7 +1161,7 @@ public class Player extends User implements Executor, IPlayer if (f >= 0.7F) { this.isDestroyingBlock = false; - this.entity.worldObj.sendBlockBreakProgress(this.entity.getId(), pos, -1); + this.sendBlockBreakProgress(pos, -1); this.tryHarvestBlock(pos); } else if (!this.receivedFinishDiggingPacket) @@ -1158,7 +1178,7 @@ public class Player extends User implements Executor, IPlayer public void cancelDestroyingBlock() { this.isDestroyingBlock = false; - this.entity.worldObj.sendBlockBreakProgress(this.entity.getId(), this.startPos, -1); + this.sendBlockBreakProgress(this.startPos, -1); } private boolean removeBlock(BlockPos pos) diff --git a/server/src/main/java/server/world/WorldServer.java b/server/src/main/java/server/world/WorldServer.java index e479134e..e5a52800 100755 --- a/server/src/main/java/server/world/WorldServer.java +++ b/server/src/main/java/server/world/WorldServer.java @@ -73,6 +73,7 @@ import common.util.Vec3; import common.vars.Vars; import common.village.Village; import common.world.BlockArray; +import common.world.Chunk; import common.world.Explosion; import common.world.AWorldServer; import common.world.LightType; @@ -405,7 +406,7 @@ public final class WorldServer extends AWorldServer { this.dimension.setTimeExisted(this.time += 1L); // this.dataModified = true; if(Vars.dayCycle) // { - this.daytime += Vars.timeFlow; + this.daytime += (long)Vars.timeFlow; // if(this.dimension.getType().dayCycle) // this.season = this.getSeasonByTime(); // } @@ -1676,14 +1677,6 @@ public final class WorldServer extends AWorldServer { { this.sendNear(x, y, z, volume > 1.0F ? (double)(16.0F * volume) : 16.0D, new SPacketSoundEffect(sound, x, y, z, volume)); } - - public void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2) - { - } - - protected void notifyLightSet(BlockPos pos) - { - } public void playAuxSFX(EntityNPC player, int sfxType, BlockPos blockPosIn, int data) { @@ -1695,25 +1688,6 @@ public final class WorldServer extends AWorldServer { // this.server.sendPacket(new S28PacketEffect(soundID, pos, data, true)); // } - public void sendBlockBreakProgress(int breakerId, BlockPos pos, int progress) - { - for (Player conn : this.server.getPlayers()) - { - EntityNPC player = conn.getPresentEntity(); - if (player != null && player.worldObj == this && player.getId() != breakerId) - { - double d0 = (double)pos.getX() - player.posX; - double d1 = (double)pos.getY() - player.posY; - double d2 = (double)pos.getZ() - player.posZ; - - if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) - { - conn.sendPacket(new SPacketBlockBreakAnim(breakerId, pos, progress)); - } - } - } - } - private void updatePlayerInstances() { long time = this.time; @@ -2046,6 +2020,24 @@ public final class WorldServer extends AWorldServer { } } } + + public boolean setState(BlockPos pos, State newState, int flags) { + if(!isValid(pos)) + return false; + Chunk chunk = this.getChunk(pos); + Block block = newState.getBlock(); + State iblockstate = chunk.setState(pos, newState); + if(iblockstate == null) + return false; + Block block1 = iblockstate.getBlock(); + if(block.getLightOpacity() != block1.getLightOpacity() || block.getLight() != block1.getLight()) + this.checkLight(pos); + if((flags & 2) != 0 && chunk.isPopulated()) + this.markBlockForUpdate(pos); + if((flags & 1) != 0) + this.notifyNeighborsOfStateChange(pos, iblockstate.getBlock()); + return true; + } public final boolean setBlock(BlockPos pos, ClipboardBlock block) { // int x = position.getBlockX(); @@ -2625,6 +2617,20 @@ public final class WorldServer extends AWorldServer { } } + public void notifyNeighborsOfStateChange(BlockPos pos, Block blockType) { + this.notifyBlockOfStateChange(pos.west(), blockType); + this.notifyBlockOfStateChange(pos.east(), blockType); + this.notifyBlockOfStateChange(pos.down(), blockType); + this.notifyBlockOfStateChange(pos.up(), blockType); + this.notifyBlockOfStateChange(pos.north(), blockType); + this.notifyBlockOfStateChange(pos.south(), blockType); + } + + private void notifyBlockOfStateChange(BlockPos pos, final Block blockIn) { + State iblockstate = this.getState(pos); + iblockstate.getBlock().onUpdate(this, pos, iblockstate, blockIn); + } + private static SPacketMultiBlockChange getPacket(int amount, long[] list, ChunkServer chunk) { ChunkPos pos = new ChunkPos(chunk.xPos, chunk.zPos); SPacketMultiBlockChange.BlockUpdateData[] changes = new SPacketMultiBlockChange.BlockUpdateData[amount];