2022-11-18 20:08:58 +01:00
|
|
|
package net.anvilcraft.classiccasting.container;
|
|
|
|
|
|
|
|
import cpw.mods.fml.common.FMLCommonHandler;
|
|
|
|
import dev.tilera.auracore.api.crafting.IInfusionRecipe;
|
2022-11-21 10:23:30 +01:00
|
|
|
import dev.tilera.auracore.crafting.AuracoreCraftingManager;
|
2022-11-18 20:08:58 +01:00
|
|
|
import net.anvilcraft.classiccasting.WandManager;
|
|
|
|
import net.anvilcraft.classiccasting.tiles.TileInfusionWorkbench;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.inventory.SlotCrafting;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
|
|
|
import thaumcraft.api.aspects.Aspect;
|
|
|
|
import thaumcraft.api.aspects.AspectList;
|
|
|
|
import thaumcraft.api.aspects.IAspectSource;
|
2022-11-21 10:23:30 +01:00
|
|
|
import thaumcraft.api.crafting.IArcaneRecipe;
|
|
|
|
import thaumcraft.common.tiles.TileMagicWorkbench;
|
2022-11-18 20:08:58 +01:00
|
|
|
|
|
|
|
public class SlotCraftingInfusionWorkbench extends SlotCrafting {
|
|
|
|
private final IInventory craftMatrix;
|
|
|
|
private EntityPlayer thePlayer;
|
|
|
|
|
|
|
|
public SlotCraftingInfusionWorkbench(
|
|
|
|
final EntityPlayer par1EntityPlayer,
|
|
|
|
final IInventory par2IInventory,
|
|
|
|
final IInventory par3IInventory,
|
|
|
|
final int par4,
|
|
|
|
final int par5,
|
|
|
|
final int par6
|
|
|
|
) {
|
|
|
|
super(par1EntityPlayer, par2IInventory, par3IInventory, par4, par5, par6);
|
|
|
|
this.thePlayer = par1EntityPlayer;
|
|
|
|
this.craftMatrix = par2IInventory;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void
|
|
|
|
onPickupFromSlot(final EntityPlayer par1EntityPlayer, final ItemStack par1ItemStack) {
|
|
|
|
FMLCommonHandler.instance().firePlayerCraftingEvent(
|
|
|
|
this.thePlayer, par1ItemStack, this.craftMatrix
|
|
|
|
);
|
|
|
|
this.onCrafting(par1ItemStack);
|
|
|
|
int cost;
|
2022-11-21 10:23:30 +01:00
|
|
|
TileMagicWorkbench bridge = AuracoreCraftingManager.createBridgeInventory(this.craftMatrix, 0, 9);
|
|
|
|
IArcaneRecipe recipe = AuracoreCraftingManager.findMatchingArcaneRecipe(bridge, this.thePlayer);
|
|
|
|
cost = AuracoreCraftingManager.getArcaneRecipeVisCost(recipe, bridge);
|
|
|
|
if (cost == 0) {
|
2023-01-08 16:43:34 +01:00
|
|
|
IInfusionRecipe rec = AuracoreCraftingManager.findMatchingInfusionRecipe(
|
|
|
|
bridge, this.thePlayer
|
2022-11-18 20:08:58 +01:00
|
|
|
);
|
|
|
|
if (rec != null) {
|
|
|
|
cost = rec.getCost();
|
|
|
|
final AspectList tags = rec.getAspects();
|
|
|
|
if (tags != null && tags.size() > 0) {
|
|
|
|
final TileInfusionWorkbench tiwb
|
|
|
|
= (TileInfusionWorkbench) this.craftMatrix;
|
|
|
|
for (final Aspect tag : tags.getAspects()) {
|
|
|
|
final IAspectSource as = tiwb.foundAspects.getSource(tag);
|
|
|
|
if (as != null) {
|
|
|
|
as.takeFromContainer(tag, tags.getAmount(tag));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-21 10:23:30 +01:00
|
|
|
if (cost > 0) {
|
|
|
|
WandManager.spendCharge(this.craftMatrix.getStackInSlot(10), par1EntityPlayer, cost);
|
|
|
|
}
|
2022-11-18 20:08:58 +01:00
|
|
|
for (int var2 = 0; var2 < 9; ++var2) {
|
|
|
|
final ItemStack var3 = this.craftMatrix.getStackInSlot(var2);
|
|
|
|
if (var3 != null) {
|
|
|
|
this.craftMatrix.decrStackSize(var2, 1);
|
|
|
|
if (var3.getItem().hasContainerItem(var3)) {
|
|
|
|
ItemStack var4 = var3.getItem().getContainerItem(var3);
|
|
|
|
if (var4.isItemStackDamageable()
|
|
|
|
&& var4.getItemDamage() > var4.getMaxDamage()) {
|
|
|
|
MinecraftForge.EVENT_BUS.post(
|
|
|
|
new PlayerDestroyItemEvent(this.thePlayer, var4)
|
|
|
|
);
|
|
|
|
var4 = null;
|
|
|
|
}
|
|
|
|
if (var4 != null
|
|
|
|
&& (!var3.getItem().doesContainerItemLeaveCraftingGrid(var3)
|
|
|
|
|| !this.thePlayer.inventory.addItemStackToInventory(var4))) {
|
|
|
|
if (this.craftMatrix.getStackInSlot(var2) == null) {
|
|
|
|
this.craftMatrix.setInventorySlotContents(var2, var4);
|
|
|
|
} else {
|
|
|
|
this.thePlayer.entityDropItem(var4, 1.5f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|