-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #327 from trainvoi/LargeFluidPump+BiomeProperty
Large fluid pump+Biome property
- Loading branch information
Showing
6 changed files
with
400 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/main/java/supersymmetry/api/recipes/builders/BiomeRecipeBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
src/main/java/supersymmetry/api/recipes/properties/BiomeProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.