mirror of
https://github.com/CompeyDev/stinky-mod.git
synced 2024-12-12 12:50:39 +00:00
feat: proper ;ec & initial death msg impl
This commit is contained in:
parent
84729afe54
commit
bb89768cf0
6 changed files with 132 additions and 8 deletions
|
@ -7,9 +7,7 @@ import net.fabricmc.api.ModInitializer;
|
|||
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.PlayerChatMessage;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -20,8 +18,8 @@ public class Stinky implements ModInitializer {
|
|||
// That way, it's clear which mod wrote info, warnings, and errors.
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("stinky");
|
||||
public static final ConfigModel Config = new ConfigHandler().getConfig();
|
||||
public static final ResourceLocation EC_SOUND_ID = new ResourceLocation("stinky:ping");
|
||||
public static SoundEvent EC_SOUND_EVENT = SoundEvent.createVariableRangeEvent(EC_SOUND_ID);
|
||||
// public static final ResourceLocation EC_SOUND_ID = new ResourceLocation("stinky:ping");
|
||||
// public static SoundEvent EC_SOUND_EVENT = SoundEvent.createVariableRangeEvent(EC_SOUND_ID);
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
|
@ -32,10 +30,10 @@ public class Stinky implements ModInitializer {
|
|||
LOGGER.info("Hello from Stinky!");
|
||||
|
||||
ServerMessageEvents.CHAT_MESSAGE.register((PlayerChatMessage msg, ServerPlayer plr, ChatType.Bound bound) -> {
|
||||
// NOTE: This makes this command dysfunctional on offline mode servers
|
||||
String msgString = msg.signedContent();
|
||||
|
||||
if (msgString == ";ec") {
|
||||
|
||||
if (msgString.trim().equalsIgnoreCase(";ec")) {
|
||||
// We're setting the health to 0, instead of plr.kill(), because this
|
||||
// abuses a flaw in the graves VanillaTweaks datapack to make the player
|
||||
// respawn without creating a grave or losing their items
|
||||
|
@ -44,5 +42,8 @@ public class Stinky implements ModInitializer {
|
|||
plr.setHealth(0);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
22
src/main/java/xyz/devcomp/mixin/LivingEntityMixin.java.bak
Normal file
22
src/main/java/xyz/devcomp/mixin/LivingEntityMixin.java.bak
Normal file
|
@ -0,0 +1,22 @@
|
|||
package xyz.devcomp.mixin;
|
||||
|
||||
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;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
||||
@Mixin(LivingEntity.class)
|
||||
public class LivingEntityMixin {
|
||||
@Inject(method = "die(Lnet/minecraft/world/damagesource/DamageSource;)V", at = @At(value = "INVOKE", target = "createWitherRose(Lnet/minecraft/world/entity/LivingEntity;)V"), locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
private void broadcastCustomDeathMessage(DamageSource source, CallbackInfo ci, Entity entity) {
|
||||
if (entity instanceof ServerPlayer) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -42,6 +42,6 @@ public class PlayerListMixin {
|
|||
// for connection
|
||||
this.currentFormattingStyle = ChatFormatting.DARK_RED;
|
||||
|
||||
return component.copy().withStyle(currentChatFormattingStyle);
|
||||
return component.copy();
|
||||
}
|
||||
}
|
||||
|
|
99
src/main/java/xyz/devcomp/mixin/ServerPlayerMixin.java
Normal file
99
src/main/java/xyz/devcomp/mixin/ServerPlayerMixin.java
Normal file
|
@ -0,0 +1,99 @@
|
|||
package xyz.devcomp.mixin;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import xyz.devcomp.Stinky;
|
||||
import xyz.devcomp.util.Strings.DeathStrings;
|
||||
|
||||
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;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.damagesource.DamageType;
|
||||
import net.minecraft.world.damagesource.DamageTypes;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
@Mixin(ServerPlayer.class)
|
||||
public abstract class ServerPlayerMixin extends Player {
|
||||
public ServerPlayerMixin(Level level, BlockPos blockPos, float f, GameProfile gameProfile) {
|
||||
super(level, blockPos, f, gameProfile);
|
||||
}
|
||||
|
||||
@Inject(method = "die(Lnet/minecraft/world/damagesource/DamageSource;)V", at = @At("TAIL"))
|
||||
private void broadcastDeathMessage(DamageSource damageSource, CallbackInfo ci) {
|
||||
ServerPlayer victim = (ServerPlayer) (Object) this;
|
||||
MinecraftServer server = this.getServer();
|
||||
|
||||
if (damageSource.getDirectEntity() instanceof ServerPlayer aggressor) {
|
||||
if (aggressor == victim) {
|
||||
// suicide balls
|
||||
|
||||
server.sendSystemMessage(
|
||||
Component.literal(DeathStrings.Suicide[(int) (Math.random() * DeathStrings.Suicide.length)]));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Map<ResourceKey<DamageType>, String[]> relevantTypes = Map.of(
|
||||
DamageTypes.ARROW, DeathStrings.Arrow,
|
||||
DamageTypes.PLAYER_ATTACK, DeathStrings.Melee,
|
||||
DamageTypes.MAGIC, DeathStrings.Potion,
|
||||
DamageTypes.PLAYER_EXPLOSION, DeathStrings.Explosion);
|
||||
|
||||
for (Map.Entry<ResourceKey<DamageType>, String[]> type : relevantTypes.entrySet()) {
|
||||
ResourceKey<DamageType> damageType = type.getKey();
|
||||
String[] msgs = type.getValue();
|
||||
|
||||
if (damageSource.is(damageType)) {
|
||||
server.getPlayerList().broadcastSystemMessage(Component.literal(msgs[(int) (Math.random() * msgs.length)]
|
||||
.replace("player", victim.getDisplayName().getString())
|
||||
.replace("killer", aggressor.getDisplayName().getString()) // check if null
|
||||
.replace("weapon", (damageSource.getDirectEntity().getName() == null ? "" : damageSource.getDirectEntity().getName().getString()))), false);
|
||||
}
|
||||
}
|
||||
;
|
||||
} else {
|
||||
// these death msgs dont work :(
|
||||
Stinky.LOGGER.info("killer: {}, weapon: {}", damageSource.getDirectEntity().getName().getString(), damageSource.getEntity().getName().getString());
|
||||
|
||||
Map<ResourceKey<DamageType>, String[]> messageMappings = Map.ofEntries(
|
||||
Map.entry(DamageTypes.FALL, DeathStrings.FallDamage),
|
||||
Map.entry(DamageTypes.ON_FIRE, DeathStrings.Burned),
|
||||
Map.entry(DamageTypes.IN_FIRE, DeathStrings.Burned),
|
||||
Map.entry(DamageTypes.DROWN, DeathStrings.Drowned),
|
||||
Map.entry(DamageTypes.IN_WALL, DeathStrings.Suffocation),
|
||||
Map.entry(DamageTypes.MOB_ATTACK, DeathStrings.Mob),
|
||||
Map.entry(DamageTypes.MOB_PROJECTILE, DeathStrings.Mob),
|
||||
Map.entry(DamageTypes.MOB_ATTACK_NO_AGGRO, DeathStrings.Mob),
|
||||
Map.entry(DamageTypes.GENERIC, DeathStrings.Wildcard),
|
||||
Map.entry(DamageTypes.EXPLOSION, DeathStrings.Explosion),
|
||||
Map.entry(DamageTypes.STARVE, DeathStrings.Starved));
|
||||
|
||||
for (Map.Entry<ResourceKey<DamageType>, String[]> type : messageMappings.entrySet()) {
|
||||
ResourceKey<DamageType> damageType = type.getKey();
|
||||
String[] msgs = type.getValue();
|
||||
|
||||
int idx = (int) (Math.random() * msgs.length);
|
||||
|
||||
if (damageSource.is(damageType)) {
|
||||
server.getPlayerList().broadcastSystemMessage(Component.literal(
|
||||
msgs[idx]
|
||||
.replace("player", victim.getDisplayName().getString())
|
||||
.replace("killer", damageSource.getEntity().getName().getString())
|
||||
.replace("weapon", damageSource.getDirectEntity().getName().getString())), false);
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -51,6 +51,7 @@ public class Strings {
|
|||
"&cplayer&7? &cplayer&7?? &cplayer&7!!!!!"
|
||||
};
|
||||
public static String[] Explosion = {
|
||||
"&cplayer&7 was blown by &ckiller",
|
||||
"&cplayer&7 blew up",
|
||||
"&cplayer&7 exploded",
|
||||
};
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
"mixins": [
|
||||
"ServerStatusPacketListenerImplMixin",
|
||||
"ComponentMixin",
|
||||
"PlayerListMixin"
|
||||
"PlayerListMixin",
|
||||
"ServerPlayerMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Reference in a new issue