-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Everything is broken, but hey, it sometimes even opens world without …
…crashing
- Loading branch information
1 parent
f8b5978
commit 7486b4e
Showing
28 changed files
with
117 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 17 additions & 29 deletions
46
src/main/java/dev/latvian/mods/kubejs/bindings/DamageSourceWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,21 @@ | ||
package dev.latvian.mods.kubejs.bindings; | ||
|
||
public class DamageSourceWrapper { | ||
/*private static Map<String, DamageSource> damageSourceMap; | ||
public static DamageSource of(Object name) { | ||
if (name instanceof DamageSource damageSource) { | ||
return damageSource; | ||
} | ||
if (name instanceof Player player) { | ||
return DamageSource.playerAttack(player); | ||
} | ||
if (damageSourceMap == null) { | ||
damageSourceMap = new HashMap<>(); | ||
import dev.latvian.mods.kubejs.util.UtilsJS; | ||
import dev.latvian.mods.rhino.Context; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.world.damagesource.DamageSource; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.neoforged.neoforge.server.ServerLifecycleHooks; | ||
|
||
try { | ||
for (var field : DamageSource.class.getDeclaredFields()) { | ||
field.setAccessible(true); | ||
if (Modifier.isStatic(field.getModifiers()) && field.getType() == DamageSource.class) { | ||
var s = (DamageSource) field.get(null); | ||
damageSourceMap.put(s.getMsgId(), s); | ||
} | ||
} | ||
} catch (Exception ignored) { | ||
} | ||
} | ||
return damageSourceMap.getOrDefault(String.valueOf(name), DamageSource.GENERIC); | ||
}*/ | ||
public class DamageSourceWrapper { | ||
public static DamageSource of(Context cx, Object from) { | ||
return switch (from) { | ||
case DamageSource source -> source; | ||
case Player player -> ServerLifecycleHooks.getCurrentServer().kjs$getOverworld().damageSources().playerAttack(player); | ||
case LivingEntity livingEntity -> ServerLifecycleHooks.getCurrentServer().kjs$getOverworld().damageSources().mobAttack(livingEntity); | ||
case null, default -> ServerLifecycleHooks.getCurrentServer().kjs$getOverworld().damageSources().source(ResourceKey.create(Registries.DAMAGE_TYPE, UtilsJS.getMCID(cx, from))); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.