Refactoring (#30)

* update buildscript

* address gradle warning about insecure connection

* simplify bit shift

* nested enums are implicitly static

See https://stackoverflow.com/questions/663834/in-java-are-enum-types-inside-a-class-static

* enum constructors are private by design

See https://stackoverflow.com/questions/36286178/java-enum-constructors-private

* semicolon not needed

* replace anonymous class with standard init

The anonymous init takes more space and is harder to understand.

* improve javadoc

* remove duplicate case in switch

* improve javadoc

* simplify float

* simplify init

* remove redundant casts

* minor nitpick on a comment

* rename BACKGROUND to lowercase

* put on separate lines

* remove reduntant semicolons

* simplify isEmpty

* remove commented code, improve javadocs

* spotless

* gradle update buildscript

* explain why >> 0 stays

* Revert "remove redundant casts"

This reverts commit e7bf60e1d2.

* suppress the inspection for redundant casts

They are kept to clarify what the functions accepts.

* spotless vs intellij

Our battle will be legendary!
This commit is contained in:
chill authored and GitHub committed 2023-05-20 18:55:27 +02:00
1 parent f5a23d1a3b
commit d147681c26
18 files changed
+78 -93

No files matched your search

+23 -6
View File
@@ -1,4 +1,4 @@
//version: 1683056771
//version: 1684218858
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
@@ -69,10 +69,10 @@ plugins {
id 'com.diffplug.spotless' version '6.13.0' apply false // 6.13.0 is the last jvm8 supporting version
id 'com.modrinth.minotaur' version '2.+' apply false
id 'com.matthewprenger.cursegradle' version '1.4.0' apply false
id 'com.gtnewhorizons.retrofuturagradle' version '1.3.7'
id 'com.gtnewhorizons.retrofuturagradle' version '1.3.14'
}
print("You might want to check out './gradlew :faq' if your build fails.")
print("You might want to check out './gradlew :faq' if your build fails.\n")
boolean settingsupdated = verifySettingsGradle()
settingsupdated = verifyGitAttributes() || settingsupdated
@@ -222,6 +222,8 @@ if (enableModernJavaSyntax.toBoolean()) {
dependencies {
annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.0'
// workaround for https://github.com/bsideup/jabel/issues/174
annotationProcessor 'net.java.dev.jna:jna-platform:5.13.0'
compileOnly('com.github.bsideup.jabel:jabel-javac-plugin:1.0.0') {
transitive = false // We only care about the 1 annotation class
}
@@ -567,9 +569,10 @@ repositories {
def mixinProviderGroup = "io.github.legacymoddingmc"
def mixinProviderModule = "unimixins"
def mixinProviderVersion = "0.1.6"
def mixinProviderVersion = "0.1.7.1"
def mixinProviderSpecNoClassifer = "${mixinProviderGroup}:${mixinProviderModule}:${mixinProviderVersion}"
def mixinProviderSpec = "${mixinProviderSpecNoClassifer}:dev"
ext.mixinProviderSpec = mixinProviderSpec
dependencies {
if (usesMixins.toBoolean()) {
@@ -727,7 +730,7 @@ dependencies {
java17Dependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}")
}
if (modId != 'hodgepodge') {
java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.2.8')
java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.2.13')
}
java17PatchDependencies('net.minecraft:launchwrapper:1.15') {transitive = false}
@@ -820,6 +823,18 @@ public abstract class RunHotswappableMinecraftTask extends RunMinecraftTask {
}
this.classpath(project.java17DependenciesCfg)
}
public void setup(Project project) {
super.setup(project)
if (project.usesMixins.toBoolean()) {
this.extraJvmArgs.addAll(project.provider(() -> {
def mixinCfg = project.configurations.detachedConfiguration(project.dependencies.create(project.mixinProviderSpec))
mixinCfg.canBeConsumed = false
mixinCfg.transitive = false
enableHotswap ? ["-javaagent:" + mixinCfg.singleFile.absolutePath] : []
}))
}
}
}
def runClient17Task = tasks.register("runClient17", RunHotswappableMinecraftTask, Distribution.CLIENT, "runClient")
@@ -1264,7 +1279,9 @@ tasks.register('faq') {
print("If your build fails to fetch dependencies, they might have been deleted and replaced by newer " +
"versions.\nCheck if the versions you try to fetch are still on the distributing sites.\n" +
"The links can be found in repositories.gradle and build.gradle:repositories, " +
"not build.gradle:buildscript.repositories - this one is for gradle plugin metadata.")
"not build.gradle:buildscript.repositories - this one is for gradle plugin metadata.\n\n" +
"If your build fails to recognize the syntax of new Java versions, enable Jabel in your " +
"gradle.properties. See how it's done in GTNH ExampleMod/gradle.properties.")
}
}
Binary file not shown.
+1 -1
View File
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Vendored
+2 -2
View File
@@ -144,7 +144,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
@@ -152,7 +152,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
+1 -1
View File
@@ -4,7 +4,7 @@ repositories {
maven {
name 'GTNH Maven'
url 'http://jenkins.usrv.eu:8081/nexus/content/groups/public/'
allowInsecureProtocol
allowInsecureProtocol = true
}
maven {
url 'https://cursemaven.com'
@@ -86,7 +86,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
)
}
val BACKGROUND: ResourceLocation = ResourceLocation(MODID, "textures/gui/advanced_memory_card.png")
val background: ResourceLocation = ResourceLocation(MODID, "textures/gui/advanced_memory_card.png")
private val selectedInfo: InfoWrapper?
get() = infos.selectedInfo
@@ -522,7 +522,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
}
private fun drawBackground() {
bindTexture(BACKGROUND)
bindTexture(background)
val tessellator = Tessellator.instance
// Draw the top part
drawTexturedQuad(tessellator,
@@ -69,8 +69,8 @@ class InfoFilter {
}
/**
* The different filter types. Probably will let these be adjustable in the
* config.
* Holds different filter types.
* TODO they will probably be adjustable in the config.
*/
enum class Filter(val pattern: Regex, val filter: (InfoWrapper, List<String>?) -> Boolean) {
INPUT("\\A@in\\z".toRegex(), { it, _ -> !it.output }),
@@ -89,7 +89,7 @@ enum class Filter(val pattern: Regex, val filter: (InfoWrapper, List<String>?) -
NAME("\"?.+\"?".toRegex(), filter@{ it, strs ->
val name = it.name.lowercase()
for (f in strs!!) {
// Ppl better not troll and use double quotes in their P2P tunnel names
// Double quotes will likely break P2P tunneling
val query = f.removeSurrounding("\"")
if (name.contains(query)) {
return@filter true
@@ -99,7 +99,7 @@ enum class Filter(val pattern: Regex, val filter: (InfoWrapper, List<String>?) -
});
}
// I spent 10 minutes on this until I gave up... regex wtf
// Splitting a string with regex is hard.
// https://stackoverflow.com/questions/366202/regex-for-splitting-a-string-using-space-when-not-surrounded-by-single-or-double
val SEARCH_REGEX = "[^\\s\"']+|\"([^\"]*)\"|'([^']*)'".toRegex()
@@ -53,12 +53,12 @@ class InfoList (initList: Collection<InfoWrapper>,
fun resort() {
sorted.sortBy {
if (it.code == selectedEntry) {
-2 // Put the selected p2p in the front
-2 // Put the selected p2p at the front
// Non-Zero frequencies
} else if (it.frequency != 0L && it.frequency == selectedInfo?.frequency && !it.output) {
-3 // Put input in the beginning
-3 // Put input at the beginning
} else if (it.frequency != 0.toLong() && it.frequency == selectedInfo?.frequency) {
-1 // Put same frequency in the front
-1 // Put same frequency at the front
} else {
// Frequencies from lowest to highest
it.frequency + Short.MAX_VALUE
@@ -85,7 +85,8 @@ class InfoList (initList: Collection<InfoWrapper>,
when {
it.code == selectedEntry -> Long.MIN_VALUE + 1
it.frequency != 0L && it.frequency == selectedInfo?.frequency && !it.output -> Long.MIN_VALUE
it.frequency != 0.toLong() && it.frequency == selectedInfo?.frequency -> Long.MIN_VALUE + 2 // Put same frequency in the front
// Put the same frequency to the front
it.frequency != 0.toLong() && it.frequency == selectedInfo?.frequency -> Long.MIN_VALUE + 2
filter.activeFilters.containsKey(Filter.NAME) -> {
var hits = 0L
var name = it.name
@@ -126,7 +127,7 @@ class InfoList (initList: Collection<InfoWrapper>,
}
/**
* Update the master list, and send the changes downstream to sorted/filtered
* Updates the master list and sends the changes downstream to sorted/filtered.
*/
fun update(updateList: Collection<InfoWrapper>) {
updateList.forEach { masterMap[it.code] = it }
@@ -38,7 +38,7 @@ abstract class WidgetButton(val gui: GuiAdvancedMemoryCard, x: Int, y: Int, widt
}
open fun drawBG(tessellator: Tessellator, mouseX: Int, mouseY: Int, partialTicks: Float) {
gui.bindTexture(gui.BACKGROUND)
gui.bindTexture(gui.background)
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f)
field_146123_n = mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + height
val k = getHoverState(field_146123_n)
@@ -58,7 +58,7 @@ class WidgetP2PColumn(private val gui: GuiAdvancedMemoryCard,
for (widget in entries){
widget.renderNameTextField = true
}
if(renameBar.info != null && !renameBar.text.isEmpty() && renameBar.info.name != renameBar.text){
if(renameBar.info != null && renameBar.text.isNotEmpty() && renameBar.info.name != renameBar.text){
val info:InfoWrapper = renameBar.info
renameBar.text = renameBar.text.trim()
ModNetwork.channel.sendToServer(C2SP2PTunnelInfo(P2PTunnelInfo(info.posX,info.posY,info.posZ,info.dim, ForgeDirection.valueOf(info.facing.name).ordinal,renameBar.text)))
@@ -69,19 +69,11 @@ class WidgetP2PColumn(private val gui: GuiAdvancedMemoryCard,
renameBar.info = null
}
//private fun transportPlayer(info: InfoWrapper){
// Minecraft.getMinecraft().thePlayer.closeScreen()
// ModNetwork.channel.sendToServer(C2STransportPlayer(P2PTunnelInfo(info.posX,info.posY,info.posZ,info.dim,0)))
//}
/**
* Called when rename button "area" is clicked. Rename text bar must be
* visible after this is called.
*/
private fun onRenameButtonClicked(info:InfoWrapper, index: Int) {
// if (GuiScreen.isShiftKeyDown()) {
// transportPlayer(info)
// }
renameBar.isVisible = true
renameBar.y = (this.y) + index * (P2PEntryConstants.HEIGHT + 1) + 1
renameBar.x = this.x + 50
@@ -82,9 +82,9 @@ class WidgetP2PDevice(private val selectedInfoProperty: KProperty0<InfoWrapper?>
GuiScreen.drawRect(x, y, x + P2PEntryConstants.WIDTH, y + P2PEntryConstants.HEIGHT, P2PEntryConstants.OUTPUT_COLOR)
}
GL11.glColor3f(255f, 255f, 255f)
// Draw our icons...
// Draw our icons
drawBlockIcon(gui.mc, info.icon, info.overlay, x + 3, y + 3)
gui.bindTexture(gui.BACKGROUND)
gui.bindTexture(gui.background)
if (info.output) {
drawTexturedQuad(Tessellator.instance, x.toDouble(), y + 4.0, x + 16.0, y + 20.0,
144.0 / GUI_WIDTH, 200.0 / GUI_TEX_HEIGHT, 160.0 / GUI_WIDTH, 216.0 / GUI_TEX_HEIGHT)
@@ -15,14 +15,10 @@ import com.projecturanus.betterp2p.util.GlStateManager;
import kotlin.Pair;
/**
* Everything in this inner class is From a mod that has MIT license owned by romelo333 and maintained by McJty
*
* License is here: https://github.com/romelo333/notenoughwands1.8.8/blob/master/LICENSE
*
* Specific source of code from the GenericWand class:
* https://github.com/romelo333/notenoughwands1.8.8/blob/20952f50e7c1ab3fd676ed3da302666295e3cac8/src/main/java/romelo333/notenoughwands/Items/GenericWand.java
*
* Version 1.1: Edited to support rotation
* This class is based on the <a href=
* "https://github.com/romelo333/notenoughwands1.8.8/blob/20952f50e7c1ab3fd676ed3da302666295e3cac8/src/main/java/romelo333/notenoughwands/Items/GenericWand.java">GenericWand</a>
* class from a mod with MIT license.
* <a href="https://github.com/romelo333/notenoughwands1.8.8/blob/master/LICENSE">Source license</a>
*/
public class OutlineRenderer {
@@ -49,10 +45,7 @@ public class OutlineRenderer {
private static void renderOutlines(Collection<List<Integer>> coordinates, int r, int g, int b, int thickness) {
Tessellator tessellator = Tessellator.instance;
// net.minecraft.client.renderer.VertexBuffer
// BufferBuilder buffer = tessellator.getBuffer();
tessellator.startDrawing(GL11.GL_LINES);
// GlStateManager.color(r / 255.0f, g / 255.0f, b / 255.0f);
GL11.glLineWidth(thickness);
for (List<Integer> coordinate : coordinates) {
float x = coordinate.get(0);
@@ -115,7 +108,6 @@ public class OutlineRenderer {
private static void renderOutlinesWithFacing(Collection<Pair<List<Integer>, ForgeDirection>> coordinates, double x,
double y, double z, int r, int g, int b, int thickness) {
Tessellator tessellator = Tessellator.instance;
// BufferBuilder buffer = tessellator.getBuffer();
for (Pair<List<Integer>, ForgeDirection> coordinate : coordinates) {
List<Integer> pos = coordinate.component1();
@@ -15,19 +15,11 @@ import org.lwjgl.opengl.GL11;
import com.projecturanus.betterp2p.util.GlStateManager;
/**
* Functions from this inner class are not authored by me (Sam Bassett aka Lothrazar) they are from BuildersGuides by
*
* @author Ipsis
*
* All credit goes to author for this
*
* Source code: https://github.com/Ipsis/BuildersGuides Source License
* https://github.com/Ipsis/BuildersGuides/blob/master/COPYING.LESSER
*
* I used and modified two functions from this library
* https://github.com/Ipsis/BuildersGuides/blob/master/src/main/java/ipsis/buildersguides/util/RenderUtils.java
*
*
* This class uses the code from BuildersGuides. <a href="https://github.com/Ipsis/BuildersGuides">Source code</a>
* <a href="https://github.com/Ipsis/BuildersGuides/blob/master/COPYING.LESSER">Source license</a> In particular, two
* functions of <a href=
* "https://github.com/Ipsis/BuildersGuides/blob/master/src/main/java/ipsis/buildersguides/util/RenderUtils.java">RenderUtils</a>
* were used.
*/
@SuppressWarnings("serial")
public class ShadowRenderer {
@@ -37,12 +29,9 @@ public class ShadowRenderer {
if (p == null) {
return;
}
renderBlockList(new ArrayList<List<Integer>>() {
{
add(p);
}
}, center, relX, relY, relZ, red, green, blue);
ArrayList<List<Integer>> blockPosList = new ArrayList<>();
blockPosList.add(p);
renderBlockList(blockPosList, center, relX, relY, relZ, red, green, blue);
}
public static void renderBlockPhantom(World world, final List<Integer> pos, ItemStack stack, final double relX,
@@ -58,9 +47,7 @@ public class ShadowRenderer {
int xOffset = target.get(0) - pos.get(0);
int yOffset = target.get(1) - pos.get(1);
int zOffset = target.get(2) - pos.get(2);
// final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
Tessellator tessellator = Tessellator.instance;
// BufferBuilder bufferBuilder = tessellator.getBuffer();
GlStateManager.pushMatrix();
// this first translate is to make relative to TE and everything
GlStateManager.translate(relX + 0.5F, relY + 0.5F, relZ + 0.5F);
@@ -113,9 +100,8 @@ public class ShadowRenderer {
}
private static void shadedCube(float scale) {
float size = 1.0F * scale;
float size = scale;
Tessellator tessellator = Tessellator.instance;
// BufferBuilder worldRenderer = tessellator.getBuffer();
// Front - anticlockwise vertices
// Back - clockwise vertices
tessellator.startDrawing(GL11.GL_QUADS);
@@ -44,7 +44,6 @@ object WorldRenderer {
fun shadedCube(scale: Float) {
val size = 1.0 * scale
val tessellator = Tessellator.instance
//val worldRenderer = tessellator.buffer
// Front - anticlockwise vertices
// Back - clockwise vertices
tessellator.startDrawing(GL11.GL_QUADS)
@@ -1,4 +1,4 @@
package com.projecturanus.betterp2p.network;
package com.projecturanus.betterp2p.network
import cpw.mods.fml.common.network.simpleimpl.IMessage
@@ -18,6 +18,8 @@ import cpw.mods.fml.relauncher.SideOnly;
/**
* Copied from forge 1.12.2-14.23.5.2847 net.minecraft.client.renderer.GlStateManager
*/
// We keep the redundant casts to clarify what the function accepts as an input
@SuppressWarnings("RedundantCast")
@SideOnly(Side.CLIENT)
public class GlStateManager {
@@ -184,6 +186,8 @@ public class GlStateManager {
public static void enableOutlineMode(int color) {
BUF_FLOAT_4.put(0, (float) (color >> 16 & 255) / 255.0F);
BUF_FLOAT_4.put(1, (float) (color >> 8 & 255) / 255.0F);
// We keep ">> 0" to convey that we extract the LSB
// noinspection PointlessBitwiseExpression
BUF_FLOAT_4.put(2, (float) (color >> 0 & 255) / 255.0F);
BUF_FLOAT_4.put(3, (float) (color >> 24 & 255) / 255.0F);
glTexEnv(8960, 8705, BUF_FLOAT_4);
@@ -335,8 +339,6 @@ public class GlStateManager {
private static GlStateManager.TexGenCoord texGenCoord(GlStateManager.TexGen texGen) {
switch (texGen) {
case S:
return texGenState.s;
case T:
return texGenState.t;
case R:
@@ -815,10 +817,6 @@ public class GlStateManager {
}
public Color(float redIn, float greenIn, float blueIn, float alphaIn) {
this.red = 1.0F;
this.green = 1.0F;
this.blue = 1.0F;
this.alpha = 1.0F;
this.red = redIn;
this.green = greenIn;
this.blue = blueIn;
@@ -869,7 +867,7 @@ public class GlStateManager {
}
@SideOnly(Side.CLIENT)
public static enum CullFace {
public enum CullFace {
FRONT(1028),
BACK(1029),
@@ -877,7 +875,7 @@ public class GlStateManager {
public final int mode;
private CullFace(int modeIn) {
CullFace(int modeIn) {
this.mode = modeIn;
}
}
@@ -909,7 +907,7 @@ public class GlStateManager {
}
@SideOnly(Side.CLIENT)
public static enum DestFactor {
public enum DestFactor {
CONSTANT_ALPHA(32771),
CONSTANT_COLOR(32769),
@@ -928,13 +926,13 @@ public class GlStateManager {
public final int factor;
private DestFactor(int factorIn) {
DestFactor(int factorIn) {
this.factor = factorIn;
}
}
@SideOnly(Side.CLIENT)
public static enum FogMode {
public enum FogMode {
LINEAR(9729),
EXP(2048),
@@ -943,7 +941,7 @@ public class GlStateManager {
/** The capability ID of this {@link FogMode} */
public final int capabilityId;
private FogMode(int capabilityIn) {
FogMode(int capabilityIn) {
this.capabilityId = capabilityIn;
}
}
@@ -966,7 +964,7 @@ public class GlStateManager {
}
@SideOnly(Side.CLIENT)
public static enum LogicOp {
public enum LogicOp {
AND(5377),
AND_INVERTED(5380),
@@ -987,7 +985,7 @@ public class GlStateManager {
public final int opcode;
private LogicOp(int opcodeIn) {
LogicOp(int opcodeIn) {
this.opcode = opcodeIn;
}
}
@@ -1007,7 +1005,7 @@ public class GlStateManager {
}
@SideOnly(Side.CLIENT)
public static enum SourceFactor {
public enum SourceFactor {
CONSTANT_ALPHA(32771),
CONSTANT_COLOR(32769),
@@ -1027,7 +1025,7 @@ public class GlStateManager {
public final int factor;
private SourceFactor(int factorIn) {
SourceFactor(int factorIn) {
this.factor = factorIn;
}
}
@@ -1063,11 +1061,11 @@ public class GlStateManager {
}
@SideOnly(Side.CLIENT)
public static enum TexGen {
public enum TexGen {
S,
T,
R,
Q;
Q
}
@SideOnly(Side.CLIENT)
@@ -25,7 +25,6 @@ class P2PStatus(val grid: IGrid, val player: EntityPlayer, type: Int) {
*/
var lastP2PType: Int = type
/**
* Refreshes the p2p list
*/
@@ -48,7 +48,7 @@ fun linkP2P(player: EntityPlayer, inputIndex: Long, outputIndex: Long, status: P
if (input.frequency == 0L || input.isOutput) {
frequency = System.currentTimeMillis()
}
// If tunnel was already bound, unbind that one.
// If tunnel was already bound, unbind that one
if (cache.getInput(frequency) != null) {
val originalInput = cache.getInput(frequency)
if (originalInput != input) {
@@ -59,7 +59,8 @@ fun linkP2P(player: EntityPlayer, inputIndex: Long, outputIndex: Long, status: P
val outputResult: PartP2PTunnel<*> = updateP2P(output, frequency, true, player, input.customName)
if (input is PartP2PInterface && output is PartP2PInterface) {
// For input and output, retain upgrades, items, and settings.
inputResult as PartP2PInterface; outputResult as PartP2PInterface
inputResult as PartP2PInterface
outputResult as PartP2PInterface
val upgradesIn = input.interfaceDuality.getInventoryByName("upgrades") as UpgradeInventory
upgradesIn.forEachIndexed { index, stack ->
(inputResult.interfaceDuality.getInventoryByName("upgrades") as UpgradeInventory).setInventorySlotContents(index, stack)
@@ -85,12 +86,12 @@ fun linkP2P(player: EntityPlayer, inputIndex: Long, outputIndex: Long, status: P
outputResult.configManager.putSetting(it, settingsOut.getSetting(it))
}
// For input, just copy the patterns over.
// For input, just copy the patterns over
val patternsIn = input.interfaceDuality.patterns as AppEngInternalInventory
patternsIn.forEachIndexed { index, stack ->
(inputResult.interfaceDuality.patterns as AppEngInternalInventory).setInventorySlotContents(index, stack)
}
// For output, drop items.
// For output, drop items
val dropItems = mutableListOf<ItemStack>()
val patternsOut = output.interfaceDuality.patterns as AppEngInternalInventory
dropItems.addAll(patternsOut)