update #21

Merged
Hanno merged 5 commits from update into main 2024-07-19 17:48:53 +02:00
16 changed files with 218 additions and 94 deletions
Showing only changes of commit 6b7188db8b - Show all commits

View File

@ -1,12 +1,10 @@
package modchest.mixin.client;
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.networking.v1.PacketByteBufs;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
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
@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 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
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!");
PacketByteBuf buffer = PacketByteBufs.create(); //Neuer Buffer wird erstellt
buffer.writeInt(1); //Beschrieben, damit der Server weiss, welcher knopf gedrueckt wurde
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
})
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
}).dimensions(xOffset - 2 * (widthButton + 5), yOffset, widthButton, heightButton).build()
);
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!");
PacketByteBuf buffer = PacketByteBufs.create();
buffer.writeInt(2);
sendPacket(buffer);
})
sendPacket(2);
}).dimensions(xOffset - (widthButton + 5), yOffset, widthButton, heightButton).build()
);
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!");
PacketByteBuf buffer = PacketByteBufs.create();
buffer.writeInt(3);
sendPacket(buffer);
})
sendPacket(3);
}).dimensions(xOffset, yOffset, widthButton, heightButton).build()
);
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!");
PacketByteBuf buffer = PacketByteBufs.create();
buffer.writeInt(4);
sendPacket(buffer);
})
sendPacket(4);
}).dimensions(xOffset + (widthButton + 5), yOffset, widthButton, heightButton).build()
);
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!");
PacketByteBuf buffer = PacketByteBufs.create();
buffer.writeInt(5);
sendPacket(buffer);
})
sendPacket(5);
}).dimensions(xOffset + 2 * (widthButton + 5), yOffset, widthButton, heightButton).build()
);
}
@Unique
private synchronized void sendPacket(PacketByteBuf buffer) {
private synchronized void sendPacket(int number) {
try {
ClientPlayNetworking.send(modNetworkingClient.death_multi_respawn_buttons, buffer);
} catch (Exception e) {}
ClientPlayNetworking.send(new startSleepingCallButtons(number));
} catch (Exception e) {
REServerModClient.LOGGER.info("Error when trying to network to server in DeathScreen class!");
}
}
}

View File

@ -1,21 +1,19 @@
package modchest.mixin.client;
import modchest.REServerModClient;
import modchest.networking.modNetworkingClient;
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.widget.ButtonWidget;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import modchest.networking.payload.deathMultiRespawnButtons;
@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) {
super(Text.of("useless"));
}
@ -27,51 +25,44 @@ public class SleepingChatScreen extends Screen { //Sehr identisch zu Deat
int yOffset = 5;
int xOffset = this.width / 2 - widthButton / 2;
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!");
PacketByteBuf buffer = PacketByteBufs.create();
buffer.writeInt(1);
sendPacket(buffer);
})
sendPacket(1);
}).dimensions(xOffset - 2 * (widthButton + 5), yOffset, widthButton, heightButton).build()
);
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!");
PacketByteBuf buffer = PacketByteBufs.create();
buffer.writeInt(2);
sendPacket(buffer);
})
sendPacket(2);
}).dimensions(xOffset - (widthButton + 5), yOffset, widthButton, heightButton).build()
);
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!");
PacketByteBuf buffer = PacketByteBufs.create();
buffer.writeInt(3);
sendPacket(buffer);
})
sendPacket(3);
}).dimensions(xOffset, yOffset, widthButton, heightButton).build()
);
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!");
PacketByteBuf buffer = PacketByteBufs.create();
buffer.writeInt(4);
sendPacket(buffer);
})
sendPacket(4);
}).dimensions(xOffset + (widthButton + 5), yOffset, widthButton, heightButton).build()
);
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!");
PacketByteBuf buffer = PacketByteBufs.create();
buffer.writeInt(5);
sendPacket(buffer);
})
sendPacket(5);
}).dimensions(xOffset + 2 * (widthButton + 5), yOffset, widthButton, heightButton).build()
);
}
@Unique
private synchronized void sendPacket(PacketByteBuf buffer) {
private synchronized void sendPacket(int number) {
try {
ClientPlayNetworking.send(modNetworkingClient.start_sleeping_call_buttons, buffer);
} catch (Exception e) {}
ClientPlayNetworking.send(new deathMultiRespawnButtons(number));
} catch (Exception e) {
REServerModClient.LOGGER.info("Error when trying to network to server in sleepingChatScreen class!");
}
}
}

View File

@ -2,14 +2,30 @@ package modchest.networking;
import modchest.REServerMod;
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.networking.v1.PayloadTypeRegistry;
import net.minecraft.util.Identifier;
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 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)
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
}
}

View File

@ -5,11 +5,18 @@ import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.CustomPayload;
public class respawnRequestS2CPacket {
/*
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!");
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();
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -25,3 +25,4 @@ public class ModModelProvider extends FabricModelProvider {
//itemModelGenerator.register(modItems.shipblock, Models.GENERATED); //ergänzt die Texturen für die Items
}
}
*/

View File

@ -4,6 +4,7 @@ import modchest.REServerMod;
import modchest.util.setAndGetMultiButtonsSpawn;
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
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
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

View File

@ -13,6 +13,7 @@ import net.minecraft.block.BedBlock;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Arrays;
import java.util.List;
@ -22,7 +23,7 @@ import java.util.Objects;
public class bedBlock {
@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
int posBedX = pos.getX();

View File

@ -3,7 +3,11 @@ package modchest.networking;
import modchest.REServerMod;
import modchest.networking.packet.deathScreenMultiButtonsC2SPacket;
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 modchest.networking.payload.startSleepingCallButtons;
import net.minecraft.util.Identifier;
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 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);
}
}

View File

@ -1,42 +1,37 @@
package modchest.networking.packet;
import modchest.REServerMod;
import modchest.networking.modNetworkingServer;
import modchest.networking.payload.requestRespawn;
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.minecraft.network.PacketByteBuf;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.awt.*;
import java.util.Arrays;
public class deathScreenMultiButtonsC2SPacket {
public static void receive(MinecraftServer server, ServerPlayerEntity player, //Passiert auf dem Server!!!
ServerPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) {
public static void receive(MinecraftServer server, ServerPlayerEntity player, int number) { //Passiert auf dem Server!!!
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
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) {
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;
}
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
try {
//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
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)));
REServerMod.LOGGER.info("Respawned Player " + player.getNameForScoreboard() + " at " + Arrays.toString(setAndGet.getMultiSpawn(player, num)));
setAndGet.setMultiSpawn(player, 6);

View File

@ -2,21 +2,15 @@ package modchest.networking.packet;
import modchest.REServerMod;
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.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import java.util.Arrays;
public class setNewRespawnsC2SPacket {
public static void receive(MinecraftServer server, ServerPlayerEntity player, //Passiert auf dem Server!!!
ServerPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) {
public static void receive(MinecraftServer server, ServerPlayerEntity player, int number) {
setAndGetMultiButtonsSpawn setAndGet = new setAndGetMultiButtonsSpawn();
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:
setAndGet.setMultiSpawn(player, 1); //Spawnpunkt wird gespeichert
player.sendMessage(Text.translatable("chat.modchest.multispawn.setspawn", "1"));

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}