Some minor fixes to the auto crafting table
This commit is contained in:
parent
ba99f70406
commit
bee8d4aab0
1 changed files with 40 additions and 33 deletions
|
@ -60,7 +60,7 @@ public class TileAutoCraftingTable extends TilePowerAcceptor implements IContain
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
super.update();
|
super.update();
|
||||||
if(world.isRemote){
|
if (world.isRemote) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
IRecipe recipe = getIRecipe();
|
IRecipe recipe = getIRecipe();
|
||||||
|
@ -92,15 +92,15 @@ public class TileAutoCraftingTable extends TilePowerAcceptor implements IContain
|
||||||
boolean foundIngredient = false;
|
boolean foundIngredient = false;
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < 9; i++) {
|
||||||
ItemStack stack = inventory.getStackInSlot(i);
|
ItemStack stack = inventory.getStackInSlot(i);
|
||||||
if(stacksInSlots[i] > 0){
|
if (stacksInSlots[i] > 0) {
|
||||||
if (ingredient.apply(stack)) {
|
if (ingredient.apply(stack)) {
|
||||||
foundIngredient = true;
|
foundIngredient = true;
|
||||||
stacksInSlots[i] --;
|
stacksInSlots[i]--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!foundIngredient){
|
if (!foundIngredient) {
|
||||||
missingOutput = true;
|
missingOutput = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ public class TileAutoCraftingTable extends TilePowerAcceptor implements IContain
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (ItemUtils.isItemEqual(stack, output, true, true)) {
|
if (ItemUtils.isItemEqual(stack, output, true, true)) {
|
||||||
if (stack.getMaxStackSize() < stack.getCount() + output.getCount()) {
|
if (stack.getMaxStackSize() > stack.getCount() + output.getCount()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,12 +130,19 @@ public class TileAutoCraftingTable extends TilePowerAcceptor implements IContain
|
||||||
|
|
||||||
public boolean make(IRecipe recipe) {
|
public boolean make(IRecipe recipe) {
|
||||||
if (canMake(recipe)) {
|
if (canMake(recipe)) {
|
||||||
for (Ingredient ingredient : recipe.getIngredients()) {
|
for (int i = 0; i < recipe.getIngredients().size(); i++) {
|
||||||
for (int i = 0; i < 9; i++) {
|
Ingredient ingredient = recipe.getIngredients().get(i);
|
||||||
ItemStack stack = inventory.getStackInSlot(i);
|
//Looks for the best slot to take it from
|
||||||
if (ingredient.apply(stack)) {
|
ItemStack bestSlot = inventory.getStackInSlot(i);
|
||||||
stack.shrink(1); //TODO is this right? or do I need to use it as an actull crafting grid
|
if (ingredient.apply(bestSlot)) {
|
||||||
break;
|
bestSlot.shrink(1);
|
||||||
|
} else {
|
||||||
|
for (int j = 0; j < 9; j++) {
|
||||||
|
ItemStack stack = inventory.getStackInSlot(j);
|
||||||
|
if (ingredient.apply(stack)) {
|
||||||
|
stack.shrink(1); //TODO is this right? or do I need to use it as an actull crafting grid
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,7 +157,7 @@ public class TileAutoCraftingTable extends TilePowerAcceptor implements IContain
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasIngredient(Ingredient ingredient){
|
public boolean hasIngredient(Ingredient ingredient) {
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < 9; i++) {
|
||||||
ItemStack stack = inventory.getStackInSlot(i);
|
ItemStack stack = inventory.getStackInSlot(i);
|
||||||
if (ingredient.apply(stack)) {
|
if (ingredient.apply(stack)) {
|
||||||
|
@ -196,7 +203,7 @@ public class TileAutoCraftingTable extends TilePowerAcceptor implements IContain
|
||||||
.slot(0, 28, 25).slot(1, 46, 25).slot(2, 64, 25)
|
.slot(0, 28, 25).slot(1, 46, 25).slot(2, 64, 25)
|
||||||
.slot(3, 28, 43).slot(4, 46, 43).slot(5, 64, 43)
|
.slot(3, 28, 43).slot(4, 46, 43).slot(5, 64, 43)
|
||||||
.slot(6, 28, 61).slot(7, 46, 61).slot(8, 64, 61)
|
.slot(6, 28, 61).slot(7, 46, 61).slot(8, 64, 61)
|
||||||
.outputSlot(9, 145, 42)
|
.outputSlot(9, 145, 42).syncEnergyValue()
|
||||||
.syncIntegerValue(this::getProgress, this::setProgress)
|
.syncIntegerValue(this::getProgress, this::setProgress)
|
||||||
.syncIntegerValue(this::getMaxProgress, this::setMaxProgress)
|
.syncIntegerValue(this::getMaxProgress, this::setMaxProgress)
|
||||||
.addInventory().create();
|
.addInventory().create();
|
||||||
|
@ -233,7 +240,7 @@ public class TileAutoCraftingTable extends TilePowerAcceptor implements IContain
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
||||||
if(currentRecipe != null){
|
if (currentRecipe != null) {
|
||||||
tag.setString("currentRecipe", currentRecipe.toString());
|
tag.setString("currentRecipe", currentRecipe.toString());
|
||||||
}
|
}
|
||||||
return super.writeToNBT(tag);
|
return super.writeToNBT(tag);
|
||||||
|
@ -241,36 +248,36 @@ public class TileAutoCraftingTable extends TilePowerAcceptor implements IContain
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound tag) {
|
public void readFromNBT(NBTTagCompound tag) {
|
||||||
if(tag.hasKey("currentRecipe")){
|
if (tag.hasKey("currentRecipe")) {
|
||||||
currentRecipe = new ResourceLocation(tag.getString("currentRecipe"));
|
currentRecipe = new ResourceLocation(tag.getString("currentRecipe"));
|
||||||
}
|
}
|
||||||
super.readFromNBT(tag);
|
super.readFromNBT(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isItemValidForRecipeSlot(IRecipe recipe, ItemStack stack, int slotID){
|
public boolean isItemValidForRecipeSlot(IRecipe recipe, ItemStack stack, int slotID) {
|
||||||
if(recipe == null){
|
if (recipe == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
int bestSlot = findBestSlotForStack(recipe, stack);
|
int bestSlot = findBestSlotForStack(recipe, stack);
|
||||||
if(bestSlot != -1){
|
if (bestSlot != -1) {
|
||||||
return bestSlot == slotID;
|
return bestSlot == slotID;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int findBestSlotForStack(IRecipe recipe, ItemStack stack){
|
public int findBestSlotForStack(IRecipe recipe, ItemStack stack) {
|
||||||
if(recipe == null){
|
if (recipe == null) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
List<Integer> possibleSlots = new ArrayList<>();
|
List<Integer> possibleSlots = new ArrayList<>();
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < 9; i++) {
|
||||||
ItemStack stackInSlot = inventory.getStackInSlot(i);
|
ItemStack stackInSlot = inventory.getStackInSlot(i);
|
||||||
Ingredient ingredient = recipe.getIngredients().get(i);
|
Ingredient ingredient = recipe.getIngredients().get(i);
|
||||||
if(ingredient != Ingredient.EMPTY && ingredient.apply(stack)){
|
if (ingredient != Ingredient.EMPTY && ingredient.apply(stack)) {
|
||||||
if(stackInSlot.isEmpty()){
|
if (stackInSlot.isEmpty()) {
|
||||||
possibleSlots.add(i);
|
possibleSlots.add(i);
|
||||||
} else if (stackInSlot.getItem() == stack.getItem() && stackInSlot.getItemDamage() == stack.getItemDamage()){
|
} else if (stackInSlot.getItem() == stack.getItem() && stackInSlot.getItemDamage() == stack.getItemDamage()) {
|
||||||
if(stackInSlot.getMaxStackSize() >= stackInSlot.getCount() + stack.getCount()){
|
if (stackInSlot.getMaxStackSize() >= stackInSlot.getCount() + stack.getCount()) {
|
||||||
possibleSlots.add(i);
|
possibleSlots.add(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -278,18 +285,18 @@ public class TileAutoCraftingTable extends TilePowerAcceptor implements IContain
|
||||||
}
|
}
|
||||||
//Slot, count
|
//Slot, count
|
||||||
Pair<Integer, Integer> smallestCount = null;
|
Pair<Integer, Integer> smallestCount = null;
|
||||||
for(Integer slot : possibleSlots){
|
for (Integer slot : possibleSlots) {
|
||||||
ItemStack slotStack = inventory.getStackInSlot(slot);
|
ItemStack slotStack = inventory.getStackInSlot(slot);
|
||||||
if(slotStack.isEmpty()){
|
if (slotStack.isEmpty()) {
|
||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
if(smallestCount == null){
|
if (smallestCount == null) {
|
||||||
smallestCount = Pair.of(slot, slotStack.getCount());
|
smallestCount = Pair.of(slot, slotStack.getCount());
|
||||||
} else if(smallestCount.getRight() >= slotStack.getCount()){
|
} else if (smallestCount.getRight() >= slotStack.getCount()) {
|
||||||
smallestCount = Pair.of(slot, slotStack.getCount());
|
smallestCount = Pair.of(slot, slotStack.getCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(smallestCount != null){
|
if (smallestCount != null) {
|
||||||
return smallestCount.getLeft();
|
return smallestCount.getLeft();
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -298,7 +305,7 @@ public class TileAutoCraftingTable extends TilePowerAcceptor implements IContain
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValidForSlot(int index, ItemStack stack) {
|
public boolean isItemValidForSlot(int index, ItemStack stack) {
|
||||||
int bestSlot = findBestSlotForStack(getIRecipe(), stack);
|
int bestSlot = findBestSlotForStack(getIRecipe(), stack);
|
||||||
if(bestSlot != -1){
|
if (bestSlot != -1) {
|
||||||
return index == bestSlot;
|
return index == bestSlot;
|
||||||
}
|
}
|
||||||
return super.isItemValidForSlot(index, stack);
|
return super.isItemValidForSlot(index, stack);
|
||||||
|
@ -306,11 +313,11 @@ public class TileAutoCraftingTable extends TilePowerAcceptor implements IContain
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction) {
|
public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction) {
|
||||||
if(index == 9){
|
if (index == 9) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int bestSlot = findBestSlotForStack(getIRecipe(), itemStackIn);
|
int bestSlot = findBestSlotForStack(getIRecipe(), itemStackIn);
|
||||||
if(bestSlot != -1){
|
if (bestSlot != -1) {
|
||||||
return index == bestSlot;
|
return index == bestSlot;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -318,6 +325,6 @@ public class TileAutoCraftingTable extends TilePowerAcceptor implements IContain
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] getSlotsForFace(EnumFacing side) {
|
public int[] getSlotsForFace(EnumFacing side) {
|
||||||
return new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
return new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue