parent
8703856c11
commit
15f5392a62
1 changed files with 38 additions and 2 deletions
|
@ -27,6 +27,7 @@ package techreborn.blockentity.machine.tier1;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.inventory.CraftingInventory;
|
import net.minecraft.inventory.CraftingInventory;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.recipe.CraftingRecipe;
|
import net.minecraft.recipe.CraftingRecipe;
|
||||||
|
@ -71,6 +72,7 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
|
||||||
public RebornInventory<AutoCraftingTableBlockEntity> inventory = new RebornInventory<>(11, "AutoCraftingTableBlockEntity", 64, this);
|
public RebornInventory<AutoCraftingTableBlockEntity> inventory = new RebornInventory<>(11, "AutoCraftingTableBlockEntity", 64, this);
|
||||||
private final int OUTPUT_SLOT = 9;
|
private final int OUTPUT_SLOT = 9;
|
||||||
private final int EXTRA_OUTPUT_SLOT = 10;
|
private final int EXTRA_OUTPUT_SLOT = 10;
|
||||||
|
|
||||||
public int progress;
|
public int progress;
|
||||||
public int maxProgress = 120;
|
public int maxProgress = 120;
|
||||||
public int euTick = 10;
|
public int euTick = 10;
|
||||||
|
@ -79,7 +81,13 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
|
||||||
CraftingInventory inventoryCrafting = null;
|
CraftingInventory inventoryCrafting = null;
|
||||||
CraftingRecipe lastRecipe = null;
|
CraftingRecipe lastRecipe = null;
|
||||||
|
|
||||||
public boolean locked = true;
|
Item[] layoutInv = {
|
||||||
|
null, null, null,
|
||||||
|
null, null, null,
|
||||||
|
null, null, null,
|
||||||
|
};
|
||||||
|
|
||||||
|
public boolean locked = false;
|
||||||
|
|
||||||
public AutoCraftingTableBlockEntity(BlockPos pos, BlockState state) {
|
public AutoCraftingTableBlockEntity(BlockPos pos, BlockState state) {
|
||||||
super(TRBlockEntities.AUTO_CRAFTING_TABLE, pos, state);
|
super(TRBlockEntities.AUTO_CRAFTING_TABLE, pos, state);
|
||||||
|
@ -93,6 +101,11 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
|
||||||
|
|
||||||
if (lastRecipe != null && lastRecipe.matches(crafting, world)) return lastRecipe;
|
if (lastRecipe != null && lastRecipe.matches(crafting, world)) return lastRecipe;
|
||||||
|
|
||||||
|
Item[] currentInvLayout = getCraftingLayout(crafting);
|
||||||
|
if(Arrays.equals(layoutInv, currentInvLayout)) return null;
|
||||||
|
|
||||||
|
layoutInv = currentInvLayout;
|
||||||
|
|
||||||
Optional<CraftingRecipe> testRecipe = world.getRecipeManager().getFirstMatch(RecipeType.CRAFTING, crafting, world);
|
Optional<CraftingRecipe> testRecipe = world.getRecipeManager().getFirstMatch(RecipeType.CRAFTING, crafting, world);
|
||||||
if (testRecipe.isPresent()) {
|
if (testRecipe.isPresent()) {
|
||||||
lastRecipe = testRecipe.get();
|
lastRecipe = testRecipe.get();
|
||||||
|
@ -102,6 +115,20 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Item[] getCraftingLayout(CraftingInventory craftingInventory){
|
||||||
|
Item[] layout = {
|
||||||
|
null, null, null,
|
||||||
|
null, null, null,
|
||||||
|
null, null, null,
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < 9; i++) {
|
||||||
|
layout[i] = craftingInventory.getStack(i).getItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
return layout;
|
||||||
|
}
|
||||||
|
|
||||||
private CraftingInventory getCraftingInventory() {
|
private CraftingInventory getCraftingInventory() {
|
||||||
if (inventoryCrafting == null) {
|
if (inventoryCrafting == null) {
|
||||||
inventoryCrafting = new CraftingInventory(new ScreenHandler(null, -1) {
|
inventoryCrafting = new CraftingInventory(new ScreenHandler(null, -1) {
|
||||||
|
@ -125,11 +152,20 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
|
||||||
CraftingInventory crafting = getCraftingInventory();
|
CraftingInventory crafting = getCraftingInventory();
|
||||||
if (crafting.isEmpty()) return false;
|
if (crafting.isEmpty()) return false;
|
||||||
|
|
||||||
|
// Don't allow recipe to change (Keep at least one of each slot stocked, assuming it's actually a recipe)
|
||||||
|
if(locked){
|
||||||
|
for(int i = 0; i < 9; i++){
|
||||||
|
if(crafting.getStack(i).getCount() == 1){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!recipe.matches(crafting, world)) return false;
|
if (!recipe.matches(crafting, world)) return false;
|
||||||
|
|
||||||
if (!hasOutputSpace(recipe.getOutput(), OUTPUT_SLOT)) return false;
|
if (!hasOutputSpace(recipe.getOutput(), OUTPUT_SLOT)) return false;
|
||||||
|
|
||||||
DefaultedList<ItemStack> remainingStacks = world.getRecipeManager().getRemainingStacks(RecipeType.CRAFTING, crafting, world);
|
DefaultedList<ItemStack> remainingStacks = recipe.getRemainingStacks(crafting);
|
||||||
for (ItemStack stack : remainingStacks){
|
for (ItemStack stack : remainingStacks){
|
||||||
if (!stack.isEmpty() && !hasRoomForExtraItem(stack)) return false;
|
if (!stack.isEmpty() && !hasRoomForExtraItem(stack)) return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue