Skip to content

Commit 8e4d817

Browse files
committed
Use registry ops if possible for computer converters
1 parent 2181913 commit 8e4d817

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/main/java/mekanism/common/config/StorageConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class StorageConfig extends BaseMekanismConfig {
2020
public final CachedFloatingLongValue electricPump;
2121
public final CachedFloatingLongValue chargePad;
2222
public final CachedFloatingLongValue rotaryCondensentrator;
23-
public final CachedFloatingLongValue oxidationChamber;
23+
public final CachedFloatingLongValue chemicalOxidizer;
2424
public final CachedFloatingLongValue chemicalInfuser;
2525
public final CachedFloatingLongValue chemicalInjectionChamber;
2626
public final CachedFloatingLongValue electrolyticSeparator;
@@ -71,7 +71,7 @@ public class StorageConfig extends BaseMekanismConfig {
7171
chargePad = CachedFloatingLongValue.define(this, builder, "Base energy storage (Joules).", "chargePad", FloatingLong.createConst(2_048_000));
7272
rotaryCondensentrator = CachedFloatingLongValue.define(this, builder, "Base energy storage (Joules).", "rotaryCondensentrator",
7373
FloatingLong.createConst(20_000));
74-
oxidationChamber = CachedFloatingLongValue.define(this, builder, "Base energy storage (Joules).", "oxidationChamber",
74+
chemicalOxidizer = CachedFloatingLongValue.define(this, builder, "Base energy storage (Joules).", "chemicalOxidizer",
7575
FloatingLong.createConst(80_000));
7676
chemicalInfuser = CachedFloatingLongValue.define(this, builder, "Base energy storage (Joules).", "chemicalInfuser",
7777
FloatingLong.createConst(80_000));

src/main/java/mekanism/common/config/UsageConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class UsageConfig extends BaseMekanismConfig {
2222
public final CachedFloatingLongValue electricPump;
2323
public final CachedFloatingLongValue chargePad;
2424
public final CachedFloatingLongValue rotaryCondensentrator;
25-
public final CachedFloatingLongValue oxidationChamber;
25+
public final CachedFloatingLongValue chemicalOxidizer;
2626
public final CachedFloatingLongValue chemicalInfuser;
2727
public final CachedFloatingLongValue chemicalInjectionChamber;
2828
public final CachedFloatingLongValue precisionSawmill;
@@ -71,7 +71,7 @@ public class UsageConfig extends BaseMekanismConfig {
7171
FloatingLong.createConst(1_024_000));
7272
rotaryCondensentrator = CachedFloatingLongValue.define(this, builder, "Energy per operation tick (Joules).", "rotaryCondensentrator",
7373
FloatingLong.createConst(50));
74-
oxidationChamber = CachedFloatingLongValue.define(this, builder, "Energy per operation tick (Joules).", "oxidationChamber",
74+
chemicalOxidizer = CachedFloatingLongValue.define(this, builder, "Energy per operation tick (Joules).", "chemicalOxidizer",
7575
FloatingLong.createConst(200));
7676
chemicalInfuser = CachedFloatingLongValue.define(this, builder, "Energy per operation tick (Joules).", "chemicalInfuser",
7777
FloatingLong.createConst(200));

src/main/java/mekanism/common/integration/computer/SpecialConverters.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mekanism.common.integration.computer;
22

33
import com.mojang.brigadier.exceptions.CommandSyntaxException;
4+
import com.mojang.serialization.DynamicOps;
45
import java.util.HashMap;
56
import java.util.Locale;
67
import java.util.Map;
@@ -26,10 +27,13 @@
2627
import net.minecraft.nbt.CompoundTag;
2728
import net.minecraft.nbt.NbtOps;
2829
import net.minecraft.nbt.NbtUtils;
30+
import net.minecraft.nbt.Tag;
2931
import net.minecraft.resources.ResourceLocation;
32+
import net.minecraft.server.MinecraftServer;
3033
import net.minecraft.world.item.Item;
3134
import net.minecraft.world.item.ItemStack;
3235
import net.minecraft.world.item.Items;
36+
import net.neoforged.neoforge.server.ServerLifecycleHooks;
3337
import org.jetbrains.annotations.NotNull;
3438
import org.jetbrains.annotations.Nullable;
3539

@@ -229,8 +233,7 @@ static Map<String, Object> wrapStack(ResourceLocation name, String sizeKey, int
229233
}
230234

231235
static String wrapComponents(@NotNull DataComponentPatch components) {
232-
//TODO - 1.20.5: Make this and unwrapComponents take a HolderLookup.Provider
233-
return NbtUtils.structureToSnbt((CompoundTag) DataComponentPatch.CODEC.encodeStart(NbtOps.INSTANCE, components).getOrThrow());
236+
return NbtUtils.structureToSnbt((CompoundTag) DataComponentPatch.CODEC.encodeStart(getRegistryNbtOps(), components).getOrThrow());
234237
}
235238

236239
static DataComponentPatch unwrapComponents(@NotNull String rawComponents) throws ComputerException {
@@ -240,6 +243,15 @@ static DataComponentPatch unwrapComponents(@NotNull String rawComponents) throws
240243
} catch (CommandSyntaxException ex) {
241244
throw new ComputerException("Invalid SNBT: " + ex.getMessage());
242245
}
243-
return DataComponentPatch.CODEC.decode(NbtOps.INSTANCE, nbt).getOrThrow(ComputerException::new).getFirst();
246+
return DataComponentPatch.CODEC.decode(getRegistryNbtOps(), nbt).getOrThrow(ComputerException::new).getFirst();
247+
}
248+
249+
private static DynamicOps<Tag> getRegistryNbtOps() {
250+
//TODO: Can we pass the registry access in from the tiles rather than having to look it up from the current server?
251+
MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
252+
if (server != null) {
253+
return server.registryAccess().createSerializationContext(NbtOps.INSTANCE);
254+
}
255+
return NbtOps.INSTANCE;
244256
}
245257
}

src/main/java/mekanism/common/registries/MekanismBlockTypes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ private MekanismBlockTypes() {
289289
.createMachine(() -> MekanismTileEntityTypes.CHEMICAL_OXIDIZER, MekanismLang.DESCRIPTION_CHEMICAL_OXIDIZER)
290290
.withGui(() -> MekanismContainerTypes.CHEMICAL_OXIDIZER)
291291
.withSound(MekanismSounds.CHEMICAL_OXIDIZER)
292-
.withEnergyConfig(MekanismConfig.usage.oxidationChamber, MekanismConfig.storage.oxidationChamber)
292+
.withEnergyConfig(MekanismConfig.usage.chemicalOxidizer, MekanismConfig.storage.chemicalOxidizer)
293293
.withSideConfig(TransmissionType.ITEM, TransmissionType.GAS, TransmissionType.ENERGY)
294294
.withCustomShape(BlockShapes.CHEMICAL_OXIDIZER)
295295
.withComputerSupport("chemicalOxidizer")

0 commit comments

Comments
 (0)