Jump to content

[1.12.2] [SOLVED] Problems With TileEntities and PropertyBools


Recommended Posts

Posted (edited)

using Forge 1.12.2

 

So I have a couple of problems to do with PropertyBool set on a block with a TileEntity. First problem is that the PropertyBool is not setting to it's default state on block placement, set in setDefaultState()

this.setDefaultState(this.blockState.getBaseState().withProperty(ACTIVATED, Boolean.valueOf(true)));

ACTIVATED is always false on placement, but, after a quick re-log (I don't restart minecraft, just the world) it changes to true.

 

Second Problem is that I don't know how to get and set the value of ACTIVATED from other classes, specifically in this case, the TileEntity class. I have tried everything, searched online, read the documentation but failed to find a mention on how to do it.

Full Block class:

  Reveal hidden contents

 

Full TileEntity class (note- I am using the CJCore Library in this mod)

  Reveal hidden contents

NOTE- I have not set the value of active(In TE class) as I need to set it equal to ACTIVATED(PropBool in Block class), which I cannot find a way to do

 

Thanks for any help!

 

EDIT - After Reading 

I moved on from using 

ITileEntityProvider

to overriding 

hasTileEntity() and createTileEntity()

 

Edited by Spacejet
Marked as Solved
Posted
  On 11/29/2018 at 1:20 AM, Spacejet said:

Boolean.valueOf(true)

Expand  

Why are you using boxed values?

 

  On 11/29/2018 at 1:20 AM, Spacejet said:

extends BlockBase

Expand  

BlockBase is an antipattern. There is already a BlockBase, it's called Block.

 

  On 11/29/2018 at 1:20 AM, Spacejet said:

@Override
    public int getMetaFromState(IBlockState state) 
    {
        if(ACTIVATED.getAllowedValues().contains(true)) return 1;
        else return 0;
    }

Expand  

This will always return 1. Serialize the value of the property, not it's property.

 

  On 11/29/2018 at 1:20 AM, Spacejet said:

implements ITickable, ICapabilityProvider

Expand  

TileEntity already implements ICapabilityProvider.

 

  On 11/29/2018 at 1:20 AM, Spacejet said:

public static boolean active;

Expand  

Why is this static?

 

  On 11/29/2018 at 1:20 AM, Spacejet said:

if(this.world != null) 

Expand  

This should never happen in onUpdate, and if it does some mod severely messes up and you should crash the game.

 

  On 11/29/2018 at 1:20 AM, Spacejet said:

active = nbt.getBoolean("active");

Expand  

active is static though. Why are you (de)serializing it for instances?

 

  On 11/29/2018 at 1:20 AM, Spacejet said:

I don't know how to get and set the value of ACTIVATED from other classes, specifically in this case, the TileEntity class.

Expand  

The same way you would do it in your block class. You have the world(TileEntity.world) and the position(TileEntity.pos). Get the blockstate from the world at position and change the value of the property in the same way you would for your block.

Posted (edited)

@V0idWa1k3r the answer to your questions :

 

active is static because I was trying to set it in my block class as ACTIVATED was a part of my block class. I just forgot to change it back. Will do that.

 

I don't really know why I used boxed values when I could have simply used 'true' or 'false' ?

 

  On 11/29/2018 at 4:43 AM, V0idWa1k3r said:
  On 11/29/2018 at 1:20 AM, Spacejet said:

mplements ITickable, ICapabilityProvider

Expand  

TileEntity already implements ICapabilityProvider

Expand  

I did not know that. Nice to know!

 

  On 11/29/2018 at 4:43 AM, V0idWa1k3r said:
  On 11/29/2018 at 1:20 AM, Spacejet said:

I don't know how to get and set the value of ACTIVATED from other classes, specifically in this case, the TileEntity class.

Expand  

The same way you would do it in your block class. You have the world(TileEntity.world) and the position(TileEntity.pos). Get the blockstate from the world at position and change the value of the property in the same way you would for your block

Expand  

Is it with setBlockState() cause now I remember that I did not try that. Thanks a ton.

 

  On 11/29/2018 at 4:43 AM, V0idWa1k3r said:
  On 11/29/2018 at 1:20 AM, Spacejet said:

extends BlockBase

Expand  

BlockBase is an antipattern. There is already a BlockBase, it's called Block.

 

Expand  

I call my Registry Handler and register all my blocks in this class.

 

  On 11/29/2018 at 4:43 AM, V0idWa1k3r said:
  On 11/29/2018 at 1:20 AM, Spacejet said:

@Override
    public int getMetaFromState(IBlockState state) 
    {
        if(ACTIVATED.getAllowedValues().contains(true)) return 1;
        else return 0;
    }

Expand  

This will always return 1. Serialize the value of the property, not it's property.

Expand  

I just got to know about an hour ago that .contains() will search every possible output, not the selected. What should I use instead of that?? How do I get the value of the property in the first place?? getBlockState()?? But that returns a BlockStateContainer.

 

EDIT: I want to get its boolean value to set active equal to, but getBlockState() returns the state, not value! Right?

 

  On 11/29/2018 at 4:43 AM, V0idWa1k3r said:

 

  On 11/29/2018 at 1:20 AM, Spacejet said:

if(this.world != null) 

Expand  

This should never happen in onUpdate, and if it does some mod severely messes up and you should crash the game.

Expand  

K. Will crash the game.

 

Thanks a lot for all those improvement tips and answers to some of my questions.

 

P.S: do you know why ACTIVATED returns false when block is first placed into the world? Set default state sets its default state to true!

Edited by Spacejet
More detail added
Posted
  On 11/29/2018 at 5:23 AM, Spacejet said:

I call my Registry Handler and register all my blocks in this class.

Expand  

That sounds bad. That sound directly accessing the registry levels of bad. And potentially IHasModel levels of bad too.

 

  On 11/29/2018 at 5:23 AM, Spacejet said:

How do I get the value of the property in the first place?? getBlockState()?? But that returns a BlockStateContainer.

Expand  

IBlockState#getValue.

 

  On 11/29/2018 at 5:23 AM, Spacejet said:

do you know why ACTIVATED returns false when block is first placed into the world? Set default state sets its default state to true!

Expand  

I am not sure but you can override Block#getStateForPlacement and return the blockstate with the correct value.

 

  On 11/29/2018 at 5:23 AM, Spacejet said:

Is it with setBlockState()

Expand  

Yes, but you will need to override TileEntity#shouldRefresh in your TE class and make sure it returns false when the value of the property changes, but true otherwise or else the game will recreate your TE when you do that.

Posted (edited)
  On 11/29/2018 at 5:27 AM, V0idWa1k3r said:
  On 11/29/2018 at 5:23 AM, Spacejet said:

do you know why ACTIVATED returns false when block is first placed into the world? Set default state sets its default state to true!

Expand  

I am not sure but you can override Block#getStateForPlacement and return the blockstate with the correct value

Expand  

Ok will try that.....sounds like it will work (hopefully)

 

  On 11/29/2018 at 5:27 AM, V0idWa1k3r said:
  On 11/29/2018 at 5:23 AM, Spacejet said:

How do I get the value of the property in the first place?? getBlockState()?? But that returns a BlockStateContainer.

Expand  

IBlockState#getValue

Expand  

Oh.

  On 11/29/2018 at 5:27 AM, V0idWa1k3r said:
  On 11/29/2018 at 5:23 AM, Spacejet said:

I call my Registry Handler and register all my blocks in this class.

Expand  

That sounds bad. That sound directly accessing the registry levels of bad. And potentially IHasModel levels of bad too

Expand  

 

I regret writing that as I am not on my computer and cannot check to make sure what I wrote was correct as that is what I thought I was doing in blockbase..... what should I do if I was doing the bad thing?

Edited by Spacejet
Spelling mistake
Posted
  On 11/29/2018 at 5:34 AM, Spacejet said:

what should I do if I was doing the bad thing?

Expand  

Don't directly access the registry, register your things in the appropriate RegistryEvent.Register, in this case it would be Register<Block>.

In case of IHasModel - get rid of it and just register your models directly in the ModelRegistryEvent.

  • Like 1
Posted
  On 11/29/2018 at 5:37 AM, Spacejet said:

Oh then it's fine as I am indeed using registryevents.. phew.. scared me real good.

Expand  

Are you instantiating your objects in their registry events?

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
  On 11/29/2018 at 9:21 AM, Cadiboo said:

Are you instantiating your objects in their registry events?

Expand  

Yes. I am just adding the blocks extend blockbase to a list and then that list is passed on to the onBlockRegister() event

BlockBase:

  Reveal hidden contents

 

RegistryHandler:

  Reveal hidden contents

 

Posted
  On 11/29/2018 at 10:46 PM, Spacejet said:

IHasModel

Expand  

Did you remove this like voidwaker said?

  On 11/29/2018 at 10:46 PM, Spacejet said:

Yes. I am just adding the blocks extend blockbase to a list and then that list is passed on to the onBlockRegister() event

Expand  

Where are you instantiating(calling the constructor) for them? Also you shouldn't have a BlockBase class when you instantiate them add them to the list like so

list.add(new Block(...).set...);

Or even 

RegistryObject registry = event.getRegistry

registry.register(new Block(...).set...);

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)
  On 11/29/2018 at 11:16 PM, Animefan8888 said:
  On 11/29/2018 at 10:46 PM, Spacejet said:

Yes. I am just adding the blocks extend blockbase to a list and then that list is passed on to the onBlockRegister() event

Expand  

Where are you instantiating(calling the constructor) for them

Expand  

This is my Mod Blocks class which has the list I am adding the blocks into

  Reveal hidden contents

The constructors are called in the class above as you can see..

Edited by Spacejet
grammar imperfections
Posted
  On 11/29/2018 at 11:26 PM, Spacejet said:

public static final Block TITANIUM_BLOCK = new TitaniumBlock("titanium_block", Material.IRON);

Expand  

Dont do this, this is a static initializer you shouldn't do this with any IForgeRegistryEntry object. Ie anything that has a registry event. They should be initialized in the registryEvent where you register them.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
  On 11/30/2018 at 12:40 AM, Animefan8888 said:

Dont do this, this is a static initializer you shouldn't do this with any IForgeRegistryEntry object. Ie anything that has a registry event. They should be initialized in the registryEvent where you register them.

Expand  

How would you do that?

Posted

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

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