Skip to content

Commit d06f2dd

Browse files
committed
Add a method to get the raw output for item to energy recipes
1 parent 0d730a1 commit d06f2dd

File tree

7 files changed

+21
-10
lines changed

7 files changed

+21
-10
lines changed

src/api/java/mekanism/api/recipes/basic/BasicItemStackToEnergyRecipe.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ public FloatingLong getOutput(ItemStack input) {
4646
return output;
4747
}
4848

49+
/**
50+
* For Serializer use. DO NOT MODIFY RETURN VALUE.
51+
*
52+
* @return the uncopied basic output
53+
*
54+
* @since 10.6.0
55+
*/
56+
public FloatingLong getOutputRaw() {
57+
return output;
58+
}
59+
4960
@Override
5061
public List<FloatingLong> getOutputDefinition() {
5162
return Collections.singletonList(output);

src/main/java/mekanism/common/lib/inventory/HashedItem.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
import java.util.UUID;
66
import mekanism.api.annotations.NothingNullByDefault;
77
import mekanism.api.inventory.IHashedItem;
8-
import mekanism.common.attachments.OverflowAware;
98
import mekanism.common.util.StackUtils;
109
import net.minecraft.core.HolderLookup;
1110
import net.minecraft.nbt.Tag;
1211
import net.minecraft.network.RegistryFriendlyByteBuf;
1312
import net.minecraft.network.codec.StreamCodec;
14-
import net.minecraft.util.ExtraCodecs;
1513
import net.minecraft.world.item.ItemStack;
1614
import org.jetbrains.annotations.NotNull;
1715
import org.jetbrains.annotations.Nullable;
@@ -24,8 +22,13 @@
2422
@NothingNullByDefault
2523
public class HashedItem implements IHashedItem {
2624

27-
//TODO - 1.20.5: Some sort of note that this doesn't handle the uuid based ones?
25+
/**
26+
* @implNote This codec does not copy any uuid information if the hashed item is a {@link UUIDAwareHashedItem}
27+
*/
2828
public static final Codec<HashedItem> CODEC = ItemStack.CODEC.xmap(HashedItem::raw, HashedItem::getInternalStack);
29+
/**
30+
* @implNote This codec does not copy any uuid information if the hashed item is a {@link UUIDAwareHashedItem}
31+
*/
2932
public static final StreamCodec<RegistryFriendlyByteBuf, HashedItem> STREAM_CODEC = ItemStack.STREAM_CODEC.map(HashedItem::raw, HashedItem::getInternalStack);
3033

3134
public static HashedItem create(ItemStack stack) {

src/main/java/mekanism/common/recipe/serializer/ChemicalCrystallizerRecipeSerializer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public ChemicalCrystallizerRecipeSerializer(BiFunction<ChemicalStackIngredient<?
3030
chemicalStackIngredientMapEncoder.forGetter(BasicChemicalCrystallizerRecipe::getInput),
3131
ItemStack.CODEC.fieldOf(JsonConstants.OUTPUT).forGetter(BasicChemicalCrystallizerRecipe::getOutputRaw)
3232
).apply(instance, factory));
33-
//TODO - 1.20.5: Figure this out. I think this technically works but it is messy
3433
this.streamCodec = StreamCodec.composite(
3534
ChemicalType.STREAM_CODEC.<RegistryFriendlyByteBuf>cast().dispatch(ChemicalType::getTypeFor,
3635
chemicalType -> IngredientCreatorAccess.getCreatorForType(chemicalType).streamCodec()), BasicChemicalCrystallizerRecipe::getInput,

src/main/java/mekanism/common/recipe/serializer/MekanismRecipeSerializer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import mekanism.api.recipes.basic.BasicFluidSlurryToSlurryRecipe;
3232
import mekanism.api.recipes.basic.BasicFluidToFluidRecipe;
3333
import mekanism.api.recipes.basic.BasicGasToGasRecipe;
34+
import mekanism.api.recipes.basic.BasicItemStackToEnergyRecipe;
3435
import mekanism.api.recipes.basic.BasicItemStackToItemStackRecipe;
3536
import mekanism.api.recipes.basic.BasicNucleosynthesizingRecipe;
3637
import mekanism.api.recipes.basic.BasicPressurizedReactionRecipe;
@@ -94,13 +95,13 @@ public static MekanismRecipeSerializer<BasicCombinerRecipe> combining(Function3<
9495
));
9596
}
9697

97-
public static <RECIPE extends ItemStackToEnergyRecipe> MekanismRecipeSerializer<RECIPE> itemToEnergy(BiFunction<ItemStackIngredient, FloatingLong, RECIPE> factory) {
98+
public static <RECIPE extends BasicItemStackToEnergyRecipe> MekanismRecipeSerializer<RECIPE> itemToEnergy(BiFunction<ItemStackIngredient, FloatingLong, RECIPE> factory) {
9899
return new MekanismRecipeSerializer<>(RecordCodecBuilder.mapCodec(instance -> instance.group(
99100
IngredientCreatorAccess.item().codec().fieldOf(JsonConstants.INPUT).forGetter(ItemStackToEnergyRecipe::getInput),
100-
FloatingLong.NONZERO_CODEC.fieldOf(JsonConstants.OUTPUT).forGetter(r -> r.getOutput(ItemStack.EMPTY))
101+
FloatingLong.NONZERO_CODEC.fieldOf(JsonConstants.OUTPUT).forGetter(BasicItemStackToEnergyRecipe::getOutputRaw)
101102
).apply(instance, factory)), StreamCodec.composite(
102103
IngredientCreatorAccess.item().streamCodec(), ItemStackToEnergyRecipe::getInput,
103-
FloatingLong.STREAM_CODEC, r -> r.getOutput(ItemStack.EMPTY),//TODO - 1.20.5: Re-evaluate passing empty to this??
104+
FloatingLong.STREAM_CODEC, BasicItemStackToEnergyRecipe::getOutputRaw,
104105
factory
105106
));
106107
}

src/main/java/mekanism/common/registration/impl/DataSerializerDeferredRegister.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public DataSerializerDeferredRegister(String modid) {
1616
super(NeoForgeRegistries.Keys.ENTITY_DATA_SERIALIZERS, modid);
1717
}
1818

19-
//TODO - 1.20.5: Do we need to make this lazy
2019
public <T> MekanismDeferredHolder<EntityDataSerializer<?>, EntityDataSerializer<T>> register(String name, StreamCodec<? super RegistryFriendlyByteBuf, T> codec) {
2120
return register(name, () -> EntityDataSerializer.forValueType(codec));
2221
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ private MekanismDataComponents() {
234234
.networkSynchronized(ByteBufCodecs.registry(Registries.ITEM))
235235
);
236236

237-
//TODO - 1.20.5: Validate this doesn't have to be optional
238237
//Note: We can't directly use ItemStack as it needs to override equals and hashcode, but as our only use case converts it to a HashedItem, we just use that
239238
public static final MekanismDeferredHolder<DataComponentType<?>, DataComponentType<HashedItem>> ITEM_TARGET = DATA_COMPONENTS.simple("item_target",
240239
builder -> builder.persistent(HashedItem.CODEC)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ private MekanismRobitSkins() {
2727
private static final DatapackDeferredRegister<RobitSkin> ROBIT_SKINS = DatapackDeferredRegister.robitSkins(Mekanism.MODID);
2828

2929
public static void createAndRegisterDatapack(IEventBus modEventBus) {
30-
//TODO - 1.20.5: Make a PR to neo changing the datapack to maybe take a stream codec??
3130
ROBIT_SKINS.createAndRegisterDatapack(modEventBus, RobitSkinSerializationHelper.DIRECT_CODEC, RobitSkinSerializationHelper.NETWORK_CODEC.codec());
3231
}
3332

0 commit comments

Comments
 (0)