示例#1
0
 def add_grid_bounding_boxes_to(self, out):
     cmz = self.can_connect_to(self.x, self.y, self.z - 1)
     cpz = self.can_connect_to(self.x, self.y, self.z + 1)
     cmx = self.can_connect_to(self.x - 1, self.y, self.z)
     cpx = self.can_connect_to(self.x + 1, self.y, self.z)
     minx = 0.375
     maxx = 0.625
     minz = 0.375
     maxz = 0.625
     if cmz:
         minz = 0.0
     if cpz:
         maxz = 1.0
     if cmz or cpz:
         out.append(
             AABB(minx, 0, minz, maxx, 1.5,
                  maxz).offset(self.x, self.y, self.z))
     minz = 0.375
     maxz = 0.625
     if cmx:
         minx = 0.0
     if cpx:
         maxx = 1.0
     if cmx or cpx or not cmz and not cpz:
         out.append(
             AABB(minx, 0, minz, maxx, 1.5,
                  maxz).offset(self.x, self.y, self.z))
     if cmz:
         minz = 0.0
     if cpz:
         maxz = 1.0
     out.append(
         AABB(minx, 0, minz, maxx, 1.0,
              maxz).offset(self.x, self.y, self.z))
示例#2
0
 def grid_bounding_box(self):
     orient = self.meta & 3
     if orient != 3 or orient != 1:
         gbb = AABB(0.125, 0.0, 0.0, 0.875, 1.0, 1.0)
     else:
         gbb = AABB(0.0, 0.0, 0.125, 1.0, 1.0, 0.875)
     return gbb.offset(self.x, self.y, self.z)
示例#3
0
class Trapdoor(BlockSolid):
    number = 96
    material = materials.wood
    bounding_box_closed = AABB(0.0, 0.0, 0.0, 1.0, 0.1875, 1.0)
    bounding_boxes = [
        AABB(0.0, 0.0, 0.8125, 1.0, 1.0, 1.0),
        AABB(0.0, 0.0, 0.0, 1.0, 1.0, 0.1875),
        AABB(0.8125, 0.0, 0.0, 1.0, 1.0, 1.0),
        AABB(0.0, 0.0, 0.0, 0.1875, 1.0, 1.0)
    ]
    render_as_normal_block = False
    is_opaque_cube = False

    @property
    def is_closed(self):
        return (self.meta & 4) == 0

    @property
    def grid_bounding_box(self):
        if self.is_closed:
            return self.bounding_box_closed.offset(self.x, self.y, self.z)
        else:
            return self.bounding_boxes[self.meta & 3].offset(
                self.x, self.y, self.z)

    @property
    def can_stand_in(self):
        return self.is_closed

    @property
    def can_fall_through(self):
        return not self.can_stand_in
示例#4
0
class Ladders(BlockSolid):
    number = 65
    material = materials.circuits
    render_as_normal_block = False
    is_opaque_cube = False
    bounding_box = [
        AABB(0.0, 0.0, 0.875, 1.0, 1.0, 1.0),
        AABB(0.0, 0.0, 0.0, 1.0, 1.0, 0.125),
        AABB(0.875, 0.0, 0.0, 1.0, 1.0, 1.0),
        AABB(0.0, 0.0, 0.0, 0.125, 1.0, 1.0)
    ]

    @property
    def grid_bounding_box(self):
        if self.meta == 2:
            i = 0
        elif self.meta == 3:
            i = 1
        elif self.meta == 4:
            i = 2
        elif self.meta == 5:
            i = 3
        return self.bounding_box[i].offset(self.x, self.y, self.z)

    @property
    def can_fall_through(self):
        return True

    @property
    def can_stand_in(self):
        return True

    @property
    def is_climbable(self):
        return True
示例#5
0
 def check_aabbs(self):
     out = []
     self.add_grid_bounding_boxes_to(out)
     check = [0, 0, 0, 0]
     if len(out) == 3:
         bb = out[2]
         if fops.gt(bb.min_x, self.x):
             check[2] = -1
         elif fops.lt(bb.max_x, self.x + 1):
             check[2] = 1
         if fops.gt(bb.min_z, self.z):
             check[3] = -1
         elif fops.lt(bb.max_z, self.z + 1):
             check[3] = 1
     bb = out[1]
     if fops.gt(bb.min_x, self.x):
         check[0] = -1
     elif fops.lt(bb.max_x, self.x + 1):
         check[0] = 1
     if fops.gt(bb.min_z, self.z):
         check[1] = -1
     elif fops.lt(bb.max_z, self.z + 1):
         check[1] = 1
     if check[2] != 0 or check[3] != 0:
         if check[0] != 0:
             check[2] = check[0]
         if check[1] != 0:
             check[3] = check[1]
         yield AABB.from_block_coords(self.x + check[2] * config.PLAYER_RADIUS, self.y + 0.5, self.z + check[3] * config.PLAYER_RADIUS)
     else:
         if check[0] != 0:
             yield AABB.from_block_coords(self.x + check[0] * config.PLAYER_RADIUS, self.y + 0.5, self.z)
         if check[1] != 0:
             yield AABB.from_block_coords(self.x, self.y + 0.5, self.z + check[1] * config.PLAYER_RADIUS)
示例#6
0
 def grid_bounding_box(self):
     orient = self.meta & 3
     if orient != 3 or orient != 1:
         gbb = AABB(0.125, 0.0, 0.0, 0.875, 1.0, 1.0)
     else:
         gbb = AABB(0.0, 0.0, 0.125, 1.0, 1.0, 0.875)
     return gbb.offset(self.x, self.y, self.z)
示例#7
0
class BrewingStandBlock(BlockMultiBox):
    inventory_avoid = True
    number = 117
    material = materials.iron
    bounding_box_stand = AABB(0.4375, 0.0, 0.4375, 0.5625, 0.875, 0.5625)
    bounding_box_base = AABB(0.0, 0.0, 0.0, 1.0, 0.125, 1.0)
    render_as_normal_block = False
    is_opaque_cube = False

    def add_grid_bounding_boxes_to(self, out):
        out.append(self.bounding_box_stand.offset(self.x, self.y, self.z))
        out.append(self.bounding_box_base.offset(self.x, self.y, self.z))
示例#8
0
 def add_grid_bounding_boxes_to(self, out):
     out.append(
         AABB(0.0, 0.0, 0.0, 1.0, 0.625,
              1.0).offset(self.x, self.y, self.z))
     side = 0.125
     out.append(
         AABB(0.0, 0.0, 0.0, side, 1.0, 1.0).offset(self.x, self.y, self.z))
     out.append(
         AABB(0.0, 0.0, 0.0, 1.0, 1.0, side).offset(self.x, self.y, self.z))
     out.append(
         AABB(1.0 - side, 0.0, 0.0, 1.0, 1.0,
              1.0).offset(self.x, self.y, self.z))
     out.append(
         AABB(0.0, 0.0, 1.0 - side, 1.0, 1.0,
              1.0).offset(self.x, self.y, self.z))
示例#9
0
class Cactus(BlockSolid):
    number = 81
    material = materials.cactus
    render_as_normal_block = False
    is_opaque_cube = False
    bounding_box = AABB(0.0625, 0.0, 0.0625, 1.0 - 0.0625, 1.0 - 0.0625,
                        1.0 - 0.0625)
示例#10
0
    def _tick(self):
        if self.cancelled:
            self.status = Status.failure
            return
        if not self.player in self.world.entities.players:
            return
        eid = self.world.entities.players[self.player]
        entity = self.world.entities.get_entity(eid)
        bot_object = self.world.bot.bot_object
        bb = AABB.from_player_coords(entity.position)
        block = self.world.grid.standing_on_block(bb)
        if block is None:
            block = self.world.grid.actual_block(bb)
#        #block = self.world.grid.downward_block(bb)
        distance = bot_object.position.distance(entity.position)
        delay = distance * self.recalc_multiplier
        #don't auto-recalculate more than once a second.
        delay = delay if delay > 1 else 1
        if (self.last_block != block
#          or distance > config.PATHFIND_MAX * 0.5  #actual path may be crooked
          or time() - self.last_attempt > delay):
          #or self.last_position != self.bot.bot_object.position_grid):
            log.msg('recalculating move..')
            # Cancel any other running behaviours we're doing
            self.manager.cancel_running(priority=self.priority - 1)
            self.last_position = self.bot.bot_object.position_grid
            self.last_attempt = time()
            self.last_block = block
            self.add_subbehaviour(TravelToBehaviour, coords=block.coords,
                                  shorten_path_by=2, estimate=True)
示例#11
0
 def grid_bounding_box(self):
     direction = self.get_direction
     v7 = (self.meta & 12) >> 2
     v8 = 4 + v7 * 2
     v9 = 5 + v7 * 2
     v10 = v8 / 2.0
     if direction == 0:
         gbb = AABB((8.0 - v10) / 16.0, (12.0 - v9) / 16.0, (15.0 - v8) / 16.0, (8.0 + v10) / 16.0, 0.75, 0.9375)
     elif direction == 1:
         gbb = AABB(0.0625, (12.0 - v9) / 16.0, (8.0 - v10) / 16.0, (1.0 + v8) / 16.0, 0.75, (8.0 + v10) / 16.0)
     elif direction == 2:
         gbb = AABB((8.0 - v10) / 16.0, (12.0 - v9) / 16.0, 0.0625, (8.0 + v10) / 16.0, 0.75, (1.0 + v8) / 16.0)
     elif direction == 3:
         gbb = AABB((15.0 - v8) / 16.0, (12.0 - v9) / 16.0, (8.0 - v10) / 16.0, 0.9375, 0.75, (8.0 + v10) / 16.0)
     else:
         raise Exception("undefined cocoa bounding box for %s" % direction)
     return gbb.offset(self.x, self.y, self.z)
示例#12
0
class BlockRedstoneCircuit(BlockSolid):
    bounding_box = AABB(0.0, 0.0, 0.0, 1.0, 0.125, 1.0)
    material = materials.circuits
    render_as_normal_block = False
    is_opaque_cube = False

    @property
    def can_stand_in(self):
        return True
示例#13
0
class FlowerPotBlock(BlockSolid):
    inventory_avoid = True
    number = 140
    material = materials.circuits
    render_as_normal_block = False
    is_opaque_cube = False
    b1 = 0.375
    b2 = b1 / 2.0
    bounding_box = AABB(0.5 - b2, 0.0, 0.5 - b2, 0.5 + b2, b1, 0.5 + b2)
示例#14
0
class EndPortalFrame(BlockMultiBox):
    number = 120
    material = materials.glass
    bounding_box = AABB(0.0, 0.0, 0.0, 1.0, 0.8125, 1.0)
    bounding_box_eye_inserted = AABB(0.3125, 0.8125, 0.3125, 0.6875, 1.0,
                                     0.6875)
    is_opaque_cube = False
    inventory_avoid = True

    @property
    def eye_inserted(self):
        return (self.meta & 4) != 0

    def add_grid_bounding_boxes_to(self, out):
        out.append(self.bounding_box.offset(self.x, self.y, self.z))
        if self.eye_inserted:
            out.append(
                self.bounding_box_eye_inserted.offset(self.x, self.y, self.z))
示例#15
0
class CauldronBlock(BlockMultiBox):
    inventory_avoid = True
    number = 118
    material = materials.iron
    render_as_normal_block = False
    is_opaque_cube = False
    c = 0.125
    bounding_boxes = [
        AABB(0.0, 0.0, 0.0, 1.0, 0.3125, 1.0),
        AABB(0.0, 0.0, 0.0, c, 1.0, 1.0),
        AABB(0.0, 0.0, 0.0, 1.0, 1.0, c),
        AABB(1.0 - c, 0.0, 0.0, 1.0, 1.0, 1.0),
        AABB(0.0, 0.0, 1.0 - c, 1.0, 1.0, 1.0)
    ]

    def add_grid_bounding_boxes_to(self, out):
        for box in self.bounding_boxes:
            out.append(box.offset(self.x, self.y, self.z))
示例#16
0
class LilyPad(BlockSolid):
    number = 111
    material = materials.plants
    bounding_box = AABB(0.0, 0.0, 0.0, 1.0, 0.015625, 1.0)
    is_opaque_cube = False
    render_as_normal_block = False

    @property
    def can_stand_in(self):
        return True
示例#17
0
class EnchantmentTable(BlockSolid):
    number = 116
    material = materials.rock
    bounding_box = AABB(0.0, 0.0, 0.0, 1.0, 0.75, 1.0)
    render_as_normal_block = False
    is_opaque_cube = False

    @property
    def can_stand_in(self):
        return True
示例#18
0
 def passing_blocks_between(self, bb1, bb2):
     out = []
     ubb = bb1.union(bb2)
     blcks = self.blocks_in_aabb(ubb)
     dvect = bb1.vector_to(bb2)
     for blk in blcks:
         bb = AABB.from_block_cube(blk.coords)
         col, _ = bb1.sweep_collision(bb, dvect)
         if col:
             out.append(blk)
     return out
示例#19
0
 def _tick(self):
     if not self.world.commander.in_game:
         return
     entity = self.world.entities.get_entity(self.world.commander.eid)
     block = self.world.grid.standing_on_block(AABB.from_player_coords(entity.position))
     if block is None:
         return
     if self.last_block != block or self.last_position != self.bot.bot_object.position_grid:
         self.last_position = self.bot.bot_object.position_grid
         self.last_block = block
         self.add_subbehaviour(TravelToBehaviour, coords=block.coords, shorten_path_by=2)
示例#20
0
 def _can_stand_on(self):
     """
     can stand on top of the center of the block
     """
     if isinstance(self.block, blocks.Cactus):
         return False
     under = self.grid.get_block(self.coords[0], self.coords[1] - 1, self.coords[2])
     if not self.block.collidable and not under.is_fence and not self.block.is_water and not self.block.is_ladder_vine:
         return False
     if self.block.is_ladder_vine or self.block.is_water:
         bb = AABB.from_block_coords(self.block.coords)
         if under.is_fence:
             self.bb_stand = bb.shift(min_y=under.max_y)
         else:
             if not under.collidable or (under.collidable and fops.lt(under.max_y, bb.min_y)):
                 bb1 = bb.offset(dy=0.5)
                 if self.can_be_in(bb1):
                     bb = bb1
             self.bb_stand = bb
         self.stand_block = self.block
         self.platform = self.bb_stand.set_to(max_y=self.bb_stand.min_y)
     else:
         if under.is_fence:
             fence_top = under.maxedge_platform(y=1)
             if self.block.collidable:
                 self.platform = self.block.maxedge_platform(y=1)
                 self.stand_block = self.block
                 if fence_top.min_y > self.platform.min_y:
                     self.platform = fence_top
                     self.stand_block = under
             else:
                 self.platform = fence_top
                 self.stand_block = under
         else:
             self.platform = self.block.maxedge_platform(y=1)
             self.stand_block = self.block
         bb = AABB.from_block_coords(self.block.coords)
         self.bb_stand = bb.offset(dy=self.platform.min_y - bb.min_y)
         if not self.bb_stand.collides_on_axes(self.platform, x=True, z=True):
             return False
     return self.can_be_in(self.bb_stand)
示例#21
0
class SoulSand(BlockSolid):
    number = 88
    material = materials.sand
    bounding_box = AABB(0.0, 0.0, 0.0, 1.0, 1.0 - 0.125, 1.0)

    def on_entity_collided(self, b_obj):
        b_obj.velocities.x *= 0.4
        b_obj.velocities.z *= 0.4

    @property
    def can_stand_in(self):
        return True
示例#22
0
 def maybe_commander(self, entity):
     if self.world.commander.eid != entity.eid:
         return
     gpos = entity.grid_position
     block = self.dimension.grid.standing_on_block(AABB.from_player_coords(entity.position))
     if block is None:
         return
     if self.world.commander.last_block is not None and self.world.commander.last_block == block:
         return
     self.world.commander.last_block = block
     #TODO put some nice debug code here
     self.world.commander.last_possition = gpos
示例#23
0
class BedBlock(BlockSolid):
    inventory_avoid = True
    number = 26
    bounding_box = AABB(0.0, 0.0, 0.0, 1.0, 0.5625, 1.0)
    sub_names = ["Top", "Bottom"]
    material = materials.cloth
    render_as_normal_block = False
    is_opaque_cube = False

    @property
    def can_stand_in(self):
        return True
示例#24
0
 def add_grid_bounding_boxes_to(self, out):
     zl, zr, xl, xr = self.cross_connected()
     if (not xl or not xr) and (xl or xr or zl or zr):
         if xl and not xr:
             out.append(
                 AABB(0.0, 0.0, 0.4375, 0.5, 1.0,
                      0.5625).offset(self.x, self.y, self.z))
         elif not xl and xr:
             out.append(
                 AABB(0.5, 0.0, 0.4375, 1.0, 1.0,
                      0.5625).offset(self.x, self.y, self.z))
     else:
         out.append(
             AABB(0.0, 0.0, 0.4375, 1.0, 1.0,
                  0.5625).offset(self.x, self.y, self.z))
     if (not zl or not zr) and (xl or xr or zl or zr):
         if zl and not zr:
             out.append(
                 AABB(0.4375, 0.0, 0.0, 0.5625, 1.0,
                      0.5).offset(self.x, self.y, self.z))
         elif not zl and zr:
             out.append(
                 AABB(0.4375, 0.0, 0.5, 0.5625, 1.0,
                      1.0).offset(self.x, self.y, self.z))
     else:
         out.append(
             AABB(0.4375, 0.0, 0.0, 0.5625, 1.0,
                  1.0).offset(self.x, self.y, self.z))
示例#25
0
 def check_aabbs(self):
     out = []
     self.add_grid_bounding_boxes_to(out)
     check = [0, 0, 0, 0]
     if len(out) == 3:
         bb = out[2]
         if fops.gt(bb.min_x, self.x):
             check[2] = -1
         elif fops.lt(bb.max_x, self.x + 1):
             check[2] = 1
         if fops.gt(bb.min_z, self.z):
             check[3] = -1
         elif fops.lt(bb.max_z, self.z + 1):
             check[3] = 1
     bb = out[1]
     if fops.gt(bb.min_x, self.x):
         check[0] = -1
     elif fops.lt(bb.max_x, self.x + 1):
         check[0] = 1
     if fops.gt(bb.min_z, self.z):
         check[1] = -1
     elif fops.lt(bb.max_z, self.z + 1):
         check[1] = 1
     if check[2] != 0 or check[3] != 0:
         if check[0] != 0:
             check[2] = check[0]
         if check[1] != 0:
             check[3] = check[1]
         yield AABB.from_block_coords(
             self.x + check[2] * config.PLAYER_RADIUS, self.y + 0.5,
             self.z + check[3] * config.PLAYER_RADIUS)
     else:
         if check[0] != 0:
             yield AABB.from_block_coords(
                 self.x + check[0] * config.PLAYER_RADIUS, self.y + 0.5,
                 self.z)
         if check[1] != 0:
             yield AABB.from_block_coords(
                 self.x, self.y + 0.5,
                 self.z + check[1] * config.PLAYER_RADIUS)
示例#26
0
class FenceGate(BlockBiCollidable):
    number = 107
    material = materials.wood
    bounding_box_north_south = AABB(0.375, 0, 0, 0.625, 1.5, 1.0)
    bounding_box_east_west = AABB(0, 0, 0.375, 1.0, 1.5, 0.625)
    is_opaque_cube = False
    render_as_normal_block = False

    @property
    def is_collidable(self):
        if self.is_open:
            return False
        else:
            return True

    @property
    def can_fall_through(self):
        return not self.is_collidable

    @property
    def can_stand_in(self):
        return False

    @property
    def can_stand_on(self):
        return False

    @property
    def is_open(self):
        return (self.meta & 4) != 0

    @property
    def grid_bounding_box(self):
        if self.is_open:
            return None
        elif self.meta != 2 and self.meta != 0:
            return self.bounding_box_north_south.offset(self.x, self.y, self.z)
        else:
            return self.bounding_box_east_west.offset(self.x, self.y, self.z)
示例#27
0
class BlockSingleSlab(BlockSolid):
    bounding_box_lower = AABB(0.0, 0.0, 0.0, 1.0, 0.5, 1.0)
    bounding_box_higher = AABB(0.0, 0.5, 0.0, 1.0, 1.0, 1.0)
    render_as_normal_block = False
    is_opaque_cube = False

    @property
    def can_stand_in(self):
        return self.lower_part

    @property
    def can_stand_on(self):
        return not self.can_stand_in

    @property
    def lower_part(self):
        return self.meta & 8 == 0

    @property
    def grid_bounding_box(self):
        if self.lower_part:
            return self.bounding_box_lower.offset(self.x, self.y, self.z)
        else:
            return self.bounding_box_higher.offset(self.x, self.y, self.z)
示例#28
0
    def maybe_commander(self, entity):
        if self.world.commander.eid != entity.eid:
            return
        gpos = entity.grid_position
        block = self.world.grid.standing_on_block(
            AABB.from_player_coords(entity.position))
        if block is None:
            return
        if self.world.commander.last_block is not None and self.world.commander.last_block == block:
            return
        self.world.commander.last_block = block
        lpos = self.world.commander.last_possition
        in_nodes = self.world.navgrid.graph.has_node(block.coords)
        gs = GridSpace(self.world.grid, block=block)
        msg = "P in nm %s nm nodes %d\n" % \
            (in_nodes, self.world.navgrid.graph.node_count)
        msg += "gs_stand %s\n" % str(gs.bb_stand)
        msg += str(block) + '\n'
        msg += str(block.grid_bounding_box)
        try:
            msg += "\nsucessors %s" % str(self.world.navgrid.graph.get_succ(block.coords))
        except:
            pass
        if lpos is not None:
            gsl = GridSpace(self.world.grid, coords=lpos)
            if gsl.can_stand_on:
                pass
            else:
                gsl = GridSpace(
                    self.world.grid, coords=(lpos[0], lpos[1] - 1, lpos[2]))
                if gsl.can_stand_on:
                    lpos = gsl.coords
            if not(gsl.bb_stand is None or gs.bb_stand is None):
                msg += "\ncost from %s to %s %s\n" % \
                    (lpos, block.coords,
                     self.world.navgrid.graph.get_edge(lpos, block.coords))
                msg += "last stand %s now stand %s from %s to %s\n" % \
                    (gsl.can_stand_on, gs.can_stand_on,
                     gsl.bb_stand, gs.bb_stand)
                if gsl.can_go_between(gs, debug=True):
                    msg += "can go True with cost %s\n" % gsl.edge_cost
                else:
                    msg += "can go False\n"
                msg += "can stand between %s intersection %s" % (
                    gsl.can_stand_between(gs, debug=True), gsl.intersection)

        log.msg(msg)
        self.world.commander.last_possition = gpos
示例#29
0
 def grid_bounding_box(self):
     direction = self.get_direction
     v7 = (self.meta & 12) >> 2
     v8 = 4 + v7 * 2
     v9 = 5 + v7 * 2
     v10 = v8 / 2.0
     if direction == 0:
         gbb = AABB((8.0 - v10) / 16.0, (12.0 - v9) / 16.0,
                    (15.0 - v8) / 16.0, (8.0 + v10) / 16.0, 0.75, 0.9375)
     elif direction == 1:
         gbb = AABB(0.0625, (12.0 - v9) / 16.0, (8.0 - v10) / 16.0,
                    (1.0 + v8) / 16.0, 0.75, (8.0 + v10) / 16.0)
     elif direction == 2:
         gbb = AABB((8.0 - v10) / 16.0, (12.0 - v9) / 16.0, 0.0625,
                    (8.0 + v10) / 16.0, 0.75, (1.0 + v8) / 16.0)
     elif direction == 3:
         gbb = AABB((15.0 - v8) / 16.0, (12.0 - v9) / 16.0,
                    (8.0 - v10) / 16.0, 0.9375, 0.75, (8.0 + v10) / 16.0)
     else:
         raise Exception("undefined cocoa bounding box for %s" % direction)
     return gbb.offset(self.x, self.y, self.z)
示例#30
0
 def grid_bounding_box(self):
     att = self.meta & 7
     if att == 1:
         gbb = AABB(0.25, 0.0, 0.25, 0.75, 0.5, 0.75)
     elif att == 2:
         gbb = AABB(0.25, 0.25, 0.5, 0.75, 0.75, 1.0)
     elif att == 3:
         gbb = AABB(0.25, 0.25, 0.0, 0.75, 0.75, 0.5)
     elif att == 4:
         gbb = AABB(0.5, 0.25, 0.25, 1.0, 0.75, 0.75)
     elif att == 5:
         gbb = AABB(0.0, 0.25, 0.25, 0.5, 0.75, 0.75)
     return gbb.offset(self.x, self.y, self.z)
示例#31
0
 def add_grid_bounding_boxes_to(self, out):
     direction = self.meta & 7
     if direction == 0:
         out.append(
             AABB(0.0, 0.0, 0.0, 1.0, 0.25,
                  1.0).offset(self.x, self.y, self.z))
         out.append(
             AABB(0.375, 0.25, 0.375, 0.625, 1.0,
                  0.625).offset(self.x, self.y, self.z))
     elif direction == 1:
         out.append(
             AABB(0.0, 0.75, 0.0, 1.0, 1.0,
                  1.0).offset(self.x, self.y, self.z))
         out.append(
             AABB(0.375, 0.0, 0.375, 0.625, 0.75,
                  0.625).offset(self.x, self.y, self.z))
     elif direction == 2:
         out.append(
             AABB(0.0, 0.0, 0.0, 1.0, 1.0,
                  0.25).offset(self.x, self.y, self.z))
         out.append(
             AABB(0.25, 0.375, 0.25, 0.75, 0.625,
                  1.0).offset(self.x, self.y, self.z))
     elif direction == 3:
         out.append(
             AABB(0.0, 0.0, 0.75, 1.0, 1.0,
                  1.0).offset(self.x, self.y, self.z))
         out.append(
             AABB(0.25, 0.375, 0.0, 0.75, 0.625,
                  0.75).offset(self.x, self.y, self.z))
     elif direction == 4:
         out.append(
             AABB(0.0, 0.0, 0.0, 0.25, 1.0,
                  1.0).offset(self.x, self.y, self.z))
         out.append(
             AABB(0.375, 0.25, 0.25, 0.625, 0.75,
                  1.0).offset(self.x, self.y, self.z))
     elif direction == 5:
         out.append(
             AABB(0.75, 0.0, 0.0, 1.0, 1.0,
                  1.0).offset(self.x, self.y, self.z))
         out.append(
             AABB(0.0, 0.375, 0.25, 0.75, 0.625,
                  0.75).offset(self.x, self.y, self.z))
示例#32
0
 def extra_bounding_boxes(self, out):
     minx = 0.0
     maxx = 1.0
     miny = 0.5
     maxy = 1
     minz = 0.0
     maxz = 0.5
     if self.is_upsite_down:
         miny = 0
         maxy = 0.5
     next_box = True
     dirc = self.meta & 3
     if dirc == 0:
         blk = self.grid.get_block(self.x + 1, self.y, self.z)
         minx = 0.5
         maxz = 1.0
         if self.similar_stairs(blk):
             m3 = blk.meta & 3
             if m3 == 3 and not self.same_orientation(
                     self.x, self.y, self.z + 1):
                 maxz = 0.5
                 next_box = False
             elif m3 == 2 and not self.same_orientation(
                     self.x, self.y, self.z - 1):
                 minz = 0.5
                 next_box = False
     elif dirc == 1:
         blk = self.grid.get_block(self.x - 1, self.y, self.z)
         maxx = 0.5
         maxz = 1.0
         if self.similar_stairs(blk):
             m3 = blk.meta & 3
             if m3 == 3 and not self.same_orientation(
                     self.x, self.y, self.z + 1):
                 maxz = 0.5
                 next_box = False
             elif m3 == 2 and not self.same_orientation(
                     self.x, self.y, self.z - 1):
                 minz = 0.5
                 next_box = False
     elif dirc == 2:
         blk = self.grid.get_block(self.x, self.y, self.z + 1)
         minz = 0.5
         maxz = 1.0
         if self.similar_stairs(blk):
             m3 = blk.meta & 3
             if m3 == 1 and not self.same_orientation(
                     self.x + 1, self.y, self.z):
                 maxx = 0.5
                 next_box = False
             elif m3 == 0 and not self.same_orientation(
                     self.x - 1, self.y, self.z):
                 minx = 0.5
                 next_box = False
     elif dirc == 3:
         blk = self.grid.get_block(self.x, self.y, self.z - 1)
         if self.similar_stairs(blk):
             m3 = blk.meta & 3
             if m3 == 1 and not self.same_orientation(
                     self.x + 1, self.y, self.z):
                 maxx = 0.5
                 next_box = False
             elif m3 == 0 and not self.same_orientation(
                     self.x - 1, self.y, self.z):
                 minx = 0.5
                 next_box = False
     out.append(
         AABB(minx, miny, minz, maxx, maxy,
              maxz).offset(self.x, self.y, self.z))
     if next_box:
         minx = 0.0
         maxx = 0.5
         miny = 0.5
         maxy = 1
         minz = 0.5
         maxz = 1.0
         if self.is_upsite_down:
             miny = 0
             maxy = 0.5
         next_box = False
         if dirc == 0:
             blk = self.grid.get_block(self.x - 1, self.y, self.z)
             if self.similar_stairs(blk):
                 m3 = blk.meta & 3
                 if m3 == 3 and not self.same_orientation(
                         self.x, self.y, self.z - 1):
                     minz = 0.0
                     maxz = 0.5
                     next_box = True
                 elif m3 == 2 and not self.same_orientation(
                         self.x, self.y, self.z + 1):
                     minz = 0.5
                     maxz = 1.0
                     next_box = True
         elif dirc == 1:
             blk = self.grid.get_block(self.x + 1, self.y, self.z)
             if self.similar_stairs(blk):
                 m3 = blk.meta & 3
                 minx = 0.5
                 maxx = 1.0
                 if m3 == 3 and not self.same_orientation(
                         self.x, self.y, self.z - 1):
                     minz = 0.0
                     maxz = 0.5
                     next_box = True
                 elif m3 == 2 and not self.same_orientation(
                         self.x, self.y, self.z + 1):
                     minz = 0.5
                     maxz = 1.0
                     next_box = True
         elif dirc == 2:
             blk = self.grid.get_block(self.x, self.y, self.z - 1)
             if self.similar_stairs(blk):
                 m3 = blk.meta & 3
                 minz = 0.0
                 maxz = 0.5
                 if m3 == 1 and not self.same_orientation(
                         self.x - 1, self.y, self.z):
                     next_box = True
                 elif m3 == 0 and not self.same_orientation(
                         self.x + 1, self.y, self.z):
                     minx = 0.5
                     maxx = 1.0
                     next_box = True
         elif dirc == 3:
             blk = self.grid.get_block(self.x, self.y, self.z + 1)
             if self.similar_stairs(blk):
                 m3 = blk.meta & 3
                 if m3 == 1 and not self.same_orientation(
                         self.x - 1, self.y, self.z):
                     next_box = True
                 elif m3 == 0 and not self.same_orientation(
                         self.x + 1, self.y, self.z):
                     minx = 0.5
                     maxx = 1.0
                     next_box = True
         if next_box:
             out.append(
                 AABB(minx, miny, minz, maxx, maxy,
                      maxz).offset(self.x, self.y, self.z))
示例#33
0
 def grid_bounding_box(self):
     att = self.meta & 7
     if att == 1:
         gbb = AABB(0.25, 0.0, 0.25, 0.75, 0.5, 0.75)
     elif att == 2:
         gbb = AABB(0.25, 0.25, 0.5, 0.75, 0.75, 1.0)
     elif att == 3:
         gbb = AABB(0.25, 0.25, 0.0, 0.75, 0.75, 0.5)
     elif att == 4:
         gbb = AABB(0.5, 0.25, 0.25, 1.0, 0.75, 0.75)
     elif att == 5:
         gbb = AABB(0.0, 0.25, 0.25, 0.5, 0.75, 0.75)
     return gbb.offset(self.x, self.y, self.z)
示例#34
0
 def aabb(self):
     return AABB.from_point_and_dimensions(self.position, self.width, self.height)
示例#35
0
 def set_xyz(self, x, y, z):
     self._x = x
     self._y = y
     self._z = z
     self._aabb = AABB.from_player_coords(self.position)
示例#36
0
 def is_goal(self, current):
     x = current.coords.x
     y = current.coords.y
     z = current.coords.z
     return self.bb.collides(AABB(x, y, z, x + 1, y + config.PLAYER_HEIGHT, z + 1))
示例#37
0
class DaylightSensor(BlockSolid):
    number = 151
    material = materials.wood
    bounding_box = AABB(0.0, 0.0, 0.0, 1.0, 0.375, 1.0)
示例#38
0
 def aabb(self):
     return AABB.from_player_coords(self.position)
示例#39
0
class BlockChest(BlockSolid):
    render_as_normal_block = False
    is_opaque_cube = False
    bounding_box = AABB(0.0625, 0.0, 0.0625, 0.9375, 0.875, 0.9375)
示例#40
0
class BlockDoor(BlockSolid):
    render_as_normal_block = False
    is_opaque_cube = False
    bounding_boxes = [
        AABB(0.0, 0.0, 0.0, 0.1875, 1.0, 1.0),
        AABB(0.0, 0.0, 0.0, 1.0, 1.0, 0.1875),
        AABB(0.8125, 0.0, 0.0, 1.0, 1.0, 1.0),
        AABB(0.0, 0.0, 0.8125, 1.0, 1.0, 1.0)
    ]
    top_part = None
    bottom_part = None

    @property
    def can_fall_through(self):
        return True

    def assign_parts(self):
        if self.top_part is not None:
            return
        if self.is_top_half:
            self.top_part = self
            self.bottom_part = self.grid.get_block(self.x, self.y - 1, self.z)
        else:
            self.bottom_part = self
            self.top_part = self.grid.get_block(self.x, self.y + 1, self.z)

    @property
    def is_open(self):
        self.assign_parts()
        return (self.bottom_part.meta & 4) != 0

    @property
    def is_hinge_right(self):
        return (self.top_part.meta & 1) != 0

    @property
    def facing_index(self):
        return self.bottom_part.meta & 3

    @property
    def is_top_half(self):
        return (self.meta & 8) != 0

    @property
    def bounding_boxes_index(self):
        self.assign_parts()
        if self.is_open:
            if self.is_hinge_right:
                fi = self.facing_index - 1
                if fi >= 0:
                    return fi
                else:
                    return 3
            else:
                fi = self.facing_index + 1
                if fi < 4:
                    return fi
                else:
                    return 0
        else:
            return self.facing_index

    @property
    def grid_bounding_box(self):
        return self.bounding_boxes[self.bounding_boxes_index].offset(
            self.x, self.y, self.z)
示例#41
0
 def avoid_aabbs_in(self, bb):
     out = []
     for blk in self.blocks_in_aabb(bb):  # lava, fire, web
         if blk.is_lava or blk.number == blocks.Fire.number or blk.number == blocks.Cobweb.number:
             out.append(AABB.from_block_cube(blk.x, blk.y, blk.z))
     return out
示例#42
0
 def avoid_aabbs_in(self, bb):
     out = []
     for blk in self.blocks_in_aabb(bb):  # lava, fire, web
         if blk.is_lava or blk.number == blocks.Fire.number or blk.number == blocks.Cobweb.number:
             out.append(AABB.from_block_cube(blk.x, blk.y, blk.z))
     return out
示例#43
0
 def set_xyz(self, x, y, z):
     self._x = x
     self._y = y
     self._z = z
     self._aabb = AABB.from_player_coords(self.position)
示例#44
0
class BlockStairs(BlockMultiBox):
    render_as_normal_block = False
    is_opaque_cube = False
    bounding_box_half = AABB(0.0, 0.0, 0.0, 1.0, 0.5, 1.0)
    bounding_box_up_half = AABB(0.0, 0.5, 0.0, 1.0, 1.0, 1.0)

    @property
    def can_stand_on(self):
        return True

    @property
    def is_upsite_down(self):
        return (self.meta & 4) != 0

    def add_grid_bounding_boxes_to(self, out):
        if self.is_upsite_down:
            out.append(self.bounding_box_up_half.offset(
                self.x, self.y, self.z))
        else:
            out.append(self.bounding_box_half.offset(self.x, self.y, self.z))
        self.extra_bounding_boxes(out)

    def similar_stairs(self, blk):
        return blk.is_stairs and self.is_upsite_down == blk.is_upsite_down

    def same_orientation(self, x, y, z):
        blk = self.grid.get_block(x, y, z)
        return blk.is_stairs and blk.meta == self.meta

    def extra_bounding_boxes(self, out):
        minx = 0.0
        maxx = 1.0
        miny = 0.5
        maxy = 1
        minz = 0.0
        maxz = 0.5
        if self.is_upsite_down:
            miny = 0
            maxy = 0.5
        next_box = True
        dirc = self.meta & 3
        if dirc == 0:
            blk = self.grid.get_block(self.x + 1, self.y, self.z)
            minx = 0.5
            maxz = 1.0
            if self.similar_stairs(blk):
                m3 = blk.meta & 3
                if m3 == 3 and not self.same_orientation(
                        self.x, self.y, self.z + 1):
                    maxz = 0.5
                    next_box = False
                elif m3 == 2 and not self.same_orientation(
                        self.x, self.y, self.z - 1):
                    minz = 0.5
                    next_box = False
        elif dirc == 1:
            blk = self.grid.get_block(self.x - 1, self.y, self.z)
            maxx = 0.5
            maxz = 1.0
            if self.similar_stairs(blk):
                m3 = blk.meta & 3
                if m3 == 3 and not self.same_orientation(
                        self.x, self.y, self.z + 1):
                    maxz = 0.5
                    next_box = False
                elif m3 == 2 and not self.same_orientation(
                        self.x, self.y, self.z - 1):
                    minz = 0.5
                    next_box = False
        elif dirc == 2:
            blk = self.grid.get_block(self.x, self.y, self.z + 1)
            minz = 0.5
            maxz = 1.0
            if self.similar_stairs(blk):
                m3 = blk.meta & 3
                if m3 == 1 and not self.same_orientation(
                        self.x + 1, self.y, self.z):
                    maxx = 0.5
                    next_box = False
                elif m3 == 0 and not self.same_orientation(
                        self.x - 1, self.y, self.z):
                    minx = 0.5
                    next_box = False
        elif dirc == 3:
            blk = self.grid.get_block(self.x, self.y, self.z - 1)
            if self.similar_stairs(blk):
                m3 = blk.meta & 3
                if m3 == 1 and not self.same_orientation(
                        self.x + 1, self.y, self.z):
                    maxx = 0.5
                    next_box = False
                elif m3 == 0 and not self.same_orientation(
                        self.x - 1, self.y, self.z):
                    minx = 0.5
                    next_box = False
        out.append(
            AABB(minx, miny, minz, maxx, maxy,
                 maxz).offset(self.x, self.y, self.z))
        if next_box:
            minx = 0.0
            maxx = 0.5
            miny = 0.5
            maxy = 1
            minz = 0.5
            maxz = 1.0
            if self.is_upsite_down:
                miny = 0
                maxy = 0.5
            next_box = False
            if dirc == 0:
                blk = self.grid.get_block(self.x - 1, self.y, self.z)
                if self.similar_stairs(blk):
                    m3 = blk.meta & 3
                    if m3 == 3 and not self.same_orientation(
                            self.x, self.y, self.z - 1):
                        minz = 0.0
                        maxz = 0.5
                        next_box = True
                    elif m3 == 2 and not self.same_orientation(
                            self.x, self.y, self.z + 1):
                        minz = 0.5
                        maxz = 1.0
                        next_box = True
            elif dirc == 1:
                blk = self.grid.get_block(self.x + 1, self.y, self.z)
                if self.similar_stairs(blk):
                    m3 = blk.meta & 3
                    minx = 0.5
                    maxx = 1.0
                    if m3 == 3 and not self.same_orientation(
                            self.x, self.y, self.z - 1):
                        minz = 0.0
                        maxz = 0.5
                        next_box = True
                    elif m3 == 2 and not self.same_orientation(
                            self.x, self.y, self.z + 1):
                        minz = 0.5
                        maxz = 1.0
                        next_box = True
            elif dirc == 2:
                blk = self.grid.get_block(self.x, self.y, self.z - 1)
                if self.similar_stairs(blk):
                    m3 = blk.meta & 3
                    minz = 0.0
                    maxz = 0.5
                    if m3 == 1 and not self.same_orientation(
                            self.x - 1, self.y, self.z):
                        next_box = True
                    elif m3 == 0 and not self.same_orientation(
                            self.x + 1, self.y, self.z):
                        minx = 0.5
                        maxx = 1.0
                        next_box = True
            elif dirc == 3:
                blk = self.grid.get_block(self.x, self.y, self.z + 1)
                if self.similar_stairs(blk):
                    m3 = blk.meta & 3
                    if m3 == 1 and not self.same_orientation(
                            self.x - 1, self.y, self.z):
                        next_box = True
                    elif m3 == 0 and not self.same_orientation(
                            self.x + 1, self.y, self.z):
                        minx = 0.5
                        maxx = 1.0
                        next_box = True
            if next_box:
                out.append(
                    AABB(minx, miny, minz, maxx, maxy,
                         maxz).offset(self.x, self.y, self.z))

    def check_aabbs(self):
        out = []
        self.add_grid_bounding_boxes_to(out)
        check = [0, 0, 0, 0]
        if len(out) == 3:
            bb = out[2]
            if fops.gt(bb.min_x, self.x):
                check[2] = -1
            elif fops.lt(bb.max_x, self.x + 1):
                check[2] = 1
            if fops.gt(bb.min_z, self.z):
                check[3] = -1
            elif fops.lt(bb.max_z, self.z + 1):
                check[3] = 1
        bb = out[1]
        if fops.gt(bb.min_x, self.x):
            check[0] = -1
        elif fops.lt(bb.max_x, self.x + 1):
            check[0] = 1
        if fops.gt(bb.min_z, self.z):
            check[1] = -1
        elif fops.lt(bb.max_z, self.z + 1):
            check[1] = 1
        if check[2] != 0 or check[3] != 0:
            if check[0] != 0:
                check[2] = check[0]
            if check[1] != 0:
                check[3] = check[1]
            yield AABB.from_block_coords(
                self.x + check[2] * config.PLAYER_RADIUS, self.y + 0.5,
                self.z + check[3] * config.PLAYER_RADIUS)
        else:
            if check[0] != 0:
                yield AABB.from_block_coords(
                    self.x + check[0] * config.PLAYER_RADIUS, self.y + 0.5,
                    self.z)
            if check[1] != 0:
                yield AABB.from_block_coords(
                    self.x, self.y + 0.5,
                    self.z + check[1] * config.PLAYER_RADIUS)