Code cleanup (#133)

* gradle updateBuildScript

* fix comments and commented-out code

Code deletion, converting comments into javadocs, and refactoring code to not
need comments.

* remove redundant suppressions

* replace C-style array declaration with Java-style

* make private field final

* remove unnecessary semicolon

* extract a common part from an if

* simplify boolean expression

* simplify ternary if

* remove unused imports

* convert escaped characters for clarity

* replace while with for

* replace explicit types with diamond operators

* replace anonymous type with lambda

* enable modern Java syntax

* migrate to enhanced switch

* migrate to pattern variables for instanceof

* remove empty javadoc

* add Nonnull annotation to overrides of Nonnull methods

* replace wailaStack with null

When wailaStack is not null, the flow breaks out of the loop,
so there's no need to confuse the reader with putting wailaStack
both as the result and the parameter of the call - there's no
recursion.

* int cannot be bigger than its max value

* suppress dataflow warning

* remove redundant initializer

The default value of int is 0.

* null check is covered by instanceof

* simplify some calls of addVertexWithUV

* fix typos and add TODOs

* make flipState more understandable
This commit is contained in:
chill authored and GitHub committed 2023-06-18 23:29:57 +02:00
1 parent f87b76347e
commit d5b8ef6ea9
89 files changed
+421 -633

No files matched your search

@@ -102,9 +102,7 @@ public class PartFluidConversionMonitor extends PartFluidStorageMonitor {
}
}
} catch (final GridAccessException e) {
// :P
}
} catch (final GridAccessException ignored) {}
return true;
}
@@ -153,9 +151,7 @@ public class PartFluidConversionMonitor extends PartFluidStorageMonitor {
player.openContainer.detectAndSendChanges();
}
}
} catch (final GridAccessException e) {
// :P
}
} catch (final GridAccessException ignored) {}
}
}
}
@@ -163,9 +163,7 @@ public class PartFluidExportBus extends FCSharedFluidBus implements ICraftingReq
}
this.updateSchedulingMode(this.getSchedulingMode(), i);
return didSomething ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
} catch (GridAccessException e) {
// Ignore
}
} catch (GridAccessException ignored) {}
}
return TickRateModulation.SLEEP;
@@ -130,10 +130,16 @@ public class PartFluidLevelEmitter extends PartUpgradeable
return false;
}
final boolean flipState = this.getConfigManager().getSetting(Settings.REDSTONE_EMITTER)
== RedstoneMode.LOW_SIGNAL;
return flipState ? this.reportingValue >= this.lastReportedValue + 1
: this.reportingValue < this.lastReportedValue + 1;
final Enum<?> redstoneEmitterSetting = this.getConfigManager().getSetting(Settings.REDSTONE_EMITTER);
final boolean result;
if (redstoneEmitterSetting == RedstoneMode.LOW_SIGNAL) {
result = this.reportingValue >= this.lastReportedValue + 1;
} else {
result = this.reportingValue < this.lastReportedValue + 1;
}
return result;
}
@MENetworkEventSubscribe
@@ -181,9 +187,7 @@ public class PartFluidLevelEmitter extends PartUpgradeable
this.myWatcher.add(myStack);
}
this.updateReportingValue(this.getProxy().getStorage().getFluidInventory());
} catch (final GridAccessException e1) {
// :/
}
} catch (final GridAccessException ignored) {}
}
private void updateReportingValue(final IMEMonitor<IAEFluidStack> monitor) {
@@ -282,9 +286,7 @@ public class PartFluidLevelEmitter extends PartUpgradeable
public void onListUpdate() {
try {
this.updateReportingValue(this.getProxy().getStorage().getFluidInventory());
} catch (final GridAccessException e) {
// ;P
}
} catch (final GridAccessException ignored) {}
}
@Override
@@ -304,40 +306,23 @@ public class PartFluidLevelEmitter extends PartUpgradeable
Tessellator.instance.startDrawingQuads();
this.renderTorchAtAngle(0, -0.5, 0);
Tessellator.instance.draw();
// rh.setBounds( 7, 7, 10, 9, 9, 15 );
// rh.renderInventoryBox( renderer );
}
private void renderTorchAtAngle(double baseX, double baseY, double baseZ) {
final boolean isOn = this.isLevelEmitterOn();
final IIcon offTexture = this.getItemStack().getIconIndex();
final IIcon IIcon = (isOn ? CableBusTextures.LevelEmitterTorchOn.getIcon() : offTexture);
//
this.centerX = baseX + 0.5;
this.centerY = baseY + 0.5;
this.centerZ = baseZ + 0.5;
baseY += 7.0 / 16.0;
// double par11 = 0;
/*
* double d5 = (double)IIcon.func_94209_e(); double d6 = (double)IIcon.func_94206_g(); double d7 =
* (double)IIcon.func_94212_f(); double d8 = (double)IIcon.func_94210_h(); double d9 =
* (double)IIcon.func_94214_a(7.0D); double d10 = (double)IIcon.func_94207_b(6.0D); double d11 =
* (double)IIcon.func_94214_a(9.0D); double d12 = (double)IIcon.func_94207_b(8.0D); double d13 =
* (double)IIcon.func_94214_a(7.0D); double d14 = (double)IIcon.func_94207_b(13.0D); double d15 =
* (double)IIcon.func_94214_a(9.0D); double d16 = (double)IIcon.func_94207_b(15.0D);
*/
final float var16 = IIcon.getMinU();
final float var17 = IIcon.getMaxU();
final float var18 = IIcon.getMinV();
final float var19 = IIcon.getMaxV();
/*
* float var16 = (float)var14 / 256.0F; float var17 = ((float)var14 + 15.99F) / 256.0F; float var18 =
* (float)var15 / 256.0F; float var19 = ((float)var15 + 15.99F) / 256.0F;
*/
final double var20b = offTexture.getInterpolatedU(7.0D);
final double var24b = offTexture.getInterpolatedU(9.0D);
@@ -376,56 +361,26 @@ public class PartFluidLevelEmitter extends PartUpgradeable
final double var44 = 0.0625D;
final double Zero = 0;
final double par10 = 0;
this.addVertexWithUV(
baseX + Zero * (1.0D - TorchLen) - var44,
baseY + TorchLen - toff,
baseZ + par10 * (1.0D - TorchLen) - var44,
var20,
var22);
this.addVertexWithUV(
baseX + Zero * (1.0D - TorchLen) - var44,
baseY + TorchLen - toff,
baseZ + par10 * (1.0D - TorchLen) + var44,
var20,
var26);
this.addVertexWithUV(
baseX + Zero * (1.0D - TorchLen) + var44,
baseY + TorchLen - toff,
baseZ + par10 * (1.0D - TorchLen) + var44,
var24,
var26);
this.addVertexWithUV(
baseX + Zero * (1.0D - TorchLen) + var44,
baseY + TorchLen - toff,
baseZ + par10 * (1.0D - TorchLen) - var44,
var24,
var22);
final double x = baseX + Zero * (1.0D - TorchLen) - var44;
final double x1 = baseX + Zero * (1.0D - TorchLen) + var44;
final double y = baseY + TorchLen - toff;
final double var422 = 0.1915D + 1.0 / 16.0;
this.addVertexWithUV(
baseX + Zero * (1.0D - TorchLen) + var44,
baseY + var422,
baseZ + par10 * (1.0D - TorchLen) - var44,
var24b,
var22b);
this.addVertexWithUV(
baseX + Zero * (1.0D - TorchLen) + var44,
baseY + var422,
baseZ + par10 * (1.0D - TorchLen) + var44,
var24b,
var26b);
this.addVertexWithUV(
baseX + Zero * (1.0D - TorchLen) - var44,
baseY + var422,
baseZ + par10 * (1.0D - TorchLen) + var44,
var20b,
var26b);
this.addVertexWithUV(
baseX + Zero * (1.0D - TorchLen) - var44,
baseY + var422,
baseZ + par10 * (1.0D - TorchLen) - var44,
var20b,
var22b);
final double y1 = baseY + var422;
final double z = baseZ + par10 * (1.0D - TorchLen) - var44;
final double z1 = baseZ + par10 * (1.0D - TorchLen) + var44;
this.addVertexWithUV(x, y, z, var20, var22);
this.addVertexWithUV(x, y, z1, var20, var26);
this.addVertexWithUV(x1, y, z1, var24, var26);
this.addVertexWithUV(x1, y, z, var24, var22);
this.addVertexWithUV(x1, y1, z, var24b, var22b);
this.addVertexWithUV(x1, y1, z1, var24b, var26b);
this.addVertexWithUV(x, y1, z1, var20b, var26b);
this.addVertexWithUV(x, y1, z, var20b, var22b);
this.addVertexWithUV(baseX + var44 + Zero, baseY, baseZ - var44 + par10, var32, var30);
this.addVertexWithUV(baseX + var44 + Zero, baseY, baseZ + var44 + par10, var32, var34);
@@ -503,13 +458,6 @@ public class PartFluidLevelEmitter extends PartUpgradeable
public void renderStatic(final int x, final int y, final int z, final IPartRenderHelper rh,
final RenderBlocks renderer) {
rh.setTexture(this.getItemStack().getIconIndex());
// rh.setTexture( CableBusTextures.ItemPartLevelEmitterOn.getIcon() );
// rh.setBounds( 2, 2, 14, 14, 14, 16 );
// rh.renderBlock( x, y, z, renderer );
// rh.setBounds( 7, 7, 10, 9, 9, 15 );
// rh.renderBlock( x, y, z, renderer );
renderer.renderAllFaces = true;
@@ -523,8 +471,6 @@ public class PartFluidLevelEmitter extends PartUpgradeable
rh.setBounds(7, 7, 11, 9, 9, 12);
this.renderLights(x, y, z, rh, renderer);
// super.renderWorldBlock( world, x, y, z, block, modelId, renderer );
}
@Override
@@ -41,9 +41,8 @@ public class PartFluidPatternTerminal extends FCFluidEncodeTerminal {
final ItemStack removedStack, final ItemStack newStack) {
if (inv == this.pattern && slot == 1) {
final ItemStack is = inv.getStackInSlot(1);
if (is != null && is.getItem() instanceof ICraftingPatternItem) {
final ICraftingPatternItem pattern = (ICraftingPatternItem) is.getItem();
final ICraftingPatternDetails details = pattern
if (is != null && is.getItem() instanceof final ICraftingPatternItem craftingPatternItem) {
final ICraftingPatternDetails details = craftingPatternItem
.getPatternForItem(is, this.getHost().getTile().getWorldObj());
if (details != null) {
final IAEItemStack[] inItems = details.getInputs();
@@ -40,9 +40,8 @@ public class PartFluidPatternTerminalEx extends FCFluidEncodeTerminal {
if (inv == this.pattern && slot == 1) {
final ItemStack is = inv.getStackInSlot(1);
if (is != null && is.getItem() instanceof ICraftingPatternItem) {
final ICraftingPatternItem pattern = (ICraftingPatternItem) is.getItem();
final ICraftingPatternDetails details = pattern
if (is != null && is.getItem() instanceof final ICraftingPatternItem craftingPatternItem) {
final ICraftingPatternDetails details = craftingPatternItem
.getPatternForItem(is, this.getHost().getTile().getWorldObj());
if (details != null) {
@@ -348,8 +348,7 @@ public class PartFluidStorageBus extends PartUpgradeable
if (esh != null) {
final IMEInventory<?> inv = esh
.getInventory(target, this.getSide().getOpposite(), StorageChannel.FLUIDS, this.source);
if (inv instanceof MEMonitorIFluidHandler) {
final MEMonitorIFluidHandler h = (MEMonitorIFluidHandler) inv;
if (inv instanceof final MEMonitorIFluidHandler h) {
h.setMode((StorageFilter) this.getConfigManager().getSetting(Settings.STORAGE_FILTER));
h.setActionSource(new MachineSource(this));
this.monitor = (MEMonitorIFluidHandler) inv;
@@ -179,8 +179,8 @@ public abstract class FCFluidEncodeTerminal extends FCPart implements IItemPatte
@Override
public void sortCraftingItems() {
List<ItemStack> items = new ArrayList<ItemStack>();
List<ItemStack> fluids = new ArrayList<ItemStack>();
List<ItemStack> items = new ArrayList<>();
List<ItemStack> fluids = new ArrayList<>();
for (ItemStack is : this.crafting) {
if (is == null) continue;
if (is.getItem() instanceof ItemFluidPacket) {
@@ -76,7 +76,7 @@ public abstract class FCPart extends AEBasePart
this.getProxy().setFlags(GridFlags.REQUIRE_CHANNEL);
this.getProxy().setIdlePowerUsage(1.0 / 2.0);
} else {
this.getProxy().setIdlePowerUsage(1.0 / 16.0); // lights drain a little bit.
this.getProxy().setIdlePowerUsage(1.0 / 16.0); // lights drain a little
}
this.cm.registerSetting(Settings.SORT_BY, SortOrder.NAME);
this.cm.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
@@ -163,9 +163,7 @@ public abstract class FCPart extends AEBasePart
if (this.getProxy().getNode().meetsChannelRequirements()) {
this.clientFlags = this.getClientFlags() | FCPart.CHANNEL_FLAG;
}
} catch (final GridAccessException e) {
// um.. nothing.
}
} catch (final GridAccessException ignored) {}
data.writeByte((byte) this.getClientFlags());
}
@@ -195,18 +193,10 @@ public abstract class FCPart extends AEBasePart
}
switch (this.getSpin()) {
case 0:
this.spin = 1;
break;
case 1:
this.spin = 3;
break;
case 2:
this.spin = 0;
break;
case 3:
this.spin = 2;
break;
case 0 -> this.spin = 1;
case 1 -> this.spin = 3;
case 2 -> this.spin = 0;
case 3 -> this.spin = 2;
}
this.getHost().markForUpdate();
@@ -276,9 +266,7 @@ public abstract class FCPart extends AEBasePart
public IMEMonitor<IAEItemStack> getItemInventory() {
try {
return this.getProxy().getStorage().getItemInventory();
} catch (final GridAccessException e) {
// err nope?
}
} catch (final GridAccessException ignored) {}
return null;
}
@@ -286,9 +274,7 @@ public abstract class FCPart extends AEBasePart
public IMEMonitor<IAEFluidStack> getFluidInventory() {
try {
return this.getProxy().getStorage().getFluidInventory();
} catch (final GridAccessException e) {
// err nope?
}
} catch (final GridAccessException ignored) {}
return null;
}
@@ -434,27 +420,27 @@ public abstract class FCPart extends AEBasePart
/**
* The texture used for the bright front layer.
* <p>
* The final texture can overlap any of the the texture in no particular order.
* The final texture can overlap any of the texture in no particular order.
*/
public abstract FCPartsTexture getFrontBright();
/**
* The texture used for the colored (medium) front layer.
* <p>
* The final texture can overlap any of the the texture in no particular order.
* The final texture can overlap any of the texture in no particular order.
*/
public abstract FCPartsTexture getFrontColored();
/**
* The texture used for the dark front layer.
* <p>
* The final texture can overlap any of the the texture in no particular order.
* The final texture can overlap any of the texture in no particular order.
*/
public abstract FCPartsTexture getFrontDark();
/**
* Should the part emit light. This actually only affects the light level, light source use a level of 15 and non
* light source 9.
* Should the part emit light. This actually only affects the light level, light source use a level of 15 and
* non-light source 9.
*/
public abstract boolean isLightSource();
}
@@ -175,9 +175,7 @@ public abstract class FCPartMonitor extends AbstractPartDisplay implements IPart
this.updateReportingValue(this.getProxy().getStorage().getFluidInventory());
}
} catch (final GridAccessException e) {
// >.>
}
} catch (final GridAccessException ignored) {}
}
protected void extractItem(final EntityPlayer player) {}
@@ -248,41 +246,35 @@ public abstract class FCPartMonitor extends AbstractPartDisplay implements IPart
}
private void tesrRenderScreen(final Tessellator tess, final IAEFluidStack ais) {
// GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS );
final ForgeDirection d = this.getSide();
GL11.glTranslated(d.offsetX * 0.77, d.offsetY * 0.77, d.offsetZ * 0.77);
switch (d) {
case UP:
case UP -> {
GL11.glScalef(1.0f, -1.0f, 1.0f);
GL11.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
GL11.glRotatef(this.getSpin() * 90.0F, 0, 0, 1);
break;
case DOWN:
}
case DOWN -> {
GL11.glScalef(1.0f, -1.0f, 1.0f);
GL11.glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
GL11.glRotatef(this.getSpin() * -90.0F, 0, 0, 1);
break;
case EAST:
}
case EAST -> {
GL11.glScalef(-1.0f, -1.0f, -1.0f);
GL11.glRotatef(-90.0f, 0.0f, 1.0f, 0.0f);
break;
case WEST:
}
case WEST -> {
GL11.glScalef(-1.0f, -1.0f, -1.0f);
GL11.glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
break;
case NORTH:
GL11.glScalef(-1.0f, -1.0f, -1.0f);
break;
case SOUTH:
}
case NORTH -> GL11.glScalef(-1.0f, -1.0f, -1.0f);
case SOUTH -> {
GL11.glScalef(-1.0f, -1.0f, -1.0f);
GL11.glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
break;
default:
break;
}
default -> {}
}
final ItemStack sis = ItemFluidPacket.newDisplayStack(ais.getFluidStack());
@@ -296,7 +288,6 @@ public abstract class FCPartMonitor extends AbstractPartDisplay implements IPart
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
// RenderHelper.enableGUIStandardItemLighting();
tess.setColorOpaque_F(1.0f, 1.0f, 1.0f);
ClientHelper.proxy.doRenderItem(sis, this.getTile().getWorldObj());
@@ -318,7 +309,6 @@ public abstract class FCPartMonitor extends AbstractPartDisplay implements IPart
GL11.glTranslatef(-0.5f * width, 0.0f, -1.0f);
fr.drawString(renderedStackSize, 0, 0, 0);
}
// GL11.glPopAttrib();
}
@Override
@@ -62,9 +62,7 @@ public abstract class FCSharedFluidBus extends PartUpgradeable implements IGridT
} else {
this.getProxy().getTick().sleepDevice(this.getProxy().getNode());
}
} catch (final GridAccessException e) {
// :P
}
} catch (final GridAccessException ignored) {}
}
@Override