Jump to content

[1.16.5] Help with Capability (Inventory)


Luis_ST

Recommended Posts

I want to overwrite the vanilla ender chest container that the enderchest uses the double chest container.

I looked in the enderchest class vanilla uses PlayerEntity#getInventoryEnderChest

to open the gui so my question how to creat my own enderchest gui with 54 slots?

 

I know that I have to create my own capability. do I have to create a completely new one or can I use IItemHandler in my TileEntity?

because in the forge doc to capabilities it says that I can use persisting capabilities.

if I can use an existing capability, is this capability unique for each player?

(this is the first time that i use capabilities so i have no experience with them).

Link to comment
Share on other sites

34 minutes ago, diesieben07 said:

No, you just need a separate interface because you can't have two capabilities with the same interface.

Now i have my custom Interfacce and a class which extends ItemStackHandler and implements my interface

now i have to create a new capability like forge doc:

@CapabilityInject(MyInterface.class)
public static Capability<MyInterface> ITEM_HANDLER_CAPABILITY = null;

but should the class in which i created the capability extends / implements another class

Link to comment
Share on other sites

17 minutes ago, diesieben07 said:

This is described in the docs on capabilities.

i just read this, and i created this but i'm not sure if this is correct:

 

public class ModCapability {
	
	public ModCapability() {
		
		CapabilityManager.INSTANCE.register(IModItemHandler.class, new Storage(), null);
		
	}
	
	private static class Storage implements IStorage<IModItemHandler> {

		@Override
		public INBT writeNBT(Capability<IModItemHandler> capability, IModItemHandler instance, Direction side) {
			
			return null;
			
		}

		@Override
		public void readNBT(Capability<IModItemHandler> capability, IModItemHandler instance, Direction side, INBT nbt) {
			
			
		}
		
	}
	
}

 

Link to comment
Share on other sites

20 minutes ago, diesieben07 said:

The last parameter for register must not be null.

do i need the factory?

and what's wrong with the factory?

	public ModCapability() {
		
		CapabilityManager.INSTANCE.register(IModItemHandler.class, new Storage(), new Factory());
		
	}
	
	private static class Storage implements IStorage<IModItemHandler> {

		@Override
		public INBT writeNBT(Capability<IModItemHandler> capability, IModItemHandler instance, Direction side) {
			
			return null;
			
		}

		@Override
		public void readNBT(Capability<IModItemHandler> capability, IModItemHandler instance, Direction side, INBT nbt) {
			
			
		}
		
	}
	
	private static class Factory implements Callable<IModItemHandler> {

		@Override
		public IModItemHandler call() throws Exception {
			// what is here wrong?
			return new IModItemHandler();
			
		}
		
	}

 

Link to comment
Share on other sites

5 minutes ago, diesieben07 said:

The Storage and Factory will most likely go away in the future, it was a flawed concept.

You can just make them throw exceptions.

this is now my complet class is this corect:

	@CapabilityInject(IModItemHandler.class)
	public static Capability<IModItemHandler> ITEM_HANDLER_CAPABILITY = null;
	
	public ModCapability() {
		
		CapabilityManager.INSTANCE.register(IModItemHandler.class, new Storage(), new Factory());
		
	}
	
	private static class Storage implements IStorage<IModItemHandler> {

		@Override
		public INBT writeNBT(Capability<IModItemHandler> capability, IModItemHandler instance, Direction side) {
			
			return null;
			
		}

		@Override
		public void readNBT(Capability<IModItemHandler> capability, IModItemHandler instance, Direction side, INBT nbt) {
			
			
		}
		
	}
	
	private static class Factory implements Callable<IModItemHandler> {

		@Override
		public IModItemHandler call() throws Exception {
			
			return null;
			
		}
		
	}

 

Link to comment
Share on other sites

17 hours ago, diesieben07 said:

You already register it...

Another question how to add the extendsEnderChestGui (Generic9x3 ChestContainer) to the Capability (with this two methode \/ )

do I have to synchronize the gui between the server and the client and if so how do I do it since I looked at a few mods on github that use SimpleChannel and an interface is there another way to do this?

 

		@Override
		public INBT writeNBT(Capability<IModItemHandler> capability, IModItemHandler instance, Direction side) {
			
			CompoundNBT nbt = new CompoundNBT();
			return nbt;
			
		}

		@Override
		public void readNBT(Capability<IModItemHandler> capability, IModItemHandler instance, Direction side, INBT nbt) {
			
			
			
		}

 

Edited by Luis_ST
Link to comment
Share on other sites

1 hour ago, diesieben07 said:

Also, please keep this forum in English.

Sorry I forgot i translate it into english

 

1 hour ago, diesieben07 said:

No. Container already does this for you.

okay thanks, if I don't want to overwrite the block (ender chest).

can I open the gui with the PlayerInteractEvent#RightClickBlock (using NetworkHooks)

the container and when closing save them in the capability?

 

do i have to creat a container with screen or an inventory because the ender chest use an inventory

Edited by Luis_ST
Link to comment
Share on other sites

7 minutes ago, diesieben07 said:

The Container will already modify the capability (IItemHandler) directly.

so i just have to open the container / inventory and forge saves the gui from automatically?

 

22 minutes ago, Luis_ST said:

do i have to creat a container with screen or an inventory because the ender chest use an inventory

?

 

and where i have to put the container/inventory into the capability because when i use the AttachCapabilitiesEvent i got an NullPointerException:

event:

	@SubscribeEvent
	public static void AttachCapabilities(AttachCapabilitiesEvent<Entity> event) {
		
		if (event.getObject() instanceof PlayerEntity && !(event.getObject() instanceof FakePlayer)) {
			
			event.addCapability(new ResourceLocation("cave:extended_enderchest_gui"), new ModCapability.Provider());
			
		}
		
	}

 

and error log:

[10:38:50] [Server thread/ERROR] [ne.mi.ev.EventBus/EVENTBUS]: Exception caught during firing event: null
	Index: 1
	Listeners:
		0: NORMAL
		1: ASM: class net.luis.cave.events.capability.OnAttachCapabilitiesEvent AttachCapabilities(Lnet/minecraftforge/event/AttachCapabilitiesEvent;)V
java.lang.NullPointerException
	at java.base/java.util.Objects.requireNonNull(Objects.java:208)
	at net.luis.cave.init.ModCapability$Provider.<init>(ModCapability.java:59)
	at net.luis.cave.events.capability.OnAttachCapabilitiesEvent.AttachCapabilities(OnAttachCapabilitiesEvent.java:21)
	at net.minecraftforge.eventbus.ASMEventHandler_16_OnAttachCapabilitiesEvent_AttachCapabilities_AttachCapabilitiesEvent.invoke(.dynamic)
	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85)
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302)
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283)
	at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:579)
	at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:573)
	at net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:48)
	at net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:44)
	at net.minecraft.entity.Entity.<init>(Entity.java:221)
	at net.minecraft.entity.LivingEntity.<init>(LivingEntity.java:207)
	at net.minecraft.entity.player.PlayerEntity.<init>(PlayerEntity.java:160)
	at net.minecraft.entity.player.ServerPlayerEntity.<init>(ServerPlayerEntity.java:182)
	at net.minecraft.server.management.PlayerList.createPlayerForUser(PlayerList.java:419)
	at net.minecraft.network.login.ServerLoginNetHandler.tryAcceptPlayer(ServerLoginNetHandler.java:122)
	at net.minecraft.network.login.ServerLoginNetHandler.tick(ServerLoginNetHandler.java:66)
	at net.minecraft.network.NetworkManager.tick(NetworkManager.java:244)
	at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:151)
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:898)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:820)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:84)
	at net.minecraft.server.MinecraftServer.func_240802_v_(MinecraftServer.java:663)
	at net.minecraft.server.MinecraftServer.lambda$startServer$0(MinecraftServer.java:233)
	at java.base/java.lang.Thread.run(Thread.java:832)

[10:38:50] [Server thread/FATAL] [ne.mi.co.ForgeMod/]: Preparing crash report with UUID 3dbca5d1-2854-4053-a647-dfa6633d91c6
[10:38:50] [Server thread/ERROR] [minecraft/MinecraftServer]: Encountered an unexpected exception
net.minecraft.crash.ReportedException: Ticking memory connection
	at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:154) ~[forge:?] {re:classloading}
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:898) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:820) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:84) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.func_240802_v_(MinecraftServer.java:663) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.lambda$startServer$0(MinecraftServer.java:233) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at java.lang.Thread.run(Thread.java:832) [?:?] {}
Caused by: java.lang.NullPointerException
	at java.util.Objects.requireNonNull(Objects.java:208) ~[?:?] {}
	at net.luis.cave.init.ModCapability$Provider.<init>(ModCapability.java:59) ~[main/:?] {re:classloading}
	at net.luis.cave.events.capability.OnAttachCapabilitiesEvent.AttachCapabilities(OnAttachCapabilitiesEvent.java:21) ~[main/:?] {re:classloading}
	at net.minecraftforge.eventbus.ASMEventHandler_16_OnAttachCapabilitiesEvent_AttachCapabilities_AttachCapabilitiesEvent.invoke(.dynamic) ~[?:?] {}
	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-4.0.0.jar:?] {}
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-4.0.0.jar:?] {}
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-4.0.0.jar:?] {}
	at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:579) ~[forge:?] {re:classloading}
	at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:573) ~[forge:?] {re:classloading}
	at net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:48) ~[forge:?] {re:classloading}
	at net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:44) ~[forge:?] {re:classloading}
	at net.minecraft.entity.Entity.<init>(Entity.java:221) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.entity.LivingEntity.<init>(LivingEntity.java:207) ~[forge:?] {re:classloading}
	at net.minecraft.entity.player.PlayerEntity.<init>(PlayerEntity.java:160) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.entity.player.ServerPlayerEntity.<init>(ServerPlayerEntity.java:182) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.management.PlayerList.createPlayerForUser(PlayerList.java:419) ~[forge:?] {re:classloading}
	at net.minecraft.network.login.ServerLoginNetHandler.tryAcceptPlayer(ServerLoginNetHandler.java:122) ~[forge:?] {re:classloading}
	at net.minecraft.network.login.ServerLoginNetHandler.tick(ServerLoginNetHandler.java:66) ~[forge:?] {re:classloading}
	at net.minecraft.network.NetworkManager.tick(NetworkManager.java:244) ~[forge:?] {re:classloading}
	at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:151) ~[forge:?] {re:classloading}
	... 6 more

 

Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

The container is completely unrelated to the capability. The inventory (i.e. IItemHandler) is the capability implementation.

so i have to use IItemHandler to get and open the gui inside there:

NetworkHooks.openGui(serverPlayer, /*here*/, pos);

 

and:

public class ModCapability {
	
	@CapabilityInject(IModItemHandler.class)
	public static Capability<IModItemHandler> CAPABILITY = null;
	
	public ModCapability() {
		
		CapabilityManager.INSTANCE.register(IModItemHandler.class, new Storage(), new Factory());
		
	}
	
	public static class Storage implements IStorage<IModItemHandler> {
		@Override
		public INBT writeNBT(Capability<IModItemHandler> capability, IModItemHandler instance, Direction side) {
			return null;
		}

		@Override
		public void readNBT(Capability<IModItemHandler> capability, IModItemHandler instance, Direction side, INBT nbt) {
		}
	}
	
	public static class Factory implements Callable<IModItemHandler> {
		@Override
		public IModItemHandler call() throws Exception {
			return null;
		}
	}
	
	public static class Provider implements ICapabilityProvider {

		private final LazyOptional<IModItemHandler> lazyOptional = LazyOptional.of(CAPABILITY::getDefaultInstance);
		
		@Override
		public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
			
			return cap == CAPABILITY ? lazyOptional.cast() : LazyOptional.empty();
			
		}
		
	}
	
}

 

Link to comment
Share on other sites

9 minutes ago, diesieben07 said:

No, you need to implement INamedContainerProvider.

do i only have to implement Named ContainerProvider because i currently extends Chest Container / Container and i think thats wrong

 

34 minutes ago, diesieben07 said:

Obviously you can't do this if your default factory returns null. Use a normal constructor.

so like this:

	public static class Provider implements ICapabilityProvider {
		
		@Override
		public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
			
			return null;
			
		}
		
	}

 

Link to comment
Share on other sites

3 hours ago, diesieben07 said:

You need both. You need a Container (and the corresponding ContainerType and ScreenFactory) and you need to implement INamedContainerProvider for openGui.

I already have that, but how do I open the container in my event?

what do I have to hand over to the method at "null"?

	@SubscribeEvent
	public static void PlayerInteract(PlayerInteractEvent.RightClickBlock event) {
		
		PlayerEntity player = event.getPlayer();
		BlockPos pos = event.getPos();
		World world = event.getWorld();
		BlockState state = world.getBlockState(pos);
		EnderChestInventory enderChestInventory = player.getInventoryEnderChest();
		
		if (state.getBlock() == Blocks.ENDER_CHEST) {
			
			if (!enderChestInventory.isEmpty()) {
				
				InventoryHelper.dropInventoryItems(world, pos, enderChestInventory);
				
			} else {
				
				if (player instanceof ServerPlayerEntity) {
					
					event.setCanceled(true);
					ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
					NetworkHooks.openGui(serverPlayer, null, pos);
					
				}
				
			}
			
		}

	}

 

3 hours ago, diesieben07 said:

No... Not at all.

you say I should use a constructor, what must be in the constructor and what should the method "getCapability" return

Edited by Luis_ST
Link to comment
Share on other sites

2 hours ago, diesieben07 said:

A new instance of your INamedContainerProvider implementation.

then like this:

					NetworkHooks.openGui(serverPlayer, new SimpleNamedContainerProvider((id, inventory, playerIn) -> {
						return new ModEnderChestContainer(id, inventory);
					}, ModEnderChestContainer.getContainerName()), pos);

 

2 hours ago, diesieben07 said:

Why do you do this?

This checks whether the player's Enderchest inventory is already in use, as the player may add the mod later. If this is the case,

the existing inventory will be dropped and the new one will be opened with the next click.

 

2 hours ago, diesieben07 said:

This is a class that extends ItemStackHandler, just add the same constructors that that class has and call the super constructors. Your IDE should do this for you automatically.

i dont get a constructor

so this is my complet class:

package net.luis.cave.init;

import java.util.concurrent.Callable;

import net.luis.cave.api.capability.IModItemHandler;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.INBT;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.Capability.IStorage;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.common.util.NonNullSupplier;

public class ModCapability {
	
	@CapabilityInject(IModItemHandler.class)
	public static Capability<IModItemHandler> CAPABILITY = null;
	
	public ModCapability() {
		
		CapabilityManager.INSTANCE.register(IModItemHandler.class, new Storage(), new Factory());
		
	}
	
	public static class Storage implements IStorage<IModItemHandler> {
		@Override
		public INBT writeNBT(Capability<IModItemHandler> capability, IModItemHandler instance, Direction side) {
			return null;
		}

		@Override
		public void readNBT(Capability<IModItemHandler> capability, IModItemHandler instance, Direction side, INBT nbt) {
		}
	}
	
	public static class Factory implements Callable<IModItemHandler> {
		@Override
		public IModItemHandler call() throws Exception {
			return null;
		}
	}
	
	public static class Provider implements ICapabilityProvider {
		
		@Override
		public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
			
			return cap == CAPABILITY ? LazyOptional.of(() -> null) : LazyOptional.empty();
			
		}
		
	}
	
}

 

2 hours ago, diesieben07 said:

you need to check if the queried capability is yours and if so return the LazyOptional containing your capability instance. Otherwise return the empty LazyOptional.

what do I have to replace null with

Link to comment
Share on other sites

34 minutes ago, diesieben07 said:

Or... you could just make your inventory an extension of the ender chest inventory (just like how chests that are next to each other merge together). That way their existing inventory (if any) stays and if they uninstall the mod at least the "normal" part still stays.

Like I already suggested...

what do I have to change so that it works like a double chest inventory?

 

50 minutes ago, Luis_ST said:

This is a class that extends ItemStackHandler, just add the same constructors that that class has and call the super constructors. Your IDE should do this for you automatically.

36 minutes ago, diesieben07 said:

I have no idea what you mean by this.

which class did you mean?

 

39 minutes ago, diesieben07 said:

You have to replace it with the instance of your capability (i.e. your inventory).

like this? (this doesent work -> "Cannot make a static reference to the non-static method getInventory() from the type Container")

	public static class Provider implements ICapabilityProvider {
		
		@Override
		public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
			
			return cap == CAPABILITY ? LazyOptional.of(ModEnderChestContainer::getInventory) : LazyOptional.empty();
			
		}
		
	}

 

Link to comment
Share on other sites

35 minutes ago, diesieben07 said:

Use CombinedInvHandler to combine the two into one.

where and when do I have to use this in the container class or when I interact with the block

 

31 minutes ago, diesieben07 said:

What on earth are you talking about?

i fixed it (it was a question about the error log)

 

32 minutes ago, diesieben07 said:

This makes zero sense. Why would the container store the inventory. Your ICapabiltyProvider needs to store and save the capability.

i don't understand what i have to set there, i tried a lot but every time i get an error

Link to comment
Share on other sites

12 hours ago, diesieben07 said:

Your ICapabiltiyProvider needs a field that holds your capability instance (the inventory). It also needs a field that holds a LazyOptional to be returned from getCapability.

like this?

	public static class Provider implements ICapabilityProvider {
		
		private static IModItemHandler inventory = new ModItemStackHandler();
		
		@Override
		public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
			
			return cap == CAPABILITY ? (LazyOptional<T>) LazyOptional.of(() -> inventory) : LazyOptional.empty();
			
		}
		
	}

 

Link to comment
Share on other sites

12 minutes ago, diesieben07 said:

Yes and yes.

this is now my ICapabilityProvider:

	public static class Provider implements ICapabilityProvider {
		
		private static IModItemHandler inventory = new ModItemStackHandler();
		private static LazyOptional<IModItemHandler> optional = LazyOptional.of(() -> inventory);
		
		@Override
		@SuppressWarnings("unchecked")
		public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
			
			return cap == CAPABILITY ? (LazyOptional<T>) optional : LazyOptional.empty();
			
		}
		
	}

 

and how do I add my extended enderchest inventory and that of the enderchest beacuse when i try this:

CombinedInvWrapper invWrapper = new CombinedInvWrapper(inventory);			

1. i got an error: "The constructor CombinedInvWrapper(IModItemHandler) is undefined"

2, how to get the ernderchest inventory?

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

PlayerEntity#getInventoryEnderChest

i know about this methode but what i mean how o get the InventoryEnderChest whitout a player or can i get beacuse i dont have a player inside the class:

or is there a way to get the player?

	public static class Provider implements ICapabilityProvider {
		
		private static IModItemHandler inventory = new ModItemStackHandler();
		private static LazyOptional<IModItemHandler> optional = LazyOptional.of(() -> inventory);
		
		@Override
		@SuppressWarnings("unchecked")
		public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
			
			CombinedInvWrapper invWrapper = new CombinedInvWrapper(inventory);			
			return cap == CAPABILITY ? (LazyOptional<T>) optional : LazyOptional.empty();
			
		}
		
	}

 

Link to comment
Share on other sites

47 minutes ago, diesieben07 said:

How would you get the ender chest without a player?

i add an constructor an remove the static of the LazyOptional so this is now my Provider:

but i can't combined the Inventories in this way.

	public static class Provider implements ICapabilityProvider {
		
		private static IModItemHandler inventory = new ModItemStackHandler();
		private LazyOptional<IModItemHandler> optional = LazyOptional.of(() -> inventory);
		
		public Provider(PlayerEntity player) {
			
			EnderChestInventory enderChestInventory = player.getInventoryEnderChest();
											/*Here is an Error*/
			CombinedInvWrapper invWrapper = new CombinedInvWrapper(inventory, enderChestInventory);
			IItemHandlerModifiable itemHandlerModifiable = invWrapper;
			
		}
		
		@Override
		@SuppressWarnings({ "unchecked", "unused" })
		public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
			
			return cap == CAPABILITY ? (LazyOptional<T>) optional : LazyOptional.empty();
			
		}
		
	}

 

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

Do you know what static means?

I know what was meant by static i forgot it to remove

 

1 hour ago, diesieben07 said:

/*Here is an Error*/

i got an error: "The constructor CombinedInvWrapper(IModItemHandler, EnderChestInventory) is undefined".

 

1 hour ago, diesieben07 said:

Also: You still completely ignore the CombinedInvWrapper that you create.

1. What do I have to do with it or how do I create IItemHandlerModifiable
2. I have to add the container that I have created to my IModItemHandler.

because I have not yet passed anything to the IModItemHandler (it is empty) or I think that it is empty

Link to comment
Share on other sites

16 hours ago, diesieben07 said:

Yes... I told you how to fix it right below. In a quote, because I already told you this previously.

i dont understand when i only use my capility it work when i add the ender chest inventory i got this error

 

16 hours ago, diesieben07 said:

You have to return it from getCapability... obviously. You want to use it in your container.

then i have to creat a field?

I have to do the following:
1. Combination of inventories
2. Creat a IItemHandlerModifiable from the combination
3. Retrun the IItemHandlerModifiable in getCapability

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements




  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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