-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Continued to fix #203, Completed EnchantmentRestriction, Updated Loader
- Mechanised Sawblade now mines wood - System for prohibiting and permitting enchants in place - Updated Fabric Loader to 0.14.19 - Updated Fabric Version to 0.76.0+1.19.2
- Loading branch information
1 parent
ad91a1f
commit 4e86ee7
Showing
10 changed files
with
110 additions
and
156 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
15 changes: 0 additions & 15 deletions
15
src/main/java/chronosacaria/mcdw/api/interfaces/CustomConditionalEnchantment.java
This file was deleted.
Oops, something went wrong.
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
19 changes: 0 additions & 19 deletions
19
src/main/java/chronosacaria/mcdw/mixin/DamageEnchantmentMixin.java
This file was deleted.
Oops, something went wrong.
66 changes: 20 additions & 46 deletions
66
src/main/java/chronosacaria/mcdw/mixin/EnchantmentHelperMixin.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 |
---|---|---|
@@ -1,65 +1,39 @@ | ||
package chronosacaria.mcdw.mixin; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import net.minecraft.enchantment.Enchantment; | ||
import net.minecraft.enchantment.EnchantmentHelper; | ||
import net.minecraft.enchantment.EnchantmentLevelEntry; | ||
import net.minecraft.enchantment.EnchantmentTarget; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.nbt.NbtElement; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.registry.Registry; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
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.CallbackInfoReturnable; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* This code is used with the permission of <a href = "https://github.com/ZsoltMolnarrr">Daedelus</a>. <br /> | ||
* The original code is from SpellEngine and can be found <a href = "https://github.com/ZsoltMolnarrr/SpellEngine/blob/1.19.2/common/src/main/java/net/spell_engine/mixin/enchant/EnchantmentHelperMixin.java">here</a>. | ||
*/ | ||
|
||
@Mixin(EnchantmentHelper.class) | ||
public class EnchantmentHelperMixin { | ||
|
||
@Inject(method = "getPossibleEntries", at = @At(value = "RETURN"), cancellable = true) | ||
private static void mcdw$permitInnateEnchantmentsToBeEnchantedButNotWithConflicts(int power, ItemStack stack, boolean treasureAllowed, | ||
CallbackInfoReturnable<List<EnchantmentLevelEntry>> cir) { | ||
List<EnchantmentLevelEntry> list = cir.getReturnValue(); | ||
for (NbtElement enchantmentNbt : stack.getEnchantments()) { | ||
NbtCompound nbtCompound = (NbtCompound) enchantmentNbt; | ||
Identifier identifier = EnchantmentHelper.getIdFromNbt(nbtCompound); | ||
Enchantment enchantmentOnStack = Registry.ENCHANTMENT.get(identifier); | ||
// If can find enchants, remove incompatible options from the list of randomly enchant-able enchantments | ||
if (enchantmentOnStack != null) | ||
list.removeIf(enchantmentLevelEntry -> !enchantmentLevelEntry.enchantment.canCombine(enchantmentOnStack)); | ||
} | ||
cir.setReturnValue(list); | ||
@Unique | ||
private static Enchantment mixedInEnchantment; | ||
|
||
// Add extra entries from those which were rejected by Vanilla logic | ||
@WrapOperation(method = "getPossibleEntries", at = @At(value = "FIELD", target = "Lnet/minecraft/enchantment/Enchantment;type:Lnet/minecraft/enchantment/EnchantmentTarget;")) | ||
private static EnchantmentTarget mcdw$getEnchantmentContext(Enchantment enchantment, Operation<EnchantmentTarget> type) { | ||
mixedInEnchantment = enchantment; | ||
return type.call(); | ||
} | ||
|
||
// Or should this be used? \/\/ | ||
var currentEntries = cir.getReturnValue(); | ||
@WrapOperation(method = "getPossibleEntries", at = @At(value = "INVOKE", target = "Lnet/minecraft/enchantment/EnchantmentTarget;isAcceptableItem(Lnet/minecraft/item/Item;)Z")) | ||
private static boolean mcdw$getPossibleEntries(EnchantmentTarget enchantmentTarget, Item item, Operation<Boolean> returnValue, int power, ItemStack stack, boolean treasureAllowed) { | ||
|
||
// This logic is mostly copied from EnchantmentHelper.getPossibleEntries | ||
Item item = stack.getItem(); | ||
boolean isBook = stack.isOf(Items.BOOK); | ||
block0: for (Enchantment enchantment : Registry.ENCHANTMENT) { | ||
// Don't check things already added | ||
boolean alreadyAdded = currentEntries.stream().anyMatch(entry -> entry.enchantment.equals(enchantment)); | ||
if (alreadyAdded) { continue; } | ||
return (!(mixedInEnchantment.isTreasure() | ||
&& !treasureAllowed | ||
|| !mixedInEnchantment.isAvailableForRandomSelection() | ||
|| !mixedInEnchantment.isAcceptableItem(stack) // Custom logic, replacing `!enchantment.type.isAcceptableItem(item)` | ||
&& !isBook)); | ||
|
||
if (enchantment.isTreasure() | ||
&& !treasureAllowed | ||
|| !enchantment.isAvailableForRandomSelection() | ||
|| !enchantment.isAcceptableItem(stack) // Custom logic, replacing `!enchantment.type.isAcceptableItem(item)` | ||
&& !isBook) continue; | ||
for (int i = enchantment.getMaxLevel(); i > enchantment.getMinLevel() - 1; --i) { | ||
if (power < enchantment.getMinPower(i) || power > enchantment.getMaxPower(i)) continue; | ||
currentEntries.add(new EnchantmentLevelEntry(enchantment, i)); | ||
continue block0; | ||
} | ||
} | ||
} | ||
} |
39 changes: 11 additions & 28 deletions
39
src/main/java/chronosacaria/mcdw/mixin/EnchantmentMixin.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 |
---|---|---|
@@ -1,47 +1,30 @@ | ||
package chronosacaria.mcdw.mixin; | ||
|
||
import chronosacaria.mcdw.bases.McdwAxe; | ||
import chronosacaria.mcdw.bases.McdwCustomWeaponBase; | ||
import chronosacaria.mcdw.bases.McdwDoubleAxe; | ||
import chronosacaria.mcdw.enums.DaggersID; | ||
import chronosacaria.mcdw.registries.EnchantsRegistry; | ||
import chronosacaria.mcdw.api.util.EnchantmentRestriction; | ||
import net.minecraft.enchantment.Enchantment; | ||
import net.minecraft.enchantment.EnchantmentTarget; | ||
import net.minecraft.enchantment.Enchantments; | ||
import net.minecraft.item.ItemStack; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.Arrays; | ||
|
||
@Mixin(Enchantment.class) | ||
public abstract class EnchantmentMixin { | ||
public class EnchantmentMixin { | ||
|
||
@Shadow @Final public EnchantmentTarget type; | ||
@Inject(method = "isAcceptableItem", at = @At("HEAD"), cancellable = true) | ||
public void mcdw$isAcceptableItem(ItemStack stack, CallbackInfoReturnable<Boolean> cir) { | ||
var enchantment = (Enchantment)((Object)this); | ||
|
||
@Inject(method = "isAcceptableItem", at = @At("RETURN"), cancellable = true) | ||
|
||
private void mcdw$isAcceptablePlz(ItemStack stack, CallbackInfoReturnable<Boolean> cir){ | ||
if ((stack.getItem() instanceof McdwAxe || stack.getItem() instanceof McdwDoubleAxe) | ||
&& mcdw$isEnchantment(Enchantments.FIRE_ASPECT)) { | ||
cir.setReturnValue(true); | ||
} | ||
if (stack.getItem() instanceof McdwCustomWeaponBase | ||
&& this.type.equals(EnchantmentTarget.WEAPON)){ | ||
cir.setReturnValue(true); | ||
if (EnchantmentRestriction.isProhibited(enchantment, stack)) { | ||
cir.setReturnValue(false); | ||
cir.cancel(); | ||
} | ||
if (stack.isOf(DaggersID.DAGGER_SWIFT_STRIKER.getItem()) | ||
&& mcdw$isEnchantment(EnchantsRegistry.ECHO, EnchantsRegistry.AMBUSH)){ | ||
|
||
if (EnchantmentRestriction.isPermitted(enchantment, stack)) { | ||
cir.setReturnValue(true); | ||
cir.cancel(); | ||
} | ||
} | ||
|
||
private boolean mcdw$isEnchantment(Enchantment ...enchantments){ | ||
return Arrays.stream(enchantments).toList().contains((Enchantment) (Object) this); | ||
} | ||
} | ||
|
15 changes: 15 additions & 0 deletions
15
src/main/java/chronosacaria/mcdw/registries/EnchantmentRestrictionsRegistry.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 chronosacaria.mcdw.registries; | ||
|
||
import chronosacaria.mcdw.api.util.EnchantmentRestriction; | ||
import chronosacaria.mcdw.bases.McdwAxe; | ||
import chronosacaria.mcdw.bases.McdwDoubleAxe; | ||
import chronosacaria.mcdw.bases.McdwSpear; | ||
import net.minecraft.enchantment.DamageEnchantment; | ||
import net.minecraft.enchantment.Enchantments; | ||
|
||
public class EnchantmentRestrictionsRegistry { | ||
public static void init() { | ||
EnchantmentRestriction.permit(Enchantments.FIRE_ASPECT, itemStack -> itemStack.getItem() instanceof McdwAxe || itemStack.getItem() instanceof McdwDoubleAxe); | ||
EnchantmentRestriction.permitTarget((enchantment, itemStack) -> enchantment instanceof DamageEnchantment && itemStack.getItem() instanceof McdwSpear); | ||
} | ||
} |
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