Comments (8)
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.
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.
Thank you!
from mciwb.
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.
@jhutar did you get a chance to try this? Did it work for you? Thanks/
from mciwb.
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.
@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.
@jhutar This fix is now merged into main #106
from mciwb.
Related Issues (20)
- Would you be interested in a chapter about drawing image? HOT 1
- Connecting without a player logged in fails HOT 3
- Handling of player not in world HOT 1
- TODO
- monitor kills thread on exception HOT 1
- break up the Iwb class HOT 5
- provide save and load HOT 1
- reconnecting a player fails HOT 1
- "if blocks" sub type of execute HOT 1
- Need to enable the windows subsystem for linux optional component for ubuntu WSL HOT 10
- Having trouble installing Docker Desktop HOT 4
- Older version of rcon package causes `pip install mciwb` to fail HOT 5
- Unhandled exception error in event loop HOT 6
- Action signs blank by default? HOT 22
- Question about Backup and Restore HOT 6
- For Loops Nether Portal HOT 7
- One-line docstring should fit on one line with quotes (found 3) (D200)
- Undo buffer
- Document Java ediition
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mciwb.