Git Product home page Git Product logo

Comments (8)

gilesknap avatar gilesknap commented on June 1, 2024

Hi @jhutar thanks for the interest in this project.

You have come across something I have not tried yet. I assume this is because doors take up 2 blocks and the setblock command applies to a single block only.

Have you tried adding

world.set_block(pos + Direction.WEST + Direction.UP,  Item.ACACIA_DOOR)

from mciwb.

gilesknap avatar gilesknap commented on June 1, 2024

OK it looks like that won't work because you need to set the DataValue of the two door blocks to represent the different halves of a door. See https://www.digminecraft.com/game_commands/setblock_door.php#:~:text=Place%20Top%20of%20Door&text=Type%20the%20command%20in%20the,South%20from%20our%20current%20location.

After work today I'll take a look at doing this from mciwb I may need to make a change to the library to allow passing of DataValues (but it might already be there).

from mciwb.

jhutar avatar jhutar commented on June 1, 2024

Thank you!

from mciwb.

gilesknap avatar gilesknap commented on June 1, 2024

Hi @jhutar, I have an update. But have run out of time this evening to get the tests working against latest dependencies.
So if you want to try a preview of this right away then you can do a git pull origin dev to get the development branch. Later this week I'll fix the tests and merge into main branch.

What I have done is add nbt= parameter to the set_block command (nbt is Named Binary Tag that some blocks have to add info). Its basic because it relies on the caller knowing what strings to pass for NBTs but will do for now.

I have also added a Utils class that implements a place_door function by utilising set_block with nbt values. So now you can do, for example:

 world.utils.place_door(pos, Item.ACACIA_DOOR, facing=Direction.NORTH, right_hinge=True)

Have a go and see if it works for you.

Here is the code for place_door as an example of how to use the nbts:

    def place_door(
        self,
        pos: Vec3,
        door_type: Item,
        facing: Direction = Direction.NORTH,
        open: bool = False,
        right_hinge: bool = False,
    ):
        """
        Place a door in the world

        :param pos: the position of the door in the world
        :param door_type: the type of door to place
        :param direction: the direction the door should face
        :param open: whether the door should be open or closed
        :param left_hinge: whether the door should have a left or right hinge
        """
        if not str(door_type).upper().endswith("_DOOR"):
            raise ValueError("door_type must be a door")

        hinge = "right" if right_hinge else "left"
        open = "true" if open else "false"

        common_nbt = [
            f"hinge={hinge}",
            f"open={open}",
            f"facing={Direction.name(facing)}",
        ]

        nbt = ["half=lower"] + common_nbt
        # doors wont replace doors with different nbt so need to clear first
        self.world.set_block(pos, Item.AIR)
        self.world.set_block(pos, door_type, nbt=nbt)
        nbt = ["half=upper"] + common_nbt
        self.world.set_block(pos + Direction.UP, Item.AIR)
        self.world.set_block(pos + Direction.UP, door_type, nbt=nbt)

from mciwb.

gilesknap avatar gilesknap commented on June 1, 2024

@jhutar did you get a chance to try this? Did it work for you? Thanks/

from mciwb.

jhutar avatar jhutar commented on June 1, 2024

Sorry for delay. Works as expected now, thank you!

pos = world.player.pos
world.set_block(pos, Item.STONE)
world.set_block(pos + Direction.UP, Item.STONE)
world.set_block(pos + Direction.WEST * 2, Item.STONE)
world.set_block(pos + Direction.WEST * 2 + Direction.UP, Item.STONE)
world.utils.place_door(pos + Direction.WEST, Item.ACACIA_DOOR, facing=Direction.NORTH, right_hinge=True)

BTW is it possible that before it was possible to open a mciwb shell --player jhutar shell before user/client connected to server? I have a feeling it worked before when I installed mciwb from pip. Now when I switched to git install in both main and dev branches it does not work (world.player.pos causes ERROR: AttributeError: 'NoneType' object has no attribute 'pos'). It is OK, I was just surprised I have not hit it before.

from mciwb.

gilesknap avatar gilesknap commented on June 1, 2024

@jhutar thanks for getting back to me.

It should be possible to connect with no player logged into the server. You should get an error but everything continues to run and then you can later do world.add_player("myplayername").

So if that is not what happens then maybe I have introduced a bug.

from mciwb.

gilesknap avatar gilesknap commented on June 1, 2024

@jhutar This fix is now merged into main #106

from mciwb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.