mirror of
https://github.com/PaperMC/Paper.git
synced 2025-05-19 05:30:23 -07:00
Add isSuffocating to Block and BlockState (#12445)
This commit is contained in:
parent
a211ac2ec5
commit
ae512811db
@ -817,4 +817,11 @@ public interface Block extends Metadatable, Translatable, net.kyori.adventure.tr
|
|||||||
return this.getBlockData().getDestroySpeed(itemStack, considerEnchants);
|
return this.getBlockData().getDestroySpeed(itemStack, considerEnchants);
|
||||||
}
|
}
|
||||||
// Paper end - destroy speed API
|
// Paper end - destroy speed API
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the block can suffocate.
|
||||||
|
*
|
||||||
|
* @return {@code true} if the block can suffocate
|
||||||
|
*/
|
||||||
|
boolean isSuffocating();
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,16 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.material.MaterialData;
|
import org.bukkit.material.MaterialData;
|
||||||
import org.bukkit.metadata.Metadatable;
|
import org.bukkit.metadata.Metadatable;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.Unmodifiable;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a captured state of a block, which will not change
|
* Represents a captured state of a block, which will not change
|
||||||
@ -226,14 +230,14 @@ public interface BlockState extends Metadatable {
|
|||||||
* @deprecated Magic value
|
* @deprecated Magic value
|
||||||
*/
|
*/
|
||||||
@Deprecated(since = "1.6.2", forRemoval = true)
|
@Deprecated(since = "1.6.2", forRemoval = true)
|
||||||
public byte getRawData();
|
byte getRawData();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param data The new data value for the block.
|
* @param data The new data value for the block.
|
||||||
* @deprecated Magic value
|
* @deprecated Magic value
|
||||||
*/
|
*/
|
||||||
@Deprecated(since = "1.6.2", forRemoval = true)
|
@Deprecated(since = "1.6.2", forRemoval = true)
|
||||||
public void setRawData(byte data);
|
void setRawData(byte data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether this state is placed in the world.
|
* Returns whether this state is placed in the world.
|
||||||
@ -246,7 +250,6 @@ public interface BlockState extends Metadatable {
|
|||||||
*/
|
*/
|
||||||
boolean isPlaced();
|
boolean isPlaced();
|
||||||
|
|
||||||
// Paper start
|
|
||||||
/**
|
/**
|
||||||
* Checks if this block state is collidable.
|
* Checks if this block state is collidable.
|
||||||
*
|
*
|
||||||
@ -261,7 +264,7 @@ public interface BlockState extends Metadatable {
|
|||||||
* @throws IllegalStateException if this block state is not placed
|
* @throws IllegalStateException if this block state is not placed
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
default java.util.@org.jetbrains.annotations.Unmodifiable Collection<org.bukkit.inventory.ItemStack> getDrops() {
|
default @Unmodifiable Collection<ItemStack> getDrops() {
|
||||||
return this.getDrops(null);
|
return this.getDrops(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,7 +277,7 @@ public interface BlockState extends Metadatable {
|
|||||||
* @throws IllegalStateException if this block state is not placed
|
* @throws IllegalStateException if this block state is not placed
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
default java.util.@org.jetbrains.annotations.Unmodifiable Collection<org.bukkit.inventory.ItemStack> getDrops(@Nullable org.bukkit.inventory.ItemStack tool) {
|
default @Unmodifiable Collection<ItemStack> getDrops(@Nullable ItemStack tool) {
|
||||||
return this.getDrops(tool, null);
|
return this.getDrops(tool, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,6 +291,14 @@ public interface BlockState extends Metadatable {
|
|||||||
* @throws IllegalStateException if this block state is not placed
|
* @throws IllegalStateException if this block state is not placed
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
java.util.@org.jetbrains.annotations.Unmodifiable Collection<org.bukkit.inventory.ItemStack> getDrops(@Nullable org.bukkit.inventory.ItemStack tool, @Nullable org.bukkit.entity.Entity entity);
|
@Unmodifiable
|
||||||
// Paper end
|
Collection<ItemStack> getDrops(@Nullable ItemStack tool, @Nullable Entity entity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the block state can suffocate.
|
||||||
|
*
|
||||||
|
* @return {@code true} if the block state can suffocate
|
||||||
|
* @throws IllegalStateException if this block state is not placed
|
||||||
|
*/
|
||||||
|
boolean isSuffocating();
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,6 @@ import org.bukkit.block.data.type.WallHangingSign;
|
|||||||
import org.bukkit.block.data.type.WallSign;
|
import org.bukkit.block.data.type.WallSign;
|
||||||
import org.bukkit.block.data.type.WallSkull;
|
import org.bukkit.block.data.type.WallSkull;
|
||||||
import org.bukkit.inventory.ItemType;
|
import org.bukkit.inventory.ItemType;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.annotations.Unmodifiable;
|
import org.jetbrains.annotations.Unmodifiable;
|
||||||
|
@ -697,6 +697,11 @@ public class CraftBlock implements Block {
|
|||||||
return this.getNMS().getBlock().getDescriptionId();
|
return this.getNMS().getBlock().getDescriptionId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSuffocating() {
|
||||||
|
return this.getNMS().isSuffocating(this.world, this.position);
|
||||||
|
}
|
||||||
|
|
||||||
// Paper start
|
// Paper start
|
||||||
@Override
|
@Override
|
||||||
public com.destroystokyo.paper.block.BlockSoundGroup getSoundGroup() {
|
public com.destroystokyo.paper.block.BlockSoundGroup getSoundGroup() {
|
||||||
|
@ -75,6 +75,7 @@ public class CraftBlockState implements BlockState {
|
|||||||
|
|
||||||
// Returns null if weakWorld is not available and the BlockState is not placed.
|
// Returns null if weakWorld is not available and the BlockState is not placed.
|
||||||
// If this returns a World instead of only a GeneratorAccess, this implies that this BlockState is placed.
|
// If this returns a World instead of only a GeneratorAccess, this implies that this BlockState is placed.
|
||||||
|
@Nullable
|
||||||
public LevelAccessor getWorldHandle() {
|
public LevelAccessor getWorldHandle() {
|
||||||
if (this.weakWorld == null) {
|
if (this.weakWorld == null) {
|
||||||
return this.isPlaced() ? this.world.getHandle() : null;
|
return this.isPlaced() ? this.world.getHandle() : null;
|
||||||
@ -177,7 +178,7 @@ public class CraftBlockState implements BlockState {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Material getType() {
|
public Material getType() {
|
||||||
return this.data.getBukkitMaterial(); // Paper - optimise getType calls
|
return this.data.getBukkitMaterial();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFlags(int flags) {
|
public void setFlags(int flags) {
|
||||||
@ -357,7 +358,6 @@ public class CraftBlockState implements BlockState {
|
|||||||
return new CraftBlockState(this, location);
|
return new CraftBlockState(this, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Paper start
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCollidable() {
|
public boolean isCollidable() {
|
||||||
return this.data.getBlock().hasCollision;
|
return this.data.getBlock().hasCollision;
|
||||||
@ -381,5 +381,10 @@ public class CraftBlockState implements BlockState {
|
|||||||
return java.util.Collections.emptyList();
|
return java.util.Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Paper end
|
|
||||||
|
@Override
|
||||||
|
public boolean isSuffocating() {
|
||||||
|
this.requirePlaced();
|
||||||
|
return this.data.isSuffocating(this.getWorldHandle(), this.position);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user