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;
|
package techreborn.api.recipe;
|
||||||
|
|
||||||
import ic2.api.energy.prefab.BasicSink;
|
import ic2.api.energy.prefab.BasicSink;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import techreborn.tiles.TileMachineBase;
|
import techreborn.tiles.TileMachineBase;
|
||||||
import techreborn.util.Inventory;
|
import techreborn.util.Inventory;
|
||||||
import techreborn.util.ItemUtils;
|
import techreborn.util.ItemUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this in your tile entity to craft things
|
* 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
|
* This is the constructor, not a lot to say here :P
|
||||||
|
*
|
||||||
* @param recipeName
|
* @param recipeName
|
||||||
* @param parentTile
|
* @param parentTile
|
||||||
* @param energy
|
* @param energy
|
||||||
|
@ -79,38 +84,98 @@ public class RecipeCrafter {
|
||||||
/**
|
/**
|
||||||
* Call this on the tile tick
|
* Call this on the tile tick
|
||||||
*/
|
*/
|
||||||
public void updateEntity(){
|
public void updateEntity() {
|
||||||
if(currentRecipe == null){
|
if (parentTile.getWorldObj().isRemote) {
|
||||||
for(IBaseRecipeType recipe : RecipeHanderer.getRecipeClassFromName(recipeName)){
|
return;
|
||||||
|
}
|
||||||
|
if (currentRecipe == null) {
|
||||||
|
for (IBaseRecipeType recipe : RecipeHanderer.getRecipeClassFromName(recipeName)) {
|
||||||
boolean isFullRecipe = false;
|
boolean isFullRecipe = false;
|
||||||
for (int i = 0; i < inputs; i++) {
|
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;
|
isFullRecipe = true;
|
||||||
} else {
|
} else {
|
||||||
isFullRecipe = false;
|
isFullRecipe = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(isFullRecipe){
|
if (isFullRecipe) {
|
||||||
currentRecipe = recipe;
|
currentRecipe = recipe;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < inputs; i++) {
|
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;
|
currentRecipe = null;
|
||||||
currentTickTime = 0;
|
currentTickTime = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(currentTickTime >= currentRecipe.tickTime()){
|
if (currentTickTime >= currentRecipe.tickTime()) {
|
||||||
//TODO give the player the goodies :)
|
boolean canGiveInvAll = true;
|
||||||
//Need some nicer way of added the crafting things.
|
for (int i = 0; i < currentRecipe.getOutputs().size(); i++) {
|
||||||
} else {
|
if (!canFitStack(currentRecipe.getOutputs().get(i), outputSlots[i])) {
|
||||||
if(energy.useEnergy(currentRecipe.euPerTick())){
|
canGiveInvAll = false;
|
||||||
currentTickTime ++;
|
}
|
||||||
|
}
|
||||||
|
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);
|
super.readFromNBT(tagCompound);
|
||||||
inventory.readFromNBT(tagCompound);
|
inventory.readFromNBT(tagCompound);
|
||||||
tickTime = tagCompound.getInteger("tickTime");
|
tickTime = tagCompound.getInteger("tickTime");
|
||||||
|
energy.readFromNBT(tagCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound tagCompound) {
|
public void writeToNBT(NBTTagCompound tagCompound) {
|
||||||
super.writeToNBT(tagCompound);
|
super.writeToNBT(tagCompound);
|
||||||
inventory.writeToNBT(tagCompound);
|
inventory.writeToNBT(tagCompound);
|
||||||
|
energy.writeToNBT(tagCompound);
|
||||||
writeUpdateToNBT(tagCompound);
|
writeUpdateToNBT(tagCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -255,6 +255,7 @@ public class TileCentrifuge extends TileMachineBase implements IInventory,
|
||||||
{
|
{
|
||||||
super.readFromNBT(tagCompound);
|
super.readFromNBT(tagCompound);
|
||||||
inventory.readFromNBT(tagCompound);
|
inventory.readFromNBT(tagCompound);
|
||||||
|
energy.readFromNBT(tagCompound);
|
||||||
String recipeName = tagCompound.getString("recipe");
|
String recipeName = tagCompound.getString("recipe");
|
||||||
for (CentrifugeRecipie recipie : TechRebornAPI.centrifugeRecipies)
|
for (CentrifugeRecipie recipie : TechRebornAPI.centrifugeRecipies)
|
||||||
{
|
{
|
||||||
|
@ -274,6 +275,7 @@ public class TileCentrifuge extends TileMachineBase implements IInventory,
|
||||||
{
|
{
|
||||||
super.writeToNBT(tagCompound);
|
super.writeToNBT(tagCompound);
|
||||||
inventory.writeToNBT(tagCompound);
|
inventory.writeToNBT(tagCompound);
|
||||||
|
energy.writeToNBT(tagCompound);
|
||||||
writeUpdateToNBT(tagCompound);
|
writeUpdateToNBT(tagCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,9 @@ package techreborn.tiles;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
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.api.recipe.RecipeCrafter;
|
||||||
import techreborn.init.ModBlocks;
|
import techreborn.init.ModBlocks;
|
||||||
import techreborn.util.Inventory;
|
import techreborn.util.Inventory;
|
||||||
|
@ -66,5 +69,23 @@ public class TileImplosionCompressor extends TileMachineBase implements IWrencha
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
crafter.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);
|
super.readFromNBT(tagCompound);
|
||||||
inventory.readFromNBT(tagCompound);
|
inventory.readFromNBT(tagCompound);
|
||||||
|
energy.readFromNBT(tagCompound);
|
||||||
ItemUtils.readInvFromNBT(craftMatrix, "Crafting", tagCompound);
|
ItemUtils.readInvFromNBT(craftMatrix, "Crafting", tagCompound);
|
||||||
isRunning = tagCompound.getBoolean("isRunning");
|
isRunning = tagCompound.getBoolean("isRunning");
|
||||||
tickTime = tagCompound.getInteger("tickTime");
|
tickTime = tagCompound.getInteger("tickTime");
|
||||||
|
@ -176,6 +177,7 @@ public class TileRollingMachine extends TileMachineBase implements IWrenchable {
|
||||||
{
|
{
|
||||||
super.writeToNBT(tagCompound);
|
super.writeToNBT(tagCompound);
|
||||||
inventory.writeToNBT(tagCompound);
|
inventory.writeToNBT(tagCompound);
|
||||||
|
energy.writeToNBT(tagCompound);
|
||||||
ItemUtils.writeInvToNBT(craftMatrix, "Crafting", tagCompound);
|
ItemUtils.writeInvToNBT(craftMatrix, "Crafting", tagCompound);
|
||||||
writeUpdateToNBT(tagCompound);
|
writeUpdateToNBT(tagCompound);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue