Skip to content

Commit

Permalink
Added facings list, fixed a bunch of bugs introduced in recent refact…
Browse files Browse the repository at this point in the history
…oring. Added explicit roof fill option. Added roof to tower example. Fixed box-shed.
  • Loading branch information
r1chardj0n3s committed Jan 7, 2017
1 parent b598647 commit e5d5d49
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 81 deletions.
70 changes: 41 additions & 29 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,12 @@ use the "hand" name here too:
pos.add(1, 0, 4) # East/X 1, Up/Y 0 and North/Z 4
``chat("message")``
Have the message appear in the in-game chat.
``water(pos)``
Have a water source be created at the position, for example
``water(pos.up())``. This will only work if the target position is clear.
``lava(pos)``
Have a water source be created at the position. This will only work if
the target position is clear.
``clear(pos)``
Clear the block at the position nominated.
``colors``
A list of all the standard Minecraft dye color names. Combine with
random.choice() for fun!

Note: using clear with the Python Block position will remove the block!
A list of all the standard Minecraft dye color names.
``facings``
A list of all the standard Minecraft facing names.

Choose colors and facings with random.choice() for extra creativity!

Event Handlers
~~~~~~~~~~~~~~
Expand Down Expand Up @@ -125,7 +117,13 @@ Doc TBD::
Event Handlers
~~~~~~~~~~~~~~

Doc TBD::
Both Python Blocks and Hands may define a "run" function::

def run():
# invoked when the Python Wand is used on the block

Additionally, Python Blocks may define other functions related
to world interaction with the block::

def powerOn():
# invoked when a redstone signal powers block
Expand Down Expand Up @@ -289,13 +287,19 @@ You may alter block variations after they've been put down::
hand.put('wool', color='red')
hand.alter(color='yellow') # any of the keywords above are acceptable

Roof styles include "hip", "gable" and "box-gable" (filled gable). To get a box gable
Roof styles include "hip", "gable", "box-gable" (flat ended gable),
"shed" (sloped one direction) and "box-shed". To get a box gable
with overhang you could::

hand.roof(7, 5, 'oak', style='box-gable')
hand.sidle(1)
hand.roof(9, 5, 'dark_oak', style='gable')

By default roofs are filled to prevent spawning, but you can turn it
off:

hand.roof(7, 5, 'oak', fill=False)


Examples
~~~~~~~~
Expand Down Expand Up @@ -330,12 +334,12 @@ Put each of these functions on a different page of the book::
def tower():
hand.down()
hand.circle(5, 'cobblestone', fill=True)
for i in range(8):
for i in range(9):
hand.up()
if i in (3, 7):
hand.circle(5, 'planks', fill=True)
hand.circle(5, 'stone')
if i in (0, 4):
if i in (0, 4, 8):
hand.put('torch')

# page 2: door and ladder access
Expand Down Expand Up @@ -369,24 +373,32 @@ Put each of these functions on a different page of the book::

# page 4: the complete tower
def run():
with hand.remember(): tower()
with hand.remember(): access()
with hand.remember(): furnish()
with hand.remember():
tower()
with hand.remember():
access()
furnish()
hand.back(6)
hand.sidle(5)
hand.up(9)
hand.roof(11, 11, 'dark_oak', fill=False)

Roof demo::

STYLES = ["hip", "gable", "shed",
"box-gable", "box-shed"]
hand.face('east')
for style in STYLES:
for i in range(4):
hand.forward(2)
hand.roof(7, 5, 'oak', style=style)
hand.left()
hand.forward(2)
hand.forward(20)
def roofs(fill):
for style in STYLES:
for i in range(4):
hand.forward(2)
hand.roof(7, 5, 'oak', style=style,
fill=fill)
hand.left()
hand.forward(2)
hand.forward(20)
with hand.remember():
roofs(False)
hand.sidle(20)
roofs(True)

Wand
----
Expand Down Expand Up @@ -537,4 +549,4 @@ This is not an exhaustive list, and should probably be put into github issues.
- texture map replacement
*hand*
- more roof generation styles
- allow roof generation to work with plain blocks as fallback
- tick() handling
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ protected void keyTyped(char typedChar, int keyCode) throws IOException {
}
if (GuiScreen.isKeyComboCtrlV(keyCode)) {
this._editString(GuiScreen.getClipboardString());
this.setCursorPosition(0, 0);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void roof(PyObject[] args, String[] kws) throws BlockTypeError {
if (this.world == null || this.world.isRemote) return;
ArgParser r = new ArgParser("roof", s("pos", "width", "depth", "blockname"),
// TODO PyRegistry.BLOCK_VARIATIONS
s("style", "color", "facing", "type", "half", "shape"));
s("style", "color", "facing", "type", "half", "shape", "fill"));
r.parse(args, kws);
MyBlockPos mpos = (MyBlockPos)r.get("pos").__tojava__(MyBlockPos.class);
RoofGen.roof(r, this.world, mpos.blockPos, EnumFacing.NORTH);
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/net/mechanicalcat/pycode/script/HandMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,13 @@ private String[] s(String ... strings) {
return strings;
}

private IBlockState getBlockVariant(ArgParser spec) {
return PyRegistry.getBlockVariant(spec, this.hand.getPosition(), this.hand.getHorizontalFacing(),
(WorldServer)this.world);
}

public void put(PyObject[] args, String[] kws) {
if (this.world == null || this.world.isRemote) return;
ArgParser r = new ArgParser("put", s("blockname"), PyRegistry.BLOCK_VARIATIONS);
r.parse(args, kws);
this.put(this.hand.getFacedPos(), getBlockVariant(r), this.hand.getHorizontalFacing());
IBlockState state = PyRegistry.getBlockVariant(r, this.hand.getFacedPos(), this.hand.getHorizontalFacing(),
(WorldServer)this.world);
this.put(this.hand.getFacedPos(),state, this.hand.getHorizontalFacing());
}

public void alter(PyObject[] args, String[] kws) {
Expand Down Expand Up @@ -217,7 +214,7 @@ public void roof(PyObject[] args, String[] kws) throws BlockTypeError {
if (this.world == null || this.world.isRemote) return;
ArgParser r = new ArgParser("roof", s("width", "depth", "blockname"),
// TODO PyRegistry.BLOCK_VARIATIONS
s("style", "color", "facing", "type", "half", "shape"));
s("style", "color", "facing", "type", "half", "shape", "fill"));
r.parse(args, kws);
RoofGen.roof(r, this.world, this.hand.getPosition(), this.hand.getHorizontalFacing());
}
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/net/mechanicalcat/pycode/script/PyRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,21 @@ public static IBlockState getBlockVariant(ArgParser spec, BlockPos pos, EnumFaci
}
IBlockState block_state = block.getDefaultState();
EnumFacing opposite = facing.getOpposite();
BlockPos faced = pos.offset(facing);
PropertyDirection direction;

block_state = modifyBlockStateFromSpec(block_state, spec, facing);

// if we haven't had an explicit facing set then try to determine a good one
if (!spec.has("facing")) {
try {
direction = (PropertyDirection) block_state.getBlock().getClass().getField("FACING").get(block_state.getBlock());
if (world.isAirBlock(faced)) {
// check whether the next pos along (pos -> faced -> farpos) is solid (attachable)
BlockPos farpos = faced.add(facing.getDirectionVec());
direction = (PropertyDirection)block.getClass().getField("FACING").get(block);
if (world.isAirBlock(pos)) {
// check whether the next pos along (pos -> farpos) is solid (attachable)
BlockPos farpos = pos.offset(facing);
if (world.isSideSolid(farpos, opposite, true)) {
// attach in faced pos on farpos
block_state = block_state.withProperty(direction, opposite);
FMLLog.fine("attach in faced pos=%s on farpos=%s", pos, opposite);
FMLLog.fine("attach in pos=%s facing=%s", pos, opposite);
}
}
} catch (NoSuchFieldException | IllegalAccessException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,12 @@ public boolean eval(WorldServer world, BlockPos pos) {
}
}

private String[] utils = {"water", "lava", "clear", "colors"};
private String[] utils = {"colors", "facings"};

public static HashMap<String, EnumDyeColor> COLORMAP = new HashMap<String, EnumDyeColor>();
public static HashMap<String, EnumFacing> FACINGMAP = new HashMap<String, EnumFacing>();
public static List<String> colors = new LinkedList<>();
public static List<String> facings = new LinkedList<>();
public static void init() {
COLORMAP.put("white", EnumDyeColor.WHITE);
COLORMAP.put("orange", EnumDyeColor.ORANGE);
Expand Down Expand Up @@ -246,6 +247,9 @@ public static void init() {
for (String name : COLORMAP.keySet()) {
colors.add(name);
}
for (String name : FACINGMAP.keySet()) {
facings.add(name);
}
}
}

Expand Down
Loading

0 comments on commit e5d5d49

Please sign in to comment.