logo
0
0
WeChat Login

HBM mod 修改

基础属性修改

Hbm-s-Nuclear-Tech-GIT/src/main/java/com/hbm/main/MainRegistry.java

// Armor Materials public static ArmorMaterial aMatSchrab = EnumHelper.addArmorMaterial("HBM_SCHRABIDIUM", 500, new int[] { 12, 32, 24, 12 }, 50);

100为装备耐久度的相对值

6, 16, 12, 6 分别为头盔胸甲裤子和鞋子的盔甲值

套装减伤修改

Hbm-s-Nuclear-Tech-GIT/src/main/java/com/hbm/util/DamageResistanceHandler.java

registerSet(ModItems.schrabidium_helmet, ModItems.schrabidium_plate, ModItems.schrabidium_legs, ModItems.schrabidium_boots, new ResistanceStats() .addCategory(CATEGORY_PHYSICAL, 0F, 0.95F) .setOther(0F, 0.9F));

意思是套装的物理减伤为95%,其他减伤为90%,从0开始减伤,0以下伤害忽略

套装buff增加

HBM/src/main/java/com/hbm/items/ModItemsArmor.java

abidium_helmet = new ArmorFSB(MainRegistry.aMatSchrab, 0, RefStrings.MODID + ":textures/armor/schrabidium_1.png") .addEffect(new PotionEffect(Potion.digSpeed.id, 20, 2)) .addEffect(new PotionEffect(Potion.damageBoost.id, 20, 2)) .addEffect(new PotionEffect(Potion.jump.id, 20, 1)) .addEffect(new PotionEffect(Potion.moveSpeed.id, 20, 3)) .addEffect(new PotionEffect(Potion.regeneration.id, 20, 1)) .addEffect(new PotionEffect(Potion.resistance.id, 20, 3)) .addEffect(new PotionEffect(Potion.nightVision.id, 20, 1)) .setUnlocalizedName("schrabidium_helmet").setTextureName(RefStrings.MODID + ":schrabidium_helmet");

新增护甲值随耐久度变化的功能

hbm/src/main/java/com/hbm/items/armor/ArmorFSB.java

public class ArmorFSB extends ItemArmor implements IArmorDisableModel { private String texture = ""; private ResourceLocation overlay = null; public List<PotionEffect> effects = new ArrayList<PotionEffect>(); public boolean noHelmet = false; public boolean vats = false; public boolean thermal = false; public boolean geigerSound = false; public boolean customGeiger = false; public boolean hardLanding = false; public int dashCount = 0; public int stepSize = 0; public int tmp = 0; // 添加变量用于存储最大护甲值属性 public String step; public String jump; public String fall;

forge内置的工具链(未使用)

import cpw.mods.fml.relauncher.ReflectionHelper; ReflectionHelper.setPrivateValue(ItemArmor.class, (ItemArmor)entry.item, (int)entry.value, 3);

hbm/src/main/java/com/hbm/util/DamageResistanceHandler.java

/// ARMOR /// for(int i = 1; i <= 4; i++) { ItemStack armor = entity.getEquipmentInSlot(i); if(armor == null) continue; if(!(armor.getItem() instanceof ArmorFSB)) continue; ArmorFSB a = ((ArmorFSB) armor.getItem()); // MainRegistry.logger.warn("damageReduceAmount: " + a.damageReduceAmount + " tmp:" + a.tmp); try { Field[] fields = a.getClass().getSuperclass().getDeclaredFields(); for (Field field : fields) { // 设置字段为可访问,即使是private字段 field.setAccessible(true); // field_77879_b MainRegistry.logger.info( "字段名称: " + field.getName() + " 字段修饰符: " + field.getModifiers() + " 字段值: " + field.get(a)); } } catch (Exception e) { MainRegistry.logger.error("字段访问异常: " + e.getMessage()); } // MainRegistry.logger.info("> getDTDR ARMOR entity.getEquipmentInSlot:" + i); int damaged = armor.getItemDamage(); int maxDamage = armor.getMaxDamage(); // MainRegistry.logger.info("getItemDamage:" + damaged + "getMaxDamage:" + maxDamage); try { Field f = a.getClass().getSuperclass().getDeclaredField("field_77879_b"); f.setAccessible(true); if(a.tmp == 0){ a.tmp = f.getInt(a); } int fin = (int) Math.floor(a.tmp * (1F - ((float) damaged / (float) maxDamage))); MainRegistry.logger.warn("fin: " + fin); f.set(a, fin); } catch (Exception e) { MainRegistry.logger.error("异常: " + e.getMessage()); } }

MC护甲属性是通过访问ItemArmor类的damageReduceAmount属性实现的,在编译之后是field_77879_b

数据包同步

由于护甲值计算仅在服务端执行,需要添加数据包同步到客户端才能在玩家界面正确显示。

新增文件

hbm/src/main/java/com/hbm/packet/toclient/ArmorValueSyncPacket.java

public class ArmorValueSyncPacket implements IMessage { private int entityId; // 实体ID private int slot; // 装备槽位(1-4) private int armorValue; // 计算后的护甲值 // 客户端收到后通过反射修改护甲值字段 @SideOnly(Side.CLIENT) public IMessage onMessage(ArmorValueSyncPacket m, MessageContext ctx) { // ... 反射修改 field_77879_b } }

修改文件

hbm/src/main/java/com/hbm/packet/PacketDispatcher.java

wrapper.registerMessage(ArmorValueSyncPacket.Handler.class, ArmorValueSyncPacket.class, i++, Side.CLIENT);

hbm/src/main/java/com/hbm/util/DamageResistanceHandler.java

// 计算完护甲值后发送同步包 if(!entity.worldObj.isRemote) { ArmorValueSyncPacket.sendToAll(entity, i, fin); }
public class ItemArmor extends Item { /** Stores the armor type: 0 is helmet, 1 is plate, 2 is legs and 3 is boots */ public final int armorType; /** Holds the amount of damage that the armor reduces at full durability. */ public final int damageReduceAmount; } // hbm/build/tmp/recompSrc/net/minecraftforge/common/ForgeHooks.java public static int getTotalArmorValue(EntityPlayer player) { int ret = 0; for (int x = 0; x < player.inventory.armorInventory.length; x++) { ItemStack stack = player.inventory.armorInventory[x]; if (stack != null && stack.getItem() instanceof ISpecialArmor) { ret += ((ISpecialArmor)stack.getItem()).getArmorDisplay(player, stack, x); } else if (stack != null && stack.getItem() instanceof ItemArmor) { ret += ((ItemArmor)stack.getItem()).damageReduceAmount; } } return ret; }

Unknown

Hbm-s-Nuclear-Tech-GIT/src/main/java/com/hbm/handler/HazmatRegistry.java

double schrab = 3D; // 99.9% double euph = 10D; // <100% HazmatRegistry.registerHazmat(ModItems.schrabidium_helmet, schrab * helmet); HazmatRegistry.registerHazmat(ModItems.schrabidium_plate, schrab * chest); HazmatRegistry.registerHazmat(ModItems.schrabidium_legs, schrab * legs); HazmatRegistry.registerHazmat(ModItems.schrabidium_boots, schrab * boots);

功能暂时未知

Hbm-s-Nuclear-Tech-GIT/src/main/java/com/hbm/main/ModEventHandler.java

event.player.inventory.addItemStackToInventory(new ItemStack(ModItems.book_guide, 1, BookType.STARTER.ordinal())); ItemStack h = new ItemStack(ModItems.schrabidium_helmet, 1); ItemStack p = new ItemStack(ModItems.schrabidium_plate, 1); ItemStack l = new ItemStack(ModItems.schrabidium_legs, 1); ItemStack b = new ItemStack(ModItems.schrabidium_boots, 1); NBTTagCompound Protection = new NBTTagCompound(); Protection.setShort("id", (short) 0); Protection.setShort("lvl", (short) 5); NBTTagCompound Unbreaking = new NBTTagCompound(); Unbreaking.setShort("id", (short) 34); Unbreaking.setShort("lvl", (short) 5); NBTTagCompound Mending = new NBTTagCompound(); Mending.setShort("id", (short) 70); Mending.setShort("lvl", (short) 1); NBTTagCompound FeatherFalling = new NBTTagCompound(); FeatherFalling.setShort("id", (short) 2); FeatherFalling.setShort("lvl", (short) 5); NBTTagCompound BlastProtection = new NBTTagCompound(); BlastProtection.setShort("id", (short) 3); BlastProtection.setShort("lvl", (short) 5); NBTTagCompound ProjectileProtection = new NBTTagCompound(); ProjectileProtection.setShort("id", (short) 3); ProjectileProtection.setShort("lvl", (short) 5); NBTTagCompound nbt = new NBTTagCompound(); NBTTagList ench = new NBTTagList(); ench.appendTag(Protection); ench.appendTag(Unbreaking); ench.appendTag(Mending); ench.appendTag(ProjectileProtection); ench.appendTag(BlastProtection); nbt.setTag("ench", ench); h.setTagCompound(nbt); p.setTagCompound(nbt); l.setTagCompound(nbt); ench.appendTag(FeatherFalling); nbt.setTag("ench", ench); b.setTagCompound(nbt); boolean addh = event.player.inventory.addItemStackToInventory(h); boolean addp = event.player.inventory.addItemStackToInventory(p); boolean addl = event.player.inventory.addItemStackToInventory(l); boolean addb = event.player.inventory.addItemStackToInventory(b); MainRegistry.logger.info("[GIVE BOOK AND INT]" + addh + " " + addp + " " + addl + " " + addb); event.player.inventoryContainer.detectAndSendChanges(); props.hasReceivedBook = true;

附魔名称 附魔 ID 保护 (Protection) 0 火焰保护 (Fire Protection) 1 摔落保护 (Feather Falling) 2 爆炸保护 (Blast Protection) 3 弹射物保护 (Projectile Protection) 4 水下呼吸 (Respiration) 5 水下速掘 (Aqua Affinity) 6 锋利 (Sharpness) 16 亡灵杀手 (Smite) 17 节肢杀手 (Bane of Arthropods) 18 击退 (Knockback) 19 火焰附加 (Fire Aspect) 20 抢夺 (Looting) 21 效率 (Efficiency) 32 精准采集 (Silk Touch) 33 耐久 (Unbreaking) 34 时运 (Fortune) 35 力量 (Power) 48 冲击 (Punch) 49 火矢 (Flame) 50 无限 (Infinity) 51

WAIT

onArmorTick

net.minecraft.item.ItemArmor.damageReduceAmount 盔甲护甲值

net.minecraft.item.ItemArmor.onArmorTick 穿在身上的时候的每时每刻都会调用的方法,可以用来追加药水效果什么的 getAttributeModifiers

大脑融化了,防护添加

About

No description, topics, or website provided.
Language
Java98.9%
Shell1.1%