Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello there mcforge forums,

 

So i was helping someone else with coding a custom machine working with the energy capability and saw that he used IInventory for his TE, i know that that shouldn't be used as its vanilla code and forge suggests to use the IItemHandler capability, so i rewrote the machine, now i only have a little bit of a problem as i wanted to make a container for it. But i needed an IInventory to add slots to the container. So i figured that i'd make a new instance of the slot and make it compatible with IItemHandler.

Spoiler

 


package harry.mod.objects.blocks.machines.electricalSinterer.slots;

import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.items.IItemHandler;

public class SlotIItemHandler extends Slot {
	IItemHandler INVENTORY;
	TileEntity TILE;

	@Deprecated
	public SlotIItemHandler(IInventory inventoryIn, int index, int xPosition, int yPosition) {
		super(inventoryIn, index, xPosition, yPosition);
		
	}
	
	public SlotIItemHandler(IItemHandler inventoryIn, int index, int xPosition, int yPosition, TileEntity tile) {
		super(null, index, xPosition, yPosition);
		this.INVENTORY = inventoryIn;
		this.TILE = tile;
	}
	
	@Override
	public int getSlotStackLimit() {
		return this.INVENTORY.getSlotLimit(slotNumber);
	}
	
	@Override
	public ItemStack getStack() {
		return this.INVENTORY.getStackInSlot(slotNumber);
	}
	
	@Override
	public void putStack(ItemStack stack) {
		this.INVENTORY.insertItem(slotNumber, stack, false);
		onSlotChanged();
	}
	
	@Override
	public void onSlotChanged() {
		this.TILE.markDirty();
	}
	
	@Override
	public ItemStack decrStackSize(int amount) {
		return this.INVENTORY.extractItem(slotNumber, amount, false);
	}

	@Override
	public boolean isHere(IInventory inv, int slotIn) {
		return false;
	}
	
	public boolean isHere(IItemHandler inv, int slotIn) {
		return this.INVENTORY.equals(inv) && this.slotNumber == slotIn;
	}
	
}

 

Now here's my question:

Wouldn't it be smart to add this standardly to the Slot class? That would save time for both me an you, i dont need to re-write this file again, and you aren't in need to explain why to use IItemHandler instead of IInventory as

Quote

The Slot will only work with IInventory

 

Edited by tebreca
marked it solved

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.