Posted September 23, 20205 yr Hello all! So I am trying to make an entity that beats minecraft. I tried using the entity class to make the entity do stuff, but now I am moving to making a custom mob goal. My problem is that the entity is supposed to move to a position, but doesn't. Entity Code: package com.jaegalaxy.illi.entities; import com.jaegalaxy.illi.ai.BotEntityNewAI; import net.minecraft.entity.*; import net.minecraft.entity.ai.goal.MeleeAttackGoal; import net.minecraft.entity.ai.goal.NearestAttackableTargetGoal; import net.minecraft.entity.ai.goal.SwimGoal; import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.monster.EndermanEntity; import net.minecraft.entity.monster.BlazeEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvents; import net.minecraft.world.World; import javax.annotation.Nullable; import java.util.Arrays; import java.util.List; public class BotEntity extends CreatureEntity { public List<ItemStack> itemStackList = Arrays.asList(); 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)); this.goalSelector.addGoal(0, new BotEntityNewAI(this)); this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 0.25f, true)); this.goalSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, BlazeEntity.class, false)); this.goalSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, EndermanEntity.class, false)); } @Override public void onDeath(DamageSource cause) { super.onDeath(cause); System.out.println("BOT HAS DIED"); if(!world.isRemote) { for (ItemStack stacky : itemStackList) { ItemEntity stackyEntity = new ItemEntity(world, getPosX(), getPosY(), getPosZ(), stacky); 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; //} } Goal Code: package com.jaegalaxy.illi.ai; import com.jaegalaxy.illi.entities.BotEntity; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.entity.Entity; import net.minecraft.entity.ai.goal.Goal; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.util.math.BlockPos; public class BotEntityNewAI extends Goal { public BotEntity MyEntity; private final float SPEED = 0.23f; private BlockPos CraftingTablePos; 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 BotEntityNewAI(BotEntity botEntity) { MyEntity = botEntity; } @Override public boolean shouldExecute() { return true; } @Override public void startExecuting() { // TODO start executing System.out.println("BOT HAS SPAWNED AND WILL NOW START"); TryFindTree(); } void TryFindTree() // we want to find a tree. { System.out.println("TRYING TO FIND A TREE"); foundTree = false; // we have not found a tree nearestTree = FindBlock(Blocks.OAK_LOG, 10); // we want to find the nearest tree MyEntity.getNavigator().tryMoveToXYZ(nearestTree.getX() - 1, nearestTree.getY(), nearestTree.getZ() - 1, SPEED); // get to the tree } void TryBreakTree() // we want to break a tree. { System.out.println("TRYING TO BREAK A TREE"); MyEntity.world.setBlockState(nearestTree, Blocks.AIR.getDefaultState()); // mine the wood MyEntity.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! { System.out.println("TRYING TO CRAFT OAK PLANKS"); for(ItemStack stacky : MyEntity.itemStackList){ // repeat for each item in the bot's inventory if(stacky.equals(new ItemStack(Items.OAK_LOG))){ // if the bot has oak log MyEntity.itemStackList.remove(stacky); // take away the oak logs MyEntity.itemStackList.add(new ItemStack(Items.OAK_PLANKS)); // give the bot wooden planks MyEntity.itemStackList.add(new ItemStack(Items.OAK_PLANKS)); // give the bot wooden planks MyEntity.itemStackList.add(new ItemStack(Items.OAK_PLANKS)); // give the bot wooden planks MyEntity.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 : MyEntity.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 MyEntity.itemStackList.remove(stacky); // take away the oak plank loops--; // we have looped } } } MyEntity.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(MyEntity.getPosX(), MyEntity.getPosY(), MyEntity.getPosZ() +1 ); int loops = 1; // do this once MyEntity.world.setBlockState(craftpos, Blocks.CRAFTING_TABLE.getDefaultState()); for(ItemStack stacky : MyEntity.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 MyEntity.itemStackList.remove(stacky); // take away the crafting table loops--; // we have looped } } } MyEntity.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 : MyEntity.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 MyEntity.itemStackList.remove(stacky); // take away an oak plank MyEntity.itemStackList.remove(stacky); // take away an oak plank MyEntity.itemStackList.add(new ItemStack(Items.CRAFTING_TABLE)); // give the bot a crafting table MyEntity.itemStackList.add(new ItemStack(Items.CRAFTING_TABLE)); // give the bot a crafting table MyEntity.itemStackList.add(new ItemStack(Items.CRAFTING_TABLE)); // give the bot a crafting table MyEntity.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 : MyEntity.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 MyEntity.itemStackList.remove(stacky); // take away an oak plank loops--; // we have looped } } } // TAKE AWAY STICKS! int loops2 = 2; // do this twice for(ItemStack stacky : MyEntity.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 MyEntity.itemStackList.remove(stacky); // take away stick loops2--; // we have looped } } } MyEntity.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 MyEntity.itemStackList.removeIf(stacky -> stacky.equals(new ItemStack(Items.COBBLESTONE))); int loops = 2; for(ItemStack stacky : MyEntity.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) { MyEntity.itemStackList.remove(stacky); // take it away loops--; } } } MyEntity.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() { MyEntity.itemStackList.removeIf(stacky -> stacky.equals(new ItemStack(Items.COBBLESTONE))); int loops = 8; for(ItemStack stacky : MyEntity.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) { MyEntity.itemStackList.remove(stacky); // take it away loops--; } } } BlockPos furnacePos = new BlockPos(CraftingTablePos.getX() - 1, CraftingTablePos.getY(), CraftingTablePos.getZ()); MyEntity.world.setBlockState(furnacePos, Blocks.FURNACE.getDefaultState()); SI_StartSmeltIron(); } void SI_StartSmeltIron() { smeltingIron = true; } void SI_HandleSmeltSystemAndCraftIronBucket() { // remove items used for smelting MyEntity.itemStackList.add(new ItemStack(Items.IRON_INGOT)); // give the bot an iron ingot MyEntity.itemStackList.add(new ItemStack(Items.IRON_INGOT)); // give the bot an iron ingot MyEntity.itemStackList.add(new ItemStack(Items.IRON_INGOT)); // give the bot an iron ingot int loops = 3; for(ItemStack stacky : MyEntity.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) { MyEntity.itemStackList.remove(stacky); // take it away loops--; } } } int loops2 = 3; for(ItemStack stacky : MyEntity.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) { MyEntity.itemStackList.remove(stacky); // take it away loops2--; } } } MyEntity.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 : MyEntity.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 MyEntity.itemStackList.remove(stacky); // take away an oak plank loops--; // we have looped } } } // TAKE AWAY STICKS! int loops2 = 1; // do this once for(ItemStack stacky : MyEntity.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 MyEntity.itemStackList.remove(stacky); // take away stick loops2--; // we have looped } } } MyEntity.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); MyEntity.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()); MyEntity.world.setBlockState(actualwaterpos, Blocks.AIR.getDefaultState()); int loops = 1; for(ItemStack stacky : MyEntity.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) { MyEntity.itemStackList.remove(stacky); // take it away MyEntity.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); MyEntity.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 : MyEntity.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) { MyEntity.itemStackList.remove(stacky); // take it away MyEntity.itemStackList.add(new ItemStack(Items.BUCKET)); // give the bot a bucket loops--; } } } // put down water at "emptyPos" MyEntity.world.setBlockState(emptyPos, Blocks.WATER.getDefaultState()); } void CP_FillLavaBucket(BlockPos fillPos) { // replace bucket with lava bucket int loops = 1; for(ItemStack stacky : MyEntity.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) { MyEntity.itemStackList.remove(stacky); // take it away MyEntity.itemStackList.add(new ItemStack(Items.LAVA_BUCKET)); // give the bot a lava bucket loops--; } } } // replace lava at "fillPos" with air MyEntity.world.setBlockState(fillPos, Blocks.AIR.getDefaultState()); } void CP_EmptyLavaBucket(BlockPos emptyPos) { // replace lava bucket with regular bucket int loops = 1; for(ItemStack stacky : MyEntity.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) { MyEntity.itemStackList.remove(stacky); // take it away MyEntity.itemStackList.add(new ItemStack(Items.BUCKET)); // give the bot a bucket loops--; } } } // put down lava at "emptyPos" MyEntity.world.setBlockState(emptyPos, Blocks.LAVA.getDefaultState()); } void CP_MineBlock(BlockPos blockPos) { // give the bot the block that will be removed MyEntity.itemStackList.add(new ItemStack(Item.getItemFromBlock(MyEntity.world.getBlockState(blockPos).getBlock()))); // give the bot a bucket // replace block at "blockPos" with air MyEntity.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 : MyEntity.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) { MyEntity.itemStackList.remove(stacky); // take it away loops--; } } } // place that block at "placePos" MyEntity.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()); MyEntity.getNavigator().tryMoveToXYZ(newBlazePos.getX(), newBlazePos.getY(), newBlazePos.getZ(), 0.23f); blazeLocation = newBlazePos; findingBlazes = true; } void Kill(Entity entity) { moveToKill(entity); } void moveToKill(Entity entity) { MyEntity.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(tryingToKill) { } if(waitingForNPortal) { BlockPos pos = FindBlock(Blocks.NETHER_PORTAL, 10); if(pos != MyEntity.getPosition()) { waitingForNPortal = false; OGPortalPos = pos; MyEntity.getNavigator().tryMoveToXYZ(pos.getX(), pos.getY(), pos.getZ(), 0.23f); goingToPortalAfterBuilt = true; } } if(goingToPortalAfterBuilt) { if(MyEntity.getPosition() == OGPortalPos) { goingToPortalAfterBuilt = false; WTSAGIP = true; } } if(WTSAGIP) { WTSAGIP_ticks++; if(WTSAGIP_ticks >= 200) { WTSAGIP = false; FindBlazes(); } } if(goingToWater) { if(MyEntity.getPosition() == WaterPos) { goingToWater = false; FillBucketWithWater(); } } if(goingToLava) { if(MyEntity.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(MyEntity.getPosition().equals(new BlockPos(nearestTree.getX() - 1, MyEntity.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(MyEntity.getPosition() == new BlockPos(mineStart.getX() - 1, MyEntity.getPosY(), mineStart.getZ() - 1)) { MineInMine(); startMining = false; } } if(movingtomine) { if(MyEntity.getPosition() == movingToMinePos) { MineInMine(); } } if(afterMiningMove) { if(MyEntity.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(MyEntity.getPosX(), MyEntity.getPosY() +1, MyEntity.getPosZ()); BlockPos blockbelow = new BlockPos(MyEntity.getPosX(), MyEntity.getPosY() -1, MyEntity.getPosZ()); BlockPos blockNZ = new BlockPos(MyEntity.getPosX(), MyEntity.getPosY(), MyEntity.getPosZ() -1); BlockPos blockPZ = new BlockPos(MyEntity.getPosX(), MyEntity.getPosY(), MyEntity.getPosZ() +1); BlockPos blockNX = new BlockPos(MyEntity.getPosX() -1, MyEntity.getPosY(), MyEntity.getPosZ()); BlockPos blockPX = new BlockPos(MyEntity.getPosX() +1, MyEntity.getPosY(), MyEntity.getPosZ()); BlockPos blockabovetwo = new BlockPos(MyEntity.getPosX(), MyEntity.getPosY() +2, MyEntity.getPosZ()); if(MyEntity.world.getBlockState(blockabove) == checkfordis.getDefaultState()) { MyEntity.world.setBlockState(blockabove, Blocks.AIR.getDefaultState()); MyEntity.itemStackList.add(new ItemStack(Item.getItemFromBlock(checkfordis))); // give the bot stuff } if(MyEntity.world.getBlockState(blockbelow) == checkfordis.getDefaultState()) { MyEntity.world.setBlockState(blockbelow, Blocks.AIR.getDefaultState()); MyEntity.itemStackList.add(new ItemStack(Item.getItemFromBlock(checkfordis))); // give the bot stuff } if(MyEntity.world.getBlockState(blockNZ) == checkfordis.getDefaultState()) { MyEntity.world.setBlockState(blockNZ, Blocks.AIR.getDefaultState()); MyEntity.itemStackList.add(new ItemStack(Item.getItemFromBlock(checkfordis))); // give the bot stuff } if(MyEntity.world.getBlockState(blockPZ) == checkfordis.getDefaultState()) { MyEntity.world.setBlockState(blockPZ, Blocks.AIR.getDefaultState()); MyEntity.itemStackList.add(new ItemStack(Item.getItemFromBlock(checkfordis))); // give the bot stuff } if(MyEntity.world.getBlockState(blockNX) == checkfordis.getDefaultState()) { MyEntity.world.setBlockState(blockNX, Blocks.AIR.getDefaultState()); MyEntity.itemStackList.add(new ItemStack(Item.getItemFromBlock(checkfordis))); // give the bot stuff } if(MyEntity.world.getBlockState(blockPX) == checkfordis.getDefaultState()) { MyEntity.world.setBlockState(blockPX, Blocks.AIR.getDefaultState()); MyEntity.itemStackList.add(new ItemStack(Item.getItemFromBlock(checkfordis))); // give the bot stuff } if(MyEntity.world.getBlockState(blockabovetwo) == checkfordis.getDefaultState()) { MyEntity.world.setBlockState(blockabovetwo, Blocks.AIR.getDefaultState()); MyEntity.itemStackList.add(new ItemStack(Item.getItemFromBlock(checkfordis))); // give the bot stuff } } BlockPos FindBlock(Block targetBlock, int radius) // finds the nearest block of a type { System.out.println("TRYING TO FIND A BLOCK OF TYPE " + targetBlock.toString() + ", WITH A CURRENT RADIUS OF " + radius); BlockPos closestPos = null; BlockPos checkPos; for (int x = (int)MyEntity.getPosX()-radius; x < (int)MyEntity.getPosX()+radius; x++) { for (int y = (int)MyEntity.getPosY()-radius; y < (int)MyEntity.getPosY()+radius; y++) { for (int z = (int)MyEntity.getPosZ()-radius; z < (int)MyEntity.getPosZ()+radius; z++) { checkPos = new BlockPos(x, y, z); if (MyEntity.world.getBlockState(checkPos).getBlock() == targetBlock) { // check if it is closer than any previously found position if (closestPos == null || MyEntity.getDistanceSq((int)MyEntity.getPosX() - checkPos.getX(), (int)MyEntity.getPosY() - checkPos.getY(), (int)MyEntity.getPosZ() - checkPos.getZ()) < MyEntity.getDistanceSq((int)MyEntity.getPosX() - closestPos.getX(), (int)MyEntity.getPosY() - closestPos.getY(), (int)MyEntity.getPosZ() - closestPos.getZ())) { closestPos = checkPos; } } } } } if(MyEntity.world.getBlockState(closestPos) != targetBlock.getDefaultState()) { System.out.println("TRYING TO FIND A NEW BLOCK"); return FindBlock(targetBlock, radius + 20); } else { System.out.println("WE FOUND A BLOCK"); return closestPos; } } void StartMine(Block newBlock) { mineForBlock = newBlock; MyEntity.getNavigator().tryMoveToXYZ(MyEntity.getPosX(), MyEntity.getPosY(), MyEntity.getPosZ() - 2, 0.23f); mineStart = new BlockPos(MyEntity.getPosX(), MyEntity.getPosY(), MyEntity.getPosZ() - 2); startMining = true; } void MineInMine() { movingtomine = false; BlockPos topblock = new BlockPos(MyEntity.getPosX(), MyEntity.getPosY() + 1, MyEntity.getPosZ() + 1); BlockPos midblock = new BlockPos(MyEntity.getPosX(), MyEntity.getPosY(), MyEntity.getPosZ() + 1); BlockPos lowblock = new BlockPos(MyEntity.getPosX(), MyEntity.getPosY() - 1, MyEntity.getPosZ() + 1); BlockState topblockOG = MyEntity.world.getBlockState(topblock); BlockState midblockOG = MyEntity.world.getBlockState(midblock); BlockState lowblockOG = MyEntity.world.getBlockState(lowblock); MyEntity.world.setBlockState(topblock, Blocks.AIR.getDefaultState()); MyEntity.world.setBlockState(midblock, Blocks.AIR.getDefaultState()); MyEntity.world.setBlockState(lowblock, Blocks.AIR.getDefaultState()); MyEntity.itemStackList.add(new ItemStack(Item.getItemFromBlock(topblockOG.getBlock()))); // give the bot stuff MyEntity.itemStackList.add(new ItemStack(Item.getItemFromBlock(midblockOG.getBlock()))); // give the bot stuff MyEntity.itemStackList.add(new ItemStack(Item.getItemFromBlock(lowblockOG.getBlock()))); // give the bot stuff if(!HasAmountOfItem(Items.COBBLESTONE, 3) && mineForBlock == Blocks.COBBLESTONE) { MyEntity.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) { MyEntity.getNavigator().tryMoveToXYZ(lowblock.getX(), lowblock.getY(), lowblock.getZ(), 0.23f); movingToMinePos = lowblock; movingtomine = true; } else{ AfterMine(); } } void AfterMine() { MyEntity.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 : MyEntity.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! Edited September 23, 20205 yr by JJ Revans
September 24, 20205 yr 43 minutes ago, JJ Revans said: So I am trying to make an entity that beats minecraft You should probably not do what you're doing. This basically says: here, try and do everything within a single tick and all at once. I'm not sure if the brain system exists yet, but this type of system is more appropriate for that over what you are doing now. This is not to mention, there are already goals that do what you are looking for correctly rather than continually executing a statement over and over again with no AI finish ever happening. You expect everything to be done in a single tick, and that's not how logic works.
September 24, 20205 yr Author I've taken into account what you have said ChampionAsh. I will definitely find a better way to do this. Until then, do you know why the myEntity.getNavigator.tryMoveToXYZ(); doesn't work?
September 24, 20205 yr Two reasons, tree not close enough so an endless loop cycles or position gets reset every tick not giving the navigator enough time to move. As I said before, you assume the entity is going to move from one location to another in a single tick. That's not how logic works. Cramming an entire brain system into a single goal is almost impossible without hundreds and hundreds of checks.
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.