def make_stack_frame_from(values, out):
    stack = NBTList(NBTType.compound)
    for val in values:
        item = NBTCompound()
        if type(val) == int:
            default = val
            vtype = VarType.i32
        elif type(val) == float:
            default = val
            vtype = VarType.decimal
        elif isinstance(val, Variable):
            vtype = val.type
            default = vtype.default_val
        elif isinstance(val, VarType):
            vtype = val
            default = val.default_val
        else:
            assert False, val
        item.set(vtype.nbt_path_key, vtype.nbt_type.new(default))
        stack.append(item)
    frame = NBTCompound()
    frame.set('stack', stack)
    out.write(c.DataModifyStack(None, None, 'append', frame))
    for i, val in enumerate(values):
        if isinstance(val, Variable):
            dest = LocalStackVariable(val.type, i)
            # Variable has moved down to the previous stack frame
            val.realign_frame(1)
            val.clone_to(dest, out)
            val.realign_frame(-1)
 def apply(self, out, func):
     if isinstance(self.value, int):
         vtype = VarType.i32
         tag = NBTCompound()
         tag.set(vtype.nbt_path_key, vtype.nbt_type.new(self.value))
         out.write(c.DataModifyStack(None, None, 'append', tag))
     else:
         self.value.push_to_stack(out)
Esempio n. 3
0
 def get_cmd(self, func):
     tag = NBTCompound()
     tag.set('cmd', FuncRefNBTString(self.func))
     return c.DataModifyStack(None, None, 'append', tag,
                              self.func.namespace)
 def get_cmd(self):
     tag = NBTCompound()
     tag.set('cmd', FutureNBTString(c.Function(self.func.global_name)))
     return c.DataModifyStack(None, None, 'append', tag, c.StackFrameHead)