diff --git a/src/cr0s/WarpDrive/BlockAir.java b/src/cr0s/WarpDrive/BlockAir.java index 15b0913e..8e12a2c7 100644 --- a/src/cr0s/WarpDrive/BlockAir.java +++ b/src/cr0s/WarpDrive/BlockAir.java @@ -14,7 +14,7 @@ public class BlockAir extends Block { private final boolean TRANSPARENT_AIR = true; private final boolean AIR_DEBUG = false; - private final int AIR_BLOCK_TICKS = 20; + private final int AIR_BLOCK_TICKS = 40; private Icon[] iconBuffer; public BlockAir(int par1) { diff --git a/src/cr0s/WarpDrive/FXBeam.java b/src/cr0s/WarpDrive/FXBeam.java index cc84f312..24f58023 100644 --- a/src/cr0s/WarpDrive/FXBeam.java +++ b/src/cr0s/WarpDrive/FXBeam.java @@ -1,7 +1,6 @@ package cr0s.WarpDrive; import net.minecraft.client.Minecraft; -import net.minecraft.client.particle.EffectRenderer; import net.minecraft.client.particle.EntityFX; import net.minecraft.client.renderer.Tessellator; import net.minecraft.entity.EntityLivingBase; @@ -58,29 +57,8 @@ public class FXBeam extends EntityFX this.particleMaxAge = age; this.energy = energy; - if (red == 1 && green == 0 && blue == 0) - { - TEXTURE = new ResourceLocation("warpdrive", "textures/blocks/energy_red.png"); - } - else if (red == 0 && green == 1 && blue == 0) - { - TEXTURE = new ResourceLocation("warpdrive", "textures/blocks/energy_green.png"); - } - else if (red == 0 && green == 0 && blue == 1) - { - TEXTURE = new ResourceLocation("warpdrive", "textures/blocks/energy.png"); - } - else if (red == 1 && green == 1 && blue == 0) - { - TEXTURE = new ResourceLocation("warpdrive", "textures/blocks/energy_yellow.png"); - } - else if (red == 1 && green == 0.5 && blue == 0) - { - TEXTURE = new ResourceLocation("warpdrive", "textures/blocks/energy_orange.png"); - } - else if (red == 0.5 && green == 0 && blue == 0.5) - { - TEXTURE = new ResourceLocation("warpdrive", "textures/blocks/energy_violet.png"); + if (red == 1 && green == 0 && blue == 0) { + TEXTURE = new ResourceLocation("warpdrive", "textures/blocks/energy_grey.png"); } /** @@ -122,31 +100,8 @@ public class FXBeam extends EntityFX this.particleMaxAge = age; this.energy = energy; - if (red == 1 && green == 0 && blue == 0) - { - TEXTURE = new ResourceLocation("warpdrive", "textures/blocks/energy_red.png"); - } - else if (red == 0 && green == 1 && blue == 0) - { - TEXTURE = new ResourceLocation("warpdrive", "textures/blocks/energy_green.png"); - } - else if (red == 0 && green == 0 && blue == 1) - { - TEXTURE = new ResourceLocation("warpdrive", "textures/blocks/energy.png"); - } - else if (red == 1 && green == 1 && blue == 0) - { - TEXTURE = new ResourceLocation("warpdrive", "textures/blocks/energy_yellow.png"); - } - else if (red == 1 && green == 0.5 && blue == 0) - { - TEXTURE = new ResourceLocation("warpdrive", "textures/blocks/energy_orange.png"); - } - else if (red == 0.5 && green == 0 && blue == 0.5) - { - TEXTURE = new ResourceLocation("warpdrive", "textures/blocks/energy_violet.png"); - } - + TEXTURE = new ResourceLocation("warpdrive", "textures/blocks/energy_grey.png"); + /** * Sets the particle age based on distance. */ diff --git a/src/cr0s/WarpDrive/PacketHandler.java b/src/cr0s/WarpDrive/PacketHandler.java index 502d2e4e..eae9f64c 100644 --- a/src/cr0s/WarpDrive/PacketHandler.java +++ b/src/cr0s/WarpDrive/PacketHandler.java @@ -209,7 +209,7 @@ public class PacketHandler implements IPacketHandler energy = inputStream.readInt(); // Render beam - WarpDrive.debugPrint("Received beam packet from " + source + " to " + target + " as RGB " + r + " " + g + " " + b + " age " + age +" energy " + energy); +// 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) diff --git a/src/cr0s/WarpDrive/SoundHandler.java b/src/cr0s/WarpDrive/SoundHandler.java index 07f6e911..b0993218 100644 --- a/src/cr0s/WarpDrive/SoundHandler.java +++ b/src/cr0s/WarpDrive/SoundHandler.java @@ -5,14 +5,11 @@ import cpw.mods.fml.relauncher.SideOnly; import net.minecraftforge.client.event.sound.SoundLoadEvent; import net.minecraftforge.event.ForgeSubscribe; -public class SoundHandler -{ +public class SoundHandler { @SideOnly(Side.CLIENT) @ForgeSubscribe - public void onSoundLoad(SoundLoadEvent event) - { - try - { + public void onSoundLoad(SoundLoadEvent event) { + try { System.out.println("[WarpDrive] Registering sound files..."); event.manager.addSound("warpdrive:warp_4s.ogg"); event.manager.addSound("warpdrive:warp_10s.ogg"); @@ -22,9 +19,7 @@ public class SoundHandler event.manager.addSound("warpdrive:lowlaser.ogg"); event.manager.addSound("warpdrive:cloak.ogg"); event.manager.addSound("warpdrive:decloak.ogg"); - } - catch (Exception e) - { + } catch (Exception e) { System.err.println("Failed to register sound: " + e.getLocalizedMessage()); e.printStackTrace(); } diff --git a/src/cr0s/WarpDrive/SpaceWorldGenerator.java b/src/cr0s/WarpDrive/SpaceWorldGenerator.java index 5237390a..c9b9c5ed 100644 --- a/src/cr0s/WarpDrive/SpaceWorldGenerator.java +++ b/src/cr0s/WarpDrive/SpaceWorldGenerator.java @@ -212,9 +212,11 @@ public class SpaceWorldGenerator implements IWorldGenerator private float binomialRandom(World world) { float linear = world.rand.nextFloat(); - // ideal sphere repartition = linear ^ 0.5 (sqrt) + // ideal sphere repartition = x ^ 0.5 (sqrt) // Dilution but slow to compute = 0.5 * ( x ^ 0.3 + 1 + (x - 1) ^ 3 ) - // Optimized form = 1.25 - 0.625 / (0.5 + 2 * x) + // Optimized 'pushed out' form = 1.25 - 0.625 / (0.5 + 2 * x) + // Natural sphere with ring = (1 - x ^ 2.5) * x ^ 0.5 + x ^ 4 + // rectangular approach: return 0.5F * linear + 0.5F * linear * linear; return 1.25F - 0.625F / (0.5F + 2.0F * linear); } diff --git a/src/cr0s/WarpDrive/Vector3.java b/src/cr0s/WarpDrive/Vector3.java index 20ba8d48..de211dee 100644 --- a/src/cr0s/WarpDrive/Vector3.java +++ b/src/cr0s/WarpDrive/Vector3.java @@ -203,6 +203,14 @@ public class Vector3 implements Cloneable return Math.sqrt(var2 * var2 + var4 * var4 + var6 * var6); } + public double distanceTo_square(Vector3 vector3) + { + double var2 = vector3.x - this.x; + double var4 = vector3.y - this.y; + double var6 = vector3.z - this.z; + return var2 * var2 + var4 * var4 + var6 * var6; + } + /** * Multiplies the vector by negative one. */ diff --git a/src/cr0s/WarpDrive/WarpCoresRegistry.java b/src/cr0s/WarpDrive/WarpCoresRegistry.java index d36a0df2..c206639e 100644 --- a/src/cr0s/WarpDrive/WarpCoresRegistry.java +++ b/src/cr0s/WarpDrive/WarpCoresRegistry.java @@ -58,13 +58,15 @@ public class WarpCoresRegistry { public ArrayList searchWarpCoresInRadius(int x, int y, int z, int radius) { ArrayList res = new ArrayList(registry.size()); + printRegistry(); for (TileEntityReactor c : registry) { double d3 = c.xCoord - x; double d4 = c.yCoord - y; double d5 = c.zCoord - z; double distance = MathHelper.sqrt_double(d3 * d3 + d4 * d4 + d5 * d5); - if (distance <= radius && !(c.controller == null || c.controller.getMode() == 0) && !isCoreHidden(c)) { +// if (distance <= radius && !(c.controller == null || c.controller.getMode() == 0) && !isCoreHidden(c)) { + if (distance <= radius && !isCoreHidden(c)) { res.add(c); } } @@ -87,6 +89,7 @@ public class WarpCoresRegistry { int randomNumber = core.worldObj.rand.nextInt(150); if (randomNumber < LOWER_HIDE_POINT + core.isolationBlocksCount) { + WarpDrive.debugPrint("" + this + " Core '" + core.coreFrequency + "' is hidden"); return true; } } diff --git a/src/cr0s/WarpDrive/WarpDrive.java b/src/cr0s/WarpDrive/WarpDrive.java index 378d7d23..38943ae4 100644 --- a/src/cr0s/WarpDrive/WarpDrive.java +++ b/src/cr0s/WarpDrive/WarpDrive.java @@ -19,6 +19,8 @@ import cr0s.WarpDrive.item.*; import cr0s.WarpDrive.machines.*; import dan200.computercraft.api.ComputerCraftAPI; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -29,6 +31,8 @@ import net.minecraft.client.Minecraft; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.network.packet.Packet250CustomPayload; +import net.minecraft.server.MinecraftServer; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.common.Configuration; @@ -118,7 +122,7 @@ public class WarpDrive implements LoadingCallback { @EventHandler public void preInit(FMLPreInitializationEvent event) { - WarpDriveConfig.Init(new Configuration(event.getSuggestedConfigurationFile())); + WarpDriveConfig.preInit(new Configuration(event.getSuggestedConfigurationFile())); if (FMLCommonHandler.instance().getSide().isClient()) { Minecraft mc = Minecraft.getMinecraft(); @@ -149,7 +153,7 @@ public class WarpDrive implements LoadingCallback { @EventHandler public void load(FMLInitializationEvent event) { - WarpDriveConfig.Init2(); + WarpDriveConfig.load(); // CORE CONTROLLER protocolBlock = new BlockProtocol(WarpDriveConfig.controllerID,0, Material.rock); @@ -332,7 +336,7 @@ public class WarpDrive implements LoadingCallback { if (!WarpDriveConfig.recipesIC2) { initVanillaRecipes(); } - + warpCores = new WarpCoresRegistry(); jumpGates = new JumpGatesRegistry(); cams = new CamRegistry(); @@ -689,4 +693,80 @@ public class WarpDrive implements LoadingCallback { for (Ticket ticket : tickets) ForgeChunkManager.releaseTicket(ticket); } + + + public static void sendLaserPacket(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(); + } + + 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 + 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(); + packet.channel = "WarpDriveBeam"; + packet.data = bos.toByteArray(); + packet.length = bos.size(); + MinecraftServer.getServer().getConfigurationManager().sendToAllNear( + dest.intX(), dest.intY(), dest.intZ(), + radius, worldObj.provider.dimensionId, packet); + } + } } \ No newline at end of file diff --git a/src/cr0s/WarpDrive/WarpDriveConfig.java b/src/cr0s/WarpDrive/WarpDriveConfig.java index 6c12f9c2..ec121472 100644 --- a/src/cr0s/WarpDrive/WarpDriveConfig.java +++ b/src/cr0s/WarpDrive/WarpDriveConfig.java @@ -25,21 +25,21 @@ public class WarpDriveConfig /* * The variables which store whether or not individual mods are loaded */ - public static boolean isGregLoaded = false; - public static boolean isAELoaded = false; - public static boolean isAdvSolPanelLoaded = false; - public static boolean isASLoaded = false; - public static boolean isAEExtraLoaded = false; - public static boolean isICBMLoaded = false; - public static boolean isMFFSLoaded = false; - public static boolean isGraviSuiteLoaded = false; - public static boolean isICLoaded = false; - public static boolean isCCLoaded = false; - public static boolean isUndergroundBiomesLoaded = false; - public static boolean isNetherOresLoaded = false; - public static boolean isThermalExpansionLoaded = false; - public static boolean isMetallurgyLoaded = false; - + public static boolean isGregLoaded = false; + public static boolean isAELoaded = false; + public static boolean isAdvSolPanelLoaded = false; + public static boolean isASLoaded = false; + public static boolean isAEExtraLoaded = false; + public static boolean isICBMLoaded = false; + public static boolean isMFFSLoaded = false; + public static boolean isGraviSuiteLoaded = false; + public static boolean isICLoaded = false; + public static boolean isCCLoaded = false; + public static boolean isUndergroundBiomesLoaded = false; + public static boolean isNetherOresLoaded = false; + public static boolean isThermalExpansionLoaded = false; + public static boolean isMetallurgyLoaded = false; + public static boolean isAdvancedRepulsionSystemsLoaded = false; /* * The variables that control which recipes should be loaded @@ -50,13 +50,18 @@ public class WarpDriveConfig public static int[] IC2_Empty; public static int IC2_RubberWood; public static ItemStack IC2_Resin; - public static int CC_Computer = 0, CC_peripheral = 0, CC_Floppy = 0, CCT_Turtle = 0, CCT_Upgraded = 0, CCT_Advanced = 0, GT_Ores = 0, GT_Granite = 0, GT_Machine = 0, ASP = 0, AS_Turbine = 0, ICBM_Machine = 0, ICBM_Missile = 0, MFFS_Field = 0; + public static int CC_Computer = 0, CC_peripheral = 0, CC_Floppy = 0, CCT_Turtle = 0, CCT_Upgraded = 0, CCT_Advanced = 0; + public static int GT_Ores = 0, GT_Granite = 0, GT_Machine = 0; + public static int ASP = 0; + public static int AS_Turbine = 0; + public static int ICBM_Machine = 0, ICBM_Missile = 0; public static int UB_igneousStone = 0, UB_igneousCobblestone = 0, UB_metamorphicStone = 0, UB_metamorphicCobblestone = 0, UB_sedimentaryStone = 0; public static int NetherOres_count; public static int[] NetherOres_block; public static int[][] Metallurgy_overworldOresBlock; public static int[][] Metallurgy_netherOresBlock; public static int[][] Metallurgy_endOresBlock; + public static ArrayList forceFieldBlocks; public static Set SpaceHelmets, Jetpacks, MinerOres, MinerLogs, MinerLeaves, scannerIgnoreBlocks; private static Class AEBlocks; @@ -101,17 +106,19 @@ public class WarpDriveConfig // Mining Laser public static int ML_MAX_BOOSTERS_NUMBER = 1; - public static int ML_SCAN_DELAY = 20 * 5; - public static int ML_MINE_DELAY = 10; - public static int ML_EU_PER_LAYER_SPACE = 100; - public static int ML_EU_PER_LAYER_EARTH = 2500; - public static int ML_EU_PER_BLOCK_SPACE = 10; - public static int ML_EU_PER_BLOCK_EARTH = 50; + public static int ML_WARMUP_DELAY_TICKS = 20; + public static int ML_SCAN_DELAY_TICKS = 10; + public static int ML_MINE_DELAY_TICKS = 3; + public static int ML_EU_PER_LAYER_SPACE = 2000; + public static int ML_EU_PER_LAYER_EARTH = 10000; + public static int ML_EU_PER_BLOCK_SPACE = 500; + public static int ML_EU_PER_BLOCK_EARTH = 2500; + public static double ML_EU_MUL_ORESONLY = 4.0; public static double ML_EU_MUL_SILKTOUCH = 2.5; - public static double ML_EU_MUL_FORTUNE = 1.5; - public static double ML_MAX_SPEED = 10; - public static double ML_MIN_SPEED = 0.1; - public static int ML_MAX_SIZE = 128; + public static double ML_EU_MUL_FORTUNE = 2.5; +// public static double ML_MAX_SPEED = 10; +// public static double ML_MIN_SPEED = 0.1; + public static int ML_MAX_RADIUS = 6; //Tree farm public static int TF_MAX_SIZE=32; @@ -150,58 +157,44 @@ public class WarpDriveConfig public static int CD_FIELD_REFRESH_INTERVAL_SECONDS = 10; public static int CD_COIL_CAPTURE_BLOCKS = 5; - public static ItemStack getIC2Item(String id) - { + public static ItemStack getIC2Item(String id) { return Items.getItem(id); } - public static ItemStack getAEBlock(String id) - { - try - { + public static ItemStack getAEBlock(String id) { + try { Object ret = AEBlocks.getField(id).get(null); if (ret instanceof ItemStack) return (ItemStack)ret; - } - catch (Exception e) - { + } catch (Exception e) { WarpDrive.debugPrint("WarpDriveConfig Call getAEBlock failed for " + id); } return null; } - public static ItemStack getAEMaterial(String id) - { - try - { + public static ItemStack getAEMaterial(String id) { + try { Object ret = AEMaterials.getField(id).get(null); if (ret instanceof ItemStack) return (ItemStack)ret; - } - catch (Exception e) - { + } catch (Exception e) { WarpDrive.debugPrint("WarpDriveConfig Call getAEMaterial failed for " + id); } return null; } - public static ItemStack getAEItem(String id) - { - try - { + public static ItemStack getAEItem(String id) { + try { Object ret = AEItems.getField(id).get(null); if (ret instanceof ItemStack) return (ItemStack)ret; - } - catch (Exception e) - { + } catch (Exception e) { WarpDrive.debugPrint("WarpDriveConfig Call getAEItem failed for " + id); } return null; } - public static void Init(Configuration configIn) - { + public static void preInit(Configuration configIn) { config = configIn; } @@ -267,17 +260,19 @@ public class WarpDriveConfig // Mining Laser ML_MAX_BOOSTERS_NUMBER = config.get("MiningLaser", "max_boosters_number", 1).getInt(); - ML_SCAN_DELAY = 20 * config.get("MiningLaser", "scan_delay_seconds", 5).getInt(); - ML_MINE_DELAY = config.get("MiningLaser", "mine_delay_ticks", 10).getInt(); - ML_EU_PER_LAYER_SPACE = config.get("MiningLaser", "eu_per_layer_space", 100).getInt(); - ML_EU_PER_LAYER_EARTH = config.get("MiningLaser", "eu_per_layer_earth", 2500).getInt(); - ML_EU_PER_BLOCK_SPACE = config.get("MiningLaser", "eu_per_block_space", 10).getInt(); - ML_EU_PER_BLOCK_EARTH = config.get("MiningLaser", "eu_per_block_earth", 50).getInt(); - ML_MAX_SIZE = config.get("MiningLaser", "max_size", 128).getInt(); + ML_WARMUP_DELAY_TICKS = config.get("MiningLaser", "warmup_delay_ticks", 20).getInt(); + ML_SCAN_DELAY_TICKS = config.get("MiningLaser", "scan_delay_ticks", 10).getInt(); + ML_MINE_DELAY_TICKS = config.get("MiningLaser", "mine_delay_ticks", 3).getInt(); + ML_EU_PER_LAYER_SPACE = config.get("MiningLaser", "eu_per_layer_space", 2000).getInt(); + ML_EU_PER_LAYER_EARTH = config.get("MiningLaser", "eu_per_layer_earth", 10000).getInt(); + ML_EU_PER_BLOCK_SPACE = config.get("MiningLaser", "eu_per_block_space", 500).getInt(); + ML_EU_PER_BLOCK_EARTH = config.get("MiningLaser", "eu_per_block_earth", 2500).getInt(); + ML_MAX_RADIUS = config.get("MiningLaser", "max_radius", 5).getInt(); + ML_EU_MUL_ORESONLY = config.get("MiningLaser", "oresonly_power_mul", 4.0).getDouble(4.0); ML_EU_MUL_SILKTOUCH = config.get("MiningLaser", "silktouch_power_mul", 2.5).getDouble(2.5); - ML_EU_MUL_FORTUNE = config.get("MiningLaser", "fortune_power_base", 1.5).getDouble(1.5); - ML_MAX_SPEED = config.get("MiningLaser", "max_speed_mul", 10).getDouble(10); - ML_MIN_SPEED = config.get("MiningLaser", "min_speed_mul", 0.1).getDouble(0.1); + ML_EU_MUL_FORTUNE = config.get("MiningLaser", "fortune_power_base", 2.5).getDouble(2.5); +// ML_MAX_SPEED = config.get("MiningLaser", "max_speed_mul", 10).getDouble(10); +// ML_MIN_SPEED = config.get("MiningLaser", "min_speed_mul", 0.1).getDouble(0.1); // Tree Farm TF_MAX_SIZE = config.get("TreeFarm", "max_treefarm_size", 16).getInt(); @@ -296,7 +291,7 @@ public class WarpDriveConfig recipesIC2 = config.get("Recipes", "ic2_recipes",true).getBoolean(true); } - public static void Init2() { + public static void load() { CommonWorldGenOres = new ArrayList(30); CommonWorldGenOres.add(new int[] {Block.oreIron.blockID, 0}); CommonWorldGenOres.add(new int[] {Block.oreGold.blockID, 0}); @@ -305,7 +300,9 @@ public class WarpDriveConfig CommonWorldGenOres.add(new int[] {Block.oreLapis.blockID, 0}); CommonWorldGenOres.add(new int[] {Block.oreRedstoneGlowing.blockID, 0}); CommonWorldGenOres.add(new int[] {Block.oreRedstone.blockID, 0}); -// + + forceFieldBlocks = new ArrayList(); + SpaceHelmets = new HashSet(); Jetpacks = new HashSet(); MinerOres = new HashSet(); @@ -398,12 +395,17 @@ public class WarpDriveConfig loadMetallurgy(); } + isAdvancedRepulsionSystemsLoaded = Loader.isModLoaded("AdvancedRepulsionSystems"); + if (isAdvancedRepulsionSystemsLoaded) { + loadAdvancedRepulsionSystems(); + } // MinerOres.add(Block.oreNetherQuartz.blockID); MinerOres.add(Block.obsidian.blockID); MinerOres.add(Block.web.blockID); MinerOres.add(Block.fence.blockID); - //MinerOres.add(Block.torchWood.blockID); + MinerOres.add(Block.torchWood.blockID); + MinerOres.add(Block.glowStone.blockID); LoadOreDict(); // Ignore WarpDrive blocks (which potentially will be duplicated by cheaters using ship scan/deploy) scannerIgnoreBlocks.add(coreID); @@ -583,61 +585,48 @@ public class WarpDriveConfig } } - private static void loadICBM() - { - try - { + private static void loadICBM() { + try { Class z = Class.forName("icbm.core.ICBMCore"); CommonWorldGenOres.add(new int[] {((Block)z.getField("blockSulfurOre").get(null)).blockID, 0}); z = Class.forName("icbm.explosion.ICBMExplosion"); ICBM_Machine = ((Block)z.getField("blockMachine").get(null)).blockID; ICBM_Missile = ((Item)z.getField("itemMissile").get(null)).itemID; - } - catch (Exception e) - { + } catch (Exception e) { WarpDrive.debugPrint("WarpDriveConfig Error loading ICBM classes"); e.printStackTrace(); isICBMLoaded = false; } } - private static void loadMFFS() - { - try - { + private static void loadMFFS() { + try { Class z = Class.forName("mffs.ModularForceFieldSystem"); - MFFS_Field = ((Block)z.getField("blockForceField").get(null)).blockID; - } - catch (Exception e) - { + int blockId = ((Block)z.getField("blockForceField").get(null)).blockID; + forceFieldBlocks.add(blockId); + } catch (Exception e) { WarpDrive.debugPrint("WarpDriveConfig Error loading MFFS classes"); e.printStackTrace(); isICBMLoaded = false; } } - private static void loadGS() - { - try - { + private static void loadGS() { + try { Class z = Class.forName("gravisuite.GraviSuite"); if (z.getField("ultimateSolarHelmet").get(null) != null) SpaceHelmets.add(((Item)z.getField("ultimateSolarHelmet").get(null)).itemID); Jetpacks.add(z.getField("advJetpackID").getInt(null) + 256); Jetpacks.add(z.getField("graviChestPlateID").getInt(null) + 256); - } - catch (Exception e) - { + } catch (Exception e) { WarpDrive.debugPrint("WarpDriveConfig Error loading GS classes"); e.printStackTrace(); isGraviSuiteLoaded = false; } } - private static void loadUndergroundBiomes() - { - try - { + private static void loadUndergroundBiomes() { + try { Class z = Class.forName("exterminatorJeff.undergroundBiomes.common.UndergroundBiomes"); UB_igneousStone = ((Block)z.getField("igneousStone").get(null)).blockID; UB_igneousCobblestone = ((Block)z.getField("igneousCobblestone").get(null)).blockID; @@ -645,19 +634,15 @@ public class WarpDriveConfig UB_metamorphicCobblestone = ((Block)z.getField("metamorphicCobblestone").get(null)).blockID; UB_sedimentaryStone = ((Block)z.getField("sedimentaryStone").get(null)).blockID; WarpDrive.debugPrint("WarpDriveConfig found UndergroundBiomes blocks " + UB_igneousStone + ", " + UB_igneousCobblestone + ", " + UB_metamorphicStone + ", " + UB_metamorphicCobblestone + ", " + UB_sedimentaryStone); - } - catch (Exception e) - { + } catch (Exception e) { WarpDrive.debugPrint("WarpDriveConfig Error loading UndergroundBiomes classes"); e.printStackTrace(); isUndergroundBiomesLoaded = false; } } - private static void loadNetherOres() - { - try - { + private static void loadNetherOres() { + try { NetherOres_count = 21; // FIXME: extract it properly /* Class z = Class.forName("powercrystals.netherores.ores.Ores"); NO_netherOresCount = z.getField("values").get(null).length; @@ -704,7 +689,19 @@ public class WarpDriveConfig isMetallurgyLoaded = false; } } - + + private static void loadAdvancedRepulsionSystems() { + try { + Class z = Class.forName("mods.immibis.ars.ARSMod"); + int fieldBlockId = ((Block)z.getField("MFFSFieldblock").get(null)).blockID; + forceFieldBlocks.add(fieldBlockId); + } catch (Exception e) { + System.out.println("WarpDriveConfig Error loading AdvancedRepulsionSystems classes"); + e.printStackTrace(); + isAdvancedRepulsionSystemsLoaded = false; + } + } + public static int[] getDefaultSurfaceBlock(Random random, boolean corrupted, boolean isMoon) { if (isMoon) { if (isGregLoaded && (random.nextInt(100) == 1)) { diff --git a/src/cr0s/WarpDrive/machines/BlockMiningLaser.java b/src/cr0s/WarpDrive/machines/BlockMiningLaser.java index 22fbdf8b..62cbbc03 100644 --- a/src/cr0s/WarpDrive/machines/BlockMiningLaser.java +++ b/src/cr0s/WarpDrive/machines/BlockMiningLaser.java @@ -1,5 +1,6 @@ package cr0s.WarpDrive.machines; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import cr0s.WarpDrive.WarpDrive; @@ -10,12 +11,19 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.World; public class BlockMiningLaser extends BlockContainer { private Icon[] iconBuffer; + private final static int ICON_TOP = 5; + public final static int ICON_IDLE = 0; + public final static int ICON_MININGLOWPOWER = 1; + public final static int ICON_MININGPOWERED = 2; + public final static int ICON_SCANNINGLOWPOWER = 3; + public final static int ICON_SCANNINGPOWERED = 4; public BlockMiningLaser(int id, int texture, Material material) { super(id, material); @@ -28,19 +36,26 @@ public class BlockMiningLaser extends BlockContainer { @Override @SideOnly(Side.CLIENT) public void registerIcons(IconRegister par1IconRegister) { - iconBuffer = new Icon[2]; + iconBuffer = new Icon[16]; // Solid textures - iconBuffer[0] = par1IconRegister.registerIcon("warpdrive:particleBoosterTopBottom"); - iconBuffer[1] = par1IconRegister.registerIcon("warpdrive:miningLaserSide0"); + iconBuffer[ICON_TOP ] = par1IconRegister.registerIcon("warpdrive:particleBoosterTopBottom"); + iconBuffer[ICON_IDLE ] = par1IconRegister.registerIcon("warpdrive:miningLaser_idle"); + iconBuffer[ICON_MININGLOWPOWER ] = par1IconRegister.registerIcon("warpdrive:miningLaser_miningLowPower"); + iconBuffer[ICON_MININGPOWERED ] = par1IconRegister.registerIcon("warpdrive:miningLaser_miningPowered"); + iconBuffer[ICON_SCANNINGLOWPOWER] = par1IconRegister.registerIcon("warpdrive:miningLaser_scanningLowPower"); + iconBuffer[ICON_SCANNINGPOWERED ] = par1IconRegister.registerIcon("warpdrive:miningLaser_scanningPowered"); } @Override public Icon getIcon(int side, int metadata) { if (side == 0 || side == 1) { - return iconBuffer[0]; + return iconBuffer[ICON_TOP]; + } + if (metadata < iconBuffer.length) { + return iconBuffer[metadata]; + } else { + return null; } - - return iconBuffer[1]; } @Override @@ -63,4 +78,23 @@ public class BlockMiningLaser extends BlockContainer { public int idDropped(int par1, Random par2Random, int par3) { return this.blockID; } + + /** + * Called upon block activation (right click on the block.) + */ + @Override + public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { + if (FMLCommonHandler.instance().getEffectiveSide().isClient()) { + return false; + } + + TileEntityMiningLaser miningLaser = (TileEntityMiningLaser)par1World.getBlockTileEntity(par2, par3, par4); + + if (miningLaser != null && (par5EntityPlayer.getHeldItem() == null)) { + par5EntityPlayer.addChatMessage(miningLaser.getStatus()); + return true; + } + + return false; + } } \ No newline at end of file diff --git a/src/cr0s/WarpDrive/machines/BlockParticleBooster.java b/src/cr0s/WarpDrive/machines/BlockParticleBooster.java index b3cff859..52d9c4eb 100644 --- a/src/cr0s/WarpDrive/machines/BlockParticleBooster.java +++ b/src/cr0s/WarpDrive/machines/BlockParticleBooster.java @@ -30,7 +30,7 @@ public class BlockParticleBooster extends BlockContainer { @Override @SideOnly(Side.CLIENT) public void registerIcons(IconRegister par1IconRegister) { - iconBuffer = new Icon[12]; + iconBuffer = new Icon[16]; iconBuffer[ 0] = par1IconRegister.registerIcon("warpdrive:particleBoosterSide0"); iconBuffer[ 1] = par1IconRegister.registerIcon("warpdrive:particleBoosterSide1"); iconBuffer[ 2] = par1IconRegister.registerIcon("warpdrive:particleBoosterSide2"); diff --git a/src/cr0s/WarpDrive/machines/BlockRadar.java b/src/cr0s/WarpDrive/machines/BlockRadar.java index 6ded8234..f9cd6d93 100644 --- a/src/cr0s/WarpDrive/machines/BlockRadar.java +++ b/src/cr0s/WarpDrive/machines/BlockRadar.java @@ -20,7 +20,11 @@ public class BlockRadar extends BlockContainer { private Icon[] iconBuffer; - private final int ICON_INACTIVE_SIDE = 0, ICON_BOTTOM = 1, ICON_TOP = 2, ICON_SIDE_ACTIVATED = 3, ICON_SIDE_ACTIVATED_SCAN = 4; + private final int ICON_SIDE_INACTIVE = 0; + private final int ICON_BOTTOM = 1; + private final int ICON_TOP = 2; + private final int ICON_SIDE_ACTIVATED = 3; + private final int ICON_SIDE_ACTIVATED_SCAN = 4; public BlockRadar(int id, int texture, Material material) { super(id, material); @@ -33,8 +37,8 @@ public class BlockRadar extends BlockContainer @Override @SideOnly(Side.CLIENT) public void registerIcons(IconRegister par1IconRegister) { - iconBuffer = new Icon[5]; - iconBuffer[ICON_INACTIVE_SIDE] = par1IconRegister.registerIcon("warpdrive:radarSideInactive"); + iconBuffer = new Icon[16]; + iconBuffer[ICON_SIDE_INACTIVE] = par1IconRegister.registerIcon("warpdrive:radarSideInactive"); iconBuffer[ICON_BOTTOM] = par1IconRegister.registerIcon("warpdrive:contBottom"); iconBuffer[ICON_TOP] = par1IconRegister.registerIcon("warpdrive:contTop"); iconBuffer[ICON_SIDE_ACTIVATED] = par1IconRegister.registerIcon("warpdrive:radarSideActive"); @@ -50,14 +54,14 @@ public class BlockRadar extends BlockContainer } if (metadata == 0) {// Inactive state - return iconBuffer[ICON_INACTIVE_SIDE]; + return iconBuffer[ICON_SIDE_INACTIVE]; } else if (metadata == 1) { // Attached state return iconBuffer[ICON_SIDE_ACTIVATED]; } else if (metadata == 2) { // Scanning state return iconBuffer[ICON_SIDE_ACTIVATED_SCAN]; } - return iconBuffer[ICON_INACTIVE_SIDE]; + return iconBuffer[ICON_SIDE_INACTIVE]; } @Override diff --git a/src/cr0s/WarpDrive/machines/TileEntityAbstractLaser.java b/src/cr0s/WarpDrive/machines/TileEntityAbstractLaser.java index f692454f..4974bd43 100644 --- a/src/cr0s/WarpDrive/machines/TileEntityAbstractLaser.java +++ b/src/cr0s/WarpDrive/machines/TileEntityAbstractLaser.java @@ -12,52 +12,5 @@ import cr0s.WarpDrive.WarpDrive; public abstract class TileEntityAbstractLaser extends WarpChunkTE { - - protected void sendLaserPacket(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) - { - WarpDrive.debugPrint("laser:" + source + ":" + dest + ":" + r + ":" + g + ":" + b + ":" + age); - if (source == null || dest == null || worldObj == null) - { - return; - } - - 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(0); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "WarpDriveBeam"; - packet.data = bos.toByteArray(); - packet.length = bos.size(); - MinecraftServer.getServer().getConfigurationManager().sendToAllNear(source.intX(), source.intY(), source.intZ(), radius, worldObj.provider.dimensionId, packet); - MinecraftServer.getServer().getConfigurationManager().sendToAllNear(dest.intX(), dest.intY(), dest.intZ(), radius, worldObj.provider.dimensionId, packet); - } - } } diff --git a/src/cr0s/WarpDrive/machines/TileEntityAbstractMiner.java b/src/cr0s/WarpDrive/machines/TileEntityAbstractMiner.java index a3696b76..6cfcd239 100644 --- a/src/cr0s/WarpDrive/machines/TileEntityAbstractMiner.java +++ b/src/cr0s/WarpDrive/machines/TileEntityAbstractMiner.java @@ -12,8 +12,8 @@ import appeng.api.me.tiles.IGridMachine; import appeng.api.me.tiles.ITileCable; import appeng.api.me.util.IGridInterface; import appeng.api.me.util.IMEInventoryHandler; - import net.minecraft.block.Block; +import net.minecraft.block.BlockFluid; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -22,6 +22,7 @@ import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import cr0s.WarpDrive.Vector3; +import cr0s.WarpDrive.WarpDrive; import cr0s.WarpDrive.WarpDriveConfig; public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser implements IGridMachine, ITileCable @@ -194,13 +195,30 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im } return false; } - - protected boolean canDig(int blockID) - { - if (Block.blocksList[blockID] != null) - return ((blockID == WarpDriveConfig.GT_Granite || blockID == WarpDriveConfig.GT_Ores || blockID == WarpDriveConfig.iridiumID || Block.blocksList[blockID].blockResistance <= Block.obsidian.blockResistance) && blockID != WarpDriveConfig.MFFS_Field && blockID != Block.bedrock.blockID); - else - return (blockID != WarpDriveConfig.MFFS_Field && blockID != Block.bedrock.blockID); + + private boolean canDig(int blockID, int x, int y, int z) {// not used + // ignore air & fluids + if (!WarpDriveConfig.isAirBlock(worldObj, blockID, x, y, z) && Block.blocksList[blockID] != null && !(Block.blocksList[blockID] instanceof BlockFluid)) { + return false; + } + // check blacklist + if (blockID == Block.bedrock.blockID) { + return false; + } + if (WarpDriveConfig.forceFieldBlocks.contains(blockID)) { +// isMining = false; + return false; + } + // check whitelist + // WarpDriveConfig.i.MinerOres.contains(blockID) then true ? + else if (blockID == WarpDriveConfig.GT_Granite || blockID == WarpDriveConfig.GT_Ores || blockID == WarpDriveConfig.iridiumID) { + return true; + } + // check default + else if ( (Block.blocksList[blockID] != null) && (Block.blocksList[blockID].blockResistance <= Block.obsidian.blockResistance) ) { + return true; + } + return false; } //MINING FUNCTIONS @@ -211,7 +229,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im float r = getColorR(); float g = getColorG(); float b = getColorB(); - sendLaserPacket(minerVector, valuable.clone().translate(0.5), r, g, b, 2 * WarpDriveConfig.ML_MINE_DELAY, 0, 50); + WarpDrive.sendLaserPacket(worldObj, minerVector, valuable.clone().translate(0.5D), r, g, b, 2 * WarpDriveConfig.ML_MINE_DELAY_TICKS, 0, 50); //worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F); } diff --git a/src/cr0s/WarpDrive/machines/TileEntityLaser.java b/src/cr0s/WarpDrive/machines/TileEntityLaser.java index 79af9553..a81f8219 100644 --- a/src/cr0s/WarpDrive/machines/TileEntityLaser.java +++ b/src/cr0s/WarpDrive/machines/TileEntityLaser.java @@ -132,7 +132,7 @@ public class TileEntityLaser extends WarpTE implements IPeripheral { return; } - Vector3 beamVector = new Vector3(this).add(0.5); + Vector3 beamVector = new Vector3(this).translate(0.5D); System.out.println("beamVector: " + beamVector); float yawz = MathHelper.cos(-yaw * 0.017453292F - (float) Math.PI); float yawx = MathHelper.sin(-yaw * 0.017453292F - (float) Math.PI); @@ -155,7 +155,7 @@ public class TileEntityLaser extends WarpTE implements IPeripheral { firstHit = worldObj.rayTraceBlocks_do_do(beamVector.toVec3(), reachPoint.toVec3(), false, false); if (firstHit != null) { - sendLaserPacket(beamVector, new Vector3(firstHit), r, g, b, 50, energy, 200); + WarpDrive.sendLaserPacket(worldObj, beamVector, new Vector3(firstHit), r, g, b, 50, energy, 200); } return; } @@ -246,7 +246,7 @@ public class TileEntityLaser extends WarpTE implements IPeripheral { } } - sendLaserPacket(beamVector, endPoint, r, g, b, 50, energy, beamLengthBlocks); + WarpDrive.instance.sendLaserPacket(worldObj, beamVector, endPoint, r, g, b, 50, energy, beamLengthBlocks); } public MovingObjectPosition raytraceEntities(Vector3 beamVec, Vector3 lookVec, boolean collisionFlag, double reachDistance) { @@ -379,72 +379,6 @@ public class TileEntityLaser extends WarpTE implements IPeripheral { return null; } - public void sendLaserPacket(Vector3 source, Vector3 dest, float r, float g, float b, int age, int energy, int radius) { - if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { - 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 e) { - e.printStackTrace(); - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "WarpDriveBeam"; - packet.data = bos.toByteArray(); - packet.length = bos.size(); - MinecraftServer.getServer().getConfigurationManager().sendToAllNear(source.intX(), source.intY(), source.intZ(), radius, worldObj.provider.dimensionId, packet); - WarpDrive.debugPrint("" + this + " Packet '" + packet.channel + "' sent around source"); - - 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 e) { - e.printStackTrace(); - } - - Packet250CustomPayload packet2 = new Packet250CustomPayload(); - packet.channel = "WarpDriveBeam"; - packet.data = bos.toByteArray(); - packet.length = bos.size(); - MinecraftServer.getServer().getConfigurationManager().sendToAllNear(dest.intX(), dest.intY(), dest.intZ(), radius, worldObj.provider.dimensionId, packet); - WarpDrive.debugPrint("" + this + " Packet '" + packet.channel + "' sent around destination"); - } - } - private void playSoundCorrespondsEnergy(int energy) { if (energy <= 500000) { worldObj.playSoundEffect(xCoord + 0.5f, yCoord - 0.5f, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F); diff --git a/src/cr0s/WarpDrive/machines/TileEntityLaserReactorMonitor.java b/src/cr0s/WarpDrive/machines/TileEntityLaserReactorMonitor.java index 3c17cb39..566f7152 100644 --- a/src/cr0s/WarpDrive/machines/TileEntityLaserReactorMonitor.java +++ b/src/cr0s/WarpDrive/machines/TileEntityLaserReactorMonitor.java @@ -110,7 +110,7 @@ public class TileEntityLaserReactorMonitor extends TileEntityAbstractLaser { if(coolReactor(react)) { TileEntity te = (TileEntity)o; - sendLaserPacket(myPos,new Vector3(te.xCoord,te.yCoord,te.zCoord).translate(0.5),0f,0.8f,1f,20,0,20); + WarpDrive.sendLaserPacket(worldObj, myPos, new Vector3(te.xCoord,te.yCoord,te.zCoord).translate(0.5D), 0f, 0.8f, 1f, 20, 0, 20); } } } diff --git a/src/cr0s/WarpDrive/machines/TileEntityLift.java b/src/cr0s/WarpDrive/machines/TileEntityLift.java index 8cbbc684..27207f15 100644 --- a/src/cr0s/WarpDrive/machines/TileEntityLift.java +++ b/src/cr0s/WarpDrive/machines/TileEntityLift.java @@ -63,24 +63,22 @@ public class TileEntityLift extends WarpEnergyTE { worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, mode, 2); // current mode // Launch a beam: search non-air blocks under lift - for (int ny = yCoord - 1; ny > 0; ny--) - { - if (!worldObj.isAirBlock(xCoord, ny, zCoord)) - { + for (int ny = yCoord - 1; ny > 0; ny--) { + int blockId = worldObj.getBlockId(xCoord, ny, zCoord); + // 63 & 68 = signs + if (blockId != 0 && blockId != 63 && blockId != 68 && !WarpDriveConfig.isAirBlock(worldObj, blockId, xCoord, ny, zCoord)) { firstUncoveredY = ny; break; } } - if (yCoord - firstUncoveredY > 0) - if (mode == 1) - { - sendLaserPacket(new Vector3(this).add(0.5), new Vector3(xCoord, firstUncoveredY, zCoord).add(0.5), 0f, 1f, 0f, 40, 0, 100); - } - else if (mode == 2) - { - sendLaserPacket(new Vector3(this).add(0.5), new Vector3(xCoord, firstUncoveredY, zCoord).add(0.5), 0f, 0f, 1f, 40, 0, 100); + if (yCoord - firstUncoveredY > 0) { + if (mode == 1) { + WarpDrive.instance.sendLaserPacket(worldObj, new Vector3(this).translate(0.5D), new Vector3(xCoord, firstUncoveredY, zCoord).translate(0.5D), 0f, 1f, 0f, 40, 0, 100); + } else if (mode == 2) { + WarpDrive.instance.sendLaserPacket(worldObj, new Vector3(this).translate(0.5D), new Vector3(xCoord, firstUncoveredY, zCoord).translate(0.5D), 0f, 0f, 1f, 40, 0, 100); } + } liftEntity(); } @@ -132,7 +130,7 @@ public class TileEntityLift extends WarpEnergyTE { if (o != null && o instanceof EntityLivingBase) { ((EntityLivingBase)o).setPositionAndUpdate(xCoord + 0.5f, yCoord + 1, zCoord + 0.5f); - sendLaserPacket(new Vector3(this).add(0.5), new Vector3(xCoord, firstUncoveredY, zCoord).add(0.5), 1, 1, 0, 40, 0, 100); + WarpDrive.sendLaserPacket(worldObj, new Vector3(this).translate(0.5), new Vector3(xCoord, firstUncoveredY, zCoord).translate(0.5), 1F, 1F, 0F, 40, 0, 100); worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:hilaser", 4F, 1F); consumeAllEnergy(); return; @@ -152,7 +150,7 @@ public class TileEntityLift extends WarpEnergyTE { if (o != null && o instanceof EntityLivingBase) { ((EntityLivingBase)o).setPositionAndUpdate(xCoord + 0.5f, firstUncoveredY + 1, zCoord + 0.5f); - sendLaserPacket(new Vector3(this).add(0.5), new Vector3(xCoord, firstUncoveredY + 1, zCoord).add(0.5), 1, 1, 0, 40, 0, 100); + WarpDrive.sendLaserPacket(worldObj, new Vector3(this).translate(0.5), new Vector3(xCoord, firstUncoveredY + 1, zCoord).translate(0.5), 1F, 1F, 0F, 40, 0, 100); worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:hilaser", 4F, 1F); consumeAllEnergy(); return; @@ -162,79 +160,6 @@ public class TileEntityLift extends WarpEnergyTE { } } - public void sendLaserPacket(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(); - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "WarpDriveBeam"; - packet.data = bos.toByteArray(); - packet.length = bos.size(); - 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 - 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(); - packet.channel = "WarpDriveBeam"; - packet.data = bos.toByteArray(); - packet.length = bos.size(); - MinecraftServer.getServer().getConfigurationManager().sendToAllNear(dest.intX(), dest.intY(), dest.intZ(), radius, worldObj.provider.dimensionId, packet); - } - } - @Override public void readFromNBT(NBTTagCompound tag) { diff --git a/src/cr0s/WarpDrive/machines/TileEntityMiningLaser.java b/src/cr0s/WarpDrive/machines/TileEntityMiningLaser.java index b3e882a4..a036a1cb 100644 --- a/src/cr0s/WarpDrive/machines/TileEntityMiningLaser.java +++ b/src/cr0s/WarpDrive/machines/TileEntityMiningLaser.java @@ -3,6 +3,7 @@ package cr0s.WarpDrive.machines; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.api.peripheral.IComputerAccess; import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.peripheral.IPeripheral; @@ -14,7 +15,9 @@ import java.util.Arrays; import java.util.List; import net.minecraft.block.Block; +import net.minecraft.block.BlockFluid; import net.minecraft.block.material.Material; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -42,19 +45,19 @@ import appeng.api.me.util.IGridInterface; import appeng.api.me.util.IMEInventoryHandler; import cr0s.WarpDrive.*; -public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IGridMachine, ITileCable -{ +public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IGridMachine, ITileCable { Boolean powerStatus = false; private IGridInterface grid; private int dx, dz, dy; - private boolean isMining = false; + private boolean isMining() { + return currentState != STATE_IDLE; + } private boolean isQuarry = false; private boolean useDeiterium = false; private boolean AENetworkReady = false; - private String[] methodsArray = - { + private String[] methodsArray = { "mine", //0 "stop", //1 "isMining", //2 @@ -63,10 +66,15 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG "offset" //5 }; + private int delayTicksWarmup = 0; private int delayTicksScan = 0; private int delayTicksMine = 0; - private int currentMode = 0; // 0 - scan next layer, 1 - collect valuables - + private final int STATE_IDLE = 0; + private final int STATE_WARMUP = 1; + private final int STATE_SCANNING = 2; + private final int STATE_MINING = 3; + private int currentState = 0; // 0 - scan next layer, 1 - collect valuables + private boolean enoughPower = false; private int currentLayer; private ArrayList valuablesInLayer = new ArrayList(); @@ -74,162 +82,225 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG private int layerOffset = 1; - private Vector3 minerVector; - //private long uid = 0; - - TileEntityParticleBooster booster = null; - - private boolean isOnEarth = false; - //int t = 20; @Override public void updateEntity() { - if (isMining) { - isOnEarth = (worldObj.provider.dimensionId == 0); - - if (minerVector != null) { - minerVector.x = xCoord; - minerVector.y = yCoord - 1; - minerVector.z = zCoord; - minerVector = minerVector.add(0.5); + if (FMLCommonHandler.instance().getEffectiveSide().isClient()) { + return; + } + if (currentState == STATE_IDLE) { + delayTicksWarmup = 0; + delayTicksScan = 0; + delayTicksMine = 0; + updateMetadata(BlockMiningLaser.ICON_IDLE); + return; + } + + boolean isOnEarth = (worldObj.provider.dimensionId == 0); + + Vector3 minerVector = new Vector3(xCoord + 0.5D, yCoord, zCoord + 0.5D); + + if (currentState == STATE_WARMUP) { // warming up + delayTicksWarmup++; + updateMetadata(BlockMiningLaser.ICON_SCANNINGLOWPOWER); + if (delayTicksWarmup >= WarpDriveConfig.ML_WARMUP_DELAY_TICKS) { + delayTicksScan = 0; + currentState = STATE_SCANNING; + updateMetadata(BlockMiningLaser.ICON_SCANNINGLOWPOWER); + return; } - - if (currentMode == 0) { // scanning - delayTicksScan++; - if (delayTicksScan > WarpDriveConfig.ML_SCAN_DELAY) { + } else if (currentState == STATE_SCANNING) { // scanning + delayTicksScan++; + if (delayTicksScan == 1) { + // check power level + enoughPower = consumeEnergyPacketFromBooster(isOnEarth ? WarpDriveConfig.ML_EU_PER_LAYER_EARTH : WarpDriveConfig.ML_EU_PER_LAYER_SPACE, true); + if (!enoughPower) { + updateMetadata(BlockMiningLaser.ICON_SCANNINGLOWPOWER); delayTicksScan = 0; - valuablesInLayer.clear(); - valuableIndex = 0; - if (!consumeEnergyPacketFromBooster(isOnEarth ? WarpDriveConfig.ML_EU_PER_LAYER_EARTH : WarpDriveConfig.ML_EU_PER_LAYER_SPACE, true)) - return; - while (currentLayer > 0) { - scanLayer(); - if (valuablesInLayer.size() > 0) { - if (!consumeEnergyPacketFromBooster(isOnEarth ? WarpDriveConfig.ML_EU_PER_LAYER_EARTH : WarpDriveConfig.ML_EU_PER_LAYER_SPACE, false)) { - return; - } - sendLaserPacket(minerVector, new Vector3(xCoord, currentLayer, zCoord).add(0.5), 0, 0, 1, 20, 0, 50); - worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:hilaser", 4F, 1F); - int blockID = worldObj.getBlockId(xCoord, currentLayer, zCoord); - if (blockID != 0) - if (canDig(blockID)) - harvestBlock(new Vector3(xCoord, currentLayer, zCoord)); - currentMode = 1; - return; - } else { - currentLayer--; - } - } - if (currentLayer <= 0) { - isMining = false; - } + return; + } else { + updateMetadata(BlockMiningLaser.ICON_SCANNINGPOWERED); } - } else { // mining - delayTicksMine++; - if (delayTicksMine > WarpDriveConfig.ML_MINE_DELAY && isMining) { + // show current layer + int age = Math.max(40, 5 * WarpDriveConfig.ML_SCAN_DELAY_TICKS); + double xmax = xCoord + WarpDriveConfig.ML_MAX_RADIUS + 1.0D; + double xmin = xCoord - WarpDriveConfig.ML_MAX_RADIUS + 0.0D; + double zmax = zCoord + WarpDriveConfig.ML_MAX_RADIUS + 1.0D; + double zmin = zCoord - WarpDriveConfig.ML_MAX_RADIUS + 0.0D; + double y = currentLayer + 1.0D; + WarpDrive.sendLaserPacket(worldObj, new Vector3(xmin, y, zmin), new Vector3(xmax, y, zmin), 0.3F, 0.0F, 1.0F, age, 0, 50); + WarpDrive.sendLaserPacket(worldObj, new Vector3(xmax, y, zmin), new Vector3(xmax, y, zmax), 0.3F, 0.0F, 1.0F, age, 0, 50); + WarpDrive.sendLaserPacket(worldObj, new Vector3(xmax, y, zmax), new Vector3(xmin, y, zmax), 0.3F, 0.0F, 1.0F, age, 0, 50); + WarpDrive.sendLaserPacket(worldObj, new Vector3(xmin, y, zmax), new Vector3(xmin, y, zmin), 0.3F, 0.0F, 1.0F, age, 0, 50); + } else if (delayTicksScan >= WarpDriveConfig.ML_SCAN_DELAY_TICKS) { + delayTicksScan = 0; + if (currentLayer <= 0) { + stop(); + return; + } + // consume power + enoughPower = consumeEnergyPacketFromBooster(isOnEarth ? WarpDriveConfig.ML_EU_PER_LAYER_EARTH : WarpDriveConfig.ML_EU_PER_LAYER_SPACE, false); + if (!enoughPower) { + updateMetadata(BlockMiningLaser.ICON_SCANNINGLOWPOWER); + return; + } else { + updateMetadata(BlockMiningLaser.ICON_SCANNINGPOWERED); + } + // scan + scanLayer(); + if (valuablesInLayer.size() > 0) { + int r = (int)Math.ceil(WarpDriveConfig.ML_MAX_RADIUS / 2.0D); + int offset = (yCoord - currentLayer) % (2 * r); + int age = Math.max(20, Math.round(2.5F * WarpDriveConfig.ML_SCAN_DELAY_TICKS)); + double y = currentLayer + 1.0D; + WarpDrive.sendLaserPacket(worldObj, minerVector, new Vector3(xCoord - r + offset, y, zCoord + r ).translate(0.3D), 0.0F, 0.0F, 1.0F, age, 0, 50); + WarpDrive.sendLaserPacket(worldObj, minerVector, new Vector3(xCoord + r , y, zCoord + r - offset).translate(0.3D), 0.0F, 0.0F, 1.0F, age, 0, 50); + WarpDrive.sendLaserPacket(worldObj, minerVector, new Vector3(xCoord + r - offset, y, zCoord - r ).translate(0.3D), 0.0F, 0.0F, 1.0F, age, 0, 50); + WarpDrive.sendLaserPacket(worldObj, minerVector, new Vector3(xCoord - r , y, zCoord - r + offset).translate(0.3D), 0.0F, 0.0F, 1.0F, age, 0, 50); + worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:hilaser", 4F, 1F); delayTicksMine = 0; - - if (valuableIndex < valuablesInLayer.size()) { - //System.out.println("[ML] Mining: " + (valuableIndex + 1) + "/" + valuablesInLayer.size()); - Vector3 valuable = valuablesInLayer.get(valuableIndex++); - // Mine valuable ore - int blockID = worldObj.getBlockId(valuable.intX(), valuable.intY(), valuable.intZ()); - - if (blockID == 0) { - delayTicksMine = (int) (WarpDriveConfig.ML_MINE_DELAY * 0.8F); - } - // Skip if block is too hard or its empty block - if (!canDig(blockID)) { - return; - } - - sendLaserPacket(minerVector, new Vector3(valuable.intX(), valuable.intY(), valuable.intZ()).add(0.5), 1, 1, 0, 2 * WarpDriveConfig.ML_MINE_DELAY, 0, 50); - worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F); - harvestBlock(valuable); - return; - } - - currentMode = 0; + currentState = STATE_MINING; + updateMetadata(BlockMiningLaser.ICON_MININGPOWERED); + return; + } else { + worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F); currentLayer--; } } + } else if (currentState == STATE_MINING) { // mining + delayTicksMine++; + if (delayTicksMine >= WarpDriveConfig.ML_MINE_DELAY_TICKS) { + delayTicksMine = 0; + + if (valuableIndex >= valuablesInLayer.size()) { + delayTicksScan = 0; + currentState = STATE_SCANNING; + updateMetadata(BlockMiningLaser.ICON_SCANNINGPOWERED); + // rescan same layer + scanLayer(); + if (valuablesInLayer.size() <= 0) { + currentLayer--; + } + return; + } + + // consume power + enoughPower = consumeEnergyPacketFromBooster(isOnEarth ? WarpDriveConfig.ML_EU_PER_BLOCK_EARTH : WarpDriveConfig.ML_EU_PER_BLOCK_SPACE, false); + if (!enoughPower) { + updateMetadata(BlockMiningLaser.ICON_MININGLOWPOWER); + return; + } else { + updateMetadata(BlockMiningLaser.ICON_MININGPOWERED); + } + + //System.out.println("[ML] Mining: " + (valuableIndex + 1) + "/" + valuablesInLayer.size()); + Vector3 valuable = valuablesInLayer.get(valuableIndex); + valuableIndex++; + // Mine valuable ore + int blockID = worldObj.getBlockId(valuable.intX(), valuable.intY(), valuable.intZ()); + // Skip if block is too hard or its empty block (check again in case it changed) + if (!canDig(blockID, valuable.intX(), valuable.intY(), valuable.intZ())) { + delayTicksMine = Math.round(WarpDriveConfig.ML_MINE_DELAY_TICKS * 0.8F); + } + int age = Math.max(10, Math.round((4 + worldObj.rand.nextFloat()) * WarpDriveConfig.ML_MINE_DELAY_TICKS)); + WarpDrive.sendLaserPacket(worldObj, minerVector, new Vector3(valuable.intX(), valuable.intY(), valuable.intZ()).translate(0.5D), 1.0F, 1.0F, 0.0F, age, 0, 50); + worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F); + harvestBlock(valuable); + } } } + private void updateMetadata(int metadata) { + int blockId = worldObj.getBlockId(xCoord, yCoord, zCoord); + if (blockId == WarpDriveConfig.miningLaserID) { + worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, metadata, 2); + } + } - private boolean canDig(int blockID) { + private void stop() { + // WarpDrive.debugPrint("" + this + " Stop requested"); + currentState = STATE_IDLE; + updateMetadata(BlockMiningLaser.ICON_IDLE); + } + + private boolean canDig(int blockID, int x, int y, int z) { + // ignore air + if (WarpDriveConfig.isAirBlock(worldObj, blockID, x, y, z)) { + return false; + } // check blacklist - if (blockID == WarpDriveConfig.MFFS_Field || blockID == Block.bedrock.blockID) { + if (blockID == Block.bedrock.blockID) { + return false; + } + if (WarpDriveConfig.forceFieldBlocks.contains(blockID)) { + stop(); return false; } // check whitelist - // WarpDriveConfig.i.MinerOres.contains(blockID) then true ? - else if (blockID == WarpDriveConfig.GT_Granite || blockID == WarpDriveConfig.GT_Ores || blockID == WarpDriveConfig.iridiumID) { + if (WarpDriveConfig.MinerOres.contains(blockID)) { return true; } // check default - else if ( (Block.blocksList[blockID] != null) && (Block.blocksList[blockID].blockResistance <= Block.obsidian.blockResistance) ) { + if ( (Block.blocksList[blockID] != null) && (Block.blocksList[blockID].blockResistance <= Block.obsidian.blockResistance) ) { return true; } + WarpDrive.debugPrint("" + this + " Rejecting " + blockID + " at (" + x + ", " + y + ", " + z + ")"); return false; } private void harvestBlock(Vector3 valuable) { int blockID = worldObj.getBlockId(valuable.intX(), valuable.intY(), valuable.intZ()); int blockMeta = worldObj.getBlockMetadata(valuable.intX(), valuable.intY(), valuable.intZ()); - if (blockID != Block.waterMoving.blockID && blockID != Block.waterStill.blockID && blockID != Block.lavaMoving.blockID && blockID != Block.lavaStill.blockID) - { + if (Block.blocksList[blockID] != null && (Block.blocksList[blockID] instanceof BlockFluid)) { + // Evaporate fluid + worldObj.playSoundEffect((double)((float)valuable.intX() + 0.5F), (double)((float)valuable.intY() + 0.5F), (double)((float)valuable.intZ() + 0.5F), "random.fizz", 0.5F, 2.6F + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) * 0.8F); + } else { List stacks = getItemStackFromBlock(valuable.intX(), valuable.intY(), valuable.intZ(), blockID, blockMeta); - if (stacks != null) - for (ItemStack stack : stacks) - { - if (grid != null && AENetworkReady) + if (stacks != null) { + boolean overflow = false; + for (ItemStack stack : stacks) { + if (grid != null && AENetworkReady) { putInGrid(stack); - else - putInChest(findChest(), stack); + } else { + if (!putInChest(findChest(), stack)) { + WarpDrive.debugPrint("" + this + " Overflow detected"); + overflow = true; + } + } } + if (overflow) { + stop(); + } + } + // standard harvest block effect worldObj.playAuxSFXAtEntity(null, 2001, valuable.intX(), valuable.intY(), valuable.intZ(), blockID + (blockMeta << 12)); } - else if (blockID == Block.waterMoving.blockID || blockID == Block.waterStill.blockID) - // Evaporate water - worldObj.playSoundEffect((double)((float)valuable.intX() + 0.5F), (double)((float)valuable.intY() + 0.5F), (double)((float)valuable.intZ() + 0.5F), "random.fizz", 0.5F, 2.6F + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) * 0.8F); worldObj.setBlockToAir(valuable.intX(), valuable.intY(), valuable.intZ()); } - private IInventory findChest() - { + private IInventory findChest() { TileEntity result = null; result = worldObj.getBlockTileEntity(xCoord + 1, yCoord, zCoord); - - if (result != null && result instanceof IInventory) - { + if (result != null && result instanceof IInventory) { return (IInventory) result; } result = worldObj.getBlockTileEntity(xCoord - 1, yCoord, zCoord); - - if (result != null && result instanceof IInventory) - { + if (result != null && result instanceof IInventory) { return (IInventory) result; } result = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord + 1); - - if (result != null && result instanceof IInventory) - { + if (result != null && result instanceof IInventory) { return (IInventory) result; } result = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord - 1); - - if (result != null && result instanceof IInventory) - { + if (result != null && result instanceof IInventory) { return (IInventory) result; } result = worldObj.getBlockTileEntity(xCoord, yCoord + 1, zCoord); - - if (result != null && result instanceof IInventory) - { + if (result != null && result instanceof IInventory) { return (IInventory) result; } @@ -274,65 +345,66 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG return transferred; } - public int putInChest(IInventory inventory, ItemStack itemStackSource) - { - if (inventory == null || itemStackSource == null) { - isMining = false; //stopping operation - return 0; + public boolean putInChest(IInventory inventory, ItemStack itemStackSource) { + if (itemStackSource == null) { + stop(); + return false; } - int transferred = 0; + int qtyLeft = itemStackSource.stackSize; + int transfer; - for (int i = 0; i < inventory.getSizeInventory(); i++) - { - if (!inventory.isItemValidForSlot(i, itemStackSource)) - { - continue; + if (inventory != null) { + // fill existing stacks first + for (int i = 0; i < inventory.getSizeInventory(); i++) { + if (!inventory.isItemValidForSlot(i, itemStackSource)) { + continue; + } + + ItemStack itemStack = inventory.getStackInSlot(i); + if (itemStack == null || !itemStack.isItemEqual(itemStackSource)) { + continue; + } + + transfer = Math.min(qtyLeft, itemStack.getMaxStackSize() - itemStack.stackSize); + itemStack.stackSize += transfer; + qtyLeft -= transfer; + if (qtyLeft <= 0) { + return true; + } } - - ItemStack itemStack = inventory.getStackInSlot(i); - - if (itemStack == null || !itemStack.isItemEqual(itemStackSource)) - { - continue; - } - - int transfer = Math.min(itemStackSource.stackSize - transferred, itemStack.getMaxStackSize() - itemStack.stackSize); - itemStack.stackSize += transfer; - transferred += transfer; - - if (transferred == itemStackSource.stackSize) - { - return transferred; + + // put remaining in empty slot + for (int i = 0; i < inventory.getSizeInventory(); i++) { + if (!inventory.isItemValidForSlot(i, itemStackSource)) { + continue; + } + + ItemStack itemStack = inventory.getStackInSlot(i); + if (itemStack != null) { + continue; + } + + transfer = Math.min(qtyLeft, itemStackSource.getMaxStackSize()); + ItemStack dest = copyWithSize(itemStackSource, transfer); + inventory.setInventorySlotContents(i, dest); + qtyLeft -= transfer; + + if (qtyLeft <= 0) { + return true; + } } } - for (int i = 0; i < inventory.getSizeInventory(); i++) - { - if (!inventory.isItemValidForSlot(i, itemStackSource)) - { - continue; - } - - ItemStack itemStack = inventory.getStackInSlot(i); - - if (itemStack != null) - { - continue; - } - - int transfer = Math.min(itemStackSource.stackSize - transferred, itemStackSource.getMaxStackSize()); - ItemStack dest = copyWithSize(itemStackSource, transfer); - inventory.setInventorySlotContents(i, dest); - transferred += transfer; - - if (transferred == itemStackSource.stackSize) - { - return transferred; - } + while (qtyLeft > 0) { + transfer = Math.min(qtyLeft, itemStackSource.getMaxStackSize()); + ItemStack dropItemStack = copyWithSize(itemStackSource, transfer); + EntityItem itemEnt = new EntityItem(worldObj, xCoord + 0.5D, yCoord + 1.0D, zCoord + 0.5D, dropItemStack); + worldObj.spawnEntityInWorld(itemEnt); + qtyLeft -= transfer; } - - return transferred; + + return false; } public ItemStack copyWithSize(ItemStack itemStack, int newSize) @@ -342,68 +414,94 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG return ret; } - private void scanLayer() - { + private void scanLayer() { //System.out.println("Scanning layer"); valuablesInLayer.clear(); - int xmax, zmax, x1, x2, z1, z2; + valuableIndex = 0; + int radius, x, z, blockID; + int xmax, zmax; int xmin, zmin; - final int CUBE_SIDE = 8; - x1 = xCoord + CUBE_SIDE / 2; - x2 = xCoord - CUBE_SIDE / 2; - - if (x1 < x2) - { - xmin = x1; - xmax = x2; - } - else - { - xmin = x2; - xmax = x1; - } - - z1 = zCoord + CUBE_SIDE / 2; - z2 = zCoord - CUBE_SIDE / 2; - - if (z1 < z2) - { - zmin = z1; - zmax = z2; - } - else - { - zmin = z2; - zmax = z1; - } - - //System.out.println("Layer: xmax: " + xmax + ", xmin: " + xmin); - //System.out.println("Layer: zmax: " + zmax + ", zmin: " + zmin); // Search for valuable blocks - for (int x = xmin; x <= xmax; x++) - for (int z = zmin; z <= zmax; z++) - { - int blockID = worldObj.getBlockId(x, currentLayer, z); - if (canDig(blockID)) - if (isQuarry) // Quarry collects all blocks - { - if (!worldObj.isAirBlock(x, currentLayer, z) && blockID != Block.lavaMoving.blockID && blockID != Block.lavaStill.blockID) - valuablesInLayer.add(new Vector3(x, currentLayer, z)); - } - else // Not-quarry collect only valuables blocks - if (WarpDriveConfig.MinerOres.contains(worldObj.getBlockId(x, currentLayer, z))) - valuablesInLayer.add(new Vector3(x, currentLayer, z)); + x = xCoord; + z = zCoord; + blockID = worldObj.getBlockId(x, currentLayer, z); + if (canDig(blockID, x, currentLayer, z)) { + if (isQuarry || WarpDriveConfig.MinerOres.contains(blockID)) {// Quarry collects all blocks or only collect valuables blocks + valuablesInLayer.add(new Vector3(x, currentLayer, z)); } + } + for (radius = 1; radius <= WarpDriveConfig.ML_MAX_RADIUS; radius++) { + xmax = xCoord + radius; + xmin = xCoord - radius; + zmax = zCoord + radius; + zmin = zCoord - radius; + x = xCoord; + z = zmin; + for (; x <= xmax; x++) { + blockID = worldObj.getBlockId(x, currentLayer, z); + if (canDig(blockID, x, currentLayer, z)) { + if (isQuarry || WarpDriveConfig.MinerOres.contains(blockID)) {// Quarry collects all blocks or only collect valuables blocks + valuablesInLayer.add(new Vector3(x, currentLayer, z)); + } + } + } + x = xmax; + z++; + for (; z <= zmax; z++) { + blockID = worldObj.getBlockId(x, currentLayer, z); + if (canDig(blockID, x, currentLayer, z)) { + if (isQuarry || WarpDriveConfig.MinerOres.contains(blockID)) {// Quarry collects all blocks or only collect valuables blocks + valuablesInLayer.add(new Vector3(x, currentLayer, z)); + } + } + } + x--; + z = zmax; + for (; x >= xmin; x--) { + blockID = worldObj.getBlockId(x, currentLayer, z); + if (canDig(blockID, x, currentLayer, z)) { + if (isQuarry || WarpDriveConfig.MinerOres.contains(blockID)) {// Quarry collects all blocks or only collect valuables blocks + valuablesInLayer.add(new Vector3(x, currentLayer, z)); + } + } + } + x = xmin; + z--; + for (; z > zmin; z--) { + blockID = worldObj.getBlockId(x, currentLayer, z); + if (canDig(blockID, x, currentLayer, z)) { + if (isQuarry || WarpDriveConfig.MinerOres.contains(blockID)) {// Quarry collects all blocks or only collect valuables blocks + valuablesInLayer.add(new Vector3(x, currentLayer, z)); + } + } + } + x = xmin; + z = zmin; + for (; x < xCoord; x++) { + blockID = worldObj.getBlockId(x, currentLayer, z); + if (canDig(blockID, x, currentLayer, z)) { + if (isQuarry || WarpDriveConfig.MinerOres.contains(blockID)) {// Quarry collects all blocks or only collect valuables blocks + valuablesInLayer.add(new Vector3(x, currentLayer, z)); + } + } + } + } - valuableIndex = 0; - //System.out.println("[ML] Found " + valuablesInLayer.size() + " valuables"); + //System.out.println("" + this + " Found " + valuablesInLayer.size() + " valuables"); + } + + private int getEnergyLevel() { + TileEntityParticleBooster booster = findFirstBooster(); + if (booster != null) { + return booster.getEnergyStored(); + } else { + return 0; + } } private boolean consumeEnergyPacketFromBooster(int amount, boolean simulate) { - if (booster == null) { - booster = findFirstBooster(); - } + TileEntityParticleBooster booster = findFirstBooster(); if (booster != null) { return booster.consumeEnergy(amount, simulate); } else { @@ -411,8 +509,7 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG } } - private TileEntityParticleBooster findFirstBooster() - { + private TileEntityParticleBooster findFirstBooster() { TileEntity result; result = worldObj.getBlockTileEntity(xCoord + 1, yCoord, zCoord); @@ -467,246 +564,218 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG return null; } - public void sendLaserPacket(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) - { - if (source == null || dest == null || worldObj == null) - { - return; - } - - 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(0); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "WarpDriveBeam"; - packet.data = bos.toByteArray(); - packet.length = bos.size(); - MinecraftServer.getServer().getConfigurationManager().sendToAllNear(source.intX(), source.intY(), source.intZ(), radius, worldObj.provider.dimensionId, packet); - MinecraftServer.getServer().getConfigurationManager().sendToAllNear(dest.intX(), dest.intY(), dest.intZ(), radius, worldObj.provider.dimensionId, packet); + @Override + public void readFromNBT(NBTTagCompound tag) { + super.readFromNBT(tag); + currentState = tag.getInteger("currentState"); + isQuarry = tag.getBoolean("isQuarry"); + currentLayer = tag.getInteger("currentLayer"); + useDeiterium = tag.getBoolean("useDeiterium"); + if (currentState == STATE_MINING) { + scanLayer(); } } @Override - public void readFromNBT(NBTTagCompound tag) - { - super.readFromNBT(tag); - isMining = tag.getBoolean("isMining"); - isQuarry = tag.getBoolean("isQuarry"); - currentLayer = tag.getInteger("currentLayer"); - useDeiterium = tag.getBoolean("useDeiterium"); - minerVector = new Vector3(xCoord, yCoord - 1, zCoord).add(0.5); - } - - @Override - public void writeToNBT(NBTTagCompound tag) - { + public void writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); - tag.setBoolean("isMining", isMining); + tag.setInteger("currentState", currentState); tag.setBoolean("isQuarry", isQuarry); tag.setInteger("currentLayer", currentLayer); tag.setBoolean("useDeiterium", useDeiterium); } -//CC + + // ComputerCraft // IPeripheral methods implementation @Override - public String getType() - { + public String getType() { return "mininglaser"; } @Override - public String[] getMethodNames() - { + public String[] getMethodNames() { return methodsArray; } @Override - public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception - { - switch (method) - { + public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception { + switch (method) { case 0: // Mine() - if (isMining) + if (isMining()) { return new Boolean[] { false }; + } + isQuarry = false; - delayTicksScan = 0; - currentMode = 0; - minerVector = new Vector3(xCoord, yCoord - 1, zCoord).add(0.5); - currentLayer = yCoord - layerOffset; - isMining = true; + delayTicksWarmup = 0; + currentState = STATE_WARMUP; + currentLayer = yCoord - layerOffset - 1; useDeiterium = (arguments.length == 1 && FluidRegistry.isFluidRegistered("deuterium")); return new Boolean[] { true }; case 1: // stop() - isMining = false; + stop(); break; case 2: // isMining() - return new Boolean[] { isMining }; + return new Boolean[] { isMining() }; case 3: // Quarry() - if (isMining) + if (isMining()) { return new Boolean[] { false }; + } isQuarry = true; delayTicksScan = 0; - currentMode = 0; - minerVector = new Vector3(xCoord, yCoord - 1, zCoord).add(0.5); - currentLayer = yCoord - layerOffset; - isMining = true; + currentState = STATE_WARMUP; + currentLayer = yCoord - layerOffset - 1; useDeiterium = (arguments.length == 1 && FluidRegistry.isFluidRegistered("deuterium")); return new Boolean[] { true }; case 4: // State is: state, energy, currentLayer, valuablesMined, valuablesInLayer = getMinerState() - int energy = 0; - if (booster != null) { - energy = booster.getEnergyStored(); + int energy = getEnergyLevel(); + String status = getStatus(); + Integer retValuablesInLayer, retValuablesMined; + if (isMining()) { + retValuablesInLayer = valuablesInLayer.size(); + retValuablesMined = valuableIndex; + + return new Object[] {status, energy, currentLayer, retValuablesMined, retValuablesInLayer}; } - String state = "not mining"; - Integer valuablesInLayer, valuablesMined; - if (isMining) { - valuablesInLayer = this.valuablesInLayer.size(); - valuablesMined = this.valuableIndex; - state = "mining" + ((isQuarry) ? " (quarry mode)" : ""); - if (energy < 0) { - state = "out of energy"; - } - return new Object[] {state, energy, currentLayer, valuablesMined, valuablesInLayer}; - } - return new Object[] {state, energy, currentLayer, 0, 0}; + return new Object[] {status, energy, currentLayer, 0, 0}; case 5: // Offset if (arguments.length == 1) { - int t = ((Double)arguments[0]).intValue(); - if (t < 0) - t = 0; - layerOffset = t + 1; + try { + layerOffset = Math.min(256, Math.abs(((Double)arguments[0]).intValue())); + } catch(Exception e) { + return new Integer[] { layerOffset }; + } } - return new Integer[] { layerOffset-1 }; + return new Integer[] { layerOffset }; } return null; } - - @Override - public void attach(IComputerAccess computer) - { + + public String getStatus() { + int energy = 0; + energy = getEnergyLevel(); + String state = "IDLE (not mining)"; + if (currentState == STATE_IDLE) { + state = "IDLE (not mining)"; + } else if (currentState == STATE_WARMUP) { + state = "Warming up..."; + } else if (currentState == STATE_SCANNING) { + if (isQuarry) { + state = "Scanning all"; + } else { + state = "Scanning ores"; + } + } else if (currentState == STATE_MINING) { + if (isQuarry) { + state = "Mining all"; + } else { + state = "Mining ores"; + } + if (useDeiterium) { + state = state + " using Deuterium"; + } + } + if (energy <= 0) { + state = state + " - Out of energy"; + } else if (((currentState == STATE_SCANNING) || (currentState == STATE_MINING)) && !enoughPower) { + state = state + " - Not enough power"; + } + return state; } @Override - public void detach(IComputerAccess computer) - { - } -//AE - @Override - public float getPowerDrainPerTick() - { - return 1; + public void attach(IComputerAccess computer) { + computer.mount("/mininglaser", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/mininglaser")); + computer.mount("/mine", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/mininglaser/mine")); + computer.mount("/stop", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/mininglaser/stop")); } @Override - public void validate() - { - super.validate(); - MinecraftForge.EVENT_BUS.post(new GridTileLoadEvent(this, worldObj, getLocation())); + public void detach(IComputerAccess computer) { } - @Override - public void invalidate() - { - super.invalidate(); - MinecraftForge.EVENT_BUS.post(new GridTileUnloadEvent(this, worldObj, getLocation())); - } - - @Override - public WorldCoord getLocation() - { - return new WorldCoord(xCoord, yCoord, zCoord); - } - - @Override - public boolean isValid() - { - return true; - } - - @Override - public void setPowerStatus(boolean hasPower) - { - powerStatus = hasPower; - } - - @Override - public boolean isPowered() - { - return powerStatus; - } - - @Override - public IGridInterface getGrid() - { - return grid; - } - - @Override - public void setGrid(IGridInterface gi) - { - grid = gi; - } - - @Override - public World getWorld() - { - return worldObj; - } - - @Override - public boolean coveredConnections() - { - return true; - } - - public void setNetworkReady( boolean isReady ) - { - AENetworkReady = isReady; - } - - public boolean isMachineActive() - { - return true; - } - - @Override public boolean equals(IPeripheral other) { // TODO Auto-generated method stub return false; } + + // Applied Energistics @Override + + public float getPowerDrainPerTick() { + return 1; + } + + @Override + public void validate() { + super.validate(); + MinecraftForge.EVENT_BUS.post(new GridTileLoadEvent(this, worldObj, getLocation())); + } + + @Override + public void invalidate() { + super.invalidate(); + MinecraftForge.EVENT_BUS.post(new GridTileUnloadEvent(this, worldObj, getLocation())); + } + + @Override + public WorldCoord getLocation() { + return new WorldCoord(xCoord, yCoord, zCoord); + } + + @Override + public boolean isValid() { + return true; + } + + @Override + public void setPowerStatus(boolean hasPower) { + powerStatus = hasPower; + } + + @Override + public boolean isPowered() { + return powerStatus; + } + + @Override + public IGridInterface getGrid() { + return grid; + } + + @Override + public void setGrid(IGridInterface parGrid) { + grid = parGrid; + } + + @Override + public World getWorld() { + return worldObj; + } + + @Override + public boolean coveredConnections() { + return true; + } + + public void setNetworkReady( boolean isReady ) { + AENetworkReady = isReady; + } + + public boolean isMachineActive() { + return isMining(); + } + + @Override + public String toString() { + return String.format("%s @ \'%s\' %d, %d, %d", new Object[] { + getClass().getSimpleName(), + worldObj == null ? "~NULL~" : worldObj.getWorldInfo().getWorldName(), + Integer.valueOf(xCoord), Integer.valueOf(yCoord), Integer.valueOf(zCoord)}); + } } diff --git a/src/cr0s/WarpDrive/machines/TileEntityParticleBooster.java b/src/cr0s/WarpDrive/machines/TileEntityParticleBooster.java index eecdda5d..a3abb25e 100644 --- a/src/cr0s/WarpDrive/machines/TileEntityParticleBooster.java +++ b/src/cr0s/WarpDrive/machines/TileEntityParticleBooster.java @@ -28,9 +28,9 @@ public class TileEntityParticleBooster extends WarpEnergyTE { super.updateEntity(); ticks++; - if (ticks > 40) { + if (ticks > 20) { ticks = 0; - worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, Math.min(0, Math.max(10, (getEnergyStored() * 10) / WarpDriveConfig.PB_MAX_ENERGY_VALUE)), 2); + worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, Math.max(0, Math.min(10, Math.round((getEnergyStored() * 10) / WarpDriveConfig.PB_MAX_ENERGY_VALUE))), 2); } } diff --git a/src/cr0s/WarpDrive/machines/TileEntityRadar.java b/src/cr0s/WarpDrive/machines/TileEntityRadar.java index feec2ae1..01b14ba6 100644 --- a/src/cr0s/WarpDrive/machines/TileEntityRadar.java +++ b/src/cr0s/WarpDrive/machines/TileEntityRadar.java @@ -3,6 +3,7 @@ package cr0s.WarpDrive.machines; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.api.peripheral.IComputerAccess; import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.peripheral.IPeripheral; @@ -43,20 +44,19 @@ public class TileEntityRadar extends WarpEnergyTE implements IPeripheral { } super.updateEntity(); - try - { + try { if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 2) { - if (cooldownTime++ > (20 * ((scanRadius / 1000) + 1))) { - //System.out.println("Scanning..."); + cooldownTime++; + if (cooldownTime > (20 * ((scanRadius / 1000) + 1))) { + WarpDrive.debugPrint("" + this + " Scanning over " + scanRadius + " radius..."); WarpDrive.instance.warpCores.removeDeadCores(); results = WarpDrive.instance.warpCores.searchWarpCoresInRadius(xCoord, yCoord, zCoord, scanRadius); + WarpDrive.debugPrint("" + this + " Scan found " + results.size() + " results"); worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 1 + 2); cooldownTime = 0; } } - } - catch (Exception e) - { + } catch (Exception e) { e.printStackTrace(); } } @@ -73,22 +73,18 @@ public class TileEntityRadar extends WarpEnergyTE implements IPeripheral { // IPeripheral methods implementation @Override - public String getType() - { + public String getType() { return "radar"; } @Override - public String[] getMethodNames() - { + public String[] getMethodNames() { return methodsArray; } @Override - public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception - { - switch (method) - { + public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception { + switch (method) { case 0: // scanRay (toX, toY, toZ) return new Object[] { -1 }; @@ -96,13 +92,19 @@ public class TileEntityRadar extends WarpEnergyTE implements IPeripheral { if (arguments.length != 1) { return new Boolean[] { false }; } - int radius = ((Double)arguments[0]).intValue(); - if (radius <= 0 || radius > 10000) - { + int radius; + try { + radius = ((Double)arguments[0]).intValue(); + } catch(Exception e) { + return new Boolean[] { false }; + } + + if (radius <= 0 || radius > 10000) { scanRadius = 0; + results = null; return new Boolean[] { false }; } - if (radius == 0 || !consumeEnergy(radius * radius, false)) { + if (!consumeEnergy(Math.max(radius, 100) * Math.max(radius, 100), false)) { results = null; return new Boolean[] { false }; } @@ -110,20 +112,25 @@ public class TileEntityRadar extends WarpEnergyTE implements IPeripheral { // Begin searching scanRadius = radius; cooldownTime = 0; + results = null; worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 2, 1 + 2); return new Boolean[] { true }; case 2: // getResultsCount - if (results != null) + if (results != null) { return new Integer[] { results.size() }; + } return new Integer[] { 0 }; case 3: // getResult - if (arguments.length == 1 && (results != null)) - { - int index = ((Double)arguments[0]).intValue(); - if (index > -1 && index < results.size()) - { + if (arguments.length == 1 && (results != null)) { + int index; + try { + index = ((Double)arguments[0]).intValue(); + } catch(Exception e) { + return new Object[] { (String)"FAIL", 0, 0, 0 }; + } + if (index >= 0 && index < results.size()) { TileEntityReactor res = results.get(index); if (res != null) { @@ -146,12 +153,17 @@ public class TileEntityRadar extends WarpEnergyTE implements IPeripheral { @Override public void attach(IComputerAccess computer) { - worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 1 + 2); + computer.mount("/radar", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/radar")); + computer.mount("/scan", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/radar/scan")); + computer.mount("/ping", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/radar/ping")); + if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 0) { + worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 1 + 2); + } } @Override public void detach(IComputerAccess computer) { - worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 1 + 2); + // worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 1 + 2); } @Override diff --git a/src/cr0s/WarpDrive/machines/TileEntityShipScanner.java b/src/cr0s/WarpDrive/machines/TileEntityShipScanner.java index d59c68f6..c5c51fc6 100644 --- a/src/cr0s/WarpDrive/machines/TileEntityShipScanner.java +++ b/src/cr0s/WarpDrive/machines/TileEntityShipScanner.java @@ -97,9 +97,9 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { if (state == 0) { // inactive if (++laserTicks > 20) { - sendLaserPacket(new Vector3(this).add(0.5), new Vector3( - core.xCoord, core.yCoord, core.zCoord).add(0.5), 0f, - 1f, 0f, 40, 0, 100); + WarpDrive.sendLaserPacket(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 (state == 1 && !isDeploying) { // active: scanning @@ -145,7 +145,7 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { g = 0f; } - sendLaserPacket(new Vector3(this).add(0.5), new Vector3(x, core.maxY, randomZ).add(0.5), r, g, b, 15, 0, 100); + WarpDrive.sendLaserPacket(worldObj, new Vector3(this).translate(0.5D), new Vector3(x, core.maxY, randomZ).translate(0.5D), r, g, b, 15, 0, 100); } } @@ -187,9 +187,10 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { if (worldObj.rand.nextInt(100) <= 10) { worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F); - sendLaserPacket(new Vector3(this).add(0.5), new Vector3( - newX + block.x, newY + block.y, newZ + block.z).add(0.5), 0f, - 1f, 0f, 15, 0, 100); + WarpDrive.sendLaserPacket(worldObj, + new Vector3(this).translate(0.5D), + new Vector3(newX + block.x, newY + block.y, newZ + block.z).translate(0.5D), + 0f, 1f, 0f, 15, 0, 100); } } @@ -226,80 +227,6 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral { return result; } - public void sendLaserPacket(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(); - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "WarpDriveBeam"; - packet.data = bos.toByteArray(); - packet.length = bos.size(); - 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 - 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(); - packet.channel = "WarpDriveBeam"; - packet.data = bos.toByteArray(); - packet.length = bos.size(); - MinecraftServer - .getServer() - .getConfigurationManager() - .sendToAllNear(dest.intX(), dest.intY(), dest.intZ(), - radius, worldObj.provider.dimensionId, packet); - } - } - private void saveShipToSchematic(String fileName) { NBTTagCompound schematic = new NBTTagCompound("Schematic"); diff --git a/src/cr0s/WarpDrive/machines/WarpEnergyTE.java b/src/cr0s/WarpDrive/machines/WarpEnergyTE.java index 5090446a..cfb31d2c 100644 --- a/src/cr0s/WarpDrive/machines/WarpEnergyTE.java +++ b/src/cr0s/WarpDrive/machines/WarpEnergyTE.java @@ -12,12 +12,11 @@ import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.MinecraftForge; -public abstract class WarpEnergyTE extends WarpTE implements IEnergyHandler, IEnergySink -{ +public abstract class WarpEnergyTE extends WarpTE implements IEnergyHandler, IEnergySink { protected boolean addedToEnergyNet = false; protected int energyStored_internal = 0; - private final double INTERNAL_TO_EU = 1.0D; - private final double INTERNAL_TO_RF = 437.5D / 1800.0D; + private static final double EU_PER_INTERNAL = 1.0D; + private static final double RF_PER_INTERNAL = 1800.0D / 437.5D; // WarpDrive methods public int getEnergyStored() { @@ -92,20 +91,20 @@ public abstract class WarpEnergyTE extends WarpTE implements IEnergyHandler, IEn // IndustrialCraft overrides @Override public double demandedEnergyUnits() { - return Math.max(0.0D, getMaxEnergyStored() - energyStored_internal) * INTERNAL_TO_EU; + return Math.max(0.0D, getMaxEnergyStored() - energyStored_internal) * EU_PER_INTERNAL; } @Override public double injectEnergyUnits(ForgeDirection directionFrom, double amount) { double leftover = 0; - energyStored_internal += Math.round(amount) / INTERNAL_TO_EU; + energyStored_internal += Math.round(amount) / EU_PER_INTERNAL; if (energyStored_internal > getMaxEnergyStored()) { leftover = (energyStored_internal - getMaxEnergyStored()); energyStored_internal = getMaxEnergyStored(); } - return leftover * INTERNAL_TO_EU; + return leftover * EU_PER_INTERNAL; } @Override @@ -121,24 +120,25 @@ public abstract class WarpEnergyTE extends WarpTE implements IEnergyHandler, IEn // ThermalExpansion overrides @Override public int getEnergyStored(ForgeDirection from) { - return (int)(getEnergyStored() * INTERNAL_TO_RF); + return (int)Math.round(getEnergyStored() * RF_PER_INTERNAL); } @Override public int getMaxEnergyStored(ForgeDirection from) { - return (int)(getMaxEnergyStored() * INTERNAL_TO_RF); + return (int)Math.round(getMaxEnergyStored() * RF_PER_INTERNAL); } @Override public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) { - int maxStored = (int)(getMaxEnergyStored() * INTERNAL_TO_RF); + int maxStored = getMaxEnergyStored(from); if (maxStored == 0) { return 0; } + int energyStored = getEnergyStored(from); - int toAdd = Math.min(maxReceive, maxStored - (int)(getEnergyStored() * INTERNAL_TO_RF)); + int toAdd = Math.min(maxReceive, maxStored - energyStored); if (!simulate) { - energyStored_internal += toAdd / INTERNAL_TO_RF; + energyStored_internal = (int)Math.min(getMaxEnergyStored(), energyStored_internal + toAdd / RF_PER_INTERNAL); } return toAdd;