From 19364fe30485cc677f64ee9b7a1a3006758ab62b Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Sun, 8 Dec 2024 16:19:31 +0800 Subject: [PATCH] Fix gun bug and hashing algo bug --- examplemods/guns.js | 7 ++++--- postinit.js | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/examplemods/guns.js b/examplemods/guns.js index 6e086bf..46cc14d 100644 --- a/examplemods/guns.js +++ b/examplemods/guns.js @@ -53,11 +53,12 @@ } ModAPI.reflect.prototypeStack(itemClass, nmi_ItemPistol); nmi_ItemPistol.prototype.$onItemRightClick = function ($itemstack, $world, $player) { + var magic = ModAPI.reflect.getClassByName("DamageSource").staticVariables.magic; var world = ModAPI.util.wrap($world); var entityplayer = ModAPI.util.wrap($player); var shotentity = entityRayCast(entityplayer, world, 12.0) if (shotentity != null){ - shotentity.heal(-10); + shotentity.attackEntityFrom(magic, 10); world.playSoundAtEntity(entityplayer.getRef(), ModAPI.util.str("tile.piston.out"), 1.0, 1.8); } return $itemstack; @@ -98,12 +99,12 @@ "thirdperson": { "rotation": [ 5, 80, -45 ], "translation": [ 0, 1, -3 ], - "scale": [ 0.55, 0.55, 0.55 ] + "scale": [ 0.1, 0.1, 0.1 ] }, "firstperson": { "rotation": [ 0, -135, 25 ], "translation": [ 0, 4, 2 ], - "scale": [ 1.7, 1.7, 1.7 ] + "scale": [ 1.8, 1.8, 1.8 ] } } } diff --git a/postinit.js b/postinit.js index 53f76b1..4e44780 100644 --- a/postinit.js +++ b/postinit.js @@ -955,8 +955,8 @@ globalThis.modapi_postinit = "(" + (() => { } function qhash(txt, arr) { - var interval = 4095 - arr.length; - if (interval < 1) { + var interval = 4095; //used to be 4095 - arr.length, but that increases incompatibility based on load order and otehr circumstances + if (arr.length >= 4095) { console.error("[ModAPI.keygen] Ran out of IDs while generating for " + txt); return -1; } @@ -969,7 +969,7 @@ globalThis.modapi_postinit = "(" + (() => { } var hash = x; while (arr.includes(hash)) { - hash = (hash + 1) % (interval + arr.length); + hash = (hash + 1) % interval; } return hash; }