diff --git a/src/cr0s/WarpDrive/EntityJump.java b/src/cr0s/WarpDrive/EntityJump.java index 7cf9ae9a..459f751b 100644 --- a/src/cr0s/WarpDrive/EntityJump.java +++ b/src/cr0s/WarpDrive/EntityJump.java @@ -81,8 +81,6 @@ public class EntityJump extends Entity private int state = STATE_IDLE; private int currentIndexInShip = 0; - private final int BLOCKS_PER_TICK = 3500; - private List entitiesOnShip; private List ASTurbines; @@ -539,7 +537,7 @@ public class EntityJump extends Entity */ private void removeShip() { LocalProfiler.start("EntityJump.removeShip"); - int blocksToMove = Math.min(BLOCKS_PER_TICK, ship.length - currentIndexInShip); + int blocksToMove = Math.min(WarpDriveConfig.G_BLOCKS_PER_TICK, ship.length - currentIndexInShip); WarpDrive.debugPrint("" + this + " Removing ship blocks " + currentIndexInShip + " to " + (currentIndexInShip + blocksToMove - 1) + " / " + (ship.length - 1)); TileEntity te; Class teClass; @@ -682,7 +680,7 @@ public class EntityJump extends Entity */ private void moveShip() { LocalProfiler.start("EntityJump.moveShip"); - int blocksToMove = Math.min(BLOCKS_PER_TICK, ship.length - currentIndexInShip); + int blocksToMove = Math.min(WarpDriveConfig.G_BLOCKS_PER_TICK, ship.length - currentIndexInShip); WarpDrive.debugPrint("" + this + " Moving ship blocks " + currentIndexInShip + " to " + (currentIndexInShip + blocksToMove - 1) + " / " + (ship.length - 1)); for (int index = 0; index < blocksToMove; index++) { @@ -690,7 +688,13 @@ public class EntityJump extends Entity break; } - moveBlockSimple(currentIndexInShip); + JumpBlock jb = ship[currentIndexInShip]; + if (jb != null) { + jb.deploy(targetWorld, moveX, moveY, moveZ); + if (jb.blockID != WarpDriveConfig.CC_peripheral || (jb.blockMeta != 2 && jb.blockMeta != 4)) { + worldObj.removeBlockTileEntity(jb.x, jb.y, jb.z); + } + } currentIndexInShip++; } @@ -1150,102 +1154,6 @@ public class EntityJump extends Entity } }/**/ - private boolean moveBlockSimple(int indexInShip) { - JumpBlock shipBlock = null; - try { - shipBlock = ship[indexInShip]; - - if (shipBlock == null) { - return false; - } - - int oldX = shipBlock.x; - int oldY = shipBlock.y; - int oldZ = shipBlock.z; - int newX = oldX + moveX; - int newY = oldY + moveY; - int newZ = oldZ + moveZ; - int blockID = shipBlock.blockID; - int blockMeta = shipBlock.blockMeta; - mySetBlock(targetWorld, newX, newY, newZ, blockID, blockMeta, 2); - - // Re-schedule air blocks update - if (blockID == WarpDriveConfig.airID) { - targetWorld.markBlockForUpdate(newX, newY, newZ); - targetWorld.scheduleBlockUpdate(newX, newY, newZ, blockID, 40 + targetWorld.rand.nextInt(20)); - } - - NBTTagCompound oldnbt = new NBTTagCompound(); - if (shipBlock.blockTileEntity != null) { - shipBlock.blockTileEntity.writeToNBT(oldnbt); - oldnbt.setInteger("x", newX); - oldnbt.setInteger("y", newY); - oldnbt.setInteger("z", newZ); - - if (oldnbt.hasKey("mainX") && oldnbt.hasKey("mainY") && oldnbt.hasKey("mainZ")) { // Mekanism 6.0.4.44 - WarpDrive.debugPrint("[JUMP] moveBlockSimple: TileEntity from Mekanism detected"); - oldnbt.setInteger("mainX", oldnbt.getInteger("mainX") + moveX); - oldnbt.setInteger("mainY", oldnbt.getInteger("mainY") + moveY); - oldnbt.setInteger("mainZ", oldnbt.getInteger("mainZ") + moveZ); - } - - TileEntity newTileEntity = null; - boolean isForgeMultipart = false; - if (oldnbt.hasKey("id") && oldnbt.getString("id") == "savedMultipart" && WarpDriveConfig.isForgeMultipartLoaded) { - isForgeMultipart = true; - newTileEntity = (TileEntity) WarpDriveConfig.forgeMultipart_helper_createTileFromNBT.invoke(null, targetWorld, oldnbt); - - } else if (blockID == WarpDriveConfig.CC_Computer || blockID == WarpDriveConfig.CC_peripheral || blockID == WarpDriveConfig.CCT_Turtle || blockID == WarpDriveConfig.CCT_Upgraded || blockID == WarpDriveConfig.CCT_Advanced) { - newTileEntity = TileEntity.createAndLoadEntity(oldnbt); - newTileEntity.invalidate(); - - } else if (blockID == WarpDriveConfig.AS_Turbine) { - if (oldnbt.hasKey("zhuYao")) { - NBTTagCompound nbt1 = oldnbt.getCompoundTag("zhuYao"); - nbt1.setDouble("x", newX); - nbt1.setDouble("y", newY); - nbt1.setDouble("z", newZ); - oldnbt.setTag("zhuYao", nbt1); - } - newTileEntity = TileEntity.createAndLoadEntity(oldnbt); - } - - if (newTileEntity == null) { - newTileEntity = TileEntity.createAndLoadEntity(oldnbt); - } - - if (newTileEntity != null) { - newTileEntity.worldObj = targetWorld; - newTileEntity.validate(); - - worldObj.removeBlockTileEntity(oldX, oldY, oldZ); - targetWorld.setBlockTileEntity(newX, newY, newZ, newTileEntity); - if (isForgeMultipart) { - WarpDriveConfig.forgeMultipart_tileMultipart_onChunkLoad.invoke(newTileEntity); - WarpDriveConfig.forgeMultipart_helper_sendDescPacket.invoke(null, targetWorld, newTileEntity); - } - } else { - WarpDrive.print(this + " moveBlockSimple failed to create new tile entity at " + shipBlock.x + ", " + shipBlock.y + ", " + shipBlock.z + " blockId " + shipBlock.blockID + ":" + shipBlock.blockMeta); - WarpDrive.print("NBT data was " + ((oldnbt == null) ? "null" : oldnbt.toString())); - } - } - } catch (Exception exception) { - exception.printStackTrace(); - String coordinates = ""; - try { - if (shipBlock != null) { - coordinates = " at " + shipBlock.x + ", " + shipBlock.y + ", " + shipBlock.z + " blockId " + shipBlock.blockID + ":" + shipBlock.blockMeta; - } - } catch (Exception dropMe) { - coordinates = " (unknown coordinates)"; - } - WarpDrive.print(this + " moveBlockSimple exception index " + indexInShip + coordinates); - return false; - } - - return true; - } - private static ArrayList removeDuplicates(List l) { Set s = new TreeSet(new Comparator() @@ -1275,152 +1183,15 @@ public class EntityJump extends Entity } @Override - protected void entityInit() - { + protected void entityInit() { //WarpDrive.debugPrint("" + this + " entityInit()"); } @Override - protected void writeEntityToNBT(NBTTagCompound var1) - { + protected void writeEntityToNBT(NBTTagCompound var1) { //WarpDrive.debugPrint("" + this + " writeEntityToNBT()"); } - // Own implementation of setting blocks without light recalculation in optimization purposes - private boolean mySetBlock(World w, int x, int y, int z, int blockId, int blockMeta, int par6) - { - if (x >= -30000000 && z >= -30000000 && x < 30000000 && z < 30000000) - { - if (y < 0) - { - return false; - } - else if (y >= 256) - { - return false; - } - else - { - w.markBlockForUpdate(x, y, z); - Chunk chunk = w.getChunkFromChunkCoords(x >> 4, z >> 4); - return myChunkSBIDWMT(chunk, x & 15, y, z & 15, blockId, blockMeta); - } - } - else - { - return false; - } - } - - private boolean myChunkSBIDWMT(Chunk c, int x, int y, int z, int blockId, int blockMeta) - { - int j1 = z << 4 | x; - - if (y >= c.precipitationHeightMap[j1] - 1) - { - c.precipitationHeightMap[j1] = -999; - } - - //int k1 = c.heightMap[j1]; - int l1 = c.getBlockID(x, y, z); - int i2 = c.getBlockMetadata(x, y, z); - - if (l1 == blockId && i2 == blockMeta) - { - return false; - } - else - { - ExtendedBlockStorage[] storageArrays = c.getBlockStorageArray(); - ExtendedBlockStorage extendedblockstorage = storageArrays[y >> 4]; - - if (extendedblockstorage == null) - { - if (blockId == 0) - { - return false; - } - - extendedblockstorage = storageArrays[y >> 4] = new ExtendedBlockStorage(y >> 4 << 4, !c.worldObj.provider.hasNoSky); - } - - int j2 = c.xPosition * 16 + x; - int k2 = c.zPosition * 16 + z; - extendedblockstorage.setExtBlockID(x, y & 15, z, blockId); - - if (l1 != 0) - { - if (!c.worldObj.isRemote) - { - Block.blocksList[l1].breakBlock(c.worldObj, j2, y, k2, l1, i2); - } - else if (Block.blocksList[l1] != null && Block.blocksList[l1].hasTileEntity(i2)) - { - TileEntity te = worldObj.getBlockTileEntity(j2, y, k2); - - if (te != null && te.shouldRefresh(l1, blockId, i2, blockMeta, worldObj, j2, y, k2)) - { - c.worldObj.removeBlockTileEntity(j2, y, k2); - } - } - } - - if (extendedblockstorage.getExtBlockID(x, y & 15, z) != blockId) - { - return false; - } - else - { - extendedblockstorage.setExtBlockMetadata(x, y & 15, z, blockMeta); - // Removed light recalculations - /*if (flag) - { - c.generateSkylightMap(); - } - else - { - if (c.getBlockLightOpacity(par1, par2, par3) > 0) - { - if (par2 >= k1) - { - c.relightBlock(par1, par2 + 1, par3); - } - } - else if (par2 == k1 - 1) - { - c.relightBlock(par1, par2, par3); - } - - c.propagateSkylightOcclusion(par1, par3); - }*/ - TileEntity tileentity; - - if (blockId != 0) - { - if (Block.blocksList[blockId] != null && Block.blocksList[blockId].hasTileEntity(blockMeta)) - { - tileentity = c.getChunkBlockTileEntity(x, y, z); - - if (tileentity == null) - { - tileentity = Block.blocksList[blockId].createTileEntity(c.worldObj, blockMeta); - c.worldObj.setBlockTileEntity(j2, y, k2, tileentity); - } - - if (tileentity != null) - { - tileentity.updateContainingBlockInfo(); - tileentity.blockMetadata = blockMeta; - } - } - } - - c.isModified = true; - return true; - } - } - } - private void FixASTurbines() { Class c; diff --git a/src/cr0s/WarpDrive/WarpDriveConfig.java b/src/cr0s/WarpDrive/WarpDriveConfig.java index 63474d4c..49a79bff 100644 --- a/src/cr0s/WarpDrive/WarpDriveConfig.java +++ b/src/cr0s/WarpDrive/WarpDriveConfig.java @@ -104,7 +104,6 @@ public class WarpDriveConfig public static Item AEExtra_fluidDrive; public static Block AEExtra_certusQuartzTank; - // Mod configuration (see loadWarpDriveConfig() for comments/definitions) // General public static int G_SPACE_PROVIDER_ID = 14; @@ -117,7 +116,8 @@ public class WarpDriveConfig public static final int LUA_SCRIPTS_ALL = 2; public static int G_LUA_SCRIPTS = LUA_SCRIPTS_ALL; public static boolean G_DEBUGMODE = false; - public static String G_SCHEMALOCATION = "/home/cros/mc_site/schematics/"; + public static String G_SCHEMALOCATION = "warpDrive_schematics"; + public static int G_BLOCKS_PER_TICK = 3500; public static boolean G_ENABLE_IC2_RECIPES = true; public static boolean G_ENABLE_VANILLA_RECIPES = false; @@ -126,7 +126,7 @@ public class WarpDriveConfig // Transition planes public static TransitionPlane[] G_TRANSITIONPLANES = null; - // Warp Core + // Warp Drive Core public static int WC_MAX_ENERGY_VALUE = 100000000; public static int WC_ENERGY_PER_BLOCK_MODE1 = 10; public static int WC_ENERGY_PER_DISTANCE_MODE1 = 100; @@ -153,6 +153,12 @@ public class WarpDriveConfig public static double WR_MIN_ISOLATION_EFFECT = 0.12; public static double WR_MAX_ISOLATION_EFFECT = 1.00; + // Ship Scanner + public static int SS_MAX_ENERGY_VALUE = 500000000; + public static int SS_EU_PER_BLOCK_SCAN = 100; // eU per block of ship volume (including air) + public static int SS_EU_PER_BLOCK_DEPLOY = 5000; + public static int SS_MAX_DEPLOY_RADIUS_BLOCKS = 50; + // Particle Booster public static int PB_MAX_ENERGY_VALUE = 100000; @@ -265,15 +271,16 @@ public class WarpDriveConfig public static void loadWarpDriveConfig() { // General - G_SPACE_PROVIDER_ID = config.get("General", "space_provider_id", G_SPACE_PROVIDER_ID).getInt(); - G_SPACE_DIMENSION_ID = config.get("General", "space_dimension_id", G_SPACE_DIMENSION_ID).getInt(); - G_HYPERSPACE_PROVIDER_ID = config.get("General", "hyperspace_provider_id", G_HYPERSPACE_PROVIDER_ID).getInt(); - G_HYPERSPACE_DIMENSION_ID = config.get("General", "hyperspace_dimension_id", G_HYPERSPACE_DIMENSION_ID).getInt(); + G_SPACE_PROVIDER_ID = config.get("General", "space_provider_id", G_SPACE_PROVIDER_ID, "Space dimension provider ID").getInt(); + G_SPACE_DIMENSION_ID = config.get("General", "space_dimension_id", G_SPACE_DIMENSION_ID, "Space dimension world ID").getInt(); + G_HYPERSPACE_PROVIDER_ID = config.get("General", "hyperspace_provider_id", G_HYPERSPACE_PROVIDER_ID, "Hyperspace dimension provider ID").getInt(); + G_HYPERSPACE_DIMENSION_ID = config.get("General", "hyperspace_dimension_id", G_HYPERSPACE_DIMENSION_ID, "Hyperspace dimension world ID").getInt(); G_SPACE_WORLDBORDER_BLOCKS = config.get("General", "space_worldborder_blocks", G_SPACE_WORLDBORDER_BLOCKS, "World border applied to hyperspace & space, set to 0 to disable it").getInt(); G_LUA_SCRIPTS = config.get("General", "lua_scripts", G_LUA_SCRIPTS, "LUA scripts to load when connecting machines: 0 = none, 1 = templates in a subfolder, 2 = ready to roll (templates are still provided)").getInt(); - G_DEBUGMODE = config.get("General", "debug_mode", G_DEBUGMODE).getBoolean(false); - G_SCHEMALOCATION = config.get("General", "schematic_location", G_SCHEMALOCATION).getString(); - + G_DEBUGMODE = config.get("General", "debug_mode", G_DEBUGMODE, "Detailled logs to help debug the mod, enable it before reporting a bug").getBoolean(false); + G_SCHEMALOCATION = config.get("General", "schematic_location", G_SCHEMALOCATION, "Folder where to save ship schematics").getString(); + G_BLOCKS_PER_TICK = config.get("General", "blocks_per_tick", G_BLOCKS_PER_TICK, "Number of blocks to move per ticks, too high will cause lag spikes on ship jumping or deployment, too low may break the ship wirings").getInt(); + G_ENABLE_IC2_RECIPES = config.get("General", "enable_ic2_recipes", G_ENABLE_IC2_RECIPES, "Original recipes based on IndustrialCrat2 by Cr0s").getBoolean(true); G_ENABLE_VANILLA_RECIPES = config.get("General", "enable_vanilla_recipes", G_ENABLE_VANILLA_RECIPES, "Vanilla recipes by DarkholmeTenk").getBoolean(false); G_ENABLE_TDK_RECIPES = config.get("General", "enable_TDK_recipes", G_ENABLE_TDK_RECIPES, "Mixed recipes for TDK packs by Lem'ADEC (currently requires at least AppliedEnergistics, Extracells, AtomicScience, IndustrialCraft2, GraviSuite and ThermalExpansion").getBoolean(false); @@ -300,7 +307,7 @@ public class WarpDriveConfig // FIXME: check transition planes have valid dimension id // Warp Core - WC_MAX_ENERGY_VALUE = config.get("WarpCore", "max_energy_value", WC_MAX_ENERGY_VALUE).getInt(); + WC_MAX_ENERGY_VALUE = config.get("WarpCore", "max_energy_value", WC_MAX_ENERGY_VALUE, "Maximum energy storage").getInt(); WC_ENERGY_PER_BLOCK_MODE1 = config.get("WarpCore", "energy_per_block_mode1", WC_ENERGY_PER_BLOCK_MODE1).getInt(); WC_ENERGY_PER_DISTANCE_MODE1 = config.get("WarpCore", "energy_per_distance_mode1", WC_ENERGY_PER_DISTANCE_MODE1).getInt(); WC_ENERGY_PER_DISTANCE_MODE2 = config.get("WarpCore", "energy_per_distance_mode2", WC_ENERGY_PER_DISTANCE_MODE2).getInt(); @@ -331,6 +338,18 @@ public class WarpDriveConfig WR_MAX_ISOLATION_EFFECT = config.get("WarpRadar", "max_isolation_effect", WR_MAX_ISOLATION_EFFECT, "isolation effect achieved with max number of isolation blocks (0.01 to 1.00)").getDouble(1.00D); WR_MAX_ISOLATION_EFFECT = Math.min(1.0D, Math.max(WR_MAX_ISOLATION_EFFECT, 0.01D)); + // Ship Scanner + SS_MAX_ENERGY_VALUE = config.get("WarpCore", "max_energy_value", SS_MAX_ENERGY_VALUE, "Maximum energy storage").getInt(); + SS_EU_PER_BLOCK_SCAN = config.get("ShipScanner", "energy_per_block_when_scanning", SS_EU_PER_BLOCK_SCAN, "Energy consummed per block when scanning a ship (use -1 to consume everything)").getInt(); + if (SS_EU_PER_BLOCK_SCAN != -1) { + SS_EU_PER_BLOCK_SCAN = Math.min(SS_MAX_ENERGY_VALUE, Math.max(SS_EU_PER_BLOCK_SCAN, 1)); + } + SS_EU_PER_BLOCK_DEPLOY = config.get("ShipScanner", "energy_per_block_when_deploying", SS_EU_PER_BLOCK_DEPLOY, "Energy consummed per block when deploying a ship (use -1 to consume everything)").getInt(); + if (SS_EU_PER_BLOCK_DEPLOY != -1) { + SS_EU_PER_BLOCK_DEPLOY = Math.min(SS_MAX_ENERGY_VALUE, Math.max(SS_EU_PER_BLOCK_DEPLOY, 1)); + } + SS_MAX_DEPLOY_RADIUS_BLOCKS = config.get("ShipScanner", "max_deploy_radius_blocks", SS_MAX_DEPLOY_RADIUS_BLOCKS, "Max distance from ship scanner to ship core, measured in blocks").getInt(); + // Particle Booster PB_MAX_ENERGY_VALUE = config.get("ParticleBooster", "max_energy_value", PB_MAX_ENERGY_VALUE).getInt(); diff --git a/src/cr0s/WarpDrive/data/JumpBlock.java b/src/cr0s/WarpDrive/data/JumpBlock.java index 03fed5a1..63f94019 100644 --- a/src/cr0s/WarpDrive/data/JumpBlock.java +++ b/src/cr0s/WarpDrive/data/JumpBlock.java @@ -1,7 +1,13 @@ package cr0s.WarpDrive.data; +import cr0s.WarpDrive.WarpDrive; +import cr0s.WarpDrive.WarpDriveConfig; +import net.minecraft.block.Block; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.storage.ExtendedBlockStorage; public class JumpBlock { @@ -13,12 +19,10 @@ public class JumpBlock public int y; public int z; - public JumpBlock() - { + public JumpBlock() { } - public JumpBlock(int i, int j, int k, int l, int i1) - { + public JumpBlock(int i, int j, int k, int l, int i1) { blockID = i; blockMeta = j; blockTileEntity = null; @@ -27,8 +31,7 @@ public class JumpBlock z = i1; } - public JumpBlock(int i, int j, TileEntity tileentity, int k, int l, int i1) - { + public JumpBlock(int i, int j, TileEntity tileentity, int k, int l, int i1) { blockID = i; blockMeta = j; blockTileEntity = tileentity; @@ -36,4 +39,189 @@ public class JumpBlock y = l; z = i1; } + + + public boolean deploy(World targetWorld, int offsetX, int offsetY, int offsetZ) { + try { + int newX = x + offsetX; + int newY = y + offsetY; + int newZ = z + offsetZ; + mySetBlock(targetWorld, newX, newY, newZ, blockID, blockMeta, 2); + + // Re-schedule air blocks update + if (blockID == WarpDriveConfig.airID) { + targetWorld.markBlockForUpdate(newX, newY, newZ); + targetWorld.scheduleBlockUpdate(newX, newY, newZ, blockID, 40 + targetWorld.rand.nextInt(20)); + } + + NBTTagCompound oldnbt = new NBTTagCompound(); + if (blockTileEntity != null) { + blockTileEntity.writeToNBT(oldnbt); + oldnbt.setInteger("x", newX); + oldnbt.setInteger("y", newY); + oldnbt.setInteger("z", newZ); + + if (oldnbt.hasKey("mainX") && oldnbt.hasKey("mainY") && oldnbt.hasKey("mainZ")) { // Mekanism 6.0.4.44 + WarpDrive.debugPrint("[JUMP] moveBlockSimple: TileEntity from Mekanism detected"); + oldnbt.setInteger("mainX", oldnbt.getInteger("mainX") + offsetX); + oldnbt.setInteger("mainY", oldnbt.getInteger("mainY") + offsetY); + oldnbt.setInteger("mainZ", oldnbt.getInteger("mainZ") + offsetZ); + } + + TileEntity newTileEntity = null; + boolean isForgeMultipart = false; + if (oldnbt.hasKey("id") && oldnbt.getString("id") == "savedMultipart" && WarpDriveConfig.isForgeMultipartLoaded) { + isForgeMultipart = true; + newTileEntity = (TileEntity) WarpDriveConfig.forgeMultipart_helper_createTileFromNBT.invoke(null, targetWorld, oldnbt); + + } else if (blockID == WarpDriveConfig.CC_Computer || blockID == WarpDriveConfig.CC_peripheral || blockID == WarpDriveConfig.CCT_Turtle || blockID == WarpDriveConfig.CCT_Upgraded || blockID == WarpDriveConfig.CCT_Advanced) { + newTileEntity = TileEntity.createAndLoadEntity(oldnbt); + newTileEntity.invalidate(); + + } else if (blockID == WarpDriveConfig.AS_Turbine) { + if (oldnbt.hasKey("zhuYao")) { + NBTTagCompound nbt1 = oldnbt.getCompoundTag("zhuYao"); + nbt1.setDouble("x", newX); + nbt1.setDouble("y", newY); + nbt1.setDouble("z", newZ); + oldnbt.setTag("zhuYao", nbt1); + } + newTileEntity = TileEntity.createAndLoadEntity(oldnbt); + } + + if (newTileEntity == null) { + newTileEntity = TileEntity.createAndLoadEntity(oldnbt); + } + + if (newTileEntity != null) { + newTileEntity.worldObj = targetWorld; + newTileEntity.validate(); + + targetWorld.setBlockTileEntity(newX, newY, newZ, newTileEntity); + if (isForgeMultipart) { + WarpDriveConfig.forgeMultipart_tileMultipart_onChunkLoad.invoke(newTileEntity); + WarpDriveConfig.forgeMultipart_helper_sendDescPacket.invoke(null, targetWorld, newTileEntity); + } + } else { + WarpDrive.print(" moveBlockSimple failed to create new tile entity at " + x + ", " + y + ", " + z + " blockId " + blockID + ":" + blockMeta); + WarpDrive.print("NBT data was " + ((oldnbt == null) ? "null" : oldnbt.toString())); + } + } + } catch (Exception exception) { + exception.printStackTrace(); + String coordinates = ""; + try { + coordinates = " at " + x + ", " + y + ", " + z + " blockId " + blockID + ":" + blockMeta; + } catch (Exception dropMe) { + coordinates = " (unknown coordinates)"; + } + WarpDrive.print("moveBlockSimple exception at " + coordinates); + return false; + } + + return true; + } + + // This code is a straight copy from Vanilla to remove lighting computations + public static boolean mySetBlock(World w, int x, int y, int z, int blockId, int blockMeta, int par6) { + if (x >= -30000000 && z >= -30000000 && x < 30000000 && z < 30000000) { + if (y < 0) { + return false; + } else if (y >= 256) { + return false; + } else { + w.markBlockForUpdate(x, y, z); + Chunk chunk = w.getChunkFromChunkCoords(x >> 4, z >> 4); + return myChunkSBIDWMT(chunk, x & 15, y, z & 15, blockId, blockMeta); + } + } else { + return false; + } + } + + // This code is a straight copy from Vanilla to remove lighting computations + public static boolean myChunkSBIDWMT(Chunk c, int x, int y, int z, int blockId, int blockMeta) { + int j1 = z << 4 | x; + + if (y >= c.precipitationHeightMap[j1] - 1) { + c.precipitationHeightMap[j1] = -999; + } + + //int k1 = c.heightMap[j1]; + int l1 = c.getBlockID(x, y, z); + int i2 = c.getBlockMetadata(x, y, z); + + if (l1 == blockId && i2 == blockMeta) { + return false; + } else { + ExtendedBlockStorage[] storageArrays = c.getBlockStorageArray(); + ExtendedBlockStorage extendedblockstorage = storageArrays[y >> 4]; + + if (extendedblockstorage == null) { + if (blockId == 0) { + return false; + } + + extendedblockstorage = storageArrays[y >> 4] = new ExtendedBlockStorage(y >> 4 << 4, !c.worldObj.provider.hasNoSky); + } + + int j2 = c.xPosition * 16 + x; + int k2 = c.zPosition * 16 + z; + extendedblockstorage.setExtBlockID(x, y & 15, z, blockId); + + if (l1 != 0) { + if (!c.worldObj.isRemote) { + Block.blocksList[l1].breakBlock(c.worldObj, j2, y, k2, l1, i2); + } else if (Block.blocksList[l1] != null && Block.blocksList[l1].hasTileEntity(i2)) { + TileEntity te = c.worldObj.getBlockTileEntity(j2, y, k2); + + if (te != null && te.shouldRefresh(l1, blockId, i2, blockMeta, c.worldObj, j2, y, k2)) { + c.worldObj.removeBlockTileEntity(j2, y, k2); + } + } + } + + if (extendedblockstorage.getExtBlockID(x, y & 15, z) != blockId) { + return false; + } else { + extendedblockstorage.setExtBlockMetadata(x, y & 15, z, blockMeta); + // Removed light recalculations + /* + if (flag) { + c.generateSkylightMap(); + } else { + if (c.getBlockLightOpacity(par1, par2, par3) > 0) { + if (par2 >= k1) { + c.relightBlock(par1, par2 + 1, par3); + } + } else if (par2 == k1 - 1) { + c.relightBlock(par1, par2, par3); + } + + c.propagateSkylightOcclusion(par1, par3); + } + /**/ + TileEntity tileentity; + + if (blockId != 0) { + if (Block.blocksList[blockId] != null && Block.blocksList[blockId].hasTileEntity(blockMeta)) { + tileentity = c.getChunkBlockTileEntity(x, y, z); + + if (tileentity == null) { + tileentity = Block.blocksList[blockId].createTileEntity(c.worldObj, blockMeta); + c.worldObj.setBlockTileEntity(j2, y, k2, tileentity); + } + + if (tileentity != null) { + tileentity.updateContainingBlockInfo(); + tileentity.blockMetadata = blockMeta; + } + } + } + + c.isModified = true; + return true; + } + } + } } diff --git a/src/cr0s/WarpDrive/machines/TileEntityShipScanner.java b/src/cr0s/WarpDrive/machines/TileEntityShipScanner.java index bad1ec55..87355220 100644 --- a/src/cr0s/WarpDrive/machines/TileEntityShipScanner.java +++ b/src/cr0s/WarpDrive/machines/TileEntityShipScanner.java @@ -26,8 +26,6 @@ import net.minecraft.world.chunk.storage.ExtendedBlockStorage; import net.minecraftforge.common.ForgeDirection; public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { - private final int MAX_ENERGY_VALUE = 500000000; // 500kk eU - private int state = 0; // 0 - inactive, 1 - active private int firstUncoveredY; @@ -40,13 +38,6 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { int warpCoreSearchTicks = 0; - // Config //TODO add to WarpDriveConfig - private final String SCHEMATICS_DIR = "warpDrive_schematics"; - private final int EU_PER_BLOCK_SCAN = 100; // eU per block of ship volume (including air) - private final int EU_PER_BLOCK_DEPLOY = 5000; - private final int BLOCK_TO_DEPLOY_PER_TICK = 3000; - private final int ALLOWED_DEPLOY_RADIUS = 50; // blocks - private String[] methodsArray = { "scan", // 0 "fileName", // 1 @@ -61,7 +52,7 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { private int blocksToDeployCount; private boolean isDeploying = false; - private int newX, newY, newZ; + private int targetX, targetY, targetZ; @Override @@ -146,7 +137,7 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { deployDelayTicks = 0; - int blocks = Math.min(BLOCK_TO_DEPLOY_PER_TICK, blocksToDeployCount - currentDeployIndex); + int blocks = Math.min(WarpDriveConfig.G_BLOCKS_PER_TICK, blocksToDeployCount - currentDeployIndex); if (blocks == 0) { isDeploying = false; @@ -164,20 +155,20 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { } // Deploy single block - JumpBlock block = blocksToDeploy[currentDeployIndex]; + JumpBlock jb = blocksToDeploy[currentDeployIndex]; - if (block != null && - block.blockID != Block.bedrock.blockID && - !WarpDriveConfig.scannerIgnoreBlocks.contains(block.blockID) && - worldObj.isAirBlock(newX + block.x, newY + block.y, newZ + block.z)) { - moveBlockSimple(block); + if (jb != null && + jb.blockID != Block.bedrock.blockID && + !WarpDriveConfig.scannerIgnoreBlocks.contains(jb.blockID) && + 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(newX + block.x, newY + block.y, newZ + block.z).translate(0.5D), + new Vector3(targetX + jb.x, targetY + jb.y, targetZ + jb.z).translate(0.5D), 0f, 1f, 0f, 15, 0, 100); } } @@ -216,28 +207,46 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { return result; } - - private void saveShipToSchematic(String fileName) { + + private int getScanningEnergyCost(int size) { + if (WarpDriveConfig.SS_EU_PER_BLOCK_SCAN > 0) { + return size * WarpDriveConfig.SS_EU_PER_BLOCK_SCAN; + } else { + 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; + } else { + return WarpDriveConfig.SS_MAX_ENERGY_VALUE; + } + } + + private boolean saveShipToSchematic(String fileName, StringBuilder reason) { NBTTagCompound schematic = new NBTTagCompound("Schematic"); - short width = (short) Math.abs(core.maxX - core.minX); - short length = (short) Math.abs(core.maxZ - core.minZ); - short height = (short) (core.maxY - core.minY); + short width = (short) (core.maxX - core.minX + 1); + short length = (short) (core.maxZ - core.minZ + 1); + short height = (short) (core.maxY - core.minY + 1); - width++; - height++; - length++; + 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 - consumeEnergy(size * EU_PER_BLOCK_SCAN, false); - + if (!consumeEnergy(getScanningEnergyCost(size), false)) { + reason.append("Insufficient energy (" + getScanningEnergyCost(size) + " required)"); + return false; + } byte localBlocks[] = new byte[size]; byte localMetadata[] = new byte[size]; @@ -328,6 +337,8 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { schematic.setTag("TileEntities", tileEntitiesList); writeNBTToFile(fileName, schematic); + + return true; } private static void writeNBTToFile(String fileName, NBTTagCompound nbttagcompound) { @@ -350,21 +361,26 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { } // Begins ship scan - private void scanShip() { + private boolean scanShip(StringBuilder reason) { // Enable scanner switchState(1); - File f = new File(SCHEMATICS_DIR); - if (!f.exists() || !f.isDirectory()) + File f = new File(WarpDriveConfig.G_SCHEMALOCATION); + if (!f.exists() || !f.isDirectory()) { f.mkdirs(); + } // Generate unique file name do { schematicFileName = (new StringBuilder().append(core.coreFrequency) .append(System.currentTimeMillis()).append(".schematic")) .toString(); - } while (new File(SCHEMATICS_DIR + "/" + schematicFileName).exists()); + } while (new File(WarpDriveConfig.G_SCHEMALOCATION + "/" + schematicFileName).exists()); - saveShipToSchematic(SCHEMATICS_DIR + "/" + schematicFileName); + if (!saveShipToSchematic(WarpDriveConfig.G_SCHEMALOCATION + "/" + schematicFileName, reason)) { + return false; + } + reason.append(schematicFileName); + return true; } private static NBTTagCompound readNBTFromFile(String fileName) { @@ -387,73 +403,70 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { return null; } - // Returns result array for CC interface: [ code, "message" ] - private Object[] deployShip(String fileName, int offsetX, int offsetY, int offsetZ) { - NBTTagCompound schematic = readNBTFromFile(SCHEMATICS_DIR + "/" + fileName); - + // Returns error code and reason string + private int deployShip(String fileName, int offsetX, int offsetY, int offsetZ, StringBuilder reason) { + // Load schematic + NBTTagCompound schematic = readNBTFromFile(WarpDriveConfig.G_SCHEMALOCATION + "/" + fileName); if (schematic == null) { - return new Object[] { -1, "Unknow error. Schematic NBT is null" }; + 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"); - int targetX = xCoord + offsetX; - int targetY = yCoord + offsetY; - int targetZ = zCoord + offsetZ; + targetX = xCoord + offsetX; + targetY = yCoord + offsetY; + targetZ = zCoord + offsetZ; + blocksToDeployCount = width * height * length; - double d3 = xCoord - targetX; - double d4 = yCoord - targetY; - double d5 = zCoord - targetZ; - double distance = MathHelper.sqrt_double(d3 * d3 + d4 * d4 + d5 * d5); - - if (distance > ALLOWED_DEPLOY_RADIUS) - return new Object[] { 5, "Cannot deploy ship so far away from scanner." }; - - int size = width* height * length; - - - // Check energy level - if (!consumeEnergy(size * EU_PER_BLOCK_DEPLOY, false)) { - String msg = "[ShipScanner] Not enough energy! Need at least " + (size * EU_PER_BLOCK_DEPLOY) + " EU"; - WarpDrive.debugPrint(msg); - return new Object[] { 1, msg }; - } - - // Check specified area for occupation by blocks - // If specified area occupied, break deploying with error message - int occupiedBlockCount = 0; - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - for (int z = 0; z < length; z++) { - if (!worldObj.isAirBlock(targetX + x, targetY + y, targetZ + z)) - occupiedBlockCount++; + // Validate context + { + // Check distance + double dX = xCoord - targetX; + 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; + for (int x = 0; x < width; x++) { + for (int y = 0; y < height; y++) { + for (int z = 0; z < length; z++) { + if (!worldObj.isAirBlock(targetX + x, targetY + y, targetZ + z)) + occupiedBlockCount++; + } } } - } - - if (occupiedBlockCount > 0) { - return new Object[] { 2, "Deploying area occupied with " + occupiedBlockCount + " blocks. Can't deploy ship." }; + if (occupiedBlockCount > 0) { + reason.append("Deploying area occupied with " + occupiedBlockCount + " blocks. Can't deploy ship."); + return 2; + } } - // Set deployment vars - this.blocksToDeploy = new JumpBlock[size]; - this.isDeploying = true; - this.currentDeployIndex = 0; - this.blocksToDeployCount = size; - - this.newX = targetX; - this.newY = targetY; - this.newZ = targetZ; - + // 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"); - boolean extra = schematic.hasKey("Add") || schematic.hasKey("AddBlocks"); byte extraBlocks[] = null; byte extraBlocksNibble[] = null; if (schematic.hasKey("AddBlocks")) { @@ -468,7 +481,7 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { } // Load Tile Entities - NBTTagCompound[] tileEntities = new NBTTagCompound[size]; + NBTTagCompound[] tileEntities = new NBTTagCompound[blocksToDeployCount]; NBTTagList tileEntitiesList = schematic.getTagList("TileEntities"); for (int i = 0; i < tileEntitiesList.tagCount(); i++) { @@ -484,41 +497,39 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { 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.blockID = (localBlocks[x + (y * length + z) * width]) & 0xFF; - if (extra) - jb.blockID |= ((extraBlocks[x + (y * length + z) * width]) & 0xFF) << 8; - - jb.blockMeta = (localMetadata[x + (y * length + z) * width]) & 0xFF; - jb.blockNBT = tileEntities[x + (y * length + z) * width]; - - - jb.x = x; jb.y = y; jb.z = z; + jb.blockID = (localBlocks[index]) & 0xFF; + if (extraBlocks != null) { + jb.blockID |= ((extraBlocks[index]) & 0xFF) << 8; + } + jb.blockMeta = (localMetadata[index]) & 0xFF; + jb.blockNBT = tileEntities[index]; if (jb.blockID != 0 && Block.blocksList[jb.blockID] != null) { - System.out.print("[ShipScanner] Saving block: " + Block.blocksList[jb.blockID].getUnlocalizedName() + ", TE: "); - if (tileEntities[x + (y * length + z) * width] == null) { - System.out.println("null!"); + if (tileEntities[index] == null) { + WarpDrive.debugPrint("[ShipScanner] Adding block to deploy: " + Block.blocksList[jb.blockID].getUnlocalizedName() + " (no tile entity)"); } else { - System.out.println(tileEntities[x + (y * length + z) * width].getString("id")); + WarpDrive.debugPrint("[ShipScanner] Adding block to deploy: " + Block.blocksList[jb.blockID].getUnlocalizedName() + " with tile entity " + tileEntities[index].getString("id")); } - blocksToDeploy[x + (y * length + z) * width] = jb; + blocksToDeploy[index] = jb; } else { jb = null; - blocksToDeploy[x + (y * length + z) * width] = jb; + blocksToDeploy[index] = jb; } } } } switchState(1); - return new Object[] { 3, "Ship deployed." }; + reason.append("Ship deploying..."); + return 3; } @Override @@ -548,24 +559,28 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { switch (method) { case 0: // scanShip() // Already scanning? - if (this.state == 1) + if (this.state == 1) { return new Object[] { false, 0, "Already scanning" }; - + } + if (core == null) { return new Object[] { false, 1, "Warp-Core not found" }; - } else if (consumeEnergy(core.shipVolume * EU_PER_BLOCK_SCAN, true)) { - scanShip(); + } else if (consumeEnergy(core.shipVolume * WarpDriveConfig.SS_EU_PER_BLOCK_SCAN, true)) { + StringBuilder reason = new StringBuilder(); + boolean success = scanShip(reason); + return new Object[] { success, 3, reason.toString() }; } else { return new Object[] { false, 2, "Not enough energy!" }; } - break; - + // break; + case 1: // getSchematicFileName() - if (state != 0 && !schematicFileName.isEmpty()) - return new Object[] { "Scanning in process. Please wait." }; + if (state != 0 && !schematicFileName.isEmpty()) { + return new Object[] { "Scanning in process. Please wait..." }; + } return new Object[] { schematicFileName }; - + case 2: // getEnergyLevel() return new Object[] { getEnergyStored() }; @@ -576,14 +591,15 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { int y = ((Double)arguments[2]).intValue(); int z = ((Double)arguments[3]).intValue(); - if (!new File(SCHEMATICS_DIR + "/" + fileName).exists()) { - return new Object[] { 0, "Specified .schematic file not found!" }; - } else - { - return deployShip(fileName, x, y, z); + if (!new File(WarpDriveConfig.G_SCHEMALOCATION + "/" + fileName).exists()) { + return new Object[] { 0, "Specified .schematic file was not found!" }; + } else { + StringBuilder reason = new StringBuilder(); + int result = deployShip(fileName, x, y, z, reason); + return new Object[] { result, reason.toString() }; } } else { - return new Object[] { 4, ".schematic file name not specified or invalid arguments count!" }; + return new Object[] { 4, "Invalid arguments count, you need .schematic file name, offsetX, offsetY and offsetZ!" }; } } @@ -601,7 +617,7 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { // IEnergySink methods implementation @Override public int getMaxEnergyStored() { - return MAX_ENERGY_VALUE; + return WarpDriveConfig.SS_MAX_ENERGY_VALUE; } @Override @@ -614,177 +630,6 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { return true; } - public boolean moveBlockSimple(JumpBlock shipBlock) - { - try - { - if (shipBlock == null) - { - return false; - } - - int oldX = shipBlock.x; - int oldY = shipBlock.y; - int oldZ = shipBlock.z; - - int blockID = shipBlock.blockID; - int blockMeta = shipBlock.blockMeta; - mySetBlock(worldObj, oldX + newX, oldY + newY, oldZ + newZ, blockID, blockMeta, 2); - - NBTTagCompound oldnbt = new NBTTagCompound(); - oldnbt = shipBlock.blockNBT; - if (oldnbt != null) { - TileEntity newTileEntity; - newTileEntity = TileEntity.createAndLoadEntity(oldnbt); - newTileEntity.worldObj = worldObj; - newTileEntity.validate(); - worldObj.setBlockTileEntity(oldX + newX, oldY + newY, oldZ + newZ, newTileEntity); - } - } - catch (Exception exception) - { - exception.printStackTrace(); - return false; - } - - return true; - } - - // Own implementation of setting blocks without light recalculation in optimization purposes - public boolean mySetBlock(World w, int x, int y, int z, int blockId, int blockMeta, int par6) - { - if (x >= -30000000 && z >= -30000000 && x < 30000000 && z < 30000000) - { - if (y < 0) - { - return false; - } - else if (y >= 256) - { - return false; - } - else - { - w.markBlockForUpdate(x, y, z); - Chunk chunk = w.getChunkFromChunkCoords(x >> 4, z >> 4); - return myChunkSBIDWMT(chunk, x & 15, y, z & 15, blockId, blockMeta); - } - } - else - { - return false; - } - } - - public boolean myChunkSBIDWMT(Chunk c, int x, int y, int z, int blockId, int blockMeta) - { - int j1 = z << 4 | x; - - if (y >= c.precipitationHeightMap[j1] - 1) - { - c.precipitationHeightMap[j1] = -999; - } - - //int k1 = c.heightMap[j1]; - int l1 = c.getBlockID(x, y, z); - int i2 = c.getBlockMetadata(x, y, z); - - if (l1 == blockId && i2 == blockMeta) - { - return false; - } - else - { - ExtendedBlockStorage[] storageArrays = c.getBlockStorageArray(); - ExtendedBlockStorage extendedblockstorage = storageArrays[y >> 4]; - - if (extendedblockstorage == null) - { - if (blockId == 0) - { - return false; - } - - extendedblockstorage = storageArrays[y >> 4] = new ExtendedBlockStorage(y >> 4 << 4, !c.worldObj.provider.hasNoSky); - } - - int j2 = c.xPosition * 16 + x; - int k2 = c.zPosition * 16 + z; - extendedblockstorage.setExtBlockID(x, y & 15, z, blockId); - - if (l1 != 0) - { - if (!c.worldObj.isRemote) - { - Block.blocksList[l1].breakBlock(c.worldObj, j2, y, k2, l1, i2); - } - else if (Block.blocksList[l1] != null && Block.blocksList[l1].hasTileEntity(i2)) - { - TileEntity te = worldObj.getBlockTileEntity(j2, y, k2); - - if (te != null && te.shouldRefresh(l1, blockId, i2, blockMeta, worldObj, j2, y, k2)) - { - c.worldObj.removeBlockTileEntity(j2, y, k2); - } - } - } - - if (extendedblockstorage.getExtBlockID(x, y & 15, z) != blockId) - { - return false; - } - else - { - extendedblockstorage.setExtBlockMetadata(x, y & 15, z, blockMeta); - // Removed light recalculations - /*if (flag) - { - c.generateSkylightMap(); - } - else - { - if (c.getBlockLightOpacity(par1, par2, par3) > 0) - { - if (par2 >= k1) - { - c.relightBlock(par1, par2 + 1, par3); - } - } - else if (par2 == k1 - 1) - { - c.relightBlock(par1, par2, par3); - } - - c.propagateSkylightOcclusion(par1, par3); - }*/ - TileEntity tileentity; - - if (blockId != 0) - { - if (Block.blocksList[blockId] != null && Block.blocksList[blockId].hasTileEntity(blockMeta)) - { - tileentity = c.getChunkBlockTileEntity(x, y, z); - - if (tileentity == null) - { - tileentity = Block.blocksList[blockId].createTileEntity(c.worldObj, blockMeta); - c.worldObj.setBlockTileEntity(j2, y, k2, tileentity); - } - - if (tileentity != null) - { - tileentity.updateContainingBlockInfo(); - tileentity.blockMetadata = blockMeta; - } - } - } - - c.isModified = true; - return true; - } - } - } - @Override public boolean equals(IPeripheral other) { return other == this; diff --git a/src/cr0s/WarpDrive/world/EntitySphereGen.java b/src/cr0s/WarpDrive/world/EntitySphereGen.java index af42d458..a941c857 100644 --- a/src/cr0s/WarpDrive/world/EntitySphereGen.java +++ b/src/cr0s/WarpDrive/world/EntitySphereGen.java @@ -138,7 +138,7 @@ public final class EntitySphereGen extends Entity break; notifyFlag = (currentIndex % 1000 == 0 ? 2 : 0); JumpBlock jb = blocks.get(currentIndex); - mySetBlock(worldObj, jb.x, jb.y, jb.z, jb.blockID, jb.blockMeta, notifyFlag); + JumpBlock.mySetBlock(worldObj, jb.x, jb.y, jb.z, jb.blockID, jb.blockMeta, notifyFlag); currentIndex++; } @@ -237,62 +237,6 @@ public final class EntitySphereGen extends Entity @Override protected void writeEntityToNBT(NBTTagCompound tag) { } - - // Own implementation of setting blocks without light recalculation in optimization purposes - private static boolean mySetBlock(World w, int x, int y, int z, int blockId, int blockMeta, int par6) { - if (x >= -30000000 && z >= -30000000 && x < 30000000 && z < 30000000) { - if (y < 0) - return false; - else if (y >= 256) - return false; - w.markBlockForUpdate(x, y, z); - Chunk chunk = w.getChunkFromChunkCoords(x >> 4, z >> 4); - return myChunkSBIDWMT(chunk, x & 15, y, z & 15, blockId, blockMeta); - } else { - return false; - } - } - - private static boolean myChunkSBIDWMT(Chunk c, int x, int y, int z, int blockId, int blockMeta) { - int j1 = z << 4 | x; - if (y >= c.precipitationHeightMap[j1] - 1) - c.precipitationHeightMap[j1] = -999; - int l1 = c.getBlockID(x, y, z); - int i2 = c.getBlockMetadata(x, y, z); - if (l1 == blockId && i2 == blockMeta) - return false; - ExtendedBlockStorage[] storageArrays = c.getBlockStorageArray(); - ExtendedBlockStorage extendedblockstorage = storageArrays[y >> 4]; - if (extendedblockstorage == null) - { - if (blockId == 0) - return false; - extendedblockstorage = storageArrays[y >> 4] = new ExtendedBlockStorage(y >> 4 << 4, !c.worldObj.provider.hasNoSky); - } - int j2 = c.xPosition * 16 + x; - int k2 = c.zPosition * 16 + z; - extendedblockstorage.setExtBlockID(x, y & 15, z, blockId); - if (extendedblockstorage.getExtBlockID(x, y & 15, z) != blockId) - return false; - extendedblockstorage.setExtBlockMetadata(x, y & 15, z, blockMeta); - if (blockId != 0) - if (Block.blocksList[blockId] != null && Block.blocksList[blockId].hasTileEntity(blockMeta)) - { - TileEntity tileentity = c.getChunkBlockTileEntity(x, y, z); - if (tileentity == null) - { - tileentity = Block.blocksList[blockId].createTileEntity(c.worldObj, blockMeta); - c.worldObj.setBlockTileEntity(j2, y, k2, tileentity); - } - else - { - tileentity.updateContainingBlockInfo(); - tileentity.blockMetadata = blockMeta; - } - } - c.isModified = true; - return true; - } @Override public boolean shouldRenderInPass(int pass) {