use of net.minecraft.inventory.SlotCrafting in project SpongeCommon by SpongePowered.
the class ContainerUtil method generateAdapterLens.
@Nullable
private static Lens<IInventory, ItemStack> generateAdapterLens(SlotProvider<IInventory, ItemStack> slots, int index, CraftingInventoryData crafting, List<Slot> slotList, @Nullable IInventory subInventory) {
if (!(subInventory instanceof InventoryAdapter)) {
return null;
}
Lens<IInventory, ItemStack> adapterLens = ((InventoryAdapter) subInventory).getRootLens();
if (adapterLens == null) {
return null;
}
if (subInventory.getSizeInventory() == 0) {
return new DefaultEmptyLens<>(((InventoryAdapter) subInventory));
}
if (adapterLens instanceof PlayerInventoryLens) {
if (slotList.size() == 36) {
return new DelegatingLens(index, new MainPlayerInventoryLensImpl(index, slots, true), slots);
}
return null;
}
// For Crafting Result we need the Slot to get Filter logic
if (subInventory instanceof InventoryCraftResult) {
Slot slot = slotList.get(0);
adapterLens = new CraftingOutputSlotLensImpl(index, item -> slot.isItemValid(((ItemStack) item)), itemType -> (slot.isItemValid((ItemStack) org.spongepowered.api.item.inventory.ItemStack.of(itemType, 1))));
crafting.out = index;
if (slot instanceof SlotCrafting) {
if (crafting.base == null) {
// In case we do not find the InventoryCrafting later assume it is directly after the SlotCrafting
// e.g. for IC2 ContainerIndustrialWorkbench
crafting.base = index + 1;
crafting.grid = ((SlotCrafting) slot).craftMatrix;
}
}
}
if (subInventory instanceof InventoryCrafting) {
crafting.base = index;
crafting.grid = ((InventoryCrafting) subInventory);
}
return new DelegatingLens(index, adapterLens, slots);
}
use of net.minecraft.inventory.SlotCrafting in project SpongeCommon by SpongePowered.
the class MixinContainer method redirectTransferStackInSlot.
@Redirect(method = "slotClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/Container;transferStackInSlot(Lnet/minecraft/entity/player/EntityPlayer;I)Lnet/minecraft/item/ItemStack;"))
private ItemStack redirectTransferStackInSlot(Container thisContainer, EntityPlayer player, int slotId) {
Slot slot = thisContainer.getSlot(slotId);
if (!(slot instanceof SlotCrafting)) {
return thisContainer.transferStackInSlot(player, slotId);
}
this.lastCraft = null;
this.shiftCraft = true;
ItemStack result = thisContainer.transferStackInSlot(player, slotId);
if (this.lastCraft != null) {
if (this.lastCraft.isCancelled()) {
// Return empty to stop shift-crafting
result = ItemStack.EMPTY;
}
}
this.shiftCraft = false;
return result;
}
use of net.minecraft.inventory.SlotCrafting in project ForestryMC by ForestryMC.
the class SlotUtil method transferStackInSlot.
public static ItemStack transferStackInSlot(List<Slot> inventorySlots, EntityPlayer player, int slotIndex) {
Slot slot = inventorySlots.get(slotIndex);
if (slot == null || !slot.getHasStack()) {
return ItemStack.EMPTY;
}
boolean fromCraftingSlot = slot instanceof SlotCrafting || slot instanceof SlotCrafter;
int numSlots = inventorySlots.size();
ItemStack stackInSlot = slot.getStack();
ItemStack originalStack = stackInSlot.copy();
if (!shiftItemStack(inventorySlots, stackInSlot, slotIndex, numSlots, fromCraftingSlot)) {
return ItemStack.EMPTY;
}
slot.onSlotChange(stackInSlot, originalStack);
if (stackInSlot.isEmpty()) {
slot.putStack(ItemStack.EMPTY);
} else {
slot.onSlotChanged();
}
if (stackInSlot.getCount() == originalStack.getCount()) {
return ItemStack.EMPTY;
}
slot.onTake(player, stackInSlot);
return originalStack;
}
use of net.minecraft.inventory.SlotCrafting in project Galacticraft by micdoodle8.
the class NEIController method handleSlotClick.
@Override
public boolean handleSlotClick(GuiContainer gui, int slotIndex, int button, Slot slot, int modifier, boolean eventconsumed) {
if (eventconsumed || !NEIClientConfig.isEnabled() || isSpreading(gui)) {
return eventconsumed;
}
if (deleteMode && slotIndex >= 0 && slot != null) {
if (NEIClientUtils.shiftKey() && button == 0) {
ItemStack itemstack1 = slot.getStack();
if (itemstack1 != null) {
NEIClientUtils.deleteItemsOfType(itemstack1);
}
} else if (button == 1) {
NEIClientUtils.decreaseSlotStack(slot.slotNumber);
} else {
NEIClientUtils.deleteSlotStack(slot.slotNumber);
}
return true;
}
if (// right click
button == 1 && slot instanceof SlotCrafting) {
for (// click this slot 64 times
int i1 = 0; // click this slot 64 times
i1 < 64; // click this slot 64 times
i1++) {
manager.handleSlotClick(slot.slotNumber, button, 0);
}
return true;
}
if (NEIClientUtils.controlKey() && slot != null && slot.getStack() != null && slot.isItemValid(slot.getStack())) {
NEIClientUtils.cheatItem(slot.getStack(), button, 1);
return true;
}
if (GuiInfo.hasCustomSlots(gui)) {
return false;
}
if (slotIndex >= 0 && NEIClientUtils.shiftKey() && NEIClientUtils.getHeldItem() != null && !slot.getHasStack()) {
ItemStack held = NEIClientUtils.getHeldItem();
manager.handleSlotClick(slot.slotNumber, button, 0);
if (slot.isItemValid(held) && !ItemInfo.fastTransferExemptions.contains(slot.getClass())) {
fastTransferManager.performMassTransfer(gui, pickedUpFromSlot, slotIndex, held);
}
return true;
}
if (slotIndex == -999 && NEIClientUtils.shiftKey() && button == 0) {
fastTransferManager.throwAll(gui, pickedUpFromSlot);
return true;
}
return false;
}
use of net.minecraft.inventory.SlotCrafting in project BuildCraft by BuildCraft.
the class TileAutoWorkbench method update.
@Override
public void update() {
super.update();
if (worldObj.isRemote) {
return;
}
if (scheduledCacheRebuild) {
craftMatrix.rebuildCache();
scheduledCacheRebuild = false;
}
if (craftMatrix.isJammed || craftMatrix.currentRecipe == null) {
progress = 0;
return;
}
if (craftSlot == null) {
craftSlot = new SlotCrafting(getInternalPlayer().get(), craftMatrix, craftResult, 0, 0, 0);
}
if (!hasWork) {
return;
}
int updateNext = update + getBattery().getEnergyStored() + 1;
int updateThreshold = (update & ~15) + 16;
update = Math.min(updateThreshold, updateNext);
if ((update % UPDATE_TIME) == 0) {
updateCrafting();
}
getBattery().setEnergy(0);
}
Aggregations