made progress with builder robot, for #1908
This commit is contained in:
parent
3ccb215cf9
commit
23d46e2bce
14 changed files with 240 additions and 25 deletions
|
@ -12,6 +12,7 @@ buildcraft.boardRobotFarmer=Farmer
|
|||
buildcraft.boardRobotHarvester=Harvester
|
||||
buildcraft.boardRobotShovelman=Shovelman
|
||||
buildcraft.boardRobotButcher=Butcher
|
||||
buildcraft.boardRobotBuilder=Builder
|
||||
buildcraft.boardDetail.parameters=Parameters
|
||||
buildcraft.boardDetail.range=Range
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.5 KiB |
BIN
buildcraft_resources/assets/buildcraft/textures/entities/robot_builder_base.png
Executable file
BIN
buildcraft_resources/assets/buildcraft/textures/entities/robot_builder_base.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
|
@ -43,6 +43,7 @@ import buildcraft.core.network.BuildCraftChannelHandler;
|
|||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.robots.RobotIntegrationRecipe;
|
||||
import buildcraft.core.robots.boards.BoardRobotBomberNBT;
|
||||
import buildcraft.core.robots.boards.BoardRobotBuilderNBT;
|
||||
import buildcraft.core.robots.boards.BoardRobotButcherNBT;
|
||||
import buildcraft.core.robots.boards.BoardRobotCarrierNBT;
|
||||
import buildcraft.core.robots.boards.BoardRobotFarmerNBT;
|
||||
|
@ -159,6 +160,7 @@ public class BuildCraftSilicon extends BuildCraftMod {
|
|||
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotShovelmanNBT.instance, 5);
|
||||
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotKnightNBT.instance, 1);
|
||||
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotBomberNBT.instance, 1);
|
||||
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotBuilderNBT.instance, 0.5F);
|
||||
|
||||
StatementManager.registerActionProvider(new RobotsActionProvider());
|
||||
StatementManager.registerTriggerProvider(new RobotsTriggerProvider());
|
||||
|
|
|
@ -12,5 +12,5 @@ import java.util.ArrayList;
|
|||
|
||||
public interface IBuildingItemsProvider {
|
||||
|
||||
ArrayList<BuildingItem> getBuildersInAction();
|
||||
ArrayList<BuildingItem> getBuilders();
|
||||
}
|
||||
|
|
|
@ -110,6 +110,7 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<BuildingItem> getBuilders() {
|
||||
return buildersInAction;
|
||||
}
|
||||
|
@ -152,9 +153,4 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil
|
|||
mjPrev = mjStored;
|
||||
mjUnchangedCycles = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<BuildingItem> getBuildersInAction() {
|
||||
return buildersInAction;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
package buildcraft.builders;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -25,6 +26,8 @@ import buildcraft.core.blueprints.BptBuilderBlueprint;
|
|||
|
||||
public class TileConstructionMarker extends TileBuildCraft implements IBuildingItemsProvider {
|
||||
|
||||
public static HashSet<TileConstructionMarker> currentMarkers = new HashSet<TileConstructionMarker>();
|
||||
|
||||
public ForgeDirection direction = ForgeDirection.UNKNOWN;
|
||||
|
||||
@NetworkData
|
||||
|
@ -33,7 +36,8 @@ public class TileConstructionMarker extends TileBuildCraft implements IBuildingI
|
|||
@NetworkData
|
||||
public ItemStack itemBlueprint;
|
||||
|
||||
private BptBuilderBase bluePrintBuilder;
|
||||
public BptBuilderBase bluePrintBuilder;
|
||||
|
||||
private ArrayList<BuildingItem> buildersInAction = new ArrayList<BuildingItem>();
|
||||
private NBTTagCompound initNBT;
|
||||
|
||||
|
@ -47,8 +51,7 @@ public class TileConstructionMarker extends TileBuildCraft implements IBuildingI
|
|||
|
||||
if (itemBlueprint != null && bluePrintBuilder == null) {
|
||||
bluePrintBuilder = new BptBuilderBlueprint((Blueprint) ItemBlueprint.loadBlueprint(itemBlueprint),
|
||||
worldObj, xCoord,
|
||||
yCoord, zCoord);
|
||||
worldObj, xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
if (laser == null && direction != ForgeDirection.UNKNOWN) {
|
||||
|
@ -113,7 +116,25 @@ public class TileConstructionMarker extends TileBuildCraft implements IBuildingI
|
|||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<BuildingItem> getBuildersInAction() {
|
||||
public ArrayList<BuildingItem> getBuilders() {
|
||||
return buildersInAction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
if (!worldObj.isRemote) {
|
||||
currentMarkers.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
if (!worldObj.isRemote) {
|
||||
currentMarkers.remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean needsToBuild() {
|
||||
return bluePrintBuilder != null && !bluePrintBuilder.isDone(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,4 +144,14 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
|
|||
public World getWorld() {
|
||||
return worldObj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ((xCoord * 37 + yCoord) * 37 + zCoord) * 37 + worldObj.provider.dimensionId * 37;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object cmp) {
|
||||
return this == cmp;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,9 @@ public abstract class BptBuilderBase implements IAreaProvider {
|
|||
|
||||
protected abstract void initialize ();
|
||||
|
||||
public abstract BuildingSlot getNextBlock(World world, TileAbstractBuilder inv);
|
||||
protected abstract BuildingSlot reserveNextBlock(World world);
|
||||
|
||||
protected abstract BuildingSlot getNextBlock(World world, TileAbstractBuilder inv);
|
||||
|
||||
public boolean buildNextSlot (World world, TileAbstractBuilder builder, int x, int y, int z) {
|
||||
if (!initialized) {
|
||||
|
@ -84,6 +86,15 @@ public abstract class BptBuilderBase implements IAreaProvider {
|
|||
return false;
|
||||
}
|
||||
|
||||
public BuildingSlot reserveNextSlot(World world) {
|
||||
if (!initialized) {
|
||||
initialize();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
return reserveNextBlock(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int xMin() {
|
||||
return x - blueprint.anchorX;
|
||||
|
@ -141,7 +152,7 @@ public abstract class BptBuilderBase implements IAreaProvider {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isDone (TileAbstractBuilder builder) {
|
||||
public boolean isDone(IBuildingItemsProvider builder) {
|
||||
return done && builder.getBuilders().size() == 0;
|
||||
}
|
||||
|
||||
|
@ -192,7 +203,7 @@ public abstract class BptBuilderBase implements IAreaProvider {
|
|||
|
||||
NBTTagList buildingList = new NBTTagList();
|
||||
|
||||
for (BuildingItem item : builder.getBuildersInAction()) {
|
||||
for (BuildingItem item : builder.getBuilders()) {
|
||||
NBTTagCompound sub = new NBTTagCompound();
|
||||
item.writeToNBT(sub);
|
||||
buildingList.appendTag(sub);
|
||||
|
@ -228,7 +239,7 @@ public abstract class BptBuilderBase implements IAreaProvider {
|
|||
try {
|
||||
item.readFromNBT(buildingList.getCompoundTagAt(i));
|
||||
item.context = getContext();
|
||||
builder.getBuildersInAction().add(item);
|
||||
builder.getBuilders().add(item);
|
||||
} catch (MappingNotFoundException e) {
|
||||
BCLog.logger.log(Level.WARNING, "can't load building item", e);
|
||||
}
|
||||
|
|
|
@ -254,10 +254,25 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuildingSlot reserveNextBlock(World world) {
|
||||
if (buildList.size() != 0) {
|
||||
BuildingSlot slot = internalGetNextBlock(world, null);
|
||||
|
||||
if (slot != null) {
|
||||
slot.reserved = true;
|
||||
}
|
||||
|
||||
return slot;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuildingSlot getNextBlock(World world, TileAbstractBuilder inv) {
|
||||
if (buildList.size() != 0) {
|
||||
BuildingSlot slot = internalGetNextBlock(world, inv, buildList);
|
||||
BuildingSlot slot = internalGetNextBlock(world, inv);
|
||||
checkDone();
|
||||
|
||||
if (slot != null) {
|
||||
|
@ -268,7 +283,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
}
|
||||
|
||||
if (entityList.size() != 0) {
|
||||
BuildingSlot slot = internalGetNextEntity(world, inv, entityList);
|
||||
BuildingSlot slot = internalGetNextEntity(world, inv);
|
||||
checkDone ();
|
||||
|
||||
if (slot != null) {
|
||||
|
@ -283,8 +298,13 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
return null;
|
||||
}
|
||||
|
||||
private BuildingSlot internalGetNextBlock(World world, TileAbstractBuilder builder, LinkedList<BuildingSlotBlock> list) {
|
||||
if (builder.energyAvailable() < SchematicRegistry.BREAK_ENERGY) {
|
||||
/**
|
||||
* Gets the next available block. If builder is not null, then building will
|
||||
* be verified and performed. Otherwise, the next possible building slot is
|
||||
* returned, possibly for reservation, with no building.
|
||||
*/
|
||||
private BuildingSlot internalGetNextBlock(World world, TileAbstractBuilder builder) {
|
||||
if (builder != null && builder.energyAvailable() < SchematicRegistry.BREAK_ENERGY) {
|
||||
// If there's no more energy available, then set reset the list and
|
||||
// quit. This will avoid situations where energy is given at a
|
||||
// random point in time, and therefore builder doesn't start from
|
||||
|
@ -304,6 +324,10 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
return null;
|
||||
}
|
||||
|
||||
if (slot.reserved) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
if (BlockUtil.isUnbreakableBlock(world, slot.x, slot.y, slot.z)) {
|
||||
// if the block can't be broken, just forget this iterator
|
||||
|
@ -324,15 +348,17 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
clearedLocations.add(new BlockIndex(slot.x,
|
||||
slot.y, slot.z));
|
||||
} else {
|
||||
if (setupForDestroy(builder, context, slot)) {
|
||||
if (builder != null && setupForDestroy(builder, context, slot)) {
|
||||
iterator.remove();
|
||||
clearedLocations.add(new BlockIndex(slot.x,
|
||||
slot.y, slot.z));
|
||||
return slot;
|
||||
} else {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
} else if (!slot.schematic.doNotBuild()) {
|
||||
if (checkRequirements(builder, slot.schematic)) {
|
||||
if (builder != null && checkRequirements(builder, slot.schematic)) {
|
||||
// At this stage, regardless of the fact that the
|
||||
// block can actually be built or not, we'll try.
|
||||
// When the item reaches the actual block, we'll
|
||||
|
@ -345,6 +371,8 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
builtLocations.add(new BlockIndex(slot.x,
|
||||
slot.y, slot.z));
|
||||
return slot;
|
||||
} else {
|
||||
return slot;
|
||||
}
|
||||
} else {
|
||||
// Even slots that don't need to be build may need
|
||||
|
@ -375,9 +403,8 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
return null;
|
||||
}
|
||||
|
||||
private BuildingSlot internalGetNextEntity(World world,
|
||||
TileAbstractBuilder builder, LinkedList<BuildingSlotEntity> list) {
|
||||
Iterator<BuildingSlotEntity> it = list.iterator();
|
||||
private BuildingSlot internalGetNextEntity(World world, TileAbstractBuilder builder) {
|
||||
Iterator<BuildingSlotEntity> it = entityList.iterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
BuildingSlotEntity slot = it.next();
|
||||
|
|
|
@ -110,10 +110,15 @@ public class BptBuilderTemplate extends BptBuilderBase {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuildingSlot reserveNextBlock(World world) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuildingSlot getNextBlock(World world, TileAbstractBuilder inv) {
|
||||
if (buildList.size() != 0) {
|
||||
BuildingSlotBlock slot = internalGetNextBlock(world, inv, buildList);
|
||||
BuildingSlotBlock slot = internalGetNextBlock(world, inv);
|
||||
checkDone();
|
||||
|
||||
if (slot != null) {
|
||||
|
@ -126,7 +131,7 @@ public class BptBuilderTemplate extends BptBuilderBase {
|
|||
return null;
|
||||
}
|
||||
|
||||
public BuildingSlotBlock internalGetNextBlock(World world, TileAbstractBuilder builder, LinkedList<BuildingSlotBlock> list) {
|
||||
public BuildingSlotBlock internalGetNextBlock(World world, TileAbstractBuilder builder) {
|
||||
BuildingSlotBlock result = null;
|
||||
|
||||
IInvSlot firstSlotToConsume = null;
|
||||
|
|
|
@ -23,6 +23,8 @@ public abstract class BuildingSlot {
|
|||
|
||||
public LinkedList<ItemStack> stackConsumed;
|
||||
|
||||
public boolean reserved = false;
|
||||
|
||||
public void writeToWorld(IBuilderContext context) {
|
||||
|
||||
}
|
||||
|
|
68
common/buildcraft/core/robots/boards/BoardRobotBuilder.java
Executable file
68
common/buildcraft/core/robots/boards/BoardRobotBuilder.java
Executable file
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.core.robots.boards;
|
||||
|
||||
import buildcraft.api.boards.RedstoneBoardRobot;
|
||||
import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
||||
import buildcraft.api.robots.AIRobot;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.builders.TileConstructionMarker;
|
||||
import buildcraft.core.blueprints.BuildingSlot;
|
||||
import buildcraft.core.robots.AIRobotGotoSleep;
|
||||
|
||||
public class BoardRobotBuilder extends RedstoneBoardRobot {
|
||||
|
||||
private TileConstructionMarker markerToBuild;
|
||||
private BuildingSlot currentBuildingSlot;
|
||||
|
||||
public BoardRobotBuilder(EntityRobotBase iRobot) {
|
||||
super(iRobot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneBoardRobotNBT getNBTHandler() {
|
||||
return BoardRobotBuilderNBT.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (markerToBuild == null) {
|
||||
double minDistance = Double.MAX_VALUE;
|
||||
|
||||
for (TileConstructionMarker marker : TileConstructionMarker.currentMarkers) {
|
||||
if (marker.getWorld() == robot.worldObj && marker.needsToBuild()) {
|
||||
double dx = robot.posX - marker.xCoord;
|
||||
double dy = robot.posY - marker.yCoord;
|
||||
double dz = robot.posZ - marker.zCoord;
|
||||
double distance = dx * dx + dy * dy + dz * dz;
|
||||
|
||||
if (distance < minDistance) {
|
||||
markerToBuild = marker;
|
||||
minDistance = distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (markerToBuild == null) {
|
||||
startDelegateAI(new AIRobotGotoSleep(robot));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (markerToBuild == null || !markerToBuild.needsToBuild()) {
|
||||
markerToBuild = null;
|
||||
startDelegateAI(new AIRobot(robot));
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentBuildingSlot == null) {
|
||||
currentBuildingSlot = markerToBuild.bluePrintBuilder.reserveNextSlot(robot.worldObj);
|
||||
}
|
||||
}
|
||||
}
|
72
common/buildcraft/core/robots/boards/BoardRobotBuilderNBT.java
Executable file
72
common/buildcraft/core/robots/boards/BoardRobotBuilderNBT.java
Executable file
|
@ -0,0 +1,72 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.core.robots.boards;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import buildcraft.api.boards.RedstoneBoardRobot;
|
||||
import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.utils.StringUtils;
|
||||
|
||||
public final class BoardRobotBuilderNBT extends RedstoneBoardRobotNBT {
|
||||
|
||||
public static BoardRobotBuilderNBT instance = new BoardRobotBuilderNBT();
|
||||
|
||||
private static final ResourceLocation TEXTURE = new ResourceLocation("buildcraft",
|
||||
DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_builder.png");
|
||||
|
||||
private IIcon icon;
|
||||
|
||||
@Override
|
||||
public RedstoneBoardRobot create(NBTTagCompound nbt, EntityRobotBase robot) {
|
||||
return new BoardRobotBuilder(robot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getRobotTexture() {
|
||||
return TEXTURE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return "buildcraft:boardRobotBuilder";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced) {
|
||||
list.add(StringUtils.localize("buildcraft.boardRobotBuilder"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister iconRegister) {
|
||||
icon = iconRegister.registerIcon("buildcraft:board_yellow");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(NBTTagCompound nbt) {
|
||||
return icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createRandomBoard(NBTTagCompound nbt) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createDefaultBoard(NBTTagCompound nbt) {
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue