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

Compatibility with JSG + Update build.gradle #546

Open
wants to merge 14 commits into
base: MC1.12
Choose a base branch
from
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"java.compile.nullAnalysis.mode": "automatic",
"java.configuration.updateBuildConfiguration": "automatic"
}
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ See the official forum [here](https://www.minecraftforum.net/forums/mapping-and-
## Developping

To setup you development environment:
1. From the WarpDrive mod folder, type:
1. Install Java 8u281 or newer
2. Install Gradle 4.8.1 (cannot be newer)
3. Clone this repository
4. From the WarpDrive mod folder, type:
```
./gradlew setupDecompWorkspace
```
2. Start IdeaJ.
3. Import the gradle project.
4. Import the code formating & inspection rules from `IntelliJ IDEA-Code Style.xml` and `IntelliJ IDEA-Inspection.xml`.
5. Create run configuration using gradle, select the gradle project, enter the task `runClient` or `runServer`.
5. Start code editor.
6. Create run configuration using gradle, select the gradle project, enter the task `runClient` or `runServer`.
22 changes: 13 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


buildscript {
repositories {
jcenter()
Expand Down Expand Up @@ -112,11 +110,14 @@ repositories {
name = "CurseForge"
url = "https://minecraft.curseforge.com/api/maven/"
}
maven {
url "https://cursemaven.com"
}
ivy {
name "GalacticraftCore"
url "https://micdoodle8.com/new-builds/"
url "https://maven.galacticraft.net/repository/legacy/"
layout 'pattern', {
artifact "[organization]/${config.Galacticraft_build}/[module]-[revision].jar"
artifact "dev/galacticraft/galacticraft-legacy/[revision]/[module]-[revision].jar"
}
metadataSources {
artifact()
Expand All @@ -133,22 +134,25 @@ dependencies {
// Real examples
//compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
//compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env

// For more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html

implementation 'javax.annotation:javax.annotation-api:1.3.1' //Fixes @Nonnull error thing
// Using deobfCompile will include in run environment
provided "blusunrize:ImmersiveEngineering:${config.ImmersiveEngineering_version}:deobf"
provided "cofh:CoFHCore:${config.CoFHCore_version}:universal"
provided "cofh:RedstoneFlux:${config.RedstoneFlux_version}:universal"
provided "codechicken:CodeChickenLib:${config.CodeChickenLib_version}:universal"
provided "GC-1.12-dev:GalacticraftCore-Dev:${config.Galacticraft_version}.${config.Galacticraft_build}"
// provided "GC-1.12-dev:GalacticraftCore-Dev:${config.Galacticraft_version}.${config.Galacticraft_build}"
provided "dev.galacticraft:galacticraft-legacy:${config.Galacticraft_version}"
provided "curse.maven:icbm-classic-244451:4524395"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version is obfuscated and hardcoded in build script, consider adding a comment on the actual version and leaving version dependencies in the separate config file? (multiple occurrences)

// provided "com.builtbroken.icbm-classic:ICBM-classic:${config.ICBMclassic_version}"
provided curse.resolve("icbm-classic", "${config.ICBMclassic_fileid}")
// provided curse.resolve("icbm-classic", "${config.ICBMclassic_fileid}")
provided "li.cil.oc:OpenComputers:${config.OpenComputers_version}"
provided "vazkii.patchouli:Patchouli:${config.Patchouli_version}"
provided curse.resolve("matteroverdrive", "${config.MatterOverdrive_fileid}") // "${config.MatterOverdrive_version}"
provided "curse.maven:matter-overdrive-community-edition-557428:4512991"
//provided curse.resolve("matteroverdrive", "${config.MatterOverdrive_fileid}") // "${config.MatterOverdrive_version}"

// compileOnly "mezz.jei:jei_1.10.2:3.13.+"
// compileOnly "mcp.mobius.waila:Waila:1.7.0-B3_1.9.4"
Expand Down
5 changes: 2 additions & 3 deletions build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ forge_version=14.23.5.2847

CoFHCore_version=1.12.2-4.6.+
CodeChickenLib_version=1.12.2-3.2.+
Galacticraft_version=1.12.2-4.0.2
Galacticraft_build=261
Galacticraft_version=4.0.5
ICBMclassic_version=1.12.2-4.0.0b74
ICBMclassic_fileid=2894147
ImmersiveEngineering_version=0.12-+
Expand All @@ -16,4 +15,4 @@ RedstoneFlux_version=1.12-2.1.+
MatterOverdrive_version=1.12.2-0.7.1.0
MatterOverdrive_fileid=2699215

mod_version=1.5.28
mod_version=1.5.29
173 changes: 173 additions & 0 deletions src/main/java/cr0s/warpdrive/compat/CompatJSG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package cr0s.warpdrive.compat;

import cr0s.warpdrive.Commons;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.api.IBlockTransformer;
import cr0s.warpdrive.api.ITransformation;
import cr0s.warpdrive.api.WarpDriveText;
import cr0s.warpdrive.config.WarpDriveConfig;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import net.minecraft.block.Block;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class CompatJSG implements IBlockTransformer {

private static Class<?> classStargateAbstractBaseTile;
private static Class<?> classStargateAbstractMemberTile;
private static Class<?> classDHDAbstractTile;
private static Class<?> classDHDAbstractBlock;
private static Class<?> classStargateClassicBaseTile;
private static Class<?> classStargateAbstractBaseBlock;
private static Class<?> classStargateAbstractMemberBlock;
private static Method methodStargateClassicBaseTile_sgStateDescription;

public static void register() {
try {
classStargateAbstractBaseTile = Class.forName("tauri.dev.jsg.tileentity.stargate.StargateAbstractBaseTile");
classStargateAbstractMemberTile = Class.forName("tauri.dev.jsg.tileentity.stargate.StargateAbstractMemberTile");
classDHDAbstractTile = Class.forName("tauri.dev.jsg.tileentity.dialhomedevice.DHDAbstractTile");
classDHDAbstractBlock = Class.forName("tauri.dev.jsg.block.dialhomedevice.DHDAbstractBlock");
classStargateClassicBaseTile = Class.forName("tauri.dev.jsg.tileentity.stargate.StargateClassicBaseTile");
classStargateAbstractBaseBlock = Class.forName("tauri.dev.jsg.block.stargate.StargateAbstractBaseBlock");
classStargateAbstractMemberBlock = Class.forName("tauri.dev.jsg.block.stargate.StargateAbstractMemberBlock");
methodStargateClassicBaseTile_sgStateDescription = classStargateAbstractBaseTile.getMethod("getStargateState");
WarpDriveConfig.registerBlockTransformer("jsg", new CompatJSG());
} catch(final ClassNotFoundException | NoSuchMethodException | SecurityException exception) {
exception.printStackTrace();
}
}

@Override
public boolean isApplicable(final Block block, final int metadata, final TileEntity tileEntity) {
if (classStargateAbstractMemberTile.isInstance(tileEntity)
|| classDHDAbstractTile.isInstance(tileEntity)
|| classStargateAbstractBaseTile.isInstance(tileEntity)
|| classDHDAbstractBlock.isInstance(block)) {
return true;
}
return false;
}

@Override
public boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, final WarpDriveText reason) {
if (classStargateClassicBaseTile.isInstance(tileEntity)) {
try {
final Object object = methodStargateClassicBaseTile_sgStateDescription.invoke(tileEntity);
final String state = object.toString();
if (!state.equalsIgnoreCase("Idle")) {
reason.append(Commons.getStyleWarning(), "warpdrive.compat.guide.stargate_is_active", state);
return false;
}
} catch (final IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) {
exception.printStackTrace();
}
}
return true;
}

@Override
public NBTBase saveExternals(final World world, final int x, final int y, final int z, final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do
return null;
}

@Override
public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do
}

@Override
public int rotate(final Block block, final int metadata, final NBTTagCompound nbtTileEntity, final ITransformation transformation) {
final byte rotationSteps = transformation.getRotationSteps();

// Translate position of the linked base for member blocks
if (nbtTileEntity.hasKey("basePos")) {
//Convert the long to a BlockPos then apply the transformation
final BlockPos basePos = transformation.apply(BlockPos.fromLong(nbtTileEntity.getLong("basePos")));
nbtTileEntity.setLong("basePos", basePos.toLong());
}

//get the blockstate (from metadata so lem doesn't get mad)
final IBlockState blockState = block.getStateFromMeta(metadata);

// Rotation for stargate blocks, I don't know why the default rotation system doesn't work for them
//get the facing property
final PropertyEnum<EnumFacing> propertyFacing = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
//check if the block has the facing property
if (blockState.getProperties().containsKey(propertyFacing)) {
//get the facing value
final EnumFacing facing = blockState.getValue(propertyFacing);
//rotate the facing value
final EnumFacing facingRotated;
switch (rotationSteps) {
case 1:
facingRotated = facing.rotateY();
break;
case 2:
facingRotated = facing.rotateY().rotateY();
break;
case 3:
facingRotated = facing.rotateY().rotateY().rotateY();
break;
default:
facingRotated = facing;
break;
}
//set the facing value
return block.getMetaFromState(blockState.withProperty(propertyFacing, facingRotated));
}

// Rotation for DHD block. The DHD uses a non-standard 16 step rotation system with a custom block property which is why this code is so messy

//get the rotation property
final PropertyInteger propertyRotation = PropertyInteger.create("rotation", 0, 15);
//check if the block has the rotation property
if (blockState.getProperties().containsKey(propertyRotation)) {
//get the rotation value
final int DHDRotation = blockState.getValue(propertyRotation);
switch (rotationSteps) {
case 1: //Wrap around if rotation is greater than 15
if (DHDRotation+4 > 15) {
return block.getMetaFromState(blockState.withProperty(propertyRotation, DHDRotation-12));
} else {
return block.getMetaFromState(blockState.withProperty(propertyRotation, DHDRotation+4));
}
case 2:
if (DHDRotation+8 > 15) {
return block.getMetaFromState(blockState.withProperty(propertyRotation, DHDRotation-8));
} else {
return block.getMetaFromState(blockState.withProperty(propertyRotation, DHDRotation+8));
}
case 3:
if (DHDRotation+12 > 15) {
return block.getMetaFromState(blockState.withProperty(propertyRotation, DHDRotation-4));
} else {
return block.getMetaFromState(blockState.withProperty(propertyRotation, DHDRotation+12));
}
default:
break;
}
}
return metadata;
}

@Override
public void restoreExternals(final World world, final BlockPos blockPos,
final IBlockState blockState, final TileEntity tileEntity,
final ITransformation transformation, final NBTBase nbtBase) {
// nothing to do
}
}
8 changes: 8 additions & 0 deletions src/main/java/cr0s/warpdrive/config/Dictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,14 @@ public static void loadConfig(@Nonnull final Configuration config) {
config.get("block_tags", "ic2:blockchambers" , "PlaceLatest").getString(); // IC2 Classic Reactor chamber
config.get("block_tags", "immersiveengineering:connector" , "PlaceLatest").getString();
config.get("block_tags", "industrialforegoing:black_hole_label" , "PlaceLatest").getString();
config.get("block_tags", "jsg:dhd_block" , "PlaceLatest").getString();
config.get("block_tags", "jsg:dhd_pegasus_block" , "PlaceLatest").getString();
config.get("block_tags", "jsg:stargate_milkyway_base_block" , "PlaceEarliest").getString();
config.get("block_tags", "jsg:stargate_milkyway_member_block" , "PlaceEarlier").getString();
config.get("block_tags", "jsg:stargate_pegasus_base_block" , "PlaceEarliest").getString();
config.get("block_tags", "jsg:stargate_pegasus_member_block" , "PlaceEarlier").getString();
config.get("block_tags", "jsg:stargate_universe_base_block" , "PlaceEarliest").getString();
config.get("block_tags", "jsg:stargate_universe_member_block" , "PlaceEarlier").getString();
config.get("block_tags", "modularforcefieldsystem:force_field" , "PlaceEarlier StopMining NoBlink").getString();
config.get("block_tags", "opencomputers:case1" , "PlaceLatest").getString();
config.get("block_tags", "opencomputers:case2" , "PlaceLatest").getString();
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import cr0s.warpdrive.compat.CompatRoots;
import cr0s.warpdrive.compat.CompatRustic;
import cr0s.warpdrive.compat.CompatSGCraft;
import cr0s.warpdrive.compat.CompatJSG;
import cr0s.warpdrive.compat.CompatStorageDrawers;
import cr0s.warpdrive.compat.CompatTConstruct;
import cr0s.warpdrive.compat.CompatTechguns;
Expand Down Expand Up @@ -250,7 +251,7 @@ public class WarpDriveConfig {
public static boolean LOGGING_RADAR = false;
public static boolean LOGGING_BREATHING = false;
public static boolean LOGGING_WORLD_GENERATION = false;
public static boolean LOGGING_PROFILING_CPU_USAGE = true;
public static boolean LOGGING_PROFILING_CPU_USAGE = false;
public static boolean LOGGING_PROFILING_MEMORY_ALLOCATION = false;
public static boolean LOGGING_PROFILING_THREAD_SAFETY = false;
public static boolean LOGGING_DICTIONARY = false;
Expand All @@ -263,11 +264,11 @@ public class WarpDriveConfig {
public static boolean LOGGING_RENDERING = false;
public static boolean LOGGING_CHUNK_HANDLER = false;
public static boolean LOGGING_CHUNK_RELOADING = false;
public static boolean LOGGING_CHUNK_LOADING = true;
public static boolean LOGGING_CHUNK_LOADING = false;
public static boolean LOGGING_ENTITY_FX = false;
public static boolean LOGGING_CLIENT_SYNCHRONIZATION = false;
public static boolean LOGGING_GRAVITY = false;
public static boolean LOGGING_OFFLINE_AVATAR = true;
public static boolean LOGGING_OFFLINE_AVATAR = false;

// Energy
public static String ENERGY_DISPLAY_UNITS = "RF";
Expand Down Expand Up @@ -1724,6 +1725,11 @@ public static void onFMLInitialization() {
if (isSGCraftLoaded) {
CompatSGCraft.register();
}

final boolean isJSGLoaded = Loader.isModLoaded("jsg");
if (isJSGLoaded) {
CompatJSG.register();
}

final boolean isStorageDrawersLoaded = Loader.isModLoaded("storagedrawers");
if (isStorageDrawersLoaded) {
Expand Down