Skip to content

Commit

Permalink
remove some more redundant generics
Browse files Browse the repository at this point in the history
  • Loading branch information
thiakil committed Aug 11, 2024
1 parent 668d0cf commit f8a3cc5
Show file tree
Hide file tree
Showing 29 changed files with 105 additions and 261 deletions.
8 changes: 4 additions & 4 deletions src/api/java/mekanism/api/chemical/ChemicalTankBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class ChemicalTankBuilder {
*/
public final BiPredicate<Chemical, @NotNull AutomationType> manualOnly = (chemical, automationType) -> automationType == AutomationType.MANUAL;

private final BasicTankCreator<IChemicalTank> tankCreator;
private final BasicTankCreator tankCreator;

private ChemicalTankBuilder(BasicTankCreator<IChemicalTank> tankCreator) {
private ChemicalTankBuilder(BasicTankCreator tankCreator) {
this.tankCreator = tankCreator;
}

Expand Down Expand Up @@ -240,9 +240,9 @@ private IChemicalTank createUnchecked(long capacity, Predicate<Chemical> canExtr
}

@FunctionalInterface
private interface BasicTankCreator<TANK extends IChemicalTank> {
private interface BasicTankCreator {

TANK create(long capacity, BiPredicate<Chemical, @NotNull AutomationType> canExtract, BiPredicate<Chemical, @NotNull AutomationType> canInsert,
IChemicalTank create(long capacity, BiPredicate<Chemical, @NotNull AutomationType> canExtract, BiPredicate<Chemical, @NotNull AutomationType> canInsert,
Predicate<Chemical> validator, @Nullable ChemicalAttributeValidator attributeValidator, @Nullable IContentsListener listener);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package mekanism.client.recipe_viewer.color;

import mekanism.api.chemical.Chemical;
import mekanism.api.chemical.ChemicalStack;

public class PaintingColorDetails extends RecipeViewerColorDetails<Chemical, ChemicalStack> {
public class PaintingColorDetails extends RecipeViewerColorDetails {

public PaintingColorDetails() {
super(() -> ChemicalStack.EMPTY);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package mekanism.client.recipe_viewer.color;

import mekanism.api.chemical.Chemical;
import mekanism.api.chemical.ChemicalStack;

public class PigmentExtractorColorDetails extends RecipeViewerColorDetails<Chemical, ChemicalStack> {
public class PigmentExtractorColorDetails extends RecipeViewerColorDetails {

public PigmentExtractorColorDetails() {
super(() -> ChemicalStack.EMPTY);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package mekanism.client.recipe_viewer.color;

import java.util.function.Supplier;
import mekanism.api.chemical.Chemical;
import mekanism.api.chemical.ChemicalStack;

public class PigmentMixerColorDetails extends RecipeViewerColorDetails<Chemical, ChemicalStack> {
public class PigmentMixerColorDetails extends RecipeViewerColorDetails {

private Supplier<ChemicalStack> outputIngredient;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
package mekanism.client.recipe_viewer.color;

import java.util.function.Supplier;
import mekanism.api.chemical.Chemical;
import mekanism.api.chemical.ChemicalStack;
import mekanism.client.gui.element.progress.GuiProgress.ColorDetails;

public abstract class RecipeViewerColorDetails<CHEMICAL extends Chemical, STACK extends ChemicalStack> implements ColorDetails {
public abstract class RecipeViewerColorDetails implements ColorDetails {

protected final Supplier<STACK> empty;
public Supplier<STACK> ingredient;
protected final Supplier<ChemicalStack> empty;
public Supplier<ChemicalStack> ingredient;

protected RecipeViewerColorDetails(Supplier<STACK> empty) {
protected RecipeViewerColorDetails(Supplier<ChemicalStack> empty) {
this.empty = empty;
setIngredient(this.empty);
}

public void setIngredient(STACK ingredient) {
public void setIngredient(ChemicalStack ingredient) {
setIngredient(() -> ingredient);
}

public void setIngredient(Supplier<STACK> ingredient) {
public void setIngredient(Supplier<ChemicalStack> ingredient) {
this.ingredient = ingredient;
}

public void reset() {
setIngredient(empty);
}

protected int getColor(Supplier<STACK> ingredient) {
protected int getColor(Supplier<ChemicalStack> ingredient) {
return getColor(ingredient.get());
}

protected int getColor(STACK ingredient) {
protected int getColor(ChemicalStack ingredient) {
return getColor(ingredient.getChemicalColorRepresentation());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@
import net.minecraft.resources.ResourceLocation;

@NothingNullByDefault
public class ChemicalEmiIngredientSerializer<CHEMICAL extends Chemical, EMI_STACK extends ChemicalEmiStack> implements EmiStackSerializer<EMI_STACK> {
public class ChemicalEmiIngredientSerializer implements EmiStackSerializer<ChemicalEmiStack> {

private final EmiStackCreator<CHEMICAL, EMI_STACK> stackCreator;
private final Registry<CHEMICAL> registry;
private final Registry<Chemical> registry;
private final String type;

ChemicalEmiIngredientSerializer(Registry<CHEMICAL> registry, EmiStackCreator<CHEMICAL, EMI_STACK> stackCreator) {
ChemicalEmiIngredientSerializer(Registry<Chemical> registry) {
this.registry = registry;
this.stackCreator = stackCreator;
this.type = registry.key().location().toString().replace(':', '_');
}

@Override
public EmiStack create(ResourceLocation id, DataComponentPatch ignored, long amount) {
Optional<CHEMICAL> chemical = registry.getOptional(id).filter(c -> !c.isEmptyType());
Optional<Chemical> chemical = registry.getOptional(id).filter(c -> !c.isEmptyType());
if (chemical.isPresent()) {
return stackCreator.create(chemical.get(), amount);
return new ChemicalEmiStack(chemical.get(), amount);
}
return EmiStack.EMPTY;
}
Expand All @@ -38,16 +36,10 @@ public String getType() {
}

void addEmiStacks(EmiRegistry emiRegistry) {
for (CHEMICAL chemical : registry) {
for (Chemical chemical : registry) {
if (!chemical.isEmptyType()) {//Don't add the empty type. We will allow EMI to filter out any that are hidden from recipe viewers
emiRegistry.addEmiStack(stackCreator.create(chemical, 1));
emiRegistry.addEmiStack(new ChemicalEmiStack(chemical, 1));
}
}
}

@FunctionalInterface
public interface EmiStackCreator<CHEMICAL extends Chemical, EMI_STACK extends ChemicalEmiStack> {

EMI_STACK create(CHEMICAL chemical, long amount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,51 +129,4 @@ public static ChemicalEmiStack create(IChemicalProvider chemicalProvider, long a
return new ChemicalEmiStack(chemicalProvider.getChemical(), amount);
}

public static class GasEmiStack extends ChemicalEmiStack {

public GasEmiStack(Chemical gas, DataComponentPatch ignored, long amount) {
this(gas, amount);
}

public GasEmiStack(Chemical gas, long amount) {
super(gas, amount);
}

}

public static class InfusionEmiStack extends ChemicalEmiStack {

public InfusionEmiStack(Chemical infuseType, DataComponentPatch ignored, long amount) {
this(infuseType, amount);
}

public InfusionEmiStack(Chemical infuseType, long amount) {
super(infuseType, amount);
}

}

public static class PigmentEmiStack extends ChemicalEmiStack {

public PigmentEmiStack(Chemical pigment, DataComponentPatch ignored, long amount) {
this(pigment, amount);
}

public PigmentEmiStack(Chemical pigment, long amount) {
super(pigment, amount);
}

}

public static class SlurryEmiStack extends ChemicalEmiStack {

public SlurryEmiStack(Chemical slurry, DataComponentPatch ignored, long amount) {
this(slurry, amount);
}

public SlurryEmiStack(Chemical slurry, long amount) {
super(slurry, amount);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import mekanism.client.recipe_viewer.emi.recipe.ItemStackToEnergyEmiRecipe;
import mekanism.client.recipe_viewer.emi.recipe.ItemStackToFluidOptionalItemEmiRecipe;
import mekanism.client.recipe_viewer.emi.recipe.ItemStackToItemStackEmiRecipe;
import mekanism.client.recipe_viewer.emi.recipe.ItemStackToPigmentEmiRecipe;
import mekanism.client.recipe_viewer.emi.recipe.MekanismEmiRecipe;
import mekanism.client.recipe_viewer.emi.recipe.MetallurgicInfuserEmiRecipe;
import mekanism.client.recipe_viewer.emi.recipe.NucleosynthesizingEmiRecipe;
Expand Down Expand Up @@ -73,7 +72,6 @@
import mekanism.common.registries.MekanismItems;
import mekanism.common.tier.FactoryTier;
import mekanism.common.tile.machine.TileEntityChemicalOxidizer;
import mekanism.common.tile.machine.TileEntityMetallurgicInfuser;
import mekanism.common.tile.machine.TileEntityNutritionalLiquifier;
import mekanism.common.tile.machine.TileEntityPigmentExtractor;
import mekanism.common.util.EnumUtils;
Expand All @@ -88,7 +86,7 @@
@EmiEntrypoint
public class MekanismEmi implements EmiPlugin {

private static final ChemicalEmiIngredientSerializer<Chemical, ChemicalEmiStack> CHEMICAL_SERIALIZER = new ChemicalEmiIngredientSerializer<>(MekanismAPI.CHEMICAL_REGISTRY, ChemicalEmiStack::new);
private static final ChemicalEmiIngredientSerializer CHEMICAL_SERIALIZER = new ChemicalEmiIngredientSerializer(MekanismAPI.CHEMICAL_REGISTRY);
private static final EmiRegistryAdapter<Chemical> CHEMICAL_REGISTRY_ADAPTER = EmiRegistryAdapter.simple(Chemical.class, MekanismAPI.CHEMICAL_REGISTRY, ChemicalEmiStack::new);

private static final Comparison MEKANISM_COMPARISON = Comparison.compareData(emiStack -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import dev.emi.emi.api.render.EmiTexture;
import dev.emi.emi.api.widget.WidgetHolder;
import mekanism.api.chemical.Chemical;
import mekanism.api.chemical.ChemicalStack;
import mekanism.api.recipes.chemical.ChemicalChemicalToChemicalRecipe;
import mekanism.client.gui.element.bar.GuiHorizontalPowerBar;
import mekanism.client.gui.element.gauge.GaugeType;
Expand All @@ -17,8 +15,7 @@
import mekanism.common.tile.component.config.DataType;
import net.minecraft.world.item.crafting.RecipeHolder;

public abstract class ChemicalChemicalToChemicalEmiRecipe<CHEMICAL extends Chemical, STACK extends ChemicalStack,
RECIPE extends ChemicalChemicalToChemicalRecipe> extends MekanismEmiHolderRecipe<RECIPE> {
public abstract class ChemicalChemicalToChemicalEmiRecipe<RECIPE extends ChemicalChemicalToChemicalRecipe> extends MekanismEmiHolderRecipe<RECIPE> {

protected ChemicalChemicalToChemicalEmiRecipe(MekanismEmiRecipeCategory category, RecipeHolder<RECIPE> recipeHolder) {
super(category, recipeHolder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public ChemicalCrystallizerEmiRecipe(MekanismEmiRecipeCategory category, RecipeH
addItemOutputDefinition(recipe.getOutputDefinition());
ChemicalStackIngredient input = recipe.getInput();
addInputDefinition(input);
List<? extends ChemicalStack> inputRepresentations = input.getRepresentations();
displayItems = input instanceof ChemicalStackIngredient ingredient ? RecipeViewerUtils.getDisplayItems(ingredient) : Collections.emptyList();
List<ChemicalStack> inputRepresentations = input.getRepresentations();
displayItems = input != null ? RecipeViewerUtils.getDisplayItems(input) : Collections.emptyList();
oreInfo = new IOreInfo() {
@Override
public @NotNull ChemicalStack getInputChemical() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package mekanism.client.recipe_viewer.emi.recipe;

import mekanism.api.chemical.Chemical;
import mekanism.api.chemical.ChemicalStack;
import mekanism.api.recipes.ChemicalInfuserRecipe;
import mekanism.client.gui.element.gauge.GaugeType;
import mekanism.client.gui.element.gauge.GuiChemicalGauge;
import mekanism.client.recipe_viewer.emi.MekanismEmiRecipeCategory;
import net.minecraft.world.item.crafting.RecipeHolder;

public class ChemicalInfuserEmiRecipe extends ChemicalChemicalToChemicalEmiRecipe<Chemical, ChemicalStack, ChemicalInfuserRecipe> {
public class ChemicalInfuserEmiRecipe extends ChemicalChemicalToChemicalEmiRecipe<ChemicalInfuserRecipe> {

public ChemicalInfuserEmiRecipe(MekanismEmiRecipeCategory category, RecipeHolder<ChemicalInfuserRecipe> recipeHolder) {
super(category, recipeHolder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected void addFluidOutputDefinition(List<FluidStack> definition) {
addOutputDefinition(definition.stream().map(NeoForgeEmiStack::of).toList());
}

protected <CHEMICAL extends Chemical, STACK extends ChemicalStack> void addChemicalOutputDefinition(List<STACK> definition) {
protected void addChemicalOutputDefinition(List<ChemicalStack> definition) {
addOutputDefinition(definition.stream().<EmiStack>map(ChemicalEmiStack::create).toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import dev.emi.emi.api.widget.WidgetHolder;
import java.util.function.Supplier;
import mekanism.api.chemical.Chemical;
import mekanism.api.chemical.ChemicalStack;
import mekanism.api.recipes.PigmentMixingRecipe;
import mekanism.client.gui.element.gauge.GaugeType;
Expand All @@ -13,7 +12,7 @@
import mekanism.client.recipe_viewer.emi.MekanismEmiRecipeCategory;
import net.minecraft.world.item.crafting.RecipeHolder;

public class PigmentMixerEmiRecipe extends ChemicalChemicalToChemicalEmiRecipe<Chemical, ChemicalStack, PigmentMixingRecipe> {
public class PigmentMixerEmiRecipe extends ChemicalChemicalToChemicalEmiRecipe<PigmentMixingRecipe> {

private final Supplier<ChemicalStack> leftInput;
private final Supplier<ChemicalStack> rightInput;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mekanism/client/render/data/RenderData.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private Builder(@Nullable Chemical chemical, FluidStack fluid) {
this.fluid = fluid;
}

public static <CHEMICAL extends Chemical> Builder<ChemicalRenderData> create(ChemicalStack chemical) {
public static Builder<ChemicalRenderData> create(ChemicalStack chemical) {
if (chemical.isEmpty()) {
throw new IllegalArgumentException("Chemical may not be empty");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public class ChemicalFluidBarDecorator implements IItemDecorator {

private final ContainerType<? extends IChemicalTank, ?, ?>[] chemicalContainerTypes;
private final ContainerType<IChemicalTank, ?, ?>[] chemicalContainerTypes;
private final boolean showFluid;
private final Predicate<ItemStack> visibleFor;

Expand All @@ -30,7 +30,7 @@ public class ChemicalFluidBarDecorator implements IItemDecorator {
* @param chemicalContainerTypes the container types to be displayed in order, starting from the bottom
*/
@SafeVarargs
public ChemicalFluidBarDecorator(boolean showFluid, Predicate<ItemStack> visibleFor, ContainerType<? extends IChemicalTank, ?, ?>... chemicalContainerTypes) {
public ChemicalFluidBarDecorator(boolean showFluid, Predicate<ItemStack> visibleFor, ContainerType<IChemicalTank, ?, ?>... chemicalContainerTypes) {
this.showFluid = showFluid;
this.chemicalContainerTypes = chemicalContainerTypes;
this.visibleFor = visibleFor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import java.util.List;
import mekanism.api.chemical.Chemical;
import mekanism.api.chemical.ChemicalStack;
import mekanism.api.chemical.IChemicalTank;
import mekanism.api.fluid.IExtendedFluidTank;
import mekanism.common.attachments.containers.ContainerType;
Expand Down Expand Up @@ -32,7 +30,7 @@ public boolean render(GuiGraphics guiGraphics, Font font, ItemStack stack, int x
}
yOffset += 12;

if (tryRender(guiGraphics, stack, ContainerType.CHEMICAL, xOffset, yOffset, armor.getGasTankSpecs())) {
if (tryRender(guiGraphics, stack, xOffset, yOffset, armor.getGasTankSpecs())) {
yOffset--;
}
//TODO: Other chemical types as they get added to different meka suit pieces
Expand All @@ -50,10 +48,9 @@ public boolean render(GuiGraphics guiGraphics, Font font, ItemStack stack, int x
return true;
}

private <CHEMICAL extends Chemical, STACK extends ChemicalStack, TANK extends IChemicalTank> boolean tryRender(
GuiGraphics guiGraphics, ItemStack stack, ContainerType<TANK, ?, ?> containerType, int xOffset, int yOffset, List<ChemicalTankSpec<CHEMICAL>> chemicalTankSpecs) {
private boolean tryRender(GuiGraphics guiGraphics, ItemStack stack, int xOffset, int yOffset, List<ChemicalTankSpec> chemicalTankSpecs) {
if (!chemicalTankSpecs.isEmpty()) {
List<TANK> tanks = containerType.getAttachmentContainersIfPresent(stack);
List<IChemicalTank> tanks = ContainerType.CHEMICAL.getAttachmentContainersIfPresent(stack);
int tank = getDisplayTank(chemicalTankSpecs, stack, tanks.size());
if (tank != -1) {
ChemicalFluidBarDecorator.renderBar(guiGraphics, xOffset, yOffset, tanks.get(tank));
Expand Down
Loading

0 comments on commit f8a3cc5

Please sign in to comment.