Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Dec 10, 2024
1 parent e68086b commit 34a4e16
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,52 @@
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
public boolean isOpaque() {
return block.canOcclude();
}

@Override
public boolean isPowerSource() {
return block.isSignalSource();
}

@Override
@SuppressWarnings("deprecation")
public boolean isLiquid() {
Expand All @@ -62,6 +78,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;
Expand All @@ -72,6 +108,11 @@ public boolean isUnpushable() {
return block.getPistonPushReaction() == PushReaction.BLOCK;
}

@Override
public boolean isTicksRandomly() {
return block.isRandomlyTicking();
}

@Override
@SuppressWarnings("deprecation")
public boolean isMovementBlocker() {
Expand All @@ -93,4 +134,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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<net.minecraft.world.level.block.state.BlockState, FabricBlockMaterial> materialMap = new HashMap<>();

Expand All @@ -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
);
}

Expand Down

0 comments on commit 34a4e16

Please sign in to comment.