main #22
|
@ -1,12 +1,10 @@
|
||||||
package modchest.mixin.client;
|
package modchest.mixin.client;
|
||||||
|
|
||||||
import modchest.REServerModClient;
|
import modchest.REServerModClient;
|
||||||
import modchest.networking.modNetworkingClient;
|
import modchest.networking.payload.startSleepingCallButtons;
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
import net.minecraft.network.PacketByteBuf;
|
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Unique;
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
@ -21,57 +19,49 @@ public class DeathScreen extends Screen {
|
||||||
} //Da wir einen bereits bestehenden Screen erweitern, wird dieser Text nie angezeigt
|
} //Da wir einen bereits bestehenden Screen erweitern, wird dieser Text nie angezeigt
|
||||||
|
|
||||||
@Inject(method = "init", at = @At("TAIL")) //Dieser Code wird in den eigentlich bereits bestehenden Code der Klasse DeathScreen hinzugefügt
|
@Inject(method = "init", at = @At("TAIL")) //Dieser Code wird in den eigentlich bereits bestehenden Code der Klasse DeathScreen hinzugefügt
|
||||||
private void addMultiSleepButtons(CallbackInfo info) {;
|
private void addMultiSleepButtons(CallbackInfo info) {
|
||||||
int widthButton = 40; //Die generelle Breite der knoepfe wird definiert
|
int widthButton = 40; //Die generelle Breite der knoepfe wird definiert
|
||||||
int heightButton = 20; // " hoehe "
|
int heightButton = 20; // " hoehe "
|
||||||
int yOffset = 5; //Wie gross der Abstand zwischen der oberen Kante un dem knop sein soll (der Nullpunkt (0|0) ist soswohl im Fenster als auch beim Knopf oben links die Ecke)
|
int yOffset = 5; //Wie gross der Abstand zwischen der oberen Kante un dem knopf sein soll (der Nullpunkt (0|0) ist sowohl im Fenster als auch beim Knopf oben links die Ecke)
|
||||||
int xOffset = this.width / 2 - widthButton / 2; //Die Mitte wird ausgerechnet (Mitte vom fenster minus halbe Breite des knopfes um tatsächlich die Mitte zu haben, weil koordinaten und so
|
int xOffset = this.width / 2 - widthButton / 2; //Die Mitte wird ausgerechnet (Mitte vom fenster minus halbe Breite des knopfes um tatsächlich die Mitte zu haben, weil koordinaten und so
|
||||||
this.addDrawableChild(
|
this.addDrawableChild(
|
||||||
new ButtonWidget(xOffset - 2 * (widthButton + 5), yOffset, widthButton, heightButton, Text.translatable("#1"), button -> { //Knopf wird erzeugt
|
ButtonWidget.builder(Text.translatable("#1"), button -> { //Knopf wird erzeugt
|
||||||
REServerModClient.LOGGER.info("First Button for using spawn pressed!");
|
REServerModClient.LOGGER.info("First Button for using spawn pressed!");
|
||||||
PacketByteBuf buffer = PacketByteBufs.create(); //Neuer Buffer wird erstellt
|
sendPacket(1); //Und an den Server gesendet zum Speichern; die gesamte logik passiert auf dem server, damit man keine fake koordinaten oder so eingeben kann
|
||||||
buffer.writeInt(1); //Beschrieben, damit der Server weiss, welcher knopf gedrueckt wurde
|
}).dimensions(xOffset - 2 * (widthButton + 5), yOffset, widthButton, heightButton).build()
|
||||||
sendPacket(buffer); //Und an den Server gesendet zum Speichern; Die gesamte logik passiert auf dem server, damit man keien fake koordinaten oder so eingeben kann
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
this.addDrawableChild(
|
this.addDrawableChild(
|
||||||
new ButtonWidget(xOffset - (widthButton + 5), yOffset, widthButton, heightButton, Text.translatable("#2"), button -> { //Kommentare siehe knopf #1
|
ButtonWidget.builder(Text.translatable("#2"), button -> { //Kommentare siehe knopf #1
|
||||||
REServerModClient.LOGGER.info("Second Button for using spawn pressed!");
|
REServerModClient.LOGGER.info("Second Button for using spawn pressed!");
|
||||||
PacketByteBuf buffer = PacketByteBufs.create();
|
sendPacket(2);
|
||||||
buffer.writeInt(2);
|
}).dimensions(xOffset - (widthButton + 5), yOffset, widthButton, heightButton).build()
|
||||||
sendPacket(buffer);
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
this.addDrawableChild(
|
this.addDrawableChild(
|
||||||
new ButtonWidget(xOffset, yOffset, widthButton, heightButton, Text.translatable("#3"), button -> { //Kommentare siehe knopf #1
|
ButtonWidget.builder(Text.translatable("#3"), button -> { //Kommentare siehe knopf #1
|
||||||
REServerModClient.LOGGER.info("Third Button for using spawn pressed!");
|
REServerModClient.LOGGER.info("Third Button for using spawn pressed!");
|
||||||
PacketByteBuf buffer = PacketByteBufs.create();
|
sendPacket(3);
|
||||||
buffer.writeInt(3);
|
}).dimensions(xOffset, yOffset, widthButton, heightButton).build()
|
||||||
sendPacket(buffer);
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
this.addDrawableChild(
|
this.addDrawableChild(
|
||||||
new ButtonWidget(xOffset + (widthButton + 5), yOffset, widthButton, heightButton, Text.translatable("#4"), button -> { //Kommentare siehe knopf #1
|
ButtonWidget.builder(Text.translatable("#4"), button -> { //Kommentare siehe knopf #1
|
||||||
REServerModClient.LOGGER.info("Fourth Button for using spawn pressed!");
|
REServerModClient.LOGGER.info("Fourth Button for using spawn pressed!");
|
||||||
PacketByteBuf buffer = PacketByteBufs.create();
|
sendPacket(4);
|
||||||
buffer.writeInt(4);
|
}).dimensions(xOffset + (widthButton + 5), yOffset, widthButton, heightButton).build()
|
||||||
sendPacket(buffer);
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
this.addDrawableChild(
|
this.addDrawableChild(
|
||||||
new ButtonWidget(xOffset + 2 * (widthButton + 5), yOffset, widthButton, heightButton, Text.translatable("#5"), button -> { //Kommentare siehe knopf #1
|
ButtonWidget.builder(Text.translatable("#5"), button -> { //Kommentare siehe knopf #1
|
||||||
REServerModClient.LOGGER.info("Fifth Button for using spawn pressed!");
|
REServerModClient.LOGGER.info("Fifth Button for using spawn pressed!");
|
||||||
PacketByteBuf buffer = PacketByteBufs.create();
|
sendPacket(5);
|
||||||
buffer.writeInt(5);
|
}).dimensions(xOffset + 2 * (widthButton + 5), yOffset, widthButton, heightButton).build()
|
||||||
sendPacket(buffer);
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
private synchronized void sendPacket(PacketByteBuf buffer) {
|
private synchronized void sendPacket(int number) {
|
||||||
try {
|
try {
|
||||||
ClientPlayNetworking.send(modNetworkingClient.death_multi_respawn_buttons, buffer);
|
ClientPlayNetworking.send(new startSleepingCallButtons(number));
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {
|
||||||
|
REServerModClient.LOGGER.info("Error when trying to network to server in DeathScreen class!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,19 @@
|
||||||
package modchest.mixin.client;
|
package modchest.mixin.client;
|
||||||
|
|
||||||
import modchest.REServerModClient;
|
import modchest.REServerModClient;
|
||||||
import modchest.networking.modNetworkingClient;
|
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
import net.minecraft.network.PacketByteBuf;
|
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Unique;
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import modchest.networking.payload.deathMultiRespawnButtons;
|
||||||
|
|
||||||
@Mixin(net.minecraft.client.gui.screen.SleepingChatScreen.class)
|
@Mixin(net.minecraft.client.gui.screen.SleepingChatScreen.class)
|
||||||
public class SleepingChatScreen extends Screen { //Sehr identisch zu Death Screen, siehe dort fuer Kommentare!!
|
public class SleepingChatScreen extends Screen { //Sehr identisch zu Death Screen, siehe dort fuer Kommentare!
|
||||||
protected SleepingChatScreen(Text title) {
|
protected SleepingChatScreen(Text title) {
|
||||||
super(Text.of("useless"));
|
super(Text.of("useless"));
|
||||||
}
|
}
|
||||||
|
@ -27,51 +25,44 @@ public class SleepingChatScreen extends Screen { //Sehr identisch zu Deat
|
||||||
int yOffset = 5;
|
int yOffset = 5;
|
||||||
int xOffset = this.width / 2 - widthButton / 2;
|
int xOffset = this.width / 2 - widthButton / 2;
|
||||||
this.addDrawableChild(
|
this.addDrawableChild(
|
||||||
new ButtonWidget(xOffset - 2 * (widthButton + 5), yOffset, widthButton, heightButton, Text.translatable("#1"), button -> {
|
ButtonWidget.builder(Text.translatable("#1"), button -> {
|
||||||
REServerModClient.LOGGER.info("First Button for saving spawn pressed!");
|
REServerModClient.LOGGER.info("First Button for saving spawn pressed!");
|
||||||
PacketByteBuf buffer = PacketByteBufs.create();
|
sendPacket(1);
|
||||||
buffer.writeInt(1);
|
}).dimensions(xOffset - 2 * (widthButton + 5), yOffset, widthButton, heightButton).build()
|
||||||
sendPacket(buffer);
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
this.addDrawableChild(
|
this.addDrawableChild(
|
||||||
new ButtonWidget(xOffset - (widthButton + 5), yOffset, widthButton, heightButton, Text.translatable("#2"), button -> {
|
ButtonWidget.builder(Text.translatable("#2"), button -> {
|
||||||
REServerModClient.LOGGER.info("Second Button for saving spawn pressed!");
|
REServerModClient.LOGGER.info("Second Button for saving spawn pressed!");
|
||||||
PacketByteBuf buffer = PacketByteBufs.create();
|
|
||||||
buffer.writeInt(2);
|
sendPacket(2);
|
||||||
sendPacket(buffer);
|
}).dimensions(xOffset - (widthButton + 5), yOffset, widthButton, heightButton).build()
|
||||||
})
|
|
||||||
);
|
);
|
||||||
this.addDrawableChild(
|
this.addDrawableChild(
|
||||||
new ButtonWidget(xOffset, yOffset, widthButton, heightButton, Text.translatable("#3"), button -> {
|
ButtonWidget.builder(Text.translatable("#3"), button -> {
|
||||||
REServerModClient.LOGGER.info("Third Button for saving spawn pressed!");
|
REServerModClient.LOGGER.info("Third Button for saving spawn pressed!");
|
||||||
PacketByteBuf buffer = PacketByteBufs.create();
|
sendPacket(3);
|
||||||
buffer.writeInt(3);
|
}).dimensions(xOffset, yOffset, widthButton, heightButton).build()
|
||||||
sendPacket(buffer);
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
this.addDrawableChild(
|
this.addDrawableChild(
|
||||||
new ButtonWidget(xOffset + (widthButton + 5), yOffset, widthButton, heightButton, Text.translatable("#4"), button -> {
|
ButtonWidget.builder(Text.translatable("#4"), button -> {
|
||||||
REServerModClient.LOGGER.info("Fourth Button for saving spawn pressed!");
|
REServerModClient.LOGGER.info("Fourth Button for saving spawn pressed!");
|
||||||
PacketByteBuf buffer = PacketByteBufs.create();
|
sendPacket(4);
|
||||||
buffer.writeInt(4);
|
}).dimensions(xOffset + (widthButton + 5), yOffset, widthButton, heightButton).build()
|
||||||
sendPacket(buffer);
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
this.addDrawableChild(
|
this.addDrawableChild(
|
||||||
new ButtonWidget(xOffset + 2 * (widthButton + 5), yOffset, widthButton, heightButton, Text.translatable("#5"), button -> {
|
ButtonWidget.builder(Text.translatable("#5"), button -> {
|
||||||
REServerModClient.LOGGER.info("Fifth Button for saving spawn pressed!");
|
REServerModClient.LOGGER.info("Fifth Button for saving spawn pressed!");
|
||||||
PacketByteBuf buffer = PacketByteBufs.create();
|
sendPacket(5);
|
||||||
buffer.writeInt(5);
|
}).dimensions(xOffset + 2 * (widthButton + 5), yOffset, widthButton, heightButton).build()
|
||||||
sendPacket(buffer);
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
private synchronized void sendPacket(PacketByteBuf buffer) {
|
private synchronized void sendPacket(int number) {
|
||||||
try {
|
try {
|
||||||
ClientPlayNetworking.send(modNetworkingClient.start_sleeping_call_buttons, buffer);
|
ClientPlayNetworking.send(new deathMultiRespawnButtons(number));
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {
|
||||||
|
REServerModClient.LOGGER.info("Error when trying to network to server in sleepingChatScreen class!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,14 +2,30 @@ package modchest.networking;
|
||||||
|
|
||||||
import modchest.REServerMod;
|
import modchest.REServerMod;
|
||||||
import modchest.networking.packet.respawnRequestS2CPacket;
|
import modchest.networking.packet.respawnRequestS2CPacket;
|
||||||
|
import modchest.networking.payload.requestRespawn;
|
||||||
|
import modchest.networking.payload.startSleepingCallButtons;
|
||||||
|
import modchest.networking.payload.deathMultiRespawnButtons;
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class modNetworkingClient { //Identifier werden eingeführt
|
public class modNetworkingClient { //Identifier werden eingeführt
|
||||||
public static final Identifier request_respawn = Identifier.of(REServerMod.MOD_ID, "request_respawn"); //alle Identifier muessen leider IMMER auf Client und Server (doppelt) eingefuehrt werden
|
//public static final Identifier request_respawn = Identifier.of(REServerMod.MOD_ID, "request_respawn"); //alle Identifier muessen leider IMMER auf Client und Server (doppelt) eingefuehrt werden
|
||||||
public static final Identifier start_sleeping_call_buttons = Identifier.of(REServerMod.MOD_ID, "start_sleeping_call_buttons");
|
public static final Identifier start_sleeping_call_buttons = Identifier.of(REServerMod.MOD_ID, "start_sleeping_call_buttons");
|
||||||
public static final Identifier death_multi_respawn_buttons = Identifier.of(REServerMod.MOD_ID, "death_call_respawn_buttons");
|
public static final Identifier death_multi_respawn_buttons = Identifier.of(REServerMod.MOD_ID, "death_call_respawn_buttons");
|
||||||
|
|
||||||
public static void registerC2SPackets() { //Identifier fuer packets werden registriert (Identifier die der Server aufruft um beim CLient was auszufuehren)
|
public static void registerC2SPackets() { //Identifier fuer packets werden registriert (Identifier die der Server aufruft um beim CLient was auszufuehren)
|
||||||
ClientPlayNetworking.registerGlobalReceiver(request_respawn, respawnRequestS2CPacket::receive); //was der Client dann machen soll steht in der receive Methode
|
PayloadTypeRegistry.playC2S().register(startSleepingCallButtons.ID, startSleepingCallButtons.CODEC);
|
||||||
|
PayloadTypeRegistry.playC2S().register(deathMultiRespawnButtons.ID, deathMultiRespawnButtons.CODEC);
|
||||||
|
|
||||||
|
|
||||||
|
ClientPlayNetworking.registerGlobalReceiver(startSleepingCallButtons.ID, (payload, context) -> {
|
||||||
|
context.client().execute(() -> {
|
||||||
|
respawnRequestS2CPacket.receive(context.client(), payload);
|
||||||
|
}
|
||||||
|
);});
|
||||||
|
|
||||||
|
|
||||||
|
//ClientPlayNetworking.registerGlobalReceiver(request_respawn, respawnRequestS2CPacket::receive); //was der Client dann machen soll steht in der receive Methode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,18 @@ import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||||
import net.minecraft.network.PacketByteBuf;
|
import net.minecraft.network.PacketByteBuf;
|
||||||
|
import net.minecraft.network.packet.CustomPayload;
|
||||||
|
|
||||||
public class respawnRequestS2CPacket {
|
public class respawnRequestS2CPacket {
|
||||||
|
/*
|
||||||
public static void receive(MinecraftClient minecraftClient, ClientPlayNetworkHandler clientPlayNetworkHandler, PacketByteBuf packetByteBuf, PacketSender packetSender) {
|
public static void receive(MinecraftClient minecraftClient, ClientPlayNetworkHandler clientPlayNetworkHandler, PacketByteBuf packetByteBuf, PacketSender packetSender) {
|
||||||
//REServerModClient.LOGGER.info("Server asked for respawn after pressing a saved respawn button!");
|
//REServerModClient.LOGGER.info("Server asked for respawn after pressing a saved respawn button!");
|
||||||
minecraftClient.player.requestRespawn();
|
minecraftClient.player.requestRespawn();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
public static void receive(MinecraftClient minecraftClient, CustomPayload payload) {
|
||||||
|
//REServerModClient.LOGGER.info("Server asked for respawn after pressing a saved respawn button!");
|
||||||
|
assert minecraftClient.player != null;
|
||||||
|
minecraftClient.player.requestRespawn();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package modchest.networking.payload;
|
||||||
|
|
||||||
|
import modchest.networking.modNetworkingServer;
|
||||||
|
import net.minecraft.network.RegistryByteBuf;
|
||||||
|
import net.minecraft.network.codec.PacketCodec;
|
||||||
|
import net.minecraft.network.codec.PacketCodecs;
|
||||||
|
import net.minecraft.network.packet.CustomPayload;
|
||||||
|
|
||||||
|
public record deathMultiRespawnButtons(int number) implements CustomPayload {
|
||||||
|
public static final Id<deathMultiRespawnButtons> ID = new Id<>(modNetworkingServer.request_respawn);
|
||||||
|
public static final PacketCodec<RegistryByteBuf, deathMultiRespawnButtons> CODEC = PacketCodec.tuple(PacketCodecs.INTEGER, deathMultiRespawnButtons::number, deathMultiRespawnButtons::new);
|
||||||
|
//PacketCodec.tuple(PacketCodecs.INTEGER, requestRespawn::new);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Id<? extends CustomPayload> getId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package modchest.networking.payload;
|
||||||
|
|
||||||
|
import modchest.networking.modNetworkingServer;
|
||||||
|
import net.minecraft.network.RegistryByteBuf;
|
||||||
|
import net.minecraft.network.codec.PacketCodec;
|
||||||
|
import net.minecraft.network.codec.PacketCodecs;
|
||||||
|
import net.minecraft.network.packet.CustomPayload;
|
||||||
|
|
||||||
|
public record requestRespawn(int number) implements CustomPayload {
|
||||||
|
public static final Id<requestRespawn> ID = new Id<>(modNetworkingServer.request_respawn);
|
||||||
|
public static final PacketCodec<RegistryByteBuf, requestRespawn> CODEC = PacketCodec.tuple(PacketCodecs.INTEGER, requestRespawn::number, requestRespawn::new);
|
||||||
|
//PacketCodec.tuple(PacketCodecs.INTEGER, requestRespawn::new);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Id<? extends CustomPayload> getId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package modchest.networking.payload;
|
||||||
|
|
||||||
|
import modchest.networking.modNetworkingServer;
|
||||||
|
import net.minecraft.network.RegistryByteBuf;
|
||||||
|
import net.minecraft.network.codec.PacketCodec;
|
||||||
|
import net.minecraft.network.codec.PacketCodecs;
|
||||||
|
import net.minecraft.network.packet.CustomPayload;
|
||||||
|
|
||||||
|
public record startSleepingCallButtons(int number) implements CustomPayload {
|
||||||
|
public static final CustomPayload.Id<startSleepingCallButtons> ID = new CustomPayload.Id<>(modNetworkingServer.request_respawn);
|
||||||
|
public static final PacketCodec<RegistryByteBuf, startSleepingCallButtons> CODEC = PacketCodec.tuple(PacketCodecs.INTEGER, startSleepingCallButtons::number, startSleepingCallButtons::new);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Id<? extends CustomPayload> getId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,4 +24,5 @@ public class ModModelProvider extends FabricModelProvider {
|
||||||
public void generateItemModels(ItemModelGenerator itemModelGenerator) {
|
public void generateItemModels(ItemModelGenerator itemModelGenerator) {
|
||||||
//itemModelGenerator.register(modItems.shipblock, Models.GENERATED); //ergänzt die Texturen für die Items
|
//itemModelGenerator.register(modItems.shipblock, Models.GENERATED); //ergänzt die Texturen für die Items
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
|
@ -4,6 +4,7 @@ import modchest.REServerMod;
|
||||||
import modchest.util.setAndGetMultiButtonsSpawn;
|
import modchest.util.setAndGetMultiButtonsSpawn;
|
||||||
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
|
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
|
import net.minecraft.registry.Registries;
|
||||||
import net.minecraft.registry.Registry;
|
import net.minecraft.registry.Registry;
|
||||||
import net.minecraft.registry.RegistryKey;
|
import net.minecraft.registry.RegistryKey;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
@ -23,7 +24,7 @@ public class playerAfterRespawnEvent implements ServerPlayerEvents.AfterRespawn
|
||||||
|
|
||||||
String[] parts = nbt.getString("dimension").split(":"); //holt sich die gespeicherte Dimension; trennt den String entspreichend; damit sollte es auch funktionieren, sollte eine Mod weitere Dimensionen hinzufuegen
|
String[] parts = nbt.getString("dimension").split(":"); //holt sich die gespeicherte Dimension; trennt den String entspreichend; damit sollte es auch funktionieren, sollte eine Mod weitere Dimensionen hinzufuegen
|
||||||
parts = parts[2].split("]");
|
parts = parts[2].split("]");
|
||||||
RegistryKey<World> dim = RegistryKey.of(Registry.WORLD_KEY, new Identifier(parts[0]));
|
RegistryKey<World> dim = RegistryKey.of(Registry<World>, Identifier.of(parts[0]));
|
||||||
|
|
||||||
float angle = nbt.getFloat("angle"); //Und den blickwinkel
|
float angle = nbt.getFloat("angle"); //Und den blickwinkel
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.block.BedBlock;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -22,7 +23,7 @@ import java.util.Objects;
|
||||||
public class bedBlock {
|
public class bedBlock {
|
||||||
|
|
||||||
@Inject(method = "onBreak", at = @At("HEAD"))
|
@Inject(method = "onBreak", at = @At("HEAD"))
|
||||||
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfo ci) { //Ueberprueft, wenn ein Bett zerstoert wird, ob jemand dieses Bett als Spawnpunkt hat
|
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfoReturnable<BlockState> cir) { //Ueberprueft, wenn ein Bett zerstoert wird, ob jemand dieses Bett als Spawnpunkt hat
|
||||||
if (!world.isClient) { //Stellt sicher, dass das ganze nicht auf dem Client gerechnet wird, weil der Code sonst abstuertzt
|
if (!world.isClient) { //Stellt sicher, dass das ganze nicht auf dem Client gerechnet wird, weil der Code sonst abstuertzt
|
||||||
|
|
||||||
int posBedX = pos.getX();
|
int posBedX = pos.getX();
|
||||||
|
|
|
@ -3,7 +3,11 @@ package modchest.networking;
|
||||||
import modchest.REServerMod;
|
import modchest.REServerMod;
|
||||||
import modchest.networking.packet.deathScreenMultiButtonsC2SPacket;
|
import modchest.networking.packet.deathScreenMultiButtonsC2SPacket;
|
||||||
import modchest.networking.packet.setNewRespawnsC2SPacket;
|
import modchest.networking.packet.setNewRespawnsC2SPacket;
|
||||||
|
import modchest.networking.payload.deathMultiRespawnButtons;
|
||||||
|
import modchest.networking.payload.requestRespawn;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||||
|
import modchest.networking.payload.startSleepingCallButtons;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class modNetworkingServer { //Identifier werden eingeführt
|
public class modNetworkingServer { //Identifier werden eingeführt
|
||||||
|
@ -12,8 +16,26 @@ public class modNetworkingServer { //Identifier werden eingeführt
|
||||||
public static final Identifier death_multi_respawn_buttons = Identifier.of(REServerMod.MOD_ID, "death_call_respawn_buttons");
|
public static final Identifier death_multi_respawn_buttons = Identifier.of(REServerMod.MOD_ID, "death_call_respawn_buttons");
|
||||||
|
|
||||||
public static void registerS2CPackets() { //Identifier fuer packets werden registriert (Identifier die der Client aufruft um beim Server was auszufuehren)
|
public static void registerS2CPackets() { //Identifier fuer packets werden registriert (Identifier die der Client aufruft um beim Server was auszufuehren)
|
||||||
ServerPlayNetworking.registerGlobalReceiver(start_sleeping_call_buttons, setNewRespawnsC2SPacket::receive); //was der Server dann machen soll steht in der receive Methode
|
PayloadTypeRegistry.playC2S().register(requestRespawn.ID, requestRespawn.CODEC);
|
||||||
|
|
||||||
ServerPlayNetworking.registerGlobalReceiver(death_multi_respawn_buttons, deathScreenMultiButtonsC2SPacket::receive);
|
ServerPlayNetworking.registerGlobalReceiver(startSleepingCallButtons.ID, (payload, context) -> {
|
||||||
|
context.server().execute(() -> {
|
||||||
|
setNewRespawnsC2SPacket.receive(context.server(), context.player(), payload.number());
|
||||||
|
}
|
||||||
|
);});
|
||||||
|
|
||||||
|
ServerPlayNetworking.registerGlobalReceiver(deathMultiRespawnButtons.ID, (payload, context) -> {
|
||||||
|
context.server().execute(() -> {
|
||||||
|
deathScreenMultiButtonsC2SPacket.receive(context.server(), context.player(), payload.number());
|
||||||
|
}
|
||||||
|
);});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//ServerPlayNetworking.registerGlobalReceiver(start_sleeping_call_buttons, setNewRespawnsC2SPacket::receive); //was der Server dann machen soll steht in der receive Methode
|
||||||
|
|
||||||
|
//ServerPlayNetworking.registerGlobalReceiver(death_multi_respawn_buttons, deathScreenMultiButtonsC2SPacket::receive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,42 +1,37 @@
|
||||||
package modchest.networking.packet;
|
package modchest.networking.packet;
|
||||||
|
|
||||||
import modchest.REServerMod;
|
import modchest.REServerMod;
|
||||||
import modchest.networking.modNetworkingServer;
|
import modchest.networking.payload.requestRespawn;
|
||||||
import modchest.util.setAndGetMultiButtonsSpawn;
|
import modchest.util.setAndGetMultiButtonsSpawn;
|
||||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
|
||||||
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||||
import net.minecraft.network.PacketByteBuf;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class deathScreenMultiButtonsC2SPacket {
|
public class deathScreenMultiButtonsC2SPacket {
|
||||||
public static void receive(MinecraftServer server, ServerPlayerEntity player, //Passiert auf dem Server!!!
|
public static void receive(MinecraftServer server, ServerPlayerEntity player, int number) { //Passiert auf dem Server!!!
|
||||||
ServerPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) {
|
|
||||||
setAndGetMultiButtonsSpawn setAndGet = new setAndGetMultiButtonsSpawn(); //um die nicht-statischen Methoden aufzurufen, erzeugen wir ein Objekt. Wir speichern aber keine Daten in der Klasse, daher ist das OK
|
setAndGetMultiButtonsSpawn setAndGet = new setAndGetMultiButtonsSpawn(); //um die nicht-statischen Methoden aufzurufen, erzeugen wir ein Objekt. Wir speichern aber keine Daten in der Klasse, daher ist das OK
|
||||||
int num; //num steht fuer Number, und sagt, welcher der 5 Knoepfe gedrueckt wurde, da das Spiel abstuertzt wenn man buf.readInt() mehr als einmal ausfuehrt
|
int num; //num steht fuer Number, und sagt, welcher der 5 Knoepfe gedrueckt wurde, da das Spiel abstuertzt wenn man buf.readInt() mehr als einmal ausfuehrt
|
||||||
try {
|
try {
|
||||||
num = buf.readInt(); //Um Spielabstuertze definitiv zu verhindern in einem try block, hat aber nie Probleme gemacht, also eine reine absicherung
|
num = number; //Um Spielabstuertze definitiv zu verhindern in einem try block, hat aber nie Probleme gemacht, also eine reine absicherung
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
REServerMod.LOGGER.info("Following Error when trying to get the number of pressed Button: " + e + "continuing bwith Button 1");
|
REServerMod.LOGGER.info("Following Error when trying to get the number of pressed Button: " + e + "continuing with Button 1");
|
||||||
num = 1;
|
num = 1;
|
||||||
}
|
}
|
||||||
setAndGet.setMultiSpawnVanilla(player);
|
setAndGet.setMultiSpawnVanilla(player);
|
||||||
|
|
||||||
int[] posXYZ = setAndGet.getMultiSpawn(player, num); //neue Koordinaten werden vom Server geholt
|
int[] posXYZ = setAndGet.getMultiSpawn(player, number); //neue Koordinaten werden vom Server geholt
|
||||||
|
|
||||||
if (posXYZ.length == 3 && posXYZ[0] < 77889900) { //Stellt sicher, dass die 3 spawnkoordinaten nicht null sind; Koordinaten 77889900 sind ausserhalb der Welt und werden daher von mir in setAndGetMultiSpawnButtonsSpawn als Errorcodes verwendet
|
if (posXYZ.length == 3 && posXYZ[0] < 77889900) { //Stellt sicher, dass die 3 spawnkoordinaten nicht null sind; Koordinaten 77889900 sind ausserhalb der Welt und werden daher von mir in setAndGetMultiSpawnButtonsSpawn als Errorcodes verwendet
|
||||||
try {
|
try {
|
||||||
//REServerMod.LOGGER.info("try Respawning from Multi-Sapwn");
|
//REServerMod.LOGGER.info("try Respawning from Multi-Sapwn");
|
||||||
player.setSpawnPoint(World.OVERWORLD, new BlockPos(posXYZ[0], posXYZ[1], posXYZ[2]), 0, true, true); //neuer Spawn wird gesetzt
|
player.setSpawnPoint(World.OVERWORLD, new BlockPos(posXYZ[0], posXYZ[1], posXYZ[2]), 0, true, true); //neuer Spawn wird gesetzt
|
||||||
ServerPlayNetworking.send(player, modNetworkingServer.request_respawn, PacketByteBufs.create()); //Anfrage an den Client zum respawnen wird gesendet
|
ServerPlayNetworking.send(player, new requestRespawn(1)); //Anfrage an den Client zum respawnen wird gesendet
|
||||||
player.sendMessage((Text.translatable("chat.modchest.multispawn.respawned", num)));
|
player.sendMessage((Text.translatable("chat.modchest.multispawn.respawned", num)));
|
||||||
REServerMod.LOGGER.info("Respawned Player " + player.getNameForScoreboard() + " at " + Arrays.toString(setAndGet.getMultiSpawn(player, num)));
|
REServerMod.LOGGER.info("Respawned Player " + player.getNameForScoreboard() + " at " + Arrays.toString(setAndGet.getMultiSpawn(player, num)));
|
||||||
setAndGet.setMultiSpawn(player, 6);
|
setAndGet.setMultiSpawn(player, 6);
|
||||||
|
@ -51,4 +46,4 @@ public class deathScreenMultiButtonsC2SPacket {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,21 +2,15 @@ package modchest.networking.packet;
|
||||||
|
|
||||||
import modchest.REServerMod;
|
import modchest.REServerMod;
|
||||||
import modchest.util.setAndGetMultiButtonsSpawn;
|
import modchest.util.setAndGetMultiButtonsSpawn;
|
||||||
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
|
||||||
import net.minecraft.network.PacketByteBuf;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class setNewRespawnsC2SPacket {
|
public class setNewRespawnsC2SPacket {
|
||||||
public static void receive(MinecraftServer server, ServerPlayerEntity player, //Passiert auf dem Server!!!
|
public static void receive(MinecraftServer server, ServerPlayerEntity player, int number) {
|
||||||
ServerPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) {
|
|
||||||
setAndGetMultiButtonsSpawn setAndGet = new setAndGetMultiButtonsSpawn();
|
setAndGetMultiButtonsSpawn setAndGet = new setAndGetMultiButtonsSpawn();
|
||||||
try {
|
try {
|
||||||
switch (buf.readInt()) { //Wird nur einmal angefragt, daher muss buf.readInt() nicht als variable gesetzt werden
|
switch (number) { //Wird nur einmal angefragt, daher muss buf.readInt() nicht als variable gesetzt werden
|
||||||
case 1:
|
case 1:
|
||||||
setAndGet.setMultiSpawn(player, 1); //Spawnpunkt wird gespeichert
|
setAndGet.setMultiSpawn(player, 1); //Spawnpunkt wird gespeichert
|
||||||
player.sendMessage(Text.translatable("chat.modchest.multispawn.setspawn", "1"));
|
player.sendMessage(Text.translatable("chat.modchest.multispawn.setspawn", "1"));
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package modchest.networking.payload;
|
||||||
|
|
||||||
|
import modchest.networking.modNetworkingServer;
|
||||||
|
import net.minecraft.network.RegistryByteBuf;
|
||||||
|
import net.minecraft.network.codec.PacketCodec;
|
||||||
|
import net.minecraft.network.codec.PacketCodecs;
|
||||||
|
import net.minecraft.network.packet.CustomPayload;
|
||||||
|
|
||||||
|
public record deathMultiRespawnButtons(int number) implements CustomPayload {
|
||||||
|
public static final Id<deathMultiRespawnButtons> ID = new Id<>(modNetworkingServer.request_respawn);
|
||||||
|
public static final PacketCodec<RegistryByteBuf, deathMultiRespawnButtons> CODEC = PacketCodec.tuple(PacketCodecs.INTEGER, deathMultiRespawnButtons::number, deathMultiRespawnButtons::new);
|
||||||
|
//PacketCodec.tuple(PacketCodecs.INTEGER, requestRespawn::new);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Id<? extends CustomPayload> getId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package modchest.networking.payload;
|
||||||
|
|
||||||
|
import modchest.networking.modNetworkingServer;
|
||||||
|
import net.minecraft.network.RegistryByteBuf;
|
||||||
|
import net.minecraft.network.codec.PacketCodec;
|
||||||
|
import net.minecraft.network.codec.PacketCodecs;
|
||||||
|
import net.minecraft.network.packet.CustomPayload;
|
||||||
|
|
||||||
|
public record requestRespawn(int number) implements CustomPayload {
|
||||||
|
public static final CustomPayload.Id<requestRespawn> ID = new CustomPayload.Id<>(modNetworkingServer.request_respawn);
|
||||||
|
public static final PacketCodec<RegistryByteBuf, requestRespawn> CODEC = PacketCodec.tuple(PacketCodecs.INTEGER, requestRespawn::number, requestRespawn::new);
|
||||||
|
//PacketCodec.tuple(PacketCodecs.INTEGER, requestRespawn::new);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Id<? extends CustomPayload> getId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package modchest.networking.payload;
|
||||||
|
|
||||||
|
import modchest.networking.modNetworkingServer;
|
||||||
|
import net.minecraft.network.RegistryByteBuf;
|
||||||
|
import net.minecraft.network.codec.PacketCodec;
|
||||||
|
import net.minecraft.network.codec.PacketCodecs;
|
||||||
|
import net.minecraft.network.packet.CustomPayload;
|
||||||
|
|
||||||
|
public record startSleepingCallButtons(int number) implements CustomPayload {
|
||||||
|
public static final Id<startSleepingCallButtons> ID = new Id<>(modNetworkingServer.request_respawn);
|
||||||
|
public static final PacketCodec<RegistryByteBuf, startSleepingCallButtons> CODEC = PacketCodec.tuple(PacketCodecs.INTEGER, startSleepingCallButtons::number, startSleepingCallButtons::new);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Id<? extends CustomPayload> getId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue