Refactor of TileQuarry to fix the robot and laser in SMP.
This commit is contained in:
parent
100ba204d4
commit
03fcd8fabc
|
@ -28,8 +28,6 @@ import net.minecraft.src.buildcraft.core.CoreProxy;
|
|||
import net.minecraft.src.buildcraft.core.DefaultActionProvider;
|
||||
import net.minecraft.src.buildcraft.core.DefaultProps;
|
||||
import net.minecraft.src.buildcraft.core.DefaultTriggerProvider;
|
||||
import net.minecraft.src.buildcraft.core.EntityEnergyLaser;
|
||||
import net.minecraft.src.buildcraft.core.EntityRobot;
|
||||
import net.minecraft.src.buildcraft.core.ItemBuildCraft;
|
||||
import net.minecraft.src.buildcraft.core.ItemWrench;
|
||||
import net.minecraft.src.buildcraft.core.RedstonePowerFramework;
|
||||
|
@ -37,7 +35,6 @@ import net.minecraft.src.buildcraft.core.TriggerInventory;
|
|||
import net.minecraft.src.buildcraft.core.TriggerLiquidContainer;
|
||||
import net.minecraft.src.buildcraft.core.TriggerMachine;
|
||||
import net.minecraft.src.buildcraft.core.network.ConnectionHandler;
|
||||
import net.minecraft.src.buildcraft.core.network.EntityIds;
|
||||
import net.minecraft.src.buildcraft.core.network.PacketUpdate;
|
||||
import net.minecraft.src.buildcraft.transport.TriggerRedstoneInput;
|
||||
import net.minecraft.src.forge.Configuration;
|
||||
|
@ -127,11 +124,6 @@ public class BuildCraftCore {
|
|||
public static void load() {
|
||||
|
||||
MinecraftForge.registerConnectionHandler(new ConnectionHandler());
|
||||
|
||||
//MinecraftForge.registerEntity(EntityBlock.class, mod_BuildCraftCore.instance, EntityIds.BLOCK, 64, 10, true);
|
||||
MinecraftForge.registerEntity(EntityRobot.class, mod_BuildCraftCore.instance, EntityIds.ROBOT, 64, 1, true);
|
||||
//MinecraftForge.registerEntity(EntityLaser.class, mod_BuildCraftCore.instance, EntityIds.LASER, 64, 1, false);
|
||||
MinecraftForge.registerEntity(EntityEnergyLaser.class, mod_BuildCraftCore.instance, EntityIds.LASER, 64, 1, false);
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
|
|
|
@ -18,9 +18,8 @@ public abstract class PowerProvider {
|
|||
public int minEnergyReceived;
|
||||
public int maxEnergyReceived;
|
||||
public int maxEnergyStored;
|
||||
public int minActivationEnergy;
|
||||
public @TileNetworkData
|
||||
float energyStored = 0;
|
||||
public @TileNetworkData int minActivationEnergy;
|
||||
public @TileNetworkData float energyStored = 0;
|
||||
|
||||
protected int powerLoss = 1;
|
||||
protected int powerLossRegularity = 100;
|
||||
|
|
|
@ -133,8 +133,6 @@ public class EntityLaser extends Entity implements ISpawnHandler {
|
|||
@Override
|
||||
public void setPosition(double x, double y, double z) {
|
||||
|
||||
//System.out.println(new Position(x, y, z));
|
||||
|
||||
posX = x;
|
||||
posY = y;
|
||||
posZ = z;
|
||||
|
|
|
@ -1,307 +1,296 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011-2012
|
||||
* 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 net.minecraft.src.buildcraft.core;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.src.Entity;
|
||||
import net.minecraft.src.ModLoader;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraft.src.buildcraft.api.APIProxy;
|
||||
import net.minecraft.src.buildcraft.api.BptSlotInfo;
|
||||
import net.minecraft.src.buildcraft.api.BuildCraftAPI;
|
||||
import net.minecraft.src.buildcraft.api.Position;
|
||||
import net.minecraft.src.buildcraft.core.BptSlot.Mode;
|
||||
import net.minecraft.src.forge.ISpawnHandler;
|
||||
|
||||
public class EntityRobot extends Entity implements ISpawnHandler {
|
||||
|
||||
private Box box;
|
||||
private int destX, destY, destZ;
|
||||
|
||||
EntityEnergyLaser laser;
|
||||
|
||||
public LinkedList<Action> targets = new LinkedList<Action>();
|
||||
public static int MAX_TARGETS = 20;
|
||||
public int wait = 0;
|
||||
|
||||
private class Action {
|
||||
|
||||
public Action(BptSlot slot, BptContext context) {
|
||||
this.slot = slot;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Action(BptBuilderBase builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
BptSlot slot;
|
||||
BptBuilderBase builder;
|
||||
BptContext context;
|
||||
}
|
||||
|
||||
public EntityRobot(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
public EntityRobot(World world, Box box) {
|
||||
|
||||
super(world);
|
||||
|
||||
this.box = box;
|
||||
init();
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
|
||||
destX = (int) box.centerX();
|
||||
destY = (int) box.centerY();
|
||||
destZ = (int) box.centerZ();
|
||||
|
||||
motionX = 0;
|
||||
motionY = 0;
|
||||
motionZ = 0;
|
||||
|
||||
setPosition(destX, destY, destZ);
|
||||
|
||||
if (!APIProxy.isClient(worldObj)) {
|
||||
|
||||
laser = new EntityEnergyLaser(worldObj, new Position(posX, posY, posZ), new Position(posX, posY, posZ));
|
||||
worldObj.spawnEntityInWorld(laser);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSpawnData(DataOutputStream data) throws IOException {
|
||||
|
||||
data.writeInt(box.xMin);
|
||||
data.writeInt(box.yMin);
|
||||
data.writeInt(box.zMin);
|
||||
data.writeInt(box.xMax);
|
||||
data.writeInt(box.yMax);
|
||||
data.writeInt(box.zMax);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSpawnData(DataInputStream data) throws IOException {
|
||||
|
||||
box = new Box();
|
||||
box.xMin = data.readInt();
|
||||
box.yMin = data.readInt();
|
||||
box.zMin = data.readInt();
|
||||
box.xMax = data.readInt();
|
||||
box.yMax = data.readInt();
|
||||
box.zMax = data.readInt();
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() {}
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound nbttagcompound) {}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound nbttagcompound) {}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
|
||||
move();
|
||||
build();
|
||||
updateLaser();
|
||||
}
|
||||
|
||||
protected void move() {
|
||||
|
||||
//System.out.println("move: " + new Position(motionX, motionY, motionZ));
|
||||
setPosition(posX + motionX, posY + motionY, posZ + motionZ);
|
||||
|
||||
if (APIProxy.isClient(worldObj))
|
||||
return;
|
||||
|
||||
if (reachedDesination()) {
|
||||
|
||||
BlockIndex newDesination = getNewDesination();
|
||||
if (newDesination != null) {
|
||||
setDestination(newDesination.i, newDesination.j, newDesination.k);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected BlockIndex getNewDesination() {
|
||||
|
||||
Box movementBoundary = new Box();
|
||||
movementBoundary.initialize(box);
|
||||
movementBoundary.expand(1);
|
||||
|
||||
Box moveArea = new Box();
|
||||
moveArea.initialize(destX, destY, destZ, 1);
|
||||
|
||||
List<BlockIndex> potentialDestinations = new ArrayList<BlockIndex>();
|
||||
for (BlockIndex blockIndex : moveArea.getBlocksInArea()) {
|
||||
|
||||
if (BuildCraftAPI.softBlock(blockIndex.getBlockId(worldObj)) && movementBoundary.contains(blockIndex)) {
|
||||
potentialDestinations.add(blockIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (!potentialDestinations.isEmpty()) {
|
||||
|
||||
int i = worldObj.rand.nextInt(potentialDestinations.size());
|
||||
return potentialDestinations.get(i);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void setDestination(int x, int y, int z) {
|
||||
|
||||
destX = x;
|
||||
destY = y;
|
||||
destZ = z;
|
||||
|
||||
// TODO: apply power modifier
|
||||
motionX = new BigDecimal((float) (destX - posX) / 75 * 1).setScale(4, BigDecimal.ROUND_HALF_EVEN).doubleValue();
|
||||
motionY = new BigDecimal((float) (destY - posY) / 75 * 1).setScale(4, BigDecimal.ROUND_HALF_EVEN).doubleValue();
|
||||
motionZ = new BigDecimal((float) (destZ - posZ) / 75 * 1).setScale(4, BigDecimal.ROUND_HALF_EVEN).doubleValue();
|
||||
|
||||
//System.out.println("setDest: " + new Position(motionX, motionY, motionZ));
|
||||
}
|
||||
|
||||
protected boolean reachedDesination() {
|
||||
|
||||
if (getDistance(destX, destY, destZ) <= .2)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void build() {
|
||||
|
||||
updateWait();
|
||||
|
||||
// TODO: possible rewrite
|
||||
if (targets.size() > 0) {
|
||||
|
||||
Action a = targets.getFirst();
|
||||
if (a.slot != null) {
|
||||
|
||||
BptSlot target = a.slot;
|
||||
if (wait <= 0) {
|
||||
|
||||
if (target.mode == Mode.ClearIfInvalid) {
|
||||
|
||||
if (!target.isValid(a.context))
|
||||
worldObj.setBlockAndMetadataWithNotify(target.x, target.y, target.z, 0, 0);
|
||||
|
||||
} else if (target.stackToUse != null) {
|
||||
|
||||
worldObj.setBlockWithNotify(target.x, target.y, target.z, 0);
|
||||
target.stackToUse.getItem().onItemUse(target.stackToUse,
|
||||
BuildCraftAPI.getBuildCraftPlayer(worldObj), worldObj, target.x, target.y - 1,
|
||||
target.z, 1);
|
||||
} else {
|
||||
|
||||
try {
|
||||
target.buildBlock(a.context);
|
||||
} catch (Throwable t) {
|
||||
// Defensive code against errors in implementers
|
||||
t.printStackTrace();
|
||||
ModLoader.getLogger().throwing("EntityRobot", "update", t);
|
||||
}
|
||||
}
|
||||
|
||||
targets.pop();
|
||||
}
|
||||
|
||||
} else if (a.builder != null) {
|
||||
a.builder.postProcessing(worldObj);
|
||||
targets.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateWait() {
|
||||
|
||||
if (targets.size() > 0)
|
||||
if (wait == 0)
|
||||
wait = MAX_TARGETS - targets.size() + 2;
|
||||
else
|
||||
wait--;
|
||||
}
|
||||
|
||||
private void updateLaser() {
|
||||
|
||||
if (APIProxy.isClient(worldObj))
|
||||
return;
|
||||
|
||||
if (targets.size() > 0) {
|
||||
|
||||
Action a = targets.getFirst();
|
||||
BptSlotInfo target = a.slot;
|
||||
|
||||
laser.setPositions(new Position(posX, posY, posZ), new Position(target.x + 0.5, target.y + 0.5, target.z + 0.5));
|
||||
laser.show();
|
||||
}
|
||||
else {
|
||||
laser.hide();
|
||||
}
|
||||
|
||||
laser.pushPower(((float) targets.size()) / ((float) MAX_TARGETS) * 4F);
|
||||
}
|
||||
|
||||
public void scheduleContruction(BptSlot slot, BptContext context) {
|
||||
|
||||
if (slot != null) {
|
||||
targets.add(new Action(slot, context));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void markEndOfBlueprint(BptBuilderBase builder) {
|
||||
targets.add(new Action(builder));
|
||||
}
|
||||
|
||||
public boolean readyToBuild() {
|
||||
return targets.size() < MAX_TARGETS;
|
||||
}
|
||||
|
||||
public boolean done() {
|
||||
return targets.isEmpty();
|
||||
}
|
||||
|
||||
public void setBox(Box box) {
|
||||
|
||||
this.box = box;
|
||||
setDestination((int) box.centerX(), (int) box.centerY(), (int) box.centerZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDead() {
|
||||
|
||||
if (laser != null)
|
||||
laser.setDead();
|
||||
|
||||
super.setDead();
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Copyright (c) SpaceToad, 2011-2012
|
||||
* 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 net.minecraft.src.buildcraft.core;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.src.Entity;
|
||||
import net.minecraft.src.ModLoader;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraft.src.buildcraft.api.APIProxy;
|
||||
import net.minecraft.src.buildcraft.api.BptSlotInfo;
|
||||
import net.minecraft.src.buildcraft.api.BuildCraftAPI;
|
||||
import net.minecraft.src.buildcraft.api.Position;
|
||||
import net.minecraft.src.buildcraft.core.BptSlot.Mode;
|
||||
import net.minecraft.src.forge.ISpawnHandler;
|
||||
|
||||
public class EntityRobot extends Entity implements ISpawnHandler {
|
||||
|
||||
private Box box;
|
||||
private int destX, destY, destZ;
|
||||
|
||||
EntityEnergyLaser laser;
|
||||
|
||||
public LinkedList<Action> targets = new LinkedList<Action>();
|
||||
public static int MAX_TARGETS = 20;
|
||||
public int wait = 0;
|
||||
|
||||
private class Action {
|
||||
|
||||
public Action(BptSlot slot, BptContext context) {
|
||||
this.slot = slot;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Action(BptBuilderBase builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
BptSlot slot;
|
||||
BptBuilderBase builder;
|
||||
BptContext context;
|
||||
}
|
||||
|
||||
public EntityRobot(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
public EntityRobot(World world, Box box) {
|
||||
|
||||
super(world);
|
||||
|
||||
this.box = box;
|
||||
init();
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
|
||||
destX = (int) box.centerX();
|
||||
destY = (int) box.centerY();
|
||||
destZ = (int) box.centerZ();
|
||||
|
||||
motionX = 0;
|
||||
motionY = 0;
|
||||
motionZ = 0;
|
||||
|
||||
setPosition(destX, destY, destZ);
|
||||
|
||||
laser = new EntityEnergyLaser(worldObj, new Position(posX, posY, posZ), new Position(posX, posY, posZ));
|
||||
worldObj.spawnEntityInWorld(laser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSpawnData(DataOutputStream data) throws IOException {
|
||||
|
||||
data.writeInt(box.xMin);
|
||||
data.writeInt(box.yMin);
|
||||
data.writeInt(box.zMin);
|
||||
data.writeInt(box.xMax);
|
||||
data.writeInt(box.yMax);
|
||||
data.writeInt(box.zMax);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSpawnData(DataInputStream data) throws IOException {
|
||||
|
||||
box = new Box();
|
||||
box.xMin = data.readInt();
|
||||
box.yMin = data.readInt();
|
||||
box.zMin = data.readInt();
|
||||
box.xMax = data.readInt();
|
||||
box.yMax = data.readInt();
|
||||
box.zMax = data.readInt();
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() {}
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound nbttagcompound) {}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound nbttagcompound) {}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
|
||||
move();
|
||||
build();
|
||||
updateLaser();
|
||||
}
|
||||
|
||||
protected void move() {
|
||||
|
||||
//System.out.println("move: " + new Position(motionX, motionY, motionZ));
|
||||
setPosition(posX + motionX, posY + motionY, posZ + motionZ);
|
||||
|
||||
if (reachedDesination()) {
|
||||
|
||||
BlockIndex newDesination = getNewDesination();
|
||||
if (newDesination != null) {
|
||||
setDestination(newDesination.i, newDesination.j, newDesination.k);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected BlockIndex getNewDesination() {
|
||||
|
||||
Box movementBoundary = new Box();
|
||||
movementBoundary.initialize(box);
|
||||
movementBoundary.expand(1);
|
||||
|
||||
Box moveArea = new Box();
|
||||
moveArea.initialize(destX, destY, destZ, 1);
|
||||
|
||||
List<BlockIndex> potentialDestinations = new ArrayList<BlockIndex>();
|
||||
for (BlockIndex blockIndex : moveArea.getBlocksInArea()) {
|
||||
|
||||
if (BuildCraftAPI.softBlock(blockIndex.getBlockId(worldObj)) && movementBoundary.contains(blockIndex)) {
|
||||
potentialDestinations.add(blockIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (!potentialDestinations.isEmpty()) {
|
||||
|
||||
int i = worldObj.rand.nextInt(potentialDestinations.size());
|
||||
return potentialDestinations.get(i);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void setDestination(int x, int y, int z) {
|
||||
|
||||
destX = x;
|
||||
destY = y;
|
||||
destZ = z;
|
||||
|
||||
motionX = (destX - posX) / 75 * laser.getPowerAverage() / 2;
|
||||
motionY = (destY - posY) / 75 * laser.getPowerAverage() / 2;
|
||||
motionZ = (destZ - posZ) / 75 * laser.getPowerAverage() / 2;
|
||||
}
|
||||
|
||||
protected boolean reachedDesination() {
|
||||
|
||||
if (getDistance(destX, destY, destZ) <= .2)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void build() {
|
||||
|
||||
updateWait();
|
||||
|
||||
if (targets.size() > 0) {
|
||||
|
||||
Action a = targets.getFirst();
|
||||
if (a.slot != null) {
|
||||
|
||||
BptSlot target = a.slot;
|
||||
if (wait <= 0) {
|
||||
|
||||
if (!APIProxy.isClient(worldObj)) {
|
||||
|
||||
if (target.mode == Mode.ClearIfInvalid) {
|
||||
|
||||
if (!target.isValid(a.context))
|
||||
worldObj.setBlockAndMetadataWithNotify(target.x, target.y, target.z, 0, 0);
|
||||
|
||||
} else if (target.stackToUse != null) {
|
||||
|
||||
worldObj.setBlockWithNotify(target.x, target.y, target.z, 0);
|
||||
target.stackToUse.getItem().onItemUse(target.stackToUse,
|
||||
BuildCraftAPI.getBuildCraftPlayer(worldObj), worldObj, target.x, target.y - 1,
|
||||
target.z, 1);
|
||||
} else {
|
||||
|
||||
try {
|
||||
target.buildBlock(a.context);
|
||||
} catch (Throwable t) {
|
||||
// Defensive code against errors in implementers
|
||||
t.printStackTrace();
|
||||
ModLoader.getLogger().throwing("EntityRobot", "update", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
targets.pop();
|
||||
}
|
||||
|
||||
} else if (a.builder != null) {
|
||||
a.builder.postProcessing(worldObj);
|
||||
targets.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateWait() {
|
||||
|
||||
if (targets.size() > 0)
|
||||
if (wait == 0)
|
||||
wait = MAX_TARGETS - targets.size() + 2;
|
||||
else
|
||||
wait--;
|
||||
}
|
||||
|
||||
private void updateLaser() {
|
||||
|
||||
if (targets.size() > 0) {
|
||||
|
||||
Action a = targets.getFirst();
|
||||
BptSlotInfo target = a.slot;
|
||||
|
||||
laser.setPositions(new Position(posX, posY, posZ), new Position(target.x + 0.5, target.y + 0.5, target.z + 0.5));
|
||||
laser.show();
|
||||
}
|
||||
else {
|
||||
laser.hide();
|
||||
}
|
||||
|
||||
laser.pushPower(((float) targets.size()) / ((float) MAX_TARGETS) * 4F);
|
||||
}
|
||||
|
||||
public void scheduleContruction(BptSlot slot, BptContext context) {
|
||||
|
||||
if (slot != null) {
|
||||
targets.add(new Action(slot, context));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void markEndOfBlueprint(BptBuilderBase builder) {
|
||||
targets.add(new Action(builder));
|
||||
}
|
||||
|
||||
public boolean readyToBuild() {
|
||||
return targets.size() < MAX_TARGETS;
|
||||
}
|
||||
|
||||
public boolean done() {
|
||||
return targets.isEmpty();
|
||||
}
|
||||
|
||||
public void setBox(Box box) {
|
||||
|
||||
this.box = box;
|
||||
setDestination((int) box.centerX(), (int) box.centerY(), (int) box.centerZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDead() {
|
||||
|
||||
if (laser != null)
|
||||
laser.setDead();
|
||||
|
||||
super.setDead();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,287 +1,288 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 net.minecraft.src.buildcraft.factory;
|
||||
|
||||
import net.minecraft.src.BuildCraftFactory;
|
||||
import net.minecraft.src.Entity;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraft.src.buildcraft.core.EntityBlock;
|
||||
|
||||
public class EntityMechanicalArm extends Entity {
|
||||
|
||||
double sizeX, sizeZ;
|
||||
EntityBlock xArm, yArm, zArm, head;
|
||||
|
||||
double angle;
|
||||
|
||||
public double targetX, targetY, targetZ;
|
||||
public double headPosX, headPosY, headPosZ;
|
||||
public double speed = 0.03;
|
||||
|
||||
double baseY;
|
||||
|
||||
public IArmListener listener;
|
||||
boolean inProgressionXZ = false;
|
||||
boolean inProgressionY = false;
|
||||
|
||||
protected TileEntity parent;
|
||||
|
||||
public EntityMechanicalArm(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
public EntityMechanicalArm(World world, double i, double j, double k, double width, double height, TileEntity parent) {
|
||||
super(world);
|
||||
|
||||
setPosition(i, j, k);
|
||||
|
||||
motionX = 0.0D;
|
||||
motionY = 0.0D;
|
||||
motionZ = 0.0D;
|
||||
prevPosX = i;
|
||||
prevPosY = j;
|
||||
prevPosZ = k;
|
||||
sizeX = height;
|
||||
sizeZ = width;
|
||||
noClip = true;
|
||||
baseY = j;
|
||||
|
||||
headPosX = i;
|
||||
headPosY = j - 2;
|
||||
headPosZ = k;
|
||||
|
||||
setTarget(headPosX, headPosY, headPosZ);
|
||||
inProgressionXZ = false;
|
||||
inProgressionY = false;
|
||||
|
||||
xArm = new EntityBlock(world, i, j, k, width, 0.5, 0.5);
|
||||
xArm.texture = BuildCraftFactory.drillTexture;
|
||||
world.spawnEntityInWorld(xArm);
|
||||
|
||||
yArm = new EntityBlock(world, i, j, k, 0.5, 1, 0.5);
|
||||
yArm.texture = BuildCraftFactory.drillTexture;
|
||||
world.spawnEntityInWorld(yArm);
|
||||
|
||||
zArm = new EntityBlock(world, i, j, k, 0.5, 0.5, height);
|
||||
zArm.texture = BuildCraftFactory.drillTexture;
|
||||
world.spawnEntityInWorld(zArm);
|
||||
|
||||
head = new EntityBlock(world, i, j, k, 0.2, 1, 0.2);
|
||||
head.texture = 2 * 16 + 10;
|
||||
world.spawnEntityInWorld(head);
|
||||
head.shadowSize = 1.0F;
|
||||
|
||||
updatePosition();
|
||||
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() {}
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound nbttagcompound) {
|
||||
sizeX = nbttagcompound.getDouble("sizeX");
|
||||
sizeZ = nbttagcompound.getDouble("sizeZ");
|
||||
|
||||
targetX = nbttagcompound.getDouble("targetX");
|
||||
targetY = nbttagcompound.getDouble("targetY");
|
||||
targetZ = nbttagcompound.getDouble("targetZ");
|
||||
angle = nbttagcompound.getDouble("angle");
|
||||
|
||||
headPosX = nbttagcompound.getDouble("headPosX");
|
||||
headPosY = nbttagcompound.getDouble("headPosY");
|
||||
headPosZ = nbttagcompound.getDouble("headPosZ");
|
||||
|
||||
baseY = nbttagcompound.getDouble("baseY");
|
||||
speed = nbttagcompound.getDouble("speed");
|
||||
|
||||
inProgressionXZ = nbttagcompound.getBoolean("progressionXY");
|
||||
inProgressionY = nbttagcompound.getBoolean("progressionY");
|
||||
|
||||
NBTTagCompound xArmStore, yArmStore, zArmStore, headStore;
|
||||
|
||||
xArmStore = nbttagcompound.getCompoundTag("xArm");
|
||||
yArmStore = nbttagcompound.getCompoundTag("yArm");
|
||||
zArmStore = nbttagcompound.getCompoundTag("zArm");
|
||||
headStore = nbttagcompound.getCompoundTag("head");
|
||||
|
||||
xArm = new EntityBlock(worldObj);
|
||||
yArm = new EntityBlock(worldObj);
|
||||
zArm = new EntityBlock(worldObj);
|
||||
head = new EntityBlock(worldObj);
|
||||
|
||||
xArm.texture = BuildCraftFactory.drillTexture;
|
||||
yArm.texture = BuildCraftFactory.drillTexture;
|
||||
zArm.texture = BuildCraftFactory.drillTexture;
|
||||
head.texture = 2 * 16 + 10;
|
||||
|
||||
xArm.readFromNBT(xArmStore);
|
||||
yArm.readFromNBT(yArmStore);
|
||||
zArm.readFromNBT(zArmStore);
|
||||
head.readFromNBT(headStore);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound.setDouble("sizeX", sizeX);
|
||||
nbttagcompound.setDouble("sizeZ", sizeZ);
|
||||
|
||||
nbttagcompound.setDouble("targetX", targetX);
|
||||
nbttagcompound.setDouble("targetY", targetY);
|
||||
nbttagcompound.setDouble("targetZ", targetZ);
|
||||
nbttagcompound.setDouble("angle", angle);
|
||||
|
||||
nbttagcompound.setDouble("headPosX", headPosX);
|
||||
nbttagcompound.setDouble("headPosY", headPosY);
|
||||
nbttagcompound.setDouble("headPosZ", headPosZ);
|
||||
|
||||
nbttagcompound.setDouble("baseY", baseY);
|
||||
nbttagcompound.setDouble("speed", speed);
|
||||
|
||||
nbttagcompound.setBoolean("progressionXY", inProgressionXZ);
|
||||
nbttagcompound.setBoolean("progressionY", inProgressionY);
|
||||
|
||||
NBTTagCompound xArmStore, yArmStore, zArmStore, headStore;
|
||||
|
||||
xArmStore = new NBTTagCompound();
|
||||
yArmStore = new NBTTagCompound();
|
||||
zArmStore = new NBTTagCompound();
|
||||
headStore = new NBTTagCompound();
|
||||
|
||||
nbttagcompound.setTag("xArm", xArmStore);
|
||||
nbttagcompound.setTag("yArm", yArmStore);
|
||||
nbttagcompound.setTag("zArm", zArmStore);
|
||||
nbttagcompound.setTag("head", headStore);
|
||||
|
||||
xArm.writeToNBT(xArmStore);
|
||||
yArm.writeToNBT(yArmStore);
|
||||
zArm.writeToNBT(zArmStore);
|
||||
head.writeToNBT(headStore);
|
||||
}
|
||||
|
||||
public void setTarget(double x, double y, double z) {
|
||||
targetX = x;
|
||||
targetY = y;
|
||||
targetZ = z;
|
||||
|
||||
double dX = targetX - headPosX;
|
||||
double dZ = targetZ - headPosZ;
|
||||
|
||||
angle = Math.atan2(dZ, dX);
|
||||
|
||||
inProgressionXZ = true;
|
||||
inProgressionY = true;
|
||||
}
|
||||
|
||||
public double[] getTarget() {
|
||||
return new double[] { targetX, targetY, targetZ };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
|
||||
if (parent != null && worldObj.getBlockTileEntity(parent.xCoord, parent.yCoord, parent.zCoord) != parent) {
|
||||
setDead();
|
||||
return;
|
||||
}
|
||||
|
||||
if (speed > 0) {
|
||||
doMove(speed);
|
||||
}
|
||||
}
|
||||
|
||||
public void doMove(double instantSpeed) {
|
||||
super.onUpdate();
|
||||
|
||||
if (inProgressionXZ) {
|
||||
if (Math.abs(targetX - headPosX) < instantSpeed * 2 && Math.abs(targetZ - headPosZ) < instantSpeed * 2) {
|
||||
headPosX = targetX;
|
||||
headPosZ = targetZ;
|
||||
|
||||
inProgressionXZ = false;
|
||||
|
||||
if (listener != null && !inProgressionY) {
|
||||
listener.positionReached(this);
|
||||
}
|
||||
} else {
|
||||
headPosX += Math.cos(angle) * instantSpeed;
|
||||
headPosZ += Math.sin(angle) * instantSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
if (inProgressionY) {
|
||||
if (Math.abs(targetY - headPosY) < instantSpeed * 2) {
|
||||
headPosY = targetY;
|
||||
|
||||
inProgressionY = false;
|
||||
|
||||
if (listener != null && !inProgressionXZ) {
|
||||
listener.positionReached(this);
|
||||
}
|
||||
} else {
|
||||
if (targetY > headPosY) {
|
||||
headPosY += instantSpeed / 2;
|
||||
} else {
|
||||
headPosY -= instantSpeed / 2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
public void updatePosition() {
|
||||
xArm.setPosition(xArm.posX, xArm.posY, headPosZ + 0.25);
|
||||
yArm.jSize = baseY - headPosY - 1;
|
||||
yArm.setPosition(headPosX + 0.25, headPosY + 1, headPosZ + 0.25);
|
||||
zArm.setPosition(headPosX + 0.25, zArm.posY, zArm.posZ);
|
||||
|
||||
head.setPosition(headPosX + 0.4, headPosY, headPosZ + 0.4);
|
||||
}
|
||||
|
||||
public void joinToWorld(World w) {
|
||||
super.worldObj = w;
|
||||
|
||||
xArm.worldObj = w;
|
||||
yArm.worldObj = w;
|
||||
zArm.worldObj = w;
|
||||
head.worldObj = w;
|
||||
|
||||
w.spawnEntityInWorld(this);
|
||||
w.spawnEntityInWorld(xArm);
|
||||
w.spawnEntityInWorld(yArm);
|
||||
w.spawnEntityInWorld(zArm);
|
||||
w.spawnEntityInWorld(head);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDead() {
|
||||
xArm.setDead();
|
||||
yArm.setDead();
|
||||
zArm.setDead();
|
||||
head.setDead();
|
||||
super.setDead();
|
||||
|
||||
}
|
||||
|
||||
public double[] getHeadPosition() {
|
||||
return new double[] { headPosX, headPosY, headPosZ };
|
||||
}
|
||||
|
||||
public void setHeadPosition(double x, double y, double z) {
|
||||
headPosX = x;
|
||||
headPosY = y;
|
||||
headPosZ = z;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 net.minecraft.src.buildcraft.factory;
|
||||
|
||||
import net.minecraft.src.BuildCraftFactory;
|
||||
import net.minecraft.src.Entity;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraft.src.buildcraft.core.EntityBlock;
|
||||
|
||||
public class EntityMechanicalArm extends Entity {
|
||||
|
||||
double sizeX, sizeZ;
|
||||
EntityBlock xArm, yArm, zArm, head;
|
||||
|
||||
double angle;
|
||||
|
||||
public double targetX, targetY, targetZ;
|
||||
public double headPosX, headPosY, headPosZ;
|
||||
public double speed = 0.03;
|
||||
|
||||
double baseY;
|
||||
|
||||
public IArmListener listener;
|
||||
boolean inProgressionXZ = false;
|
||||
boolean inProgressionY = false;
|
||||
|
||||
protected TileEntity parent;
|
||||
|
||||
public EntityMechanicalArm(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
public EntityMechanicalArm(World world, double i, double j, double k, double width, double height, TileEntity parent) {
|
||||
super(world);
|
||||
|
||||
setPosition(i, j, k);
|
||||
|
||||
motionX = 0.0D;
|
||||
motionY = 0.0D;
|
||||
motionZ = 0.0D;
|
||||
prevPosX = i;
|
||||
prevPosY = j;
|
||||
prevPosZ = k;
|
||||
sizeX = height;
|
||||
sizeZ = width;
|
||||
noClip = true;
|
||||
baseY = j;
|
||||
|
||||
headPosX = i;
|
||||
headPosY = j - 2;
|
||||
headPosZ = k;
|
||||
|
||||
setTarget(headPosX, headPosY, headPosZ);
|
||||
inProgressionXZ = false;
|
||||
inProgressionY = false;
|
||||
|
||||
xArm = new EntityBlock(world, i, j, k, width, 0.5, 0.5);
|
||||
xArm.texture = BuildCraftFactory.drillTexture;
|
||||
world.spawnEntityInWorld(xArm);
|
||||
|
||||
yArm = new EntityBlock(world, i, j, k, 0.5, 1, 0.5);
|
||||
yArm.texture = BuildCraftFactory.drillTexture;
|
||||
world.spawnEntityInWorld(yArm);
|
||||
|
||||
zArm = new EntityBlock(world, i, j, k, 0.5, 0.5, height);
|
||||
zArm.texture = BuildCraftFactory.drillTexture;
|
||||
world.spawnEntityInWorld(zArm);
|
||||
|
||||
head = new EntityBlock(world, i, j, k, 0.2, 1, 0.2);
|
||||
head.texture = 2 * 16 + 10;
|
||||
world.spawnEntityInWorld(head);
|
||||
head.shadowSize = 1.0F;
|
||||
|
||||
updatePosition();
|
||||
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() {}
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound nbttagcompound) {
|
||||
sizeX = nbttagcompound.getDouble("sizeX");
|
||||
sizeZ = nbttagcompound.getDouble("sizeZ");
|
||||
|
||||
targetX = nbttagcompound.getDouble("targetX");
|
||||
targetY = nbttagcompound.getDouble("targetY");
|
||||
targetZ = nbttagcompound.getDouble("targetZ");
|
||||
angle = nbttagcompound.getDouble("angle");
|
||||
|
||||
headPosX = nbttagcompound.getDouble("headPosX");
|
||||
headPosY = nbttagcompound.getDouble("headPosY");
|
||||
headPosZ = nbttagcompound.getDouble("headPosZ");
|
||||
|
||||
baseY = nbttagcompound.getDouble("baseY");
|
||||
speed = nbttagcompound.getDouble("speed");
|
||||
|
||||
inProgressionXZ = nbttagcompound.getBoolean("progressionXY");
|
||||
inProgressionY = nbttagcompound.getBoolean("progressionY");
|
||||
|
||||
NBTTagCompound xArmStore, yArmStore, zArmStore, headStore;
|
||||
|
||||
xArmStore = nbttagcompound.getCompoundTag("xArm");
|
||||
yArmStore = nbttagcompound.getCompoundTag("yArm");
|
||||
zArmStore = nbttagcompound.getCompoundTag("zArm");
|
||||
headStore = nbttagcompound.getCompoundTag("head");
|
||||
|
||||
xArm = new EntityBlock(worldObj);
|
||||
yArm = new EntityBlock(worldObj);
|
||||
zArm = new EntityBlock(worldObj);
|
||||
head = new EntityBlock(worldObj);
|
||||
|
||||
xArm.texture = BuildCraftFactory.drillTexture;
|
||||
yArm.texture = BuildCraftFactory.drillTexture;
|
||||
zArm.texture = BuildCraftFactory.drillTexture;
|
||||
head.texture = 2 * 16 + 10;
|
||||
|
||||
xArm.readFromNBT(xArmStore);
|
||||
yArm.readFromNBT(yArmStore);
|
||||
zArm.readFromNBT(zArmStore);
|
||||
head.readFromNBT(headStore);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound.setDouble("sizeX", sizeX);
|
||||
nbttagcompound.setDouble("sizeZ", sizeZ);
|
||||
|
||||
nbttagcompound.setDouble("targetX", targetX);
|
||||
nbttagcompound.setDouble("targetY", targetY);
|
||||
nbttagcompound.setDouble("targetZ", targetZ);
|
||||
nbttagcompound.setDouble("angle", angle);
|
||||
|
||||
nbttagcompound.setDouble("headPosX", headPosX);
|
||||
nbttagcompound.setDouble("headPosY", headPosY);
|
||||
nbttagcompound.setDouble("headPosZ", headPosZ);
|
||||
|
||||
nbttagcompound.setDouble("baseY", baseY);
|
||||
nbttagcompound.setDouble("speed", speed);
|
||||
|
||||
nbttagcompound.setBoolean("progressionXY", inProgressionXZ);
|
||||
nbttagcompound.setBoolean("progressionY", inProgressionY);
|
||||
|
||||
NBTTagCompound xArmStore, yArmStore, zArmStore, headStore;
|
||||
|
||||
xArmStore = new NBTTagCompound();
|
||||
yArmStore = new NBTTagCompound();
|
||||
zArmStore = new NBTTagCompound();
|
||||
headStore = new NBTTagCompound();
|
||||
|
||||
nbttagcompound.setTag("xArm", xArmStore);
|
||||
nbttagcompound.setTag("yArm", yArmStore);
|
||||
nbttagcompound.setTag("zArm", zArmStore);
|
||||
nbttagcompound.setTag("head", headStore);
|
||||
|
||||
xArm.writeToNBT(xArmStore);
|
||||
yArm.writeToNBT(yArmStore);
|
||||
zArm.writeToNBT(zArmStore);
|
||||
head.writeToNBT(headStore);
|
||||
}
|
||||
|
||||
public void setTarget(double x, double y, double z) {
|
||||
|
||||
targetX = x;
|
||||
targetY = y;
|
||||
targetZ = z;
|
||||
|
||||
double dX = targetX - headPosX;
|
||||
double dZ = targetZ - headPosZ;
|
||||
|
||||
angle = Math.atan2(dZ, dX);
|
||||
|
||||
inProgressionXZ = true;
|
||||
inProgressionY = true;
|
||||
}
|
||||
|
||||
public double[] getTarget() {
|
||||
return new double[] { targetX, targetY, targetZ };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
|
||||
if (parent != null && worldObj.getBlockTileEntity(parent.xCoord, parent.yCoord, parent.zCoord) != parent) {
|
||||
setDead();
|
||||
return;
|
||||
}
|
||||
|
||||
if (speed > 0) {
|
||||
doMove(speed);
|
||||
}
|
||||
}
|
||||
|
||||
public void doMove(double instantSpeed) {
|
||||
super.onUpdate();
|
||||
|
||||
if (inProgressionXZ) {
|
||||
if (Math.abs(targetX - headPosX) < instantSpeed * 2 && Math.abs(targetZ - headPosZ) < instantSpeed * 2) {
|
||||
headPosX = targetX;
|
||||
headPosZ = targetZ;
|
||||
|
||||
inProgressionXZ = false;
|
||||
|
||||
if (listener != null && !inProgressionY) {
|
||||
listener.positionReached(this);
|
||||
}
|
||||
} else {
|
||||
headPosX += Math.cos(angle) * instantSpeed;
|
||||
headPosZ += Math.sin(angle) * instantSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
if (inProgressionY) {
|
||||
if (Math.abs(targetY - headPosY) < instantSpeed * 2) {
|
||||
headPosY = targetY;
|
||||
|
||||
inProgressionY = false;
|
||||
|
||||
if (listener != null && !inProgressionXZ) {
|
||||
listener.positionReached(this);
|
||||
}
|
||||
} else {
|
||||
if (targetY > headPosY) {
|
||||
headPosY += instantSpeed / 2;
|
||||
} else {
|
||||
headPosY -= instantSpeed / 2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
public void updatePosition() {
|
||||
xArm.setPosition(xArm.posX, xArm.posY, headPosZ + 0.25);
|
||||
yArm.jSize = baseY - headPosY - 1;
|
||||
yArm.setPosition(headPosX + 0.25, headPosY + 1, headPosZ + 0.25);
|
||||
zArm.setPosition(headPosX + 0.25, zArm.posY, zArm.posZ);
|
||||
|
||||
head.setPosition(headPosX + 0.4, headPosY, headPosZ + 0.4);
|
||||
}
|
||||
|
||||
public void joinToWorld(World w) {
|
||||
super.worldObj = w;
|
||||
|
||||
xArm.worldObj = w;
|
||||
yArm.worldObj = w;
|
||||
zArm.worldObj = w;
|
||||
head.worldObj = w;
|
||||
|
||||
w.spawnEntityInWorld(this);
|
||||
w.spawnEntityInWorld(xArm);
|
||||
w.spawnEntityInWorld(yArm);
|
||||
w.spawnEntityInWorld(zArm);
|
||||
w.spawnEntityInWorld(head);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDead() {
|
||||
xArm.setDead();
|
||||
yArm.setDead();
|
||||
zArm.setDead();
|
||||
head.setDead();
|
||||
super.setDead();
|
||||
|
||||
}
|
||||
|
||||
public double[] getHeadPosition() {
|
||||
return new double[] { headPosX, headPosY, headPosZ };
|
||||
}
|
||||
|
||||
public void setHeadPosition(double x, double y, double z) {
|
||||
headPosX = x;
|
||||
headPosY = y;
|
||||
headPosZ = z;
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue