It crafts to a point
This commit is contained in:
parent
752751319a
commit
86c3e99666
5 changed files with 104 additions and 12 deletions
|
@ -1,10 +1,14 @@
|
|||
package techreborn.api.recipe;
|
||||
|
||||
import ic2.api.energy.prefab.BasicSink;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import techreborn.tiles.TileMachineBase;
|
||||
import techreborn.util.Inventory;
|
||||
import techreborn.util.ItemUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Use this in your tile entity to craft things
|
||||
*/
|
||||
|
@ -52,6 +56,7 @@ public class RecipeCrafter {
|
|||
|
||||
/**
|
||||
* This is the constructor, not a lot to say here :P
|
||||
*
|
||||
* @param recipeName
|
||||
* @param parentTile
|
||||
* @param energy
|
||||
|
@ -79,38 +84,98 @@ public class RecipeCrafter {
|
|||
/**
|
||||
* Call this on the tile tick
|
||||
*/
|
||||
public void updateEntity(){
|
||||
if(currentRecipe == null){
|
||||
for(IBaseRecipeType recipe : RecipeHanderer.getRecipeClassFromName(recipeName)){
|
||||
public void updateEntity() {
|
||||
if (parentTile.getWorldObj().isRemote) {
|
||||
return;
|
||||
}
|
||||
if (currentRecipe == null) {
|
||||
for (IBaseRecipeType recipe : RecipeHanderer.getRecipeClassFromName(recipeName)) {
|
||||
boolean isFullRecipe = false;
|
||||
for (int i = 0; i < inputs; i++) {
|
||||
if(ItemUtils.isItemEqual(inventory.getStackInSlot(inputSlots[i]), recipe.getInputs().get(i), true, true)){
|
||||
if (ItemUtils.isItemEqual(inventory.getStackInSlot(inputSlots[i]), recipe.getInputs().get(i), true, true)) {
|
||||
isFullRecipe = true;
|
||||
} else {
|
||||
isFullRecipe = false;
|
||||
}
|
||||
}
|
||||
if(isFullRecipe){
|
||||
if (isFullRecipe) {
|
||||
currentRecipe = recipe;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < inputs; i++) {
|
||||
if(!ItemUtils.isItemEqual(inventory.getStackInSlot(inputSlots[i]), currentRecipe.getInputs().get(i), true, true)){
|
||||
if (!ItemUtils.isItemEqual(inventory.getStackInSlot(inputSlots[i]), currentRecipe.getInputs().get(i), true, true)) {
|
||||
currentRecipe = null;
|
||||
currentTickTime = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(currentTickTime >= currentRecipe.tickTime()){
|
||||
//TODO give the player the goodies :)
|
||||
//Need some nicer way of added the crafting things.
|
||||
} else {
|
||||
if(energy.useEnergy(currentRecipe.euPerTick())){
|
||||
currentTickTime ++;
|
||||
if (currentTickTime >= currentRecipe.tickTime()) {
|
||||
boolean canGiveInvAll = true;
|
||||
for (int i = 0; i < currentRecipe.getOutputs().size(); i++) {
|
||||
if (!canFitStack(currentRecipe.getOutputs().get(i), outputSlots[i])) {
|
||||
canGiveInvAll = false;
|
||||
}
|
||||
}
|
||||
ArrayList<Integer> filledSlots = new ArrayList<Integer>();
|
||||
if (canGiveInvAll) {
|
||||
for (int i = 0; i < currentRecipe.getOutputs().size(); i++) {
|
||||
if (!filledSlots.contains(outputSlots[i])) {
|
||||
fitStack(currentRecipe.getOutputs().get(i), outputSlots[i]);
|
||||
filledSlots.add(outputSlots[i]);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < inputs; i++) {
|
||||
if (!filledSlots.contains(inputSlots[i])) {
|
||||
inventory.decrStackSize(inputSlots[i], currentRecipe.getInputs().get(i).stackSize);
|
||||
}
|
||||
}
|
||||
currentRecipe = null;
|
||||
currentTickTime = 0;
|
||||
parentTile.syncWithAll();
|
||||
}
|
||||
} else if (currentTickTime < currentRecipe.tickTime()) {
|
||||
if (energy.useEnergy(currentRecipe.euPerTick())) {
|
||||
currentTickTime++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canFitStack(ItemStack stack, int slot) {
|
||||
if (stack == null) {
|
||||
return true;
|
||||
}
|
||||
if (inventory.getStackInSlot(slot) == null) {
|
||||
return true;
|
||||
}
|
||||
if (ItemUtils.isItemEqual(inventory.getStackInSlot(slot), stack, true, true)) {
|
||||
if (stack.stackSize + inventory.getStackInSlot(slot).stackSize <= stack.getMaxStackSize()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void fitStack(ItemStack stack, int slot) {
|
||||
if (stack == null) {
|
||||
return;
|
||||
}
|
||||
if (inventory.getStackInSlot(slot) == null) {
|
||||
inventory.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
if (ItemUtils.isItemEqual(inventory.getStackInSlot(slot), stack, true, true)) {
|
||||
if (stack.stackSize + inventory.getStackInSlot(slot).stackSize <= stack.getMaxStackSize()) {
|
||||
inventory.decrStackSize(slot, -stack.stackSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound tagCompound) {
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound tagCompound) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -265,12 +265,14 @@ public class TileBlastFurnace extends TileMachineBase implements IWrenchable, II
|
|||
super.readFromNBT(tagCompound);
|
||||
inventory.readFromNBT(tagCompound);
|
||||
tickTime = tagCompound.getInteger("tickTime");
|
||||
energy.readFromNBT(tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tagCompound) {
|
||||
super.writeToNBT(tagCompound);
|
||||
inventory.writeToNBT(tagCompound);
|
||||
energy.writeToNBT(tagCompound);
|
||||
writeUpdateToNBT(tagCompound);
|
||||
}
|
||||
|
||||
|
|
|
@ -255,6 +255,7 @@ public class TileCentrifuge extends TileMachineBase implements IInventory,
|
|||
{
|
||||
super.readFromNBT(tagCompound);
|
||||
inventory.readFromNBT(tagCompound);
|
||||
energy.readFromNBT(tagCompound);
|
||||
String recipeName = tagCompound.getString("recipe");
|
||||
for (CentrifugeRecipie recipie : TechRebornAPI.centrifugeRecipies)
|
||||
{
|
||||
|
@ -274,6 +275,7 @@ public class TileCentrifuge extends TileMachineBase implements IInventory,
|
|||
{
|
||||
super.writeToNBT(tagCompound);
|
||||
inventory.writeToNBT(tagCompound);
|
||||
energy.writeToNBT(tagCompound);
|
||||
writeUpdateToNBT(tagCompound);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,9 @@ package techreborn.tiles;
|
|||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import techreborn.api.CentrifugeRecipie;
|
||||
import techreborn.api.TechRebornAPI;
|
||||
import techreborn.api.recipe.RecipeCrafter;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.util.Inventory;
|
||||
|
@ -66,5 +69,23 @@ public class TileImplosionCompressor extends TileMachineBase implements IWrencha
|
|||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
crafter.updateEntity();
|
||||
energy.updateEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tagCompound)
|
||||
{
|
||||
super.readFromNBT(tagCompound);
|
||||
inventory.readFromNBT(tagCompound);
|
||||
energy.readFromNBT(tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tagCompound)
|
||||
{
|
||||
super.writeToNBT(tagCompound);
|
||||
inventory.writeToNBT(tagCompound);
|
||||
energy.writeToNBT(tagCompound);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -166,6 +166,7 @@ public class TileRollingMachine extends TileMachineBase implements IWrenchable {
|
|||
{
|
||||
super.readFromNBT(tagCompound);
|
||||
inventory.readFromNBT(tagCompound);
|
||||
energy.readFromNBT(tagCompound);
|
||||
ItemUtils.readInvFromNBT(craftMatrix, "Crafting", tagCompound);
|
||||
isRunning = tagCompound.getBoolean("isRunning");
|
||||
tickTime = tagCompound.getInteger("tickTime");
|
||||
|
@ -176,6 +177,7 @@ public class TileRollingMachine extends TileMachineBase implements IWrenchable {
|
|||
{
|
||||
super.writeToNBT(tagCompound);
|
||||
inventory.writeToNBT(tagCompound);
|
||||
energy.writeToNBT(tagCompound);
|
||||
ItemUtils.writeInvToNBT(craftMatrix, "Crafting", tagCompound);
|
||||
writeUpdateToNBT(tagCompound);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue