From b088958c9f6935d356b6c087c8e8106b400aa24f Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Sat, 1 Apr 2023 20:06:12 +0100 Subject: Jabel, Generic injection and mostly automatic code cleanup (#1829) * Enable Jabel&Generic injection, fix type error caused by this * add missing <> * Infer generic types automatically * Parametrize cast types * Use enhanced for loops * Unnecessary boxing * Unnecessary unboxing * Use Objects.equals * Explicit type can be replaced with `<>` * Collapse identical catch blocks * Add SafeVarargs where applicable * Anonymous type can be replaced with lambda * Use List.sort directly * Lambda can be a method reference * Statement lambda can be an expression lambda * Use string switches * Instanceof pattern matching * Text block can be used * Migrate to enhanced switch * Java style array declarations * Unnecessary toString() * More unnecessary String conversions * Unnecessary modifiers * Unnecessary semicolons * Fix duplicate conditions * Extract common code from if branches * Replace switches with ifs for 1-2 cases * Inner class may be static * Minor performance issues * Replace string appending in loops with string builders * Fix IntelliJ using the wrong empty list method * Use Long.compare * Generic arguments: getSubItems * Generic arguments: getSubBlocks * Raw types warnings * Fix remaining missing generics * Too weak variable type leads to unnecessary cast * Redundant type casts * Redundant array length check * Redundant vararg arrays * Manual min/max implementations * A couple missed inspections * Goodbye explosion power ternary ladder * Apply spotless * Get rid of the other two big ternary ladders * Binary search explosion power * Don't overcomplicate things --- .../multiblock/base/MultiBlockController.java | 7 +++---- .../multiblock/base/MultiBlockPart.java | 22 ++++++++++------------ 2 files changed, 13 insertions(+), 16 deletions(-) (limited to 'src/main/java/gregtech/api/multitileentity/multiblock/base') diff --git a/src/main/java/gregtech/api/multitileentity/multiblock/base/MultiBlockController.java b/src/main/java/gregtech/api/multitileentity/multiblock/base/MultiBlockController.java index 72e766d54c..b76dc1b4bc 100644 --- a/src/main/java/gregtech/api/multitileentity/multiblock/base/MultiBlockController.java +++ b/src/main/java/gregtech/api/multitileentity/multiblock/base/MultiBlockController.java @@ -656,9 +656,8 @@ public abstract class MultiBlockController> ex @Override public boolean check(S t, World world, int x, int y, int z) { final TileEntity tileEntity = world.getTileEntity(x, y, z); - if (!(tileEntity instanceof MultiBlockPart)) return false; + if (!(tileEntity instanceof MultiBlockPart part)) return false; - final MultiBlockPart part = (MultiBlockPart) tileEntity; if (registryID != part.getMultiTileEntityRegistryID() || meta != part.getMultiTileEntityID()) return false; @@ -974,7 +973,7 @@ public abstract class MultiBlockController> ex if (tInv == null) return false; final int tSlot = tInv.getRight(); - final IItemHandlerModifiable inv = tInv.getLeft();; + final IItemHandlerModifiable inv = tInv.getLeft(); return inv.getStackInSlot(tSlot) == null || GT_Utility.areStacksEqual(aStack, inv.getStackInSlot(tSlot)); // && // allowPutStack(getBaseMetaTileEntity(), @@ -1441,7 +1440,7 @@ public abstract class MultiBlockController> ex buttons.setSize(16, 167) .setPos(7, 86); buttons.addChild(createPowerSwitchButton()) - .addChild(new FakeSyncWidget.BooleanSyncer(() -> isAllowedToWork(), val -> { + .addChild(new FakeSyncWidget.BooleanSyncer(this::isAllowedToWork, val -> { if (val) enableWorking(); else disableWorking(); })) diff --git a/src/main/java/gregtech/api/multitileentity/multiblock/base/MultiBlockPart.java b/src/main/java/gregtech/api/multitileentity/multiblock/base/MultiBlockPart.java index 0ea8cd77c8..953fc42f56 100644 --- a/src/main/java/gregtech/api/multitileentity/multiblock/base/MultiBlockPart.java +++ b/src/main/java/gregtech/api/multitileentity/multiblock/base/MultiBlockPart.java @@ -674,18 +674,16 @@ public abstract class MultiBlockPart extends NonTickableMultiTileEntity DropDownWidget dropDown = new DropDownWidget(); dropDown.addDropDownItemsSimple( controller.getInventoryNames(this), - (buttonWidget, index, label, setSelected) -> { - buttonWidget.setOnClick((clickData, widget) -> { - if (getNameOfInventoryFromIndex(controller, index).equals("all")) { - mLockedInventory = GT_Values.E; - mLockedInventoryIndex = 0; - } else { - mLockedInventory = getNameOfInventoryFromIndex(controller, index); - mLockedInventoryIndex = index; - } - setSelected.run(); - }); - }, + (buttonWidget, index, label, setSelected) -> buttonWidget.setOnClick((clickData, widget) -> { + if (getNameOfInventoryFromIndex(controller, index).equals("all")) { + mLockedInventory = GT_Values.E; + mLockedInventoryIndex = 0; + } else { + mLockedInventory = getNameOfInventoryFromIndex(controller, index); + mLockedInventoryIndex = index; + } + setSelected.run(); + }), true); builder.widget( dropDown.setSelected(mLockedInventoryIndex) -- cgit