feat: Улучшения для кастомной брони
- Броню теперь можно надевать на стойку, а не только ложить ее в руку. - Броня надевается без открытия инвентаря.
This commit is contained in:
@@ -72,12 +72,13 @@ public class Main {
|
||||
loader.registerHooksInitializationForClass(GlobalBlockPalette.class);
|
||||
loader.registerHooksInitializationForClass(ServerHooks.class);
|
||||
loader.registerHooksInitializationForClass(CraftingTransactionPacket.class);
|
||||
loader.registerHooksInitializationForClass(Other.class);
|
||||
loader.registerHooksInitializationForClass(RhinoOverrides.class);
|
||||
loader.registerHooksInitializationForClass(PlayerHooks.class);
|
||||
loader.registerHooksInitializationForClass(RuntimeItemsHooks.class);
|
||||
loader.registerHooksInitializationForClass(BlocksHooks.class);
|
||||
loader.registerHooksInitializationForClass(LevelHooks.class);
|
||||
loader.registerHooksInitializationForClass(ItemUtils.class);
|
||||
loader.registerHooksInitializationForClass(EntityOverrides.class);
|
||||
loader.registerHooksInitializationForClass(AndroidHooks.class);
|
||||
|
||||
if (Arrays.stream(args).anyMatch("--snowfall-everywhere"::equals)) {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.reider745.hooks;
|
||||
|
||||
import com.reider745.api.hooks.HookClass;
|
||||
import com.reider745.api.hooks.annotation.Hooks;
|
||||
|
||||
import javassist.CannotCompileException;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtMethod;
|
||||
import javassist.NotFoundException;
|
||||
|
||||
@Hooks(className = "cn.nukkit.entity.item.EntityArmorStand")
|
||||
public class EntityOverrides implements HookClass {
|
||||
|
||||
@Override
|
||||
public void init(CtClass ctClass) {
|
||||
try {
|
||||
CtMethod onInteractMethod = ctClass.getDeclaredMethod("onInteract");
|
||||
onInteractMethod.insertAt(onInteractMethod.getMethodInfo().getLineNumber(70),
|
||||
"if (flag && item instanceof com.reider745.item.CustomArmorItem) {"
|
||||
+ "i = ((com.reider745.item.CustomArmorItem) item).getArmorSlot();"
|
||||
+ "isArmorSlot = true;"
|
||||
+ "}");
|
||||
} catch (NotFoundException | CannotCompileException e) {
|
||||
System.out.println("Nukkit-MOT has been updated and overrides for `EntityArmorStand.onInteract` method are no longer available.");
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -15,7 +15,7 @@ import com.reider745.api.hooks.annotation.Hooks;
|
||||
import com.reider745.api.hooks.annotation.Inject;
|
||||
|
||||
@Hooks(className = "org.mozilla.javascript.JavaMembers")
|
||||
public class Other implements HookClass {
|
||||
public class RhinoOverrides implements HookClass {
|
||||
private static final Logger logger = LogManager.getLogger(MainLogger.class);
|
||||
|
||||
@Override
|
||||
@@ -4,6 +4,11 @@ import com.reider745.api.CustomManager;
|
||||
|
||||
import com.reider745.item.ItemMethod.PropertiesNames;
|
||||
|
||||
import cn.nukkit.Player;
|
||||
import cn.nukkit.item.Item;
|
||||
import cn.nukkit.math.Vector3;
|
||||
import cn.nukkit.network.protocol.LevelSoundEventPacket;
|
||||
|
||||
public class CustomArmorItem extends CustomItemClass {
|
||||
private int slot;
|
||||
|
||||
@@ -21,6 +26,10 @@ public class CustomArmorItem extends CustomItemClass {
|
||||
this.slot = parameters.get(PropertiesNames.Armors.SLOT, -1);
|
||||
}
|
||||
|
||||
public int getArmorSlot() {
|
||||
return slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArmor() {
|
||||
return true;
|
||||
@@ -65,4 +74,37 @@ public class CustomArmorItem extends CustomItemClass {
|
||||
public int getToughness() {
|
||||
return (int) (float) parameters.get(PropertiesNames.Armors.KNOCKBACK_RESIST, 0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClickAir(Player player, Vector3 directionVector) {
|
||||
boolean equip = false;
|
||||
Item oldSlotItem = Item.get(AIR);
|
||||
if (this.isHelmet()) {
|
||||
oldSlotItem = player.getInventory().getHelmetFast();
|
||||
if (player.getInventory().setHelmet(this)) {
|
||||
equip = true;
|
||||
}
|
||||
} else if (this.isChestplate()) {
|
||||
oldSlotItem = player.getInventory().getChestplateFast();
|
||||
if (player.getInventory().setChestplate(this)) {
|
||||
equip = true;
|
||||
}
|
||||
} else if (this.isLeggings()) {
|
||||
oldSlotItem = player.getInventory().getLeggingsFast();
|
||||
if (player.getInventory().setLeggings(this)) {
|
||||
equip = true;
|
||||
}
|
||||
} else if (this.isBoots()) {
|
||||
oldSlotItem = player.getInventory().getBootsFast();
|
||||
if (player.getInventory().setBoots(this)) {
|
||||
equip = true;
|
||||
}
|
||||
}
|
||||
if (equip) {
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemIndex(), oldSlotItem);
|
||||
player.getLevel().addLevelSoundEvent(player, LevelSoundEventPacket.SOUND_ARMOR_EQUIP_GENERIC);
|
||||
}
|
||||
|
||||
return this.getCount() == 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user