seat riding gate fix

This commit is contained in:
Darto KLoning
2026-10-03 12:00:13 +07:00
parent 258354b7d9
commit 57ee17b56c
9 changed files with 40 additions and 37 deletions
@@ -92,19 +92,13 @@ public class ChairBlock extends HorizontalDirectionalBlock implements SittableBl
protected InteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
InteractionResult result = InteractionUtils.interactOptionalCushion(state, level, pos, player, stack, COLOR);
if (result != InteractionResult.TRY_WITH_EMPTY_HAND) return result;
if (this.sitOn(level, pos, player, state.getValue(FACING))) {
return InteractionResult.CONSUME;
}
return InteractionResult.CONSUME;
return InteractionResult.TRY_WITH_EMPTY_HAND;
}
@Override
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) {
return this.sitOn(level, pos, player, state.getValue(FACING))
? InteractionResult.SUCCESS
: InteractionResult.PASS;
this.sitOn(level, pos, player, state.getValue(FACING));
return InteractionResult.SUCCESS;
}
@Override
@@ -36,10 +36,8 @@ public class CushionBlock extends Block implements SittableBlock {
@Override
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) {
if (this.sitOn(level, pos, player, null)) {
return InteractionResult.CONSUME;
}
return InteractionResult.CONSUME;
this.sitOn(level, pos, player, null);
return InteractionResult.SUCCESS;
}
@Override
@@ -63,17 +63,13 @@ public class DiningBenchBlock extends HorizontalDirectionalBlock implements Sitt
@Override
protected InteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
if (this.sitOn(level, pos, player, null)) {
return InteractionResult.CONSUME;
}
return InteractionResult.CONSUME;
return InteractionResult.TRY_WITH_EMPTY_HAND;
}
@Override
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) {
return this.sitOn(level, pos, player, null)
? InteractionResult.SUCCESS
: InteractionResult.PASS;
this.sitOn(level, pos, player, null);
return InteractionResult.SUCCESS;
}
@Override
@@ -89,17 +89,13 @@ public abstract class ModularSeatBlock extends HorizontalDirectionalBlock implem
@Override
protected InteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
if (this.sitOn(level, pos, player, state.getValue(FACING))) {
return InteractionResult.CONSUME;
}
return InteractionResult.CONSUME;
return InteractionResult.TRY_WITH_EMPTY_HAND;
}
@Override
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) {
return this.sitOn(level, pos, player, state.getValue(FACING))
? InteractionResult.SUCCESS
: InteractionResult.PASS;
this.sitOn(level, pos, player, state.getValue(FACING));
return InteractionResult.SUCCESS;
}
@Override
@@ -10,11 +10,6 @@ import net.minecraft.world.phys.AABB;
public interface SittableBlock {
default boolean sitOn(Level level, BlockPos pos, Player player, Direction dir) {
// Keep seating server-authoritative. On the client, report a handled
// interaction so Minecraft sends/keeps the block-use interaction path.
if (level.isClientSide()) {
return true;
}
return Seat.sit(player, pos, this.getSeatHeight(level.getBlockState(pos)), dir);
}
@@ -1,6 +1,9 @@
package earth.terrarium.handcrafted.common.entities;
import earth.terrarium.handcrafted.Handcrafted;
import earth.terrarium.handcrafted.common.blocks.base.SittableBlock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import earth.terrarium.handcrafted.common.registry.ModEntityTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
@@ -20,6 +23,7 @@ import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
public class Seat extends Entity {
private static final Logger LOGGER = LoggerFactory.getLogger(Handcrafted.MOD_ID + "/Seat");
private boolean canRotate;
public Seat(EntityType<? extends Entity> entityType, Level level) {
@@ -39,10 +43,17 @@ public class Seat extends Entity {
public static boolean sit(Player player, BlockPos pos, double seatHeight, Direction dir) {
Level level = player.level();
if (!level.isClientSide() && availableAt(level, pos)) {
if (level.isClientSide()) {
return false;
}
boolean available = availableAt(level, pos);
LOGGER.info("Seat attempt: player={}, pos={}, height={}, direction={}, available={}", player.getName().getString(), pos, seatHeight, dir, available);
if (available) {
Seat seat = new Seat(level, pos, seatHeight, dir);
level.addFreshEntity(seat);
if (player.startRiding(seat)) {
boolean spawned = level.addFreshEntity(seat);
boolean mounted = spawned && player.startRiding(seat);
LOGGER.info("Seat result: spawned={}, mounted={}, seatId={}", spawned, mounted, seat.getId());
if (mounted) {
return true;
}
seat.discard();
@@ -19,7 +19,6 @@ public class ModEntityTypes {
public static final RegistryEntry<EntityType<Seat>> SEAT = ENTITY_TYPES.register("seat", () ->
EntityType.Builder.<Seat>of(Seat::new, MobCategory.MISC)
.sized(0, 0)
.noSave()
.fireImmune()
.noSummon()
.build(ResourceKey.create(Registries.ENTITY_TYPE, Identifier.fromNamespaceAndPath(Handcrafted.MOD_ID, "seat"))));