public class SlotToolStationOut extends Slot { public ContainerToolStation parent; public SlotToolStationOut(int index, int xPosition, int yPosition, ContainerToolStation container) { super(new InventoryCraftResult(), index, xPosition, yPosition); this.parent = container; } @Override public boolean isItemValid(ItemStack stack) { return false; } @Nonnull @Override public ItemStack onTake(EntityPlayer playerIn, @Nonnull ItemStack stack) { FMLCommonHandler.instance().firePlayerCraftingEvent(playerIn, stack, parent.getTile()); parent.onResultTaken(playerIn, stack); stack.onCrafting(playerIn.getEntityWorld(), playerIn, 1); return super.onTake(playerIn, stack); } }
if (this.amountCrafted > 0) { stack.onCrafting(this.player.world, this.player, this.amountCrafted); FMLCommonHandler.instance().firePlayerCraftingEvent(this.player, stack, craftMatrix);
FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) this.world ), this.details.getOutput( ic, this.world ), ic );
FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) world ), details.getOutput( ic, world ), ic );
.firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) this.getWorld() ), details.getOutput( ic, this.getWorld() ), ic );
@Override protected void onCrafting(@Nonnull ItemStack stack) { if (amountCrafted > 0) { stack.onCrafting(player.world, player, amountCrafted); net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent(player, stack, craftMatrix); } amountCrafted = 0; // InventoryCraftResult inventorycraftresult = (InventoryCraftResult)this.inventory; // IRecipe irecipe = inventorycraftresult.getRecipeUsed(); // // if (irecipe != null && !irecipe.isDynamic()) // { // this.player.unlockRecipes(Lists.newArrayList(irecipe)); // inventorycraftresult.setRecipeUsed((IRecipe)null); // } }
private void fireEventsAndHandleAchievements(EntityPlayer player, ItemStack result) { FMLCommonHandler.instance().firePlayerCraftingEvent(player, result, this); result.onCrafting(player.world, player, 1); }
@Override public ItemStack onTake( final EntityPlayer playerIn, final ItemStack stack ) net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent( playerIn, stack, new WrapperInvItemHandler( this.craftMatrix ) ); this.onCrafting( stack ); net.minecraftforge.common.ForgeHooks.setCraftingPlayer( playerIn );
/** * Copied from {@link SlotCrafting#onCrafting(ItemStack)} */ @Override protected void onCrafting(ItemStack stack) { if (this.amountCrafted > 0) { stack.onCrafting(this.player.world, this.player, this.amountCrafted); net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent(this.player, stack, craftMatrix); } this.amountCrafted = 0; IRecipe irecipe = crafter.getRecipeUsed(); if (irecipe != null && !irecipe.isDynamic()) { this.player.unlockRecipes(Lists.newArrayList(irecipe)); } }
public class SlotCraftingCustom extends SlotCrafting { private final InventoryCrafting craftMatrix; private final IContainerCraftingCustom callback; /** * @param callback Container that gets the crafting call on crafting * @param player Player that does the crafting * @param craftingInventory Inventory where the ingredients are taken from * @param craftResult Inventory where the result is put */ public SlotCraftingCustom(IContainerCraftingCustom callback, EntityPlayer player, InventoryCrafting craftingInventory, IInventory craftResult, int slotIndex, int xPosition, int yPosition) { super(player, craftingInventory, craftResult, slotIndex, xPosition, yPosition); this.craftMatrix = craftingInventory; this.callback = callback; } @Override @Nonnull public ItemStack onTake(EntityPlayer playerIn, @Nonnull ItemStack stack) { net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent(playerIn, stack, craftMatrix); this.onCrafting(stack); callback.onCrafting(playerIn, stack, craftMatrix); return stack; } }
@Override protected void onCrafting(ItemStack stack) { InventoryCraftResult inventorycraftresult = (InventoryCraftResult) inventory; IRecipe irecipe = inventorycraftresult.getRecipeUsed(); if (amountCrafted > 0) { stack.onCrafting(player.world, player, amountCrafted); if (irecipe != null) { FMLCommonHandler.instance().firePlayerCraftingEvent(player, stack, craftMatrix); } } amountCrafted = 0; if (irecipe != null && !irecipe.isDynamic()) { player.unlockRecipes(Lists.newArrayList(irecipe)); inventorycraftresult.setRecipeUsed(null); } }
if( !output.isEmpty() ) FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) this.getWorld() ), output, this.craftingInv );
@Override @Nonnull public ItemStack onTake(@Nonnull EntityPlayer playerIn, @Nonnull ItemStack stack) { net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent(playerIn, stack, craftMatrix); this.onCrafting(stack); net.minecraftforge.common.ForgeHooks.setCraftingPlayer(playerIn); NonNullList<ItemStack> containeritems = CraftingManager.getRemainingItems(craftMatrix, playerIn.world); net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null); for (int i = 0; i < containeritems.size(); ++i) { ItemStack itemstack = this.craftMatrix.getStackInSlot(i); ItemStack containeritemstack = containeritems.get(i); if (!itemstack.isEmpty()) { this.craftMatrix.decrStackSize(i, 1); } if (!containeritemstack.isEmpty()) { if (this.craftMatrix.getStackInSlot(i).isEmpty()) { this.craftMatrix.setInventorySlotContents(i, containeritemstack); } else { ItemStack remainder = ItemHandlerHelper .insertItem(inventory.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null), containeritemstack, false); if (!remainder.isEmpty()) { if (!playerIn.inventory.addItemStackToInventory(remainder)) { playerIn.dropItem(remainder, false); } } } } } return stack; }
public static void onCraftedShift(IGridNetworkAware grid, EntityPlayer player) { List<ItemStack> craftedItemsList = new ArrayList<>(); int craftedItems = 0; ItemStack crafted = grid.getCraftingResult().getStackInSlot(0); while (true) { grid.onCrafted(player); craftedItemsList.add(crafted.copy()); craftedItems += crafted.getCount(); if (!API.instance().getComparer().isEqual(crafted, grid.getCraftingResult().getStackInSlot(0)) || craftedItems + crafted.getCount() > crafted.getMaxStackSize()) { break; } } INetwork network = grid.getNetwork(); for (ItemStack craftedItem : craftedItemsList) { if (!player.inventory.addItemStackToInventory(craftedItem.copy())) { ItemStack remainder = network == null ? craftedItem : network.insertItem(craftedItem, craftedItem.getCount(), Action.PERFORM); if (remainder != null) { InventoryHelper.spawnItemStack(player.getEntityWorld(), player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), remainder); } } } FMLCommonHandler.instance().firePlayerCraftingEvent(player, ItemHandlerHelper.copyStackWithSize(crafted, craftedItems), grid.getCraftingMatrix()); }