Skip to content
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
25 changes: 13 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'fabric-loom' version '1.3-SNAPSHOT'
id 'fabric-loom' version '1.9-SNAPSHOT'
id 'maven-publish'
id 'org.jetbrains.kotlin.jvm' version '2.1.0'
}

version = project.mod_version
Expand All @@ -17,10 +18,7 @@ repositories {
}

maven {
url = uri("https://cursemaven.com")
content {
includeGroup("curse.maven")
}
url = "https://api.modrinth.com/maven"
}
}

Expand All @@ -39,15 +37,18 @@ loom {
dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
mappings(loom.layered {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${project.minecraft_version}:${project.parchment_version}")
})
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

include(modImplementation('me.lucko:fabric-permissions-api:0.2-SNAPSHOT'))
include(modImplementation('me.lucko:fabric-permissions-api:0.3.1'))

modImplementation("curse.maven:cobblemon-687131:${property("cobblemon_curse_file_id")}")
modImplementation("maven.modrinth:cobblemon:${property("cobblemon_modrinth_file_id")}")
}

processResources {
Expand All @@ -59,7 +60,7 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 17
it.options.release = 21
}

java {
Expand All @@ -68,8 +69,8 @@ java {
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

jar {
Expand All @@ -93,4 +94,4 @@ publishing {
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
}
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.19.2
yarn_mappings=1.19.2+build.28
loader_version=0.14.21
minecraft_version=1.21.1
parchment_version=2024.11.17@zip
loader_version=0.16.10

# Mod Properties
mod_version=1.0.0
mod_version=1.1.0+1.21.1
maven_group=unsafedodo.cobblemonexplock
archives_base_name=cobblemon-explock

# Dependencies
fabric_version=0.76.0+1.19.2
fabric_version=0.115.0+1.21.1

cobblemon_curse_file_id=4468330
cobblemon_modrinth_file_id=eLcb8xod
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.context.CommandContext;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.ChatFormatting;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import unsafedodo.cobblemonexplock.util.ExpData;
import unsafedodo.cobblemonexplock.util.IPokemonDataSaver;

public class ExpLockToggleCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess commandRegistryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) {
dispatcher.register(CommandManager.literal("explock")
.then(CommandManager.argument("slotNumber", IntegerArgumentType.integer(1,6))
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandRegistryAccess, Commands.CommandSelection registrationEnvironment) {
dispatcher.register(Commands.literal("explock")
.then(Commands.argument("slotNumber", IntegerArgumentType.integer(1,6))
.requires(Permissions.require("explock.toggle", 0))
.executes(ExpLockToggleCommand::run)));
}

private static int run(CommandContext<ServerCommandSource> context) {
private static int run(CommandContext<CommandSourceStack> context) {
try{
PlayerPartyStore partyStore = Cobblemon.INSTANCE.getStorage().getParty(context.getSource().getPlayer().getUuid());
PlayerPartyStore partyStore = Cobblemon.INSTANCE.getStorage().getParty(context.getSource().getPlayer());
int slot = (IntegerArgumentType.getInteger(context, "slotNumber")-1);
Pokemon pokemon = partyStore.get(slot);
if(pokemon != null){
boolean state = ExpData.setExpState((IPokemonDataSaver) pokemon);
context.getSource().sendFeedback(Text.literal("Exp gain state for "+pokemon.getDisplayName().getString()+" changed to "+state).formatted(Formatting.GREEN), false);
context.getSource().sendSuccess(() -> Component.literal("Exp lock state for "+pokemon.getDisplayName()+" changed to "+state).withStyle(ChatFormatting.GREEN), false);
} else {
context.getSource().sendFeedback(Text.literal("Invalid slot").formatted(Formatting.RED), false);
context.getSource().sendSuccess(() -> Component.literal("Invalid slot").withStyle(ChatFormatting.RED), false);
return -1;
}
} catch (NoPokemonStoreException e){
} catch (Exception e){
e.printStackTrace();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public class ExpGainMixin {
@ModifyVariable(method = "calculate", at = @At("STORE"), name = "term4", remap = false)
private double injectedExpGainLock(double term4, BattlePokemon battlePokemon) {
Pokemon pokemon = battlePokemon.getOriginalPokemon();
boolean state = ((IPokemonDataSaver) pokemon).getPersistentData().getBoolean("explock");
boolean state = ((IPokemonDataSaver) pokemon).cobblemon_explock$getPersistentData().getBoolean("explock");
if(!state)
return term4;
else
return 0.0;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
package unsafedodo.cobblemonexplock.mixin;

import com.cobblemon.mod.common.pokemon.Pokemon;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CompoundTag;
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 unsafedodo.cobblemonexplock.util.IPokemonDataSaver;

@Mixin(Pokemon.class)
public abstract class SaveNbtMixin implements IPokemonDataSaver {
private NbtCompound persistentData;
@Unique
private CompoundTag persistentData;

@Override
public NbtCompound getPersistentData(){
public CompoundTag cobblemon_explock$getPersistentData(){
if(this.persistentData == null){
this.persistentData = new NbtCompound();
this.persistentData = new CompoundTag();
}
return persistentData;
}

@Inject(method = "loadFromNBT", at = @At("TAIL"))
protected void loadFromNbt(NbtCompound nbt, CallbackInfoReturnable<Pokemon> cir){
protected void loadFromNbt(RegistryAccess registryAccess, CompoundTag nbt, CallbackInfoReturnable<Pokemon> cir){
if(nbt.contains("explock")){
persistentData = nbt.getCompound("explock");
}
}


@Inject(method = "saveToNBT", at = @At("TAIL"))
protected void saveToNbt(NbtCompound nbt, CallbackInfoReturnable<NbtCompound> cir){
protected void saveToNbt(RegistryAccess registryAccess, CompoundTag nbt, CallbackInfoReturnable<CompoundTag> cir){
if(persistentData != null){
nbt.put("explock", persistentData);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/unsafedodo/cobblemonexplock/util/ExpData.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package unsafedodo.cobblemonexplock.util;

import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.CompoundTag;

public class ExpData {

public static boolean setExpState(IPokemonDataSaver pokemon){
NbtCompound nbt = pokemon.getPersistentData();
CompoundTag nbt = pokemon.cobblemon_explock$getPersistentData();
boolean state = nbt.getBoolean("explock");
state = !state;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package unsafedodo.cobblemonexplock.util;

import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.CompoundTag;

public interface IPokemonDataSaver {
NbtCompound getPersistentData();
CompoundTag cobblemon_explock$getPersistentData();
}
11 changes: 4 additions & 7 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@
"cobblemon-explock.mixins.json"
],
"depends": {
"fabricloader": ">=0.14.18",
"minecraft": "~1.19.2",
"java": ">=17",
"fabricloader": ">=0.16.0",
"minecraft": "~1.21.1",
"java": ">=21",
"fabric-api": "*"
},
"suggests": {
"another-mod": "*"
}
}
}