diff --git a/core/src/main/java/mrtjp/projectred/core/BundledSignalsLib.java b/core/src/main/java/mrtjp/projectred/core/BundledSignalsLib.java index 66868f083..0614e46cd 100644 --- a/core/src/main/java/mrtjp/projectred/core/BundledSignalsLib.java +++ b/core/src/main/java/mrtjp/projectred/core/BundledSignalsLib.java @@ -40,8 +40,7 @@ public static void registerBundledTileInteraction(IBundledTileInteraction intera return ((IBundledTile) tile).getBundledSignal(side ^ 1); } - if (tile instanceof TileMultipart) { - TileMultipart tmp = (TileMultipart) tile; + if (tile instanceof TileMultipart tmp) { byte[] signal = null; // Source signal from all 4 perpendicular faces diff --git a/core/src/main/java/mrtjp/projectred/core/part/IPropagationCenterPart.java b/core/src/main/java/mrtjp/projectred/core/part/IPropagationCenterPart.java index af689910d..279de134f 100644 --- a/core/src/main/java/mrtjp/projectred/core/part/IPropagationCenterPart.java +++ b/core/src/main/java/mrtjp/projectred/core/part/IPropagationCenterPart.java @@ -40,8 +40,7 @@ default void propagateBackward(@Nullable IPropagationPart prev, int mode) { default boolean propagateTo(@Nullable IConnectable to, @Nullable IPropagationPart prev, int mode) { if (to != null) { if (to == prev) return false; - if (to instanceof IPropagationPart) { - IPropagationPart part = (IPropagationPart) to; + if (to instanceof IPropagationPart part) { if (shouldPropagate(part, mode)) { RedstonePropagator.propagateTo(part, this, mode); return true; diff --git a/core/src/main/java/mrtjp/projectred/core/part/IPropagationFacePart.java b/core/src/main/java/mrtjp/projectred/core/part/IPropagationFacePart.java index 6cb48d651..d4ee5bfa9 100644 --- a/core/src/main/java/mrtjp/projectred/core/part/IPropagationFacePart.java +++ b/core/src/main/java/mrtjp/projectred/core/part/IPropagationFacePart.java @@ -54,8 +54,7 @@ default int getPropagationMask() { default boolean propagateTo(@Nullable IConnectable to, @Nullable IPropagationPart prev, int mode) { if (to != null) { if (to == prev) return false; - if (to instanceof IPropagationPart) { - IPropagationPart part = (IPropagationPart) to; + if (to instanceof IPropagationPart part) { if (shouldPropagate(part, mode)) { RedstonePropagator.propagateTo(part, this, mode); return true; diff --git a/core/src/main/java/mrtjp/projectred/core/tile/IConnectableTile.java b/core/src/main/java/mrtjp/projectred/core/tile/IConnectableTile.java index 8b7badd0b..2133303a7 100644 --- a/core/src/main/java/mrtjp/projectred/core/tile/IConnectableTile.java +++ b/core/src/main/java/mrtjp/projectred/core/tile/IConnectableTile.java @@ -179,8 +179,7 @@ default boolean outsideCornerEdgeOpen(int s, int edgeRot) { default boolean discoverStraightCenter(int s) { MultiPart p = getStraightCenter(s); - if (p instanceof IConnectable) { - IConnectable connectable = (IConnectable) p; + if (p instanceof IConnectable connectable) { return canConnectPart(connectable, s, -1) && connectable.connectStraight(this, s ^ 1, -1); } @@ -189,8 +188,7 @@ default boolean discoverStraightCenter(int s) { default boolean discoverStraight(int s, int edgeRot) { MultiPart p = getStraight(s, edgeRot); - if (p instanceof IConnectable) { - IConnectable connectable = (IConnectable) p; + if (p instanceof IConnectable connectable) { return canConnectPart(connectable, s, edgeRot) && connectable.connectStraight(this, rotFromStraight(s, edgeRot), -1); } @@ -199,8 +197,7 @@ default boolean discoverStraight(int s, int edgeRot) { default boolean discoverCorner(int s, int edgeRot) { MultiPart p = getCorner(s, edgeRot); - if (p instanceof IConnectable) { - IConnectable connectable = (IConnectable) p; + if (p instanceof IConnectable connectable) { return canConnectPart(connectable, s, edgeRot) && outsideCornerEdgeOpen(s, edgeRot) && connectable.canConnectCorner(rotFromCorner(s, edgeRot)) && //TODO shouldnt this be handled by next line? @@ -214,8 +211,7 @@ default boolean discoverCorner(int s, int edgeRot) { default boolean discoverStraightCenterOverride(int s) { BlockPos pos = posOfStraight(s); BlockEntity tile = getBlockLevel().getBlockEntity(pos); - if (tile instanceof IConnectable) { - IConnectable connectable = (IConnectable) tile; + if (tile instanceof IConnectable connectable) { return canConnectPart(connectable, s, -1) && connectable.connectStraight(this, s, -1); } diff --git a/core/src/main/java/mrtjp/projectred/lib/Point.java b/core/src/main/java/mrtjp/projectred/lib/Point.java index 4527f04eb..de0c98dec 100644 --- a/core/src/main/java/mrtjp/projectred/lib/Point.java +++ b/core/src/main/java/mrtjp/projectred/lib/Point.java @@ -94,8 +94,7 @@ public Point offset(int r, int amount) { @Override public boolean equals(Object obj) { - if (obj instanceof Point) { - Point p = (Point) obj; + if (obj instanceof Point p) { return x == p.x && y == p.y; } return false; diff --git a/core/src/main/java/mrtjp/projectred/lib/Size.java b/core/src/main/java/mrtjp/projectred/lib/Size.java index e6cc2f223..6a1bcb86f 100644 --- a/core/src/main/java/mrtjp/projectred/lib/Size.java +++ b/core/src/main/java/mrtjp/projectred/lib/Size.java @@ -51,8 +51,7 @@ public Vec2 toVec2() { @Override public boolean equals(Object obj) { - if (obj instanceof Size) { - Size size = (Size) obj; + if (obj instanceof Size size) { return size.width == width && size.height == height; } return false; diff --git a/core/src/main/java/mrtjp/projectred/lib/Vec2.java b/core/src/main/java/mrtjp/projectred/lib/Vec2.java index 5c6bca993..057c79adb 100644 --- a/core/src/main/java/mrtjp/projectred/lib/Vec2.java +++ b/core/src/main/java/mrtjp/projectred/lib/Vec2.java @@ -108,8 +108,7 @@ public Vec2 axialProject() { @Override public boolean equals(Object obj) { - if (obj instanceof Vec2) { - Vec2 other = (Vec2) obj; + if (obj instanceof Vec2 other) { return dx == other.dx && dy == other.dy; } return false; diff --git a/core/src/test/java/mrtjp/projectred/lib/ModelVoxelShapeTest.java b/core/src/test/java/mrtjp/projectred/lib/ModelVoxelShapeTest.java index d74cb0602..1718ce03a 100644 --- a/core/src/test/java/mrtjp/projectred/lib/ModelVoxelShapeTest.java +++ b/core/src/test/java/mrtjp/projectred/lib/ModelVoxelShapeTest.java @@ -83,7 +83,7 @@ public static void assertEqualsT(@Nullable Vector3 a, @Nullable Vector3 b) { assertTrue(a.equalsT(b)); } - public List createTestCases() { + private List createTestCases() { List testCases = new LinkedList<>(); // Simple half-quad on the XZ plane with normal facing up diff --git a/expansion/src/main/java/mrtjp/projectred/expansion/block/BatteryBoxBlock.java b/expansion/src/main/java/mrtjp/projectred/expansion/block/BatteryBoxBlock.java index 60a95f4a0..e8e341caa 100644 --- a/expansion/src/main/java/mrtjp/projectred/expansion/block/BatteryBoxBlock.java +++ b/expansion/src/main/java/mrtjp/projectred/expansion/block/BatteryBoxBlock.java @@ -63,8 +63,7 @@ protected void createBlockStateDefinition(StateDefinition.Builder getDrops(BlockState state, LootContext.Builder builder) { BlockEntity tile = builder.getParameter(LootContextParams.BLOCK_ENTITY); - if (tile instanceof BatteryBoxTile) { - BatteryBoxTile batteryBoxTile = (BatteryBoxTile) tile; + if (tile instanceof BatteryBoxTile batteryBoxTile) { return Collections.singletonList(batteryBoxTile.createStackWithStoredPower()); // Retain power inside itemstack } return super.getDrops(state, builder); diff --git a/expansion/src/main/java/mrtjp/projectred/expansion/tile/BaseDeviceTile.java b/expansion/src/main/java/mrtjp/projectred/expansion/tile/BaseDeviceTile.java index b19de9756..02db25604 100644 --- a/expansion/src/main/java/mrtjp/projectred/expansion/tile/BaseDeviceTile.java +++ b/expansion/src/main/java/mrtjp/projectred/expansion/tile/BaseDeviceTile.java @@ -120,8 +120,7 @@ public InteractionResult onBlockActivated(Player player, InteractionHand hand, B ItemStack held = player.getItemInHand(hand); // Try to rotate block - if (held.getItem() instanceof IScrewdriver) { - IScrewdriver screwdriver = (IScrewdriver) held.getItem(); + if (held.getItem() instanceof IScrewdriver screwdriver) { if (screwdriver.canUse(player, held)) { if (!level.isClientSide) { side = (side + 1) % 6; diff --git a/expansion/src/main/java/mrtjp/projectred/expansion/tile/BaseMachineTile.java b/expansion/src/main/java/mrtjp/projectred/expansion/tile/BaseMachineTile.java index b5dd1cc11..ccbb5a74d 100644 --- a/expansion/src/main/java/mrtjp/projectred/expansion/tile/BaseMachineTile.java +++ b/expansion/src/main/java/mrtjp/projectred/expansion/tile/BaseMachineTile.java @@ -102,8 +102,7 @@ public InteractionResult onBlockActivated(Player player, InteractionHand hand, B ItemStack held = player.getItemInHand(hand); // Try to rotate block - if (held.getItem() instanceof IScrewdriver) { - IScrewdriver screwdriver = (IScrewdriver) held.getItem(); + if (held.getItem() instanceof IScrewdriver screwdriver) { if (screwdriver.canUse(player, held)) { if (!level.isClientSide) { diff --git a/fabrication/src/main/java/mrtjp/projectred/fabrication/engine/IRotatableICTile.java b/fabrication/src/main/java/mrtjp/projectred/fabrication/engine/IRotatableICTile.java index 35a74aede..c3d97cc3c 100644 --- a/fabrication/src/main/java/mrtjp/projectred/fabrication/engine/IRotatableICTile.java +++ b/fabrication/src/main/java/mrtjp/projectred/fabrication/engine/IRotatableICTile.java @@ -24,23 +24,23 @@ default int toAbsoluteMask(int intMask) { //@formatter:off static int rotationToDir(int r) { - switch (r) { - case 0: return 3; - case 1: return 4; - case 2: return 2; - case 3: return 5; - default: return -1; - } + return switch (r) { + case 0 -> 3; + case 1 -> 4; + case 2 -> 2; + case 3 -> 5; + default -> -1; + }; } static int dirToRotation(int dir) { - switch (dir) { - case 2: return 2; - case 3: return 0; - case 4: return 1; - case 5: return 3; - default: return -1; - } + return switch (dir) { + case 2 -> 2; + case 3 -> 0; + case 4 -> 1; + case 5 -> 3; + default -> -1; + }; } //@formatter:on diff --git a/fabrication/src/main/java/mrtjp/projectred/fabrication/engine/gates/IOGateTile.java b/fabrication/src/main/java/mrtjp/projectred/fabrication/engine/gates/IOGateTile.java index be297d867..dc73911dc 100644 --- a/fabrication/src/main/java/mrtjp/projectred/fabrication/engine/gates/IOGateTile.java +++ b/fabrication/src/main/java/mrtjp/projectred/fabrication/engine/gates/IOGateTile.java @@ -70,11 +70,8 @@ public void readDesc(MCDataInput in) { @Override public void read(MCDataInput in, int key) { switch (key) { - case COLOUR_PACKET: - colour = in.readByte(); - break; - default: - super.read(in, key); + case COLOUR_PACKET -> colour = in.readByte(); + default -> super.read(in, key); } } diff --git a/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/ICEditorToolTab.java b/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/ICEditorToolTab.java index 0c9fec37d..f2a1aaf5b 100644 --- a/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/ICEditorToolTab.java +++ b/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/ICEditorToolTab.java @@ -141,7 +141,7 @@ public void buildTooltip(List tooltip) { }; } - interface ButtonController { + protected interface ButtonController { void getTooltip(List tooltip); void onClick(); boolean isSelected(); diff --git a/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/TabButtonNode.java b/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/TabButtonNode.java index 1812ecee2..007ea8f8f 100644 --- a/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/TabButtonNode.java +++ b/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/TabButtonNode.java @@ -128,7 +128,7 @@ public void onTabStateChanged(TabState prevState, TabState newState) { public abstract void buildTooltip(List tooltip); - enum TabState { + public enum TabState { ALL_CLOSED, // Unselected with no extension CLOSED, // Unselected with extension MINIMIZED, // Selected with no extension diff --git a/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/VerticalListNode.java b/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/VerticalListNode.java index 3ee60a5e0..20d49d3d5 100644 --- a/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/VerticalListNode.java +++ b/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/VerticalListNode.java @@ -192,29 +192,19 @@ private Rect getPaddedFrame() { } private int getXForAlignment(Font fontRenderer, Component text) { - switch (horizontalAlignment) { - case LEFT: - return getPaddedFrame().x(); - case CENTER: - return getPaddedFrame().midX() - fontRenderer.width(text) / 2; - case RIGHT: - return getPaddedFrame().maxX() - fontRenderer.width(text); - default: - return getPaddedFrame().x(); - } + return switch (horizontalAlignment) { + case LEFT -> getPaddedFrame().x(); + case CENTER -> getPaddedFrame().midX() - fontRenderer.width(text) / 2; + case RIGHT -> getPaddedFrame().maxX() - fontRenderer.width(text); + }; } private int getYForAlignment(Font fontRenderer) { - switch (verticalAlignment) { - case TOP: - return getPaddedFrame().y(); - case CENTER: - return getPaddedFrame().midY() - fontRenderer.lineHeight / 2; - case BOTTOM: - return getPaddedFrame().maxY() - fontRenderer.lineHeight; - default: - return getPaddedFrame().y(); - } + return switch (verticalAlignment) { + case TOP -> getPaddedFrame().y(); + case CENTER -> getPaddedFrame().midY() - fontRenderer.lineHeight / 2; + case BOTTOM -> getPaddedFrame().maxY() - fontRenderer.lineHeight; + }; } public enum HorizontalAlignment { diff --git a/fabrication/src/main/java/mrtjp/projectred/fabrication/tile/LithographyTableTile.java b/fabrication/src/main/java/mrtjp/projectred/fabrication/tile/LithographyTableTile.java index 4cbbb6dd3..21db539d0 100644 --- a/fabrication/src/main/java/mrtjp/projectred/fabrication/tile/LithographyTableTile.java +++ b/fabrication/src/main/java/mrtjp/projectred/fabrication/tile/LithographyTableTile.java @@ -37,14 +37,11 @@ public class LithographyTableTile extends FabricationMachineTile { @Override public boolean canPlaceItem(int slot, ItemStack stack) { - switch (slot) { - case 0: - return stack.getItem() instanceof PhotomaskSetItem; - case 1: - return stack.getItem() instanceof BaseSiliconWaferItem; - default: - return false; - } + return switch (slot) { + case 0 -> stack.getItem() instanceof PhotomaskSetItem; + case 1 -> stack.getItem() instanceof BaseSiliconWaferItem; + default -> false; + }; } @Override diff --git a/fabrication/src/main/java/mrtjp/projectred/fabrication/tile/PlottingTableTile.java b/fabrication/src/main/java/mrtjp/projectred/fabrication/tile/PlottingTableTile.java index fd784c108..55dcde9ff 100644 --- a/fabrication/src/main/java/mrtjp/projectred/fabrication/tile/PlottingTableTile.java +++ b/fabrication/src/main/java/mrtjp/projectred/fabrication/tile/PlottingTableTile.java @@ -35,14 +35,11 @@ public class PlottingTableTile extends FabricationMachineTile { @Override public boolean canPlaceItem(int slot, ItemStack stack) { - switch (slot) { - case 0: - return stack.getItem() instanceof ICBlueprintItem; - case 1: - return stack.getItem() instanceof BlankPhotomaskItem; - default: - return false; - } + return switch (slot) { + case 0 -> stack.getItem() instanceof ICBlueprintItem; + case 1 -> stack.getItem() instanceof BlankPhotomaskItem; + default -> false; + }; } @Override diff --git a/illumination/src/main/java/mrtjp/projectred/illumination/MultipartLightProperties.java b/illumination/src/main/java/mrtjp/projectred/illumination/MultipartLightProperties.java index 79f06762f..78fe27ade 100644 --- a/illumination/src/main/java/mrtjp/projectred/illumination/MultipartLightProperties.java +++ b/illumination/src/main/java/mrtjp/projectred/illumination/MultipartLightProperties.java @@ -105,9 +105,8 @@ public IItemRenderer getItemRenderer() { return new IItemRenderer() { @Override public void renderItem(ItemStack stack, ItemTransforms.TransformType transformType, PoseStack mStack, MultiBufferSource getter, int packedLight, int packedOverlay) { - if (!(stack.getItem() instanceof MultipartLightPartItem)) return; + if (!(stack.getItem() instanceof MultipartLightPartItem lightItem)) return; - MultipartLightPartItem lightItem = (MultipartLightPartItem) stack.getItem(); CCRenderState ccrs = CCRenderState.instance(); ccrs.reset(); ccrs.brightness = packedLight; diff --git a/illumination/src/main/java/mrtjp/projectred/illumination/client/IllumarLampItemRenderer.java b/illumination/src/main/java/mrtjp/projectred/illumination/client/IllumarLampItemRenderer.java index 927fbd975..240474c16 100644 --- a/illumination/src/main/java/mrtjp/projectred/illumination/client/IllumarLampItemRenderer.java +++ b/illumination/src/main/java/mrtjp/projectred/illumination/client/IllumarLampItemRenderer.java @@ -37,12 +37,10 @@ public IllumarLampItemRenderer(BakedModel wrapped) { @Override public void renderItem(ItemStack stack, ItemTransforms.TransformType transformType, PoseStack mStack, MultiBufferSource getter, int packedLight, int packedOverlay) { Item item = stack.getItem(); - if (!(item instanceof BlockItem)) return; + if (!(item instanceof BlockItem blockItem)) return; - BlockItem blockItem = (BlockItem) item; - if (!(blockItem.getBlock() instanceof IllumarLampBlock)) return; + if (!(blockItem.getBlock() instanceof IllumarLampBlock block)) return; - IllumarLampBlock block = (IllumarLampBlock) blockItem.getBlock(); if (!block.isInverted()) { // Non-inverted blocks can use default Minecraft BlockItem model. Shouldn't happen // because this renderer should only be registered to inverted variants. diff --git a/integration/src/main/java/mrtjp/projectred/integration/IntegrationNetwork.java b/integration/src/main/java/mrtjp/projectred/integration/IntegrationNetwork.java index 569cf2128..a8ba5439d 100644 --- a/integration/src/main/java/mrtjp/projectred/integration/IntegrationNetwork.java +++ b/integration/src/main/java/mrtjp/projectred/integration/IntegrationNetwork.java @@ -107,16 +107,14 @@ public void handlePacket(PacketCustom packet, ServerPlayer sender, ServerGamePac private void handleIncrTimerMessage(Level world, PacketCustom packet) { MultiPart part = readPartIndex(world, packet); - if (part instanceof ComplexGatePart.ITimerGuiLogic) { - ComplexGatePart.ITimerGuiLogic gate = (ComplexGatePart.ITimerGuiLogic) part; + if (part instanceof ComplexGatePart.ITimerGuiLogic gate) { gate.setTimerMax(gate.getTimerMax() + packet.readShort()); } } private void handleIncrCounterMessage(Level world, PacketCustom packet) { MultiPart part = readPartIndex(world, packet); - if (part instanceof ComplexGatePart.ICounterGuiLogic) { - ComplexGatePart.ICounterGuiLogic gate = (ComplexGatePart.ICounterGuiLogic) part; + if (part instanceof ComplexGatePart.ICounterGuiLogic gate) { int actionId = packet.readByte(); switch (actionId) { case 0: diff --git a/integration/src/main/java/mrtjp/projectred/integration/client/GatePartItemRenderer.java b/integration/src/main/java/mrtjp/projectred/integration/client/GatePartItemRenderer.java index d423efb5e..a229bbd80 100644 --- a/integration/src/main/java/mrtjp/projectred/integration/client/GatePartItemRenderer.java +++ b/integration/src/main/java/mrtjp/projectred/integration/client/GatePartItemRenderer.java @@ -39,9 +39,7 @@ public ModelState getModelTransform() { @Override public void renderItem(ItemStack stack, ItemTransforms.TransformType transformType, PoseStack mStack, MultiBufferSource getter, int packedLight, int packedOverlay) { - if (!(stack.getItem() instanceof GatePartItem)) return; - - GatePartItem gateItem = (GatePartItem) stack.getItem(); + if (!(stack.getItem() instanceof GatePartItem gateItem)) return; CCRenderState ccrs = CCRenderState.instance(); ccrs.reset(); diff --git a/integration/src/main/java/mrtjp/projectred/integration/part/ArrayGatePart.java b/integration/src/main/java/mrtjp/projectred/integration/part/ArrayGatePart.java index 553deaed1..621f4389c 100644 --- a/integration/src/main/java/mrtjp/projectred/integration/part/ArrayGatePart.java +++ b/integration/src/main/java/mrtjp/projectred/integration/part/ArrayGatePart.java @@ -84,12 +84,10 @@ public void propagateOther(int mode) { } private int sideDiff(@Nullable IPropagationPart p) { - if (!(p instanceof MultiPart)) return 0xF; + if (!(p instanceof MultiPart part)) return 0xF; - if (!(p instanceof IOrientableFacePart)) return 0xF; + if (!(p instanceof IOrientableFacePart facePart)) return 0xF; - MultiPart part = (MultiPart) p; - IOrientableFacePart facePart = (IOrientableFacePart) p; BlockPos here = pos(); BlockPos there = part.pos(); @@ -165,8 +163,7 @@ protected int calcInsideSignal(int r) { protected int resolveSignal(FaceLookup lookup) { // Part signal resolution - if (lookup.part instanceof IRedwirePart) { - IRedwirePart redwirePart = (IRedwirePart) lookup.part; + if (lookup.part instanceof IRedwirePart redwirePart) { if (redwirePart.diminishOnSide(lookup.otherRotation)) { return redwirePart.getRedwireSignal(lookup.otherRotation) - 1; } @@ -177,8 +174,7 @@ protected int resolveSignal(FaceLookup lookup) { } // Shouldn't matter, no space for a face part inside - if (lookup.part instanceof FaceRedstonePart) { - FaceRedstonePart faceRsPart = (FaceRedstonePart) lookup.part; + if (lookup.part instanceof FaceRedstonePart faceRsPart) { int s = Rotation.rotateSide(lookup.otherSide, lookup.otherRotation); return Math.max(faceRsPart.strongPowerLevel(s), faceRsPart.weakPowerLevel(s)) * 17; } @@ -262,8 +258,7 @@ public void preparePlacement(@Nullable Player player, BlockPos pos, int side) { if (canCross() && player != null) { // Note: tile() is not available yet, must access from player.level MultiPart tpart = BlockMultipart.getPart(player.level, pos, getSide()^1); - if (tpart instanceof ArrayGatePart) { - ArrayGatePart part = (ArrayGatePart) tpart; + if (tpart instanceof ArrayGatePart part) { if (part.getGateType() == getGateType() && (part.getRotation() & 1) == (getRotation() & 1)) { setRotation((getRotation() + 1) % 4); } @@ -273,8 +268,7 @@ public void preparePlacement(@Nullable Player player, BlockPos pos, int side) { @Override public boolean occlusionTest(MultiPart npart) { - if (npart instanceof ArrayGatePart) { - ArrayGatePart part = (ArrayGatePart) npart; + if (npart instanceof ArrayGatePart part) { if (part.getGateType() == getGateType() && part.getSide() == (getSide() ^ 1) && (part.getRotation() & 1) != (getRotation() & 1)) { return true; } @@ -352,9 +346,7 @@ static int getConnsAtHeight(GatePart gate, double h) { static double getConnHeight(GatePart gate, int r) { IConnectable part = gate.getStraight(r); - if (part instanceof IGateWireRenderConnect && part instanceof GatePart) { - GatePart gPart = (GatePart) part; - IGateWireRenderConnect gConn = (IGateWireRenderConnect) part; + if (part instanceof IGateWireRenderConnect gConn && part instanceof GatePart gPart) { int ir = gPart.toInternal(gate.rotFromStraight(r)); if ((gConn.renderConnectMask() & 1 << ir) != 0) return gConn.getHeight(ir); } diff --git a/integration/src/main/java/mrtjp/projectred/integration/part/BundledGatePart.java b/integration/src/main/java/mrtjp/projectred/integration/part/BundledGatePart.java index ae5d1f344..36f117ffe 100644 --- a/integration/src/main/java/mrtjp/projectred/integration/part/BundledGatePart.java +++ b/integration/src/main/java/mrtjp/projectred/integration/part/BundledGatePart.java @@ -98,8 +98,7 @@ public BundledGatePart(GateType type) { public boolean discoverStraightOverride(int absDir) { BlockPos pos = pos().relative(Direction.values()[absDir]); BlockEntity tile = level().getBlockEntity(pos); - if (tile instanceof IMaskedBundledTile) { - IMaskedBundledTile b = (IMaskedBundledTile) tile; + if (tile instanceof IMaskedBundledTile b) { int r = Rotation.rotationTo(absDir, getSide()); return b.canConnectBundled(absDir ^ 1) && (b.getConnectionMask(absDir ^ 1) & 1 << r) != 0; } diff --git a/integration/src/main/java/mrtjp/projectred/integration/part/GatePart.java b/integration/src/main/java/mrtjp/projectred/integration/part/GatePart.java index eab33954b..620fde507 100644 --- a/integration/src/main/java/mrtjp/projectred/integration/part/GatePart.java +++ b/integration/src/main/java/mrtjp/projectred/integration/part/GatePart.java @@ -419,8 +419,7 @@ public int getSlotMask() { public InteractionResult activate(Player player, PartRayTraceResult hit, ItemStack held, InteractionHand hand) { if (gateLogicActivate(player, held, hit)) return InteractionResult.SUCCESS; - if (!held.isEmpty() && held.getItem() instanceof IScrewdriver) { - IScrewdriver screwdriver = (IScrewdriver) held.getItem(); + if (!held.isEmpty() && held.getItem() instanceof IScrewdriver screwdriver) { if (!level().isClientSide) { if (player.isCrouching()) { configure(); diff --git a/transmission/src/main/java/mrtjp/projectred/transmission/client/FramedWireHighlightRenderer.java b/transmission/src/main/java/mrtjp/projectred/transmission/client/FramedWireHighlightRenderer.java index 19b7f8529..b324302cd 100644 --- a/transmission/src/main/java/mrtjp/projectred/transmission/client/FramedWireHighlightRenderer.java +++ b/transmission/src/main/java/mrtjp/projectred/transmission/client/FramedWireHighlightRenderer.java @@ -30,14 +30,12 @@ public boolean renderHighlight(Player player, InteractionHand hand, BlockHitResu return false; } - if (!(hit instanceof PartRayTraceResult)) return false; - PartRayTraceResult partHit = (PartRayTraceResult) hit; + if (!(hit instanceof PartRayTraceResult partHit)) return false; TileMultipart tile = BlockMultipart.getTile(player.level, hit.getBlockPos()); if (tile == null) return false; - if (partHit.part instanceof BaseCenterWirePart) { - BaseCenterWirePart wire = (BaseCenterWirePart) partHit.part; + if (partHit.part instanceof BaseCenterWirePart wire) { if (wire.getMaterial() == null || wire.getMaterial() != material) { FramedWireModelRenderer.renderCoverHighlight(wire, material, CCRenderState.instance(), mStack, getter); return true; diff --git a/transmission/src/main/java/mrtjp/projectred/transmission/client/WireModelBuilder.java b/transmission/src/main/java/mrtjp/projectred/transmission/client/WireModelBuilder.java index fa5069f4d..9d3d6b21f 100644 --- a/transmission/src/main/java/mrtjp/projectred/transmission/client/WireModelBuilder.java +++ b/transmission/src/main/java/mrtjp/projectred/transmission/client/WireModelBuilder.java @@ -90,17 +90,11 @@ private int countNumberOfFaces() { private void generateCenter() { - int tex; //0 = straight n/s, 1 = straight e/w, 2 = circle - switch (connCount) { - case 0: - tex = 1; - break; - case 1: - tex = (connMask & 5) != 0 ? 0 : 1; - break; - default: - tex = connMask == 5 ? 0 : connMask == 10 ? 1 : 2; - } + int tex = switch (connCount) { + case 0 -> 1; + case 1 -> (connMask & 5) != 0 ? 0 : 1; + default -> connMask == 5 ? 0 : connMask == 10 ? 1 : 2; + }; //0 = straight n/s, 1 = straight e/w, 2 = circle Vertex5[] verts = new Vertex5[] { new Vertex5(0.5 - w, h, 0.5 + w, 8 - tw, 16 + tw), @@ -253,16 +247,12 @@ private Vertex5[] generateInternal(int r) { } private Vertex5[] generateSideFromType(int stype, int r) { - switch (stype) { - case 0x00: - return generateFlat(r); - case 0x01: - return generateCorner(r); - case 0x10: - return generateStraight(r); - default: - return generateInternal(r); - } + return switch (stype) { + case 0x00 -> generateFlat(r); + case 0x01 -> generateCorner(r); + case 0x10 -> generateStraight(r); + default -> generateInternal(r); + }; } //region Utils diff --git a/transmission/src/main/java/mrtjp/projectred/transmission/part/BaseFaceWirePart.java b/transmission/src/main/java/mrtjp/projectred/transmission/part/BaseFaceWirePart.java index c83b7af8f..432d9ceb3 100644 --- a/transmission/src/main/java/mrtjp/projectred/transmission/part/BaseFaceWirePart.java +++ b/transmission/src/main/java/mrtjp/projectred/transmission/part/BaseFaceWirePart.java @@ -242,8 +242,7 @@ public boolean canConnectCorner(int r) { @Override public boolean setRenderFlag(IConnectable part) { - if (part instanceof BaseFaceWirePart) { - BaseFaceWirePart wire = (BaseFaceWirePart) part; + if (part instanceof BaseFaceWirePart wire) { // For wires of same thickness, use side for tie-breaker as it // is guaranteed to be unique for a corner connected wire if (wire.getWireType().getThickness() == getWireType().getThickness()) { diff --git a/transmission/src/main/java/mrtjp/projectred/transmission/part/BundledCablePart.java b/transmission/src/main/java/mrtjp/projectred/transmission/part/BundledCablePart.java index c2f3100b8..60c0108fe 100644 --- a/transmission/src/main/java/mrtjp/projectred/transmission/part/BundledCablePart.java +++ b/transmission/src/main/java/mrtjp/projectred/transmission/part/BundledCablePart.java @@ -133,8 +133,7 @@ public boolean canConnectPart(IConnectable part, int dir) { public boolean discoverStraightOverride(int absDir) { BlockPos pos = pos().relative(Direction.values()[absDir]); BlockEntity tile = level().getBlockEntity(pos); - if (tile instanceof IMaskedBundledTile) { - IMaskedBundledTile b = (IMaskedBundledTile) tile; + if (tile instanceof IMaskedBundledTile b) { int r = Rotation.rotationTo(absDir, getSide()); return b.canConnectBundled(absDir^1) && (b.getConnectionMask(absDir^1) & 1<< r) != 0; } @@ -218,8 +217,7 @@ protected void resolveSignal(FaceLookup lookup) { tmpSignal[i] = (byte) Math.max(tmpSignal[i] & 0xFF, (signalIn[i] & 0xFF) - 1); } - } else if (lookup.part instanceof IInsulatedRedwirePart) { - IInsulatedRedwirePart insulatedWire = (IInsulatedRedwirePart) lookup.part; + } else if (lookup.part instanceof IInsulatedRedwirePart insulatedWire) { int c = insulatedWire.getInsulatedColour(); int signalIn = insulatedWire.getRedwireSignal(lookup.otherRotation); tmpSignal[c] = (byte) Math.max(tmpSignal[c] & 0xFF, signalIn - 1); diff --git a/transmission/src/main/java/mrtjp/projectred/transmission/part/FramedBundledCablePart.java b/transmission/src/main/java/mrtjp/projectred/transmission/part/FramedBundledCablePart.java index 938256c20..9ebb27ba1 100644 --- a/transmission/src/main/java/mrtjp/projectred/transmission/part/FramedBundledCablePart.java +++ b/transmission/src/main/java/mrtjp/projectred/transmission/part/FramedBundledCablePart.java @@ -129,8 +129,7 @@ public boolean canConnectPart(IConnectable part, int dir) { public boolean discoverStraightOverride(int absDir) { BlockPos pos = pos().relative(Direction.values()[absDir]); BlockEntity tile = level().getBlockEntity(pos); - if (tile instanceof IMaskedBundledTile) { - IMaskedBundledTile b = (IMaskedBundledTile) tile; + if (tile instanceof IMaskedBundledTile b) { return b.canConnectBundled(absDir^1) && (b.getConnectionMask(absDir^1) & 0x10) != 0; } @@ -198,8 +197,7 @@ protected void resolveSignal(CenterLookup lookup) { tmpSignal[i] = (byte) Math.max(tmpSignal[i] & 0xFF, (signalIn[i] & 0xFF) - 1); } - } else if (lookup.part instanceof IInsulatedRedwirePart) { - IInsulatedRedwirePart insulatedWire = (IInsulatedRedwirePart) lookup.part; + } else if (lookup.part instanceof IInsulatedRedwirePart insulatedWire) { int c = insulatedWire.getInsulatedColour(); int signalIn = insulatedWire.getRedwireSignal(lookup.otherDirection); tmpSignal[c] = (byte) Math.max(tmpSignal[c] & 0xFF, signalIn - 1); diff --git a/transmission/src/main/java/mrtjp/projectred/transmission/part/FramedInsulatedRedAlloyWirePart.java b/transmission/src/main/java/mrtjp/projectred/transmission/part/FramedInsulatedRedAlloyWirePart.java index 7b21dbe1e..423c4b3b9 100644 --- a/transmission/src/main/java/mrtjp/projectred/transmission/part/FramedInsulatedRedAlloyWirePart.java +++ b/transmission/src/main/java/mrtjp/projectred/transmission/part/FramedInsulatedRedAlloyWirePart.java @@ -24,8 +24,7 @@ public TextureAtlasSprite getIcon() { //region FramedRedwirePart overrides @Override protected int resolveSignal(CenterLookup lookup) { - if (lookup.part instanceof IBundledCablePart) { - IBundledCablePart bundledPart = (IBundledCablePart) lookup.part; + if (lookup.part instanceof IBundledCablePart bundledPart) { return (bundledPart.getBundledSignal()[getInsulatedColour()] & 0xFF) - 1; } return super.resolveSignal(lookup); diff --git a/transmission/src/main/java/mrtjp/projectred/transmission/part/FramedRedwirePart.java b/transmission/src/main/java/mrtjp/projectred/transmission/part/FramedRedwirePart.java index adac9f21f..b3a314d87 100644 --- a/transmission/src/main/java/mrtjp/projectred/transmission/part/FramedRedwirePart.java +++ b/transmission/src/main/java/mrtjp/projectred/transmission/part/FramedRedwirePart.java @@ -233,8 +233,7 @@ protected int calculateInternalSignal(int s) { return signal; } - if (lookup.part instanceof RedstonePart) { - RedstonePart rw = (RedstonePart) lookup.part; + if (lookup.part instanceof RedstonePart rw) { return Math.max(rw.strongPowerLevel(lookup.otherDirection), rw.weakPowerLevel(lookup.otherDirection)); } @@ -242,8 +241,7 @@ protected int calculateInternalSignal(int s) { } protected int resolveSignal(CenterLookup lookup) { - if (lookup.part instanceof IRedwirePart) { - IRedwirePart rw = (IRedwirePart) lookup.part; + if (lookup.part instanceof IRedwirePart rw) { int signal = rw.getRedwireSignal(lookup.otherDirection); if (rw.diminishOnSide(lookup.otherDirection)) { diff --git a/transmission/src/main/java/mrtjp/projectred/transmission/part/InsulatedRedAlloyWirePart.java b/transmission/src/main/java/mrtjp/projectred/transmission/part/InsulatedRedAlloyWirePart.java index f40b54bea..f5e1c1918 100644 --- a/transmission/src/main/java/mrtjp/projectred/transmission/part/InsulatedRedAlloyWirePart.java +++ b/transmission/src/main/java/mrtjp/projectred/transmission/part/InsulatedRedAlloyWirePart.java @@ -24,8 +24,7 @@ protected boolean powerUnderside() { @Override protected int resolveSignal(FaceLookup lookup) { - if (lookup.part instanceof IBundledCablePart) { - IBundledCablePart bundledPart = (IBundledCablePart) lookup.part; + if (lookup.part instanceof IBundledCablePart bundledPart) { return (bundledPart.getBundledSignal()[getInsulatedColour()] & 0xFF) - 1; } return super.resolveSignal(lookup); diff --git a/transmission/src/main/java/mrtjp/projectred/transmission/part/RedwirePart.java b/transmission/src/main/java/mrtjp/projectred/transmission/part/RedwirePart.java index b96c49914..c4aebfb75 100644 --- a/transmission/src/main/java/mrtjp/projectred/transmission/part/RedwirePart.java +++ b/transmission/src/main/java/mrtjp/projectred/transmission/part/RedwirePart.java @@ -267,8 +267,7 @@ protected int calcCenterSignal() { protected int resolveSignal(FaceLookup lookup) { // Part signal resolution - if (lookup.part instanceof IRedwirePart) { - IRedwirePart redwirePart = (IRedwirePart) lookup.part; + if (lookup.part instanceof IRedwirePart redwirePart) { if (redwirePart.diminishOnSide(lookup.otherRotation)) { return redwirePart.getRedwireSignal(lookup.otherRotation) - 1; } @@ -278,8 +277,7 @@ protected int resolveSignal(FaceLookup lookup) { return ((IRedwireEmitter) lookup.part).getRedwireSignal(lookup.otherRotation); } - if (lookup.part instanceof FaceRedstonePart) { - FaceRedstonePart faceRsPart = (FaceRedstonePart) lookup.part; + if (lookup.part instanceof FaceRedstonePart faceRsPart) { int s = Rotation.rotateSide(lookup.otherSide, lookup.otherRotation); return Math.max(faceRsPart.strongPowerLevel(s), faceRsPart.weakPowerLevel(s)) * 17; }