Skip to content

Commit 20503dd

Browse files
committed
Add BlockState.getMaterial()
1 parent 59f7f46 commit 20503dd

16 files changed

Lines changed: 108 additions & 22 deletions

File tree

verification/src/changes/accepted-bukkit-public-api-changes.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,15 @@
88
"ANNOTATION_REMOVED"
99
]
1010
}
11+
],
12+
"Replaced by default method": [
13+
{
14+
"type": "com.sk89q.worldedit.bukkit.BukkitBlockRegistry",
15+
"member": "Method com.sk89q.worldedit.bukkit.BukkitBlockRegistry.getMaterial(com.sk89q.worldedit.world.block.BlockType)",
16+
"changes": [
17+
"METHOD_REMOVED",
18+
"ANNOTATION_REMOVED"
19+
]
20+
}
1121
]
1222
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
{
2+
"Replaced by default method": [
3+
{
4+
"type": "com.sk89q.worldedit.sponge.SpongeBlockRegistry",
5+
"member": "Method com.sk89q.worldedit.sponge.SpongeBlockRegistry.getMaterial(com.sk89q.worldedit.world.block.BlockType)",
6+
"changes": [
7+
"METHOD_REMOVED"
8+
]
9+
}
10+
]
211
}

worldedit-bukkit/adapters/adapter-1.21.11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_11/PaperweightAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,11 @@ public BlockMaterial getBlockMaterial(BlockType blockType) {
586586
return new PaperweightBlockMaterial(mcBlockState);
587587
}
588588

589+
@Override
590+
public BlockMaterial getBlockMaterial(BlockState blockState) {
591+
return new PaperweightBlockMaterial(adapt(blockState));
592+
}
593+
589594
@SuppressWarnings({ "unchecked", "rawtypes" })
590595
private static final LoadingCache<net.minecraft.world.level.block.state.properties.Property, Property<?>> PROPERTY_CACHE = CacheBuilder.newBuilder().build(new CacheLoader<>() {
591596
@Override

worldedit-bukkit/adapters/adapter-1.21.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_4/PaperweightAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,11 @@ public BlockMaterial getBlockMaterial(BlockType blockType) {
567567
return new PaperweightBlockMaterial(mcBlockState);
568568
}
569569

570+
@Override
571+
public BlockMaterial getBlockMaterial(BlockState blockState) {
572+
return new PaperweightBlockMaterial(adapt(blockState));
573+
}
574+
570575
@SuppressWarnings({ "unchecked", "rawtypes" })
571576
private static final LoadingCache<net.minecraft.world.level.block.state.properties.Property, Property<?>> PROPERTY_CACHE = CacheBuilder.newBuilder().build(new CacheLoader<>() {
572577
@Override

worldedit-bukkit/adapters/adapter-1.21.5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_5/PaperweightAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,11 @@ public BlockMaterial getBlockMaterial(BlockType blockType) {
565565
return new PaperweightBlockMaterial(mcBlockState);
566566
}
567567

568+
@Override
569+
public BlockMaterial getBlockMaterial(BlockState blockState) {
570+
return new PaperweightBlockMaterial(adapt(blockState));
571+
}
572+
568573
@SuppressWarnings({ "unchecked", "rawtypes" })
569574
private static final LoadingCache<net.minecraft.world.level.block.state.properties.Property, Property<?>> PROPERTY_CACHE = CacheBuilder.newBuilder().build(new CacheLoader<>() {
570575
@Override

worldedit-bukkit/adapters/adapter-1.21.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_6/PaperweightAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,11 @@ public BlockMaterial getBlockMaterial(BlockType blockType) {
587587
return new PaperweightBlockMaterial(mcBlockState);
588588
}
589589

590+
@Override
591+
public BlockMaterial getBlockMaterial(BlockState blockState) {
592+
return new PaperweightBlockMaterial(adapt(blockState));
593+
}
594+
590595
@SuppressWarnings({ "unchecked", "rawtypes" })
591596
private static final LoadingCache<net.minecraft.world.level.block.state.properties.Property, Property<?>> PROPERTY_CACHE = CacheBuilder.newBuilder().build(new CacheLoader<>() {
592597
@Override

worldedit-bukkit/adapters/adapter-1.21.9/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_9/PaperweightAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,11 @@ public BlockMaterial getBlockMaterial(BlockType blockType) {
586586
return new PaperweightBlockMaterial(mcBlockState);
587587
}
588588

589+
@Override
590+
public BlockMaterial getBlockMaterial(BlockState blockState) {
591+
return new PaperweightBlockMaterial(adapt(blockState));
592+
}
593+
589594
@SuppressWarnings({ "unchecked", "rawtypes" })
590595
private static final LoadingCache<net.minecraft.world.level.block.state.properties.Property, Property<?>> PROPERTY_CACHE = CacheBuilder.newBuilder().build(new CacheLoader<>() {
591596
@Override

worldedit-bukkit/adapters/adapter-26.1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v26_1/PaperweightAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,11 @@ public BlockMaterial getBlockMaterial(BlockType blockType) {
603603
return new PaperweightBlockMaterial(mcBlockState);
604604
}
605605

606+
@Override
607+
public BlockMaterial getBlockMaterial(BlockState blockState) {
608+
return new PaperweightBlockMaterial(adapt(blockState));
609+
}
610+
606611
@SuppressWarnings({ "unchecked", "rawtypes" })
607612
private static final LoadingCache<net.minecraft.world.level.block.state.properties.Property, Property<?>> PROPERTY_CACHE = CacheBuilder.newBuilder().build(new CacheLoader<>() {
608613
@Override

worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ public Component getRichName(BlockType blockType) {
4747

4848
@Nullable
4949
@Override
50-
public BlockMaterial getMaterial(BlockType blockType) {
51-
Material mat = BukkitAdapter.adapt(blockType);
50+
public BlockMaterial getMaterial(BlockState blockState) {
51+
Material mat = BukkitAdapter.adapt(blockState.getBlockType());
5252
if (mat == null) {
5353
return null;
5454
}
5555
return materialMap.computeIfAbsent(mat, material -> {
5656
BlockMaterial platformMaterial = null;
5757
if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) {
58-
platformMaterial = WorldEditPlugin.getInstance().getBukkitImplAdapter().getBlockMaterial(blockType);
58+
platformMaterial = WorldEditPlugin.getInstance().getBukkitImplAdapter().getBlockMaterial(blockState);
5959
}
6060
return new BukkitBlockMaterial(platformMaterial, material);
6161
});

worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ default void tickWatchdog() {
161161
@Nullable
162162
BlockMaterial getBlockMaterial(BlockType blockType);
163163

164+
/**
165+
* Gets the block material for the given block state.
166+
*
167+
* @param blockState the block state
168+
* @return the material
169+
*/
170+
@Nullable
171+
default BlockMaterial getBlockMaterial(BlockState blockState) {
172+
return getBlockMaterial(blockState.getBlockType());
173+
}
174+
164175
/**
165176
* Get a map of {@code string -> property}.
166177
*

0 commit comments

Comments
 (0)