diff --git a/verification/src/changes/accepted-fabric-public-api-changes.json b/verification/src/changes/accepted-fabric-public-api-changes.json index 7a73a41bfd..b0ab7f4ad6 100644 --- a/verification/src/changes/accepted-fabric-public-api-changes.json +++ b/verification/src/changes/accepted-fabric-public-api-changes.json @@ -1,2 +1,11 @@ { -} \ No newline at end of file + "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" + ] + } + ] +} diff --git a/verification/src/changes/accepted-neoforge-public-api-changes.json b/verification/src/changes/accepted-neoforge-public-api-changes.json index 7a73a41bfd..3a15b5320f 100644 --- a/verification/src/changes/accepted-neoforge-public-api-changes.json +++ b/verification/src/changes/accepted-neoforge-public-api-changes.json @@ -1,2 +1,11 @@ { -} \ No newline at end of file + "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" + ] + } + ] +} diff --git a/worldedit-bukkit/adapters/adapter-1.20.2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R2/PaperweightAdapter.java b/worldedit-bukkit/adapters/adapter-1.20.2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R2/PaperweightAdapter.java index 19b96c9691..a79cb84f52 100644 --- a/worldedit-bukkit/adapters/adapter-1.20.2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R2/PaperweightAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1.20.2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R2/PaperweightAdapter.java @@ -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; @@ -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> PROPERTY_CACHE = CacheBuilder.newBuilder().build(new CacheLoader>() { @Override diff --git a/worldedit-bukkit/adapters/adapter-1.20.2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R2/PaperweightBlockMaterial.java b/worldedit-bukkit/adapters/adapter-1.20.2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R2/PaperweightBlockMaterial.java new file mode 100644 index 0000000000..b1e66944bc --- /dev/null +++ b/worldedit-bukkit/adapters/adapter-1.20.2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R2/PaperweightBlockMaterial.java @@ -0,0 +1,140 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +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; + } + +} diff --git a/worldedit-bukkit/adapters/adapter-1.20.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R3/PaperweightAdapter.java b/worldedit-bukkit/adapters/adapter-1.20.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R3/PaperweightAdapter.java index d7abcbaa38..f5d5ace8c0 100644 --- a/worldedit-bukkit/adapters/adapter-1.20.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R3/PaperweightAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1.20.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R3/PaperweightAdapter.java @@ -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; @@ -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> PROPERTY_CACHE = CacheBuilder.newBuilder().build(new CacheLoader>() { @Override diff --git a/worldedit-bukkit/adapters/adapter-1.20.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R3/PaperweightBlockMaterial.java b/worldedit-bukkit/adapters/adapter-1.20.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R3/PaperweightBlockMaterial.java new file mode 100644 index 0000000000..c6c7a9f95f --- /dev/null +++ b/worldedit-bukkit/adapters/adapter-1.20.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R3/PaperweightBlockMaterial.java @@ -0,0 +1,140 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +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; + } + +} diff --git a/worldedit-bukkit/adapters/adapter-1.20.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R4/PaperweightAdapter.java b/worldedit-bukkit/adapters/adapter-1.20.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R4/PaperweightAdapter.java index ca3ec0d9b2..b3c82ddc76 100644 --- a/worldedit-bukkit/adapters/adapter-1.20.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R4/PaperweightAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1.20.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R4/PaperweightAdapter.java @@ -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; @@ -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> PROPERTY_CACHE = CacheBuilder.newBuilder().build(new CacheLoader>() { @Override diff --git a/worldedit-bukkit/adapters/adapter-1.20.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R4/PaperweightBlockMaterial.java b/worldedit-bukkit/adapters/adapter-1.20.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R4/PaperweightBlockMaterial.java new file mode 100644 index 0000000000..e0b97ce1db --- /dev/null +++ b/worldedit-bukkit/adapters/adapter-1.20.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R4/PaperweightBlockMaterial.java @@ -0,0 +1,140 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +package com.sk89q.worldedit.bukkit.adapter.impl.v1_20_R4; + +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; + } + +} diff --git a/worldedit-bukkit/adapters/adapter-1.21.3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_3/PaperweightAdapter.java b/worldedit-bukkit/adapters/adapter-1.21.3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_3/PaperweightAdapter.java index 0edeae839e..30adb5b05b 100644 --- a/worldedit-bukkit/adapters/adapter-1.21.3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_3/PaperweightAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1.21.3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_3/PaperweightAdapter.java @@ -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.SharedConstants; import net.minecraft.Util; import net.minecraft.core.BlockPos; @@ -557,6 +558,12 @@ public Component getRichItemName(BaseItemStack itemStack) { ); } + @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> PROPERTY_CACHE = CacheBuilder.newBuilder().build(new CacheLoader<>() { @Override diff --git a/worldedit-bukkit/adapters/adapter-1.21.3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_3/PaperweightBlockMaterial.java b/worldedit-bukkit/adapters/adapter-1.21.3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_3/PaperweightBlockMaterial.java new file mode 100644 index 0000000000..876898e325 --- /dev/null +++ b/worldedit-bukkit/adapters/adapter-1.21.3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_3/PaperweightBlockMaterial.java @@ -0,0 +1,140 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +package com.sk89q.worldedit.bukkit.adapter.impl.v1_21_3; + +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; + } + +} diff --git a/worldedit-bukkit/adapters/adapter-1.21.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_4/PaperweightAdapter.java b/worldedit-bukkit/adapters/adapter-1.21.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_4/PaperweightAdapter.java index 2cc50bd0d0..6d6d1cc79c 100644 --- a/worldedit-bukkit/adapters/adapter-1.21.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_4/PaperweightAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1.21.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_4/PaperweightAdapter.java @@ -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.SharedConstants; import net.minecraft.Util; import net.minecraft.core.BlockPos; @@ -557,6 +558,12 @@ public Component getRichItemName(BaseItemStack itemStack) { ); } + @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> PROPERTY_CACHE = CacheBuilder.newBuilder().build(new CacheLoader<>() { @Override diff --git a/worldedit-bukkit/adapters/adapter-1.21.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_4/PaperweightBlockMaterial.java b/worldedit-bukkit/adapters/adapter-1.21.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_4/PaperweightBlockMaterial.java new file mode 100644 index 0000000000..10c1f7d222 --- /dev/null +++ b/worldedit-bukkit/adapters/adapter-1.21.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_4/PaperweightBlockMaterial.java @@ -0,0 +1,140 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +package com.sk89q.worldedit.bukkit.adapter.impl.v1_21_4; + +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; + } + +} diff --git a/worldedit-bukkit/adapters/adapter-1.21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21/PaperweightAdapter.java b/worldedit-bukkit/adapters/adapter-1.21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21/PaperweightAdapter.java index 25cbc8d47b..189fbaeb47 100644 --- a/worldedit-bukkit/adapters/adapter-1.21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21/PaperweightAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1.21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21/PaperweightAdapter.java @@ -68,6 +68,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.SharedConstants; import net.minecraft.Util; import net.minecraft.core.BlockPos; @@ -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> PROPERTY_CACHE = CacheBuilder.newBuilder().build(new CacheLoader>() { @Override diff --git a/worldedit-bukkit/adapters/adapter-1.21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21/PaperweightBlockMaterial.java b/worldedit-bukkit/adapters/adapter-1.21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21/PaperweightBlockMaterial.java new file mode 100644 index 0000000000..367535b1f6 --- /dev/null +++ b/worldedit-bukkit/adapters/adapter-1.21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21/PaperweightBlockMaterial.java @@ -0,0 +1,140 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +package com.sk89q.worldedit.bukkit.adapter.impl.v1_21; + +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; + } + +} diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java index b6b7cece12..9fd52970f2 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java @@ -21,10 +21,11 @@ import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.formatting.text.TextComponent; 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 com.sk89q.worldedit.world.registry.PassthroughBlockMaterial; import org.bukkit.Material; @@ -33,7 +34,7 @@ import java.util.OptionalInt; import javax.annotation.Nullable; -public class BukkitBlockRegistry extends BundledBlockRegistry { +public class BukkitBlockRegistry implements BlockRegistry { private final Map materialMap = new HashMap<>(); @Override @@ -41,7 +42,7 @@ public Component getRichName(BlockType blockType) { if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { return WorldEditPlugin.getInstance().getBukkitImplAdapter().getRichBlockName(blockType); } - return super.getRichName(blockType); + return TextComponent.of(blockType.id()); } @Nullable @@ -51,7 +52,13 @@ public BlockMaterial getMaterial(BlockType blockType) { if (mat == null) { return null; } - return materialMap.computeIfAbsent(mat, material -> new BukkitBlockMaterial(BukkitBlockRegistry.super.getMaterial(blockType), material)); + return materialMap.computeIfAbsent(mat, material -> { + BlockMaterial platformMaterial = null; + if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { + platformMaterial = WorldEditPlugin.getInstance().getBukkitImplAdapter().getBlockMaterial(blockType); + } + return new BukkitBlockMaterial(platformMaterial, material); + }); } @Nullable @@ -60,7 +67,7 @@ public BlockMaterial getMaterial(BlockType blockType) { if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { return WorldEditPlugin.getInstance().getBukkitImplAdapter().getProperties(blockType); } - return super.getProperties(blockType); + return null; } @Override @@ -82,14 +89,7 @@ public BukkitBlockMaterial(@Nullable BlockMaterial material, Material bukkitMate @Override public boolean isAir() { - switch (material) { - case AIR: - case CAVE_AIR: - case VOID_AIR: - return true; - default: - return false; - } + return material.isAir(); } @Override @@ -105,7 +105,7 @@ public boolean isBurnable() { @SuppressWarnings("deprecation") @Override public boolean isTranslucent() { - return material.isTransparent(); + return super.isTranslucent() || material.isTransparent(); } } } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java index f6a42b8bc8..ee10cb7669 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java @@ -41,6 +41,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 org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.data.BlockData; @@ -149,6 +150,15 @@ default void tickWatchdog() { */ Component getRichItemName(BaseItemStack itemStack); + /** + * Gets the block material for the given block type. + * + * @param blockType the block type + * @return the material + */ + @Nullable + BlockMaterial getBlockMaterial(BlockType blockType); + /** * Get a map of {@code string -> property}. * diff --git a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIBlockRegistry.java b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIBlockRegistry.java index 7d9c0f9eb9..de69656dea 100644 --- a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIBlockRegistry.java +++ b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIBlockRegistry.java @@ -35,6 +35,7 @@ import java.util.Map; import javax.annotation.Nullable; +@SuppressWarnings("removal") public class CLIBlockRegistry extends BundledBlockRegistry { private Property createProperty(String type, String key, List values) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java index 6e82d8cdab..4261e56834 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -71,7 +71,6 @@ import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; -import com.sk89q.worldedit.world.registry.BundledBlockData; import com.sk89q.worldedit.world.registry.LegacyMapper; import org.apache.logging.log4j.Logger; @@ -404,7 +403,6 @@ private boolean checkFilename(String filename) { * Load the bundled mappings. */ public void loadMappings() { - BundledBlockData.getInstance(); // Load block registry LegacyMapper.getInstance(); // Load legacy mappings } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java index 807ee83507..8a1b4c1f17 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java @@ -47,6 +47,7 @@ * reading fails (which occurs when this class is first instantiated), then * the methods will return {@code null}s for all blocks.

*/ +@Deprecated(forRemoval = true) public final class BundledBlockData { private static final Logger LOGGER = LogManagerCompat.getLogger(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockRegistry.java index 6ac361c70e..1a7774dbae 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockRegistry.java @@ -36,6 +36,8 @@ * A block registry that uses {@link BundledBlockData} to serve information * about blocks. */ +@SuppressWarnings({ "deprecation", "removal" }) +@Deprecated(forRemoval = true) public class BundledBlockRegistry implements BlockRegistry { @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledRegistries.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledRegistries.java index bd81098c7d..b26e1a411c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledRegistries.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledRegistries.java @@ -66,6 +66,7 @@ static URL loadRegistry(String name) throws IOException { return url; } + @SuppressWarnings("removal") private final BundledBlockRegistry blockRegistry = new BundledBlockRegistry(); @SuppressWarnings("removal") private final BundledItemRegistry itemRegistry = new BundledItemRegistry(); 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 f24e195a0e..8c70c417d3 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,35 @@ 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.Block; +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; - /** * 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 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() { + return Block.isShapeFullBlock(block.getShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); } @Override @@ -50,6 +56,11 @@ public boolean isOpaque() { return block.canOcclude(); } + @Override + public boolean isPowerSource() { + return block.isSignalSource(); + } + @Override @SuppressWarnings("deprecation") public boolean isLiquid() { @@ -62,6 +73,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; @@ -72,6 +103,11 @@ public boolean isUnpushable() { return block.getPistonPushReaction() == PushReaction.BLOCK; } + @Override + public boolean isTicksRandomly() { + return block.isRandomlyTicking(); + } + @Override @SuppressWarnings("deprecation") public boolean isMovementBlocker() { @@ -93,4 +129,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 ); } diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeBlockMaterial.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeBlockMaterial.java index 74c98c854c..7b243a7aab 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeBlockMaterial.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeBlockMaterial.java @@ -20,29 +20,35 @@ package com.sk89q.worldedit.neoforge; 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.Block; +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; - /** * Forge 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 NeoForgeBlockMaterial extends PassthroughBlockMaterial { +public class NeoForgeBlockMaterial implements BlockMaterial { private final BlockState block; - public NeoForgeBlockMaterial(BlockState block, @Nullable BlockMaterial secondary) { - super(secondary); + public NeoForgeBlockMaterial(BlockState block) { this.block = block; } @Override public boolean isAir() { - return block.isAir() || super.isAir(); + return block.isAir(); + } + + @Override + public boolean isFullCube() { + return Block.isShapeFullBlock(block.getShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); } @Override @@ -50,18 +56,45 @@ public boolean isOpaque() { return block.canOcclude(); } - @SuppressWarnings("deprecation") @Override + public boolean isPowerSource() { + return block.isSignalSource(); + } + + @Override + @SuppressWarnings("deprecation") public boolean isLiquid() { return block.liquid(); } - @SuppressWarnings("deprecation") @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; @@ -72,8 +105,13 @@ public boolean isUnpushable() { return block.getPistonPushReaction() == PushReaction.BLOCK; } - @SuppressWarnings("deprecation") @Override + public boolean isTicksRandomly() { + return block.isRandomlyTicking(); + } + + @Override + @SuppressWarnings("deprecation") public boolean isMovementBlocker() { return block.blocksMotion(); } @@ -85,7 +123,7 @@ public boolean isBurnable() { @Override public boolean isToolRequired() { - return !block.requiresCorrectToolForDrops(); + return block.requiresCorrectToolForDrops(); } @Override @@ -93,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-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeBlockRegistry.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeBlockRegistry.java index 5867d9a4e6..cdd812db63 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeBlockRegistry.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeBlockRegistry.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 NeoForgeBlockRegistry extends BundledBlockRegistry { +public class NeoForgeBlockRegistry implements BlockRegistry { private final Map materialMap = new HashMap<>(); @@ -47,12 +47,9 @@ public Component getRichName(BlockType blockType) { @Override public BlockMaterial getMaterial(BlockType blockType) { Block block = NeoForgeAdapter.adapt(blockType); - if (block == null) { - return super.getMaterial(blockType); - } return materialMap.computeIfAbsent( block.defaultBlockState(), - s -> new NeoForgeBlockMaterial(s, super.getMaterial(blockType)) + NeoForgeBlockMaterial::new ); } diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBlockMaterial.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBlockMaterial.java index 861b9d633b..4dd6622de4 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBlockMaterial.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBlockMaterial.java @@ -20,29 +20,35 @@ package com.sk89q.worldedit.sponge; 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.Block; +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; - /** * Sponge 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 SpongeBlockMaterial extends PassthroughBlockMaterial { +public class SpongeBlockMaterial implements BlockMaterial { private final BlockState block; - public SpongeBlockMaterial(BlockState block, @Nullable BlockMaterial secondary) { - super(secondary); + public SpongeBlockMaterial(BlockState block) { this.block = block; } @Override public boolean isAir() { - return block.isAir() || super.isAir(); + return block.isAir(); + } + + @Override + public boolean isFullCube() { + return Block.isShapeFullBlock(block.getShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); } @Override @@ -50,6 +56,11 @@ public boolean isOpaque() { return block.canOcclude(); } + @Override + public boolean isPowerSource() { + return block.isSignalSource(); + } + @Override @SuppressWarnings("deprecation") public boolean isLiquid() { @@ -62,6 +73,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; @@ -72,6 +103,11 @@ public boolean isUnpushable() { return block.getPistonPushReaction() == PushReaction.BLOCK; } + @Override + public boolean isTicksRandomly() { + return block.isRandomlyTicking(); + } + @Override @SuppressWarnings("deprecation") public boolean isMovementBlocker() { @@ -93,4 +129,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-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBlockRegistry.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBlockRegistry.java index f692e9c278..5c0434d36a 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBlockRegistry.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBlockRegistry.java @@ -25,7 +25,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 org.spongepowered.api.ResourceKey; import org.spongepowered.api.Sponge; @@ -38,7 +38,7 @@ import java.util.OptionalInt; import java.util.TreeMap; -public class SpongeBlockRegistry extends BundledBlockRegistry { +public class SpongeBlockRegistry implements BlockRegistry { private final Map materialMap = new HashMap<>(); @@ -60,8 +60,7 @@ public BlockMaterial getMaterial(BlockType blockType) { net.minecraft.world.level.block.state.BlockState blockState = (net.minecraft.world.level.block.state.BlockState) m; return new SpongeBlockMaterial( - blockState, - super.getMaterial(blockType) + blockState ); } );