Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

ScottBot10

Members
  • Joined

  • Last visited

Everything posted by ScottBot10

  1. I have a float Capabilty for players and I have it so that it increases by 0.05 when a certain item is used. But when I use the item it does not increase exactly. (For example, instead of going from 1.05 to 1.1, it goes to 1.0999999). How would I fix this? Relevant code: // SkillLevel.java public class SkillLevel implements ISkillLevel { private float level = 1F; @Override public void remove(float num) { this.level -= num; } @Override public void add(float num) { this.level += num; } @Override public void set(float num) { this.level = num; } @Override public float getLevel() { return this.level; } public static class SkillLevelProvider implements ICapabilitySerializable<FloatNBT> { @CapabilityInject(ISkillLevel.class) public static Capability<ISkillLevel> SKILL_CAP; private LazyOptional<ISkillLevel> instance = LazyOptional.of(SKILL_CAP::getDefaultInstance); @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { return SKILL_CAP.orEmpty(cap, instance); } @Override public FloatNBT serializeNBT() { return (FloatNBT) SKILL_CAP.getStorage().writeNBT(SKILL_CAP, instance.orElseThrow(() -> new IllegalArgumentException("LazyOptional cannot be empty!")), null); } @Override public void deserializeNBT(FloatNBT nbt) { SKILL_CAP.getStorage().readNBT(SKILL_CAP, instance.orElseThrow(() -> new IllegalArgumentException("LazyOptional cannot be empty!")), null, nbt); } } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { ISkillLevel skill = playerIn.getCapability(SkillLevel.SkillLevelProvider.SKILL_CAP).orElse(null); skill.add(0.05f); System.out.println(skill.getLevel()); } Thanks!
  2. I would like to create a points system where a player has to have a certain amount of points to do a special ability. What is the best way to store these points? I thought of NBT tags or a json file but I don't know the best method
  3. Where would I call it from? Is there a method for it?
  4. Thanks so much! And how would I make it get the tags from the /give command?
  5. How would I implement this? I have this: @Override public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) { if (this.isInGroup(group)) { ItemStack stack = new ItemStack(this); CompoundNBT nbt = stack.getOrCreateTag(); TestMod.LOGGER.info(stack.getTag()); ListNBT bookPages = new ListNBT(); String[] values = {"test", "test2", "test3", "test4"}; for (String text : values) { bookPages.add(StringNBT.valueOf("{\"text\":\"" + text + "}\""));} nbt.put("pages", bookPages); nbt.putString("author", "Test Author"); nbt.putString("title", "Test Title"); TestMod.LOGGER.info(stack.hasTag()); TestMod.LOGGER.info(stack.getTag()); TestMod.LOGGER.info(nbt); items.add(new ItemStack(this, 1, nbt)); } } But still doesn't work
  6. I have made a custom boom item and I would like to add default NBT data: the author the title and the pages. This is my code: package com.scottbot.testmod.objects.items; import com.scottbot.testmod.TestMod; import com.scottbot.testmod.gui.ModBookReadScreen; import net.minecraft.client.Minecraft; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.WrittenBookItem; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.StringNBT; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.StringUtils; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.World; import javax.annotation.Nullable; import java.util.List; public class ModBookItem extends WrittenBookItem { public ModBookItem(Properties builder) { super(builder); ItemStack stack = new ItemStack(this); TestMod.LOGGER.info("tagging"); addTags(stack); } public void addTags(ItemStack stack) { CompoundNBT nbt = stack.getOrCreateTag(); TestMod.LOGGER.info(stack.getTag()); ListNBT bookPages = new ListNBT(); String[] values = {"test", "test2", "test3", "test4"}; for (String text : values) { bookPages.add(StringNBT.valueOf("{\"text\":\"" + text + "}\""));} nbt.put("pages", bookPages); nbt.putString("author", "Test Author"); nbt.putString("title", "Test Title"); stack.setTag(nbt); TestMod.LOGGER.info(stack.hasTag()); TestMod.LOGGER.info(stack.getTag()); } @Override public void onCreated(ItemStack stack, World worldIn, PlayerEntity playerIn) { addTags(stack); super.onCreated(stack, worldIn, playerIn); } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { ItemStack stack = playerIn.getHeldItem(handIn); Minecraft.getInstance().displayGuiScreen(new ModBookReadScreen(new ModBookReadScreen.WrittenBookInfo(stack))); return ActionResult.resultSuccess(stack); } @Override public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) { TestMod.LOGGER.info(stack.getTag()); TestMod.LOGGER.info(stack.hasTag()); if (stack.hasTag()) { CompoundNBT compoundnbt = stack.getTag(); TestMod.LOGGER.info(compoundnbt); assert compoundnbt != null; String s = compoundnbt.getString("author"); TestMod.LOGGER.info(s); if (!StringUtils.isNullOrEmpty(s)) { tooltip.add((new TranslationTextComponent("book.byAuthor", s)).applyTextStyle(TextFormatting.GRAY)); } } } When I start the game, it logs that the tags were added: But when I actually get it from the creative menu it doesn't have the author tag and when I open the book it says invalid tag. Any help would be appreciated, thanks!
  7. Where do I get GuiScreen? I couldn't find a class called GuiScreen, only GuiScreenEvent.
  8. So I have an class extending Item and would like to add a tooltip when SHIFT is pressed while mousing over the item. I have the addInformation method but I don't know how to check if a key is pressed down. Thanks in advance
  9. I am making a mod that I can use on servers and what I would like to do is monitor the messages being sent by the player and if they contain a certain string to not send them. For example if it has bad language it will prevent it from being sent. I could not find an event for this, only for receiving chat and not for sending it. I am new to modding and any help would be appreciated. Thanks!

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.