LorenzoPapi Posted December 6, 2019 Posted December 6, 2019 (edited) I've got my "block_afp" block. It's formed by two parts, "TOP" and "DOWN". The block can be placed both on walls, on the floor and under the roof and it works perfectly but, when I break a part of the block, there's a problem. If the block isn't on the floor, the other part gets detroyed too. If the block IS on the floor, I don't know how to check for the other part to get destroyed. Here is a working and updated repo of my mod, with my test worlds too: https://github.com/LorenzoPapi/Test-1.12.2 Edited December 6, 2019 by LorenzoPapi Quote
Draco18s Posted December 6, 2019 Posted December 6, 2019 if (state.getValue(FACING) != EnumFacing.DOWN || state.getValue(FACING) != EnumFacing.UP) { That will always be true. If the facing is UP, then this looks like if(false OR true). False or true is true. If the facing is DOWN then it would read if(true OR false). False or true is true. A good thing, too, otherwise you'd get a NPE. BlockPos blockpos1 = pos.up(); You now set this value to the pos above the pos passed, as opposed to the pos above the bottom you just worked out. blockpos1 is now two above blockpos. if (state.getValue(PART) == BlockAFP.EnumPartType.DOWN && worldIn.getBlockState(blockpos1).getBlock() == this) { if (player.capabilities.isCreativeMode) { worldIn.setBlockToAir(pos); } worldIn.setBlockToAir(blockpos1); } So if the top location is this block, set the location passed to this method to air? Did you mean blockpos1? Oh also, you set it blockpos1 to air anyway regardless of creative mode, so I guess that check is pointless... else { //TODO how to check for the block? } Uh, what does this comment even mean? 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.
LorenzoPapi Posted December 6, 2019 Author Posted December 6, 2019 On 12/6/2019 at 3:43 PM, Draco18s said: You now set this value to the pos above the pos passed, as opposed to the pos above the bottom you just worked out. blockpos1 is now two above blockpos. Expand That's strange. This works for me. On 12/6/2019 at 3:43 PM, Draco18s said: Uh, what does this comment even mean? Expand Don't care about comments, they're just sentences without any logic sometimes. On 12/6/2019 at 3:43 PM, Draco18s said: That will always be true. If the facing is UP, then this looks like if(false OR true). False or true is true. If the facing is DOWN then it would read if(true OR false). False or true is true. A good thing, too, otherwise you'd get a NPE. Expand One thing I don't understand. Why would always one condition be true? Does Minecraft says that if FACING isn't DOWN, it is UP? Maybe it's something I've missed. On 12/6/2019 at 3:43 PM, Draco18s said: So if the top location is this block, set the location passed to this method to air? Did you mean blockpos1? Oh also, you set it blockpos1 to air anyway regardless of creative mode, so I guess that check is pointless... Expand I'll change this tomorrow, I'm really tired. Anyways, maybe I haven't explained well. This block's placement acts like a bed on the floor, kinda like a door on the sides of a block and like an "upside-down" bed under the roof of a block. But I can't destroy both the parts of the block when it's placed on the floor and under the floor. Quote
Draco18s Posted December 6, 2019 Posted December 6, 2019 On 12/6/2019 at 9:07 PM, LorenzoPapi said: One thing I don't understand. Why would always one condition be true? Does Minecraft says that if FACING isn't DOWN, it is UP? Maybe it's something I've missed. Expand Lets start here: if(facing != Down || facing != UP) lets assume that facing is equal to UP and do a replacement to see what happens when the code is run. if(UP != DOWN || UP != UP) obviously the first one is false and the second one is true. if(false || true) Now we simplify. False or True is true, because we only need one side to be true for the whole statement to be true. if(true) If we repeat when facing equals DOWN instead... if(DOWN != DOWN || DOWN != UP) if(false || true) if(true) What about a different direction? Say...EAST? if(EAST != DOWN || EAST != UP) if(true || true) if(true) All possible variations will resolve to if(true) because a value cannot both be equal to DOWN and UP at the same time. On 12/6/2019 at 9:07 PM, LorenzoPapi said: This block's placement acts like a bed on the floor, kinda like a door on the sides of a block and like an "upside-down" bed under the roof of a block. Expand Oh boy. That's going to be a nightmare to figure out where all the bits are. Because when its on the floor or ceiling, the other "half" of the block is going to not be above or below. 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.
LorenzoPapi Posted December 7, 2019 Author Posted December 7, 2019 (edited) On 12/6/2019 at 9:37 PM, Draco18s said: Lets start here: if(facing != Down || facing != UP) lets assume that facing is equal to UP and do a replacement to see what happens when the code is run. if(UP != DOWN || UP != UP) obviously the first one is false and the second one is true. if(false || true) Now we simplify. False or True is true, because we only need one side to be true for the whole statement to be true. if(true) If we repeat when facing equals DOWN instead... if(DOWN != DOWN || DOWN != UP) if(false || true) if(true) What about a different direction? Say...EAST? if(EAST != DOWN || EAST != UP) if(true || true) if(true) All possible variations will resolve to if(true) because a value cannot both be equal to DOWN and UP at the same time. Expand I didn't think about it. Thanks for explaining! On 12/6/2019 at 9:07 PM, LorenzoPapi said: I'll change this tomorrow, I'm really tired. Expand Actually, this entire piece of code was copied and pasted from BlockDoor.class . And it works. On 12/6/2019 at 9:37 PM, Draco18s said: Oh boy. That's going to be a nightmare to figure out where all the bits are. Because when its on the floor or ceiling, the other "half" of the block is going to not be above or below Expand Ikr? This is why I asked help on the forum. I was going crazy. Anyways, I've updated the repo: https://github.com/LorenzoPapi/Test-1.12.2 Some help would be amazing. Edited December 7, 2019 by LorenzoPapi Quote
LorenzoPapi Posted December 7, 2019 Author Posted December 7, 2019 I really don't know how to do this. I've been thinking of how to do this (didn't code anything, since I didn't know what to write), but I had only an idea. Using another HOR_FACING property, but: 1) This HOR_FACING property should be null when the normal "FACING" property isn't DOWN or UP; 2) I think making another property just to check for a part of the block is completely useless. So this is what I have right now...nothing. Any kind of help would be appreciated. I'm going to bed now. Quote
Draco18s Posted December 8, 2019 Posted December 8, 2019 You need two properties. HALF and FACING If HALF is A (call it whatever you want) you know you have the A part of the bed and can using the facing.offset property to find the other half. If HALF is B you know you have the B part of the bed and can use the facing.getOpposite().offset to find the other half. 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.
LorenzoPapi Posted December 8, 2019 Author Posted December 8, 2019 (edited) On 12/6/2019 at 9:37 PM, Draco18s said: That's going to be a nightmare to figure out where all the bits are. Because when its on the floor or ceiling, the other "half" of the block is going to not be above or below. Expand But as you said, I can't use offset, because the other "HALF" of the block won't be above or below. And btw I already have those two properties. Edited December 8, 2019 by LorenzoPapi Quote
Draco18s Posted December 8, 2019 Posted December 8, 2019 On 12/8/2019 at 7:27 AM, LorenzoPapi said: But as you said, I can't use offset, because the other "HALF" of the block won't be above or below. And btw I already have those two properties. Expand ...Did you not understand what I said? facing.offset totally tells you where the other block is because you know which half due to the HALF property. I said you couldn't do what you were doing with only a FACING property. 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.
LorenzoPapi Posted December 8, 2019 Author Posted December 8, 2019 (edited) Oops. I totally confused facing.offset with BlockPos.offset Excuse my misunderstanding. I'll try this method when I'll go back to my pc. EDIT: @Draco18s, I don't find facing.offset property. Edited December 8, 2019 by LorenzoPapi Quote
Draco18s Posted December 8, 2019 Posted December 8, 2019 (edited) Whassit called... give me a bit to find it. Oh yeah, they split it up. getXOffset(), getYOffset(), getZOffset() You can also use blockpos.offset(facing). Edited December 11, 2019 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.
LorenzoPapi Posted December 11, 2019 Author Posted December 11, 2019 Alright. Now it works. Thanks! 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.