Added custom block drag support

This commit is contained in:
TheMode 2021-05-29 00:58:40 +02:00
parent ba892ced05
commit e62a837bf0
2 changed files with 6 additions and 15 deletions

View File

@ -568,8 +568,10 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer,
float drag;
if (onGround) {
final BlockPosition blockPosition = position.toBlockPosition();
if (false) {
// TODO: Handle drag for CustomBlock
final Block block = finalChunk.getBlock(blockPosition);
final BlockHandler handler = block.getHandler();
if (handler != null) {
drag = handler.getDrag(instance, block, blockPosition);
} else {
// Default ground drag
drag = 0.5f;

View File

@ -10,7 +10,7 @@ import net.minestom.server.entity.pathfinding.PFColumnarSpace;
import net.minestom.server.event.player.PlayerChunkLoadEvent;
import net.minestom.server.event.player.PlayerChunkUnloadEvent;
import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.block.BlockManager;
import net.minestom.server.instance.block.BlockGetter;
import net.minestom.server.network.packet.server.play.ChunkDataPacket;
import net.minestom.server.network.packet.server.play.UpdateLightPacket;
import net.minestom.server.network.player.PlayerConnection;
@ -47,9 +47,8 @@ import java.util.concurrent.ConcurrentHashMap;
* You generally want to avoid storing references of this object as this could lead to a huge memory leak,
* you should store the chunk coordinates instead.
*/
public abstract class Chunk implements Viewable, Tickable, DataContainer {
public abstract class Chunk implements BlockGetter, Viewable, Tickable, DataContainer {
protected static final BlockManager BLOCK_MANAGER = MinecraftServer.getBlockManager();
protected static final BiomeManager BIOME_MANAGER = MinecraftServer.getBiomeManager();
public static final int CHUNK_SIZE_X = 16;
@ -124,16 +123,6 @@ public abstract class Chunk implements Viewable, Tickable, DataContainer {
@Override
public abstract void tick(long time);
/**
* Gets the block at a position.
*
* @param x the block X
* @param y the block Y
* @param z the block Z
* @return the block at the position
*/
public abstract @NotNull Block getBlock(int x, int y, int z);
/**
* Gets all the block entities in this chunk.
*