mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-01 23:47:50 +00:00
feat: provide default MinestomBlockEntity implementation
Introduce the `MinestomBlockEntity` class to represent block entities and hook into the block system. Update `DefaultBlockEntityFactory` to create `MinestomBlockEntity` instances and adjust `TerraMinestomWorldBuilder` initialization for factory injection. These changes improve extensibility and block entity management.
This commit is contained in:
parent
b12fe77f32
commit
c08e973e3e
@ -8,8 +8,8 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a factory interface for creating instances of BlockEntity
|
* Represents a factory interface for creating instances of BlockEntity
|
||||||
* at a specified BlockVec position. This is not implemented directly because
|
* at a specified BlockVec position. For more fine-grained control, users
|
||||||
* Minestom does not define a way to build block entities out of the box.
|
* may supply their own version of this interface.
|
||||||
*/
|
*/
|
||||||
public interface BlockEntityFactory {
|
public interface BlockEntityFactory {
|
||||||
@Nullable BlockEntity createBlockEntity(BlockVec position);
|
@Nullable BlockEntity createBlockEntity(BlockVec position);
|
||||||
|
@ -22,13 +22,14 @@ public class TerraMinestomWorldBuilder {
|
|||||||
private ConfigPack pack;
|
private ConfigPack pack;
|
||||||
private long seed = new Random().nextLong();
|
private long seed = new Random().nextLong();
|
||||||
private EntityFactory entityFactory = new DefaultEntityFactory();
|
private EntityFactory entityFactory = new DefaultEntityFactory();
|
||||||
private BlockEntityFactory blockEntityFactory = new DefaultBlockEntityFactory();
|
private BlockEntityFactory blockEntityFactory;
|
||||||
private BiomeFactory biomeFactory = new MinestomUserDefinedBiomeFactory();
|
private BiomeFactory biomeFactory = new MinestomUserDefinedBiomeFactory();
|
||||||
private boolean doFineGrainedBiomes = true;
|
private boolean doFineGrainedBiomes = true;
|
||||||
|
|
||||||
public TerraMinestomWorldBuilder(TerraMinestomPlatform platform, Instance instance) {
|
public TerraMinestomWorldBuilder(TerraMinestomPlatform platform, Instance instance) {
|
||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
|
this.blockEntityFactory = new DefaultBlockEntityFactory(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TerraMinestomWorldBuilder pack(ConfigPack pack) {
|
public TerraMinestomWorldBuilder pack(ConfigPack pack) {
|
||||||
|
@ -4,11 +4,18 @@ import com.dfsek.terra.api.block.entity.BlockEntity;
|
|||||||
import com.dfsek.terra.minestom.api.BlockEntityFactory;
|
import com.dfsek.terra.minestom.api.BlockEntityFactory;
|
||||||
|
|
||||||
import net.minestom.server.coordinate.BlockVec;
|
import net.minestom.server.coordinate.BlockVec;
|
||||||
|
import net.minestom.server.instance.Instance;
|
||||||
|
|
||||||
|
|
||||||
public class DefaultBlockEntityFactory implements BlockEntityFactory {
|
public class DefaultBlockEntityFactory implements BlockEntityFactory {
|
||||||
|
private final Instance instance;
|
||||||
|
|
||||||
|
public DefaultBlockEntityFactory(Instance instance) {
|
||||||
|
this.instance = instance;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockEntity createBlockEntity(BlockVec position) {
|
public BlockEntity createBlockEntity(BlockVec position) {
|
||||||
return null;
|
return new MinestomBlockEntity(instance, position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.dfsek.terra.minestom.block;
|
||||||
|
|
||||||
|
import com.dfsek.seismic.type.vector.Vector3;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.block.state.BlockState;
|
||||||
|
|
||||||
|
import net.minestom.server.coordinate.BlockVec;
|
||||||
|
import net.minestom.server.instance.Instance;
|
||||||
|
import net.minestom.server.instance.block.Block;
|
||||||
|
|
||||||
|
|
||||||
|
public class MinestomBlockEntity implements BlockEntity {
|
||||||
|
private final Instance instance;
|
||||||
|
private final BlockVec position;
|
||||||
|
private final Vector3 positionVec;
|
||||||
|
|
||||||
|
public MinestomBlockEntity(Instance instance, BlockVec position) {
|
||||||
|
this.instance = instance;
|
||||||
|
this.position = position;
|
||||||
|
this.positionVec = Vector3.of(position.blockX(), position.blockY(), position.blockZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean update(boolean applyPhysics) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vector3 getPosition() {
|
||||||
|
return positionVec;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getX() {
|
||||||
|
return position.blockX();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getY() {
|
||||||
|
return position.blockY();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getZ() {
|
||||||
|
return position.blockZ();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlockState() {
|
||||||
|
return new MinestomBlockState(instance.getBlock(position));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Block getHandle() {
|
||||||
|
return instance.getBlock(position);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user