Fixed some crashes

This commit is contained in:
Frank 2023-12-19 18:54:04 +01:00
parent 98d49997fd
commit a6ad865f05

View file

@ -29,6 +29,7 @@ import net.fabricmc.api.Environment;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import org.jetbrains.annotations.NotNull;
public class AlloyingRecipe implements Recipe<Container>, UnknownReceipBookCategory { public class AlloyingRecipe implements Recipe<Container>, UnknownReceipBookCategory {
public final static String GROUP = "alloying"; public final static String GROUP = "alloying";
@ -47,15 +48,15 @@ public class AlloyingRecipe implements Recipe<Container>, UnknownReceipBookCateg
protected final float experience; protected final float experience;
protected final int smeltTime; protected final int smeltTime;
public AlloyingRecipe( private AlloyingRecipe(
List<Ingredient> inputs, List<Ingredient> inputs,
String group, Optional<String> group,
ItemStack output, ItemStack output,
float experience, float experience,
int smeltTime int smeltTime
) { ) {
this( this(
group, group.orElse(""),
!inputs.isEmpty() ? inputs.get(0) : null, !inputs.isEmpty() ? inputs.get(0) : null,
inputs.size() > 1 ? inputs.get(1) : null, inputs.size() > 1 ? inputs.get(1) : null,
output, output,
@ -64,18 +65,8 @@ public class AlloyingRecipe implements Recipe<Container>, UnknownReceipBookCateg
); );
} }
public AlloyingRecipe( private AlloyingRecipe(
List<Ingredient> inputs, @NotNull String group,
Optional<String> group,
ItemStack output,
float experience,
int smeltTime
) {
this(inputs, group.orElse(null), output, experience, smeltTime);
}
public AlloyingRecipe(
String group,
Ingredient primaryInput, Ingredient primaryInput,
Ingredient secondaryInput, Ingredient secondaryInput,
ItemStack output, ItemStack output,
@ -219,7 +210,14 @@ public class AlloyingRecipe implements Recipe<Container>, UnknownReceipBookCateg
@Override @Override
protected AlloyingRecipe createRecipe(ResourceLocation id) { protected AlloyingRecipe createRecipe(ResourceLocation id) {
checkRecipe(); checkRecipe();
return new AlloyingRecipe(group, primaryInput, secondaryInput, output, experience, smeltTime); return new AlloyingRecipe(
group == null ? "" : group,
primaryInput,
secondaryInput,
output,
experience,
smeltTime
);
} }
} }
@ -236,7 +234,7 @@ public class AlloyingRecipe implements Recipe<Container>, UnknownReceipBookCateg
).apply(instance, AlloyingRecipe::new)); ).apply(instance, AlloyingRecipe::new));
@Override @Override
public AlloyingRecipe fromNetwork(FriendlyByteBuf packetBuffer) { public @NotNull AlloyingRecipe fromNetwork(FriendlyByteBuf packetBuffer) {
String group = packetBuffer.readUtf(32767); String group = packetBuffer.readUtf(32767);
Ingredient primary = Ingredient.fromNetwork(packetBuffer); Ingredient primary = Ingredient.fromNetwork(packetBuffer);
Ingredient secondary = Ingredient.fromNetwork(packetBuffer); Ingredient secondary = Ingredient.fromNetwork(packetBuffer);
@ -244,11 +242,11 @@ public class AlloyingRecipe implements Recipe<Container>, UnknownReceipBookCateg
float experience = packetBuffer.readFloat(); float experience = packetBuffer.readFloat();
int smeltTime = packetBuffer.readVarInt(); int smeltTime = packetBuffer.readVarInt();
return new AlloyingRecipe(group, primary, secondary, output, experience, smeltTime); return new AlloyingRecipe(group == null ? "" : group, primary, secondary, output, experience, smeltTime);
} }
@Override @Override
public Codec<AlloyingRecipe> codec() { public @NotNull Codec<AlloyingRecipe> codec() {
return CODEC; return CODEC;
} }