Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

Hello,

 

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()
    {    	
    	if(!testBool){
    	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){
    					searchIDs.add(searchID);
    				}
    			}
	    	}
    	}
    	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!

  • Author

Still looking for help on this.  I would imagine it's pretty straightforward but I can't seem to figure out how to detect wood.

 

Thanks!

  • Author

Thanks!

 

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?

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.