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

Add Draconicevolution energy core block compat #135

Merged
merged 8 commits into from
Mar 25, 2024
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
28 changes: 16 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//version: 1707604215
//version: 1707682661
/*
* DO NOT CHANGE THIS FILE!
* Also, you may replace this file at any time if there is an update available.
Expand All @@ -24,9 +24,9 @@ plugins {
id 'eclipse'
id 'maven-publish'
id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.7'
id 'com.gtnewhorizons.retrofuturagradle' version '1.3.28'
id 'net.darkhax.curseforgegradle' version '1.1.17' apply false
id 'com.modrinth.minotaur' version '2.8.6' apply false
id 'com.gtnewhorizons.retrofuturagradle' version '1.3.33'
id 'net.darkhax.curseforgegradle' version '1.1.18' apply false
id 'com.modrinth.minotaur' version '2.8.7' apply false
id 'com.diffplug.spotless' version '6.13.0' apply false
id 'com.palantir.git-version' version '3.0.0' apply false
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
Expand Down Expand Up @@ -495,7 +495,7 @@ configurations {
testRuntimeClasspath.extendsFrom(runtimeOnlyNonPublishable)
}

String mixinProviderSpec = 'zone.rong:mixinbooter:8.9'
String mixinProviderSpec = 'zone.rong:mixinbooter:9.1'
dependencies {
if (usesMixins.toBoolean()) {
annotationProcessor 'org.ow2.asm:asm-debug-all:5.2'
Expand Down Expand Up @@ -523,8 +523,8 @@ dependencies {
}

if (enableModernJavaSyntax.toBoolean()) {
annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.0'
compileOnly('com.github.bsideup.jabel:jabel-javac-plugin:1.0.0') {
annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.1'
compileOnly('com.github.bsideup.jabel:jabel-javac-plugin:1.0.1') {
transitive = false
}
// workaround for https://github.com/bsideup/jabel/issues/174
Expand All @@ -533,8 +533,8 @@ dependencies {
patchedMinecraft 'me.eigenraven.java8unsupported:java-8-unsupported-shim:1.0.0'

// allow Jabel to work in tests
testAnnotationProcessor "com.github.bsideup.jabel:jabel-javac-plugin:1.0.0"
testCompileOnly("com.github.bsideup.jabel:jabel-javac-plugin:1.0.0") {
testAnnotationProcessor "com.github.bsideup.jabel:jabel-javac-plugin:1.0.1"
testCompileOnly("com.github.bsideup.jabel:jabel-javac-plugin:1.0.1") {
transitive = false // We only care about the 1 annotation class
}
testCompileOnly "me.eigenraven.java8unsupported:java-8-unsupported-shim:1.0.0"
Expand All @@ -547,9 +547,13 @@ dependencies {
}

if (includeCommonDevEnvMods.toBoolean()) {
implementation 'mezz.jei:jei_1.12.2:4.16.1.302'
//noinspection DependencyNotationArgument
implementation rfg.deobf('curse.maven:top-245211:2667280') // TOP 1.4.28
if (!(modId.equals('jei'))) {
implementation 'mezz.jei:jei_1.12.2:4.16.1.302'
}
if (!(modId.equals('theoneprobe'))) {
//noinspection DependencyNotationArgument
implementation rfg.deobf('curse.maven:top-245211:2667280') // TOP 1.4.28
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions examples/postInit/draconicevolution.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

println 'mod \'draconicevolution\' detected, running script'

// Energy Core:
// A multiblock which stores energy

mods.draconicevolution.energy_core.setInnerBlock(7, blockstate('minecraft:stone', 1))
mods.draconicevolution.energy_core.setOuterBlock(2, blockstate('minecraft:diamond_block'))
mods.draconicevolution.energy_core.setOuterBlock(7, blockstate('minecraft:diamond_block'))

// Fusion:
// Consumes items and power from up to 54 pedestals of at least a given tier pointing towards a Fusion Crafting Core
// containing a catalyst to produce an output item.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ modGroup = com.cleanroommc.groovyscript
modVersion = 0.8.0
groovy_version = 4.0.13
debug_use_examples_folder = true
debug_run_ls = true
debug_run_ls = false

# Whether to use the old jar naming structure (modid-mcversion-version) instead of the new version (modid-version)
includeMCVersionJar = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ public class GroovyScriptConfig {

@Config.Comment("Port for the VSC connection. Default: 25564")
public static int languageServerPort = 25564;

public static Compat compat = new Compat();

public static class Compat {

@Config.Comment("Enables DE energy core compat. Config is mainly for other mods compat.")
public boolean draconicEvolutionEnergyCore = true;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.cleanroommc.groovyscript.compat.mods.draconicevolution;

import com.cleanroommc.groovyscript.GroovyScriptConfig;
import com.cleanroommc.groovyscript.compat.mods.ModPropertyContainer;

public class DraconicEvolution extends ModPropertyContainer {

public final Fusion fusion = new Fusion();
public final EnergyCore energyCore;

public DraconicEvolution() {
this.energyCore = GroovyScriptConfig.compat.draconicEvolutionEnergyCore ? new EnergyCore() : null;
addRegistry(fusion);
if (this.energyCore != null) addRegistry(energyCore);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package com.cleanroommc.groovyscript.compat.mods.draconicevolution;

import com.cleanroommc.groovyscript.api.GroovyBlacklist;
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IScriptReloadable;
import com.cleanroommc.groovyscript.api.documentation.annotations.Example;
import com.cleanroommc.groovyscript.api.documentation.annotations.MethodDescription;
import com.cleanroommc.groovyscript.api.documentation.annotations.RegistryDescription;
import com.cleanroommc.groovyscript.compat.mods.draconicevolution.helpers.BlockStateEnergyCoreStructure;
import com.cleanroommc.groovyscript.compat.mods.draconicevolution.helpers.BlockStateMultiblockStorage;
import com.cleanroommc.groovyscript.compat.mods.draconicevolution.helpers.BlockStates;
import com.cleanroommc.groovyscript.helper.Alias;
import com.cleanroommc.groovyscript.helper.ArrayUtils;
import net.minecraft.block.state.IBlockState;
import org.jetbrains.annotations.ApiStatus;

import java.util.Arrays;
import java.util.Collection;

@RegistryDescription
public class EnergyCore implements IScriptReloadable {

private int version = 0;
private BlockStates[][][][] original;
private BlockStates[][][][] edited;
private BlockStates[] inner;
private BlockStates[] outer;

private void init() {
if (this.original != null) return;
BlockStateEnergyCoreStructure bsecs = new BlockStateEnergyCoreStructure(null);
this.original = new BlockStates[bsecs.getStructureTiers().length][][][];
BlockStateMultiblockStorage[] structureTiers = bsecs.getStructureTiers();
// deep copy structure
for (int i = 0; i < structureTiers.length; i++) {
this.original[i] = ArrayUtils.deepCopy3d(structureTiers[i].getStructure(), null);
}
this.inner = new BlockStates[this.original.length];
this.outer = new BlockStates[this.original.length];
onReload(); // increases version to 1
}

@Override
public Collection<String> getAliases() {
return Alias.generateOfClass(EnergyCore.class);
}

@Override
public void onReload() {
WaitingIdly marked this conversation as resolved.
Show resolved Hide resolved
if (this.original == null) return;
this.edited = ArrayUtils.deepCopy4d(this.original, this.edited);
Arrays.fill(this.inner, BlockStates.redstone());
Arrays.fill(this.outer, BlockStates.draconium());
this.inner[this.inner.length - 1] = BlockStates.draconium();
this.outer[this.outer.length - 1] = BlockStates.draconic();
this.version++;
}

@Override
public void afterScriptLoad() {}

@GroovyBlacklist
public int getVersion() {
return version;
}

@GroovyBlacklist
@ApiStatus.Internal
public void applyEdit(BlockStateMultiblockStorage[] mbs) {
for (int i = 0; i < mbs.length; i++) {
mbs[i].setStructure(this.edited[i]);
}
}

private void replaceBlock(int tier, BlockStates edit, boolean inner) {
if (tier < 1 || tier > 8) {
GroovyLog.msg("Error setting block of Draconic Evolution Energy Core")
.add("Tier {} is invalid. Must be between 1 and 8")
.error()
.post();
return;
}
init();
BlockStates old = inner ? this.inner[tier - 1] : this.outer[tier - 1];
BlockStates[][][] blocks = this.edited[tier - 1];
for (int i = 0; i < blocks.length; i++) {
for (int j = 0; j < blocks[i].length; j++) {
for (int k = 0; k < blocks[i][j].length; k++) {
if (old == blocks[i][j][k]) {
blocks[i][j][k] = edit;
}
}
}
}
(inner ? this.inner : this.outer)[tier - 1] = edit;
}

@MethodDescription(description = "groovyscript.wiki.draconicevolution.inner_block", type = MethodDescription.Type.VALUE, example = {
@Example("7, blockstate('minecraft:stone', 1)")
})
public EnergyCore setInnerBlock(int tier, IBlockState... blockStates) {
if (blockStates == null || blockStates.length == 0) {
GroovyLog.msg("Error setting inner block of tier {} Draconic Evolution Energy Core", tier)
.add("block states must not be null or empty")
.error()
.post();
return this;
}
replaceBlock(tier, BlockStates.of(blockStates), true);
return this;
}

@MethodDescription(description = "groovyscript.wiki.draconicevolution.outer_block", type = MethodDescription.Type.VALUE, example = {
@Example("7, blockstate('minecraft:diamond_block')"),
@Example("2, blockstate('minecraft:diamond_block')")
})
public EnergyCore setOuterBlock(int tier, IBlockState... blockStates) {
if (blockStates == null || blockStates.length == 0) {
GroovyLog.msg("Error setting outer block of tier {} Draconic Evolution Energy Core", tier)
.add("block states must not be null or empty")
.error()
.post();
return this;
}
replaceBlock(tier, BlockStates.of(blockStates), false);
return this;
}
}
Loading
Loading