Better 3d falling
-Sand now can fall from and to the direction of gravity -Registers every FallingBlock block to a different value. It doesnt quite work though -Removed unused code
This commit is contained in:
parent
51752f95f9
commit
71250104ea
@ -94,8 +94,7 @@ public class Server {
|
|||||||
world.addListener(new WorldDataListener() {
|
world.addListener(new WorldDataListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onChunkLoaded(DefaultWorldData world, DefaultChunkData chunk) {
|
public void onChunkLoaded(DefaultWorldData world, DefaultChunkData chunk) {
|
||||||
//PlanetGenerator.this.planet;
|
|
||||||
//LogManager.getLogger().info("Loaded chunk");
|
|
||||||
GravityModelRegistry.getInstance().get("Test:PlanetGravityModel");
|
GravityModelRegistry.getInstance().get("Test:PlanetGravityModel");
|
||||||
chunk.addListener(new ChunkDataListener() { // Falling Block
|
chunk.addListener(new ChunkDataListener() { // Falling Block
|
||||||
// spawning logic
|
// spawning logic
|
||||||
@ -105,35 +104,34 @@ public class Server {
|
|||||||
Vec3i chunkWorldPos = new Vec3i(0,0,0);
|
Vec3i chunkWorldPos = new Vec3i(0,0,0);
|
||||||
Coordinates.getInWorld(chunk_2.getPosition(), blockInChunk, chunkWorldPos);
|
Coordinates.getInWorld(chunk_2.getPosition(), blockInChunk, chunkWorldPos);
|
||||||
|
|
||||||
/*List<Vec3i> underBlocks = getGoodCardinals(fallBlock.getUpVector().negate_());
|
|
||||||
|
|
||||||
boolean notSupported = false;
|
|
||||||
for (Vec3i v3 : underBlocks)
|
|
||||||
|
boolean isUnsupported = false;
|
||||||
|
List<Vec3i> 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 (chunk_2.getWorld().isLocationLoaded(chunkWorldPos.sub_(card)) &&
|
||||||
if (context.getBlock(inWorld).getId()=="Test:Air") {
|
chunk_2.getWorld().getBlock(chunkWorldPos.sub_(card)).getId() == "Test:Air")
|
||||||
notSupported=true;
|
{
|
||||||
break;
|
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())) {
|
if (!TestEntityLogicFallingBlock.FallingBlocks.contains(current.getId())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//LogManager.getLogger().info("Cont");
|
if (isUnsupported) {
|
||||||
if (chunk_2.getWorld().getBlock(chunkWorldPos.add_(0, 0, -1)).getId() == "Test:Air") {
|
|
||||||
LogManager.getLogger().info("Inserting FallingBlock {},{},{}",
|
|
||||||
chunkWorldPos.x,chunkWorldPos.y,chunkWorldPos.z);
|
|
||||||
|
|
||||||
TestEntityDataFallingBlock fallingBlock = new TestEntityDataFallingBlock(current);
|
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);
|
Vec3i worldPos = chunk_2.getPosition().mul_(16).add_(blockInChunk);
|
||||||
Vec3 floatWorldPos = new Vec3(worldPos.x, worldPos.y, worldPos.z);
|
Vec3 floatWorldPos = new Vec3(worldPos.x, worldPos.y, worldPos.z);
|
||||||
@ -142,15 +140,7 @@ public class Server {
|
|||||||
fallingBlock.setEntityId(("Test:FallingBlock" + floatWorldPos.toString()
|
fallingBlock.setEntityId(("Test:FallingBlock" + floatWorldPos.toString()
|
||||||
+ String.valueOf(new Random().nextFloat())).hashCode());
|
+ String.valueOf(new Random().nextFloat())).hashCode());
|
||||||
|
|
||||||
chunk.getWorld().addEntity(fallingBlock);
|
invokeLater(() -> 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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -257,9 +257,24 @@ public class TestContent {
|
|||||||
register(new TestEntityRenderStatie("Test:Statie"));
|
register(new TestEntityRenderStatie("Test:Statie"));
|
||||||
register(new TestEntityLogicStatie("Test:Statie"));
|
register(new TestEntityLogicStatie("Test:Statie"));
|
||||||
|
|
||||||
|
registerSands();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void registerSands()
|
||||||
|
{
|
||||||
|
TestEntityLogicFallingBlock.addFallables();
|
||||||
|
|
||||||
register("Test:FallingBlock", TestEntityDataFallingBlock::new);
|
register("Test:FallingBlock", TestEntityDataFallingBlock::new);
|
||||||
register(new TestEntityLogicFallingBlock("Test:FallingBlock"));
|
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() {
|
private static void regsiterControls() {
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package ru.windcorp.progressia.test;
|
package ru.windcorp.progressia.test;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
|
|
||||||
import ru.windcorp.progressia.common.collision.AABB;
|
import ru.windcorp.progressia.common.collision.AABB;
|
||||||
import ru.windcorp.progressia.common.world.block.BlockData;
|
import ru.windcorp.progressia.common.world.block.BlockData;
|
||||||
import ru.windcorp.progressia.common.world.entity.EntityData;
|
import ru.windcorp.progressia.common.world.entity.EntityData;
|
||||||
@ -18,19 +16,23 @@ public class TestEntityDataFallingBlock extends EntityData {
|
|||||||
private boolean isDone = false;
|
private boolean isDone = false;
|
||||||
private boolean hasDeleted = false;
|
private boolean hasDeleted = false;
|
||||||
|
|
||||||
public TestEntityDataFallingBlock() {
|
public TestEntityDataFallingBlock()
|
||||||
this("Test:FallingBlock", new BlockData("Test:LogTop"));
|
{
|
||||||
|
this("Test:FallingBlock");
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestEntityDataFallingBlock(BlockData data) {
|
public TestEntityDataFallingBlock(String id, BlockData inBlock) {
|
||||||
this("Test:FallingBlock", data);
|
super(id);
|
||||||
|
block = inBlock;
|
||||||
|
setCollisionModel(new AABB(0, 0, 0, 1, 1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TestEntityDataFallingBlock(String id, BlockData blockInput) {
|
public TestEntityDataFallingBlock(String string) {
|
||||||
super(id);
|
this(string, new BlockData((String) TestEntityLogicFallingBlock.FallingBlocks.toArray()[0]));
|
||||||
setCollisionModel(new AABB(0, 0, 0, 1, 1, 1));
|
}
|
||||||
block = blockInput;
|
|
||||||
LogManager.getLogger().info(blockInput.getId());
|
public TestEntityDataFallingBlock(BlockData current) {
|
||||||
|
this("Test:FallingBlock"+current.getId().substring(5), current);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDestroyed() {
|
public void setDestroyed() {
|
||||||
@ -40,15 +42,16 @@ public class TestEntityDataFallingBlock extends EntityData {
|
|||||||
public boolean hasDestroyed() {
|
public boolean hasDestroyed() {
|
||||||
return hasDeleted;
|
return hasDeleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockData getBlock() {
|
public BlockData getBlock()
|
||||||
|
{
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInvisible() {
|
public void setInvisible() {
|
||||||
// block = new BlockData("Test:Log");
|
// block = new BlockData("Test:Log");
|
||||||
isDone = true;
|
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() {
|
public boolean isDone() {
|
||||||
|
@ -27,7 +27,7 @@ public class TestEntityLogicFallingBlock extends EntityLogic {
|
|||||||
|
|
||||||
public static Set<String> FallingBlocks = new HashSet<String>();
|
public static Set<String> FallingBlocks = new HashSet<String>();
|
||||||
|
|
||||||
public void addFallables() {
|
public static void addFallables() {
|
||||||
FallingBlocks.add("Test:Sand");
|
FallingBlocks.add("Test:Sand");
|
||||||
for (Rock rock : TestContent.ROCKS.getRocks())
|
for (Rock rock : TestContent.ROCKS.getRocks())
|
||||||
{
|
{
|
||||||
@ -38,7 +38,6 @@ public class TestEntityLogicFallingBlock extends EntityLogic {
|
|||||||
|
|
||||||
public TestEntityLogicFallingBlock(String id) {
|
public TestEntityLogicFallingBlock(String id) {
|
||||||
super(id);
|
super(id);
|
||||||
addFallables();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private Vec3i trueMod(Vec3i input, Vec3i modulus) // Move this to a class in
|
/*private Vec3i trueMod(Vec3i input, Vec3i modulus) // Move this to a class in
|
||||||
@ -55,7 +54,7 @@ public class TestEntityLogicFallingBlock extends EntityLogic {
|
|||||||
return temp;
|
return temp;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
public Vec3i getBestCardinal(Vec3 dir)
|
public static Vec3i getBestCardinal(Vec3 dir)
|
||||||
{
|
{
|
||||||
Vec3 a = dir.abs_();
|
Vec3 a = dir.abs_();
|
||||||
if (a.x>a.y && a.x>a.z)
|
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);
|
return new Vec3i(0,0,dir.z>0 ? 1 : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Vec3i> getGoodCardinals(Vec3 dir)
|
public static List<Vec3i> getGoodCardinals(Vec3 dir)
|
||||||
{
|
{
|
||||||
return getGoodCardinals(dir,.05f);
|
return getGoodCardinals(dir,.05f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Vec3i> getGoodCardinals(Vec3 dir, float d) {
|
public static List<Vec3i> getGoodCardinals(Vec3 dir, float d) {
|
||||||
List<Vec3i> list = new ArrayList<>();
|
List<Vec3i> list = new ArrayList<>();
|
||||||
Vec3 a = dir.abs_();
|
Vec3 a = dir.abs_();
|
||||||
if (a.x>d)
|
if (a.x>d)
|
||||||
@ -142,14 +141,13 @@ public class TestEntityLogicFallingBlock extends EntityLogic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vec3i occupiedBlock = fallBlock.getBlockInWorld(null);
|
Vec3i occupiedBlock = fallBlock.getBlockInWorld(null);
|
||||||
Vec3i underBlock = occupiedBlock.sub_(getBestCardinal(fallBlock.getUpVector()));
|
|
||||||
List<Vec3i> underBlocks = getGoodCardinals(fallBlock.getUpVector());
|
List<Vec3i> underBlocks = getGoodCardinals(fallBlock.getUpVector());
|
||||||
|
|
||||||
boolean notSupported = false;
|
boolean notSupported = false;
|
||||||
for (Vec3i v3 : underBlocks)
|
for (Vec3i v3 : underBlocks)
|
||||||
{
|
{
|
||||||
Vec3i inWorld = occupiedBlock.sub_(v3);
|
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;
|
notSupported=true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -166,10 +164,7 @@ public class TestEntityLogicFallingBlock extends EntityLogic {
|
|||||||
String.valueOf(occupiedBlock.z));*/
|
String.valueOf(occupiedBlock.z));*/
|
||||||
//LogManager.getLogger().info("Block is of type " +
|
//LogManager.getLogger().info("Block is of type " +
|
||||||
//context.getWorldData().getChunk(chunkCoords).getBlock(inChunkCoords).getId());
|
//context.getWorldData().getChunk(chunkCoords).getBlock(inChunkCoords).getId());
|
||||||
|
if ( !notSupported && context.isLocationLoaded(occupiedBlock)) {
|
||||||
if (context.getBlock(underBlock) != null
|
|
||||||
// && context.getBlock(underBlock).getId() != "Test:Air") {
|
|
||||||
&& !notSupported) {
|
|
||||||
LogManager.getLogger().info("Deleting FallingBlock at " + String.valueOf(occupiedBlock.x) + " " + String.valueOf(occupiedBlock.y) + " " + String.valueOf(occupiedBlock.z));
|
LogManager.getLogger().info("Deleting FallingBlock at " + String.valueOf(occupiedBlock.x) + " " + String.valueOf(occupiedBlock.y) + " " + String.valueOf(occupiedBlock.z));
|
||||||
context.setBlock(occupiedBlock, fallBlock2.getBlock());
|
context.setBlock(occupiedBlock, fallBlock2.getBlock());
|
||||||
fallBlock.setInvisible();
|
fallBlock.setInvisible();
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package ru.windcorp.progressia.test;
|
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.Renderable;
|
||||||
import ru.windcorp.progressia.client.graphics.model.ShapeRenderHelper;
|
import ru.windcorp.progressia.client.graphics.model.ShapeRenderHelper;
|
||||||
import ru.windcorp.progressia.client.graphics.model.Shapes;
|
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 {
|
public class TestEntityRenderFallingBlock extends EntityRender {
|
||||||
private Renderable cube;
|
private Renderable cube;
|
||||||
|
|
||||||
public TestEntityRenderFallingBlock(String id) {
|
public TestEntityRenderFallingBlock(String id, String blockName) {
|
||||||
super(id);
|
super(id);
|
||||||
String dflt = TestEntityLogicFallingBlock.FallingBlocks.toArray()[0].toString().substring(5);
|
cube = new Shapes.PppBuilder(WorldRenderProgram.getDefault(), BlockRenderRegistry.getBlockTexture(blockName ) )// TODO idk actual ggood this
|
||||||
cube = new Shapes.PppBuilder(WorldRenderProgram.getDefault(), BlockRenderRegistry.getBlockTexture(dflt ) )// TODO idk actual ggood this
|
|
||||||
.create();
|
.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,18 +34,9 @@ public class TestEntityRenderFallingBlock extends EntityRender {
|
|||||||
return new EntityRenderable(entity) {
|
return new EntityRenderable(entity) {
|
||||||
@Override
|
@Override
|
||||||
public void doRender(ShapeRenderHelper renderer) {
|
public void doRender(ShapeRenderHelper renderer) {
|
||||||
// LogManager.getLogger().info("Rendering FallingBlock");
|
|
||||||
if (((TestEntityDataFallingBlock) entity).isDone()) {
|
if (((TestEntityDataFallingBlock) entity).isDone()) {
|
||||||
return;
|
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);
|
cube.render(renderer);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user