Esempio n. 1
0
 public static string[] Do(string[,] items)
 {
     foreach (KeyValuePair <string[, ], string[]> pair in recipes)
     {
         if (pair.Key.Length == items.Length)
         {
             bool ok = true;
             for (int v = 0; v < 3; v++)
             {
                 for (int v1 = 0; v1 < 3; v1++)
                 {
                     bool ok2 = false;
                     //Debug.Log(pair.Key.Length+" "+v+" "+v1+" "+pair.Key[v,v1]);
                     for (int v2 = 0; v2 < groups[pair.Key[v, v1]].Count; v2++)
                     {
                         if (EntityId.ByName(groups[pair.Key[v, v1]][v2]).name == EntityId.ByName(items[v, v1]).name)
                         {
                             ok2 = true;
                         }
                     }
                     if (!ok2)
                     {
                         ok = false;
                     }
                 }
             }
             if (ok)
             {
                 return(pair.Value);
             }
         }
     }
     return(new string[] { "air" });
 }
Esempio n. 2
0
    void CraftingFU()
    {
        string[,] cells = new string[3, 3];
        string curCraftInput = "";

        for (int v = 0; v < 3; v++)
        {
            for (int v1 = 0; v1 < 3; v1++)
            {
                curCraftInput += (cells[v, v1] = craftInput[v, v1].text);
            }
        }
        if (curCraftInput != lastCraftInput)
        {
            for (int v = 0; v < 3; v++)
            {
                for (int v1 = 0; v1 < 3; v1++)
                {
                    images[v, v1].material.SetTextureOffset("_MainTex", EntityId.ByName(craftInput[v, v1].text).textures[0] * images[v, v1].material.GetTextureScale("_MainTex"));
                }
            }
            craftResult.text = string.Join(Craft.spl0 + "", Craft.Do(cells));
            craftImage.material.SetTextureOffset("_MainTex", EntityId.ByName(craftResult.text.Split(Craft.spl0)[0]).textures[0] * craftImage.material.GetTextureScale("_MainTex"));
        }
        lastCraftInput = curCraftInput;
    }
Esempio n. 3
0
 public void addItem(string name)
 {
     for (int i = 0; i < items.Length; i++)
     {
         if (EntityId.ByName(items[i]).name == "air")
         {
             items[i] = name;
             break;
         }
     }
 }
Esempio n. 4
0
    public void InventoryFU()
    {
        for (int v = 0; v < inventory.items.Length; v++)
        {
            slots[v].material.SetTextureOffset("_MainTex", EntityId.ByName(inventory.items[v]).textures[0] * slots[v].material.GetTextureScale("_MainTex"));
            slots[v].rectTransform.localPosition = new Vector3(0, 0, 0);
            slots[v].rectTransform.sizeDelta     = slotSize * (EntityId.ByName(inventory.items[v]).type == "block" ? blockMultiplier : otherMultiplier);
        }

        inventorySelector.rectTransform.localPosition = new Vector3((inventory.selected - inventory.items.Length / 2) * slotSize.x, 0, 0);
    }
Esempio n. 5
0
    public void InteractFU(float breakControl, float placeControl, float cloneControl, Ray ray)
    {
        if (gamemode == "creative" || true)
        {
            creativeCounter++;
            if (creativeCounter > creativeTimeout / Time.fixedDeltaTime)
            {
                creativeCounter = 0;
                haveInteract    = true;
            }
        }
        RaycastHit hit;

        Physics.Raycast(ray.origin, ray.direction, out hit, editRange);
        breakSelector = hit.point + ray.direction * 0.1f;
        placeSelector = hit.point - ray.direction * 0.1f;
        breakSelector = new Vector3((int)breakSelector.x, (int)breakSelector.y, (int)breakSelector.z);
        placeSelector = new Vector3((int)placeSelector.x, (int)placeSelector.y, (int)placeSelector.z);
        if (haveInteract)
        {
            if (breakControl > 0)
            {
                if (perms.canBreak && world.set(new EntityLocation((int)breakSelector.x, (int)breakSelector.y, (int)breakSelector.z)).interact(this, "mine"))
                {
                    haveInteract = false;
                }
            }

            if (placeControl > 0)
            {
                if (perms.canInteract && world.set(new EntityLocation((int)breakSelector.x, (int)breakSelector.y, (int)breakSelector.z)).interact(this, "interfact"))
                {
                    haveInteract = false;
                }
                else if (perms.canPlace && EntityId.ByName(hotbar.items[hotbar.selected]).name != "air")
                {
                    world.set(new EntityLocation((int)placeSelector.x, (int)placeSelector.y, (int)placeSelector.z), new Entity().recreate(EntityId.ByName(hotbar.items[hotbar.selected])));
                    haveInteract = false;
                }
            }

            if (cloneControl > 0)
            {
                if (perms.canClone)
                {
                    hotbar.items[hotbar.selected] = world.set(new EntityLocation((int)breakSelector.x, (int)breakSelector.y, (int)breakSelector.z)).id.name;
                    haveInteract = false;
                }
            }
        }
    }
Esempio n. 6
0
 public void init()
 {
     blocks = new Entity[xBlocks, yBlocks, zBlocks];
     for (int x = 0; x < xBlocks; x++)
     {
         for (int y = 0; y < yBlocks; y++)
         {
             for (int z = 0; z < zBlocks; z++)
             {
                 blocks[x, y, z] = new Entity().recreate(EntityId.ByName("air"));
             }
         }
     }
 }
Esempio n. 7
0
    public bool interact(Mob mob, string type)
    {
        EntityId tool = EntityId.ByName(mob.hotbar.items[mob.hotbar.selected]);

        if (typeof(I3dContainer).IsInstanceOfType(container))
        {
            I3dContainer container = (I3dContainer)this.container;
            switch (type)
            {
            case "mine":
                hits -= mob.minemode == "momental" ? hits : Time.fixedDeltaTime * mob.breakSpeed;
                if (hits <= 0)
                {
                    if (!mob.perms.canIntoNothing)
                    {
                        if (mob.touchmode == "silk")
                        {
                            mob.hotbar.addItem(id.name);
                        }
                        if (mob.touchmode == "mine")
                        {
                            mob.hotbar.addItem(id.drop);
                        }
                    }
                    this.recreate(EntityId.ByName("air"));
                    return(true);
                }
                break;

            default:
                Debug.Log("interact");
                switch (id.name)
                {
                case "tnt":
                    if (tool.name == "fire")
                    {
                        return(ignite());
                    }
                    break;
                }
                break;
            }
        }
        else
        {
            Debug.Log("re");
        }
        return(false);
    }
Esempio n. 8
0
 public bool ignite()
 {
     if (typeof(I3dContainer).IsInstanceOfType(container))
     {
         I3dContainer container = (I3dContainer)this.container;
         string       idName    = id.name;
         container.set(location, new Entity().recreate(EntityId.ByName("air")));
         switch (idName)
         {
         case "tnt":
             container.fill(new Vector3(location.x, location.y, location.z), 3, new Entity().recreate(EntityId.ByName("air")), "sphere", "ignite;set");
             return(true);
         }
     }
     return(false);
 }
Esempio n. 9
0
    void Start()
    {
        cam.farClipPlane = mob.world.xChunks * mob.world.xBlocks - 4;


        craftInput = new InputField[3, 3];
        images     = new Image[3, 3];
        for (int v = 0; v < 3; v++)
        {
            InputField[] f = v == 0 ? craftInput0 : (v == 1 ? craftInput1 : craftInput2);
            for (int v1 = 0; v1 < 3; v1++)
            {
                craftInput[v, v1] = f[v1];
                images[v, v1]     = new GameObject().AddComponent <Image>();
                images[v, v1].rectTransform.SetParent(f[v1].gameObject.transform);
                images[v, v1].material = new Material(mob.world.blocksSprite);
                images[v, v1].rectTransform.sizeDelta     = new Vector2(30, 30);
                images[v, v1].rectTransform.localPosition = new Vector3(120 / 2 - slotSize.x / 2, 0, 0);
                images[v, v1].material.SetTextureOffset("_MainTex", EntityId.ByName("air").textures[0] * images[v, v1].material.GetTextureScale("_MainTex"));
            }
        }
        craftImage.material = new Material(mob.world.blocksSprite);
        craftImage.material.SetTextureOffset("_MainTex", EntityId.ByName("air").textures[0] * craftImage.material.GetTextureScale("_MainTex"));
    }
Esempio n. 10
0
 public Entity recreate(string idName) => this.recreate(EntityId.ByName(idName));
Esempio n. 11
0
 // Start is called before the first frame update
 void Start()
 {
     entity = new Entity().recreate(EntityId.ByName(idName));
 }
Esempio n. 12
0
    public void perform(World world)
    {
        string last = "air";

        for (float xl = 0; xl < world.xChunks * world.xBlocks; xl++)
        {
            for (float yl = 0; yl < world.yChunks * world.yBlocks; yl++)
            {
                for (float zl = 0; zl < world.zChunks * world.zBlocks; zl++)
                {
                    float perlinX = xl / (world.xChunks * world.xBlocks) / perlinCoefX - perlinPlusX, perlinZ = zl / (world.zChunks * world.zBlocks) / perlinCoefZ - perlinPlusZ;
                    float perlinY = Mathf.PerlinNoise(perlinX, perlinZ) * perlinCoefY + perlinPlusY;
                    //Debug.Log(perlinX+" "+perlinZ+" "+perlinY);
                    float x = xl, y = yl / coef * (perlinNoise && !perlinPlus ? perlinY : 1) + (perlinNoise && perlinPlus ? perlinY : 0), z = zl;
                    foreach (GenerationElement gElem in levels)
                    {
                        float xc = gElem.rawX ? xl : x, yc = gElem.rawY ? yl : y, zc = gElem.rawZ ? zl : z;
                        if (Limiter.check(gElem.xMin, xc) && Limiter.check(gElem.xMax, xc) && Limiter.check(gElem.yMin, yc) && Limiter.check(gElem.yMax, yc) && Limiter.check(gElem.zMin, zc) && Limiter.check(gElem.zMax, zc))
                        {
                            last = gElem.idName;
                            if (gElem.endFor)
                            {
                                break;
                            }
                        }
                    }
                    world.set(new EntityLocation((int)xl, (int)yl, (int)zl, 0, 0, 0, Random.Range(0, 2) > 0, Random.Range(0, 2) > 0, Random.Range(0, 2) > 0), new Entity().recreate(EntityId.ByName(last)));
                }
            }
        }
    }
Esempio n. 13
0
    void CommandFU()
    {
        bool cmd = false;

        if (text.text.Split(' ').Length > 1)
        {
            if (text.text.Split(' ')[0] == "/load")
            {
                cmd = true;
                mob.world.load("Assets/WorldSaves", text.text.Split(' ')[1]);
            }
        }
        if (text.text.Split(' ').Length > 1)
        {
            if (text.text.Split(' ')[0] == "/save")
            {
                cmd = true;
                mob.world.save("Assets/WorldSaves", text.text.Split(' ')[1]);
            }
        }
        if (text.text.Split(' ').Length > 4)
        {
            if (text.text.Split(' ')[0] == "/setblock")
            {
                cmd = true;
                mob.world.fill(new Vector3(int.Parse(text.text.Split(' ')[1]), int.Parse(text.text.Split(' ')[2]), int.Parse(text.text.Split(' ')[3])), new Entity().recreate(EntityId.ByName(text.text.Split(' ')[4])));
            }
        }
        if (text.text.Split(' ').Length > 7)
        {
            if (text.text.Split(' ')[0] == "/fill")
            {
                cmd = true;
                mob.world.fill(new Vector3(int.Parse(text.text.Split(' ')[1]), int.Parse(text.text.Split(' ')[2]), int.Parse(text.text.Split(' ')[3])), new Vector3(int.Parse(text.text.Split(' ')[5]), int.Parse(text.text.Split(' ')[6]), int.Parse(text.text.Split(' ')[7])), new Entity().recreate(EntityId.ByName(text.text.Split(' ')[4])));
            }
        }
        if (text.text.Split(' ').Length > 7)
        {
            if (text.text.Split(' ')[0] == "/fillarea")
            {
                cmd = true;
                mob.world.fillArea(new Vector3(int.Parse(text.text.Split(' ')[1]), int.Parse(text.text.Split(' ')[2]), int.Parse(text.text.Split(' ')[3])), new Vector3(int.Parse(text.text.Split(' ')[5]), int.Parse(text.text.Split(' ')[6]), int.Parse(text.text.Split(' ')[7])), new Entity().recreate(EntityId.ByName(text.text.Split(' ')[4])));
            }
        }
        if (cmd)
        {
            text.text = "$" + text.text;
            prevCmds.Add(text.text.Substring(1));
        }
    }