示例#1
0
def main():
    log = JavaClass("org/apache/logging/log4j/LogManager").getLogger("Modid")

    log.info("Hello Fabric World!")
    try:
        _fabric_item_settings = mc.ItemSettings()
        _fabric_item_settings.group(mc.ItemGroups.getMisc())

        class FabricItem(mc.Item):
            def onUse(self, world, user, hand, return_value):
                if world.isClient:
                    log.info(
                        "If You See This You Right Clicked tutorial:fabric_item"
                    )
                    world.setBlockState(user.getBlockPos().down(),
                                        mc.Blocks.getGlass().getDefaultState())
                return_value.set(mc.ActionResult.CONSUME)

        fabric_item = FabricItem(_fabric_item_settings)
        log.info(fabric_item._settings)
        mc.registry.register_item(mc.Identifier("tutorial", "fabric_item"),
                                  fabric_item)
        import sys
        log.info(str(sys.getrefcount(fabric_item)))
    except Exception as e:
        log.error(str(e))
        import traceback
        track = traceback.format_exc()
        log.error(track)
示例#2
0
class _StderrWrapper(io.StringIO):
    def flush(self):
        for line in self.getvalue().split("\n"):
            if line != "":
                _log.error(line)
sys.stderr = _StderrWrapper()

def _full_stack():
    exc = sys.exc_info()[0]
    if exc is not None:
        f = sys.exc_info()[-1].tb_frame.f_back
        stack = traceback.extract_stack(f)
    else:
        stack = traceback.extract_stack()[:-1]  # last one would be full_stack()
    trc = 'Traceback (most recent call last):\n'
    stackstr = trc + ''.join(traceback.format_list(stack))
    if exc is not None:
        stackstr += '  ' + traceback.format_exc().lstrip(trc)
    return stackstr

_PythonThread = JavaClass("io/github/nylonmc/core/PythonThread")

while True:
    try:
        exec(_PythonThread.getCodeInternal())
    except Exception as e:
        _log.error("Error Running User Python Code")
        _log.error(str(e))
        _log.error(_full_stack())
    _PythonThread.getjThread().resume()
    _PythonThread.getPyThread().suspend()