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

Update mod to 1.20.1 #53

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.EnchantedBookItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentInstance;

import java.util.Collection;
import java.util.function.Supplier;

public class EnchantedBookCommand {
public static void register(CommandDispatcher<CommandSourceStack> commandDispatcher, CommandBuildContext commandBuildContext) {
Expand All @@ -35,9 +37,9 @@ private static int enchant(CommandSourceStack commandSourceStack, Collection<? e
player.addItem(itemStack);
}
if (collection.size() == 1) {
commandSourceStack.sendSuccess(Component.translatable("commands.noenchantcap.enchantedbook.success.single", enchantment.getFullname(level), collection.iterator().next().getDisplayName()), true);
commandSourceStack.sendSuccess((Supplier<Component>) Component.translatable("commands.noenchantcap.enchantedbook.success.single", enchantment.getFullname(level), collection.iterator().next().getDisplayName()), true);
} else {
commandSourceStack.sendSuccess(Component.translatable("commands.noenchantcap.enchantedbook.success.multiple", enchantment.getFullname(level), collection.size()), true);
commandSourceStack.sendSuccess((Supplier<Component>) Component.translatable("commands.noenchantcap.enchantedbook.success.multiple", enchantment.getFullname(level), collection.size()), true);
}
return collection.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public AnvilMenuMixin(@Nullable MenuType<?> menuType, int i, Inventory inventory
if (max == 1) {
return 1;
}
if (this.player.level.getGameRules().getBoolean(NoEnchantCap.UNCAPPED_ANVILS)) {
if (this.player.level().getGameRules().getBoolean(NoEnchantCap.UNCAPPED_ANVILS)) {
return Integer.MAX_VALUE;
} else {
ItemStack itemStack1 = this.inputSlots.getItem(0);
Expand All @@ -44,15 +44,15 @@ public AnvilMenuMixin(@Nullable MenuType<?> menuType, int i, Inventory inventory

@WrapOperation(method = "createResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/enchantment/Enchantment;isCompatibleWith(Lnet/minecraft/world/item/enchantment/Enchantment;)Z"))
private boolean noEnchantCap$moreCombinations(Enchantment enchantment1, Enchantment enchantment2, Operation<Boolean> original) {
if (this.player.level.getGameRules().getBoolean(NoEnchantCap.MIX_ANY_ENCHANTS)) {
if (this.player.level().getGameRules().getBoolean(NoEnchantCap.MIX_ANY_ENCHANTS)) {
return true;
}
return original.call(enchantment1, enchantment2);
}

@WrapOperation(method = "createResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;getAbilities()Lnet/minecraft/world/entity/player/Abilities;", ordinal = 0))
private Abilities noEnchantCap$enchantAnyItem(Player player, Operation<Abilities> original) {
if (this.player.level.getGameRules().getBoolean(NoEnchantCap.ENCHANT_ANY_ITEM)) {
if (this.player.level().getGameRules().getBoolean(NoEnchantCap.ENCHANT_ANY_ITEM)) {
Abilities abilities = new Abilities();
abilities.instabuild = true;
return abilities;
Expand All @@ -67,13 +67,13 @@ public AnvilMenuMixin(@Nullable MenuType<?> menuType, int i, Inventory inventory

@WrapWithCondition(method = "createResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;setRepairCost(I)V"))
private boolean noEnchantCap$staticRepairCost(ItemStack instance, int repairCost) {
return !this.player.level.getGameRules().getBoolean(NoEnchantCap.STATIC_REPAIR_COST);
return !this.player.level().getGameRules().getBoolean(NoEnchantCap.STATIC_REPAIR_COST);
}


@WrapWithCondition(method = "onTake", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;giveExperienceLevels(I)V"))
private boolean noEnchantCap$fairAnvilCost(Player instance, int levels) {
if (this.player.level.getGameRules().getBoolean(NoEnchantCap.FAIR_EXPERIENCE_COST)) {
if (this.player.level().getGameRules().getBoolean(NoEnchantCap.FAIR_EXPERIENCE_COST)) {
this.player.giveExperiencePoints(-noEnchantCap$getExperienceTotal(-levels));
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected PlayerMixin(EntityType<? extends LivingEntity> $$0, Level $$1) {

@Inject(method = "onEnchantmentPerformed", at = @At(value = "HEAD"), cancellable = true)
private void noEnchantCap$fairishEnchantCost(ItemStack stack, int levels, CallbackInfo ci) {
if (this.level.getGameRules().getBoolean(NoEnchantCap.FAIR_EXPERIENCE_COST)) {
if (this.level().getGameRules().getBoolean(NoEnchantCap.FAIR_EXPERIENCE_COST)) {
int min = Math.min(30, this.experienceLevel);
this.giveExperiencePoints(-noEnchantCap$getExperienceTotal(min - levels, min));
if (this.experienceLevel < 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package xyz.amymialee.noenchantcap;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.gamerule.v1.CustomGameRuleCategory;
import net.minecraft.text.Text;

/**
* Initializes the custom gamerule category and the common initializer.
*/
public class NoEnchantCapFabric implements ModInitializer {
/**
* Custom Gamerules category for the mod on fabric. Uses players category on forge due to lack of custom gamerule categories.
*/
public static final CustomGameRuleCategory ENCHANT_CAP_GAMERULES = new CustomGameRuleCategory(NoEnchantCap.id("no_enchant_cap"), Text.translatable("gamerule.category."+ NoEnchantCap.MOD_ID));

@Override
public void onInitialize() {
NoEnchantCap.init();
CommandRegistrationCallback.EVENT.register((commandDispatcher, commandBuildContext, commandSelection) -> EnchantedBookCommand.register(commandDispatcher, commandBuildContext));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package xyz.amymialee.noenchantcap;

import com.llamalad7.mixinextras.MixinExtrasBootstrap;
import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint;

/**
* PreLaunch to Initialize Mixin Extras which is used heavily in the mod.
*/
public class NoEnchantCapPreLaunch implements PreLaunchEntrypoint {
@Override
public void onPreLaunch() {
MixinExtrasBootstrap.init();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package xyz.amymialee.noenchantcap.platform;

import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.world.GameRules;
import xyz.amymialee.noenchantcap.NoEnchantCapFabric;
import xyz.amymialee.noenchantcap.platform.services.IPlatformHelper;

/**
* Handles Fabric exclusive code.
*/
public class FabricPlatformHelper implements IPlatformHelper {
@Override
public String getPlatformName() {
return "Fabric";
}

@Override
public boolean isModLoaded(String modId) {
return FabricLoader.getInstance().isModLoaded(modId);
}

@Override
public boolean isDevelopmentEnvironment() {
return FabricLoader.getInstance().isDevelopmentEnvironment();
}

@Override
public <T extends GameRules.Rule<T>> GameRules.Key<T> registerGamerule(String name, GameRules.Type<T> type) {
return GameRuleRegistry.register(name, NoEnchantCapFabric.ENCHANT_CAP_GAMERULES, type);
}

@Override
public GameRules.Type<GameRules.BooleanRule> createBooleanValue(boolean defaultValue) {
return GameRuleFactory.createBooleanRule(defaultValue);
}

@Override
public GameRules.Type<GameRules.IntRule> createIntegerValue(int defaultValue) {
return GameRuleFactory.createIntRule(defaultValue);
}
}
3 changes: 2 additions & 1 deletion Forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ dependencies {
minecraftLibrary("com.github.LlamaLad7:MixinExtras:0.1.1")
annotationProcessor("com.github.LlamaLad7:MixinExtras:0.1.1")
annotationProcessor('org.spongepowered:mixin:0.8.5:processor')
jarJar("com.github.LlamaLad7:MixinExtras:0.1.1")
implementation("com.github.LlamaLad7:MixinExtras:0.1.1")
//jarJar("com.github.LlamaLad7:MixinExtras:0.1.1")
}

shadowJar {
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ version=2.2.6
group=xyz.amymialee.noenchantcap

# Common
minecraft_version=1.19.3
minecraft_version=1.20.1
common_runs_enabled=false
common_client_run_name=Common Client
common_server_run_name=Common Server

# Forge
forge_version=44.0.23
forge_version=47.0.19
forge_ats_enabled=true

# Fabric https://fabricmc.net/develop/
fabric_version=0.69.1+1.19.3
fabric_loader_version=0.14.11
fabric_version=0.84.0+1.20.1
fabric_loader_version=0.14.21

# Mod options
mod_name=No Enchant Cap
Expand Down