Refactor of TileQuarry to fix the robot and laser in SMP.
This commit is contained in:
parent
100ba204d4
commit
03fcd8fabc
6 changed files with 1276 additions and 1276 deletions
|
@ -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;
|
||||
|
|
|
@ -12,7 +12,6 @@ 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;
|
||||
|
@ -79,11 +78,8 @@ public class EntityRobot extends Entity implements ISpawnHandler {
|
|||
|
||||
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);
|
||||
}
|
||||
laser = new EntityEnergyLaser(worldObj, new Position(posX, posY, posZ), new Position(posX, posY, posZ));
|
||||
worldObj.spawnEntityInWorld(laser);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -133,9 +129,6 @@ public class EntityRobot extends Entity implements ISpawnHandler {
|
|||
//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();
|
||||
|
@ -179,12 +172,9 @@ public class EntityRobot extends Entity implements ISpawnHandler {
|
|||
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));
|
||||
motionX = (destX - posX) / 75 * laser.getPowerAverage() / 2;
|
||||
motionY = (destY - posY) / 75 * laser.getPowerAverage() / 2;
|
||||
motionZ = (destZ - posZ) / 75 * laser.getPowerAverage() / 2;
|
||||
}
|
||||
|
||||
protected boolean reachedDesination() {
|
||||
|
@ -199,7 +189,6 @@ public class EntityRobot extends Entity implements ISpawnHandler {
|
|||
|
||||
updateWait();
|
||||
|
||||
// TODO: possible rewrite
|
||||
if (targets.size() > 0) {
|
||||
|
||||
Action a = targets.getFirst();
|
||||
|
@ -208,25 +197,28 @@ public class EntityRobot extends Entity implements ISpawnHandler {
|
|||
BptSlot target = a.slot;
|
||||
if (wait <= 0) {
|
||||
|
||||
if (target.mode == Mode.ClearIfInvalid) {
|
||||
if (!APIProxy.isClient(worldObj)) {
|
||||
|
||||
if (!target.isValid(a.context))
|
||||
worldObj.setBlockAndMetadataWithNotify(target.x, target.y, target.z, 0, 0);
|
||||
if (target.mode == Mode.ClearIfInvalid) {
|
||||
|
||||
} else if (target.stackToUse != null) {
|
||||
if (!target.isValid(a.context))
|
||||
worldObj.setBlockAndMetadataWithNotify(target.x, target.y, target.z, 0, 0);
|
||||
|
||||
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 {
|
||||
} else if (target.stackToUse != null) {
|
||||
|
||||
try {
|
||||
target.buildBlock(a.context);
|
||||
} catch (Throwable t) {
|
||||
// Defensive code against errors in implementers
|
||||
t.printStackTrace();
|
||||
ModLoader.getLogger().throwing("EntityRobot", "update", t);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -251,9 +243,6 @@ public class EntityRobot extends Entity implements ISpawnHandler {
|
|||
|
||||
private void updateLaser() {
|
||||
|
||||
if (APIProxy.isClient(worldObj))
|
||||
return;
|
||||
|
||||
if (targets.size() > 0) {
|
||||
|
||||
Action a = targets.getFirst();
|
||||
|
|
|
@ -170,6 +170,7 @@ public class EntityMechanicalArm extends Entity {
|
|||
}
|
||||
|
||||
public void setTarget(double x, double y, double z) {
|
||||
|
||||
targetX = x;
|
||||
targetY = y;
|
||||
targetZ = z;
|
||||
|
|
|
@ -67,12 +67,12 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
|
|||
|
||||
BptBuilderBase bluePrintBuilder;
|
||||
|
||||
public @TileNetworkData
|
||||
PowerProvider powerProvider;
|
||||
public @TileNetworkData PowerProvider powerProvider;
|
||||
|
||||
public static int MAX_ENERGY = 7000;
|
||||
|
||||
public TileQuarry() {
|
||||
|
||||
powerProvider = PowerFramework.currentFramework.createPowerProvider();
|
||||
powerProvider.configure(20, 25, 25, 25, MAX_ENERGY);
|
||||
}
|
||||
|
@ -84,6 +84,7 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
|
|||
}
|
||||
|
||||
if (bluePrintBuilder == null) {
|
||||
|
||||
if (!box.isInitialized()) {
|
||||
setBoundaries(loadDefaultBoundaries);
|
||||
}
|
||||
|
@ -92,6 +93,7 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
|
|||
}
|
||||
|
||||
if (builderDone) {
|
||||
|
||||
box.deleteLasers();
|
||||
|
||||
if (arm == null) {
|
||||
|
@ -106,7 +108,9 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
|
|||
isDigging = true;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
box.createLasers(worldObj, LaserKind.Stripes);
|
||||
isDigging = true;
|
||||
}
|
||||
|
@ -115,9 +119,10 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
|
|||
private boolean loadDefaultBoundaries = false;
|
||||
|
||||
private void createArm() {
|
||||
arm = new EntityMechanicalArm(worldObj, box.xMin + Utils.pipeMaxPos,
|
||||
yCoord + bluePrintBuilder.bluePrint.sizeY - 1
|
||||
+ Utils.pipeMinPos, box.zMin + Utils.pipeMaxPos,
|
||||
|
||||
arm = new EntityMechanicalArm(worldObj,
|
||||
box.xMin + Utils.pipeMaxPos,
|
||||
yCoord + bluePrintBuilder.bluePrint.sizeY - 1 + Utils.pipeMinPos, box.zMin + Utils.pipeMaxPos,
|
||||
bluePrintBuilder.bluePrint.sizeX - 2 + Utils.pipeMinPos * 2,
|
||||
bluePrintBuilder.bluePrint.sizeZ - 2 + Utils.pipeMinPos * 2, this);
|
||||
|
||||
|
@ -150,15 +155,9 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
|
|||
|
||||
speed = arm.speed;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWork() {
|
||||
|
||||
builderDone = bluePrintBuilder.done;
|
||||
|
||||
if (APIProxy.isClient(worldObj)) {
|
||||
return;
|
||||
if (APIProxy.isServerSide()) {
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
|
||||
if (inProcess || !isDigging) {
|
||||
|
@ -169,30 +168,16 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
|
|||
|
||||
if (bluePrintBuilder != null) {
|
||||
|
||||
builderDone = bluePrintBuilder.done;
|
||||
if (!builderDone) {
|
||||
// configuration for building phase
|
||||
powerProvider.configure(20, 25, 25, 25, MAX_ENERGY);
|
||||
|
||||
if (powerProvider.useEnergy(25, 25, true) != 25) {
|
||||
return;
|
||||
}
|
||||
|
||||
powerProvider.timeTracker.markTime(worldObj);
|
||||
|
||||
if (builder == null) {
|
||||
builder = new EntityRobot(worldObj, box);
|
||||
worldObj.spawnEntityInWorld(builder);
|
||||
}
|
||||
|
||||
if (builder.readyToBuild()) {
|
||||
builder.scheduleContruction(bluePrintBuilder.getNextBlock(worldObj, this), bluePrintBuilder.getContext());
|
||||
}
|
||||
|
||||
buildFrame();
|
||||
return;
|
||||
|
||||
} else {
|
||||
|
||||
if (builder != null && builder.done()) {
|
||||
|
||||
box.deleteLasers();
|
||||
builder.setDead();
|
||||
builder = null;
|
||||
|
@ -201,24 +186,58 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
|
|||
}
|
||||
|
||||
if (builder == null) {
|
||||
// configuration for digging phase
|
||||
powerProvider.configure(20, 30, 200, 50, MAX_ENERGY);
|
||||
|
||||
if (!findTarget(true)) {
|
||||
arm.setTarget(box.xMin + arm.sizeX / 2, yCoord + 2, box.zMin + arm.sizeX / 2);
|
||||
|
||||
isDigging = false;
|
||||
}
|
||||
|
||||
inProcess = true;
|
||||
dig();
|
||||
}
|
||||
|
||||
if (APIProxy.isServerSide()) {
|
||||
sendNetworkUpdate();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWork() {}
|
||||
|
||||
protected void buildFrame() {
|
||||
|
||||
System.out.println(powerProvider.energyStored);
|
||||
powerProvider.configure(20, 25, 25, 25, MAX_ENERGY);
|
||||
if (powerProvider.useEnergy(25, 25, true) != 25) {
|
||||
return;
|
||||
}
|
||||
|
||||
powerProvider.timeTracker.markTime(worldObj);
|
||||
|
||||
if (builder == null) {
|
||||
builder = new EntityRobot(worldObj, box);
|
||||
worldObj.spawnEntityInWorld(builder);
|
||||
}
|
||||
|
||||
if (builder.readyToBuild()) {
|
||||
builder.scheduleContruction(bluePrintBuilder.getNextBlock(worldObj, this), bluePrintBuilder.getContext());
|
||||
}
|
||||
}
|
||||
|
||||
protected void dig() {
|
||||
|
||||
powerProvider.configure(20, 30, 200, 50, MAX_ENERGY);
|
||||
if (powerProvider.useEnergy(30, 30, true) != 30) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!findTarget(true)) {
|
||||
|
||||
arm.setTarget(box.xMin + arm.sizeX / 2, yCoord + 2, box.zMin + arm.sizeX / 2);
|
||||
|
||||
isDigging = false;
|
||||
}
|
||||
|
||||
inProcess = true;
|
||||
}
|
||||
|
||||
public boolean findTarget(boolean doSet) {
|
||||
|
||||
if (APIProxy.isClient(worldObj))
|
||||
return false;
|
||||
|
||||
boolean[][] blockedColumns = new boolean[bluePrintBuilder.bluePrint.sizeX - 2][bluePrintBuilder.bluePrint.sizeZ - 2];
|
||||
|
||||
for (int searchX = 0; searchX < bluePrintBuilder.bluePrint.sizeX - 2; ++searchX) {
|
||||
|
@ -462,6 +481,7 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
|
|||
}
|
||||
|
||||
private void setBoundaries(boolean useDefault) {
|
||||
|
||||
IAreaProvider a = null;
|
||||
|
||||
if (!useDefault) {
|
||||
|
@ -562,6 +582,7 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
|
|||
|
||||
@Override
|
||||
public void postPacketHandling(PacketUpdate packet) {
|
||||
|
||||
super.postPacketHandling(packet);
|
||||
|
||||
createUtilsIfNeeded();
|
||||
|
|
Loading…
Reference in a new issue