update
This commit is contained in:
@@ -13,40 +13,38 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.rtast.rminecounter
|
||||
|
||||
import cn.rtast.rminecounter.mixins.StatsAccessor
|
||||
package cn.rtast.rmc
|
||||
|
||||
import cn.rtast.rmc.mixin.StatsAccessor
|
||||
import com.google.common.collect.Sets
|
||||
import net.fabricmc.api.ModInitializer
|
||||
import net.minecraft.entity.player.PlayerEntity
|
||||
import net.fabricmc.api.DedicatedServerModInitializer
|
||||
import net.minecraft.stat.Stat
|
||||
import net.minecraft.stat.StatFormatter
|
||||
import net.minecraft.util.Identifier
|
||||
|
||||
class RMC : DedicatedServerModInitializer {
|
||||
|
||||
object RMineCounter : ModInitializer {
|
||||
|
||||
private var RMC: Identifier? = null
|
||||
companion object {
|
||||
private val stats: MutableSet<String> = Sets.newHashSet()
|
||||
|
||||
private val stats: MutableSet<String> = Sets.newHashSet()
|
||||
var RMC_STAT_ID: Identifier? = null
|
||||
|
||||
private fun addStat(stat: Identifier) {
|
||||
stats.add(stat.toString())
|
||||
private fun addStat(stat: Identifier) {
|
||||
stats.add(stat.toString())
|
||||
}
|
||||
|
||||
fun registerStats() {
|
||||
addStat(StatsAccessor.callRegister("rmc", StatFormatter.TIME).also { RMC_STAT_ID = it })
|
||||
}
|
||||
|
||||
operator fun contains(stat: Stat<*>): Boolean {
|
||||
return stats.contains(stat.value.toString())
|
||||
}
|
||||
}
|
||||
|
||||
fun registerStats() {
|
||||
addStat(StatsAccessor.callRegister("rmc", StatFormatter.DEFAULT).also { RMC = it })
|
||||
}
|
||||
|
||||
fun onPlayerMineFinish(player: PlayerEntity) {
|
||||
player.increaseStat(RMC, 1)
|
||||
}
|
||||
|
||||
operator fun contains(stat: Stat<*>): Boolean {
|
||||
return stats.contains(stat.value.toString())
|
||||
}
|
||||
|
||||
override fun onInitialize() {
|
||||
override fun onInitializeServer() {
|
||||
println("RMC 已加载!")
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.rtast.rminecounter.mixins;
|
||||
package cn.rtast.rmc.mixin;
|
||||
|
||||
import cn.rtast.rminecounter.RMineCounter;
|
||||
import cn.rtast.rmc.RMC;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -29,11 +29,8 @@ 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);
|
||||
player.increaseStat(RMC.Companion.getRMC_STAT_ID(), 1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,9 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.rtast.rminecounter.mixins;
|
||||
package cn.rtast.rmc.mixin;
|
||||
|
||||
import cn.rtast.rminecounter.RMineCounter;
|
||||
import cn.rtast.rmc.RMC;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.stat.ServerStatHandler;
|
||||
@@ -29,7 +29,7 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
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)) {
|
||||
if (!RMC.Companion.contains((Stat<?>) object)) {
|
||||
return map.put((Stat<?>) object, value);
|
||||
} else {
|
||||
return map.defaultReturnValue();
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.rtast.rminecounter.mixins;
|
||||
package cn.rtast.rmc.mixin;
|
||||
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.stat.StatFormatter;
|
||||
@@ -35,4 +35,4 @@ public interface StatsAccessor {
|
||||
static <T> StatType<T> callRegisterType(String string, Registry<T> registry) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.rtast.rminecounter.mixins;
|
||||
package cn.rtast.rmc.mixin;
|
||||
|
||||
|
||||
import cn.rtast.rminecounter.RMineCounter;
|
||||
import cn.rtast.rmc.RMC;
|
||||
import net.minecraft.stat.Stats;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@@ -25,6 +24,6 @@ import org.spongepowered.asm.mixin.Mixin;
|
||||
public class StatsMixin {
|
||||
|
||||
static {
|
||||
RMineCounter.INSTANCE.registerStats();
|
||||
RMC.Companion.registerStats();
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
src/main/resources/assets/rmc/icon.png
Normal file
BIN
src/main/resources/assets/rmc/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
3
src/main/resources/assets/rmc/lang/en_us.json
Normal file
3
src/main/resources/assets/rmc/lang/en_us.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"stat.rmc.rmc_stat": "挖掘数"
|
||||
}
|
||||
3
src/main/resources/assets/rmc/lang/zh_cn.json
Normal file
3
src/main/resources/assets/rmc/lang/zh_cn.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"stat.rmc.rmc_stat": "Total number of blocks destroyed."
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.6 KiB |
@@ -1,28 +1,29 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "rminecounter",
|
||||
"id": "rmc",
|
||||
"version": "${version}",
|
||||
"name": "RMineCounter",
|
||||
"name": "RMC",
|
||||
"description": "添加挖掘榜",
|
||||
"authors": [
|
||||
"RTAkland"
|
||||
],
|
||||
"contact": {
|
||||
"repo": "https://github.com/RTAkland/RMineCounter"
|
||||
"website": "https://github.com/DangoTown/RMC",
|
||||
"repo": "https://github.com/DangoTown/RMC"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"icon": "assets/rminecounter/icon.png",
|
||||
"environment": "*",
|
||||
"icon": "assets/rmc/icon.png",
|
||||
"environment": "server",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"server": [
|
||||
{
|
||||
"adapter": "kotlin",
|
||||
"value": "cn.rtast.rminecounter.RMineCounter"
|
||||
"value": "cn.rtast.rmc.RMC"
|
||||
}
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"rminecounter.mixins.json"
|
||||
"rmc.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=${loader_version}",
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "cn.rtast.rminecounter.mixins",
|
||||
"package": "cn.rtast.rmc.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"BlockMixin",
|
||||
"ServerPlayNetworkHandlerAccessor",
|
||||
"ServerStatHandlerMixin",
|
||||
"StatsAccessor",
|
||||
"StatsMixin"
|
||||
Reference in New Issue
Block a user