Jump to content

[1.16.5]Capability reset after restarting the game


LYXHAHA
 Share

Recommended Posts

Every time you restart the game or re-enter the map, the capability is reset. I don’t know if this is a problem with my code or is it the way it is.

public class CapabilityAttachHandler {
    public CapabilityAttachHandler() {}

    public static void capabilityAttachHandler(AttachCapabilitiesEvent<Entity> event) {
        Entity entity = event.getObject();
        if (entity instanceof PlayerEntity){
            if (!entity.getCapability(LibCapabilities.MIND_CAPABILITY).isPresent()) {
                event.addCapability(SaintChapter.key("mind_strength"), new MindCapabilityProvider());
                SaintChapter.LOGGER.info("Mind Capability attached");
            }
            if (!entity.getCapability(LibCapabilities.SOUL_CAPABILITY).isPresent()){
                event.addCapability(SaintChapter.key("soul_strength"), new SoulCapabilityProvider());
                SaintChapter.LOGGER.info("Player Soul Capability attached");
            }
        }
        if (entity instanceof MobEntity) {
            if (!entity.getCapability(LibCapabilities.SOUL_CAPABILITY).isPresent()){
                event.addCapability(SaintChapter.key("soul_strength"), new SoulCapabilityProvider());
                SaintChapter.LOGGER.info("Mob Soul Capability attached");
            }
        }
    }
}
public interface ISoulCapability extends INBTSerializable<CompoundNBT> {
    int getSoulStrength ();
    boolean getInitialized();
}
public class SoulCapability implements ISoulCapability {
    private int soulStrength;
    private boolean initialized;

    public SoulCapability(int soulStrength, boolean isInitialized) {
        this.soulStrength = soulStrength;
        this.initialized = isInitialized;
    }

    @Override
    public boolean getInitialized() {
        return this.initialized;
    }

    @Override
    public int getSoulStrength() {
        return soulStrength;
    }


    @Override
    public CompoundNBT serializeNBT() {
        CompoundNBT compoundNBT = new CompoundNBT();
        compoundNBT.putInt("soulStrength", this.soulStrength);
        compoundNBT.putBoolean("initialized", this.initialized);
        return compoundNBT;
    }

    @Override
    public void deserializeNBT(CompoundNBT nbt) {
        this.soulStrength = nbt.getInt("soulStrength");
        this.initialized = nbt.getBoolean("initialized");
    }
}
public class SoulCapabilityProvider implements ICapabilityProvider, INBTSerializable<CompoundNBT> {
    private ISoulCapability soulCapability;

    @Nonnull
    @Override
    public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
        return cap == LibCapabilities.SOUL_CAPABILITY ? LazyOptional.of(this::getOrCreateCapability).cast() : LazyOptional.empty();
    }

    @Nonnull
    private ISoulCapability getOrCreateCapability() {
        if (soulCapability == null) {
            this.soulCapability = new SoulCapability(888, false);
        }
        return this.soulCapability;
    }

    @Override
    public CompoundNBT serializeNBT() {
        return getOrCreateCapability().serializeNBT();
    }

    @Override
    public void deserializeNBT(CompoundNBT nbt) {
        getOrCreateCapability().deserializeNBT(nbt);
    }
}

 

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

    • https://gist.github.com/Phoenix-warrior9/d2ac353246276d557d002bffa99e2031
    • ---- Minecraft Crash Report ---- // Don't be sad, have a hug! ❤️ Time: 12/4/22, 6:07 PM Description: Mod loading error has occurred java.lang.Exception: Mod Loading has failed     at net.minecraftforge.logging.CrashReportExtender.dumpModLoadingCrashReport(CrashReportExtender.java:55) ~[forge-1.18.2-40.1.0-universal.jar%2358!/:?] {re:classloading}     at net.minecraftforge.client.loading.ClientModLoader.completeModLoading(ClientModLoader.java:169) ~[forge-1.18.2-40.1.0-universal.jar%2358!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.lambda$new$1(Minecraft.java:555) ~[client-1.18.2-20220404.173914-srg.jar%2354!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:create.mixins.json:WindowResizeMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.Util.m_137521_(Util.java:397) ~[client-1.18.2-20220404.173914-srg.jar%2354!/:?] {re:classloading}     at net.minecraft.client.Minecraft.lambda$new$2(Minecraft.java:549) ~[client-1.18.2-20220404.173914-srg.jar%2354!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:create.mixins.json:WindowResizeMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.client.gui.screens.LoadingOverlay.m_6305_(LoadingOverlay.java:135) ~[client-1.18.2-20220404.173914-srg.jar%2354!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.GameRenderer.m_109093_(GameRenderer.java:877) ~[client-1.18.2-20220404.173914-srg.jar%2354!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:create.mixins.json:GameRendererMixin,pl:mixin:APP:create.mixins.json:accessor.GameRendererAccessor,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1044) ~[client-1.18.2-20220404.173914-srg.jar%2354!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:create.mixins.json:WindowResizeMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:663) ~[client-1.18.2-20220404.173914-srg.jar%2354!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:create.mixins.json:WindowResizeMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:205) ~[client-1.18.2-20220404.173914-srg.jar%2354!/:?] {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:31) ~[fmlloader-1.18.2-40.1.0.jar%2316!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) [bootstraplauncher-1.0.0.jar:?] {} A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Render thread Stacktrace:     at net.minecraftforge.logging.CrashReportExtender.lambda$dumpModLoadingCrashReport$7(CrashReportExtender.java:58) ~[forge-1.18.2-40.1.0-universal.jar%2358!/:?] {re:classloading} -- MOD create -- Details:     Mod File: create-1.18.2-0.5.0.e.jar     Failure message: Mod create requires forge 40.1.60 or above         Currently, forge is 40.1.0     Mod Version: 0.5.0.e     Mod Issue URL: https://github.com/Creators-of-Create/Create/issues     Exception message: MISSING EXCEPTION MESSAGE Stacktrace:     at net.minecraftforge.logging.CrashReportExtender.lambda$dumpModLoadingCrashReport$7(CrashReportExtender.java:58) ~[forge-1.18.2-40.1.0-universal.jar%2358!/:?] {re:classloading}     at java.util.ArrayList.forEach(ArrayList.java:1511) ~[?:?] {}     at net.minecraftforge.logging.CrashReportExtender.dumpModLoadingCrashReport(CrashReportExtender.java:56) ~[forge-1.18.2-40.1.0-universal.jar%2358!/:?] {re:classloading}     at net.minecraftforge.client.loading.ClientModLoader.completeModLoading(ClientModLoader.java:169) ~[forge-1.18.2-40.1.0-universal.jar%2358!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.lambda$new$1(Minecraft.java:555) ~[client-1.18.2-20220404.173914-srg.jar%2354!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:create.mixins.json:WindowResizeMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.Util.m_137521_(Util.java:397) ~[client-1.18.2-20220404.173914-srg.jar%2354!/:?] {re:classloading}     at net.minecraft.client.Minecraft.lambda$new$2(Minecraft.java:549) ~[client-1.18.2-20220404.173914-srg.jar%2354!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:create.mixins.json:WindowResizeMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.client.gui.screens.LoadingOverlay.m_6305_(LoadingOverlay.java:135) ~[client-1.18.2-20220404.173914-srg.jar%2354!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.GameRenderer.m_109093_(GameRenderer.java:877) ~[client-1.18.2-20220404.173914-srg.jar%2354!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:create.mixins.json:GameRendererMixin,pl:mixin:APP:create.mixins.json:accessor.GameRendererAccessor,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1044) ~[client-1.18.2-20220404.173914-srg.jar%2354!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:create.mixins.json:WindowResizeMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:663) ~[client-1.18.2-20220404.173914-srg.jar%2354!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:create.mixins.json:WindowResizeMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:205) ~[client-1.18.2-20220404.173914-srg.jar%2354!/:?] {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:31) ~[fmlloader-1.18.2-40.1.0.jar%2316!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) [bootstraplauncher-1.0.0.jar:?] {} -- MOD create -- Details:     Mod File: create-1.18.2-0.5.0.e.jar     Failure message: Mod create requires flywheel 0.6.5 or above, and below 0.6.7         Currently, flywheel is not installed     Mod Version: 0.5.0.e     Mod Issue URL: https://github.com/Creators-of-Create/Create/issues     Exception message: MISSING EXCEPTION MESSAGE -- MOD chipped -- Details:     Mod File: chipped-2.0.0-forge.jar     Failure message: Mod chipped requires ctm 0 or above         Currently, ctm is not installed     Mod Version: 2.0.0     Mod Issue URL: NOT PROVIDED     Exception message: MISSING EXCEPTION MESSAGE -- System Details -- Details:     Minecraft Version: 1.18.2     Minecraft Version ID: 1.18.2     Operating System: Windows 10 (amd64) version 10.0     Java Version: 17.0.1, Microsoft     Java VM Version: OpenJDK 64-Bit Server VM (mixed mode), Microsoft     Memory: 1033808624 bytes (985 MiB) / 1778384896 bytes (1696 MiB) up to 2147483648 bytes (2048 MiB)     CPUs: 16     Processor Vendor: AuthenticAMD     Processor Name: AMD Ryzen 7 5800X 8-Core Processor                  Identifier: AuthenticAMD Family 25 Model 33 Stepping 2     Microarchitecture: Zen 3     Frequency (GHz): 3.80     Number of physical packages: 1     Number of physical CPUs: 8     Number of logical CPUs: 16     Graphics card #0 name: NVIDIA GeForce RTX 3070     Graphics card #0 vendor: NVIDIA (0x10de)     Graphics card #0 VRAM (MB): 4095.00     Graphics card #0 deviceId: 0x2484     Graphics card #0 versionInfo: DriverVersion=31.0.15.2686     Memory slot #0 capacity (MB): 8192.00     Memory slot #0 clockSpeed (GHz): 2.13     Memory slot #0 type: DDR4     Memory slot #1 capacity (MB): 32768.00     Memory slot #1 clockSpeed (GHz): 2.13     Memory slot #1 type: DDR4     Memory slot #2 capacity (MB): 8192.00     Memory slot #2 clockSpeed (GHz): 2.13     Memory slot #2 type: DDR4     Memory slot #3 capacity (MB): 32768.00     Memory slot #3 clockSpeed (GHz): 2.13     Memory slot #3 type: DDR4     Virtual memory max (MB): 86966.09     Virtual memory used (MB): 26648.90     Swap memory total (MB): 5120.00     Swap memory used (MB): 24.13     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: 9.1.3+9.1.3+main.9b69c82a     ModLauncher launch target: forgeclient     ModLauncher naming: srg     ModLauncher services:           mixin PLUGINSERVICE           eventbus PLUGINSERVICE           slf4jfixer PLUGINSERVICE           object_holder_definalize PLUGINSERVICE           runtime_enum_extender PLUGINSERVICE           capability_token_subclass PLUGINSERVICE           accesstransformer PLUGINSERVICE           runtimedistcleaner PLUGINSERVICE           mixin TRANSFORMATIONSERVICE           fml TRANSFORMATIONSERVICE      FML Language Providers:          minecraft@1.0         javafml@null     Mod List:          client-1.18.2-20220404.173914-srg.jar             |Minecraft                     |minecraft                     |1.18.2              |NONE      |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.18.2-40.1.0-universal.jar                 |Forge                         |forge                         |40.1.0              |NONE      |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
    • Besides all my mods are working because I use the same mods for the forge version 43.1.6.5 and it works very well (1.9.2) but with the new forge it does not
    • Thank you for you time Mr warjort. I don’t have a crash report. But it does say exit code 1 
  • Topics

×
×
  • Create New...

Important Information

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