Skip to content

Commit

Permalink
update to a working crochet version, fix level sync
Browse files Browse the repository at this point in the history
  • Loading branch information
LemmaEOF committed May 17, 2019
1 parent 0f31226 commit 516d884
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if(rootProject.file('private.gradle').exists()) { //Publishing details

archivesBaseName = "skillcheck"
group = "io.github.cottonmc"
version = "1.0.4+1.14.1"
version = "1.0.5+1.14.1"

minecraft {
refmapName = 'mixins.skillcheck.refmap.json'
Expand All @@ -58,8 +58,8 @@ dependencies {
modCompile "io.github.prospector.modmenu:ModMenu:1.5.3-84"
modCompile "io.github.cottonmc:cotton:0.6.6+1.14.1-SNAPSHOT"
include "io.github.cottonmc:cotton:0.6.6+1.14.1-SNAPSHOT"
modCompile "crochet:Crochet:1.0.2"
include "crochet:Crochet:1.0.2"
modCompile "crochet:Crochet:1.0.3:1"
include "crochet:Crochet:1.0.3:1"
modCompile "cloth-config:ClothConfig:0.2.1.14"
include "cloth-config:ClothConfig:0.2.1.14"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import io.netty.buffer.Unpooled;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.packet.CustomPayloadS2CPacket;
import net.minecraft.container.Container;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.network.packet.CustomPayloadC2SPacket;
import net.minecraft.util.Identifier;
import net.minecraft.util.PacketByteBuf;
Expand All @@ -17,22 +20,29 @@ public class SkillCheckNetworking {

public static final Identifier SYNC_SELECTION = new Identifier(SkillCheck.MOD_ID, "sync_selection");
public static final Identifier SYNC_LEVELUP = new Identifier(SkillCheck.MOD_ID, "sync_levelup");
public static final Identifier SYNC_PLAYER_LEVEL = new Identifier(SkillCheck.MOD_ID, "sync_player_level");

public static void init() {
ServerSidePacketRegistry.INSTANCE.register(SYNC_SELECTION, ((packetContext, packetByteBuf) -> {
ServerSidePacketRegistry.INSTANCE.register(SYNC_SELECTION, (packetContext, packetByteBuf) -> {
Container container = packetContext.getPlayer().container;
if (container instanceof CharacterSheetContainer) {
int index = packetByteBuf.readInt();
CharacterSheetContainer table = (CharacterSheetContainer)container;
table.setCurrentSkill(index);
}
}));
ServerSidePacketRegistry.INSTANCE.register(SYNC_LEVELUP, (((packetContext, packetByteBuf) -> {
});
ServerSidePacketRegistry.INSTANCE.register(SYNC_LEVELUP, (packetContext, packetByteBuf) -> {
Identifier id = packetByteBuf.readIdentifier();
int xpCost = packetByteBuf.readInt();
if (!packetContext.getPlayer().isCreative()) packetContext.getPlayer().experienceLevel -= xpCost;
if (!packetContext.getPlayer().isCreative()) {
packetContext.getPlayer().experienceLevel -= xpCost;
setSyncPlayerLevel(packetContext.getPlayer().experienceLevel, (ServerPlayerEntity)packetContext.getPlayer());
}
ClassManager.levelUp(packetContext.getPlayer(), id);
})));
});
ClientSidePacketRegistry.INSTANCE.register(SYNC_PLAYER_LEVEL, (packetContext, packetByteBuf) -> {
packetContext.getPlayer().experienceLevel = packetByteBuf.readInt();
});
}

@Environment(EnvType.CLIENT)
Expand All @@ -42,10 +52,18 @@ public static void syncSelection(int index) {
MinecraftClient.getInstance().getNetworkHandler().getClientConnection().send(new CustomPayloadC2SPacket(SYNC_SELECTION, buf));
}

@Environment(EnvType.CLIENT)
public static void syncLevelup(Identifier id, int xpCost) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeIdentifier(id);
buf.writeInt(xpCost);
MinecraftClient.getInstance().getNetworkHandler().getClientConnection().send(new CustomPayloadC2SPacket(SYNC_LEVELUP, buf));
}

@Environment(EnvType.CLIENT)
public static void setSyncPlayerLevel(int level, ServerPlayerEntity player) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeInt(level);
player.networkHandler.sendPacket(new CustomPayloadS2CPacket(SYNC_PLAYER_LEVEL, buf));
}
}

0 comments on commit 516d884

Please sign in to comment.