• 0

    posted a message on Portable furnace

    I've found a way to do the job, but, i need an Event for interaction on inventory ... any idea how i can do that ? ( this is for switch my system to use only IItemHandler without IIventory for my crafting bench, and i think i can use that for the furnace that's why i need an event or .. a new listener ? to do the job )

    @SubscribeEvent
    	public void onCraftGridChange( PlayerContainerEvent.Open e ) {
    		Container c = e.getContainer();
    		EntityPlayer p = e.getEntityPlayer();
    		World w = p.world;
    		
    		if( c instanceof KitbagContainer && !w.isRemote ) {
    			NonNullList<ItemStack> stackList = NonNullList.<ItemStack>withSize( 9, ItemStack.EMPTY );
    			int id = 0;
    			for( int i = 105; i < 113; i++ ) {
    				stackList.set( id, c.getSlot( i ).getStack() );
    				id++;
    			}
    			    
    			EntityPlayerMP pmp = ( EntityPlayerMP ) p;
    			ItemStack is = simulateRecipes( c, stackList, w, pmp );
    			stackList.clear(); // Do not forget to clear ;)
    		}
    	}
    	
    	private ItemStack simulateRecipes( Container c, NonNullList<ItemStack> s, World w, EntityPlayerMP p ) {
    		ItemStack is = ItemStack.EMPTY;
    		if( !w.isRemote ) {
    			InventoryCrafting m = new InventoryCrafting( c, 3, 3 );
    			for( int i = 0; i < m.getSizeInventory(); i++ ) {
    				m.setInventorySlotContents( i, s.get( i ));
    			}
    			IRecipe ir = CraftingManager.findMatchingRecipe( m, w );
    			if( ir != null && ( ir.isDynamic() || !w.getGameRules().getBoolean( "doLimitedCrafting" ) || p.getRecipeBook().isUnlocked( ir ))) {
    				is = ir.getCraftingResult( m );
    			}
    			m.clear();
    			
    			c.getInventory().set( 104, is );
    			p.connection.sendPacket( new SPacketSetSlot( c.windowId, 104, is ));
    		}
    		return is;
    	}
    Posted in: Modification Development
  • 0

    posted a message on Error in Executing exec for :runClient in Eclipse (SOLVED)

    Try to put your modid lowercase only, if i'm right it's required

    Can you post your error log ?

    Posted in: Modification Development
  • 0

    posted a message on Portable furnace

    Sure but i can't, because forge do not support any more any version under 1.14.4 so they just block my thread ... that's why i'm here ^^

    Posted in: Modification Development
  • 0

    posted a message on Portable furnace

    Hello, i need help for a portable tool that include a workbench, an inventory and a furnace in the same Container / GUI.The workbench and inventory work fine, my problem is about the furnace because the furnace use IInventory ( workbench too but use it's own class instance ... ) where the inventory itself use IItemHandler. I already know i need to create my own slots and that's all fine, my question is, how to proceed next


    I mean :

    1: how to declare slot X as "fuel" slot

    2: how to register the fuel usage

    3: how to set the input and output slot


    That's my actual code : ( do not included my custom slot wich isn't required ... i just use them to define what kind of item i can put in )


    package com.kporal.mcplus;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.inventory.Container;
    import net.minecraft.inventory.IInventory;
    import net.minecraft.inventory.InventoryCraftResult;
    import net.minecraft.inventory.InventoryCrafting;
    import net.minecraft.inventory.Slot;
    import net.minecraft.inventory.SlotCrafting;
    import net.minecraft.inventory.SlotFurnaceFuel;
    import net.minecraft.inventory.SlotFurnaceOutput;
    import net.minecraft.item.ItemStack;
    import net.minecraft.tileentity.TileEntityFurnace;
    import net.minecraft.world.World;
    import net.minecraftforge.items.CapabilityItemHandler;
    import net.minecraftforge.items.IItemHandler;
    import net.minecraftforge.items.ItemStackHandler;
    import net.minecraftforge.items.SlotItemHandler;
    
    public class KitbagContainer extends Container {
    
    	private final int numRows;
    	public InventoryCrafting craftMatrix = new InventoryCrafting( this, 3, 3 );
        public InventoryCraftResult craftResult = new InventoryCraftResult();
        public EntityPlayer player;
        public World world;
        
    	public KitbagContainer( IItemHandler i, EntityPlayer p ) {
    		
    		// Inventory slots informations
    		int xPos = 5;
    		int yPos = 5;
    		int iid = 0;
    		this.numRows = 104 / 13; // 13*8 104 slots
    		this.player = p;
    		this.world = p.world;
    		
    		// CraftBench
    	    this.addSlotToContainer( new SlotCrafting( p, this.craftMatrix, this.craftResult, 0, 167, 170 ));
    
            for (int y = 0; y < 3; ++y) {
            	for (int x = 0; x < 3; ++x) {
            		this.addSlotToContainer( new Slot( this.craftMatrix, x + y * 3, 185 + x * 18, 152 + y * 18 ));
            	}
            }
    		
            // Inventory
    		for( int y = 0; y < 8; ++y ) {
    			for( int x = 0; x < 13; ++x ) {
    				this.addSlotToContainer( new SlotItemHandler( i, iid, xPos + x * 18, yPos + y * 18 ));
    				iid++;
    			}
    		}
    		
    		yPos = 152;
    		
    		// Player inventory
    		for( int y = 0; y < 3; ++y ) {
    			for( int x = 0; x < 9; ++x ) {
    				this.addSlotToContainer( new Slot( p.inventory, x + y * 9 + 9, xPos + x * 18, yPos + y * 18 ));
    			}
    		}
    		
    		// Player hotbar
    		for( int x = 0; x < 9; ++x ) {
    			this.addSlotToContainer( new Slot( p.inventory, x, xPos + x * 18, 209 ));
    		}
    		
    		//i.getStackInSlot(0).
    		
    		
    		
    		// Furnace slots
    		//IInventory ii = (IInventory) p.getHeldItemMainhand().getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null );
    		
    		//this.addSlotToContainer( new Slot( fi.getInventory(), 115, 221, 209 ));
            //this.addSlotToContainer( new SlotFurnaceFuel( fi, 116, 185, 209 ));
            //this.addSlotToContainer( new SlotFurnaceOutput( p, fi, 117, 203, 209 ));
    		
    	}
    	
    	public void onCraftMatrixChanged(IInventory inventoryIn)
        {
            this.slotChangedCraftingGrid( this.world, this.player, this.craftMatrix, this.craftResult );
        }
    	
    	 public void onContainerClosed(EntityPlayer playerIn)
    	    {
    	        super.onContainerClosed(playerIn);
    
    	        if (!this.world.isRemote)
    	        {
    	            this.clearContainer(playerIn, this.world, this.craftMatrix);
    	        }
    	    }
    	
    	@Override
    	public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
            ItemStack itemstack = ItemStack.EMPTY;
            Slot slot = this.inventorySlots.get(index);
            int startRow = 10;
    
            if (slot != null && slot.getHasStack()) {
                ItemStack itemstack1 = slot.getStack();
                itemstack = itemstack1.copy();
                
                if (index == 0)
                {
                    itemstack1.getItem().onCreated(itemstack1, this.world, playerIn);
    
                    if (!this.mergeItemStack(itemstack1, 0 + startRow, this.numRows * 13 + startRow, false))
                    {
                        return ItemStack.EMPTY;
                    }
    
                    slot.onSlotChange(itemstack1, itemstack);
                }
                else if (index < this.numRows * 13 + startRow)
                {
                    if (!this.mergeItemStack(itemstack1, this.numRows * 13 + startRow, this.inventorySlots.size(), true))
                    {
                        return ItemStack.EMPTY;
                    }
                }
                else if (!this.mergeItemStack(itemstack1, 0 + startRow, this.numRows * 13 + startRow, false))
                {
                    return ItemStack.EMPTY;
                }
    
                if (itemstack1.isEmpty())
                {
                    slot.putStack(ItemStack.EMPTY);
                }
                else
                {
                    slot.onSlotChanged();
                }
                
                if (itemstack1.getCount() == itemstack.getCount())
                {
                    return ItemStack.EMPTY;
                }
    
                ItemStack itemstack2 = slot.onTake(playerIn, itemstack1);
    
                if (index == 0)
                {
                    playerIn.dropItem(itemstack2, false);
                }
            }
    
            return itemstack;
        }
    
    	
    	@Override
    	public boolean canInteractWith( EntityPlayer p ) {
    		return true;
    	}
    	
    }

    Posted in: Modification Development
  • To post a comment, please .