generated from CleanroomMC/ForgeDevEnv
-
Notifications
You must be signed in to change notification settings - Fork 31
Chisel compat #61
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
Merged
Merged
Chisel compat #61
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fd59082
add sound bracket handler
WaitingIdly 8db54ea
add Chisel compat
WaitingIdly b527a7a
fix typo in example file name
WaitingIdly 8f624d2
remove testing code
WaitingIdly caea395
address review
WaitingIdly 97669b2
reviews
brachy84 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,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.
This file contains hidden or 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 hidden or 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 hidden or 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
184 changes: 184 additions & 0 deletions
184
src/main/java/com/cleanroommc/groovyscript/compat/mods/chisel/Carving.java
This file contains hidden or 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,184 @@ | ||
| 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; | ||
| import java.util.List; | ||
|
|
||
| public class Carving extends VirtualizedRegistry<Pair<String, ItemStack>> { | ||
|
|
||
| private static ICarvingRegistry getRegistry() { | ||
| if (CarvingUtils.getChiselRegistry() == null) { | ||
| throw new IllegalStateException("Chisel carving getRegistry() is not yet initialized!"); | ||
| } | ||
| return CarvingUtils.getChiselRegistry(); | ||
| } | ||
|
|
||
| private List<Pair<String, SoundEvent>> sounds; | ||
| private List<String> groupBackup; | ||
| private List<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 -> getRegistry().removeVariation(pair.getValue(), pair.getKey())); | ||
| restoreFromBackup().forEach(pair -> getRegistry().addVariation(pair.getKey(), CarvingUtils.variationFor(pair.getValue(), 0))); | ||
|
|
||
| this.sounds.forEach(pair -> getRegistry().setVariationSound(pair.getKey(), pair.getValue())); | ||
| this.groupBackup.forEach(group -> getRegistry().addGroup(CarvingUtils.getDefaultGroupFor(group))); | ||
| this.groupScripted.forEach(getRegistry()::removeGroup); | ||
|
|
||
| this.sounds = new ArrayList<>(); | ||
| this.groupBackup = new ArrayList<>(); | ||
| this.groupScripted = new ArrayList<>(); | ||
| } | ||
|
|
||
| public void addVariation(String groupName, ItemStack item) { | ||
| try { | ||
| getRegistry().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 { | ||
| getRegistry().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 = getRegistry().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) { | ||
| getRegistry().setVariationSound(group.getName(), sound); | ||
| this.sounds.add(Pair.of(group.getName(), group.getSound())); | ||
| } | ||
|
|
||
| public void addGroup(String groupName) { | ||
| if (getRegistry().getSortedGroupNames().contains(groupName)) { | ||
| GroovyLog.msg("Error adding Chisel Carving group") | ||
| .add("found a duplicate Chisel Carving group with name {}", groupName) | ||
| .error() | ||
| .post(); | ||
| return; | ||
| } | ||
| getRegistry().addGroup(CarvingUtils.getDefaultGroupFor(groupName)); | ||
| this.groupScripted.add(groupName); | ||
| } | ||
|
|
||
| public void removeGroup(String groupName) { | ||
| if (!getRegistry().getSortedGroupNames().contains(groupName)) { | ||
| GroovyLog.msg("Error removing Chisel Carving group") | ||
| .add("could not find Chisel Carving group with name {}", groupName) | ||
| .error() | ||
| .post(); | ||
| return; | ||
| } | ||
| getRegistry().removeGroup(groupName); | ||
| this.groupBackup.add(groupName); | ||
| } | ||
|
|
||
| public void removeAll() { | ||
| getRegistry().getSortedGroupNames().forEach(name -> { | ||
| getRegistry().removeGroup(name); | ||
| this.groupBackup.add(name); | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| public static class CarvingGroup { | ||
|
|
||
| private final ICarvingGroup group; | ||
|
|
||
| public CarvingGroup(String group) { | ||
| if (!getRegistry().getSortedGroupNames().contains(group)) ModSupport.CHISEL.get().carving.addGroup(group); | ||
| this.group = getRegistry().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) { | ||
| 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; | ||
| } | ||
| } | ||
|
|
||
| } | ||
13 changes: 13 additions & 0 deletions
13
src/main/java/com/cleanroommc/groovyscript/compat/mods/chisel/Chisel.java
This file contains hidden or 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.compat.mods.chisel; | ||
|
|
||
| import com.cleanroommc.groovyscript.compat.mods.ModPropertyContainer; | ||
|
|
||
| public class Chisel extends ModPropertyContainer { | ||
|
|
||
| public final Carving carving = new Carving(); | ||
|
|
||
| public Chisel() { | ||
| addRegistry(carving); | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.