Jump to content

Ghost20000

Members
  • Posts

    16
  • Joined

  • Last visited

Everything posted by Ghost20000

  1. Thank you so much!!! Would've never thought that was the case, I'd assume that stuff like buckets have special creative mode checks, but I guess not! Will mark as solved!
  2. Oh my god I'm so stupid, sorry about that. Here you go. Can you tell I sent that at 2 AM?
  3. Alright, after updating to 1.16 and enduring even more weirdness, I've decided to upload my code to github. If you have the time, I'd love if you looked over it. Thanks a lot!
  4. Could it somehow be a client-server desync issue? I've been trying to figure it out for a while now...
  5. Oh, is there a simpler way to store data in itemstacks? I'm not very proficient with forge (as you can probably tell lol). It sets entityType, but when read/writeNBT are called it's back to null.
  6. I'm trying to add a custom capability to an item that will store a string representing an EntityType, but it seems like the NBT functions keep overriding it! Am I missing something obvious here? // Class that stores actual data for capability. public class Pet { private EntityType<?> entityType; public Pet() { this.entityType = null; } public String getEntityTypeString() { if (this.entityType == null) { return ""; } return EntityType.getKey(this.entityType).toString(); } public EntityType<?> getEntityType() { return this.entityType; } public void setEntityType(EntityType<?> entityType) { this.entityType = entityType; Datamine.LOGGER.debug("setEntityType type: " + this.entityType); } public void setEntityType(String entityType) { this.entityType = EntityType.byKey(entityType).orElse(null); Datamine.LOGGER.debug("setEntityType string: " + this.entityType); } public void releaseEntity() { this.entityType = null; } public static class PetStorage implements IStorage<Pet> { @Override public void readNBT(Capability<Pet> capability, Pet instance, Direction side, INBT nbt) { if (nbt instanceof CompoundNBT) { instance.setEntityType(((CompoundNBT) nbt).getString("type")); } } @Override public INBT writeNBT(Capability<Pet> capability, Pet instance, Direction side) { CompoundNBT nbt = new CompoundNBT(); nbt.putString("type", instance.getEntityTypeString()); return nbt; } } } public class PetItem extends Item { public PetItem(Item.Properties properties) { super(properties); } @Override public boolean itemInteractionForEntity(ItemStack stack, PlayerEntity playerIn, LivingEntity target, Hand hand) { if (target.world.isRemote) { return false; } Pet pet = stack.getCapability(PetCapability.CAPABILITY_PET).orElse(null); if (pet == null) { return false; } if (target instanceof AnimalEntity) { Datamine.LOGGER.debug("AnimalEntity: " + target.getType()); pet.setEntityType(target.getType()); return true; } return false; } @Override public ActionResultType onItemUse(ItemUseContext context) { Datamine.LOGGER.debug("onItemUse: " + context.getItem().getCapability(PetCapability.CAPABILITY_PET).orElse(null).getEntityType()); return super.onItemUse(context); } @Override public ICapabilityProvider initCapabilities(ItemStack stack, CompoundNBT nbt) { return new PetCapabilityProvider(); } } public class PetCapabilityProvider implements ICapabilitySerializable<INBT> { private final Pet pet = new Pet(); private final LazyOptional<Pet> petOptional = LazyOptional.of(() -> pet); @Override public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) { return petOptional.cast(); } @Override public INBT serializeNBT() { return PetCapability.CAPABILITY_PET.writeNBT(this.pet, null); } @Override public void deserializeNBT(INBT nbt) { PetCapability.CAPABILITY_PET.readNBT(this.pet, null, nbt); } } public class PetCapability { @CapabilityInject(Pet.class) public static Capability<Pet> CAPABILITY_PET = null; public static void register() { CapabilityManager.INSTANCE.register(Pet.class, new Pet.PetStorage(), () -> new Pet()); } } Thanks in advance!
  7. 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!
  8. There seems to be a lot of conflicting information out there on creating capabilities. On what classes/interfaces you need, what needs to implement what, whether serializeNBT should call writeNBT or the other way around, etc. I understand there's probably a lot of ways to create a capability, but I just want the simplest possible thing. I have a capability which I only want 1 item to use. It'll be able to store an EntityType, and serialize it into a String or deserialize it from a String when needed. Right now I have 2 classes, Pet and PetCapability: public class Pet implements INBTSerializable<CompoundNBT> { private EntityType<?> entityType; public Pet() { this.entityType = null; } @Override public CompoundNBT serializeNBT() { CompoundNBT result = new CompoundNBT(); String entityTypeString = EntityType.getKey(this.entityType).toString(); result.putString("entityType", entityTypeString); return result; } @Override public void deserializeNBT(CompoundNBT nbt) { if (nbt.contains("entityType")) { String entityTypeString = nbt.getString("entityType"); this.entityType = EntityType.byKey(entityTypeString).get(); } } } 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) { instance.deserializeNBT((CompoundNBT) nbt); } @Override public INBT writeNBT(Capability<Pet> capability, Pet instance, Direction side) { return instance.serializeNBT(); } } } Where do I go from here? I need a provider to attach to capability to the item right? Are my classes ok? Am I doing something where I shouldn't be doing it? Thanks!
  9. Hi, I'm trying to make a simple item that, when you hold it in your main hand and right click on a living entity, will kill the entity and spawn an entity of the same type in your location. So if you right click on a pig, the pig will die and a second, new pig will spawn on you. It seems to me that making such a simple item would be incredibly complicated with forge. You'd need to raytrace on the client-side to find the mob, tell the server about the mob through networking, kill the mob, then spawn a new one. Is there something I'm missing? Do you really need to set up networking for such a simple item? How would you do this? Thank you!
  10. Ok, I'll start to follow the tutorial less and look at the example mod more. Thanks!
  11. Wait, I'm confused. Why do I need to set the unlocalized name to the registry name?
  12. I don't think so, I've looked at other mods and it doesn't look like I need more than the 2 jsons I have...
  13. Hello! I am following this tutorial and for some reason the block's texture isn't showing up (not placed or in inventory). Here is a small temporary git repo of my code. Can anyone help?
  14. I basically spammed it for a while until it downloaded everything, wtf is going on.
  15. I've been trying to fix it for hours! Should I just wait until they fix it?
  16. Hello! I'm trying to run setupDecompWorkspace, but it keeps failing. Here is the log: FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring root project 'First Mod'. > Could not resolve all dependencies for configuration ':classpath'. > Could not download ForgeGradle.jar (net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT) > Could not close resource 'http://files.minecraftforge.net/maven/net/minecraftforge/gradle/ForgeGradle/2.3-SNAPSHOT/ForgeGradle-2.3-20180601.071940-30.jar'. > Premature end of Content-Length delimited message body (expected: 12535717; received: 76947 * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Can anyone help?
×
×
  • Create New...

Important Information

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