Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Commit

Permalink
better armourstand positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
BradBot1 committed May 9, 2021
1 parent d73ed00 commit d410d41
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
27 changes: 26 additions & 1 deletion src/main/java/com/bb1/sit/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
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;
import net.minecraft.server.command.ServerCommandSource;
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
Expand Down Expand Up @@ -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;
}));
Expand Down Expand Up @@ -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;
}


}
2 changes: 1 addition & 1 deletion src/main/java/com/bb1/sit/mixins/InteractModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d410d41

Please sign in to comment.