generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
7101915
commit f2f70a4
Showing
18 changed files
with
250 additions
and
139 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
42 changes: 42 additions & 0 deletions
42
common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/MixinBlock.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,42 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package uk.debb.vanilla_disable.mixin.command.enchantment; | ||
|
||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.enchantment.EnchantmentHelper; | ||
import net.minecraft.world.item.enchantment.ItemEnchantments; | ||
import net.minecraft.world.level.block.Block; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.ModifyArg; | ||
import uk.debb.vanilla_disable.data.command.CommandDataHandler; | ||
|
||
@Mixin(Block.class) | ||
public abstract class MixinBlock { | ||
@ModifyArg( | ||
method = "getDrops(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/item/ItemStack;)Ljava/util/List;", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/level/storage/loot/LootParams$Builder;withParameter(Lnet/minecraft/world/level/storage/loot/parameters/LootContextParam;Ljava/lang/Object;)Lnet/minecraft/world/level/storage/loot/LootParams$Builder;", | ||
ordinal = 1 | ||
), | ||
index = 1 | ||
) | ||
private static Object vanillaDisable$getDrops(Object value) { | ||
if (value instanceof ItemStack itemStack) { | ||
String item = "can_enchant_" + CommandDataHandler.lightCleanup(CommandDataHandler.getKeyFromItemRegistry(itemStack.getItem())); | ||
ItemEnchantments itemEnchantments = itemStack.getEnchantments(); | ||
itemEnchantments.enchantments = itemEnchantments.enchantments.object2IntEntrySet().stream() | ||
.filter(e -> CommandDataHandler.getCachedBoolean("enchantments", CommandDataHandler.getKeyFromEnchantmentRegistry(e.getKey().value()), item)) | ||
.collect(Object2IntOpenHashMap::new, (m, e) -> m.put(e.getKey(), e.getIntValue()), Object2IntOpenHashMap::putAll); | ||
EnchantmentHelper.setEnchantments(itemStack, itemEnchantments); | ||
return itemStack; | ||
} | ||
return value; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/MixinEnchantment.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,43 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package uk.debb.vanilla_disable.mixin.command.enchantment; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyReturnValue; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.enchantment.Enchantment; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import uk.debb.vanilla_disable.data.command.CommandDataHandler; | ||
|
||
@Mixin(Enchantment.class) | ||
public abstract class MixinEnchantment { | ||
@ModifyReturnValue(method = "canEnchant", at = @At("RETURN")) | ||
private boolean vanillaDisable$canEnchant(boolean original, ItemStack stack) { | ||
if (CommandDataHandler.isConnectionNull()) return original; | ||
if (stack.getMaxDamage() == 0) return original; | ||
String item = "can_enchant_" + CommandDataHandler.lightCleanup(CommandDataHandler.getKeyFromItemRegistry(stack.getItem())); | ||
ResourceLocation enchantment = CommandDataHandler.enchantmentRegistry.getKey((Enchantment) (Object) this); | ||
if (enchantment == null) return original; | ||
return CommandDataHandler.getCachedBoolean("enchantments", enchantment.toString(), item); | ||
} | ||
|
||
@ModifyReturnValue(method = "areCompatible", at = @At("RETURN")) | ||
private static boolean vanillaDisable$areCompatible(boolean original, Holder<Enchantment> holder, Holder<Enchantment> holder2) { | ||
if (CommandDataHandler.isConnectionNull()) return original; | ||
ResourceLocation enchantmentRL = CommandDataHandler.enchantmentRegistry.getKey(holder.value()); | ||
ResourceLocation otherEnchantmentRL = CommandDataHandler.enchantmentRegistry.getKey(holder2.value()); | ||
if (enchantmentRL == null || otherEnchantmentRL == null) return original; | ||
String enchantment = enchantmentRL.toString(); | ||
String otherEnchantment = "compatible_with_" + CommandDataHandler.lightCleanup(otherEnchantmentRL); | ||
String reversedEnchantment = enchantment.replace("minecraft:", "compatible_with_"); | ||
String reversedOtherEnchantment = otherEnchantment.replace("compatible_with_", "minecraft:"); | ||
return CommandDataHandler.getCachedBoolean("enchantments", enchantment, otherEnchantment) || | ||
CommandDataHandler.getCachedBoolean("enchantments", reversedOtherEnchantment, reversedEnchantment); | ||
} | ||
} |
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
27 changes: 0 additions & 27 deletions
27
...ava/uk/debb/vanilla_disable/mixin/command/enchantment/compatibility/MixinEnchantment.java
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
...rc/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/item/MixinEnchantment.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
Oops, something went wrong.