Skip to content

Commit ab5dccc

Browse files
committed
Minor cleanup of some serialization constants, and switch constants that aren't used for representing vanilla stuff to using snake case which is what vanilla has been moving to for use in codecs
1 parent fb5ab39 commit ab5dccc

28 files changed

+200
-256
lines changed

src/api/java/mekanism/api/SerializationConstants.java

Lines changed: 124 additions & 132 deletions
Large diffs are not rendered by default.

src/api/java/mekanism/api/chemical/Chemical.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public abstract class Chemical<CHEMICAL extends Chemical<CHEMICAL>> implements I
4040
* @see mekanism.api.chemical.merged.BoxedChemical
4141
* @since 10.6.0
4242
*/
43-
public static final Codec<Chemical<?>> BOXED_OPTIONAL_CODEC = ChemicalType.CODEC.dispatch(SerializationConstants.CHEMICAL_TYPE, ChemicalType::getTypeFor,
43+
public static final Codec<Chemical<?>> BOXED_OPTIONAL_CODEC = ChemicalType.CODEC.dispatch(SerializationConstants.TYPE, ChemicalType::getTypeFor,
4444
type -> switch (type) {
4545
case GAS -> MekanismAPI.GAS_REGISTRY.byNameCodec().fieldOf(SerializationConstants.GAS);
4646
case INFUSION -> MekanismAPI.INFUSE_TYPE_REGISTRY.byNameCodec().fieldOf(SerializationConstants.INFUSE_TYPE);

src/api/java/mekanism/api/chemical/ChemicalStack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public void encode(RegistryFriendlyByteBuf buffer, STACK stack) {
164164
* @see mekanism.api.chemical.merged.BoxedChemicalStack
165165
* @since 10.6.0
166166
*/
167-
public static final Codec<ChemicalStack<?>> BOXED_CODEC = ChemicalType.CODEC.dispatch(SerializationConstants.CHEMICAL_TYPE, ChemicalType::getTypeFor, type -> switch (type) {
167+
public static final Codec<ChemicalStack<?>> BOXED_CODEC = ChemicalType.CODEC.dispatch(SerializationConstants.TYPE, ChemicalType::getTypeFor, type -> switch (type) {
168168
case GAS -> GasStack.MAP_CODEC;
169169
case INFUSION -> InfusionStack.MAP_CODEC;
170170
case PIGMENT -> PigmentStack.MAP_CODEC;

src/api/java/mekanism/api/chemical/ChemicalType.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.Map;
77
import java.util.function.IntFunction;
88
import java.util.function.Predicate;
9-
import mekanism.api.SerializationConstants;
109
import mekanism.api.chemical.gas.Gas;
1110
import mekanism.api.chemical.gas.IGasHandler;
1211
import mekanism.api.chemical.gas.IGasTank;
@@ -29,8 +28,6 @@
2928
import mekanism.api.recipes.ingredients.chemical.IInfusionIngredient;
3029
import mekanism.api.recipes.ingredients.chemical.IPigmentIngredient;
3130
import mekanism.api.recipes.ingredients.chemical.ISlurryIngredient;
32-
import net.minecraft.nbt.CompoundTag;
33-
import net.minecraft.nbt.Tag;
3431
import net.minecraft.network.codec.ByteBufCodecs;
3532
import net.minecraft.network.codec.StreamCodec;
3633
import net.minecraft.util.ByIdMap;
@@ -100,15 +97,6 @@ public boolean isInstance(Chemical<?> chemical) {
10097
return instanceCheck.test(chemical);
10198
}
10299

103-
/**
104-
* Writes a Chemical Type to NBT.
105-
*
106-
* @param nbt Tag to write to.
107-
*/
108-
public void write(@NotNull CompoundTag nbt) {
109-
nbt.putString(SerializationConstants.CHEMICAL_TYPE, getSerializedName());
110-
}
111-
112100
/**
113101
* Gets a chemical type by name.
114102
*
@@ -121,21 +109,6 @@ public static ChemicalType fromString(String name) {
121109
return nameToType.get(name);
122110
}
123111

124-
/**
125-
* Reads a Chemical Type from NBT.
126-
*
127-
* @param nbt NBT.
128-
*
129-
* @return Chemical Type.
130-
*/
131-
@Nullable
132-
public static ChemicalType fromNBT(@Nullable CompoundTag nbt) {
133-
if (nbt != null && nbt.contains(SerializationConstants.CHEMICAL_TYPE, Tag.TAG_STRING)) {
134-
return fromString(nbt.getString(SerializationConstants.CHEMICAL_TYPE));
135-
}
136-
return null;
137-
}
138-
139112
/**
140113
* Gets the Chemical Type of a chemical.
141114
*

src/generators/java/mekanism/generators/common/content/fission/FissionReactorMultiblockData.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,19 @@ public void readUpdateTag(CompoundTag tag, HolderLookup.Provider provider) {
255255
NBTUtils.setFloatIfPresent(tag, SerializationConstants.SCALE_ALT_2, scale -> prevHeatedCoolantScale = scale);
256256
NBTUtils.setFloatIfPresent(tag, SerializationConstants.SCALE_ALT_3, scale -> prevWasteScale = scale);
257257
NBTUtils.setIntIfPresent(tag, SerializationConstants.VOLUME, this::setVolume);
258-
NBTUtils.setFluidStackIfPresent(provider, tag, SerializationConstants.FLUID_STORED, value -> fluidCoolantTank.setStack(value));
259-
NBTUtils.setGasStackIfPresent(provider, tag, SerializationConstants.GAS_STORED, value -> fuelTank.setStack(value));
258+
NBTUtils.setFluidStackIfPresent(provider, tag, SerializationConstants.FLUID, value -> fluidCoolantTank.setStack(value));
259+
NBTUtils.setGasStackIfPresent(provider, tag, SerializationConstants.GAS, value -> fuelTank.setStack(value));
260260
NBTUtils.setGasStackIfPresent(provider, tag, SerializationConstants.GAS_STORED_ALT, value -> heatedCoolantTank.setStack(value));
261261
NBTUtils.setGasStackIfPresent(provider, tag, SerializationConstants.GAS_STORED_ALT_2, value -> wasteTank.setStack(value));
262262
readValves(tag);
263263
assemblies.clear();
264264
if (tag.contains(SerializationConstants.ASSEMBLIES, Tag.TAG_LIST)) {
265265
ListTag list = tag.getList(SerializationConstants.ASSEMBLIES, Tag.TAG_COMPOUND);
266266
for (int i = 0; i < list.size(); i++) {
267-
assemblies.add(FormedAssembly.read(list.getCompound(i)));
267+
FormedAssembly assembly = FormedAssembly.read(list.getCompound(i));
268+
if (assembly != null) {
269+
assemblies.add(assembly);
270+
}
268271
}
269272
}
270273
}
@@ -277,8 +280,8 @@ public void writeUpdateTag(CompoundTag tag, HolderLookup.Provider provider) {
277280
tag.putFloat(SerializationConstants.SCALE_ALT_2, prevHeatedCoolantScale);
278281
tag.putFloat(SerializationConstants.SCALE_ALT_3, prevWasteScale);
279282
tag.putInt(SerializationConstants.VOLUME, getVolume());
280-
tag.put(SerializationConstants.FLUID_STORED, fluidCoolantTank.getFluid().saveOptional(provider));
281-
tag.put(SerializationConstants.GAS_STORED, fuelTank.getStack().saveOptional(provider));
283+
tag.put(SerializationConstants.FLUID, fluidCoolantTank.getFluid().saveOptional(provider));
284+
tag.put(SerializationConstants.GAS, fuelTank.getStack().saveOptional(provider));
282285
tag.put(SerializationConstants.GAS_STORED_ALT, heatedCoolantTank.getStack().saveOptional(provider));
283286
tag.put(SerializationConstants.GAS_STORED_ALT_2, wasteTank.getStack().saveOptional(provider));
284287
writeValves(tag);

src/generators/java/mekanism/generators/common/content/fission/FissionReactorValidator.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
import net.minecraft.core.Direction;
2727
import net.minecraft.core.Vec3i;
2828
import net.minecraft.nbt.CompoundTag;
29+
import net.minecraft.nbt.NbtUtils;
2930
import net.minecraft.world.level.block.Block;
3031
import net.minecraft.world.level.block.entity.BlockEntity;
3132
import net.minecraft.world.level.block.state.BlockState;
3233
import net.minecraft.world.level.chunk.ChunkAccess;
34+
import org.jetbrains.annotations.Nullable;
3335

3436
public class FissionReactorValidator extends CuboidStructureValidator<FissionReactorMultiblockData> {
3537

@@ -158,16 +160,18 @@ public record FormedAssembly(BlockPos pos, int height) {
158160

159161
public CompoundTag write() {
160162
CompoundTag ret = new CompoundTag();
161-
ret.putInt(SerializationConstants.X, pos.getX());
162-
ret.putInt(SerializationConstants.Y, pos.getY());
163-
ret.putInt(SerializationConstants.Z, pos.getZ());
163+
ret.put(SerializationConstants.POSITION, NbtUtils.writeBlockPos(pos));
164164
ret.putInt(SerializationConstants.HEIGHT, height);
165165
return ret;
166166
}
167167

168+
@Nullable
168169
public static FormedAssembly read(CompoundTag nbt) {
169-
return new FormedAssembly(new BlockPos(nbt.getInt(SerializationConstants.X), nbt.getInt(SerializationConstants.Y), nbt.getInt(SerializationConstants.Z)),
170-
nbt.getInt(SerializationConstants.HEIGHT));
170+
BlockPos blockPos = NbtUtils.readBlockPos(nbt, SerializationConstants.POSITION).orElse(null);
171+
if (blockPos == null) {
172+
return null;
173+
}
174+
return new FormedAssembly(blockPos, nbt.getInt(SerializationConstants.HEIGHT));
171175
}
172176
}
173177

src/generators/java/mekanism/generators/common/content/turbine/TurbineMultiblockData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public void readUpdateTag(CompoundTag tag, HolderLookup.Provider provider) {
210210
NBTUtils.setFloatIfPresent(tag, SerializationConstants.SCALE, scale -> prevSteamScale = scale);
211211
NBTUtils.setIntIfPresent(tag, SerializationConstants.VOLUME, this::setVolume);
212212
NBTUtils.setIntIfPresent(tag, SerializationConstants.LOWER_VOLUME, value -> lowerVolume = value);
213-
NBTUtils.setGasStackIfPresent(provider, tag, SerializationConstants.GAS_STORED, value -> gasTank.setStack(value));
213+
NBTUtils.setGasStackIfPresent(provider, tag, SerializationConstants.GAS, value -> gasTank.setStack(value));
214214
NBTUtils.setBlockPosIfPresent(tag, SerializationConstants.COMPLEX, value -> complex = value);
215215
NBTUtils.setFloatIfPresent(tag, SerializationConstants.ROTATION, value -> clientRotation = value);
216216
clientRotationMap.put(inventoryID, clientRotation);
@@ -222,7 +222,7 @@ public void writeUpdateTag(CompoundTag tag, HolderLookup.Provider provider) {
222222
tag.putFloat(SerializationConstants.SCALE, prevSteamScale);
223223
tag.putInt(SerializationConstants.VOLUME, getVolume());
224224
tag.putInt(SerializationConstants.LOWER_VOLUME, lowerVolume);
225-
tag.put(SerializationConstants.GAS_STORED, gasTank.getStack().saveOptional(provider));
225+
tag.put(SerializationConstants.GAS, gasTank.getStack().saveOptional(provider));
226226
tag.put(SerializationConstants.COMPLEX, NbtUtils.writeBlockPos(complex));
227227
tag.putFloat(SerializationConstants.ROTATION, clientRotation);
228228
}

src/generators/java/mekanism/generators/common/tile/TileEntityBioGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ protected boolean onUpdateServer() {
9292
@Override
9393
public CompoundTag getReducedUpdateTag(@NotNull HolderLookup.Provider provider) {
9494
CompoundTag updateTag = super.getReducedUpdateTag(provider);
95-
updateTag.put(SerializationConstants.FLUID_STORED, bioFuelTank.serializeNBT(provider));
95+
updateTag.put(SerializationConstants.FLUID, bioFuelTank.serializeNBT(provider));
9696
return updateTag;
9797
}
9898

9999
@Override
100100
public void handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Provider provider) {
101101
super.handleUpdateTag(tag, provider);
102-
NBTUtils.setCompoundIfPresent(tag, SerializationConstants.FLUID_STORED, nbt -> bioFuelTank.deserializeNBT(provider, nbt));
102+
NBTUtils.setCompoundIfPresent(tag, SerializationConstants.FLUID, nbt -> bioFuelTank.deserializeNBT(provider, nbt));
103103
}
104104

105105
@Override

src/main/java/mekanism/common/attachments/component/AttachedEjector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public record AttachedEjector(List<Optional<EnumColor>> inputColors, boolean str
2323
public static final Codec<AttachedEjector> CODEC = RecordCodecBuilder.create(instance -> instance.group(
2424
ExtraCodecs.optionalEmptyMap(EnumColor.CODEC).listOf(EnumUtils.SIDES.length, EnumUtils.SIDES.length).fieldOf(SerializationConstants.INPUT_COLOR).forGetter(AttachedEjector::inputColors),
2525
Codec.BOOL.fieldOf(SerializationConstants.STRICT_INPUT).forGetter(AttachedEjector::strictInput),
26-
EnumColor.CODEC.optionalFieldOf(SerializationConstants.QIO_META_TYPES).forGetter(AttachedEjector::outputColor)
26+
EnumColor.CODEC.optionalFieldOf(SerializationConstants.TYPES).forGetter(AttachedEjector::outputColor)
2727
).apply(instance, AttachedEjector::new));
2828
public static final StreamCodec<ByteBuf, AttachedEjector> STREAM_CODEC = StreamCodec.composite(
2929
EnumColor.OPTIONAL_STREAM_CODEC.apply(ByteBufCodecs.list(EnumUtils.SIDES.length)), AttachedEjector::inputColors,

src/main/java/mekanism/common/attachments/qio/DriveMetadata.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public record DriveMetadata(long count, int types) {
1515
public static final DriveMetadata EMPTY = new DriveMetadata(0, 0);
1616

1717
public static final Codec<DriveMetadata> CODEC = RecordCodecBuilder.create(instance -> instance.group(
18-
SerializerHelper.POSITIVE_LONG_CODEC.fieldOf(SerializationConstants.QIO_META_COUNT).forGetter(DriveMetadata::count),
18+
SerializerHelper.POSITIVE_LONG_CODEC.fieldOf(SerializationConstants.COUNT).forGetter(DriveMetadata::count),
1919
ExtraCodecs.NON_NEGATIVE_INT.fieldOf(SerializationConstants.QIO_META_TYPES).forGetter(DriveMetadata::types)
2020
).apply(instance, DriveMetadata::new));
2121
public static final StreamCodec<ByteBuf, DriveMetadata> STREAM_CODEC = StreamCodec.composite(

0 commit comments

Comments
 (0)