Skip to content

Commit

Permalink
get dedicated servers actually working
Browse files Browse the repository at this point in the history
  • Loading branch information
fzzyhmstrs committed Sep 12, 2024
1 parent c438d1f commit d0d3dbb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 33 deletions.
14 changes: 7 additions & 7 deletions xplat/src/main/java/fzzyhmstrs/emi_loot/EMILoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.JsonElement;
import fzzyhmstrs.emi_loot.client.ClientLootTables;
import fzzyhmstrs.emi_loot.client.ClientLootTablesReceiver;
import fzzyhmstrs.emi_loot.networking.ArchaeologyLootPayload;
import fzzyhmstrs.emi_loot.networking.BlockLootPayload;
import fzzyhmstrs.emi_loot.networking.ChestLootPayload;
Expand All @@ -16,7 +17,6 @@
import me.fzzyhmstrs.fzzy_config.annotations.IgnoreVisibility;
import me.fzzyhmstrs.fzzy_config.annotations.NonSync;
import me.fzzyhmstrs.fzzy_config.annotations.RequiresAction;
import me.fzzyhmstrs.fzzy_config.annotations.RequiresRestart;
import me.fzzyhmstrs.fzzy_config.annotations.Version;
import me.fzzyhmstrs.fzzy_config.api.ConfigApi;
import me.fzzyhmstrs.fzzy_config.api.ConfigApiJava;
Expand Down Expand Up @@ -70,11 +70,11 @@ public static Identifier identity(String path) {

public static void onInitialize() {
ConfigApi.INSTANCE.network().registerS2C(ClearPayload.TYPE, ClearPayload.CODEC, (payload, ctx) -> ClientLootTables.INSTANCE.clearLoots());
ConfigApi.INSTANCE.network().registerS2C(ChestLootPayload.TYPE, ChestLootPayload.CODEC, (payload, ctx) -> ClientLootTables.INSTANCE.receiveChestSender(payload, ctx));
ConfigApi.INSTANCE.network().registerS2C(BlockLootPayload.TYPE, BlockLootPayload.CODEC, (payload, ctx) -> ClientLootTables.INSTANCE.receiveBlockSender(payload, ctx));
ConfigApi.INSTANCE.network().registerS2C(MobLootPayload.TYPE, MobLootPayload.CODEC, (payload, ctx) -> ClientLootTables.INSTANCE.receiveMobSender(payload, ctx));
ConfigApi.INSTANCE.network().registerS2C(GameplayLootPayload.TYPE, GameplayLootPayload.CODEC, (payload, ctx) -> ClientLootTables.INSTANCE.receiveGameplaySender(payload, ctx));
ConfigApi.INSTANCE.network().registerS2C(ArchaeologyLootPayload.TYPE, ArchaeologyLootPayload.CODEC, (payload, ctx) -> ClientLootTables.INSTANCE.receiveArchaeologySender(payload, ctx));
ConfigApi.INSTANCE.network().registerS2C(ChestLootPayload.TYPE, ChestLootPayload.CODEC, ClientLootTablesReceiver::receiveChestSender);
ConfigApi.INSTANCE.network().registerS2C(BlockLootPayload.TYPE, BlockLootPayload.CODEC, ClientLootTablesReceiver::receiveBlockSender);
ConfigApi.INSTANCE.network().registerS2C(MobLootPayload.TYPE, MobLootPayload.CODEC, ClientLootTablesReceiver::receiveMobSender);
ConfigApi.INSTANCE.network().registerS2C(GameplayLootPayload.TYPE, GameplayLootPayload.CODEC, ClientLootTablesReceiver::receiveGameplaySender);
ConfigApi.INSTANCE.network().registerS2C(ArchaeologyLootPayload.TYPE, ArchaeologyLootPayload.CODEC, ClientLootTablesReceiver::receiveArchaeologySender);
}

public static void parseTables(ResourceManager resourceManager, Registry<LootTable> lootManager, RegistryOps<JsonElement> ops) {
Expand Down Expand Up @@ -212,4 +212,4 @@ public enum Type {
this.logUntranslatedTablesSupplier = logUntranslatedTablesSupplier;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,54 +27,34 @@ public void clearLoots() {
loots.clear();
}

public void receiveChestSender(payload: ChestLootPayload, context: ClientPlayNetworkContext) {
receiveChestSender(payload.buf(), ctx.player().clientWorld)
}

private void receiveChestSender(PacketByteBuf buf, World world) {
void receiveChestSender(PacketByteBuf buf, World world) {
LootReceiver table = ClientChestLootTable.INSTANCE.fromBuf(buf, world);
loots.add(table);
if (EMILoot.config.isDebug(EMILoot.Type.CHEST)) EMILoot.LOGGER.info("received chest " + table.getId());
}

public void receiveBlockSender(payload: ChestLootPayload, context: ClientPlayNetworkContext) {
receiveBlockSender(payload.buf(), ctx.player().clientWorld)
}

private void receiveBlockSender(PacketByteBuf buf, World world) {
void receiveBlockSender(PacketByteBuf buf, World world) {
LootReceiver table = ClientBlockLootTable.INSTANCE.fromBuf(buf, world);
loots.add(table);
if (EMILoot.config.isDebug(EMILoot.Type.BLOCK)) EMILoot.LOGGER.info("received block " + table.getId());
}

public void receiveMobSender(payload: ChestLootPayload, context: ClientPlayNetworkContext) {
receiveMobSender(payload.buf(), ctx.player().clientWorld)
}

private void receiveMobSender(PacketByteBuf buf, World world) {
void receiveMobSender(PacketByteBuf buf, World world) {
LootReceiver table = ClientMobLootTable.INSTANCE.fromBuf(buf, world);
loots.add(table);
if (EMILoot.config.isDebug(EMILoot.Type.MOB)) EMILoot.LOGGER.info("received mob " + table.getId());
}

public void receiveGameplaySender(payload: ChestLootPayload, context: ClientPlayNetworkContext) {
receiveGameplaySender(payload.buf(), ctx.player().clientWorld)
}

private void receiveGameplaySender(PacketByteBuf buf, World world) {
void receiveGameplaySender(PacketByteBuf buf, World world) {
LootReceiver table = ClientGameplayLootTable.INSTANCE.fromBuf(buf, world);
loots.add(table);
if (EMILoot.config.isDebug(EMILoot.Type.GAMEPLAY)) EMILoot.LOGGER.info("received gameplay loot: " + table.getId());
}

public void receiveArchaeologySender(payload: ChestLootPayload, context: ClientPlayNetworkContext) {
receiveArchaeologySender(payload.buf(), ctx.player().clientWorld)
}

private void receiveArchaeologySender(PacketByteBuf buf, World world) {
void receiveArchaeologySender(PacketByteBuf buf, World world) {
LootReceiver table = ClientArchaeologyLootTable.INSTANCE.fromBuf(buf, world);
loots.add(table);
if (EMILoot.config.isDebug(EMILoot.Type.ARCHAEOLOGY)) EMILoot.LOGGER.info("received archaeology loot: " + table.getId());
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package fzzyhmstrs.emi_loot.client;

import fzzyhmstrs.emi_loot.networking.ArchaeologyLootPayload;
import fzzyhmstrs.emi_loot.networking.BlockLootPayload;
import fzzyhmstrs.emi_loot.networking.ChestLootPayload;
import fzzyhmstrs.emi_loot.networking.GameplayLootPayload;
import fzzyhmstrs.emi_loot.networking.MobLootPayload;
import me.fzzyhmstrs.fzzy_config.networking.api.ClientPlayNetworkContext;

public class ClientLootTablesReceiver {

public static void receiveChestSender(ChestLootPayload payload, ClientPlayNetworkContext ctx) {
ClientLootTables.INSTANCE.receiveChestSender(payload.buf(), ctx.player().getWorld());
}

public static void receiveBlockSender(BlockLootPayload payload, ClientPlayNetworkContext ctx) {
ClientLootTables.INSTANCE.receiveBlockSender(payload.buf(), ctx.player().getWorld());
}

public static void receiveMobSender(MobLootPayload payload, ClientPlayNetworkContext ctx) {
ClientLootTables.INSTANCE.receiveMobSender(payload.buf(), ctx.player().getWorld());
}

public static void receiveGameplaySender(GameplayLootPayload payload, ClientPlayNetworkContext ctx) {
ClientLootTables.INSTANCE.receiveGameplaySender(payload.buf(), ctx.player().getWorld());
}

public static void receiveArchaeologySender(ArchaeologyLootPayload payload, ClientPlayNetworkContext ctx) {
ClientLootTables.INSTANCE.receiveArchaeologySender(payload.buf(), ctx.player().getWorld());
}

}

0 comments on commit d0d3dbb

Please sign in to comment.