Jump to content

[1.8.7] AI Entity can only sometimes find block IDs; want to find wood


Recommended Posts



Goal: Find wood (trees) and later navigate to and chop the trees


Method: The entity I created implements a custom ai method that extends EntityAIBase.  It creates a list of blocks within a certain radius of the entity and finds blocks of interest.  I've tried to filter the list of nearby blocks using both the block name and id (deprecated?)  then printing the results.


Problem: Depending on where I place the entity it only sometimes finds something other than air even if it's standing near dirt, trees, or stone.


Question: What is a good way to find wood blocks near the entity?  It seems id's and names are useless in this endeavor.


Code:  A few of the support functions are removed for clarity.

package com.dm.gatherer.ai;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;

public class tempAI extends EntityAIBase
    private EntityCreature entity;
    private double xPosition;
    private double yPosition;
    private double zPosition;
    private double speed;
    private int field_179481_f;
    private boolean field_179482_g;
    private static final String __OBFID = "CL_00001608";
    int searchRadius = 25;
    private int harvestID = 17;
    private boolean navigationSuccessful = false;
boolean runonce = false;
List<Entity> harvestableEntities;
boolean testBool = false;
int testInt = 0;

BlockPos searchPos;
Block searchBlock;
int searchID;
List<Integer> searchIDs = new ArrayList<Integer>();
     * Execute a one shot task or start executing a continuous task
    public void startExecuting()
    	for(int searchX = (int) (this.entity.posX - searchRadius); searchX < this.entity.posX + searchRadius; searchX++){
    		for(int searchY = (int) (this.entity.posY - searchRadius); searchY < this.entity.posY + searchRadius; searchY++){
    			for(int searchZ = (int) (this.entity.posX - searchRadius); searchZ < this.entity.posX + searchRadius; searchZ++){
    				searchPos = new BlockPos(searchX, searchY, searchZ);
    				searchBlock = Minecraft.getMinecraft().theWorld.getBlockState(searchPos).getBlock();
    				searchID = searchBlock.getIdFromBlock(Minecraft.getMinecraft().theWorld.getBlockState(searchPos).getBlock());
    				if(searchID != 0){
    	testBool = true;
    	System.out.println("Start printing!");
    	for(int id: searchIDs){
    		System.out.println("ID: " + id);
    	System.out.println("Done printing!");


Thanks for your attention!

Link to comment
Share on other sites



I use the block but need to make sure it's the correct type of block. 


How do I ensure that the block it is looking at is wood, for example?  Names are useful for this, I guess ID's would be too if they weren't depreciated.  Do you mean to check equality (using the equality operator of the Block class) of some wood Block instance to the block we're looking at?

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.

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.


  • Create New...

Important Information

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