Skip to content

convert args to ints in getLine() - #1

Open
mattvenn wants to merge 1 commit into
martinohanlon:masterfrom
mattvenn:master
Open

mattvenn wants to merge 1 commit into
martinohanlon:masterfrom
mattvenn:master

Conversation

@mattvenn

Copy link
Copy Markdown

Hi Martin,
I started playing with your code and because I was using getPos not getTilePos I was getting conversion exceptions. I thought it would be an improvement to force all args to ints so it didn't matter which was used.

Cheers,
Matt

jdeast added a commit to jdeast/pyncraft that referenced this pull request Sep 7, 2026
Closes #5, #6, #7, #8, #9, #10, #11, #12, #13, #14.

#5  MinecraftTurtle could not be constructed at all. __init__ set the pen and
    turtle blocks to material name strings but _drawTurtle read .id and .data
    off them, which is the pre-1.13 Block API, and the last line of __init__
    calls _drawTurtle -- so the class raised AttributeError on construction and
    had been unreachable since the flattening. It now uses names throughout.
    Also passes z rather than y twice when drawing itself, takes a Block object
    in penblock() for old code, and defaults position to None instead of a
    shared mutable Vec3(0,0,0).

#6  Block raised TypeError on both hash() and repr(), because __hash__ did
    (id << 8) + data and __repr__ used %d, on ids that are now material names.
    __cmp__ has not existed since Python 2, so sorting raised too.

#7  MinecraftDrawing passed blockData as setBlock's fifth positional argument,
    which since the flattening is the block's FACING. Every directional block --
    stairs, furnaces, chests, doors, beds, torches -- silently failed to place
    and left a stray Fail in the stream. drawPoint3d and MinecraftShape.draw no
    longer forward it; the parameter stays so old calls still work.

#8  getLine bitshifts its deltas, so float coordinates raised TypeError -- and
    player.getPos() returns floats, making the most natural call the broken one.
    Now floors first. Upstream has had this fix open since 2013:
    martinohanlon/minecraft-stuff#1, whose author hit it exactly this way.
    We use math.floor rather than his int(), which truncates toward zero and
    puts negative coordinates in the wrong block.

#9  drain() decoded as cp437, but FruitJuice reads and writes the socket as
    UTF-8 and util encodes UTF-8 on the way out. Same bug upstream:
    martinohanlon/mcpi#27, attempted in mcpi#31.

#10 receive() built a new makefile() per call, each with its own buffer, so two
    replies arriving in one TCP segment meant the second was buffered and then
    thrown away with the reader. One file object for the connection now.

#11 SHOW_DEBUG and SHOW_Log defaulted to True, so importing and connecting
    printed ANSI-coloured text to stdout. Off by default; the old name still
    works.

#12 receive() returned "" when the server hung up, which does not start with
    "Fail" and so was handed back as an ordinary answer. Raises ConnectionClosed.

#13 ArrowHitEvent.__repr__ announced itself as BlockEvent.

#14 46 tests covering coordinates, the wire protocol against a fake socket, and
    the drawing helpers. Every case is a bug that shipped. They now gate the
    release: the publish workflow runs them before building, and the smoke check
    on the built wheel imports minecraftstuff and block, which is what would
    have caught 0.2.2 shipping without minecraftstuff.py.

Writing the tests turned up one more: a str is Iterable, so Coord("x", 2, 3)
took the sequence branch and complained about the number of coordinates rather
than the type.

All verified against a live 1.20 server: the turtle constructs and leaves a
trail, drawLine places stairs, Block hashes and sorts, getLine takes floats.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kq1Cjkh3bVT1WLzh5FRVQG
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

Successfully merging this pull request may close these issues.

1 participant