• Posts

    • Plugins? Is your server using SpongeForge? See the FAQ entry in that case.
    • I ended up solving this with some help from the MinecraftByExample repo. public class Pet { private EntityType<?> entityType; public Pet() { this.entityType = null; } public String getEntityTypeString() { if (this.entityType == null) { return null; } return EntityType.getKey(this.entityType).toString(); } public EntityType<?> getEntityType() { return this.entityType; } public void setEntityType(String entityType) { this.entityType = EntityType.byKey(entityType).get(); } public void setEntityType(EntityType<?> entityType) { this.entityType = entityType; } } public class PetCapability { @CapabilityInject(Pet.class) public static Capability<Pet> CAPABILITY_PET = null; public static void register() { CapabilityManager.INSTANCE.register(Pet.class, new PetStorage(), () -> new Pet()); } public static class PetStorage implements IStorage<Pet> { @Override public void readNBT(Capability<Pet> capability, Pet instance, Direction side, INBT nbt) { if (nbt instanceof CompoundNBT && ((CompoundNBT) nbt).contains("type")) { String entityType = ((CompoundNBT) nbt).getString("type"); instance.setEntityType(entityType); } } @Override public INBT writeNBT(Capability<Pet> capability, Pet instance, Direction side) { CompoundNBT result = new CompoundNBT(); String entityTypeString = instance.getEntityTypeString(); if (entityTypeString != null) { result.putString("type", entityTypeString); } return result; } } } public class PetCapabilityProvider implements ICapabilitySerializable<INBT> { private Pet pet = new Pet(); @Override public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) { if (cap == PetCapability.CAPABILITY_PET) { return (LazyOptional<T>) LazyOptional.of(() -> pet); } return LazyOptional.empty(); } @Override public INBT serializeNBT() { return PetCapability.CAPABILITY_PET.writeNBT(pet, null); } @Override public void deserializeNBT(INBT nbt) { PetCapability.CAPABILITY_PET.readNBT(pet, null, nbt); } } Then register in the FMLCommonSetupEvent in your mod event subscriber and in your item class add the following function: @Override public ICapabilityProvider initCapabilities(ItemStack stack, CompoundNBT nbt) { return new PetCapabilityProvider(); } Whenever you want to access the capability, just get the ItemStack and call GetCapability on it. If it's null, something went wrong, but if it's an instance of Pet, you can access it!
    • You need an interface to make a capability, I'd say you should call it IPet, Pet should implement it and you should pass in IPet in @CapabilityInject and the first parameter of register. The interface should look something like this with what you're currently doing:  public interface IExample { EntityType<?> getEntityType(); void setEntityType(EntityType<?> type); } I strongly recommend you use generics instead if you can, something like this: public interface IExample { <T extends Entity> EntityType<T> getEntityType(); <T extends Entity> void setEntityType(EntityType<T> type); } Ping me or something next post, I'll help you out if I can. Edit: Oh come on, solved as I was posting.
    • This server is mine and I didn't put mods on it, I put only plugins
    • Can you verify with the server owner if they have mods installed on their server? A server will refuse the connection from a client if that client does not have the same mods as the server. (of course, excluding the client- and server-only mods)
  • Topics

  • Who's Online (See full list)