Skip to content

Commit 73d08c0

Browse files
authored
Update to 1.20.6 (#242)
1 parent 78a5908 commit 73d08c0

File tree

11 files changed

+82
-53
lines changed

11 files changed

+82
-53
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'fabric-loom' version '1.4.+'
2+
id 'fabric-loom' version '1.6.+'
33
id 'maven-publish'
44
id 'checkstyle'
55
}

gradle.properties

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ org.gradle.jvmargs=-Xmx1G
33

44
# Fabric Properties
55
# check these on https://fabricmc.net/develop
6-
minecraft_version=1.20.2
7-
yarn_mappings=1.20.2+build.1
8-
loader_version=0.14.22
6+
minecraft_version=1.20.6
7+
yarn_mappings=1.20.6+build.1
8+
loader_version=0.15.10
99

1010
# Mod Properties
1111
mod_version = 9.2.2
1212
maven_group = io.github.cottonmc
1313
archives_base_name = LibGui
1414

1515
# Dependencies
16-
fabric_version=0.89.2+1.20.2
17-
jankson_version=6.0.0+j1.2.3
18-
modmenu_version=8.0.0
16+
fabric_version=0.97.8+1.20.6
17+
jankson_version=7.0.0+j1.2.3
18+
modmenu_version=10.0.0-beta.1
1919
libninepatch_version=1.2.0

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public ItemStack quickMove(PlayerEntity player, int index) {
170170
/** WILL MODIFY toInsert! Returns true if anything was inserted. */
171171
private boolean insertIntoExisting(ItemStack toInsert, Slot slot, PlayerEntity player) {
172172
ItemStack curSlotStack = slot.getStack();
173-
if (!curSlotStack.isEmpty() && ItemStack.canCombine(toInsert, curSlotStack) && slot.canInsert(toInsert)) {
173+
if (!curSlotStack.isEmpty() && ItemStack.areItemsAndComponentsEqual(toInsert, curSlotStack) && slot.canInsert(toInsert)) {
174174
int combinedAmount = curSlotStack.getCount() + toInsert.getCount();
175175
int maxAmount = Math.min(toInsert.getMaxCount(), slot.getMaxItemCount(toInsert));
176176
if (combinedAmount <= maxAmount) {

src/main/java/io/github/cottonmc/cotton/gui/impl/ScreenNetworkingImpl.java

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package io.github.cottonmc.cotton.gui.impl;
22

33
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
4+
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
45
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
56
import net.minecraft.entity.player.PlayerEntity;
67
import net.minecraft.network.PacketByteBuf;
8+
import net.minecraft.network.RegistryByteBuf;
9+
import net.minecraft.network.codec.PacketCodec;
10+
import net.minecraft.network.codec.PacketCodecs;
11+
import net.minecraft.network.packet.CustomPayload;
712
import net.minecraft.screen.ScreenHandler;
813
import net.minecraft.util.Identifier;
914

@@ -26,8 +31,34 @@ public class ScreenNetworkingImpl implements ScreenNetworking {
2631
// message: identifier
2732
// rest: buf
2833

29-
public static final Identifier SCREEN_MESSAGE_S2C = new Identifier(LibGuiCommon.MOD_ID, "screen_message_s2c");
30-
public static final Identifier SCREEN_MESSAGE_C2S = new Identifier(LibGuiCommon.MOD_ID, "screen_message_c2s");
34+
public record ScreenMessageData(int syncId, Identifier message, PacketByteBuf buf) {
35+
public static final PacketCodec<RegistryByteBuf, ScreenMessageData> PACKET_CODEC = PacketCodec.tuple(
36+
PacketCodecs.INTEGER, ScreenMessageData::syncId,
37+
Identifier.PACKET_CODEC, ScreenMessageData::message,
38+
PacketCodec.of(PacketByteBuf::writeBytes, packetBuf -> packetBuf.readBytes(PacketByteBufs.create())), ScreenMessageData::buf,
39+
ScreenMessageData::new
40+
);
41+
}
42+
43+
public record S2CScreenMessage(ScreenMessageData data) implements CustomPayload {
44+
public static final Id<S2CScreenMessage> PACKET_ID = new Id<>(new Identifier(LibGuiCommon.MOD_ID, "screen_message_s2c"));
45+
public static final PacketCodec<RegistryByteBuf, S2CScreenMessage> PACKET_CODEC = ScreenMessageData.PACKET_CODEC.xmap(S2CScreenMessage::new, S2CScreenMessage::data);
46+
47+
@Override
48+
public Id<? extends CustomPayload> getId() {
49+
return PACKET_ID;
50+
}
51+
}
52+
53+
public record C2SScreenMessage(ScreenMessageData data) implements CustomPayload {
54+
public static final Id<C2SScreenMessage> PACKET_ID = new Id<>(new Identifier(LibGuiCommon.MOD_ID, "screen_message_c2s"));
55+
public static final PacketCodec<RegistryByteBuf, C2SScreenMessage> PACKET_CODEC = ScreenMessageData.PACKET_CODEC.xmap(C2SScreenMessage::new, C2SScreenMessage::data);
56+
57+
@Override
58+
public Id<? extends CustomPayload> getId() {
59+
return PACKET_ID;
60+
}
61+
}
3162

3263
private static final Logger LOGGER = LogManager.getLogger();
3364
private static final Map<SyncedGuiDescription, ScreenNetworkingImpl> instanceCache = new WeakHashMap<>();
@@ -58,51 +89,48 @@ public void send(Identifier message, Consumer<PacketByteBuf> writer) {
5889
Objects.requireNonNull(writer, "writer");
5990

6091
PacketByteBuf buf = PacketByteBufs.create();
61-
buf.writeVarInt(description.syncId);
62-
buf.writeIdentifier(message);
6392
writer.accept(buf);
64-
description.getPacketSender().sendPacket(side == NetworkSide.SERVER ? SCREEN_MESSAGE_S2C : SCREEN_MESSAGE_C2S, buf);
93+
ScreenMessageData data = new ScreenMessageData(description.syncId, message, buf);
94+
description.getPacketSender().sendPacket(side == NetworkSide.SERVER ? new S2CScreenMessage(data) : new C2SScreenMessage(data));
6595
}
6696

6797
public static void init() {
68-
ServerPlayNetworking.registerGlobalReceiver(SCREEN_MESSAGE_C2S, (server, player, networkHandler, buf, responseSender) -> {
69-
handle(server, player, buf);
98+
PayloadTypeRegistry.playS2C().register(S2CScreenMessage.PACKET_ID, S2CScreenMessage.PACKET_CODEC);
99+
PayloadTypeRegistry.playC2S().register(C2SScreenMessage.PACKET_ID, C2SScreenMessage.PACKET_CODEC);
100+
ServerPlayNetworking.registerGlobalReceiver(C2SScreenMessage.PACKET_ID, (payload, context) -> {
101+
handle(context.player().server, context.player(), payload.data());
70102
});
71103
}
72104

73-
public static void handle(Executor executor, PlayerEntity player, PacketByteBuf buf) {
105+
public static void handle(Executor executor, PlayerEntity player, ScreenMessageData data) {
74106
ScreenHandler screenHandler = player.currentScreenHandler;
75107

76-
// Packet data
77-
int syncId = buf.readVarInt();
78-
Identifier messageId = buf.readIdentifier();
79-
80108
if (!(screenHandler instanceof SyncedGuiDescription)) {
81109
LOGGER.error("Received message packet for screen handler {} which is not a SyncedGuiDescription", screenHandler);
82110
return;
83-
} else if (syncId != screenHandler.syncId) {
84-
LOGGER.error("Received message for sync ID {}, current sync ID: {}", syncId, screenHandler.syncId);
111+
} else if (data.syncId() != screenHandler.syncId) {
112+
LOGGER.error("Received message for sync ID {}, current sync ID: {}", data.syncId(), screenHandler.syncId);
85113
return;
86114
}
87115

88116
ScreenNetworkingImpl networking = instanceCache.get(screenHandler);
89117

90118
if (networking != null) {
91-
MessageReceiver receiver = networking.messages.get(messageId);
119+
MessageReceiver receiver = networking.messages.get(data.message());
92120

93121
if (receiver != null) {
94-
buf.retain();
122+
data.buf().retain();
95123
executor.execute(() -> {
96124
try {
97-
receiver.onMessage(buf);
125+
receiver.onMessage(data.buf());
98126
} catch (Exception e) {
99-
LOGGER.error("Error handling screen message {} for {} on side {}", messageId, screenHandler, networking.side, e);
127+
LOGGER.error("Error handling screen message {} for {} on side {}", data.message(), screenHandler, networking.side, e);
100128
} finally {
101-
buf.release();
129+
data.buf().release();
102130
}
103131
});
104132
} else {
105-
LOGGER.warn("Message {} not registered for {} on side {}", messageId, screenHandler, networking.side);
133+
LOGGER.warn("Message {} not registered for {} on side {}", data.message(), screenHandler, networking.side);
106134
}
107135
} else {
108136
LOGGER.warn("GUI description {} does not use networking", screenHandler);

src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public class LibGuiClient implements ClientModInitializer {
2828
public void onInitializeClient() {
2929
config = loadConfig();
3030

31-
ClientPlayNetworking.registerGlobalReceiver(ScreenNetworkingImpl.SCREEN_MESSAGE_S2C, (client, networkHandler, buf, responseSender) -> {
32-
ScreenNetworkingImpl.handle(client, client.player, buf);
31+
ClientPlayNetworking.registerGlobalReceiver(ScreenNetworkingImpl.S2CScreenMessage.PACKET_ID, (payload, context) -> {
32+
ScreenNetworkingImpl.handle(context.client(), context.player(), payload.data());
3333
});
3434

3535
LibGuiShaders.register();

src/main/resources/fabric.mod.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
"java": ">=17",
2828
"fabricloader": ">=0.14.22",
2929
"fabric-api-base": ">=0.4.4",
30-
"fabric-lifecycle-events-v1": "^2.0.2",
31-
"fabric-networking-api-v1": "^3.0.5",
32-
"fabric-rendering-v1": "^3.0.6",
30+
"fabric-lifecycle-events-v1": ">=2.0.2",
31+
"fabric-networking-api-v1": ">=3.0.5",
32+
"fabric-rendering-v1": ">=3.0.6",
3333
"fabric-resource-loader-v0": "*",
34-
"minecraft": ">=1.20.2",
35-
"jankson": "^6.0.0",
34+
"minecraft": ">=1.20.5",
35+
"jankson": "^7.0.0",
3636
"libninepatch": "^1.2.0"
3737
},
3838
"suggests": {

src/testMod/java/io/github/cottonmc/test/GuiBlock.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
package io.github.cottonmc.test;
22

3-
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
3+
import com.mojang.serialization.MapCodec;
44
import net.minecraft.block.BlockRenderType;
55
import net.minecraft.block.BlockState;
66
import net.minecraft.block.BlockWithEntity;
77
import net.minecraft.block.Blocks;
88
import net.minecraft.block.entity.BlockEntity;
99
import net.minecraft.entity.player.PlayerEntity;
1010
import net.minecraft.util.ActionResult;
11-
import net.minecraft.util.Hand;
1211
import net.minecraft.util.hit.BlockHitResult;
1312
import net.minecraft.util.math.BlockPos;
1413
import net.minecraft.world.World;
1514

1615
public class GuiBlock extends BlockWithEntity {
1716

1817
public GuiBlock() {
19-
super(FabricBlockSettings.copy(Blocks.IRON_BLOCK));
18+
super(Settings.copy(Blocks.IRON_BLOCK));
2019
}
21-
20+
2221
@Override
23-
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hitResult) {
22+
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
2423
player.openHandledScreen(state.createScreenHandlerFactory(world, pos));
2524
return ActionResult.SUCCESS;
2625
}
@@ -34,4 +33,9 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
3433
public BlockRenderType getRenderType(BlockState state) {
3534
return BlockRenderType.MODEL;
3635
}
36+
37+
@Override
38+
protected MapCodec<? extends BlockWithEntity> getCodec() {
39+
return null;
40+
}
3741
}

src/testMod/java/io/github/cottonmc/test/GuiItem.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import net.minecraft.inventory.StackReference;
88
import net.minecraft.item.Item;
99
import net.minecraft.item.ItemStack;
10-
import net.minecraft.network.PacketByteBuf;
1110
import net.minecraft.screen.NamedScreenHandlerFactory;
1211
import net.minecraft.screen.ScreenHandler;
1312
import net.minecraft.server.network.ServerPlayerEntity;
@@ -35,7 +34,7 @@ private NamedScreenHandlerFactory createScreenHandlerFactory(PlayerEntity player
3534
case OFF_HAND -> EquipmentSlot.OFFHAND;
3635
};
3736
ItemStack stack = player.getStackInHand(hand);
38-
return new ExtendedScreenHandlerFactory() {
37+
return new ExtendedScreenHandlerFactory<EquipmentSlot>() {
3938
@Override
4039
public Text getDisplayName() {
4140
return stack.getName();
@@ -47,8 +46,8 @@ public ScreenHandler createMenu(int syncId, PlayerInventory playerInventory, Pla
4746
}
4847

4948
@Override
50-
public void writeScreenOpeningData(ServerPlayerEntity player, PacketByteBuf buf) {
51-
buf.writeEnumConstant(slot);
49+
public EquipmentSlot getScreenOpeningData(ServerPlayerEntity player) {
50+
return slot;
5251
}
5352
};
5453
}

src/testMod/java/io/github/cottonmc/test/LibGuiTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.github.cottonmc.test;
22

33
import net.fabricmc.api.ModInitializer;
4-
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
54
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerType;
65
import net.fabricmc.loader.api.FabricLoader;
76
import net.fabricmc.loader.api.ModContainer;
@@ -14,6 +13,7 @@
1413
import net.minecraft.inventory.StackReference;
1514
import net.minecraft.item.BlockItem;
1615
import net.minecraft.item.Item;
16+
import net.minecraft.network.codec.PacketCodecs;
1717
import net.minecraft.registry.Registries;
1818
import net.minecraft.registry.Registry;
1919
import net.minecraft.resource.featuretoggle.FeatureFlags;
@@ -49,18 +49,17 @@ public void onInitialize() {
4949
NO_BLOCK_INVENTORY_BLOCK = new NoBlockInventoryBlock(AbstractBlock.Settings.copy(Blocks.STONE));
5050
Registry.register(Registries.BLOCK, new Identifier(MODID, "no_block_inventory"), NO_BLOCK_INVENTORY_BLOCK);
5151
Registry.register(Registries.ITEM, new Identifier(MODID, "no_block_inventory"), new BlockItem(NO_BLOCK_INVENTORY_BLOCK, new Item.Settings()));
52-
GUI_BLOCKENTITY_TYPE = FabricBlockEntityTypeBuilder.create(GuiBlockEntity::new, GUI_BLOCK).build(null);
52+
GUI_BLOCKENTITY_TYPE = BlockEntityType.Builder.create(GuiBlockEntity::new, GUI_BLOCK).build(null);
5353
Registry.register(Registries.BLOCK_ENTITY_TYPE, new Identifier(MODID, "gui"), GUI_BLOCKENTITY_TYPE);
5454

5555
GUI_SCREEN_HANDLER_TYPE = new ScreenHandlerType<>((int syncId, PlayerInventory inventory) -> {
5656
return new TestDescription(GUI_SCREEN_HANDLER_TYPE, syncId, inventory, ScreenHandlerContext.EMPTY);
5757
}, FeatureSet.of(FeatureFlags.VANILLA));
5858
Registry.register(Registries.SCREEN_HANDLER, new Identifier(MODID, "gui"), GUI_SCREEN_HANDLER_TYPE);
59-
ITEM_SCREEN_HANDLER_TYPE = new ExtendedScreenHandlerType<>((syncId, inventory, buf) -> {
60-
var equipmentSlot = buf.readEnumConstant(EquipmentSlot.class);
61-
StackReference handStack = StackReference.of(inventory.player, equipmentSlot);
59+
ITEM_SCREEN_HANDLER_TYPE = new ExtendedScreenHandlerType<>((syncId, inventory, slot) -> {
60+
StackReference handStack = StackReference.of(inventory.player, slot);
6261
return new TestItemDescription(syncId, inventory, handStack);
63-
});
62+
}, PacketCodecs.codec(EquipmentSlot.CODEC).cast());
6463
Registry.register(Registries.SCREEN_HANDLER, new Identifier(MODID, "item_gui"), ITEM_SCREEN_HANDLER_TYPE);
6564

6665
REALLY_SIMPLE_SCREEN_HANDLER_TYPE = new ScreenHandlerType<>(ReallySimpleDescription::new, FeatureSet.of(FeatureFlags.VANILLA));

src/testMod/java/io/github/cottonmc/test/NoBlockInventoryBlock.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import net.minecraft.screen.ScreenHandler;
99
import net.minecraft.text.Text;
1010
import net.minecraft.util.ActionResult;
11-
import net.minecraft.util.Hand;
1211
import net.minecraft.util.hit.BlockHitResult;
1312
import net.minecraft.util.math.BlockPos;
1413
import net.minecraft.world.World;
@@ -21,7 +20,7 @@ public NoBlockInventoryBlock(Settings settings) {
2120
}
2221

2322
@Override
24-
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
23+
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
2524
player.openHandledScreen(this);
2625
return world.isClient ? ActionResult.SUCCESS : ActionResult.CONSUME;
2726
}

0 commit comments

Comments
 (0)