[HELP] Need help with an Base-Creator

Discussion in 'Programming' started by sunyx, Aug 15, 2018.

  1. Hey, Guys! :D
    I wanna code something like this: (at 2:40)

    EXPLANATION
    You place a head on a block and at this point it will start building a base (like in the video: The second player is placing a block and there is beeing built a base around him. I want exactly the same base.

    But i really dont know how :( It tried like 20 different methods but i wont work! I really need your help guys.

    Greetings
     
    #1 sunyx, Aug 15, 2018
    Last edited: Aug 15, 2018
  2. Well, we won't do the dirty work for you just because you need it fast. Show us what you tried and try to explain it.
     
  3. DavidDevelops

    Supporter

    Oof thats pretty advanced 1 block at a time, don't think W/Es API can help much there, none the less try saving the blocks to a multidimensional array and loading them from there? Or store it in a hashmap with Location (With offset) + Block type?
    Example: ~ = from where the player is standing
    Item 1 = ~ ~(-1) ~, Material.DIRT
    Item 2 = ~(-1) ~ ~, Material.STONE
    And so on, although storing it could be trouble so id wait to see if someone else has a better way, check the W/E API its normally helpful
     
  4. Code (Java):
    package net.raynight.basecreator;

    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.HashMap;
    import java.util.List;

    import org.bukkit.Effect;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.scheduler.BukkitRunnable;

    import net.raynight.Critical;
    import net.raynight.database.Data;
    import net.raynight.utils.ItemSkulls;

    public class BaseCreator {

        public static HashMap<ItemStack, BaseCreator> hashMap = new HashMap<>();
        public static ItemStack bedrockHead = ItemSkulls.getSkull(
                "http://textures.minecraft.net/texture/6753482c1d5061e9b243f259b52f95c433ff03039ac843ddc46267b903052");

        private int length;
        private int height;
        private int width;
        private Material material;

        public BaseCreator(int size, Material material) {

            size += 1;
            this.height = size;
            this.width = size + 1;
            this.length = size + 1;
            this.material = material;

        }

        public int getHeight() {
            return height;
        }

        public int getLength() {
            return length;
        }

        public int getWidth() {
            return width;
        }

        public void build(Location createLocation) {

            createLocation.subtract(this.length / 2, 0, this.width / 2);
            List<Block> blocks = new ArrayList<>();

            for (int x = 0; x < length; x++) {

                for (int z = 0; z < width; z++) {

                    for (int y = 0; y <= height; y++) {

                        Location loc = new Location(createLocation.getWorld(), createLocation.getX() + x,
                                createLocation.getY() + y, createLocation.getZ() + z);

                        if (y != height && y != 0) {

                            if ((x >= 0 && z == 0) || (x >= 0 && z == width - 1) || (x == 0 && z >= 0)
                                    || (x == length - 1 && z >= 0))

                                blocks.add(loc.getBlock());

                        } else {

                            blocks.add(loc.getBlock());

                        }

                    }

                }

            }

            new BukkitRunnable() {

                int index = 0;

                @Override
                public void run() {

                    if (index < blocks.size()) {

                        blocks.get(index).getWorld().playEffect(blocks.get(index).getLocation().clone().add(0.5, 0, 0.5),
                                Effect.STEP_SOUND, 1);

                        blocks.get(index).setType(Material.BEDROCK);
                        index++;

                    } else {

                        cancel();

                    }

                }
            }.runTaskTimer(Critical.inst, 2, 1);

        }

        public boolean isPlaceableFor(Location location) {

            int blocks = 0;

            location.subtract(this.length / 2, 0, this.width / 2);

            for (int x = 0; x < length; x++) {

                for (int z = 0; z < width; z++) {

                    for (int y = 0; y <= height; y++) {

                        Location loc = new Location(location.getWorld(), location.getX() + x, location.getY() + y,
                                location.getZ() + z);

                        if (y != height && y != 0) {

                            if ((x >= 0 && z == 0) || (x >= 0 && z == width - 1) || (x == 0 && z >= 0)
                                    || (x == length - 1 && z >= 0))

                                if (loc.getBlock().getType() == Material.BEDROCK) {

                                    blocks++;
                                }

                        } else {

                            if (loc.getBlock().getType() == Material.BEDROCK) {

                                blocks++;

                            }

                        }

                    }

                }

            }

            return blocks == 0;

        }

        public void autoRegister(String displayName) {

            hashMap.put(getAsCreatorItem(displayName), this);

        }

        public ItemStack getAsCreatorItem(String displayName) {

            ItemStack res = bedrockHead.clone();
            ItemMeta resMeta = res.getItemMeta();
            resMeta.setDisplayName(displayName);
            resMeta.setLore(Arrays.asList("", Data.sc + "Dieser Instant-Bunker baut dir eine",
                    Data.mc + "" + (this.height - 1) + "§6 *§6" + (this.length - 2) + "§6 *§6" + (this.width - 2)
                            + " §7Blöcke grosse Basis aus Bedrock!",
                    "", Data.sc + "§oKlicke auf den Boden um die Base zu erstellen!"));
            res.setItemMeta(resMeta);
            return res;

        }

    }
     
    idk how to place chest in there and idk how to make it starting on the placed block
     
    #4 sunyx, Aug 15, 2018
    Last edited: Aug 15, 2018
  5. DavidDevelops

    Supporter

    Your telling me you write that code yet cant find out how to do those? Smh, learn it and stop copying
     
  6. Sorry that i dont want to waste more 20 hours
     
  7. You haven't much choice here, or you pay someone to do it or you learn to do it yourself. It would be difficult to find someone that would do all the work, especially with the "Please, spoonfeed me" attitude.
     
  8. Got it myself.
     
    • Optimistic Optimistic x 1