Code cleanup

This commit is contained in:
Unknown 2019-01-04 19:09:58 +01:00 committed by unknown
parent c8241775a3
commit a5a336f3db
11 changed files with 28 additions and 24 deletions

View file

@ -447,13 +447,14 @@ public abstract class TileEntityAbstractInterfaced extends TileEntityAbstractBas
private void CC_mount(@Nonnull final IComputerAccess computer) { private void CC_mount(@Nonnull final IComputerAccess computer) {
if (CC_hasResource && WarpDriveConfig.G_LUA_SCRIPTS != WarpDriveConfig.LUA_SCRIPTS_NONE) { if (CC_hasResource && WarpDriveConfig.G_LUA_SCRIPTS != WarpDriveConfig.LUA_SCRIPTS_NONE) {
try { try {
final String modid = WarpDrive.MODID.toLowerCase(); CC_mount(computer, "lua.ComputerCraft/common", "/" + WarpDrive.MODID);
final String folderPeripheral = peripheralName.replace(modid, modid + "/");
computer.mount("/" + modid , ComputerCraftAPI.createResourceMount(WarpDrive.class, modid, "lua.ComputerCraft/common")); final String folderPeripheral = peripheralName.replace(WarpDrive.MODID, WarpDrive.MODID + "/");
computer.mount("/" + folderPeripheral, ComputerCraftAPI.createResourceMount(WarpDrive.class, modid, "lua.ComputerCraft/" + peripheralName)); CC_mount(computer, "lua.ComputerCraft/" + peripheralName, "/" + folderPeripheral);
if (WarpDriveConfig.G_LUA_SCRIPTS == WarpDriveConfig.LUA_SCRIPTS_ALL) { if (WarpDriveConfig.G_LUA_SCRIPTS == WarpDriveConfig.LUA_SCRIPTS_ALL) {
for (final String script : CC_scripts) { 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) { } 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") @Optional.Method(modid = "computercraft")
private void CC_unmount() { private void CC_unmount() {
for (final IComputerAccess computerAccess : CC_connectedComputers.values()) { 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) { private void CC_unmount(@Nonnull final IComputerAccess computer) {
if (CC_hasResource && WarpDriveConfig.G_LUA_SCRIPTS != WarpDriveConfig.LUA_SCRIPTS_NONE) { if (CC_hasResource && WarpDriveConfig.G_LUA_SCRIPTS != WarpDriveConfig.LUA_SCRIPTS_NONE) {
try { try {
final String modid = WarpDrive.MODID.toLowerCase(); final String folderPeripheral = peripheralName.replace(WarpDrive.MODID, WarpDrive.MODID + "/");
final String folderPeripheral = peripheralName.replace(modid, modid + "/"); computer.unmount("/" + WarpDrive.MODID);
computer.unmount("/" + modid );
computer.unmount("/" + folderPeripheral); computer.unmount("/" + folderPeripheral);
if (WarpDriveConfig.G_LUA_SCRIPTS == WarpDriveConfig.LUA_SCRIPTS_ALL) { if (WarpDriveConfig.G_LUA_SCRIPTS == WarpDriveConfig.LUA_SCRIPTS_ALL) {
for (final String script : CC_scripts) { for (final String script : CC_scripts) {

View file

@ -774,7 +774,6 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
final float deltaY = -Commons.toFloat(arguments[1]); final float deltaY = -Commons.toFloat(arguments[1]);
final float deltaZ = Commons.toFloat(arguments[2]); final float deltaZ = Commons.toFloat(arguments[2]);
final double horizontalDistance = MathHelper.sqrt(deltaX * deltaX + deltaZ * deltaZ); final double horizontalDistance = MathHelper.sqrt(deltaX * deltaX + deltaZ * deltaZ);
//noinspection SuspiciousNameCombination
newYaw = (float) (Math.atan2(deltaX, deltaZ) * 180.0D / Math.PI); newYaw = (float) (Math.atan2(deltaX, deltaZ) * 180.0D / Math.PI);
newPitch = (float) (Math.atan2(deltaY, horizontalDistance) * 180.0D / Math.PI); newPitch = (float) (Math.atan2(deltaY, horizontalDistance) * 180.0D / Math.PI);
initiateBeamEmission(newYaw, newPitch); initiateBeamEmission(newYaw, newPitch);

View file

@ -627,7 +627,7 @@ public class TileEntityShipScanner extends TileEntityAbstractMachine implements
} }
@Override @Override
public void onDataPacket(NetworkManager networkManager, SPacketUpdateTileEntity packet) { public void onDataPacket(final NetworkManager networkManager, final SPacketUpdateTileEntity packet) {
final NBTTagCompound tagCompound = packet.getNbtCompound(); final NBTTagCompound tagCompound = packet.getNbtCompound();
readFromNBT(tagCompound); readFromNBT(tagCompound);
} }

View file

@ -480,10 +480,11 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
if (isActive()) { if (isActive()) {
retValuablesInLayer = valuablesInLayer.size(); retValuablesInLayer = valuablesInLayer.size();
retValuablesMined = valuableIndex; retValuablesMined = valuableIndex;
} else {
return new Object[] { status, isActive(), energy, currentLayer, retValuablesMined, retValuablesInLayer }; 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) { private Object[] onlyOres(final Object[] arguments) {

View file

@ -76,10 +76,10 @@ public class TileEntityCamera extends TileEntityAbstractMachine implements IVide
if (WarpDriveConfig.LOGGING_VIDEO_CHANNEL) { if (WarpDriveConfig.LOGGING_VIDEO_CHANNEL) {
WarpDrive.logger.info(this + " Video channel set to " + videoChannel); WarpDrive.logger.info(this + " Video channel set to " + videoChannel);
} }
markDirty();
// force update through main thread since CC runs on server as 'client' // force update through main thread since CC runs on server as 'client'
packetSendTicks = 0; packetSendTicks = 0;
registryUpdateTicks = 0; registryUpdateTicks = 0;
markDirty();
} }
} }

View file

@ -62,9 +62,9 @@ public class TileEntityMonitor extends TileEntityAbstractMachine implements IVid
if (WarpDriveConfig.LOGGING_VIDEO_CHANNEL) { if (WarpDriveConfig.LOGGING_VIDEO_CHANNEL) {
WarpDrive.logger.info(this + " Monitor video channel set to " + videoChannel); WarpDrive.logger.info(this + " Monitor video channel set to " + videoChannel);
} }
markDirty();
// force update through main thread since CC runs on server as 'client' // force update through main thread since CC runs on server as 'client'
packetSendTicks = 0; packetSendTicks = 0;
markDirty();
} }
} }

View file

@ -107,8 +107,8 @@ public class TileEntityTransporterCore extends TileEntityAbstractEnergyConsumer
private GlobalPosition globalPositionLocal = null; private GlobalPosition globalPositionLocal = null;
private GlobalPosition globalPositionRemote = null; private GlobalPosition globalPositionRemote = null;
private ArrayList<BlockPos> vRemoteScanners = null; private ArrayList<BlockPos> vRemoteScanners = null;
private HashMap<Integer, MovingEntity> movingEntitiesLocal = new HashMap<>(8); private final HashMap<Integer, MovingEntity> movingEntitiesLocal = new HashMap<>(8);
private HashMap<Integer, MovingEntity> movingEntitiesRemote = new HashMap<>(8); private final HashMap<Integer, MovingEntity> movingEntitiesRemote = new HashMap<>(8);
private int tickEnergizing = 0; private int tickEnergizing = 0;
public TileEntityTransporterCore() { public TileEntityTransporterCore() {
@ -646,7 +646,6 @@ public class TileEntityTransporterCore extends TileEntityAbstractEnergyConsumer
vMax.x + 1.0D, vMax.y + 1.0D, vMax.z + 1.0D); vMax.x + 1.0D, vMax.y + 1.0D, vMax.z + 1.0D);
} }
@SuppressWarnings("unchecked")
public Collection<BlockPos> getContainments() { public Collection<BlockPos> getContainments() {
return vLocalContainments; return vLocalContainments;
} }
@ -1480,7 +1479,6 @@ public class TileEntityTransporterCore extends TileEntityAbstractEnergyConsumer
if ( tagCompound.hasKey("scanners", Constants.NBT.TAG_LIST) if ( tagCompound.hasKey("scanners", Constants.NBT.TAG_LIST)
&& tagCompound.hasKey("containments", Constants.NBT.TAG_LIST)) { && tagCompound.hasKey("containments", Constants.NBT.TAG_LIST)) {
final NBTTagList tagListScanners = (NBTTagList) tagCompound.getTag("scanners"); final NBTTagList tagListScanners = (NBTTagList) tagCompound.getTag("scanners");
assert tagListScanners != null;
final ArrayList<BlockPos> vScanners = new ArrayList<>(tagListScanners.tagCount()); final ArrayList<BlockPos> vScanners = new ArrayList<>(tagListScanners.tagCount());
for (int indexScanner = 0; indexScanner < tagListScanners.tagCount(); indexScanner++) { for (int indexScanner = 0; indexScanner < tagListScanners.tagCount(); indexScanner++) {
final BlockPos vScanner = Commons.createBlockPosFromNBT(tagListScanners.getCompoundTagAt(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"); final NBTTagList tagListContainments = (NBTTagList) tagCompound.getTag("containments");
assert tagListContainments != null;
final ArrayList<BlockPos> vContainments = new ArrayList<>(tagListContainments.tagCount()); final ArrayList<BlockPos> vContainments = new ArrayList<>(tagListContainments.tagCount());
for (int indexContainment = 0; indexContainment < tagListContainments.tagCount(); indexContainment++) { for (int indexContainment = 0; indexContainment < tagListContainments.tagCount(); indexContainment++) {
final BlockPos vContainment = Commons.createBlockPosFromNBT(tagListContainments.getCompoundTagAt(indexContainment)); final BlockPos vContainment = Commons.createBlockPosFromNBT(tagListContainments.getCompoundTagAt(indexContainment));

View file

@ -73,10 +73,10 @@ public class TileEntityLaserCamera extends TileEntityLaser implements IVideoChan
public void setVideoChannel(final int parVideoChannel) { public void setVideoChannel(final int parVideoChannel) {
if (videoChannel != parVideoChannel && (parVideoChannel <= VIDEO_CHANNEL_MAX) && (parVideoChannel > VIDEO_CHANNEL_MIN)) { if (videoChannel != parVideoChannel && (parVideoChannel <= VIDEO_CHANNEL_MAX) && (parVideoChannel > VIDEO_CHANNEL_MIN)) {
videoChannel = parVideoChannel; videoChannel = parVideoChannel;
markDirty();
if (WarpDriveConfig.LOGGING_VIDEO_CHANNEL) { if (WarpDriveConfig.LOGGING_VIDEO_CHANNEL) {
WarpDrive.logger.info(this + " Video channel updated from " + videoChannel + " to " + parVideoChannel); WarpDrive.logger.info(this + " Video channel updated from " + videoChannel + " to " + parVideoChannel);
} }
markDirty();
// force update through main thread since CC runs on server as 'client' // force update through main thread since CC runs on server as 'client'
packetSendTicks = 0; packetSendTicks = 0;
registryUpdateTicks = 0; registryUpdateTicks = 0;

View file

@ -18,6 +18,7 @@ import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class CommandDump extends AbstractCommand { 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"; 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 BlockPos blockPos = new BlockPos(x, y, z);
final IBlockState blockState = world.getBlockState(blockPos); final IBlockState blockState = world.getBlockState(blockPos);
if (blockState.getBlock() instanceof ITileEntityProvider) { if (blockState.getBlock() instanceof ITileEntityProvider) {

View file

@ -279,7 +279,6 @@ end
function ship_page_setRotation() function ship_page_setRotation()
local inputAbort = false local inputAbort = false
local drun = true
w.page_begin("<==== Set ship rotation ====>") w.page_begin("<==== Set ship rotation ====>")
w.setCursorPos(1, 8) w.setCursorPos(1, 8)
w.setColorHelp() w.setColorHelp()

View file

@ -284,7 +284,6 @@ end
function ship_page_setRotation() function ship_page_setRotation()
local inputAbort = false local inputAbort = false
local drun = true
w.page_begin("<==== Set ship rotation ====>") w.page_begin("<==== Set ship rotation ====>")
w.setCursorPos(1, 11) w.setCursorPos(1, 11)
w.setColorHelp() w.setColorHelp()