init
This commit is contained in:
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
gradle/wrapper/gradle-wrapper.properties
vendored
5
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -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
|
||||
|
||||
47
src/main/java/cn/rtast/rminecounter/RMineCounter.kt
Normal file
47
src/main/java/cn/rtast/rminecounter/RMineCounter.kt
Normal 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())
|
||||
}
|
||||
}
|
||||
39
src/main/java/cn/rtast/rminecounter/mixins/BlockMixin.java
Normal file
39
src/main/java/cn/rtast/rminecounter/mixins/BlockMixin.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
30
src/main/java/cn/rtast/rminecounter/mixins/StatsMixin.java
Normal file
30
src/main/java/cn/rtast/rminecounter/mixins/StatsMixin.java
Normal 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();
|
||||
}
|
||||
}
|
||||
BIN
src/main/resources/assets/rminecounter/icon.png
Normal file
BIN
src/main/resources/assets/rminecounter/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.6 KiB |
@@ -2,22 +2,23 @@
|
||||
"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": {},
|
||||
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": []
|
||||
},
|
||||
"mixins": [
|
||||
"rminecounter.mixins.json"
|
||||
],
|
||||
|
||||
"depends": {
|
||||
"fabricloader": ">=${loader_version}",
|
||||
"fabric": "*",
|
||||
|
||||
@@ -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": [
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user