Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Deprecate the concept of bundled block data #2447

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
public boolean isLiquid() {
return block.liquid();
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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;
}

}
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
Loading