Jump to content

[1.10] Capabilities


ErnstLustig
 Share

Recommended Posts

I'm still not fully understanding the new Capability system.

I know how to define what to access from which side, but what I care about is what to access depending on input or output. What I mean by that is that I might want to allow to put items in with a hopper for a specific slot, but not allow a hopper to pull the items out of that slot. How do I do that? Any examples you can point me at? I looked at a lot of code, but couldn't find the specific part where to define that.

 

Also it doesn't seem to check isItemValid if it's inserted with a hopper. So I'm not allowed to manually put items in the slot, but disallowed items land in the slot if accessed with a hopper. For reference, here is how I define the slot in the container.

 

        IItemHandler itemHandler = this.te.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null );

        addSlotToContainer( new SlotItemHandler( itemHandler, 0, 18, 24 ){
            @Override
            public boolean isItemValid( ItemStack stack ){
                return stack.getItem() instanceof ItemDrop;
            }
        });

Link to comment
Share on other sites

Well I implemented this now and it seems to work. I tried a block where for the input only a certain item type is allowed (both manual and automatic), but it can be removed manually, but not automatically. But it seems rather hacked than a clean simple solution. I think this can be made way more simple. What do you think?

 

public class TileEntitySqueezer extends TileEntity implements ITickable {

    public static final int INPUT_SIZE = 1;
    public static final int CAPACITY = Fluid.BUCKET_VOLUME * 8;
    private FluidTank tank = new FluidTank( CAPACITY ) {
        @Override
        protected void onContentsChanged(){ TileEntitySqueezer.this.markDirty(); }
    };

    private SqueezerItemStackHandler inputStack = new SqueezerItemStackHandler( INPUT_SIZE );

    [...]

    @Override
    public boolean hasCapability( Capability<?> capability, EnumFacing facing ){
        if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY ){
            return true;
        }
        return super.hasCapability( capability, facing );
    }

    @Override
    public <T> T getCapability( Capability<T> capability, EnumFacing facing ){
        if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ){
            if( facing == null ){ return (T) inputStack; }
            return (T) new InsertItemStackHandler( inputStack );
        }
        if( capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY ){
            return (T) tank;
        }
        return super.getCapability( capability, facing );
    }

    public class SqueezerItemStackHandler extends ItemStackHandler{

        public SqueezerItemStackHandler(){
            super( 1 );
        }

        public SqueezerItemStackHandler( int size ){
            super( size );
        }

        @Override
        protected void onContentsChanged( int slot ){
            TileEntitySqueezer.this.markDirty();
        }

        @Override
        public ItemStack insertItem( int slot, ItemStack stack, boolean simulate ){
            if( !( stack.getItem() instanceof ItemDrop ) ){ return stack; }
            return super.insertItem( slot, stack, simulate );
        }

        public ItemStack[] getStacks(){
            return stacks;
        }
    }

    public class InsertItemStackHandler extends SqueezerItemStackHandler{

        public InsertItemStackHandler( SqueezerItemStackHandler stackhandler ){
            this.stacks = stackhandler.getStacks();
        }

        @Override
        public ItemStack extractItem( int slot, int amount, boolean simulate ){
            return null;
        }
    }

Link to comment
Share on other sites

Well I don't know how to do it better, that's why I asked. I needed two StackHandlers because I need one to be a subclass of the other with the added restriction of not extracting items, but I can't copy the StackHandler because I can't access the ItemStacks. So I need to add the method of getStacks.

 

Not sure what you mean with not using the capability at all, you mean in the Container to access the ItemStacks? But that seems like even more work to me.

Link to comment
Share on other sites

Well I don't know how to do it better, that's why I asked. I needed two StackHandlers because I need one to be a subclass of the other with the added restriction of not extracting items, but I can't copy the StackHandler because I can't access the ItemStacks. So I need to add the method of getStacks.
Oh so you want different behavior for automation and players? Then yes, you need to handlers.

 

Not sure what you mean with not using the capability at all, you mean in the Container to access the ItemStacks? But that seems like even more work to me.

I was saying this, because some automation might access your capability with side null. That is not a valid indication for "this is a player".
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
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.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello! I downloaded the MrCrayfishs Furniture mod for 1.19.3. I also have 1.19.3 for forge and optifine. It's the only mod in my mods folder. It would be nice if anyone could help me. xx This is the crash report: ---- Minecraft Crash Report ---- // My bad. Time: 2023-01-30 13:17:38 Description: Mod loading error has occurred java.lang.Exception: Mod Loading has failed     at net.minecraftforge.logging.CrashReportExtender.dumpModLoadingCrashReport(CrashReportExtender.java:55) ~[forge-1.19.3-44.1.0-universal.jar%23155!/:?] {re:classloading}     at net.minecraftforge.client.loading.ClientModLoader.completeModLoading(ClientModLoader.java:167) ~[forge-1.19.3-44.1.0-universal.jar%23155!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.lambda$new$2(Minecraft.java:588) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.Util.m_137521_(Util.java:432) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading}     at net.minecraft.client.Minecraft.lambda$new$3(Minecraft.java:582) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.gui.screens.LoadingOverlay.m_86412_(LoadingOverlay.java:137) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.GameRenderer.m_109093_(GameRenderer.java:920) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1135) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:713) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.m_239872_(Main.java:212) ~[1.19.3-forge-44.1.0.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:51) ~[1.19.3-forge-44.1.0.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}     at net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:27) ~[fmlloader-1.19.3-44.1.0.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) ~[bootstraplauncher-1.1.2.jar:?] {} A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Render thread Stacktrace:     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:141) ~[securejarhandler-2.1.4.jar:?] {} -- MOD cfm -- Details:     Caused by 0: java.lang.NoClassDefFoundError: net/minecraft/data/tags/BlockTagsProvider         at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:?] {}         at java.lang.Class.privateGetDeclaredConstructors(Class.java:3373) ~[?:?] {}         at java.lang.Class.getConstructor0(Class.java:3578) ~[?:?] {}         at java.lang.Class.getDeclaredConstructor(Class.java:2754) ~[?:?] {}         at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:68) ~[javafmllanguage-1.19.3-44.1.0.jar%23152!/:?] {}         at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$10(ModContainer.java:121) ~[fmlcore-1.19.3-44.1.0.jar%23151!/:?] {}         at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?] {}         at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?] {}         at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}         at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}         at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {}         at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {}         at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {}     Mod File: /C:/Users/User/AppData/Roaming/.minecraft/mods/MrCrayfishs-Furniture-Mod-Forge-1.19.3.jar     Failure message: MrCrayfish's Furniture Mod (cfm) has failed to load correctly         java.lang.NoClassDefFoundError: net/minecraft/data/tags/BlockTagsProvider     Mod Version: 7.0.0-pre34     Mod Issue URL: https://github.com/MrCrayfish/MrCrayfishFurnitureMod/issues     Exception message: java.lang.ClassNotFoundException: net.minecraft.data.tags.BlockTagsProvider Stacktrace:     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:141) ~[securejarhandler-2.1.4.jar:?] {}     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}     at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:?] {}     at java.lang.Class.privateGetDeclaredConstructors(Class.java:3373) ~[?:?] {}     at java.lang.Class.getConstructor0(Class.java:3578) ~[?:?] {}     at java.lang.Class.getDeclaredConstructor(Class.java:2754) ~[?:?] {}     at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:68) ~[javafmllanguage-1.19.3-44.1.0.jar%23152!/:?] {}     at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$10(ModContainer.java:121) ~[fmlcore-1.19.3-44.1.0.jar%23151!/:?] {}     at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?] {}     at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?] {}     at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}     at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}     at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {}     at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {}     at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {} -- System Details -- Details:     Minecraft Version: 1.19.3     Minecraft Version ID: 1.19.3     Operating System: Windows 10 (amd64) version 10.0     Java Version: 17.0.3, Microsoft     Java VM Version: OpenJDK 64-Bit Server VM (mixed mode), Microsoft     Memory: 241410776 bytes (230 MiB) / 503316480 bytes (480 MiB) up to 2147483648 bytes (2048 MiB)     CPUs: 4     Processor Vendor: AuthenticAMD     Processor Name: AMD FX-8800P Radeon R7, 12 Compute Cores 4C+8G      Identifier: AuthenticAMD Family 21 Model 96 Stepping 1     Microarchitecture: unknown     Frequency (GHz): 2.10     Number of physical packages: 1     Number of physical CPUs: 4     Number of logical CPUs: 4     Graphics card #0 name: AMD Radeon R7 Graphics     Graphics card #0 vendor: Advanced Micro Devices, Inc. (0x1002)     Graphics card #0 VRAM (MB): 256.00     Graphics card #0 deviceId: 0x9874     Graphics card #0 versionInfo: DriverVersion=27.20.1034.6     Memory slot #0 capacity (MB): 8192.00     Memory slot #0 clockSpeed (GHz): 2.13     Memory slot #0 type: DDR4     Memory slot #1 capacity (MB): 8192.00     Memory slot #1 clockSpeed (GHz): 2.13     Memory slot #1 type: DDR4     Virtual memory max (MB): 18519.90     Virtual memory used (MB): 7647.12     Swap memory total (MB): 2432.00     Swap memory used (MB): 35.46     JVM Flags: 9 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xss1M -Xmx2G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M     ModLauncher: 10.0.8+10.0.8+main.0ef7e830     ModLauncher launch target: forgeclient     ModLauncher naming: srg     ModLauncher services:          mixin-0.8.5.jar mixin PLUGINSERVICE          eventbus-6.0.3.jar eventbus PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar slf4jfixer PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar object_holder_definalize PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar runtime_enum_extender PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar capability_token_subclass PLUGINSERVICE          accesstransformers-8.0.4.jar accesstransformer PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar runtimedistcleaner PLUGINSERVICE          modlauncher-10.0.8.jar mixin TRANSFORMATIONSERVICE          modlauncher-10.0.8.jar fml TRANSFORMATIONSERVICE      FML Language Providers:          minecraft@1.0         lowcodefml@null         javafml@null     Mod List:          client-1.19.3-20221207.122022-srg.jar             |Minecraft                     |minecraft                     |1.19.3              |COMMON_SET|Manifest: a1:d4:5e:04:4f:d3:d6:e0:7b:37:97:cf:77:b0:de:ad:4a:47:ce:8c:96:49:5f:0a:cf:8c:ae:b2:6d:4b:8a:3f         forge-1.19.3-44.1.0-universal.jar                 |Forge                         |forge                         |44.1.0              |COMMON_SET|Manifest: 84:ce:76:e8:45:35:e4:0e:63:86:df:47:59:80:0f:67:6c:c1:5f:6e:5f:4d:b3:54:47:1a:9f:7f:ed:5e:f2:90         MrCrayfishs-Furniture-Mod-Forge-1.19.3.jar        |MrCrayfish's Furniture Mod    |cfm                           |7.0.0-pre34         |ERROR     |Manifest: NOSIGNATURE     Crash Report UUID: d668c79d-366a-4acb-9754-f4cd52ab88cb     FML: 44.1     Forge: net.minecraftforge:44.1.0
    • thanks for your help. I found that issue: https://github.com/MinecraftForge/MinecraftForge/issues/8498
    • i'm trying to have my friend join my modded server. I gave them all the mods i have installed and the 'mixmatched mod list' keeps poping up.
  • Topics

×
×
  • Create New...

Important Information

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