generated from CleanroomMC/TemplateDevEnv
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
235 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
src/main/java/com/cleanroommc/groovyscript/compat/mods/draconicevolution/EnergyCore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package com.cleanroommc.groovyscript.compat.mods.draconicevolution; | ||
|
||
import com.brandon3055.brandonscore.lib.MultiBlockStorage; | ||
import com.brandon3055.draconicevolution.world.EnergyCoreStructure; | ||
import com.cleanroommc.groovyscript.api.GroovyBlacklist; | ||
import com.cleanroommc.groovyscript.api.GroovyLog; | ||
import com.cleanroommc.groovyscript.api.IScriptReloadable; | ||
import com.cleanroommc.groovyscript.core.mixin.draconicevolution.EnergyCoreStructureAccessor; | ||
import com.cleanroommc.groovyscript.core.mixin.draconicevolution.MultiBlockStorageAccessor; | ||
import com.cleanroommc.groovyscript.helper.Alias; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraftforge.fml.common.registry.ForgeRegistries; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
public class EnergyCore implements IScriptReloadable { | ||
|
||
private static final String DRACONIUM = "draconicevolution:draconium_block"; | ||
private static final String DRACONIC = "draconicevolution:draconic_block"; | ||
private static final String REDSTONE = "minecraft:redstone_block"; | ||
|
||
private int version = 0; | ||
private MultiBlockStorage[] original; | ||
private MultiBlockStorage[] edited; | ||
private String[] inner; | ||
private String[] outer; | ||
|
||
private void init() { | ||
if (this.original != null) return; | ||
EnergyCoreStructure ecs = new EnergyCoreStructure(); | ||
ecs.initialize(null); | ||
this.original = ((EnergyCoreStructureAccessor) ecs).getStructureTiers(); | ||
this.edited = Arrays.copyOf(this.original, this.original.length); | ||
this.inner = new String[this.original.length]; | ||
this.outer = new String[this.original.length]; | ||
onReload(); // increases version to 1 | ||
} | ||
|
||
@Override | ||
public Collection<String> getAliases() { | ||
return Alias.generateOfClass(EnergyCore.class); | ||
} | ||
|
||
@Override | ||
public void onReload() { | ||
if (this.original == null) return; | ||
this.edited = Arrays.copyOf(this.original, this.original.length); | ||
Arrays.fill(this.inner, REDSTONE); | ||
Arrays.fill(this.outer, DRACONIUM); | ||
this.inner[this.inner.length - 1] = DRACONIUM; | ||
this.outer[this.outer.length - 1] = DRACONIC; | ||
this.version++; | ||
} | ||
|
||
@Override | ||
public void afterScriptLoad() {} | ||
|
||
@GroovyBlacklist | ||
public int getVersion() { | ||
return version; | ||
} | ||
|
||
@GroovyBlacklist | ||
@ApiStatus.Internal | ||
public void applyEdit(MultiBlockStorage[] mbs) { | ||
for (int i = 0; i < mbs.length; i++) { | ||
((MultiBlockStorageAccessor) mbs[i]).setBlockStorage(((MultiBlockStorageAccessor) this.edited[i]).getBlockStorage()); | ||
} | ||
} | ||
|
||
private void replaceBlock(int tier, String 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(); | ||
String old = inner ? this.inner[tier - 1] : this.outer[tier - 1]; | ||
String[][][] blocks = ((MultiBlockStorageAccessor) this.edited[tier - 1]).getBlockStorage(); | ||
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.equals(blocks[i][j][k])) { | ||
blocks[i][j][k] = edit; | ||
} | ||
} | ||
} | ||
} | ||
(inner ? this.inner : this.outer)[tier - 1] = edit; | ||
} | ||
|
||
public EnergyCore setInnerBlock(int tier, String id) { | ||
if (!ForgeRegistries.BLOCKS.containsKey(new ResourceLocation(id))) { | ||
GroovyLog.get().error("Can't set block '{}' as inner block of tier {} of Draconic Evolution Energy Core, because the block doesn't exist!", id, tier); | ||
return this; | ||
} | ||
replaceBlock(tier, id, true); | ||
return this; | ||
} | ||
|
||
public EnergyCore setOuterBlock(int tier, String id) { | ||
if (!ForgeRegistries.BLOCKS.containsKey(new ResourceLocation(id))) { | ||
GroovyLog.get().error("Can't set block '{}' as outer block of tier {} of Draconic Evolution Energy Core, because the block doesn't exist!", id, tier); | ||
return this; | ||
} | ||
replaceBlock(tier, id, false); | ||
return this; | ||
} | ||
|
||
public EnergyCore setInnerBlock(int tier, Block block) { | ||
if (block == null) { | ||
GroovyLog.msg("Error setting inner block of tier {} Draconic Evolution Energy Core", tier) | ||
.add("block must not be null") | ||
.error() | ||
.post(); | ||
return this; | ||
} | ||
replaceBlock(tier, block.getRegistryName().toString(), true); | ||
return this; | ||
} | ||
|
||
public EnergyCore setOuterBlock(int tier, Block block) { | ||
if (block == null) { | ||
GroovyLog.msg("Error setting outer block of tier {} Draconic Evolution Energy Core", tier) | ||
.add("block must not be null") | ||
.error() | ||
.post(); | ||
return this; | ||
} | ||
replaceBlock(tier, block.getRegistryName().toString(), false); | ||
return this; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...om/cleanroommc/groovyscript/core/mixin/draconicevolution/EnergyCoreStructureAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.cleanroommc.groovyscript.core.mixin.draconicevolution; | ||
|
||
import com.brandon3055.brandonscore.lib.MultiBlockStorage; | ||
import com.brandon3055.draconicevolution.world.EnergyCoreStructure; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(EnergyCoreStructure.class) | ||
public interface EnergyCoreStructureAccessor { | ||
|
||
@Accessor | ||
MultiBlockStorage[] getStructureTiers(); | ||
} |
61 changes: 61 additions & 0 deletions
61
...a/com/cleanroommc/groovyscript/core/mixin/draconicevolution/EnergyCoreStructureMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.cleanroommc.groovyscript.core.mixin.draconicevolution; | ||
|
||
import com.brandon3055.brandonscore.lib.MultiBlockStorage; | ||
import com.brandon3055.draconicevolution.blocks.tileentity.TileEnergyStorageCore; | ||
import com.brandon3055.draconicevolution.utils.LogHelper; | ||
import com.brandon3055.draconicevolution.world.EnergyCoreStructure; | ||
import com.cleanroommc.groovyscript.compat.mods.ModSupport; | ||
import net.minecraft.util.math.BlockPos; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(value = EnergyCoreStructure.class, remap = false) | ||
public abstract class EnergyCoreStructureMixin { | ||
|
||
@Shadow | ||
private MultiBlockStorage[] structureTiers; | ||
@Shadow | ||
private TileEnergyStorageCore core; | ||
|
||
@Shadow | ||
public abstract BlockPos getCoreOffset(int tier); | ||
|
||
@Unique | ||
private int groovyScript$version = 0; | ||
|
||
@Inject(method = "checkTier", at = @At("HEAD"), cancellable = true) | ||
public void checkTier(int tier, CallbackInfoReturnable<Boolean> cir) { | ||
// check if the structure was edited and update | ||
if (groovyScript$version != ModSupport.DRACONIC_EVOLUTION.get().energyCore.getVersion()) { | ||
groovyScript$version = ModSupport.DRACONIC_EVOLUTION.get().energyCore.getVersion(); | ||
ModSupport.DRACONIC_EVOLUTION.get().energyCore.applyEdit(structureTiers); | ||
} | ||
// this part is the same as de | ||
// I just do this because theirs is ugly | ||
if (tier <= 0) { | ||
LogHelper.error("[EnergyCoreStructure] Tier value to small. As far as TileEnergyStorageCore is concerned the tiers now start at 1 not 0. This class automatically handles the conversion now"); | ||
cir.setReturnValue(false); | ||
return; | ||
} | ||
if (tier > 8) { | ||
LogHelper.error("[EnergyCoreStructure#checkTeir] What exactly were you expecting after Tier 8? Infinity.MAX_VALUE?"); | ||
cir.setReturnValue(false); | ||
return; | ||
} | ||
cir.setReturnValue(this.structureTiers[tier - 1].checkStructure(this.core.getWorld(), this.core.getPos().add(getCoreOffset(tier)))); | ||
} | ||
|
||
@Inject(method = "forTier", at = @At("HEAD")) | ||
private void forTier(int tier, int flag, CallbackInfo ci) { | ||
// check if the structure was edited and update | ||
if (groovyScript$version != ModSupport.DRACONIC_EVOLUTION.get().energyCore.getVersion()) { | ||
groovyScript$version = ModSupport.DRACONIC_EVOLUTION.get().energyCore.getVersion(); | ||
ModSupport.DRACONIC_EVOLUTION.get().energyCore.applyEdit(structureTiers); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
.../com/cleanroommc/groovyscript/core/mixin/draconicevolution/MultiBlockStorageAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.cleanroommc.groovyscript.core.mixin.draconicevolution; | ||
|
||
import com.brandon3055.brandonscore.lib.MultiBlockStorage; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(MultiBlockStorage.class) | ||
public interface MultiBlockStorageAccessor { | ||
|
||
@Accessor | ||
String[][][] getBlockStorage(); | ||
|
||
@Accessor | ||
void setBlockStorage(String[][][] blockStorage); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters