Jump to content

Danieldrd

Members
  • Posts

    3
  • Joined

  • Last visited

Danieldrd's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. @Override public void read(CompoundNBT tag) { CompoundNBT invTag = tag.getCompound("inv"); getHandler().deserializeNBT(invTag); super.read(tag); } @Override public CompoundNBT write(CompoundNBT tag) { CompoundNBT compound = getHandler().serializeNBT(); tag.put("inv", compound); return super.write(tag); } private ItemStackHandler getHandler() { if (handler == null) { handler = new ItemStackHandler(1); } return handler; } @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap) { if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return LazyOptional.of(() -> (T) getHandler()); } return super.getCapability(cap); } I've been watching YouTube tutorials and when trying to make a tile entity block which holds items, he wrote this. Could someone clarify what is going on in this section of code? Thanks.
  2. Hi everyone, I'm really new to forge and everything and am trying to make a new enchantment that can be applied to boots called "Jump". As the name may imply, I want it to make a player jump higher. For testing purposes at least, this is twice as high as normal. The enchantment book appears in game and applies to boots just fine, but nothing happens. This is the EnchantmentJump class (everything is imported above this): public class EnchantmentJump extends Enchantment { public EnchantmentJump() { super(Enchantment.Rarity.RARE, EnumEnchantmentType.ARMOR_FEET, new EntityEquipmentSlot[] {EntityEquipmentSlot.FEET}); this.setRegistryName("Jump"); this.setName("Jump"); } @Override public int getMaxLevel() { return 1; } @SubscribeEvent public void jumpBoost(LivingEvent.LivingJumpEvent event){ int level = EnchantmentHelper.getMaxEnchantmentLevel(ModEnchantments.JUMP, event.getEntityLiving()); if (level > 0) { EntityLivingBase player = event.getEntityLiving(); player.motionY *= 2; } } } Here is my ModEnchantments class (again, everything is imported above this): @Mod.EventBusSubscriber(modid=DanielsMinecraftMod.MODID) public class ModEnchantments { public static final Enchantment JUMP = new EnchantmentJump(); @SubscribeEvent public static void registerEnchantments(RegistryEvent.Register<Enchantment> event) { event.getRegistry().registerAll(JUMP); } } I realise that the reason this isn't working is likely a misunderstanding of how Forge works or something incredibly obvious, but I have been having trouble nonetheless. Thanks!
×
×
  • Create New...

Important Information

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