From 23d46e2bce30e0894f2aeea14d5103853899b43a Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Mon, 7 Jul 2014 00:19:01 +0200 Subject: [PATCH] made progress with builder robot, for #1908 --- .../assets/buildcraft/lang/en_US.lang | 1 + .../textures/entities/robot_builder.png | Bin 1287 -> 1546 bytes .../textures/entities/robot_builder_base.png | Bin 0 -> 1287 bytes common/buildcraft/BuildCraftSilicon.java | 2 + .../builders/IBuildingItemsProvider.java | 2 +- .../builders/TileAbstractBuilder.java | 6 +- .../builders/TileConstructionMarker.java | 29 ++++++- common/buildcraft/core/TileBuildCraft.java | 10 +++ .../core/blueprints/BptBuilderBase.java | 19 ++++- .../core/blueprints/BptBuilderBlueprint.java | 45 ++++++++--- .../core/blueprints/BptBuilderTemplate.java | 9 ++- .../core/blueprints/BuildingSlot.java | 2 + .../core/robots/boards/BoardRobotBuilder.java | 68 +++++++++++++++++ .../robots/boards/BoardRobotBuilderNBT.java | 72 ++++++++++++++++++ 14 files changed, 240 insertions(+), 25 deletions(-) create mode 100755 buildcraft_resources/assets/buildcraft/textures/entities/robot_builder_base.png create mode 100755 common/buildcraft/core/robots/boards/BoardRobotBuilder.java create mode 100755 common/buildcraft/core/robots/boards/BoardRobotBuilderNBT.java diff --git a/buildcraft_resources/assets/buildcraft/lang/en_US.lang b/buildcraft_resources/assets/buildcraft/lang/en_US.lang index 9295b8c4..7747e5df 100755 --- a/buildcraft_resources/assets/buildcraft/lang/en_US.lang +++ b/buildcraft_resources/assets/buildcraft/lang/en_US.lang @@ -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 diff --git a/buildcraft_resources/assets/buildcraft/textures/entities/robot_builder.png b/buildcraft_resources/assets/buildcraft/textures/entities/robot_builder.png index e4da83fe55e81f0d403d69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g2dc6*sqLItxFgMSe@_;k* z8i-yKp?>H;F+e+x`#C>$_x4PoY;9=*nx-Kdje??S_zW++_vU*vK)>`80JPoJn_%56 zqEo9@*(cJ^V(|O@?=m}oi+M+U4+d!St!5KE&m(p3t)+gFbiwEKn%uG*Pj<#}E2(5| zgJoIJ6lI$Sybo_DoxD)3nl^8jhuHCCXB;OCr=t|+p{gn(kq8);G0pF{DaLU_Bzx9)LaXc6d zp7?HC4*!`$u~Y=dad67pNx$_I=UJ}yMf%(iATdDFuII0gkHa%EV%mKA={1lfdD0Is zZr+L?m>bZp=e1U=r+$F(+MmV`gaNjeZ=g}H+x7z(mW3=ymi>U!_)G5s{q6@`dIN+* zVI1TSpsFg8U+tNH(qEs?3x;8!s;Xr_z>dH4E^xRt2b!iV>v>6*5DJB{v$K6_KR}k{ zt~_d_$+M~c_XC{O^8?PiI$sDHG_Wj-y-WrlSbS6vt0H_p z9~hQJ!thaIPJw50=>9n36be_niXHJp?V@atL=5cf~B*5)SFl4qyNP002ovPDHLkV1ioaNB{r; diff --git a/buildcraft_resources/assets/buildcraft/textures/entities/robot_builder_base.png b/buildcraft_resources/assets/buildcraft/textures/entities/robot_builder_base.png new file mode 100755 index 0000000000000000000000000000000000000000..e4da83fe55e81f0d403d69d3cfc6a8b726095def GIT binary patch literal 1287 zcmV+i1^D`jP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2ipu2 z79=$LhMDaE00f6gL_t(&-qo4gQrlJ(hJVRAm|(z`&!HuD-Ao{EAueU6?WCC`Q|`iR zq>s_*V>GWp?%JlEA!#!$flM)!lyIP=KCWw5LpG)RRU}$IvqF6O;-i|-h z4KSWO0949l1Ofq26a{bWnQl%g%!9#?jtmeEg^|r>aolVob@z?Q?L@H(hG8IyA`+i% znhvL4t99jjHh|IR+rs%dyxw|^_^ox5@?x0gP|^PH~YgOyAkpJ=*Fuyg2 zdc6*sqLItxFgMSe@_;k*8i-yKp?>H;F+e+x`#C>$_x4PoY;9=*nx-Kdje??S_zW++ z_vU*vK)>`80JPoJn_%56qEo9@*(cJ^V(|O@?=m}!c}IK?259rGW)nQmBX#esrGAoh z!RPgw+_D=_cE)ilsbp@0Wm(V^Wt#`Q4{s-(yil#0HgA`Q*zsg%948E?qZH<$swyIp z2pE+~ua1wy zGcsb@eER7%kR*B14=`@tiXWI8(5~mTR;#CefbrU&#t(!6ww7<8QLo$f0~nTtEJ>FA zfYbO(?*jeq2V8msghOE*AxA(GTd}*H3lt2UykP=gG6F{`Ui%)$;?+yESFl4qyNP002ovPDHLkV1iT=QDXoA literal 0 HcmV?d00001 diff --git a/common/buildcraft/BuildCraftSilicon.java b/common/buildcraft/BuildCraftSilicon.java index b24b2c9f..4c142e6e 100644 --- a/common/buildcraft/BuildCraftSilicon.java +++ b/common/buildcraft/BuildCraftSilicon.java @@ -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()); diff --git a/common/buildcraft/builders/IBuildingItemsProvider.java b/common/buildcraft/builders/IBuildingItemsProvider.java index dc0c8f68..f873a10a 100755 --- a/common/buildcraft/builders/IBuildingItemsProvider.java +++ b/common/buildcraft/builders/IBuildingItemsProvider.java @@ -12,5 +12,5 @@ import java.util.ArrayList; public interface IBuildingItemsProvider { - ArrayList getBuildersInAction(); + ArrayList getBuilders(); } diff --git a/common/buildcraft/builders/TileAbstractBuilder.java b/common/buildcraft/builders/TileAbstractBuilder.java index 32471697..464df373 100755 --- a/common/buildcraft/builders/TileAbstractBuilder.java +++ b/common/buildcraft/builders/TileAbstractBuilder.java @@ -110,6 +110,7 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil } } + @Override public ArrayList getBuilders() { return buildersInAction; } @@ -152,9 +153,4 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil mjPrev = mjStored; mjUnchangedCycles = 0; } - - @Override - public ArrayList getBuildersInAction() { - return buildersInAction; - } } diff --git a/common/buildcraft/builders/TileConstructionMarker.java b/common/buildcraft/builders/TileConstructionMarker.java index 691a1dcd..d4679927 100755 --- a/common/buildcraft/builders/TileConstructionMarker.java +++ b/common/buildcraft/builders/TileConstructionMarker.java @@ -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 currentMarkers = new HashSet(); + 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 buildersInAction = new ArrayList(); 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 getBuildersInAction() { + public ArrayList 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); + } } diff --git a/common/buildcraft/core/TileBuildCraft.java b/common/buildcraft/core/TileBuildCraft.java index 2008a4b7..707c30bb 100644 --- a/common/buildcraft/core/TileBuildCraft.java +++ b/common/buildcraft/core/TileBuildCraft.java @@ -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; + } } diff --git a/common/buildcraft/core/blueprints/BptBuilderBase.java b/common/buildcraft/core/blueprints/BptBuilderBase.java index 9a8a66f2..f3334426 100644 --- a/common/buildcraft/core/blueprints/BptBuilderBase.java +++ b/common/buildcraft/core/blueprints/BptBuilderBase.java @@ -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); } diff --git a/common/buildcraft/core/blueprints/BptBuilderBlueprint.java b/common/buildcraft/core/blueprints/BptBuilderBlueprint.java index eaeda1ee..a54b3083 100644 --- a/common/buildcraft/core/blueprints/BptBuilderBlueprint.java +++ b/common/buildcraft/core/blueprints/BptBuilderBlueprint.java @@ -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 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 list) { - Iterator it = list.iterator(); + private BuildingSlot internalGetNextEntity(World world, TileAbstractBuilder builder) { + Iterator it = entityList.iterator(); while (it.hasNext()) { BuildingSlotEntity slot = it.next(); diff --git a/common/buildcraft/core/blueprints/BptBuilderTemplate.java b/common/buildcraft/core/blueprints/BptBuilderTemplate.java index 13e4d852..70de4ac3 100644 --- a/common/buildcraft/core/blueprints/BptBuilderTemplate.java +++ b/common/buildcraft/core/blueprints/BptBuilderTemplate.java @@ -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 list) { + public BuildingSlotBlock internalGetNextBlock(World world, TileAbstractBuilder builder) { BuildingSlotBlock result = null; IInvSlot firstSlotToConsume = null; diff --git a/common/buildcraft/core/blueprints/BuildingSlot.java b/common/buildcraft/core/blueprints/BuildingSlot.java index ac0d083b..65c223a0 100755 --- a/common/buildcraft/core/blueprints/BuildingSlot.java +++ b/common/buildcraft/core/blueprints/BuildingSlot.java @@ -23,6 +23,8 @@ public abstract class BuildingSlot { public LinkedList stackConsumed; + public boolean reserved = false; + public void writeToWorld(IBuilderContext context) { } diff --git a/common/buildcraft/core/robots/boards/BoardRobotBuilder.java b/common/buildcraft/core/robots/boards/BoardRobotBuilder.java new file mode 100755 index 00000000..af41e836 --- /dev/null +++ b/common/buildcraft/core/robots/boards/BoardRobotBuilder.java @@ -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); + } + } +} diff --git a/common/buildcraft/core/robots/boards/BoardRobotBuilderNBT.java b/common/buildcraft/core/robots/boards/BoardRobotBuilderNBT.java new file mode 100755 index 00000000..9cb35b53 --- /dev/null +++ b/common/buildcraft/core/robots/boards/BoardRobotBuilderNBT.java @@ -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) { + } +}