示例#1
0
    def _load_schematics(self, load_minecraft_specs=True):
        if load_minecraft_specs:
            for premem in minecraft_specs.get_schematics():
                npy = premem["schematic"]
                memid = SchematicNode.create(self, npy_to_blocks_list(npy))
                if premem.get("name"):
                    for n in premem["name"]:
                        self.add_triple(subj=memid,
                                        pred_text="has_name",
                                        obj_text=n)
                        self.add_triple(subj=memid,
                                        pred_text="has_tag",
                                        obj_text=n)
                if premem.get("tags"):
                    for t in premem["tags"]:
                        self.add_triple(subj=memid,
                                        pred_text="has_tag",
                                        obj_text=t)

        # load single blocks as schematics
        bid_to_name = minecraft_specs.get_block_data()["bid_to_name"]
        for (d, m), name in bid_to_name.items():
            if d >= 256:
                continue
            memid = SchematicNode.create(self, [((0, 0, 0), (d, m))])
            self.add_triple(subj=memid, pred_text="has_name", obj_text=name)
            if "block" in name:
                self.add_triple(subj=memid,
                                pred_text="has_name",
                                obj_text=name.strip("block").strip())
            # tag single blocks with 'block'
            self.add_triple(subj=memid, pred_text="has_name", obj_text="block")
示例#2
0
    def _load_mob_types(self, load_mob_types=True):
        if not load_mob_types:
            return

        mob_property_data = minecraft_specs.get_mob_property_data()
        mob_name_to_properties = mob_property_data["name_to_properties"]
        for (name, m) in SPAWN_OBJECTS.items():
            type_name = "spawn " + name

            # load single mob as schematics
            memid = SchematicNode.create(self, [((0, 0, 0), (383, m))])
            self.add_triple(subj=memid,
                            pred_text="has_name",
                            obj_text=type_name)
            if "block" in type_name:
                self.add_triple(subj=memid,
                                pred_text="has_name",
                                obj_text=type_name.strip("block").strip())

            # then load properties
            memid = MobTypeNode.create(self, type_name, (383, m))
            self.add_triple(subj=memid,
                            pred_text="has_name",
                            obj_text=type_name)
            if mob_name_to_properties.get(type_name) is not None:
                for property in mob_name_to_properties[type_name]:
                    self.add_triple(subj=memid,
                                    pred_text="has_name",
                                    obj_text=property)
示例#3
0
    def convert_block_object_to_schematic(
            self, block_object_memid: str) -> "SchematicNode":
        """Save a BlockObject as a Schematic node along with the link"""
        r = self._db_read_one(
            'SELECT subj FROM Triples WHERE pred_text="_source_block_object" AND obj=?',
            block_object_memid,
        )
        if r:
            # previously converted; return old schematic
            return self.get_schematic_by_id(r[0])

        else:
            # get up to date BlockObject
            block_object = self.get_block_object_by_id(block_object_memid)

            # create schematic
            memid = SchematicNode.create(self,
                                         list(block_object.blocks.items()))

            # add triple linking the object to the schematic
            self.add_triple(subj=memid,
                            pred_text="_source_block_object",
                            obj=block_object.memid)

            return self.get_schematic_by_id(memid)
示例#4
0
    def _load_schematics(self, load_minecraft_specs=True):
        """Load all Minecraft schematics into agent memory"""
        if load_minecraft_specs:
            for premem in minecraft_specs.get_schematics():
                npy = premem["schematic"]

                # lazy loading, only store memid in db, ((0, 0, 0), (0, 0)) as a placeholder
                memid = SchematicNode.create(self, [((0, 0, 0), (0, 0))])
                self.schematics[memid] = npy_to_blocks_list(npy)

                if premem.get("name"):
                    for n in premem["name"]:
                        self.add_triple(subj=memid,
                                        pred_text="has_name",
                                        obj_text=n)
                        self.add_triple(subj=memid,
                                        pred_text="has_tag",
                                        obj_text=n)
                if premem.get("tags"):
                    for t in premem["tags"]:
                        self.add_triple(subj=memid,
                                        pred_text="has_tag",
                                        obj_text=t)

        # load single blocks as schematics
        bid_to_name = minecraft_specs.get_block_data()["bid_to_name"]
        for (d, m), name in bid_to_name.items():
            if d >= 256:
                continue
            memid = SchematicNode.create(self, [((0, 0, 0), (d, m))])
            self.add_triple(subj=memid, pred_text="has_name", obj_text=name)
            if "block" in name:
                self.add_triple(subj=memid,
                                pred_text="has_name",
                                obj_text=name.strip("block").strip())
            # tag single blocks with 'block'
            self.add_triple(subj=memid, pred_text="has_name", obj_text="block")