From 7587adf4eee2782e3d99bf429285d602e81e2220 Mon Sep 17 00:00:00 2001 From: Byteandahalf Date: Wed, 23 Apr 2014 21:21:22 -0400 Subject: [PATCH 01/19] Create custom block render types --- .../mcpelauncher/ScriptManager.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/net/zhuoweizhang/mcpelauncher/ScriptManager.java b/src/net/zhuoweizhang/mcpelauncher/ScriptManager.java index 0edb1265..7503d80f 100644 --- a/src/net/zhuoweizhang/mcpelauncher/ScriptManager.java +++ b/src/net/zhuoweizhang/mcpelauncher/ScriptManager.java @@ -207,6 +207,7 @@ public static void initJustLoadedScript(Context ctx, Script script, String sourc classConstantsToJSObject(ItemCategory.class)); ScriptableObject.defineClass(scope, NativeBlockApi.class); ScriptableObject.defineClass(scope, NativeServerApi.class); + ScriptableObject.defineClass(scope, NativeBlockRendererApi.class); RendererManager.defineClasses(scope); } catch (Exception e) { e.printStackTrace(); @@ -665,6 +666,7 @@ public static String getAllApiMethodsDescriptions() { appendApiMethods(builder, NativeItemApi.class, "Item"); appendApiMethods(builder, NativeBlockApi.class, "Block"); appendApiMethods(builder, NativeServerApi.class, "Server"); + appendApiMethods(builder, NativeBlockRendererApi.class, "BlockRenderer"); return builder.toString(); } @@ -1210,6 +1212,12 @@ public static native void nativeAddItemFurnace(int x, int y, int z, int slot, in public static native int nativeGetItemCountFurnace(int x, int y, int z, int slot); public static native void nativeSetItemMaxDamage(int id, int maxDamage); + + // Custom block renderers + public static native void nativeRenderStandardBlock(int blockId, int x, int y, int z); + + public static native void nativeRenderCrossBlock(int blockId, int x, int y, int z); + // setup public static native void nativeSetupHooks(int versionCode); @@ -2317,6 +2325,26 @@ public String getClassName() { return "Gui"; } } + + private static class NativeBlockRendererApi extends ScriptableObject { + public NativeBlockRendererApi() { + } + + @JSStaticFunction + public static void renderStandardBlock(int blockId, int x, int y, int z) { + nativeRenderStandardBlock(blockId, x, y, z); + } + + @JSStaticFunction + public static void renderCrossBlock(int blockId, int x, int y, int z) { + nativeRenderCrossBlock(blockId, x, y, z); + } + + @Override + public String getClassName() { + return "BlockRenderer"; + } + } private static class SelectLevelRequest { public String dir; From d919c10dc30e3f9e4bf34e3b03b98621cbf1fb83 Mon Sep 17 00:00:00 2001 From: Byteandahalf Date: Wed, 23 Apr 2014 22:29:04 -0400 Subject: [PATCH 02/19] Create custom block render types --- jni/modscript_nextgen.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/jni/modscript_nextgen.cpp b/jni/modscript_nextgen.cpp index b42ef723..851d3082 100644 --- a/jni/modscript_nextgen.cpp +++ b/jni/modscript_nextgen.cpp @@ -163,6 +163,10 @@ static void (*bl_Packet_Packet)(void*); static void (*bl_ClientSideNetworkHandler_handleMessagePacket_real)(void*, void*, MessagePacket*); static void** bl_MessagePacket_vtable; +// Custom block renderers +static void (*bl_TileRenderer_tesselateBlockInWorld)(Tile*, int, int, int); + + bool bl_text_parse_color_codes = true; //custom blocks @@ -1118,6 +1122,20 @@ JNIEXPORT jlongArray JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_na return uuidArray; } +// Custom block renderers +JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeRenderStandardBlock + (JNIEnv *env jclass clazz, jint blockId, jint x, jint y, jint z) { + Tile* tile = bl_Tile_tiles[blockId]; + if(tile == NULL) return; + + bl_TileRenderer_tesselateBlockinWorld(tile, x, y, z); +} + +JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeAddVertex + () { + // BLANK FOR NOW +} + void bl_cppNewLevelInit() { bl_entityUUIDMap.clear(); } From 279c50832a44f4dfe936d39a911251ed53486ed9 Mon Sep 17 00:00:00 2001 From: Byteandahalf Date: Thu, 24 Apr 2014 09:45:31 -0400 Subject: [PATCH 03/19] Create custom block renderers --- jni/modscript_nextgen.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/jni/modscript_nextgen.cpp b/jni/modscript_nextgen.cpp index 851d3082..f8bd8033 100644 --- a/jni/modscript_nextgen.cpp +++ b/jni/modscript_nextgen.cpp @@ -969,7 +969,7 @@ JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeAd JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeAddFurnaceRecipe (JNIEnv *env, jclass clazz, jint inputId, jint outputId, jint outputDamage) { ItemInstance outputStack; - bl_setItemInstance(&outputStack, outputId, 1, outputDamage); // Should this be null? You don't need count, not sure how to omit it completely + bl_setItemInstance(&outputStack, outputId, 1, outputDamage); FurnaceRecipes* recipes = bl_FurnaceRecipes_getInstance(); bl_FurnaceRecipes_addFurnaceRecipe(recipes, inputId, outputStack); } @@ -1131,9 +1131,10 @@ JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeRe bl_TileRenderer_tesselateBlockinWorld(tile, x, y, z); } -JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeAddVertex - () { - // BLANK FOR NOW +JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeAddVertexUV + (JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z, jint blockId) { + // TODO: Convert textures on Java side with bitwise/bitshift operators + bl_Tesselator_vertexUV(x, y, z); } void bl_cppNewLevelInit() { From 07da5ddb5960c03e44914c8f478db80588faba2c Mon Sep 17 00:00:00 2001 From: Byteandahalf Date: Fri, 25 Apr 2014 09:45:43 -0400 Subject: [PATCH 04/19] Create custom block renderers --- jni/modscript_nextgen.cpp | 43 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/jni/modscript_nextgen.cpp b/jni/modscript_nextgen.cpp index f8bd8033..d5d4602e 100644 --- a/jni/modscript_nextgen.cpp +++ b/jni/modscript_nextgen.cpp @@ -164,7 +164,11 @@ static void (*bl_ClientSideNetworkHandler_handleMessagePacket_real)(void*, void* static void** bl_MessagePacket_vtable; // Custom block renderers +static void (*bl_TileRenderer_tesselateInWorld)(Tile*, int, int, int); + static void (*bl_TileRenderer_tesselateBlockInWorld)(Tile*, int, int, int); +static void (*bl_TileRenderer_tesselateCrossInWorld)(Tile*, int, int, int); +static void (*bl_TileRenderer_tesselateTorchInWorld)(Tile*, int, int, int); bool bl_text_parse_color_codes = true; @@ -252,6 +256,31 @@ void bl_RakNetInstance_connect_hook(RakNetInstance* rakNetInstance, char const* bl_RakNetInstance_connect_real(rakNetInstance, host, port); } +void bl_TileRenderer_tesselateInWorld_hook(Tile* tile, int x, int y, int z) { + JNIEnv *env; + + int attachStatus = bl_JavaVM->GetEnv((void**) &env, JNI_VERSION_1_2); + if(attachStatus == JNI_EDETACHED) { + bl_JavaVM->AttachCurrentThread(&env, NULL); + } + + int blockId = tile->id; + + // Don't allow PREVENT_DEFAULT_STATUS to be invoked, as it would break all block rendering in the game + // And nuke everything, leaving only pigs, cows, sheep, and chickens + jmethodID mid = env->GetStaticMethodID(bl_scriptmanager_class, "blockRendererCallback", "(III)V"); + + // TODO: The above is missing one argument + + env->CallStaticVoidMethod(bl_scriptmanager_class, mid, blockId, x, y, z); + + if(attachStatus == JNI_EDETACHED) { + bl_JavaVM->DetachCurrentThread(); + } + + bl_TileRenderer_tesselateInWorld_real(tile, x, y, z); +} + void bl_Font_drawSlow_hook(Font* font, char const* text, int length, float xOffset, float yOffset, int color, bool isShadow) { if (bl_text_parse_color_codes) { char const* currentTextBegin = text; //the current coloured section @@ -1200,6 +1229,18 @@ void bl_setuphooks_cppside() { dlsym(RTLD_DEFAULT, "_ZNK4Tile16getDescriptionIdEv"); bl_initCustomBlockVtable(); + + // This method switches out the Tile* render type and calls into the render type's respective tesselator + bl_TileRenderer_tesselateInWorld = (void(*)(Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer16tesselateInWorldEP4Tileiii"); + + + // To render a standard block into the world; Use Tile::setShape to change the size and shape of it + bl_TileRenderer_tesselateBlockInWorld = (void (*)(Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer21tesselateBlockInWorldEP4Tileiii"); + // To render a cross block into the world; Use the tesselator to render a vertexUV into the location, in a cross shape + bl_TileRenderer_tesselateCrossInWorld = (void (*)(Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer21tesselateCrossInWorldEP4Tileiii"); + // To render a torch into the world at the given location. I think I can hook the angled torch renderer to make a torch at an angle + // That's an experiment for later. + bl_TileRenderer_tesselateTorchInWorld = (void (*)(Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer21tesselateTorchInWorldEP4Tileiii"); bl_I18n_strings = (std::map *) dlsym(RTLD_DEFAULT, "_ZN4I18n8_stringsE"); bl_Item_setIcon = (void (*)(Item*, std::string const&, int)) dlsym(mcpelibhandle, "_ZN4Item7setIconERKSsi"); @@ -1219,7 +1260,7 @@ void bl_setuphooks_cppside() { bl_Tile_getTexture = (TextureUVCoordinateSet* (*)(Tile*, int, int)) dlsym(mcpelibhandle, "_ZN4Tile10getTextureEii"); bl_Tile_getTextureUVCoordinateSet = (void (*)(TextureUVCoordinateSet*, Tile*, std::string const&, int)) dlsym(mcpelibhandle, "_ZN4Tile25getTextureUVCoordinateSetERKSsi"); - bl_Recipes_getInstance = (Recipes* (*)()) dlsym(mcpelibhandle, "_ZN7Recipes11getInstanceEv"); + bl_Recipes_getInstance =Recipes* (*)()) dlsym(mcpelibhandle, "_ZN7Recipes11getInstanceEv"); bl_Recipes_addShapelessRecipe = (void (*)(Recipes*, ItemInstance const&, std::vector const&)) dlsym(mcpelibhandle, "_ZN7Recipes18addShapelessRecipeERK12ItemInstanceRKSt6vectorINS_4TypeESaIS4_EE"); bl_FurnaceRecipes_getInstance = (FurnaceRecipes* (*)()) dlsym(mcpelibhandle, "_ZN14FurnaceRecipes11getInstanceEv"); From b9b9f9021d1759112d1b27636b9a9f74e5931be0 Mon Sep 17 00:00:00 2001 From: Byteandahalf Date: Fri, 25 Apr 2014 13:01:27 -0400 Subject: [PATCH 05/19] Create custom block renderers --- jni/modscript_nextgen.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/jni/modscript_nextgen.cpp b/jni/modscript_nextgen.cpp index d5d4602e..19dbf33b 100644 --- a/jni/modscript_nextgen.cpp +++ b/jni/modscript_nextgen.cpp @@ -1160,10 +1160,20 @@ JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeRe bl_TileRenderer_tesselateBlockinWorld(tile, x, y, z); } -JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeAddVertexUV - (JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z, jint blockId) { - // TODO: Convert textures on Java side with bitwise/bitshift operators - bl_Tesselator_vertexUV(x, y, z); +JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeRenderCrossBlock + (JNIEnv *env, jclass clazz, jint blockId, jint x, jint y, jint z) { + Tile* tile = bl_Tile_tiles[blockId]; + if(tile == NULL) return; + + bl_TileRenderer_tesselateCrossInWorld(tile, x, y, z); +} + +JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeRenderTorchBlock + (JNIEnv *env, jclass clazz, jint blockId, jint x, jint y, jint z) { + Tile* tile = bl_Tile_tiles[blockId]; + if(tile == NULL) return; + + bl_TileRenderer_tesselateTorchInWorld(tile, x, y, z); } void bl_cppNewLevelInit() { From d34bf7b25cfab92fa0fb054059e47baaf1f7240b Mon Sep 17 00:00:00 2001 From: Byteandahalf Date: Fri, 25 Apr 2014 13:12:15 -0400 Subject: [PATCH 06/19] Create custom block renderers --- jni/modscript_nextgen.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jni/modscript_nextgen.cpp b/jni/modscript_nextgen.cpp index 19dbf33b..faf60e8b 100644 --- a/jni/modscript_nextgen.cpp +++ b/jni/modscript_nextgen.cpp @@ -268,9 +268,9 @@ void bl_TileRenderer_tesselateInWorld_hook(Tile* tile, int x, int y, int z) { // Don't allow PREVENT_DEFAULT_STATUS to be invoked, as it would break all block rendering in the game // And nuke everything, leaving only pigs, cows, sheep, and chickens - jmethodID mid = env->GetStaticMethodID(bl_scriptmanager_class, "blockRendererCallback", "(III)V"); + jmethodID mid = env->GetStaticMethodID(bl_scriptmanager_class, "blockRendererCallback", "(ZIII)V"); - // TODO: The above is missing one argument + // TODO: Get information on the above env->CallStaticVoidMethod(bl_scriptmanager_class, mid, blockId, x, y, z); @@ -1270,7 +1270,7 @@ void bl_setuphooks_cppside() { bl_Tile_getTexture = (TextureUVCoordinateSet* (*)(Tile*, int, int)) dlsym(mcpelibhandle, "_ZN4Tile10getTextureEii"); bl_Tile_getTextureUVCoordinateSet = (void (*)(TextureUVCoordinateSet*, Tile*, std::string const&, int)) dlsym(mcpelibhandle, "_ZN4Tile25getTextureUVCoordinateSetERKSsi"); - bl_Recipes_getInstance =Recipes* (*)()) dlsym(mcpelibhandle, "_ZN7Recipes11getInstanceEv"); + bl_Recipes_getInstance = (Recipes* (*)()) dlsym(mcpelibhandle, "_ZN7Recipes11getInstanceEv"); bl_Recipes_addShapelessRecipe = (void (*)(Recipes*, ItemInstance const&, std::vector const&)) dlsym(mcpelibhandle, "_ZN7Recipes18addShapelessRecipeERK12ItemInstanceRKSt6vectorINS_4TypeESaIS4_EE"); bl_FurnaceRecipes_getInstance = (FurnaceRecipes* (*)()) dlsym(mcpelibhandle, "_ZN14FurnaceRecipes11getInstanceEv"); From 8e94fa80725814e37a8a741fabf6a7ff7abc65bc Mon Sep 17 00:00:00 2001 From: Byteandahalf Date: Fri, 25 Apr 2014 13:21:10 -0400 Subject: [PATCH 07/19] Create custom block renderers --- src/net/zhuoweizhang/mcpelauncher/ScriptManager.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/net/zhuoweizhang/mcpelauncher/ScriptManager.java b/src/net/zhuoweizhang/mcpelauncher/ScriptManager.java index 7503d80f..0f999c56 100644 --- a/src/net/zhuoweizhang/mcpelauncher/ScriptManager.java +++ b/src/net/zhuoweizhang/mcpelauncher/ScriptManager.java @@ -298,6 +298,10 @@ public static void leaveGameCallback(boolean thatboolean) { public static void attackCallback(int attacker, int victim) { callScriptMethod("attackHook", attacker, victim); } + + public static void blockRendererCallback(int blockId, int x, int y, int z) { + callScriptMethod("renderBlockHook", blockId, x, y, z); + } public static void tickCallback() { callScriptMethod("modTick"); @@ -1217,6 +1221,8 @@ public static native void nativeAddItemFurnace(int x, int y, int z, int slot, in public static native void nativeRenderStandardBlock(int blockId, int x, int y, int z); public static native void nativeRenderCrossBlock(int blockId, int x, int y, int z); + + public static native void nativeRenderTorchBlock(int blockId, int x, int y, int z); // setup @@ -2331,12 +2337,12 @@ public NativeBlockRendererApi() { } @JSStaticFunction - public static void renderStandardBlock(int blockId, int x, int y, int z) { + public static void renderBlock(int blockId, int x, int y, int z) { nativeRenderStandardBlock(blockId, x, y, z); } @JSStaticFunction - public static void renderCrossBlock(int blockId, int x, int y, int z) { + public static void renderCross(int blockId, int x, int y, int z) { nativeRenderCrossBlock(blockId, x, y, z); } From 386b1a2eff33307b74f22435c0fbbcac4115b835 Mon Sep 17 00:00:00 2001 From: Byteandahalf Date: Fri, 25 Apr 2014 13:24:13 -0400 Subject: [PATCH 08/19] Create custom block renderers --- jni/modscript_nextgen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jni/modscript_nextgen.cpp b/jni/modscript_nextgen.cpp index faf60e8b..9045ae14 100644 --- a/jni/modscript_nextgen.cpp +++ b/jni/modscript_nextgen.cpp @@ -164,7 +164,7 @@ static void (*bl_ClientSideNetworkHandler_handleMessagePacket_real)(void*, void* static void** bl_MessagePacket_vtable; // Custom block renderers -static void (*bl_TileRenderer_tesselateInWorld)(Tile*, int, int, int); +static void (*bl_TileRenderer_tesselateInWorld_real)(Tile*, int, int, int); static void (*bl_TileRenderer_tesselateBlockInWorld)(Tile*, int, int, int); static void (*bl_TileRenderer_tesselateCrossInWorld)(Tile*, int, int, int); @@ -1241,7 +1241,7 @@ void bl_setuphooks_cppside() { bl_initCustomBlockVtable(); // This method switches out the Tile* render type and calls into the render type's respective tesselator - bl_TileRenderer_tesselateInWorld = (void(*)(Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer16tesselateInWorldEP4Tileiii"); + bl_TileRenderer_tesselateInWorld_real = (void(*)(Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer16tesselateInWorldEP4Tileiii"); // To render a standard block into the world; Use Tile::setShape to change the size and shape of it From 7fbf49927040e0d30e2efd909c08d646a4a9cea8 Mon Sep 17 00:00:00 2001 From: Byteandahalf Date: Fri, 25 Apr 2014 16:23:18 -0400 Subject: [PATCH 09/19] Create custom block render types --- src/net/zhuoweizhang/mcpelauncher/ScriptManager.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/net/zhuoweizhang/mcpelauncher/ScriptManager.java b/src/net/zhuoweizhang/mcpelauncher/ScriptManager.java index 0f999c56..70180a79 100644 --- a/src/net/zhuoweizhang/mcpelauncher/ScriptManager.java +++ b/src/net/zhuoweizhang/mcpelauncher/ScriptManager.java @@ -1511,6 +1511,7 @@ public static int spawnMob(double x, double y, double z, int typeId, String tex) return entityId; } + @JSStaticFunction public static String getSignText(int x, int y, int z, int line) { if (line < 0 || line >= 4) @@ -2346,6 +2347,11 @@ public static void renderCross(int blockId, int x, int y, int z) { nativeRenderCrossBlock(blockId, x, y, z); } + @JSStaticFunction + public static void renderTorch(int blockId, int x, int y, int z) { + nativeRenderTorchBlock(blockId, x, y, z); + } + @Override public String getClassName() { return "BlockRenderer"; From 25e928e1cd5db16e393fd48876e5928fc7e77c30 Mon Sep 17 00:00:00 2001 From: Byteandahalf Date: Fri, 25 Apr 2014 22:10:47 -0400 Subject: [PATCH 10/19] Create custom blocks renderers --- jni/modscript_nextgen.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/jni/modscript_nextgen.cpp b/jni/modscript_nextgen.cpp index 9045ae14..ddc1fe6e 100644 --- a/jni/modscript_nextgen.cpp +++ b/jni/modscript_nextgen.cpp @@ -266,11 +266,8 @@ void bl_TileRenderer_tesselateInWorld_hook(Tile* tile, int x, int y, int z) { int blockId = tile->id; - // Don't allow PREVENT_DEFAULT_STATUS to be invoked, as it would break all block rendering in the game - // And nuke everything, leaving only pigs, cows, sheep, and chickens - jmethodID mid = env->GetStaticMethodID(bl_scriptmanager_class, "blockRendererCallback", "(ZIII)V"); - - // TODO: Get information on the above + // Don't allow PREVENT_DEFAULT_STATUS to be invoked, as it would nuke all block rendering in the game + jmethodID mid = env->GetStaticMethodID(bl_scriptmanager_class, "blockRendererCallback", "(IIII)V"); env->CallStaticVoidMethod(bl_scriptmanager_class, mid, blockId, x, y, z); From 188a200b3bbc7f272d089fcb5350f8315e9cd2b4 Mon Sep 17 00:00:00 2001 From: Byteandahalf Date: Fri, 25 Apr 2014 22:37:07 -0400 Subject: [PATCH 11/19] Create custom block render types --- jni/modscript.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/jni/modscript.h b/jni/modscript.h index 65dc6266..d94838e5 100644 --- a/jni/modscript.h +++ b/jni/modscript.h @@ -717,6 +717,30 @@ JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativePl JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeClearSlotInventory (JNIEnv *, jclass, jint); +/* + * Class: net_zhuoweizhang_mcpelauncher_ScriptManager + * Method: nativeRenderStandardBlock + * Signature: (IIII)V + */ +JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeRenderStandardBlock + (JNIEnv *, jclass, jint, jint, jint, jint); + +/* + * Class: net_zhuoweizhang_mcpelauncher_ScriptManager + * Method: nativeRenderCrossBlock + * Signature: (IIII)V + */ +JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeRenderCrossBlock + (JNIEnv *, jclass, jint, jint, jint, jint); + +/* + * Class: net_zhuoweizhang_mcpelauncher_ScriptManager + * Method: nativeRenderTorchBlock + * Signature: (IIII)V + */ +JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeRenderTorchBlock + (JNIEnv *, jclass, jint, jint, jint, jint); + /* * Class: net_zhuoweizhang_mcpelauncher_ScriptManager * Method: nativeGetSlotInventory From 0c6cf4904d38ba95dc615ca4c2906b375682aee4 Mon Sep 17 00:00:00 2001 From: Byteandahalf Date: Sat, 26 Apr 2014 11:33:33 -0400 Subject: [PATCH 12/19] Create custom block render types --- jni/modscript_nextgen.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/jni/modscript_nextgen.cpp b/jni/modscript_nextgen.cpp index ddc1fe6e..e270dc9a 100644 --- a/jni/modscript_nextgen.cpp +++ b/jni/modscript_nextgen.cpp @@ -550,6 +550,19 @@ JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeCl env->ReleaseStringUTFChars(text, utfChars); } +JNIEXPORT int JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeGetBlockRenderShape + (JNIEnv *env, jclass clazz, jint blockId) { + Tile* tile = bl_Tile_tiles[blockId]; + if(tile == NULL) return 0; + + return bl_CustomBlock_getRenderShapeHook(tile); +} + +JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeSetBlockRenderShape + (JNIEnv *env, jclass clazz, jint blockId, jint renderType) { + bl_custom_block_renderShape[blockId] = renderType; +} + Item* bl_constructItem(int id) { Item* retval = (Item*) ::operator new((std::size_t) 72); bl_Item_Item(retval, id - 0x100); @@ -1150,11 +1163,11 @@ JNIEXPORT jlongArray JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_na // Custom block renderers JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeRenderStandardBlock - (JNIEnv *env jclass clazz, jint blockId, jint x, jint y, jint z) { + (JNIEnv *env, jclass clazz, jint blockId, jint x, jint y, jint z) { Tile* tile = bl_Tile_tiles[blockId]; if(tile == NULL) return; - bl_TileRenderer_tesselateBlockinWorld(tile, x, y, z); + bl_TileRenderer_tesselateBlockInWorld(tile, x, y, z); } JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeRenderCrossBlock From e9f5e503e4b96f845f96c00adb01a0f1b43f7208 Mon Sep 17 00:00:00 2001 From: Byteandahalf Date: Sat, 26 Apr 2014 11:34:30 -0400 Subject: [PATCH 13/19] Create custom block render types --- .../zhuoweizhang/mcpelauncher/ScriptManager.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/net/zhuoweizhang/mcpelauncher/ScriptManager.java b/src/net/zhuoweizhang/mcpelauncher/ScriptManager.java index 70180a79..32f2020f 100644 --- a/src/net/zhuoweizhang/mcpelauncher/ScriptManager.java +++ b/src/net/zhuoweizhang/mcpelauncher/ScriptManager.java @@ -1216,6 +1216,10 @@ public static native void nativeAddItemFurnace(int x, int y, int z, int slot, in public static native int nativeGetItemCountFurnace(int x, int y, int z, int slot); public static native void nativeSetItemMaxDamage(int id, int maxDamage); + + public static native int nativeGetBlockRenderShape(int blockId); + + public static native void nativeSetBlockRenderShape(int blockId, int renderType); // Custom block renderers public static native void nativeRenderStandardBlock(int blockId, int x, int y, int z); @@ -2220,6 +2224,16 @@ public static void setDestroyTime(int blockId, double time) { nativeBlockSetDestroyTime(blockId, (float) time); } + @JSStaticFunction + public static int getRenderType(int blockId) { + return nativeGetBlockRenderShape(blockId); + } + + @JSStaticFunction + public static void setRenderType(int blockId, int renderType) { + nativeSetBlockRenderShape(blockId, renderType); + } + @JSStaticFunction public static void setExplosionResistance(int blockId, double resist) { nativeBlockSetExplosionResistance(blockId, (float) resist); From c52bf577a976013c8de4ec94a29db7df99b72cf8 Mon Sep 17 00:00:00 2001 From: Byteandahalf Date: Sat, 26 Apr 2014 11:35:02 -0400 Subject: [PATCH 14/19] Create custom block render types --- jni/modscript.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/jni/modscript.h b/jni/modscript.h index d94838e5..468e9cdc 100644 --- a/jni/modscript.h +++ b/jni/modscript.h @@ -405,6 +405,22 @@ JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeDe JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeBlockSetDestroyTime (JNIEnv *, jclass, jint, jfloat); +/* + * Class: net_zhuoweizhang_mcpelauncher_ScriptManager + * Method: nativeGetBlockRenderShape + * Signature: (I)I + */ +JNIEXPORT int JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeGetBlockRenderShape + (JNIEnv *, jclass, jint); + +/* + * Class: net_zhuoweizhang_mcpelauncher_ScriptManager + * Method: nativeSetBlockRenderShape + * Signature: (II)V + */ +JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeSetBlockRenderShape + (JNIEnv *, jclass, jint, jint); + /* * Class: net_zhuoweizhang_mcpelauncher_ScriptManager * Method: nativeBlockSetExplosionResistance From a8a656b9196a81d89dc3becedc1d5f62c85d96c5 Mon Sep 17 00:00:00 2001 From: Byteandahalf Date: Sat, 26 Apr 2014 12:47:49 -0400 Subject: [PATCH 15/19] Create custom block renderers --- jni/modscript_nextgen.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jni/modscript_nextgen.cpp b/jni/modscript_nextgen.cpp index e270dc9a..8d3c4268 100644 --- a/jni/modscript_nextgen.cpp +++ b/jni/modscript_nextgen.cpp @@ -1251,7 +1251,8 @@ void bl_setuphooks_cppside() { bl_initCustomBlockVtable(); // This method switches out the Tile* render type and calls into the render type's respective tesselator - bl_TileRenderer_tesselateInWorld_real = (void(*)(Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer16tesselateInWorldEP4Tileiii"); + bl_TileRenderer_tesselateInWorld = (void(*)(Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer16tesselateInWorldEP4Tileiii"); + mcpelauncher_hook(bl_TileRenderer_tesselateInWorld, (void*) &bl_TileRenderer_tesselateInWorld_hook, (void**) &bl_TileRenderer_tesselateInWorld_real); // To render a standard block into the world; Use Tile::setShape to change the size and shape of it From 63b3a0d1626fc728c0ae978a3aa7dbedac262dd3 Mon Sep 17 00:00:00 2001 From: Byteandahalf Date: Sat, 26 Apr 2014 13:42:30 -0400 Subject: [PATCH 16/19] Fix TileRenderer_tesselateInWorld hook --- jni/modscript_nextgen.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jni/modscript_nextgen.cpp b/jni/modscript_nextgen.cpp index 8d3c4268..1de8d2eb 100644 --- a/jni/modscript_nextgen.cpp +++ b/jni/modscript_nextgen.cpp @@ -1251,10 +1251,9 @@ void bl_setuphooks_cppside() { bl_initCustomBlockVtable(); // This method switches out the Tile* render type and calls into the render type's respective tesselator - bl_TileRenderer_tesselateInWorld = (void(*)(Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer16tesselateInWorldEP4Tileiii"); + void* bl_TileRenderer_tesselateInWorld = (void(*)(Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer16tesselateInWorldEP4Tileiii"); mcpelauncher_hook(bl_TileRenderer_tesselateInWorld, (void*) &bl_TileRenderer_tesselateInWorld_hook, (void**) &bl_TileRenderer_tesselateInWorld_real); - // To render a standard block into the world; Use Tile::setShape to change the size and shape of it bl_TileRenderer_tesselateBlockInWorld = (void (*)(Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer21tesselateBlockInWorldEP4Tileiii"); // To render a cross block into the world; Use the tesselator to render a vertexUV into the location, in a cross shape From 68c26b4c93628d58ffbfc3aa34bd49d18aa272f6 Mon Sep 17 00:00:00 2001 From: Byteandahalf Date: Sat, 26 Apr 2014 13:47:43 -0400 Subject: [PATCH 17/19] Corrected the hook? --- jni/modscript_nextgen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jni/modscript_nextgen.cpp b/jni/modscript_nextgen.cpp index 1de8d2eb..4d885fc1 100644 --- a/jni/modscript_nextgen.cpp +++ b/jni/modscript_nextgen.cpp @@ -1251,7 +1251,7 @@ void bl_setuphooks_cppside() { bl_initCustomBlockVtable(); // This method switches out the Tile* render type and calls into the render type's respective tesselator - void* bl_TileRenderer_tesselateInWorld = (void(*)(Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer16tesselateInWorldEP4Tileiii"); + void* bl_TileRenderer_tesselateInWorld = dlsym(RTLD_DEFAULT, "_ZN12TileRenderer16tesselateInWorldEP4Tileiii"); mcpelauncher_hook(bl_TileRenderer_tesselateInWorld, (void*) &bl_TileRenderer_tesselateInWorld_hook, (void**) &bl_TileRenderer_tesselateInWorld_real); // To render a standard block into the world; Use Tile::setShape to change the size and shape of it From b26a47380a0904a6c880be63393e8817e1a16997 Mon Sep 17 00:00:00 2001 From: Zhuowei Zhang Date: Sat, 26 Apr 2014 17:30:49 -0400 Subject: [PATCH 18/19] Pass in the TileRenderer instance when calling tile renderer methods --- jni/modscript_nextgen.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/jni/modscript_nextgen.cpp b/jni/modscript_nextgen.cpp index 4d885fc1..45a30408 100644 --- a/jni/modscript_nextgen.cpp +++ b/jni/modscript_nextgen.cpp @@ -164,11 +164,13 @@ static void (*bl_ClientSideNetworkHandler_handleMessagePacket_real)(void*, void* static void** bl_MessagePacket_vtable; // Custom block renderers -static void (*bl_TileRenderer_tesselateInWorld_real)(Tile*, int, int, int); +static void (*bl_TileRenderer_tesselateInWorld_real)(void*, Tile*, int, int, int); -static void (*bl_TileRenderer_tesselateBlockInWorld)(Tile*, int, int, int); -static void (*bl_TileRenderer_tesselateCrossInWorld)(Tile*, int, int, int); -static void (*bl_TileRenderer_tesselateTorchInWorld)(Tile*, int, int, int); +static void (*bl_TileRenderer_tesselateBlockInWorld)(void*, Tile*, int, int, int); +static void (*bl_TileRenderer_tesselateCrossInWorld)(void*, Tile*, int, int, int); +static void (*bl_TileRenderer_tesselateTorchInWorld)(void*, Tile*, int, int, int); + +static void* bl_TileRenderer_instance; bool bl_text_parse_color_codes = true; @@ -256,13 +258,15 @@ void bl_RakNetInstance_connect_hook(RakNetInstance* rakNetInstance, char const* bl_RakNetInstance_connect_real(rakNetInstance, host, port); } -void bl_TileRenderer_tesselateInWorld_hook(Tile* tile, int x, int y, int z) { +void bl_TileRenderer_tesselateInWorld_hook(void* tileRenderer, Tile* tile, int x, int y, int z) { JNIEnv *env; int attachStatus = bl_JavaVM->GetEnv((void**) &env, JNI_VERSION_1_2); if(attachStatus == JNI_EDETACHED) { bl_JavaVM->AttachCurrentThread(&env, NULL); } + + bl_TileRenderer_instance = tileRenderer; int blockId = tile->id; @@ -275,7 +279,7 @@ void bl_TileRenderer_tesselateInWorld_hook(Tile* tile, int x, int y, int z) { bl_JavaVM->DetachCurrentThread(); } - bl_TileRenderer_tesselateInWorld_real(tile, x, y, z); + bl_TileRenderer_tesselateInWorld_real(tileRenderer, tile, x, y, z); } void bl_Font_drawSlow_hook(Font* font, char const* text, int length, float xOffset, float yOffset, int color, bool isShadow) { @@ -1167,7 +1171,7 @@ JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeRe Tile* tile = bl_Tile_tiles[blockId]; if(tile == NULL) return; - bl_TileRenderer_tesselateBlockInWorld(tile, x, y, z); + bl_TileRenderer_tesselateBlockInWorld(bl_TileRenderer_instance, tile, x, y, z); } JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeRenderCrossBlock @@ -1175,7 +1179,7 @@ JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeRe Tile* tile = bl_Tile_tiles[blockId]; if(tile == NULL) return; - bl_TileRenderer_tesselateCrossInWorld(tile, x, y, z); + bl_TileRenderer_tesselateCrossInWorld(bl_TileRenderer_instance, tile, x, y, z); } JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeRenderTorchBlock @@ -1183,7 +1187,7 @@ JNIEXPORT void JNICALL Java_net_zhuoweizhang_mcpelauncher_ScriptManager_nativeRe Tile* tile = bl_Tile_tiles[blockId]; if(tile == NULL) return; - bl_TileRenderer_tesselateTorchInWorld(tile, x, y, z); + bl_TileRenderer_tesselateTorchInWorld(bl_TileRenderer_instance, tile, x, y, z); } void bl_cppNewLevelInit() { @@ -1255,12 +1259,12 @@ void bl_setuphooks_cppside() { mcpelauncher_hook(bl_TileRenderer_tesselateInWorld, (void*) &bl_TileRenderer_tesselateInWorld_hook, (void**) &bl_TileRenderer_tesselateInWorld_real); // To render a standard block into the world; Use Tile::setShape to change the size and shape of it - bl_TileRenderer_tesselateBlockInWorld = (void (*)(Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer21tesselateBlockInWorldEP4Tileiii"); + bl_TileRenderer_tesselateBlockInWorld = (void (*)(void*, Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer21tesselateBlockInWorldEP4Tileiii"); // To render a cross block into the world; Use the tesselator to render a vertexUV into the location, in a cross shape - bl_TileRenderer_tesselateCrossInWorld = (void (*)(Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer21tesselateCrossInWorldEP4Tileiii"); + bl_TileRenderer_tesselateCrossInWorld = (void (*)(void*, Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer21tesselateCrossInWorldEP4Tileiii"); // To render a torch into the world at the given location. I think I can hook the angled torch renderer to make a torch at an angle // That's an experiment for later. - bl_TileRenderer_tesselateTorchInWorld = (void (*)(Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer21tesselateTorchInWorldEP4Tileiii"); + bl_TileRenderer_tesselateTorchInWorld = (void (*)(void*, Tile*, int, int, int)) dlsym(RTLD_DEFAULT, "_ZN12TileRenderer21tesselateTorchInWorldEP4Tileiii"); bl_I18n_strings = (std::map *) dlsym(RTLD_DEFAULT, "_ZN4I18n8_stringsE"); bl_Item_setIcon = (void (*)(Item*, std::string const&, int)) dlsym(mcpelibhandle, "_ZN4Item7setIconERKSsi"); From 686f5dc461d46641c8004394ed7815dfa6d44f49 Mon Sep 17 00:00:00 2001 From: Zhuowei Zhang Date: Sat, 26 Apr 2014 19:33:51 -0400 Subject: [PATCH 19/19] Only call a JavaScript renderer when the render type of the block is set to -1 --- jni/modscript_nextgen.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/jni/modscript_nextgen.cpp b/jni/modscript_nextgen.cpp index 45a30408..89ecdb90 100644 --- a/jni/modscript_nextgen.cpp +++ b/jni/modscript_nextgen.cpp @@ -259,16 +259,19 @@ void bl_RakNetInstance_connect_hook(RakNetInstance* rakNetInstance, char const* } void bl_TileRenderer_tesselateInWorld_hook(void* tileRenderer, Tile* tile, int x, int y, int z) { + bl_TileRenderer_instance = tileRenderer; + + int blockId = tile->id; + if (bl_custom_block_renderShape[blockId] != -1) { + bl_TileRenderer_tesselateInWorld_real(tileRenderer, tile, x, y, z); + return; + } JNIEnv *env; int attachStatus = bl_JavaVM->GetEnv((void**) &env, JNI_VERSION_1_2); if(attachStatus == JNI_EDETACHED) { bl_JavaVM->AttachCurrentThread(&env, NULL); } - - bl_TileRenderer_instance = tileRenderer; - - int blockId = tile->id; // Don't allow PREVENT_DEFAULT_STATUS to be invoked, as it would nuke all block rendering in the game jmethodID mid = env->GetStaticMethodID(bl_scriptmanager_class, "blockRendererCallback", "(IIII)V");