Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.18.1 Fabric port [Ported directly from last 1.14.4 commit] #21

Open
wants to merge 7 commits into
base: 1.14.4-fabric
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.


version = "1.12.2-1.2.1"
version = "1.12.2-1.3.1"
group= "net.profhugo.nodami" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "nodami"

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Mon Sep 14 12:28:28 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip
Binary file added lib/snakeyaml-1.30-sources.jar
Binary file not shown.
Binary file added lib/snakeyaml-1.30.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/java/profhugo/nodami/NoDamI.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class NoDamI {

public static final String MODID = "nodami";
public static final String NAME = "No Damage Immunity";
public static final String VERSION = "1.2.1";
public static final String VERSION = "1.3.1";

@Mod.Instance(MODID)
public static NoDamI instance;
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/profhugo/nodami/config/NodamiConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package profhugo.nodami.config;

import java.io.File;
import java.util.Arrays;
import java.util.HashSet;

import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.Loader;
Expand All @@ -13,7 +15,7 @@ public class NodamiConfig {
public static boolean excludePlayers, excludeAllMobs, debugMode;
public static float attackCancelThreshold, knockbackCancelThreshold;

public static String[] attackExcludedEntities, dmgReceiveExcludedEntities, damageSrcWhitelist;
public static HashSet<String> attackExcludedEntities, dmgReceiveExcludedEntities, damageSrcWhitelist;

public static void preInit() {
File configFile = new File(Loader.instance().getConfigDir(), "nodami.cfg");
Expand All @@ -34,9 +36,9 @@ private static void syncConfig() {
attackCancelThreshold = config.getFloat("attackCancelThreshold", "thresholds", 0.1f, -0.1f, 1, "How weak a player's attack can be before it gets nullified, from 0 (0%, cancels multiple attacks on the same tick) to 1 (100%, players cannot attack), or -0.1 (disables this feature)");
knockbackCancelThreshold = config.getFloat("knockbackCancelThreshold", "thresholds", 0.75f, -0.1f, 1, "How weak a player's attack can be before the knockback gets nullified, from 0 (0%, cancels multiple attacks on the same tick) to 1 (100%, no knockback), or -0.1 (disables this feature)");

attackExcludedEntities = config.getStringList("attackExcludedEntities", "exclusions", new String[] {"minecraft:slime", "tconstruct:blueslime", "thaumcraft:thaumslime", "grimoireofgaia:*"}, "List of entities that need to give i-frames on attacking");
dmgReceiveExcludedEntities = config.getStringList("damageReceiveExcludedEntities", "exclusions", new String[0], "List of entities that need to receive i-frames on receiving attacks or relies on iFrames");
damageSrcWhitelist = config.getStringList("dmgSrcWhitelist", "exclusions", new String[] {"inFire", "lava", "cactus", "lightningBolt", "inWall", "hotFloor"}, "List of damage sources that need to give i-frames on doing damage (ex: lava).");
attackExcludedEntities = new HashSet<>(Arrays.asList(config.getStringList("attackExcludedEntities", "exclusions", new String[] {"minecraft:slime", "tconstruct:blueslime", "thaumcraft:thaumslime"}, "List of entities that need to give i-frames on attacking")));
dmgReceiveExcludedEntities = new HashSet<>(Arrays.asList(config.getStringList("damageReceiveExcludedEntities", "exclusions", new String[0], "List of entities that need to receive i-frames on receiving attacks or relies on iFrames")));
damageSrcWhitelist = new HashSet<>(Arrays.asList(config.getStringList("dmgSrcWhitelist", "exclusions", new String[] {"inFire", "lava", "cactus", "lightningBolt", "inWall", "hotFloor"}, "List of damage sources that need to give i-frames on doing damage (ex: lava).")));

debugMode = config.getBoolean("debugMode", "misc", false, "If true, turns on feature which sends a message when a player receives damage, containing information such as the name of the source and the quantity. Use this to find the name of the source you need to whitelist, or the id of the mob you want to exclude.");

Expand Down
55 changes: 23 additions & 32 deletions src/main/java/profhugo/nodami/handlers/EntityHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,64 +16,55 @@

public class EntityHandler {

@SubscribeEvent(priority = EventPriority.LOWEST)
@SubscribeEvent(priority = EventPriority.LOW)
public void onEntityHurt(LivingHurtEvent event) {
if (!event.isCanceled()) {
EntityLivingBase entity = event.getEntityLiving();
if (entity.getEntityWorld().isRemote) {
return;
}
DamageSource source = event.getSource();
Entity trueSource = source.getTrueSource();
if (NodamiConfig.debugMode && entity instanceof EntityPlayer) {
String trueSourceName;
if (trueSource != null && EntityList.getKey(trueSource.getClass()) != null) {
trueSourceName = EntityList.getKey(trueSource.getClass()).toString();
} else {
trueSourceName = "null";
}
String message = String.format("Type of damage received: %s\nAmount: %.3f\nTrue Source (mob id): %s\n",
source.getDamageType(), event.getAmount(), source.getTrueSource() == null ? "null"
: EntityList.getKey(source.getTrueSource().getClass()).toString());
source.getDamageType(), event.getAmount(), trueSourceName);
((EntityPlayer) entity).sendMessage(new TextComponentString(message));
}

if (NodamiConfig.excludePlayers && entity instanceof EntityPlayer) {
return;
}

if (NodamiConfig.excludeAllMobs && !(entity instanceof EntityPlayer)) {
return;
}
for (String id : NodamiConfig.dmgReceiveExcludedEntities) {
ResourceLocation loc = EntityList.getKey(entity.getClass());
if (loc == null)
break;
int starIndex = id.indexOf('*');
if (starIndex != -1) {
if (loc.toString().indexOf(id.substring(0, starIndex)) != -1) {
return;
}
} else if (loc.toString().equals(id)) {
return;
}

ResourceLocation loc = EntityList.getKey(entity.getClass());
if (loc != null && NodamiConfig.dmgReceiveExcludedEntities.contains(loc.toString())) {
return;
}

// May have more DoTs missing in this list
// Not anymore (/s)
for (String dmgType : NodamiConfig.damageSrcWhitelist) {
if (source.getDamageType().equals(dmgType)) {
return;
}
if (NodamiConfig.damageSrcWhitelist.contains(source.getDamageType())) {
return;
}

// Mobs that do damage on collusion but have no attack timer
for (String id : NodamiConfig.attackExcludedEntities) {
if (source.getTrueSource() == null)
break;
ResourceLocation loc = EntityList.getKey(source.getTrueSource().getClass());
if (loc == null)
break;
int starIndex = id.indexOf('*');
if (starIndex != -1) {
if (loc.toString().indexOf(id.substring(0, starIndex)) != -1) {
return;
}
} else if (loc.toString().equals(id)) {
if (trueSource != null) {
loc = EntityList.getKey(trueSource.getClass());
if (loc != null && NodamiConfig.attackExcludedEntities.contains(loc.toString())) {
return;
}

}


entity.hurtResistantTime = NodamiConfig.iFrameInterval;
}
}
Expand Down