diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..c1962a7 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 02f683e..37aef8d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1 +1,6 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +networkTimeout=10000 +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/src/main/java/cn/rtast/rminecounter/RMineCounter.kt b/src/main/java/cn/rtast/rminecounter/RMineCounter.kt new file mode 100644 index 0000000..15a57da --- /dev/null +++ b/src/main/java/cn/rtast/rminecounter/RMineCounter.kt @@ -0,0 +1,47 @@ +/* + * Copyright 2023 RTAkland + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.rtast.rminecounter + +import cn.rtast.rminecounter.mixins.StatsAccessor +import com.google.common.collect.Sets +import net.minecraft.entity.player.PlayerEntity +import net.minecraft.stat.Stat +import net.minecraft.stat.StatFormatter +import net.minecraft.util.Identifier + + +object RMineCounter { + + private var RMCC: Identifier? = null + + private val stats: MutableSet = Sets.newHashSet() + + private fun addStat(stat: Identifier) { + this.stats.add(stat.toString()) + } + + fun registerStats() { + this.addStat(StatsAccessor.callRegister("rmc", StatFormatter.DEFAULT).also { this.RMCC = it }) + } + + fun onPlayerMineFinish(player: PlayerEntity) { + player.increaseStat(this.RMCC, 1) + } + + operator fun contains(stat: Stat<*>): Boolean { + return this.stats.contains(stat.value.toString()) + } +} \ No newline at end of file diff --git a/src/main/java/cn/rtast/rminecounter/mixins/BlockMixin.java b/src/main/java/cn/rtast/rminecounter/mixins/BlockMixin.java new file mode 100644 index 0000000..47e815f --- /dev/null +++ b/src/main/java/cn/rtast/rminecounter/mixins/BlockMixin.java @@ -0,0 +1,39 @@ +/* + * Copyright 2023 RTAkland + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.rtast.rminecounter.mixins; + +import cn.rtast.rminecounter.RMineCounter; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Block.class) +public class BlockMixin { + + @Inject(method = "onBreak", at = @At("HEAD")) + public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfo ci) { +// BlockListener.INSTANCE.onBreak(player); + RMineCounter.INSTANCE.onPlayerMineFinish(player); + } + +} diff --git a/src/main/java/cn/rtast/rminecounter/mixins/ServerStatHandlerMixin.java b/src/main/java/cn/rtast/rminecounter/mixins/ServerStatHandlerMixin.java new file mode 100644 index 0000000..ce856a5 --- /dev/null +++ b/src/main/java/cn/rtast/rminecounter/mixins/ServerStatHandlerMixin.java @@ -0,0 +1,38 @@ +/* + * Copyright 2023 RTAkland + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.rtast.rminecounter.mixins; + +import cn.rtast.rminecounter.RMineCounter; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.stat.ServerStatHandler; +import net.minecraft.stat.Stat; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ServerStatHandler.class) +public abstract class ServerStatHandlerMixin { + @Redirect(method = "sendStats", at = @At(value = "INVOKE", target = "Lit/unimi/dsi/fastutil/objects/Object2IntMap;put(Ljava/lang/Object;I)I"), remap = false) + private int excludeCustomStats(Object2IntMap> map, Object object, int value, ServerPlayerEntity player) { + if (!RMineCounter.INSTANCE.contains((Stat) object)) { + return map.put((Stat) object, value); + } else { + return map.defaultReturnValue(); + } + } +} \ No newline at end of file diff --git a/src/main/java/cn/rtast/rminecounter/mixins/StatsAccessor.java b/src/main/java/cn/rtast/rminecounter/mixins/StatsAccessor.java new file mode 100644 index 0000000..9ab63a9 --- /dev/null +++ b/src/main/java/cn/rtast/rminecounter/mixins/StatsAccessor.java @@ -0,0 +1,38 @@ +/* + * Copyright 2023 RTAkland + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.rtast.rminecounter.mixins; + +import net.minecraft.registry.Registry; +import net.minecraft.stat.StatFormatter; +import net.minecraft.stat.StatType; +import net.minecraft.stat.Stats; +import net.minecraft.util.Identifier; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(Stats.class) +public interface StatsAccessor { + @Invoker + static Identifier callRegister(String string, StatFormatter statFormatter) { + return null; + } + + @Invoker + static StatType callRegisterType(String string, Registry registry) { + return null; + } +} \ No newline at end of file diff --git a/src/main/java/cn/rtast/rminecounter/mixins/StatsMixin.java b/src/main/java/cn/rtast/rminecounter/mixins/StatsMixin.java new file mode 100644 index 0000000..e714b15 --- /dev/null +++ b/src/main/java/cn/rtast/rminecounter/mixins/StatsMixin.java @@ -0,0 +1,30 @@ +/* + * Copyright 2023 RTAkland + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.rtast.rminecounter.mixins; + + +import cn.rtast.rminecounter.RMineCounter; +import net.minecraft.stat.Stats; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(Stats.class) +public class StatsMixin { + + static { + RMineCounter.INSTANCE.registerStats(); + } +} diff --git a/src/main/resources/assets/rminecounter/icon.png b/src/main/resources/assets/rminecounter/icon.png new file mode 100644 index 0000000..ac9df0d Binary files /dev/null and b/src/main/resources/assets/rminecounter/icon.png differ diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index ae2a1bb..24d0211 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -2,25 +2,26 @@ "schemaVersion": 1, "id": "rminecounter", "version": "${version}", - "name": "RMineCounter", "description": "添加挖掘榜", - "authors": [], - "contact": {}, - + "authors": [ + "RTAkland" + ], + "contact": { + "repo": "https://github.com/RTAkland/RMineCounter" + }, "license": "Apache-2.0", "icon": "assets/rminecounter/icon.png", - - "environment": "server", - "entrypoints": {}, - - "mixins": [ - "rminecounter.mixins.json" - ], - + "environment": "*", + "entrypoints": { + "main": [] + }, + "mixins": [ + "rminecounter.mixins.json" + ], "depends": { "fabricloader": ">=${loader_version}", - "fabric": "*", + "fabric": "*", "minecraft": "${minecraft_version}" } } diff --git a/src/main/resources/rminecounter.mixins.json b/src/main/resources/rminecounter.mixins.json index 6998402..099c24b 100644 --- a/src/main/resources/rminecounter.mixins.json +++ b/src/main/resources/rminecounter.mixins.json @@ -1,9 +1,13 @@ { "required": true, "minVersion": "0.8", - "package": "cn.rtast.rminecounter.mixin", + "package": "cn.rtast.rminecounter.mixins", "compatibilityLevel": "JAVA_17", "mixins": [ + "BlockMixin", + "ServerStatHandlerMixin", + "StatsAccessor", + "StatsMixin" ], "client": [ ],