def gen_assign(n, g=True): slot = c.Var('memory_slot_%d' % n) self.define_objective('memory_slot_%d' % n, None) return c.ExecuteChain() \ .cond('if') \ .score_range(mar, c.ScoreRange(n, n)) \ .run(c.OpAssign(mbr if g else slot, slot if g else mbr))
def apply(self, out): chain = c.ExecuteChain() for component in self.components: component.apply(self, chain, out) try: yield chain finally: self.close()
def _branch_apply(out, if_true, if_false, apply): inverted = not if_true if inverted: if_true, if_false = if_false, if_true have_false = if_false is not None if have_false: # Workaround: execute store doesn't set success to 0 if failed # See MC-125058 # Can't use execute store anyway because it locks the success # tracker. See MC-125145 out.write(c.SetConst(c.Var('success_tracker'), 0)) true_fn = c.Function(if_true.global_name) out.write( apply(c.ExecuteChain().cond('unless' if inverted else 'if')).run( true_fn)) if have_false: false_fn = c.Function(if_false.global_name) out.write(c.ExecuteChain().cond('if').score_range( c.Var('success_tracker'), c.ScoreRange(0, 0)).run(false_fn))
def _store_from_cmd(self, cmd, out): out.write(c.ExecuteChain() .store('result') .score(self.ref) .run(cmd))
def _store_from_cmd(self, cmd, out): out.write(c.ExecuteChain() .store('result') .nbt(self.storage, self.path, self.type.nbt_type. exec_store_name, 1 / self.type.scale) .run(cmd))
def _write_to_reference(self, ref, out): out.write(c.ExecuteChain() .store('result') .score(ref) .run(self.read()))
def gen_fn(fn, p): return c.ExecuteChain() \ .cond('if') \ .score_range(mar, c.ScoreRange(p.min, p.max)) \ .run(c.Function(pair_name(fn, p)))