From b3ae82938327f3cff4ec86e091a1f5a877319c87 Mon Sep 17 00:00:00 2001 From: opfromthestart Date: Sun, 9 May 2021 15:57:38 -0400 Subject: [PATCH] Almost All Works -Added Set in TestEntityLogicFallingBlock to keep track of gravity blocks -Used this set in listener in TestWorldGenerator -setInvisible and isDone() methods in TestEntityDataFallingBlock -Used to determine if the entity should be rendered/cared about in TestEntityRenderFallingBlock and TestEntityLogicFallingBlock -Added more accurate Vec3i mod and div methods in TestEntityLogicFallingBlock *Change this to a better place -TestEntityLogicFallingBlock actually places the block when the entity lands -Better air block detection in TestWorldGenerator *Still cannot erase the original placed block, not sure why. --- .../test/TestEntityDataFallingBlock.java | 13 +++++ .../test/TestEntityLogicFallingBlock.java | 58 +++++++++++++++---- .../test/TestEntityRenderFallingBlock.java | 29 +++++----- .../test/gen/TestWorldGenerator.java | 21 +++---- 4 files changed, 82 insertions(+), 39 deletions(-) diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityDataFallingBlock.java b/src/main/java/ru/windcorp/progressia/test/TestEntityDataFallingBlock.java index cdb5060..cf47a29 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityDataFallingBlock.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityDataFallingBlock.java @@ -12,6 +12,7 @@ import ru.windcorp.progressia.common.world.entity.EntityData; public class TestEntityDataFallingBlock extends EntityData { private BlockData block; + private boolean isDone = false; public TestEntityDataFallingBlock() { this("Test:FallingBlock",new BlockData("Test:Sand")); @@ -27,4 +28,16 @@ public class TestEntityDataFallingBlock extends EntityData { { return block; } + + public void setInvisible() + { + //block = new BlockData("Test:Log"); + isDone = true; + setCollisionModel(new AABB(0,0,0,.5f,0.5f,0.5f)); + } + + public boolean isDone() + { + return isDone; + } } diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java b/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java index 1b8b600..2c52c73 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java @@ -1,9 +1,13 @@ package ru.windcorp.progressia.test; +import java.util.HashSet; +import java.util.Set; + import org.apache.logging.log4j.LogManager; import glm.vec._3.Vec3; import glm.vec._3.i.Vec3i; +import ru.windcorp.progressia.client.ClientState; import ru.windcorp.progressia.common.world.entity.EntityData; import ru.windcorp.progressia.server.world.TickContext; import ru.windcorp.progressia.server.world.entity.EntityLogic; @@ -15,12 +19,37 @@ import ru.windcorp.progressia.server.world.entity.EntityLogic; */ public class TestEntityLogicFallingBlock extends EntityLogic { + public static Set FallingBlocks = new HashSet(); + + public void addFallables() + { + FallingBlocks.add("Test:Sand"); + } + public TestEntityLogicFallingBlock(String id) { super(id); + addFallables(); + } + + private Vec3i trueMod(Vec3i input,Vec3i modulus) //Move this to a class in Vec or something + { + return input.mod_(modulus).add_(modulus).mod_(modulus); + } + + private Vec3i trueDiv(Vec3i input,Vec3i divisor) //Move this to a class in Vec or something + { + Vec3i temp = input.div_(divisor); + temp.add(new Vec3i(input.x<0 ? -1 : 0,input.y<0 ? -1 : 0,input.z<0 ? -1 : 0)); + return temp; } @Override public void tick(EntityData entity, TickContext context) { + if (entity == null) + { + return; + } + //LogManager.getLogger().info("NotNull "+entity.toString() + " " + context.toString()); super.tick(entity, context); //friction @@ -28,24 +57,31 @@ public class TestEntityLogicFallingBlock extends EntityLogic { float friction = .8f; vel = new Vec3(vel.x*friction,vel.y*friction,vel.z); entity.setVelocity(vel); - - TestEntityDataFallingBlock fallBlock = (TestEntityDataFallingBlock) context.getServer().getWorld().getData().getEntity(entity.getEntityId());; - - Vec3i occupiedBlock = entity.getBlockInWorld(null); + TestEntityDataFallingBlock fallBlock = (TestEntityDataFallingBlock) ClientState.getInstance().getWorld().getData().getEntity(entity.getEntityId()); + //fallBlock = (TestEntityDataFallingBlock) entity; + + if (fallBlock.isDone() || !context.getWorld().isBlockLoaded(fallBlock.getBlockInWorld(null))) + { + return; + } + + Vec3i occupiedBlock = fallBlock.getBlockInWorld(null); Vec3i underBlock = occupiedBlock.sub_(0, 0, 1); - Vec3i chunkCoords = underBlock.div_(16); - Vec3i inChunkCoords = underBlock.mod_(new Vec3i(16)); + Vec3i chunkCoords = trueDiv(underBlock, new Vec3i(16)); + Vec3i inChunkCoords = trueMod(underBlock, new Vec3i(16)); - LogManager.getLogger().info("FallingBlock is at "+String.valueOf(occupiedBlock.x)+" "+String.valueOf(occupiedBlock.y)+" "+String.valueOf(occupiedBlock.z)); - LogManager.getLogger().info("Block is of type " + context.getWorldData().getChunk(chunkCoords).getBlock(inChunkCoords).getId()); + //LogManager.getLogger().info("InChunk "+String.valueOf(chunkCoords.x)+" "+String.valueOf(chunkCoords.y)+" "+String.valueOf(chunkCoords.z)+" "+String.valueOf(inChunkCoords.x)+" "+String.valueOf(inChunkCoords.y)+" "+String.valueOf(inChunkCoords.z)); + //LogManager.getLogger().info("FallingBlock is at "+String.valueOf(occupiedBlock.x)+" "+String.valueOf(occupiedBlock.y)+" "+String.valueOf(occupiedBlock.z)); + //LogManager.getLogger().info("Block is of type " + context.getWorldData().getChunk(chunkCoords).getBlock(inChunkCoords).getId()); - if (context.getServer().getWorld().getData().getChunk(chunkCoords).getBlock(inChunkCoords) + if (ClientState.getInstance().getWorld().getData().getChunk(chunkCoords).getBlock(inChunkCoords) .getId() != "Test:Air") { LogManager.getLogger().info("Deleting FallingBlock at " + String.valueOf(occupiedBlock.x)); - context.getServer().getWorldAccessor().setBlock(occupiedBlock, fallBlock.getBlock()); - context.getServer().getWorld().getData().removeEntity(entity); + ClientState.getInstance().getWorld().getData().setBlock(occupiedBlock, fallBlock.getBlock(),true); + fallBlock.setInvisible(); //Until I know how to properly delete it. + //ClientState.getInstance().getWorld().getData().removeEntity(entity.getEntityId()); } } } diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityRenderFallingBlock.java b/src/main/java/ru/windcorp/progressia/test/TestEntityRenderFallingBlock.java index 7fe07da..fccb704 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityRenderFallingBlock.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityRenderFallingBlock.java @@ -15,6 +15,7 @@ import ru.windcorp.progressia.common.world.entity.EntityData; /** * Renderer for Test:FallingBlock + * * @author opfromthestart * */ @@ -23,22 +24,13 @@ public class TestEntityRenderFallingBlock extends EntityRender { public TestEntityRenderFallingBlock(String id) { super(id); - cube = new Shapes.PppBuilder( - WorldRenderProgram.getDefault(), - new SimpleTexture( - Atlases.getSprite( - ResourceManager.getTextureResource("blocks/Sand"), new AtlasGroup("Blocks", 1 << 12) - ) - ) - ).create(); + cube = new Shapes.PppBuilder(WorldRenderProgram.getDefault(), new SimpleTexture(Atlases + .getSprite(ResourceManager.getTextureResource("blocks/Sand"), new AtlasGroup("Blocks", 1 << 12)))) + .create(); } - + public void setTexture(Texture texture) { // There has to be a better way. - cube = new Shapes.PppBuilder( - WorldRenderProgram.getDefault(), - texture - ) - .create(); + cube = new Shapes.PppBuilder(WorldRenderProgram.getDefault(), texture).create(); } @Override @@ -46,7 +38,14 @@ public class TestEntityRenderFallingBlock extends EntityRender { return new EntityRenderable(entity) { @Override public void render(ShapeRenderHelper renderer) { - //LogManager.getLogger().info("Rendering FallingBlock"); + // LogManager.getLogger().info("Rendering FallingBlock"); + if (((TestEntityDataFallingBlock) entity).isDone()) { + return; + //setTexture(new SimpleTexture(Atlases.getSprite(ResourceManager.getTextureResource("blocks/LogSide"), + // new AtlasGroup("Blocks", 1 << 12)))); + } + //setTexture(new SimpleTexture(Atlases.getSprite(ResourceManager.getTextureResource("blocks/Sand"), + // new AtlasGroup("Blocks", 1 << 12)))); cube.render(renderer); } }; diff --git a/src/main/java/ru/windcorp/progressia/test/gen/TestWorldGenerator.java b/src/main/java/ru/windcorp/progressia/test/gen/TestWorldGenerator.java index 5898fe3..6ec975f 100644 --- a/src/main/java/ru/windcorp/progressia/test/gen/TestWorldGenerator.java +++ b/src/main/java/ru/windcorp/progressia/test/gen/TestWorldGenerator.java @@ -27,6 +27,7 @@ import org.apache.logging.log4j.LogManager; import glm.vec._3.Vec3; import glm.vec._3.i.Vec3i; +import ru.windcorp.progressia.client.ClientState; import ru.windcorp.progressia.common.util.VectorUtil; import ru.windcorp.progressia.common.util.Vectors; import ru.windcorp.progressia.common.world.ChunkData; @@ -43,6 +44,7 @@ import ru.windcorp.progressia.common.world.tile.TileDataRegistry; import ru.windcorp.progressia.server.world.WorldLogic; import ru.windcorp.progressia.server.world.generation.AbstractWorldGenerator; import ru.windcorp.progressia.test.TestEntityDataFallingBlock; +import ru.windcorp.progressia.test.TestEntityLogicFallingBlock; public class TestWorldGenerator extends AbstractWorldGenerator { @@ -60,20 +62,10 @@ public class TestWorldGenerator extends AbstractWorldGenerator { @Override public void onChunkBlockChanged(ChunkData chunk, Vec3i blockInChunk, BlockData previous, BlockData current) { - if (current.getId() != "Test:Sand") { // Replace with - // proper check - // for all - // gravity - // blocks + if (!TestEntityLogicFallingBlock.FallingBlocks.contains(current.getId())) { return; } - if (chunk.getBlock(blockInChunk.add_(0, 0, -1)).getId() == "Test:Air")// TODO - // Won't - // work - // on - // z - // chunk - // boundaries + if (chunk.getWorld().getBlock(chunk.getPosition().mul_(16).add_(blockInChunk.add_(0, 0, -1))).getId() == "Test:Air") { LogManager.getLogger().info("Inserting FallingBlock"); @@ -87,7 +79,10 @@ public class TestWorldGenerator extends AbstractWorldGenerator { + String.valueOf(new Random().nextFloat())).hashCode()); chunk.getWorld().addEntity(fallingBlock); - chunk.setBlock(blockInChunk, BlockDataRegistry.getInstance().get("Test:Air"), true); + chunk.setBlock(blockInChunk, previous, true); + Vec3i chunkWorldPos = chunk.getPosition().mul_(16).add_(blockInChunk); + LogManager.getLogger().info(String.valueOf(chunkWorldPos.x)+" "+String.valueOf(chunkWorldPos.y)+" "+String.valueOf(chunkWorldPos.z)); + ClientState.getInstance().getWorld().getData().setBlock(chunkWorldPos, BlockDataRegistry.getInstance().get("Test:Glass"), true); } } });