Code for automation

will seperate into its own repo later.
This commit is contained in:
Rseifert 2012-07-16 14:14:08 -04:00
parent 82106411b7
commit 4809099e8a
5 changed files with 335 additions and 0 deletions

View file

@ -0,0 +1,84 @@
package net.minecraft.src.eui.robotics;
import java.util.List;
import net.minecraft.src.*;
public class EntityShoeBot extends EntityRobot {
EntityItem targetItem = null;
public EntityShoeBot(World par1World) {
super(par1World);
this.moveSpeed = 0.23F;
// this.tasks.addTask(1, new EntityAIWander(this, this.moveSpeed));
this.texture = "/mobs/char.png";
}
public float getBlockPathWeight(int par1, int par2, int par3)
{
return 0.5F + this.worldObj.getLightBrightness(par1, par2, par3);
}
@Override
public void onEntityUpdate()
{
super.onEntityUpdate();
if(targetItem == null)
{
targetItem = findClosestItem(this.posX, this.posY, this.posZ,30);
}
else
{
if(!targetItem.isEntityAlive())
{
targetItem = null;
}
}
if(targetItem != null)
{
PathEntity PathToItem = this.worldObj.getPathEntityToEntity(this, targetItem, 30, true, false, false, true);
if(hasPath()){
this.setPathToEntity(PathToItem);
this.moveSpeed = 1.0F;
if(targetItem.getDistanceSq(this.posX,this.posY,this.posZ) < 1.5)
{
targetItem.setDead();
targetItem = null;
}
}
else
{
this.moveSpeed = 0.23F;
}
}
}
public EntityItem findClosestItem(double par1, double par3, double par5, double par7)
{
double var9 = -1.0D;
EntityItem var11 = null;
List itemList = worldObj.getEntitiesWithinAABB(EntityItem.class, this.boundingBox.expand(par7, 4.0D, par7));
for (int var12 = 0; var12 < itemList.size(); ++var12)
{
EntityItem var13 = (EntityItem)itemList.get(var12);
double var14 = var13.getDistanceSq(par1, par3, par5);
if ((par7 < 0.0D || var14 < par7 * par7) && (var9 == -1.0D || var14 < var9))
{
var9 = var14;
var11 = var13;
}
}
return var11;
}
@Override
public int getMaxHealth() {
// TODO Auto-generated method stub
return 5;
}
public String getRenderedName() {
// TODO Auto-generated method stub
return "BlockEater";
}
}

View file

@ -0,0 +1,58 @@
package net.minecraft.src.eui.robotics;
import java.util.ArrayList;
import net.minecraft.src.*;
public class ItemSpawn extends Item
{
public ItemSpawn (int id)
{
super(id);
maxStackSize = 1;
setMaxDamage(0);
setHasSubtypes(true);
}
public void addCreativeItems(ArrayList itemList)
{
itemList.add(new ItemStack(this, 1,1));
}
public String getItemNameIS(ItemStack itemstack) {
switch(itemstack.getItemDamage())
{
case 1: return "Bot";
}
return "Blank";
}
public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l)
{
if(!world.isRemote)
{
i += Facing.offsetsXForSide[l];
j += Facing.offsetsYForSide[l];
k += Facing.offsetsZForSide[l];
EntityShoeBot Guard = new EntityShoeBot(world);
Guard.setLocationAndAngles((double)i + 0.5D, (double)j + 1.0D, (double)k + 0.5D, 0.0F, 0.0F);
world.spawnEntityInWorld(Guard);
entityplayer.swingItem();
--itemstack.stackSize;
}
return true;
}
}

View file

@ -0,0 +1,45 @@
package net.minecraft.src.eui.robotics;
import net.minecraft.src.Entity;
import net.minecraft.src.ModelBase;
//Model code generated by MCModeller. All animation, AI,
//and special features are yours to program. Also keep in
//mind that some of these class names may have changed since
//wrote this. Make sure to check for compatibility with the
//latest version of the Minecraft Coder Pack before attempting
//to use this code.
import net.minecraft.src.ModelRenderer;
public class ModelModelShoeBot extends ModelBase
{
public ModelRenderer body;
public ModelRenderer Head;
public ModelModelShoeBot()
{
body = new ModelRenderer(this,0, 0);
body.addBox(-4.0F, -2.0F, -4.0F, 8, 4, 8, 0);
Head = new ModelRenderer(this,0, 0);
Head.addBox(-2.0F, -2.0F, -2.0F, 4, 4, 4, 0);
}
@Override
public void render(Entity par1Entity, float f, float f1, float f2, float f3, float f4, float f5)
{
this.setRotationAngles(f, f1, f2, f3, f4, f5);
body.render(f5);
Head.render(f5);
}
private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5)
{
super.setRotationAngles(f, f1, f2, f3, f4, f5);
}
}

View file

@ -0,0 +1,101 @@
package net.minecraft.src.eui.robotics;
import static net.minecraft.src.forge.IItemRenderer.ItemRenderType.EQUIPPED;
import static net.minecraft.src.forge.IItemRenderer.ItemRendererHelper.BLOCK_3D;
import net.minecraft.client.Minecraft;
import net.minecraft.src.Block;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityBlaze;
import net.minecraft.src.EntityLiving;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.EntityPlayerSP;
import net.minecraft.src.EnumAction;
import net.minecraft.src.FontRenderer;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.ModelBiped;
import net.minecraft.src.ModelBlaze;
import net.minecraft.src.ModelGhast;
import net.minecraft.src.RenderBlocks;
import net.minecraft.src.RenderLiving;
import net.minecraft.src.Tessellator;
import net.minecraft.src.forge.IItemRenderer;
import net.minecraft.src.forge.MinecraftForgeClient;
import org.lwjgl.opengl.GL11;
public class RenderShoeBot extends RenderLiving
{
public RenderShoeBot()
{
super(new ModelModelShoeBot(), 0.5F);
}
protected void renderName(EntityShoeBot par1EntityGuard, double par2, double par4, double par6)
{
if (Minecraft.isGuiEnabled())
{
float var8 = 1.6F;
float var9 = 0.016666668F * var8;
float var10 = par1EntityGuard.getDistanceToEntity(this.renderManager.livingPlayer);
float var11 = par1EntityGuard.isSneaking() ? 4.0F : 32.0F;
if (var10 < var11)
{
String var12 = par1EntityGuard.getRenderedName();
FontRenderer var13 = this.getFontRendererFromRenderManager();
GL11.glPushMatrix();
GL11.glTranslatef((float)par2 + 0.0F, (float)par4 + 2.3F, (float)par6);
GL11.glNormal3f(0.0F, 1.0F, 0.0F);
GL11.glRotatef(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
GL11.glScalef(-var9, -var9, var9);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glTranslatef(0.0F, 0.25F / var9, 0.0F);
GL11.glDepthMask(false);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Tessellator var14 = Tessellator.instance;
GL11.glDisable(GL11.GL_TEXTURE_2D);
var14.startDrawingQuads();
int var15 = var13.getStringWidth(var12) / 2;
var14.setColorRGBA_F(0.0F, 0.0F, 0.0F, 0.25F);
var14.addVertex((double)(-var15 - 1), -1.0D, 0.0D);
var14.addVertex((double)(-var15 - 1), 8.0D, 0.0D);
var14.addVertex((double)(var15 + 1), 8.0D, 0.0D);
var14.addVertex((double)(var15 + 1), -1.0D, 0.0D);
var14.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDepthMask(true);
var13.drawString(var12, -var13.getStringWidth(var12) / 2, 0, 553648127);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_BLEND);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glPopMatrix();
}
}
}
public void renderBot(EntityShoeBot par1Entity, double par2, double par4, double par6, float par8, float par9)
{
double var13 = par4 - (double)par1Entity.yOffset - 1.2;
super.doRenderLiving(par1Entity, par2, var13, par6, par8, par9);
}
@Override
public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
{
this.renderBot((EntityShoeBot)par1Entity, par2, par4, par6, par8, par9);
}
public void doRenderLiving(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par8, float par9)
{
this.renderBot((EntityShoeBot)par1EntityLiving, par2, par4, par6, par8, par9);
}
@Override
protected void passSpecialRender(EntityLiving par1EntityLiving, double par2, double par4, double par6)
{
this.renderName((EntityShoeBot)par1EntityLiving, par2, par4, par6);
}
}

View file

@ -0,0 +1,47 @@
package net.minecraft.src;
import net.minecraft.client.Minecraft;
import net.minecraft.src.basiccomponents.BasicComponents;
import net.minecraft.src.eui.*;
import net.minecraft.src.eui.robotics.ModelModelShoeBot;
import net.minecraft.src.eui.robotics.RenderShoeBot;
import net.minecraft.src.forge.*;
import net.minecraft.src.universalelectricity.*;
import java.util.ArrayList;
import java.util.Map;
import java.io.*;
public class mod_automation extends NetworkMod {
static Configuration config = new Configuration((new File(Minecraft.getMinecraftDir(), "config/EUIndustry/SteamPower.cfg")));
public static int spawnItemId = configurationProperties();
public static Item spawnItem = (new net.minecraft.src.eui.robotics.ItemSpawn(spawnItemId)).setItemName("Bot");
@Override
public String getVersion() {
// TODO change version on each update ;/
return "0.0.1";
}
public static int configurationProperties()
{
config.load();
spawnItemId = Integer.parseInt(config.getOrCreateIntProperty("BotItem", Configuration.CATEGORY_ITEM, 31356).value);
config.save();
return spawnItemId;
}
@Override
public void load() {
//register
UniversalElectricity.registerAddon(this, "0.4.5");
MinecraftForgeClient.preloadTexture("/eui/Blocks.png");
MinecraftForgeClient.preloadTexture("/eui/Items.png");
ModLoader.addName((new ItemStack(spawnItem, 1, 0)), "Bot");
//...........
ModLoader.registerEntityID(net.minecraft.src.eui.robotics.EntityShoeBot.class, "Bot", 101);
}
@Override
public void addRenderer(Map map)
{
map.put(net.minecraft.src.eui.robotics.EntityShoeBot.class, new RenderShoeBot());
}
}