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

setBlock set only 'Sandstone' #16

Open
Domroon opened this issue Sep 11, 2022 · 7 comments
Open

setBlock set only 'Sandstone' #16

Domroon opened this issue Sep 11, 2022 · 7 comments

Comments

@Domroon
Copy link

Domroon commented Sep 11, 2022

I run a spigot server and the JuiciyRaspberryPie Plugin in the Version 1.18.1 and i can only set 'Sandstone' Blocks. What's wrong here?

import mcpi.minecraft as minecraft
import mcpi.block

mc = minecraft.Minecraft.create('127.0.0.1')
x, y, z = mc.player.getTilePos()

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)
@Flapchik
Copy link

try this
mc.setBlock(x+2, y, z, "AIR")
and
mc.setBlock(x+2, y+1, z, "DOOR_WOOD", 8)

@pa7lux
Copy link

pa7lux commented Dec 21, 2022

Any ideas of how to make all scripts written with ID but not a string as parameter work again?

@Flapchik
Copy link

You need to create a simple dictionary...

blocks = {
    0: "AIR",
    1: "GRASS" 
}

@pa7lux
Copy link

pa7lux commented Dec 21, 2022

oh no... that's not the best way. I wish I could change something in mcpi files to bring it to life.
The most serious troubles are blocks with combined ids. In previous versions It looked like mc.setBlock(x,y,z, 35, 15) for lime_wool as an example. Now I can hardly redesign it with a dictionary. Also such dictionary is a real overhead.

@Flapchik
Copy link

Try to use original mcpi

@pa7lux
Copy link

pa7lux commented Dec 22, 2022

unfortunately it doesn't help =(

@cjdell
Copy link

cjdell commented Dec 26, 2023

I have a solution for this:
cjdell/mcpi@5ba6bd6

In short:

mc.setBlock(1, 2, 3, mcpi.block.TNT.id)

needs to be:

mc.setBlock(1, 2, 3, 'tnt')

This is because the newer protocol now needs the actual string representation of the block type passed over the connection rather than the integer ID. Not sure when exactly this became the case.

You will need to install my fork of the mcpi library from here:
https://github.com/cjdell/mcpi

I think you can install with pip using this command:

pip install git+https://github.com/cjdell/mcpi

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

4 participants