use of net.minecraft.inventory.SlotCrafting in project LogisticsPipes by RS485.
the class LogisticsCraftingTableTileEntity method getOutput.
@Nonnull
public ItemStack getOutput(IResource wanted, IRoutedPowerProvider power) {
boolean isFuzzy = isFuzzy();
if (cache == null) {
cacheRecipe();
if (cache == null) {
return ItemStack.EMPTY;
}
}
int[] toUse = new int[9];
int[] used = new int[inv.getSizeInventory()];
outer: for (int i = 0; i < 9; i++) {
ItemIdentifierStack item = matrix.getIDStackInSlot(i);
if (item == null) {
toUse[i] = -1;
continue;
}
ItemIdentifier ident = item.getItem();
for (int j = 0; j < inv.getSizeInventory(); j++) {
item = inv.getIDStackInSlot(j);
if (item == null) {
continue;
}
final boolean doItemsEqual = isFuzzy ? (FuzzyUtil.INSTANCE.fuzzyMatches(FuzzyUtil.INSTANCE.getter(inputFuzzy(i)), ident, item.getItem())) : ident.equalsForCrafting(item.getItem());
if (doItemsEqual && item.getStackSize() > used[j]) {
used[j]++;
toUse[i] = j;
continue outer;
}
}
// Not enough material
return ItemStack.EMPTY;
}
AutoCraftingInventory crafter = new AutoCraftingInventory(placedBy);
for (int i = 0; i < 9; i++) {
int j = toUse[i];
if (j != -1) {
crafter.setInventorySlotContents(i, inv.getStackInSlot(j));
}
}
IRecipe recipe = cache;
final ItemIdentifierStack outStack = Objects.requireNonNull(resultInv.getIDStackInSlot(0));
if (!recipe.matches(crafter, getWorld())) {
if (isFuzzy && outputFuzzy().nextSetBit(0) != -1) {
recipe = null;
for (IRecipe r : CraftingUtil.getRecipeList()) {
if (r.matches(crafter, getWorld()) && FuzzyUtil.INSTANCE.fuzzyMatches(FuzzyUtil.INSTANCE.getter(outputFuzzy()), outStack.getItem(), ItemIdentifier.get(r.getRecipeOutput()))) {
recipe = r;
break;
}
}
if (recipe == null) {
return ItemStack.EMPTY;
}
} else {
// Fix MystCraft
return ItemStack.EMPTY;
}
}
ItemStack result = recipe.getCraftingResult(crafter);
if (result.isEmpty()) {
return ItemStack.EMPTY;
}
if (isFuzzy && outputFuzzy().nextSetBit(0) != -1) {
if (!FuzzyUtil.INSTANCE.fuzzyMatches(FuzzyUtil.INSTANCE.getter(outputFuzzy()), outStack.getItem(), ItemIdentifier.get(result))) {
return ItemStack.EMPTY;
}
if (!FuzzyUtil.INSTANCE.fuzzyMatches(FuzzyUtil.INSTANCE.getter(outputFuzzy()), wanted.getAsItem(), ItemIdentifier.get(result))) {
return ItemStack.EMPTY;
}
} else {
if (!outStack.getItem().equalsWithoutNBT(ItemIdentifier.get(result))) {
return ItemStack.EMPTY;
}
if (!wanted.matches(outStack.getItem(), IResource.MatchSettings.WITHOUT_NBT)) {
return ItemStack.EMPTY;
}
}
if (!power.useEnergy(Configs.LOGISTICS_CRAFTING_TABLE_POWER_USAGE)) {
return ItemStack.EMPTY;
}
crafter = new AutoCraftingInventory(placedBy);
for (int i = 0; i < 9; i++) {
int j = toUse[i];
if (j != -1) {
crafter.setInventorySlotContents(i, inv.decrStackSize(j, 1));
}
}
result = recipe.getCraftingResult(crafter);
if (fake == null) {
fake = MainProxy.getFakePlayer(this.world);
}
result = result.copy();
SlotCrafting craftingSlot = new SlotCrafting(fake, crafter, resultInv, 0, 0, 0) {
@Override
protected void onCrafting(@Nonnull ItemStack stack) {
IInventory tmp = this.inventory;
vanillaResult.setRecipeUsed(cache);
this.inventory = vanillaResult;
super.onCrafting(stack);
this.inventory = tmp;
}
};
result = craftingSlot.onTake(fake, result);
for (int i = 0; i < 9; i++) {
ItemStack left = crafter.getStackInSlot(i);
crafter.setInventorySlotContents(i, ItemStack.EMPTY);
if (!left.isEmpty()) {
left.setCount(inv.addCompressed(left, false));
if (left.getCount() > 0) {
ItemIdentifierInventory.dropItems(world, left, getPos());
}
}
}
for (int i = 0; i < fake.inventory.getSizeInventory(); i++) {
ItemStack left = fake.inventory.getStackInSlot(i);
fake.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
if (!left.isEmpty()) {
left.setCount(inv.addCompressed(left, false));
if (left.getCount() > 0) {
ItemIdentifierInventory.dropItems(world, left, getPos());
}
}
}
return result;
}
use of net.minecraft.inventory.SlotCrafting in project LogisticsPipes by RS485.
the class PipeBlockRequestTable method getOutput.
@Nonnull
public ItemStack getOutput(boolean oreDict) {
if (cache == null) {
cacheRecipe();
if (cache == null) {
return ItemStack.EMPTY;
}
}
if (resultInv.getIDStackInSlot(0) == null) {
return ItemStack.EMPTY;
}
int[] toUse = new int[9];
int[] used = new int[inv.getSizeInventory()];
outer: for (int i = 0; i < 9; i++) {
ItemStack item = matrix.getStackInSlot(i);
if (item.isEmpty()) {
toUse[i] = -1;
continue;
}
ItemIdentifier ident = ItemIdentifier.get(item);
for (int j = 0; j < inv.getSizeInventory(); j++) {
item = inv.getStackInSlot(j);
if (item.isEmpty()) {
continue;
}
ItemIdentifier withIdent = ItemIdentifier.get(item);
if (ident.equalsForCrafting(withIdent)) {
if (item.getCount() > used[j]) {
used[j]++;
toUse[i] = j;
continue outer;
}
}
if (oreDict) {
if (ident.getDictIdentifiers() != null && withIdent.getDictIdentifiers() != null && ident.getDictIdentifiers().canMatch(withIdent.getDictIdentifiers(), true, false)) {
if (item.getCount() > used[j]) {
used[j]++;
toUse[i] = j;
continue outer;
}
}
}
}
// Not enough material
return ItemStack.EMPTY;
}
// TODO
AutoCraftingInventory crafter = new AutoCraftingInventory(null);
for (int i = 0; i < 9; i++) {
int j = toUse[i];
if (j != -1) {
crafter.setInventorySlotContents(i, inv.getStackInSlot(j));
}
}
if (!cache.matches(crafter, getWorld())) {
// Fix MystCraft
return ItemStack.EMPTY;
}
ItemStack result = cache.getCraftingResult(crafter);
if (result.isEmpty()) {
return ItemStack.EMPTY;
}
if (!resultInv.getIDStackInSlot(0).getItem().equalsWithoutNBT(ItemIdentifier.get(result))) {
return ItemStack.EMPTY;
}
// TODO
crafter = new AutoCraftingInventory(null);
for (int i = 0; i < 9; i++) {
int j = toUse[i];
if (j != -1) {
crafter.setInventorySlotContents(i, inv.decrStackSize(j, 1));
}
}
result = cache.getCraftingResult(crafter);
if (fake == null) {
fake = MainProxy.getFakePlayer(getWorld());
}
result = result.copy();
SlotCrafting craftingSlot = new SlotCrafting(fake, crafter, resultInv, 0, 0, 0) {
@Override
protected void onCrafting(@Nonnull ItemStack stack) {
IInventory tmp = this.inventory;
vanillaResult.setRecipeUsed(cache);
this.inventory = vanillaResult;
super.onCrafting(stack);
this.inventory = tmp;
}
};
result = craftingSlot.onTake(fake, result);
for (int i = 0; i < 9; i++) {
ItemStack left = crafter.getStackInSlot(i);
crafter.setInventorySlotContents(i, ItemStack.EMPTY);
if (!left.isEmpty()) {
left.setCount(inv.addCompressed(left, false));
if (left.getCount() > 0) {
ItemIdentifierInventory.dropItems(getWorld(), left, getX(), getY(), getZ());
}
}
}
for (int i = 0; i < fake.inventory.getSizeInventory(); i++) {
ItemStack left = fake.inventory.getStackInSlot(i);
fake.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
if (!left.isEmpty()) {
left.setCount(inv.addCompressed(left, false));
if (left.getCount() > 0) {
ItemIdentifierInventory.dropItems(getWorld(), left, getX(), getY(), getZ());
}
}
}
return result;
}
use of net.minecraft.inventory.SlotCrafting in project SpongeCommon by SpongePowered.
the class MixinContainer method redirectOnTakeThrow.
@Redirect(method = "slotClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/Slot;onTake(Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;", ordinal = 5))
private ItemStack redirectOnTakeThrow(Slot slot, EntityPlayer player, ItemStack stackOnCursor) {
this.lastCraft = null;
ItemStack result = slot.onTake(player, stackOnCursor);
if (this.lastCraft != null) {
if (slot instanceof SlotCrafting) {
if (this.lastCraft.isCancelled()) {
// do not drop crafted item when cancelled
stackOnCursor.setCount(0);
}
}
}
return result;
}
use of net.minecraft.inventory.SlotCrafting in project BuildCraft by BuildCraft.
the class TileAdvancedCraftingTable method update.
@Override
public void update() {
super.update();
if (worldObj.isRemote) {
return;
}
if (internalInventoryCrafting == null) {
internalInventoryCrafting = new InternalInventoryCrafting();
craftSlot = new SlotCrafting(getInternalPlayer().get(), internalInventoryCrafting, craftResult, 0, 0, 0);
updateRecipe();
}
if (worldObj.isRemote) {
return;
}
updateRecipe();
searchNeighborsForIngredients();
locateAndBindIngredients();
updateRecipeOutputDisplay();
justCrafted = false;
if (canCraftAndOutput()) {
if (getEnergy() >= getRequiredEnergy()) {
craftItem();
justCrafted = true;
}
} else {
craftable = false;
internalInventoryCrafting.tempStacks = null;
internalInventoryCrafting.hitCount = null;
setEnergy(0);
}
}
Aggregations