Jump to content

Search the Community

Showing results for tags 'capabilities'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Minecraft Forge
    • Releases
    • Support & Bug Reports
    • Suggestions
    • General Discussion
  • Mod Developer Central
    • Modder Support
    • User Submitted Tutorials
  • Non-Forge
    • Site News (non-forge)
    • Minecraft General
    • Off-topic
  • Forge Mods
    • Mods

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


XMPP/GTalk


Gender


URL


Location


ICQ


AIM


Yahoo IM


MSN Messenger


Personal Text

Found 7 results

  1. I made a few custom capabilities for my mod and I'm trying to use the player clone event to make the capabilities persistent between deaths. If I look at the debugger I can see that the oldPlayer variable has the capabilities and the correct values attached to it. But when I try to use getCapability, it just returns a LazyOptional with null as you would expect when it is not found. Also the ifPresent(...) method does not execute the code inside. I have used the getCapability multiple times already in other parts and never ran into any problem. For example, I've supplied a debug 3 variable from my LivingEntity death event (this part is only active on players) and this one works just fine and returns the capability as you would expect. Does anyone see anything I did wrong or a reason as to why it doesn't work and how to fix this issue? Edit: Solved: I needed to reviveCaps() before I could get them. @SubscribeEvent public void onPlayerClone(PlayerEvent.Clone event) { Player oldPlayer = event.getOriginal(); Player newPlayer = event.getEntity(); var debug = oldPlayer.getCapability(UpgradeDataProvider.UPGRADE_DATA); // This returns a LazyOptional with supplier null var debug2 = newPlayer.getCapability(UpgradeDataProvider.UPGRADE_DATA); // This returns a LazyOptional with a valid supplier and works fine oldPlayer.getCapability(PlayerDataProvider.PLAYER_DATA).ifPresent(oldStore -> { newPlayer.getCapability(PlayerDataProvider.PLAYER_DATA).ifPresent(newStore -> { newStore.copyFrom(oldStore); }); }); // this does absolutely nothing oldPlayer.getCapability(UpgradeDataProvider.UPGRADE_DATA).ifPresent(oldStore -> { newPlayer.getCapability(UpgradeDataProvider.UPGRADE_DATA).ifPresent(newStore -> { newStore.copyFrom(oldStore); }); }); // this doesn't either oldPlayer.getCapability(CurrencyDataProvider.CURRENCY_DATA).ifPresent(oldStore -> { newPlayer.getCapability(CurrencyDataProvider.CURRENCY_DATA).ifPresent(newStore -> { newStore.copyFrom(oldStore); }); }); } // neither does this In the LivingDeath event: var debug3 = player.getCapability(UpgradeDataProvider.UPGRADE_DATA); // This works just fine and returns the capability as expected.
  2. I currently have a capability and everything I want to do with it setup correctly. I want to make it clear my capability works, persists through death updates correctly and all that. What I'm trying to do is force the NBT data to save at a time besides exiting the game/dying. I've tried to look at the super methods for saving but I can't grasp how exactly it's functioning. The reason I'm trying to do this in the first place is that I'm trying to make my mod-compatible with a modelling mod known as "Figura", and it's able to read the NBT data attached to a player for use in players models. Currently players can't actually read the new values because it doesn't save to NBT until death or exit.
  3. Hello. I want to put every dimension on it's own server and establish player interaction between them. Is there any mod already or way to send data from one server to another?
  4. Hello! So, I'm having a problem where I always lose the data when I exit and rejoin a world, I think my problem is with the deserialization and serialization of the NBT, but i'm not sure and i don't know how to fix it. I think my error is somewhere here: import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityManager; import net.minecraftforge.common.capabilities.CapabilityToken; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.util.INBTSerializable; import net.minecraftforge.common.util.LazyOptional; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class PlayerGodParentProvider implements ICapabilityProvider, INBTSerializable<CompoundTag> { public static Capability<PlayerGodParent> PLAYER_GOD_PARENT = CapabilityManager.get(new CapabilityToken<PlayerGodParent>() { }); private PlayerGodParent godParent = null; private final LazyOptional<PlayerGodParent> optional = LazyOptional.of(this::createPlayerGodParent); private PlayerGodParent createPlayerGodParent() { if(this.godParent == null) { this.godParent = new PlayerGodParent(); } return this.godParent; } @Override public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { if(cap == PLAYER_GOD_PARENT) { return optional.cast(); } return LazyOptional.empty(); } @Override public CompoundTag serializeNBT() { CompoundTag nbt = new CompoundTag(); createPlayerGodParent().saveNBTData(nbt); return nbt; } @Override public void deserializeNBT(CompoundTag nbt) { createPlayerGodParent().loadNBTData(nbt); } } The whole repo is here: https://github.com/P3terD/myths-mod/tree/main
  5. I am Attempting to register a custom capability to NBT running (mostly) off of a tutorial and failing miserably. I have spoken with someone familiar with Java, and both they and my IDE concur that there is no outward problem with my code, so I believe there is a problem with my implementation (likely caused by a mixture of ignorance and new versions. Github linked, if anyone is able to help, that would be greatly appreciated https://github.com/Zebralear/SoulCraft
  6. I'm trying to use Capabilities to add a kind of player currency. But I can't get it to work. I've followed a couple of tutorials on it pretty much exactly, but when I try to render the amount on the corner of the screen it's always null. I apologise if this post is large, I guess the site appearance just changed and there's no preview option? ScreenTag (the gui with currency amount that's trying to be rendered) private Minecraft mc; private final int colour = new Color(255, 85, 255).getRGB(); public ScreenTag(Minecraft mc) { this.mc = mc; } @SubscribeEvent public void onRenderGui(RenderGameOverlayEvent.Post event) { if (event.getType() != ElementType.EXPERIENCE) { return; } IEchoesCapability echoes = mc.thePlayer.getCapability(EchoesManager.ECHOES, null); // if (echoes == null) return; // <- This always fires. Why is this always null? // drawCenteredString(mc.fontRendererObj, TextFormatting.RED + "Blood Echoes: " + TextFormatting.WHITE + echoes.getEchoes(), 20, 20, colour); drawCenteredString(mc.fontRendererObj, TextFormatting.RED + "Insight: " + TextFormatting.WHITE + echoes.getInsight(), 20, 50, colour); } IEchoesCapability (I don't think I'd need to post the Echoes class that implements this interface since it's just variable setters/getters) public boolean useEchoes(int amount); public void addEchoes(int amount); public void setEchoes(int amount); public int getEchoes(); // public boolean useInsight(int amount); public void addInsight(int amount); public void setInsight(int amount); public int getInsight(); EchoesStorage implements IStorage<IEchoesCapability> @Override public NBTBase writeNBT(Capability<IEchoesCapability> capability, IEchoesCapability instance, EnumFacing side) { NBTTagCompound nbt = new NBTTagCompound(); nbt.setInteger("echoes", instance.getEchoes()); nbt.setInteger("insight", instance.getInsight()); return nbt; } @Override public void readNBT(Capability<IEchoesCapability> capability, IEchoesCapability instance, EnumFacing side, NBTBase nbt) { instance.setEchoes(((NBTTagCompound) nbt).getInteger("echoes")); instance.setInsight(((NBTTagCompound) nbt).getInteger("insight")); } Capabilities (event handler) public static final ResourceLocation ECHOES = new ResourceLocation(Main.MODID, "echoes"); @SubscribeEvent public void attach(AttachCapabilitiesEvent.Entity event) { if (event.getEntity() instanceof EntityPlayer) { event.addCapability(ECHOES, new EchoesManager()); } } @SubscribeEvent public void clone(PlayerEvent.Clone event) { if (event.isWasDeath()) { IEchoesCapability original = event.getOriginal().getCapability(EchoesManager.ECHOES, null); IEchoesCapability cloned = event.getEntityPlayer().getCapability(EchoesManager.ECHOES, null); cloned.setEchoes(original.getEchoes()); cloned.setInsight(original.getInsight()); } } EchoesManager implements ICapabilitySerializable<NBTBase> @CapabilityInject(IEchoesCapability.class) public static final Capability<IEchoesCapability> ECHOES = null; private IEchoesCapability instance = ECHOES.getDefaultInstance(); @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { return capability == ECHOES; } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { return capability == ECHOES ? ECHOES.<T>cast(instance) : null; } @Override public NBTBase serializeNBT() { return ECHOES.getStorage().writeNBT(ECHOES, instance, null); } @Override public void deserializeNBT(NBTBase nbt) { ECHOES.getStorage().readNBT(ECHOES, instance, null, nbt); } inside Main class @EventHandler public void init(FMLInitializationEvent event) { proxy.init(); MinecraftForge.EVENT_BUS.register(new ScreenTag(Minecraft.getMinecraft())); } and inside ServerProxy public void init() { CapabilityManager.INSTANCE.register(IEchoesCapability.class, new EchoesStorage(), Echoes.class); MinecraftForge.EVENT_BUS.register(new Capabilities()); } I think that should be everything relevant. The whole mod kinda depends on this working properly, so could someone tell me what exactly I'm doing wrong?
×
×
  • Create New...

Important Information

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