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

Instantiate it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

I thought it requires more things....

I allready had the ItemStackHandler here, but i thought i am supposed to implement IItemHandler

 

 

But now what do i do with this?

this.addSlotToContainer(new SlotItemHandler(te, x + y * 9, 15 + x * 16, 15 + y * 16));

 

(adding slots to a container)

te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

I tried this:

 

this.addSlotToContainer(new SlotItemHandler(te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP), x + y * 9, 15 + x * 16, 15 + y * 16));
		}

doesn't work

  • Author

Multiple markers at this line

- The constructor SlotItemHandler(TileEntityStoneCrate, int, int, int) is

undefined

- The constructor SlotItemHandler(Capability, int, int, int) is undefined

  • Author

I think i have this wrong:

 

ItemStackHandler itemHandler = new ItemStackHandler(81);

@Override
public boolean hasCapability(Capability capability, EnumFacing facing) {
     return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ? true : super.hasCapability(capability, facing);
}

@Override
public Capability getCapability(Capability capability, EnumFacing facing) {
	if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
	    return itemHandler;
	  }
	  return super.getCapability(capability, facing);
}

Use generics.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

I'm back now.

i mde some changes and it works, but when i place itemstack in slot, it goes in there, but it is also left in my cursor and when i remove itemstack it just disappears.

 

package com.villfuk02.essence.tileentities;

import java.awt.ItemSelectable;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemStackHandler;

public class TileEntityStoneCrate extends TileEntity implements ICapabilityProvider{

private String customName;

private static ItemStackHandler itemHandler = new ItemStackHandler(81);

@Override
public boolean hasCapability(Capability capability, EnumFacing facing) {
     return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ? true : super.hasCapability(capability, facing);
}

@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
	if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
	    return (T) itemHandler;
	  }
	  return super.getCapability(capability, facing);
}

public String getCustomName(){
	return this.customName;
}

public void setCustomName(String customName){
	this.customName = customName;
}



public String getName() {
	return this.hasCustomName() ? this.customName : "Stone Storage Crate";
}

public boolean hasCustomName() {
	return this.customName != null && !this.customName.equals("");
}

public int getSizeInventory() {
	return 81;
}


public boolean isUseableByPlayer(EntityPlayer player) {
	return this.worldObj.getTileEntity(this.getPos()) == this && player.getDistanceSq(this.pos.add(0.5, 0.5, 0.5)) <= 64;
}


}

  • Author

I think everything happens twice and doesnt sync perfectly, because when i place less than 32 items in the slot, it just doubles in the slot. When i put 48 items in, in the slot goes 64 and i get 32 back. when i split the stack with rightclicking, in the slot is left just quarter of the items and in my cursor too.

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.