-
Posts
9 -
Joined
-
Last visited
Everything posted by JJ Revans
-
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?
-
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!
-
I am going to look into using Goals
-
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(); ?
-
So I added some debugs and now I know that my entity starts up and then runs the function to find a tree, but never gets past that... Edit: Will do some more debugging
-
I fixed this (thanks Animefan8888), and now separate entities work fine. But when the entity spawns it does nothing, and when I damage it it freezes like before, but other entities work?
-
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!
-
Is the code getting stuck in an infinite loop?
-
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!