Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix server crash with magic beans #32

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.gradle
.settings
/.idea/
/.vscode/
/run/
/build/
/eclipse/
Expand All @@ -25,5 +26,13 @@ whitelist.json
*.iml
*.ipr
*.iws
src/main/resources/mixins.*.json
src/main/resources/mixins.*([!.]).json
*.bat
*.DS_Store
!gradlew.bat
.factorypath
addon.local.gradle
addon.local.gradle.kts
addon.late.local.gradle
addon.late.local.gradle.kts
layout.json
73 changes: 53 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//version: 1692122114
//version: 1696952014
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
Expand Down Expand Up @@ -89,6 +89,23 @@ def out = services.get(StyledTextOutputFactory).create('an-output')
def projectJavaVersion = JavaLanguageVersion.of(8)

boolean disableSpotless = project.hasProperty("disableSpotless") ? project.disableSpotless.toBoolean() : false
boolean disableCheckstyle = project.hasProperty("disableCheckstyle") ? project.disableCheckstyle.toBoolean() : false

final String CHECKSTYLE_CONFIG = """
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="TreeWalker">
<!-- Use CHECKSTYLE:OFF and CHECKSTYLE:ON comments to suppress checkstyle lints in a block -->
<module name="SuppressionCommentFilter"/>
<module name="AvoidStarImport">
<!-- Allow static wildcard imports for cases like Opcodes and LWJGL classes, these don't get created accidentally by the IDE -->
<property name="allowStaticMemberImports" value="true"/>
</module>
</module>
</module>
"""

checkPropertyExists("modName")
checkPropertyExists("modId")
Expand Down Expand Up @@ -140,6 +157,17 @@ if (!disableSpotless) {
apply from: Blowdryer.file('spotless.gradle')
}

if (!disableCheckstyle) {
apply plugin: 'checkstyle'
tasks.named("checkstylePatchedMc") { enabled = false }
tasks.named("checkstyleMcLauncher") { enabled = false }
tasks.named("checkstyleIdeVirtualMain") { enabled = false }
tasks.named("checkstyleInjectedTags") { enabled = false }
checkstyle {
config = resources.text.fromString(CHECKSTYLE_CONFIG)
}
}

String javaSourceDir = "src/main/java/"
String scalaSourceDir = "src/main/scala/"
String kotlinSourceDir = "src/main/kotlin/"
Expand Down Expand Up @@ -600,15 +628,10 @@ repositories {
}
maven {
name = "ic2"
url = "https://maven.ic2.player.to/"
metadataSources {
mavenPom()
artifact()
url = getURL("https://maven.ic2.player.to/", "https://maven2.ic2.player.to/")
content {
includeGroup "net.industrial-craft"
}
}
maven {
name = "ic2-mirror"
url = "https://maven2.ic2.player.to/"
metadataSources {
mavenPom()
artifact()
Expand Down Expand Up @@ -770,23 +793,14 @@ ext.java17PatchDependenciesCfg = configurations.create("java17PatchDependencies"
}

dependencies {
def lwjgl3ifyVersion = '1.4.0'
def asmVersion = '9.4'
def lwjgl3ifyVersion = '1.5.1'
if (modId != 'lwjgl3ify') {
java17Dependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}")
}
if (modId != 'hodgepodge') {
java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.2.26')
java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.3.7')
}

java17PatchDependencies('net.minecraft:launchwrapper:1.17.2') {transitive = false}
java17PatchDependencies("org.ow2.asm:asm:${asmVersion}")
java17PatchDependencies("org.ow2.asm:asm-commons:${asmVersion}")
java17PatchDependencies("org.ow2.asm:asm-tree:${asmVersion}")
java17PatchDependencies("org.ow2.asm:asm-analysis:${asmVersion}")
java17PatchDependencies("org.ow2.asm:asm-util:${asmVersion}")
java17PatchDependencies('org.ow2.asm:asm-deprecated:7.1')
java17PatchDependencies("org.apache.commons:commons-lang3:3.12.0")
java17PatchDependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}:forgePatches") {transitive = false}
}

Expand Down Expand Up @@ -1576,6 +1590,25 @@ def getSecondaryArtifacts() {
return secondaryArtifacts
}

def getURL(String main, String fallback) {
return pingURL(main, 10000) ? main : fallback
}

// credit: https://stackoverflow.com/a/3584332
def pingURL(String url, int timeout) {
url = url.replaceFirst("^https", "http") // Otherwise an exception may be thrown on invalid SSL certificates.
try {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection()
connection.setConnectTimeout(timeout)
connection.setReadTimeout(timeout)
connection.setRequestMethod("HEAD")
int responseCode = connection.getResponseCode()
return 200 <= responseCode && responseCode <= 399
} catch (IOException ignored) {
return false
}
}

// For easier scripting of things that require variables defined earlier in the buildscript
if (file('addon.late.gradle.kts').exists()) {
apply from: 'addon.late.gradle.kts'
Expand Down
3 changes: 2 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
dependencies {
compileOnly("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev") {transitive = false}

runtimeOnly("com.github.GTNewHorizons:Baubles:1.0.1.16:dev")
// For Thaumcraft runtime
//runtimeOnlyNonPublishable("com.github.GTNewHorizons:Baubles:1.0.1.16:dev")
}
18 changes: 3 additions & 15 deletions src/main/java/twilightforest/item/ItemTFMagicBeans.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public ItemTFMagicBeans() {
* Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
* True if something happen and false if it don't. This is for ITEMS, not BLOCKS
*/
@Override
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer player, World world, int x, int y, int z, int side,
float hitX, float hitY, float hitZ) {
Block blockAt = world.getBlock(x, y, z);
Expand All @@ -40,25 +41,12 @@ public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer player, World wor

/**
* Try to find the given world's cloud height
*
* @param world
* @return
*/
private float getCloudHeight(World world) {

if (world.provider instanceof WorldProviderTwilightForest) {
// WorldProviderTwilightForest has this method on both server and client
return world.provider.getCloudHeight();
} else {
// are we on a dedicated server
// TODO: don't use exceptions for program flow?
try {
return world.provider.getCloudHeight();
} catch (NoSuchMethodError nsme) {
// this method exists even on a dedicated server
return world.provider.terrainType.getCloudHeight();
}
return WorldProviderTwilightForest.CLOUD_HEIGHT;
}
return world.provider.terrainType.getCloudHeight();
}

private void makeHugeStalk(World world, int x, int z, int minY, int maxY) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/twilightforest/item/ItemTFOreMagnet.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package twilightforest.item;

import java.util.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
public class WorldProviderTwilightForest extends WorldProviderSurface {

public static final float CLOUD_HEIGHT = 161.0F;

public final String saveFolder;
public ChunkProviderTwilightForest chunkProvider;

Expand Down Expand Up @@ -64,6 +66,7 @@ public Vec3 getFogColor(float f, float f1) {
/**
* Calculates the angle of sun and moon in the sky relative to a specified time (usually worldTime)
*/
@Override
public float calculateCelestialAngle(long par1, float par3) {
// return super.calculateCelestialAngle(par1, par3);
return 0.225f;
Expand All @@ -78,6 +81,7 @@ public void registerWorldChunkManager() {
/**
* Returns a new chunk provider which generates chunks for this world
*/
@Override
public IChunkProvider createChunkGenerator() {
// save chunk generator?
if (this.chunkProvider == null) {
Expand Down Expand Up @@ -106,13 +110,7 @@ public boolean isSkyColored() {
return false;
}

//
// @Override
// public float getCloudHeight()
// {
// return 64F;
// }

@Override
public int getAverageGroundLevel() {
return 30;
}
Expand Down Expand Up @@ -225,6 +223,7 @@ public void updateWeather() {
// }
}

@Override
@SideOnly(Side.CLIENT)
public IRenderHandler getSkyRenderer() {
if (super.getSkyRenderer() == null) {
Expand All @@ -234,6 +233,7 @@ public IRenderHandler getSkyRenderer() {
return super.getSkyRenderer();
}

@Override
@SideOnly(Side.CLIENT)
public IRenderHandler getWeatherRenderer() {
if (super.getWeatherRenderer() == null) {
Expand All @@ -246,8 +246,8 @@ public IRenderHandler getWeatherRenderer() {
/**
* the y level at which clouds are rendered.
*/
// @SideOnly(Side.CLIENT) // need for magic beans, even on server
@Override
public float getCloudHeight() {
return 161.0F;
return CLOUD_HEIGHT;
}
}