mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Remove get
prefixes for protocol objects to be more record-friendly
This commit is contained in:
parent
123f0bec04
commit
106125319a
@ -607,7 +607,7 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
|
||||
continue;
|
||||
|
||||
final Block block = chunk.getBlock(x, y, z);
|
||||
final BlockHandler handler = block.getHandler();
|
||||
final BlockHandler handler = block.handler();
|
||||
if (handler != null) {
|
||||
tmpPosition.setX(x);
|
||||
tmpPosition.setY(y);
|
||||
|
@ -49,8 +49,8 @@ public class EatBlockGoal extends GoalSelector {
|
||||
}
|
||||
|
||||
final BlockPosition blockPosition = entityCreature.getPosition().toBlockPosition();
|
||||
final short blockStateIdIn = instance.getBlock(blockPosition.clone().subtract(0, 1, 0)).getStateId();
|
||||
final short blockStateIdBelow = instance.getBlock(blockPosition.clone().subtract(0, 2, 0)).getStateId();
|
||||
final short blockStateIdIn = instance.getBlock(blockPosition.clone().subtract(0, 1, 0)).stateId();
|
||||
final short blockStateIdBelow = instance.getBlock(blockPosition.clone().subtract(0, 2, 0)).stateId();
|
||||
|
||||
return eatInMap.containsKey(blockStateIdIn) || eatBelowMap.containsKey(blockStateIdBelow);
|
||||
}
|
||||
@ -73,8 +73,8 @@ public class EatBlockGoal extends GoalSelector {
|
||||
final BlockPosition currentPosition = entityCreature.getPosition().toBlockPosition().clone().subtract(0, 1, 0);
|
||||
final BlockPosition belowPosition = currentPosition.clone().subtract(0, 1, 0);
|
||||
|
||||
final short blockStateIdIn = instance.getBlock(currentPosition).getStateId();
|
||||
final short blockStateIdBelow = instance.getBlock(belowPosition).getStateId();
|
||||
final short blockStateIdIn = instance.getBlock(currentPosition).stateId();
|
||||
final short blockStateIdBelow = instance.getBlock(belowPosition).stateId();
|
||||
if (eatInMap.containsKey(blockStateIdIn)) {
|
||||
instance.setBlock(currentPosition, Block.fromStateId(eatInMap.get(blockStateIdIn)));
|
||||
} else if (eatBelowMap.containsKey(blockStateIdBelow)) {
|
||||
|
@ -44,7 +44,7 @@ public class FallingBlockMeta extends EntityMeta implements ObjectDataProvider {
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Override
|
||||
public int getObjectData() {
|
||||
int id = this.block.getId();
|
||||
int id = this.block.id();
|
||||
int metadata = 0; // TODO ?
|
||||
return id | (metadata << 12);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public class PFBlockDescription implements IBlockDescription {
|
||||
* @return the {@link PFBlockDescription} linked to {@code blockStateId}
|
||||
*/
|
||||
public static PFBlockDescription getBlockDescription(Block block) {
|
||||
final short blockStateId = block.getStateId();
|
||||
final short blockStateId = block.stateId();
|
||||
if (!BLOCK_DESCRIPTION_MAP.containsKey(blockStateId)) {
|
||||
synchronized (BLOCK_DESCRIPTION_MAP) {
|
||||
final PFBlockDescription blockDescription = new PFBlockDescription(block);
|
||||
@ -41,26 +41,26 @@ public class PFBlockDescription implements IBlockDescription {
|
||||
// TODO: Use Hitbox
|
||||
// Return fences, fencegates and walls.
|
||||
// It just so happens that their namespace IDs contain "fence".
|
||||
if (block.getNamespaceId().asString().contains("fence")) {
|
||||
if (block.namespace().asString().contains("fence")) {
|
||||
return true;
|
||||
}
|
||||
// Return all walls
|
||||
// It just so happens that their namespace IDs all end with "door".
|
||||
return block.getNamespaceId().asString().endsWith("wall");
|
||||
return block.namespace().asString().endsWith("wall");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClimbable() {
|
||||
// Return ladders and vines (including weeping and twisting vines)
|
||||
// Note that no other Namespace IDs contain "vine" except vines.
|
||||
return block.compare(Block.LADDER) || block.getNamespaceId().asString().contains("vine");
|
||||
return block.compare(Block.LADDER) || block.namespace().asString().contains("vine");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDoor() {
|
||||
// Return all normal doors and trap doors.
|
||||
// It just so happens that their namespace IDs all end with "door".
|
||||
return block.getNamespaceId().asString().endsWith("door");
|
||||
return block.namespace().asString().endsWith("door");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -85,29 +85,29 @@ public class PFBlockDescription implements IBlockDescription {
|
||||
if (isDoor()) {
|
||||
return false;
|
||||
}
|
||||
if (block.getName().startsWith("potted")) {
|
||||
if (block.name().startsWith("potted")) {
|
||||
return false;
|
||||
}
|
||||
// Skulls & Heads
|
||||
if (block.getName().contains("skull") || block.getName().contains("head")) {
|
||||
if (block.name().contains("skull") || block.name().contains("head")) {
|
||||
// NOTE: blocks.getName().contains("head") also matches Piston_Head
|
||||
// I could not find out by documentation if piston_head is fully bounded, I would presume it is NOT.
|
||||
return false;
|
||||
}
|
||||
// Carpets
|
||||
if (block.getName().endsWith("carpet")) {
|
||||
if (block.name().endsWith("carpet")) {
|
||||
return false;
|
||||
}
|
||||
// Slabs
|
||||
if (block.getName().contains("slab")) {
|
||||
if (block.name().contains("slab")) {
|
||||
return false;
|
||||
}
|
||||
// Beds
|
||||
if (block.getName().endsWith("bed")) {
|
||||
if (block.name().endsWith("bed")) {
|
||||
return false;
|
||||
}
|
||||
// Glass Panes
|
||||
if (block.getName().endsWith("pane")) {
|
||||
if (block.name().endsWith("pane")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ public class PFBlockObject implements IBlockObject {
|
||||
* @return the {@link PFBlockObject} linked to {@code blockStateId}
|
||||
*/
|
||||
public static PFBlockObject getBlockObject(Block block) {
|
||||
final short blockStateId = block.getStateId();
|
||||
final short blockStateId = block.stateId();
|
||||
if (!BLOCK_OBJECT_MAP.containsKey(blockStateId)) {
|
||||
synchronized (BLOCK_OBJECT_MAP) {
|
||||
final PFBlockObject blockObject = new PFBlockObject(block);
|
||||
@ -50,26 +50,26 @@ public class PFBlockObject implements IBlockObject {
|
||||
// TODO: Use Hitbox
|
||||
// Return fences, fencegates and walls.
|
||||
// It just so happens that their namespace IDs contain "fence".
|
||||
if (block.getNamespaceId().asString().contains("fence")) {
|
||||
if (block.namespace().asString().contains("fence")) {
|
||||
return true;
|
||||
}
|
||||
// Return all walls
|
||||
// It just so happens that their namespace IDs all end with "door".
|
||||
return block.getNamespaceId().asString().endsWith("wall");
|
||||
return block.namespace().asString().endsWith("wall");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClimbable() {
|
||||
// Return ladders and vines (including weeping and twisting vines)
|
||||
// Note that no other Namespace IDs contain "vine" except vines.
|
||||
return block.compare(Block.LADDER) || block.getNamespaceId().asString().contains("vine");
|
||||
return block.compare(Block.LADDER) || block.namespace().asString().contains("vine");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDoor() {
|
||||
// Return all normal doors and trap doors.
|
||||
// It just so happens that their namespace IDs all end with "door".
|
||||
return block.getNamespaceId().asString().endsWith("door");
|
||||
return block.namespace().asString().endsWith("door");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -94,29 +94,29 @@ public class PFBlockObject implements IBlockObject {
|
||||
if (isDoor()) {
|
||||
return false;
|
||||
}
|
||||
if (block.getName().startsWith("potted")) {
|
||||
if (block.name().startsWith("potted")) {
|
||||
return false;
|
||||
}
|
||||
// Skulls & Heads
|
||||
if (block.getName().contains("skull") || block.getName().contains("head")) {
|
||||
if (block.name().contains("skull") || block.name().contains("head")) {
|
||||
// NOTE: blocks.getName().contains("head") also matches Piston_Head
|
||||
// I could not find out by documentation if piston_head is fully bounded, I would presume it is NOT.
|
||||
return false;
|
||||
}
|
||||
// Carpets
|
||||
if (block.getName().endsWith("carpet")) {
|
||||
if (block.name().endsWith("carpet")) {
|
||||
return false;
|
||||
}
|
||||
// Slabs
|
||||
if (block.getName().contains("slab")) {
|
||||
if (block.name().contains("slab")) {
|
||||
return false;
|
||||
}
|
||||
// Beds
|
||||
if (block.getName().endsWith("bed")) {
|
||||
if (block.name().endsWith("bed")) {
|
||||
return false;
|
||||
}
|
||||
// Glass Panes
|
||||
if (block.getName().endsWith("pane")) {
|
||||
if (block.name().endsWith("pane")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -68,18 +68,18 @@ public class DynamicChunk extends Chunk {
|
||||
columnarOcclusionFieldList.onBlockChanged(x, y, z, blockDescription, 0);
|
||||
}
|
||||
Section section = retrieveSection(y);
|
||||
section.setBlockAt(x, y, z, block.getStateId());
|
||||
section.setBlockAt(x, y, z, block.stateId());
|
||||
|
||||
final int index = getBlockIndex(x, y, z);
|
||||
// Handler
|
||||
final BlockHandler handler = block.getHandler();
|
||||
final BlockHandler handler = block.handler();
|
||||
if (handler != null) {
|
||||
this.handlerMap.put(index, handler);
|
||||
} else {
|
||||
this.handlerMap.remove(index);
|
||||
}
|
||||
// Nbt
|
||||
final NBTCompound nbt = block.getNbt();
|
||||
final NBTCompound nbt = block.nbt();
|
||||
if (nbt != null) {
|
||||
this.nbtMap.put(index, nbt);
|
||||
} else {
|
||||
|
@ -572,7 +572,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ev
|
||||
blockActionPacket.blockPosition = blockPosition;
|
||||
blockActionPacket.actionId = actionId;
|
||||
blockActionPacket.actionParam = actionParam;
|
||||
blockActionPacket.blockId = block.getId();
|
||||
blockActionPacket.blockId = block.id();
|
||||
|
||||
final Chunk chunk = getChunkAt(blockPosition);
|
||||
Check.notNull(chunk, "The chunk at " + blockPosition + " is not loaded!");
|
||||
|
@ -149,7 +149,7 @@ public class InstanceContainer extends Instance {
|
||||
setAlreadyChanged(blockPosition, block);
|
||||
|
||||
final Block previousBlock = chunk.getBlock(blockPosition);
|
||||
final BlockHandler previousHandler = previousBlock.getHandler();
|
||||
final BlockHandler previousHandler = previousBlock.handler();
|
||||
|
||||
// Change id based on neighbors
|
||||
block = executeBlockPlacementRule(block, blockPosition);
|
||||
@ -167,7 +167,7 @@ public class InstanceContainer extends Instance {
|
||||
// Previous destroy
|
||||
previousHandler.onDestroy(BlockHandler.Destroy.from(previousBlock, this, blockPosition));
|
||||
}
|
||||
final BlockHandler handler = block.getHandler();
|
||||
final BlockHandler handler = block.handler();
|
||||
if (handler != null) {
|
||||
// New placement
|
||||
handler.onPlace(BlockHandler.Placement.from(block, this, blockPosition));
|
||||
@ -191,7 +191,7 @@ public class InstanceContainer extends Instance {
|
||||
final Block changedBlock = currentlyChangingBlocks.get(blockPosition);
|
||||
if (changedBlock == null)
|
||||
return false;
|
||||
return changedBlock.getId() == block.getId();
|
||||
return changedBlock.id() == block.id();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -285,7 +285,7 @@ public class InstanceContainer extends Instance {
|
||||
EffectPacket effectPacket = new EffectPacket();
|
||||
effectPacket.effectId = 2001; // Block break + block break sound
|
||||
effectPacket.position = blockPosition;
|
||||
effectPacket.data = resultBlock.getStateId();
|
||||
effectPacket.data = resultBlock.stateId();
|
||||
effectPacket.disableRelativeVolume = false;
|
||||
|
||||
PacketUtils.sendGroupedPacket(chunk.getViewers(), effectPacket,
|
||||
@ -639,7 +639,7 @@ public class InstanceContainer extends Instance {
|
||||
private void sendBlockChange(@NotNull Chunk chunk, @NotNull BlockPosition blockPosition, @NotNull Block block) {
|
||||
BlockChangePacket blockChangePacket = new BlockChangePacket();
|
||||
blockChangePacket.blockPosition = blockPosition;
|
||||
blockChangePacket.blockStateId = block.getStateId();
|
||||
blockChangePacket.blockStateId = block.stateId();
|
||||
chunk.sendPacketToViewers(blockChangePacket);
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ public interface Block extends ProtocolObject, TagReadable, BlockConstants {
|
||||
|
||||
@Contract(pure = true)
|
||||
default <T> @NotNull Block withTag(@NotNull Tag<T> tag, @Nullable T value) {
|
||||
var compound = Objects.requireNonNullElseGet(getNbt(), NBTCompound::new);
|
||||
var compound = Objects.requireNonNullElseGet(nbt(), NBTCompound::new);
|
||||
tag.write(compound, value);
|
||||
return withNbt(compound);
|
||||
}
|
||||
@ -45,38 +45,38 @@ public interface Block extends ProtocolObject, TagReadable, BlockConstants {
|
||||
@NotNull Block withHandler(@Nullable BlockHandler handler);
|
||||
|
||||
@Contract(pure = true)
|
||||
@Nullable NBTCompound getNbt();
|
||||
@Nullable NBTCompound nbt();
|
||||
|
||||
@Contract(pure = true)
|
||||
@Nullable BlockHandler getHandler();
|
||||
@Nullable BlockHandler handler();
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull Map<String, String> getProperties();
|
||||
@NotNull Map<String, String> properties();
|
||||
|
||||
@Contract(pure = true)
|
||||
default @NotNull String getProperty(@NotNull String property) {
|
||||
return getProperties().get(property);
|
||||
default @NotNull String property(@NotNull String property) {
|
||||
return properties().get(property);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
default <T> @NotNull String getProperty(@NotNull BlockProperty<T> property) {
|
||||
return getProperty(property.getName());
|
||||
default <T> @NotNull String property(@NotNull BlockProperty<T> property) {
|
||||
return property(property.getName());
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull Registry.BlockEntry registry();
|
||||
|
||||
@Override
|
||||
default @NotNull NamespaceID getNamespaceId() {
|
||||
default @NotNull NamespaceID namespace() {
|
||||
return NamespaceID.from(registry().namespace());
|
||||
}
|
||||
|
||||
@Override
|
||||
default int getId() {
|
||||
default int id() {
|
||||
return registry().id();
|
||||
}
|
||||
|
||||
default short getStateId() {
|
||||
default short stateId() {
|
||||
return (short) registry().stateId();
|
||||
}
|
||||
|
||||
@ -120,8 +120,8 @@ public interface Block extends ProtocolObject, TagReadable, BlockConstants {
|
||||
interface Comparator extends BiPredicate<Block, Block> {
|
||||
Comparator IDENTITY = (b1, b2) -> b1 == b2;
|
||||
|
||||
Comparator ID = (b1, b2) -> b1.getId() == b2.getId();
|
||||
Comparator ID = (b1, b2) -> b1.id() == b2.id();
|
||||
|
||||
Comparator STATE = (b1, b2) -> b1.getStateId() == b2.getStateId();
|
||||
Comparator STATE = (b1, b2) -> b1.stateId() == b2.stateId();
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public class BlockManager {
|
||||
* @throws IllegalArgumentException if <code>blockPlacementRule</code> block id is negative
|
||||
*/
|
||||
public synchronized void registerBlockPlacementRule(@NotNull BlockPlacementRule blockPlacementRule) {
|
||||
final int id = blockPlacementRule.getBlock().getId();
|
||||
final int id = blockPlacementRule.getBlock().id();
|
||||
Check.argCondition(id < 0, "Block ID must be >= 0, got: " + id);
|
||||
|
||||
this.placementRules[id] = blockPlacementRule;
|
||||
@ -31,6 +31,6 @@ public class BlockManager {
|
||||
*/
|
||||
@Nullable
|
||||
public BlockPlacementRule getBlockPlacementRule(@NotNull Block block) {
|
||||
return this.placementRules[block.getId()];
|
||||
return this.placementRules[block.id()];
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class BlockRegistry {
|
||||
}
|
||||
|
||||
static @Nullable Block getProperties(Block block, Map<String, String> properties) {
|
||||
return getProperties(block.getNamespaceId().asString(), properties);
|
||||
return getProperties(block.namespace().asString(), properties);
|
||||
}
|
||||
|
||||
static {
|
||||
|
@ -52,17 +52,17 @@ class BlockTest implements Block {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable NBTCompound getNbt() {
|
||||
public @Nullable NBTCompound nbt() {
|
||||
return compound != null ? compound.deepClone() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BlockHandler getHandler() {
|
||||
public @Nullable BlockHandler handler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Map<String, String> getProperties() {
|
||||
public @NotNull Map<String, String> properties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package net.minestom.server.item;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.minestom.server.adventure.AdventureSerializer;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.item.attribute.ItemAttribute;
|
||||
import net.minestom.server.tag.Tag;
|
||||
@ -156,7 +155,7 @@ public abstract class ItemMetaBuilder implements TagWritable {
|
||||
this.canPlaceOn = blocks;
|
||||
handleCollection(canPlaceOn, "CanPlaceOn", nbt, () -> {
|
||||
NBTList<NBTString> list = new NBTList<>(NBTTypes.TAG_String);
|
||||
canPlaceOn.forEach(block -> list.add(new NBTString(block.getName())));
|
||||
canPlaceOn.forEach(block -> list.add(new NBTString(block.name())));
|
||||
nbt.set("CanPlaceOn", list);
|
||||
return list;
|
||||
});
|
||||
@ -173,7 +172,7 @@ public abstract class ItemMetaBuilder implements TagWritable {
|
||||
this.canDestroy = blocks;
|
||||
handleCollection(canDestroy, "CanDestroy", nbt, () -> {
|
||||
NBTList<NBTString> list = new NBTList<>(NBTTypes.TAG_String);
|
||||
canDestroy.forEach(block -> list.add(new NBTString(block.getName())));
|
||||
canDestroy.forEach(block -> list.add(new NBTString(block.name())));
|
||||
nbt.set("CanDestroy", list);
|
||||
return list;
|
||||
});
|
||||
|
@ -91,7 +91,7 @@ public class BlockPlacementListener {
|
||||
//after rapid invalid block placements
|
||||
BlockChangePacket blockChangePacket = new BlockChangePacket();
|
||||
blockChangePacket.blockPosition = blockPosition;
|
||||
blockChangePacket.blockStateId = Block.AIR.getStateId();
|
||||
blockChangePacket.blockStateId = Block.AIR.stateId();
|
||||
player.getPlayerConnection().sendPacket(blockChangePacket);
|
||||
}
|
||||
return;
|
||||
|
@ -181,7 +181,7 @@ public class PlayerDiggingListener {
|
||||
@NotNull ClientPlayerDiggingPacket.Status status, boolean success) {
|
||||
AcknowledgePlayerDiggingPacket acknowledgePlayerDiggingPacket = new AcknowledgePlayerDiggingPacket();
|
||||
acknowledgePlayerDiggingPacket.blockPosition = blockPosition;
|
||||
acknowledgePlayerDiggingPacket.blockStateId = block.getStateId();
|
||||
acknowledgePlayerDiggingPacket.blockStateId = block.stateId();
|
||||
acknowledgePlayerDiggingPacket.status = status;
|
||||
acknowledgePlayerDiggingPacket.successful = success;
|
||||
|
||||
|
@ -58,7 +58,7 @@ public class TagsPacket implements ServerPacket {
|
||||
writer.writeVarInt(-1);
|
||||
continue;
|
||||
}
|
||||
writer.writeVarInt(b.getId());
|
||||
writer.writeVarInt(b.id());
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -7,16 +7,16 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface ProtocolObject extends Keyed {
|
||||
|
||||
@NotNull NamespaceID getNamespaceId();
|
||||
@NotNull NamespaceID namespace();
|
||||
|
||||
@Override
|
||||
default @NotNull Key key() {
|
||||
return getNamespaceId();
|
||||
return namespace();
|
||||
}
|
||||
|
||||
default @NotNull String getName() {
|
||||
return getNamespaceId().asString();
|
||||
default @NotNull String name() {
|
||||
return namespace().asString();
|
||||
}
|
||||
|
||||
int getId();
|
||||
int id();
|
||||
}
|
||||
|
@ -44,8 +44,8 @@ public class BiomeParticles {
|
||||
public NBTCompound toNbt() {
|
||||
NBTCompound nbtCompound = new NBTCompound();
|
||||
nbtCompound.setString("type", type);
|
||||
nbtCompound.setString("Name", block.getName());
|
||||
Map<String, String> propertiesMap = block.getProperties();
|
||||
nbtCompound.setString("Name", block.name());
|
||||
Map<String, String> propertiesMap = block.properties();
|
||||
if (propertiesMap.size() != 0) {
|
||||
NBTCompound properties = new NBTCompound();
|
||||
propertiesMap.forEach(properties::setString);
|
||||
|
@ -9,10 +9,10 @@ import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
@Mixin(DynamicChunk.class)
|
||||
public class DynamicChunkMixin {
|
||||
|
||||
@ModifyVariable(method = "UNSAFE_setBlock", at = @At("HEAD"), index = 4, require = 1, argsOnly = true, remap = false)
|
||||
@ModifyVariable(method = "setBlock", at = @At("HEAD"), index = 4, require = 1, argsOnly = true, remap = false)
|
||||
public int oopsAllTnt(short blockStateId) {
|
||||
if(blockStateId != 0)
|
||||
return Block.TNT.getId();
|
||||
return Block.TNT.id();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user