generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Generic run function for sit-based poses - Class abstraction to prevent instantiation
- Loading branch information
Showing
9 changed files
with
90 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/net/fill1890/fabsit/command/GenericSitBasedCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package net.fill1890.fabsit.command; | ||
|
||
import com.mojang.brigadier.context.CommandContext; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import net.fill1890.fabsit.config.ConfigManager; | ||
import net.fill1890.fabsit.entity.Pose; | ||
import net.fill1890.fabsit.entity.PoseManagerEntity; | ||
import net.fill1890.fabsit.error.PoseException; | ||
import net.fill1890.fabsit.util.Messages; | ||
import net.fill1890.fabsit.util.PoseTest; | ||
import net.minecraft.server.command.ServerCommandSource; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.text.Text; | ||
|
||
/** | ||
* Generic sit-based command class | ||
* <br> | ||
* Implementation details taken from <a href="https://github.com/Gecolay/GSit">GSit</a> | ||
*/ | ||
public abstract class GenericSitBasedCommand { | ||
public static int run(CommandContext<ServerCommandSource> context, Pose pose) { | ||
final ServerCommandSource source = context.getSource(); | ||
ServerPlayerEntity player; | ||
|
||
try { | ||
player = source.getPlayerOrThrow(); | ||
} catch (CommandSyntaxException e) { | ||
source.sendError(Text.of("You must be a player to run this command!")); | ||
return -1; | ||
} | ||
|
||
// check the pose is config-enabled | ||
try { | ||
PoseTest.confirmEnabled(pose); | ||
} catch(PoseException e) { | ||
if(ConfigManager.getConfig().enable_messages.pose_errors) | ||
Messages.sendByException(player, pose, e); | ||
return -1; | ||
} | ||
|
||
|
||
// toggle sitting if the player was sat down | ||
if(player.hasVehicle()) { | ||
player.dismountVehicle(); | ||
// TODO: should be able to add to manager? | ||
player.teleport(player.getX(), player.getY() + 0.6, player.getZ()); | ||
return 1; | ||
} | ||
|
||
// confirm player can pose right now | ||
try { | ||
PoseTest.confirmPosable(player); | ||
} catch (PoseException e) { | ||
if(ConfigManager.getConfig().enable_messages.pose_errors) | ||
Messages.sendByException(player, pose, e); | ||
return -1; | ||
} | ||
|
||
// create a new pose manager for laying and sit the player down | ||
// (player is then invisible and an npc lays down) | ||
PoseManagerEntity chair = new PoseManagerEntity(player.getPos(), pose, player); | ||
player.getEntityWorld().spawnEntity(chair); | ||
player.startRiding(chair, true); | ||
|
||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters