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.
This commit is contained in:
opfromthestart 2021-05-09 15:57:38 -04:00
parent b374e9a736
commit b3ae829383
4 changed files with 82 additions and 39 deletions

View File

@ -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;
}
}

View File

@ -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<String> FallingBlocks = new HashSet<String>();
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
@ -29,23 +58,30 @@ public class TestEntityLogicFallingBlock extends EntityLogic {
vel = new Vec3(vel.x*friction,vel.y*friction,vel.z);
entity.setVelocity(vel);
TestEntityDataFallingBlock fallBlock = (TestEntityDataFallingBlock) ClientState.getInstance().getWorld().getData().getEntity(entity.getEntityId());
//fallBlock = (TestEntityDataFallingBlock) entity;
TestEntityDataFallingBlock fallBlock = (TestEntityDataFallingBlock) context.getServer().getWorld().getData().getEntity(entity.getEntityId());;
if (fallBlock.isDone() || !context.getWorld().isBlockLoaded(fallBlock.getBlockInWorld(null)))
{
return;
}
Vec3i occupiedBlock = entity.getBlockInWorld(null);
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());
}
}
}

View File

@ -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);
}
};

View File

@ -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<Boolean> {
@ -60,20 +62,10 @@ public class TestWorldGenerator extends AbstractWorldGenerator<Boolean> {
@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<Boolean> {
+ 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);
}
}
});