BliX5 Posted August 30, 2020 Posted August 30, 2020 I've searched through videos and websites, as well as the forge docs, but I can't find how to properly add a custom blockstate to my custom-modeled block. I'm trying to change the texture of the block whenever I right click it, but nothing I add in seems to work correctly. I keep getting the correct hitbox, but no model or texture is recognized. What is the proper way to do this for the newest version? Quote
urbanxx001 Posted August 30, 2020 Posted August 30, 2020 (edited) Luckily there's a vanilla block that has this functionality already: the daylight detector. The blockstate for that looks like: { "variants": { "inverted=false": { "model": "minecraft:block/daylight_detector" }, "inverted=true": { "model": "minecraft:block/daylight_detector_inverted" } } } So you can adapt your blockstate to use true/false flags like that. Now we need to look at the class file for the daylight detector to see how the tags are implemented. I've added the relevant parts here. public static final BooleanProperty INVERTED = BlockStateProperties.INVERTED; public DaylightDetectorBlock(AbstractBlock.Properties properties) { super(properties); this.setDefaultState(this.stateContainer.getBaseState().with(INVERTED, Boolean.FALSE)); } public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { if (player.isAllowEdit()) { if (worldIn.isRemote) { return ActionResultType.SUCCESS; } else { BlockState blockstate = state.func_235896_a_(INVERTED); worldIn.setBlockState(pos, blockstate, 4); return ActionResultType.CONSUME; } } else { return super.onBlockActivated(state, worldIn, pos, player, handIn, hit); } } Edited August 30, 2020 by urbanxx001 1 Quote
poopoodice Posted August 30, 2020 Posted August 30, 2020 Remember to add to state to the state container. Quote
BliX5 Posted August 30, 2020 Author Posted August 30, 2020 Thanks for the help! I just realized my mistake: for some reason, in the block.json file, if I insert a space between two attributes, it doesn't recognize the second one. I fixed it, and now my block works perfectly Quote
BliX5 Posted August 31, 2020 Author Posted August 31, 2020 Adding onto it, is there any way I can change it so you can only toggle it once? Quote
Beethoven92 Posted August 31, 2020 Posted August 31, 2020 (edited) Do you mean so that when its toggled, it just stays always in that state? just use the value of your boolean property then...the first time the block gets toggled your boolean property will become true (or false, depends on the default value you set before)..you have to make it so that the next time it won't toggle if the boolean property has already changed Edited August 31, 2020 by Beethoven92 Quote Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
BliX5 Posted August 31, 2020 Author Posted August 31, 2020 1 hour ago, Beethoven92 said: Do you mean so that when its toggled, it just stays always in that state? just use the value of your boolean property then...the first time the block gets toggled your boolean property will become true (or false, depends on the default value you set before)..you have to make it so that the next time it won't toggle if the boolean property has already changed The if statement won't let me compare a BooleanProperty to a Boolean because apparently they're two separate things, and I have no idea how to fix this. Quote
Draco18s Posted August 31, 2020 Posted August 31, 2020 (edited) A BooleanProperty is an object that says "a blockstate is allowed to have two values: true and false." It is not, itself, the state of the block in the world. Getting a bool from the blockstate is simple: you ask the blockstate for its value. Edited August 31, 2020 by Draco18s Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
BliX5 Posted August 31, 2020 Author Posted August 31, 2020 How would I get a value from the blockstate itself? Quote
BliX5 Posted August 31, 2020 Author Posted August 31, 2020 Nevermind, I had a different name specified in my arguments, so for me it was just state.get(). All works find now, thanks for the help. 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.