Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Store potion in blockdata
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 1
BlockyPenguin

Store potion in blockdata

By BlockyPenguin, November 21 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

BlockyPenguin    0

BlockyPenguin

BlockyPenguin    0

  • Tree Puncher
  • BlockyPenguin
  • Members
  • 0
  • 5 posts
Posted November 21

Hi, I'm fairly new to modding, and I'd like to know if it's possible to store a potion's effect (e.g. slowness, invisibility, strength, etc) inside of some blockdata. If not, how else could I do this?

  • Quote

Share this post


Link to post
Share on other sites

Cadiboo    277

Cadiboo

Cadiboo    277

  • Reality Controller
  • Cadiboo
  • Members
  • 277
  • 3303 posts
Posted November 21

What are you trying to do, from a players perspective?

  • Quote

Share this post


Link to post
Share on other sites

BlockyPenguin    0

BlockyPenguin

BlockyPenguin    0

  • Tree Puncher
  • BlockyPenguin
  • Members
  • 0
  • 5 posts
Posted November 21 (edited)
5 hours ago, Cadiboo said:

What are you trying to do, from a players perspective?

So, I'm looking to make a block that, when right-clicked with a potion, will store that potion's data (effect and length) in some blockdata, then when the player right clicks again with an empty hand, it gives them the correct effect for the correct amount of time. If that sounds too op, don't worry, it only has three uses :)

Edit: Or maybe I could use a String if that's possible?

labkit:potiondispensary[potion="speed",time="8:00",level=3]

 

Edited November 21 by BlockyPenguin
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6684

diesieben07

diesieben07    6684

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6684
  • 45696 posts
Posted November 21

Your block will need a TileEntity. Then you can store an EffectInstance in that tile entity. You can use EffectInstance#write(CompoundNBT) to store this effect in NBT.

  • Like 1
  • Quote

Share this post


Link to post
Share on other sites

BlockyPenguin    0

BlockyPenguin

BlockyPenguin    0

  • Tree Puncher
  • BlockyPenguin
  • Members
  • 0
  • 5 posts
Posted November 21
5 hours ago, diesieben07 said:

Your block will need a TileEntity. Then you can store an EffectInstance in that tile entity. You can use EffectInstance#write(CompoundNBT) to store this effect in NBT.

Cool, thx. :)

  • Quote

Share this post


Link to post
Share on other sites

BlockyPenguin    0

BlockyPenguin

BlockyPenguin    0

  • Tree Puncher
  • BlockyPenguin
  • Members
  • 0
  • 5 posts
Posted November 25

Okay, so I've added this code to my block's constructor:
 

CompoundNBT nbt = new CompoundNBT();
EffectInstance potion = new EffectInstance(Effects.LUCK, 6000);
potion.write(nbt);

 

but if I run "/data get block <x> <y> <z>" ingame, it doesn't give me any info on the potion, just the x, y, z and id, so I'm guessing it isn't writing properly. Nothing seems to be amiss in the logs. Please forgive me if I'm missing something important here, this is my first time working with TileEntities.

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6684

diesieben07

diesieben07    6684

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6684
  • 45696 posts
Posted November 25
2 minutes ago, BlockyPenguin said:

Okay, so I've added this code to my block's constructor:

How is that at all related to what I told you to do?

  • Quote

Share this post


Link to post
Share on other sites

BlockyPenguin    0

BlockyPenguin

BlockyPenguin    0

  • Tree Puncher
  • BlockyPenguin
  • Members
  • 0
  • 5 posts
Posted November 25
On 11/21/2019 at 8:10 AM, diesieben07 said:

You can use EffectInstance#write(CompoundNBT) to store this effect in NBT.

I created an EffectInstance and passed some CompoundNBT in the .write method.

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6684

diesieben07

diesieben07    6684

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6684
  • 45696 posts
Posted November 25

I can see that. But you create a blank NBT compount, write something to it and then just drop it on the ground.

You need to add a tile entity to your block.

  • Quote

Share this post


Link to post
Share on other sites

BlockyPenguin    0

BlockyPenguin

BlockyPenguin    0

  • Tree Puncher
  • BlockyPenguin
  • Members
  • 0
  • 5 posts
Posted November 25

Oh, I've done that too, forgot to mention it, sorry. How would I write it to the tile entity then?

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6684

diesieben07

diesieben07    6684

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6684
  • 45696 posts
Posted November 25

You don't "write it to the tile entity". To store data in your tile entity you simply add whatever fields you want to the tile entity class and store the data there.

Then you override the methods TileEntity#write and TileEntity#read to serialize and deserialize your data to and from NBT.

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • mindstorm3223
      1.12.2-Problem with tile entity custom crafting table

      By mindstorm3223 · Posted 3 minutes ago

      Sorry, I looked around and couldn't figure out how to do that, do you know of any good place where it can tell me how to?
    • Jaffaaaaa
      ScreenGui does nothing

      By Jaffaaaaa · Posted 4 minutes ago

      I'm trying to make a gui to edit values and settings using a command, but the gui just does nothing apart from showing me the "init gui" message I put i the initGui() method. package xyz.jaffaaaa.zealotmanager; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.util.ChatComponentText; public class GuiHandler extends GuiScreen { private GuiButton reset; private ZealotManager zm; public GuiHandler(ZealotManager zm) { this.zm=zm; } @Override public void initGui() { super.initGui(); this.buttonList.clear(); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("init gui")); this.buttonList.add(reset = new GuiButton(0, this.width / 2 - 100, this.height / 2, "Reset Counters")); } @Override protected void actionPerformed(GuiButton button) { if (button == reset) { zm.counter.zealotsSinceLastEye = 0; zm.counter.totalEyes = 0; zm.counter.totalZealots = 0; } } @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { super.drawScreen(mouseX, mouseY, partialTicks); drawDefaultBackground(); } }  
    • Yanny7
      [1.14.4] Stone Age mod

      By Yanny7 · Posted 5 minutes ago

      Stone age is minecraft 1.14.4 mod that gives you feeling of man from stone age. No more magically created planks from wood logs, the way to first crafting table is long and dangerous. In prehistoric ages, animals was not domesticated and same apply to this mod. There are no cows/sheeps/pigs/chickens, but their ancestors aurochs/mouflons/boars/fowls which are quit upset when you attack them or their friends. For more information, see wiki. Found bug? Please report here. This mod depends on Ages api.   Suggestions? New ides? Code comments? Just comment or PM me
    • ShyAlpha22
      More Player Models won't change character

      By ShyAlpha22 · Posted 23 minutes ago

      I have been having this problem for quite some time with the 1.12.2 versions of More Player Models. Whenever I change anything with my character it doesn't actually change, for example, I changed the size and my view changed but my character remained the same size. Animations and movements also don't work, once again if I try to sit it changes my view, but my character is just standing with their feet slightly in the ground. I am using other mods with this, but not anything I think would affect it. The mods are:   chiselsandbits-14.33 CMDCam_v1.4.4_mc1.12.2 CreativeCore_v1.9.66_mc1.12.2 CutsomNPCs_1.12.2-(01Oct19) Decocraft-2.6.3_1.12.2 DoggyTalents-1.12.2-1.15.1.4-universal mclib-1.0.3-1.12.2 MorePlayerModels_1.12.2-(05Dec19) pa1.10 PTRLib-1.0.4   Any help would be appreciated, thank you.
    • DaemonUmbra
      Gradle launches Minecraft, then hangs demanding open mods folder.

      By DaemonUmbra · Posted 27 minutes ago

      You misunderstand what 4.9 and 3.+ represent, that is not what fixed your issue.
  • Topics

    • mindstorm3223
      2
      1.12.2-Problem with tile entity custom crafting table

      By mindstorm3223
      Started Yesterday at 02:18 AM

    • Jaffaaaaa
      0
      ScreenGui does nothing

      By Jaffaaaaa
      Started 4 minutes ago

    • Yanny7
      0
      [1.14.4] Stone Age mod

      By Yanny7
      Started 5 minutes ago

    • ShyAlpha22
      0
      More Player Models won't change character

      By ShyAlpha22
      Started 24 minutes ago

    • JMAS
      3
      Gradle launches Minecraft, then hangs demanding open mods folder.

      By JMAS
      Started Yesterday at 03:02 PM

  • Who's Online (See full list)

    • Jaffaaaaa
    • Yanny7
    • salvestrom
    • fenekvert
    • Pyre540
    • DcZipPL
    • DaemonUmbra
    • mindstorm3223
    • matorassan
    • diesieben07
    • D4Rk
    • EmerProd
    • coolsim
    • ShyAlpha22
    • RyanGV95
    • motky
    • Lycanite
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Store potion in blockdata
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community