Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mcpi] How to use setBlock to create a door? #112

Open
changgengli opened this issue May 31, 2022 · 4 comments
Open

[mcpi] How to use setBlock to create a door? #112

changgengli opened this issue May 31, 2022 · 4 comments

Comments

@changgengli
Copy link

changgengli commented May 31, 2022

I am following the answers here, but it doesn't seem to work now.

I can use setBlock in command console to create a door but not the API. Not sure if values for the block data fields are changed. I also tried getBlockWithData to get the state of a door I manually created, using setBlock with those state didn't work either.

@Marcinosoft
Copy link

I checked it with Minecraft 1.18.2 and it works but door parts have to be placed in reverse order.
First upper part, then bottom one.
Also if you want to place a door while door already exists, you have to remove bottom part first, by inserting for example AIR block before you put upper door part.

Previous door order worked with Minecraft 1.12.2 for sure.

import mcpi.minecraft as minecraft
import mcpi.block

mc = minecraft.Minecraft.create('127.0.0.1')
my_player_name = 'player_nickname'
my_player_id = mc.getPlayerEntityId(my_player_name)
x, y, z = mc.entity.getTilePos(my_player_id)

mc.setBlock(x+2, y, z, mcpi.block.AIR.id)
mc.setBlock(x+2, y+1, z, mcpi.block.DOOR_WOOD.id, 8)
mc.setBlock(x+2, y, z, mcpi.block.DOOR_WOOD.id, 0)

mc.setBlock(x+4, y, z, mcpi.block.AIR.id)
mc.setBlock(x+4, y+1, z, mcpi.block.DOOR_ACACIA.id, 8)
mc.setBlock(x+4, y, z, mcpi.block.DOOR_ACACIA.id, 0)

mc.setBlock(x+6, y, z, mcpi.block.AIR.id, 8)
mc.setBlock(x+6, y+1, z, mcpi.block.DOOR_BIRCH.id, 8)
mc.setBlock(x+6, y, z, mcpi.block.DOOR_BIRCH.id, 0)

mc.setBlock(x+8, y, z, mcpi.block.AIR.id)
mc.setBlock(x+8, y+1, z, mcpi.block.DOOR_DARK_OAK.id, 8)
mc.setBlock(x+8, y, z, mcpi.block.DOOR_DARK_OAK.id, 0)

mc.setBlock(x+10, y, z, mcpi.block.AIR.id)
mc.setBlock(x+10, y+1, z, mcpi.block.DOOR_IRON.id, 8)
mc.setBlock(x+10, y, z, mcpi.block.DOOR_IRON.id, 0)

mc.setBlock(x+12, y, z, mcpi.block.AIR.id)
mc.setBlock(x+12, y+1, z, mcpi.block.DOOR_JUNGLE.id, 8)
mc.setBlock(x+12, y, z, mcpi.block.DOOR_JUNGLE.id, 0)

mc.setBlock(x+14, y, z, mcpi.block.AIR.id)
mc.setBlock(x+14, y+1, z, mcpi.block.DOOR_SPRUCE.id, 8)
mc.setBlock(x+14, y, z, mcpi.block.DOOR_SPRUCE.id, 0)

@changgengli
Copy link
Author

I will test this, but how do you find out the order need to be reversed?

@Marcinosoft
Copy link

Every door are constructed with two parts, bottom one and upper one. In recent Minecraft somehow when you put upper part on bottom one it breaks. So I tried set upper part first. That's the whole story :)
By default RaspberryJuice is designed to wok well with 1.12.2, but it generally also works with latest Minecraft versions too, but sometimes there are suprises. For example some blocks cannot be replaced with AIR, but you can replace it with any other block like STONE, then it can be replaced with AIR.

@javier-cantu
Copy link

javier-cantu commented Jun 3, 2022

I will test this, but how do you find out the order need to be reversed?

I found it by brute force hahaha

I did a tutorial but it's in spanish but the code it's the same.
https://youtu.be/glvhzWoiV_A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants