Jump to content

[1.12.2]Double-part block breaking problem


LorenzoPapi

Recommended Posts

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 by LorenzoPapi
Link to comment
Share on other sites

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?

 

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.

Link to comment
Share on other sites

5 hours ago, 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.

That's strange. This works for me.

5 hours ago, Draco18s said:

Uh, what does this comment even mean?

Don't care about comments, they're just sentences without any logic sometimes.

5 hours ago, 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.

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.

5 hours ago, 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...

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.

Link to comment
Share on other sites

24 minutes ago, 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.

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.

 

28 minutes ago, 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.

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.

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.

Link to comment
Share on other sites

22 hours ago, 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.

I didn't think about it. Thanks for explaining!

23 hours ago, LorenzoPapi said:

I'll change this tomorrow, I'm really tired.

Actually, this entire piece of code was copied and pasted from BlockDoor.class . And it works.

22 hours ago, 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

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 by LorenzoPapi
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.

Link to comment
Share on other sites

On 12/6/2019 at 10: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.

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 by LorenzoPapi
Link to comment
Share on other sites

9 hours ago, 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.

...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.

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.

Link to comment
Share on other sites

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 by Draco18s

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.

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.