Skip to content

Commit 316908b

Browse files
committed
code cleanup
1 parent eaec528 commit 316908b

File tree

76 files changed

+673
-604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+673
-604
lines changed

src/main/java/com/falsepattern/lib/DeprecationDetails.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
@Retention(RetentionPolicy.RUNTIME)
1313
@StableAPI(since = "0.10.0")
1414
public @interface DeprecationDetails {
15-
@StableAPI(since = "0.10.0")
16-
String stableSince() default "";
17-
@StableAPI(since = "0.10.0")
18-
String deprecatedSince();
15+
@StableAPI(since = "0.10.0") String stableSince() default "";
16+
17+
@StableAPI(since = "0.10.0") String deprecatedSince();
1918
}

src/main/java/com/falsepattern/lib/StableAPI.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (C) 2022 FalsePattern
33
* All Rights Reserved
44
*
@@ -43,6 +43,5 @@
4343
/**
4444
* The version this API was introduced/stabilized in. Used for library version tracking.
4545
*/
46-
@StableAPI(since = "0.6.0")
47-
String since();
46+
@StableAPI(since = "0.6.0") String since();
4847
}

src/main/java/com/falsepattern/lib/asm/ASMUtil.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (C) 2022 FalsePattern
33
* All Rights Reserved
44
*
@@ -32,15 +32,12 @@
3232
import com.falsepattern.lib.mapping.types.UniversalMethod;
3333
import lombok.SneakyThrows;
3434
import lombok.val;
35-
import org.apache.logging.log4j.Logger;
3635
import org.objectweb.asm.ClassReader;
37-
import org.objectweb.asm.ClassVisitor;
3836
import org.objectweb.asm.ClassWriter;
3937
import org.objectweb.asm.Opcodes;
4038
import org.objectweb.asm.tree.ClassNode;
4139
import org.objectweb.asm.tree.FieldNode;
4240
import org.objectweb.asm.tree.MethodNode;
43-
import org.objectweb.asm.util.CheckClassAdapter;
4441

4542
import java.util.Arrays;
4643
import java.util.Objects;
@@ -65,17 +62,15 @@ public static FieldNode findFieldFromMCP(ClassNode cn, String fieldName, boolean
6562
throw new AsmClassNotFoundException("The class " + cn + " is not from Minecraft, or the mapping manager" +
6663
"doesn't have it, cannot use findFieldFromMCP! Use findFieldStandard instead!");
6764
}
68-
return findFieldStandard(cn,
69-
MappingManager.classForName(NameType.Internal, classMapping, cn.name)
70-
.getField(MappingType.MCP, fieldName)
71-
.getName(classMapping),
72-
optional);
65+
return findFieldStandard(cn, MappingManager.classForName(NameType.Internal, classMapping, cn.name)
66+
.getField(MappingType.MCP, fieldName)
67+
.getName(classMapping), optional);
7368
}
7469

7570
public static FieldNode findFieldFromUniversal(ClassNode cn, UniversalField field, boolean optional) {
76-
String[] possibilities = CoreLoadingPlugin.isObfuscated() ?
77-
new String[]{field.getName(MappingType.SRG), field.getName(MappingType.Notch)} :
78-
new String[] {field.getName(MappingType.MCP)};
71+
String[] possibilities = CoreLoadingPlugin.isObfuscated() ? new String[]{field.getName(MappingType.SRG),
72+
field.getName(MappingType.Notch)}
73+
: new String[]{field.getName(MappingType.MCP)};
7974
for (final FieldNode ret : cn.fields) {
8075
if (anyEquals(ret.name, possibilities)) {
8176
return ret;
@@ -84,7 +79,8 @@ public static FieldNode findFieldFromUniversal(ClassNode cn, UniversalField fiel
8479
if (optional) {
8580
return null;
8681
}
87-
throw new AsmFieldNotFoundException(possibilities.length == 1 ? possibilities[0] : Arrays.toString(possibilities));
82+
throw new AsmFieldNotFoundException(
83+
possibilities.length == 1 ? possibilities[0] : Arrays.toString(possibilities));
8884
}
8985

9086
public static MethodNode findMethodStandard(ClassNode cn, String name, String descriptor, boolean optional) {
@@ -112,12 +108,13 @@ public static MethodNode findMethodFromMCP(ClassNode cn, String mcpName, String
112108
}
113109

114110
public static MethodNode findMethodFromUniversal(ClassNode cn, UniversalMethod method, boolean optional) {
115-
String[] possibleNames = CoreLoadingPlugin.isObfuscated() ?
116-
new String[]{method.getName(MappingType.SRG), method.getName(MappingType.Notch)} :
117-
new String[] {method.getName(MappingType.MCP)};
118-
String[] possibleDescriptors = CoreLoadingPlugin.isObfuscated() ?
119-
new String[]{method.getDescriptor(MappingType.SRG), method.getDescriptor(MappingType.Notch)} :
120-
new String[] {method.getDescriptor(MappingType.MCP)};
111+
String[] possibleNames = CoreLoadingPlugin.isObfuscated() ? new String[]{method.getName(MappingType.SRG),
112+
method.getName(MappingType.Notch)}
113+
: new String[]{method.getName(MappingType.MCP)};
114+
String[] possibleDescriptors =
115+
CoreLoadingPlugin.isObfuscated() ? new String[]{method.getDescriptor(MappingType.SRG),
116+
method.getDescriptor(MappingType.Notch)}
117+
: new String[]{method.getDescriptor(MappingType.MCP)};
121118
for (final MethodNode ret : cn.methods) {
122119
if (anyEquals(ret.name, possibleNames) && anyEquals(ret.desc, possibleDescriptors)) {
123120
return ret;
@@ -126,7 +123,8 @@ public static MethodNode findMethodFromUniversal(ClassNode cn, UniversalMethod m
126123
if (optional) {
127124
return null;
128125
}
129-
throw new AsmFieldNotFoundException(possibleDescriptors.length == 1 ? possibleDescriptors[0] : Arrays.toString(possibleDescriptors));
126+
throw new AsmFieldNotFoundException(
127+
possibleDescriptors.length == 1 ? possibleDescriptors[0] : Arrays.toString(possibleDescriptors));
130128
}
131129

132130
public static MappingType discoverClassMappingType(ClassNode cn) {
@@ -175,7 +173,7 @@ public static byte[] serializeClass(ClassNode cn, int writerFlags) {
175173
}
176174

177175
public static boolean anyEquals(String str, String... options) {
178-
for (val option: options) {
176+
for (val option : options) {
179177
if (Objects.equals(str, option)) {
180178
return true;
181179
}

src/main/java/com/falsepattern/lib/asm/IClassNodeTransformer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (C) 2022 FalsePattern
33
* All Rights Reserved
44
*
@@ -24,7 +24,9 @@
2424

2525
public interface IClassNodeTransformer {
2626
String getName();
27+
2728
boolean shouldTransform(ClassNode cn, String transformedName, boolean obfuscated);
29+
2830
default int internalSortingOrder() {
2931
return 0;
3032
}

src/main/java/com/falsepattern/lib/asm/SmartTransformer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (C) 2022 FalsePattern
33
* All Rights Reserved
44
*
@@ -20,7 +20,6 @@
2020
*/
2121
package com.falsepattern.lib.asm;
2222

23-
import com.falsepattern.lib.asm.exceptions.AsmTransformException;
2423
import com.falsepattern.lib.internal.CoreLoadingPlugin;
2524
import lombok.val;
2625
import org.apache.logging.log4j.Logger;
@@ -38,15 +37,17 @@
3837
*/
3938
public interface SmartTransformer extends IClassTransformer {
4039
Logger logger();
40+
4141
List<IClassNodeTransformer> transformers();
42+
4243
@Override
4344
default byte[] transform(String name, String transformedName, byte[] bytes) {
4445
if (bytes == null) {
4546
return null;
4647
}
4748
val transformers = new ArrayList<IClassNodeTransformer>();
4849
val cn = ASMUtil.parseClass(bytes, ClassReader.EXPAND_FRAMES);
49-
for (val transformer: transformers()) {
50+
for (val transformer : transformers()) {
5051
if (transformer.shouldTransform(cn, transformedName, CoreLoadingPlugin.isObfuscated())) {
5152
transformers.add(transformer);
5253
}
@@ -56,7 +57,7 @@ default byte[] transform(String name, String transformedName, byte[] bytes) {
5657
}
5758
transformers.sort(Comparator.comparingInt(IClassNodeTransformer::internalSortingOrder));
5859
val log = logger();
59-
for (val transformer: transformers) {
60+
for (val transformer : transformers) {
6061
log.debug("Patching {} with {}...", transformedName, transformer.getName());
6162
try {
6263
transformer.transform(cn, transformedName, CoreLoadingPlugin.isObfuscated());

src/main/java/com/falsepattern/lib/asm/exceptions/AsmClassNotFoundException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (C) 2022 FalsePattern
33
* All Rights Reserved
44
*

src/main/java/com/falsepattern/lib/asm/exceptions/AsmFieldNotFoundException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (C) 2022 FalsePattern
33
* All Rights Reserved
44
*

src/main/java/com/falsepattern/lib/asm/exceptions/AsmMethodNotFoundException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (C) 2022 FalsePattern
33
* All Rights Reserved
44
*

src/main/java/com/falsepattern/lib/asm/exceptions/AsmTransformException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (C) 2022 FalsePattern
33
* All Rights Reserved
44
*

src/main/java/com/falsepattern/lib/compat/BlockPos.java

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (C) 2022 FalsePattern
33
* All Rights Reserved
44
*
@@ -23,20 +23,22 @@
2323
import com.falsepattern.lib.StableAPI;
2424
import com.falsepattern.lib.util.MathUtil;
2525
import com.google.common.collect.AbstractIterator;
26-
import cpw.mods.fml.relauncher.Side;
27-
import cpw.mods.fml.relauncher.SideOnly;
28-
import java.util.ArrayList;
29-
import java.util.List;
30-
import javax.annotation.concurrent.Immutable;
3126
import lombok.Getter;
3227
import lombok.NonNull;
3328
import lombok.Setter;
3429
import lombok.val;
30+
import org.apache.logging.log4j.LogManager;
31+
import org.apache.logging.log4j.Logger;
32+
3533
import net.minecraft.entity.Entity;
3634
import net.minecraft.util.EnumFacing;
3735
import net.minecraft.util.Vec3;
38-
import org.apache.logging.log4j.LogManager;
39-
import org.apache.logging.log4j.Logger;
36+
import cpw.mods.fml.relauncher.Side;
37+
import cpw.mods.fml.relauncher.SideOnly;
38+
39+
import javax.annotation.concurrent.Immutable;
40+
import java.util.ArrayList;
41+
import java.util.List;
4042

4143
import static net.minecraft.util.EnumFacing.DOWN;
4244
import static net.minecraft.util.EnumFacing.EAST;
@@ -105,12 +107,9 @@ public static BlockPos fromLong(long serialized) {
105107
* @see #getAllInBoxMutable(BlockPos, BlockPos)
106108
*/
107109
public static Iterable<BlockPos> getAllInBox(@NonNull BlockPos from, @NonNull BlockPos to) {
108-
return getAllInBox(Math.min(from.getX(), to.getX()),
109-
Math.min(from.getY(), to.getY()),
110-
Math.min(from.getZ(), to.getZ()),
111-
Math.max(from.getX(), to.getX()),
112-
Math.max(from.getY(), to.getY()),
113-
Math.max(from.getZ(), to.getZ()));
110+
return getAllInBox(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()),
111+
Math.min(from.getZ(), to.getZ()), Math.max(from.getX(), to.getX()),
112+
Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ()));
114113
}
115114

116115
/**
@@ -130,12 +129,7 @@ public static Iterable<BlockPos> getAllInBox(@NonNull BlockPos from, @NonNull Bl
130129
* @see #getAllInBox(BlockPos, BlockPos)
131130
* @see #getAllInBoxMutable(BlockPos, BlockPos)
132131
*/
133-
public static Iterable<BlockPos> getAllInBox(final int x0,
134-
final int y0,
135-
final int z0,
136-
final int x1,
137-
final int y1,
138-
final int z1) {
132+
public static Iterable<BlockPos> getAllInBox(final int x0, final int y0, final int z0, final int x1, final int y1, final int z1) {
139133
return () -> new AbstractIterator<BlockPos>() {
140134
private boolean first = true;
141135
private int lastX;
@@ -186,12 +180,9 @@ protected BlockPos computeNext() {
186180
* @see #getAllInBoxMutable(BlockPos, BlockPos)
187181
*/
188182
public static Iterable<BlockPos.MutableBlockPos> getAllInBoxMutable(@NonNull BlockPos from, @NonNull BlockPos to) {
189-
return getAllInBoxMutable(Math.min(from.getX(), to.getX()),
190-
Math.min(from.getY(), to.getY()),
191-
Math.min(from.getZ(), to.getZ()),
192-
Math.max(from.getX(), to.getX()),
193-
Math.max(from.getY(), to.getY()),
194-
Math.max(from.getZ(), to.getZ()));
183+
return getAllInBoxMutable(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()),
184+
Math.min(from.getZ(), to.getZ()), Math.max(from.getX(), to.getX()),
185+
Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ()));
195186
}
196187

197188
/**
@@ -214,12 +205,7 @@ public static Iterable<BlockPos.MutableBlockPos> getAllInBoxMutable(@NonNull Blo
214205
* @see #getAllInBox(int, int, int, int, int, int)
215206
* @see #getAllInBoxMutable(BlockPos, BlockPos)
216207
*/
217-
public static Iterable<BlockPos.MutableBlockPos> getAllInBoxMutable(final int x0,
218-
final int y0,
219-
final int z0,
220-
final int x1,
221-
final int y1,
222-
final int z1) {
208+
public static Iterable<BlockPos.MutableBlockPos> getAllInBoxMutable(final int x0, final int y0, final int z0, final int x1, final int y1, final int z1) {
223209
return () -> new AbstractIterator<MutableBlockPos>() {
224210
private MutableBlockPos pos;
225211

@@ -297,8 +283,7 @@ public BlockPos offset(@NonNull EnumFacing facing, int blocks) {
297283
if (blocks == 0) {
298284
return this;
299285
}
300-
return new BlockPos(x + facing.getFrontOffsetX() * blocks,
301-
y + facing.getFrontOffsetY() * blocks,
286+
return new BlockPos(x + facing.getFrontOffsetX() * blocks, y + facing.getFrontOffsetY() * blocks,
302287
z + facing.getFrontOffsetZ() * blocks);
303288
}
304289

@@ -362,8 +347,7 @@ public BlockPos rotate(@NonNull Rotation rotation) {
362347

363348
@Override
364349
public BlockPos crossProduct(@NonNull Vec3i vec) {
365-
return new BlockPos(y * vec.getZ() - z * vec.getY(),
366-
z * vec.getX() - x * vec.getZ(),
350+
return new BlockPos(y * vec.getZ() - z * vec.getY(), z * vec.getX() - x * vec.getZ(),
367351
x * vec.getY() - y * vec.getX());
368352
}
369353

@@ -451,8 +435,7 @@ public BlockPos.MutableBlockPos move(@NonNull EnumFacing facing) {
451435
}
452436

453437
public BlockPos.MutableBlockPos move(@NonNull EnumFacing facing, int blocks) {
454-
return this.setPos(x + facing.getFrontOffsetX() * blocks,
455-
y + facing.getFrontOffsetY() * blocks,
438+
return this.setPos(x + facing.getFrontOffsetX() * blocks, y + facing.getFrontOffsetY() * blocks,
456439
z + facing.getFrontOffsetZ() * blocks);
457440
}
458441
}

0 commit comments

Comments
 (0)