zhuowei/RaspberryJuice

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

changgengli opened this issue · 4 comments

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.

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)

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

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.

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