Code cleanup

This commit is contained in:
LemADEC 2015-09-08 00:17:52 +02:00
parent 7ee3252070
commit 625d422a36
10 changed files with 183 additions and 136 deletions

View file

@ -1057,6 +1057,11 @@ public class EntityJump extends Entity {
case 270: case 270:
v[0] = -dz; v[0] = -dz;
v[2] = dx; v[2] = dx;
break;
default:
WarpDrive.logger.error(this + "Invalid direction " + i);
break;
} }
return v; return v;

View file

@ -33,23 +33,23 @@ import dan200.computercraft.api.peripheral.IComputerAccess;
public class TileEntityShipScanner extends TileEntityAbstractEnergy { public class TileEntityShipScanner extends TileEntityAbstractEnergy {
private boolean isActive = false; private boolean isActive = false;
private TileEntityShipCore shipCore = null; private TileEntityShipCore shipCore = null;
int laserTicks = 0; int laserTicks = 0;
int scanTicks = 0; int scanTicks = 0;
int deployDelayTicks = 0; int deployDelayTicks = 0;
int searchTicks = 0; int searchTicks = 0;
private String schematicFileName; private String schematicFileName;
private JumpBlock[] blocksToDeploy; // JumpBlock class stores a basic private JumpBlock[] blocksToDeploy; // JumpBlock class stores a basic
// information about block // information about block
private int currentDeployIndex; private int currentDeployIndex;
private int blocksToDeployCount; private int blocksToDeployCount;
private boolean isDeploying = false; private boolean isDeploying = false;
private int targetX, targetY, targetZ; private int targetX, targetY, targetZ;
public TileEntityShipScanner() { public TileEntityShipScanner() {
super(); super();
peripheralName = "warpdriveShipScanner"; peripheralName = "warpdriveShipScanner";
@ -60,25 +60,25 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
"state" "state"
}); });
} }
@Override @Override
public void updateEntity() { public void updateEntity() {
super.updateEntity(); super.updateEntity();
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) if (FMLCommonHandler.instance().getEffectiveSide().isClient())
return; return;
if (++searchTicks > 20) { if (++searchTicks > 20) {
shipCore = searchShipCore(); shipCore = searchShipCore();
searchTicks = 0; searchTicks = 0;
} }
// Warp core is not found // Warp core is not found
if (!isDeploying && shipCore == null) { if (!isDeploying && shipCore == null) {
setActive(false); // disable scanner setActive(false); // disable scanner
return; return;
} }
if (!isActive) {// inactive if (!isActive) {// inactive
if (++laserTicks > 20) { if (++laserTicks > 20) {
PacketHandler.sendBeamPacket(worldObj, new Vector3(this).translate(0.5D), new Vector3(shipCore.xCoord, shipCore.yCoord, shipCore.zCoord).translate(0.5D), PacketHandler.sendBeamPacket(worldObj, new Vector3(this).translate(0.5D), new Vector3(shipCore.xCoord, shipCore.yCoord, shipCore.zCoord).translate(0.5D),
@ -88,51 +88,57 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
} else if (!isDeploying) {// active and scanning } else if (!isDeploying) {// active and scanning
if (++laserTicks > 5) { if (++laserTicks > 5) {
laserTicks = 0; laserTicks = 0;
for (int i = 0; i < shipCore.maxX - shipCore.minX; i++) { for (int i = 0; i < shipCore.maxX - shipCore.minX; i++) {
int x = shipCore.minX + i; int x = shipCore.minX + i;
int randomZ = shipCore.minZ + worldObj.rand.nextInt(shipCore.maxZ - shipCore.minZ); int randomZ = shipCore.minZ + worldObj.rand.nextInt(shipCore.maxZ - shipCore.minZ);
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F); worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
float r = 0.0f, g = 0.0f, b = 0.0f; float r = 0.0f, g = 0.0f, b = 0.0f;
switch (worldObj.rand.nextInt(6)) { switch (worldObj.rand.nextInt(6)) {
case 0: case 0:
r = 1.0f; r = 1.0f;
g = b = 0; g = b = 0;
break; break;
case 1: case 1:
r = b = 0; r = b = 0;
g = 1.0f; g = 1.0f;
break; break;
case 2: case 2:
r = g = 0; r = g = 0;
b = 1.0f; b = 1.0f;
break; break;
case 3: case 3:
r = b = 0.5f; r = b = 0.5f;
g = 0; g = 0;
break; break;
case 4: case 4:
r = g = 1.0f; r = g = 1.0f;
b = 0; b = 0;
break; break;
case 5: case 5:
r = 1.0f; r = 1.0f;
b = 0.5f; b = 0.5f;
g = 0f; g = 0f;
break;
default:
break;
} }
PacketHandler.sendBeamPacket(worldObj, new Vector3(this).translate(0.5D), new Vector3(x, shipCore.maxY, randomZ).translate(0.5D), r, g, b, 15, PacketHandler.sendBeamPacket(worldObj,
0, 100); new Vector3(this).translate(0.5D),
new Vector3(x, shipCore.maxY, randomZ).translate(0.5D),
r, g, b, 15, 0, 100);
} }
} }
if (++scanTicks > 20 * (1 + shipCore.shipMass / 10)) { if (++scanTicks > 20 * (1 + shipCore.shipMass / 10)) {
setActive(false); // disable scanner setActive(false); // disable scanner
scanTicks = 0; scanTicks = 0;
@ -140,20 +146,20 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
} else {// active and deploying } else {// active and deploying
if (++deployDelayTicks < 20) if (++deployDelayTicks < 20)
return; return;
deployDelayTicks = 0; deployDelayTicks = 0;
int blocks = Math.min(WarpDriveConfig.G_BLOCKS_PER_TICK, blocksToDeployCount - currentDeployIndex); int blocks = Math.min(WarpDriveConfig.G_BLOCKS_PER_TICK, blocksToDeployCount - currentDeployIndex);
if (blocks == 0) { if (blocks == 0) {
isDeploying = false; isDeploying = false;
setActive(false); // disable scanner setActive(false); // disable scanner
return; return;
} }
for (int index = 0; index < blocks; index++) { for (int index = 0; index < blocks; index++) {
if (currentDeployIndex >= blocksToDeployCount) { if (currentDeployIndex >= blocksToDeployCount) {
isDeploying = false; isDeploying = false;
setActive(false); // disable scanner setActive(false); // disable scanner
break; break;
} }
@ -165,12 +171,14 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
Block blockAtTarget = worldObj.getBlock(targetX + jb.x, targetY + jb.y, targetZ + jb.z); Block blockAtTarget = worldObj.getBlock(targetX + jb.x, targetY + jb.y, targetZ + jb.z);
if (blockAtTarget == Blocks.air || WarpDriveConfig.BLOCKS_EXPANDABLE.contains(blockAtTarget)) { if (blockAtTarget == Blocks.air || WarpDriveConfig.BLOCKS_EXPANDABLE.contains(blockAtTarget)) {
jb.deploy(worldObj, targetX, targetY, targetZ); jb.deploy(worldObj, targetX, targetY, targetZ);
if (worldObj.rand.nextInt(100) <= 10) { if (worldObj.rand.nextInt(100) <= 10) {
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F); worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
PacketHandler.sendBeamPacket(worldObj, new Vector3(this).translate(0.5D), PacketHandler.sendBeamPacket(worldObj,
new Vector3(targetX + jb.x, targetY + jb.y, targetZ + jb.z).translate(0.5D), 0f, 1f, 0f, 15, 0, 100); new Vector3(this).translate(0.5D),
new Vector3(targetX + jb.x, targetY + jb.y, targetZ + jb.z).translate(0.5D),
0f, 1f, 0f, 15, 0, 100);
} }
} }
} }
@ -179,46 +187,46 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
} }
} }
} }
private void setActive(boolean newState) { private void setActive(boolean newState) {
isActive = newState; isActive = newState;
if ((getBlockMetadata() == 1) == newState) { if ((getBlockMetadata() == 1) == newState) {
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, isActive ? 1 : 0, 2); worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, isActive ? 1 : 0, 2);
} }
} }
private TileEntityShipCore searchShipCore() { private TileEntityShipCore searchShipCore() {
StringBuilder reason = new StringBuilder(); StringBuilder reason = new StringBuilder();
TileEntityShipCore result = null; TileEntityShipCore result = null;
// Search for warp cores above // Search for warp cores above
for (int newY = yCoord + 1; newY <= 255; newY++) { for (int newY = yCoord + 1; newY <= 255; newY++) {
if (worldObj.getBlock(xCoord, newY, zCoord).isAssociatedBlock(WarpDrive.blockShipCore)) { // found if (worldObj.getBlock(xCoord, newY, zCoord).isAssociatedBlock(WarpDrive.blockShipCore)) { // found
// warp core above // warp core above
result = (TileEntityShipCore) worldObj.getTileEntity(xCoord, newY, zCoord); result = (TileEntityShipCore) worldObj.getTileEntity(xCoord, newY, zCoord);
if (result != null) { if (result != null) {
if (!result.validateShipSpatialParameters(reason)) { // If if (!result.validateShipSpatialParameters(reason)) { // If
// we can't refresh ship's spatial parameters // we can't refresh ship's spatial parameters
result = null; result = null;
} }
} }
break; break;
} }
} }
return result; return result;
} }
private int getScanningEnergyCost(int size) { private int getScanningEnergyCost(int size) {
if (WarpDriveConfig.SS_ENERGY_PER_BLOCK_SCAN > 0) { if (WarpDriveConfig.SS_ENERGY_PER_BLOCK_SCAN > 0) {
return size * WarpDriveConfig.SS_ENERGY_PER_BLOCK_SCAN; return size * WarpDriveConfig.SS_ENERGY_PER_BLOCK_SCAN;
} else { } else {
return WarpDriveConfig.SS_MAX_ENERGY_STORED; return WarpDriveConfig.SS_MAX_ENERGY_STORED;
} }
} }
private int getDeploymentEnergyCost(int size) { private int getDeploymentEnergyCost(int size) {
if (WarpDriveConfig.SS_ENERGY_PER_BLOCK_DEPLOY > 0) { if (WarpDriveConfig.SS_ENERGY_PER_BLOCK_DEPLOY > 0) {
return size * WarpDriveConfig.SS_ENERGY_PER_BLOCK_DEPLOY; return size * WarpDriveConfig.SS_ENERGY_PER_BLOCK_DEPLOY;
@ -226,60 +234,59 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
return WarpDriveConfig.SS_MAX_ENERGY_STORED; return WarpDriveConfig.SS_MAX_ENERGY_STORED;
} }
} }
private boolean saveShipToSchematic(String fileName, StringBuilder reason) { private boolean saveShipToSchematic(String fileName, StringBuilder reason) {
NBTTagCompound schematic = new NBTTagCompound(); NBTTagCompound schematic = new NBTTagCompound();
short width = (short) (shipCore.maxX - shipCore.minX + 1); short width = (short) (shipCore.maxX - shipCore.minX + 1);
short length = (short) (shipCore.maxZ - shipCore.minZ + 1); short length = (short) (shipCore.maxZ - shipCore.minZ + 1);
short height = (short) (shipCore.maxY - shipCore.minY + 1); short height = (short) (shipCore.maxY - shipCore.minY + 1);
if (width <= 0 || length <= 0 || height <= 0) { if (width <= 0 || length <= 0 || height <= 0) {
reason.append("Invalid ship dimensions, nothing to scan"); reason.append("Invalid ship dimensions, nothing to scan");
return false; return false;
} }
schematic.setShort("Width", width); schematic.setShort("Width", width);
schematic.setShort("Length", length); schematic.setShort("Length", length);
schematic.setShort("Height", height); schematic.setShort("Height", height);
int size = width * length * height; int size = width * length * height;
// Consume energy // Consume energy
if (!consumeEnergy(getScanningEnergyCost(size), false)) { if (!consumeEnergy(getScanningEnergyCost(size), false)) {
reason.append("Insufficient energy (" + getScanningEnergyCost(size) + " required)"); reason.append("Insufficient energy (" + getScanningEnergyCost(size) + " required)");
return false; return false;
} }
NBTTagList localBlocks = new NBTTagList(); NBTTagList localBlocks = new NBTTagList();
byte localMetadata[] = new byte[size]; byte localMetadata[] = new byte[size];
NBTTagList tileEntitiesList = new NBTTagList(); NBTTagList tileEntitiesList = new NBTTagList();
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
for (int z = 0; z < length; z++) { for (int z = 0; z < length; z++) {
Block block = worldObj.getBlock(shipCore.minX + x, shipCore.minY + y, shipCore.minZ + z); Block block = worldObj.getBlock(shipCore.minX + x, shipCore.minY + y, shipCore.minZ + z);
// Skip leftBehind and anchor blocks // Skip leftBehind and anchor blocks
if ( WarpDriveConfig.BLOCKS_LEFTBEHIND.contains(block) if (WarpDriveConfig.BLOCKS_LEFTBEHIND.contains(block) || WarpDriveConfig.BLOCKS_ANCHOR.contains(block)) {
|| WarpDriveConfig.BLOCKS_ANCHOR.contains(block)) {
block = Blocks.air; block = Blocks.air;
} }
//Old coord calc [x + (y * length + z) * width] //Old coord calc [x + (y * length + z) * width]
localBlocks.appendTag(new NBTTagString(block.getUnlocalizedName())); localBlocks.appendTag(new NBTTagString(block.getUnlocalizedName()));
localMetadata[x + (y * length + z) * width] = (byte) worldObj.getBlockMetadata(shipCore.minX + x, shipCore.minY + y, shipCore.minZ + z); localMetadata[x + (y * length + z) * width] = (byte) worldObj.getBlockMetadata(shipCore.minX + x, shipCore.minY + y, shipCore.minZ + z);
if (!block.isAssociatedBlock(Blocks.air)) { if (!block.isAssociatedBlock(Blocks.air)) {
TileEntity te = worldObj.getTileEntity(shipCore.minX + x, shipCore.minY + y, shipCore.minZ + z); TileEntity te = worldObj.getTileEntity(shipCore.minX + x, shipCore.minY + y, shipCore.minZ + z);
if (te != null) { if (te != null) {
try { try {
NBTTagCompound tileTag = new NBTTagCompound(); NBTTagCompound tileTag = new NBTTagCompound();
te.writeToNBT(tileTag); te.writeToNBT(tileTag);
// Clear inventory. // Clear inventory.
if (te instanceof IInventory) { if (te instanceof IInventory) {
TileEntity tmp_te = TileEntity.createAndLoadEntity(tileTag); TileEntity tmp_te = TileEntity.createAndLoadEntity(tileTag);
if (tmp_te instanceof IInventory) { if (tmp_te instanceof IInventory) {
for (int i = 0; i < ((IInventory) tmp_te).getSizeInventory(); i++) { for (int i = 0; i < ((IInventory) tmp_te).getSizeInventory(); i++) {
@ -288,7 +295,7 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
} }
tmp_te.writeToNBT(tileTag); tmp_te.writeToNBT(tileTag);
} }
// Remove energy from energy storages // Remove energy from energy storages
// IC2 // IC2
if (tileTag.hasKey("energy")) { if (tileTag.hasKey("energy")) {
@ -298,54 +305,54 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
if (tileTag.hasKey("mStoredEnergy")) { if (tileTag.hasKey("mStoredEnergy")) {
tileTag.setInteger("mStoredEnergy", 0); tileTag.setInteger("mStoredEnergy", 0);
} }
// Transform TE's coordinates from local axis to // Transform TE's coordinates from local axis to
// .schematic offset-axis // .schematic offset-axis
tileTag.setInteger("x", te.xCoord - shipCore.minX); tileTag.setInteger("x", te.xCoord - shipCore.minX);
tileTag.setInteger("y", te.yCoord - shipCore.minY); tileTag.setInteger("y", te.yCoord - shipCore.minY);
tileTag.setInteger("z", te.zCoord - shipCore.minZ); tileTag.setInteger("z", te.zCoord - shipCore.minZ);
tileEntitiesList.appendTag(tileTag); tileEntitiesList.appendTag(tileTag);
} catch (Exception exception) { } catch (Exception exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
} }
} }
} }
} }
schematic.setString("Materials", "Alpha"); schematic.setString("Materials", "Alpha");
schematic.setTag("Blocks", localBlocks); schematic.setTag("Blocks", localBlocks);
schematic.setByteArray("Data", localMetadata); schematic.setByteArray("Data", localMetadata);
schematic.setTag("Entities", new NBTTagList()); // don't save entities schematic.setTag("Entities", new NBTTagList()); // don't save entities
schematic.setTag("TileEntities", tileEntitiesList); schematic.setTag("TileEntities", tileEntitiesList);
writeNBTToFile(fileName, schematic); writeNBTToFile(fileName, schematic);
return true; return true;
} }
private void writeNBTToFile(String fileName, NBTTagCompound nbttagcompound) { private void writeNBTToFile(String fileName, NBTTagCompound nbttagcompound) {
WarpDrive.logger.info(this + " Filename: " + fileName); WarpDrive.logger.info(this + " Filename: " + fileName);
try { try {
File file = new File(fileName); File file = new File(fileName);
if (!file.exists()) { if (!file.exists()) {
file.createNewFile(); file.createNewFile();
} }
FileOutputStream fileoutputstream = new FileOutputStream(file); FileOutputStream fileoutputstream = new FileOutputStream(file);
CompressedStreamTools.writeCompressed(nbttagcompound, fileoutputstream); CompressedStreamTools.writeCompressed(nbttagcompound, fileoutputstream);
fileoutputstream.close(); fileoutputstream.close();
} catch (Exception exception) { } catch (Exception exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
// Begins ship scan // Begins ship scan
private boolean scanShip(StringBuilder reason) { private boolean scanShip(StringBuilder reason) {
// Enable scanner // Enable scanner
@ -354,39 +361,39 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
if (!f.exists() || !f.isDirectory()) { if (!f.exists() || !f.isDirectory()) {
f.mkdirs(); f.mkdirs();
} }
// Generate unique file name // Generate unique file name
do { do {
schematicFileName = (new StringBuilder().append(shipCore.shipName).append(System.currentTimeMillis()).append(".schematic")).toString(); schematicFileName = (new StringBuilder().append(shipCore.shipName).append(System.currentTimeMillis()).append(".schematic")).toString();
} while (new File(WarpDriveConfig.G_SCHEMALOCATION + "/" + schematicFileName).exists()); } while (new File(WarpDriveConfig.G_SCHEMALOCATION + "/" + schematicFileName).exists());
if (!saveShipToSchematic(WarpDriveConfig.G_SCHEMALOCATION + "/" + schematicFileName, reason)) { if (!saveShipToSchematic(WarpDriveConfig.G_SCHEMALOCATION + "/" + schematicFileName, reason)) {
return false; return false;
} }
reason.append(schematicFileName); reason.append(schematicFileName);
return true; return true;
} }
private static NBTTagCompound readNBTFromFile(String fileName) { private static NBTTagCompound readNBTFromFile(String fileName) {
try { try {
File file = new File(fileName); File file = new File(fileName);
if (!file.exists()) { if (!file.exists()) {
return null; return null;
} }
FileInputStream fileinputstream = new FileInputStream(file); FileInputStream fileinputstream = new FileInputStream(file);
NBTTagCompound nbttagcompound = CompressedStreamTools.readCompressed(fileinputstream); NBTTagCompound nbttagcompound = CompressedStreamTools.readCompressed(fileinputstream);
fileinputstream.close(); fileinputstream.close();
return nbttagcompound; return nbttagcompound;
} catch (Exception exception) { } catch (Exception exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
return null; return null;
} }
// Returns error code and reason string // Returns error code and reason string
private int deployShip(String fileName, int offsetX, int offsetY, int offsetZ, StringBuilder reason) { private int deployShip(String fileName, int offsetX, int offsetY, int offsetZ, StringBuilder reason) {
// Load schematic // Load schematic
@ -395,17 +402,17 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
reason.append("Schematic not found or unknow error reading it."); reason.append("Schematic not found or unknow error reading it.");
return -1; return -1;
} }
// Compute geometry // Compute geometry
short width = schematic.getShort("Width"); short width = schematic.getShort("Width");
short height = schematic.getShort("Height"); short height = schematic.getShort("Height");
short length = schematic.getShort("Length"); short length = schematic.getShort("Length");
targetX = xCoord + offsetX; targetX = xCoord + offsetX;
targetY = yCoord + offsetY; targetY = yCoord + offsetY;
targetZ = zCoord + offsetZ; targetZ = zCoord + offsetZ;
blocksToDeployCount = width * height * length; blocksToDeployCount = width * height * length;
// Validate context // Validate context
{ {
// Check distance // Check distance
@ -413,18 +420,18 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
double dY = yCoord - targetY; double dY = yCoord - targetY;
double dZ = zCoord - targetZ; double dZ = zCoord - targetZ;
double distance = MathHelper.sqrt_double(dX * dX + dY * dY + dZ * dZ); double distance = MathHelper.sqrt_double(dX * dX + dY * dY + dZ * dZ);
if (distance > WarpDriveConfig.SS_MAX_DEPLOY_RADIUS_BLOCKS) { if (distance > WarpDriveConfig.SS_MAX_DEPLOY_RADIUS_BLOCKS) {
reason.append("Cannot deploy ship so far away from scanner."); reason.append("Cannot deploy ship so far away from scanner.");
return 5; return 5;
} }
// Consume energy // Consume energy
if (!consumeEnergy(getDeploymentEnergyCost(blocksToDeployCount), false)) { if (!consumeEnergy(getDeploymentEnergyCost(blocksToDeployCount), false)) {
reason.append("Insufficient energy (" + getDeploymentEnergyCost(blocksToDeployCount) + " required)"); reason.append("Insufficient energy (" + getDeploymentEnergyCost(blocksToDeployCount) + " required)");
return 1; return 1;
} }
// Check specified area for occupation by blocks // Check specified area for occupation by blocks
// If specified area occupied, break deploying with error message // If specified area occupied, break deploying with error message
int occupiedBlockCount = 0; int occupiedBlockCount = 0;
@ -441,43 +448,43 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
return 2; return 2;
} }
} }
// Set deployment variables // Set deployment variables
blocksToDeploy = new JumpBlock[blocksToDeployCount]; blocksToDeploy = new JumpBlock[blocksToDeployCount];
isDeploying = true; isDeploying = true;
currentDeployIndex = 0; currentDeployIndex = 0;
// Read blocks and TileEntities from NBT to internal storage array // Read blocks and TileEntities from NBT to internal storage array
NBTTagList localBlocks = (NBTTagList) schematic.getTag("Blocks"); NBTTagList localBlocks = (NBTTagList) schematic.getTag("Blocks");
byte localMetadata[] = schematic.getByteArray("Data"); byte localMetadata[] = schematic.getByteArray("Data");
// Load Tile Entities // Load Tile Entities
NBTTagCompound[] tileEntities = new NBTTagCompound[blocksToDeployCount]; NBTTagCompound[] tileEntities = new NBTTagCompound[blocksToDeployCount];
NBTTagList tileEntitiesList = schematic.getTagList("TileEntities", new NBTTagByteArray(new byte[0]).getId()); //TODO: 0 is not correct NBTTagList tileEntitiesList = schematic.getTagList("TileEntities", new NBTTagByteArray(new byte[0]).getId()); //TODO: 0 is not correct
for (int i = 0; i < tileEntitiesList.tagCount(); i++) { for (int i = 0; i < tileEntitiesList.tagCount(); i++) {
NBTTagCompound teTag = tileEntitiesList.getCompoundTagAt(i); NBTTagCompound teTag = tileEntitiesList.getCompoundTagAt(i);
int teX = teTag.getInteger("x"); int teX = teTag.getInteger("x");
int teY = teTag.getInteger("y"); int teY = teTag.getInteger("y");
int teZ = teTag.getInteger("z"); int teZ = teTag.getInteger("z");
tileEntities[teX + (teY * length + teZ) * width] = teTag; tileEntities[teX + (teY * length + teZ) * width] = teTag;
} }
// Create list of blocks to deploy // Create list of blocks to deploy
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
for (int z = 0; z < length; z++) { for (int z = 0; z < length; z++) {
int index = x + (y * length + z) * width; int index = x + (y * length + z) * width;
JumpBlock jb = new JumpBlock(); JumpBlock jb = new JumpBlock();
jb.x = x; jb.x = x;
jb.y = y; jb.y = y;
jb.z = z; jb.z = z;
jb.block = Block.getBlockFromName(localBlocks.getStringTagAt(index)); jb.block = Block.getBlockFromName(localBlocks.getStringTagAt(index));
jb.blockMeta = (localMetadata[index]) & 0xFF; jb.blockMeta = (localMetadata[index]) & 0xFF;
jb.blockNBT = tileEntities[index]; jb.blockNBT = tileEntities[index];
if (jb.block != null) { if (jb.block != null) {
if (WarpDriveConfig.LOGGING_BUILDING) { if (WarpDriveConfig.LOGGING_BUILDING) {
@ -487,57 +494,57 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
WarpDrive.logger.info("[ShipScanner] Adding block to deploy: " + jb.block.getUnlocalizedName() + " with tile entity " + tileEntities[index].getString("id")); WarpDrive.logger.info("[ShipScanner] Adding block to deploy: " + jb.block.getUnlocalizedName() + " with tile entity " + tileEntities[index].getString("id"));
} }
} }
blocksToDeploy[index] = jb; blocksToDeploy[index] = jb;
} else { } else {
jb = null; jb = null;
blocksToDeploy[index] = jb; blocksToDeploy[index] = jb;
} }
} }
} }
} }
setActive(true); setActive(true);
reason.append("Ship deploying..."); reason.append("Ship deploying...");
return 3; return 3;
} }
@Override @Override
public void readFromNBT(NBTTagCompound tag) { public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag); super.readFromNBT(tag);
} }
@Override @Override
public void writeToNBT(NBTTagCompound tag) { public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag); super.writeToNBT(tag);
} }
// OpenComputer callback methods // OpenComputer callback methods
@Callback @Callback
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] scan(Context context, Arguments arguments) { public Object[] scan(Context context, Arguments arguments) {
return scan(argumentsOCtoCC(arguments)); return scan(argumentsOCtoCC(arguments));
} }
@Callback @Callback
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] filename(Context context, Arguments arguments) { public Object[] filename(Context context, Arguments arguments) {
return filename(argumentsOCtoCC(arguments)); return filename(argumentsOCtoCC(arguments));
} }
@Callback @Callback
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] deploy(Context context, Arguments arguments) { public Object[] deploy(Context context, Arguments arguments) {
return deploy(argumentsOCtoCC(arguments)); return deploy(argumentsOCtoCC(arguments));
} }
private Object[] scan(Object[] arguments) { private Object[] scan(Object[] arguments) {
// Already scanning? // Already scanning?
if (isActive) { if (isActive) {
return new Object[] { false, 0, "Already active" }; return new Object[] { false, 0, "Already active" };
} }
if (shipCore == null) { if (shipCore == null) {
return new Object[] { false, 1, "Warp-Core not found" }; return new Object[] { false, 1, "Warp-Core not found" };
} else if (!consumeEnergy(getScanningEnergyCost(shipCore.shipMass), true)) { } else if (!consumeEnergy(getScanningEnergyCost(shipCore.shipMass), true)) {
@ -548,7 +555,7 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
return new Object[] { success, 3, reason.toString() }; return new Object[] { success, 3, reason.toString() };
} }
} }
private Object[] filename(Object[] arguments) { private Object[] filename(Object[] arguments) {
if (isActive && !schematicFileName.isEmpty()) { if (isActive && !schematicFileName.isEmpty()) {
if (isDeploying) { if (isDeploying) {
@ -557,17 +564,17 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
return new Object[] { false, "Scan in progress. Please wait..." }; return new Object[] { false, "Scan in progress. Please wait..." };
} }
} }
return new Object[] { true, schematicFileName }; return new Object[] { true, schematicFileName };
} }
private Object[] deploy(Object[] arguments) { private Object[] deploy(Object[] arguments) {
if (arguments.length == 4) { if (arguments.length == 4) {
String fileName = (String) arguments[0]; String fileName = (String) arguments[0];
int x = toInt(arguments[1]); int x = toInt(arguments[1]);
int y = toInt(arguments[2]); int y = toInt(arguments[2]);
int z = toInt(arguments[3]); int z = toInt(arguments[3]);
if (!new File(WarpDriveConfig.G_SCHEMALOCATION + "/" + fileName).exists()) { if (!new File(WarpDriveConfig.G_SCHEMALOCATION + "/" + fileName).exists()) {
return new Object[] { 0, "Specified .schematic file was not found!" }; return new Object[] { 0, "Specified .schematic file was not found!" };
} else { } else {
@ -579,7 +586,7 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
return new Object[] { 4, "Invalid arguments count, you need .schematic file name, offsetX, offsetY and offsetZ!" }; return new Object[] { 4, "Invalid arguments count, you need .schematic file name, offsetX, offsetY and offsetZ!" };
} }
} }
private Object[] state(Object[] arguments) { private Object[] state(Object[] arguments) {
if (!isActive) { if (!isActive) {
return new Object[] { false, "IDLE", 0, 0 }; return new Object[] { false, "IDLE", 0, 0 };
@ -589,7 +596,7 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
return new Object[] { true, "Deploying", currentDeployIndex, blocksToDeployCount }; return new Object[] { true, "Deploying", currentDeployIndex, blocksToDeployCount };
} }
} }
// ComputerCraft IPeripheral methods implementation // ComputerCraft IPeripheral methods implementation
@Override @Override
@Optional.Method(modid = "ComputerCraft") @Optional.Method(modid = "ComputerCraft")
@ -611,13 +618,13 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
return super.callMethod(computer, context, method, arguments); return super.callMethod(computer, context, method, arguments);
} }
// IEnergySink methods implementation // IEnergySink methods implementation
@Override @Override
public int getMaxEnergyStored() { public int getMaxEnergyStored() {
return WarpDriveConfig.SS_MAX_ENERGY_STORED; return WarpDriveConfig.SS_MAX_ENERGY_STORED;
} }
@Override @Override
public boolean canInputEnergy(ForgeDirection from) { public boolean canInputEnergy(ForgeDirection from) {
return true; return true;

View file

@ -223,6 +223,8 @@ public class TileEntityLift extends TileEntityAbstractEnergy {
return new Object[] { "up" }; return new Object[] { "up" };
case 2: case 2:
return new Object[] { "down" }; return new Object[] { "down" };
default:
break;
} }
return null; return null;
} }

View file

@ -144,6 +144,9 @@ public class CommandDebug extends CommandBase
te.updateContainingBlockInfo(); te.updateContainingBlockInfo();
} }
break; break;
default:
WarpDrive.logger.info("[" + getCommandName() + "] " + side + ": invalid step '" + ch + "'");
break;
} }
} }
} }

View file

@ -934,6 +934,9 @@ public class WarpDriveConfig {
case "PlaceNormal" : BLOCKS_PLACE.put(block, 2); break; case "PlaceNormal" : BLOCKS_PLACE.put(block, 2); break;
case "PlaceLater" : BLOCKS_PLACE.put(block, 3); break; case "PlaceLater" : BLOCKS_PLACE.put(block, 3); break;
case "PlaceLatest" : BLOCKS_PLACE.put(block, 4); break; case "PlaceLatest" : BLOCKS_PLACE.put(block, 4); break;
default:
WarpDrive.logger.error("Unsupported tag '" + tag + "' for block " + block);
break;
} }
} }
} }
@ -968,6 +971,9 @@ public class WarpDriveConfig {
case "NoMass" : ENTITIES_NOMASS.add(entityId); break; case "NoMass" : ENTITIES_NOMASS.add(entityId); break;
case "LeftBehind" : ENTITIES_LEFTBEHIND.add(entityId); break; case "LeftBehind" : ENTITIES_LEFTBEHIND.add(entityId); break;
case "NonLivingTarget" : ENTITIES_NONLIVINGTARGET.add(entityId); break; case "NonLivingTarget" : ENTITIES_NONLIVINGTARGET.add(entityId); break;
default:
WarpDrive.logger.error("Unsupported tag '" + tag + "' for entity " + entityId);
break;
} }
} }
} }
@ -993,6 +999,9 @@ public class WarpDriveConfig {
case "FlyInSpace" : ITEMS_FLYINSPACE.add(item); break; case "FlyInSpace" : ITEMS_FLYINSPACE.add(item); break;
case "NoFallDamage" : ITEMS_NOFALLDAMAGE.add(item); break; case "NoFallDamage" : ITEMS_NOFALLDAMAGE.add(item); break;
case "BreathingIC2" : ITEMS_BREATHINGIC2.add(item); break; case "BreathingIC2" : ITEMS_BREATHINGIC2.add(item); break;
default:
WarpDrive.logger.error("Unsupported tag '" + tag + "' for item " + item);
break;
} }
} }
} }

View file

@ -200,6 +200,7 @@ public class StarMapRegistry {
case STAR: break; case STAR: break;
case STRUCTURE: break; case STRUCTURE: break;
case WARPECHO: break; case WARPECHO: break;
default: break;
} }
} }

View file

@ -233,6 +233,9 @@ public class Vector3 implements Cloneable {
break; break;
case EAST: case EAST:
x += amount; x += amount;
break;
default:
break;
} }
return this; return this;
@ -383,28 +386,31 @@ public class Vector3 implements Cloneable {
case 0: case 0:
this.y -= amount; this.y -= amount;
break; break;
case 1: case 1:
this.y += amount; this.y += amount;
break; break;
case 2: case 2:
this.z -= amount; this.z -= amount;
break; break;
case 3: case 3:
this.z += amount; this.z += amount;
break; break;
case 4: case 4:
this.x -= amount; this.x -= amount;
break; break;
case 5: case 5:
this.x += amount; this.x += amount;
break; break;
default:
break;
} }
return this; return this;
} }

View file

@ -176,6 +176,9 @@ public class VectorI implements Cloneable {
break; break;
case EAST: case EAST:
x += amount; x += amount;
break;
default:
break;
} }
return this; return this;

View file

@ -99,27 +99,34 @@ public final class EntitySphereGen extends Entity {
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) { if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
return; return;
} }
if (ticksDelay > 0) { if (ticksDelay > 0) {
ticksDelay--; ticksDelay--;
return; return;
} }
switch (this.state) { switch (state) {
case STATE_SAVING: case STATE_SAVING:
tickScheduleBlocks(); tickScheduleBlocks();
this.state = STATE_SETUP; this.state = STATE_SETUP;
break; break;
case STATE_SETUP: case STATE_SETUP:
if (currentIndex >= blocks.size() - 1) if (currentIndex >= blocks.size() - 1)
this.state = STATE_DELETE; this.state = STATE_DELETE;
else else
tickPlaceBlocks(); tickPlaceBlocks();
break; break;
case STATE_DELETE: case STATE_DELETE:
currentIndex = 0; currentIndex = 0;
killEntity(); killEntity();
break; break;
default:
WarpDrive.logger.error(this + " Invalid state " + state + ". Killing entity...");
killEntity();
break;
} }
} }

View file

@ -49,21 +49,24 @@ public class WorldGenSmallShip extends WorldGenerator {
case 0: case 0:
cableType.setItemDamage(0); cableType.setItemDamage(0);
break; break;
case 1: case 1:
cableType.setItemDamage(3); cableType.setItemDamage(3);
break; break;
case 2: case 2:
cableType.setItemDamage(6); cableType.setItemDamage(6);
break; break;
case 3: case 3:
cableType.setItemDamage(9); cableType.setItemDamage(9);
break; break;
default:
break;
} }
} }
int i = centerX - 5, j = centerY - 4, k = centerZ - 6; int i = centerX - 5, j = centerY - 4, k = centerZ - 6;
world.setBlock(i + 0, j + 1, k + 4, WorldGenStructure.getStoneBlock(corrupted, rand)); world.setBlock(i + 0, j + 1, k + 4, WorldGenStructure.getStoneBlock(corrupted, rand));
world.setBlock(i + 0, j + 1, k + 10, WorldGenStructure.getStoneBlock(corrupted, rand)); world.setBlock(i + 0, j + 1, k + 10, WorldGenStructure.getStoneBlock(corrupted, rand));
@ -627,7 +630,7 @@ public class WorldGenSmallShip extends WorldGenerator {
while (!isDone) { while (!isDone) {
switch (rand.nextInt(14)) { switch (rand.nextInt(14)) {
case 0:// Mass fabricator case 0: // Mass fabricator
res = WarpDriveConfig.getModItemStack("IC2", "blockMachine", -1); res = WarpDriveConfig.getModItemStack("IC2", "blockMachine", -1);
res.setItemDamage(14); res.setItemDamage(14);
res.stackSize = 1; // + rand.nextInt(2); res.stackSize = 1; // + rand.nextInt(2);
@ -653,22 +656,21 @@ public class WorldGenSmallShip extends WorldGenerator {
res.stackSize = 2 + rand.nextInt(12); res.stackSize = 2 + rand.nextInt(12);
isDone = true; isDone = true;
break; break;
case 7:// UU matter cell case 7:// UU matter cell
res = WarpDriveConfig.getModItemStack("IC2", "itemCellEmpty", -1); res = WarpDriveConfig.getModItemStack("IC2", "itemCellEmpty", -1);
res.setItemDamage(3); res.setItemDamage(3);
res.stackSize = 2 + rand.nextInt(14); res.stackSize = 2 + rand.nextInt(14);
isDone = true; isDone = true;
break; break;
case 8: case 8:
isDone = true; isDone = true;
break;// skipped break;// skipped
case 9: case 9:
case 10: case 10:
// Rocket launcher platform Tier3 case 11: // Rocket launcher platform Tier3
case 11:
if (WarpDriveConfig.isICBMLoaded) { if (WarpDriveConfig.isICBMLoaded) {
// TODO: No 1.7 ICBM yet // TODO: No 1.7 ICBM yet
// res = new ItemStack(WarpDriveConfig.ICBM_Machine, 1 + // res = new ItemStack(WarpDriveConfig.ICBM_Machine, 1 +
@ -676,9 +678,9 @@ public class WorldGenSmallShip extends WorldGenerator {
isDone = true; isDone = true;
} }
break; break;
// Missles from conventional to hypersonic
case 12: case 12: // Missiles from conventional to hypersonic
if (WarpDriveConfig.isICBMLoaded) { if (WarpDriveConfig.isICBMLoaded) {
// TODO: No 1.7 ICBM yet // TODO: No 1.7 ICBM yet
// res = new ItemStack(WarpDriveConfig.ICBM_Missile, 2 + // res = new ItemStack(WarpDriveConfig.ICBM_Missile, 2 +
@ -686,14 +688,16 @@ public class WorldGenSmallShip extends WorldGenerator {
isDone = true; isDone = true;
} }
break; break;
// Advanced solar panels case 13: // Advanced solar panels
case 13:
if (WarpDriveConfig.isAdvancedSolarPanelLoaded) { if (WarpDriveConfig.isAdvancedSolarPanelLoaded) {
res = new ItemStack(solarPanel_block, rand.nextInt(3), solarPanel_metadata); res = new ItemStack(solarPanel_block, rand.nextInt(3), solarPanel_metadata);
isDone = true; isDone = true;
} }
break; break;
default:
break;
} }
} }