Solderer API package

This commit is contained in:
Raoul Van den Berge
2016-06-04 11:42:33 +02:00
parent d9ecbe8773
commit bd35cf873a
19 changed files with 330 additions and 263 deletions

View File

@@ -0,0 +1,24 @@
package refinedstorage.api.solderer;
import net.minecraft.item.ItemStack;
/**
* Represents a recipe in the solderer.
*/
public interface ISoldererRecipe {
/**
* @param row The solderer row (between 1 - 3)
* @return A stack for the given row, can be null for an empty row
*/
ItemStack getRow(int row);
/**
* @return The stack that this recipe gives back
*/
ItemStack getResult();
/**
* @return The duration in ticks
*/
int getDuration();
}

View File

@@ -1,20 +1,29 @@
package refinedstorage.tile.solderer;
package refinedstorage.api.solderer;
import net.minecraft.item.ItemStack;
/**
* A solderer recipe with basic behaviour
* Implement {@link refinedstorage.api.solderer.ISoldererRecipe} for custom behaviour
*/
public class SoldererRecipeBasic implements ISoldererRecipe {
private int duration;
private ItemStack result;
private ItemStack[] rows;
/**
* @param result The result that this recipe gives back
* @param duration The duration of this recipe
* @param rows The rows of this recipe, has to be 3 rows (null for an empty row)
*/
public SoldererRecipeBasic(ItemStack result, int duration, ItemStack... rows) {
this.duration = duration;
this.result = result;
this.rows = rows;
if (rows.length != 3) {
throw new IllegalArgumentException("Solderer recipe expects 3 rows, got " + rows.length + " rows");
}
this.duration = duration;
this.result = result;
this.rows = rows;
}
@Override

View File

@@ -1,39 +1,63 @@
package refinedstorage.tile.solderer;
import net.minecraftforge.items.IItemHandler;
import refinedstorage.RefinedStorageUtils;
import java.util.ArrayList;
import java.util.List;
public class SoldererRegistry {
public static List<ISoldererRecipe> recipes = new ArrayList<ISoldererRecipe>();
public static void addRecipe(ISoldererRecipe recipe) {
recipes.add(recipe);
}
public static ISoldererRecipe getRecipe(IItemHandler items) {
for (ISoldererRecipe recipe : recipes) {
boolean found = true;
for (int i = 0; i < 3; ++i) {
if (!RefinedStorageUtils.compareStackNoQuantity(recipe.getRow(i), items.getStackInSlot(i)) && !RefinedStorageUtils.compareStackOreDict(recipe.getRow(i), items.getStackInSlot(i))) {
found = false;
}
if (items.getStackInSlot(i) != null && recipe.getRow(i) != null) {
if (items.getStackInSlot(i).stackSize < recipe.getRow(i).stackSize) {
found = false;
}
}
}
if (found) {
return recipe;
}
}
return null;
}
}
package refinedstorage.api.solderer;
import com.google.common.collect.ImmutableList;
import net.minecraftforge.items.IItemHandler;
import refinedstorage.RefinedStorageUtils;
import java.util.ArrayList;
import java.util.List;
/**
* The recipe registry of the solderer.
*/
public class SoldererRegistry {
private static List<ISoldererRecipe> recipes = new ArrayList<ISoldererRecipe>();
/**
* Adds a recipe to the registry.
*
* @param recipe
*/
public static void addRecipe(ISoldererRecipe recipe) {
recipes.add(recipe);
}
/**
* @return An immutable recipe list
*/
public ImmutableList<ISoldererRecipe> getRecipes() {
return ImmutableList.copyOf(recipes);
}
/**
* @param items The item handler that has 3 slots
* @return The recipe
*/
public static ISoldererRecipe getRecipe(IItemHandler items) {
if (items.getSlots() != 3) {
throw new IllegalArgumentException("Expected a item handler with 3 slots, got " + items.getSlots() + " slots");
}
for (ISoldererRecipe recipe : recipes) {
boolean found = true;
for (int i = 0; i < 3; ++i) {
if (!RefinedStorageUtils.compareStackNoQuantity(recipe.getRow(i), items.getStackInSlot(i)) && !RefinedStorageUtils.compareStackOreDict(recipe.getRow(i), items.getStackInSlot(i))) {
found = false;
}
if (items.getStackInSlot(i) != null && recipe.getRow(i) != null) {
if (items.getStackInSlot(i).stackSize < recipe.getRow(i).stackSize) {
found = false;
}
}
}
if (found) {
return recipe;
}
}
return null;
}
}

View File

@@ -14,7 +14,7 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import refinedstorage.RefinedStorage;
import refinedstorage.RefinedStorageGui;
import refinedstorage.tile.solderer.TileSolderer;
import refinedstorage.tile.TileSolderer;
public class BlockSolderer extends BlockMachine {
public static final PropertyBool WORKING = PropertyBool.create("working");

View File

@@ -5,7 +5,7 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.SlotItemHandler;
import refinedstorage.container.slot.SlotOutput;
import refinedstorage.tile.solderer.TileSolderer;
import refinedstorage.tile.TileSolderer;
public class ContainerSolderer extends ContainerBase {
public ContainerSolderer(EntityPlayer player, TileSolderer solderer) {

View File

@@ -17,7 +17,6 @@ import refinedstorage.tile.autocrafting.TileProcessingPatternEncoder;
import refinedstorage.tile.controller.TileController;
import refinedstorage.tile.grid.TileGrid;
import refinedstorage.tile.grid.WirelessGrid;
import refinedstorage.tile.solderer.TileSolderer;
public class GuiHandler implements IGuiHandler {
private Container getContainer(int ID, EntityPlayer player, TileEntity tile) {

View File

@@ -2,7 +2,7 @@ package refinedstorage.gui;
import refinedstorage.container.ContainerSolderer;
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
import refinedstorage.tile.solderer.TileSolderer;
import refinedstorage.tile.TileSolderer;
public class GuiSolderer extends GuiBase {
private TileSolderer solderer;

View File

@@ -2,7 +2,7 @@ package refinedstorage.inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import refinedstorage.tile.solderer.TileSolderer;
import refinedstorage.tile.TileSolderer;
public class SoldererItemHandler extends ProxyItemHandler {
private TileSolderer solderer;

View File

@@ -1,8 +1,8 @@
package refinedstorage.jei;
import net.minecraft.item.ItemStack;
import refinedstorage.tile.solderer.ISoldererRecipe;
import refinedstorage.tile.solderer.SoldererRegistry;
import refinedstorage.api.solderer.ISoldererRecipe;
import refinedstorage.api.solderer.SoldererRegistry;
import java.util.ArrayList;
import java.util.List;

View File

@@ -16,6 +16,8 @@ import net.minecraftforge.oredict.ShapedOreRecipe;
import refinedstorage.RefinedStorage;
import refinedstorage.RefinedStorageBlocks;
import refinedstorage.RefinedStorageItems;
import refinedstorage.api.solderer.SoldererRecipeBasic;
import refinedstorage.api.solderer.SoldererRegistry;
import refinedstorage.block.BlockBase;
import refinedstorage.block.EnumControllerType;
import refinedstorage.block.EnumGridType;
@@ -23,6 +25,10 @@ import refinedstorage.block.EnumStorageType;
import refinedstorage.gui.GuiHandler;
import refinedstorage.item.*;
import refinedstorage.network.*;
import refinedstorage.solderer.SoldererRecipePrintedProcessor;
import refinedstorage.solderer.SoldererRecipeProcessor;
import refinedstorage.solderer.SoldererRecipeStorage;
import refinedstorage.solderer.SoldererRecipeUpgrade;
import refinedstorage.storage.NBTStorage;
import refinedstorage.tile.*;
import refinedstorage.tile.autocrafting.TileCrafter;
@@ -30,7 +36,6 @@ import refinedstorage.tile.autocrafting.TileCraftingMonitor;
import refinedstorage.tile.autocrafting.TileProcessingPatternEncoder;
import refinedstorage.tile.controller.TileController;
import refinedstorage.tile.grid.TileGrid;
import refinedstorage.tile.solderer.*;
import static refinedstorage.RefinedStorage.ID;

View File

@@ -0,0 +1,63 @@
package refinedstorage.solderer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import refinedstorage.RefinedStorageItems;
import refinedstorage.api.solderer.ISoldererRecipe;
import refinedstorage.item.ItemProcessor;
public class SoldererRecipePrintedProcessor implements ISoldererRecipe {
private int type;
private ItemStack requirement;
private ItemStack result;
public SoldererRecipePrintedProcessor(int type) {
this.type = type;
this.result = new ItemStack(RefinedStorageItems.PROCESSOR, 1, type);
switch (type) {
case ItemProcessor.TYPE_PRINTED_BASIC:
this.requirement = new ItemStack(Items.IRON_INGOT);
break;
case ItemProcessor.TYPE_PRINTED_IMPROVED:
this.requirement = new ItemStack(Items.GOLD_INGOT);
break;
case ItemProcessor.TYPE_PRINTED_ADVANCED:
this.requirement = new ItemStack(Items.DIAMOND);
break;
case ItemProcessor.TYPE_PRINTED_SILICON:
this.requirement = new ItemStack(RefinedStorageItems.SILICON);
break;
}
}
@Override
public ItemStack getRow(int row) {
if (row == 1) {
return requirement;
}
return null;
}
@Override
public ItemStack getResult() {
return result;
}
@Override
public int getDuration() {
switch (type) {
case ItemProcessor.TYPE_PRINTED_BASIC:
return 100;
case ItemProcessor.TYPE_PRINTED_IMPROVED:
return 150;
case ItemProcessor.TYPE_PRINTED_ADVANCED:
return 200;
case ItemProcessor.TYPE_PRINTED_SILICON:
return 90;
default:
return 0;
}
}
}

View File

@@ -0,0 +1,62 @@
package refinedstorage.solderer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import refinedstorage.RefinedStorageItems;
import refinedstorage.api.solderer.ISoldererRecipe;
import refinedstorage.item.ItemProcessor;
public class SoldererRecipeProcessor implements ISoldererRecipe {
private int type;
private ItemStack[] rows;
private ItemStack result;
public SoldererRecipeProcessor(int type) {
this.type = type;
ItemStack printedProcessor = null;
switch (type) {
case ItemProcessor.TYPE_BASIC:
printedProcessor = new ItemStack(RefinedStorageItems.PROCESSOR, 1, ItemProcessor.TYPE_PRINTED_BASIC);
break;
case ItemProcessor.TYPE_IMPROVED:
printedProcessor = new ItemStack(RefinedStorageItems.PROCESSOR, 1, ItemProcessor.TYPE_PRINTED_IMPROVED);
break;
case ItemProcessor.TYPE_ADVANCED:
printedProcessor = new ItemStack(RefinedStorageItems.PROCESSOR, 1, ItemProcessor.TYPE_PRINTED_ADVANCED);
break;
}
this.result = new ItemStack(RefinedStorageItems.PROCESSOR, 1, type);
this.rows = new ItemStack[]{
printedProcessor,
new ItemStack(Items.REDSTONE),
new ItemStack(RefinedStorageItems.PROCESSOR, 1, ItemProcessor.TYPE_PRINTED_SILICON)
};
}
@Override
public ItemStack getRow(int row) {
return rows[row];
}
@Override
public ItemStack getResult() {
return result;
}
@Override
public int getDuration() {
switch (type) {
case ItemProcessor.TYPE_BASIC:
return 250;
case ItemProcessor.TYPE_IMPROVED:
return 300;
case ItemProcessor.TYPE_ADVANCED:
return 350;
default:
return 0;
}
}
}

View File

@@ -1,41 +1,38 @@
package refinedstorage.tile.solderer;
import net.minecraft.item.ItemStack;
import refinedstorage.RefinedStorageBlocks;
import refinedstorage.RefinedStorageItems;
import refinedstorage.block.EnumStorageType;
import refinedstorage.item.ItemBlockStorage;
import refinedstorage.item.ItemProcessor;
public class SoldererRecipeStorage implements ISoldererRecipe {
private EnumStorageType type;
private int storagePart;
public SoldererRecipeStorage(EnumStorageType type, int storagePart) {
this.type = type;
this.storagePart = storagePart;
}
@Override
public ItemStack getRow(int row) {
if (row == 0) {
return new ItemStack(RefinedStorageItems.PROCESSOR, 1, ItemProcessor.TYPE_BASIC);
} else if (row == 1) {
return new ItemStack(RefinedStorageBlocks.MACHINE_CASING);
} else if (row == 2) {
return new ItemStack(RefinedStorageItems.STORAGE_PART, 1, storagePart);
}
return null;
}
@Override
public ItemStack getResult() {
return ItemBlockStorage.initNBT(new ItemStack(RefinedStorageBlocks.STORAGE, 1, type.getId()));
}
@Override
public int getDuration() {
return 200;
}
}
package refinedstorage.solderer;
import net.minecraft.item.ItemStack;
import refinedstorage.RefinedStorageBlocks;
import refinedstorage.RefinedStorageItems;
import refinedstorage.api.solderer.ISoldererRecipe;
import refinedstorage.block.EnumStorageType;
import refinedstorage.item.ItemBlockStorage;
import refinedstorage.item.ItemProcessor;
public class SoldererRecipeStorage implements ISoldererRecipe {
private EnumStorageType type;
private ItemStack[] rows;
public SoldererRecipeStorage(EnumStorageType type, int storagePart) {
this.type = type;
this.rows = new ItemStack[]{
new ItemStack(RefinedStorageItems.PROCESSOR, 1, ItemProcessor.TYPE_BASIC),
new ItemStack(RefinedStorageBlocks.MACHINE_CASING),
new ItemStack(RefinedStorageItems.STORAGE_PART, 1, storagePart)
};
}
@Override
public ItemStack getRow(int row) {
return rows[row];
}
@Override
public ItemStack getResult() {
return ItemBlockStorage.initNBT(new ItemStack(RefinedStorageBlocks.STORAGE, 1, type.getId()));
}
@Override
public int getDuration() {
return 200;
}
}

View File

@@ -0,0 +1,51 @@
package refinedstorage.solderer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import refinedstorage.RefinedStorageItems;
import refinedstorage.api.solderer.ISoldererRecipe;
import refinedstorage.item.ItemUpgrade;
public class SoldererRecipeUpgrade implements ISoldererRecipe {
private ItemStack[] rows;
private ItemStack result;
public SoldererRecipeUpgrade(int type) {
ItemStack requirement = null;
switch (type) {
case ItemUpgrade.TYPE_RANGE:
requirement = new ItemStack(Items.ENDER_PEARL);
break;
case ItemUpgrade.TYPE_SPEED:
requirement = new ItemStack(Items.SUGAR);
break;
case ItemUpgrade.TYPE_CRAFTING:
requirement = new ItemStack(Blocks.CRAFTING_TABLE);
break;
}
this.result = new ItemStack(RefinedStorageItems.UPGRADE, 1, type);
this.rows = new ItemStack[]{
requirement,
new ItemStack(RefinedStorageItems.UPGRADE, 1, 0),
requirement
};
}
@Override
public ItemStack getRow(int row) {
return rows[row];
}
@Override
public ItemStack getResult() {
return result;
}
@Override
public int getDuration() {
return 250;
}
}

View File

@@ -1,4 +1,4 @@
package refinedstorage.tile.solderer;
package refinedstorage.tile;
import io.netty.buffer.ByteBuf;
import net.minecraft.inventory.Container;
@@ -11,12 +11,13 @@ import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
import refinedstorage.RefinedStorageItems;
import refinedstorage.RefinedStorageUtils;
import refinedstorage.api.solderer.ISoldererRecipe;
import refinedstorage.api.solderer.SoldererRegistry;
import refinedstorage.container.ContainerSolderer;
import refinedstorage.inventory.BasicItemHandler;
import refinedstorage.inventory.BasicItemValidator;
import refinedstorage.inventory.SoldererItemHandler;
import refinedstorage.item.ItemUpgrade;
import refinedstorage.tile.TileMachine;
public class TileSolderer extends TileMachine {
public static final String NBT_WORKING = "Working";

View File

@@ -1,11 +0,0 @@
package refinedstorage.tile.solderer;
import net.minecraft.item.ItemStack;
public interface ISoldererRecipe {
ItemStack getRow(int row);
ItemStack getResult();
int getDuration();
}

View File

@@ -1,53 +0,0 @@
package refinedstorage.tile.solderer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import refinedstorage.RefinedStorageItems;
import refinedstorage.item.ItemProcessor;
public class SoldererRecipePrintedProcessor implements ISoldererRecipe {
private int type;
public SoldererRecipePrintedProcessor(int type) {
this.type = type;
}
@Override
public ItemStack getRow(int row) {
if (row == 1) {
switch (type) {
case ItemProcessor.TYPE_PRINTED_BASIC:
return new ItemStack(Items.IRON_INGOT);
case ItemProcessor.TYPE_PRINTED_IMPROVED:
return new ItemStack(Items.GOLD_INGOT);
case ItemProcessor.TYPE_PRINTED_ADVANCED:
return new ItemStack(Items.DIAMOND);
case ItemProcessor.TYPE_PRINTED_SILICON:
return new ItemStack(RefinedStorageItems.SILICON);
}
}
return null;
}
@Override
public ItemStack getResult() {
return new ItemStack(RefinedStorageItems.PROCESSOR, 1, type);
}
@Override
public int getDuration() {
switch (type) {
case ItemProcessor.TYPE_PRINTED_BASIC:
return 100;
case ItemProcessor.TYPE_PRINTED_IMPROVED:
return 150;
case ItemProcessor.TYPE_PRINTED_ADVANCED:
return 200;
case ItemProcessor.TYPE_PRINTED_SILICON:
return 90;
}
return 0;
}
}

View File

@@ -1,53 +0,0 @@
package refinedstorage.tile.solderer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import refinedstorage.RefinedStorageItems;
import refinedstorage.item.ItemProcessor;
public class SoldererRecipeProcessor implements ISoldererRecipe {
private int type;
public SoldererRecipeProcessor(int type) {
this.type = type;
}
@Override
public ItemStack getRow(int row) {
if (row == 0) {
switch (type) {
case ItemProcessor.TYPE_BASIC:
return new ItemStack(RefinedStorageItems.PROCESSOR, 1, ItemProcessor.TYPE_PRINTED_BASIC);
case ItemProcessor.TYPE_IMPROVED:
return new ItemStack(RefinedStorageItems.PROCESSOR, 1, ItemProcessor.TYPE_PRINTED_IMPROVED);
case ItemProcessor.TYPE_ADVANCED:
return new ItemStack(RefinedStorageItems.PROCESSOR, 1, ItemProcessor.TYPE_PRINTED_ADVANCED);
}
} else if (row == 1) {
return new ItemStack(Items.REDSTONE);
} else if (row == 2) {
return new ItemStack(RefinedStorageItems.PROCESSOR, 1, ItemProcessor.TYPE_PRINTED_SILICON);
}
return null;
}
@Override
public ItemStack getResult() {
return new ItemStack(RefinedStorageItems.PROCESSOR, 1, type);
}
@Override
public int getDuration() {
switch (type) {
case ItemProcessor.TYPE_BASIC:
return 250;
case ItemProcessor.TYPE_IMPROVED:
return 300;
case ItemProcessor.TYPE_ADVANCED:
return 350;
}
return 0;
}
}

View File

@@ -1,51 +0,0 @@
package refinedstorage.tile.solderer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import refinedstorage.RefinedStorageItems;
import refinedstorage.item.ItemUpgrade;
public class SoldererRecipeUpgrade implements ISoldererRecipe {
private int type;
public SoldererRecipeUpgrade(int type) {
this.type = type;
}
@Override
public ItemStack getRow(int row) {
if (row == 0) {
return getBottomAndTopItem();
} else if (row == 1) {
return new ItemStack(RefinedStorageItems.UPGRADE, 1, 0);
} else if (row == 2) {
return getBottomAndTopItem();
}
return null;
}
private ItemStack getBottomAndTopItem() {
switch (type) {
case ItemUpgrade.TYPE_RANGE:
return new ItemStack(Items.ENDER_PEARL);
case ItemUpgrade.TYPE_SPEED:
return new ItemStack(Items.SUGAR);
case ItemUpgrade.TYPE_CRAFTING:
return new ItemStack(Blocks.CRAFTING_TABLE);
}
return null;
}
@Override
public ItemStack getResult() {
return new ItemStack(RefinedStorageItems.UPGRADE, 1, type);
}
@Override
public int getDuration() {
return 250;
}
}