• Recently Browsing

    No registered users viewing this page.

  • Posts

    • Hi, I'm currently trying to learn how to use capabilities. My requirement is as follows: I have a "relic" item (max stack size 1) in my player's inventory. Whenever a certain event happens (for now I'm using breaking a stone block as prototype), the "experience" of the item is increased. The experience must only be increased if the item is actually in the player's inventory, not just when it exists somewhere in the world e.g. a chest or on the ground.   My problem is that if I drop the item, it continues to gain experience when I break more blocks. When I try to debug and look at the player's inventory, I can see that after dropping the item the ItemStack in that slot is an Air item - but its delegate is my "relic" item, and it also apparently has inherited my "experience" capability from the dropped item??   Could anybody please help me to understand: what this delegate property is, how it is used and/or how it is affecting this situation why the Air itemstack has also been given my item's capabilities? (shouldn't my instanceof check stop that?)   I'm going to go ahead and assume I've set up the boilerplate capability bits&bobs wrong in some way, too (all the tutorials I could find were either out of date, or only dealt with simple cases for blocks/entities/tileentities and not items) - so if anybody could point out where that'd be great too   Thanks in advance!   (Note that because I have the following, this issue only occurs if I've got more than one of the item in the inventory and then dropped one of them before breaking the stone block; both the dropped and still-held relics continue to gain experience) if (player.inventory.hasAny(Set.of(MyMod.MINING_RELIC_ITEM.get())))   Relevant classes are as follows:   public class MiningRelicItem extends Item { ... @Override public ICapabilityProvider initCapabilities(ItemStack itemStack, @Nullable CompoundNBT nbt) { // To try to stop passing the capability to an Air item if our item is no longer in the inventory? Bah, didn't seem to help if (!itemStack.isEmpty()) { MyMod.LOGGER.info("MagicRelicItem just provided some kind of capability"); return new RelicExperienceCapabilityProvider(); } return null; } } public class CapabilityHandler { public static final ResourceLocation RELIC_EXP_CAP = new ResourceLocation(MyMod.MODID, "relic_exp"); @SubscribeEvent public void attachCapability(AttachCapabilitiesEvent<Item> event) { Item item = event.getObject().asItem(); if (item instanceof MiningRelicItem) { event.addCapability(RELIC_EXP_CAP, new RelicExperienceCapabilityProvider()); } } } public class RelicExperienceCapabilityProvider implements ICapabilitySerializable<INBT> { @CapabilityInject(IRelicExperienceCapability.class) public static Capability<IRelicExperienceCapability> RELIC_EXP_CAPABILITY = null; private final RelicExperienceCapability relicExperienceCapability = new RelicExperienceCapability(); private final RelicExperienceStorage relicExperienceStorage = new RelicExperienceStorage(); @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { if (cap == RELIC_EXP_CAPABILITY) { return (LazyOptional<T>) LazyOptional.of(() -> relicExperienceCapability); } return LazyOptional.empty(); } @Override public INBT serializeNBT() { return relicExperienceStorage.writeNBT(RELIC_EXP_CAPABILITY, relicExperienceCapability, null); } @Override public void deserializeNBT(INBT nbt) { relicExperienceStorage.readNBT(RELIC_EXP_CAPABILITY, relicExperienceCapability, null, nbt); } } @Mod.EventBusSubscriber(modid = MyMod.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class ClientEvents { @SubscribeEvent public static void onBlockDestroyed(BlockEvent.BreakEvent breakEvent) { if (!breakEvent.isCanceled()) { if (breakEvent.getState().getBlock() == Blocks.STONE) { MyMod.LOGGER.info("Stone block broken."); PlayerEntity player = breakEvent.getPlayer(); if (player.inventory.hasAny(Set.of(MyMod.MINING_RELIC_ITEM.get()))) { MyMod.LOGGER.info("The dude is holding a relic"); final List<ItemStack> playerItems = Stream .concat(player.inventory.mainInventory.stream(), player.inventory.offHandInventory.stream()) .collect(Collectors.toList()); for (ItemStack i : playerItems) { IRelicExperienceCapability relicExperienceCapability = i.getCapability(RelicExperienceCapabilityProvider.RELIC_EXP_CAPABILITY).orElse(null); if (relicExperienceCapability != null) { relicExperienceCapability.addExp(5); MyMod.LOGGER.info("I just added 5 exp to a relic..."); MyMod.LOGGER.info(String.format("Current exp for this relic is: %d", relicExperienceCapability.getExp())); } } } } } } }  
    • I have this issue please help me : https://pastebin.com/irqaHPvF or without pastebin   openjdk version "1.8.0_242" OpenJDK Runtime Environment (build 1.8.0_242-b08) OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode) :/home/container$ java -Xms128M -Xmx2048M -Dterminal.jline=false -Dterminal.ansi=true -jar server.jar [14:46:10] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.FMLServerTweaker [14:46:10] [main/INFO] [LaunchWrapper]: Using primary tweak class name cpw.mods.fml.common.launcher.FMLServerTweaker [14:46:10] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLServerTweaker [14:46:10] [main/INFO] [FML]: Forge Mod Loader version 7.99.40.1614 for Minecraft 1.7.10 loading [14:46:10] [main/INFO] [FML]: Java is OpenJDK 64-Bit Server VM, version 1.8.0_242, running on Linux:amd64:4.15.0-106-generic, installed at /usr/local/openjdk-8 [14:46:11] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker [14:46:11] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.FMLDeobfTweaker [14:46:11] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker [14:46:11] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker [14:46:11] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper [14:46:14] [main/INFO] [FML]: Found valid fingerprint for Minecraft Forge. Certificate fingerprint e3c3d50c7c986df74c645c0ac54639741c90a557 [14:46:14] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper [14:46:14] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLDeobfTweaker [14:46:16] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.TerminalTweaker [14:46:16] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.TerminalTweaker [14:46:16] [main/WARN] [LaunchWrapper]: Problem loading class java.util.zip.ZipException: invalid LOC header (bad signature) at java.util.zip.ZipFile.read(Native Method) ~[?:1.8.0_242] at java.util.zip.ZipFile.access$1400(ZipFile.java:60) ~[?:1.8.0_242] at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:734) ~[?:1.8.0_242] at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(ZipFile.java:434) ~[?:1.8.0_242] at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158) ~[?:1.8.0_242] at java.io.FilterInputStream.read(FilterInputStream.java:133) ~[?:1.8.0_242] at net.minecraft.launchwrapper.LaunchClassLoader.readFully(LaunchClassLoader.java:301) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.LaunchClassLoader.getClassBytes(LaunchClassLoader.java:373) [launchwrapper-1.12.jar:?] at cpw.mods.fml.common.patcher.ClassPatchManager.getPatchedResource(ClassPatchManager.java:60) [server.jar:?] at cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.findAndMergeSuperMaps(FMLDeobfuscatingRemapper.java:342) [server.jar:?] at cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.mergeSuperMaps(FMLDeobfuscatingRemapper.java:375) [server.jar:?] at cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.findAndMergeSuperMaps(FMLDeobfuscatingRemapper.java:349) [server.jar:?] at cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.getMethodMap(FMLDeobfuscatingRemapper.java:322) [server.jar:?] at cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.mapMethodName(FMLDeobfuscatingRemapper.java:295) [server.jar:?] at org.objectweb.asm.commons.RemappingMethodAdapter.doVisitMethodInsn(Unknown Source) [asm-all-5.0.3.jar:5.0.3] at org.objectweb.asm.commons.RemappingMethodAdapter.visitMethodInsn(Unknown Source) [asm-all-5.0.3.jar:5.0.3] at org.objectweb.asm.ClassReader.a(Unknown Source) [asm-all-5.0.3.jar:5.0.3] at org.objectweb.asm.ClassReader.b(Unknown Source) [asm-all-5.0.3.jar:5.0.3] at org.objectweb.asm.ClassReader.accept(Unknown Source) [asm-all-5.0.3.jar:5.0.3] at org.objectweb.asm.ClassReader.accept(Unknown Source) [asm-all-5.0.3.jar:5.0.3] at cpw.mods.fml.common.asm.transformers.DeobfuscationTransformer.transform(DeobfuscationTransformer.java:37) [server.jar:?] at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:279) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:176) [launchwrapper-1.12.jar:?] at java.lang.ClassLoader.loadClass(ClassLoader.java:419) [?:1.8.0_242] at java.lang.ClassLoader.loadClass(ClassLoader.java:352) [?:1.8.0_242] at java.lang.Class.forName0(Native Method) [?:1.8.0_242] at java.lang.Class.forName(Class.java:348) [?:1.8.0_242] at net.minecraft.launchwrapper.Launch.launch(Launch.java:131) [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_242] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_242] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_242] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_242] at cpw.mods.fml.relauncher.ServerLaunchWrapper.run(ServerLaunchWrapper.java:43) [server.jar:?] at cpw.mods.fml.relauncher.ServerLaunchWrapper.main(ServerLaunchWrapper.java:12) [server.jar:?] [14:46:16] [main/ERROR] [LaunchWrapper]: Unable to launch java.lang.ClassNotFoundException: net.minecraft.server.MinecraftServer at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191) ~[launchwrapper-1.12.jar:?] at java.lang.ClassLoader.loadClass(ClassLoader.java:419) ~[?:1.8.0_242] at java.lang.ClassLoader.loadClass(ClassLoader.java:352) ~[?:1.8.0_242] at java.lang.Class.forName0(Native Method) ~[?:1.8.0_242] at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_242] at net.minecraft.launchwrapper.Launch.launch(Launch.java:131) [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_242] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_242] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_242] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_242] at cpw.mods.fml.relauncher.ServerLaunchWrapper.run(ServerLaunchWrapper.java:43) [server.jar:?] at cpw.mods.fml.relauncher.ServerLaunchWrapper.main(ServerLaunchWrapper.java:12) [server.jar:?] Caused by: java.lang.ArrayIndexOutOfBoundsException: 6 at org.objectweb.asm.ClassReader.readShort(Unknown Source) ~[asm-all-5.0.3.jar:5.0.3] at org.objectweb.asm.ClassReader.<init>(Unknown Source) ~[asm-all-5.0.3.jar:5.0.3] at org.objectweb.asm.ClassReader.<init>(Unknown Source) ~[asm-all-5.0.3.jar:5.0.3] at cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.findAndMergeSuperMaps(FMLDeobfuscatingRemapper.java:345) ~[server.jar:?] at cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.mergeSuperMaps(FMLDeobfuscatingRemapper.java:375) ~[server.jar:?] at cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.findAndMergeSuperMaps(FMLDeobfuscatingRemapper.java:349) ~[server.jar:?] at cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.getMethodMap(FMLDeobfuscatingRemapper.java:322) ~[server.jar:?] at cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.mapMethodName(FMLDeobfuscatingRemapper.java:295) ~[server.jar:?] at org.objectweb.asm.commons.RemappingMethodAdapter.doVisitMethodInsn(Unknown Source) ~[asm-all-5.0.3.jar:5.0.3] at org.objectweb.asm.commons.RemappingMethodAdapter.visitMethodInsn(Unknown Source) ~[asm-all-5.0.3.jar:5.0.3] at org.objectweb.asm.ClassReader.a(Unknown Source) ~[asm-all-5.0.3.jar:5.0.3] at org.objectweb.asm.ClassReader.b(Unknown Source) ~[asm-all-5.0.3.jar:5.0.3] at org.objectweb.asm.ClassReader.accept(Unknown Source) ~[asm-all-5.0.3.jar:5.0.3] at org.objectweb.asm.ClassReader.accept(Unknown Source) ~[asm-all-5.0.3.jar:5.0.3] at cpw.mods.fml.common.asm.transformers.DeobfuscationTransformer.transform(DeobfuscationTransformer.java:37) ~[server.jar:?] at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:279) ~[launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:176) ~[launchwrapper-1.12.jar:?] ... 12 more A problem occurred running the Server launcher.[14:46:16] [main/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:749]: java.lang.reflect.InvocationTargetException [14:46:16] [main/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:749]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [14:46:16] [main/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:749]: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [14:46:16] [main/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:749]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [14:46:16] [main/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:749]: at java.lang.reflect.Method.invoke(Method.java:498) [14:46:16] [main/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:749]: at cpw.mods.fml.relauncher.ServerLaunchWrapper.run(ServerLaunchWrapper.java:43) [14:46:16] [main/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:749]: at cpw.mods.fml.relauncher.ServerLaunchWrapper.main(ServerLaunchWrapper.java:12) [14:46:16] [main/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:749]: Caused by: cpw.mods.fml.relauncher.FMLSecurityManager$ExitTrappedException [14:46:16] [main/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:749]: at cpw.mods.fml.relauncher.FMLSecurityManager.checkPermission(FMLSecurityManager.java:25) [14:46:16] [main/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:749]: at java.lang.SecurityManager.checkExit(SecurityManager.java:761) [14:46:16] [main/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:749]: at java.lang.Runtime.exit(Runtime.java:108) [14:46:16] [main/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:749]: at java.lang.System.exit(System.java:973) [14:46:16] [main/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:749]: at net.minecraft.launchwrapper.Launch.launch(Launch.java:138) [14:46:16] [main/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:749]: at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [14:46:16] [main/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:749]: ... 6 more [MChost Daemon] Server marked as OFF [MChost Daemon] ---------- Detected server process in a crashed state! ---------- [MChost Daemon] Exit Code: 1 [MChost Daemon] Out of Memory: false [MChost Daemon] Error Response: [MChost Daemon] Aborting automatic reboot due to crash within the last 60 seconds.
  • Topics

  • Who's Online (See full list)