Impl ignore specific damage sources in battle
Fixes #1. (Damage is inhibited, but some things like amount of air while underwater still decreases for the duration of being underwater regardless of being in battle.) Server-side config specifies which damage sources are ignored in battle. This can also be set in-game with `/tbm-server-edit`. Also updated config for entities which should reduce the amount of stuff printed into the logs (sorry about that).
This commit is contained in:
parent
ff326bcbe9
commit
a3431b135e
9 changed files with 505 additions and 9 deletions
|
@ -14,7 +14,7 @@ apply plugin: 'net.minecraftforge.gradle'
|
|||
//apply plugin: 'eclipse'
|
||||
//apply plugin: 'maven-publish'
|
||||
|
||||
version = "1.19.0"
|
||||
version = "1.20.0"
|
||||
group = "com.burnedkirby.TurnBasedMinecraft"
|
||||
archivesBaseName = "TurnBasedMinecraft"
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ import net.minecraft.world.entity.Entity;
|
|||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ClientProxy extends CommonProxy {
|
||||
|
@ -1050,6 +1049,19 @@ public class ClientProxy extends CommonProxy {
|
|||
"/tbm-server-edit creeper_always_allow_damage false")));
|
||||
parent.getSiblings().add(sub);
|
||||
|
||||
sub = Component.literal("ignore_damage_sources ");
|
||||
sub.setStyle(sub.getStyle()
|
||||
.withColor(ChatFormatting.DARK_GREEN)
|
||||
.withClickEvent(new ClickEvent(
|
||||
ClickEvent.Action.RUN_COMMAND,
|
||||
"/tbm-server-edit ignore_damage_sources"))
|
||||
.withHoverEvent(new HoverEvent(
|
||||
HoverEvent.Action.SHOW_TEXT,
|
||||
Component.literal("Click to show current ignored damage sources (during battle), or use /tbm-server-edit ignore_damage_sources add/remove <type>")
|
||||
))
|
||||
.withBold(true));
|
||||
parent.getSiblings().add(sub);
|
||||
|
||||
TurnBasedMinecraftMod.proxy.displayComponent(parent);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -350,4 +350,14 @@ public class BattleManager
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isInBattle(int entityID) {
|
||||
for (Battle battle : battleMap.values()) {
|
||||
if (battle.hasCombatant(entityID)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -50,6 +50,9 @@ public class Config
|
|||
private boolean creeperStopExplodeOnLeaveBattle = true;
|
||||
private boolean creeperAlwaysAllowDamage = true;
|
||||
|
||||
private Set<String> possibleIgnoreHurtDamageSources;
|
||||
private Set<String> ignoreHurtDamageSources;
|
||||
|
||||
public Config(Logger logger)
|
||||
{
|
||||
entityInfoMap = new HashMap<String, EntityInfo>();
|
||||
|
@ -59,6 +62,32 @@ public class Config
|
|||
musicBattleTypes = new HashSet<String>();
|
||||
musicSillyTypes = new HashSet<String>();
|
||||
battleIgnoringPlayers = new HashSet<Integer>();
|
||||
possibleIgnoreHurtDamageSources = new HashSet<String>();
|
||||
ignoreHurtDamageSources = new HashSet<String>();
|
||||
|
||||
possibleIgnoreHurtDamageSources.add("inFire");
|
||||
possibleIgnoreHurtDamageSources.add("lightningBolt");
|
||||
possibleIgnoreHurtDamageSources.add("onFire");
|
||||
possibleIgnoreHurtDamageSources.add("lava");
|
||||
possibleIgnoreHurtDamageSources.add("hotFloor");
|
||||
possibleIgnoreHurtDamageSources.add("inWall");
|
||||
possibleIgnoreHurtDamageSources.add("cramming");
|
||||
possibleIgnoreHurtDamageSources.add("drown");
|
||||
possibleIgnoreHurtDamageSources.add("starve");
|
||||
possibleIgnoreHurtDamageSources.add("cactus");
|
||||
possibleIgnoreHurtDamageSources.add("fall");
|
||||
possibleIgnoreHurtDamageSources.add("flyIntoWall");
|
||||
possibleIgnoreHurtDamageSources.add("outOfWorld");
|
||||
possibleIgnoreHurtDamageSources.add("magic");
|
||||
possibleIgnoreHurtDamageSources.add("wither");
|
||||
possibleIgnoreHurtDamageSources.add("anvil");
|
||||
possibleIgnoreHurtDamageSources.add("fallingBlock");
|
||||
possibleIgnoreHurtDamageSources.add("dragonBreath");
|
||||
possibleIgnoreHurtDamageSources.add("dryout");
|
||||
possibleIgnoreHurtDamageSources.add("sweetBerryBush");
|
||||
possibleIgnoreHurtDamageSources.add("freeze");
|
||||
possibleIgnoreHurtDamageSources.add("fallingStalactite");
|
||||
possibleIgnoreHurtDamageSources.add("stalagmite");
|
||||
|
||||
{
|
||||
File confPath = new File(TurnBasedMinecraftMod.CONFIG_DIRECTORY);
|
||||
|
@ -508,6 +537,17 @@ public class Config
|
|||
logTOMLInvalidValue("server_config.battle_turn_wait_forever", "false");
|
||||
}
|
||||
|
||||
try {
|
||||
Collection<String> damage_sources = conf.get("server_config.ignore_damage_sources");
|
||||
for (String source : damage_sources) {
|
||||
if (possibleIgnoreHurtDamageSources.contains(source)) {
|
||||
ignoreHurtDamageSources.add(source);
|
||||
}
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
logTOMLInvalidValue("server_config.ignore_damage_sources");
|
||||
}
|
||||
|
||||
Collection<com.electronwill.nightconfig.core.Config> entities = null;
|
||||
try {
|
||||
entities = conf.get("server_config.entity");
|
||||
|
@ -1452,4 +1492,25 @@ public class Config
|
|||
public void setBattleDecisionDurationForever(boolean battleDecisionDurationForever) {
|
||||
this.battleDecisionDurationForever = battleDecisionDurationForever;
|
||||
}
|
||||
}
|
||||
|
||||
public final Collection<String> getPossibleIgnoreHurtDamageSources() {
|
||||
return possibleIgnoreHurtDamageSources;
|
||||
}
|
||||
|
||||
public final Collection<String> getIgnoreHurtDamageSources() {
|
||||
return ignoreHurtDamageSources;
|
||||
}
|
||||
|
||||
public boolean addIgnoreHurtDamageSource(String source) {
|
||||
if (possibleIgnoreHurtDamageSources.contains(source) && !ignoreHurtDamageSources.contains(source)) {
|
||||
ignoreHurtDamageSources.add(source);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removeIgnoreHurtDamageSource(String source) {
|
||||
return ignoreHurtDamageSources.remove(source);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.burnedkirby.TurnBasedMinecraft.common;
|
||||
|
||||
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
public class HurtEventHandler {
|
||||
@SubscribeEvent
|
||||
public void handleHurtEvent(LivingHurtEvent event) {
|
||||
CommonProxy proxy = TurnBasedMinecraftMod.proxy;
|
||||
if (event.getEntity().level.isClientSide || proxy.getBattleManager() == null) {
|
||||
return;
|
||||
} else if (proxy.getBattleManager().isInBattle(event.getEntity().getId())
|
||||
&& proxy.getConfig().getIgnoreHurtDamageSources().contains(event.getSource().msgId)) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,8 +13,8 @@ import net.minecraft.ChatFormatting;
|
|||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.HoverEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.HoverEvent;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
@ -39,7 +39,7 @@ import org.apache.logging.log4j.Logger;
|
|||
public class TurnBasedMinecraftMod {
|
||||
public static final String MODID = "com_burnedkirby_turnbasedminecraft";
|
||||
public static final String NAME = "Turn Based Minecraft Mod";
|
||||
public static final String VERSION = "1.19.0";
|
||||
public static final String VERSION = "1.20.0";
|
||||
public static final String CONFIG_FILENAME = "TBM_Config.toml";
|
||||
public static final String DEFAULT_CONFIG_FILENAME = "TBM_Config_DEFAULT.toml";
|
||||
public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
|
||||
|
@ -126,6 +126,7 @@ public class TurnBasedMinecraftMod {
|
|||
MinecraftForge.EVENT_BUS.register(new AttackEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new PlayerJoinEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new DimensionChangedHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new HurtEventHandler());
|
||||
|
||||
logger.debug("Init com_burnedkirby_turnbasedminecraft");
|
||||
}
|
||||
|
@ -1065,7 +1066,7 @@ public class TurnBasedMinecraftMod {
|
|||
}
|
||||
|
||||
c.getSource().sendFailure(Component.literal(
|
||||
"Failed to remove category \"" + category + "\" to ignore_battle_types"));
|
||||
"Failed to remove category \"" + category + "\" from ignore_battle_types"));
|
||||
return 1;
|
||||
}))))
|
||||
.then(Commands.literal("player_speed").executes(c -> {
|
||||
|
@ -1484,6 +1485,110 @@ public class TurnBasedMinecraftMod {
|
|||
}
|
||||
return 1;
|
||||
})))
|
||||
.then(Commands.literal("ignore_damage_sources").executes(c -> {
|
||||
MutableComponent response = Component.literal("Use ");
|
||||
MutableComponent subResponse = Component.literal("/tbm-server-edit ignore_damage_sources add/remove <type> ");
|
||||
subResponse.setStyle(subResponse.getStyle().withColor(ChatFormatting.YELLOW));
|
||||
response.getSiblings().add(subResponse);
|
||||
|
||||
subResponse = Component.literal("ignore_damage_sources is currently: [");
|
||||
response.getSiblings().add(subResponse);
|
||||
|
||||
boolean isFirst = true;
|
||||
for (String type : TurnBasedMinecraftMod.proxy.getConfig().getIgnoreHurtDamageSources()) {
|
||||
if (!isFirst) {
|
||||
response.getSiblings().add(Component.literal(", "));
|
||||
}
|
||||
subResponse = Component.literal(type);
|
||||
subResponse.setStyle(subResponse.getStyle()
|
||||
.withColor(ChatFormatting.GREEN)
|
||||
.withClickEvent(new ClickEvent(
|
||||
ClickEvent.Action.RUN_COMMAND,
|
||||
"/tbm-server-edit ignore_damage_sources remove " + type))
|
||||
.withHoverEvent(new HoverEvent(
|
||||
HoverEvent.Action.SHOW_TEXT,
|
||||
Component.literal("Click to remove type"))));
|
||||
response.getSiblings().add(subResponse);
|
||||
isFirst = false;
|
||||
}
|
||||
response.getSiblings().add(Component.literal("] "));
|
||||
|
||||
subResponse = Component.literal("Possible Damage Sources: [");
|
||||
response.getSiblings().add(subResponse);
|
||||
|
||||
isFirst = true;
|
||||
for (String type : TurnBasedMinecraftMod.proxy.getConfig().getPossibleIgnoreHurtDamageSources()) {
|
||||
if (!isFirst) {
|
||||
response.getSiblings().add(Component.literal(", "));
|
||||
}
|
||||
subResponse = Component.literal(type);
|
||||
subResponse.setStyle(subResponse.getStyle()
|
||||
.withColor(ChatFormatting.YELLOW)
|
||||
.withClickEvent(new ClickEvent(
|
||||
ClickEvent.Action.RUN_COMMAND,
|
||||
"/tbm-server-edit ignore_damage_sources add " + type))
|
||||
.withHoverEvent(new HoverEvent(
|
||||
HoverEvent.Action.SHOW_TEXT,
|
||||
Component.literal("Click to add type")
|
||||
)));
|
||||
response.getSiblings().add(subResponse);
|
||||
isFirst = false;
|
||||
}
|
||||
response.getSiblings().add(Component.literal("] "));
|
||||
|
||||
c.getSource().sendSuccess(response, false);
|
||||
return 1;
|
||||
})
|
||||
.then(Commands.literal("add").executes(c -> {
|
||||
c.getSource().sendFailure(Component.literal("/tbm-server-edit ignore_damage_sources add <type>"));
|
||||
return 1;
|
||||
})
|
||||
.then(Commands.argument("type", StringArgumentType.greedyString()).executes(c -> {
|
||||
String type = StringArgumentType.getString(c, "type");
|
||||
if (TurnBasedMinecraftMod.proxy.getConfig().addIgnoreHurtDamageSource(type)
|
||||
&& TurnBasedMinecraftMod.proxy.getConfig().updateConfigAppendToStringArray("server_config.ignore_damage_sources", type)) {
|
||||
MutableComponent response = Component.literal("Successfully appended Damage Source type \"");
|
||||
|
||||
MutableComponent sub = Component.literal(type);
|
||||
sub.setStyle(sub.getStyle().withColor(ChatFormatting.GREEN));
|
||||
response.getSiblings().add(sub);
|
||||
|
||||
sub = Component.literal("\" to ignore_damage_sources");
|
||||
response.getSiblings().add(sub);
|
||||
|
||||
c.getSource().sendSuccess(response, true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
c.getSource().sendFailure(Component.literal(
|
||||
"Failed to append type \"" + type + "\" to ignore_damage_sources"
|
||||
));
|
||||
return 1;
|
||||
})))
|
||||
.then(Commands.literal("remove").executes(c -> {
|
||||
c.getSource().sendFailure(Component.literal("/tbm-server-edit ignore_damage_sources remove <type>"));
|
||||
return 1;
|
||||
})
|
||||
.then(Commands.argument("type", StringArgumentType.greedyString()).executes(c -> {
|
||||
String type = StringArgumentType.getString(c, "type");
|
||||
if (TurnBasedMinecraftMod.proxy.getConfig().removeIgnoreHurtDamageSource(type)
|
||||
&& TurnBasedMinecraftMod.proxy.getConfig().updateConfigRemoveFromStringArray("server_config.ignore_damage_sources", type)) {
|
||||
MutableComponent response = Component.literal("Successfully removed category \"");
|
||||
|
||||
MutableComponent sub = Component.literal(type);
|
||||
sub.setStyle(sub.getStyle().withColor(ChatFormatting.GREEN));
|
||||
response.getSiblings().add(sub);
|
||||
|
||||
sub = Component.literal("\" from ignore_damage_sources");
|
||||
response.getSiblings().add(sub);
|
||||
|
||||
c.getSource().sendSuccess(response, true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
c.getSource().sendFailure(Component.literal("Failed to remove type \"" + type + "\" from ignore_damage_sources"));
|
||||
return 1;
|
||||
}))))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ license="MIT"
|
|||
# The modid of the mod
|
||||
modId="com_burnedkirby_turnbasedminecraft" #mandatory
|
||||
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
|
||||
version="1.19.0" #mandatory
|
||||
version="1.20.0" #mandatory
|
||||
# A display name for the mod
|
||||
displayName="TurnBasedMinecraftMod" #mandatory
|
||||
# A URL to query for updates for this mod. See the JSON update specification <here>
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -3,7 +3,7 @@
|
|||
"modid": "com_burnedkirby_turnbasedminecraft",
|
||||
"name": "Turn Based Minecraft",
|
||||
"description": "Changes battles to be turn-based.",
|
||||
"version": "1.19.0",
|
||||
"version": "1.20.0",
|
||||
"mcversion": "1.18.2",
|
||||
"url": "",
|
||||
"updateUrl": "",
|
||||
|
|
Loading…
Reference in a new issue