From b5ccf6fe6a2627f0ba2b924979d3593faceeb80e Mon Sep 17 00:00:00 2001 From: HellFirePvP <01ecs01m> Date: Mon, 9 Nov 2015 13:45:25 +0100 Subject: [PATCH] - TC Eldritch Challenge: -> Known Issues: -> Doesn't create properly if chunk XCoord is <0 -> Doesn't unload Chunks if session is deleted -> Doesn't unload Chunks if entered without session/maze -> Doesn't update BlockPortalNothing -> Transparent --- .../common/registration/RegisteredBlocks.java | 1 + .../utils/world/ChunkProviderTCOuter.java | 34 ++++++++++--------- .../common/utils/world/TCMazeHandler.java | 5 ++- .../world/fake/FakeWorldTCGeneration.java | 31 +++++++++++++---- 4 files changed, 47 insertions(+), 24 deletions(-) diff --git a/src/main/java/makeo/gadomancy/common/registration/RegisteredBlocks.java b/src/main/java/makeo/gadomancy/common/registration/RegisteredBlocks.java index 4e301d4..c47760e 100644 --- a/src/main/java/makeo/gadomancy/common/registration/RegisteredBlocks.java +++ b/src/main/java/makeo/gadomancy/common/registration/RegisteredBlocks.java @@ -13,6 +13,7 @@ import makeo.gadomancy.common.blocks.BlockStickyJar; import makeo.gadomancy.common.blocks.BlockStoneMachine; import makeo.gadomancy.common.blocks.tiles.TileAdditionalEldritchPortal; import makeo.gadomancy.common.blocks.tiles.TileArcaneDropper; +import makeo.gadomancy.common.blocks.tiles.TileBlockProtector; import makeo.gadomancy.common.blocks.tiles.TileExtendedNode; import makeo.gadomancy.common.blocks.tiles.TileExtendedNodeJar; import makeo.gadomancy.common.blocks.tiles.TileInfusionClaw; diff --git a/src/main/java/makeo/gadomancy/common/utils/world/ChunkProviderTCOuter.java b/src/main/java/makeo/gadomancy/common/utils/world/ChunkProviderTCOuter.java index 88ce807..04ef9ef 100644 --- a/src/main/java/makeo/gadomancy/common/utils/world/ChunkProviderTCOuter.java +++ b/src/main/java/makeo/gadomancy/common/utils/world/ChunkProviderTCOuter.java @@ -50,21 +50,21 @@ public class ChunkProviderTCOuter implements IChunkProvider { public Chunk provideChunk(int x, int z) { Chunk chunk; - long key = ((long) x & 15) | ((long) z & 15) << 32; + long key = ((long) x) | ((long) z) << 32; if(TCMazeHandler.GEN.chunks.containsKey(key)) { - System.out.println("preGen Chunk found for " + x + ", " + z); FakeWorldTCGeneration.ChunkBuffer buf = TCMazeHandler.GEN.chunks.get(key); + TCMazeHandler.GEN.chunks.remove(key); + chunk = new Chunk(worldObj, buf.blockData, buf.metaBuffer, x, z); byte[] abyte = chunk.getBiomeArray(); System.arraycopy(biomeArr, 0, abyte, 0, biomeArr.length); for(Integer[] pos : buf.tiles) { - TileEntity te = buf.blockData[pos[3]].createTileEntity(worldObj, metaArr[pos[3]]); + TileEntity te = buf.blockData[pos[3]].createTileEntity(worldObj, buf.metaBuffer[pos[3]]); if(te != null) { - System.out.println("te wasn't null"); worldObj.loadedTileEntityList.add(te); chunk.func_150812_a(pos[0] & 15, pos[1], pos[2] & 15, te); - te.blockMetadata = metaArr[pos[3]]; + te.blockMetadata = buf.metaBuffer[pos[3]]; } } @@ -83,28 +83,36 @@ public class ChunkProviderTCOuter implements IChunkProvider { if(te instanceof TileEntityMobSpawner) { if(!(correspondingTE instanceof TileEntityMobSpawner)) { System.out.println("DATA INCONSISTENCY - TE at " + te.xCoord + ", " + te.yCoord + ", " + te.zCoord + " EXPECTED: " + te.getClass().getSimpleName() + " GIVEN " + correspondingTE.getClass().getSimpleName()); - throw new IllegalStateException(); + //throw new IllegalStateException(); + it.remove(); + continue; } ((TileEntityMobSpawner) correspondingTE).func_145881_a().setEntityName(((TileEntityMobSpawner) te).func_145881_a().getEntityNameToSpawn()); } else if(te instanceof TileEldritchLock) { if(!(correspondingTE instanceof TileEldritchLock)) { System.out.println("DATA INCONSISTENCY - TE at " + te.xCoord + ", " + te.yCoord + ", " + te.zCoord + " EXPECTED: " + te.getClass().getSimpleName() + " GIVEN " + correspondingTE.getClass().getSimpleName()); - throw new IllegalStateException(); + //throw new IllegalStateException(); + it.remove(); + continue; } ((TileEldritchLock) correspondingTE).setFacing(((TileEldritchLock) te).getFacing()); } else if(te instanceof TileCrystal) { if(!(correspondingTE instanceof TileCrystal)) { System.out.println("DATA INCONSISTENCY - TE at " + te.xCoord + ", " + te.yCoord + ", " + te.zCoord + " EXPECTED: " + te.getClass().getSimpleName() + " GIVEN " + correspondingTE.getClass().getSimpleName()); - throw new IllegalStateException(); + //throw new IllegalStateException(); + it.remove(); + continue; } ((TileCrystal) correspondingTE).orientation = ((TileCrystal) te).orientation; } else if(te instanceof TileEldritchCrabSpawner) { if(!(correspondingTE instanceof TileEldritchCrabSpawner)) { System.out.println("DATA INCONSISTENCY - TE at " + te.xCoord + ", " + te.yCoord + ", " + te.zCoord + " EXPECTED: " + te.getClass().getSimpleName() + " GIVEN " + correspondingTE.getClass().getSimpleName()); - throw new IllegalStateException(); + //throw new IllegalStateException(); + it.remove(); + continue; } ((TileEldritchCrabSpawner) correspondingTE).setFacing(((TileEldritchCrabSpawner) te).getFacing()); @@ -126,8 +134,6 @@ public class ChunkProviderTCOuter implements IChunkProvider { item.motionY = 0; item.motionZ = 0; chunk.addEntity(item); - worldObj.loadedEntityList.add(item); - worldObj.onEntityAdded(item); itEntity.remove(); } else if(bufE instanceof FakeWorldTCGeneration.EntityGuardianBuf) { FakeWorldTCGeneration.EntityGuardianBuf b = (FakeWorldTCGeneration.EntityGuardianBuf) bufE; @@ -136,17 +142,13 @@ public class ChunkProviderTCOuter implements IChunkProvider { guardian.setPosition(b.x, b.y, b.z); guardian.setHomeArea(b.coordinates.posX, b.coordinates.posY, b.coordinates.posZ, (int) b.dst); chunk.addEntity(guardian); - worldObj.loadedEntityList.add(guardian); - worldObj.onEntityAdded(guardian); itEntity.remove(); } else { throw new IllegalStateException("Unexpected Entity: " + bufE); } } - - TCMazeHandler.GEN.chunks.remove(key); } else { - System.out.println("Creating NEW Chunk"); + //System.out.println("Creating NEW Chunk"); Block[] ablock = new Block[blockArr.length]; System.arraycopy(blockArr, 0, ablock, 0, blockArr.length); diff --git a/src/main/java/makeo/gadomancy/common/utils/world/TCMazeHandler.java b/src/main/java/makeo/gadomancy/common/utils/world/TCMazeHandler.java index 8306833..cf2c630 100644 --- a/src/main/java/makeo/gadomancy/common/utils/world/TCMazeHandler.java +++ b/src/main/java/makeo/gadomancy/common/utils/world/TCMazeHandler.java @@ -143,7 +143,7 @@ public class TCMazeHandler { } private static int randWH(Random random) { - return 15 + random.nextInt(8) * 2; + return 17 + random.nextInt(2) * 2; } public static void init() { @@ -244,6 +244,9 @@ public class TCMazeHandler { MazeHandler.labyrinth = old; } System.out.println("BuildTime: " + (System.currentTimeMillis() - startMs) + " (ms)"); + System.out.println("Blocks SET: " + GEN.blockCount); + System.out.println("Blocks OVERWRITTEN: " + GEN.blockOverwriteCount); + System.out.println("BufferChunks CREATED: " + FakeWorldTCGeneration.ChunkBuffer.cnt); finishBuild(); } diff --git a/src/main/java/makeo/gadomancy/common/utils/world/fake/FakeWorldTCGeneration.java b/src/main/java/makeo/gadomancy/common/utils/world/fake/FakeWorldTCGeneration.java index f486e57..22248d7 100644 --- a/src/main/java/makeo/gadomancy/common/utils/world/fake/FakeWorldTCGeneration.java +++ b/src/main/java/makeo/gadomancy/common/utils/world/fake/FakeWorldTCGeneration.java @@ -7,6 +7,7 @@ import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChunkCoordinates; +import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.WorldProvider; import net.minecraft.world.chunk.Chunk; import net.minecraftforge.common.util.ForgeDirection; @@ -36,15 +37,24 @@ public class FakeWorldTCGeneration extends FakeWorld { public ChunkMap chunks = new ChunkMap(); public List bufferedEntities = new ArrayList(); public Map gettedTE = new HashMap(); + public int blockCount = 0, blockOverwriteCount = 0; @Override public boolean setBlock(int x, int y, int z, Block block, int meta, int flags) { if(block == ConfigBlocks.blockEldritchPortal) return true; if(block == ConfigBlocks.blockEldritch && (meta == 1 || meta == 2 || meta == 3)) return true; - ChunkBuffer buf = chunks.get(((long) x & 15) | ((long) z & 15) << 32); - int key = ((x & 15) << 4 | (z & 15)) << 7 | y; + blockCount++; + long chKey = ((long) x >> 4) | ((long) z >> 4) << 32; + ChunkBuffer buf = chunks.get(chKey); + int keyX = (x & 15) << 7 << 4; + int keyZ = (z & 15) << 7; + int key = keyX | keyZ | y; + + if(buf.blockData[key] != null) { + blockOverwriteCount++; + } buf.blockData[key] = block; buf.metaBuffer[key] = (byte) meta; if(block.hasTileEntity(meta)) buf.tiles.add(new Integer[] {x, y, z, key}); @@ -53,8 +63,12 @@ public class FakeWorldTCGeneration extends FakeWorld { @Override public Block getBlock(int x, int y, int z) { - ChunkBuffer buf = chunks.get(((long) x & 15) | ((long) z & 15) << 32); - int key = ((x & 15) << 4 | (z & 15)) << 7 | y; + long chKey = ((long) x >> 4) | ((long) z >> 4) << 32; + ChunkBuffer buf = chunks.get(chKey); + int keyX = (x & 15) << 7 << 4; + int keyZ = (z & 15) << 7; + int key = keyX | keyZ | y; + //int key = ((x & 15) << 4 | (z & 15)) << 7 | y; Block b = buf.blockData[key]; return b == null ? Blocks.air : b; @@ -62,8 +76,11 @@ public class FakeWorldTCGeneration extends FakeWorld { @Override public int getBlockMetadata(int x, int y, int z) { - ChunkBuffer buf = chunks.get(((long) x & 15) | ((long) z & 15) << 32); - int key = ((x & 15) << 4 | (z & 15)) << 7 | y; + long chKey = ((long) x >> 4) | ((long) z >> 4) << 32; + ChunkBuffer buf = chunks.get(chKey); + int keyX = (x & 15) << 7 << 4; + int keyZ = (z & 15) << 7; + int key = keyX | keyZ | y; return buf.metaBuffer[key]; } @@ -158,7 +175,7 @@ public class FakeWorldTCGeneration extends FakeWorld { public Block[] blockData = new Block[32768]; public byte[] metaBuffer = new byte[32768]; public List tiles = new ArrayList(); - static int cnt = 0; + public static int cnt = 0; public ChunkBuffer(long key) { this.key = key;