Topic category: Help with Minecraft modding (Java Edition)
Issue in short
Hello! Recently, I've faced an issue when trying to create an enum property for a block. In the block java file, I've tried creating the property to which I assigned the public enum I wanted to use. However, doing this has resulted in compilation errors as the console is telling me it cannot find the symbol. Now, I've already attempted deleting the caches as recommended in The Second Most Common SolutionTM section provided on the website without success. I'm somewhat convinced that the problem stems from my own shortcomings in coding, however, after hours of research, I've unable to find the answer. (Additionally, it seems that other people have been experiencing the same issue.)
Additional note
I've found two other posts listing what seems to be the same issue. They can be found here: https://mcreator.net/forum/89014/enum-blockstates-using-custom-code, https://mcreator.net/forum/96691/i-want-make-enum-blockstate-block#new. As such, this post could technically be viewed as a duplicate. Seeing as neither of these posts have received any responses, I decided to make my own in the hopes of bringing attention to the problem.
Code
The errors are nearly (if not completely) the same as the ones in the other posts I listed. Here's the line that causes issues (TileLogicProcedure is a public enum in the same folder in MCREATOR):
public static final EnumProperty TEXTURE_VARIANT = EnumProperty.create("texture_variant", TileLogicProcedure);
Here's the console output:
> Configure project :
The code of this workspace uses official obfuscation mappings provided by Mojang. These mappings fall under their associated license you should be fully aware of.
(c) 2020 Microsoft Corporation. These mappings are provided "as-is" and you bear the risk of using them. You may copy and use the mappings for development purposes,
but you may not redistribute the mappings complete and unmodified. Microsoft makes no warranties, express or implied, with respect to the mappings provided here.
Use and modification of this document or the source code (in any form) of Minecraft: Java Edition is governed by the Minecraft End User License Agreement available
at https://account.mojang.com/documents/minecraft_eula.
> Task :compileJava
C:\Users\david\MCreatorWorkspaces\coastseeker_mod\src\main\java\net\mcreator\coastseekermod\block\GlazedRedmatSingleBlock.java:36: error: cannot find symbol public static final EnumProperty TEXTURE_VARIANT = EnumProperty.create("texture_variant", TileLogicProcedure);
^
symbol: variable TileLogicProcedure
location: class GlazedRedmatSingleBlock
1 error
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 5s
1 actionable task: 1 executed
BUILD FAILED
Task completed in 9 seconds
If anyone can find a solution to this problem, please share! It would not only help me but the other people who also had it. The issue may very well not be linked to MCREATOR itself, but seeing as I use it as my sole programming tool for Minecraft, I thought I'd be most succesful asking for help here. Thank you for reading, be well!
I'm glad to announce that I found the issue (after consulting ChatGPT!)! The public enum needs to implement a string representable. Apparently, Minecraft needs the enum values in strings. Yet, it wasn't immediately obvious (to me anyways) how it's done in practise. Here's how the code for the enum looks, to give an example:
Additionally, I should mention that the enum needs to be imported in the block java file!