Made the api usefull

This commit is contained in:
modmuss50 2016-04-03 14:25:46 +01:00
parent b44cdd4064
commit 7e7fcf2ad9
18 changed files with 162 additions and 133 deletions

View file

@ -4,26 +4,26 @@ import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.common.util.EnumHelper;
import techreborn.lib.ModInfo;
/**
* This contains some static stuff used in recipes and other things
*/
//TODO move this out of the api, and make it nicer
public class Reference {
public static ToolMaterial BRONZE = EnumHelper.addToolMaterial("BRONZE", 2, 375, 6.0F, 2.25F, 8);
public static ArmorMaterial BRONZE_ARMOUR = EnumHelper.addArmorMaterial("BRONZE", ModInfo.MOD_ID + ":bronze", 17,
public static ArmorMaterial BRONZE_ARMOUR = EnumHelper.addArmorMaterial("BRONZE", "techreborn:bronze", 17,
new int[]{3, 6, 5, 2}, 8, null/* TODO: SoundEvent */);
public static ToolMaterial RUBY = EnumHelper.addToolMaterial("RUBY", 2, 320, 6.2F, 2.7F, 10);
public static ArmorMaterial RUBY_ARMOUR = EnumHelper.addArmorMaterial("RUBY", ModInfo.MOD_ID + ":ruby", 16,
public static ArmorMaterial RUBY_ARMOUR = EnumHelper.addArmorMaterial("RUBY", "techreborn:ruby", 16,
new int[]{2, 7, 5, 2}, 10, null/* TODO: SoundEvent */);
public static ToolMaterial SAPPHIRE = EnumHelper.addToolMaterial("SAPPHIRE", 2, 620, 5.0F, 2F, 8);
public static ArmorMaterial SAPPHIRE_ARMOUR = EnumHelper.addArmorMaterial("SAPPHIRE", ModInfo.MOD_ID + ":sapphire",
public static ArmorMaterial SAPPHIRE_ARMOUR = EnumHelper.addArmorMaterial("SAPPHIRE", "techreborn:sapphire",
19, new int[]{4, 4, 4, 4}, 8, null/* TODO: SoundEvent */);
public static ToolMaterial PERIDOT = EnumHelper.addToolMaterial("PERIDOT", 2, 400, 7.0F, 2.4F, 16);
public static ArmorMaterial PERIDOT_ARMOUR = EnumHelper.addArmorMaterial("PERIDOT", ModInfo.MOD_ID + ":peridot", 17,
public static ArmorMaterial PERIDOT_ARMOUR = EnumHelper.addArmorMaterial("PERIDOT", "techreborn:peridot", 17,
new int[]{3, 8, 3, 2}, 16, null/* TODO: SoundEvent */);
public static String alloySmelteRecipe = I18n.translateToLocal("techreborn.recipe.alloysmelter");

View file

@ -3,7 +3,7 @@ package techreborn.api.gui;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import techreborn.api.upgrade.IMachineUpgrade;
import techreborn.utils.upgrade.IMachineUpgrade;
public class SlotUpgrade extends Slot {

View file

@ -62,11 +62,17 @@ public abstract class BaseRecipe implements IBaseRecipeType, Cloneable {
@Override
public boolean canCraft(TileEntity tile) {
if(tile instanceof ITileRecipeHandler){
return ((ITileRecipeHandler) tile).canCraft(tile, this);
}
return true;
}
@Override
public boolean onCraft(TileEntity tile) {
if(tile instanceof ITileRecipeHandler){
return ((ITileRecipeHandler) tile).onCraft(tile, this);
}
return true;
}

View file

@ -0,0 +1,12 @@
package techreborn.api.recipe;
import net.minecraft.tileentity.TileEntity;
/**
* Created by Mark on 03/04/2016.
*/
public interface ITileRecipeHandler<T extends BaseRecipe> {
boolean canCraft(TileEntity tile, T recipe);
boolean onCraft(TileEntity tile, T recipe);
}

View file

@ -2,7 +2,7 @@ package techreborn.api.recipe;
import net.minecraft.item.ItemStack;
import techreborn.api.Reference;
import techreborn.items.ItemParts;
import techreborn.api.TechRebornAPI;
//THIS is only here to trick JEI into showing recipes for the recycler
public class RecyclerRecipe extends BaseRecipe {
@ -10,7 +10,7 @@ public class RecyclerRecipe extends BaseRecipe {
public RecyclerRecipe(ItemStack input) {
super(Reference.recyclerRecipe, 0, 0);
inputs.add(input);
addOutput(ItemParts.getPartByName("scrap"));
addOutput(TechRebornAPI.subItemRetriever.getPartByName("scrap"));
}
@Override

View file

@ -4,7 +4,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import techreborn.api.Reference;
import techreborn.api.recipe.BaseRecipe;
import techreborn.tiles.TileBlastFurnace;
public class BlastFurnaceRecipe extends BaseRecipe {
@ -29,18 +28,4 @@ public class BlastFurnaceRecipe extends BaseRecipe {
public String getUserFreindlyName() {
return "Blast Furnace";
}
@Override
public boolean canCraft(TileEntity tile) {
if (tile instanceof TileBlastFurnace) {
TileBlastFurnace blastFurnace = (TileBlastFurnace) tile;
return blastFurnace.getHeat() >= neededHeat;
}
return false;
}
@Override
public boolean onCraft(TileEntity tile) {
return super.onCraft(tile);
}
}

View file

@ -5,7 +5,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidStack;
import techreborn.api.Reference;
import techreborn.api.recipe.BaseRecipe;
import techreborn.tiles.TileIndustrialGrinder;
public class IndustrialGrinderRecipe extends BaseRecipe {
@ -33,48 +32,4 @@ public class IndustrialGrinderRecipe extends BaseRecipe {
public String getUserFreindlyName() {
return "IndustrialGrinder";
}
@Override
public boolean canCraft(TileEntity tile) {
if (fluidStack == null) {
return true;
}
if (tile instanceof TileIndustrialGrinder) {
TileIndustrialGrinder grinder = (TileIndustrialGrinder) tile;
if (grinder.tank.getFluid() == null) {
return false;
}
if (grinder.tank.getFluid() == fluidStack) {
if (grinder.tank.getFluidAmount() >= fluidStack.amount) {
return true;
}
}
}
return false;
}
@Override
public boolean onCraft(TileEntity tile) {
if (fluidStack == null) {
return true;
}
if (tile instanceof TileIndustrialGrinder) {
TileIndustrialGrinder grinder = (TileIndustrialGrinder) tile;
if (grinder.tank.getFluid() == null) {
return false;
}
if (grinder.tank.getFluid() == fluidStack) {
if (grinder.tank.getFluidAmount() >= fluidStack.amount) {
if (grinder.tank.getFluidAmount() > 0) {
grinder.tank.setFluid(new FluidStack(fluidStack.getFluid(),
grinder.tank.getFluidAmount() - fluidStack.amount));
} else {
grinder.tank.setFluid(null);
}
return true;
}
}
}
return false;
}
}

View file

@ -5,7 +5,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidStack;
import techreborn.api.Reference;
import techreborn.api.recipe.BaseRecipe;
import techreborn.tiles.TileIndustrialSawmill;
public class IndustrialSawmillRecipe extends BaseRecipe {
@ -51,50 +50,6 @@ public class IndustrialSawmillRecipe extends BaseRecipe {
return "Industrial Sawmill";
}
@Override
public boolean canCraft(TileEntity tile) {
if (fluidStack == null) {
return true;
}
if (tile instanceof TileIndustrialSawmill) {
TileIndustrialSawmill sawmill = (TileIndustrialSawmill) tile;
if (sawmill.tank.getFluid() == null) {
return false;
}
if (sawmill.tank.getFluid() == fluidStack) {
if (sawmill.tank.getFluidAmount() >= fluidStack.amount) {
return true;
}
}
}
return false;
}
@Override
public boolean onCraft(TileEntity tile) {
if (fluidStack == null) {
return true;
}
if (tile instanceof TileIndustrialSawmill) {
TileIndustrialSawmill sawmill = (TileIndustrialSawmill) tile;
if (sawmill.tank.getFluid() == null) {
return false;
}
if (sawmill.tank.getFluid() == fluidStack) {
if (sawmill.tank.getFluidAmount() >= fluidStack.amount) {
if (sawmill.tank.getFluidAmount() > 0) {
sawmill.tank.setFluid(new FluidStack(fluidStack.getFluid(),
sawmill.tank.getFluidAmount() - fluidStack.amount));
} else {
sawmill.tank.setFluid(null);
}
return true;
}
}
}
return false;
}
@Override
public boolean useOreDic() {
return canUseOreDict;

View file

@ -4,7 +4,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import techreborn.api.Reference;
import techreborn.api.recipe.BaseRecipe;
import techreborn.tiles.TileVacuumFreezer;
public class VacuumFreezerRecipe extends BaseRecipe {
@ -20,14 +19,4 @@ public class VacuumFreezerRecipe extends BaseRecipe {
public String getUserFreindlyName() {
return "Vacuum Freezer";
}
@Override
public boolean canCraft(TileEntity tile) {
if (tile instanceof TileVacuumFreezer) {
if (((TileVacuumFreezer) tile).multiBlockStatus == 1) {
return true;
}
}
return false;
}
}

View file

@ -10,7 +10,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting;
import techreborn.utils.RecipeCrafter;
import techreborn.api.upgrade.IMachineUpgrade;
import techreborn.utils.upgrade.IMachineUpgrade;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.init.ModItems;

View file

@ -11,7 +11,7 @@ import reborncore.api.power.EnumPowerTier;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import techreborn.utils.RecipeCrafter;
import techreborn.api.upgrade.UpgradeHandler;
import techreborn.utils.upgrade.UpgradeHandler;
import techreborn.init.ModBlocks;
import techreborn.api.Reference;
import ic2.api.tile.IWrenchable;

View file

@ -17,6 +17,8 @@ import reborncore.common.misc.Location;
import reborncore.common.multiblock.IMultiblockPart;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import techreborn.api.recipe.ITileRecipeHandler;
import techreborn.api.recipe.machines.BlastFurnaceRecipe;
import techreborn.utils.RecipeCrafter;
import techreborn.blocks.BlockMachineCasing;
import techreborn.config.ConfigTechReborn;
@ -25,7 +27,7 @@ import techreborn.api.Reference;
import techreborn.multiblocks.MultiBlockCasing;
import ic2.api.tile.IWrenchable;
public class TileBlastFurnace extends TilePowerAcceptor implements IWrenchable, IInventory, ISidedInventory
public class TileBlastFurnace extends TilePowerAcceptor implements IWrenchable, IInventory, ISidedInventory, ITileRecipeHandler<BlastFurnaceRecipe>
{
public static int euTick = 5;
@ -336,4 +338,18 @@ public class TileBlastFurnace extends TilePowerAcceptor implements IWrenchable,
{
return inventory.getDisplayName();
}
@Override
public boolean canCraft(TileEntity tile, BlastFurnaceRecipe recipe) {
if (tile instanceof TileBlastFurnace) {
TileBlastFurnace blastFurnace = (TileBlastFurnace) tile;
return blastFurnace.getHeat() >= recipe.neededHeat;
}
return false;
}
@Override
public boolean onCraft(TileEntity tile, BlastFurnaceRecipe recipe) {
return true;
}
}

View file

@ -19,6 +19,9 @@ import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.FluidUtils;
import reborncore.common.util.Inventory;
import reborncore.common.util.Tank;
import techreborn.api.recipe.BaseRecipe;
import techreborn.api.recipe.ITileRecipeHandler;
import techreborn.api.recipe.machines.IndustrialGrinderRecipe;
import techreborn.utils.RecipeCrafter;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
@ -27,7 +30,7 @@ import techreborn.api.Reference;
import ic2.api.tile.IWrenchable;
public class TileIndustrialGrinder extends TilePowerAcceptor
implements IWrenchable, IFluidHandler, IInventory, ISidedInventory
implements IWrenchable, IFluidHandler, IInventory, ISidedInventory, ITileRecipeHandler<IndustrialGrinderRecipe>
{
public static final int TANK_CAPACITY = 16000;
@ -378,4 +381,49 @@ public class TileIndustrialGrinder extends TilePowerAcceptor
{
return EnumPowerTier.LOW;
}
@Override
public boolean canCraft(TileEntity tile, IndustrialGrinderRecipe recipe) {
if (recipe.fluidStack == null) {
return true;
}
if (tile instanceof TileIndustrialGrinder) {
TileIndustrialGrinder grinder = (TileIndustrialGrinder) tile;
if (grinder.tank.getFluid() == null) {
return false;
}
if (grinder.tank.getFluid() == recipe.fluidStack) {
if (grinder.tank.getFluidAmount() >= recipe.fluidStack.amount) {
return true;
}
}
}
return false;
}
@Override
public boolean onCraft(TileEntity tile, IndustrialGrinderRecipe recipe) {
if (recipe.fluidStack == null) {
return true;
}
if (tile instanceof TileIndustrialGrinder) {
TileIndustrialGrinder grinder = (TileIndustrialGrinder) tile;
if (grinder.tank.getFluid() == null) {
return false;
}
if (grinder.tank.getFluid() == recipe.fluidStack) {
if (grinder.tank.getFluidAmount() >= recipe.fluidStack.amount) {
if (grinder.tank.getFluidAmount() > 0) {
grinder.tank.setFluid(new FluidStack(recipe.fluidStack.getFluid(),
grinder.tank.getFluidAmount() - recipe.fluidStack.amount));
} else {
grinder.tank.setFluid(null);
}
return true;
}
}
}
return false;
}
}

View file

@ -21,6 +21,8 @@ import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.FluidUtils;
import reborncore.common.util.Inventory;
import reborncore.common.util.Tank;
import techreborn.api.recipe.ITileRecipeHandler;
import techreborn.api.recipe.machines.IndustrialSawmillRecipe;
import techreborn.utils.RecipeCrafter;
import techreborn.blocks.BlockMachineCasing;
import techreborn.init.ModBlocks;
@ -29,7 +31,7 @@ import techreborn.api.Reference;
import ic2.api.tile.IWrenchable;
public class TileIndustrialSawmill extends TilePowerAcceptor
implements IWrenchable, IFluidHandler, IInventory, ISidedInventory, IListInfoProvider
implements IWrenchable, IFluidHandler, IInventory, ISidedInventory, IListInfoProvider, ITileRecipeHandler<IndustrialSawmillRecipe>
{
public static final int TANK_CAPACITY = 16000;
@ -373,4 +375,48 @@ public class TileIndustrialSawmill extends TilePowerAcceptor
{
return EnumPowerTier.LOW;
}
@Override
public boolean canCraft(TileEntity tile, IndustrialSawmillRecipe recipe) {
if (recipe.fluidStack == null) {
return true;
}
if (tile instanceof TileIndustrialSawmill) {
TileIndustrialSawmill sawmill = (TileIndustrialSawmill) tile;
if (sawmill.tank.getFluid() == null) {
return false;
}
if (sawmill.tank.getFluid() == recipe.fluidStack) {
if (sawmill.tank.getFluidAmount() >= recipe.fluidStack.amount) {
return true;
}
}
}
return false;
}
@Override
public boolean onCraft(TileEntity tile, IndustrialSawmillRecipe recipe) {
if (recipe.fluidStack == null) {
return true;
}
if (tile instanceof TileIndustrialSawmill) {
TileIndustrialSawmill sawmill = (TileIndustrialSawmill) tile;
if (sawmill.tank.getFluid() == null) {
return false;
}
if (sawmill.tank.getFluid() == recipe.fluidStack) {
if (sawmill.tank.getFluidAmount() >= recipe.fluidStack.amount) {
if (sawmill.tank.getFluidAmount() > 0) {
sawmill.tank.setFluid(new FluidStack(recipe.fluidStack.getFluid(),
sawmill.tank.getFluidAmount() - recipe.fluidStack.amount));
} else {
sawmill.tank.setFluid(null);
}
return true;
}
}
}
return false;
}
}

View file

@ -5,19 +5,22 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import reborncore.api.power.EnumPowerTier;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import techreborn.api.recipe.ITileRecipeHandler;
import techreborn.api.recipe.machines.VacuumFreezerRecipe;
import techreborn.utils.RecipeCrafter;
import techreborn.blocks.BlockMachineCasing;
import techreborn.init.ModBlocks;
import techreborn.api.Reference;
import ic2.api.tile.IWrenchable;
public class TileVacuumFreezer extends TilePowerAcceptor implements IWrenchable, IInventory
public class TileVacuumFreezer extends TilePowerAcceptor implements IWrenchable, IInventory, ITileRecipeHandler<VacuumFreezerRecipe>
{
public int tickTime;
@ -289,4 +292,18 @@ public class TileVacuumFreezer extends TilePowerAcceptor implements IWrenchable,
return true;
}
@Override
public boolean canCraft(TileEntity tile, VacuumFreezerRecipe recipe) {
if (tile instanceof TileVacuumFreezer) {
if (((TileVacuumFreezer) tile).multiBlockStatus == 1) {
return true;
}
}
return false;
}
@Override
public boolean onCraft(TileEntity tile, VacuumFreezerRecipe recipe) {
return true;
}
}

View file

@ -1,4 +1,4 @@
package techreborn.api.upgrade;
package techreborn.utils.upgrade;
import net.minecraft.item.ItemStack;
import techreborn.utils.RecipeCrafter;

View file

@ -1,4 +1,4 @@
package techreborn.api.upgrade;
package techreborn.utils.upgrade;
import net.minecraft.item.ItemStack;
import reborncore.common.util.Inventory;

View file

@ -1,4 +1,4 @@
@API(apiVersion = "@MODVERSION@", owner = "techreborn", provides = "techrebornAPI")
package techreborn.api.upgrade;
package techreborn.utils.upgrade;
import net.minecraftforge.fml.common.API;