mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Use climbable block tag and TrapDoorBlock
This commit is contained in:
parent
814784823c
commit
30a37fa8a5
3 changed files with 11 additions and 34 deletions
|
|
@ -44,9 +44,11 @@ import org.geysermc.geyser.level.block.property.Properties;
|
|||
import org.geysermc.geyser.level.block.type.BedBlock;
|
||||
import org.geysermc.geyser.level.block.type.Block;
|
||||
import org.geysermc.geyser.level.block.type.BlockState;
|
||||
import org.geysermc.geyser.level.block.type.TrapDoorBlock;
|
||||
import org.geysermc.geyser.level.physics.BoundingBox;
|
||||
import org.geysermc.geyser.level.physics.CollisionManager;
|
||||
import org.geysermc.geyser.level.physics.Direction;
|
||||
import org.geysermc.geyser.session.cache.tags.BlockTag;
|
||||
import org.geysermc.geyser.translator.collision.BlockCollision;
|
||||
import org.geysermc.geyser.translator.collision.SolidCollision;
|
||||
import org.geysermc.geyser.util.BlockUtils;
|
||||
|
|
@ -379,7 +381,7 @@ public class VehicleComponent<T extends LivingEntity & ClientVehicle> {
|
|||
|
||||
protected void landMovement() {
|
||||
float gravity = getGravity();
|
||||
float slipperiness = BlockStateValues.getSlipperiness(getBlockId(getVelocityAffectingPos()));
|
||||
float slipperiness = BlockStateValues.getSlipperiness(getBlockState(getVelocityAffectingPos()));
|
||||
float drag = vehicle.isOnGround() ? 0.91f * slipperiness : 0.91f;
|
||||
float speed = vehicle.getVehicleSpeed() * (vehicle.isOnGround() ? BASE_SLIPPERINESS_CUBED / (slipperiness * slipperiness * slipperiness) : 0.1f);
|
||||
|
||||
|
|
@ -595,17 +597,17 @@ public class VehicleComponent<T extends LivingEntity & ClientVehicle> {
|
|||
}
|
||||
|
||||
Vector3i blockPos = boundingBox.getBottomCenter().toInt();
|
||||
int blockId = getBlockId(blockPos);
|
||||
BlockState blockState = getBlockState(blockPos);
|
||||
|
||||
if (BlockStateValues.isClimbable(blockId)) {
|
||||
if (vehicle.getSession().getTagCache().is(BlockTag.CLIMBABLE, blockState.block())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if the vehicle is in an open trapdoor with a ladder of the same direction under it
|
||||
Direction openTrapdoorDirection = BlockStateValues.getOpenTrapdoorDirection(blockId);
|
||||
if (openTrapdoorDirection != null) {
|
||||
BlockState ladder = getBlockState(blockPos.down());
|
||||
return ladder.is(Blocks.LADDER) && ladder.getValue(Properties.HORIZONTAL_FACING) == openTrapdoorDirection;
|
||||
if (blockState.block() instanceof TrapDoorBlock && blockState.getValue(Properties.OPEN)) {
|
||||
BlockState ladderState = getBlockState(blockPos.down());
|
||||
return ladderState.is(Blocks.LADDER) &&
|
||||
ladderState.getValue(Properties.HORIZONTAL_FACING) == blockState.getValue(Properties.HORIZONTAL_FACING);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ package org.geysermc.geyser.level.block;
|
|||
import it.unimi.dsi.fastutil.ints.*;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.geysermc.geyser.level.block.property.Properties;
|
||||
import org.geysermc.geyser.level.block.type.Block;
|
||||
import org.geysermc.geyser.level.block.type.BlockState;
|
||||
|
|
@ -50,8 +49,6 @@ public final class BlockStateValues {
|
|||
private static final IntSet ALL_PISTON_HEADS = new IntOpenHashSet();
|
||||
private static final Int2IntMap WATER_LEVEL = new Int2IntOpenHashMap();
|
||||
private static final Int2IntMap LAVA_LEVEL = new Int2IntOpenHashMap();
|
||||
private static final IntSet ALL_CLIMBABLE = new IntOpenHashSet();
|
||||
private static final Int2ObjectMap<Direction> OPEN_TRAPDOOR_DIRECTION = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
public static int JAVA_WATER_ID;
|
||||
|
||||
|
|
@ -99,14 +96,6 @@ public final class BlockStateValues {
|
|||
HORIZONTAL_FACING_JIGSAWS.add(javaBlockState);
|
||||
}
|
||||
}
|
||||
|
||||
if (javaId.contains("vine") || javaId.startsWith("minecraft:ladder") || javaId.startsWith("minecraft:scaffolding")) {
|
||||
ALL_CLIMBABLE.add(javaBlockState);
|
||||
}
|
||||
|
||||
if (javaId.contains("_trapdoor[") && javaId.contains("open=true")) {
|
||||
OPEN_TRAPDOOR_DIRECTION.put(javaBlockState, getBlockDirection(javaId));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -288,10 +277,6 @@ public final class BlockStateValues {
|
|||
return -1;
|
||||
}
|
||||
|
||||
public static boolean isClimbable(int state) {
|
||||
return ALL_CLIMBABLE.contains(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the slipperiness of a block.
|
||||
* This is used in ItemEntity to calculate the friction on an item as it slides across the ground
|
||||
|
|
@ -313,17 +298,6 @@ public final class BlockStateValues {
|
|||
return 0.6f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the direction of an open trapdoor.
|
||||
* Used when determining if an entity is climbing
|
||||
*
|
||||
* @param state BlockState of the block
|
||||
* @return The open trapdoor's direction, or null if not an open trapdoor
|
||||
*/
|
||||
public static @Nullable Direction getOpenTrapdoorDirection(int state) {
|
||||
return OPEN_TRAPDOOR_DIRECTION.get(state);
|
||||
}
|
||||
|
||||
private static Direction getBlockDirection(String javaId) {
|
||||
if (javaId.contains("down")) {
|
||||
return Direction.DOWN;
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@ public enum BlockTag {
|
|||
SHOVEL_EFFECTIVE("mineable/shovel"),
|
||||
NEEDS_STONE_TOOL("needs_stone_tool"),
|
||||
NEEDS_IRON_TOOL("needs_iron_tool"),
|
||||
NEEDS_DIAMOND_TOOL("needs_diamond_tool");
|
||||
NEEDS_DIAMOND_TOOL("needs_diamond_tool"),
|
||||
CLIMBABLE("climbable");
|
||||
|
||||
BlockTag(String identifier) {
|
||||
register(identifier, this);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue