Jump to content

Rendering Block Model dependiong on a property loaded from a Tile entity


Recommended Posts

Posted (edited)

So I've been trying to add some more beds to Minecraft. (1.12.2)
Naturally for my block i extended BlockBed class and for my item ItemBed class.
I've got most of the funcionality working but due to lack of expirience I resorted to having Blocks be the model and not the tile entity. (i know i should just make the colored part a TE model but I have no real idea how to)
Limited by block meta I stored the color property in the tile entity, upon placing the bed has its desired color, testing for drops also confirms that the entity works.
However after reolading the bed (via either leaving the area or loading up the save again) the bed is always white, but upon breaking the particles have the correct color, the dropped items also correspond to the color stored in TE.
(note that im not very expirienced in java or forge, code is mostly what i picked up from others and slight modifications to vanilla)

 

Block class

pastebin

 

Item class (i dont think this one matters in this situation)

pastebin

 

TileEntity class 

pastebin

 

 

Edited by ThePiekar
Posted

Please post your code as a GitHub repository, I think your probably not syncing the data correctly.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

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

BlockBase is an anti-pattern, there is already a BlockBase class, it’s called Block.

Don’t use IHasModel, all items need models. You can do all your item model registration automatically in 1 line. IHasModel forces you to write the exact same code over and over again.

Package names should be singular

Methods should start lowercase

A CommonProxy doesn’t make sense. Proxies seperate code. If it’s common code it doesn’t belong in a proxy.

Have you tried stepping through your code in a debugger? You seem to be overriding all the correct syncing methods.

Where is your rendering code?

  • Confused 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

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 (edited)

Sorry for lack of proffesionality, lot of things are there temporary, like block and item base, for me to just test if certain things work on an easier basis.

 

I'll look into renaming stuff according to the rules and getting rid of IHasModel and CommonProxy ( to be fair by the time I introduced them I had no idea what anything did), where do you advise me to put the things i had in common proxy (basically a empty void called registerItemRenderer)?

 

That's all the code I have, maybe besides json files, they are a bit ugly, since I didn't want to spend my whole life checking where I missed the coma, but I'll upload them as well.

 

Sorry to be difficult but if that's not what you mean by rendering code, could you specify and/or give examples?

 

 

///EDIT///

Updated github with jsons

 

Also i wouldn't really know what to do with debugger information 

Edited by ThePiekar
Posted

You should set up your GitHub repo differently, it should be in your root mod folder (the one right above /src/)

Your repository is currently missing the files needed for someone else to download and set it up.

Here’s an example of a properly set up repository (notice the build.gradle file) https://github.com/Cadiboo/Example-Mod.

I think you should put a breakpoint in loadColor in your block class, and see what color it returns and why. As a programmer you need to know how to use the debugger, it’s an extremely helpful and powerful tool and there are plenty of online tutorials about it.

 

12 hours ago, ThePiekar said:

Sorry to be difficult but if that's not what you mean by rendering code, could you specify and/or give examples?

Because you were using a TE, I assumed you were using a TESR. It’s good that you’re not though

  • Like 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

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 (edited)

Ok, I've set up something that resembles a proper repo now, same link.
Even if i make loadColor method always return let's say red it still renders the bed white after reolading.
That's why i suspect it to be a sync issue, as destroy particles have the correct texture, as if getActualState was called on breaking the block but not on choosing a model for it.
I'm trying to further investigate the loadColor right now.

Replacing code in getActualState to make it always return a let's say red as color property makes the bed be still white but always have red destruction particles.

Is there any way for me to pass the state from TE to the block before it's rendered (I was convinced getActualState already did it)? 

 

///Edit///


~~I managed to get the color of  bed loaded last( I'm not entirely sure)(so still not the desired one, particles and drops match the desired one) of TE to be the color of the block until the game is restarted, after which it gets back ot block default (white). Even after game restart item drops and particles are correct, so I'd assume TE saves and reads the data correctly. 
Im as confused as it gets
(code added to TE)

	@Override
	    public void onLoad()
	{
		Block bed = getWorld().getBlockState(getPos()).getBlock();
		BlockFancyBed fbed = (BlockFancyBed) bed;
		fbed.setRenderState(fbed.getActualState(getWorld().getBlockState(getPos()), getWorld(), getPos()));
		notifyBlockUpdate();
	}

 

(code added to Block)

    	   public void setRenderState(IBlockState state) {
    		   this.setDefaultState(state);
    	   }

~~ doesn't work anymore for some reason

///Edit2///
Woking with debugger confirms that getActualState is called after interacting with block and not on rendering it, so thats why clolor stays default.

 

So the question is how to change the state of a single block before it's rendered
(defaulst state and actual state don't seem to cut it)
 

///Edit3///
i played around with setBlockState in onLoad method of the TE and discovered it gets seemingly called twice per TE, once by Server (color values from debugger seem fine here) and second time by the client Thread (with either null or default color value declared in the TE class)
 

///Edit4///
Even if I don't get to solve it just yet, thank You for giving me great leads, I have learned a lot.

Edited by ThePiekar
Posted

Don’t call set default state anywhere other than the constructor.

Have you tried debugging your syncing?

  • Thanks 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

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

I figured out as much, took me a while.

 

Well I'm going to have to take a break this weekend, but as soon as I'm back I'll check every sync method. Till then thanks for all help till now, I have a much better understanding on how to fiddle with code just after those few replies.

Posted

Well while reading the NBT debugger shows color to be null, i don't get it.


Also I noticed a lot of tile enitites using public void update with Override adnotation. I cannot seem to find it in my code, any hints?

Posted
6 hours ago, ThePiekar said:

Also I noticed a lot of tile enitites using public void update with Override adnotation. I cannot seem to find it in my code, any hints?

To use that method you need to implement ITickable.

  • Thanks 1

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.

  • 2 weeks later...
Posted

Thanks for the patience everyone.
For anyone struggling with a similar issue,  I figured i casted IBlockAcces to World for my method what was fetching me the color from TE (silly me), changing that fixed everything. 
 

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.