• 0

    posted a message on Modding Swords

    Sorry that downloading didn't work, I forgot to add an important line:

    A new file couldn't be created because the necessary directories don't exist, therefore they must first be created, which is done by this line:

    file.getParentFile().mkdirs();

    It first gets the parent file of the to be created jpg-image, which is simply the folder in which it should be. It then creates all the directories for this folder.


    Another problem with the code was that ModPE.setItem() can use as a texture only a Minecraft texture that already exists. (In the code below I used the camera texture as it is used rarely.)

    What you can do however is to override this texture. The function that overrides textures can't use the path to an image for the texture, it needs the path as an URI (https://en.wikipedia.org/wiki/URI), which is why I put File://localhost/ in front of the path.


    This is how the code for that looks:


    var filePath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "/games/com.mojang/ModScript/MasterSword/images/";
    var fileName = "masterSword.jpg";
    try{
    if(!java.io.File(filePath + fileName).exists()){
    var file = new java.io.File(filePath + fileName);
    file.getParentFile().mkdirs();
    file.createNewFile();
    var fos = new java.io.FileOutputStream(file);
    var url = "http://i.imgur.com/8cvUB5X.jpg";
    var response = android.net.http.AndroidHttpClient.newInstance("").execute(new org.apache.http.client.methods.HttpGet(url)).getEntity().writeTo(fos);
    fos.close();
    }
    }catch(err){
    //optional error handling
    }
    var texture = "File://localhost/" + filePath + fileName;
    ModPE.overrideTexture("camera", texture);
    ModPE.setItem(500, "camera", null, "Master Sword", 1);

    function attackHook(attacker, victim){
    if(Player.getCarriedItem() == 500){
    var dmg = 15;
    Entity.setHealth(victim, Entity.getHealth(victim) - dmg);
    }
    }


    In theory (if BlockLauncher supports this) you should be able to simplify this since an URL is just a type of URI:


    var url = "http://i.imgur.com/8cvUB5X.jpg";
    ModPE.overrideTexture("camera", url);
    ModPE.setItem(500, "camera", null, "Master Sword", 1);

    function attackHook(attacker, victim){
    if(Player.getCarriedItem() == 500){
    var dmg = 15;
    Entity.setHealth(victim, Entity.getHealth(victim) - dmg);
    }
    }


    When I tested this code the ModPE.overrideTexture()-function didn't work, in both versions. I don't know whether this is a bug in the current BlockLauncher-App or if something else is wrong.

    The best way to fix this is probably to use a texture pack with just the camera-texture replaced (or whichever texture you want to use).

    Of course this situation as a whole is not good, after all there are only so many textures in MCPE. I'm sorry that I don't really now if you can just add a texture somehow.


    The parameters of the setItem function are: ModPE.setItem(Id, texture, texture-version, name, max-stack-size);


    If you want a list of all textures there are you can:

    -Copy the MCPE-APK to some other directory. (On my device it is located at /data/app/com.mojang.minecraftpe-1/base.apk. If you want an easier way to locate it you can use for example FX File Explorer.)

    -Rename the file from .apk to .zip (it really is just a zip archive).

    -Open this zip-archive and go to assets/resource_packs/vanilla/textures/items.

    Posted in: MCPE: Mod / Tool Help & Requests
  • 0

    posted a message on Modding Swords

    I don't know what's wrong with your code.

    Could you post/pm it, so I can look what could be wrong? Also, do you get an error message?

    Posted in: MCPE: Mod / Tool Help & Requests
  • 0

    posted a message on Saving a .txt at a ModPE Script (Javascript) on android
    Quote from TpsModz»

    what If I want to save my mod menu and when you open BlockLuncher everthing that has been done is saved as it was when you closed blockluncher


    What do you mean by mod menu? A graphical menu that your mod uses?

    Posted in: MCPE: Mod / Tool Help & Requests
  • 2

    posted a message on Modding Swords

    You can't use an image from the internet as if it would be an image stored on the device.

    The image has to be downloaded before it can be used in your mod.

    You can:

    1) Tell the person who downloads your mod to download the images for it, too, and put them in a specific folder with a specific name so that your mod can use them. Not recommended, the user just wants to download the mod an run it without having to worry about images.

    2) Create a variable that stores the file as a Byte-Array and write this to a file and then use this file.

    3) Download the image from the internet and use this file.


    A possible way to use solution 3):


    First of all, the url to the image shouldn't start with // since // is a part of the url to specify a protocol but for this to work this part has to be complete.

    So replace // with https://.

    Next, you never used the texture-variable. You wrote "texture" when calling the ModPE.setItem()-method which would give this method a string containing texture and not the previous defined variable.

    I also added some of these: ;


    A little bit improved version:

    /*Master Sword*/

    var texture = "https://i.imgur.com/oJlYgpy.jpg";

    ModPE.setItem(500, texture, 0, "Master Sword");

    function attackHook(attacker, victim){

    if(Player.getCarriedItem() == 500){

    var dmg = 15;

    Entity.setHealth(victim, Entity.getHealth(victim) - dmg);

    }

    }


    This would still result in an error since the previous explained image-problem is still unsolved.


    You can download the image and use it this way:


    //specifiy where the file should be saved on the device and under which name. You can customize these two.

    var filePath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "/games/com.mojang/ModScript/MasterSword/images/";

    var fileName = "masterSword.jpg";

    //Put the following parts in a try-catch block. Error can easily occur, for example when there is now internet connection.

    try{

    //check whether the image already exists. This should be the case when the mod is started for the second time.

    //When the image already exists there is no need to download it again.

    if(!java.io.File(filePath + fileName).exists()){

    //specify a file with the filePath and fileName variables
    var file = new java.io.File(filePath + fileName);

    //create the file:
    file.createNewFile();

    //In programming in general you don't just put stuff into a file, you use a stream.

    //This stream is usually buffered to speed up the overall process of using a file.

    //Create a Stream to put things into the file:
    var fos = new java.io.FileOutputStream(file);

    //specify the url to download the image from:

    //This url has to refer to only an image and not a whole website!

    var url = "https://i.imgur.com/oJlYgpy.jpg";

    //Write data to the file using the url above:
    var response = android.net.http.AndroidHttpClient.newInstance("").execute(new org.apache.http.client.methods.HttpGet(url)).getEntity().writeTo(fos);

    //Close the Stream now:
    fos.close();

    }
    }catch(err){
    //optional error handling
    }

    //Now the image is downloaded an ready to use.

    /*Master Sword*/

    //change the texture variable to the path of the downloaded image:

    var texture = filePath + fileName;

    ModPE.setItem(500, texture, 0, "Master Sword");

    function attackHook(attacker, victim){

    if(Player.getCarriedItem() == 500){

    var dmg = 15;

    Entity.setHealth(victim, Entity.getHealth(victim) - dmg);

    }

    }


    This should work.


    You should know that the method that is used in this example to get the image from the internet is deprecated: https://developer.android.com/sdk/api_diff/22/changes/android.net.http.AndroidHttpClient


    You should use URL ( https://developer.android.com/reference/java/net/URL ) to get an input-stream from the internet ( https://developer.android.com/reference/java/net/URL#openConnection() ).

    You should also do this in background using AsyncTask ( https://developer.android.com/reference/android/os/AsyncTask ).

    As you see, this is not an easy thing to do.

    The example solution is a pretty easy way to accomplish this but, if possible, I recommend to google how you should do this, but that's really not a topic for a beginner.

    Posted in: MCPE: Mod / Tool Help & Requests
  • 0

    posted a message on How to generate ores random with ModPE, (nearly) lagless and automatical

    var tick=0;
    var curX=0;
    var curY=0;
    var curZ=0;
    var cX=0;
    var cY=0;
    var cZ=0;
    var count=0;
    var changeBack=false;

    /*
    You can change:
    The Ore Block (line 22) (You can add more, too)
    The high where it start generating the ore (line 186 and line 188)
    The function setTile2 (line 164), but this is not important, but, if you want, you can change what for blocks it replace with ore and what for blocks not
    Copy - Paste the part where it generates ore (line 180 - ...) for more veines of one ore in one chunk and for other ores
    Change the probability to generate one ore-vein (line 181)
    */

    try{
    Block.defineBlock(220, "Copper Ore", [["copper_ore", 0]], 1, false, 0); //define a block, in this example it should be copper ore
    }catch(error){
    print("Import the texture pack first!");
    }

    function modTick(){
    tick++;
    if(tick%100==0){//every 5 seconds the function doTick() is called
    doTick();
    }
    }

    function doTick(){
    if(Player.getDimension()==DimensionId.NORMAL){ //only generate in the normal dimension, not in the Nether
    curX=Math.floor(Player.getX());
    curZ=Math.floor(Player.getZ());
    for(var i=0; i<16; i++){
    if(curX<0){
    changeBack=true;
    curX=curX*(-1);
    }
    if(curX%16!=0){
    curX--;
    }
    if(changeBack){
    curX=curX*(-1);
    }
    changeBack=false;
    if(curZ<0){
    changeBack=true;
    curZ=curZ*(-1);
    }
    if(curZ%16!=0){
    curZ--;
    }
    if(changeBack){
    curZ=curZ*(-1);
    }
    changeBack=false;
    }
    curX++;
    curZ++;
    spawnOres();
    curX=curX+16;
    spawnOres();
    curZ=curZ+16;
    spawnOres();
    curX=curX-16;
    spawnOres();
    curX=curX-16;
    spawnOres();
    curZ=curZ-16;
    spawnOres();
    curZ=curZ-16;
    spawnOres();
    curX=curX+16;
    spawnOres();
    curX=curX+16;
    spawnOres();
    curX=curX+16;
    spawnOres();
    curZ=curZ+16;
    spawnOres();
    curZ=curZ+16;
    spawnOres();
    curZ=curZ+16;
    spawnOres();
    curX=curX-16;
    spawnOres();
    curX=curX-16;
    spawnOres();
    curX=curX-16;
    spawnOres();
    curX=curX-16;
    spawnOres();
    curZ=curZ-16;
    spawnOres();
    curZ=curZ-16;
    spawnOres();
    curZ=curZ-16;
    spawnOres();
    curZ=curZ-16;
    spawnOres();
    curX=curX+16;
    spawnOres();
    curX=curX+16;
    spawnOres();
    curX=curX+16;
    spawnOres();
    curX=curX+16;
    spawnOres();
    curX=curX+16;
    spawnOres();
    curZ=curZ+16;
    spawnOres();
    curZ=curZ+16;
    spawnOres();
    curZ=curZ+16;
    spawnOres();
    curZ=curZ+16;
    spawnOres();
    curZ=curZ+16;
    spawnOres();
    curX=curX-16;
    spawnOres();
    curX=curX-16;
    spawnOres();
    curX=curX-16;
    spawnOres();
    curX=curX-16;
    spawnOres();
    curX=curX-16;
    spawnOres();
    curX=curX-16;
    spawnOres();
    curZ=curZ-16;
    spawnOres();
    curZ=curZ-16;
    spawnOres();
    curZ=curZ-16;
    spawnOres();
    curZ=curZ-16;
    spawnOres();
    curZ=curZ-16;
    spawnOres();
    curZ=curZ-16;
    spawnOres();
    curX=curX+16;
    spawnOres();
    curX=curX+16;
    spawnOres();
    curX=curX+16;
    spawnOres();
    curX=curX+16;
    spawnOres();
    curX=curX+16;
    spawnOres();
    curX=curX+16;
    spawnOres();
    }
    }

    function setTile2(p1, p2, p3, p4, p5){ //This function gives more possibilities to place ore, in this case it only places ore when it destroys Stone for that
    if(Level.getTile(p1, p2, p3)==1){ //if there, where the ore should be placed, is stone...
    Level.setTile(p1, p2, p3, p4, p5);
    }
    }

    function spawnOres(){ //this function spawns your block in one chunk
    if(Level.getTile(curX, 1, curZ)!=57){
    Level.setTile(curX, 1, curZ, 57, 0);
    Level.setTile(curX, 0, curZ, 7, 0);
    Level.setTile(curX, 2, curZ, 7, 0);
    Level.setTile(curX+1, 1, curZ, 7, 0);
    Level.setTile(curX-1, 1, curZ, 7, 0);
    Level.setTile(curX, 1, curZ+1, 7, 0);
    Level.setTile(curX, 1, curZ-1, 7, 0);
    //start generating
    //start to generate copper - copy-paste this part (from start to generate copper until end of generating copper (line229)) for more ores or generating one ore twice
    if(Math.floor(Math.random()*20)>7){ //probability that the following lines will generate ore
    cX=curX;
    cZ=curZ;
    cX=cX+Math.floor(Math.random()*10)+2; //random X
    cZ=cZ+Math.floor(Math.random()*10)+2; //random Z
    cY=255; //highest posible height
    while(Level.getTile(cX, cY, cZ)==0){ //lower the y-coordinate until a block is at cX, cY, cZ
    cY--;
    }
    cY++; //these line is necessary to spawn a block above the first non-air-block
    if(Level.getTile(cX, cY, cZ)!=8 && Level.getTile(cX, cY, cZ)!=9 && Level.getTile(cX, cY, cZ)!=10 && Level.getTile(cX, cY, cZ)!=11){//don`t spawn above water or lava
    setTile2(cX, cY, cZ, 220, 0); //220 is the Id of the block
    }
    }
    //end of generating a block
    //end of generating ores
    }
    //
    }





    I didn`t tested this, put it should give you at least an idea.

    Posted in: MCPE: Mods / Tools
  • 0

    posted a message on How to install Mods for MCPE!
    Quote from TreeTopCreeper»

    Hey can you tell me how to use b1 free archiver to install .jar mods on block launcher please no one has this, and I just wanna play tinkers construct. Thanks.


    I don't know how to install those mods. I don't think .jar mods are possible for MCPE because MCPE is written in C++ and not in Java. (BlockLauncher kind of converts JavaScript to C++.)
    Posted in: MCPE: Mod / Tool Help & Requests
  • 0

    posted a message on How to generate ores random with ModPE, (nearly) lagless and automatical
    Quote from Saccy701»


    I see, would it be ok if I copy the code and modify for use in my mod? Credit will be provided.


    Yes.
    Posted in: MCPE: Mods / Tools
  • 0

    posted a message on How to generate ores random with ModPE, (nearly) lagless and automatical
    Quote from Saccy701»

    [..] Also do you have a way to save what chunks have generated ores already? You'll need to use Java I/O for that.


    When ore is generated this code places a diamond-block (protected with bedrock) to prevent generating ore twice.
    Posted in: MCPE: Mods / Tools
  • 0

    posted a message on [ModPE] deleteFile(path, filename) function to delete files

    Example:





    function deleteFile(path, filename) {

    try {

    java.io.File(path).mkdirs();

    var theFile = new java.io.File(path, filename);

    theFile.delete();

    }catch(err){

    print("An Error occurred: " + err);

    }

    }


    function procCmd(cmd){

    if(cmd=="test"){

    deleteFile("storage/emulated/0/house/","house.js");

    }

    }



    Posted in: MCPE: Mods / Tools
  • 0

    posted a message on BlockLauncher: an Android app that patches Minecraft PE without reinstall

    Is there a place where I can get a list of code terms? (Block.defineBloc, etc...).

    Oh, and is there a way to add custom textures without dropbox? You used to b able to use a texture pack, but that isn't possible anymore.


    You can find a list of code terms in the BlockLauncher-App: settings-->Troubleshooting-->dump ModPE Script functions
    You can find most of the code terms here (with explanations): https://github.com/Connor4898/ModPE-Docs/wiki
    About adding textures: https://github.com/zhuowei/MCPELauncher/wiki/Including-textures-in-ModPE-scripts
    Posted in: MCPE: Mods / Tools
  • 0

    posted a message on VoxelMap [1.15.1 to 1.7.10] - a minimap and worldmap

    Great Mod!

    I appreciate that it uses liteloader and works for 1.9.4.

    The only option I miss is to show the Minimap only in Creative|Survival|Singleplayer|Multiplayer|Creative and Multiplayer...

    Posted in: Minecraft Mods
  • 0

    posted a message on help! How Blocks Will Face to you if you place a block in front of you!?

    You can use this from my easyBuilding-Mod(Forum-Link: http://www.minecraftforum.net/forums/minecraft-pocket-edition/mcpe-mods-tools/2409511-modpe-easybuilding-mod (line 2424) ):

    (This does maybe more than you want. It gives the correct damage for stairs, too.)


    function useItem(x2, y2, z2, itemId, blockId, side, itemDm, blockDm){
    switch(itemId){
    case 43:
    case 44:
    case 126:
    case 158:
    var vec=Player.getPointedVecY()-Math.floor(Player.getPointedVecY());
    if(vec>0.5){
    itemDm=itemDm+8;
    }
    break;
    case 53:
    case 67:
    case 108:
    case 109:
    case 114:
    case 128:
    case 134:
    case 135:
    case 136:
    case 156:
    case 163:
    case 164:
    case 180:
    case 203:
    var vecX=Player.getPointedVecX()-Math.floor(Player.getPointedVecX());
    var vecY=Player.getPointedVecY()-Math.floor(Player.getPointedVecY());
    var vecZ=Player.getPointedVecZ()-Math.floor(Player.getPointedVecZ());
    if(side==2 || side==3){
    if(vecX<0.33){
    itemDm=1;
    }else{
    if(vecX<0.67){
    itemDm=side;
    }else{
    itemDm=0;
    }
    }
    }
    if(side==4 || side==5){
    if(vecZ<0.33){
    itemDm=3;
    }else{
    if(vecZ<0.67){
    if(side==4){
    itemDm=0;
    }else{
    itemDm=1;
    }
    }else{
    itemDm=2;
    }
    }
    }
    if(vecY>0.5){
    itemDm=itemDm+4;
    }
    break;
    case 170:
    if(side==2 || side==3){
    itemDm=8;
    }
    if(side==4 || side==5){
    itemDm=4;
    }
    break;
    case 61:
    itemDm=2;
    if(side>1){
    itemDm=side;
    }
    break;
    case 86:
    case 91:
    switch(side){
    case 2:
    itemDm=2;
    break;
    case 3:
    itemDm=0;
    break;
    case 4:
    itemDm=1;
    break;
    case 5:
    itemDm=3;
    break;
    }
    break;
    case 17:
    case 162:
    if(side==2 || side==3){
    itemDm=itemDm+8;
    }
    if(side==4 || side==5){
    itemDm=itemDm+4;
    }
    break;
    case 155:
    if(itemDm==1 || itemDm==2){
    if(side==2 || side==3){
    itemDm=itemDm+8;
    }
    if(side==4 || side==5){
    itemDm=itemDm+4;
    }
    }
    break;
    }
    //now itemDm is the correct damage for the block you want to place
    }
    Posted in: MCPE: Mod / Tool Help & Requests
  • 0

    posted a message on Spider eye help

    You have to make the spider eyes image transparent, if you delete it minecraft uses the default texture.

    Posted in: Resource Pack Help
  • 0

    posted a message on [MCPE Mod] 0.14x Need help with a simple js (procCmd)

    /*FireWalk*/

    var isEnabled=false;


    function procCmd(cmd){

    cmd = cmd.toLowerCase();

    if(cmd == "on"){

    clientMessage("PowerEnabled!");

    isEnabled=true;

    }

    if(cmd == "off"){

    clientMessage("PowerDisabled!");

    isEnabled=false;

    }

    }


    function modTick(){

    if(isEnabled==true){

    Level.setTile(getPlayerX(), getPlgyerY() -1, getPlayerZ(), 51, 0);

    }

    }

    Posted in: MCPE: Mod / Tool Help & Requests
  • To post a comment, please or register a new account.