mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-20 00:13:21 +02:00
make a common sit method
This commit is contained in:
parent
911133de23
commit
8b78bf4651
2 changed files with 27 additions and 29 deletions
|
@ -167,6 +167,24 @@ public class Events {
|
||||||
if (entity.getY() <= pos.getY()+.35+oneTwentyTwo) entity.setPitch(90); // below
|
if (entity.getY() <= pos.getY()+.35+oneTwentyTwo) entity.setPitch(90); // below
|
||||||
else entity.setPitch(-90); // above
|
else entity.setPitch(-90); // above
|
||||||
}
|
}
|
||||||
|
public static boolean sit(ServerPlayerEntity player, BlockPos pos) {
|
||||||
|
// todo interactions entity to make the sitting hitbox?
|
||||||
|
World world = player.getWorld();
|
||||||
|
DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld());
|
||||||
|
setEntity(pos,world,entity);
|
||||||
|
if (checkBlocks(pos,world,isAboveBlockheight(entity))) {
|
||||||
|
if (entities.containsKey(player)) {
|
||||||
|
if (!config.sitWhileSeated) return false;
|
||||||
|
entities.get(player).setRemoved(Entity.RemovalReason.DISCARDED);
|
||||||
|
entities.remove(player);
|
||||||
|
}
|
||||||
|
player.getServerWorld().spawnEntity(entity);
|
||||||
|
player.startRiding(entity);
|
||||||
|
entities.put(player,entity);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
public static void register() {
|
public static void register() {
|
||||||
ServerTickEvents.END_SERVER_TICK.register(minecraftServer -> minecraftServer.execute(Events::cleanUp));
|
ServerTickEvents.END_SERVER_TICK.register(minecraftServer -> minecraftServer.execute(Events::cleanUp));
|
||||||
// PLAYER JOIN
|
// PLAYER JOIN
|
||||||
|
@ -196,22 +214,12 @@ public class Events {
|
||||||
if (player == null) return ActionResult.PASS;
|
if (player == null) return ActionResult.PASS;
|
||||||
if (hand == net.minecraft.util.Hand.MAIN_HAND && hitResult.getType() == HitResult.Type.BLOCK) {
|
if (hand == net.minecraft.util.Hand.MAIN_HAND && hitResult.getType() == HitResult.Type.BLOCK) {
|
||||||
BlockPos pos = hitResult.getBlockPos();
|
BlockPos pos = hitResult.getBlockPos();
|
||||||
|
// check the players hands
|
||||||
if (!checkLogic(player)) return ActionResult.PASS;
|
if (!checkLogic(player)) return ActionResult.PASS;
|
||||||
// todo interactions entity to make the hitbox?
|
// make the player sit
|
||||||
// make the entity first before checking to make sure the blocks around are fine
|
boolean status = sit(player,pos);
|
||||||
DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld());
|
// if sat, cancel / FAIL the use block event
|
||||||
setEntity(pos,world,entity);
|
if (status) return ActionResult.FAIL;
|
||||||
if (checkBlocks(pos,world,isAboveBlockheight(entity))) {
|
|
||||||
if (entities.containsKey(player)) {
|
|
||||||
if (!config.sitWhileSeated) return ActionResult.PASS;
|
|
||||||
entities.get(player).setRemoved(Entity.RemovalReason.DISCARDED);
|
|
||||||
entities.remove(player);
|
|
||||||
}
|
|
||||||
player.getServerWorld().spawnEntity(entity);
|
|
||||||
player.startRiding(entity);
|
|
||||||
entities.put(player,entity);
|
|
||||||
return ActionResult.FAIL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ActionResult.PASS;
|
return ActionResult.PASS;
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,15 +7,12 @@ import com.mojang.brigadier.context.CommandContext;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import com.mojang.brigadier.suggestion.Suggestions;
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
import net.minecraft.entity.EntityType;
|
|
||||||
import net.minecraft.entity.decoration.DisplayEntity;
|
|
||||||
import net.minecraft.server.command.CommandManager;
|
import net.minecraft.server.command.CommandManager;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.TextColor;
|
import net.minecraft.text.TextColor;
|
||||||
import net.minecraft.util.Formatting;
|
import net.minecraft.util.Formatting;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@ -55,21 +52,14 @@ public class SitCommand {
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("sit")) {
|
if (args[0].equalsIgnoreCase("sit")) {
|
||||||
BlockPos pos = player.getBlockPos();
|
BlockPos pos = player.getBlockPos();
|
||||||
if (!(player.getY() -((int) player.getY()) > 0.00)) {
|
// get the block under the player if player on top of a solid
|
||||||
|
if (!(player.getY() - ((int) player.getY()) > 0.00)) {
|
||||||
pos = pos.add(0,-1,0);
|
pos = pos.add(0,-1,0);
|
||||||
}
|
}
|
||||||
World world = player.getWorld();
|
|
||||||
// if already sitting, ignore
|
// if already sitting, ignore
|
||||||
if (Events.entities.containsKey(player)) return 1;
|
if (Events.entities.containsKey(player)) return 1;
|
||||||
// make entity first to check the blocks
|
// sit
|
||||||
DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld());
|
Events.sit(player,pos);
|
||||||
Events.setEntity(pos,world,entity);
|
|
||||||
if (Events.checkBlocks(pos,world,Events.isAboveBlockheight(entity))) {
|
|
||||||
player.getServerWorld().spawnEntity(entity);
|
|
||||||
player.startRiding(entity);
|
|
||||||
Events.entities.put(player,entity);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("reload")) {
|
if (args[0].equalsIgnoreCase("reload")) {
|
||||||
config.load();
|
config.load();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue