Skip to content

Commit f778687

Browse files
authored
Deprecate the concept of bundled block data (#2447)
* 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
1 parent f608c01 commit f778687

27 files changed

Lines changed: 1108 additions & 56 deletions

File tree

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
{
2-
}
2+
"Removal of constructor in non-API class": [
3+
{
4+
"type": "com.sk89q.worldedit.fabric.FabricBlockMaterial",
5+
"member": "Constructor com.sk89q.worldedit.fabric.FabricBlockMaterial(net.minecraft.class_2680,com.sk89q.worldedit.world.registry.BlockMaterial)",
6+
"changes": [
7+
"CONSTRUCTOR_REMOVED"
8+
]
9+
}
10+
]
11+
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
{
2-
}
2+
"Removal of constructor in non-API class": [
3+
{
4+
"type": "com.sk89q.worldedit.neoforge.NeoForgeBlockMaterial",
5+
"member": "Constructor com.sk89q.worldedit.neoforge.NeoForgeBlockMaterial(net.minecraft.world.level.block.state.BlockState,com.sk89q.worldedit.world.registry.BlockMaterial)",
6+
"changes": [
7+
"CONSTRUCTOR_REMOVED"
8+
]
9+
}
10+
]
11+
}

worldedit-bukkit/adapters/adapter-1.20.2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R2/PaperweightAdapter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
7070
import com.sk89q.worldedit.world.generation.StructureType;
7171
import com.sk89q.worldedit.world.item.ItemType;
72+
import com.sk89q.worldedit.world.registry.BlockMaterial;
7273
import net.minecraft.Util;
7374
import net.minecraft.core.BlockPos;
7475
import net.minecraft.core.Holder;
@@ -578,6 +579,12 @@ public Component getRichItemName(BaseItemStack itemStack) {
578579
return TranslatableComponent.of(CraftItemStack.asNMSCopy(BukkitAdapter.adapt(itemStack)).getDescriptionId());
579580
}
580581

582+
@Override
583+
public BlockMaterial getBlockMaterial(BlockType blockType) {
584+
net.minecraft.world.level.block.state.BlockState mcBlockState = getBlockFromType(blockType).defaultBlockState();
585+
return new PaperweightBlockMaterial(mcBlockState);
586+
}
587+
581588
@SuppressWarnings({ "unchecked", "rawtypes" })
582589
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<?>>() {
583590
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* WorldEdit, a Minecraft world manipulation toolkit
3+
* Copyright (C) sk89q <http://www.sk89q.com>
4+
* Copyright (C) WorldEdit team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
package com.sk89q.worldedit.bukkit.adapter.impl.v1_20_R2;
21+
22+
import com.sk89q.worldedit.world.registry.BlockMaterial;
23+
import net.minecraft.core.BlockPos;
24+
import net.minecraft.world.Clearable;
25+
import net.minecraft.world.level.EmptyBlockGetter;
26+
import net.minecraft.world.level.block.Block;
27+
import net.minecraft.world.level.block.EntityBlock;
28+
import net.minecraft.world.level.block.state.BlockState;
29+
import net.minecraft.world.level.material.PushReaction;
30+
31+
public class PaperweightBlockMaterial implements BlockMaterial {
32+
33+
private final BlockState block;
34+
35+
public PaperweightBlockMaterial(BlockState block) {
36+
this.block = block;
37+
}
38+
39+
@Override
40+
public boolean isAir() {
41+
return block.isAir();
42+
}
43+
44+
@Override
45+
public boolean isFullCube() {
46+
return Block.isShapeFullBlock(block.getShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO));
47+
}
48+
49+
@Override
50+
public boolean isOpaque() {
51+
return block.canOcclude();
52+
}
53+
54+
@Override
55+
public boolean isPowerSource() {
56+
return block.isSignalSource();
57+
}
58+
59+
@Override
60+
@SuppressWarnings("deprecation")
61+
public boolean isLiquid() {
62+
return block.liquid();
63+
}
64+
65+
@Override
66+
@SuppressWarnings("deprecation")
67+
public boolean isSolid() {
68+
return block.isSolid();
69+
}
70+
71+
@Override
72+
public float getHardness() {
73+
return block.getDestroySpeed(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
74+
}
75+
76+
@Override
77+
@SuppressWarnings("deprecation")
78+
public float getResistance() {
79+
return block.getBlock().getExplosionResistance();
80+
}
81+
82+
@Override
83+
public float getSlipperiness() {
84+
return block.getBlock().getFriction();
85+
}
86+
87+
@Override
88+
@SuppressWarnings("deprecation")
89+
public int getLightValue() {
90+
return block.getLightEmission();
91+
}
92+
93+
@Override
94+
public boolean isFragileWhenPushed() {
95+
return block.getPistonPushReaction() == PushReaction.DESTROY;
96+
}
97+
98+
@Override
99+
public boolean isUnpushable() {
100+
return block.getPistonPushReaction() == PushReaction.BLOCK;
101+
}
102+
103+
@Override
104+
public boolean isTicksRandomly() {
105+
return block.isRandomlyTicking();
106+
}
107+
108+
@Override
109+
@SuppressWarnings("deprecation")
110+
public boolean isMovementBlocker() {
111+
return block.blocksMotion();
112+
}
113+
114+
@Override
115+
public boolean isBurnable() {
116+
return block.ignitedByLava();
117+
}
118+
119+
@Override
120+
public boolean isToolRequired() {
121+
return block.requiresCorrectToolForDrops();
122+
}
123+
124+
@Override
125+
public boolean isReplacedDuringPlacement() {
126+
return block.canBeReplaced();
127+
}
128+
129+
@Override
130+
public boolean isTranslucent() {
131+
return !block.canOcclude();
132+
}
133+
134+
@Override
135+
public boolean hasContainer() {
136+
return block.getBlock() instanceof EntityBlock entityBlock
137+
&& entityBlock.newBlockEntity(BlockPos.ZERO, block) instanceof Clearable;
138+
}
139+
140+
}

worldedit-bukkit/adapters/adapter-1.20.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R3/PaperweightAdapter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
7070
import com.sk89q.worldedit.world.generation.StructureType;
7171
import com.sk89q.worldedit.world.item.ItemType;
72+
import com.sk89q.worldedit.world.registry.BlockMaterial;
7273
import net.minecraft.Util;
7374
import net.minecraft.core.BlockPos;
7475
import net.minecraft.core.Holder;
@@ -577,6 +578,12 @@ public Component getRichItemName(BaseItemStack itemStack) {
577578
return TranslatableComponent.of(CraftItemStack.asNMSCopy(BukkitAdapter.adapt(itemStack)).getDescriptionId());
578579
}
579580

581+
@Override
582+
public BlockMaterial getBlockMaterial(BlockType blockType) {
583+
net.minecraft.world.level.block.state.BlockState mcBlockState = getBlockFromType(blockType).defaultBlockState();
584+
return new PaperweightBlockMaterial(mcBlockState);
585+
}
586+
580587
@SuppressWarnings({ "unchecked", "rawtypes" })
581588
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<?>>() {
582589
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* WorldEdit, a Minecraft world manipulation toolkit
3+
* Copyright (C) sk89q <http://www.sk89q.com>
4+
* Copyright (C) WorldEdit team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
package com.sk89q.worldedit.bukkit.adapter.impl.v1_20_R3;
21+
22+
import com.sk89q.worldedit.world.registry.BlockMaterial;
23+
import net.minecraft.core.BlockPos;
24+
import net.minecraft.world.Clearable;
25+
import net.minecraft.world.level.EmptyBlockGetter;
26+
import net.minecraft.world.level.block.Block;
27+
import net.minecraft.world.level.block.EntityBlock;
28+
import net.minecraft.world.level.block.state.BlockState;
29+
import net.minecraft.world.level.material.PushReaction;
30+
31+
public class PaperweightBlockMaterial implements BlockMaterial {
32+
33+
private final BlockState block;
34+
35+
public PaperweightBlockMaterial(BlockState block) {
36+
this.block = block;
37+
}
38+
39+
@Override
40+
public boolean isAir() {
41+
return block.isAir();
42+
}
43+
44+
@Override
45+
public boolean isFullCube() {
46+
return Block.isShapeFullBlock(block.getShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO));
47+
}
48+
49+
@Override
50+
public boolean isOpaque() {
51+
return block.canOcclude();
52+
}
53+
54+
@Override
55+
public boolean isPowerSource() {
56+
return block.isSignalSource();
57+
}
58+
59+
@Override
60+
@SuppressWarnings("deprecation")
61+
public boolean isLiquid() {
62+
return block.liquid();
63+
}
64+
65+
@Override
66+
@SuppressWarnings("deprecation")
67+
public boolean isSolid() {
68+
return block.isSolid();
69+
}
70+
71+
@Override
72+
public float getHardness() {
73+
return block.getDestroySpeed(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
74+
}
75+
76+
@Override
77+
@SuppressWarnings("deprecation")
78+
public float getResistance() {
79+
return block.getBlock().getExplosionResistance();
80+
}
81+
82+
@Override
83+
public float getSlipperiness() {
84+
return block.getBlock().getFriction();
85+
}
86+
87+
@Override
88+
@SuppressWarnings("deprecation")
89+
public int getLightValue() {
90+
return block.getLightEmission();
91+
}
92+
93+
@Override
94+
public boolean isFragileWhenPushed() {
95+
return block.getPistonPushReaction() == PushReaction.DESTROY;
96+
}
97+
98+
@Override
99+
public boolean isUnpushable() {
100+
return block.getPistonPushReaction() == PushReaction.BLOCK;
101+
}
102+
103+
@Override
104+
public boolean isTicksRandomly() {
105+
return block.isRandomlyTicking();
106+
}
107+
108+
@Override
109+
@SuppressWarnings("deprecation")
110+
public boolean isMovementBlocker() {
111+
return block.blocksMotion();
112+
}
113+
114+
@Override
115+
public boolean isBurnable() {
116+
return block.ignitedByLava();
117+
}
118+
119+
@Override
120+
public boolean isToolRequired() {
121+
return block.requiresCorrectToolForDrops();
122+
}
123+
124+
@Override
125+
public boolean isReplacedDuringPlacement() {
126+
return block.canBeReplaced();
127+
}
128+
129+
@Override
130+
public boolean isTranslucent() {
131+
return !block.canOcclude();
132+
}
133+
134+
@Override
135+
public boolean hasContainer() {
136+
return block.getBlock() instanceof EntityBlock entityBlock
137+
&& entityBlock.newBlockEntity(BlockPos.ZERO, block) instanceof Clearable;
138+
}
139+
140+
}

worldedit-bukkit/adapters/adapter-1.20.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R4/PaperweightAdapter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
7070
import com.sk89q.worldedit.world.generation.StructureType;
7171
import com.sk89q.worldedit.world.item.ItemType;
72+
import com.sk89q.worldedit.world.registry.BlockMaterial;
7273
import net.minecraft.Util;
7374
import net.minecraft.core.BlockPos;
7475
import net.minecraft.core.Holder;
@@ -579,6 +580,12 @@ public Component getRichItemName(BaseItemStack itemStack) {
579580
return TranslatableComponent.of(CraftItemStack.asNMSCopy(BukkitAdapter.adapt(itemStack)).getDescriptionId());
580581
}
581582

583+
@Override
584+
public BlockMaterial getBlockMaterial(BlockType blockType) {
585+
net.minecraft.world.level.block.state.BlockState mcBlockState = getBlockFromType(blockType).defaultBlockState();
586+
return new PaperweightBlockMaterial(mcBlockState);
587+
}
588+
582589
@SuppressWarnings({ "unchecked", "rawtypes" })
583590
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<?>>() {
584591
@Override

0 commit comments

Comments
 (0)