diff --git a/src/main/java/ru/windcorp/progressia/server/Server.java b/src/main/java/ru/windcorp/progressia/server/Server.java index c3cbb03..9c6b67e 100644 --- a/src/main/java/ru/windcorp/progressia/server/Server.java +++ b/src/main/java/ru/windcorp/progressia/server/Server.java @@ -94,8 +94,7 @@ public class Server { world.addListener(new WorldDataListener() { @Override public void onChunkLoaded(DefaultWorldData world, DefaultChunkData chunk) { - //PlanetGenerator.this.planet; - //LogManager.getLogger().info("Loaded chunk"); + GravityModelRegistry.getInstance().get("Test:PlanetGravityModel"); chunk.addListener(new ChunkDataListener() { // Falling Block // spawning logic @@ -105,35 +104,34 @@ public class Server { Vec3i chunkWorldPos = new Vec3i(0,0,0); Coordinates.getInWorld(chunk_2.getPosition(), blockInChunk, chunkWorldPos); - /*List underBlocks = getGoodCardinals(fallBlock.getUpVector().negate_()); - boolean notSupported = false; - for (Vec3i v3 : underBlocks) + + + boolean isUnsupported = false; + List cards = TestEntityLogicFallingBlock.getGoodCardinals(chunk_2.getWorld().getGravityModel().getUp(new Vec3(chunkWorldPos.x,chunkWorldPos.y,chunkWorldPos.z), null)); + for (Vec3i card : cards) { - Vec3i inWorld = occupiedBlock.sub_(v3); - if (context.getBlock(inWorld).getId()=="Test:Air") { - notSupported=true; - break; + if (chunk_2.getWorld().isLocationLoaded(chunkWorldPos.sub_(card)) && + chunk_2.getWorld().getBlock(chunkWorldPos.sub_(card)).getId() == "Test:Air") + { + isUnsupported = true; + } + if (TestEntityLogicFallingBlock.FallingBlocks + .contains(chunk_2.getWorld().getBlock(chunkWorldPos.add_(card)).getId())) { + chunk_2.getWorld().setBlock(chunkWorldPos.add_(card), BlockDataRegistry.getInstance() + .get(chunk_2.getWorld().getBlock(chunkWorldPos.add_(card)).getId()), true); } - }*/ - - //chunk.getPosition().mul_(16).add_(blockInChunk); - //LogManager.getLogger().info("Put block {} at {}<{}<{}",current.getId(),chunkWorldPos.x,chunkWorldPos.y,chunkWorldPos.z); - - if (TestEntityLogicFallingBlock.FallingBlocks - .contains(chunk_2.getWorld().getBlock(chunkWorldPos.add_(0, 0, 1)).getId())) { - chunk_2.getWorld().setBlock(chunkWorldPos.add_(0, 0, 1), BlockDataRegistry.getInstance() - .get(chunk_2.getWorld().getBlock(chunkWorldPos.add_(0, 0, 1)).getId()), true); } if (!TestEntityLogicFallingBlock.FallingBlocks.contains(current.getId())) { return; } - //LogManager.getLogger().info("Cont"); - if (chunk_2.getWorld().getBlock(chunkWorldPos.add_(0, 0, -1)).getId() == "Test:Air") { - LogManager.getLogger().info("Inserting FallingBlock {},{},{}", - chunkWorldPos.x,chunkWorldPos.y,chunkWorldPos.z); + if (isUnsupported) { + TestEntityDataFallingBlock fallingBlock = new TestEntityDataFallingBlock(current); + + LogManager.getLogger().info("Inserting {} {},{},{}", fallingBlock.getId(), + chunkWorldPos.x,chunkWorldPos.y,chunkWorldPos.z); Vec3i worldPos = chunk_2.getPosition().mul_(16).add_(blockInChunk); Vec3 floatWorldPos = new Vec3(worldPos.x, worldPos.y, worldPos.z); @@ -142,15 +140,7 @@ public class Server { fallingBlock.setEntityId(("Test:FallingBlock" + floatWorldPos.toString() + String.valueOf(new Random().nextFloat())).hashCode()); - chunk.getWorld().addEntity(fallingBlock); - //invokeLater(() -> world.addEntity(fallingBlock)); - - //chunk.setBlock(blockInChunk, previous, false); - //invokeLater(() -> world.setBlock(chunkWorldPos, BlockDataRegistry.getInstance().get("Test:Air"), false)); - - - //LogManager.getLogger().info(String.valueOf(chunkWorldPos.x) + " " - // + String.valueOf(chunkWorldPos.y) + " " + String.valueOf(chunkWorldPos.z)); + invokeLater(() -> chunk.getWorld().addEntity(fallingBlock)); } } }); diff --git a/src/main/java/ru/windcorp/progressia/test/TestContent.java b/src/main/java/ru/windcorp/progressia/test/TestContent.java index 99c41fc..591024e 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestContent.java +++ b/src/main/java/ru/windcorp/progressia/test/TestContent.java @@ -257,9 +257,24 @@ public class TestContent { register(new TestEntityRenderStatie("Test:Statie")); register(new TestEntityLogicStatie("Test:Statie")); + registerSands(); + } + + private static void registerSands() + { + TestEntityLogicFallingBlock.addFallables(); + register("Test:FallingBlock", TestEntityDataFallingBlock::new); register(new TestEntityLogicFallingBlock("Test:FallingBlock")); - register(new TestEntityRenderFallingBlock("Test:FallingBlock")); + register(new TestEntityRenderFallingBlock("Test:FallingBlock","Sand")); + + for (String str : TestEntityLogicFallingBlock.FallingBlocks) + { + register("Test:FallingBlock" + str.substring(5), TestEntityDataFallingBlock::new); + register(new TestEntityLogicFallingBlock("Test:FallingBlock"+str.substring(5))); + register(new TestEntityRenderFallingBlock("Test:FallingBlock"+str.substring(5), str.substring(5))); + } + } private static void regsiterControls() { diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityDataFallingBlock.java b/src/main/java/ru/windcorp/progressia/test/TestEntityDataFallingBlock.java index 705d1af..469da1b 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityDataFallingBlock.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityDataFallingBlock.java @@ -1,7 +1,5 @@ package ru.windcorp.progressia.test; -import org.apache.logging.log4j.LogManager; - import ru.windcorp.progressia.common.collision.AABB; import ru.windcorp.progressia.common.world.block.BlockData; import ru.windcorp.progressia.common.world.entity.EntityData; @@ -18,19 +16,23 @@ public class TestEntityDataFallingBlock extends EntityData { private boolean isDone = false; private boolean hasDeleted = false; - public TestEntityDataFallingBlock() { - this("Test:FallingBlock", new BlockData("Test:LogTop")); + public TestEntityDataFallingBlock() + { + this("Test:FallingBlock"); } - public TestEntityDataFallingBlock(BlockData data) { - this("Test:FallingBlock", data); + public TestEntityDataFallingBlock(String id, BlockData inBlock) { + super(id); + block = inBlock; + setCollisionModel(new AABB(0, 0, 0, 1, 1, 1)); } - protected TestEntityDataFallingBlock(String id, BlockData blockInput) { - super(id); - setCollisionModel(new AABB(0, 0, 0, 1, 1, 1)); - block = blockInput; - LogManager.getLogger().info(blockInput.getId()); + public TestEntityDataFallingBlock(String string) { + this(string, new BlockData((String) TestEntityLogicFallingBlock.FallingBlocks.toArray()[0])); + } + + public TestEntityDataFallingBlock(BlockData current) { + this("Test:FallingBlock"+current.getId().substring(5), current); } public void setDestroyed() { @@ -40,15 +42,16 @@ public class TestEntityDataFallingBlock extends EntityData { public boolean hasDestroyed() { return hasDeleted; } - - public BlockData getBlock() { + + public BlockData getBlock() + { return block; } public void setInvisible() { // block = new BlockData("Test:Log"); isDone = true; - setCollisionModel(new AABB(0, 0, 0, .5f, 0.5f, 0.5f)); + setCollisionModel(new AABB(0, 0, 0, 0.5f, 0.5f, 0.5f)); } public boolean isDone() { diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java b/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java index 03c725d..460b464 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java @@ -27,7 +27,7 @@ public class TestEntityLogicFallingBlock extends EntityLogic { public static Set FallingBlocks = new HashSet(); - public void addFallables() { + public static void addFallables() { FallingBlocks.add("Test:Sand"); for (Rock rock : TestContent.ROCKS.getRocks()) { @@ -38,7 +38,6 @@ public class TestEntityLogicFallingBlock extends EntityLogic { public TestEntityLogicFallingBlock(String id) { super(id); - addFallables(); } /*private Vec3i trueMod(Vec3i input, Vec3i modulus) // Move this to a class in @@ -55,7 +54,7 @@ public class TestEntityLogicFallingBlock extends EntityLogic { return temp; }*/ - public Vec3i getBestCardinal(Vec3 dir) + public static Vec3i getBestCardinal(Vec3 dir) { Vec3 a = dir.abs_(); if (a.x>a.y && a.x>a.z) @@ -69,12 +68,12 @@ public class TestEntityLogicFallingBlock extends EntityLogic { return new Vec3i(0,0,dir.z>0 ? 1 : -1); } - public List getGoodCardinals(Vec3 dir) + public static List getGoodCardinals(Vec3 dir) { return getGoodCardinals(dir,.05f); } - public List getGoodCardinals(Vec3 dir, float d) { + public static List getGoodCardinals(Vec3 dir, float d) { List list = new ArrayList<>(); Vec3 a = dir.abs_(); if (a.x>d) @@ -142,14 +141,13 @@ public class TestEntityLogicFallingBlock extends EntityLogic { } Vec3i occupiedBlock = fallBlock.getBlockInWorld(null); - Vec3i underBlock = occupiedBlock.sub_(getBestCardinal(fallBlock.getUpVector())); List underBlocks = getGoodCardinals(fallBlock.getUpVector()); boolean notSupported = false; for (Vec3i v3 : underBlocks) { Vec3i inWorld = occupiedBlock.sub_(v3); - if (context.getBlock(inWorld).getId()=="Test:Air") { + if (context.getBlock(inWorld) != null && context.getBlock(inWorld).getId()=="Test:Air") { notSupported=true; break; } @@ -166,10 +164,7 @@ public class TestEntityLogicFallingBlock extends EntityLogic { String.valueOf(occupiedBlock.z));*/ //LogManager.getLogger().info("Block is of type " + //context.getWorldData().getChunk(chunkCoords).getBlock(inChunkCoords).getId()); - - if (context.getBlock(underBlock) != null - // && context.getBlock(underBlock).getId() != "Test:Air") { - && !notSupported) { + if ( !notSupported && context.isLocationLoaded(occupiedBlock)) { LogManager.getLogger().info("Deleting FallingBlock at " + String.valueOf(occupiedBlock.x) + " " + String.valueOf(occupiedBlock.y) + " " + String.valueOf(occupiedBlock.z)); context.setBlock(occupiedBlock, fallBlock2.getBlock()); fallBlock.setInvisible(); diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityRenderFallingBlock.java b/src/main/java/ru/windcorp/progressia/test/TestEntityRenderFallingBlock.java index ab121e3..003b201 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityRenderFallingBlock.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityRenderFallingBlock.java @@ -1,6 +1,5 @@ package ru.windcorp.progressia.test; -import ru.windcorp.progressia.client.ClientState; import ru.windcorp.progressia.client.graphics.model.Renderable; import ru.windcorp.progressia.client.graphics.model.ShapeRenderHelper; import ru.windcorp.progressia.client.graphics.model.Shapes; @@ -20,10 +19,9 @@ import ru.windcorp.progressia.common.world.entity.EntityData; public class TestEntityRenderFallingBlock extends EntityRender { private Renderable cube; - public TestEntityRenderFallingBlock(String id) { + public TestEntityRenderFallingBlock(String id, String blockName) { super(id); - String dflt = TestEntityLogicFallingBlock.FallingBlocks.toArray()[0].toString().substring(5); - cube = new Shapes.PppBuilder(WorldRenderProgram.getDefault(), BlockRenderRegistry.getBlockTexture(dflt ) )// TODO idk actual ggood this + cube = new Shapes.PppBuilder(WorldRenderProgram.getDefault(), BlockRenderRegistry.getBlockTexture(blockName ) )// TODO idk actual ggood this .create(); } @@ -36,18 +34,9 @@ public class TestEntityRenderFallingBlock extends EntityRender { return new EntityRenderable(entity) { @Override public void doRender(ShapeRenderHelper renderer) { - // LogManager.getLogger().info("Rendering FallingBlock"); if (((TestEntityDataFallingBlock) entity).isDone()) { return; - // setTexture(new - // SimpleTexture(Atlases.getSprite(ResourceManager.getTextureResource("blocks/LogSide"), - // new AtlasGroup("Blocks", 1 << 12)))); } - TestEntityDataFallingBlock fallEntity = (TestEntityDataFallingBlock) ClientState.getInstance().getWorld().getData().getEntity(entity.getEntityId()); - setTexture(BlockRenderRegistry.getBlockTexture(fallEntity.getBlock().getId().substring(5))); - // setTexture(new - // SimpleTexture(Atlases.getSprite(ResourceManager.getTextureResource("blocks/Sand"), - // new AtlasGroup("Blocks", 1 << 12)))); cube.render(renderer); } };