Skip to content

Commit

Permalink
Merge pull request #327 from trainvoi/LargeFluidPump+BiomeProperty
Browse files Browse the repository at this point in the history
Large fluid pump+Biome property
  • Loading branch information
bruberu authored Oct 24, 2024
2 parents ae2a87c + 2d306b3 commit fbb2fc5
Show file tree
Hide file tree
Showing 6 changed files with 400 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/supersymmetry/api/recipes/SuSyRecipeMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ public class SuSyRecipeMaps {
.setProgressBar(GuiTextures.PROGRESS_BAR_SIFT, ProgressWidget.MoveType.VERTICAL)
.setSound(GTSoundEvents.BATH);

public static final RecipeMap<BiomeRecipeBuilder> PUMPING_RECIPES = new RecipeMap<>("large_fluid_pump", 1, 0, 0, 1, new BiomeRecipeBuilder(), false)
.setProgressBar(GuiTextures.PROGRESS_BAR_GAS_COLLECTOR, ProgressWidget.MoveType.HORIZONTAL)
.setSound(GTSoundEvents.MINER);

public static final RecipeMap<DronePadRecipeBuilder> DRONE_PAD = new RecipeMap<>("drone_pad", 4, 9, 0, 0, new DronePadRecipeBuilder(), false);

public static final RecipeMap<SimpleRecipeBuilder> BLENDER_RECIPES = new RecipeMap<>("blender", 9, 1, 6, 2, new SimpleRecipeBuilder().EUt(VA[LV]), false)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package supersymmetry.api.recipes.builders;

import gregtech.api.recipes.Recipe;
import gregtech.api.recipes.RecipeBuilder;
import gregtech.api.recipes.RecipeMap;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.biome.Biome;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.jetbrains.annotations.NotNull;
import supersymmetry.api.recipes.properties.BiomeProperty;

import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

/**
* A custom recipeBuilder, for allowing us to put our own recipeProperty {@link BiomeProperty} into a recipe
*/
public class BiomeRecipeBuilder extends RecipeBuilder<BiomeRecipeBuilder> {

public BiomeRecipeBuilder() {
}

public BiomeRecipeBuilder(Recipe recipe, RecipeMap<BiomeRecipeBuilder> recipeMap) {
super(recipe, recipeMap);
}

public BiomeRecipeBuilder(RecipeBuilder<BiomeRecipeBuilder> recipeBuilder) {
super(recipeBuilder);
}

@Override
public BiomeRecipeBuilder copy() {
return new BiomeRecipeBuilder(this);
}

@Override
public boolean applyProperty(@NotNull String key, Object value) {
if (key.equals(BiomeProperty.KEY)) {
if (value instanceof BiomeProperty.BiomePropertyList list) {
BiomeProperty.BiomePropertyList biomes = getBiomePropertyList();
if (biomes == BiomeProperty.BiomePropertyList.EMPTY_LIST) {
biomes = new BiomeProperty.BiomePropertyList();
this.applyProperty(BiomeProperty.getInstance(), biomes);
}
biomes.merge(list);
return true;
}
return false;
}
return super.applyProperty(key, value);
}

public BiomeRecipeBuilder biomes(String... biomes) {
return biomes(false, biomes);
}

private BiomeRecipeBuilder biomes(boolean toBlacklist, String... biomeRLs) {
List<Biome> biomes = new ArrayList<>();
for (String biomeRL : biomeRLs) {
Biome biome = Biome.REGISTRY.getObject(new ResourceLocation(biomeRL));
if (biome != null) {
biomes.add(biome);
} else {
throw new NoSuchElementException("No biome with ResouceLocation \"" + biomeRL + "\" found");
}
}
return biomesInternal(toBlacklist, biomes);
}

private BiomeRecipeBuilder biomesInternal(boolean toBlacklist, List<Biome> biomes) {
BiomeProperty.BiomePropertyList biomePropertyList = getBiomePropertyList();
if (biomePropertyList == BiomeProperty.BiomePropertyList.EMPTY_LIST) {
biomePropertyList = new BiomeProperty.BiomePropertyList();
this.applyProperty(BiomeProperty.getInstance(), biomePropertyList);
}
for (Biome biome : biomes) {
biomePropertyList.add(biome, toBlacklist);
}
return this;
}

public BiomeProperty.BiomePropertyList getBiomePropertyList() {
return this.recipePropertyStorage == null ? BiomeProperty.BiomePropertyList.EMPTY_LIST :
this.recipePropertyStorage.getRecipePropertyValue(BiomeProperty.getInstance(),
BiomeProperty.BiomePropertyList.EMPTY_LIST);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.appendSuper(super.toString())
.append("biomes", getBiomePropertyList())
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package supersymmetry.api.recipes.properties;

import gregtech.api.recipes.recipeproperties.RecipeProperty;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.I18n;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class BiomeProperty extends RecipeProperty<BiomeProperty.BiomePropertyList> {

public static final String KEY = "biome";

private static BiomeProperty INSTANCE;

private BiomeProperty() {
super(KEY, BiomePropertyList.class);
}

public static BiomeProperty getInstance() {
if (INSTANCE == null)
INSTANCE = new BiomeProperty();
return INSTANCE;
}

private static String getBiomesForRecipe(List<Biome> value) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < value.size(); i++) {
builder.append(value.get(i).biomeName);
if (i != value.size() - 1)
builder.append(", ");
}
String str = builder.toString();

if (str.length() >= 13) {
str = str.substring(0, 10) + "..";
}
return str;
}

@Override
@SideOnly(Side.CLIENT)
public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) {
BiomePropertyList list = castValue(value);

if (list.whiteListBiomes.size() > 0)
minecraft.fontRenderer.drawString(I18n.format("susy.recipe.biomes",
getBiomesForRecipe(castValue(value).whiteListBiomes)), x, y, color);
if (list.blackListBiomes.size() > 0)
minecraft.fontRenderer.drawString(I18n.format("susy.recipe.biomes_blocked",
getBiomesForRecipe(castValue(value).blackListBiomes)), x, y, color);
}

public static class BiomePropertyList {

public static BiomePropertyList EMPTY_LIST = new BiomePropertyList();

public final List<Biome> whiteListBiomes = new ObjectArrayList<>();
public final List<Biome> blackListBiomes = new ObjectArrayList<>();

public void add(Biome biome, boolean toBlacklist) {
if (toBlacklist) {
blackListBiomes.add(biome);
whiteListBiomes.remove(biome);
} else {
whiteListBiomes.add(biome);
blackListBiomes.remove(biome);
}
}

public void merge(@NotNull BiomeProperty.BiomePropertyList list) {
this.whiteListBiomes.addAll(list.whiteListBiomes);
this.blackListBiomes.addAll(list.blackListBiomes);
}

public boolean checkBiome(Biome biome) {
boolean valid = true;
if (this.blackListBiomes.size() > 0) valid = !this.blackListBiomes.contains(biome);
if (this.whiteListBiomes.size() > 0) valid = this.whiteListBiomes.contains(biome);
return valid;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public class SuSyMetaTileEntities {
public static MetaTileEntityFrothFlotationTank FROTH_FLOTATION_TANK;
public static MetaTileEntityMultiStageFlashDistiller MULTI_STAGE_FLASH_DISTILLER;

public static MetaTileEntityLargeFluidPump LARGE_FLUID_PUMP;
public static MetaTileEntityOceanPumper OCEAN_PUMPER;
public static MetaTileEntityHighTemperatureDistillationTower HIGH_TEMPERATURE_DISTILLATION_TOWER;
public static MetaTileEntityRotaryKiln ROTARY_KILN;
Expand Down Expand Up @@ -273,6 +274,8 @@ public static void init() {
PHASE_SEPARATOR[0] = registerMetaTileEntity(17018, new MetaTileEntityPhaseSeparator(susyId("phase_separator")));
BATH_CONDENSER[0] = registerMetaTileEntity(17019, new MetaTileEntityBathCondenser(susyId("bath_condenser")));

LARGE_FLUID_PUMP = registerMetaTileEntity(17021, new MetaTileEntityLargeFluidPump(susyId("large_fluid_pump")));

registerSimpleMTE(ELECTROSTATIC_SEPARATOR, 12, 17035, "electrostatic_separator", SuSyRecipeMaps.ELECTROSTATIC_SEPARATOR, SusyTextures.ELECTROSTATIC_SEPARATOR_OVERLAY, true, GTUtility.defaultTankSizeFunction);
registerSimpleMTE(POLISHING_MACHINE, 12, 17048, "polishing_machine", SuSyRecipeMaps.POLISHING_MACHINE, SusyTextures.POLISHING_MACHINE_OVERLAY, true, GTUtility.defaultTankSizeFunction);
registerSimpleMTE(TEXTILE_SPINNER, 12, 17061, "textile_spinner", SuSyRecipeMaps.SPINNING_RECIPES, SusyTextures.TEXTILE_SPINNER_OVERLAY, true);
Expand Down
Loading

0 comments on commit fbb2fc5

Please sign in to comment.