diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBlockMaterial.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBlockMaterial.java index 05b670783a..b64921ccd9 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBlockMaterial.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBlockMaterial.java @@ -20,29 +20,40 @@ package com.sk89q.worldedit.fabric; import com.sk89q.worldedit.world.registry.BlockMaterial; -import com.sk89q.worldedit.world.registry.PassthroughBlockMaterial; +import net.minecraft.core.BlockPos; +import net.minecraft.world.Clearable; +import net.minecraft.world.level.EmptyBlockGetter; +import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.PushReaction; - -import javax.annotation.Nullable; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.VoxelShape; /** * Fabric block material that pulls as much info as possible from the Minecraft * Material, and passes the rest to another implementation, typically the * bundled block info. */ -public class FabricBlockMaterial extends PassthroughBlockMaterial { +public class FabricBlockMaterial implements BlockMaterial { + + private static final AABB FULL_CUBE = AABB.unitCubeFromLowerCorner(Vec3.ZERO); private final BlockState block; - public FabricBlockMaterial(BlockState block, @Nullable BlockMaterial secondary) { - super(secondary); + public FabricBlockMaterial(BlockState block) { this.block = block; } @Override public boolean isAir() { - return block.isAir() || super.isAir(); + return block.isAir(); + } + + @Override + public boolean isFullCube() { + VoxelShape vs = block.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO); + return !vs.isEmpty() && vs.bounds().equals(FULL_CUBE); } @Override @@ -50,6 +61,11 @@ public boolean isOpaque() { return block.canOcclude(); } + @Override + public boolean isPowerSource() { + return block.isSignalSource(); + } + @Override public boolean isLiquid() { return block.liquid(); @@ -60,6 +76,26 @@ public boolean isSolid() { return block.isSolid(); } + @Override + public float getHardness() { + return block.getDestroySpeed(EmptyBlockGetter.INSTANCE, BlockPos.ZERO); + } + + @Override + public float getResistance() { + return block.getBlock().getExplosionResistance(); + } + + @Override + public float getSlipperiness() { + return block.getBlock().getFriction(); + } + + @Override + public int getLightValue() { + return block.getLightEmission(); + } + @Override public boolean isFragileWhenPushed() { return block.getPistonPushReaction() == PushReaction.DESTROY; @@ -70,6 +106,11 @@ public boolean isUnpushable() { return block.getPistonPushReaction() == PushReaction.BLOCK; } + @Override + public boolean isTicksRandomly() { + return block.isRandomlyTicking(); + } + @Override public boolean isMovementBlocker() { return block.blocksMotion(); @@ -90,4 +131,15 @@ public boolean isReplacedDuringPlacement() { return block.canBeReplaced(); } + @Override + public boolean isTranslucent() { + return !block.canOcclude(); + } + + @Override + public boolean hasContainer() { + return block.getBlock() instanceof EntityBlock entityBlock && + entityBlock.newBlockEntity(BlockPos.ZERO, block) instanceof Clearable; + } + } diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBlockRegistry.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBlockRegistry.java index 3652a04aba..48ef164a80 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBlockRegistry.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBlockRegistry.java @@ -26,7 +26,7 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.registry.BlockMaterial; -import com.sk89q.worldedit.world.registry.BundledBlockRegistry; +import com.sk89q.worldedit.world.registry.BlockRegistry; import net.minecraft.world.level.block.Block; import java.util.Collection; @@ -35,7 +35,7 @@ import java.util.OptionalInt; import java.util.TreeMap; -public class FabricBlockRegistry extends BundledBlockRegistry { +public class FabricBlockRegistry implements BlockRegistry { private final Map materialMap = new HashMap<>(); @@ -49,7 +49,7 @@ public BlockMaterial getMaterial(BlockType blockType) { Block block = FabricAdapter.adapt(blockType); return materialMap.computeIfAbsent( block.defaultBlockState(), - m -> new FabricBlockMaterial(m, super.getMaterial(blockType)) + FabricBlockMaterial::new ); }