Jump to content

Custom Mod Breaks Mobs in 1.15.2


JJ Revans

Recommended Posts

So I am making a mod that adds an entity that beats the game for you. When I spawn it in, all mobs in the game freeze and liquids stop working. Not only that, but chunk generation slows down considerably and the world becomes un-savable. The script for the entity's actions is in it's basic Entity script, so the script is very very lengthy. Here it is: (btw, it is incomplete)

package com.jaegalaxy.illi.entities;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.*;
import net.minecraft.entity.ai.goal.SwimGoal;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.DamageSource;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;

public class BotEntity extends MobEntity
{
    public List<ItemStack> itemStackList = Arrays.asList();

    private final float SPEED = 0.23f;

    private BlockPos CraftingTablePos;

    private boolean SPAWNEDYET = false;

    private boolean foundTree = false; // whether or not we have found a tree
    private BlockPos nearestTree; // where the nearest tree is
    private int tryfindtreerepeats = 5; // how many times we want to find and break a tree

    private Block mineForBlock;
    private boolean startMining = false;
    private boolean movingtomine = false;
    private BlockPos mineStart;
    private BlockPos movingToMinePos;
    private boolean afterMiningMove = false;

    private boolean smeltingIron = false;
    private int ticksSinceStartedSmeltingIron = 0;

    private boolean goingToWater = false;
    private BlockPos WaterPos;
    private boolean goingToLava = false;
    private BlockPos LavaPos;

    private boolean waitingForNPortal = false;
    private boolean goingToPortalAfterBuilt = false;
    private BlockPos OGPortalPos;
    private boolean WTSAGIP = false;
    private int WTSAGIP_ticks = 0;

    boolean findingBlazes = false;
    BlockPos blazeLocation;

    boolean tryingToKill = false;


    public BotEntity(EntityType<? extends BotEntity> type, World worldIn)
    {
        super(type, worldIn);
    }

    @Override
    protected void registerAttributes() {
        super.registerAttributes();
        this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20);
        this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.23F);
    }

    @Override
    protected void registerGoals() {
        this.goalSelector.addGoal(0, new SwimGoal(this));
    }

    @Nullable
    @Override
    public ILivingEntityData onInitialSpawn(IWorld worldIn, DifficultyInstance difficultyIn, SpawnReason reason, @Nullable ILivingEntityData spawnDataIn, @Nullable CompoundNBT dataTag)
    {
        BotStart();
        return super.onInitialSpawn(worldIn, difficultyIn, reason, spawnDataIn, dataTag);
    }

    void BotStart()
    {
        SPAWNEDYET = true;
        TryFindTree();
    }

    @Override
    public void onDeath(DamageSource cause) {
        super.onDeath(cause);

        if(!world.isRemote)
        {
            for (ItemStack stacky : itemStackList)
            {
                ItemEntity stackyEntity = new ItemEntity(world, getPosX(), getPosY(), getPosZ());
                world.addEntity(stackyEntity);
            }
        }
    }

    @Nullable
    @Override
    protected SoundEvent getHurtSound(DamageSource damageSourceIn) {
        return SoundEvents.ENTITY_PLAYER_HURT;
    }

    @Nullable
    @Override
    protected SoundEvent getDeathSound() {
        return SoundEvents.ENTITY_PLAYER_DEATH;
    }

    //public boolean canAttackClass(Class par1Class)
    //{
      //  return EntityCreeper.class != par1Class && EntityGhast.class != par1Class;
    //}

    void TryFindTree() // we want to find a tree.
    {
        foundTree = false; // we have not found a tree
        nearestTree = FindBlock(Blocks.OAK_LOG, 50); // we want to find the nearest tree
        if(!nearestTree.equals(new BlockPos(getPosX(), getPosY(), getPosZ()))) // if the FindBlock doesnt give us the random thing...
            getNavigator().tryMoveToXYZ(nearestTree.getX() - 1, nearestTree.getY(), nearestTree.getZ() - 1, SPEED); // get to the tree
        else{ // otherwise...
            foundTree = true; // P.S. this is totally a lie just FYI
            TryFindTree(); // find a new tree
        }
    }

    void TryBreakTree() // we want to break a tree.
    {
        world.setBlockState(nearestTree, Blocks.AIR.getDefaultState()); // mine the wood
        itemStackList.add(new ItemStack(Items.OAK_LOG)); // mmm get that nice tasty wood
    }

    void TryCraftOakPlanks() // 4 oak planks = 1 oak log. do this for every log!
    {
        for(ItemStack stacky : itemStackList){ // repeat for each item in the bot's inventory
            if(stacky.equals(new ItemStack(Items.OAK_LOG))){ // if the bot has oak log
                itemStackList.remove(stacky); // take away the oak logs
                itemStackList.add(new ItemStack(Items.OAK_PLANKS)); // give the bot wooden planks
                itemStackList.add(new ItemStack(Items.OAK_PLANKS)); // give the bot wooden planks
                itemStackList.add(new ItemStack(Items.OAK_PLANKS)); // give the bot wooden planks
                itemStackList.add(new ItemStack(Items.OAK_PLANKS)); // give the bot wooden planks
                // these planks will be used for sticks and such
            }
        }

        TryCraftCraftingTable(); // craft a crafting table
    }

    void TryCraftCraftingTable() // crafting table = 4 oak planks.
    {
        int loops = 4; // do this once
        for(ItemStack stacky : itemStackList){ // repeat for each item in the bot's inventory
            if(stacky.equals(new ItemStack(Items.OAK_PLANKS))){ // if the bot has oak planks
                if(loops > 0) { // if we have not looped enough
                    itemStackList.remove(stacky); // take away the oak plank
                    loops--; // we have looped
                }
            }
        }
        itemStackList.add(new ItemStack(Items.CRAFTING_TABLE)); // give the bot a crafting table

        TryPlaceCraftingTable(); // place a crafting table
    }

    void TryPlaceCraftingTable() // place crafting table. do this until a crafting table is crafted
    {
        BlockPos craftpos = new BlockPos(getPosX(), getPosY(), getPosZ() +1 );
        int loops = 1; // do this once
        world.setBlockState(craftpos, Blocks.CRAFTING_TABLE.getDefaultState());
        for(ItemStack stacky : itemStackList){ // repeat for each item in the bot's inventory
            if(stacky.equals(new ItemStack(Items.CRAFTING_TABLE))){ // if the bot has crafting table
                if(loops > 0) { // if we have not looped enough
                    itemStackList.remove(stacky); // take away the crafting table
                    loops--; // we have looped
                }
            }
        }
        world.setBlockState(craftpos, Blocks.CRAFTING_TABLE.getDefaultState()); // place the crafting table
        CraftingTablePos = craftpos;
        TryCraftSomeSticks(); // craft those sticks!
    }

    void TryCraftSomeSticks() // 8 sticks = 4 oak planks
    {
        int loops = 2; // do this twice
        for(ItemStack stacky : itemStackList) { // repeat for each item in the bot's inventory
            if (stacky.equals(new ItemStack(Items.OAK_PLANKS))) { // if the bot has oak planks
                if (loops > 0) { // if we have not looped enough
                    itemStackList.remove(stacky); // take away an oak plank
                    itemStackList.remove(stacky); // take away an oak plank
                    itemStackList.add(new ItemStack(Items.CRAFTING_TABLE)); // give the bot a crafting table
                    itemStackList.add(new ItemStack(Items.CRAFTING_TABLE)); // give the bot a crafting table
                    itemStackList.add(new ItemStack(Items.CRAFTING_TABLE)); // give the bot a crafting table
                    itemStackList.add(new ItemStack(Items.CRAFTING_TABLE)); // give the bot a crafting table
                    loops--;
                }
            }
        }

        TryCraftPickaxe(); // craft a pickaxe...
    }

    void TryCraftPickaxe()
    {
        // TAKE AWAY OAK PLANKS!
        int loops = 3; // do this 3 times
        for(ItemStack stacky : itemStackList) { // repeat for each item in the bot's inventory
            if (stacky.equals(new ItemStack(Items.OAK_PLANKS))) { // if the bot has oak planks
                if (loops > 0) { // if we have not looped enough
                    itemStackList.remove(stacky); // take away an oak plank
                    loops--; // we have looped
                }
            }
        }

        // TAKE AWAY STICKS!
        int loops2 = 2; // do this twice
        for(ItemStack stacky : itemStackList) { // repeat for each item in the bot's inventory
            if (stacky.equals(new ItemStack(Items.STICK))) { // if the bot has stick
                if (loops2 > 0) { // if we have not looped enough
                    itemStackList.remove(stacky); // take away stick
                    loops2--; // we have looped
                }
            }
        }

        itemStackList.add(new ItemStack(Items.WOODEN_PICKAXE)); // give the bot a pickaxe

        TryMineForCobble();
    }

    void TryMineForCobble()
    {
        StartMine(Blocks.COBBLESTONE);
    }

    void TryCraftStonePickaxe()
    {
        // repeat for each item in the bot's inventory
        // if the bot has cobblestone
        // take it away
        itemStackList.removeIf(stacky -> stacky.equals(new ItemStack(Items.COBBLESTONE)));
        int loops = 2;
        for(ItemStack stacky : itemStackList){ // repeat for each item in the bot's inventory
            if(stacky.equals(new ItemStack(Items.STICK))){ // if the bot has sticks
                if(loops > 0) {
                    itemStackList.remove(stacky); // take it away
                    loops--;
                }
            }
        }

        itemStackList.add(new ItemStack(Items.STONE_PICKAXE)); // give the bot a pickaxe

        TryMineMoreForIron();
    }

    void TryMineMoreForIron()
    {
        StartMine(Blocks.IRON_ORE);
    }

    void SmeltIron()
    {
        // craft a furnace using cobblestone collected
        SI_CraftFurnace();
    }

    void SI_CraftFurnace()
    {
        itemStackList.removeIf(stacky -> stacky.equals(new ItemStack(Items.COBBLESTONE)));
        int loops = 8;
        for(ItemStack stacky : itemStackList){ // repeat for each item in the bot's inventory
            if(stacky.equals(new ItemStack(Items.COBBLESTONE))){ // if the bot has cobblestone
                if(loops > 0) {
                    itemStackList.remove(stacky); // take it away
                    loops--;
                }
            }
        }

        BlockPos furnacePos = new BlockPos(CraftingTablePos.getX() - 1, CraftingTablePos.getY(), CraftingTablePos.getZ());
        world.setBlockState(furnacePos, Blocks.FURNACE.getDefaultState());

        SI_StartSmeltIron();
    }

    void SI_StartSmeltIron()
    {
        smeltingIron = true;
    }

    void SI_HandleSmeltSystemAndCraftIronBucket()
    {
        // remove items used for smelting
        itemStackList.add(new ItemStack(Items.IRON_INGOT)); // give the bot an iron ingot
        itemStackList.add(new ItemStack(Items.IRON_INGOT)); // give the bot an iron ingot
        itemStackList.add(new ItemStack(Items.IRON_INGOT)); // give the bot an iron ingot

        int loops = 3;
        for(ItemStack stacky : itemStackList){ // repeat for each item in the bot's inventory
            if(stacky.equals(new ItemStack(Items.OAK_PLANKS))){ // if the bot has cobblestone
                if(loops > 0) {
                    itemStackList.remove(stacky); // take it away
                    loops--;
                }
            }
        }

        int loops2 = 3;
        for(ItemStack stacky : itemStackList){ // repeat for each item in the bot's inventory
            if(stacky.equals(new ItemStack(Items.IRON_INGOT))){ // if the bot has cobblestone
                if(loops2 > 0) {
                    itemStackList.remove(stacky); // take it away
                    loops2--;
                }
            }
        }

        itemStackList.add(new ItemStack(Items.BUCKET)); // give the bot an iron ingot

        AfterwardsCraftAStoneSwordPlease();
    }

    void AfterwardsCraftAStoneSwordPlease()
    {
        // use the crafting algorithm to make a stone sword
        // TAKE AWAY COBBLESTONE!
        int loops = 2; // do this twice
        for(ItemStack stacky : itemStackList) { // repeat for each item in the bot's inventory
            if (stacky.equals(new ItemStack(Items.COBBLESTONE))) { // if the bot has oak planks
                if (loops > 0) { // if we have not looped enough
                    itemStackList.remove(stacky); // take away an oak plank
                    loops--; // we have looped
                }
            }
        }

        // TAKE AWAY STICKS!
        int loops2 = 1; // do this once
        for(ItemStack stacky : itemStackList) { // repeat for each item in the bot's inventory
            if (stacky.equals(new ItemStack(Items.STICK))) { // if the bot has stick
                if (loops2 > 0) { // if we have not looped enough
                    itemStackList.remove(stacky); // take away stick
                    loops2--; // we have looped
                }
            }
        }

        itemStackList.add(new ItemStack(Items.STONE_SWORD)); // give the bot a sword
        FindWater();
    }

    void FindWater()
    {
        // set destination to water and wait
        BlockPos waterPos = FindBlock(Blocks.WATER, 100);
        getNavigator().tryMoveToXYZ(waterPos.getX(), waterPos.getY(), waterPos.getZ(), 0.23f);
        WaterPos = new BlockPos(waterPos.getX() - 1, waterPos.getY(), waterPos.getZ());
        goingToWater = true;
    }

    void FillBucketWithWater()
    {
        // get some water in the bucket!
        BlockPos actualwaterpos = new BlockPos(WaterPos.getX() + 1, WaterPos.getY(), WaterPos.getZ());
        world.setBlockState(actualwaterpos, Blocks.AIR.getDefaultState());

        int loops = 1;
        for(ItemStack stacky : itemStackList){ // repeat for each item in the bot's inventory
            if(stacky.equals(new ItemStack(Items.BUCKET))){ // if the bot has bucket
                if(loops > 0) {
                    itemStackList.remove(stacky); // take it away
                    itemStackList.add(new ItemStack(Items.WATER_BUCKET)); // give the bot a water bucket
                    loops--;
                }
            }
        }

        FindLava();
    }

    void FindLava()
    {
        // set destination to lava and wait
        BlockPos _lavaPos = FindBlock(Blocks.LAVA, 100);
        getNavigator().tryMoveToXYZ(_lavaPos.getX()-7, _lavaPos.getY(), _lavaPos.getZ()-7, 0.23f);
        LavaPos = new BlockPos(_lavaPos.getX()-7, _lavaPos.getY(), _lavaPos.getZ()-7);
        goingToLava = true;
    }

    void CreatePortal()
    {
        // follow the slightly complex algorithm to build a portal

        // make a hole (2x1x2)
        BlockPos pos1 = new BlockPos(LavaPos.getX(), LavaPos.getY(), LavaPos.getZ());
        BlockPos pos2 = new BlockPos(LavaPos.getX(), LavaPos.getY(), LavaPos.getZ()+1);
        BlockPos pos3 = new BlockPos(LavaPos.getX()+1, LavaPos.getY(), LavaPos.getZ());
        BlockPos pos4 = new BlockPos(LavaPos.getX()+1, LavaPos.getY(), LavaPos.getZ()+1);

        CP_MineBlock(pos1);
        CP_MineBlock(pos2);
        CP_MineBlock(pos3);
        CP_MineBlock(pos4);

        // make a wall (2x3x1)
        BlockPos PP1 = new BlockPos(LavaPos.getX()-1, LavaPos.getY()+1, LavaPos.getZ());
        BlockPos PP2 = new BlockPos(LavaPos.getX()-1, LavaPos.getY()+2, LavaPos.getZ());
        BlockPos PP3 = new BlockPos(LavaPos.getX()-1, LavaPos.getY()+3, LavaPos.getZ());
        BlockPos PP4 = new BlockPos(LavaPos.getX()-1, LavaPos.getY()+1, LavaPos.getZ()+1);
        BlockPos PP5 = new BlockPos(LavaPos.getX()-1, LavaPos.getY()+2, LavaPos.getZ()+1);
        BlockPos PP6 = new BlockPos(LavaPos.getX()-1, LavaPos.getY()+3, LavaPos.getZ()+1);

        CP_PlaceBLock(PP1, Blocks.COBBLESTONE);
        CP_PlaceBLock(PP2, Blocks.COBBLESTONE);
        CP_PlaceBLock(PP3, Blocks.COBBLESTONE);
        CP_PlaceBLock(PP4, Blocks.COBBLESTONE);
        CP_PlaceBLock(PP5, Blocks.COBBLESTONE);
        CP_PlaceBLock(PP6, Blocks.COBBLESTONE);

        // pour some water
        BlockPos WP = new BlockPos(LavaPos.getX()-1, LavaPos.getY()+4, LavaPos.getZ()+1);

        CP_EmptyWaterBucket(WP);

        // fill bucket with lava and empty it repeatedly!
        BlockPos EP1 = new BlockPos(LavaPos.getX(), LavaPos.getY()+1, LavaPos.getZ()-1);
        BlockPos EP2 = new BlockPos(LavaPos.getX(), LavaPos.getY()+2, LavaPos.getZ()-1);
        BlockPos EP3 = new BlockPos(LavaPos.getX(), LavaPos.getY()+3, LavaPos.getZ()-1);
        BlockPos EP4 = new BlockPos(LavaPos.getX(), LavaPos.getY()+4, LavaPos.getZ());
        BlockPos EP5 = new BlockPos(LavaPos.getX(), LavaPos.getY()+1, LavaPos.getZ()+2);
        BlockPos EP6 = new BlockPos(LavaPos.getX(), LavaPos.getY()+2, LavaPos.getZ()+2);
        BlockPos EP7 = new BlockPos(LavaPos.getX(), LavaPos.getY()+3, LavaPos.getZ()+2);
        BlockPos EP8 = new BlockPos(LavaPos.getX(), LavaPos.getY()+4, LavaPos.getZ()+1);
        BlockPos EP9 = new BlockPos(LavaPos.getX(), LavaPos.getY(), LavaPos.getZ());
        BlockPos EP10 = new BlockPos(LavaPos.getX(), LavaPos.getY(), LavaPos.getZ()+1);

        CP_FillLavaBucket(FindBlock(Blocks.LAVA, 25));
        CP_EmptyLavaBucket(EP1);
        CP_FillLavaBucket(FindBlock(Blocks.LAVA, 25));
        CP_EmptyLavaBucket(EP2);
        CP_FillLavaBucket(FindBlock(Blocks.LAVA, 25));
        CP_EmptyLavaBucket(EP3);
        CP_FillLavaBucket(FindBlock(Blocks.LAVA, 25));
        CP_EmptyLavaBucket(EP4);
        CP_FillLavaBucket(FindBlock(Blocks.LAVA, 25));
        CP_EmptyLavaBucket(EP5);
        CP_FillLavaBucket(FindBlock(Blocks.LAVA, 25));
        CP_EmptyLavaBucket(EP6);
        CP_FillLavaBucket(FindBlock(Blocks.LAVA, 25));
        CP_EmptyLavaBucket(EP7);
        CP_FillLavaBucket(FindBlock(Blocks.LAVA, 25));
        CP_EmptyLavaBucket(EP8);
        CP_FillLavaBucket(FindBlock(Blocks.LAVA, 25));
        CP_EmptyLavaBucket(EP9);
        CP_FillLavaBucket(FindBlock(Blocks.LAVA, 25));
        CP_EmptyLavaBucket(EP10);

        // use an algorithm to set the portal on fire - run IgnitePortal()
        IgnitePortal(EP10, EP9);
    }

    void CP_EmptyWaterBucket(BlockPos emptyPos)
    {
        // replace water bucket with regular bucket
        int loops = 1;
        for(ItemStack stacky : itemStackList){ // repeat for each item in the bot's inventory
            if(stacky.equals(new ItemStack(Items.WATER_BUCKET))){ // if the bot has water bucket
                if(loops > 0) {
                    itemStackList.remove(stacky); // take it away
                    itemStackList.add(new ItemStack(Items.BUCKET)); // give the bot a bucket
                    loops--;
                }
            }
        }

        // put down water at "emptyPos"
        world.setBlockState(emptyPos, Blocks.WATER.getDefaultState());
    }

    void CP_FillLavaBucket(BlockPos fillPos)
    {
        // replace bucket with lava bucket
        int loops = 1;
        for(ItemStack stacky : itemStackList){ // repeat for each item in the bot's inventory
            if(stacky.equals(new ItemStack(Items.BUCKET))){ // if the bot has bucket
                if(loops > 0) {
                    itemStackList.remove(stacky); // take it away
                    itemStackList.add(new ItemStack(Items.LAVA_BUCKET)); // give the bot a lava bucket
                    loops--;
                }
            }
        }

        // replace lava at "fillPos" with air
        world.setBlockState(fillPos, Blocks.AIR.getDefaultState());
    }

    void CP_EmptyLavaBucket(BlockPos emptyPos)
    {
        // replace lava bucket with regular bucket
        int loops = 1;
        for(ItemStack stacky : itemStackList){ // repeat for each item in the bot's inventory
            if(stacky.equals(new ItemStack(Items.LAVA_BUCKET))){ // if the bot has lava bucket
                if(loops > 0) {
                    itemStackList.remove(stacky); // take it away
                    itemStackList.add(new ItemStack(Items.BUCKET)); // give the bot a bucket
                    loops--;
                }
            }
        }

        // put down lava at "emptyPos"
        world.setBlockState(emptyPos, Blocks.LAVA.getDefaultState());
    }

    void CP_MineBlock(BlockPos blockPos)
    {
        // give the bot the block that will be removed
        itemStackList.add(new ItemStack(Item.getItemFromBlock(world.getBlockState(blockPos).getBlock()))); // give the bot a bucket

        // replace block at "blockPos" with air
        world.setBlockState(blockPos, Blocks.AIR.getDefaultState());
    }

    void CP_PlaceBLock(BlockPos placePos, Block blockToPlace)
    {
        // remove "blockToPlace" from the bot's inv.
        int loops = 1;
        for(ItemStack stacky : itemStackList) { // repeat for each item in the bot's inventory
            if (stacky.equals(new ItemStack(Item.getItemFromBlock(blockToPlace)))) { // if the bot has lava bucket
                if (loops > 0) {
                    itemStackList.remove(stacky); // take it away
                    loops--;
                }
            }
        }

        // place that block at "placePos"
        world.setBlockState(placePos, blockToPlace.getDefaultState());
    }

    void IgnitePortal(BlockPos portalBottomRight, BlockPos portalBottomLeft)
    {
        // replace a block behind the bottom of the portal with lava (left I guess)
        CP_MineBlock(portalBottomLeft);
        CP_FillLavaBucket(FindBlock(Blocks.LAVA, 25));
        CP_PlaceBLock(portalBottomLeft, Blocks.LAVA);

        // place wooden planks right above it
        BlockPos PBRA = new BlockPos(portalBottomRight.getX()-1, portalBottomRight.getY()+1, portalBottomRight.getZ());
        BlockPos PBLA = new BlockPos(portalBottomLeft.getX()-1, portalBottomLeft.getY()+1, portalBottomLeft.getZ());

        CP_MineBlock(PBRA);
        CP_MineBlock(PBLA);
        CP_PlaceBLock(PBRA, Blocks.OAK_PLANKS);
        CP_PlaceBLock(PBLA, Blocks.OAK_PLANKS);

        // wait for the portal to ignite
        waitingForNPortal = true;
    }

    void FindBlazes()
    {
        // set destination to a blaze spawner and wait
        BlockPos blazePos = FindBlock(Blocks.SPAWNER, 100);
        BlockPos newBlazePos = new BlockPos(blazePos.getX(), blazePos.getY() + 1, blazePos.getZ());
        getNavigator().tryMoveToXYZ(newBlazePos.getX(), newBlazePos.getY(), newBlazePos.getZ(), 0.23f);
        blazeLocation = newBlazePos;
        findingBlazes = true;
    }

    void Kill(Entity entity)
    {
        moveToKill(entity);
    }

    void moveToKill(Entity entity)
    {
        getNavigator().tryMoveToEntityLiving(entity, 0.23f); // this may not work...
    }

    @Override
    public void tick() // called every 1/20 of a second
    {
        //super.tick(); // makes sure the parent "Goal" does all it needs to do in tick TODO possibly uncomment

        if(!SPAWNEDYET) return;

        if(tryingToKill)
        {

        }

        if(waitingForNPortal)
        {
            BlockPos pos = FindBlock(Blocks.NETHER_PORTAL, 10);
            if(pos != getPosition())
            {
                waitingForNPortal = false;
                OGPortalPos = pos;
                getNavigator().tryMoveToXYZ(pos.getX(), pos.getY(), pos.getZ(), 0.23f);
                goingToPortalAfterBuilt = true;
            }
        }

        if(goingToPortalAfterBuilt)
        {
            if(getPosition() == OGPortalPos)
            {
                goingToPortalAfterBuilt = false;
                WTSAGIP = true;
            }
        }

        if(WTSAGIP)
        {
            WTSAGIP_ticks++;
            if(WTSAGIP_ticks >= 200)
            {
                WTSAGIP = false;
                FindBlazes();
            }
        }

        if(goingToWater)
        {
            if(getPosition() == WaterPos)
            {
                goingToWater = false;
                FillBucketWithWater();
            }
        }

        if(goingToLava)
        {
            if(getPosition() == LavaPos)
            {
                goingToWater = false;
                CreatePortal();
            }
        }

        if(smeltingIron) {
            ticksSinceStartedSmeltingIron++;
            if(ticksSinceStartedSmeltingIron >= 60)
            {
                smeltingIron = false;
                SI_HandleSmeltSystemAndCraftIronBucket();
            }
        }

        if(!foundTree) // updates whether or not we have found a tree
        {
            if(getPosition().equals(new BlockPos(nearestTree.getX() - 1, getPosY(), nearestTree.getZ() - 1)))
            {
                foundTree = true; // we have gotten to the tree
                tryfindtreerepeats--; // we have "repeated"
                if(tryfindtreerepeats <= 0) // if we have repeated enough...
                {
                    TryCraftOakPlanks(); // craft some oak planks
                }
                else { // otherwise...
                    TryBreakTree(); // break the tree we found
                    TryFindTree(); // find a new tree
                }
            }
        }

        if(startMining)
        {
            if(getPosition() == new BlockPos(mineStart.getX() - 1, getPosY(), mineStart.getZ() - 1))
            {
                MineInMine();
                startMining = false;
            }
        }

        if(movingtomine)
        {
            if(getPosition() == movingToMinePos)
            {
                MineInMine();
            }
        }

        if(afterMiningMove)
        {
            if(getPosition() == new BlockPos(CraftingTablePos.getX(), CraftingTablePos.getY(), CraftingTablePos.getZ() - 1))
            {
                afterMiningMove = false;
                if(mineForBlock == Blocks.COBBLESTONE)
                    TryCraftStonePickaxe();
                else if (mineForBlock == Blocks.IRON_ORE)
                    SmeltIron();
            }
        }

        CheckBlocksNearAndMine(Blocks.IRON_ORE);
        CheckBlocksNearAndMine(Blocks.DIAMOND_ORE);
    }

    void CheckBlocksNearAndMine(Block checkfordis)
    {
        BlockPos blockabove = new BlockPos(getPosX(), getPosY() +1, getPosZ());
        BlockPos blockbelow = new BlockPos(getPosX(), getPosY() -1, getPosZ());
        BlockPos blockNZ = new BlockPos(getPosX(), getPosY(), getPosZ() -1);
        BlockPos blockPZ = new BlockPos(getPosX(), getPosY(), getPosZ() +1);
        BlockPos blockNX = new BlockPos(getPosX() -1, getPosY(), getPosZ());
        BlockPos blockPX = new BlockPos(getPosX() +1, getPosY(), getPosZ());
        BlockPos blockabovetwo = new BlockPos(getPosX(), getPosY() +2, getPosZ());
        if(world.getBlockState(blockabove) == checkfordis.getDefaultState())
        {
            world.setBlockState(blockabove, Blocks.AIR.getDefaultState());
            itemStackList.add(new ItemStack(Item.getItemFromBlock(checkfordis))); // give the bot stuff
        }
        if(world.getBlockState(blockbelow) == checkfordis.getDefaultState())
        {
            world.setBlockState(blockbelow, Blocks.AIR.getDefaultState());
            itemStackList.add(new ItemStack(Item.getItemFromBlock(checkfordis))); // give the bot stuff
        }
        if(world.getBlockState(blockNZ) == checkfordis.getDefaultState())
        {
            world.setBlockState(blockNZ, Blocks.AIR.getDefaultState());
            itemStackList.add(new ItemStack(Item.getItemFromBlock(checkfordis))); // give the bot stuff
        }
        if(world.getBlockState(blockPZ) == checkfordis.getDefaultState())
        {
            world.setBlockState(blockPZ, Blocks.AIR.getDefaultState());
            itemStackList.add(new ItemStack(Item.getItemFromBlock(checkfordis))); // give the bot stuff
        }
        if(world.getBlockState(blockNX) == checkfordis.getDefaultState())
        {
            world.setBlockState(blockNX, Blocks.AIR.getDefaultState());
            itemStackList.add(new ItemStack(Item.getItemFromBlock(checkfordis))); // give the bot stuff
        }
        if(world.getBlockState(blockPX) == checkfordis.getDefaultState())
        {
            world.setBlockState(blockPX, Blocks.AIR.getDefaultState());
            itemStackList.add(new ItemStack(Item.getItemFromBlock(checkfordis))); // give the bot stuff
        }
        if(world.getBlockState(blockabovetwo) == checkfordis.getDefaultState())
        {
            world.setBlockState(blockabovetwo, Blocks.AIR.getDefaultState());
            itemStackList.add(new ItemStack(Item.getItemFromBlock(checkfordis))); // give the bot stuff
        }
    }

    BlockPos FindBlock(Block targetBlock, int radius) // finds the nearest block of a type
    {
        BlockPos closestPos = null;
        BlockPos checkPos = getPosition();

        for (int x = (int)getPosX()-radius; x < (int)getPosX()+radius; x++)
        {
            for (int y = (int)getPosY()-radius; x < (int)getPosY()+radius; y++)
            {
                for (int z = (int)getPosZ()-radius; z < (int)getPosZ()+radius; z++)
                {
                    checkPos = new BlockPos(x, y, z);
                    if (world.getBlockState(checkPos).getBlock() == targetBlock)
                    {
                        // check if it is closer than any previously found position
                        if (closestPos == null ||
                                getDistanceSq((int)getPosX() - checkPos.getX(),
                                        (int)getPosY() - checkPos.getY(),
                                        (int)getPosZ() - checkPos.getZ())
                                        < getDistanceSq((int)getPosX() - closestPos.getX(),
                                        (int)getPosY() - closestPos.getY(),
                                        (int)getPosZ() - closestPos.getZ()))
                        {
                            closestPos = checkPos;
                        }
                    }
                }
            }
        }
        if(closestPos != null)
            return closestPos;
        else
            return new BlockPos(getPosX(),getPosY(),getPosZ()); // return this random thing
    }

    void StartMine(Block thisisnewblock)
    {
        mineForBlock = thisisnewblock;
        getNavigator().tryMoveToXYZ(getPosX(), getPosY(), getPosZ() - 2, 0.23f);
        mineStart = new BlockPos(getPosX(), getPosY(), getPosZ() - 2);
        startMining = true;
    }

    void MineInMine()
    {
        movingtomine = false;
        BlockPos topblock = new BlockPos(getPosX(), getPosY() + 1, getPosZ() + 1);
        BlockPos midblock = new BlockPos(getPosX(), getPosY(), getPosZ() + 1);
        BlockPos lowblock = new BlockPos(getPosX(), getPosY() - 1, getPosZ() + 1);
        BlockState topblockOG = world.getBlockState(topblock);
        BlockState midblockOG = world.getBlockState(midblock);
        BlockState lowblockOG = world.getBlockState(lowblock);
        world.setBlockState(topblock, Blocks.AIR.getDefaultState());
        world.setBlockState(midblock, Blocks.AIR.getDefaultState());
        world.setBlockState(lowblock, Blocks.AIR.getDefaultState());
        itemStackList.add(new ItemStack(Item.getItemFromBlock(topblockOG.getBlock()))); // give the bot stuff
        itemStackList.add(new ItemStack(Item.getItemFromBlock(midblockOG.getBlock()))); // give the bot stuff
        itemStackList.add(new ItemStack(Item.getItemFromBlock(lowblockOG.getBlock()))); // give the bot stuff
        if(!HasAmountOfItem(Items.COBBLESTONE, 3) && mineForBlock == Blocks.COBBLESTONE)
        {
            getNavigator().tryMoveToXYZ(lowblock.getX(), lowblock.getY(), lowblock.getZ(), 0.23f);
            movingToMinePos = lowblock;
            movingtomine = true;
        }else if (!HasAmountOfItem(Items.IRON_ORE, 3) && mineForBlock == Blocks.IRON_ORE)
        {
            getNavigator().tryMoveToXYZ(lowblock.getX(), lowblock.getY(), lowblock.getZ(), 0.23f);
            movingToMinePos = lowblock;
            movingtomine = true;
        }
        else{
            AfterMine();
        }
    }

    void AfterMine()
    {
        getNavigator().tryMoveToXYZ(CraftingTablePos.getX(), CraftingTablePos.getY(), CraftingTablePos.getZ() - 1, 0.23f);
        afterMiningMove = true;
    }

    boolean HasAmountOfItem(Item checkForItem, int amountOfItem)
    {
        int amountfound = 0;
        for(ItemStack stacky : itemStackList){ // repeat for each item in the bot's inventory
            if(stacky.equals(new ItemStack(checkForItem))) { // if the bot has oak log
                amountfound++;
            }
        }
        if(amountfound >= amountOfItem)
            return true;
        else
            return false;
    }
}

 

 

Any help is appreciated!

Link to comment
Share on other sites

 

32 minutes ago, JJ Revans said:

    void TryFindTree() // we want to find a tree.
    {
        foundTree = false; // we have not found a tree
        nearestTree = FindBlock(Blocks.OAK_LOG, 50); // we want to find the nearest tree
        if(!nearestTree.equals(new BlockPos(getPosX(), getPosY(), getPosZ()))) // if the FindBlock doesnt give us the random thing...
            getNavigator().tryMoveToXYZ(nearestTree.getX() - 1, nearestTree.getY(), nearestTree.getZ() - 1, SPEED); // get to the tree
        else{ // otherwise...
            foundTree = true; // P.S. this is totally a lie just FYI
            TryFindTree(); // find a new tree
        }
    }

(1) Try to find a tree:
(2)  - If you fail to find a tree:

(3)  - - Goto 1

 

Plus you have a bunch of stuff that appears to indicate that you don't understand how the mob AI works, like your CreateNetherPortal method which tells the entity to find 14 lava blocks in one tick. It doesn't wait for the entity to actually DO anything, it says "find a lava blocks, place lava block, repeat 13 more times." All in the same function.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

3 minutes ago, JJ Revans said:

Is the code getting stuck in an infinite loop?

Yes.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

    private int startingRadius = 9; // the radius of our block checking

void TryFindTree() // we want to find a tree.
    {
        foundTree = false; // we have not found a tree
        startingRadius+=20;
        nearestTree = FindBlock(Blocks.OAK_LOG, startingRadius); // we want to find the nearest tree
        if(!nearestTree.equals(new BlockPos(getPosX(), getPosY(), getPosZ()))) // if the FindBlock doesnt give us the random thing...
            getNavigator().tryMoveToXYZ(nearestTree.getX() - 1, nearestTree.getY(), nearestTree.getZ() - 1, SPEED); // get to the tree
        else{ // otherwise...
            foundTree = true; // P.S. this is totally a lie just FYI
            TryFindTree(); // find a new tree
        }
    }

 

 

So I changed the script to work like this and spawned the entity near a tree. The problem still occurs. I may have put another infinite loop somewhere, but I am not sure...

 

About your Mob AI statement, I may be doing this in the completely wrong way. It was just the first way of doing things that jumped to my mind. Feel free to give suggestions if I have no idea what I'm doing, and thanks for your help!

Edited by JJ Revans
Link to comment
Share on other sites

2 hours ago, JJ Revans said:

So I changed the script to work like this and spawned the entity near a tree. The problem still occurs. I may have put another infinite loop somewhere, but I am not sure...

I'm not sure either, use the debugger.

2 hours ago, JJ Revans said:

I may be doing this in the completely wrong way. It was just the first way of doing things that jumped to my mind.

Here's a hint: you need to do one thing at a time and wait for the entity to complete that thing before you have it do something else.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

20 hours ago, JJ Revans said:

I may have put another infinite loop somewhere

Yes you did in your y for loop in FindBlock.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 hour ago, JJ Revans said:

when I damage it it freezes like before

This sure sounds like a good place to start debugging.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Congrats! You know what function is the problem. Now debug that function.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

So I believe the problem occurs when I run

        getNavigator().tryMoveToXYZ(nearestTree.getX() - 1, nearestTree.getY(), nearestTree.getZ() - 1, SPEED); // get to the tree

Is there a different function I should use, or is there another problem?

 

should I use 

getNavigator.getPathToXYZ();
getNavigator.setPath();

?

Edited by JJ Revans
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • アジアバスケットボールトーナメント▒BCGAME33·COM♠トーゴバスケットボール賭博場アジアトルコバスケットボール競技[本社お問い合わせテレJBOX7]アジアバスケットボール↔♠ポーカー大会エスワティーニバスケットボールゲームアジアジブチアジアバスケットボールポーカー大会[総販お問い合わせカカオトークJBOX7]アジアバスケットボール○総販バーレーンバスケットボールコミュニティアジアリゾートワールドカジノアジアバスケット業者[各種オフィコミュニティ制作]アジアバスケ☜♩バカラパブ東アジアバスケトーナメント[マーケティングお問い合わせ] アジアンバスケ☏●キャッシュゲームオーストラリアバスケゲーム アジアンバスケ中継 [カジノ本社] アジアンバスケサイト リトアニア ボリビア動画サイト バスケットボール ☜ サイトアンゴラバスケットボール中継 アジアタジキスタンアジアバスケットボール旅行 [トト本社お問い合わせ]アジアバスケットボール @♭ ゲームセンターサンマリノバスケットボール総販 アジアMGMカジノアジアバスケットボール競技 [トト総販購入]アジアバスケットボール ♥♧ 総販 ウズベキスタンバスケットボールツアー アジアアンドラアジアバスケットサイト [カジノ総販] アジアンバスケ▶▷YouTube中央アフリカバスケツアー アシアグランドレスカジノ·アーゴホールダンバー [大和本社]アジアンバスケ○トーナメント南アメリカバスケ グループトークルーム·アジブティ·グループチャットルーム [バッカラ総販] アジアンゴ総販] アジアンバカラ総販 [バカラ総販 [BCGAMEBCゲーム総販お問い合わせ] お知らせ設定おすすめ購読いいですね
    • 四国歌谣酒店经营场所@BCGAME55·COM♤四国歌谣酒店Telegram曲棍球四国歌谣酒店总经销滑雪歌谣酒店故事地板运动歌谣酒店视频[本社咨询的Tele@JBOX7]四国歌谣酒店 Twitter 单杠四国歌谣酒店社区滑雪歌谣酒店总经销羽毛球歌曲酒吧视频[总经销的Kakao Talk JBOX7]四国歌曲酒吧 推特壁球场 公开 滑冰网站 制作 制作 市容株式会社Kakao Talk 主题曲棍球游戏网站] 歌谣酒吧Kakao Talk [赌场总公司]四国歌谣酒吧 夜动摔跤 四国歌谣酒吧聚会信息 网球歌谣酒吧 Instagram 警报 歌谣酒吧 视频 [体育总公司] 四国歌谣酒吧 系统摔跤 四国歌谣酒吧 tour boachi歌谣酒吧 总判跳远歌曲酒店夜动[TOTO总公司咨询]四国歌曲酒店最新住址滑雪 西国歌曲酒店总判排球, Instagram,击剑,总地址, TOTO TO TO CO CO CO CO CO WORE SE SE SE SE SE SE SE S 马术四国歌谣酒店Tiktok Kongpu歌谣酒店巡演曲棍球歌谣酒店的地方[百家乐总经销]四国歌谣酒店系统 匹克球 四国歌谣酒店 度假村 单杠歌谣酒店最新地址 网络游戏 歌谣酒店 公开聊天[赛马总经销] 四国歌谣酒店 新地址 机械体操四国歌曲酒吧推特单杠推特 世界杯歌曲酒吧系统[BCGAME BC游戏总经销]推荐订阅 点赞
    • ヨーロッパバドゥギ競技↕BCGAME33·COM○スリナムバドゥギ業者ヨーロッパエルサルバドゥギ遊び場[本社お問い合わせテレJBOX7]ヨーロッパバドゥギ ↔#ホールダンバーアルメニアバドゥギ住所ヨーロッパセーシェルヨーロッパバドゥギ募集[総販お問い合わせカカオトークJBOX7]ヨーロッパバドゥギ ↙▷放送アルメニアバドゥギゲーム場ヨーロッパアイランド ヨーロッパバージュサイト[各種オフィコミュニティ制作]欧州バージュ ▣◇京畿ジャマイカバージュ ホールダンパブ 欧州アラブ首長国連邦欧州バージュ機 [マーケティングお問い合わせ] § 欧州カジノ本 バドゥギ□↙おすすめカンボジアバドゥギ賭博場ヨーロッパウガンダヨーロッパバドゥギ本社[トト本社お問い合わせ]ヨーロッパバドゥギ■↖本社エスワティーニバドゥギゲーム場ヨーロッパサントメプリンシフェヨーロッパバドゥギトーナメント[トト総販購入]ヨーロッパバドゥギ△☏検証チャドバドゥギ方法ヨーロッパカザフスタンヨーロッパバッダ接続[カジノ総販]欧州バッジュ ㏘&ゲーム場リベリアバッジュ競技欧州エクアドル欧州バッダリムホールダンバー [大和本社]欧州バッジュム♥サイトグランドレスカジノバッジュ ホールダンパブ 欧州レソト 欧州レソト 欧州バージュアバージュアルバンバージュ [BCGAMEBCゲーム総販お問い合わせ] お知らせ設定おすすめ購読いいですね
    • chuwaku客栈抖音◇BCGAME55·COM♩chuwaku客栈网站软性网球chuwaku客栈连接高尔夫客栈抖音板球客栈line[本社咨询的tele @JBOX7]chuwaku客栈服务区招募壁球客栈最新地址网络游戏客栈联谊会推荐[总经销咨询的kakaotalk JBOX7] 制作super 女宿运动网站choowakiwakookoowakootootaqootaqoo 制作人 joo jo  [赌场总公司] [CHUUGOOKUYO客栈最新地址 掷标枪] CHUGOOK客栈 曲棍球客栈 招募 地板运动 客栈故事 [体育总公司] CHUGO客栈 链接 CHUGO客栈最新地址 滑雪客栈 旅行足球客栈 Telegram[TOTO总公司咨询] CHUGO KAKO KAKO KATAL KA KALK 打跳远女宿舍 LINK [TO总网购买 CHOOK] SKUKY SKY总网 SKY KY Ski KY Ski 客栈最新地址软式网球客栈Kakao Talk拳击客栈的地方[百家乐总经销] Chuwaku客栈网站E体育 Chuwaku客栈度假村跳高客栈Kakao Talk Free Style客栈TikTok[赛马总经销] Chuwaku客栈验证警报 Chuwaku旅舍同好友会壁球壁球,按摩客人宿舍最新地址[BCGAME BC游戏总经销通知],推荐订阅,点赞。
    • 私設オリンピック賭博場☏BCGAME33·COM  그레グレナダオリンピック中継私設サウジアラビアオリンピックゲーム[本社お問い合わせテレJBOX7]私設オリンピック◑↖ツアーバーデンバーデンオリンピックゲーム私設フォールズビューカジノ私設オリンピックユーチューブ[総販お問い合わせカカオトークJBOX7]私設オリンピック♧☎検証コモロオリンピック本社私設ルクセンブルク私設五輪会社[各種オフィコミュニティ制作]社説五輪↗住所アルバニア五輪会社社説ブラジル社説五輪遊び場[マーケティングお問い合わせ]社説五輪º↔放送シエラレオネの社説エクアドル社説五輪サイト[カジノ本社]米国社説五輪戦略本部 旅行 スウェーデン五輪サイト私設エリトリア私設五輪推薦[ト本社お問い合わせ]私設五輪♤☎賭博場チリ五輪競技私設サモア私設五輪賭博場[ト総販購入]私設五輪§◁業者MGMカジノ五輪ホールダンバー私設チュニジア私設五輪放送[カジノ総販]社説オリンピック◈方法東南アジアオリンピックポーカー大会社説バハマ社説オリンピック旅行[大和本社]社説オリンピック↑戦略南アフリカオリンピッククープーン社説ブルガリア社説オリンピック住所[バカラ総販]社説オリンピック⊙住所モナコオリンピックキャッシュゲーム社説シンガポール総合競技場 購読、いいですね
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.