Skip to content

Commit

Permalink
Deprecate the concept of bundled block data (#2447)
Browse files Browse the repository at this point in the history
* wip

* do all platforms but bukkit & cli

* use the paperweight adapters for material information on bukkit

* Move bundled block data load to CLI

* Drop this part, let it load when needed

* Stray warning suppression

* Swap to using an MC utility function for full block detection
  • Loading branch information
me4502 authored Jan 9, 2025
1 parent f608c01 commit f778687
Show file tree
Hide file tree
Showing 27 changed files with 1,108 additions and 56 deletions.
11 changes: 10 additions & 1 deletion verification/src/changes/accepted-fabric-public-api-changes.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
{
}
"Removal of constructor in non-API class": [
{
"type": "com.sk89q.worldedit.fabric.FabricBlockMaterial",
"member": "Constructor com.sk89q.worldedit.fabric.FabricBlockMaterial(net.minecraft.class_2680,com.sk89q.worldedit.world.registry.BlockMaterial)",
"changes": [
"CONSTRUCTOR_REMOVED"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
{
}
"Removal of constructor in non-API class": [
{
"type": "com.sk89q.worldedit.neoforge.NeoForgeBlockMaterial",
"member": "Constructor com.sk89q.worldedit.neoforge.NeoForgeBlockMaterial(net.minecraft.world.level.block.state.BlockState,com.sk89q.worldedit.world.registry.BlockMaterial)",
"changes": [
"CONSTRUCTOR_REMOVED"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
Expand Down Expand Up @@ -578,6 +579,12 @@ public Component getRichItemName(BaseItemStack itemStack) {
return TranslatableComponent.of(CraftItemStack.asNMSCopy(BukkitAdapter.adapt(itemStack)).getDescriptionId());
}

@Override
public BlockMaterial getBlockMaterial(BlockType blockType) {
net.minecraft.world.level.block.state.BlockState mcBlockState = getBlockFromType(blockType).defaultBlockState();
return new PaperweightBlockMaterial(mcBlockState);
}

@SuppressWarnings({ "unchecked", "rawtypes" })
private static final LoadingCache<net.minecraft.world.level.block.state.properties.Property, Property<?>> PROPERTY_CACHE = CacheBuilder.newBuilder().build(new CacheLoader<net.minecraft.world.level.block.state.properties.Property, Property<?>>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.sk89q.worldedit.bukkit.adapter.impl.v1_20_R2;

import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.core.BlockPos;
import net.minecraft.world.Clearable;
import net.minecraft.world.level.EmptyBlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.PushReaction;

public class PaperweightBlockMaterial implements BlockMaterial {

private final BlockState block;

public PaperweightBlockMaterial(BlockState block) {
this.block = block;
}

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

@Override
public boolean isFullCube() {
return Block.isShapeFullBlock(block.getShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO));
}

@Override
public boolean isOpaque() {
return block.canOcclude();
}

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

@Override
@SuppressWarnings("deprecation")
public boolean isLiquid() {
return block.liquid();
}

@Override
@SuppressWarnings("deprecation")
public boolean isSolid() {
return block.isSolid();
}

@Override
public float getHardness() {
return block.getDestroySpeed(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
}

@Override
@SuppressWarnings("deprecation")
public float getResistance() {
return block.getBlock().getExplosionResistance();
}

@Override
public float getSlipperiness() {
return block.getBlock().getFriction();
}

@Override
@SuppressWarnings("deprecation")
public int getLightValue() {
return block.getLightEmission();
}

@Override
public boolean isFragileWhenPushed() {
return block.getPistonPushReaction() == PushReaction.DESTROY;
}

@Override
public boolean isUnpushable() {
return block.getPistonPushReaction() == PushReaction.BLOCK;
}

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

@Override
@SuppressWarnings("deprecation")
public boolean isMovementBlocker() {
return block.blocksMotion();
}

@Override
public boolean isBurnable() {
return block.ignitedByLava();
}

@Override
public boolean isToolRequired() {
return block.requiresCorrectToolForDrops();
}

@Override
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 @@ -69,6 +69,7 @@
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
Expand Down Expand Up @@ -577,6 +578,12 @@ public Component getRichItemName(BaseItemStack itemStack) {
return TranslatableComponent.of(CraftItemStack.asNMSCopy(BukkitAdapter.adapt(itemStack)).getDescriptionId());
}

@Override
public BlockMaterial getBlockMaterial(BlockType blockType) {
net.minecraft.world.level.block.state.BlockState mcBlockState = getBlockFromType(blockType).defaultBlockState();
return new PaperweightBlockMaterial(mcBlockState);
}

@SuppressWarnings({ "unchecked", "rawtypes" })
private static final LoadingCache<net.minecraft.world.level.block.state.properties.Property, Property<?>> PROPERTY_CACHE = CacheBuilder.newBuilder().build(new CacheLoader<net.minecraft.world.level.block.state.properties.Property, Property<?>>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.sk89q.worldedit.bukkit.adapter.impl.v1_20_R3;

import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.core.BlockPos;
import net.minecraft.world.Clearable;
import net.minecraft.world.level.EmptyBlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.PushReaction;

public class PaperweightBlockMaterial implements BlockMaterial {

private final BlockState block;

public PaperweightBlockMaterial(BlockState block) {
this.block = block;
}

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

@Override
public boolean isFullCube() {
return Block.isShapeFullBlock(block.getShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO));
}

@Override
public boolean isOpaque() {
return block.canOcclude();
}

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

@Override
@SuppressWarnings("deprecation")
public boolean isLiquid() {
return block.liquid();
}

@Override
@SuppressWarnings("deprecation")
public boolean isSolid() {
return block.isSolid();
}

@Override
public float getHardness() {
return block.getDestroySpeed(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
}

@Override
@SuppressWarnings("deprecation")
public float getResistance() {
return block.getBlock().getExplosionResistance();
}

@Override
public float getSlipperiness() {
return block.getBlock().getFriction();
}

@Override
@SuppressWarnings("deprecation")
public int getLightValue() {
return block.getLightEmission();
}

@Override
public boolean isFragileWhenPushed() {
return block.getPistonPushReaction() == PushReaction.DESTROY;
}

@Override
public boolean isUnpushable() {
return block.getPistonPushReaction() == PushReaction.BLOCK;
}

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

@Override
@SuppressWarnings("deprecation")
public boolean isMovementBlocker() {
return block.blocksMotion();
}

@Override
public boolean isBurnable() {
return block.ignitedByLava();
}

@Override
public boolean isToolRequired() {
return block.requiresCorrectToolForDrops();
}

@Override
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 @@ -69,6 +69,7 @@
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
Expand Down Expand Up @@ -579,6 +580,12 @@ public Component getRichItemName(BaseItemStack itemStack) {
return TranslatableComponent.of(CraftItemStack.asNMSCopy(BukkitAdapter.adapt(itemStack)).getDescriptionId());
}

@Override
public BlockMaterial getBlockMaterial(BlockType blockType) {
net.minecraft.world.level.block.state.BlockState mcBlockState = getBlockFromType(blockType).defaultBlockState();
return new PaperweightBlockMaterial(mcBlockState);
}

@SuppressWarnings({ "unchecked", "rawtypes" })
private static final LoadingCache<net.minecraft.world.level.block.state.properties.Property, Property<?>> PROPERTY_CACHE = CacheBuilder.newBuilder().build(new CacheLoader<net.minecraft.world.level.block.state.properties.Property, Property<?>>() {
@Override
Expand Down
Loading

0 comments on commit f778687

Please sign in to comment.