forked from virt-mirrors/Sit
Compare commits
57 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b7094bb437 | ||
![]() |
ebe2f66ff2 | ||
![]() |
0a093bebc0 | ||
![]() |
134496d7d0 | ||
![]() |
f774802d69 | ||
![]() |
2c4dc72f42 | ||
![]() |
65431280a3 | ||
![]() |
2e7967699e | ||
![]() |
e11b4acd35 | ||
![]() |
a878e2b41e | ||
![]() |
7658dbd40e | ||
![]() |
a971fa9926 | ||
![]() |
b5eaf3df7a | ||
![]() |
41abc4d361 | ||
![]() |
a9399fcbf9 | ||
![]() |
08788456b2 | ||
![]() |
de1e7d8d65 | ||
![]() |
1298e1940a | ||
![]() |
18ad774e63 | ||
![]() |
fda08029bb | ||
![]() |
2b661a0fa8 | ||
![]() |
aa59c9cdfd | ||
![]() |
9d6cc9b785 | ||
![]() |
0810fd64e8 | ||
![]() |
32a4b0006a | ||
![]() |
8b7b3d39ec | ||
![]() |
78f7d81d93 | ||
![]() |
77f59e7b6a | ||
![]() |
0065e7e33b | ||
![]() |
e772e5813a | ||
![]() |
7bf178a1d2 | ||
![]() |
6c3607f515 | ||
![]() |
1c70328b35 | ||
![]() |
32356d0c6d | ||
![]() |
4d7faf0397 | ||
![]() |
1368650a49 | ||
![]() |
f019b89647 | ||
![]() |
ada03ba40e | ||
![]() |
a7b70323e4 | ||
![]() |
af4ca45788 | ||
![]() |
01463a50b6 | ||
![]() |
fa968f17c2 | ||
![]() |
f98436a917 | ||
![]() |
6ea4831a1c | ||
![]() |
7eaf280a88 | ||
![]() |
4ec37db7b0 | ||
![]() |
be158c66ed | ||
![]() |
05eaedf503 | ||
![]() |
322b663358 | ||
![]() |
648f20e5db | ||
![]() |
df46547cbf | ||
![]() |
4e902c1236 | ||
![]() |
86676dd0a1 | ||
![]() |
61940e95db | ||
![]() |
25d524b081 | ||
![]() |
4eef33e6ae | ||
![]() |
a470896924 |
14 changed files with 138 additions and 117 deletions
|
@ -1,5 +1,5 @@
|
|||
plugins {
|
||||
id 'fabric-loom' version '1.8-SNAPSHOT'
|
||||
id 'fabric-loom' version '1.10-SNAPSHOT'
|
||||
id 'maven-publish'
|
||||
id 'com.modrinth.minotaur' version '2.+'
|
||||
id 'net.darkhax.curseforgegradle' version '1.1.+'
|
||||
|
@ -14,8 +14,8 @@ base {
|
|||
}
|
||||
|
||||
repositories {
|
||||
maven { url "https://maven.terraformersmc.com/releases/" }
|
||||
maven { url "https://maven.isxander.dev/releases" }
|
||||
maven { url = "https://maven.terraformersmc.com/releases/" }
|
||||
maven { url = "https://maven.isxander.dev/releases" }
|
||||
}
|
||||
|
||||
loom {
|
||||
|
@ -33,7 +33,7 @@ dependencies {
|
|||
}
|
||||
|
||||
processResources {
|
||||
filteringCharset "UTF-8"
|
||||
filteringCharset = "UTF-8"
|
||||
|
||||
var replaceProperties = [
|
||||
version : project.version,
|
||||
|
|
|
@ -4,16 +4,16 @@ org.gradle.parallel=true
|
|||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/develop
|
||||
min_minecraft_version=1.21.4
|
||||
minecraft_version=1.21.4
|
||||
yarn_mappings=1.21.4+build.8
|
||||
loader_version=0.16.10
|
||||
min_minecraft_version=1.20.1
|
||||
minecraft_version=1.20.1
|
||||
yarn_mappings=1.20.1+build.10
|
||||
loader_version=0.14.24
|
||||
|
||||
# Mod Properties
|
||||
mod_version=1.2.3+1.21.4
|
||||
mod_version=1.2.3+1.20.1
|
||||
maven_group=one.oth3r
|
||||
file_name=sit!
|
||||
|
||||
# Dependencies
|
||||
fabric_version=0.116.1+1.21.4
|
||||
modmenu_version=13.0.0-beta.1
|
||||
fabric_version=0.91.0+1.20.1
|
||||
modmenu_version=7.0.0
|
|
@ -96,7 +96,7 @@ public class CustomBlock {
|
|||
for (String tag : blockTags) {
|
||||
// substring to remove # and if needed, !
|
||||
// if there is a math for the NOT(!) tag, return false
|
||||
if (tag.startsWith("!") && blockState.isIn(TagKey.of(Registries.BLOCK.getKey(), Identifier.of(tag.substring(2))))) return false;
|
||||
if (tag.startsWith("!") && blockState.isIn(TagKey.of(Registries.BLOCK.getKey(), new Identifier(tag.substring(2))))) return false;
|
||||
// if there is a match, return true
|
||||
if (blockState.isIn(TagKey.of(Registries.BLOCK.getKey(), Identifier.tryParse(tag.substring(1))))) tagCheck = true;
|
||||
}
|
||||
|
|
|
@ -53,10 +53,10 @@ public class CustomItem {
|
|||
// if a NOT tag
|
||||
if (tag.startsWith("!")) {
|
||||
// if there is a math for the NOT(!) tag, return false
|
||||
if (itemStack.isIn(TagKey.of(Registries.ITEM.getKey(), Identifier.of(tag.substring(2))))) return false;
|
||||
if (itemStack.isIn(TagKey.of(Registries.ITEM.getKey(), new Identifier(tag.substring(2))))) return false;
|
||||
}
|
||||
// else (normal tag), if there is a match, set tagCheck to true
|
||||
else if (itemStack.isIn(TagKey.of(Registries.ITEM.getKey(), Identifier.of(tag.substring(1))))) tagCheck = true;
|
||||
else if (itemStack.isIn(TagKey.of(Registries.ITEM.getKey(), new Identifier(tag.substring(1))))) tagCheck = true;
|
||||
}
|
||||
|
||||
// not returning true in the loop because there might be a (!) not tag that the item might fall into, after the item was already in another tag
|
||||
|
|
38
src/main/java/one/oth3r/sit/packet/PacketSender.java
Normal file
38
src/main/java/one/oth3r/sit/packet/PacketSender.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package one.oth3r.sit.packet;
|
||||
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import one.oth3r.sit.utl.Data;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class PacketSender {
|
||||
private final PacketByteBuf data = PacketByteBufs.create();
|
||||
private final PacketType type;
|
||||
|
||||
public PacketSender(PacketType type, String data) {
|
||||
this.type = type;
|
||||
this.data.writeBytes(ByteBuffer.wrap(data.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
|
||||
public void sendToPlayer(ServerPlayerEntity player) {
|
||||
ServerPlayNetworking.send(player,getIdentifier(type),data);
|
||||
}
|
||||
|
||||
public void sendToServer() {
|
||||
ClientPlayNetworking.send(getIdentifier(type),data);
|
||||
}
|
||||
|
||||
public static Identifier getIdentifier(PacketType packetType) {
|
||||
return new Identifier(Data.MOD_ID, packetType.getId());
|
||||
}
|
||||
|
||||
public static String getPacketData(PacketByteBuf buf) {
|
||||
return buf.toString(StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
16
src/main/java/one/oth3r/sit/packet/PacketType.java
Normal file
16
src/main/java/one/oth3r/sit/packet/PacketType.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
package one.oth3r.sit.packet;
|
||||
|
||||
public enum PacketType {
|
||||
RESPONSE("response_v1.0"),
|
||||
SETTINGS("settings_v2.0");
|
||||
|
||||
final String id;
|
||||
|
||||
PacketType(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package one.oth3r.sit.packet;
|
||||
|
||||
import net.minecraft.network.RegistryByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.network.codec.PacketCodecs;
|
||||
import net.minecraft.network.packet.CustomPayload;
|
||||
import net.minecraft.util.Identifier;
|
||||
import one.oth3r.sit.utl.Data;
|
||||
|
||||
public class SitPayloads {
|
||||
/**
|
||||
* the packet that the client sends to the server
|
||||
* @param value the sitting settings for the client
|
||||
*/
|
||||
public record SettingsPayload(String value) implements CustomPayload {
|
||||
|
||||
public static final Id<SettingsPayload> ID = new Id<>(Identifier.of(Data.MOD_ID,"settings_v2.0"));
|
||||
|
||||
public static final PacketCodec<RegistryByteBuf, SettingsPayload> CODEC = PacketCodecs.STRING.xmap(SettingsPayload::new, SettingsPayload::value).cast();
|
||||
|
||||
@Override
|
||||
public Id<SettingsPayload> getId() {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* the packet that the server sends to the client when responding to the settings payload
|
||||
*/
|
||||
public record ResponsePayload(String value) implements CustomPayload {
|
||||
|
||||
public static final String VERSION = "response_v1.0";
|
||||
|
||||
public static final Id<ResponsePayload> ID = new Id<>(Identifier.of(Data.MOD_ID,VERSION));
|
||||
|
||||
public static final PacketCodec<RegistryByteBuf, ResponsePayload> CODEC = PacketCodecs.STRING.xmap(ResponsePayload::new, ResponsePayload::value).cast();
|
||||
|
||||
@Override
|
||||
public Id<ResponsePayload> getId() {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,6 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
|||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.tooltip.Tooltip;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
|
@ -20,11 +19,13 @@ public class ClickableImageWidget extends ButtonWidget {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
protected void renderButton(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
context.setShaderColor(1.0f, 1.0f, 1.0f, this.alpha);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.enableDepthTest();
|
||||
context.drawTexture(RenderLayer::getGuiTextured, image,
|
||||
context.drawTexture(image,
|
||||
this.getX(), this.getY(), 0.0f, 0.0f, this.getWidth(), this.getHeight(), this.getWidth(), this.getHeight());
|
||||
context.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
package one.oth3r.sit.screen;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.terraformersmc.modmenu.gui.ModMenuOptionsScreen;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.ConfirmLinkScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.ColorHelper;
|
||||
import one.oth3r.sit.file.FileData;
|
||||
import one.oth3r.sit.utl.Data;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public class ConfigScreen extends Screen {
|
||||
protected final Screen parent;
|
||||
|
||||
|
@ -28,23 +25,23 @@ public class ConfigScreen extends Screen {
|
|||
int spacing = 36;
|
||||
TextureButtonWidget serverConfigButton = this.addDrawableChild(new TextureButtonWidget.Builder(Text.translatable("config.server"),
|
||||
(button) -> client.setScreen(new UnderConstructionScreen(this, FileData.getServerConfig())), false)
|
||||
.dimensions(250,30).texture(Identifier.of(Data.MOD_ID, "server_button"), 246, 26).build());
|
||||
.dimensions(250,30).texture(Identifier.of(Data.MOD_ID, "textures/gui/sprites/server_button.png"), 246, 26).build());
|
||||
serverConfigButton.setPosition(this.width / 2 - (serverConfigButton.getWidth()/2), startY);
|
||||
|
||||
TextureButtonWidget sittingConfigButton = this.addDrawableChild(new TextureButtonWidget.Builder(Text.translatable("config.sitting"),
|
||||
(button) -> client.setScreen(new UnderConstructionScreen(this, FileData.getSittingConfig())), false)
|
||||
.dimensions(250,30).texture(Identifier.of(Data.MOD_ID, "sitting_button"), 246, 26).build());
|
||||
.dimensions(250,30).texture(Identifier.of(Data.MOD_ID, "textures/gui/sprites/sitting_button.png"), 246, 26).build());
|
||||
sittingConfigButton.setPosition(this.width / 2 - (sittingConfigButton.getWidth()/2), startY+36);
|
||||
|
||||
|
||||
TextureButtonWidget issuesButton = this.addDrawableChild(new TextureButtonWidget.Builder(Text.translatable("sit!.gui.button.issues"),
|
||||
ConfirmLinkScreen.opening(this, URI.create("https://github.com/Oth3r/Sit/issues")), true)
|
||||
.dimensions(20,20).texture(Identifier.of(Data.MOD_ID, "issues"), 15, 15).build());
|
||||
ConfirmLinkScreen.opening("https://github.com/Oth3r/Sit/issues",this,true), true)
|
||||
.dimensions(20,20).texture(Identifier.of(Data.MOD_ID, "textures/gui/sprites/issues.png"), 15, 15).build());
|
||||
issuesButton.setPosition(this.width / 2 - 125, startY + 72 + 12);
|
||||
|
||||
|
||||
this.addDrawableChild(ButtonWidget.builder(Text.translatable("sit!.gui.button.website"),
|
||||
ConfirmLinkScreen.opening(this, URI.create("https://modrinth.com/mod/sit!"))
|
||||
ConfirmLinkScreen.opening("https://modrinth.com/mod/sit!",this,true)
|
||||
).dimensions(this.width / 2 - 100, startY + 72 + 12, 98, 20).build());
|
||||
|
||||
this.addDrawableChild(ButtonWidget.builder(Text.translatable("gui.done"), (button) -> {
|
||||
|
@ -52,17 +49,21 @@ public class ConfigScreen extends Screen {
|
|||
}).dimensions(this.width / 2 + 2, startY + 72 + 12, 98, 20).build());
|
||||
|
||||
TextureButtonWidget donateButton = this.addDrawableChild(new TextureButtonWidget.Builder(Text.translatable("sit!.gui.button.donate"),
|
||||
ConfirmLinkScreen.opening(this, URI.create("https://Ko-fi.com/oth3r")), true)
|
||||
.dimensions(20,20).texture(Identifier.of(Data.MOD_ID, "donate"), 15, 15).build());
|
||||
ConfirmLinkScreen.opening("https://Ko-fi.com/oth3r",this,true), true)
|
||||
.dimensions(20,20).texture(Identifier.of(Data.MOD_ID, "textures/gui/sprites/donate.png"), 15, 15).build());
|
||||
donateButton.setPosition(this.width / 2 + 105, startY + 72 + 12);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
|
||||
// render the background because you have to in this version
|
||||
this.renderBackground(context);
|
||||
// todo fade in like the title screen on first load?
|
||||
renderBanner(context,width/2 - 64,this.height / 4 -38,1);
|
||||
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -73,8 +74,8 @@ public class ConfigScreen extends Screen {
|
|||
private void renderBanner(DrawContext context, int x, int y, float alpha) {
|
||||
RenderSystem.enableBlend();
|
||||
|
||||
context.drawTexture(RenderLayer::getGuiTextured,Identifier.of(Data.MOD_ID, "textures/gui/banner.png"),
|
||||
x, y, 0.0f, 0.0f, 128, 72, 128, 72, ColorHelper.getWhite(alpha));
|
||||
context.drawTexture(Identifier.of(Data.MOD_ID, "textures/gui/banner.png"),
|
||||
x, y, 0.0f, 0.0f, 128, 72, 128, 72);
|
||||
|
||||
RenderSystem.disableBlend();
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import net.minecraft.client.font.TextRenderer;
|
|||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.tooltip.Tooltip;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -26,11 +25,11 @@ public class TextureButtonWidget extends ButtonWidget {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
super.renderWidget(context, mouseX, mouseY, delta);
|
||||
protected void renderButton(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
super.renderButton(context, mouseX, mouseY, delta);
|
||||
int x = this.getX() + this.getWidth() / 2 - this.textureWidth / 2;
|
||||
int y = this.getY() + this.getHeight() / 2 - this.textureHeight / 2;
|
||||
context.drawGuiTexture(RenderLayer::getGuiTextured, this.texture, x, y, this.textureWidth, this.textureHeight);
|
||||
context.drawTexture(this.texture, x, y, 0, 0, this.textureWidth, this.textureHeight, this.textureWidth, this.textureHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package one.oth3r.sit.screen;
|
||||
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.ConfirmLinkScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.tooltip.Tooltip;
|
||||
|
@ -29,7 +30,7 @@ public class UnderConstructionScreen<T extends CustomFile<T>> extends Screen {
|
|||
protected void init() {
|
||||
int startY = this.height / 5-4;
|
||||
ButtonWidget foxPNG = this.addDrawableChild(new ClickableImageWidget(70,70,140,140, Tooltip.of(Text.of("Art by @bunnestbun")),
|
||||
Identifier.of(Data.MOD_ID, "textures/gui/fox.png"), ConfirmLinkScreen.opening(this, URI.create("https://www.instagram.com/bunnestbun/"))));
|
||||
Identifier.of(Data.MOD_ID, "textures/gui/fox.png"), ConfirmLinkScreen.opening("https://www.instagram.com/bunnestbun/",this, true)));
|
||||
foxPNG.setPosition(this.width / 2 - (foxPNG.getWidth()/2), startY-35);
|
||||
|
||||
ButtonWidget openFileButton = this.addDrawableChild(new ButtonWidget.Builder(Text.translatable("sit!.gui.button.file"),
|
||||
|
@ -38,8 +39,8 @@ public class UnderConstructionScreen<T extends CustomFile<T>> extends Screen {
|
|||
openFileButton.setPosition(this.width / 2 - 70, startY+110);
|
||||
|
||||
TextureButtonWidget folderButton = this.addDrawableChild(new TextureButtonWidget.Builder(Text.translatable("sit!.gui.button.folder"),
|
||||
(button) -> Util.getOperatingSystem().open(Paths.get(this.file.getFile().getParent())), true)
|
||||
.dimensions(20,20).texture(Identifier.of(Data.MOD_ID, "folder"), 15, 15).build());
|
||||
(button) -> Util.getOperatingSystem().open(this.file.getFile().getParentFile().toURI()), true)
|
||||
.dimensions(20,20).texture(Identifier.of(Data.MOD_ID, "textures/gui/sprites/folder.png"), 15, 15).build());
|
||||
folderButton.setPosition(this.width / 2 + 50, startY + 110);
|
||||
|
||||
TextureButtonWidget resetButton = this.addDrawableChild(new TextureButtonWidget.Builder(Text.translatable("sit!.gui.button.reset"),
|
||||
|
@ -47,7 +48,7 @@ public class UnderConstructionScreen<T extends CustomFile<T>> extends Screen {
|
|||
this.file.reset();
|
||||
this.file.save();
|
||||
}, true)
|
||||
.dimensions(20,20).texture(Identifier.of(Data.MOD_ID, "reset_file"), 15, 15).build());
|
||||
.dimensions(20,20).texture(Identifier.of(Data.MOD_ID, "textures/gui/sprites/reset_file.png"), 15, 15).build());
|
||||
resetButton.setPosition(this.width / 2 -70, startY + 135);
|
||||
|
||||
ButtonWidget revertButton = this.addDrawableChild(new ButtonWidget.Builder(Text.translatable("sit!.gui.button.revert"),
|
||||
|
@ -72,6 +73,13 @@ public class UnderConstructionScreen<T extends CustomFile<T>> extends Screen {
|
|||
saveExitButton.setPosition(this.width / 2 - 70, startY+168);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
// render the background because you have to in this version
|
||||
this.renderBackground(context);
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
this.client.setScreen(parent);
|
||||
|
|
|
@ -8,7 +8,6 @@ import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
|||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
@ -21,7 +20,8 @@ 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.packet.PacketSender;
|
||||
import one.oth3r.sit.packet.PacketType;
|
||||
import one.oth3r.sit.screen.ConfigScreen;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
|
@ -83,34 +83,36 @@ public class Events {
|
|||
|
||||
private static class Packet {
|
||||
private static void common() {
|
||||
// register the data
|
||||
PayloadTypeRegistry.playC2S().register(SitPayloads.SettingsPayload.ID, SitPayloads.SettingsPayload.CODEC);
|
||||
|
||||
PayloadTypeRegistry.playS2C().register(SitPayloads.ResponsePayload.ID, SitPayloads.ResponsePayload.CODEC);
|
||||
|
||||
// server receiver is common
|
||||
|
||||
/// receiving the sitting setting payload
|
||||
ServerPlayNetworking.registerGlobalReceiver(SitPayloads.SettingsPayload.ID,((payload, context) -> Data.getServer().execute(() -> {
|
||||
ServerPlayNetworking.registerGlobalReceiver(PacketSender.getIdentifier(PacketType.SETTINGS),
|
||||
((server, player, handler, buf, responseSender) -> {
|
||||
String packetData = PacketSender.getPacketData(buf);
|
||||
server.execute(() -> {
|
||||
// save the setting on the server for that player
|
||||
FileData.setPlayerSetting(context.player(),Utl.getGson().fromJson(payload.value(), SittingConfig.class));
|
||||
FileData.setPlayerSetting(player,Utl.getGson().fromJson(packetData, SittingConfig.class));
|
||||
|
||||
// send the player back a response packet for confirmation
|
||||
ServerPlayNetworking.send(context.player(),new SitPayloads.ResponsePayload(SitPayloads.ResponsePayload.VERSION));
|
||||
new PacketSender(PacketType.RESPONSE,PacketType.RESPONSE.getId()).sendToPlayer(player);
|
||||
|
||||
// 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",player.getName().getString()).getString());
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
private static void client() {
|
||||
/// receiving the response packet from the server
|
||||
ClientPlayNetworking.registerGlobalReceiver(SitPayloads.ResponsePayload.ID, ((payload, context) -> {
|
||||
// only update when needed
|
||||
ClientPlayNetworking.registerGlobalReceiver(PacketSender.getIdentifier(PacketType.RESPONSE),
|
||||
((client, handler, buf, responseSender) -> {
|
||||
String packetData = PacketSender.getPacketData(buf);
|
||||
client.execute(() -> {
|
||||
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",packetData).getString());
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ public class Logic {
|
|||
// get the poses to check above the block
|
||||
BlockPos pos1 = new BlockPos(pos).add(0,1,0), pos2 = new BlockPos(pos).add(0,2,0), posBelow = new BlockPos(pos);
|
||||
// doesn't check 2 blocks above if not sitting above .80 of the block
|
||||
if (pos.getY() > entity.getY() - .80) {
|
||||
if (pos.getY() > (entity.getY()-Utl.Entity.Y_ADJUSTMENT) - .80) {
|
||||
pos2 = pos2.add(0,-1,0);
|
||||
posBelow = posBelow.add(0,-1,0);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.google.gson.reflect.TypeToken;
|
|||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.google.gson.stream.MalformedJsonException;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.enums.BlockHalf;
|
||||
import net.minecraft.block.enums.SlabType;
|
||||
|
@ -14,7 +13,6 @@ import net.minecraft.entity.decoration.DisplayEntity;
|
|||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.consume.UseAction;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
|
@ -29,7 +27,8 @@ import net.minecraft.util.math.Vec3d;
|
|||
import net.minecraft.world.RaycastContext;
|
||||
import net.minecraft.world.World;
|
||||
import one.oth3r.sit.file.*;
|
||||
import one.oth3r.sit.packet.SitPayloads;
|
||||
import one.oth3r.sit.packet.PacketSender;
|
||||
import one.oth3r.sit.packet.PacketType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -208,7 +207,7 @@ public class Utl {
|
|||
/**
|
||||
* the customizable y height of the entity, as some versions have different sitting heights on the entity
|
||||
*/
|
||||
private static final double Y_ADJUSTMENT = 0;
|
||||
public static final double Y_ADJUSTMENT = -0.2;
|
||||
|
||||
/**
|
||||
* checks if the entity's block is still there, & is valid
|
||||
|
@ -227,9 +226,9 @@ public class Utl {
|
|||
public static BlockPos getBlockPos(DisplayEntity.TextDisplayEntity entity) {
|
||||
// the entity Y level, adjusted
|
||||
// the adjustment - is the opposite of the offset applied in Entity.create()
|
||||
double entityY = entity.getBlockY() + (Y_ADJUSTMENT*-1);
|
||||
int entityBlockY = (int) (Math.floor(entity.getY() + (Y_ADJUSTMENT*-1)));
|
||||
// get the block pos
|
||||
BlockPos pos = new BlockPos(entity.getBlockX(),(int)entityY,entity.getBlockZ());
|
||||
BlockPos pos = new BlockPos(entity.getBlockX(),entityBlockY,entity.getBlockZ());
|
||||
// if above the block, subtract 1
|
||||
if (isAboveBlockHeight(entity)) {
|
||||
pos = pos.add(0,-1,0);
|
||||
|
@ -320,9 +319,9 @@ 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)
|
||||
style -> style.withColor(Formatting.GRAY).withItalic(true)
|
||||
)).styled(
|
||||
style -> style.withColor(Colors.GREEN)
|
||||
style -> style.withColor(Formatting.GREEN)
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
@ -330,7 +329,7 @@ public class Utl {
|
|||
|
||||
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))))
|
||||
style -> style.withColor(TextColor.parse("#c400ff")))
|
||||
).append("] ");
|
||||
}
|
||||
|
||||
|
@ -370,7 +369,7 @@ public class Utl {
|
|||
*/
|
||||
public static void sendSettingsPackets() {
|
||||
if (Data.isClient() && Data.isInGame()) {
|
||||
ClientPlayNetworking.send(new SitPayloads.SettingsPayload(Utl.getGson().toJson(FileData.getSittingConfig())));
|
||||
new PacketSender(PacketType.SETTINGS, Utl.getGson().toJson(FileData.getSittingConfig())).sendToServer();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -466,7 +465,7 @@ public class Utl {
|
|||
// extend ray by the range
|
||||
Vec3d rayEnd = rayStart.add(player.getRotationVector().multiply(range));
|
||||
|
||||
BlockHitResult hitResult = world.raycast(new RaycastContext(rayStart, rayEnd, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, ShapeContext.absent()));
|
||||
BlockHitResult hitResult = world.raycast(new RaycastContext(rayStart, rayEnd, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, player));
|
||||
|
||||
if (hitResult.getType() == HitResult.Type.BLOCK) {
|
||||
return hitResult.getBlockPos();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue