use of net.minecraft.item.crafting.ICraftingRecipe in project BluePower by Qmunity.
the class TileAutoProjectTable method removeItem.
@Override
public ItemStack removeItem(int slot, int amount) {
if (slot == OUTPUT_SLOT) {
InventoryProjectTableCrafting craftingInv = new InventoryProjectTableCrafting(null, this, 3, 3);
ItemStack itemstack = ItemStack.EMPTY;
Optional<ICraftingRecipe> optional = level.getServer().getRecipeManager().getRecipeFor(IRecipeType.CRAFTING, craftingInv, level);
if (optional.isPresent()) {
ICraftingRecipe icraftingrecipe = optional.get();
itemstack = icraftingrecipe.assemble(craftingInv);
}
for (int i = 0; i < 9; i++) {
ItemStack slotStack = craftingGrid.get(i);
if (slotStack.getCount() == 1) {
// Get items from the Inventory to Craft
for (int ptSlot = 0; ptSlot < 19; ++ptSlot) {
if (ptSlot == 18) {
// No available items so end here to keep template
return ItemStack.EMPTY;
}
ItemStack ptStack = getItem(ptSlot);
if (ptStack.getItem() == slotStack.getItem() && ptStack.getTag() == slotStack.getTag()) {
slotStack.setCount(2);
craftingGrid.set(i, slotStack);
removeItem(ptSlot, 1);
break;
}
}
}
}
for (int i = 0; i < 9; i++) {
ItemStack currentItem = craftingGrid.get(i);
currentItem.setCount(currentItem.getCount() - 1);
craftingGrid.set(i, currentItem);
}
return itemstack;
} else {
return super.removeItem(slot, amount);
}
}
use of net.minecraft.item.crafting.ICraftingRecipe in project BluePower by Qmunity.
the class ContainerProjectTable method updateCrafting.
protected static void updateCrafting(int id, World world, PlayerEntity playerEntity, CraftingInventory craftingInventory, CraftResultInventory craftResultInventory) {
if (!world.isClientSide) {
ServerPlayerEntity serverplayerentity = (ServerPlayerEntity) playerEntity;
ItemStack itemstack = ItemStack.EMPTY;
Optional<ICraftingRecipe> optional = world.getServer().getRecipeManager().getRecipeFor(IRecipeType.CRAFTING, craftingInventory, world);
if (optional.isPresent()) {
ICraftingRecipe icraftingrecipe = optional.get();
if (craftResultInventory.setRecipeUsed(world, serverplayerentity, icraftingrecipe)) {
itemstack = icraftingrecipe.assemble(craftingInventory);
}
}
craftResultInventory.setItem(0, itemstack);
serverplayerentity.connection.send(new SSetSlotPacket(id, 0, itemstack));
}
}
use of net.minecraft.item.crafting.ICraftingRecipe in project BluePower by Qmunity.
the class TileAutoProjectTable method getItem.
@Override
public ItemStack getItem(int i) {
if (i == OUTPUT_SLOT) {
InventoryProjectTableCrafting craftingInv = new InventoryProjectTableCrafting(null, this, 3, 3);
ItemStack itemstack = ItemStack.EMPTY;
Optional<ICraftingRecipe> optional = level.getServer().getRecipeManager().getRecipeFor(IRecipeType.CRAFTING, craftingInv, level);
if (optional.isPresent()) {
ICraftingRecipe icraftingrecipe = optional.get();
itemstack = icraftingrecipe.assemble(craftingInv);
}
return itemstack;
} else {
return super.getItem(i);
}
}
Aggregations