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

Chisel compat #61

Merged
merged 6 commits into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ dependencies {

implementation 'mezz.jei:jei_1.12.2:4.16.1.302'

compileOnly rfg.deobf("curse.maven:ctm-267602:2915363")
compileOnly rfg.deobf("curse.maven:chisel-235279:2915375")
if (project.debug_chisel.toBoolean()) {
runtimeOnly rfg.deobf('curse.maven:ctm-267602:2915363')
runtimeOnly rfg.deobf('curse.maven:chisel-235279:2915375')
}

compileOnly rfg.deobf('curse.maven:mekanism-268560:2835175')
if (project.debug_mekanism.toBoolean()) {
runtimeOnly rfg.deobf('curse.maven:mekanism-268560:2835175')
Expand Down
22 changes: 22 additions & 0 deletions examples/chisel.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Carving
mods.chisel.carving.addGroup('demo')
mods.chisel.carving.removeGroup('blockDiamond')

mods.chisel.carving.removeVariation('antiblock', item('chisel:antiblock:3'))
mods.chisel.carving.removeVariation('antiblock', item('chisel:antiblock:15'))
mods.chisel.carving.addVariation('demo', item('minecraft:diamond_block'))
mods.chisel.carving.addVariation('demo', item('chisel:antiblock:3'))
mods.chisel.carving.addVariation('demo', item('minecraft:sea_lantern'))

// Set the sound of the Variation
mods.chisel.carving.setSound('demo', sound('block.glass.break'))

// You cannot addVariation/removeVariation to chisel groups based on the oredict, you have to modify the oredict directly.
oredict.add('blockCoal', item('chisel:antiblock:15'))
oredict.remove('blockCoal', item('minecraft:coal_block'))

// Can also run multiple operations on a group, creating the group if it didnt exist prior:
mods.chisel.carving.carvingGroup('valentines')
.remove(item('chisel:valentines'), item('chisel:valentines:1'), item('chisel:valentines:2'), item('chisel:valentines:3'))
.add(item('minecraft:grass'), item('minecraft:diamond_ore'))
.sound(sound('block.anvil.destroy'))
File renamed without changes.
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ debug_load_all_mods = true
coremod_plugin_class_name = com.cleanroommc.groovyscript.core.GroovyScriptCore

# Debug mod compat
debug_chisel = false
debug_mekanism = false
debug_thermal = false
debug_thaum = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public static void init() {
registerBracketHandler("blockstate", BlockStateBracketHandler.INSTANCE);
registerBracketHandler("enchantment", Enchantment::getEnchantmentByLocation);
registerBracketHandler("potion", Potion::getPotionFromResourceLocation);
registerBracketHandler("sound", s -> ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(s)));
registerBracketHandler("entity", s -> ForgeRegistries.ENTITIES.getValue(new ResourceLocation(s)));
registerBracketHandler("creativeTab", s -> {
if (!NetworkUtils.isDedicatedClient()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.cleanroommc.groovyscript.compat.mods.astralsorcery.AstralSorcery;
import com.cleanroommc.groovyscript.compat.mods.bloodmagic.BloodMagic;
import com.cleanroommc.groovyscript.compat.mods.botania.Botania;
import com.cleanroommc.groovyscript.compat.mods.chisel.Chisel;
import com.cleanroommc.groovyscript.compat.mods.draconicevolution.DraconicEvolution;
import com.cleanroommc.groovyscript.compat.mods.enderio.EnderIO;
import com.cleanroommc.groovyscript.compat.mods.extendedcrafting.ExtendedCrafting;
Expand Down Expand Up @@ -36,6 +37,7 @@ public class ModSupport implements IDynamicGroovyProperty {

public static final ModSupport INSTANCE = new ModSupport(); // Just for Binding purposes

public static final Container<Chisel> CHISEL = new Container<>("chisel", "Chisel", Chisel::new);
public static final Container<AstralSorcery> ASTRAL_SORCERY = new Container<>("astralsorcery", "Astral Sorcery", AstralSorcery::new, "astral", "astral_sorcery", "as");
public static final Container<EnderIO> ENDER_IO = new Container<>("enderio", "Ender IO", EnderIO::new, "eio");
public static final Container<JustEnoughItems> JEI = new Container<>("jei", "Just Enough Items", JustEnoughItems::new, "hei");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
package com.cleanroommc.groovyscript.compat.mods.chisel;

import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.compat.mods.ModSupport;
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import net.minecraft.item.ItemStack;
import net.minecraft.util.SoundEvent;
import org.apache.commons.lang3.tuple.Pair;
import team.chisel.api.carving.CarvingUtils;
import team.chisel.api.carving.ICarvingGroup;
import team.chisel.api.carving.ICarvingRegistry;

import java.util.ArrayList;
import java.util.Collection;

public class Carving extends VirtualizedRegistry<Pair<String, ItemStack>> {

private static final ICarvingRegistry registry = CarvingUtils.getChiselRegistry();
WaitingIdly marked this conversation as resolved.
Show resolved Hide resolved

private ArrayList<Pair<String, SoundEvent>> sounds;
private ArrayList<String> groupBackup;
private ArrayList<String> groupScripted;

public Carving() {
super();
this.sounds = new ArrayList<>();
this.groupBackup = new ArrayList<>();
this.groupScripted = new ArrayList<>();
}

public static CarvingGroup carvingGroup(String group) {
return new CarvingGroup(group);
}

@Override
public void onReload() {
removeScripted().forEach(pair -> registry.removeVariation(pair.getValue(), pair.getKey()));
restoreFromBackup().forEach(pair -> registry.addVariation(pair.getKey(), CarvingUtils.variationFor(pair.getValue(), 0)));

this.sounds.forEach(pair -> registry.setVariationSound(pair.getKey(), pair.getValue()));
this.groupBackup.forEach(group -> registry.addGroup(CarvingUtils.getDefaultGroupFor(group)));
this.groupScripted.forEach(registry::removeGroup);

this.sounds = new ArrayList<>();
this.groupBackup = new ArrayList<>();
this.groupScripted = new ArrayList<>();
}

public void addVariation(String groupName, ItemStack item) {
try {
registry.addVariation(groupName, CarvingUtils.variationFor(item, 0));
addScripted(Pair.of(groupName, item));
} catch (UnsupportedOperationException e) {
GroovyLog.msg("Error adding a Chisel Carving variation")
.add("you cannot add variations to Oredict chisel groups {}", groupName)
.add("instead, edit the oredict via `oredict.add('{}', {})`", groupName, IngredientHelper.asGroovyCode(item, false))
.error()
.post();
}
}

public void removeVariation(String groupName, ItemStack item) {
try {
registry.removeVariation(item, groupName);
addBackup(Pair.of(groupName, item));
} catch (UnsupportedOperationException e) {
GroovyLog.msg("Error removing a Chisel Carving variation")
.add("you cannot remove variations to Oredict chisel groups {}", groupName)
.add("instead, edit the oredict via `oredict.remove('{}', {})`", groupName, IngredientHelper.asGroovyCode(item, false))
.error()
.post();
}
}

public void setSound(String group, SoundEvent sound) {
ICarvingGroup carvingGroup = registry.getGroup(group);
if (carvingGroup == null) {
GroovyLog.msg("Error setting the sound for a Chisel Carving group")
.add("could not find a Carving Group with the name {}", group)
.error()
.post();
return;
}
setSound(carvingGroup, sound);
}

public void setSound(ICarvingGroup group, SoundEvent sound) {
registry.setVariationSound(group.getName(), sound);
this.sounds.add(Pair.of(group.getName(), group.getSound()));
}

public void addGroup(String groupName) {
if (registry.getSortedGroupNames().contains(groupName)) {
GroovyLog.msg("Error adding Chisel Carving group")
.add("found a duplicate Chisel Carving group with name {}", groupName)
.error()
.post();
return;
}
registry.addGroup(CarvingUtils.getDefaultGroupFor(groupName));
this.groupScripted.add(groupName);
}

public void removeGroup(String groupName) {
if (!registry.getSortedGroupNames().contains(groupName)) {
GroovyLog.msg("Error removing Chisel Carving group")
.add("could not find Chisel Carving group with name {}", groupName)
.error()
.post();
return;
}
registry.removeGroup(groupName);
this.groupBackup.add(groupName);
}

public void removeAll() {
registry.getSortedGroupNames().forEach(name -> {
registry.removeGroup(name);
this.groupBackup.add(name);
});
}


public static class CarvingGroup {

ICarvingGroup group;

public CarvingGroup(String group) {
if (registry == null) {
GroovyLog.msg("Error finding or creating Chisel Carving group")
.add("Chisel Registry not yet initialized {}")
.error()
.post();
return;
}
if (!registry.getSortedGroupNames().contains(group)) ModSupport.CHISEL.get().carving.addGroup(group);
this.group = registry.getGroup(group);
}

public CarvingGroup sound(SoundEvent sound) {
ModSupport.CHISEL.get().carving.setSound(group, sound);
return this;
}

public CarvingGroup add(ItemStack item) {
ModSupport.CHISEL.get().carving.addVariation(this.group.getName(), item);
return this;
}

public CarvingGroup add(ItemStack... items) {
for (ItemStack item : items) {
add(item);
}
return this;
}

public CarvingGroup add(Collection<ItemStack> items) {
for (ItemStack item : items) {
WaitingIdly marked this conversation as resolved.
Show resolved Hide resolved
add(item);
}
return this;
}

public CarvingGroup remove(ItemStack item) {
ModSupport.CHISEL.get().carving.removeVariation(this.group.getName(), item);
return this;
}

public CarvingGroup remove(ItemStack... items) {
for (ItemStack item : items) {
remove(item);
}
return this;
}

public CarvingGroup remove(Collection<ItemStack> items) {
for (ItemStack item : items) {
remove(item);
}
return this;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.cleanroommc.groovyscript.compat.mods.chisel;

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

public class Chisel extends ModPropertyContainer {

Carving carving = new Carving();
brachy84 marked this conversation as resolved.
Show resolved Hide resolved

public Chisel() {
addRegistry(carving);
}

}