Added grinder and inscriber recipes. Improved JEI integration.
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
package appeng;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.items.materials.MaterialType;
|
||||
import appeng.items.parts.PartType;
|
||||
import com.google.gson.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.Map;
|
||||
|
||||
public class FixupIngredients {
|
||||
|
||||
private static Gson gson = new GsonBuilder()
|
||||
.setPrettyPrinting()
|
||||
.create();
|
||||
|
||||
private static JsonObject visitObjProps(JsonObject obj) {
|
||||
for (Map.Entry<String, JsonElement> e : obj.entrySet()) {
|
||||
e.setValue(visitAndReplace(e.getValue()));
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
private static JsonElement visitAndReplace(JsonElement el) {
|
||||
if (el.isJsonArray()) {
|
||||
JsonArray arr = el.getAsJsonArray();
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
arr.set(i, visitAndReplace(arr.get(i)));
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
if (!el.isJsonObject()) {
|
||||
return el;
|
||||
}
|
||||
|
||||
JsonObject obj = el.getAsJsonObject();
|
||||
if (obj.size() != 2 && (obj.size() != 3 || !obj.has("count"))) {
|
||||
return visitObjProps(obj);
|
||||
}
|
||||
Integer count = null;
|
||||
if (obj.has("count")) {
|
||||
count = obj.get("count").getAsInt();
|
||||
}
|
||||
|
||||
JsonPrimitive type = obj.getAsJsonPrimitive("type");
|
||||
|
||||
if (type == null) {
|
||||
return visitObjProps(obj);
|
||||
}
|
||||
|
||||
if ("forge:ore_dict".equals(type.getAsString())) {
|
||||
String ore = obj.get("ore").getAsString();
|
||||
JsonObject r = new JsonObject();
|
||||
r.add("tag", new JsonPrimitive(AppEng.MOD_ID + ':' + "ore_" + ore));
|
||||
return r;
|
||||
}
|
||||
|
||||
if (!type.getAsString().equals("appliedenergistics2:part")) {
|
||||
return visitObjProps(obj);
|
||||
}
|
||||
String part = obj.getAsJsonPrimitive("part").getAsString();
|
||||
|
||||
String itemName = null;
|
||||
if (part.startsWith("material.")) {
|
||||
String mtName = part.substring(9).toUpperCase();
|
||||
if ("WIRELESS".equals(mtName)) {
|
||||
mtName = "WIRELESS_RECEIVER";
|
||||
}
|
||||
|
||||
itemName = mtName.toLowerCase();
|
||||
} else if (part.startsWith("part.")) {
|
||||
part = part.substring(5);
|
||||
|
||||
if ("fluid_interface".equals(part)) {
|
||||
part = "cable_fluid_interface";
|
||||
} else if ("interface".equals(part)) {
|
||||
part = "cable_interface";
|
||||
}
|
||||
}
|
||||
|
||||
if (itemName == null) {
|
||||
// Handle tags
|
||||
String tagName = null;
|
||||
if ( part.equalsIgnoreCase("cable_glass")) {
|
||||
tagName = "glass_cable";
|
||||
} else if (part.equalsIgnoreCase("cable_covered")) {
|
||||
tagName = "covered_cable";
|
||||
} else if (part.equalsIgnoreCase("cable_smart")) {
|
||||
tagName = "smart_cable";
|
||||
} else if (part.equalsIgnoreCase("cable_dense_covered")) {
|
||||
tagName = "covered_dense_cable";
|
||||
} else if (part.equalsIgnoreCase("cable_dense_smart")) {
|
||||
tagName = "smart_dense_cable";
|
||||
}
|
||||
if (tagName != null) {
|
||||
JsonObject r = new JsonObject();
|
||||
r.add("tag", new JsonPrimitive(AppEng.MOD_ID + ':' + tagName));
|
||||
return r;
|
||||
}
|
||||
itemName = part.toLowerCase();
|
||||
}
|
||||
|
||||
for (AEColor c : AEColor.values()) {
|
||||
String colorSuffix = '.' + c.registryPrefix;
|
||||
if (itemName.endsWith(colorSuffix)) {
|
||||
String p = itemName.substring(0, itemName.length() - colorSuffix.length());
|
||||
itemName = c.registryPrefix + "_" + p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (itemName.startsWith("p2p_tunnel_")) {
|
||||
itemName = itemName.substring("p2p_tunnel_".length()) + "_p2p_tunnel";
|
||||
}
|
||||
|
||||
JsonObject r = new JsonObject();
|
||||
r.add("item", new JsonPrimitive(AppEng.MOD_ID + ':' + itemName));
|
||||
if (count != null) {
|
||||
r.add("count", new JsonPrimitive(count));
|
||||
}
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
Path p= Paths.get("D:\\Applied-Energistics-2\\src\\main\\resources\\data\\appliedenergistics2");
|
||||
|
||||
Files.walkFileTree(p, new FileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
if (!file.getFileName().toString().endsWith(".json")) {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
if (file.getFileName().toString().contains("_constants")) {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
if (file.getFileName().toString().contains("_factories")) {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
JsonElement el;
|
||||
try (Reader r = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
|
||||
el = visitAndReplace(gson.fromJson(r, JsonElement.class));
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to process file " + file);
|
||||
e.printStackTrace();
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
try (Writer w = Files.newBufferedWriter(file, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
|
||||
gson.toJson(el, w);
|
||||
}
|
||||
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
package appeng.container.slot;
|
||||
|
||||
|
||||
import appeng.recipes.handlers.GrinderRecipes;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
@@ -192,7 +193,7 @@ public class SlotRestrictedInput extends AppEngSlot
|
||||
case VIEW_CELL:
|
||||
return items.viewCell().isSameAs( i );
|
||||
case ORE:
|
||||
return AEApi.instance().registries().grinder().getRecipeForInput( i ) != null;
|
||||
return GrinderRecipes.isValidIngredient(p.player.world, i);
|
||||
case FUEL:
|
||||
return ForgeHooks.getBurnTime( i ) > 0;
|
||||
case POWERED_TOOL:
|
||||
|
||||
@@ -101,7 +101,7 @@ public final class AEConfig implements IConfigurableObject, IConfigManagerHost
|
||||
// Grindstone
|
||||
private List<String> grinderOres;
|
||||
private Set<String> grinderBlackList;
|
||||
private double oreDoublePercentage;
|
||||
private float oreDoublePercentage;
|
||||
|
||||
// Batteries
|
||||
private int wirelessTerminalBattery;
|
||||
@@ -154,7 +154,7 @@ public final class AEConfig implements IConfigurableObject, IConfigManagerHost
|
||||
|
||||
this.grinderOres = new ArrayList<>(config.grinderOres.get());
|
||||
this.grinderBlackList = new HashSet<>(config.grinderBlackList.get());
|
||||
this.oreDoublePercentage = config.oreDoublePercentage.get();
|
||||
this.oreDoublePercentage = config.oreDoublePercentage.get().floatValue();
|
||||
|
||||
// FIXME: why is this here exactly???
|
||||
this.settings.registerSetting( Settings.SEARCH_TOOLTIPS, YesNo.YES );
|
||||
@@ -522,7 +522,7 @@ public final class AEConfig implements IConfigurableObject, IConfigManagerHost
|
||||
return this.grinderBlackList;
|
||||
}
|
||||
|
||||
public double getOreDoublePercentage()
|
||||
public float getOreDoublePercentage()
|
||||
{
|
||||
return this.oreDoublePercentage;
|
||||
}
|
||||
|
||||
@@ -96,6 +96,8 @@ import appeng.recipes.conditions.FeaturesEnabled;
|
||||
import appeng.recipes.game.DisassembleRecipe;
|
||||
import appeng.recipes.handlers.GrinderRecipe;
|
||||
import appeng.recipes.handlers.GrinderRecipeSerializer;
|
||||
import appeng.recipes.handlers.InscriberRecipe;
|
||||
import appeng.recipes.handlers.InscriberRecipeSerializer;
|
||||
import appeng.server.AECommand;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
@@ -587,14 +589,13 @@ final class Registration
|
||||
final ApiDefinitions definitions = Api.INSTANCE.definitions();
|
||||
|
||||
GrinderRecipe.TYPE = new AERecipeType<>(GrinderRecipeSerializer.INSTANCE.getRegistryName());
|
||||
InscriberRecipe.TYPE = new AERecipeType<>(InscriberRecipeSerializer.INSTANCE.getRegistryName());
|
||||
|
||||
r.registerAll(
|
||||
DisassembleRecipe.SERIALIZER,
|
||||
GrinderRecipeSerializer.INSTANCE
|
||||
GrinderRecipeSerializer.INSTANCE,
|
||||
InscriberRecipeSerializer.INSTANCE
|
||||
// FacadeRecipe.getSerializer( (ItemFacade) definitions.items().facade().item() ) FIXME reimplement facades
|
||||
// this.factories.put( new ResourceLocation( AppEng.MOD_ID, "inscriber" ), new InscriberHandler() ); FIXME re-implement machine recipes
|
||||
// this.factories.put( new ResourceLocation( AppEng.MOD_ID, "smelt" ), new SmeltingHandler() );
|
||||
// this.factories.put( new ResourceLocation( AppEng.MOD_ID, "grinder" ), new GrinderHandler() );
|
||||
);
|
||||
|
||||
CraftingHelper.register( FeaturesEnabled.Serializer.INSTANCE );
|
||||
|
||||
@@ -20,7 +20,6 @@ package appeng.core.features.registries;
|
||||
|
||||
|
||||
import appeng.api.features.IChargerRegistry;
|
||||
import appeng.api.features.IGrinderRegistry;
|
||||
import appeng.api.features.IInscriberRegistry;
|
||||
import appeng.api.features.ILocatableRegistry;
|
||||
import appeng.api.features.IMatterCannonAmmoRegistry;
|
||||
@@ -37,7 +36,6 @@ import appeng.api.parts.IPartModels;
|
||||
import appeng.api.storage.ICellRegistry;
|
||||
import appeng.core.features.registries.cell.CellRegistry;
|
||||
import appeng.core.features.registries.charger.ChargerRegistry;
|
||||
import appeng.core.features.registries.grinder.GrinderRecipeManager;
|
||||
import appeng.core.features.registries.inscriber.InscriberRegistry;
|
||||
|
||||
|
||||
@@ -52,7 +50,6 @@ import appeng.core.features.registries.inscriber.InscriberRegistry;
|
||||
*/
|
||||
public class RegistryContainer implements IRegistryContainer
|
||||
{
|
||||
private final IGrinderRegistry grinder = new GrinderRecipeManager();
|
||||
private final IInscriberRegistry inscriber = new InscriberRegistry();
|
||||
private final IChargerRegistry charger = new ChargerRegistry();
|
||||
private final ICellRegistry cell = new CellRegistry();
|
||||
@@ -97,12 +94,6 @@ public class RegistryContainer implements IRegistryContainer
|
||||
return this.cell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGrinderRegistry grinder()
|
||||
{
|
||||
return this.grinder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInscriberRegistry inscriber()
|
||||
{
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.core.features.registries.grinder;
|
||||
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.features.IGrinderRecipe;
|
||||
|
||||
|
||||
public class AppEngGrinderRecipe implements IGrinderRecipe
|
||||
{
|
||||
|
||||
private final ItemStack in;
|
||||
private final ItemStack out;
|
||||
|
||||
private final float optionalChance;
|
||||
private final Optional<ItemStack> optionalOutput;
|
||||
|
||||
private final float optionalChance2;
|
||||
private final Optional<ItemStack> optionalOutput2;
|
||||
|
||||
private final int turns;
|
||||
|
||||
AppEngGrinderRecipe( final ItemStack input, final ItemStack output, final int cost )
|
||||
{
|
||||
this( input, output, null, null, 0, 0, cost );
|
||||
}
|
||||
|
||||
AppEngGrinderRecipe( final ItemStack input, final ItemStack output, final ItemStack optional, final float chance, final int cost )
|
||||
{
|
||||
this( input, output, optional, null, chance, 0, cost );
|
||||
}
|
||||
|
||||
AppEngGrinderRecipe( final ItemStack input, final ItemStack output, final ItemStack optional1, final ItemStack optional2, final float chance1, final float chance2, final int cost )
|
||||
{
|
||||
this.in = input;
|
||||
this.out = output;
|
||||
|
||||
this.optionalOutput = Optional.ofNullable( optional1 );
|
||||
this.optionalChance = chance1;
|
||||
|
||||
this.optionalOutput2 = Optional.ofNullable( optional2 );
|
||||
this.optionalChance2 = chance2;
|
||||
|
||||
this.turns = cost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getInput()
|
||||
{
|
||||
return this.in;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getOutput()
|
||||
{
|
||||
return this.out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ItemStack> getOptionalOutput()
|
||||
{
|
||||
return this.optionalOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ItemStack> getSecondOptionalOutput()
|
||||
{
|
||||
return this.optionalOutput2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getOptionalChance()
|
||||
{
|
||||
return this.optionalChance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getSecondOptionalChance()
|
||||
{
|
||||
return this.optionalChance2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredTurns()
|
||||
{
|
||||
return this.turns;
|
||||
}
|
||||
}
|
||||
@@ -1,489 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.core.features.registries.grinder;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
|
||||
import appeng.api.features.IGrinderRecipe;
|
||||
import appeng.api.features.IGrinderRecipeBuilder;
|
||||
import appeng.api.features.IGrinderRegistry;
|
||||
import appeng.api.features.IInscriberRecipe;
|
||||
import appeng.api.features.IInscriberRecipeBuilder;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AELog;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public final class GrinderRecipeManager implements IGrinderRegistry // FIXME, IOreListener
|
||||
{
|
||||
private final Map<CacheKey, IGrinderRecipe> recipes;
|
||||
private final Map<ItemStack, String> ores;
|
||||
private final Map<ItemStack, String> ingots;
|
||||
private final Map<String, ItemStack> dusts;
|
||||
private final Map<String, Integer> dustToOreRatio;
|
||||
|
||||
public GrinderRecipeManager()
|
||||
{
|
||||
this.recipes = Maps.newHashMap();
|
||||
this.ores = Maps.newHashMap();
|
||||
this.ingots = Maps.newHashMap();
|
||||
this.dusts = Maps.newHashMap();
|
||||
this.dustToOreRatio = Maps.newHashMap();
|
||||
|
||||
this.addDustRatio( "Obsidian", 1 );
|
||||
this.addDustRatio( "Charcoal", 1 );
|
||||
this.addDustRatio( "Coal", 1 );
|
||||
|
||||
this.addOre( "Coal", new ItemStack( Items.COAL ) );
|
||||
this.addOre( "Charcoal", new ItemStack( Items.COAL, 1 ) );
|
||||
|
||||
this.addOre( "NetherQuartz", new ItemStack( Blocks.NETHER_QUARTZ_ORE ) );
|
||||
this.addIngot( "NetherQuartz", new ItemStack( Items.QUARTZ ) );
|
||||
|
||||
this.addOre( "Gold", new ItemStack( Blocks.GOLD_ORE ) );
|
||||
this.addIngot( "Gold", new ItemStack( Items.GOLD_INGOT ) );
|
||||
|
||||
this.addOre( "Iron", new ItemStack( Blocks.IRON_ORE ) );
|
||||
this.addIngot( "Iron", new ItemStack( Items.IRON_INGOT ) );
|
||||
|
||||
this.addOre( "Obsidian", new ItemStack( Blocks.OBSIDIAN ) );
|
||||
|
||||
this.addIngot( "Ender", new ItemStack( Items.ENDER_PEARL ) );
|
||||
this.addIngot( "EnderPearl", new ItemStack( Items.ENDER_PEARL ) );
|
||||
|
||||
this.addIngot( "Wheat", new ItemStack( Items.WHEAT ) );
|
||||
|
||||
// FIXME OreDictionaryHandler.INSTANCE.observe( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGrinderRecipeBuilder builder()
|
||||
{
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addRecipe( IGrinderRecipe recipe )
|
||||
{
|
||||
Preconditions.checkNotNull( recipe, "Cannot add null as recipe." );
|
||||
|
||||
return this.injectRecipe( recipe );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IGrinderRecipe> getRecipes()
|
||||
{
|
||||
return Collections.unmodifiableCollection( this.recipes.values() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeRecipe( IGrinderRecipe recipe )
|
||||
{
|
||||
Preconditions.checkNotNull( recipe, "Cannot remove null as recipe." );
|
||||
|
||||
final CacheKey key = new CacheKey( recipe.getInput() );
|
||||
final IGrinderRecipe removedRecipe = this.recipes.remove( key );
|
||||
|
||||
this.log( "Removed Grinding of '%1%s'", Platform.getItemDisplayName( recipe.getInput() ) );
|
||||
|
||||
return removedRecipe != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGrinderRecipe getRecipeForInput( final ItemStack input )
|
||||
{
|
||||
this.log( "Looking up recipe for '%1$s'", Platform.getItemDisplayName( input ) );
|
||||
|
||||
if( input == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final IGrinderRecipe recipe = this.recipes.get( new CacheKey( input ) );
|
||||
|
||||
if( recipe == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
this.log( "Recipe for '%1$s' found '%2$s'", input.getTranslationKey(), Platform.getItemDisplayName( recipe.getOutput() ) );
|
||||
return recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDustRatio( String oredictName, int ratio )
|
||||
{
|
||||
Preconditions.checkNotNull( oredictName );
|
||||
Preconditions.checkArgument( ratio > 0 );
|
||||
|
||||
this.log( "Added ratio for '%1$s' of %2$d", oredictName, ratio );
|
||||
|
||||
this.dustToOreRatio.put( oredictName, ratio );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeDustRatio( String oredictName )
|
||||
{
|
||||
Preconditions.checkNotNull( oredictName );
|
||||
|
||||
this.log( "Removed ratio for '%1$s'", oredictName );
|
||||
|
||||
return this.dustToOreRatio.remove( oredictName ) != null;
|
||||
}
|
||||
|
||||
// FIXME @Override
|
||||
// FIXME public void oreRegistered( final String name, final ItemStack item )
|
||||
// FIXME {
|
||||
// FIXME if( !AEConfig.instance().getGrinderBlackList().contains( name ) && ( name.startsWith( "ore" ) || name.startsWith( "crystal" ) || name
|
||||
// FIXME .startsWith( "gem" ) || name.startsWith( "ingot" ) || name.startsWith( "dust" ) ) )
|
||||
// FIXME {
|
||||
// FIXME for( final String ore : AEConfig.instance().getGrinderOres() )
|
||||
// FIXME {
|
||||
// FIXME if( name.equals( "ore" + ore ) )
|
||||
// FIXME {
|
||||
// FIXME this.addOre( ore, item );
|
||||
// FIXME }
|
||||
// FIXME else if( name.equals( "crystal" + ore ) || name.equals( "ingot" + ore ) || name.equals( "gem" + ore ) )
|
||||
// FIXME {
|
||||
// FIXME this.addIngot( ore, item );
|
||||
// FIXME }
|
||||
// FIXME else if( name.equals( "dust" + ore ) )
|
||||
// FIXME {
|
||||
// FIXME this.addDust( ore, item );
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
|
||||
private boolean injectRecipe( final IGrinderRecipe grinderRecipe )
|
||||
{
|
||||
final CacheKey cacheKey = new CacheKey( grinderRecipe.getInput() );
|
||||
|
||||
if( this.recipes.containsKey( cacheKey ) )
|
||||
{
|
||||
this.log( "Tried to add duplicate recipe for '%1$s'", Platform.getItemDisplayName( grinderRecipe.getInput() ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
this.recipes.put( cacheKey, grinderRecipe );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private int getDustToOreRatio( final String name )
|
||||
{
|
||||
return this.dustToOreRatio.getOrDefault( name, 2 );
|
||||
}
|
||||
|
||||
private void addOre( final String name, final ItemStack item )
|
||||
{
|
||||
if( item == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.log( "Adding Ore: '%1$s'", Platform.getItemDisplayName( item ) );
|
||||
|
||||
this.ores.put( item, name );
|
||||
|
||||
if( this.dusts.containsKey( name ) )
|
||||
{
|
||||
final ItemStack is = this.dusts.get( name ).copy();
|
||||
final int ratio = this.getDustToOreRatio( name );
|
||||
if( ratio > 1 )
|
||||
{
|
||||
final ItemStack extra = is.copy();
|
||||
extra.setCount( ratio - 1 );
|
||||
|
||||
final IGrinderRecipeBuilder builder = this.builder();
|
||||
IGrinderRecipe grinderRecipe = builder.withInput( item )
|
||||
.withOutput( is )
|
||||
.withFirstOptional( extra, (float) ( AEConfig.instance().getOreDoublePercentage() / 100.0 ) )
|
||||
.withTurns( 8 )
|
||||
.build();
|
||||
|
||||
this.addRecipe( grinderRecipe );
|
||||
}
|
||||
else
|
||||
{
|
||||
final IGrinderRecipeBuilder builder = this.builder();
|
||||
IGrinderRecipe grinderRecipe = builder.withInput( item )
|
||||
.withOutput( is )
|
||||
.withTurns( 8 )
|
||||
.build();
|
||||
|
||||
this.addRecipe( grinderRecipe );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addIngot( final String name, final ItemStack item )
|
||||
{
|
||||
if( item == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.log( "Adding Ingot: '%1$s'", Platform.getItemDisplayName( item ) );
|
||||
|
||||
this.ingots.put( item, name );
|
||||
|
||||
if( this.dusts.containsKey( name ) )
|
||||
{
|
||||
final IGrinderRecipeBuilder builder = this.builder();
|
||||
IGrinderRecipe grinderRecipe = builder.withInput( item )
|
||||
.withOutput( this.dusts.get( name ) )
|
||||
.withTurns( 4 )
|
||||
.build();
|
||||
|
||||
this.addRecipe( grinderRecipe );
|
||||
}
|
||||
}
|
||||
|
||||
private void addDust( final String name, final ItemStack item )
|
||||
{
|
||||
if( item == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if( this.dusts.containsKey( name ) )
|
||||
{
|
||||
this.log( "Rejecting Dust: '%1$s'", Platform.getItemDisplayName( item ) );
|
||||
return;
|
||||
}
|
||||
|
||||
this.log( "Adding Dust: '%1$s'", Platform.getItemDisplayName( item ) );
|
||||
|
||||
this.dusts.put( name, item );
|
||||
|
||||
for( final Entry<ItemStack, String> d : this.ores.entrySet() )
|
||||
{
|
||||
if( name.equals( d.getValue() ) )
|
||||
{
|
||||
final ItemStack is = item.copy();
|
||||
is.setCount( 1 );
|
||||
final int ratio = this.getDustToOreRatio( name );
|
||||
if( ratio > 1 )
|
||||
{
|
||||
final ItemStack extra = is.copy();
|
||||
extra.setCount( ratio - 1 );
|
||||
|
||||
final IGrinderRecipeBuilder builder = this.builder();
|
||||
final IGrinderRecipe grinderRecipe = builder.withInput( d.getKey() )
|
||||
.withOutput( is )
|
||||
.withFirstOptional( extra, (float) ( AEConfig.instance().getOreDoublePercentage() / 100.0 ) )
|
||||
.withTurns( 8 )
|
||||
.build();
|
||||
|
||||
this.addRecipe( grinderRecipe );
|
||||
}
|
||||
else
|
||||
{
|
||||
final IGrinderRecipeBuilder builder = this.builder();
|
||||
final IGrinderRecipe grinderRecipe = builder.withInput( d.getKey() )
|
||||
.withOutput( is )
|
||||
.withTurns( 8 )
|
||||
.build();
|
||||
|
||||
this.addRecipe( grinderRecipe );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( final Entry<ItemStack, String> d : this.ingots.entrySet() )
|
||||
{
|
||||
if( name.equals( d.getValue() ) )
|
||||
{
|
||||
final IGrinderRecipeBuilder builder = this.builder();
|
||||
final IGrinderRecipe grinderRecipe = builder.withInput( d.getKey() )
|
||||
.withOutput( item )
|
||||
.withTurns( 4 )
|
||||
.build();
|
||||
|
||||
this.addRecipe( grinderRecipe );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void log( final String o, Object... params )
|
||||
{
|
||||
AELog.grinder( o, params );
|
||||
}
|
||||
|
||||
private static class CacheKey
|
||||
{
|
||||
private final Item item;
|
||||
|
||||
CacheKey( ItemStack input )
|
||||
{
|
||||
Preconditions.checkNotNull( input );
|
||||
Preconditions.checkNotNull( input.getItem() );
|
||||
|
||||
this.item = input.getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ( ( this.item == null ) ? 0 : this.item.hashCode() );
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object obj )
|
||||
{
|
||||
if( this == obj )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if( obj == null || this.getClass() != obj.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CacheKey other = (CacheKey) obj;
|
||||
|
||||
if( this.item == null )
|
||||
{
|
||||
if( other.item != null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( this.item != other.item )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal {@link IInscriberRecipeBuilder} implementation.
|
||||
* Needs to be adapted to represent a correct {@link IInscriberRecipe}
|
||||
*/
|
||||
private static final class Builder implements IGrinderRecipeBuilder
|
||||
{
|
||||
|
||||
private ItemStack in;
|
||||
private ItemStack out;
|
||||
|
||||
private float optionalChance;
|
||||
private ItemStack optionalOutput;
|
||||
|
||||
private float optionalChance2;
|
||||
private ItemStack optionalOutput2;
|
||||
|
||||
private int turns = 8;
|
||||
|
||||
@Override
|
||||
public IGrinderRecipeBuilder withInput( ItemStack input )
|
||||
{
|
||||
Preconditions.checkNotNull( input );
|
||||
Preconditions.checkArgument( !input.isEmpty(), "Input cannot be empty." );
|
||||
|
||||
this.in = this.copy( input );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGrinderRecipeBuilder withOutput( ItemStack output )
|
||||
{
|
||||
Preconditions.checkNotNull( output );
|
||||
Preconditions.checkArgument( !output.isEmpty(), "Output cannot be empty." );
|
||||
|
||||
this.out = this.copy( output );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGrinderRecipeBuilder withFirstOptional( ItemStack optional, float chance )
|
||||
{
|
||||
Preconditions.checkNotNull( optional );
|
||||
Preconditions.checkArgument( !optional.isEmpty(), "Optional cannot be empty." );
|
||||
Preconditions.checkArgument( chance >= 0 && chance <= 1.0 );
|
||||
|
||||
this.optionalOutput = this.copy( optional );
|
||||
this.optionalChance = chance;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGrinderRecipeBuilder withSecondOptional( ItemStack optional, float chance )
|
||||
{
|
||||
Preconditions.checkNotNull( optional );
|
||||
Preconditions.checkArgument( !optional.isEmpty(), "Optional cannot be empty." );
|
||||
Preconditions.checkArgument( chance >= 0 && chance <= 1.0 );
|
||||
|
||||
this.optionalOutput2 = this.copy( optional );
|
||||
this.optionalChance2 = chance;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGrinderRecipeBuilder withTurns( int turns )
|
||||
{
|
||||
Preconditions.checkArgument( turns > 0 );
|
||||
|
||||
this.turns = turns;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IGrinderRecipe build()
|
||||
{
|
||||
Preconditions.checkState( this.in != null, "Input itemstack must be defined." );
|
||||
Preconditions.checkState( this.out != null, "Output itemstack must be defined." );
|
||||
|
||||
return new AppEngGrinderRecipe( this.in, this.out, this.optionalOutput, this.optionalOutput2, this.optionalChance, this.optionalChance2, this.turns );
|
||||
}
|
||||
|
||||
private ItemStack copy( final ItemStack is )
|
||||
{
|
||||
if( is != null )
|
||||
{
|
||||
return is.copy();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class GrinderRecipeCategory implements IRecipeCategory<GrinderRecipe>
|
||||
|
||||
public GrinderRecipeCategory( IGuiHelper guiHelper )
|
||||
{
|
||||
this.localizedName = I18n.format( "tile.appliedenergistics2.grindstone.name" );
|
||||
this.localizedName = I18n.format( "block.appliedenergistics2.grindstone" );
|
||||
|
||||
ResourceLocation location = new ResourceLocation( AppEng.MOD_ID, "textures/guis/grinder.png" );
|
||||
this.background = guiHelper.createDrawable( location, 11, 16, 154, 70 );
|
||||
|
||||
@@ -32,8 +32,12 @@ import mezz.jei.api.helpers.IGuiHelper;
|
||||
import mezz.jei.api.ingredients.IIngredients;
|
||||
import mezz.jei.api.recipe.category.IRecipeCategory;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
class InscriberRecipeCategory implements IRecipeCategory<InscriberRecipe>
|
||||
{
|
||||
@@ -57,7 +61,7 @@ class InscriberRecipeCategory implements IRecipeCategory<InscriberRecipe>
|
||||
{
|
||||
ResourceLocation location = new ResourceLocation( AppEng.MOD_ID, "textures/guis/inscriber.png" );
|
||||
this.background = guiHelper.createDrawable( location, 44, 15, 97, 64 );
|
||||
this.localizedName = I18n.format( "tile.appliedenergistics2.inscriber.name" );
|
||||
this.localizedName = I18n.format( "block.appliedenergistics2.inscriber" );
|
||||
|
||||
IDrawableStatic progressDrawable = guiHelper.drawableBuilder( location, 135, 177, 6, 18 )
|
||||
.addPadding(24, 0, 91, 0)
|
||||
@@ -110,13 +114,7 @@ class InscriberRecipeCategory implements IRecipeCategory<InscriberRecipe>
|
||||
|
||||
@Override
|
||||
public void setIngredients(InscriberRecipe recipe, IIngredients ingredients) {
|
||||
|
||||
// FIXME List<List<ItemStack>> inputSlots = new ArrayList<>( 3 );
|
||||
// FIXME inputSlots.add( Collections.singletonList( recipe.getTopOptional() ) );
|
||||
// FIXME inputSlots.add( recipe.getInputs() );
|
||||
// FIXME inputSlots.add( Collections.singletonList( recipe.getBottomOptional() ) );
|
||||
// FIXME ingredients.setInputLists(VanillaTypes.ITEM, inputSlots );
|
||||
|
||||
ingredients.setInputIngredients(recipe.getIngredients());
|
||||
ingredients.setOutput( VanillaTypes.ITEM, recipe.getOutput() );
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import appeng.core.AEConfig;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.recipes.handlers.GrinderRecipe;
|
||||
import appeng.recipes.handlers.InscriberRecipe;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import mezz.jei.api.IModPlugin;
|
||||
import mezz.jei.api.JeiPlugin;
|
||||
@@ -95,90 +96,72 @@ public class JEIPlugin implements IModPlugin
|
||||
// FIXME registration.addRecipeRegistryPlugin( new FacadeRegistryPlugin( (ItemFacade) itemFacade.get(), cableAnchor.get() ) );
|
||||
// FIXME }
|
||||
|
||||
ItemStack condenser = definitions.blocks().condenser().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
if(!condenser.isEmpty()) {
|
||||
ItemStack matterBall = definitions.materials().matterBall().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
if (!matterBall.isEmpty()) {
|
||||
registration.addRecipes(ImmutableList.of(CondenserOutput.MATTER_BALLS), CondenserCategory.UID);
|
||||
}
|
||||
ItemStack singularity = definitions.materials().singularity().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
if (!singularity.isEmpty()) {
|
||||
registration.addRecipes(ImmutableList.of(CondenserOutput.SINGULARITY), CondenserCategory.UID);
|
||||
}
|
||||
}
|
||||
|
||||
RecipeManager recipeManager = Minecraft.getInstance().world.getRecipeManager();
|
||||
registration.addRecipes(recipeManager.getRecipes(GrinderRecipe.TYPE).values(), GrinderRecipeCategory.UID);
|
||||
// FIXME registration.addRecipes( recipeManager.getRecipes(InscriberRecipe.TYPE), InscriberRecipeCategory.UID );
|
||||
registration.addRecipes(recipeManager.getRecipes(InscriberRecipe.TYPE).values(), InscriberRecipeCategory.UID );
|
||||
registration.addRecipes(ImmutableList.of(CondenserOutput.MATTER_BALLS, CondenserOutput.SINGULARITY), CondenserCategory.UID);
|
||||
|
||||
registerDescriptions(definitions, registration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
|
||||
IDefinitions definitions = AEApi.instance().definitions();
|
||||
|
||||
ItemStack grindstone = definitions.blocks().grindstone().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
if( !grindstone.isEmpty() )
|
||||
{
|
||||
registration.addRecipeCatalyst( grindstone, GrinderRecipeCategory.UID );
|
||||
}
|
||||
ItemStack grindstone = definitions.blocks().grindstone().stack(1);
|
||||
registration.addRecipeCatalyst( grindstone, GrinderRecipeCategory.UID );
|
||||
|
||||
definitions.blocks().condenser().maybeStack( 1 ).ifPresent(condenser -> {
|
||||
registration.addRecipeCatalyst(condenser, CondenserCategory.UID);
|
||||
});
|
||||
|
||||
// Register the inscriber as the crafting item for the inscription category
|
||||
definitions.blocks().inscriber().maybeStack( 1 ).ifPresent( inscriber ->
|
||||
{
|
||||
registration.addRecipeCatalyst( inscriber, InscriberRecipeCategory.UID );
|
||||
} );
|
||||
ItemStack condenser = definitions.blocks().condenser().stack(1);
|
||||
registration.addRecipeCatalyst(condenser, CondenserCategory.UID);
|
||||
|
||||
ItemStack inscriber = definitions.blocks().inscriber().stack(1);
|
||||
registration.addRecipeCatalyst( inscriber, InscriberRecipeCategory.UID );
|
||||
}
|
||||
|
||||
private void registerDescriptions(IDefinitions definitions, IRecipeRegistration registry )
|
||||
{
|
||||
IMaterials materials = definitions.materials();
|
||||
|
||||
final String message;
|
||||
final String[] message;
|
||||
if( AEConfig.instance().isFeatureEnabled( AEFeature.CERTUS_QUARTZ_WORLD_GEN ) )
|
||||
{
|
||||
message = GuiText.ChargedQuartz.getLocal() + "\n\n" + GuiText.ChargedQuartzFind.getLocal();
|
||||
message = new String[]{GuiText.ChargedQuartz.getTranslationKey(), "", GuiText.ChargedQuartzFind.getTranslationKey()};
|
||||
}
|
||||
else
|
||||
{
|
||||
message = GuiText.ChargedQuartzFind.getLocal();
|
||||
message = new String[]{GuiText.ChargedQuartzFind.getTranslationKey()};
|
||||
}
|
||||
this.addDescription( registry, materials.certusQuartzCrystalCharged(), message );
|
||||
|
||||
if( AEConfig.instance().isFeatureEnabled( AEFeature.METEORITE_WORLD_GEN ) )
|
||||
{
|
||||
this.addDescription( registry, materials.logicProcessorPress(), GuiText.inWorldCraftingPresses.getLocal() );
|
||||
this.addDescription( registry, materials.calcProcessorPress(), GuiText.inWorldCraftingPresses.getLocal() );
|
||||
this.addDescription( registry, materials.engProcessorPress(), GuiText.inWorldCraftingPresses.getLocal() );
|
||||
this.addDescription( registry, materials.logicProcessorPress(), GuiText.inWorldCraftingPresses.getTranslationKey() );
|
||||
this.addDescription( registry, materials.calcProcessorPress(), GuiText.inWorldCraftingPresses.getTranslationKey() );
|
||||
this.addDescription( registry, materials.engProcessorPress(), GuiText.inWorldCraftingPresses.getTranslationKey() );
|
||||
}
|
||||
|
||||
if( AEConfig.instance().isFeatureEnabled( AEFeature.IN_WORLD_FLUIX ) )
|
||||
{
|
||||
this.addDescription( registry, materials.fluixCrystal(), GuiText.inWorldFluix.getLocal() );
|
||||
this.addDescription( registry, materials.fluixCrystal(), GuiText.inWorldFluix.getTranslationKey() );
|
||||
}
|
||||
|
||||
if( AEConfig.instance().isFeatureEnabled( AEFeature.IN_WORLD_SINGULARITY ) )
|
||||
{
|
||||
this.addDescription( registry, materials.qESingularity(), GuiText.inWorldSingularity.getLocal() );
|
||||
this.addDescription( registry, materials.qESingularity(), GuiText.inWorldSingularity.getTranslationKey() );
|
||||
}
|
||||
|
||||
if( AEConfig.instance().isFeatureEnabled( AEFeature.IN_WORLD_PURIFICATION ) )
|
||||
{
|
||||
this.addDescription( registry, materials.purifiedCertusQuartzCrystal(), GuiText.inWorldPurificationCertus.getLocal() );
|
||||
this.addDescription( registry, materials.purifiedNetherQuartzCrystal(), GuiText.inWorldPurificationNether.getLocal() );
|
||||
this.addDescription( registry, materials.purifiedFluixCrystal(), GuiText.inWorldPurificationFluix.getLocal() );
|
||||
this.addDescription( registry, materials.purifiedCertusQuartzCrystal(), GuiText.inWorldPurificationCertus.getTranslationKey() );
|
||||
this.addDescription( registry, materials.purifiedNetherQuartzCrystal(), GuiText.inWorldPurificationNether.getTranslationKey() );
|
||||
this.addDescription( registry, materials.purifiedFluixCrystal(), GuiText.inWorldPurificationFluix.getTranslationKey() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void addDescription(IRecipeRegistration registry, IItemDefinition itemDefinition, String message )
|
||||
private void addDescription(IRecipeRegistration registry, IItemDefinition itemDefinition, String... message )
|
||||
{
|
||||
itemDefinition.maybeStack( 1 ).ifPresent( itemStack -> registry.addIngredientInfo( itemStack, VanillaTypes.ITEM, message ) );
|
||||
registry.addIngredientInfo( itemDefinition.stack(1), VanillaTypes.ITEM, message );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,196 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.recipes;
|
||||
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IDefinitions;
|
||||
import appeng.api.definitions.IItems;
|
||||
import appeng.api.definitions.IParts;
|
||||
import appeng.api.recipes.ISubItemResolver;
|
||||
import appeng.api.recipes.ResolverResult;
|
||||
import appeng.api.recipes.ResolverResultSet;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.api.util.AEColoredItemDefinition;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.items.materials.ItemMaterial;
|
||||
import appeng.items.materials.MaterialType;
|
||||
import appeng.items.parts.ItemPart;
|
||||
import appeng.items.parts.PartType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public class AEItemResolver implements ISubItemResolver
|
||||
{
|
||||
|
||||
@Override
|
||||
public Object resolveItemByName( final String nameSpace, final String itemName )
|
||||
{
|
||||
|
||||
if( nameSpace.equals( AppEng.MOD_ID ) )
|
||||
{
|
||||
final IDefinitions definitions = AEApi.instance().definitions();
|
||||
final IItems items = definitions.items();
|
||||
final IParts parts = definitions.parts();
|
||||
|
||||
if( itemName.startsWith( "paint_ball." ) )
|
||||
{
|
||||
return this.paintBall( items.coloredPaintBall(), itemName.substring( itemName.indexOf( '.' ) + 1 ), false );
|
||||
}
|
||||
|
||||
if( itemName.startsWith( "lumen_paint_ball." ) )
|
||||
{
|
||||
return this.paintBall( items.coloredPaintBall(), itemName.substring( itemName.indexOf( '.' ) + 1 ), true );
|
||||
}
|
||||
|
||||
if( itemName.equals( "cable_glass" ) )
|
||||
{
|
||||
return new ResolverResultSet( "cable_glass", parts.cableGlass().allStacks( 1 ) );
|
||||
}
|
||||
|
||||
if( itemName.startsWith( "cable_glass." ) )
|
||||
{
|
||||
return this.cableItem( parts.cableGlass(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
|
||||
}
|
||||
|
||||
if( itemName.equals( "cable_covered" ) )
|
||||
{
|
||||
return new ResolverResultSet( "cable_covered", parts.cableCovered().allStacks( 1 ) );
|
||||
}
|
||||
|
||||
if( itemName.startsWith( "cable_covered." ) )
|
||||
{
|
||||
return this.cableItem( parts.cableCovered(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
|
||||
}
|
||||
|
||||
if( itemName.equals( "cable_smart" ) )
|
||||
{
|
||||
return new ResolverResultSet( "cable_smart", parts.cableSmart().allStacks( 1 ) );
|
||||
}
|
||||
|
||||
if( itemName.startsWith( "cable_smart." ) )
|
||||
{
|
||||
return this.cableItem( parts.cableSmart(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
|
||||
}
|
||||
|
||||
if( itemName.equals( "cable_dense_covered" ) )
|
||||
{
|
||||
return new ResolverResultSet( "cable_dense_covered", parts.cableDenseCovered().allStacks( 1 ) );
|
||||
}
|
||||
|
||||
if( itemName.startsWith( "cable_dense_covered." ) )
|
||||
{
|
||||
return this.cableItem( parts.cableDenseCovered(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
|
||||
}
|
||||
|
||||
if( itemName.equals( "cable_dense_smart" ) )
|
||||
{
|
||||
return new ResolverResultSet( "cable_dense_smart", parts.cableDenseSmart().allStacks( 1 ) );
|
||||
}
|
||||
|
||||
if( itemName.startsWith( "cable_dense_smart." ) )
|
||||
{
|
||||
return this.cableItem( parts.cableDenseSmart(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
|
||||
}
|
||||
|
||||
if( itemName.startsWith( "crystal_seed." ) )
|
||||
{
|
||||
if( itemName.equalsIgnoreCase( "crystal_seed.certus" ) )
|
||||
{
|
||||
return new ResolverResultSet( "certus_crystal_seed", items.certusCrystalSeed().stack( 1 ) );
|
||||
}
|
||||
if( itemName.equalsIgnoreCase( "crystal_seed.nether" ) )
|
||||
{
|
||||
return new ResolverResultSet( "nether_crystal_seed", items.netherQuartzSeed().stack( 1 ) );
|
||||
}
|
||||
if( itemName.equalsIgnoreCase( "crystal_seed.fluix" ) )
|
||||
{
|
||||
return new ResolverResultSet( "fluix_crystal_seed", items.fluixCrystalSeed().stack( 1 ) );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if( itemName.startsWith( "material." ) )
|
||||
{
|
||||
// FIXME entire class is redundant i think
|
||||
// FIXME final String materialName = itemName.substring( itemName.indexOf( '.' ) + 1 );
|
||||
// FIXME final MaterialType mt = MaterialType.valueOf( materialName.toUpperCase() );
|
||||
// FIXME // itemName = itemName.substring( 0, itemName.indexOf( "." ) );
|
||||
// FIXME if( mt.getItemInstance() == ItemMaterial.instance && mt.getDamageValue() >= 0 && mt.isRegistered() )
|
||||
// FIXME {
|
||||
// FIXME return new ResolverResult( "material", mt.getDamageValue() );
|
||||
// FIXME }
|
||||
}
|
||||
|
||||
// FIXME if( itemName.startsWith( "part." ) )
|
||||
// FIXME {
|
||||
// FIXME final String partName = itemName.substring( itemName.indexOf( '.' ) + 1 );
|
||||
// FIXME final PartType pt = PartType.valueOf( partName.toUpperCase() );
|
||||
// FIXME // itemName = itemName.substring( 0, itemName.indexOf( "." ) );
|
||||
// FIXME final int dVal = ItemPart.instance.getDamageByType( pt );
|
||||
// FIXME if( dVal >= 0 )
|
||||
// FIXME {
|
||||
// FIXME return new ResolverResult( "part", dVal );
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object paintBall( final AEColoredItemDefinition partType, final String substring, final boolean lumen )
|
||||
{
|
||||
AEColor col;
|
||||
|
||||
try
|
||||
{
|
||||
col = AEColor.valueOf( substring.toUpperCase() );
|
||||
}
|
||||
catch( final Throwable t )
|
||||
{
|
||||
col = AEColor.TRANSPARENT;
|
||||
}
|
||||
|
||||
if( col == AEColor.TRANSPARENT )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final ItemStack is = partType.stack( col, 1 );
|
||||
return new ResolverResult( "paint_ball", ( lumen ? 20 : 0 ) + is.getDamage() );
|
||||
}
|
||||
|
||||
private Object cableItem( final AEColoredItemDefinition partType, final String substring )
|
||||
{
|
||||
AEColor col;
|
||||
|
||||
try
|
||||
{
|
||||
col = AEColor.valueOf( substring.toUpperCase() );
|
||||
}
|
||||
catch( final Throwable t )
|
||||
{
|
||||
col = AEColor.TRANSPARENT;
|
||||
}
|
||||
|
||||
final ItemStack is = partType.stack( col, 1 );
|
||||
return new ResolverResult( "part", is.getDamage() );
|
||||
}
|
||||
}
|
||||
@@ -20,18 +20,21 @@ public class GrinderRecipe implements IRecipe<IInventory> {
|
||||
private final ResourceLocation id;
|
||||
private final String group;
|
||||
private final Ingredient ingredient;
|
||||
private final int ingredientCount;
|
||||
private final ItemStack result;
|
||||
private final List<GrinderOptionalResult> optionalResults;
|
||||
private final int turns;
|
||||
|
||||
public GrinderRecipe(ResourceLocation id, String group, Ingredient ingredient, ItemStack result, int turns, List<GrinderOptionalResult> optionalResults) {
|
||||
public GrinderRecipe(ResourceLocation id, String group, Ingredient ingredient, int ingredientCount, ItemStack result, int turns, List<GrinderOptionalResult> optionalResults) {
|
||||
this.id = id;
|
||||
this.group = group;
|
||||
this.ingredient = ingredient;
|
||||
this.ingredientCount = ingredientCount;
|
||||
this.result = result;
|
||||
this.turns = turns;
|
||||
this.optionalResults = ImmutableList.copyOf(optionalResults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IInventory inv, World worldIn) {
|
||||
return this.ingredient.test(inv.getStackInSlot(0));
|
||||
@@ -72,6 +75,14 @@ public class GrinderRecipe implements IRecipe<IInventory> {
|
||||
return ingredient;
|
||||
}
|
||||
|
||||
public int getTurns() {
|
||||
return turns;
|
||||
}
|
||||
|
||||
public int getIngredientCount() {
|
||||
return ingredientCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<Ingredient> getIngredients() {
|
||||
NonNullList<Ingredient> nonnulllist = NonNullList.create();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package appeng.recipes.handlers;
|
||||
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AppEng;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -32,7 +33,12 @@ public class GrinderRecipeSerializer extends ForgeRegistryEntry<IRecipeSerialize
|
||||
@Override
|
||||
public GrinderRecipe read(ResourceLocation recipeId, JsonObject json) {
|
||||
String group = JSONUtils.getString(json, "group", "");
|
||||
Ingredient ingredient = Ingredient.deserialize(JSONUtils.getJsonObject(json, "input"));
|
||||
JsonObject inputObj = JSONUtils.getJsonObject(json, "input");
|
||||
Ingredient ingredient = Ingredient.deserialize(inputObj);
|
||||
int ingredientCount = 1;
|
||||
if (inputObj.has("count")) {
|
||||
ingredientCount = inputObj.get("count").getAsInt();
|
||||
}
|
||||
|
||||
JsonObject result = JSONUtils.getJsonObject(json, "result");
|
||||
ItemStack primaryResult = ShapedRecipe.deserializeItem(JSONUtils.getJsonObject(result, "primary"));
|
||||
@@ -45,25 +51,28 @@ public class GrinderRecipeSerializer extends ForgeRegistryEntry<IRecipeSerialize
|
||||
throw new IllegalStateException("Entry in optional result list should be an object.");
|
||||
}
|
||||
ItemStack optionalResultItem = ShapedRecipe.deserializeItem(optionalResultJson.getAsJsonObject());
|
||||
float optionalChance = JSONUtils.getFloat(optionalResultJson.getAsJsonObject(), "chance", 1.0f);
|
||||
float optionalChance = JSONUtils.getFloat(optionalResultJson.getAsJsonObject(), "percentageChance",
|
||||
AEConfig.instance().getOreDoublePercentage()) / 100.0f;
|
||||
optionalResults.add(new GrinderOptionalResult(optionalChance, optionalResultItem));
|
||||
}
|
||||
}
|
||||
|
||||
int turns = JSONUtils.getInt(json, "turns", 8);
|
||||
|
||||
return new GrinderRecipe(recipeId, group, ingredient, primaryResult, turns, optionalResults);
|
||||
return new GrinderRecipe(recipeId, group, ingredient, ingredientCount, primaryResult, turns, optionalResults);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public GrinderRecipe read(ResourceLocation recipeId, PacketBuffer buffer) {
|
||||
return null;
|
||||
// FIXME NOT YET IMPLEMENTED
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buffer, GrinderRecipe recipe) {
|
||||
|
||||
// FIXME NOT YET IMPLEMENTED
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package appeng.recipes.handlers;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class GrinderRecipes {
|
||||
|
||||
private GrinderRecipes() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Search all available Grinder recipes for a recipe matching the given input or null;
|
||||
*/
|
||||
@Nullable
|
||||
public static GrinderRecipe findForInput(World world, ItemStack input) {
|
||||
for (IRecipe<IInventory> recipe : world.getRecipeManager().getRecipes(GrinderRecipe.TYPE).values()) {
|
||||
GrinderRecipe grinderRecipe = (GrinderRecipe) recipe;
|
||||
if (grinderRecipe.getIngredient().test(input) && input.getCount() >= grinderRecipe.getIngredientCount()) {
|
||||
return grinderRecipe;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given item stack is an ingredient in any grinder recipe, disregarding its current size.
|
||||
*/
|
||||
public static boolean isValidIngredient(World world, ItemStack stack) {
|
||||
for (IRecipe<IInventory> recipe : world.getRecipeManager().getRecipes(GrinderRecipe.TYPE).values()) {
|
||||
GrinderRecipe grinderRecipe = (GrinderRecipe) recipe;
|
||||
if (grinderRecipe.getIngredient().test(stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
|
||||
package appeng.recipes.handlers;
|
||||
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
|
||||
public class InscriberHandler
|
||||
{
|
||||
|
||||
// @Override
|
||||
// public void register( JsonObject json, JsonContext ctx )
|
||||
// {
|
||||
// ItemStack result = PartRecipeFactory.getResult( json, ctx );
|
||||
// String mode = JSONUtils.getString( json, "mode" );
|
||||
//
|
||||
// JsonObject ingredients = JSONUtils.getJsonObject( json, "ingredients" );
|
||||
//
|
||||
// List<ItemStack> middle = Arrays.asList( CraftingHelper.getIngredient( ingredients.get( "middle" ), ctx ).getMatchingStacks() );
|
||||
// ItemStack[] top = new ItemStack[] { null };
|
||||
// if( ingredients.has( "top" ) )
|
||||
// {
|
||||
// top = CraftingHelper.getIngredient( JSONUtils.getJsonObject( ingredients, "top" ), ctx ).getMatchingStacks();
|
||||
// }
|
||||
//
|
||||
// ItemStack[] bottom = new ItemStack[] { null };
|
||||
// if( ingredients.has( "bottom" ) )
|
||||
// {
|
||||
// bottom = CraftingHelper.getIngredient( JSONUtils.getJsonObject( ingredients, "bottom" ), ctx ).getMatchingStacks();
|
||||
// }
|
||||
//
|
||||
// final IInscriberRegistry reg = AEApi.instance().registries().inscriber();
|
||||
// for( int i = 0; i < top.length; ++i )
|
||||
// {
|
||||
// for( int j = 0; j < bottom.length; ++j )
|
||||
// {
|
||||
// final IInscriberRecipeBuilder builder = reg.builder();
|
||||
// builder.withOutput( result );
|
||||
// builder.withProcessType( "press".equals( mode ) ? InscriberProcessType.PRESS : InscriberProcessType.INSCRIBE );
|
||||
// builder.withInputs( middle );
|
||||
//
|
||||
// if( top[i] != null )
|
||||
// {
|
||||
// builder.withTopOptional( top[i] );
|
||||
// }
|
||||
// if( bottom[j] != null )
|
||||
// {
|
||||
// builder.withBottomOptional( bottom[j] );
|
||||
// }
|
||||
//
|
||||
// reg.addRecipe( builder.build() );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
package appeng.recipes.handlers;
|
||||
|
||||
import appeng.api.features.InscriberProcessType;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class InscriberRecipe implements IRecipe<IInventory> {
|
||||
|
||||
@@ -20,20 +20,20 @@ public class InscriberRecipe implements IRecipe<IInventory> {
|
||||
private final ResourceLocation id;
|
||||
private final String group;
|
||||
|
||||
private List<Ingredient> inputs;
|
||||
private Ingredient middleInput;
|
||||
private Ingredient topOptional;
|
||||
private Ingredient bottomOptional;
|
||||
private ItemStack output;
|
||||
private ItemStack topOptional;
|
||||
private ItemStack bottomOptional;
|
||||
private InscriberProcessType type;
|
||||
private InscriberProcessType processType;
|
||||
|
||||
public InscriberRecipe(ResourceLocation id, String group, List<Ingredient> inputs, ItemStack output, ItemStack topOptional, ItemStack bottomOptional, InscriberProcessType type) {
|
||||
public InscriberRecipe(ResourceLocation id, String group, Ingredient middleInput, ItemStack output, Ingredient topOptional, Ingredient bottomOptional, InscriberProcessType processType) {
|
||||
this.id = id;
|
||||
this.group = group;
|
||||
this.inputs = inputs;
|
||||
this.middleInput = middleInput;
|
||||
this.output = output;
|
||||
this.topOptional = topOptional;
|
||||
this.bottomOptional = bottomOptional;
|
||||
this.type = type;
|
||||
this.processType = processType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,27 +43,27 @@ public class InscriberRecipe implements IRecipe<IInventory> {
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(IInventory inv) {
|
||||
return null;
|
||||
return this.output.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFit(int width, int height) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() {
|
||||
return null;
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return null;
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeSerializer<?> getSerializer() {
|
||||
return null;
|
||||
return GrinderRecipeSerializer.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,20 +71,33 @@ public class InscriberRecipe implements IRecipe<IInventory> {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
public List<Ingredient> getInputs() {
|
||||
return inputs;
|
||||
@Override
|
||||
public NonNullList<Ingredient> getIngredients() {
|
||||
NonNullList<Ingredient> nonnulllist = NonNullList.create();
|
||||
nonnulllist.add(this.topOptional);
|
||||
nonnulllist.add(this.middleInput);
|
||||
nonnulllist.add(this.bottomOptional);
|
||||
return nonnulllist;
|
||||
}
|
||||
|
||||
public Ingredient getMiddleInput() {
|
||||
return middleInput;
|
||||
}
|
||||
|
||||
public ItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
public ItemStack getTopOptional() {
|
||||
public Ingredient getTopOptional() {
|
||||
return topOptional;
|
||||
}
|
||||
|
||||
public ItemStack getBottomOptional() {
|
||||
public Ingredient getBottomOptional() {
|
||||
return bottomOptional;
|
||||
}
|
||||
|
||||
public InscriberProcessType getProcessType() {
|
||||
return processType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package appeng.recipes.handlers;
|
||||
|
||||
import appeng.api.features.InscriberProcessType;
|
||||
import appeng.core.AppEng;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.item.crafting.ShapedRecipe;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.JSONUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class InscriberRecipeSerializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<InscriberRecipe> {
|
||||
|
||||
public static final InscriberRecipeSerializer INSTANCE = new InscriberRecipeSerializer();
|
||||
|
||||
static {
|
||||
INSTANCE.setRegistryName(AppEng.MOD_ID, "inscriber");
|
||||
}
|
||||
|
||||
private InscriberRecipeSerializer() {
|
||||
}
|
||||
|
||||
private static InscriberProcessType getMode(JsonObject json) {
|
||||
String mode = JSONUtils.getString( json, "mode", "inscribe" );
|
||||
switch (mode) {
|
||||
case "inscribe":
|
||||
return InscriberProcessType.INSCRIBE;
|
||||
case "press":
|
||||
return InscriberProcessType.PRESS;
|
||||
default:
|
||||
throw new IllegalStateException("Unknown mode for inscriber recipe: " + mode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public InscriberRecipe read(ResourceLocation recipeId, JsonObject json) {
|
||||
|
||||
InscriberProcessType mode = getMode(json);
|
||||
|
||||
String group = JSONUtils.getString(json, "group", "");
|
||||
ItemStack result = ShapedRecipe.deserializeItem(JSONUtils.getJsonObject(json, "result"));
|
||||
|
||||
// Deserialize the three parts of the input
|
||||
JsonObject ingredients = JSONUtils.getJsonObject( json, "ingredients" );
|
||||
Ingredient middle = Ingredient.deserialize( ingredients.get( "middle" ) );
|
||||
Ingredient top = Ingredient.EMPTY;
|
||||
if( ingredients.has( "top" ) )
|
||||
{
|
||||
top = Ingredient.deserialize( ingredients.get( "top" ) );
|
||||
}
|
||||
Ingredient bottom = Ingredient.EMPTY;
|
||||
if( ingredients.has( "bottom" ) )
|
||||
{
|
||||
bottom = Ingredient.deserialize( ingredients.get( "bottom" ) );
|
||||
}
|
||||
|
||||
return new InscriberRecipe(recipeId, group, middle, result, top, bottom, mode);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public InscriberRecipe read(ResourceLocation recipeId, PacketBuffer buffer) {
|
||||
// FIXME NOT YET IMPLEMENTED
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buffer, InscriberRecipe recipe) {
|
||||
// FIXME NOT YET IMPLEMENTED
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,19 +19,10 @@
|
||||
package appeng.tile.grindstone;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.RangedWrapper;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.features.IGrinderRecipe;
|
||||
import appeng.api.implementations.tiles.ICrankable;
|
||||
import appeng.recipes.handlers.GrinderOptionalResult;
|
||||
import appeng.recipes.handlers.GrinderRecipe;
|
||||
import appeng.recipes.handlers.GrinderRecipes;
|
||||
import appeng.tile.AEBaseInvTile;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
@@ -40,10 +31,21 @@ import appeng.util.inv.AdaptorItemHandler;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.inv.WrapperFilteredItemHandler;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.RangedWrapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class TileGrinder extends AEBaseInvTile implements ICrankable
|
||||
{
|
||||
private static final int SLOT_PROCESSING = 6;
|
||||
|
||||
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 7 );
|
||||
private final IItemHandler invExt = new WrapperFilteredItemHandler( this.inv, new GrinderFilter() );
|
||||
private int points;
|
||||
@@ -96,24 +98,21 @@ public class TileGrinder extends AEBaseInvTile implements ICrankable
|
||||
continue;
|
||||
}
|
||||
|
||||
final IGrinderRecipe r = AEApi.instance().registries().grinder().getRecipeForInput( item );
|
||||
GrinderRecipe r = GrinderRecipes.findForInput(world, item);
|
||||
if( r != null )
|
||||
{
|
||||
if( item.getCount() >= r.getInput().getCount() )
|
||||
final ItemStack ais = item.copy();
|
||||
ais.setCount( r.getIngredientCount() );
|
||||
item.shrink( r.getIngredientCount() );
|
||||
|
||||
if( item.getCount() <= 0 )
|
||||
{
|
||||
final ItemStack ais = item.copy();
|
||||
ais.setCount( r.getInput().getCount() );
|
||||
item.shrink( r.getInput().getCount() );
|
||||
|
||||
if( item.getCount() <= 0 )
|
||||
{
|
||||
item = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
this.inv.setStackInSlot( x, item );
|
||||
this.inv.setStackInSlot( 6, ais );
|
||||
return true;
|
||||
item = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
this.inv.setStackInSlot( x, item );
|
||||
this.inv.setStackInSlot( 6, ais );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -131,11 +130,11 @@ public class TileGrinder extends AEBaseInvTile implements ICrankable
|
||||
|
||||
this.points++;
|
||||
|
||||
final ItemStack processing = this.inv.getStackInSlot( 6 );
|
||||
final IGrinderRecipe r = AEApi.instance().registries().grinder().getRecipeForInput( processing );
|
||||
final ItemStack processing = this.inv.getStackInSlot(SLOT_PROCESSING);
|
||||
GrinderRecipe r = GrinderRecipes.findForInput(world, processing);
|
||||
if( r != null )
|
||||
{
|
||||
if( r.getRequiredTurns() > this.points )
|
||||
if( r.getTurns() > this.points )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -143,27 +142,16 @@ public class TileGrinder extends AEBaseInvTile implements ICrankable
|
||||
this.points = 0;
|
||||
final InventoryAdaptor sia = new AdaptorItemHandler( new RangedWrapper( this.inv, 3, 6 ) );
|
||||
|
||||
this.addItem( sia, r.getOutput() );
|
||||
this.addItem( sia, r.getRecipeOutput());
|
||||
|
||||
r.getOptionalOutput().ifPresent( itemStack ->
|
||||
{
|
||||
for (GrinderOptionalResult optionalResult : r.getOptionalResults()) {
|
||||
final float chance = ( Platform.getRandomInt() % 2000 ) / 2000.0f;
|
||||
|
||||
if( chance <= r.getOptionalChance() )
|
||||
if( chance <= optionalResult.getChance() )
|
||||
{
|
||||
this.addItem( sia, itemStack );
|
||||
this.addItem( sia, optionalResult.getResult() );
|
||||
}
|
||||
} );
|
||||
|
||||
r.getSecondOptionalOutput().ifPresent( itemStack ->
|
||||
{
|
||||
final float chance = ( Platform.getRandomInt() % 2000 ) / 2000.0f;
|
||||
|
||||
if( chance <= r.getSecondOptionalChance() )
|
||||
{
|
||||
this.addItem( sia, itemStack );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
this.inv.setStackInSlot( 6, ItemStack.EMPTY );
|
||||
}
|
||||
@@ -203,7 +191,7 @@ public class TileGrinder extends AEBaseInvTile implements ICrankable
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slotIndex, ItemStack stack )
|
||||
{
|
||||
if( AEApi.instance().registries().grinder().getRecipeForInput( stack ) == null )
|
||||
if( !GrinderRecipes.isValidIngredient(world, stack) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user