Jump to content

TallYate

Members
  • Posts

    141
  • Joined

  • Last visited

Everything posted by TallYate

  1. oh no, key is just what I called the packet
  2. Thank you. Everything works now! using CapabilityManager.INSTANCE.register() is not needed right?
  3. public class Packets { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel( new ResourceLocation(CrudeTechMod.MOD_ID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static int i=0; } This is the handler of the packet sent public static void handle(key msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity sender = ctx.get().getSender(); ItemStack feet = ctx.get().getSender().getItemStackFromSlot(EquipmentSlotType.FEET); feet.damageItem(1, sender, player -> {}); }); ctx.get().setPacketHandled(true); } This is where the packet is sent @SubscribeEvent public static void onInput(InputEvent.KeyInputEvent event) { Packets.INSTANCE.sendToServer(new key(0)); } I've removed some stuff to make it easier to read. Also, the handle is being run because I put a logger in it and it logged stuff
  4. Thank you. Everything works now! using CapabilityManager.INSTANCE.register() is not needed right?
  5. @Override public IntNBT serializeNBT() { int a = 0; getCapability(ModCapabilityEnergy.ENERGY, null).ifPresent(handler -> { a = handler.getEnergyStored(); }); return IntNBT.valueOf(a); } This doesn't work so I did that bad thing. Is there a better way that you know of?
  6. @Override public ICapabilitySerializable initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) { return new ICapabilitySerializable() { protected ModEnergyStorage storage = newStorage(); protected LazyOptional<ModEnergyStorage> storageHolder = LazyOptional.of(() -> storage); public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) { if (cap == ModCapabilityEnergy.ENERGY) { return storageHolder.cast(); } return LazyOptional.empty(); } public Integer a = null; public void setA(int x) { a = x; } @Override public IntNBT serializeNBT() { getCapability(ModCapabilityEnergy.ENERGY, null).ifPresent(handler -> { setA(handler.getEnergyStored()); }); return IntNBT.valueOf(a); } @Override public void deserializeNBT(INBT nbt) { getCapability(ModCapabilityEnergy.ENERGY, null).ifPresent(handler -> { handler.setEnergy(((IntNBT) nbt).getInt()); }); } }; } is this ok?
  7. Also I can't just put return IntNBT.valueOf(handler.getEnergyStored()); in the handler because it has to return nothing (void)
  8. Override public IntNBT serializeNBT() { IntNBT nbt = null; getCapability(ModCapabilityEnergy.ENERGY, null).ifPresent(handler -> { nbt = IntNBT.valueOf(handler.getEnergyStored()); }); return nbt; } That needs a serializeNBT and deserializeNBT. Do you know how I can make the handler return the nbt? Because "nbt cannot be assigned, since it is defined in an enclosing type"
  9. Do you know why the energy keeps resetting? I updated the github
  10. yeah that makes sense
  11. @Override public IntNBT serializeNBT() { return IntNBT.valueOf(this.energy); } @Override public void deserializeNBT(IntNBT nbt) { this.energy = ((IntNBT)nbt).getInt(); } thanks so I'm not supposed to use a modified version?
  12. yes because the IntNBT constructor is private so I copy pasted it and made it public
  13. actually @Override public ModIntNBT serializeNBT() { return new ModIntNBT(this.energy); } public class ModEnergyStorage implements ModIEnergyStorage, INBTSerializable<ModIntNBT> {
  14. ok I made it this: @Override public INBT serializeNBT() { return new ModIntNBT(this.energy); } (ModIntNBT is IntNBT but with a public constructor) What do you mean. It returns storageHolder, which holds a ModEnergyStorage public class ModEnergyStorage implements ModIEnergyStorage, INBTSerializable
  15. @SuppressWarnings("null") @Override public INBT serializeNBT() { DataOutput d = null; try { d.writeInt(this.energy); } catch (IOException e) { e.printStackTrace(); } IntNBT a = null; try { a.write(d); } catch (IOException e) { e.printStackTrace(); } return a; } @Override public void deserializeNBT(INBT nbt) { this.energy = ((IntNBT)nbt).getInt(); } I did serializeNBT and deserializeNBT, and added a thing so when I jump, I get 100 power. It works, but when I open a chest, the power resets https://github.com/TallYate/CrudeTechMod/tree/master/src/main/java/me/joshua/crudetechmod
  16. Cooked and uncooked foods are seperate items. You can use an uncooked tag (if it exists) in the recipe, but you can't get the result.
  17. @Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) { return new ICapabilityProvider() { protected ModEnergyStorage storage = newStorage(); protected LazyOptional<ModEnergyStorage> storageHolder = LazyOptional.of(() -> storage); public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) { if (cap == ModCapabilityEnergy.ENERGY) { return storageHolder.cast(); } return LazyOptional.empty(); } }; } How would I make this method in PowerArmor.java implement INBTSerializable, and attach it to the ItemStack? Or should PowerArmor.java implement INBTSerializable Also, do you know what I am supposed to put in here? CapabilityManager.INSTANCE.register(ModIEnergyStorage.class, ModCapabilityEnergy.ENERGY.getStorage(), ModEnergyStorage.class); The method register(Class<T>, Capability.IStorage<T>, Callable<? extends T>) in the type CapabilityManager is not applicable for the arguments (Class<ModIEnergyStorage>, Capability.IStorage<ModIEnergyStorage>, Class<ModEnergyStorage>)
  18. Oh I've been trying to test the energy using /give ...{Energy:500} public class ModCapabilityEnergy implements INBTSerializable { @CapabilityInject(ModIEnergyStorage.class) public static Capability<ModIEnergyStorage> ENERGY = null; public static void register() { CapabilityManager.INSTANCE.register(ModIEnergyStorage.class, new IStorage<ModIEnergyStorage>() { @Override public INBT writeNBT(Capability<ModIEnergyStorage> capability, ModIEnergyStorage instance, Direction side) { CrudeTechMod.log("writeNBT " + IntNBT.valueOf(instance.getEnergyStored())); return IntNBT.valueOf(instance.getEnergyStored()); } @Override public void readNBT(Capability<ModIEnergyStorage> capability, ModIEnergyStorage instance, Direction side, INBT nbt) { if (!(instance instanceof ModEnergyStorage)) throw new IllegalArgumentException("Can not deserialize to an instance that isn't the default implementation"); ((ModEnergyStorage)instance).energy = ((IntNBT)nbt).getInt(); CrudeTechMod.log("readNBT " + ((ModEnergyStorage)instance).energy); } }, () -> new ModEnergyStorage(1000)); } @Override public INBT serializeNBT() { return null; } @Override public void deserializeNBT(INBT nbt) { } } how would I do serializeNBT since there is no input Also I see that I'm supposed to do something like this CapabilityManager.INSTANCE.register(ModIEnergyStorage.class, ModCapabilityEnergy.ENERGY.getStorage(), ModEnergyStorage.class); but: The method register(Class<T>, Capability.IStorage<T>, Callable<? extends T>) in the type CapabilityManager is not applicable for the arguments (Class<ModIEnergyStorage>, Capability.IStorage<ModIEnergyStorage>, Class<ModEnergyStorage>) How do I write the capability to the ItemStack?
  19. I added the build.gradle Also, could you link me to the javadocs you're reading?
  20. I have put all the code on github https://github.com/TallYate/CrudeTechMod/tree/master/src/main/java/me/joshua/crudetechmod
  21. @Override @Nullable public CompoundNBT getShareTag(ItemStack stack) { CompoundNBT tag = stack.getOrCreateTag(); stack.getCapability(ModCapabilityEnergy.ENERGY, null).ifPresent(handler -> { tag.putInt("Energy", handler.getEnergyStored()); CrudeTechMod.log("getEnergy: " + handler.getEnergyStored()); }); CrudeTechMod.log("getShareTag end"); return tag; } Ok I made the capability more like forges and made a ModIEnergyStorage now getShareTag is being run, but not readShareTag Also, getShareTag is getting 0 energy
  22. They are not getting called at all maybe I need to implement something?
  23. Ok so I saw that <T> is based on the capability so I made a class that is basically the same as CapabilityEnergy public class ModEnergy { @CapabilityInject(ModEnergyStorage.class) public static Capability<ModEnergyStorage> ENERGY = null; public static void register() { CapabilityManager.INSTANCE.register(ModEnergyStorage.class, new IStorage<ModEnergyStorage>() { @Override public INBT writeNBT(Capability<ModEnergyStorage> capability, ModEnergyStorage instance, Direction side) { return IntNBT.valueOf(instance.getEnergyStored()); } @Override public void readNBT(Capability<ModEnergyStorage> capability, ModEnergyStorage instance, Direction side, INBT nbt) { if (!(instance instanceof EnergyStorage)) throw new IllegalArgumentException("Can not deserialize to an instance that isn't the default implementation"); instance.setEnergyStored(((IntNBT)nbt).getInt()); } }, () -> new ModEnergyStorage(10000, 1000, 1000)); } } but it uses ModEnergyStorage public class ModEnergyStorage extends EnergyStorage{ public ModEnergyStorage(int capacity, int maxReceive, int maxExtract) { super(capacity, maxReceive, maxExtract); } public void setEnergyStored(int x) { this.energy=x; } } for the extra method and this is the Item Class public class PowerArmor extends ArmorItem { public PowerArmor(IArmorMaterial materialIn, EquipmentSlotType slot, Properties builder) { super(materialIn, slot, builder); } private ModEnergyStorage newStorage() { return new ModEnergyStorage(10000, 1000, 1000); } @Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) { return new ICapabilityProvider() { protected ModEnergyStorage storage = newStorage(); protected LazyOptional<ModEnergyStorage> storageHolder = LazyOptional.of(() -> storage); public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) { if (cap == ModEnergy.ENERGY) { return storageHolder.cast(); } return LazyOptional.empty(); } }; } @Override public boolean shouldSyncTag() { return true; } @Override @Nullable public CompoundNBT getShareTag(ItemStack stack) { CompoundNBT tag = stack.getOrCreateTag(); stack.getCapability(ModEnergy.ENERGY, null).ifPresent(handler -> { tag.putInt("Energy", handler.getEnergyStored()); CrudeTechMod.log("getEnergy: " + handler.getEnergyStored()); }); return tag; } @Override public void readShareTag(ItemStack stack, @Nullable CompoundNBT nbt) { stack.getCapability(ModEnergy.ENERGY, null).ifPresent(handler -> { handler.setEnergyStored(nbt.getInt("Energy")); CrudeTechMod.log("readEnergy: " + handler.getEnergyStored()); }); } @Override public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) { IEnergyStorage cap = stack.getCapability(ModEnergy.ENERGY, null).orElseGet(null); if (cap != null) { String charge = Integer.toString(cap.getEnergyStored()); String capacity = Integer.toString(cap.getMaxEnergyStored()); tooltip.add(new TranslationTextComponent("Charge: " + charge + "/" + capacity)); } else { tooltip.add(new TranslationTextComponent("missing capability")); } } }
  24. I put loggers in them, but nothing is logged. Is this normal?
×
×
  • Create New...

Important Information

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