This commit is contained in:
RTAkland
2023-08-16 16:51:36 +08:00
parent 9b44a32f44
commit 2d73a88f16
10 changed files with 216 additions and 14 deletions

View File

@@ -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<String> = 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())
}
}

View File

@@ -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);
}
}

View File

@@ -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<Stat<?>> map, Object object, int value, ServerPlayerEntity player) {
if (!RMineCounter.INSTANCE.contains((Stat<?>) object)) {
return map.put((Stat<?>) object, value);
} else {
return map.defaultReturnValue();
}
}
}

View File

@@ -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 <T> StatType<T> callRegisterType(String string, Registry<T> registry) {
return null;
}
}

View File

@@ -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();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@@ -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}"
}
}

View File

@@ -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": [
],