diff --git a/src/main/java/cr0s/warpdrive/block/breathing/BlockAirGeneratorTiered.java b/src/main/java/cr0s/warpdrive/block/breathing/BlockAirGeneratorTiered.java index 2747b0d6..7fb6f5ad 100644 --- a/src/main/java/cr0s/warpdrive/block/breathing/BlockAirGeneratorTiered.java +++ b/src/main/java/cr0s/warpdrive/block/breathing/BlockAirGeneratorTiered.java @@ -51,7 +51,7 @@ public class BlockAirGeneratorTiered extends BlockAbstractContainer { @SideOnly(Side.CLIENT) @Override - public IIcon getIcon(IBlockAccess blockAccess, int x, int y, int z, int side) { + public IIcon getIcon(final IBlockAccess blockAccess, final int x, final int y, final int z, final int side) { final int metadata = blockAccess.getBlockMetadata(x, y, z); if (side == (metadata & 7)) { if ((metadata & 8) == 0) { // Inactive state @@ -66,7 +66,7 @@ public class BlockAirGeneratorTiered extends BlockAbstractContainer { @SideOnly(Side.CLIENT) @Override - public IIcon getIcon(int side, int metadata) { + public IIcon getIcon(final int side, final int metadata) { if (side == 3) { return iconBuffer[ICON_SIDE_ACTIVATED]; } @@ -80,7 +80,7 @@ public class BlockAirGeneratorTiered extends BlockAbstractContainer { } @Override - public int quantityDropped(Random random) { + public int quantityDropped(final Random random) { return 1; } @@ -95,28 +95,29 @@ public class BlockAirGeneratorTiered extends BlockAbstractContainer { } @Override - public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) { + public boolean onBlockActivated(final World world, final int x, final int y, final int z, + final EntityPlayer entityPlayer, final int side, final float hitX, final float hitY, final float hitZ) { if (world.isRemote) { return false; } - TileEntity tileEntity = world.getTileEntity(x, y, z); + final TileEntity tileEntity = world.getTileEntity(x, y, z); if (tileEntity instanceof TileEntityAirGeneratorTiered) { - TileEntityAirGeneratorTiered airGenerator = (TileEntityAirGeneratorTiered)tileEntity; - ItemStack itemStackHeld = entityPlayer.getHeldItem(); + final TileEntityAirGeneratorTiered airGenerator = (TileEntityAirGeneratorTiered)tileEntity; + final ItemStack itemStackHeld = entityPlayer.getHeldItem(); if (itemStackHeld == null) { Commons.addChatMessage(entityPlayer, airGenerator.getStatus()); return true; } else { - Item itemHeld = itemStackHeld.getItem(); + final Item itemHeld = itemStackHeld.getItem(); if (itemHeld instanceof IAirContainerItem) { - IAirContainerItem airCanister = (IAirContainerItem) itemHeld; + final IAirContainerItem airCanister = (IAirContainerItem) itemHeld; if (airCanister.canContainAir(itemStackHeld) && airGenerator.energy_consume(WarpDriveConfig.BREATHING_ENERGY_PER_CANISTER, true)) { entityPlayer.inventory.decrStackSize(entityPlayer.inventory.currentItem, 1); - ItemStack toAdd = airCanister.getFullAirContainer(itemStackHeld); + final ItemStack toAdd = airCanister.getFullAirContainer(itemStackHeld); if (toAdd != null) { if (!entityPlayer.inventory.addItemStackToInventory(toAdd)) { - EntityItem entityItem = new EntityItem(entityPlayer.worldObj, entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, toAdd); + final EntityItem entityItem = new EntityItem(entityPlayer.worldObj, entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, toAdd); entityPlayer.worldObj.spawnEntityInWorld(entityItem); } ((EntityPlayerMP)entityPlayer).sendContainerToPlayer(entityPlayer.inventoryContainer); diff --git a/src/main/java/cr0s/warpdrive/block/breathing/TileEntityAirGeneratorTiered.java b/src/main/java/cr0s/warpdrive/block/breathing/TileEntityAirGeneratorTiered.java index 3d4923fb..b060d4a1 100644 --- a/src/main/java/cr0s/warpdrive/block/breathing/TileEntityAirGeneratorTiered.java +++ b/src/main/java/cr0s/warpdrive/block/breathing/TileEntityAirGeneratorTiered.java @@ -41,7 +41,7 @@ public class TileEntityAirGeneratorTiered extends TileEntityAbstractEnergy { @Override protected void onFirstUpdateTick() { super.onFirstUpdateTick(); - Block block = getBlockType(); + final Block block = getBlockType(); if (block instanceof BlockAirGeneratorTiered) { tier = ((BlockAirGeneratorTiered) block).tier; maxEnergyStored = WarpDriveConfig.BREATHING_MAX_ENERGY_STORED[tier - 1]; @@ -152,7 +152,7 @@ public class TileEntityAirGeneratorTiered extends TileEntityAbstractEnergy { xCoord, yCoord, zCoord); } - public Object[] enable(Object[] arguments) { + public Object[] enable(final Object[] arguments) { if (arguments.length == 1 && arguments[0] != null) { isEnabled = Commons.toBool(arguments[0]); } @@ -162,14 +162,14 @@ public class TileEntityAirGeneratorTiered extends TileEntityAbstractEnergy { // OpenComputer callback methods @Callback @Optional.Method(modid = "OpenComputers") - public Object[] enable(Context context, Arguments arguments) { + public Object[] enable(final Context context, final Arguments arguments) { return enable(argumentsOCtoCC(arguments)); } // ComputerCraft IPeripheral methods implementation @Override @Optional.Method(modid = "ComputerCraft") - public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) { + public Object[] callMethod(final IComputerAccess computer, final ILuaContext context, final int method, final Object[] arguments) { final String methodName = getMethodName(method); switch (methodName) { diff --git a/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java b/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java index 69096255..f7611de7 100644 --- a/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java +++ b/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java @@ -41,7 +41,6 @@ import cr0s.warpdrive.data.EnumDisplayAlignment; import cr0s.warpdrive.data.EnumTooltipCondition; import cr0s.warpdrive.network.PacketHandler; import org.xml.sax.ErrorHandler; -import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import javax.xml.parsers.DocumentBuilder; @@ -435,7 +434,7 @@ public class WarpDriveConfig { public static Block getModBlock(final String mod, final String id) { try { return GameRegistry.findBlock(mod, id); - } catch (Exception exception) { + } catch (final Exception exception) { WarpDrive.logger.info(String.format("Failed to get mod block for %s:%s", mod, id)); exception.printStackTrace(); } @@ -483,12 +482,12 @@ public class WarpDriveConfig { private static ItemStack getModItemStackOrNull(final String mod, final String id, final int meta) { try { - ItemStack item = new ItemStack((Item) Item.itemRegistry.getObject(mod + ":" + id)); + final ItemStack item = new ItemStack((Item) Item.itemRegistry.getObject(mod + ":" + id)); if (meta != -1) { item.setItemDamage(meta); } return item; - } catch (Exception exception) { + } catch (final Exception exception) { WarpDrive.logger.info(String.format("Failed to get mod item for %s:%s@%d", mod, id, meta)); return null; } @@ -1058,7 +1057,7 @@ public class WarpDriveConfig { config.save(); } - public static void registerBlockTransformer(final String modId, IBlockTransformer blockTransformer) { + public static void registerBlockTransformer(final String modId, final IBlockTransformer blockTransformer) { blockTransformers.put(modId, blockTransformer); WarpDrive.logger.info(modId + " blockTransformer registered"); } @@ -1130,79 +1129,97 @@ public class WarpDriveConfig { } isNotEnoughItemsLoaded = Loader.isModLoaded("NotEnoughItems"); - boolean isBotaniaLoaded = Loader.isModLoaded("Botania"); + final boolean isBotaniaLoaded = Loader.isModLoaded("Botania"); if (isBotaniaLoaded) { CompatBotania.register(); } - boolean isBiblioCraftLoaded = Loader.isModLoaded("BiblioCraft"); + + final boolean isBiblioCraftLoaded = Loader.isModLoaded("BiblioCraft"); if (isBiblioCraftLoaded) { CompatBiblioCraft.register(); } - boolean isBuildCraftLoaded = Loader.isModLoaded("BuildCraft|Core"); + + final boolean isBuildCraftLoaded = Loader.isModLoaded("BuildCraft|Core"); if (isBuildCraftLoaded) { CompatBuildCraft.register(); } - boolean isCarpentersBlocksLoaded = Loader.isModLoaded("CarpentersBlocks"); + + final boolean isCarpentersBlocksLoaded = Loader.isModLoaded("CarpentersBlocks"); if (isCarpentersBlocksLoaded) { CompatCarpentersBlocks.register(); } - boolean isCustomNpcsLoaded = Loader.isModLoaded("customnpcs"); + + final boolean isCustomNpcsLoaded = Loader.isModLoaded("customnpcs"); if (isCustomNpcsLoaded) { CompatCustomNpcs.register(); } - boolean isDraconicEvolutionLoaded = Loader.isModLoaded("DraconicEvolution"); + + final boolean isDraconicEvolutionLoaded = Loader.isModLoaded("DraconicEvolution"); if (isDraconicEvolutionLoaded) { CompatDraconicEvolution.register(); } - boolean isEvilCraftLoaded = Loader.isModLoaded("evilcraft"); + + final boolean isEvilCraftLoaded = Loader.isModLoaded("evilcraft"); if (isEvilCraftLoaded) { CompatEvilCraft.register(); } - boolean isJABBAloaded = Loader.isModLoaded("JABBA"); + + final boolean isJABBAloaded = Loader.isModLoaded("JABBA"); if (isJABBAloaded) { CompatJABBA.register(); } - boolean isMekanismLoaded = Loader.isModLoaded("Mekanism"); + + final boolean isMekanismLoaded = Loader.isModLoaded("Mekanism"); if (isMekanismLoaded) { CompatMekanism.register(); } - boolean isMetallurgyLoaded = Loader.isModLoaded("Metallurgy"); + + final boolean isMetallurgyLoaded = Loader.isModLoaded("Metallurgy"); if (isMetallurgyLoaded) { CompatMetallurgy.register(); } - boolean isNaturaLoaded = Loader.isModLoaded("Natura"); + + final boolean isNaturaLoaded = Loader.isModLoaded("Natura"); if (isNaturaLoaded) { CompatNatura.register(); } - boolean isPneumaticCraftLoaded = Loader.isModLoaded("PneumaticCraft"); + + final boolean isPneumaticCraftLoaded = Loader.isModLoaded("PneumaticCraft"); if (isPneumaticCraftLoaded) { CompatPneumaticCraft.register(); } - boolean isRedstonePasteLoaded = Loader.isModLoaded("RedstonePasteMod"); + + final boolean isRedstonePasteLoaded = Loader.isModLoaded("RedstonePasteMod"); if (isRedstonePasteLoaded) { CompatRedstonePaste.register(); } - boolean isSGCraftLoaded = Loader.isModLoaded("SGCraft"); + + final boolean isSGCraftLoaded = Loader.isModLoaded("SGCraft"); if (isSGCraftLoaded) { CompatSGCraft.register(); } - boolean isStargateTech2Loaded = Loader.isModLoaded("StargateTech2"); + + final boolean isStargateTech2Loaded = Loader.isModLoaded("StargateTech2"); if (isStargateTech2Loaded) { CompatStargateTech2.register(); } - boolean isTConstructLoaded = Loader.isModLoaded("TConstruct"); + + final boolean isTConstructLoaded = Loader.isModLoaded("TConstruct"); if (isTConstructLoaded) { CompatTConstruct.register(); } - boolean isTechgunsLoaded = Loader.isModLoaded("Techguns"); + + final boolean isTechgunsLoaded = Loader.isModLoaded("Techguns"); if (isTechgunsLoaded) { CompatTechguns.register(); } - boolean isThaumcraftLoaded = Loader.isModLoaded("Thaumcraft"); + + final boolean isThaumcraftLoaded = Loader.isModLoaded("Thaumcraft"); if (isThaumcraftLoaded) { CompatThaumcraft.register(); } - boolean isThermalDynamicsLoaded = Loader.isModLoaded("ThermalDynamics"); + + final boolean isThermalDynamicsLoaded = Loader.isModLoaded("ThermalDynamics"); if (isThermalDynamicsLoaded) { CompatThermalDynamics.register(); } @@ -1224,7 +1241,7 @@ public class WarpDriveConfig { IC2_rubberWood = getModBlock("IC2", "blockRubWood"); IC2_Resin = getModItemStack("IC2", "itemHarz", -1); - } catch (Exception exception) { + } catch (final Exception exception) { WarpDrive.logger.error("Error loading IndustrialCraft2 classes"); exception.printStackTrace(); } @@ -1237,7 +1254,7 @@ public class WarpDriveConfig { CCT_Turtle = getModBlock("ComputerCraft", "CC-Turtle"); CCT_Expanded = getModBlock("ComputerCraft", "CC-TurtleExpanded"); CCT_Advanced = getModBlock("ComputerCraft", "CC-TurtleAdvanced"); - } catch (Exception exception) { + } catch (final Exception exception) { WarpDrive.logger.error("Error loading ComputerCraft classes"); exception.printStackTrace(); } @@ -1246,9 +1263,9 @@ public class WarpDriveConfig { public static DocumentBuilder getXmlDocumentBuilder() { if (xmlDocumentBuilder == null) { - ErrorHandler xmlErrorHandler = new ErrorHandler() { + final ErrorHandler xmlErrorHandler = new ErrorHandler() { @Override - public void warning(SAXParseException exception) throws SAXException { + public void warning(final SAXParseException exception) { WarpDrive.logger.warn(String.format("XML warning at line %d: %s", exception.getLineNumber(), exception.getLocalizedMessage() )); @@ -1256,7 +1273,7 @@ public class WarpDriveConfig { } @Override - public void fatalError(SAXParseException exception) throws SAXException { + public void fatalError(final SAXParseException exception) { WarpDrive.logger.warn(String.format("XML fatal error at line %d: %s", exception.getLineNumber(), exception.getLocalizedMessage() )); @@ -1264,7 +1281,7 @@ public class WarpDriveConfig { } @Override - public void error(SAXParseException exception) throws SAXException { + public void error(final SAXParseException exception) { WarpDrive.logger.warn(String.format("XML error at line %d: %s", exception.getLineNumber(), exception.getLocalizedMessage() )); @@ -1273,7 +1290,7 @@ public class WarpDriveConfig { } }; - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setIgnoringComments(false); documentBuilderFactory.setNamespaceAware(true); documentBuilderFactory.setValidating(true); @@ -1281,7 +1298,7 @@ public class WarpDriveConfig { try { xmlDocumentBuilder = documentBuilderFactory.newDocumentBuilder(); - } catch (ParserConfigurationException exception) { + } catch (final ParserConfigurationException exception) { exception.printStackTrace(); } xmlDocumentBuilder.setErrorHandler(xmlErrorHandler); @@ -1295,7 +1312,7 @@ public class WarpDriveConfig { * Target folder should be already created **/ private static void unpackResourcesToFolder(final String prefix, final String suffix, final String[] filenames, final String resourcePathSource, File folderTarget) { - File[] files = configDirectory.listFiles((file_notUsed, name) -> name.startsWith(prefix) && name.endsWith(suffix)); + final File[] files = configDirectory.listFiles((file_notUsed, name) -> name.startsWith(prefix) && name.endsWith(suffix)); if (files == null) { throw new RuntimeException(String.format("Critical error accessing configuration directory, searching for %s*%s files: %s", prefix, suffix, configDirectory)); } @@ -1310,16 +1327,16 @@ public class WarpDriveConfig { * Copy a default configuration file from the mod's resources to the specified configuration folder * Target folder should be already created **/ - private static void unpackResourceToFolder(final String filename, final String resourcePathSource, File folderTarget) { - String resourceName = resourcePathSource + "/" + filename; + private static void unpackResourceToFolder(final String filename, final String resourcePathSource, final File folderTarget) { + final String resourceName = resourcePathSource + "/" + filename; - File destination = new File(folderTarget, filename); + final File destination = new File(folderTarget, filename); try { - InputStream inputStream = WarpDrive.class.getClassLoader().getResourceAsStream(resourceName); - BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(destination)); + final InputStream inputStream = WarpDrive.class.getClassLoader().getResourceAsStream(resourceName); + final BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(destination)); - byte[] byteBuffer = new byte[Math.max(8192, inputStream.available())]; + final byte[] byteBuffer = new byte[Math.max(8192, inputStream.available())]; int bytesRead; while ((bytesRead = inputStream.read(byteBuffer)) >= 0) { outputStream.write(byteBuffer, 0, bytesRead); @@ -1327,7 +1344,7 @@ public class WarpDriveConfig { inputStream.close(); outputStream.close(); - } catch (Exception exception) { + } catch (final Exception exception) { WarpDrive.logger.error("Failed to unpack resource \'" + resourceName + "\' into " + destination); exception.printStackTrace(); } diff --git a/src/main/java/cr0s/warpdrive/data/JumpBlock.java b/src/main/java/cr0s/warpdrive/data/JumpBlock.java index 6714a75a..a803018e 100644 --- a/src/main/java/cr0s/warpdrive/data/JumpBlock.java +++ b/src/main/java/cr0s/warpdrive/data/JumpBlock.java @@ -88,7 +88,7 @@ public class JumpBlock { } } - public JumpBlock(Filler filler, int x, int y, int z) { + public JumpBlock(final Filler filler, final int x, final int y, final int z) { if (filler.block == null) { WarpDrive.logger.info("Forcing glass for invalid filler with null block at " + x + " " + y + " " + z); filler.block = Blocks.glass; @@ -105,7 +105,7 @@ public class JumpBlock { if (externals == null) { return null; } - NBTBase nbtExternal = externals.get(modId); + final NBTBase nbtExternal = externals.get(modId); if (WarpDriveConfig.LOGGING_JUMPBLOCKS) { WarpDrive.logger.info("Returning " + modId + " externals at " + x + " " + y + " " + z + " " + nbtExternal); } @@ -147,7 +147,7 @@ public class JumpBlock { private static final byte[] mrotWoodLog = { 0, 1, 2, 3, 8, 9, 10, 11, 4, 5, 6, 7, 12, 13, 14, 15 }; // Return updated metadata from rotating a vanilla block - private int getMetadataRotation(NBTTagCompound nbtTileEntity, final byte rotationSteps) { + private int getMetadataRotation(final NBTTagCompound nbtTileEntity, final byte rotationSteps) { if (rotationSteps == 0) { return blockMeta; } @@ -197,8 +197,8 @@ public class JumpBlock { } else if (block instanceof BlockLog) { mrot = mrotWoodLog; } else if (block instanceof BlockSkull) { - mrot = mrotNone; - short facing = nbtTileEntity.getShort("Rot"); + // mrot = mrotNone; + final short facing = nbtTileEntity.getShort("Rot"); switch (rotationSteps) { case 1: nbtTileEntity.setShort("Rot", mrotSign[facing]); @@ -226,19 +226,13 @@ public class JumpBlock { } } - public ChunkCoordinates deploy(World targetWorld, ITransformation transformation) { + public ChunkCoordinates deploy(final World targetWorld, final ITransformation transformation) { try { - NBTTagCompound nbtToDeploy = null; - if (blockTileEntity != null) { - nbtToDeploy = new NBTTagCompound(); - blockTileEntity.writeToNBT(nbtToDeploy); - } else if (blockNBT != null) { - nbtToDeploy = (NBTTagCompound) blockNBT.copy(); - } + final NBTTagCompound nbtToDeploy = getBlockNBT(); int newBlockMeta = blockMeta; if (externals != null) { for (final Entry external : externals.entrySet()) { - IBlockTransformer blockTransformer = WarpDriveConfig.blockTransformers.get(external.getKey()); + final IBlockTransformer blockTransformer = WarpDriveConfig.blockTransformers.get(external.getKey()); if (blockTransformer != null) { newBlockMeta = blockTransformer.rotate(block, blockMeta, nbtToDeploy, transformation); } @@ -264,24 +258,24 @@ public class JumpBlock { if (WarpDriveConfig.LOGGING_JUMPBLOCKS) { WarpDrive.logger.info(this + " deploy: TileEntity has mainXYZ"); } - ChunkCoordinates mainTarget = transformation.apply(nbtToDeploy.getInteger("mainX"), nbtToDeploy.getInteger("mainY"), nbtToDeploy.getInteger("mainZ")); + final ChunkCoordinates mainTarget = transformation.apply(nbtToDeploy.getInteger("mainX"), nbtToDeploy.getInteger("mainY"), nbtToDeploy.getInteger("mainZ")); nbtToDeploy.setInteger("mainX", mainTarget.posX); nbtToDeploy.setInteger("mainY", mainTarget.posY); nbtToDeploy.setInteger("mainZ", mainTarget.posZ); } if (nbtToDeploy.hasKey("screenData")) {// IC2NuclearControl 2.2.5a - NBTTagCompound nbtScreenData = nbtToDeploy.getCompoundTag("screenData"); + final NBTTagCompound nbtScreenData = nbtToDeploy.getCompoundTag("screenData"); if ( nbtScreenData.hasKey("minX") && nbtScreenData.hasKey("minY") && nbtScreenData.hasKey("minZ") && nbtScreenData.hasKey("maxX") && nbtScreenData.hasKey("maxY") && nbtScreenData.hasKey("maxZ")) { if (WarpDriveConfig.LOGGING_JUMPBLOCKS) { WarpDrive.logger.info(this + " deploy: TileEntity has screenData.min/maxXYZ"); } - ChunkCoordinates minTarget = transformation.apply(nbtScreenData.getInteger("minX"), nbtScreenData.getInteger("minY"), nbtScreenData.getInteger("minZ")); + final ChunkCoordinates minTarget = transformation.apply(nbtScreenData.getInteger("minX"), nbtScreenData.getInteger("minY"), nbtScreenData.getInteger("minZ")); nbtScreenData.setInteger("minX", minTarget.posX); nbtScreenData.setInteger("minY", minTarget.posY); nbtScreenData.setInteger("minZ", minTarget.posZ); - ChunkCoordinates maxTarget = transformation.apply(nbtScreenData.getInteger("maxX"), nbtScreenData.getInteger("maxY"), nbtScreenData.getInteger("maxZ")); + final ChunkCoordinates maxTarget = transformation.apply(nbtScreenData.getInteger("maxX"), nbtScreenData.getInteger("maxY"), nbtScreenData.getInteger("maxZ")); nbtScreenData.setInteger("maxX", maxTarget.posX); nbtScreenData.setInteger("maxY", maxTarget.posY); nbtScreenData.setInteger("maxZ", maxTarget.posZ); @@ -329,12 +323,12 @@ public class JumpBlock { } return target; - } catch (Exception exception) { + } catch (final Exception exception) { exception.printStackTrace(); String coordinates; try { coordinates = " at " + x + " " + y + " " + z + " blockId " + block + ":" + blockMeta; - } catch (Exception dropMe) { + } catch (final Exception dropMe) { coordinates = " (unknown coordinates)"; } WarpDrive.logger.error("moveBlockSimple exception at " + coordinates); @@ -342,10 +336,10 @@ public class JumpBlock { return null; } - public static void refreshBlockStateOnClient(World world, int x, int y, int z) { - TileEntity tileEntity = world.getTileEntity(x, y, z); + public static void refreshBlockStateOnClient(final World world, final int x, final int y, final int z) { + final TileEntity tileEntity = world.getTileEntity(x, y, z); if (tileEntity != null) { - Class teClass = tileEntity.getClass(); + final Class teClass = tileEntity.getClass(); if (WarpDriveConfig.LOGGING_JUMPBLOCKS) { WarpDrive.logger.info(String.format("Refreshing clients @ %s (%d %d %d) with %s derived from %s", world.provider.getDimensionName(), @@ -354,11 +348,11 @@ public class JumpBlock { teClass.getSuperclass())); } try { - String superClassName = teClass.getSuperclass().getName(); - boolean isIC2 = superClassName.contains("ic2.core.block"); + final String superClassName = teClass.getSuperclass().getName(); + final boolean isIC2 = superClassName.contains("ic2.core.block"); if (isIC2 || superClassName.contains("advsolar.common.tiles")) {// IC2 - Method onUnloaded = teClass.getMethod("onUnloaded"); - Method onLoaded = teClass.getMethod("onLoaded"); + final Method onUnloaded = teClass.getMethod("onUnloaded"); + final Method onLoaded = teClass.getMethod("onLoaded"); if (onUnloaded != null && onLoaded != null) { onUnloaded.invoke(tileEntity); onLoaded.invoke(tileEntity); @@ -385,17 +379,17 @@ public class JumpBlock { } } else {// IC2 extensions without network optimization (transferring all fields) try { - Method getNetworkedFields = teClass.getMethod("getNetworkedFields"); - List fields = (List) getNetworkedFields.invoke(tileEntity); + final Method getNetworkedFields = teClass.getMethod("getNetworkedFields"); + final List fields = (List) getNetworkedFields.invoke(tileEntity); if (WarpDriveConfig.LOGGING_JUMPBLOCKS) { WarpDrive.logger.info("Tile has " + fields.size() + " networked fields: " + fields); } for (final String field : fields) { NetworkHelper_updateTileEntityField(tileEntity, field); } - } catch (NoSuchMethodException exception) { + } catch (final NoSuchMethodException exception) { // WarpDrive.logger.info("Tile has no getNetworkedFields method"); - } catch (NoClassDefFoundError exception) { + } catch (final NoClassDefFoundError exception) { if (WarpDriveConfig.LOGGING_JUMP) { WarpDrive.logger.info("TileEntity " + teClass.getName() + " at " + x + " " + y + " " + z + " is missing a class definition"); if (WarpDriveConfig.LOGGING_JUMPBLOCKS) { @@ -404,7 +398,7 @@ public class JumpBlock { } } } - } catch (Exception exception) { + } catch (final Exception exception) { WarpDrive.logger.info("Exception involving TileEntity " + teClass.getName() + " at " + x + " " + y + " " + z); exception.printStackTrace(); } @@ -421,7 +415,7 @@ public class JumpBlock { return; } blockMeta = tagCompound.getByte("blockMeta"); - blockTileEntity = null; + weakTileEntity = null; if (tagCompound.hasKey("blockNBT")) { blockNBT = tagCompound.getCompoundTag("blockNBT"); @@ -430,7 +424,7 @@ public class JumpBlock { blockNBT.removeTag("computerID"); } if (blockNBT.hasKey("oc:computer")) { - NBTTagCompound tagComputer = blockNBT.getCompoundTag("oc:computer"); + final NBTTagCompound tagComputer = blockNBT.getCompoundTag("oc:computer"); tagComputer.removeTag("components"); tagComputer.removeTag("node"); blockNBT.setTag("oc:computer", tagComputer); @@ -456,12 +450,9 @@ public class JumpBlock { public void writeToNBT(final NBTTagCompound tagCompound) { tagCompound.setString("block", Block.blockRegistry.getNameForObject(block)); tagCompound.setByte("blockMeta", (byte) blockMeta); - if (blockTileEntity != null) { - final NBTTagCompound nbtTileEntity = new NBTTagCompound(); - blockTileEntity.writeToNBT(nbtTileEntity); + final NBTTagCompound nbtTileEntity = getBlockNBT(); + if (nbtTileEntity != null) { tagCompound.setTag("blockNBT", nbtTileEntity); - } else if (blockNBT != null) { - tagCompound.setTag("blockNBT", blockNBT); } tagCompound.setInteger("x", x); tagCompound.setInteger("y", y); @@ -507,7 +498,7 @@ public class JumpBlock { // OpenComputers case if (tagCompound.hasKey("oc:computer")) { - NBTTagCompound tagComputer = tagCompound.getCompoundTag("oc:computer"); + final NBTTagCompound tagComputer = tagCompound.getCompoundTag("oc:computer"); tagComputer.removeTag("chunkX"); tagComputer.removeTag("chunkZ"); tagComputer.removeTag("components"); @@ -520,11 +511,11 @@ public class JumpBlock { if (tagCompound.hasKey("oc:items")) { NBTTagList tagListItems = tagCompound.getTagList("oc:items", Constants.NBT.TAG_COMPOUND); for (int indexItemSlot = 0; indexItemSlot < tagListItems.tagCount(); indexItemSlot++) { - NBTTagCompound tagCompoundItemSlot = tagListItems.getCompoundTagAt(indexItemSlot); - NBTTagCompound tagCompoundItem = tagCompoundItemSlot.getCompoundTag("item"); - NBTTagCompound tagCompoundTag = tagCompoundItem.getCompoundTag("tag"); - NBTTagCompound tagCompoundOCData = tagCompoundTag.getCompoundTag("oc:data"); - NBTTagCompound tagCompoundNode = tagCompoundOCData.getCompoundTag("node"); + final NBTTagCompound tagCompoundItemSlot = tagListItems.getCompoundTagAt(indexItemSlot); + final NBTTagCompound tagCompoundItem = tagCompoundItemSlot.getCompoundTag("item"); + final NBTTagCompound tagCompoundTag = tagCompoundItem.getCompoundTag("tag"); + final NBTTagCompound tagCompoundOCData = tagCompoundTag.getCompoundTag("oc:data"); + final NBTTagCompound tagCompoundNode = tagCompoundOCData.getCompoundTag("node"); if (tagCompoundNode.hasKey("address")) { tagCompoundNode.removeTag("address"); } @@ -533,7 +524,7 @@ public class JumpBlock { // OpenComputers keyboard if (tagCompound.hasKey("oc:keyboard")) { - NBTTagCompound tagCompoundKeyboard = tagCompound.getCompoundTag("oc:keyboard"); + final NBTTagCompound tagCompoundKeyboard = tagCompound.getCompoundTag("oc:keyboard"); tagCompoundKeyboard.removeTag("node"); } @@ -556,7 +547,7 @@ public class JumpBlock { public static void emptyEnergyStorage(final NBTTagCompound tagCompound) { // BuildCraft if (tagCompound.hasKey("battery", NBT.TAG_COMPOUND)) { - NBTTagCompound tagCompoundBattery = tagCompound.getCompoundTag("battery"); + final NBTTagCompound tagCompoundBattery = tagCompound.getCompoundTag("battery"); if (tagCompoundBattery.hasKey("energy", NBT.TAG_INT)) { tagCompoundBattery.setInteger("energy", 0); } @@ -617,25 +608,25 @@ public class JumpBlock { WarpDrive.logger.info("Patched IC2 API, new instance is '" + NetworkManager_instance + "'"); } // IC2 hack ends here - } catch (Exception exception) { + } catch (final Exception exception) { throw new RuntimeException(exception); } } - private static void NetworkHelper_updateTileEntityField(TileEntity tileEntity, String field) { + private static void NetworkHelper_updateTileEntityField(final TileEntity tileEntity, final String field) { try { if (NetworkManager_instance == null) { NetworkHelper_init(); } NetworkManager_updateTileEntityField.invoke(NetworkManager_instance, tileEntity, field); - } catch (Exception exception) { + } catch (final Exception exception) { throw new RuntimeException(exception); } } // IC2 support ends here // This code is a straight copy from Vanilla net.minecraft.world.World.setBlock to remove lighting computations - public static boolean setBlockNoLight(World w, int x, int y, int z, Block block, int blockMeta, int par6) { + public static boolean setBlockNoLight(final World w, final int x, final int y, final int z, final Block block, final int blockMeta, final int par6) { // return w.setBlock(x, y, z, block, blockMeta, par6); if (x >= -30000000 && z >= -30000000 && x < 30000000 && z < 30000000) { @@ -644,7 +635,7 @@ public class JumpBlock { } else if (y >= 256) { return false; } else { - Chunk chunk = w.getChunkFromChunkCoords(x >> 4, z >> 4); + final Chunk chunk = w.getChunkFromChunkCoords(x >> 4, z >> 4); Block block1 = null; // net.minecraftforge.common.util.BlockSnapshot blockSnapshot = null; @@ -658,7 +649,7 @@ public class JumpBlock { // w.capturedBlockSnapshots.add(blockSnapshot); // } - boolean flag = myChunkSBIDWMT(chunk, x & 15, y, z & 15, block, blockMeta); + final boolean flag = myChunkSBIDWMT(chunk, x & 15, y, z & 15, block, blockMeta); // Disable rollback on item use // if (!flag && blockSnapshot != null) { @@ -688,8 +679,8 @@ public class JumpBlock { } // This code is a straight copy from Vanilla net.minecraft.world.Chunk.func_150807_a to remove lighting computations - private static boolean myChunkSBIDWMT(Chunk c, int x, int y, int z, Block block, int blockMeta) { - int i1 = z << 4 | x; + private static boolean myChunkSBIDWMT(final Chunk c, final int x, final int y, final int z, final Block block, final int blockMeta) { + final int i1 = z << 4 | x; if (y >= c.precipitationHeightMap[i1] - 1) { c.precipitationHeightMap[i1] = -999; @@ -697,13 +688,13 @@ public class JumpBlock { // Removed light recalculations // int j1 = c.heightMap[i1]; - Block block1 = c.getBlock(x, y, z); - int k1 = c.getBlockMetadata(x, y, z); + final Block block1 = c.getBlock(x, y, z); + final int k1 = c.getBlockMetadata(x, y, z); if (block1 == block && k1 == blockMeta) { return false; } else { - ExtendedBlockStorage[] storageArrays = c.getBlockStorageArray(); + final ExtendedBlockStorage[] storageArrays = c.getBlockStorageArray(); ExtendedBlockStorage extendedblockstorage = storageArrays[y >> 4]; // Removed light recalculations // boolean flag = false; @@ -718,8 +709,8 @@ public class JumpBlock { // flag = y >= j1; } - int l1 = c.xPosition * 16 + x; - int i2 = c.zPosition * 16 + z; + final int l1 = c.xPosition * 16 + x; + final int i2 = c.zPosition * 16 + z; // Removed light recalculations // int k2 = block1.getLightOpacity(c.worldObj, l1, y, i2); @@ -737,12 +728,12 @@ public class JumpBlock { if (!c.worldObj.isRemote) { block1.breakBlock(c.worldObj, l1, y, i2, block1, k1); // After breakBlock a phantom TE might have been created with incorrect meta. This attempts to kill that phantom TE so the normal one can be created properly later - TileEntity te = c.getTileEntityUnsafe(x & 0x0F, y, z & 0x0F); + final TileEntity te = c.getTileEntityUnsafe(x & 0x0F, y, z & 0x0F); if (te != null && te.shouldRefresh(block1, c.getBlock(x & 0x0F, y, z & 0x0F), k1, c.getBlockMetadata(x & 0x0F, y, z & 0x0F), c.worldObj, l1, y, i2)) { c.removeTileEntity(x & 0x0F, y, z & 0x0F); } } else if (block1.hasTileEntity(k1)) { - TileEntity te = c.getTileEntityUnsafe(x & 0x0F, y, z & 0x0F); + final TileEntity te = c.getTileEntityUnsafe(x & 0x0F, y, z & 0x0F); if (te != null && te.shouldRefresh(block1, block, k1, blockMeta, c.worldObj, l1, y, i2)) { c.worldObj.removeTileEntity(l1, y, i2); } @@ -774,7 +765,7 @@ public class JumpBlock { } /**/ - TileEntity tileentity; + final TileEntity tileentity; // Removed onBlockAdded event // if (!c.worldObj.isRemote) { diff --git a/src/main/java/cr0s/warpdrive/data/JumpShip.java b/src/main/java/cr0s/warpdrive/data/JumpShip.java index ab04bcd9..7a1901b4 100644 --- a/src/main/java/cr0s/warpdrive/data/JumpShip.java +++ b/src/main/java/cr0s/warpdrive/data/JumpShip.java @@ -49,7 +49,7 @@ public class JumpShip { } public static JumpShip createFromFile(final String fileName, final StringBuilder reason) { - NBTTagCompound schematic = Commons.readNBTFromFile(WarpDriveConfig.G_SCHEMALOCATION + "/" + fileName + ".schematic"); + final NBTTagCompound schematic = Commons.readNBTFromFile(WarpDriveConfig.G_SCHEMALOCATION + "/" + fileName + ".schematic"); if (schematic == null) { reason.append(String.format("Schematic not found or unknown error reading it: '%s'.", fileName)); return null; @@ -233,14 +233,14 @@ public class JumpShip { coreX, coreY, coreZ); } - public boolean checkBorders(StringBuilder reason) { + public boolean checkBorders(final StringBuilder reason) { // Abort jump if blocks with TE are connecting to the ship (avoid crash when splitting multi-blocks) for (int x = minX - 1; x <= maxX + 1; x++) { - boolean xBorder = (x == minX - 1) || (x == maxX + 1); + final boolean xBorder = (x == minX - 1) || (x == maxX + 1); for (int z = minZ - 1; z <= maxZ + 1; z++) { - boolean zBorder = (z == minZ - 1) || (z == maxZ + 1); + final boolean zBorder = (z == minZ - 1) || (z == maxZ + 1); for (int y = minY - 1; y <= maxY + 1; y++) { - boolean yBorder = (y == minY - 1) || (y == maxY + 1); + final boolean yBorder = (y == minY - 1) || (y == maxY + 1); if ((y < 0) || (y > 255)) { continue; } @@ -248,7 +248,7 @@ public class JumpShip { continue; } - Block block = worldObj.getBlock(x, y, z); + final Block block = worldObj.getBlock(x, y, z); // Skipping any air block & ignored blocks if (worldObj.isAirBlock(x, y, z) || Dictionary.BLOCKS_LEFTBEHIND.contains(block)) { @@ -261,7 +261,7 @@ public class JumpShip { } // Skipping blocks without tile entities - TileEntity tileEntity = worldObj.getTileEntity(x, y, z); + final TileEntity tileEntity = worldObj.getTileEntity(x, y, z); if (tileEntity == null) { continue; } @@ -280,27 +280,27 @@ public class JumpShip { /** * Saving ship to memory */ - public boolean save(StringBuilder reason) { - VectorI vPosition = new VectorI(); + public boolean save(final StringBuilder reason) { + final VectorI vPosition = new VectorI(); try { - int estimatedVolume = (maxX - minX + 1) * (maxY - minY + 1) * (maxZ - minZ + 1); - JumpBlock[][] placeTimeJumpBlocks = { new JumpBlock[estimatedVolume], new JumpBlock[estimatedVolume], new JumpBlock[estimatedVolume], new JumpBlock[estimatedVolume], new JumpBlock[estimatedVolume] }; - int[] placeTimeIndexes = { 0, 0, 0, 0, 0 }; + final int estimatedVolume = (maxX - minX + 1) * (maxY - minY + 1) * (maxZ - minZ + 1); + final JumpBlock[][] placeTimeJumpBlocks = { new JumpBlock[estimatedVolume], new JumpBlock[estimatedVolume], new JumpBlock[estimatedVolume], new JumpBlock[estimatedVolume], new JumpBlock[estimatedVolume] }; + final int[] placeTimeIndexes = { 0, 0, 0, 0, 0 }; int actualVolume = 0; int newMass = 0; - int xc1 = minX >> 4; - int xc2 = maxX >> 4; - int zc1 = minZ >> 4; - int zc2 = maxZ >> 4; + final int xc1 = minX >> 4; + final int xc2 = maxX >> 4; + final int zc1 = minZ >> 4; + final int zc2 = maxZ >> 4; for (int xc = xc1; xc <= xc2; xc++) { - int x1 = Math.max(minX, xc << 4); - int x2 = Math.min(maxX, (xc << 4) + 15); + final int x1 = Math.max(minX, xc << 4); + final int x2 = Math.min(maxX, (xc << 4) + 15); for (int zc = zc1; zc <= zc2; zc++) { - int z1 = Math.max(minZ, zc << 4); - int z2 = Math.min(maxZ, (zc << 4) + 15); + final int z1 = Math.max(minZ, zc << 4); + final int z2 = Math.min(maxZ, (zc << 4) + 15); for (int y = minY; y <= maxY; y++) { vPosition.y = y; @@ -308,7 +308,7 @@ public class JumpShip { vPosition.x = x; for (int z = z1; z <= z2; z++) { vPosition.z = z; - Block block = worldObj.getBlock(x, y, z); + final Block block = worldObj.getBlock(x, y, z); // Skipping vanilla air & ignored blocks if (block == Blocks.air || Dictionary.BLOCKS_LEFTBEHIND.contains(block)) { @@ -336,11 +336,11 @@ public class JumpShip { final TileEntity tileEntity = worldObj.getTileEntity(x, y, z); final JumpBlock jumpBlock = new JumpBlock(worldObj, x, y, z, block, blockMeta, tileEntity); - if (jumpBlock.blockTileEntity != null && jumpBlock.externals != null) { + if (tileEntity != null && jumpBlock.externals != null) { for (final Entry external : jumpBlock.externals.entrySet()) { - IBlockTransformer blockTransformer = WarpDriveConfig.blockTransformers.get(external.getKey()); + final IBlockTransformer blockTransformer = WarpDriveConfig.blockTransformers.get(external.getKey()); if (blockTransformer != null) { - if (!blockTransformer.isJumpReady(jumpBlock.block, jumpBlock.blockMeta, jumpBlock.blockTileEntity, reason)) { + if (!blockTransformer.isJumpReady(jumpBlock.block, jumpBlock.blockMeta, tileEntity, reason)) { if (reason.length() > 0) { reason.append("\n"); } @@ -380,7 +380,7 @@ public class JumpShip { } } actualMass = newMass; - } catch (Exception exception) { + } catch (final Exception exception) { exception.printStackTrace(); final String msg = String.format("Exception while saving ship, probably a corrupted block at (%d %d %d).", vPosition.x, vPosition.y, vPosition.z); @@ -395,7 +395,7 @@ public class JumpShip { return true; } - public void readFromNBT(NBTTagCompound tagCompound) { + public void readFromNBT(final NBTTagCompound tagCompound) { coreX = tagCompound.getInteger("coreX"); coreY = tagCompound.getInteger("coreY"); coreZ = tagCompound.getInteger("coreZ"); @@ -430,7 +430,7 @@ public class JumpShip { tagCompound.setInteger("minY", minY); tagCompound.setInteger("actualMass", actualMass); final NBTTagList tagListJumpBlocks = new NBTTagList(); - for (JumpBlock jumpBlock : jumpBlocks) { + for (final JumpBlock jumpBlock : jumpBlocks) { final NBTTagCompound tagCompoundBlock = new NBTTagCompound(); jumpBlock.writeToNBT(tagCompoundBlock); tagListJumpBlocks.appendTag(tagCompoundBlock); diff --git a/src/main/java/cr0s/warpdrive/data/StateAir.java b/src/main/java/cr0s/warpdrive/data/StateAir.java index d7e66017..095a0d7f 100644 --- a/src/main/java/cr0s/warpdrive/data/StateAir.java +++ b/src/main/java/cr0s/warpdrive/data/StateAir.java @@ -189,7 +189,9 @@ public class StateAir { public boolean setAirSource(final World world, final ForgeDirection direction, final short pressure) { assert(block != null); - final boolean isPlaceable = (dataAir & BLOCK_MASK) == BLOCK_AIR_PLACEABLE || (dataAir & BLOCK_MASK) == BLOCK_AIR_FLOW || (dataAir & BLOCK_MASK) == BLOCK_AIR_SOURCE; + final boolean isPlaceable = (dataAir & BLOCK_MASK) == BLOCK_AIR_PLACEABLE + || (dataAir & BLOCK_MASK) == BLOCK_AIR_FLOW + || (dataAir & BLOCK_MASK) == BLOCK_AIR_SOURCE; final boolean updateRequired = (block != WarpDrive.blockAirSource) || pressureGenerator != pressure || pressureVoid != 0 @@ -202,7 +204,7 @@ public class StateAir { updateBlockType(world); try { setGeneratorAndUpdateVoid(world, pressure, direction.getOpposite()); - } catch (ExceptionChunkNotLoaded exceptionChunkNotLoaded) { + } catch (final ExceptionChunkNotLoaded exceptionChunkNotLoaded) { // no operation } setConcentration(world, (byte) CONCENTRATION_MAX); @@ -512,7 +514,7 @@ public class StateAir { for (int dy = -1; dy <= 1; dy++) { for (int dz = -1; dz <= 1; dz++) { for (int dx = -1; dx <= 1; dx++) { - StateAir stateAir = new StateAir(null); + final StateAir stateAir = new StateAir(null); stateAir.refresh(entityPlayer.worldObj, MathHelper.floor_double(entityPlayer.posX) + dx, MathHelper.floor_double(entityPlayer.posY) + dy, @@ -527,20 +529,20 @@ public class StateAir { for (int indexZ = 2; indexZ >= 0; indexZ--) { message.append("\n"); for (int indexX = 0; indexX <= 2; indexX++) { - StateAir stateAir = stateAirs[indexX][indexY][indexZ]; + final StateAir stateAir = stateAirs[indexX][indexY][indexZ]; final String stringValue = String.format("%2d", 100 + stateAir.concentration).substring(1); message.append(String.format("§3%s ", stringValue)); } message.append("§f| "); for (int indexX = 0; indexX <= 2; indexX++) { - StateAir stateAir = stateAirs[indexX][indexY][indexZ]; + final StateAir stateAir = stateAirs[indexX][indexY][indexZ]; final String stringValue = String.format("%X", 0x100 + stateAir.pressureGenerator).substring(1); final String stringDirection = directionToChar(stateAir.directionGenerator); message.append(String.format("§e%s §a%s ", stringValue, stringDirection)); } message.append("§f| "); for (int indexX = 0; indexX <= 2; indexX++) { - StateAir stateAir = stateAirs[indexX][indexY][indexZ]; + final StateAir stateAir = stateAirs[indexX][indexY][indexZ]; final String stringValue = String.format("%X", 0x100 + stateAir.pressureVoid).substring(1); final String stringDirection = directionToChar(stateAir.directionVoid); message.append(String.format("§e%s §d%s ", stringValue, stringDirection)); @@ -551,7 +553,7 @@ public class StateAir { } } Commons.addChatMessage(entityPlayer, message.toString()); - } catch (ExceptionChunkNotLoaded exceptionChunkNotLoaded) { + } catch (final ExceptionChunkNotLoaded exceptionChunkNotLoaded) { // no operation } } diff --git a/src/main/java/cr0s/warpdrive/event/JumpSequencer.java b/src/main/java/cr0s/warpdrive/event/JumpSequencer.java index ecc51f32..7ac2f3ce 100644 --- a/src/main/java/cr0s/warpdrive/event/JumpSequencer.java +++ b/src/main/java/cr0s/warpdrive/event/JumpSequencer.java @@ -169,7 +169,7 @@ public class JumpSequencer extends AbstractSequencer { register(); } - public void disable(String reason) { + public void disable(final String reason) { if (!isEnabled) { return; } @@ -203,7 +203,7 @@ public class JumpSequencer extends AbstractSequencer { } if (ship.minY < 0 || ship.maxY > 255) { - String msg = "Invalid Y coordinate(s), check ship dimensions..."; + final String msg = "Invalid Y coordinate(s), check ship dimensions..."; ship.messageToAllPlayersOnShip(msg); disable(msg); return true; @@ -299,7 +299,7 @@ public class JumpSequencer extends AbstractSequencer { break; default: - String msg = "Invalid state, aborting jump..."; + final String msg = "Invalid state, aborting jump..."; ship.messageToAllPlayersOnShip(msg); disable(msg); return true; @@ -307,7 +307,7 @@ public class JumpSequencer extends AbstractSequencer { return true; } - private boolean forceSourceChunks(StringBuilder reason) { + private boolean forceSourceChunks(final StringBuilder reason) { if (WarpDriveConfig.LOGGING_JUMP) { WarpDrive.logger.info(this + " Forcing source chunks in " + sourceWorld.provider.getDimensionName()); } @@ -338,7 +338,7 @@ public class JumpSequencer extends AbstractSequencer { return true; } - private boolean forceTargetChunks(StringBuilder reason) { + private boolean forceTargetChunks(final StringBuilder reason) { LocalProfiler.start("Jump.forceTargetChunks"); if (WarpDriveConfig.LOGGING_JUMP) { WarpDrive.logger.info(this + " Forcing target chunks in " + targetWorld.provider.getDimensionName()); @@ -415,10 +415,10 @@ public class JumpSequencer extends AbstractSequencer { protected void state_chunkLoadingSource() { LocalProfiler.start("Jump.chunkLoadingSource"); - StringBuilder reason = new StringBuilder(); + final StringBuilder reason = new StringBuilder(); if (!forceSourceChunks(reason)) { - String msg = reason.toString(); + final String msg = reason.toString(); disable(msg); ship.messageToAllPlayersOnShip(msg); LocalProfiler.stop(); @@ -479,7 +479,7 @@ public class JumpSequencer extends AbstractSequencer { final String shipName = ship.shipCore.shipName.replaceAll("[^ -~]", "").replaceAll("[:/\\\\]", ""); String schematicFileName; do { - Date now = new Date(); + final Date now = new Date(); schematicFileName = WarpDriveConfig.G_SCHEMALOCATION + "/auto/" + shipName + "_" + sdfDate.format(now) + ".schematic"; } while (new File(schematicFileName).exists()); @@ -503,7 +503,7 @@ public class JumpSequencer extends AbstractSequencer { if (WarpDriveConfig.LOGGING_JUMP && WarpDrive.isDev) { WarpDrive.logger.info(this + " Ship saved as " + schematicFileName); } - } catch (Exception exception) { + } catch (final Exception exception) { exception.printStackTrace(); } @@ -594,8 +594,8 @@ public class JumpSequencer extends AbstractSequencer { } // Do not check in long jumps - int rangeX = Math.abs(moveX) - (ship.maxX - ship.minX); - int rangeZ = Math.abs(moveZ) - (ship.maxZ - ship.minZ); + final int rangeX = Math.abs(moveX) - (ship.maxX - ship.minX); + final int rangeZ = Math.abs(moveZ) - (ship.maxZ - ship.minZ); if (Math.max(rangeX, rangeZ) < 256) { firstAdjustmentReason = getPossibleJumpDistance(); isPluginCheckDone = true; @@ -629,7 +629,7 @@ public class JumpSequencer extends AbstractSequencer { doCollisionDamage(false); // cancel jump - String msg; + final String msg; if (firstAdjustmentReason == null || firstAdjustmentReason.isEmpty()) { msg = "Source and target areas are overlapping, jump aborted! Try increasing jump distance..."; } else { @@ -642,7 +642,7 @@ public class JumpSequencer extends AbstractSequencer { } // Check world border - CelestialObject celestialObjectTarget = CelestialObjectManager.get(targetWorld, (int) aabbTarget.minX, (int) aabbTarget.minZ); + final CelestialObject celestialObjectTarget = CelestialObjectManager.get(targetWorld, (int) aabbTarget.minX, (int) aabbTarget.minZ); if (celestialObjectTarget == null) { if (WarpDriveConfig.LOGGING_JUMP) { WarpDrive.logger.error(String.format("There's no world border defined for dimension %s (%d)", @@ -668,7 +668,7 @@ public class JumpSequencer extends AbstractSequencer { if (!isPluginCheckDone) { final CheckMovementResult checkMovementResult = checkCollisionAndProtection(transformation, true, "target"); if (checkMovementResult != null) { - String msg = checkMovementResult.reason + "\nJump aborted!"; + final String msg = checkMovementResult.reason + "\nJump aborted!"; disable(msg); ship.messageToAllPlayersOnShip(msg); LocalProfiler.stop(); @@ -763,7 +763,7 @@ public class JumpSequencer extends AbstractSequencer { break; case HYPERSPACE_EXITING: { - CelestialObject celestialObject = CelestialObjectManager.getClosestChild(sourceWorld, ship.coreX, ship.coreZ); + final CelestialObject celestialObject = CelestialObjectManager.getClosestChild(sourceWorld, ship.coreX, ship.coreZ); // anything defined? if (celestialObject == null) { reason.append(String.format("Unable to reach space from this location!\nThere's no celestial object defined for current dimension %s (%d).", @@ -774,7 +774,7 @@ public class JumpSequencer extends AbstractSequencer { // are we clear for transit? final double distanceSquared = celestialObject.getSquareDistanceInParent(sourceWorld.provider.dimensionId, ship.coreX, ship.coreZ); if (distanceSquared > 0.0D) { - AxisAlignedBB axisAlignedBB = celestialObject.getAreaInParent(); + final AxisAlignedBB axisAlignedBB = celestialObject.getAreaInParent(); reason.append(String.format( "Ship is outside any solar system, unable to reach space!\n" + "Closest transition area is ~%d m away (%d %d %d) to (%d %d %d).", @@ -873,7 +873,7 @@ public class JumpSequencer extends AbstractSequencer { // are we in orbit? final double distanceSquared = celestialObject.getSquareDistanceInParent(sourceWorld.provider.dimensionId, ship.coreX, ship.coreZ); if (distanceSquared > 0.0D) { - AxisAlignedBB axisAlignedBB = celestialObject.getAreaInParent(); + final AxisAlignedBB axisAlignedBB = celestialObject.getAreaInParent(); reason.append(String.format( "No planet in range, unable to enter atmosphere!\n" + "Closest planet is %d m away (%d %d %d) to (%d %d %d).", @@ -1028,7 +1028,7 @@ public class JumpSequencer extends AbstractSequencer { protected void state_moveExternals() { LocalProfiler.start("Jump.moveExternals"); - int blocksToMove = Math.min(blocksPerTick, ship.jumpBlocks.length - actualIndexInShip); + final int blocksToMove = Math.min(blocksPerTick, ship.jumpBlocks.length - actualIndexInShip); if (WarpDriveConfig.LOGGING_JUMP) { WarpDrive.logger.info(this + " Moving ship externals from " + actualIndexInShip + " / " + (ship.jumpBlocks.length - 1)); } @@ -1119,7 +1119,7 @@ public class JumpSequencer extends AbstractSequencer { protected void state_removeBlocks() { LocalProfiler.start("Jump.removeBlocks"); - int blocksToMove = Math.min(blocksPerTick, ship.jumpBlocks.length - actualIndexInShip); + final int blocksToMove = Math.min(blocksPerTick, ship.jumpBlocks.length - actualIndexInShip); if (WarpDriveConfig.LOGGING_JUMP) { WarpDrive.logger.info(this + " Removing ship blocks " + actualIndexInShip + " to " + (actualIndexInShip + blocksToMove - 1) + " / " + (ship.jumpBlocks.length - 1)); } @@ -1148,7 +1148,7 @@ public class JumpSequencer extends AbstractSequencer { } try { JumpBlock.setBlockNoLight(sourceWorld, jumpBlock.x, jumpBlock.y, jumpBlock.z, Blocks.air, 0, 2); - } catch (Exception exception) { + } catch (final Exception exception) { WarpDrive.logger.info("Exception while removing " + jumpBlock.block + "@" + jumpBlock.blockMeta + " at " + jumpBlock.x + " " + jumpBlock.y + " " + jumpBlock.z); if (WarpDriveConfig.LOGGING_JUMPBLOCKS) { exception.printStackTrace(); @@ -1186,7 +1186,7 @@ public class JumpSequencer extends AbstractSequencer { try { targetWorld.loadedTileEntityList = removeDuplicates(targetWorld.loadedTileEntityList); - } catch (Exception exception) { + } catch (final Exception exception) { if (WarpDriveConfig.LOGGING_JUMP) { WarpDrive.logger.info("TE Duplicates removing exception: " + exception.getMessage()); exception.printStackTrace(); @@ -1210,7 +1210,7 @@ public class JumpSequencer extends AbstractSequencer { if (WarpDriveConfig.LOGGING_JUMP) { WarpDrive.logger.info(this + " Calculating possible jump distance..."); } - int originalRange = Math.max(Math.abs(moveX), Math.max(Math.abs(moveY), Math.abs(moveZ))); + final int originalRange = Math.max(Math.abs(moveX), Math.max(Math.abs(moveY), Math.abs(moveZ))); int testRange = originalRange; int blowPoints = 0; collisionDetected = false; @@ -1232,7 +1232,7 @@ public class JumpSequencer extends AbstractSequencer { } testRange--; } - VectorI finalMovement = getMovementVector(testRange / (double)originalRange); + final VectorI finalMovement = getMovementVector(testRange / (double)originalRange); if (originalRange != testRange && WarpDriveConfig.LOGGING_JUMP) { WarpDrive.logger.info(this + " Jump range adjusted from " + originalRange + " to " + testRange + " after " + blowPoints + " collisions"); @@ -1251,7 +1251,7 @@ public class JumpSequencer extends AbstractSequencer { * Wither boom = 5 * Endercrystal = 6 */ - float massCorrection = 0.5F + final float massCorrection = 0.5F + (float) Math.sqrt(Math.min(1.0D, Math.max(0.0D, ship.shipCore.shipMass - WarpDriveConfig.SHIP_VOLUME_MAX_ON_PLANET_SURFACE) / WarpDriveConfig.SHIP_VOLUME_MIN_FOR_HYPERSPACE)); collisionDetected = true; @@ -1273,17 +1273,17 @@ public class JumpSequencer extends AbstractSequencer { return firstAdjustmentReason; } - private void doCollisionDamage(boolean atTarget) { + private void doCollisionDamage(final boolean atTarget) { if (!collisionDetected) { if (WarpDriveConfig.LOGGING_JUMP) { WarpDrive.logger.info(this + " doCollisionDamage No collision detected..."); } return; } - ArrayList collisionPoints = atTarget ? collisionAtTarget : collisionAtSource; - Vector3 min = collisionPoints.get(0).clone(); - Vector3 max = collisionPoints.get(0).clone(); - for (Vector3 v : collisionPoints) { + final ArrayList collisionPoints = atTarget ? collisionAtTarget : collisionAtSource; + final Vector3 min = collisionPoints.get(0).clone(); + final Vector3 max = collisionPoints.get(0).clone(); + for (final Vector3 v : collisionPoints) { if (min.x > v.x) { min.x = v.x; } else if (max.x < v.x) { @@ -1305,19 +1305,19 @@ public class JumpSequencer extends AbstractSequencer { } // inform players on board - double rx = Math.round(min.x + sourceWorld.rand.nextInt(Math.max(1, (int) (max.x - min.x)))); - double ry = Math.round(min.y + sourceWorld.rand.nextInt(Math.max(1, (int) (max.y - min.y)))); - double rz = Math.round(min.z + sourceWorld.rand.nextInt(Math.max(1, (int) (max.z - min.z)))); + final double rx = Math.round(min.x + sourceWorld.rand.nextInt(Math.max(1, (int) (max.x - min.x)))); + final double ry = Math.round(min.y + sourceWorld.rand.nextInt(Math.max(1, (int) (max.y - min.y)))); + final double rz = Math.round(min.z + sourceWorld.rand.nextInt(Math.max(1, (int) (max.z - min.z)))); ship.messageToAllPlayersOnShip("Ship collision detected around " + (int) rx + ", " + (int) ry + ", " + (int) rz + ". Damage report pending..."); // randomize if too many collision points - int nbExplosions = Math.min(5, collisionPoints.size()); + final int nbExplosions = Math.min(5, collisionPoints.size()); if (WarpDriveConfig.LOGGING_JUMP) { WarpDrive.logger.info("doCollisionDamage nbExplosions " + nbExplosions + "/" + collisionPoints.size()); } for (int i = 0; i < nbExplosions; i++) { // get location - Vector3 current; + final Vector3 current; if (nbExplosions < collisionPoints.size()) { if (WarpDriveConfig.LOGGING_JUMP) { WarpDrive.logger.info("doCollisionDamage random #" + i); @@ -1331,7 +1331,7 @@ public class JumpSequencer extends AbstractSequencer { } // compute explosion strength with a jitter, at least 1 TNT - float strength = Math.max(4.0F, collisionStrength / nbExplosions - 2.0F + 2.0F * sourceWorld.rand.nextFloat()); + final float strength = Math.max(4.0F, collisionStrength / nbExplosions - 2.0F + 2.0F * sourceWorld.rand.nextFloat()); (atTarget ? targetWorld : sourceWorld).newExplosion(null, current.x, current.y, current.z, strength, atTarget, atTarget); WarpDrive.logger.info("Ship collision caused explosion at " + current.x + " " + current.y + " " + current.z + " with strength " + strength); @@ -1384,7 +1384,9 @@ public class JumpSequencer extends AbstractSequencer { reason = "Unknown reason"; } - public void add(double sx, double sy, double sz, double tx, double ty, double tz, boolean pisCollision, String preason) { + public void add(final double sx, final double sy, final double sz, + final double tx, final double ty, final double tz, + final boolean pisCollision, final String preason) { atSource.add(new Vector3(sx, sy, sz)); atTarget.add(new Vector3(tx, ty, tz)); isCollision = isCollision || pisCollision; @@ -1395,13 +1397,13 @@ public class JumpSequencer extends AbstractSequencer { } } - private CheckMovementResult checkCollisionAndProtection(ITransformation transformation, final boolean fullCollisionDetails, final String context) { + private CheckMovementResult checkCollisionAndProtection(final ITransformation transformation, final boolean fullCollisionDetails, final String context) { final CheckMovementResult result = new CheckMovementResult(); final VectorI offset = new VectorI((int) Math.signum(moveX), (int) Math.signum(moveY), (int) Math.signum(moveZ)); int x, y, z; ChunkCoordinates coordTarget; - ChunkCoordinates coordCoreAtTarget = transformation.apply(ship.coreX, ship.coreY, ship.coreZ); + final ChunkCoordinates coordCoreAtTarget = transformation.apply(ship.coreX, ship.coreY, ship.coreZ); Block blockSource; Block blockTarget; for (y = ship.minY; y <= ship.maxY; y++) { @@ -1467,8 +1469,8 @@ public class JumpSequencer extends AbstractSequencer { } private CheckMovementResult checkMovement(final double ratio, final boolean fullCollisionDetails) { - CheckMovementResult result = new CheckMovementResult(); - VectorI testMovement = getMovementVector(ratio); + final CheckMovementResult result = new CheckMovementResult(); + final VectorI testMovement = getMovementVector(ratio); if ((moveY > 0 && ship.maxY + testMovement.y > 255) && !betweenWorlds) { result.add(ship.coreX, ship.maxY + testMovement.y, ship.coreZ, ship.coreX + 0.5D, @@ -1487,7 +1489,7 @@ public class JumpSequencer extends AbstractSequencer { return result; } - ITransformation testTransformation = new Transformation(ship, targetWorld, testMovement.x, testMovement.y, testMovement.z, rotationSteps); + final ITransformation testTransformation = new Transformation(ship, targetWorld, testMovement.x, testMovement.y, testMovement.z, rotationSteps); return checkCollisionAndProtection(testTransformation, fullCollisionDetails, "ratio " + ratio + " testMovement " + testMovement); } @@ -1495,11 +1497,11 @@ public class JumpSequencer extends AbstractSequencer { return new VectorI((int)Math.round(moveX * ratio), (int)Math.round(moveY * ratio), (int)Math.round(moveZ * ratio)); } - private static ArrayList removeDuplicates(List l) { + private static ArrayList removeDuplicates(final List l) { @SuppressWarnings("Convert2Lambda") - Set s = new TreeSet<>(new Comparator() { + final Set s = new TreeSet<>(new Comparator() { @Override - public int compare(TileEntity o1, TileEntity o2) { + public int compare(final TileEntity o1, final TileEntity o2) { if (o1.xCoord == o2.xCoord && o1.yCoord == o2.yCoord && o1.zCoord == o2.zCoord) { if (WarpDriveConfig.LOGGING_JUMP) { WarpDrive.logger.warn(String.format("Removing TE duplicates: detected duplicate in %s @ %d %d %d: %s vs %s", diff --git a/src/main/java/cr0s/warpdrive/world/WorldGenStructure.java b/src/main/java/cr0s/warpdrive/world/WorldGenStructure.java index b03ad09a..548906bb 100644 --- a/src/main/java/cr0s/warpdrive/world/WorldGenStructure.java +++ b/src/main/java/cr0s/warpdrive/world/WorldGenStructure.java @@ -179,7 +179,7 @@ public class WorldGenStructure { } public void generateFromFile(final World world, final String filename, final int targetX, final int targetY, final int targetZ, final byte rotationSteps) { - StringBuilder reason = new StringBuilder(); + final StringBuilder reason = new StringBuilder(); final JumpShip jumpShip = JumpShip.createFromFile(filename, reason); if (jumpShip == null) { WarpDrive.logger.error(String.format("%s Failed to read schematic %s: %s", this, filename, reason.toString())); @@ -190,10 +190,10 @@ public class WorldGenStructure { public void deployShip(final World world, final JumpShip jumpShip, final int targetX, final int targetY, final int targetZ, final byte rotationSteps) { - Transformation transformation = new Transformation(jumpShip, world, targetX - jumpShip.coreX, targetY - jumpShip.coreY, targetZ - jumpShip.coreZ, rotationSteps); + final Transformation transformation = new Transformation(jumpShip, world, targetX - jumpShip.coreX, targetY - jumpShip.coreY, targetZ - jumpShip.coreZ, rotationSteps); for (int index = 0; index < jumpShip.jumpBlocks.length; index++) { // Deploy single block - JumpBlock jumpBlock = jumpShip.jumpBlocks[index]; + final JumpBlock jumpBlock = jumpShip.jumpBlocks[index]; if (jumpBlock == null) { if (WarpDriveConfig.LOGGING_BUILDING) { @@ -213,8 +213,8 @@ public class WorldGenStructure { WarpDrive.logger.info("At index " + index + ", deploying block " + Block.blockRegistry.getNameForObject(jumpBlock.block) + ":" + jumpBlock.blockMeta + " tileEntity " + jumpBlock.blockTileEntity + " NBT " + jumpBlock.blockNBT); } - ChunkCoordinates targetLocation = transformation.apply(jumpBlock.x, jumpBlock.y, jumpBlock.z); - Block blockAtTarget = world.getBlock(targetLocation.posX, targetLocation.posY, targetLocation.posZ); + final ChunkCoordinates targetLocation = transformation.apply(jumpBlock.x, jumpBlock.y, jumpBlock.z); + final Block blockAtTarget = world.getBlock(targetLocation.posX, targetLocation.posY, targetLocation.posZ); if (blockAtTarget == Blocks.air || Dictionary.BLOCKS_EXPANDABLE.contains(blockAtTarget)) { jumpBlock.deploy(world, transformation); } else {