From a5a336f3db87f632ebc59bfea2ca8be289d50182 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 4 Jan 2019 19:09:58 +0100 Subject: [PATCH] Code cleanup --- .../block/TileEntityAbstractInterfaced.java | 23 ++++++++++++------- .../cr0s/warpdrive/block/TileEntityLaser.java | 1 - .../block/building/TileEntityShipScanner.java | 2 +- .../collection/TileEntityMiningLaser.java | 7 +++--- .../block/detection/TileEntityCamera.java | 2 +- .../block/detection/TileEntityMonitor.java | 2 +- .../movement/TileEntityTransporterCore.java | 7 ++---- .../block/weapon/TileEntityLaserCamera.java | 2 +- .../cr0s/warpdrive/command/CommandDump.java | 4 +++- .../warpdriveShipController/startup | 1 - .../warpdriveShipController/startup | 1 - 11 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/main/java/cr0s/warpdrive/block/TileEntityAbstractInterfaced.java b/src/main/java/cr0s/warpdrive/block/TileEntityAbstractInterfaced.java index 88d1e5e7..10ebc32c 100644 --- a/src/main/java/cr0s/warpdrive/block/TileEntityAbstractInterfaced.java +++ b/src/main/java/cr0s/warpdrive/block/TileEntityAbstractInterfaced.java @@ -447,13 +447,14 @@ public abstract class TileEntityAbstractInterfaced extends TileEntityAbstractBas private void CC_mount(@Nonnull final IComputerAccess computer) { if (CC_hasResource && WarpDriveConfig.G_LUA_SCRIPTS != WarpDriveConfig.LUA_SCRIPTS_NONE) { try { - final String modid = WarpDrive.MODID.toLowerCase(); - final String folderPeripheral = peripheralName.replace(modid, modid + "/"); - computer.mount("/" + modid , ComputerCraftAPI.createResourceMount(WarpDrive.class, modid, "lua.ComputerCraft/common")); - computer.mount("/" + folderPeripheral, ComputerCraftAPI.createResourceMount(WarpDrive.class, modid, "lua.ComputerCraft/" + peripheralName)); + CC_mount(computer, "lua.ComputerCraft/common", "/" + WarpDrive.MODID); + + final String folderPeripheral = peripheralName.replace(WarpDrive.MODID, WarpDrive.MODID + "/"); + CC_mount(computer, "lua.ComputerCraft/" + peripheralName, "/" + folderPeripheral); + if (WarpDriveConfig.G_LUA_SCRIPTS == WarpDriveConfig.LUA_SCRIPTS_ALL) { for (final String script : CC_scripts) { - computer.mount("/" + script, ComputerCraftAPI.createResourceMount(WarpDrive.class, modid, "lua.ComputerCraft/" + peripheralName + "/" + script)); + CC_mount(computer, "lua.ComputerCraft/" + peripheralName + "/" + script, "/" + script); } } } catch (final Exception exception) { @@ -466,6 +467,13 @@ public abstract class TileEntityAbstractInterfaced extends TileEntityAbstractBas } } + @Optional.Method(modid = "computercraft") + private void CC_mount(@Nonnull final IComputerAccess computer, final String pathAsset, final String pathLUA) { + final IMount mountCommon = ComputerCraftAPI.createResourceMount(WarpDrive.class, WarpDrive.MODID, pathAsset); + assert mountCommon != null; + computer.mount(pathLUA, mountCommon); + } + @Optional.Method(modid = "computercraft") private void CC_unmount() { for (final IComputerAccess computerAccess : CC_connectedComputers.values()) { @@ -477,9 +485,8 @@ public abstract class TileEntityAbstractInterfaced extends TileEntityAbstractBas private void CC_unmount(@Nonnull final IComputerAccess computer) { if (CC_hasResource && WarpDriveConfig.G_LUA_SCRIPTS != WarpDriveConfig.LUA_SCRIPTS_NONE) { try { - final String modid = WarpDrive.MODID.toLowerCase(); - final String folderPeripheral = peripheralName.replace(modid, modid + "/"); - computer.unmount("/" + modid ); + final String folderPeripheral = peripheralName.replace(WarpDrive.MODID, WarpDrive.MODID + "/"); + computer.unmount("/" + WarpDrive.MODID); computer.unmount("/" + folderPeripheral); if (WarpDriveConfig.G_LUA_SCRIPTS == WarpDriveConfig.LUA_SCRIPTS_ALL) { for (final String script : CC_scripts) { diff --git a/src/main/java/cr0s/warpdrive/block/TileEntityLaser.java b/src/main/java/cr0s/warpdrive/block/TileEntityLaser.java index b7ea0fa1..5ed61a63 100644 --- a/src/main/java/cr0s/warpdrive/block/TileEntityLaser.java +++ b/src/main/java/cr0s/warpdrive/block/TileEntityLaser.java @@ -774,7 +774,6 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre final float deltaY = -Commons.toFloat(arguments[1]); final float deltaZ = Commons.toFloat(arguments[2]); final double horizontalDistance = MathHelper.sqrt(deltaX * deltaX + deltaZ * deltaZ); - //noinspection SuspiciousNameCombination newYaw = (float) (Math.atan2(deltaX, deltaZ) * 180.0D / Math.PI); newPitch = (float) (Math.atan2(deltaY, horizontalDistance) * 180.0D / Math.PI); initiateBeamEmission(newYaw, newPitch); diff --git a/src/main/java/cr0s/warpdrive/block/building/TileEntityShipScanner.java b/src/main/java/cr0s/warpdrive/block/building/TileEntityShipScanner.java index 5ce5eaeb..faa10606 100644 --- a/src/main/java/cr0s/warpdrive/block/building/TileEntityShipScanner.java +++ b/src/main/java/cr0s/warpdrive/block/building/TileEntityShipScanner.java @@ -627,7 +627,7 @@ public class TileEntityShipScanner extends TileEntityAbstractMachine implements } @Override - public void onDataPacket(NetworkManager networkManager, SPacketUpdateTileEntity packet) { + public void onDataPacket(final NetworkManager networkManager, final SPacketUpdateTileEntity packet) { final NBTTagCompound tagCompound = packet.getNbtCompound(); readFromNBT(tagCompound); } diff --git a/src/main/java/cr0s/warpdrive/block/collection/TileEntityMiningLaser.java b/src/main/java/cr0s/warpdrive/block/collection/TileEntityMiningLaser.java index d3b9dd7c..abbff790 100644 --- a/src/main/java/cr0s/warpdrive/block/collection/TileEntityMiningLaser.java +++ b/src/main/java/cr0s/warpdrive/block/collection/TileEntityMiningLaser.java @@ -480,10 +480,11 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner { if (isActive()) { retValuablesInLayer = valuablesInLayer.size(); retValuablesMined = valuableIndex; - - return new Object[] { status, isActive(), energy, currentLayer, retValuablesMined, retValuablesInLayer }; + } else { + retValuablesInLayer = 0; + retValuablesMined = 0; } - return new Object[] { status, isActive(), energy, currentLayer, 0, 0 }; + return new Object[] { status, isActive(), energy, currentLayer, retValuablesMined, retValuablesInLayer }; } private Object[] onlyOres(final Object[] arguments) { diff --git a/src/main/java/cr0s/warpdrive/block/detection/TileEntityCamera.java b/src/main/java/cr0s/warpdrive/block/detection/TileEntityCamera.java index b56df15c..4023c0af 100644 --- a/src/main/java/cr0s/warpdrive/block/detection/TileEntityCamera.java +++ b/src/main/java/cr0s/warpdrive/block/detection/TileEntityCamera.java @@ -76,10 +76,10 @@ public class TileEntityCamera extends TileEntityAbstractMachine implements IVide if (WarpDriveConfig.LOGGING_VIDEO_CHANNEL) { WarpDrive.logger.info(this + " Video channel set to " + videoChannel); } + markDirty(); // force update through main thread since CC runs on server as 'client' packetSendTicks = 0; registryUpdateTicks = 0; - markDirty(); } } diff --git a/src/main/java/cr0s/warpdrive/block/detection/TileEntityMonitor.java b/src/main/java/cr0s/warpdrive/block/detection/TileEntityMonitor.java index ee9c8c52..83b94462 100644 --- a/src/main/java/cr0s/warpdrive/block/detection/TileEntityMonitor.java +++ b/src/main/java/cr0s/warpdrive/block/detection/TileEntityMonitor.java @@ -62,9 +62,9 @@ public class TileEntityMonitor extends TileEntityAbstractMachine implements IVid if (WarpDriveConfig.LOGGING_VIDEO_CHANNEL) { WarpDrive.logger.info(this + " Monitor video channel set to " + videoChannel); } + markDirty(); // force update through main thread since CC runs on server as 'client' packetSendTicks = 0; - markDirty(); } } diff --git a/src/main/java/cr0s/warpdrive/block/movement/TileEntityTransporterCore.java b/src/main/java/cr0s/warpdrive/block/movement/TileEntityTransporterCore.java index 1247db45..038f7cc0 100644 --- a/src/main/java/cr0s/warpdrive/block/movement/TileEntityTransporterCore.java +++ b/src/main/java/cr0s/warpdrive/block/movement/TileEntityTransporterCore.java @@ -107,8 +107,8 @@ public class TileEntityTransporterCore extends TileEntityAbstractEnergyConsumer private GlobalPosition globalPositionLocal = null; private GlobalPosition globalPositionRemote = null; private ArrayList vRemoteScanners = null; - private HashMap movingEntitiesLocal = new HashMap<>(8); - private HashMap movingEntitiesRemote = new HashMap<>(8); + private final HashMap movingEntitiesLocal = new HashMap<>(8); + private final HashMap movingEntitiesRemote = new HashMap<>(8); private int tickEnergizing = 0; public TileEntityTransporterCore() { @@ -646,7 +646,6 @@ public class TileEntityTransporterCore extends TileEntityAbstractEnergyConsumer vMax.x + 1.0D, vMax.y + 1.0D, vMax.z + 1.0D); } - @SuppressWarnings("unchecked") public Collection getContainments() { return vLocalContainments; } @@ -1480,7 +1479,6 @@ public class TileEntityTransporterCore extends TileEntityAbstractEnergyConsumer if ( tagCompound.hasKey("scanners", Constants.NBT.TAG_LIST) && tagCompound.hasKey("containments", Constants.NBT.TAG_LIST)) { final NBTTagList tagListScanners = (NBTTagList) tagCompound.getTag("scanners"); - assert tagListScanners != null; final ArrayList vScanners = new ArrayList<>(tagListScanners.tagCount()); for (int indexScanner = 0; indexScanner < tagListScanners.tagCount(); indexScanner++) { final BlockPos vScanner = Commons.createBlockPosFromNBT(tagListScanners.getCompoundTagAt(indexScanner)); @@ -1488,7 +1486,6 @@ public class TileEntityTransporterCore extends TileEntityAbstractEnergyConsumer } final NBTTagList tagListContainments = (NBTTagList) tagCompound.getTag("containments"); - assert tagListContainments != null; final ArrayList vContainments = new ArrayList<>(tagListContainments.tagCount()); for (int indexContainment = 0; indexContainment < tagListContainments.tagCount(); indexContainment++) { final BlockPos vContainment = Commons.createBlockPosFromNBT(tagListContainments.getCompoundTagAt(indexContainment)); diff --git a/src/main/java/cr0s/warpdrive/block/weapon/TileEntityLaserCamera.java b/src/main/java/cr0s/warpdrive/block/weapon/TileEntityLaserCamera.java index 0b5a678c..ad82b15e 100644 --- a/src/main/java/cr0s/warpdrive/block/weapon/TileEntityLaserCamera.java +++ b/src/main/java/cr0s/warpdrive/block/weapon/TileEntityLaserCamera.java @@ -73,10 +73,10 @@ public class TileEntityLaserCamera extends TileEntityLaser implements IVideoChan public void setVideoChannel(final int parVideoChannel) { if (videoChannel != parVideoChannel && (parVideoChannel <= VIDEO_CHANNEL_MAX) && (parVideoChannel > VIDEO_CHANNEL_MIN)) { videoChannel = parVideoChannel; - markDirty(); if (WarpDriveConfig.LOGGING_VIDEO_CHANNEL) { WarpDrive.logger.info(this + " Video channel updated from " + videoChannel + " to " + parVideoChannel); } + markDirty(); // force update through main thread since CC runs on server as 'client' packetSendTicks = 0; registryUpdateTicks = 0; diff --git a/src/main/java/cr0s/warpdrive/command/CommandDump.java b/src/main/java/cr0s/warpdrive/command/CommandDump.java index e98e1f37..56e75c06 100644 --- a/src/main/java/cr0s/warpdrive/command/CommandDump.java +++ b/src/main/java/cr0s/warpdrive/command/CommandDump.java @@ -18,6 +18,7 @@ import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import javax.annotation.Nonnull; +import javax.annotation.Nullable; public class CommandDump extends AbstractCommand { @@ -95,7 +96,8 @@ public class CommandDump extends AbstractCommand { return "/wdump: write loot table in console for item container below or next to player"; } - private IInventory getInventory(final World world, final int x, final int y, final int z) { + @Nullable + private IInventory getInventory(@Nonnull final World world, final int x, final int y, final int z) { final BlockPos blockPos = new BlockPos(x, y, z); final IBlockState blockState = world.getBlockState(blockPos); if (blockState.getBlock() instanceof ITileEntityProvider) { diff --git a/src/main/resources/assets/warpdrive/lua.ComputerCraft/warpdriveShipController/startup b/src/main/resources/assets/warpdrive/lua.ComputerCraft/warpdriveShipController/startup index 60653a0a..53dda324 100644 --- a/src/main/resources/assets/warpdrive/lua.ComputerCraft/warpdriveShipController/startup +++ b/src/main/resources/assets/warpdrive/lua.ComputerCraft/warpdriveShipController/startup @@ -279,7 +279,6 @@ end function ship_page_setRotation() local inputAbort = false - local drun = true w.page_begin("<==== Set ship rotation ====>") w.setCursorPos(1, 8) w.setColorHelp() diff --git a/src/main/resources/assets/warpdrive/lua.OpenComputers/warpdriveShipController/startup b/src/main/resources/assets/warpdrive/lua.OpenComputers/warpdriveShipController/startup index a1cdaa91..51876db5 100644 --- a/src/main/resources/assets/warpdrive/lua.OpenComputers/warpdriveShipController/startup +++ b/src/main/resources/assets/warpdrive/lua.OpenComputers/warpdriveShipController/startup @@ -284,7 +284,6 @@ end function ship_page_setRotation() local inputAbort = false - local drun = true w.page_begin("<==== Set ship rotation ====>") w.setCursorPos(1, 11) w.setColorHelp()