-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DefaultEnchantmentType, SimpleEnchantmentType, TableExclusionEnchantmentType And FilteredEnchantmentType Add FilterList, BlackList And WhiteList Change Some Mixins Update Quilt Loader
- Loading branch information
1 parent
1a8da29
commit 04ca2e1
Showing
21 changed files
with
311 additions
and
51 deletions.
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
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
26 changes: 0 additions & 26 deletions
26
src/main/java/com/mmodding/mmodding_lib/library/enchantments/EnchantmentType.java
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
...ain/java/com/mmodding/mmodding_lib/library/enchantments/types/DefaultEnchantmentType.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,25 @@ | ||
package com.mmodding.mmodding_lib.library.enchantments.types; | ||
|
||
import net.minecraft.item.EnchantedBookItem; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.text.Text; | ||
|
||
public class DefaultEnchantmentType implements EnchantmentType { | ||
|
||
DefaultEnchantmentType() {} | ||
|
||
@Override | ||
public String getQualifier() { | ||
return "default"; | ||
} | ||
|
||
@Override | ||
public Text getPrefix() { | ||
return Text.of(""); | ||
} | ||
|
||
@Override | ||
public EnchantedBookItem getEnchantedBook() { | ||
return (EnchantedBookItem) Items.ENCHANTED_BOOK; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/com/mmodding/mmodding_lib/library/enchantments/types/EnchantmentType.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,59 @@ | ||
package com.mmodding.mmodding_lib.library.enchantments.types; | ||
|
||
import com.mmodding.mmodding_lib.library.enchantments.CustomEnchantedBookItem; | ||
import com.mmodding.mmodding_lib.library.items.settings.AdvancedItemSettings; | ||
import com.mmodding.mmodding_lib.library.utils.FilterList; | ||
import net.minecraft.item.EnchantedBookItem; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.Rarity; | ||
|
||
public interface EnchantmentType { | ||
|
||
EnchantmentType DEFAULT = new DefaultEnchantmentType(); | ||
|
||
static EnchantmentType of(String qualifier, Text prefix) { | ||
return EnchantmentType.of(qualifier, prefix, new AdvancedItemSettings().maxCount(1).rarity(Rarity.UNCOMMON)); | ||
} | ||
|
||
static EnchantmentType of(String qualifier, Text prefix, boolean inEnchantingTable) { | ||
return new TableExclusionEnchantmentType(qualifier, prefix, new AdvancedItemSettings().maxCount(1).rarity(Rarity.UNCOMMON), inEnchantingTable); | ||
} | ||
|
||
static EnchantmentType of(String qualifier, Text prefix, boolean inEnchantingTable, FilterList<EnchantmentType> filter) { | ||
return new FilteredEnchantmentType(qualifier, prefix, new AdvancedItemSettings().maxCount(1).rarity(Rarity.UNCOMMON), inEnchantingTable, filter); | ||
} | ||
|
||
static EnchantmentType of(String qualifier, Text prefix, Item.Settings enchantedBookSettings) { | ||
return new SimpleEnchantmentType(qualifier, prefix, enchantedBookSettings); | ||
} | ||
|
||
static EnchantmentType of(String qualifier, Text prefix, Item.Settings enchantedBookSettings, boolean inEnchantingTable) { | ||
return new TableExclusionEnchantmentType(qualifier, prefix, enchantedBookSettings, inEnchantingTable); | ||
} | ||
|
||
static EnchantmentType of(String qualifier, Text prefix, Item.Settings enchantedBookSettings, boolean inEnchantingTable, FilterList<EnchantmentType> filter) { | ||
return new FilteredEnchantmentType(qualifier, prefix, enchantedBookSettings, inEnchantingTable, filter); | ||
} | ||
|
||
String getQualifier(); | ||
|
||
Text getPrefix(); | ||
|
||
EnchantedBookItem getEnchantedBook(); | ||
|
||
default boolean isInEnchantingTable() { | ||
return true; | ||
} | ||
|
||
default FilterList<EnchantmentType> typeCompatibilities() { | ||
return FilterList.always(); | ||
} | ||
|
||
default void register(Identifier identifier) { | ||
if (this.getEnchantedBook() instanceof CustomEnchantedBookItem item) { | ||
item.register(identifier); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...in/java/com/mmodding/mmodding_lib/library/enchantments/types/FilteredEnchantmentType.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,20 @@ | ||
package com.mmodding.mmodding_lib.library.enchantments.types; | ||
|
||
import com.mmodding.mmodding_lib.library.utils.FilterList; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.text.Text; | ||
|
||
public class FilteredEnchantmentType extends TableExclusionEnchantmentType { | ||
|
||
private final FilterList<EnchantmentType> filterList; | ||
|
||
FilteredEnchantmentType(String qualifier, Text prefix, Item.Settings enchantedBookSettings, boolean inEnchantingTable, FilterList<EnchantmentType> filterList) { | ||
super(qualifier, prefix, enchantedBookSettings, inEnchantingTable); | ||
this.filterList = filterList; | ||
} | ||
|
||
@Override | ||
public FilterList<EnchantmentType> typeCompatibilities() { | ||
return this.filterList; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...main/java/com/mmodding/mmodding_lib/library/enchantments/types/SimpleEnchantmentType.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,34 @@ | ||
package com.mmodding.mmodding_lib.library.enchantments.types; | ||
|
||
import com.mmodding.mmodding_lib.library.enchantments.CustomEnchantedBookItem; | ||
import net.minecraft.item.EnchantedBookItem; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.text.Text; | ||
|
||
public class SimpleEnchantmentType implements EnchantmentType { | ||
|
||
private final String qualifier; | ||
private final Text prefix; | ||
private final EnchantedBookItem enchantedBook; | ||
|
||
SimpleEnchantmentType(String qualifier, Text prefix, Item.Settings enchantedBookSettings) { | ||
this.qualifier = qualifier; | ||
this.prefix = prefix; | ||
this.enchantedBook = new CustomEnchantedBookItem(this, enchantedBookSettings); | ||
} | ||
|
||
@Override | ||
public String getQualifier() { | ||
return this.qualifier; | ||
} | ||
|
||
@Override | ||
public Text getPrefix() { | ||
return this.prefix; | ||
} | ||
|
||
@Override | ||
public EnchantedBookItem getEnchantedBook() { | ||
return this.enchantedBook; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...a/com/mmodding/mmodding_lib/library/enchantments/types/TableExclusionEnchantmentType.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,19 @@ | ||
package com.mmodding.mmodding_lib.library.enchantments.types; | ||
|
||
import net.minecraft.item.Item; | ||
import net.minecraft.text.Text; | ||
|
||
public class TableExclusionEnchantmentType extends SimpleEnchantmentType { | ||
|
||
private final boolean inEnchantingTable; | ||
|
||
TableExclusionEnchantmentType(String qualifier, Text prefix, Item.Settings enchantedBookSettings, boolean inEnchantingTable) { | ||
super(qualifier, prefix, enchantedBookSettings); | ||
this.inEnchantingTable = inEnchantingTable; | ||
} | ||
|
||
@Override | ||
public boolean isInEnchantingTable() { | ||
return this.inEnchantingTable; | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
src/main/java/com/mmodding/mmodding_lib/library/utils/BlackList.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,18 @@ | ||
package com.mmodding.mmodding_lib.library.utils; | ||
|
||
import java.util.List; | ||
|
||
public class BlackList<E> implements FilterList<E> { | ||
|
||
private final List<E> elements; | ||
|
||
@SafeVarargs | ||
public BlackList(E... elements) { | ||
this.elements = List.of(elements); | ||
} | ||
|
||
@Override | ||
public boolean check(E element) { | ||
return !this.elements.contains(element); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/mmodding/mmodding_lib/library/utils/FilterList.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,14 @@ | ||
package com.mmodding.mmodding_lib.library.utils; | ||
|
||
public interface FilterList<E> { | ||
|
||
static <E> FilterList<E> always() { | ||
return element -> true; | ||
} | ||
|
||
static <E> FilterList<E> never() { | ||
return element -> false; | ||
} | ||
|
||
boolean check(E element); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/mmodding/mmodding_lib/library/utils/WhiteList.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,18 @@ | ||
package com.mmodding.mmodding_lib.library.utils; | ||
|
||
import java.util.List; | ||
|
||
public class WhiteList<E> implements FilterList<E> { | ||
|
||
private final List<E> elements; | ||
|
||
@SafeVarargs | ||
public WhiteList(E... elements) { | ||
this.elements = List.of(elements); | ||
} | ||
|
||
@Override | ||
public boolean check(E element) { | ||
return this.elements.contains(element); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/mmodding/mmodding_lib/mixin/injectors/AnvilScreenHandlerMixin.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,24 @@ | ||
package com.mmodding.mmodding_lib.mixin.injectors; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.mmodding.mmodding_lib.library.enchantments.CustomEnchantedBookItem; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.screen.AnvilScreenHandler; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(AnvilScreenHandler.class) | ||
public class AnvilScreenHandlerMixin { | ||
|
||
@WrapOperation(method = "updateResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z", ordinal = 0)) | ||
private boolean updateResultFirst(ItemStack stack, Item item, Operation<Boolean> original) { | ||
return stack.getItem() instanceof CustomEnchantedBookItem || original.call(stack, item); | ||
} | ||
|
||
@WrapOperation(method = "updateResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z", ordinal = 2)) | ||
private boolean updateResultSecond(ItemStack stack, Item item, Operation<Boolean> original) { | ||
return stack.getItem() instanceof CustomEnchantedBookItem || original.call(stack, item); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/mmodding/mmodding_lib/mixin/injectors/EnchantedBookItemMixin.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,23 @@ | ||
package com.mmodding.mmodding_lib.mixin.injectors; | ||
|
||
import com.google.common.collect.Iterators; | ||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue; | ||
import com.mmodding.mmodding_lib.library.enchantments.CustomEnchantment; | ||
import com.mmodding.mmodding_lib.library.enchantments.types.EnchantmentType; | ||
import net.minecraft.enchantment.Enchantment; | ||
import net.minecraft.item.EnchantedBookItem; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
import java.util.Iterator; | ||
|
||
@Mixin(EnchantedBookItem.class) | ||
public class EnchantedBookItemMixin { | ||
|
||
@ModifyExpressionValue(method = "appendStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/registry/Registry;iterator()Ljava/util/Iterator;")) | ||
private Iterator<Enchantment> appendStacks(Iterator<Enchantment> original) { | ||
return Iterators.filter( | ||
original, enchantment -> !(enchantment instanceof CustomEnchantment customEnchantment) || customEnchantment.getType() == EnchantmentType.DEFAULT | ||
); | ||
} | ||
} |
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
Oops, something went wrong.