Refactor of TileQuarry to fix the robot and laser in SMP.

This commit is contained in:
Kyprus 2012-06-26 12:48:48 -04:00
parent 100ba204d4
commit 03fcd8fabc
6 changed files with 1276 additions and 1276 deletions

View file

@ -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() {

View file

@ -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;

View file

@ -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;

View file

@ -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,12 +78,9 @@ 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);
}
}
@Override
public void writeSpawnData(DataOutputStream data) throws IOException {
@ -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,6 +197,8 @@ public class EntityRobot extends Entity implements ISpawnHandler {
BptSlot target = a.slot;
if (wait <= 0) {
if (!APIProxy.isClient(worldObj)) {
if (target.mode == Mode.ClearIfInvalid) {
if (!target.isValid(a.context))
@ -229,6 +220,7 @@ public class EntityRobot extends Entity implements ISpawnHandler {
ModLoader.getLogger().throwing("EntityRobot", "update", t);
}
}
}
targets.pop();
}
@ -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();

View file

@ -170,6 +170,7 @@ public class EntityMechanicalArm extends Entity {
}
public void setTarget(double x, double y, double z) {
targetX = x;
targetY = y;
targetZ = z;

View file

@ -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,10 +168,38 @@ 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);
buildFrame();
return;
} else {
if (builder != null && builder.done()) {
box.deleteLasers();
builder.setDead();
builder = null;
}
}
}
if (builder == null) {
dig();
}
}
@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;
}
@ -187,24 +214,17 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
if (builder.readyToBuild()) {
builder.scheduleContruction(bluePrintBuilder.getNextBlock(worldObj, this), bluePrintBuilder.getContext());
}
return;
} else {
if (builder != null && builder.done()) {
box.deleteLasers();
builder.setDead();
builder = null;
}
}
}
if (builder == null) {
// configuration for digging phase
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;
@ -213,12 +233,11 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
inProcess = true;
}
if (APIProxy.isServerSide()) {
sendNetworkUpdate();
}
}
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();