Jump to content

[1.11] [solved] Casting Capabilities.


Lambda

Recommended Posts

Hey there,

 

So I'm having an issue with one of my items, in which I'm casting IEnergyStorage to Capability.Energy.

 

However, I'm getting a crash saying that I cannot cast it to each other. This worked in 1.10 however.

 

java.lang.ClassCastException: com.lambda.plentifulmisc.items.base.ItemEnergy$EnergyCapabilityProvider$1 cannot be cast to net.minecraftforge.energy.IEnergyStorage
at com.lambda.plentifulmisc.items.base.ItemEnergy.getMaxEnergyStored(ItemEnergy.java:175)
at com.lambda.plentifulmisc.items.ItemDrill.addDrillStack(ItemDrill.java:324)
at com.lambda.plentifulmisc.items.ItemDrill.getSubItems(ItemDrill.java:318)
at net.minecraft.creativetab.CreativeTabs.displayAllRelevantItems(CreativeTabs.java:301)
at net.minecraft.client.gui.inventory.GuiContainerCreative.setCurrentCreativeTab(GuiContainerCreative.java:493)
at net.minecraft.client.gui.inventory.GuiContainerCreative.mouseReleased(GuiContainerCreative.java:464)
at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:621)
at net.minecraft.client.gui.inventory.GuiContainerCreative.handleMouseInput(GuiContainerCreative.java:585)
at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:576)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1790)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1117)
at net.minecraft.client.Minecraft.run(Minecraft.java:405)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)

 

Here is the item:

    @Override
    @SideOnly(Side.CLIENT)
    public void getSubItems(Item item, CreativeTabs tabs, NonNullList list){
        ItemStack stackFull = new ItemStack(this);
        if(stackFull.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stackFull.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage != null){
                this.setEnergy(stackFull, storage.getMaxEnergyStored());
                list.add(stackFull);
            }
        }

        ItemStack stackEmpty = new ItemStack(this);
        this.setEnergy(stackEmpty, 0);
        list.add(stackEmpty);
    }

    @Override
    public boolean showDurabilityBar(ItemStack itemStack){
        return true;
    }

    @Override
    public double getDurabilityForDisplay(ItemStack stack){
        if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage != null){
                double maxAmount = storage.getMaxEnergyStored();
                double energyDif = maxAmount-storage.getEnergyStored();
                return energyDif/maxAmount;
            }
        }
        return super.getDurabilityForDisplay(stack);
    }

    @Override
    public int getRGBDurabilityForDisplay(ItemStack stack){
        EntityPlayer player = PlentifulMisc.proxy.getCurrentPlayer();
        if(player != null && player.worldObj != null){
            float[] color = AssetUtil.getRGB(player.worldObj.getTotalWorldTime()%256);
            return MathHelper.rgb(color[0]/255F, color[1]/255F, color[2]/255F);
        }
        return super.getRGBDurabilityForDisplay(stack);
    }

    public void setEnergy(ItemStack stack, int energy){
        if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage instanceof CustomEnergyStorage){
                ((CustomEnergyStorage)storage).setEnergyStored(energy);
            }
        }
    }

    public int receiveEnergyInternal(ItemStack stack, int maxReceive, boolean simulate){
        if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage instanceof CustomEnergyStorage){
                ((CustomEnergyStorage)storage).receiveEnergyInternal(maxReceive, simulate);
            }
        }
        return 0;
    }

    public int extractEnergyInternal(ItemStack stack, int maxExtract, boolean simulate){
        if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage instanceof CustomEnergyStorage){
                ((CustomEnergyStorage)storage).extractEnergyInternal(maxExtract, simulate);
            }
        }
        return 0;
    }

    public int receiveEnergy(ItemStack stack, int maxReceive, boolean simulate){
        if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage != null){
                return storage.receiveEnergy(maxReceive, simulate);
            }
        }
        return 0;
    }

    public int extractEnergy(ItemStack stack, int maxExtract, boolean simulate){
        if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage != null){
                return storage.extractEnergy(maxExtract, simulate);
            }
        }
        return 0;
    }

    public int getEnergyStored(ItemStack stack){
        if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage != null){
                return storage.getEnergyStored();
            }
        }
        return 0;
    }

 

All these lines do this:

        ItemStack stackFull = new ItemStack(this);
        if(stackFull.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stackFull.getCapability(CapabilityEnergy.ENERGY, null);

 

Thanks.

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Link to comment
Share on other sites

Usually, I don't like doing this, find it kinda scummy :^|

 

*cough*

 

Well, maybe not all that useless, Some Update on the situation:

Anytime I open the Creative Tab it crashes with the same error, but during Pre-Init I get:

 

[19:40:01] [Client thread/INFO]: Starting JEI...
[19:40:01] [Client thread/ERROR]: Creative tab crashed while getting items. Some items from this tab will be missing from the item list. com.lambda.plentifulmisc.creative.CreativeTab@31092e1f
java.lang.ClassCastException: com.lambda.plentifulmisc.items.base.ItemEnergy$EnergyCapabilityProvider$1 cannot be cast to net.minecraftforge.energy.IEnergyStorage
at com.lambda.plentifulmisc.items.base.ItemEnergy.getSubItems(ItemEnergy.java:72) ~[itemEnergy.class:?]
at net.minecraft.creativetab.CreativeTabs.displayAllRelevantItems(CreativeTabs.java:301) ~[CreativeTabs.class:?]
at mezz.jei.plugins.vanilla.ingredients.ItemStackListFactory.create(ItemStackListFactory.java:33) [itemStackListFactory.class:?]
at mezz.jei.plugins.vanilla.VanillaPlugin.registerIngredients(VanillaPlugin.java:92) [VanillaPlugin.class:?]
at mezz.jei.JeiStarter.registerIngredients(JeiStarter.java:110) [JeiStarter.class:?]
at mezz.jei.JeiStarter.start(JeiStarter.java:36) [JeiStarter.class:?]
at mezz.jei.ProxyCommonClient.loadComplete(ProxyCommonClient.java:111) [ProxyCommonClient.class:?]
at mezz.jei.JustEnoughItems.loadComplete(JustEnoughItems.java:53) [JustEnoughItems.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:602) [FMLModContainer.class:?]
at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) [guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:243) [LoadController.class:?]
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:221) [LoadController.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) [guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:145) [LoadController.class:?]
at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:804) [Loader.class:?]
at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:331) [FMLClientHandler.class:?]
at net.minecraft.client.Minecraft.startGame(Minecraft.java:560) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:385) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
at GradleStart.main(GradleStart.java:26) [start/:?]
[19:40:01] [Client thread/WARN]: Found an empty subItem of net.minecraft.item.ItemAir@16a3d9a7
[19:40:01] [Client thread/WARN]: Caught a crash while getting sub-items of com.lambda.plentifulmisc.items.ItemBattery@4111c29d
java.lang.ClassCastException: com.lambda.plentifulmisc.items.base.ItemEnergy$EnergyCapabilityProvider$1 cannot be cast to net.minecraftforge.energy.IEnergyStorage
at com.lambda.plentifulmisc.items.base.ItemEnergy.getSubItems(ItemEnergy.java:72) ~[itemEnergy.class:?]
at mezz.jei.util.StackHelper.getSubtypes(StackHelper.java:242) [stackHelper.class:?]
at mezz.jei.plugins.vanilla.ingredients.ItemStackListFactory.addItemAndSubItems(ItemStackListFactory.java:66) [itemStackListFactory.class:?]
at mezz.jei.plugins.vanilla.ingredients.ItemStackListFactory.create(ItemStackListFactory.java:55) [itemStackListFactory.class:?]
at mezz.jei.plugins.vanilla.VanillaPlugin.registerIngredients(VanillaPlugin.java:92) [VanillaPlugin.class:?]
at mezz.jei.JeiStarter.registerIngredients(JeiStarter.java:110) [JeiStarter.class:?]
at mezz.jei.JeiStarter.start(JeiStarter.java:36) [JeiStarter.class:?]
at mezz.jei.ProxyCommonClient.loadComplete(ProxyCommonClient.java:111) [ProxyCommonClient.class:?]
at mezz.jei.JustEnoughItems.loadComplete(JustEnoughItems.java:53) [JustEnoughItems.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:602) [FMLModContainer.class:?]
at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) [guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:243) [LoadController.class:?]
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:221) [LoadController.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) [guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:145) [LoadController.class:?]
at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:804) [Loader.class:?]
at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:331) [FMLClientHandler.class:?]
at net.minecraft.client.Minecraft.startGame(Minecraft.java:560) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:385) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
at GradleStart.main(GradleStart.java:26) [start/:?]
[19:40:01] [Client thread/WARN]: Caught a crash while getting sub-items of com.lambda.plentifulmisc.items.ItemDrill@80cb5f6
java.lang.ClassCastException: com.lambda.plentifulmisc.items.base.ItemEnergy$EnergyCapabilityProvider$1 cannot be cast to net.minecraftforge.energy.IEnergyStorage
at com.lambda.plentifulmisc.items.base.ItemEnergy.getMaxEnergyStored(ItemEnergy.java:173) ~[itemEnergy.class:?]
at com.lambda.plentifulmisc.items.ItemDrill.addDrillStack(ItemDrill.java:323) ~[itemDrill.class:?]
at com.lambda.plentifulmisc.items.ItemDrill.getSubItems(ItemDrill.java:317) ~[itemDrill.class:?]
at mezz.jei.util.StackHelper.getSubtypes(StackHelper.java:242) [stackHelper.class:?]
at mezz.jei.plugins.vanilla.ingredients.ItemStackListFactory.addItemAndSubItems(ItemStackListFactory.java:66) [itemStackListFactory.class:?]
at mezz.jei.plugins.vanilla.ingredients.ItemStackListFactory.create(ItemStackListFactory.java:55) [itemStackListFactory.class:?]
at mezz.jei.plugins.vanilla.VanillaPlugin.registerIngredients(VanillaPlugin.java:92) [VanillaPlugin.class:?]
at mezz.jei.JeiStarter.registerIngredients(JeiStarter.java:110) [JeiStarter.class:?]
at mezz.jei.JeiStarter.start(JeiStarter.java:36) [JeiStarter.class:?]
at mezz.jei.ProxyCommonClient.loadComplete(ProxyCommonClient.java:111) [ProxyCommonClient.class:?]
at mezz.jei.JustEnoughItems.loadComplete(JustEnoughItems.java:53) [JustEnoughItems.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:602) [FMLModContainer.class:?]
at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) [guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:243) [LoadController.class:?]
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:221) [LoadController.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) [guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:145) [LoadController.class:?]
at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:804) [Loader.class:?]
at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:331) [FMLClientHandler.class:?]
at net.minecraft.client.Minecraft.startGame(Minecraft.java:560) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:385) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
at GradleStart.main(GradleStart.java:26) [start/:?]
[19:40:01] [Client thread/WARN]: Caught a crash while getting sub-items of com.lambda.plentifulmisc.items.ItemBattery@2a7eb66e
java.lang.ClassCastException: com.lambda.plentifulmisc.items.base.ItemEnergy$EnergyCapabilityProvider$1 cannot be cast to net.minecraftforge.energy.IEnergyStorage
at com.lambda.plentifulmisc.items.base.ItemEnergy.getSubItems(ItemEnergy.java:72) ~[itemEnergy.class:?]
at mezz.jei.util.StackHelper.getSubtypes(StackHelper.java:242) [stackHelper.class:?]
at mezz.jei.plugins.vanilla.ingredients.ItemStackListFactory.addItemAndSubItems(ItemStackListFactory.java:66) [itemStackListFactory.class:?]
at mezz.jei.plugins.vanilla.ingredients.ItemStackListFactory.create(ItemStackListFactory.java:55) [itemStackListFactory.class:?]
at mezz.jei.plugins.vanilla.VanillaPlugin.registerIngredients(VanillaPlugin.java:92) [VanillaPlugin.class:?]
at mezz.jei.JeiStarter.registerIngredients(JeiStarter.java:110) [JeiStarter.class:?]
at mezz.jei.JeiStarter.start(JeiStarter.java:36) [JeiStarter.class:?]
at mezz.jei.ProxyCommonClient.loadComplete(ProxyCommonClient.java:111) [ProxyCommonClient.class:?]
at mezz.jei.JustEnoughItems.loadComplete(JustEnoughItems.java:53) [JustEnoughItems.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:602) [FMLModContainer.class:?]
at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) [guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:243) [LoadController.class:?]
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:221) [LoadController.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) [guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:145) [LoadController.class:?]
at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:804) [Loader.class:?]
at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:331) [FMLClientHandler.class:?]
at net.minecraft.client.Minecraft.startGame(Minecraft.java:560) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:385) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
at GradleStart.main(GradleStart.java:26) [start/:?]

 

I still can't find a reason, I'm almost certain these can be cast, especially since the IDE isn't giving me an error :/

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Link to comment
Share on other sites

Oh I thought I had a spoiler with that :/

My Bad.

 

Here is the ItemEnergy:

public abstract class ItemEnergy extends ItemBase{

    private final int maxPower;
    private final int transfer;

    public ItemEnergy(int maxPower, int transfer, String name){
        super(name);
        this.maxPower = maxPower;
        this.transfer = transfer;

        this.setHasSubtypes(true);
        this.setMaxStackSize(1);
    }

    @Override
    public boolean getShareTag(){
        return true;
    }

    @Override
    public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool){
        if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage != null){
                NumberFormat format = NumberFormat.getInstance();
                list.add(format.format(storage.getEnergyStored())+"/"+format.format(storage.getMaxEnergyStored())+" Crystal Flux");
            }
        }
    }

    @Override
    @SideOnly(Side.CLIENT)
    public boolean hasEffect(ItemStack stack){
        return false;
    }

    @Override
    @SideOnly(Side.CLIENT)
    public void getSubItems(Item item, CreativeTabs tabs, NonNullList list){
        ItemStack stackFull = new ItemStack(this);
        if(stackFull.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stackFull.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage != null){
                this.setEnergy(stackFull, storage.getMaxEnergyStored());
                list.add(stackFull);
            }
        }

        ItemStack stackEmpty = new ItemStack(this);
        this.setEnergy(stackEmpty, 0);
        list.add(stackEmpty);
    }

    @Override
    public boolean showDurabilityBar(ItemStack itemStack){
        return true;
    }

    @Override
    public double getDurabilityForDisplay(ItemStack stack){
        if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage != null){
                double maxAmount = storage.getMaxEnergyStored();
                double energyDif = maxAmount-storage.getEnergyStored();
                return energyDif/maxAmount;
            }
        }
        return super.getDurabilityForDisplay(stack);
    }

    @Override
    public int getRGBDurabilityForDisplay(ItemStack stack){
        EntityPlayer player = PlentifulMisc.proxy.getCurrentPlayer();
        if(player != null && player.worldObj != null){
            float[] color = AssetUtil.getRGB(player.worldObj.getTotalWorldTime()%256);
            return MathHelper.rgb(color[0]/255F, color[1]/255F, color[2]/255F);
        }
        return super.getRGBDurabilityForDisplay(stack);
    }

    public void setEnergy(ItemStack stack, int energy){
        if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage instanceof CustomEnergyStorage){
                ((CustomEnergyStorage)storage).setEnergyStored(energy);
            }
        }
    }

    public int receiveEnergyInternal(ItemStack stack, int maxReceive, boolean simulate){
        if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage instanceof CustomEnergyStorage){
                ((CustomEnergyStorage)storage).receiveEnergyInternal(maxReceive, simulate);
            }
        }
        return 0;
    }

    public int extractEnergyInternal(ItemStack stack, int maxExtract, boolean simulate){
        if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage instanceof CustomEnergyStorage){
                ((CustomEnergyStorage)storage).extractEnergyInternal(maxExtract, simulate);
            }
        }
        return 0;
    }

    public int receiveEnergy(ItemStack stack, int maxReceive, boolean simulate){
        if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage != null){
                return storage.receiveEnergy(maxReceive, simulate);
            }
        }
        return 0;
    }

    public int extractEnergy(ItemStack stack, int maxExtract, boolean simulate){
        if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage != null){
                return storage.extractEnergy(maxExtract, simulate);
            }
        }
        return 0;
    }

    public int getEnergyStored(ItemStack stack){
        if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage != null){
                return storage.getEnergyStored();
            }
        }
        return 0;
    }

    public int getMaxEnergyStored(ItemStack stack){
        if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
            IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
            if(storage != null){
                return storage.getMaxEnergyStored();
            }
        }
        return 0;
    }

    @Override
    public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt){
        return new EnergyCapabilityProvider(stack, this);
    }

    private static class EnergyCapabilityProvider implements ICapabilityProvider{

        private final CustomEnergyStorage storage;

        public EnergyCapabilityProvider(final ItemStack stack, ItemEnergy item){
            this.storage = new CustomEnergyStorage(item.maxPower, item.transfer, item.transfer){
                @Override
                public int getEnergyStored(){
                    if(stack.hasTagCompound()){
                        return stack.getTagCompound().getInteger("Energy");
                    }
                    else{
                        return 0;
                    }
                }

                @Override
                public void setEnergyStored(int energy){
                    if(!stack.hasTagCompound()){
                        stack.setTagCompound(new NBTTagCompound());
                    }

                    stack.getTagCompound().setInteger("Energy", energy);
                }
            };
        }

        @Override
        public boolean hasCapability(Capability<?> capability, EnumFacing facing){
            return this.getCapability(capability, facing) != null;
        }

        @Nullable
        @Override
        public <T> T getCapability(Capability<T> capability, EnumFacing facing){
            if(capability == CapabilityEnergy.ENERGY){
                return (T)this.storage;
            }
            return null;
        }
    }
}

 

And the battery as an example, all energy Items are crashing:

public class ItemBattery extends ItemEnergy{

    public ItemBattery(String name, int capacity, int transfer){
        super(capacity, transfer, name);
        this.setMaxStackSize(1);
    }

    @Override
    public EnumRarity getRarity(ItemStack stack){
        return EnumRarity.RARE;
    }

    @Override
    public boolean hasEffect(ItemStack stack){
        return ItemUtil.isEnabled(stack);
    }

    @Override
    public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected){
        if(!world.isRemote && entity instanceof EntityPlayer && ItemUtil.isEnabled(stack)){
            EntityPlayer player = (EntityPlayer)entity;
            for(int i = 0; i < player.inventory.getSizeInventory(); i++){
                ItemStack slot = player.inventory.getStackInSlot(i);
                if(StackUtil.isValid(slot)){
                    int extractable = this.extractEnergy(stack, Integer.MAX_VALUE, true);
                    int received = 0;

                    if(slot.hasCapability(CapabilityEnergy.ENERGY, null)){
                        IEnergyStorage cap = slot.getCapability(CapabilityEnergy.ENERGY, null);
                        if(cap != null){
                            received = cap.receiveEnergy(extractable, false);
                        }
                    }

                    if(received > 0){
                        this.extractEnergy(stack, received, false);
                    }
                }
            }
        }
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand hand){
        if(!worldIn.isRemote && player.isSneaking()){
            ItemUtil.changeEnabled(player, hand);
            return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
        }
        return super.onItemRightClick(worldIn, player, hand);
    }

    @Override
    public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool){
        super.addInformation(stack, player, list, bool);
        list.add(StringUtil.localize("tooltip."+ModUtil.MOD_ID+".battery."+(ItemUtil.isEnabled(stack) ? "discharge" : "noDischarge")));
        list.add(StringUtil.localize("tooltip."+ModUtil.MOD_ID+".battery.changeMode"));
    }
}

 

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Link to comment
Share on other sites

I love that this is such a simple issue yet you keep posting things that have nothing to do with the issue.

The issue is that whatever you are RETURNING from getCapability is NOT following the capability contract.

This has nothing to do with calling/using the cap. It has everything to do with what you're returning.

So, whatever your implementation of getCapability is, show us.

com.lambda.plentifulmisc.items.base.ItemEnergy

Give us that entire class.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

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

    • I recently updated my mods and now my game is crashing on startup i tried adding them one at a time and couldn't find anything wrong and no crash log is being made the only thing I have is the debug log. If it helps I'm also using the curseforge launcher to launch the game. Minecraft version- 1.20.1 Forge Version-47.2.0 https://gist.github.com/keepinitreal247/d3105af6bb70e30f183505715113c61a
    • i managed to use another launcher but it still says logging in
    • i tried to open the modpack with multimc by importing it from Ftb and it gave me an error https://paste.ee/p/YDqWN
    • Hi, I'm trying to render a single quad in the world. I'm mixing into the ChestRenderer class. If I understand correctly, BufferSource#getBuffer opens a buffer according to the supplied RenderType (Quads with POSITION_COLOR in my case). Then, I can supply my vertices (a simple 1-block plane along the Z Axis) and close the buffer using BufferSource#endBatch for rendering. This is the code I'm using: @Inject(at = @At("TAIL"), method = "render(...)V") public void render(T blockEntity, float partialTick, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, int packedOverlay, CallbackInfo ci) { BlockPos pos = blockEntity.getBlockPos(); AABB box = new AABB(pos, pos.offset(1, 1, 1)); BufferSource buffer = Minecraft.getInstance().renderBuffers().bufferSource(); VertexConsumer consumer = buffer.getBuffer(RenderType.guiOverlay()); poseStack.pushPose(); poseStack.translate(-pos.getX(), -pos.getY(), -pos.getZ()); consumer.vertex(box.minX, box.maxY, box.minZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.maxY, box.maxZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.minY, box.maxZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.minY, box.minZ).color(1, 1, 1, 1).endVertex(); buffer.endBatch(RenderType.guiOverlay()); poseStack.popPose(); } However, the plane does not get rendered. However, if I replace those 4 vertices with a call to LevelRenderer#renderLineBox and set the RenderType to LINES, it works. Do I need something else to render planes other than the 4 edges of the quad? I used QUADS back in 1.8 where it was still the raw OpenGL type and it worked then. Or am I missing something else entirely? Thanks!
  • Topics

×
×
  • Create New...

Important Information

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