Skip to content

Commit e9eb3c7

Browse files
committed
Work on addressing misc TODOs
1 parent 670d34b commit e9eb3c7

15 files changed

+33
-45
lines changed

src/api/java/mekanism/api/robit/RobitSkinSerializationHelper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ private RobitSkinSerializationHelper() {
4747
*/
4848
public static final MapCodec<RobitSkin> NETWORK_CODEC = RecordCodecBuilder.mapCodec(builder -> builder.group(
4949
ExtraCodecs.nonEmptyList(ResourceLocation.CODEC.listOf()).fieldOf(SerializationConstants.TEXTURES).forGetter(RobitSkin::textures),
50-
//TODO - 1.20.5: Update wiki to state that in 1.20.6+ it is custom_model instead of customModel
5150
ResourceLocation.CODEC.optionalFieldOf(SerializationConstants.CUSTOM_MODEL).forGetter(skin -> Optional.ofNullable(skin.customModel()))
5251
).apply(builder, (textures, model) -> new BasicRobitSkin(textures, model.orElse(null))));
5352
/**

src/main/java/mekanism/common/Mekanism.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
import mekanism.common.registries.MekanismTileEntityTypes;
105105
import mekanism.common.tile.component.TileComponentChunkLoader;
106106
import mekanism.common.tile.machine.TileEntityOredictionificator.ODConfigValueInvalidationListener;
107+
import mekanism.common.util.RegistryUtils;
107108
import mekanism.common.world.GenHandler;
108109
import net.minecraft.core.GlobalPos;
109110
import net.minecraft.core.cauldron.CauldronInteraction;
@@ -423,15 +424,15 @@ private void onEnergyTransferred(EnergyTransferEvent event) {
423424
}
424425

425426
private void onChemicalTransferred(ChemicalTransferEvent event) {
426-
//TODO - 1.20.5: ??
427-
//PacketUtils.log("Sending type '{}' update message for chemical network with id {}", chemical.getChemical().getRegistryName(), networkID);
428-
PacketUtils.sendToAllTracking(event.network, new PacketNetworkScale(event.network), new PacketChemicalNetworkContents(event.network.getUUID(), event.transferType));
427+
UUID networkID = event.network.getUUID();
428+
PacketUtils.log("Sending type '{}' update message for chemical network with id {}", event.transferType.getChemical().getRegistryName(), networkID);
429+
PacketUtils.sendToAllTracking(event.network, new PacketNetworkScale(event.network), new PacketChemicalNetworkContents(networkID, event.transferType));
429430
}
430431

431432
private void onLiquidTransferred(FluidTransferEvent event) {
432-
//TODO - 1.20.5:??
433-
//PacketUtils.log("Sending type '{}' update message for fluid network with id {}", RegistryUtils.getName(fluid.getFluid()), networkID);
434-
PacketUtils.sendToAllTracking(event.network, new PacketNetworkScale(event.network), new PacketFluidNetworkContents(event.network.getUUID(), event.fluidType));
433+
UUID networkID = event.network.getUUID();
434+
PacketUtils.log("Sending type '{}' update message for fluid network with id {}", RegistryUtils.getName(event.fluidType.getFluid()), networkID);
435+
PacketUtils.sendToAllTracking(event.network, new PacketNetworkScale(event.network), new PacketFluidNetworkContents(networkID, event.fluidType));
435436
}
436437

437438
private void onConfigLoad(ModConfigEvent configEvent) {

src/main/java/mekanism/common/attachments/BlockData.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public record BlockData(BlockState blockState, @Nullable CompoundTag blockEntity
4343
BlockState.CODEC.fieldOf(SerializationConstants.STATE).forGetter(BlockData::blockState),
4444
CompoundTag.CODEC.optionalFieldOf(SerializationConstants.BLOCK_ENTITY_TAG).forGetter(data -> Optional.ofNullable(data.blockEntityTag))
4545
).apply(instance, (state, tag) -> new BlockData(state, tag.orElse(null))));
46-
//TODO - 1.20.5: Test this and see if there is a proper stream codec for block states
4746
public static final StreamCodec<ByteBuf, BlockData> STREAM_CODEC = StreamCodec.composite(
4847
ByteBufCodecs.fromCodecTrusted(BlockState.CODEC), BlockData::blockState,
4948
ByteBufCodecs.optional(ByteBufCodecs.TRUSTED_COMPOUND_TAG), data -> Optional.ofNullable(data.blockEntityTag()),

src/main/java/mekanism/common/content/network/transmitter/LogisticalTransporter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void parseUpgradeData(@NotNull LogisticalTransporterUpgradeData data) {
8787
@Override
8888
protected void readFromNBT(HolderLookup.Provider provider, CompoundTag nbtTags) {
8989
super.readFromNBT(provider, nbtTags);
90-
setColor(NBTUtils.getEnum(nbtTags, SerializationConstants.COLOR, TransporterUtils::readColor));
90+
setColor(NBTUtils.getEnum(nbtTags, SerializationConstants.COLOR, EnumColor.BY_ID));
9191
}
9292

9393
@Override
@@ -111,6 +111,6 @@ public CompoundTag getReducedUpdateTag(@NotNull HolderLookup.Provider provider,
111111
@Override
112112
public void handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Provider provider) {
113113
super.handleUpdateTag(tag, provider);
114-
setColor(NBTUtils.getEnum(tag, SerializationConstants.COLOR, TransporterUtils::readColor));
114+
setColor(NBTUtils.getEnum(tag, SerializationConstants.COLOR, EnumColor.BY_ID));
115115
}
116116
}

src/main/java/mekanism/common/content/transporter/TransporterStack.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import mekanism.common.lib.inventory.TransitRequest;
1818
import mekanism.common.lib.inventory.TransitRequest.TransitResponse;
1919
import mekanism.common.util.NBTUtils;
20-
import mekanism.common.util.TransporterUtils;
2120
import mekanism.common.util.WorldUtils;
2221
import net.minecraft.core.BlockPos;
2322
import net.minecraft.core.Direction;
@@ -109,7 +108,7 @@ public void writeToUpdateTag(HolderLookup.Provider provider, LogisticalTransport
109108
}
110109

111110
public void readFromUpdateTag(HolderLookup.Provider provider, CompoundTag updateTag) {
112-
this.color = NBTUtils.getEnum(updateTag, SerializationConstants.COLOR, TransporterUtils::readColor);
111+
this.color = NBTUtils.getEnum(updateTag, SerializationConstants.COLOR, EnumColor.BY_ID);
113112
progress = updateTag.getInt(SerializationConstants.PROGRESS);
114113
NBTUtils.setBlockPosIfPresent(updateTag, SerializationConstants.ORIGINAL_LOCATION, coord -> originalLocation = coord);
115114
NBTUtils.setEnumIfPresent(updateTag, SerializationConstants.PATH_TYPE, Path.BY_ID, type -> pathType = type);
@@ -141,7 +140,7 @@ public void write(HolderLookup.Provider provider, CompoundTag nbtTags) {
141140
}
142141

143142
public void read(HolderLookup.Provider provider, CompoundTag nbtTags) {
144-
this.color = NBTUtils.getEnum(nbtTags, SerializationConstants.COLOR, TransporterUtils::readColor);
143+
this.color = NBTUtils.getEnum(nbtTags, SerializationConstants.COLOR, EnumColor.BY_ID);
145144
progress = nbtTags.getInt(SerializationConstants.PROGRESS);
146145
NBTUtils.setBlockPosIfPresent(nbtTags, SerializationConstants.ORIGINAL_LOCATION, coord -> originalLocation = coord);
147146
NBTUtils.setEnumIfPresent(nbtTags, SerializationConstants.IDLE_DIR, Direction::from3DDataValue, dir -> idleDir = dir);

src/main/java/mekanism/common/network/PacketUtils.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import net.minecraft.server.level.ServerPlayer;
3636
import net.minecraft.server.players.PlayerList;
3737
import net.minecraft.tags.TagKey;
38+
import net.minecraft.util.ByIdMap;
3839
import net.minecraft.world.InteractionHand;
3940
import net.minecraft.world.entity.EquipmentSlot;
4041
import net.minecraft.world.level.ChunkPos;
@@ -43,7 +44,6 @@
4344
import net.minecraft.world.phys.BlockHitResult;
4445
import net.minecraft.world.phys.Vec3;
4546
import net.neoforged.neoforge.network.PacketDistributor;
46-
import net.neoforged.neoforge.network.codec.NeoForgeStreamCodecs;
4747
import net.neoforged.neoforge.network.handling.IPayloadContext;
4848
import net.neoforged.neoforge.server.ServerLifecycleHooks;
4949
import org.jetbrains.annotations.NotNull;
@@ -58,16 +58,20 @@ private PacketUtils() {
5858
public static final int LAST_USERNAME_LENGTH = Math.max(SharedConstants.MAX_PLAYER_NAME_LENGTH, 38);
5959

6060
public static final StreamCodec<FriendlyByteBuf, BlockHitResult> BLOCK_HIT_RESULT_STREAM_CODEC = StreamCodec.of(FriendlyByteBuf::writeBlockHitResult, FriendlyByteBuf::readBlockHitResult);
61-
//TODO - 1.20.5: Do we want this ot be FriendlyByteBuf or do like vanilla does and make an id mapping and let it just be a ByteBuf?
62-
public static final StreamCodec<FriendlyByteBuf, InteractionHand> INTERACTION_HAND_STREAM_CODEC = NeoForgeStreamCodecs.enumCodec(InteractionHand.class);
63-
public static final StreamCodec<FriendlyByteBuf, EquipmentSlot> EQUIPMENT_SLOT_STREAM_CODEC = NeoForgeStreamCodecs.enumCodec(EquipmentSlot.class);
61+
public static final StreamCodec<ByteBuf, InteractionHand> INTERACTION_HAND_STREAM_CODEC = enumCodec(InteractionHand.class);
62+
public static final StreamCodec<ByteBuf, EquipmentSlot> EQUIPMENT_SLOT_STREAM_CODEC = enumCodec(EquipmentSlot.class);
6463
public static final StreamCodec<ByteBuf, Vec3> VEC3_STREAM_CODEC = StreamCodec.composite(
6564
ByteBufCodecs.DOUBLE, Vec3::x,
6665
ByteBufCodecs.DOUBLE, Vec3::y,
6766
ByteBufCodecs.DOUBLE, Vec3::z,
6867
Vec3::new
6968
);
7069

70+
//Similar to NeoForgeStreamCodecs#enumCodec but allows for keeping it as a ByteBuf and wrapping the value
71+
public static <V extends Enum<V>> StreamCodec<ByteBuf, V> enumCodec(Class<V> enumClass) {
72+
return ByteBufCodecs.idMapper(ByIdMap.continuous(Enum::ordinal, enumClass.getEnumConstants(), ByIdMap.OutOfBoundsStrategy.WRAP), Enum::ordinal);
73+
}
74+
7175
public static void log(String logFormat, Object... params) {
7276
//TODO: Add more logging for packets using this
7377
if (MekanismConfig.general.logPackets.get()) {

src/main/java/mekanism/common/network/to_server/PacketItemGuiInteract.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import mekanism.common.network.IMekanismPacket;
1010
import mekanism.common.network.PacketUtils;
1111
import mekanism.common.registries.MekanismDataComponents;
12-
import net.minecraft.network.FriendlyByteBuf;
1312
import net.minecraft.network.codec.ByteBufCodecs;
1413
import net.minecraft.network.codec.StreamCodec;
1514
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
@@ -23,7 +22,7 @@
2322
public record PacketItemGuiInteract(ItemGuiInteraction interaction, InteractionHand hand, int extra) implements IMekanismPacket {
2423

2524
public static final CustomPacketPayload.Type<PacketItemGuiInteract> TYPE = new CustomPacketPayload.Type<>(Mekanism.rl("item_gui_interact"));
26-
public static final StreamCodec<FriendlyByteBuf, PacketItemGuiInteract> STREAM_CODEC = StreamCodec.composite(
25+
public static final StreamCodec<ByteBuf, PacketItemGuiInteract> STREAM_CODEC = StreamCodec.composite(
2726
ItemGuiInteraction.STREAM_CODEC, PacketItemGuiInteract::interaction,
2827
PacketUtils.INTERACTION_HAND_STREAM_CODEC, PacketItemGuiInteract::hand,
2928
ByteBufCodecs.VAR_INT, PacketItemGuiInteract::extra,

src/main/java/mekanism/common/network/to_server/PacketModeChange.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package mekanism.common.network.to_server;
22

3+
import io.netty.buffer.ByteBuf;
34
import mekanism.common.Mekanism;
45
import mekanism.common.item.interfaces.IModeItem;
56
import mekanism.common.item.interfaces.IModeItem.DisplayChange;
67
import mekanism.common.network.IMekanismPacket;
78
import mekanism.common.network.PacketUtils;
8-
import net.minecraft.network.FriendlyByteBuf;
99
import net.minecraft.network.codec.ByteBufCodecs;
1010
import net.minecraft.network.codec.StreamCodec;
1111
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
@@ -18,7 +18,7 @@
1818
public record PacketModeChange(EquipmentSlot slot, int shift, boolean displayChangeMessage) implements IMekanismPacket {
1919

2020
public static final CustomPacketPayload.Type<PacketModeChange> TYPE = new CustomPacketPayload.Type<>(Mekanism.rl("mode"));
21-
public static final StreamCodec<FriendlyByteBuf, PacketModeChange> STREAM_CODEC = StreamCodec.composite(
21+
public static final StreamCodec<ByteBuf, PacketModeChange> STREAM_CODEC = StreamCodec.composite(
2222
PacketUtils.EQUIPMENT_SLOT_STREAM_CODEC, PacketModeChange::slot,
2323
ByteBufCodecs.VAR_INT, PacketModeChange::shift,
2424
ByteBufCodecs.BOOL, PacketModeChange::displayChangeMessage,

src/main/java/mekanism/common/network/to_server/PacketPortableTeleporterTeleport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package mekanism.common.network.to_server;
22

3+
import io.netty.buffer.ByteBuf;
34
import mekanism.api.Action;
45
import mekanism.api.AutomationType;
56
import mekanism.api.energy.IEnergyContainer;
@@ -18,7 +19,6 @@
1819
import mekanism.common.util.WorldUtils;
1920
import net.minecraft.core.BlockPos;
2021
import net.minecraft.core.GlobalPos;
21-
import net.minecraft.network.RegistryFriendlyByteBuf;
2222
import net.minecraft.network.codec.StreamCodec;
2323
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
2424
import net.minecraft.server.MinecraftServer;
@@ -35,7 +35,7 @@
3535
public record PacketPortableTeleporterTeleport(InteractionHand currentHand, FrequencyIdentity identity) implements IMekanismPacket {
3636

3737
public static final CustomPacketPayload.Type<PacketPortableTeleporterTeleport> TYPE = new CustomPacketPayload.Type<>(Mekanism.rl("portable_teleport"));
38-
public static final StreamCodec<RegistryFriendlyByteBuf, PacketPortableTeleporterTeleport> STREAM_CODEC = StreamCodec.composite(
38+
public static final StreamCodec<ByteBuf, PacketPortableTeleporterTeleport> STREAM_CODEC = StreamCodec.composite(
3939
PacketUtils.INTERACTION_HAND_STREAM_CODEC, PacketPortableTeleporterTeleport::currentHand,
4040
FrequencyType.TELEPORTER.getIdentitySerializer().streamCodec(), PacketPortableTeleporterTeleport::identity,
4141
PacketPortableTeleporterTeleport::new

src/main/java/mekanism/common/network/to_server/PacketRadialModeChange.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package mekanism.common.network.to_server;
22

3+
import io.netty.buffer.ByteBuf;
34
import java.util.List;
45
import mekanism.api.radial.RadialData;
56
import mekanism.api.radial.mode.INestedRadialMode;
@@ -8,7 +9,6 @@
89
import mekanism.common.lib.radial.IGenericRadialModeItem;
910
import mekanism.common.network.IMekanismPacket;
1011
import mekanism.common.network.PacketUtils;
11-
import net.minecraft.network.FriendlyByteBuf;
1212
import net.minecraft.network.codec.ByteBufCodecs;
1313
import net.minecraft.network.codec.StreamCodec;
1414
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
@@ -22,7 +22,7 @@
2222
public record PacketRadialModeChange(EquipmentSlot slot, List<ResourceLocation> path, int networkRepresentation) implements IMekanismPacket {
2323

2424
public static final CustomPacketPayload.Type<PacketRadialModeChange> TYPE = new CustomPacketPayload.Type<>(Mekanism.rl("radial_mode"));
25-
public static final StreamCodec<FriendlyByteBuf, PacketRadialModeChange> STREAM_CODEC = StreamCodec.composite(
25+
public static final StreamCodec<ByteBuf, PacketRadialModeChange> STREAM_CODEC = StreamCodec.composite(
2626
PacketUtils.EQUIPMENT_SLOT_STREAM_CODEC, PacketRadialModeChange::slot,
2727
ResourceLocation.STREAM_CODEC.apply(ByteBufCodecs.list()), PacketRadialModeChange::path,
2828
ByteBufCodecs.VAR_INT, PacketRadialModeChange::networkRepresentation,

0 commit comments

Comments
 (0)