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

Deprecate the concept of bundled block data #2447

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
@@ -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,145 @@
/*
* 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.EntityBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.VoxelShape;

public class PaperweightBlockMaterial implements BlockMaterial {

private static final AABB FULL_CUBE = AABB.unitCubeFromLowerCorner(Vec3.ZERO);

private final BlockState block;

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

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

@Override
public boolean isFullCube() {
VoxelShape vs = block.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
return !vs.isEmpty() && vs.bounds().equals(FULL_CUBE);
me4502 marked this conversation as resolved.
Show resolved Hide resolved
}

@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,145 @@
/*
* 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.EntityBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.VoxelShape;

public class PaperweightBlockMaterial implements BlockMaterial {

private static final AABB FULL_CUBE = AABB.unitCubeFromLowerCorner(Vec3.ZERO);

private final BlockState block;

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

@Override
public boolean 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() {
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
Loading