Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.2] Create Book


delpi
 Share

Recommended Posts

I noticed a lot of post about how to create a book type questions but nobody had an answer for 1.7.2.

 

I created one and it seems to work fine so posting here for others.  This is a snipet of code from a command I have in each of my mods.

 

 

 

 

    // Create the book

    ItemStack book = new ItemStack(Items.written_book);

   

    // Create NBT data and add to the book

    NBTTagCompound tag = new NBTTagCompound();

    NBTTagList bookPages = new NBTTagList();

    bookPages.appendTag(new NBTTagString("This should be page 1 data"));

    bookPages.appendTag(new NBTTagString("This should be page 2 data"));

    book.setTagInfo("pages", bookPages);

    book.setTagInfo("author", new NBTTagString("delpi"));

    book.setTagInfo("title", new NBTTagString("ClanDoolittle Permissions Mod Instructions"));

 

    // Give the player the book

    player.inventory.addItemStackToInventory(book);

 

 

 

 

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Got the rotation working. I had to look at LivingEntityRenderer#render and setupRotations a little more closely, and I realized that I needed to change the custom entity's yBodyRot and yBodyRotO.  private static boolean renderingCustomEntity = false; private static CustomEntity customEntity; private static void refreshCustomEntity(LocalPlayer localPlayer, LivingEntity livingEntity) { if (customEntity == null || customEntity.isRemoved()) { customEntity = ModEntities.CUSTOM_ENTITY.get().create(localPlayer.clientLevel); } if (!customEntity.level.dimension().equals(livingEntity.level.dimension())) { customEntity.discard(); } } @SubscribeEvent public static void replaceMobModel(RenderLivingEvent.Pre<LivingEntity, EntityModel<LivingEntity>> event) { LocalPlayer localPlayer = Minecraft.getInstance().player; if (localPlayer != null && event.getEntity() instanceof Mob mob) { if (/* put your own condition here */) { if (!renderingCustomEntity) { try { renderingCustomEntity = true; event.setCanceled(true); refreshCustomEntity(localPlayer, mob); // (truth be told, my custom entity does not have a "head", so these lines aren't needed) // customEntity.setYHeadRot(mob.getYHeadRot()); // customEntity.yHeadRotO = mob.yHeadRotO; customEntity.setYBodyRot(mob.yBodyRot); customEntity.yBodyRotO = mob.yBodyRotO; customEntity.setPose(mob.getPose()); Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(customEntity).render( customEntity, customEntity.yBodyRot, event.getPartialTick(), event.getPoseStack(), event.getMultiBufferSource(), event.getPackedLight() ); } finally { renderingCustomEntity = false; } } } } }   As shown in my code, if the mob whose model is replaced moves to a different dimension, I unload the custom entity with Entity#discard and then reinitialize it on the next tick. I wonder if I also have to unload the custom entity when the mob it is "replacing" dies.
    • Thank you for the video, but I found the issue. I had to update the Gradle from 7.2 to 7.3 in gradle/wrapper/gradle-wrapper.properties.
    • Some zip managers like to take control of the .jar file extension away from Java. Make sure you have Java installed and try running Jarfix once, then try the installer again.
    • Whenever i try and download forge specifically 1.18.2 it will download as a JAR file as a note page and theirs no way to install it i have watched a few videos but none show how to fix this problem
    • Hello, I dont really understand why the nbt tag in the code below is not attached to the item. @Override public InteractionResult interactLivingEntity(ItemStack pStack, Player pPlayer, LivingEntity pInteractionTarget, InteractionHand pUsedHand) { if (pPlayer.getLevel().isClientSide()) { if (pInteractionTarget instanceof Mob mob) { System.out.println("ITEMSTACK " + pStack); CompoundTag nbtTag = null; System.out.println("nbt tag " + nbtTag); if (!(pStack.hasTag())) { nbtTag = new CompoundTag(); CompoundTag nbtMobTag = new CompoundTag(); mob.save(nbtMobTag); nbtTag.put("mob", nbtMobTag); System.out.println("IN NBT NULL " + nbtTag); pStack.setTag(nbtTag); System.out.println("AFTER TAG SET " + pStack.hasTag()); pPlayer.sendMessage(new TextComponent("Shard used on " + mob.getDisplayName().getString()), pPlayer.getUUID()); } else { nbtTag = pStack.getTag(); System.out.println("item has tag"); System.out.println(nbtTag.contains("mob")); } } } return InteractionResult.PASS; } @Override public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltipComponents, TooltipFlag pIsAdvanced) { CompoundTag nbtTag = pStack.getTag(); if (nbtTag != null) { if (nbtTag.contains("mob")) { Mob targetMob = null; targetMob.deserializeNBT(nbtTag.getCompound("mob")); pTooltipComponents.add(new TextComponent("Mob : " + targetMob.getDisplayName().getString())); } } } Everytime I right click with the Item on a LivingEntity, It goes on the if(!pStack.hasTag()), but It shouldn't because we set the tag on the first right click on an Entity   Do you have a solution ?
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.