MSpace-Dev Posted December 17, 2017 Posted December 17, 2017 Hey everyone, So I am trying to make a switch statement to compare the block that I am looking at, to the blocks within my mod. Yet, when I try make my first case, I get Constant Expression Required error. I'm not sure how to fix this. All my blocks in my mod are declared as final variables. Here are the two things I've tried so far: switch (worldIn.getBlockState(pos).getBlock()) { case ModBlocks.my_mod_block : Utils.getLogger().info("mod block right clicked"); break; } switch (true) { case (worldIn.getBlockState(pos).getBlock() == ModBlocks.my_mod_block) : Utils.getLogger().info("mod block right clicked"); break; } ModBlocks.class public class ModBlocks { public static final Block my_mod_block = new MyModBlock("my_mod_block", Material.WOOD); public static final Block[] BLOCKS = { my_mod_block }; } Thanks! Quote
Leviathan143 Posted December 17, 2017 Posted December 17, 2017 switch statements only work on primitive types, Strings, enums & the wrapper objects for primitive types(These are special cased). Since Block does not fall into any of those categories, you can't switch on a field/method return of type Block. What are you actually trying to do here? Blocks have a method that is called when they are right-clicked. Quote
MSpace-Dev Posted December 17, 2017 Author Posted December 17, 2017 Compare a bunch of blocks to the one I'm looking at. Quote
Leviathan143 Posted December 17, 2017 Posted December 17, 2017 (edited) Why? It looks like you're trying to add a right-click action to your block. That is not the way to do it. Edited December 17, 2017 by Leviathan143 Quote
MSpace-Dev Posted December 17, 2017 Author Posted December 17, 2017 Thanks, diesieben for the actual answer, exactly what I am looking for! Leviathan, I want to see what block I am looking at with the item I am holding from my mod... Not trying to add right click action... (This item is a tool) I'm not that stupid. Quote
Recommended Posts
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.