Made a basic harvester block
basic harvester proto type too test search function for bots.
This commit is contained in:
parent
35b1f75329
commit
249c6cfef6
3 changed files with 255 additions and 2 deletions
|
@ -1,5 +1,61 @@
|
||||||
package net.minecraft.src.eui.robotics;
|
package net.minecraft.src.eui.robotics;
|
||||||
|
|
||||||
public class BlockComp {
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.src.Block;
|
||||||
|
import net.minecraft.src.IBlockAccess;
|
||||||
|
import net.minecraft.src.Material;
|
||||||
|
import net.minecraft.src.TileEntity;
|
||||||
|
import net.minecraft.src.eui.TileEntityNuller;
|
||||||
|
import net.minecraft.src.eui.boiler.TileEntityBoiler;
|
||||||
|
import net.minecraft.src.eui.burner.TileEntityFireBox;
|
||||||
|
import net.minecraft.src.eui.turbine.TileEntityGenerator;
|
||||||
|
import net.minecraft.src.universalelectricity.Vector3;
|
||||||
|
|
||||||
|
public class BlockComp extends net.minecraft.src.universalelectricity.extend.BlockMachine {
|
||||||
|
|
||||||
|
public BlockComp(int par1) {
|
||||||
|
super("RobotMachine", par1, Material.iron);
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
public int getBlockTexture(IBlockAccess par1iBlockAccess, int x, int y, int z, int side)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
public int getBlockTextureFromSideAndMetadata(int side, int metadata)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public TileEntity getBlockEntity() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public TileEntity getBlockEntity(int meta)
|
||||||
|
{
|
||||||
|
switch(meta)
|
||||||
|
{
|
||||||
|
case 0: return new TileEntityComp();
|
||||||
|
case 1: return new TileEntityComp();
|
||||||
|
case 2: return new TileEntityComp();
|
||||||
|
case 3: return new TileEntityComp();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String getTextureFile() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return "/eui/blocks.png";
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean isOpaqueCube()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public int getRenderType()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
24
minecraft/net/minecraft/src/eui/robotics/ItemMachine.java
Normal file
24
minecraft/net/minecraft/src/eui/robotics/ItemMachine.java
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package net.minecraft.src.eui.robotics;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import net.minecraft.src.*;
|
||||||
|
|
||||||
|
public class ItemMachine extends ItemBlock {
|
||||||
|
|
||||||
|
public ItemMachine(int id) {
|
||||||
|
super(id);
|
||||||
|
setMaxDamage(0);
|
||||||
|
setHasSubtypes(true);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int getMetadata(int metadata)
|
||||||
|
{
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String getItemName()
|
||||||
|
{
|
||||||
|
return "Machine";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,178 @@
|
||||||
package net.minecraft.src.eui.robotics;
|
package net.minecraft.src.eui.robotics;
|
||||||
|
|
||||||
public class TileEntityComp {
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.src.AxisAlignedBB;
|
||||||
|
import net.minecraft.src.Block;
|
||||||
|
import net.minecraft.src.EntityItem;
|
||||||
|
import net.minecraft.src.EntityPlayer;
|
||||||
|
import net.minecraft.src.ItemStack;
|
||||||
|
import net.minecraft.src.Material;
|
||||||
|
import net.minecraft.src.ModLoader;
|
||||||
|
import net.minecraft.src.TileEntity;
|
||||||
|
import net.minecraft.src.universalelectricity.Vector3;
|
||||||
|
import net.minecraft.src.universalelectricity.electricity.TileEntityElectricUnit;
|
||||||
|
|
||||||
|
public class TileEntityComp extends TileEntityElectricUnit {
|
||||||
|
public EntityRobot[] BotList = {null,null,null,null};
|
||||||
|
|
||||||
|
int updateCount = 0;
|
||||||
|
int scanCount = 0;
|
||||||
|
boolean hasScanned = false;
|
||||||
|
int lastScanXDif=0;
|
||||||
|
int lastScanYDif=0;
|
||||||
|
int lastScanZDif=0;
|
||||||
|
public void onUpdate(float watts, float voltage, byte side)
|
||||||
|
{
|
||||||
|
++updateCount;
|
||||||
|
|
||||||
|
|
||||||
|
if(updateCount >= 100 && worldObj.checkChunksExist(xCoord, yCoord, zCoord, xCoord+1, yCoord+1, zCoord+1))
|
||||||
|
{
|
||||||
|
++scanCount;
|
||||||
|
if(scanCount < 10){hasScanned = true;}else{scanCount = 0;}
|
||||||
|
Vector3 thisBlock = new Vector3(this.xCoord,this.yCoord,this.zCoord);
|
||||||
|
updateCount = 0;
|
||||||
|
Vector3 targetVec = findBlock(thisBlock,Block.leaves,2,hasScanned);
|
||||||
|
if(targetVec == null)
|
||||||
|
{
|
||||||
|
targetVec = findBlock(thisBlock,Block.wood,2,hasScanned);
|
||||||
|
}
|
||||||
|
if(targetVec != null)
|
||||||
|
{
|
||||||
|
int Targetx = targetVec.intX();
|
||||||
|
int Targety = targetVec.intY();
|
||||||
|
int Targetz = targetVec.intZ();
|
||||||
|
ModLoader.getMinecraftInstance().thePlayer.addChatMessage("rb:"+Targetx+"X:"+Targety+"Y:"+Targetz+"Z");
|
||||||
|
int blockTargetc = worldObj.getBlockId(Targetx, Targety, Targetz);
|
||||||
|
worldObj.setBlock(Targetx, Targety, Targetz, 0);
|
||||||
|
|
||||||
|
if(blockTargetc > 0)
|
||||||
|
{
|
||||||
|
EntityItem dropedItem = new EntityItem(worldObj, Targetx, Targety - 0.3D, Targetz, new ItemStack(blockTargetc,1,1));
|
||||||
|
worldObj.spawnEntityInWorld(dropedItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ModLoader.getMinecraftInstance().thePlayer.addChatMessage("N/A");//nothing found froms scan
|
||||||
|
scanCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//resets scan to zero location every 10 scans
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param startSpot - center of the scan radius
|
||||||
|
* @param block - block being looked for
|
||||||
|
* @param range - block count from center to scan
|
||||||
|
* @param resume - whether or not to resume scan from returned block
|
||||||
|
* @return location vector3 of the block equaling scan args
|
||||||
|
*/
|
||||||
|
public Vector3 findBlock(Vector3 startSpot,Block block,int range,boolean resume)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
int Startx = startSpot.intX();
|
||||||
|
int Starty = startSpot.intY();
|
||||||
|
int Startz = startSpot.intZ();
|
||||||
|
int distanceX = (range * 2) + 1;
|
||||||
|
int distanceZ = (range * 2) + 1;
|
||||||
|
int distanceY = (range * 2) + 1;
|
||||||
|
Boolean negX = Startx < 0;
|
||||||
|
Boolean negZ = Startz < 0;
|
||||||
|
int xChange = -1;
|
||||||
|
int zChange = -1;
|
||||||
|
int yChange = -1;
|
||||||
|
Startx += range;
|
||||||
|
Startz += range;
|
||||||
|
Starty += range;
|
||||||
|
int pauseCount = 0;
|
||||||
|
ModLoader.getMinecraftInstance().thePlayer.addChatMessage("starting Scan For " + block.getBlockName());
|
||||||
|
int y = Starty;
|
||||||
|
for(int iY=0;iY < (distanceY*2);iY++)
|
||||||
|
{
|
||||||
|
|
||||||
|
pauseCount++;
|
||||||
|
if(pauseCount >= 2)
|
||||||
|
{
|
||||||
|
int x = Startx;
|
||||||
|
int z = Startz;
|
||||||
|
|
||||||
|
for(int iX=0;iX < distanceY;iX++)
|
||||||
|
{
|
||||||
|
for(int iZ=0;iZ < distanceZ;iZ++)
|
||||||
|
{
|
||||||
|
|
||||||
|
int blockTargetID = worldObj.getBlockId(x, y, z);
|
||||||
|
System.out.println("BlockAt:"+x+"x:"+y+"y:"+z+"z:"+blockTargetID+"ID");
|
||||||
|
if(blockTargetID == block.blockID)
|
||||||
|
{
|
||||||
|
Vector3 targetBlock = new Vector3(x,y,z);
|
||||||
|
ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Target Block Found");
|
||||||
|
return targetBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
z += zChange;
|
||||||
|
}
|
||||||
|
x += xChange;
|
||||||
|
z = Startz;
|
||||||
|
}
|
||||||
|
pauseCount =0;
|
||||||
|
y += yChange;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
public EntityRobot[] getControlList()
|
||||||
|
{
|
||||||
|
return BotList;
|
||||||
|
|
||||||
|
}
|
||||||
|
public void addBot(EntityRobot bot)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
/**will be used to update the bot list on restart or reload of the world.
|
||||||
|
This way entity ids that are not bots are not stored in the list.
|
||||||
|
Generally the bots themselves will send the controller there ids when they load
|
||||||
|
into the world. The controller will then tell the bot its linked to the controller.
|
||||||
|
**/
|
||||||
|
public void cleanList()
|
||||||
|
{
|
||||||
|
for(int i = 0;i<4;i++)
|
||||||
|
{
|
||||||
|
if(BotList[i] instanceof EntityRobot)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
BotList[i] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public float electricityRequest() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean canReceiveFromSide(byte side) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public boolean canUpdate()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue