Jump to content

[1.8.9] Some kind of EntityEngineer


BusyBeever

Recommended Posts

Hello everyone,

 

what I am triing to is code an Entity that will construct something (e.g. a building) and im starting to question if my approach is the right one.

The information about what he should be building is called the "ConstructionTask", which is storing nothing but an ArrayList of the BlockInformations needed

public class ConstructionTask {

private ArrayList<BlockInf> blocksToPlace;

public ConstructionTask(ArrayList<BlockInf> blocksToPlace) {
	this.blocksToPlace = blocksToPlace;
}

public BlockInf getNextBlock(BlockPos myPos) {
	if(blocksToPlace.size()==0) return null;
	return blocksToPlace.remove(0);
}
}

public class BlockInf {

private final BlockPos pos;
private final IBlockState state;

public BlockInf(BlockPos pos, IBlockState state)
{
	this.pos = pos;
	this.state= state;

}

public BlockPos getPos() {
	return pos;
}

public IBlockState getState() {
	return state;
}
}

 

First question is it a good idea to store a building that way while constructing it?

 

Now comes the bigger problem. Creating the building.

 

My idea was that the engineer takes the next task from the list, tries to move near the position (e.g. max distance = 3) and then places the block.

Problem nr.1 what if there is no position that is close enough to stand on a block and have the desired distance

Problem nr.2 if there is such a block, how to find it?

 

If my approach is total bs please tell me, since this part of the project beeing messy can kill the performance of the mod.

 

My first attempt on creating a construction task

private class BuildVillageTask extends EntityAIBase {

	//The task the Engineer is working on
	private ConstructionTask task;
	//The next block the Engineer should place
	private BlockInf nextBlock;

	public BuildVillageTask() {
	}

	@Override
	public boolean shouldExecute() {
		//Always execute the task if the home has a new task for us
		return home.hasConstructionTask();
	}
	@Override
	public boolean isInterruptible() {
		//Not interruptable. Maybe change this later
		return false;
	}

	@Override
	public void startExecuting() {
		//Get the task from home
		task = home.getNextConstructionTask();
		//Get the first block to place
		nextBlock = task.getNextBlock(new BlockPos(EntityVillagerCustom.this));
	}

	@Override
	public boolean continueExecuting() {

		//If we reached our path
		if(getNavigator().noPath()) {
			//What we should do here:
			//Place the black
			//Get the next task
			//Set the navigator path to that place
		}
		else {
			//Do nothing since we are waiting to reach our place
		}

		//this will be changed later to "when building is done"
		return true;
	}


}

 

 

 

 

Link to comment
Share on other sites

The nice thing here is that, if I'm remembering correctly, you should be able to just use Minecrafts built-in pathing via "this.theCreature.getNavigator().tryMoveToXYZ" within an EntityAI class. That will bring your Engineer as close as possible to the target block (which you know the position of) and when he arrives, you can check his distance. If the distance is too large, then you don't place the block. Otherwise, place the block and move on. Makes sense, hopefully?

Have a modding question? PM me and hopefully I'll be able to help. Good at 2d Pixel Art? We need your help!  http://www.minecraftforum.net/topic/1806355-looking-for-2d-pixel-artist/

Link to comment
Share on other sites

Sadly thats not how tryMoveToXYZ works (If i get it right)

This method will only try to find a way to the specific XYZ, and if it cant it will return false

Or am I wrong with that?

Because the last time I tried to make that work it was returning me false all the time ( because the blocks I wanted him to build were out of range I guess)

Link to comment
Share on other sites

Join the conversation

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

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

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

×   Your previous content has been restored.   Clear editor

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

×
×
  • Create New...

Important Information

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