Skip to content

Commit

Permalink
fromNetwork signature change
Browse files Browse the repository at this point in the history
  • Loading branch information
thiakil committed Nov 4, 2023
1 parent 84707db commit 58d59d5
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ public RECIPE fromJson(@NotNull ResourceLocation recipeId, @NotNull JsonObject j
if (output.isEmpty()) {
throw new JsonSyntaxException("Recipe output must not be empty.");
}
return this.factory.create(recipeId, leftInput, rightInput, output);
return this.factory.create(leftInput, rightInput, output);
}

@Override
public RECIPE fromNetwork(@NotNull ResourceLocation recipeId, @NotNull FriendlyByteBuf buffer) {
public RECIPE fromNetwork(@NotNull FriendlyByteBuf buffer) {
try {
INGREDIENT leftInput = getDeserializer().read(buffer);
INGREDIENT rightInput = getDeserializer().read(buffer);
STACK output = fromBuffer(buffer);
return this.factory.create(recipeId, leftInput, rightInput, output);
return this.factory.create(leftInput, rightInput, output);
} catch (Exception e) {
Mekanism.logger.error("Error reading chemical chemical to chemical recipe from packet.", e);
throw e;
Expand All @@ -75,6 +75,6 @@ public void toNetwork(@NotNull FriendlyByteBuf buffer, @NotNull RECIPE recipe) {
public interface IFactory<CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>,
INGREDIENT extends ChemicalStackIngredient<CHEMICAL, STACK>, RECIPE extends ChemicalChemicalToChemicalRecipe<CHEMICAL, STACK, INGREDIENT>> {

RECIPE create(ResourceLocation id, INGREDIENT leftInput, INGREDIENT rightInput, STACK output);
RECIPE create(INGREDIENT leftInput, INGREDIENT rightInput, STACK output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public RECIPE fromJson(@NotNull ResourceLocation recipeId, @NotNull JsonObject j
}

@Override
public RECIPE fromNetwork(@NotNull ResourceLocation recipeId, @NotNull FriendlyByteBuf buffer) {
public RECIPE fromNetwork(@NotNull FriendlyByteBuf buffer) {
try {
ChemicalType chemicalType = buffer.readEnum(ChemicalType.class);
ChemicalStackIngredient<?, ?> inputIngredient = IngredientCreatorAccess.getCreatorForType(chemicalType).read(buffer);
ItemStack output = buffer.readItem();
return this.factory.create(recipeId, inputIngredient, output);
return this.factory.create(inputIngredient, output);
} catch (Exception e) {
Mekanism.logger.error("Error reading boxed chemical to itemstack recipe from packet.", e);
throw e;
Expand All @@ -65,6 +65,6 @@ public void toNetwork(@NotNull FriendlyByteBuf buffer, @NotNull RECIPE recipe) {
@FunctionalInterface
public interface IFactory<RECIPE extends ChemicalCrystallizerRecipe> {

RECIPE create(ResourceLocation id, ChemicalStackIngredient<?, ?> input, ItemStack output);
RECIPE create(ChemicalStackIngredient<?, ?> input, ItemStack output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public RECIPE fromJson(@NotNull ResourceLocation recipeId, @NotNull JsonObject j
}

@Override
public RECIPE fromNetwork(@NotNull ResourceLocation recipeId, @NotNull FriendlyByteBuf buffer) {
public RECIPE fromNetwork(@NotNull FriendlyByteBuf buffer) {
try {
ItemStackIngredient itemInput = IngredientCreatorAccess.item().read(buffer);
GasStackIngredient gasInput = IngredientCreatorAccess.gas().read(buffer);
Expand All @@ -58,7 +58,7 @@ public RECIPE fromNetwork(@NotNull ResourceLocation recipeId, @NotNull FriendlyB
case PIGMENT -> PigmentStack.readFromPacket(buffer);
case SLURRY -> SlurryStack.readFromPacket(buffer);
};
return this.factory.create(recipeId, itemInput, gasInput, output);
return this.factory.create(itemInput, gasInput, output);
} catch (Exception e) {
Mekanism.logger.error("Error reading itemstack gas to gas recipe from packet.", e);
throw e;
Expand All @@ -78,6 +78,6 @@ public void toNetwork(@NotNull FriendlyByteBuf buffer, @NotNull RECIPE recipe) {
@FunctionalInterface
public interface IFactory<RECIPE extends ChemicalDissolutionRecipe> {

RECIPE create(ResourceLocation id, ItemStackIngredient itemInput, GasStackIngredient gasInput, ChemicalStack<?> output);
RECIPE create(ItemStackIngredient itemInput, GasStackIngredient gasInput, ChemicalStack<?> output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public RECIPE fromJson(@NotNull ResourceLocation recipeId, @NotNull JsonObject j
}

@Override
public RECIPE fromNetwork(@NotNull ResourceLocation recipeId, @NotNull FriendlyByteBuf buffer) {
public RECIPE fromNetwork(@NotNull FriendlyByteBuf buffer) {
try {
ItemStackIngredient mainInput = IngredientCreatorAccess.item().read(buffer);
ItemStackIngredient extraInput = IngredientCreatorAccess.item().read(buffer);
ItemStack output = buffer.readItem();
return this.factory.create(recipeId, mainInput, extraInput, output);
return this.factory.create(mainInput, extraInput, output);
} catch (Exception e) {
Mekanism.logger.error("Error reading combiner recipe from packet.", e);
throw e;
Expand All @@ -66,6 +66,6 @@ public void toNetwork(@NotNull FriendlyByteBuf buffer, @NotNull RECIPE recipe) {
@FunctionalInterface
public interface IFactory<RECIPE extends CombinerRecipe> {

RECIPE create(ResourceLocation id, ItemStackIngredient mainInput, ItemStackIngredient extraInput, ItemStack output);
RECIPE create(ItemStackIngredient mainInput, ItemStackIngredient extraInput, ItemStack output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public RECIPE fromJson(@NotNull ResourceLocation recipeId, @NotNull JsonObject j
}

@Override
public RECIPE fromNetwork(@NotNull ResourceLocation recipeId, @NotNull FriendlyByteBuf buffer) {
public RECIPE fromNetwork(@NotNull FriendlyByteBuf buffer) {
try {
FluidStackIngredient input = IngredientCreatorAccess.fluid().read(buffer);
FloatingLong energyMultiplier = FloatingLong.readFromBuffer(buffer);
GasStack leftGasOutput = GasStack.readFromPacket(buffer);
GasStack rightGasOutput = GasStack.readFromPacket(buffer);
return this.factory.create(recipeId, input, energyMultiplier, leftGasOutput, rightGasOutput);
return this.factory.create(input, energyMultiplier, leftGasOutput, rightGasOutput);
} catch (Exception e) {
Mekanism.logger.error("Error reading electrolysis recipe from packet.", e);
throw e;
Expand All @@ -73,6 +73,6 @@ public void toNetwork(@NotNull FriendlyByteBuf buffer, @NotNull RECIPE recipe) {
@FunctionalInterface
public interface IFactory<RECIPE extends ElectrolysisRecipe> {

RECIPE create(ResourceLocation id, FluidStackIngredient input, FloatingLong energyMultiplier, GasStack leftGasOutput, GasStack rightGasOutput);
RECIPE create(FluidStackIngredient input, FloatingLong energyMultiplier, GasStack leftGasOutput, GasStack rightGasOutput);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public RECIPE fromJson(@NotNull ResourceLocation recipeId, @NotNull JsonObject j
}

@Override
public RECIPE fromNetwork(@NotNull ResourceLocation recipeId, @NotNull FriendlyByteBuf buffer) {
public RECIPE fromNetwork(@NotNull FriendlyByteBuf buffer) {
try {
FluidStackIngredient fluidInput = IngredientCreatorAccess.fluid().read(buffer);
SlurryStackIngredient slurryInput = IngredientCreatorAccess.slurry().read(buffer);
SlurryStack output = SlurryStack.readFromPacket(buffer);
return this.factory.create(recipeId, fluidInput, slurryInput, output);
return this.factory.create(fluidInput, slurryInput, output);
} catch (Exception e) {
Mekanism.logger.error("Error reading fluid slurry to slurry recipe from packet.", e);
throw e;
Expand All @@ -67,6 +67,6 @@ public void toNetwork(@NotNull FriendlyByteBuf buffer, @NotNull RECIPE recipe) {
@FunctionalInterface
public interface IFactory<RECIPE extends FluidSlurryToSlurryRecipe> {

RECIPE create(ResourceLocation id, FluidStackIngredient fluidInput, SlurryStackIngredient slurryInput, SlurryStack output);
RECIPE create(FluidStackIngredient fluidInput, SlurryStackIngredient slurryInput, SlurryStack output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public RECIPE fromJson(@NotNull ResourceLocation recipeId, @NotNull JsonObject j
}

@Override
public RECIPE fromNetwork(@NotNull ResourceLocation recipeId, @NotNull FriendlyByteBuf buffer) {
public RECIPE fromNetwork(@NotNull FriendlyByteBuf buffer) {
try {
FluidStackIngredient inputIngredient = IngredientCreatorAccess.fluid().read(buffer);
FluidStack output = FluidStack.readFromPacket(buffer);
return this.factory.create(recipeId, inputIngredient, output);
return this.factory.create(inputIngredient, output);
} catch (Exception e) {
Mekanism.logger.error("Error reading fluid to fluid recipe from packet.", e);
throw e;
Expand All @@ -62,6 +62,6 @@ public void toNetwork(@NotNull FriendlyByteBuf buffer, @NotNull RECIPE recipe) {
@FunctionalInterface
public interface IFactory<RECIPE extends FluidToFluidRecipe> {

RECIPE create(ResourceLocation id, FluidStackIngredient input, FluidStack output);
RECIPE create(FluidStackIngredient input, FluidStack output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public RECIPE fromJson(@NotNull ResourceLocation recipeId, @NotNull JsonObject j
}

@Override
public RECIPE fromNetwork(@NotNull ResourceLocation recipeId, @NotNull FriendlyByteBuf buffer) {
public RECIPE fromNetwork(@NotNull FriendlyByteBuf buffer) {
try {
GasStackIngredient inputIngredient = IngredientCreatorAccess.gas().read(buffer);
GasStack output = GasStack.readFromPacket(buffer);
return this.factory.create(recipeId, inputIngredient, output);
return this.factory.create(inputIngredient, output);
} catch (Exception e) {
Mekanism.logger.error("Error reading gas to gas recipe from packet.", e);
throw e;
Expand All @@ -62,6 +62,6 @@ public void toNetwork(@NotNull FriendlyByteBuf buffer, @NotNull RECIPE recipe) {
@FunctionalInterface
public interface IFactory<RECIPE extends GasToGasRecipe> {

RECIPE create(ResourceLocation id, GasStackIngredient input, GasStack output);
RECIPE create(GasStackIngredient input, GasStack output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public RECIPE fromJson(@NotNull ResourceLocation recipeId, @NotNull JsonObject j
}

@Override
public RECIPE fromNetwork(@NotNull ResourceLocation recipeId, @NotNull FriendlyByteBuf buffer) {
public RECIPE fromNetwork(@NotNull FriendlyByteBuf buffer) {
try {
ItemStackIngredient itemInput = IngredientCreatorAccess.item().read(buffer);
INGREDIENT chemicalInput = getDeserializer().read(buffer);
ItemStack output = buffer.readItem();
return this.factory.create(recipeId, itemInput, chemicalInput, output);
return this.factory.create(itemInput, chemicalInput, output);
} catch (Exception e) {
Mekanism.logger.error("Error reading itemstack chemical to itemstack recipe from packet.", e);
throw e;
Expand All @@ -75,6 +75,6 @@ public void toNetwork(@NotNull FriendlyByteBuf buffer, @NotNull RECIPE recipe) {
public interface IFactory<CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>,
INGREDIENT extends ChemicalStackIngredient<CHEMICAL, STACK>, RECIPE extends ItemStackChemicalToItemStackRecipe<CHEMICAL, STACK, INGREDIENT>> {

RECIPE create(ResourceLocation id, ItemStackIngredient itemInput, INGREDIENT chemicalInput, ItemStack output);
RECIPE create(ItemStackIngredient itemInput, INGREDIENT chemicalInput, ItemStack output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ protected ItemStackToChemicalRecipeSerializer(IFactory<CHEMICAL, STACK, RECIPE>
this.factory = factory;
}

protected abstract STACK fromJson(@NotNull JsonObject json, @NotNull String key);
protected abstract STACK stackFromJson(@NotNull JsonObject json, @NotNull String key);

protected abstract STACK fromBuffer(@NotNull FriendlyByteBuf buffer);
protected abstract STACK stackFromBuffer(@NotNull FriendlyByteBuf buffer);

@NotNull
@Override
public RECIPE fromJson(@NotNull ResourceLocation recipeId, @NotNull JsonObject json) {
JsonElement input = GsonHelper.isArrayNode(json, JsonConstants.INPUT) ? GsonHelper.getAsJsonArray(json, JsonConstants.INPUT) :
GsonHelper.getAsJsonObject(json, JsonConstants.INPUT);
ItemStackIngredient inputIngredient = IngredientCreatorAccess.item().deserialize(input);
STACK output = fromJson(json, JsonConstants.OUTPUT);
STACK output = stackFromJson(json, JsonConstants.OUTPUT);
if (output.isEmpty()) {
throw new JsonSyntaxException("Recipe output must not be empty.");
}
return this.factory.create(recipeId, inputIngredient, output);
}

@Override
public RECIPE fromNetwork(@NotNull ResourceLocation recipeId, @NotNull FriendlyByteBuf buffer) {
public RECIPE fromNetwork(@NotNull FriendlyByteBuf buffer) {
try {
ItemStackIngredient inputIngredient = IngredientCreatorAccess.item().read(buffer);
STACK output = fromBuffer(buffer);
STACK output = stackFromBuffer(buffer);
return this.factory.create(recipeId, inputIngredient, output);
} catch (Exception e) {
Mekanism.logger.error("Error reading itemstack to chemical recipe from packet.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public RECIPE fromJson(@NotNull ResourceLocation recipeId, @NotNull JsonObject j
}

@Override
public RECIPE fromNetwork(@NotNull ResourceLocation recipeId, @NotNull FriendlyByteBuf buffer) {
public RECIPE fromNetwork(@NotNull FriendlyByteBuf buffer) {
try {
ItemStackIngredient inputIngredient = IngredientCreatorAccess.item().read(buffer);
FloatingLong output = FloatingLong.readFromBuffer(buffer);
return this.factory.create(recipeId, inputIngredient, output);
return this.factory.create(inputIngredient, output);
} catch (Exception e) {
Mekanism.logger.error("Error reading itemstack to energy recipe from packet.", e);
throw e;
Expand All @@ -62,6 +62,6 @@ public void toNetwork(@NotNull FriendlyByteBuf buffer, @NotNull RECIPE recipe) {
@FunctionalInterface
public interface IFactory<RECIPE extends ItemStackToEnergyRecipe> {

RECIPE create(ResourceLocation id, ItemStackIngredient input, FloatingLong output);
RECIPE create(ItemStackIngredient input, FloatingLong output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public ItemStackToGasRecipeSerializer(IFactory<Gas, GasStack, RECIPE> factory) {
}

@Override
protected GasStack fromJson(@NotNull JsonObject json, @NotNull String key) {
protected GasStack stackFromJson(@NotNull JsonObject json, @NotNull String key) {
return SerializerHelper.getGasStack(json, key);
}

@Override
protected GasStack fromBuffer(@NotNull FriendlyByteBuf buffer) {
protected GasStack stackFromBuffer(@NotNull FriendlyByteBuf buffer) {
return GasStack.readFromPacket(buffer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public ItemStackToInfuseTypeRecipeSerializer(IFactory<InfuseType, InfusionStack,
}

@Override
protected InfusionStack fromJson(@NotNull JsonObject json, @NotNull String key) {
protected InfusionStack stackFromJson(@NotNull JsonObject json, @NotNull String key) {
return SerializerHelper.getInfusionStack(json, key);
}

@Override
protected InfusionStack fromBuffer(@NotNull FriendlyByteBuf buffer) {
protected InfusionStack stackFromBuffer(@NotNull FriendlyByteBuf buffer) {
return InfusionStack.readFromPacket(buffer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public RECIPE fromJson(@NotNull ResourceLocation recipeId, @NotNull JsonObject j
}

@Override
public RECIPE fromNetwork(@NotNull ResourceLocation recipeId, @NotNull FriendlyByteBuf buffer) {
public RECIPE fromNetwork(@NotNull FriendlyByteBuf buffer) {
try {
ItemStackIngredient inputIngredient = IngredientCreatorAccess.item().read(buffer);
ItemStack output = buffer.readItem();
return this.factory.create(recipeId, inputIngredient, output);
return this.factory.create(inputIngredient, output);
} catch (Exception e) {
Mekanism.logger.error("Error reading itemstack to itemstack recipe from packet.", e);
throw e;
Expand All @@ -62,6 +62,6 @@ public void toNetwork(@NotNull FriendlyByteBuf buffer, @NotNull RECIPE recipe) {
@FunctionalInterface
public interface IFactory<RECIPE extends ItemStackToItemStackRecipe> {

RECIPE create(ResourceLocation id, ItemStackIngredient input, ItemStack output);
RECIPE create(ItemStackIngredient input, ItemStack output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public ItemStackToPigmentRecipeSerializer(IFactory<Pigment, PigmentStack, RECIPE
}

@Override
protected PigmentStack fromJson(@NotNull JsonObject json, @NotNull String key) {
protected PigmentStack stackFromJson(@NotNull JsonObject json, @NotNull String key) {
return SerializerHelper.getPigmentStack(json, key);
}

@Override
protected PigmentStack fromBuffer(@NotNull FriendlyByteBuf buffer) {
protected PigmentStack stackFromBuffer(@NotNull FriendlyByteBuf buffer) {
return PigmentStack.readFromPacket(buffer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public RECIPE fromJson(@NotNull ResourceLocation recipeId, @NotNull JsonObject j
}

@Override
public RECIPE fromNetwork(@NotNull ResourceLocation recipeId, @NotNull FriendlyByteBuf buffer) {
public RECIPE fromNetwork(@NotNull FriendlyByteBuf buffer) {
try {
ItemStackIngredient inputSolid = IngredientCreatorAccess.item().read(buffer);
GasStackIngredient inputGas = IngredientCreatorAccess.gas().read(buffer);
ItemStack outputItem = buffer.readItem();
int duration = buffer.readVarInt();
return this.factory.create(recipeId, inputSolid, inputGas, outputItem, duration);
return this.factory.create(inputSolid, inputGas, outputItem, duration);
} catch (Exception e) {
Mekanism.logger.error("Error reading nucleosynthesizing recipe from packet.", e);
throw e;
Expand All @@ -77,6 +77,6 @@ public void toNetwork(@NotNull FriendlyByteBuf buffer, @NotNull RECIPE recipe) {
@FunctionalInterface
public interface IFactory<RECIPE extends NucleosynthesizingRecipe> {

RECIPE create(ResourceLocation id, ItemStackIngredient itemInput, GasStackIngredient gasInput, ItemStack outputItem, int duration);
RECIPE create(ItemStackIngredient itemInput, GasStackIngredient gasInput, ItemStack outputItem, int duration);
}
}
Loading

0 comments on commit 58d59d5

Please sign in to comment.