mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-20 00:13:21 +02:00
Merge branch '1.21.4' into 1.21.1
# Conflicts: # changelog.md # gradle.properties # src/main/java/one/oth3r/sit/screen/ClickableImageWidget.java # src/main/java/one/oth3r/sit/screen/ConfigScreen.java # src/main/java/one/oth3r/sit/screen/TextureButtonWidget.java
This commit is contained in:
commit
b7b3b39d82
65 changed files with 960 additions and 528 deletions
|
@ -1,5 +1,8 @@
|
|||
package one.oth3r.sit.utl;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.ParseResults;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
|
||||
|
@ -14,17 +17,19 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
|||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Formatting;
|
||||
import one.oth3r.sit.SitClient;
|
||||
import one.oth3r.sit.command.SitCommand;
|
||||
import one.oth3r.sit.file.FileData;
|
||||
import one.oth3r.sit.file.LangReader;
|
||||
import one.oth3r.sit.file.SittingConfig;
|
||||
import one.oth3r.sit.packet.SitPayloads;
|
||||
import one.oth3r.sit.screen.ConfigScreen;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class Events {
|
||||
|
||||
private static class Keybindings {
|
||||
|
@ -54,7 +59,7 @@ public class Events {
|
|||
ClientPlayerEntity player = client.player;
|
||||
|
||||
while (config__key.wasPressed()) {
|
||||
client.setScreen(new ConfigScreen(client.currentScreen));
|
||||
client.setScreen(SitClient.getConfigScreen(client.currentScreen));
|
||||
}
|
||||
|
||||
/// anything below uses the player object, make sure it's not null
|
||||
|
@ -74,7 +79,7 @@ public class Events {
|
|||
} else {
|
||||
// unsupported server message if not in a Sit! server
|
||||
player.sendMessage(Utl.lang("sit!.chat.unsupported")
|
||||
.formatted(Formatting.RED), true);
|
||||
.color(Color.RED).b(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +104,7 @@ public class Events {
|
|||
ServerPlayNetworking.send(context.player(),new SitPayloads.ResponsePayload(SitPayloads.ResponsePayload.VERSION));
|
||||
|
||||
// log the receiving of the packet from the player
|
||||
Data.LOGGER.info(Utl.lang("sit!.console.player_settings",context.player().getName().getString()).getString());
|
||||
Data.LOGGER.info(Utl.lang("sit!.console.player_settings",context.player().getName().getString()).toString());
|
||||
})));
|
||||
}
|
||||
|
||||
|
@ -109,7 +114,7 @@ public class Events {
|
|||
// only update when needed
|
||||
if (!Data.isSupportedServer()) {
|
||||
Data.setSupportedServer(true);
|
||||
Data.LOGGER.info(Utl.lang("sit!.console.connected",payload.value()).getString());
|
||||
Data.LOGGER.info(Utl.lang("sit!.console.connected",payload.value()).toString());
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
@ -179,7 +184,19 @@ public class Events {
|
|||
if (player == null || player.isSpectator()) return ActionResult.PASS;
|
||||
|
||||
// consume if sitting, if not pass
|
||||
return Logic.sit(player,hitResult.getBlockPos(),hitResult) ? ActionResult.CONSUME : ActionResult.PASS;
|
||||
ActionResult result = Logic.canSit(player,hitResult.getBlockPos(),hitResult) ? ActionResult.CONSUME : ActionResult.PASS;
|
||||
// todo test
|
||||
if (result.equals(ActionResult.CONSUME)) {
|
||||
try {
|
||||
CommandDispatcher<ServerCommandSource> dispatcher = Data.getServer().getCommandSource().getDispatcher();
|
||||
ParseResults<ServerCommandSource> parse = dispatcher.parse("sit", player.getCommandSource());
|
||||
dispatcher.execute(parse);
|
||||
} catch (CommandSyntaxException e) {
|
||||
Data.LOGGER.error("Error executing sit command for player {}", player.getName().getString());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package one.oth3r.sit.utl;
|
||||
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.entity.decoration.DisplayEntity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
|
@ -9,14 +8,21 @@ import net.minecraft.util.Formatting;
|
|||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import one.oth3r.sit.file.FileData;
|
||||
import one.oth3r.sit.file.ServerConfig;
|
||||
import one.oth3r.sit.file.SittingConfig;
|
||||
import one.oth3r.sit.file.HandSetting;
|
||||
import one.oth3r.sit.file.*;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class Logic {
|
||||
public static boolean sit(ServerPlayerEntity player, BlockPos blockPos, @Nullable BlockHitResult hitResult) {
|
||||
|
||||
/**
|
||||
* checks if the player can sit at the block specified
|
||||
* @param player the player that's going to sit
|
||||
* @param blockPos the position that the player is going to sit at
|
||||
* @param hitResult nullable, not null if the player is sitting with their hand
|
||||
* @return true if the player can sit with the conditions provided
|
||||
*/
|
||||
public static boolean canSit(ServerPlayerEntity player, BlockPos blockPos, @Nullable BlockHitResult hitResult) {
|
||||
// cant sit if crouching
|
||||
if (player.isSneaking()) return false;
|
||||
|
||||
|
@ -32,22 +38,44 @@ public class Logic {
|
|||
if (!checkYLimits(player, blockPos)) return false;
|
||||
|
||||
ServerWorld serverWorld = player.getServerWorld();
|
||||
BlockState blockState = serverWorld.getBlockState(blockPos);
|
||||
|
||||
Double sitHeight = Utl.getSittingHeight(blockState,player,blockPos,hitResult);
|
||||
Double sitHeight = Utl.getSittingHeight(player,blockPos,hitResult);
|
||||
|
||||
// if the sit height is null, its not a sittable block
|
||||
// if the sit height is null, it's not a sittable block
|
||||
if (sitHeight == null) return false;
|
||||
|
||||
DisplayEntity.TextDisplayEntity entity = Utl.Entity.create(serverWorld,blockPos,sitHeight);
|
||||
|
||||
if (!checkPlayerSitAbility(entity)) return false;
|
||||
// checks if the player can sit
|
||||
return checkPlayerSitAbility(entity);
|
||||
}
|
||||
|
||||
Utl.Entity.spawnSit(player, entity);
|
||||
/**
|
||||
* makes the player attempt to sit at the position provided (checks if the player can sit before)
|
||||
* @param player the player that is sitting
|
||||
* @param blockPos the pos the player is going to sit at
|
||||
* @param hitResult nullable, not null if the player is sitting with their hand
|
||||
* @return true if sitting was successful
|
||||
*/
|
||||
public static boolean sit(ServerPlayerEntity player, BlockPos blockPos, @Nullable BlockHitResult hitResult) {
|
||||
if (!canSit(player, blockPos, hitResult)) return false;
|
||||
// assets
|
||||
ServerWorld serverWorld = player.getServerWorld();
|
||||
Double sitHeight = Utl.getSittingHeight(player,blockPos,hitResult);
|
||||
// shouldn't be null because we already checked, but do another check to clear IDE errors
|
||||
assert sitHeight != null;
|
||||
|
||||
// spawn the entity and make the player sit
|
||||
Utl.Entity.spawnSit(player, Utl.Entity.create(serverWorld,blockPos,sitHeight));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* makes the player attempt to sit at the block they are looking at (range of 5)
|
||||
* @param player the player who is trying to sit
|
||||
* @return true if sitting was successful
|
||||
*/
|
||||
public static boolean sitLooking(ServerPlayerEntity player) {
|
||||
return sit(player, Utl.getBlockPosPlayerIsLookingAt(player.getServerWorld(),player,5),null);
|
||||
}
|
||||
|
@ -172,6 +200,7 @@ public class Logic {
|
|||
public static void reload() {
|
||||
FileData.loadFiles();
|
||||
FileData.saveFiles();
|
||||
LangReader.loadLanguageFile();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,11 +228,11 @@ public class Logic {
|
|||
|
||||
// send the player the actionbar message
|
||||
return Utl.lang("sit!.chat.toggle_sit",
|
||||
Utl.lang(messageKey).formatted(messageColor));
|
||||
Utl.lang(messageKey).color(config.getEnabled()? Color.GREEN : Color.RED)).b();
|
||||
} else {
|
||||
// unsupported server message if not in a Sit! server
|
||||
return Utl.lang("sit!.chat.unsupported")
|
||||
.formatted(Formatting.RED);
|
||||
.color(Color.RED).b();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,9 +17,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TextColor;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
|
@ -27,11 +25,13 @@ import net.minecraft.util.math.BlockPos;
|
|||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.RaycastContext;
|
||||
import net.minecraft.world.World;
|
||||
import one.oth3r.otterlib.chat.CTxT;
|
||||
import one.oth3r.sit.file.*;
|
||||
import one.oth3r.sit.packet.SitPayloads;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
@ -152,14 +152,15 @@ public class Utl {
|
|||
|
||||
/**
|
||||
* gets the sitting height for the provided blockstate, via memory loaded config from Data
|
||||
* @param blockState the state of the block
|
||||
* @param player the player to
|
||||
* @param blockPos the pos of the block
|
||||
* @param hit nullable, for the player interaction check
|
||||
* @return null if not a valid block
|
||||
*/
|
||||
public static Double getSittingHeight(BlockState blockState, ServerPlayerEntity player, BlockPos blockPos, @Nullable BlockHitResult hit) {
|
||||
public static Double getSittingHeight(ServerPlayerEntity player, BlockPos blockPos, @Nullable BlockHitResult hit) {
|
||||
ServerWorld serverWorld = player.getServerWorld();
|
||||
ServerConfig config = FileData.getServerConfig();
|
||||
BlockState blockState = serverWorld.getBlockState(blockPos);
|
||||
Block block = blockState.getBlock();
|
||||
|
||||
// make sure that the block that is being sit on has no interaction when hand sitting
|
||||
|
@ -217,7 +218,7 @@ public class Utl {
|
|||
// get the blockstate
|
||||
BlockState blockState = player.getWorld().getBlockState(blockPos);
|
||||
// check if the block is still there & the block is a valid sit block (by checking if there is a sit height for the block)
|
||||
return !blockState.isAir() && getSittingHeight(blockState,player,blockPos,null) != null;
|
||||
return !blockState.isAir() && getSittingHeight(player,blockPos,null) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -318,26 +319,32 @@ public class Utl {
|
|||
|
||||
// send a message if needed
|
||||
if (message) {
|
||||
player.sendMessage(messageTag().append(Utl.lang("sit!.chat.purged",Utl.lang("sit!.chat.purged.total",count).styled(
|
||||
style -> style.withColor(Colors.LIGHT_GRAY).withItalic(true)
|
||||
)).styled(
|
||||
style -> style.withColor(Colors.GREEN)
|
||||
)));
|
||||
player.sendMessage(messageTag()
|
||||
.append(lang("sit!.chat.purged",lang("sit!.chat.purged.total",count).color(Color.gray).b()).color(Color.GREEN)).b());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static MutableText messageTag() {
|
||||
return Text.literal("[").append(Text.literal("Sit!").styled(
|
||||
style -> style.withColor(TextColor.parse("#c400ff").result().orElse(TextColor.fromFormatting(Formatting.DARK_PURPLE))))
|
||||
).append("] ");
|
||||
public static CTxT messageTag() {
|
||||
return new CTxT("Sit!").btn(true).color(Color.decode("#c400ff")).append(" ");
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a MutableText using the language key, if on server, using the custom lang reader
|
||||
*/
|
||||
public static MutableText lang(String key, Object... args) {
|
||||
if (Data.isClient()) return Text.translatable(key, args);
|
||||
public static CTxT lang(String key, Object... args) {
|
||||
if (Data.isClient()) {
|
||||
// we have to first convert all the CTxT's to the built version because minecraft lang reader doesn't know how to process it
|
||||
// make a array with the same size of the args
|
||||
Object[] fixedArgs = new Object[args.length];
|
||||
// for every arg, build & add if CTxT or just add if not
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
if (args[i] instanceof CTxT) fixedArgs[i] = ((CTxT) args[i]).b();
|
||||
else fixedArgs[i] = args[i];
|
||||
}
|
||||
// return the translated text
|
||||
return new CTxT(Text.translatable(key,fixedArgs));
|
||||
}
|
||||
else return LangReader.of(key, args).getTxT();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue