From d410d4182e8b3a625ae8f460b34a644279ed82a5 Mon Sep 17 00:00:00 2001 From: BradBot1 Date: Sun, 9 May 2021 15:29:19 +0100 Subject: [PATCH] better armourstand positioning --- src/main/java/com/bb1/sit/Loader.java | 27 ++++++++++++++++++- .../com/bb1/sit/mixins/InteractModifier.java | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bb1/sit/Loader.java b/src/main/java/com/bb1/sit/Loader.java index a163b74..41e55c3 100644 --- a/src/main/java/com/bb1/sit/Loader.java +++ b/src/main/java/com/bb1/sit/Loader.java @@ -3,6 +3,7 @@ import net.fabricmc.api.DedicatedServerModInitializer; import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; import net.minecraft.block.BlockState; +import net.minecraft.command.argument.EntityAnchorArgumentType.EntityAnchor; import net.minecraft.entity.Entity; import net.minecraft.entity.decoration.ArmorStandEntity; import net.minecraft.server.command.CommandManager; @@ -10,6 +11,7 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; /** * Copyright 2021 BradBot_1 @@ -42,7 +44,7 @@ public void onInitializeServer() { } BlockState blockState = player.getEntityWorld().getBlockState(new BlockPos(player.getX(), player.getY()-1, player.getZ())); if (player.isFallFlying() || player.isSleeping() || player.isSwimming() || player.isSpectator() || blockState.isAir() || blockState.getMaterial().isLiquid()) return 0; - Entity entity = createChair(player.getEntityWorld(), player.getBlockPos(), 1.7); + Entity entity = createChair(player.getEntityWorld(), player.getBlockPos(), 1.7, player.getPos()); player.startRiding(entity, true); return 1; })); @@ -72,5 +74,28 @@ public boolean collides() { return entity; } + public static Entity createChair(World world, BlockPos blockPos, double yOffset, Vec3d target) { + ArmorStandEntity entity = new ArmorStandEntity(world, 0.5d+blockPos.getX(), blockPos.getY()-yOffset, 0.5d+blockPos.getZ()) { + + @Override + public boolean canMoveVoluntarily() { + return false; + } + + @Override + public boolean collides() { + return false; + } + + }; + entity.lookAt(EntityAnchor.EYES, target.subtract(0, (target.getY()*2), 0)); + entity.setInvisible(true); + entity.setInvulnerable(true); + entity.setCustomName(new LiteralText("FABRIC_SEAT")); + entity.setNoGravity(true); + world.spawnEntity(entity); + return entity; + } + } diff --git a/src/main/java/com/bb1/sit/mixins/InteractModifier.java b/src/main/java/com/bb1/sit/mixins/InteractModifier.java index f4a0cba..98a95de 100644 --- a/src/main/java/com/bb1/sit/mixins/InteractModifier.java +++ b/src/main/java/com/bb1/sit/mixins/InteractModifier.java @@ -51,7 +51,7 @@ public void inject(ServerPlayerEntity player, World world, ItemStack stack, Hand BlockState blockState = world.getBlockState(blockPos); Block block = blockState.getBlock(); if (!(block instanceof StairsBlock || block instanceof SlabBlock)) return; - Entity chair = Loader.createChair(world, blockPos, 1.2); + Entity chair = Loader.createChair(world, blockPos, 1.2, player.getPos()); Entity v = player.getVehicle(); if (v!=null) { player.setSneaking(true);