Conservation of Matter

-Placing a Test:Sand block now deletes the block and summons a Test:FallingBlock in its place.
This commit is contained in:
opfromthestart 2021-06-10 14:08:35 -04:00
parent bf49687ab6
commit 47eb9fa5af
3 changed files with 23 additions and 4 deletions

View File

@ -13,6 +13,7 @@ public class TestEntityDataFallingBlock extends EntityData {
private BlockData block;
private boolean isDone = false;
private boolean hasDeleted = false;
public TestEntityDataFallingBlock() {
this("Test:FallingBlock",new BlockData("Test:Sand"));
@ -24,6 +25,16 @@ public class TestEntityDataFallingBlock extends EntityData {
block = blockInput;
}
public void setDestroyed()
{
hasDeleted = true;
}
public boolean hasDestroyed()
{
return hasDeleted;
}
public BlockData getBlock()
{
return block;

View File

@ -8,6 +8,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.world.block.BlockDataRegistry;
import ru.windcorp.progressia.common.world.entity.EntityData;
import ru.windcorp.progressia.server.world.TickContext;
import ru.windcorp.progressia.server.world.entity.EntityLogic;
@ -49,12 +50,13 @@ public class TestEntityLogicFallingBlock extends EntityLogic {
{
return;
}
//LogManager.getLogger().info("NotNull "+entity.toString() + " " + context.toString());
super.tick(entity, context);
//friction
Vec3 vel = entity.getVelocity();
float friction = .8f;
float friction = 0f;
vel = new Vec3(vel.x*friction,vel.y*friction,vel.z);
entity.setVelocity(vel);
@ -66,6 +68,13 @@ public class TestEntityLogicFallingBlock extends EntityLogic {
return;
}
if (!fallBlock.hasDestroyed())
{
//LogManager.getLogger().info(fallBlock.getStartPos());
context.getAccessor().setBlock(fallBlock.getBlockInWorld(null), BlockDataRegistry.getInstance().get("Test:Air"));
fallBlock.setDestroyed();
}
Vec3i occupiedBlock = fallBlock.getBlockInWorld(null);
Vec3i underBlock = occupiedBlock.sub_(0, 0, 1);
@ -81,8 +90,8 @@ public class TestEntityLogicFallingBlock extends EntityLogic {
LogManager.getLogger().info("Deleting FallingBlock at " + String.valueOf(occupiedBlock.x));
//ClientState.getInstance().getWorld().getData().setBlock(occupiedBlock, fallBlock.getBlock(),true);
context.getAccessor().setBlock(occupiedBlock, fallBlock.getBlock());
//fallBlock.setInvisible(); //Until I know how to properly delete it.
context.getWorldData().removeEntity(entity.getEntityId());
fallBlock.setInvisible(); //Until I know how to properly delete it.
//context.getWorldData().removeEntity(entity.getEntityId());
}
}
}

View File

@ -82,7 +82,6 @@ public class TestWorldGenerator extends AbstractWorldGenerator<Boolean> {
chunk.setBlock(blockInChunk, previous, false);
Vec3i chunkWorldPos = chunk.getPosition().mul_(16).add_(blockInChunk);
LogManager.getLogger().info(String.valueOf(chunkWorldPos.x)+" "+String.valueOf(chunkWorldPos.y)+" "+String.valueOf(chunkWorldPos.z));
world.setBlock(chunkWorldPos, BlockDataRegistry.getInstance().get("Test:Glass"), false);
}
}
});