Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert all Records to Classes #221

Merged
merged 5 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.cleanroommc.groovyscript.helper.recipe.IRecipeBuilder;
import com.cleanroommc.groovyscript.registry.AbstractReloadableStorage;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import com.github.bsideup.jabel.Desugar;
import mezz.jei.api.IGuiHelper;
import mezz.jei.api.IModRegistry;
import mezz.jei.api.IRecipeRegistry;
Expand All @@ -19,6 +18,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;

@RegistryDescription(category = RegistryDescription.Category.ENTRIES,
Expand Down Expand Up @@ -115,11 +115,64 @@ public void hideAll() {
hideAllCategories = true;
}

@Desugar
record CustomCategory(String id,
Function<IGuiHelper, ? extends IRecipeCategory<? extends IRecipeWrapper>> category,
List<?> catalysts,
List<? extends IRecipeWrapper> wrappers) {
@SuppressWarnings("ClassCanBeRecord")
public static final class CustomCategory {

private final String id;
private final Function<IGuiHelper, ? extends IRecipeCategory<? extends IRecipeWrapper>> category;
private final List<?> catalysts;
private final List<? extends IRecipeWrapper> wrappers;

public CustomCategory(String id,
Function<IGuiHelper, ? extends IRecipeCategory<? extends IRecipeWrapper>> category,
List<?> catalysts,
List<? extends IRecipeWrapper> wrappers) {
this.id = id;
this.category = category;
this.catalysts = catalysts;
this.wrappers = wrappers;
}

public String id() {
return id;
}

public Function<IGuiHelper, ? extends IRecipeCategory<? extends IRecipeWrapper>> category() {
return category;
}

public List<?> catalysts() {
return catalysts;
}

public List<? extends IRecipeWrapper> wrappers() {
return wrappers;
}

@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (CustomCategory) obj;
return Objects.equals(this.id, that.id) &&
Objects.equals(this.category, that.category) &&
Objects.equals(this.catalysts, that.catalysts) &&
Objects.equals(this.wrappers, that.wrappers);
}

@Override
public int hashCode() {
return Objects.hash(id, category, catalysts, wrappers);
}

@Override
public String toString() {
return "CustomCategory[" +
"id=" + id + ", " +
"category=" + category + ", " +
"catalysts=" + catalysts + ", " +
"wrappers=" + wrappers + ']';
}
}

public static class CategoryBuilder implements IRecipeBuilder<CustomCategory> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import com.cleanroommc.groovyscript.helper.ingredient.ItemsIngredient;
import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import com.github.bsideup.jabel.Desugar;
import lykrast.prodigytech.common.recipe.ExplosionFurnaceManager;
import net.minecraft.item.ItemStack;

import java.util.Objects;

@RegistryDescription(category = RegistryDescription.Category.ENTRIES)
public class ExplosionFurnaceAdditives extends VirtualizedRegistry<ExplosionFurnaceAdditives.EFAdditiveRecipe> {

Expand Down Expand Up @@ -87,8 +88,16 @@ public interface EFAdditiveRecipe {
void unregister();
}

@Desugar
public record EFAdditiveExplosive(IIngredient input, int value) implements EFAdditiveRecipe {
@SuppressWarnings("ClassCanBeRecord")
public static final class EFAdditiveExplosive implements EFAdditiveRecipe {

private final IIngredient input;
private final int value;

public EFAdditiveExplosive(IIngredient input, int value) {
this.input = input;
this.value = value;
}

@Override
public void register() {
Expand All @@ -111,10 +120,47 @@ public void unregister() {
}
}
}

public IIngredient input() {
return input;
}

public int value() {
return value;
}

@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (EFAdditiveExplosive) obj;
return Objects.equals(this.input, that.input) &&
this.value == that.value;
}

@Override
public int hashCode() {
return Objects.hash(input, value);
}

@Override
public String toString() {
return "EFAdditiveExplosive[" +
"input=" + input + ", " +
"value=" + value + ']';
}
}

@Desugar
public record EFAdditiveDampener(IIngredient input, int value) implements EFAdditiveRecipe {
@SuppressWarnings("ClassCanBeRecord")
public static final class EFAdditiveDampener implements EFAdditiveRecipe {

private final IIngredient input;
private final int value;

public EFAdditiveDampener(IIngredient input, int value) {
this.input = input;
this.value = value;
}

@Override
public void register() {
Expand All @@ -137,5 +183,34 @@ public void unregister() {
}
}
}

public IIngredient input() {
return input;
}

public int value() {
return value;
}

@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (EFAdditiveDampener) obj;
return Objects.equals(this.input, that.input) &&
this.value == that.value;
}

@Override
public int hashCode() {
return Objects.hash(input, value);
}

@Override
public String toString() {
return "EFAdditiveDampener[" +
"input=" + input + ", " +
"value=" + value + ']';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import com.cleanroommc.groovyscript.api.documentation.annotations.MethodDescription;
import com.cleanroommc.groovyscript.api.documentation.annotations.RegistryDescription;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import com.github.bsideup.jabel.Desugar;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import lykrast.prodigytech.common.recipe.ZorraAltarManager;
import lykrast.prodigytech.common.util.Config;
import net.minecraft.enchantment.Enchantment;

import java.util.Map;
import java.util.Objects;


@RegistryDescription
Expand Down Expand Up @@ -71,6 +71,50 @@ public boolean removeEnchantment(String registry, Enchantment enchantment) {
return managers.get(registry).removeEnchant(enchantment);
}

@Desugar
public record ZorraRecipeData(String registry, Enchantment enchantment, int maxLevel) {}
@SuppressWarnings("ClassCanBeRecord")
public static final class ZorraRecipeData {

private final String registry;
private final Enchantment enchantment;
private final int maxLevel;

public ZorraRecipeData(String registry, Enchantment enchantment, int maxLevel) {
this.registry = registry;
this.enchantment = enchantment;
this.maxLevel = maxLevel;
}

public String registry() {return registry;}

public Enchantment enchantment() {
return enchantment;
}

public int maxLevel() {
return maxLevel;
}

@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (ZorraRecipeData) obj;
return Objects.equals(this.registry, that.registry) &&
Objects.equals(this.enchantment, that.enchantment) &&
this.maxLevel == that.maxLevel;
}

@Override
public int hashCode() {
return Objects.hash(registry, enchantment, maxLevel);
}

@Override
public String toString() {
return "ZorraRecipeData[" +
"registry=" + registry + ", " +
"enchantment=" + enchantment + ", " +
"maxLevel=" + maxLevel + ']';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
import com.cleanroommc.groovyscript.core.mixin.thermalexpansion.CoolantManagerAccessor;
import com.cleanroommc.groovyscript.helper.SimpleObjectStream;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import com.github.bsideup.jabel.Desugar;
import mezz.jei.api.IGuiHelper;
import net.minecraftforge.fluids.FluidStack;
import org.jetbrains.annotations.ApiStatus;

import java.util.Objects;

@RegistryDescription(category = RegistryDescription.Category.ENTRIES,
admonition = @Admonition(value = "groovyscript.wiki.thermalexpansion.coolant.note0", type = Admonition.Type.WARNING))
public class Coolant extends VirtualizedRegistry<Coolant.CoolantRecipe> {
Expand Down Expand Up @@ -85,9 +86,53 @@ public void removeAll() {
CoolantManagerAccessor.getCoolantFactorMap().clear();
}

@Desugar
public record CoolantRecipe(String fluid, int rf, int factor) {
@SuppressWarnings("ClassCanBeRecord")
public static final class CoolantRecipe {

private final String fluid;
private final int rf;
private final int factor;

public CoolantRecipe(String fluid, int rf, int factor) {
this.fluid = fluid;
this.rf = rf;
this.factor = factor;
}

public String fluid() {
return fluid;
}

public int rf() {
return rf;
}

public int factor() {
return factor;
}

@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (CoolantRecipe) obj;
return Objects.equals(this.fluid, that.fluid) &&
this.rf == that.rf &&
this.factor == that.factor;
}

@Override
public int hashCode() {
return Objects.hash(fluid, rf, factor);
}

@Override
public String toString() {
return "CoolantRecipe[" +
"fluid=" + fluid + ", " +
"rf=" + rf + ", " +
"factor=" + factor + ']';
}
}

}
Loading