Miscellaneous updates
Only committing because i need to do some fixing
This commit is contained in:
parent
5ce392555f
commit
3eaea54c72
3 changed files with 481 additions and 452 deletions
|
@ -17,16 +17,20 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cr0s.warpdrive.data.Vector3;
|
||||
import cr0s.warpdrive.machines.TileEntityCamera;
|
||||
import cr0s.warpdrive.machines.TileEntityLaser;
|
||||
import cr0s.warpdrive.machines.TileEntityMonitor;
|
||||
|
||||
public class PacketHandler implements IPacketHandler {
|
||||
public class PacketHandler implements IMessageHandler {
|
||||
|
||||
@Override
|
||||
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
|
||||
if (packet.channel.equals("WarpDriveBeam")) {
|
||||
public IMessage onMessage(IMessage message, MessageContext ctx) {
|
||||
if (ctx..channel.equals("WarpDriveBeam")) {
|
||||
handleBeam(packet, (EntityPlayer)player);
|
||||
} else if (packet.channel.equals("WarpDriveFreq")) {
|
||||
handleFreqUpdate(packet, (EntityPlayer)player);
|
||||
|
@ -37,144 +41,143 @@ public class PacketHandler implements IPacketHandler {
|
|||
}
|
||||
}
|
||||
|
||||
public static void handleCloak(Packet250CustomPayload packet, EntityPlayer player) {
|
||||
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
|
||||
public static void handleCloak(Packet250CustomPayload packet, EntityPlayer player) {
|
||||
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
|
||||
|
||||
try {
|
||||
// Read cloaked area parameters
|
||||
int minX = inputStream.readInt();
|
||||
int minY = inputStream.readInt();
|
||||
int minZ = inputStream.readInt();
|
||||
|
||||
int maxX = inputStream.readInt();
|
||||
int maxY = inputStream.readInt();
|
||||
int maxZ = inputStream.readInt();
|
||||
|
||||
boolean decloak = inputStream.readBoolean();
|
||||
|
||||
byte tier = inputStream.readByte();
|
||||
|
||||
// WarpDrive.debugPrint("[Cloak Packet] Received " + ((decloak) ?
|
||||
// "DEcloaked" : "cloaked") + "area: (" + minX + "; " + minY + "; "
|
||||
// + minZ + ") -> (" + maxX + "; " + maxY + "; " + maxZ + ")");
|
||||
|
||||
if (minX <= player.posX && (maxX + 1) > player.posY && minY <= player.posZ && (maxY + 1) > player.posX && minZ <= player.posY
|
||||
&& (maxZ + 1) > player.posZ) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Read cloaked area parameters
|
||||
int minX = inputStream.readInt();
|
||||
int minY = inputStream.readInt();
|
||||
int minZ = inputStream.readInt();
|
||||
|
||||
int maxX = inputStream.readInt();
|
||||
int maxY = inputStream.readInt();
|
||||
int maxZ = inputStream.readInt();
|
||||
|
||||
boolean decloak = inputStream.readBoolean();
|
||||
|
||||
byte tier = inputStream.readByte();
|
||||
|
||||
//WarpDrive.debugPrint("[Cloak Packet] Received " + ((decloak) ? "DEcloaked" : "cloaked") + "area: (" + minX + "; " + minY + "; " + minZ + ") -> (" + maxX + "; " + maxY + "; " + maxZ + ")");
|
||||
|
||||
if (minX <= player.posX && (maxX + 1) > player.posY && minY <= player.posZ && (maxY + 1) > player.posX && minZ <= player.posY && (maxZ + 1) > player.posZ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide the area
|
||||
if (!decloak) {
|
||||
//WarpDrive.debugPrint("[Cloak Packet] Removing " + size + " blocks...");
|
||||
|
||||
// Now hide the blocks within area
|
||||
World worldObj = player.worldObj;
|
||||
int cloakBlockID = (tier == 1) ? WarpDriveConfig.gasID : 0;
|
||||
int cloakBlockMetadata = (tier == 1) ? 5 : 0;
|
||||
int minYmap = Math.max( 0, minY);
|
||||
int maxYmap = Math.min(255, maxY);
|
||||
// WarpDrive.debugPrint("[Cloak Packet] Removing " + size +
|
||||
// " blocks...");
|
||||
|
||||
// Now hide the blocks within area
|
||||
World worldObj = player.worldObj;
|
||||
int cloakBlockID = (tier == 1) ? WarpDriveConfig.gasID : 0;
|
||||
int cloakBlockMetadata = (tier == 1) ? 5 : 0;
|
||||
int minYmap = Math.max(0, minY);
|
||||
int maxYmap = Math.min(255, maxY);
|
||||
for (int y = minYmap; y <= maxYmap; y++) {
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
for(int z = minZ; z <= maxZ; z++) {
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
int blockID = worldObj.getBlockId(x, y, z);
|
||||
if (blockID != 0) {
|
||||
if (blockID != 0) {
|
||||
boolean isSafe = true;
|
||||
if (blockID == WarpDriveConfig.CC_peripheral) {
|
||||
int blockMetadata = worldObj.getBlockMetadata(x, y, z);
|
||||
isSafe = (blockMetadata != 2 && blockMetadata != 4);
|
||||
}
|
||||
if (isSafe) {
|
||||
worldObj.setBlock(x, y, z, cloakBlockID, cloakBlockMetadata, 4);
|
||||
}
|
||||
}
|
||||
if (blockID == WarpDriveConfig.CC_peripheral) {
|
||||
int blockMetadata = worldObj.getBlockMetadata(x, y, z);
|
||||
isSafe = (blockMetadata != 2 && blockMetadata != 4);
|
||||
}
|
||||
if (isSafe) {
|
||||
worldObj.setBlock(x, y, z, cloakBlockID, cloakBlockMetadata, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//WarpDrive.debugPrint("[Cloak Packet] Removing entity...");
|
||||
// Hide any entities inside area
|
||||
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1);
|
||||
List<Entity> list = worldObj.getEntitiesWithinAABBExcludingEntity(player, aabb);
|
||||
for (Entity e : list) {
|
||||
worldObj.removeEntity(e);
|
||||
((WorldClient)worldObj).removeEntityFromWorld(e.entityId);
|
||||
}
|
||||
} else { // reveal the area
|
||||
player.worldObj.markBlockRangeForRenderUpdate(minX - 1, Math.max(0, minY - 1), minZ - 1, maxX + 1, Math.min(255, maxY + 1), maxZ + 1);
|
||||
|
||||
// Make some graphics
|
||||
int numLasers = 80 + player.worldObj.rand.nextInt(50);
|
||||
|
||||
double centerX = (minX + maxX) / 2.0D;
|
||||
double centerY = (minY + maxY) / 2.0D;
|
||||
double centerZ = (minZ + maxZ) / 2.0D;
|
||||
double radiusX = (maxX - minX) / 2.0D + 5.0D;
|
||||
double radiusY = (maxY - minY) / 2.0D + 5.0D;
|
||||
double radiusZ = (maxZ - minZ) / 2.0D + 5.0D;
|
||||
|
||||
for (int i = 0; i < numLasers; i++) {
|
||||
WarpDrive.proxy.renderBeam(player.worldObj,
|
||||
new Vector3(
|
||||
centerX + radiusX * player.worldObj.rand.nextGaussian(),
|
||||
centerY + radiusY * player.worldObj.rand.nextGaussian(),
|
||||
centerZ + radiusZ * player.worldObj.rand.nextGaussian()),
|
||||
new Vector3(
|
||||
centerX + radiusX * player.worldObj.rand.nextGaussian(),
|
||||
centerY + radiusY * player.worldObj.rand.nextGaussian(),
|
||||
centerZ + radiusZ * player.worldObj.rand.nextGaussian()),
|
||||
player.worldObj.rand.nextFloat(), player.worldObj.rand.nextFloat(), player.worldObj.rand.nextFloat(),
|
||||
60 + player.worldObj.rand.nextInt(60), 100);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleLaserTargeting(Packet250CustomPayload packet, EntityPlayer player) {
|
||||
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
|
||||
|
||||
try {
|
||||
int x = inputStream.readInt();
|
||||
int y = inputStream.readInt();
|
||||
int z = inputStream.readInt();
|
||||
float yaw = inputStream.readFloat();
|
||||
float pitch = inputStream.readFloat();
|
||||
WarpDrive.debugPrint("Received target packet: (" + x + "; " + y + "; " + z + ") yaw: " + yaw + " pitch: " + pitch);
|
||||
TileEntity te = player.worldObj.getBlockTileEntity(x, y, z);
|
||||
if (te != null && te instanceof TileEntityLaser) {
|
||||
TileEntityLaser laser = (TileEntityLaser)te;
|
||||
laser.initiateBeamEmission(yaw, pitch);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// WarpDrive.debugPrint("[Cloak Packet] Removing entity...");
|
||||
// Hide any entities inside area
|
||||
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1);
|
||||
List<Entity> list = worldObj.getEntitiesWithinAABBExcludingEntity(player, aabb);
|
||||
for (Entity e : list) {
|
||||
worldObj.removeEntity(e);
|
||||
((WorldClient) worldObj).removeEntityFromWorld(e.entityId);
|
||||
}
|
||||
} else { // reveal the area
|
||||
player.worldObj.markBlockRangeForRenderUpdate(minX - 1, Math.max(0, minY - 1), minZ - 1, maxX + 1, Math.min(255, maxY + 1), maxZ + 1);
|
||||
|
||||
// Make some graphics
|
||||
int numLasers = 80 + player.worldObj.rand.nextInt(50);
|
||||
|
||||
double centerX = (minX + maxX) / 2.0D;
|
||||
double centerY = (minY + maxY) / 2.0D;
|
||||
double centerZ = (minZ + maxZ) / 2.0D;
|
||||
double radiusX = (maxX - minX) / 2.0D + 5.0D;
|
||||
double radiusY = (maxY - minY) / 2.0D + 5.0D;
|
||||
double radiusZ = (maxZ - minZ) / 2.0D + 5.0D;
|
||||
|
||||
for (int i = 0; i < numLasers; i++) {
|
||||
WarpDrive.proxy.renderBeam(player.worldObj, new Vector3(centerX + radiusX * player.worldObj.rand.nextGaussian(), centerY + radiusY
|
||||
* player.worldObj.rand.nextGaussian(), centerZ + radiusZ * player.worldObj.rand.nextGaussian()), new Vector3(centerX + radiusX
|
||||
* player.worldObj.rand.nextGaussian(), centerY + radiusY * player.worldObj.rand.nextGaussian(), centerZ + radiusZ
|
||||
* player.worldObj.rand.nextGaussian()), player.worldObj.rand.nextFloat(), player.worldObj.rand.nextFloat(),
|
||||
player.worldObj.rand.nextFloat(), 60 + player.worldObj.rand.nextInt(60), 100);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleFreqUpdate(Packet250CustomPayload packet, EntityPlayer player) {
|
||||
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
|
||||
public static void handleLaserTargeting(Packet250CustomPayload packet, EntityPlayer player) {
|
||||
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
|
||||
|
||||
try {
|
||||
int x = inputStream.readInt();
|
||||
int y = inputStream.readInt();
|
||||
int z = inputStream.readInt();
|
||||
int frequency = inputStream.readInt();
|
||||
// WarpDrive.debugPrint("Received frequency packet: (" + x + ", " + y + ", " + z + ") frequency '" + frequency + "'");
|
||||
TileEntity te = player.worldObj.getBlockTileEntity(x, y, z);
|
||||
if (te != null) {
|
||||
if (te instanceof TileEntityMonitor) {
|
||||
((TileEntityMonitor)te).setFrequency(frequency);
|
||||
} else if (te instanceof TileEntityCamera) {
|
||||
((TileEntityCamera)te).setFrequency(frequency);
|
||||
} else if (te instanceof TileEntityLaser) {
|
||||
((TileEntityLaser)te).setCameraFrequency(frequency);
|
||||
} else {
|
||||
WarpDrive.print("Received frequency packet: (" + x + ", " + y + ", " + z + ") is not a valid tile entity");
|
||||
}
|
||||
} else {
|
||||
WarpDrive.print("Received frequency packet: (" + x + ", " + y + ", " + z + ") has no tile entity");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
int x = inputStream.readInt();
|
||||
int y = inputStream.readInt();
|
||||
int z = inputStream.readInt();
|
||||
float yaw = inputStream.readFloat();
|
||||
float pitch = inputStream.readFloat();
|
||||
WarpDrive.debugPrint("Received target packet: (" + x + "; " + y + "; " + z + ") yaw: " + yaw + " pitch: " + pitch);
|
||||
TileEntity te = player.worldObj.getBlockTileEntity(x, y, z);
|
||||
if (te != null && te instanceof TileEntityLaser) {
|
||||
TileEntityLaser laser = (TileEntityLaser) te;
|
||||
laser.initiateBeamEmission(yaw, pitch);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleFreqUpdate(Packet250CustomPayload packet, EntityPlayer player) {
|
||||
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
|
||||
|
||||
try {
|
||||
int x = inputStream.readInt();
|
||||
int y = inputStream.readInt();
|
||||
int z = inputStream.readInt();
|
||||
int frequency = inputStream.readInt();
|
||||
// WarpDrive.debugPrint("Received frequency packet: (" + x + ", " +
|
||||
// y + ", " + z + ") frequency '" + frequency + "'");
|
||||
TileEntity te = player.worldObj.getBlockTileEntity(x, y, z);
|
||||
if (te != null) {
|
||||
if (te instanceof TileEntityMonitor) {
|
||||
((TileEntityMonitor) te).setFrequency(frequency);
|
||||
} else if (te instanceof TileEntityCamera) {
|
||||
((TileEntityCamera) te).setFrequency(frequency);
|
||||
} else if (te instanceof TileEntityLaser) {
|
||||
((TileEntityLaser) te).setCameraFrequency(frequency);
|
||||
} else {
|
||||
WarpDrive.print("Received frequency packet: (" + x + ", " + y + ", " + z + ") is not a valid tile entity");
|
||||
}
|
||||
} else {
|
||||
WarpDrive.print("Received frequency packet: (" + x + ", " + y + ", " + z + ") has no tile entity");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleBeam(Packet250CustomPayload packet, EntityPlayer player) {
|
||||
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
|
||||
|
@ -206,14 +209,16 @@ public class PacketHandler implements IPacketHandler {
|
|||
// Read energy value
|
||||
energy = inputStream.readInt();
|
||||
|
||||
// Render beam
|
||||
// WarpDrive.debugPrint("Received beam packet from " + source + " to " + target + " as RGB " + r + " " + g + " " + b + " age " + age +" energy " + energy);
|
||||
// Render beam
|
||||
// WarpDrive.debugPrint("Received beam packet from " + source +
|
||||
// " to " + target + " as RGB " + r + " " + g + " " + b + " age " +
|
||||
// age +" energy " + energy);
|
||||
|
||||
// To avoid NPE at logging in
|
||||
if (worldObj == null) {
|
||||
WarpDrive.debugPrint("WorldObj is null, ignoring beam packet");
|
||||
return;
|
||||
}
|
||||
// To avoid NPE at logging in
|
||||
if (worldObj == null) {
|
||||
WarpDrive.debugPrint("WorldObj is null, ignoring beam packet");
|
||||
return;
|
||||
}
|
||||
|
||||
WarpDrive.proxy.renderBeam(worldObj, source.clone(), target.clone(), r, g, b, age, energy);
|
||||
} catch (Exception e) {
|
||||
|
@ -221,81 +226,81 @@ public class PacketHandler implements IPacketHandler {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendBeamPacket(World worldObj, Vector3 source, Vector3 dest, float r, float g, float b, int age, int energy, int radius) {
|
||||
Side side = FMLCommonHandler.instance().getEffectiveSide();
|
||||
if (side == Side.SERVER) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
|
||||
DataOutputStream outputStream = new DataOutputStream(bos);
|
||||
|
||||
try {
|
||||
// Write source vector
|
||||
outputStream.writeDouble(source.x);
|
||||
outputStream.writeDouble(source.y);
|
||||
outputStream.writeDouble(source.z);
|
||||
// Write target vector
|
||||
outputStream.writeDouble(dest.x);
|
||||
outputStream.writeDouble(dest.y);
|
||||
outputStream.writeDouble(dest.z);
|
||||
// Write r, g, b of laser
|
||||
outputStream.writeFloat(r);
|
||||
outputStream.writeFloat(g);
|
||||
outputStream.writeFloat(b);
|
||||
// Write age
|
||||
outputStream.writeByte(age);
|
||||
// Write energy value
|
||||
outputStream.writeInt(energy);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
public static void sendBeamPacket(World worldObj, Vector3 source, Vector3 dest, float r, float g, float b, int age, int energy, int radius) {
|
||||
Side side = FMLCommonHandler.instance().getEffectiveSide();
|
||||
if (side == Side.SERVER) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
|
||||
DataOutputStream outputStream = new DataOutputStream(bos);
|
||||
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
packet.channel = "WarpDriveBeam";
|
||||
packet.data = bos.toByteArray();
|
||||
packet.length = bos.size();
|
||||
if (source.distanceTo_square(dest) < 3600 /* 60 * 60 */) {
|
||||
MinecraftServer.getServer().getConfigurationManager().sendToAllNear(
|
||||
(source.intX() + dest.intX()) / 2, (source.intY() + dest.intY()) / 2, (source.intZ() + dest.intZ()) / 2,
|
||||
radius, worldObj.provider.dimensionId, packet);
|
||||
return;
|
||||
}
|
||||
MinecraftServer.getServer().getConfigurationManager().sendToAllNear(
|
||||
source.intX(), source.intY(), source.intZ(),
|
||||
radius, worldObj.provider.dimensionId, packet);
|
||||
|
||||
ByteArrayOutputStream bos2 = new ByteArrayOutputStream(8);
|
||||
DataOutputStream outputStream2 = new DataOutputStream(bos2);
|
||||
try {
|
||||
// Write source vector
|
||||
outputStream.writeDouble(source.x);
|
||||
outputStream.writeDouble(source.y);
|
||||
outputStream.writeDouble(source.z);
|
||||
// Write target vector
|
||||
outputStream.writeDouble(dest.x);
|
||||
outputStream.writeDouble(dest.y);
|
||||
outputStream.writeDouble(dest.z);
|
||||
// Write r, g, b of laser
|
||||
outputStream.writeFloat(r);
|
||||
outputStream.writeFloat(g);
|
||||
outputStream.writeFloat(b);
|
||||
// Write age
|
||||
outputStream.writeByte(age);
|
||||
// Write energy value
|
||||
outputStream.writeInt(energy);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
// Write source vector
|
||||
outputStream2.writeDouble(source.x);
|
||||
outputStream2.writeDouble(source.y);
|
||||
outputStream2.writeDouble(source.z);
|
||||
// Write target vector
|
||||
outputStream2.writeDouble(dest.x);
|
||||
outputStream2.writeDouble(dest.y);
|
||||
outputStream2.writeDouble(dest.z);
|
||||
// Write r, g, b of laser
|
||||
outputStream2.writeFloat(r);
|
||||
outputStream2.writeFloat(g);
|
||||
outputStream2.writeFloat(b);
|
||||
// Write age
|
||||
outputStream2.writeByte(age);
|
||||
// Write energy value
|
||||
outputStream2.writeInt(energy);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
packet.channel = "WarpDriveBeam";
|
||||
packet.data = bos.toByteArray();
|
||||
packet.length = bos.size();
|
||||
if (source.distanceTo_square(dest) < 3600 /* 60 * 60 */) {
|
||||
MinecraftServer
|
||||
.getServer()
|
||||
.getConfigurationManager()
|
||||
.sendToAllNear((source.intX() + dest.intX()) / 2, (source.intY() + dest.intY()) / 2, (source.intZ() + dest.intZ()) / 2, radius,
|
||||
worldObj.provider.dimensionId, packet);
|
||||
return;
|
||||
}
|
||||
MinecraftServer.getServer().getConfigurationManager()
|
||||
.sendToAllNear(source.intX(), source.intY(), source.intZ(), radius, worldObj.provider.dimensionId, packet);
|
||||
|
||||
Packet250CustomPayload packet2 = new Packet250CustomPayload();
|
||||
packet2.channel = "WarpDriveBeam";
|
||||
packet2.data = bos.toByteArray();
|
||||
packet2.length = bos.size();
|
||||
MinecraftServer.getServer().getConfigurationManager().sendToAllNear(
|
||||
dest.intX(), dest.intY(), dest.intZ(),
|
||||
radius, worldObj.provider.dimensionId, packet2);
|
||||
}
|
||||
}
|
||||
ByteArrayOutputStream bos2 = new ByteArrayOutputStream(8);
|
||||
DataOutputStream outputStream2 = new DataOutputStream(bos2);
|
||||
|
||||
try {
|
||||
// Write source vector
|
||||
outputStream2.writeDouble(source.x);
|
||||
outputStream2.writeDouble(source.y);
|
||||
outputStream2.writeDouble(source.z);
|
||||
// Write target vector
|
||||
outputStream2.writeDouble(dest.x);
|
||||
outputStream2.writeDouble(dest.y);
|
||||
outputStream2.writeDouble(dest.z);
|
||||
// Write r, g, b of laser
|
||||
outputStream2.writeFloat(r);
|
||||
outputStream2.writeFloat(g);
|
||||
outputStream2.writeFloat(b);
|
||||
// Write age
|
||||
outputStream2.writeByte(age);
|
||||
// Write energy value
|
||||
outputStream2.writeInt(energy);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
Packet250CustomPayload packet2 = new Packet250CustomPayload();
|
||||
packet2.channel = "WarpDriveBeam";
|
||||
packet2.data = bos.toByteArray();
|
||||
packet2.length = bos.size();
|
||||
MinecraftServer.getServer().getConfigurationManager()
|
||||
.sendToAllNear(dest.intX(), dest.intY(), dest.intZ(), radius, worldObj.provider.dimensionId, packet2);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendFreqPacket(int dimensionId, int xCoord, int yCoord, int zCoord, int frequency) {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
|
||||
|
@ -316,7 +321,9 @@ public class PacketHandler implements IPacketHandler {
|
|||
packet.data = bos.toByteArray();
|
||||
packet.length = bos.size();
|
||||
MinecraftServer.getServer().getConfigurationManager().sendToAllNear(xCoord, yCoord, zCoord, 100, dimensionId, packet);
|
||||
// WarpDrive.debugPrint("Packet '" + packet.channel + "' sent (" + xCoord + ", " + yCoord + ", " + zCoord + ") '" + frequency + "'");
|
||||
// WarpDrive.debugPrint("Packet '" + packet.channel + "' sent (" +
|
||||
// xCoord + ", " + yCoord + ", " + zCoord + ") '" + frequency +
|
||||
// "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -325,7 +332,7 @@ public class PacketHandler implements IPacketHandler {
|
|||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
|
||||
DataOutputStream outputStream = new DataOutputStream(bos);
|
||||
|
||||
|
||||
try {
|
||||
outputStream.writeInt(x);
|
||||
outputStream.writeInt(y);
|
||||
|
@ -335,7 +342,7 @@ public class PacketHandler implements IPacketHandler {
|
|||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
packet.channel = "WarpDriveLaserT";
|
||||
packet.data = bos.toByteArray();
|
||||
|
@ -344,34 +351,35 @@ public class PacketHandler implements IPacketHandler {
|
|||
WarpDrive.debugPrint("Packet '" + packet.channel + "' sent (" + x + ", " + y + ", " + z + ") yaw " + yaw + " pitch " + pitch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Sending cloaking area definition (server -> client)
|
||||
public static void sendCloakPacket(EntityPlayer player, AxisAlignedBB aabb, int tier, boolean decloak) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
|
||||
DataOutputStream outputStream = new DataOutputStream(bos);
|
||||
|
||||
|
||||
try {
|
||||
outputStream.writeInt((int) aabb.minX);
|
||||
outputStream.writeInt((int) aabb.minY);
|
||||
outputStream.writeInt((int) aabb.minZ);
|
||||
|
||||
|
||||
outputStream.writeInt((int) aabb.maxX);
|
||||
outputStream.writeInt((int) aabb.maxY);
|
||||
outputStream.writeInt((int) aabb.maxZ);
|
||||
|
||||
|
||||
outputStream.writeBoolean(decloak);
|
||||
|
||||
|
||||
outputStream.writeByte(tier);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
// WarpDrive.debugPrint("" + this + " Sending cloak packet to player " + player.username);
|
||||
|
||||
// WarpDrive.debugPrint("" + this + " Sending cloak packet to player " +
|
||||
// player.username);
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
packet.channel = "WarpDriveCloaks";
|
||||
packet.data = bos.toByteArray();
|
||||
packet.length = bos.size();
|
||||
|
||||
((EntityPlayerMP)player).playerNetServerHandler.sendPacketToPlayer(packet);
|
||||
|
||||
((EntityPlayerMP) player).playerNetServerHandler.sendPacketToPlayer(packet);
|
||||
}
|
||||
}
|
|
@ -8,16 +8,16 @@ import cr0s.warpdrive.WarpDrive;
|
|||
import cr0s.warpdrive.WarpDriveConfig;
|
||||
|
||||
public class TileEntityAirGenerator extends WarpEnergyTE {
|
||||
private final int EU_PER_NEWAIRBLOCK = 12;
|
||||
private final int EU_PER_EXISTINGAIRBLOCK = 4; // 1 solar = 1 EU/t
|
||||
private final int MAX_ENERGY_VALUE = 8 * EU_PER_NEWAIRBLOCK;
|
||||
private final int EU_PER_NEWAIRBLOCK = 12;
|
||||
private final int EU_PER_EXISTINGAIRBLOCK = 4; // 1 solar = 1 EU/t
|
||||
private final int MAX_ENERGY_VALUE = 8 * EU_PER_NEWAIRBLOCK;
|
||||
|
||||
private int cooldownTicks = 0;
|
||||
private final int AIR_GENERATION_TICKS = 40;
|
||||
private final int START_CONCENTRATION_VALUE = 15;
|
||||
private int cooldownTicks = 0;
|
||||
private final int AIR_GENERATION_TICKS = 40;
|
||||
private final int START_CONCENTRATION_VALUE = 15;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
return;
|
||||
}
|
||||
|
@ -26,87 +26,106 @@ public class TileEntityAirGenerator extends WarpEnergyTE {
|
|||
if (this.isInvalid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Air generator works only in spaces
|
||||
if (worldObj.provider.dimensionId != WarpDriveConfig.G_SPACE_DIMENSION_ID && worldObj.provider.dimensionId != WarpDriveConfig.G_HYPERSPACE_DIMENSION_ID) {
|
||||
if (getBlockMetadata() != 0) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 2); // set disabled texture
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
cooldownTicks++;
|
||||
if (cooldownTicks > AIR_GENERATION_TICKS) {
|
||||
if (consumeEnergy(EU_PER_NEWAIRBLOCK, true)) {
|
||||
if (getBlockMetadata() != 1) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 2); // set enabled texture
|
||||
}
|
||||
} else {
|
||||
if (getBlockMetadata() != 0) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 2); // set disabled texture
|
||||
}
|
||||
}
|
||||
releaseAir( 1, 0, 0);
|
||||
releaseAir(-1, 0, 0);
|
||||
releaseAir( 0, 1, 0);
|
||||
releaseAir( 0, -1, 0);
|
||||
releaseAir( 0, 0, 1);
|
||||
releaseAir( 0, 0, -1);
|
||||
// Air generator works only in spaces
|
||||
if (worldObj.provider.dimensionId != WarpDriveConfig.G_SPACE_DIMENSION_ID && worldObj.provider.dimensionId != WarpDriveConfig.G_HYPERSPACE_DIMENSION_ID) {
|
||||
if (getBlockMetadata() != 0) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 2); // set
|
||||
// disabled
|
||||
// texture
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
cooldownTicks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void releaseAir(int xOffset, int yOffset, int zOffset) {
|
||||
Block block = worldObj.getBlock(xCoord + xOffset, yCoord + yOffset, zCoord + zOffset);
|
||||
if (block.isAir(worldObj, xOffset, yOffset, zOffset)) {// can be air
|
||||
int energy_cost = (!block.isAssociatedBlock(WarpDrive.airBlock)) ? EU_PER_NEWAIRBLOCK : EU_PER_EXISTINGAIRBLOCK;
|
||||
if (consumeEnergy(energy_cost, true)) {// enough energy
|
||||
if (worldObj.setBlock(xCoord + xOffset, yCoord + yOffset, zCoord + zOffset, WarpDrive.airBlock, START_CONCENTRATION_VALUE, 2)) {// needs to renew air or was not maxed out
|
||||
consumeEnergy(EU_PER_NEWAIRBLOCK, false);
|
||||
} else {
|
||||
consumeEnergy(EU_PER_EXISTINGAIRBLOCK, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{// low energy => remove air block
|
||||
if (block.isAssociatedBlock(WarpDrive.airBlock)){
|
||||
int metadata = worldObj.getBlockMetadata(xCoord + xOffset, yCoord + yOffset, zCoord + zOffset);
|
||||
if (metadata > 4) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord + xOffset, yCoord + yOffset, zCoord + zOffset, metadata - 4, 2);
|
||||
} else if (metadata > 1) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord + xOffset, yCoord + yOffset, zCoord + zOffset, 1, 2);
|
||||
} else {
|
||||
// worldObj.setBlock(xCoord + xOffset, yCoord + yOffset, zCoord + zOffset, 0, 0, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cooldownTicks++;
|
||||
if (cooldownTicks > AIR_GENERATION_TICKS) {
|
||||
if (consumeEnergy(EU_PER_NEWAIRBLOCK, true)) {
|
||||
if (getBlockMetadata() != 1) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 2); // set
|
||||
// enabled
|
||||
// texture
|
||||
}
|
||||
} else {
|
||||
if (getBlockMetadata() != 0) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 2); // set
|
||||
// disabled
|
||||
// texture
|
||||
}
|
||||
}
|
||||
releaseAir(1, 0, 0);
|
||||
releaseAir(-1, 0, 0);
|
||||
releaseAir(0, 1, 0);
|
||||
releaseAir(0, -1, 0);
|
||||
releaseAir(0, 0, 1);
|
||||
releaseAir(0, 0, -1);
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
}
|
||||
cooldownTicks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
}
|
||||
private void releaseAir(int xOffset, int yOffset, int zOffset) {
|
||||
Block block = worldObj.getBlock(xCoord + xOffset, yCoord + yOffset, zCoord + zOffset);
|
||||
if (block.isAir(worldObj, xOffset, yOffset, zOffset)) {// can be air
|
||||
int energy_cost = (!block.isAssociatedBlock(WarpDrive.airBlock)) ? EU_PER_NEWAIRBLOCK : EU_PER_EXISTINGAIRBLOCK;
|
||||
if (consumeEnergy(energy_cost, true)) {// enough energy
|
||||
if (worldObj.setBlock(xCoord + xOffset, yCoord + yOffset, zCoord + zOffset, WarpDrive.airBlock, START_CONCENTRATION_VALUE, 2)) {// needs
|
||||
// to
|
||||
// renew
|
||||
// air
|
||||
// or
|
||||
// was
|
||||
// not
|
||||
// maxed
|
||||
// out
|
||||
consumeEnergy(EU_PER_NEWAIRBLOCK, false);
|
||||
} else {
|
||||
consumeEnergy(EU_PER_EXISTINGAIRBLOCK, false);
|
||||
}
|
||||
} else {// low energy => remove air block
|
||||
if (block.isAssociatedBlock(WarpDrive.airBlock)) {
|
||||
int metadata = worldObj.getBlockMetadata(xCoord + xOffset, yCoord + yOffset, zCoord + zOffset);
|
||||
if (metadata > 4) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord + xOffset, yCoord + yOffset, zCoord + zOffset, metadata - 4, 2);
|
||||
} else if (metadata > 1) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord + xOffset, yCoord + yOffset, zCoord + zOffset, 1, 2);
|
||||
} else {
|
||||
// worldObj.setBlock(xCoord + xOffset, yCoord + yOffset,
|
||||
// zCoord + zOffset, 0, 0, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return MAX_ENERGY_VALUE;
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
}
|
||||
|
||||
// IEnergySink methods implementation
|
||||
@Override
|
||||
public int getMaxSafeInput() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return MAX_ENERGY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSinkTier() {
|
||||
// TODO Auto-generated method stub
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourceTier() {
|
||||
// TODO Auto-generated method stub
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -35,30 +36,25 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
int laserTicks = 0;
|
||||
int scanTicks = 0;
|
||||
int deployDelayTicks = 0;
|
||||
|
||||
|
||||
int warpCoreSearchTicks = 0;
|
||||
|
||||
private String schematicFileName;
|
||||
|
||||
private JumpBlock[] blocksToDeploy; // JumpBlock class stores a basic information about block
|
||||
|
||||
private JumpBlock[] blocksToDeploy; // JumpBlock class stores a basic
|
||||
// information about block
|
||||
private int currentDeployIndex;
|
||||
private int blocksToDeployCount;
|
||||
private boolean isDeploying = false;
|
||||
|
||||
|
||||
private int targetX, targetY, targetZ;
|
||||
|
||||
public TileEntityShipScanner() {
|
||||
super();
|
||||
peripheralName = "shipscanner";
|
||||
methodsArray = new String[] {
|
||||
"scan",
|
||||
"fileName",
|
||||
"getEnergyLevel",
|
||||
"deploy",
|
||||
"state"
|
||||
};
|
||||
methodsArray = new String[] { "scan", "fileName", "getEnergyLevel", "deploy", "state" };
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient())
|
||||
|
@ -79,58 +75,58 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
|
||||
if (!isActive) {// inactive
|
||||
if (++laserTicks > 20) {
|
||||
PacketHandler.sendBeamPacket(worldObj,
|
||||
new Vector3(this).translate(0.5D), new Vector3(core.xCoord, core.yCoord, core.zCoord).translate(0.5D),
|
||||
PacketHandler.sendBeamPacket(worldObj, new Vector3(this).translate(0.5D), new Vector3(core.xCoord, core.yCoord, core.zCoord).translate(0.5D),
|
||||
0f, 1f, 0f, 40, 0, 100);
|
||||
laserTicks = 0;
|
||||
}
|
||||
} else if (!isDeploying) {// active and scanning
|
||||
if (++laserTicks > 5) {
|
||||
laserTicks = 0;
|
||||
|
||||
|
||||
for (int i = 0; i < core.maxX - core.minX; i++) {
|
||||
int x = core.minX + i;
|
||||
int randomZ = core.minZ + worldObj.rand.nextInt(core.maxZ - core.minZ);
|
||||
|
||||
|
||||
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
|
||||
float r = 0.0f, g = 0.0f, b = 0.0f;
|
||||
|
||||
|
||||
switch (worldObj.rand.nextInt(6)) {
|
||||
case 0:
|
||||
r = 1.0f;
|
||||
g = b = 0;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
r = b = 0;
|
||||
g = 1.0f;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
r = g = 0;
|
||||
b = 1.0f;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
r = b = 0.5f;
|
||||
g = 0;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
r = g = 1.0f;
|
||||
b = 0;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
r = 1.0f;
|
||||
b = 0.5f;
|
||||
g = 0f;
|
||||
case 0:
|
||||
r = 1.0f;
|
||||
g = b = 0;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
r = b = 0;
|
||||
g = 1.0f;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
r = g = 0;
|
||||
b = 1.0f;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
r = b = 0.5f;
|
||||
g = 0;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
r = g = 1.0f;
|
||||
b = 0;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
r = 1.0f;
|
||||
b = 0.5f;
|
||||
g = 0f;
|
||||
}
|
||||
|
||||
PacketHandler.sendBeamPacket(worldObj, new Vector3(this).translate(0.5D), new Vector3(x, core.maxY, randomZ).translate(0.5D), r, g, b, 15, 0, 100);
|
||||
|
||||
PacketHandler.sendBeamPacket(worldObj, new Vector3(this).translate(0.5D), new Vector3(x, core.maxY, randomZ).translate(0.5D), r, g, b, 15,
|
||||
0, 100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (++scanTicks > 20 * (1 + core.shipVolume / 10)) {
|
||||
setActive(false); // disable scanner
|
||||
scanTicks = 0;
|
||||
|
@ -138,9 +134,9 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
} else {// active and deploying
|
||||
if (++deployDelayTicks < 20)
|
||||
return;
|
||||
|
||||
|
||||
deployDelayTicks = 0;
|
||||
|
||||
|
||||
int blocks = Math.min(WarpDriveConfig.G_BLOCKS_PER_TICK, blocksToDeployCount - currentDeployIndex);
|
||||
|
||||
if (blocks == 0) {
|
||||
|
@ -148,37 +144,31 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
setActive(false); // disable scanner
|
||||
return;
|
||||
}
|
||||
|
||||
for (int index = 0; index < blocks; index++)
|
||||
{
|
||||
if (currentDeployIndex >= blocksToDeployCount)
|
||||
{
|
||||
|
||||
for (int index = 0; index < blocks; index++) {
|
||||
if (currentDeployIndex >= blocksToDeployCount) {
|
||||
isDeploying = false;
|
||||
setActive(false); // disable scanner
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// Deploy single block
|
||||
JumpBlock jb = blocksToDeploy[currentDeployIndex];
|
||||
|
||||
if (jb != null &&
|
||||
!jb.block.isAssociatedBlock(Blocks.bedrock) &&
|
||||
!WarpDriveConfig.scannerIgnoreBlocks.contains(jb.block) &&
|
||||
worldObj.isAirBlock(targetX + jb.x, targetY + jb.y, targetZ + jb.z)) {
|
||||
|
||||
if (jb != null && !jb.block.isAssociatedBlock(Blocks.bedrock) && !WarpDriveConfig.scannerIgnoreBlocks.contains(jb.block)
|
||||
&& worldObj.isAirBlock(targetX + jb.x, targetY + jb.y, targetZ + jb.z)) {
|
||||
jb.deploy(worldObj, targetX, targetY, targetZ);
|
||||
|
||||
|
||||
if (worldObj.rand.nextInt(100) <= 10) {
|
||||
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
|
||||
|
||||
PacketHandler.sendBeamPacket(worldObj,
|
||||
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);
|
||||
|
||||
PacketHandler.sendBeamPacket(worldObj, 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
currentDeployIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,12 +185,20 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
|
||||
// Search for warp cores above
|
||||
for (int newY = yCoord + 1; newY <= 255; newY++) {
|
||||
if (worldObj.getBlock(xCoord, newY, zCoord).isAssociatedBlock(WarpDrive.warpCore)) { // found warp core above
|
||||
result = (TileEntityReactor) worldObj.getTileEntity(
|
||||
xCoord, newY, zCoord);
|
||||
if (worldObj.getBlock(xCoord, newY, zCoord).isAssociatedBlock(WarpDrive.warpCore)) { // found
|
||||
// warp
|
||||
// core
|
||||
// above
|
||||
result = (TileEntityReactor) worldObj.getTileEntity(xCoord, newY, zCoord);
|
||||
|
||||
if (result != null) {
|
||||
if (!result.validateShipSpatialParameters(reason)) { // If we can't refresh ship's spatial parameters
|
||||
if (!result.validateShipSpatialParameters(reason)) { // If
|
||||
// we
|
||||
// can't
|
||||
// refresh
|
||||
// ship's
|
||||
// spatial
|
||||
// parameters
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
|
@ -211,7 +209,7 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private int getScanningEnergyCost(int size) {
|
||||
if (WarpDriveConfig.SS_EU_PER_BLOCK_SCAN > 0) {
|
||||
return size * WarpDriveConfig.SS_EU_PER_BLOCK_SCAN;
|
||||
|
@ -219,7 +217,7 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
return WarpDriveConfig.SS_MAX_ENERGY_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int getDeploymentEnergyCost(int size) {
|
||||
if (WarpDriveConfig.SS_EU_PER_BLOCK_DEPLOY > 0) {
|
||||
return size * WarpDriveConfig.SS_EU_PER_BLOCK_DEPLOY;
|
||||
|
@ -227,68 +225,70 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
return WarpDriveConfig.SS_MAX_ENERGY_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean saveShipToSchematic(String fileName, StringBuilder reason) {
|
||||
NBTTagCompound schematic = new NBTTagCompound();
|
||||
|
||||
short width = (short) (core.maxX - core.minX + 1);
|
||||
short width = (short) (core.maxX - core.minX + 1);
|
||||
short length = (short) (core.maxZ - core.minZ + 1);
|
||||
short height = (short) (core.maxY - core.minY + 1);
|
||||
|
||||
|
||||
if (width <= 0 || length <= 0 || height <= 0) {
|
||||
reason.append("Invalid ship dimensions, nothing to scan");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
schematic.setShort("Width", width);
|
||||
schematic.setShort("Length", length);
|
||||
schematic.setShort("Height", height);
|
||||
|
||||
|
||||
int size = width * length * height;
|
||||
|
||||
|
||||
// Consume energy
|
||||
if (!consumeEnergy(getScanningEnergyCost(size), false)) {
|
||||
reason.append("Insufficient energy (" + getScanningEnergyCost(size) + " required)");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
byte localBlocks[] = new byte[size];
|
||||
byte localMetadata[] = new byte[size];
|
||||
byte extraBlocks[] = new byte[size];
|
||||
byte extraBlocksNibble[] = new byte[(int) Math.ceil(size / 2.0)];
|
||||
boolean extra = false;
|
||||
|
||||
NBTTagList tileEntitiesList = new NBTTagList();
|
||||
|
||||
NBTTagList tileEntitiesList = new NBTTagList();
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int z = 0; z < length; z++) {
|
||||
Block block = worldObj.getBlock(core.minX + x, core.minY + y, core.minZ + z);
|
||||
|
||||
// Do not scan air, bedrock and specified forbidden blocks (like ore or Warp-Cores)
|
||||
if (worldObj.isAirBlock(core.minX + x, core.minY + y, core.minZ + z) || block.isAssociatedBlock(Blocks.bedrock) || WarpDriveConfig.scannerIgnoreBlocks.contains(block)) {
|
||||
|
||||
// Do not scan air, bedrock and specified forbidden blocks
|
||||
// (like ore or Warp-Cores)
|
||||
if (worldObj.isAirBlock(core.minX + x, core.minY + y, core.minZ + z) || block.isAssociatedBlock(Blocks.bedrock)
|
||||
|| WarpDriveConfig.scannerIgnoreBlocks.contains(block)) {
|
||||
block = Blocks.air;
|
||||
}
|
||||
|
||||
|
||||
localBlocks[x + (y * length + z) * width] = (byte) block.getUnlocalizedName();
|
||||
localMetadata[x + (y * length + z) * width] = (byte) worldObj.getBlockMetadata(core.minX + x, core.minY + y, core.minZ + z);
|
||||
if ((extraBlocks[x + (y * length + z) * width] = (byte) (block >> 8)) > 0) {
|
||||
extra = true;
|
||||
}
|
||||
|
||||
|
||||
if (!block.isAssociatedBlock(Blocks.air)) {
|
||||
TileEntity te = worldObj.getTileEntity(core.minX + x, core.minY + y, core.minZ + z);
|
||||
if (te != null) {
|
||||
try {
|
||||
NBTTagCompound tileTag = new NBTTagCompound();
|
||||
te.writeToNBT(tileTag);
|
||||
|
||||
|
||||
// Clear inventory.
|
||||
if (te instanceof IInventory) {
|
||||
TileEntity tmp_te = TileEntity.createAndLoadEntity(tileTag);
|
||||
if (tmp_te instanceof IInventory) {
|
||||
for (int i = 0; i < ((IInventory)tmp_te).getSizeInventory(); i++) {
|
||||
((IInventory)tmp_te).setInventorySlotContents(i, null);
|
||||
for (int i = 0; i < ((IInventory) tmp_te).getSizeInventory(); i++) {
|
||||
((IInventory) tmp_te).setInventorySlotContents(i, null);
|
||||
}
|
||||
}
|
||||
tmp_te.writeToNBT(tileTag);
|
||||
|
@ -305,12 +305,13 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
tileTag.setInteger("mStoredEnergy", 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Transform TE's coordinates from local axis to .schematic offset-axis
|
||||
|
||||
// Transform TE's coordinates from local axis to
|
||||
// .schematic offset-axis
|
||||
tileTag.setInteger("x", te.xCoord - core.minX);
|
||||
tileTag.setInteger("y", te.yCoord - core.minY);
|
||||
tileTag.setInteger("z", te.zCoord - core.minZ);
|
||||
|
||||
|
||||
tileEntitiesList.appendTag(tileTag);
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
|
@ -332,21 +333,21 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
schematic.setString("Materials", "Alpha");
|
||||
schematic.setByteArray("Blocks", localBlocks);
|
||||
schematic.setByteArray("Data", localMetadata);
|
||||
|
||||
|
||||
if (extra)
|
||||
schematic.setByteArray("AddBlocks", extraBlocksNibble);
|
||||
|
||||
|
||||
schematic.setTag("Entities", new NBTTagList()); // don't save entities
|
||||
schematic.setTag("TileEntities", tileEntitiesList);
|
||||
|
||||
schematic.setTag("TileEntities", tileEntitiesList);
|
||||
|
||||
writeNBTToFile(fileName, schematic);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void writeNBTToFile(String fileName, NBTTagCompound nbttagcompound) {
|
||||
WarpDrive.print(this + " Filename: " + fileName);
|
||||
|
||||
|
||||
try {
|
||||
File file = new File(fileName);
|
||||
if (!file.exists()) {
|
||||
|
@ -374,9 +375,7 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
|
||||
// Generate unique file name
|
||||
do {
|
||||
schematicFileName = (new StringBuilder().append(core.coreFrequency)
|
||||
.append(System.currentTimeMillis()).append(".schematic"))
|
||||
.toString();
|
||||
schematicFileName = (new StringBuilder().append(core.coreFrequency).append(System.currentTimeMillis()).append(".schematic")).toString();
|
||||
} while (new File(WarpDriveConfig.G_SCHEMALOCATION + "/" + schematicFileName).exists());
|
||||
|
||||
if (!saveShipToSchematic(WarpDriveConfig.G_SCHEMALOCATION + "/" + schematicFileName, reason)) {
|
||||
|
@ -392,20 +391,20 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
FileInputStream fileinputstream = new FileInputStream(file);
|
||||
NBTTagCompound nbttagcompound = CompressedStreamTools.readCompressed(fileinputstream);
|
||||
|
||||
fileinputstream.close();
|
||||
|
||||
|
||||
return nbttagcompound;
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// Returns error code and reason string
|
||||
private int deployShip(String fileName, int offsetX, int offsetY, int offsetZ, StringBuilder reason) {
|
||||
// Load schematic
|
||||
|
@ -414,17 +413,17 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
reason.append("Schematic not found or unknow error reading it.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// Compute geometry
|
||||
short width = schematic.getShort("Width");
|
||||
short height = schematic.getShort("Height");
|
||||
short length = schematic.getShort("Length");
|
||||
|
||||
|
||||
targetX = xCoord + offsetX;
|
||||
targetY = yCoord + offsetY;
|
||||
targetZ = zCoord + offsetZ;
|
||||
blocksToDeployCount = width * height * length;
|
||||
|
||||
|
||||
// Validate context
|
||||
{
|
||||
// Check distance
|
||||
|
@ -432,18 +431,18 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
double dY = yCoord - targetY;
|
||||
double dZ = zCoord - targetZ;
|
||||
double distance = MathHelper.sqrt_double(dX * dX + dY * dY + dZ * dZ);
|
||||
|
||||
|
||||
if (distance > WarpDriveConfig.SS_MAX_DEPLOY_RADIUS_BLOCKS) {
|
||||
reason.append("Cannot deploy ship so far away from scanner.");
|
||||
return 5;
|
||||
}
|
||||
|
||||
|
||||
// Consume energy
|
||||
if (!consumeEnergy(getDeploymentEnergyCost(blocksToDeployCount), false)) {
|
||||
reason.append("Insufficient energy (" + getDeploymentEnergyCost(blocksToDeployCount) + " required)");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Check specified area for occupation by blocks
|
||||
// If specified area occupied, break deploying with error message
|
||||
int occupiedBlockCount = 0;
|
||||
|
@ -460,12 +459,12 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set deployment variables
|
||||
blocksToDeploy = new JumpBlock[blocksToDeployCount];
|
||||
isDeploying = true;
|
||||
currentDeployIndex = 0;
|
||||
|
||||
|
||||
// Read blocks and TileEntities from NBT to internal storage array
|
||||
byte localBlocks[] = schematic.getByteArray("Blocks");
|
||||
byte localMetadata[] = schematic.getByteArray("Data");
|
||||
|
@ -482,27 +481,27 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
} else if (schematic.hasKey("Add")) {
|
||||
extraBlocks = schematic.getByteArray("Add");
|
||||
}
|
||||
|
||||
|
||||
// Load Tile Entities
|
||||
NBTTagCompound[] tileEntities = new NBTTagCompound[blocksToDeployCount];
|
||||
NBTTagList tileEntitiesList = schematic.getTagList("TileEntities");
|
||||
NBTTagList tileEntitiesList = schematic.getTagList("TileEntities", 0); //TODO: 0 is not corect
|
||||
|
||||
for (int i = 0; i < tileEntitiesList.tagCount(); i++) {
|
||||
NBTTagCompound teTag = (NBTTagCompound) tileEntitiesList.tagAt(i);
|
||||
NBTTagCompound teTag = tileEntitiesList.getCompoundTagAt(i);
|
||||
int teX = teTag.getInteger("x");
|
||||
int teY = teTag.getInteger("y");
|
||||
int teZ = teTag.getInteger("z");
|
||||
|
||||
|
||||
tileEntities[teX + (teY * length + teZ) * width] = teTag;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Create list of blocks to deploy
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int z = 0; z < length; z++) {
|
||||
int index = x + (y * length + z) * width;
|
||||
JumpBlock jb = new JumpBlock();
|
||||
|
||||
|
||||
jb.x = x;
|
||||
jb.y = y;
|
||||
jb.z = z;
|
||||
|
@ -512,29 +511,29 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
}
|
||||
jb.blockMeta = (localMetadata[index]) & 0xFF;
|
||||
jb.blockNBT = tileEntities[index];
|
||||
|
||||
|
||||
if (jb.block != 0 && Block.blocksList[jb.block] != null) {
|
||||
if (tileEntities[index] == null) {
|
||||
WarpDrive.debugPrint("[ShipScanner] Adding block to deploy: " + Block.blocksList[jb.block].getUnlocalizedName() + " (no tile entity)");
|
||||
WarpDrive.debugPrint("[ShipScanner] Adding block to deploy: " + Block.blocksList[jb.block.getUnlocalizedName() + " (no tile entity)");
|
||||
} else {
|
||||
WarpDrive.debugPrint("[ShipScanner] Adding block to deploy: " + Block.blocksList[jb.block].getUnlocalizedName() + " with tile entity " + tileEntities[index].getString("id"));
|
||||
}
|
||||
|
||||
|
||||
blocksToDeploy[index] = jb;
|
||||
} else {
|
||||
jb = null;
|
||||
|
||||
|
||||
blocksToDeploy[index] = jb;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setActive(true);
|
||||
reason.append("Ship deploying...");
|
||||
return 3;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
|
@ -563,13 +562,13 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
private Object[] deploy(Context context, Arguments arguments) {
|
||||
return deploy(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
|
||||
private Object[] scan(Object[] arguments) {
|
||||
// Already scanning?
|
||||
if (isActive) {
|
||||
return new Object[] { false, 0, "Already active" };
|
||||
}
|
||||
|
||||
|
||||
if (core == null) {
|
||||
return new Object[] { false, 1, "Warp-Core not found" };
|
||||
} else if (!consumeEnergy(getScanningEnergyCost(core.shipVolume), true)) {
|
||||
|
@ -580,7 +579,7 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
return new Object[] { success, 3, reason.toString() };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Object[] filename(Object[] arguments) {
|
||||
if (isActive && !schematicFileName.isEmpty()) {
|
||||
if (isDeploying) {
|
||||
|
@ -589,17 +588,17 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
return new Object[] { "Scan in progress. Please wait..." };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return new Object[] { schematicFileName };
|
||||
}
|
||||
|
||||
|
||||
private Object[] deploy(Object[] arguments) {
|
||||
if (arguments.length == 4) {
|
||||
String fileName = (String)arguments[0];
|
||||
String fileName = (String) arguments[0];
|
||||
int x = toInt(arguments[1]);
|
||||
int y = toInt(arguments[2]);
|
||||
int z = toInt(arguments[3]);
|
||||
|
||||
|
||||
if (!new File(WarpDriveConfig.G_SCHEMALOCATION + "/" + fileName).exists()) {
|
||||
return new Object[] { 0, "Specified .schematic file was not found!" };
|
||||
} else {
|
||||
|
@ -611,7 +610,7 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
return new Object[] { 4, "Invalid arguments count, you need .schematic file name, offsetX, offsetY and offsetZ!" };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Object[] state(Object[] arguments) {
|
||||
if (!isActive) {
|
||||
return new Object[] { false, "IDLE", 0, 0 };
|
||||
|
@ -621,28 +620,30 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
return new Object[] { true, "Deploying", currentDeployIndex, blocksToDeployCount };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ComputerCraft IPeripheral methods implementation
|
||||
@Override
|
||||
@Optional.Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
|
||||
String methodName = methodsArray[method];
|
||||
String methodName = methodsArray[method];
|
||||
if (methodName.equals("scan")) {
|
||||
return scan(arguments);
|
||||
|
||||
|
||||
} else if (methodName.equals("fileName")) {
|
||||
return filename(arguments);
|
||||
|
||||
|
||||
} else if (methodName.equals("getEnergyLevel")) {
|
||||
return getEnergyLevel();
|
||||
|
||||
} else if (methodName.equals("deploy")) {// deploy(schematicFileName, offsetX, offsetY, offsetZ)
|
||||
|
||||
} else if (methodName.equals("deploy")) {// deploy(schematicFileName,
|
||||
// offsetX, offsetY,
|
||||
// offsetZ)
|
||||
return deploy(arguments);
|
||||
|
||||
|
||||
} else if (methodName.equals("state")) {
|
||||
return state(arguments);
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -651,10 +652,11 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
public int getMaxEnergyStored() {
|
||||
return WarpDriveConfig.SS_MAX_ENERGY_VALUE;
|
||||
}
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSinkTier() {
|
||||
|
|
Loading…
Add table
Reference in a new issue