Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

cwJn

Members
  • Posts

    18
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

cwJn's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Why? Do you know a better way of doing it?
  2. It's because I need to take the original item's attack damage attribute and convert it to data in my capability. So the original attribute needs to be removed, and I also need that data.
  3. I'm having the strangest problem with my item events, and I can't think of a reason why this could be happening. To start, I have the following event. //this method needs to remove the armour (toughness) and attack damage from items. Also, //use the attack damage and armour to convert to extra damage @SubscribeEvent(priority = LOWEST) public static void removeVanillaAttributes(ItemAttributeModifierEvent event) { ItemStack item = event.getItemStack(); //the item if (!(GearApi.isGear(item))) { double damage = event.removeAttribute(ATTACK_DAMAGE).stream().mapToDouble(AttributeModifier::getAmount).sum(); //the sum of the damage attribute double armor = event.removeAttribute(ARMOR).stream().mapToDouble(AttributeModifier::getAmount).sum(); //the sum of the armor attribute IDamageTypes typing = item.getCapability(CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY).orElse(null); IDamageResistance res = item.getCapability(CapabilityDamageResistance.DAMAGE_RESISTANCE_CAPABILITY).orElse(null); if (typing != null) { doDamageTypesCalc(damage, item); } if (res != null) { doResistanceCalc(armor, item); } } else { event.removeAttribute(ATTACK_DAMAGE).stream().mapToDouble(AttributeModifier::getAmount).sum(); //the sum of the damage attribute event.removeAttribute(ARMOR).stream().mapToDouble(AttributeModifier::getAmount).sum(); //the sum of the armor attribute double armor = GearApi.getStat(item, ItemStats.ARMOR); double damage = GearApi.getStat(item, ItemStats.MELEE_DAMAGE); damage += GearApi.getStat(item, ItemStats.RANGED_DAMAGE); IDamageTypes typing = item.getCapability(CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY).orElse(null); IDamageResistance res = item.getCapability(CapabilityDamageResistance.DAMAGE_RESISTANCE_CAPABILITY).orElse(null); if (typing != null) { handleSilentGearTool(item, damage); } if (res != null) { handleSilentGearArmour(item, armor); } } event.removeAttribute(ARMOR_TOUGHNESS); //remove redundant stat } All of the calculation helper methods work the same way, so I'll just use the doDamageTypesCalc as example. private static void doDamageTypesCalc(double val, ItemStack item) { item.getCapability(CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY).ifPresent(c -> { //we only want to change the capability if it hasn't been affected yet. This assumes if an item has a damage capability, it isn't all 0. if (c.getSlashDamage() == 0 && c.getPunctureDamage() == 0 && c.getImpactDamage() == 0 && c.getFireDamage() == 0 && c.getLightningDamage() == 0 && c.getIceDamage() == 0 && c.getDarkDamage() == 0 && c.getHolyDamage() == 0 && c.getMagicDamage() == 0) { System.out.println("recognized damage capability as all 0, updating damage."); WeaponItemData data = JSONHandler.getWeaponData(item.getItem().getRegistryName()); // get data from config file double[] damageConversions = data.getDmgConversion(); //get item's conversion ratios float i = data.getImpactDmg(); //get base damages float p = data.getPunctureDmg(); float s = data.getSlashDmg(); float f = data.getFireDmg(); float l = data.getLightningDmg(); float ic = data.getIceDmg(); float d = data.getDarkDmg(); float h = data.getHolyDmg(); float m = data.getMagicDmg(); double id, pd, sd, fd, ld, icd, dd, hd, md; id = (val * damageConversions[0]) + i; //add them together pd = (val * damageConversions[1]) + p; sd = (val * damageConversions[2]) + s; fd = (val * damageConversions[3]) + f; ld = (val * damageConversions[4]) + l; icd = (val * damageConversions[5]) + ic; dd = (val * damageConversions[6]) + d; hd = (val * damageConversions[7]) + h; md = (val * damageConversions[8]) + m; int sharpnessLevel = EnchantmentHelper.getItemEnchantmentLevel(SHARPNESS, item); //System.out.println("sharpness level: " + sharpnessLevel); c.setImpactDamage((float) id); c.setPunctureDamage((float) pd); c.setSlashDamage((float) sd); c.setFireDamage((float) fd); c.setLightningDamage((float) ld); c.setIceDamage((float) icd); c.setDarkDamage((float) dd); c.setHolyDamage((float) hd); c.setMagicDamage((float) md); } }); } In this method, I use a custom capability to update the weapon's "damage typing". (ignore the system print lines, they are used for debugging and will be removed). This method works correctly, which then brings me to my event that adds a tooltip to display these properties. @SubscribeEvent(priority = LOWEST) public static void addExtraDamageTooltip(ItemTooltipEvent event) { ItemStack item = event.getItemStack(); IDamageResistance res = item.getCapability(CapabilityDamageResistance.DAMAGE_RESISTANCE_CAPABILITY).orElse(null); IDamageTypes dmg = item.getCapability(CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY).orElse(null); if (res != null) { //MAKE VARIABLES float ir = res.getImpactResistance(); float pr = res.getPunctureResistance(); float sr = res.getSlashResistance(); float fr = res.getFireResistance(); float lr = res.getLightningResistance(); float icr = res.getIceResistance(); float dr = res.getDarkResistance(); float hr = res.getHolyResistance(); float mr = res.getMagicResistance(); IFormattableTextComponent impactText; IFormattableTextComponent punctureText; IFormattableTextComponent slashText; IFormattableTextComponent fireText; IFormattableTextComponent lightningText; IFormattableTextComponent iceText; IFormattableTextComponent darkText; IFormattableTextComponent holyText; IFormattableTextComponent magicText; IFormattableTextComponent resistanceText; IFormattableTextComponent irText; IFormattableTextComponent prText; IFormattableTextComponent srText; IFormattableTextComponent frText; IFormattableTextComponent lrText; IFormattableTextComponent icrText; IFormattableTextComponent drText; IFormattableTextComponent hrText; IFormattableTextComponent mrText; resistanceText = new TranslationTextComponent("----------Damage Resistances----------"); impactText = new TranslationTextComponent("Impact Resistance: "); punctureText = new TranslationTextComponent("Puncture Resistance: "); slashText = new TranslationTextComponent("Slash Resistance: "); fireText = new TranslationTextComponent("Fire Resistance: "); lightningText = new TranslationTextComponent("Lightning Resistance: "); iceText = new TranslationTextComponent("Ice Resistance: "); darkText = new TranslationTextComponent("Dark Resistance: "); holyText = new TranslationTextComponent("Divine Resistance: "); magicText = new TranslationTextComponent("Magic Resistance: "); irText = new TranslationTextComponent(df.format(ir)); prText = new TranslationTextComponent(df.format(pr)); srText = new TranslationTextComponent(df.format(sr)); frText = new TranslationTextComponent(df.format(fr)); lrText = new TranslationTextComponent(df.format(lr)); icrText = new TranslationTextComponent(df.format(icr)); drText = new TranslationTextComponent(df.format(dr)); hrText = new TranslationTextComponent(df.format(hr)); mrText = new TranslationTextComponent(df.format(mr)); event.getToolTip().add(TextUtil.withColor(resistanceText, Color.MAGENTA).withStyle(TextFormatting.BOLD)); event.getToolTip().add(TextUtil.withColor(impactText, Color.GREEN).append(TextUtil.withColor(irText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(punctureText, Color.GREEN).append(TextUtil.withColor(prText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(slashText, Color.GREEN).append(TextUtil.withColor(srText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(fireText, Color.ORANGERED).append(TextUtil.withColor(frText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(lightningText, Color.YELLOW).append(TextUtil.withColor(lrText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(iceText, Color.LIGHTBLUE).append(TextUtil.withColor(icrText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(darkText, Color.DARKVIOLET).append(TextUtil.withColor(drText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(holyText, Color.FLORALWHITE).append(TextUtil.withColor(hrText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(magicText, Color.CORNFLOWERBLUE).append(TextUtil.withColor(mrText, Color.LIGHTSTEELBLUE))); } else if (dmg != null) { float id = dmg.getImpactDamage(); float pd = dmg.getPunctureDamage(); float sd = dmg.getSlashDamage(); float fd = dmg.getFireDamage(); float ld = dmg.getLightningDamage(); float icd = dmg.getIceDamage(); float dd = dmg.getDarkDamage(); float hd = dmg.getHolyDamage(); float md = dmg.getMagicDamage(); IFormattableTextComponent impactText; IFormattableTextComponent punctureText; IFormattableTextComponent slashText; IFormattableTextComponent fireText; IFormattableTextComponent lightningText; IFormattableTextComponent iceText; IFormattableTextComponent darkText; IFormattableTextComponent holyText; IFormattableTextComponent magicText; IFormattableTextComponent damageText; IFormattableTextComponent idText; IFormattableTextComponent pdText; IFormattableTextComponent sdText; IFormattableTextComponent fdText; IFormattableTextComponent ldText; IFormattableTextComponent icdText; IFormattableTextComponent ddText; IFormattableTextComponent hdText; IFormattableTextComponent mdText; damageText = new TranslationTextComponent("----------Damage Typing----------"); impactText = new TranslationTextComponent("Impact Damage: "); punctureText = new TranslationTextComponent("Puncture Damage: "); slashText = new TranslationTextComponent("Slash Damage: "); fireText = new TranslationTextComponent("Fire Damage: "); lightningText = new TranslationTextComponent("Lightning Damage: "); iceText = new TranslationTextComponent("Ice Damage: "); darkText = new TranslationTextComponent("Dark Damage: "); holyText = new TranslationTextComponent("Divine Damage: "); magicText = new TranslationTextComponent("Magic Damage: "); idText = new TranslationTextComponent(df.format(id)); pdText = new TranslationTextComponent(df.format(pd)); sdText = new TranslationTextComponent(df.format(sd)); fdText = new TranslationTextComponent(df.format(fd)); ldText = new TranslationTextComponent(df.format(ld)); icdText = new TranslationTextComponent(df.format(icd)); ddText = new TranslationTextComponent(df.format(dd)); hdText = new TranslationTextComponent(df.format(hd)); mdText = new TranslationTextComponent(df.format(md)); event.getToolTip().add(TextUtil.withColor(damageText, Color.MAGENTA).withStyle(TextFormatting.BOLD)); event.getToolTip().add(TextUtil.withColor(impactText, Color.LIGHTGREEN).append(TextUtil.withColor(idText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(punctureText, Color.LIGHTGREEN).append(TextUtil.withColor(pdText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(slashText, Color.LIGHTGREEN).append(TextUtil.withColor(sdText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(fireText, Color.ORANGERED).append(TextUtil.withColor(fdText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(lightningText, Color.YELLOW).append(TextUtil.withColor(ldText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(iceText, Color.LIGHTBLUE).append(TextUtil.withColor(icdText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(darkText, Color.DARKVIOLET).append(TextUtil.withColor(ddText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(holyText, Color.FLORALWHITE).append(TextUtil.withColor(hdText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(magicText, Color.CORNFLOWERBLUE).append(TextUtil.withColor(mdText, Color.LIGHTSTEELBLUE))); } } The issue I'm having, is with the if statement check that I have surrounding my doDamageTypesCalc helper method (the one that checks if all those things are == 0). If I remove that if statement, the itemTooltip event starts displaying all 0's. I have no idea what could be causing the issue. I'm not sure if it will help, but these are my DamageType capability classes: public class CapabilityDamageTypes { @CapabilityInject(IDamageTypes.class) public static Capability<IDamageTypes> DAMAGE_TYPES_CAPABILITY = null; public static void register() { CapabilityManager.INSTANCE.register(IDamageTypes.class, new Storage(), new Factory()); } private static class Storage implements Capability.IStorage<IDamageTypes> { @Nullable @Override public INBT writeNBT(Capability<IDamageTypes> capability, IDamageTypes instance, Direction side) { CompoundNBT tag = new CompoundNBT(); tag.putFloat("slash", instance.getSlashDamage()); tag.putFloat("impact", instance.getImpactDamage()); tag.putFloat("puncture", instance.getPunctureDamage()); tag.putFloat("fire", instance.getFireDamage()); tag.putFloat("lightning", instance.getLightningDamage()); tag.putFloat("ice", instance.getIceDamage()); tag.putFloat("dark", instance.getDarkDamage()); tag.putFloat("holy", instance.getHolyDamage()); tag.putFloat("magic", instance.getMagicDamage()); tag.putString("mobDamageType", instance.getMobDamageType()); return tag; } @Override public void readNBT(Capability<IDamageTypes> capability, IDamageTypes instance, Direction side, INBT nbt) { float slash = ((CompoundNBT) nbt).getFloat("slash"); float impact = ((CompoundNBT) nbt).getFloat("impact"); float puncture = ((CompoundNBT) nbt).getFloat("puncture"); float fire = ((CompoundNBT) nbt).getFloat("fire"); float lightning = ((CompoundNBT) nbt).getFloat("lightning"); float ice = ((CompoundNBT) nbt).getFloat("ice"); float dark = ((CompoundNBT) nbt).getFloat("dark"); float holy = ((CompoundNBT) nbt).getFloat("holy"); float magic = ((CompoundNBT) nbt).getFloat("magic"); String mobDamageType = ((CompoundNBT) nbt).getString("mobDamageType"); instance.setSlashDamage(slash); instance.setImpactDamage(impact); instance.setPunctureDamage(puncture); instance.setFireDamage(fire); instance.setLightningDamage(lightning); instance.setIceDamage(ice); instance.setDarkDamage(dark); instance.setHolyDamage(holy); instance.setMagicDamage(magic); instance.setMobDamageType(mobDamageType); } } private static class Factory implements Callable<IDamageTypes> { @Override public IDamageTypes call() throws Exception { return new DamageTypes(0, 0, 0, 0, 0, 0, 0, 0, 0, "IMPACT"); } } } public class DamageTypesProvider implements ICapabilitySerializable<CompoundNBT> { private DamageTypes damage; private LazyOptional<IDamageTypes> damageOptional; public void invalidate() { damageOptional.invalidate(); } public DamageTypesProvider(float I, float P, float S, float F, float L, float IC, float D, float H, float M, String mobDamageType) { damage = new DamageTypes(I, P, S, F, L, IC, D, H, M, mobDamageType); damageOptional = LazyOptional.of(() -> damage); } @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { return cap == CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY ? damageOptional.cast() : LazyOptional.empty(); } @Override public CompoundNBT serializeNBT() { if (CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY == null) { return new CompoundNBT(); } else { return (CompoundNBT) CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY.writeNBT(damage, null); } } @Override public void deserializeNBT(CompoundNBT nbt) { if (CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY != null) { CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY.readNBT(damage, null, nbt); } } }
  4. This is the capability inject and provider for one of my capabilities. All of them are coded the exact same way. public class CapabilityDamageTypes { @CapabilityInject(IDamageTypes.class) public static Capability<IDamageTypes> DAMAGE_TYPES_CAPABILITY = null; public static void register() { CapabilityManager.INSTANCE.register(IDamageTypes.class, new Storage(), new Factory()); } private static class Storage implements Capability.IStorage<IDamageTypes> { @Nullable @Override public INBT writeNBT(Capability<IDamageTypes> capability, IDamageTypes instance, Direction side) { CompoundNBT tag = new CompoundNBT(); tag.putFloat("slash", instance.getSlashDamage()); tag.putFloat("impact", instance.getImpactDamage()); tag.putFloat("puncture", instance.getPunctureDamage()); tag.putFloat("fire", instance.getFireDamage()); tag.putFloat("lightning", instance.getLightningDamage()); tag.putFloat("ice", instance.getIceDamage()); tag.putFloat("dark", instance.getDarkDamage()); tag.putFloat("holy", instance.getHolyDamage()); tag.putFloat("magic", instance.getMagicDamage()); tag.putString("mobDamageType", instance.getMobDamageType()); return tag; } @Override public void readNBT(Capability<IDamageTypes> capability, IDamageTypes instance, Direction side, INBT nbt) { float slash = ((CompoundNBT) nbt).getFloat("slash"); float impact = ((CompoundNBT) nbt).getFloat("impact"); float puncture = ((CompoundNBT) nbt).getFloat("puncture"); float fire = ((CompoundNBT) nbt).getFloat("fire"); float lightning = ((CompoundNBT) nbt).getFloat("lightning"); float ice = ((CompoundNBT) nbt).getFloat("ice"); float dark = ((CompoundNBT) nbt).getFloat("dark"); float holy = ((CompoundNBT) nbt).getFloat("holy"); float magic = ((CompoundNBT) nbt).getFloat("magic"); String mobDamageType = ((CompoundNBT) nbt).getString("mobDamageType"); instance.setSlashDamage(slash); instance.setImpactDamage(impact); instance.setPunctureDamage(puncture); instance.setFireDamage(fire); instance.setLightningDamage(lightning); instance.setIceDamage(ice); instance.setDarkDamage(dark); instance.setHolyDamage(holy); instance.setMagicDamage(magic); instance.setMobDamageType(mobDamageType); } } private static class Factory implements Callable<IDamageTypes> { @Override public IDamageTypes call() throws Exception { return new DamageTypes(0, 0, 0, 0, 0, 0, 0, 0, 0, "IMPACT"); } } } package com.cwjn.hardstuckintegration.Capabilities.DamageTypes; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilitySerializable; import net.minecraftforge.common.util.LazyOptional; import javax.annotation.Nonnull; import javax.annotation.Nullable; public class DamageTypesProvider implements ICapabilitySerializable<CompoundNBT> { //private final DamageTypes damage = new DamageTypes(); //private final LazyOptional<IDamageTypes> damageOptional = LazyOptional.of(() -> damage); private DamageTypes damage; private LazyOptional<IDamageTypes> damageOptional; public void invalidate() { damageOptional.invalidate(); } public DamageTypesProvider(float I, float P, float S, float F, float L, float IC, float D, float H, float M, String mobDamageType) { damage = new DamageTypes(I, P, S, F, L, IC, D, H, M, mobDamageType); damageOptional = LazyOptional.of(() -> damage); } @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { return cap == CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY ? damageOptional.cast() : LazyOptional.empty(); } @Override public CompoundNBT serializeNBT() { if (CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY == null) { return new CompoundNBT(); } else { return (CompoundNBT) CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY.writeNBT(damage, null); } } @Override public void deserializeNBT(CompoundNBT nbt) { if (CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY != null) { CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY.readNBT(damage, null, nbt); } } }
  5. @SubscribeEvent public static void ItemHandler(AttachCapabilitiesEvent<ItemStack> event) { ItemStack item = event.getObject(); if (GearApi.isGear(item)) { SGearTraitHelperProvider provider = new SGearTraitHelperProvider(); event.addCapability(TRAIT_HELPER_KEY, provider); event.addListener(provider::invalidate); } if (isArmour(item) || item.getItem() instanceof ICoreArmor) { DamageResistanceProvider provider = new DamageResistanceProvider(0, 0, 0, 0, 0, 0, 0, 0, 0); event.addCapability(RES_KEY, provider); event.addListener(provider::invalidate); } else if (isWeapon(item) || item.getItem() instanceof ICoreTool) { DamageTypesProvider provider = new DamageTypesProvider(0, 0, 0, 0, 0, 0, 0, 0, 0, "IMPACT"); event.addCapability(DMG_KEY, provider); event.addListener(provider::invalidate); } }
  6. So I thought that when a capability is attached to an item/entity/etc... the capability will stay until whatever it's attached to is gone. But this doesn't seem to be the case, as when I printed to console whenever a capability is attached, it seems as though a new version of the capability is attached to an item every time I select it in my hotbar, hover over it in inventory, etc. Is this how it's supposed to work? If so, why?
  7. Hi, as the title says, I need to overwrite another mod's data/resources. I tried just adding files of the same directory and name, but they don't overwrite and are just ignored. Is this something to do with load order or do I need to make a separate datapack for this to work?
  8. I have to use events for this because I have to operate on every single item in the game. This is the code I'm worried about. I can't think of a better way to do this though. @Mod.EventBusSubscriber(modid = HardstuckIntegration.modID) public class ItemEvents { private static DecimalFormat df = new DecimalFormat("#.##"); //this method needs to remove the armour (toughness) and attack damage from items. Also, //use the attack damage and armour to convert to extra damage @SubscribeEvent(priority = LOWEST) public static void removeVanillaAttributes(ItemAttributeModifierEvent event) { ItemStack item = event.getItemStack(); //the item double damage = event.removeAttribute(ATTACK_DAMAGE).stream().mapToDouble(AttributeModifier::getAmount).sum(); //the sum of the damage attribute double armor = event.removeAttribute(ARMOR).stream().mapToDouble(AttributeModifier::getAmount).sum(); //the sum of the armor attribute if (armor > 0) { //make sure there is actually armor to convert doResistanceCalc(armor, item); //attach capabilities to the item by converting its base stats and taking the config into account } if (damage > 0) { //make sure there is actually damage to convert doDamageTypesCalc(damage, item); //attach capabilities to the item by converting its base stats and taking the config into account } event.removeAttribute(ARMOR_TOUGHNESS); //remove redundant stat } private static void doResistanceCalc(double val, ItemStack item) { item.getCapability(CapabilityDamageResistance.DAMAGE_RESISTANCE_CAPABILITY).ifPresent(c -> { //we only want to change the capability if it hasn't been affected yet. This assumes if an item has a resistance capability, it isn't all 0. if (c.getImpactResistance() == 0 && c.getPunctureResistance() == 0 && c.getSlashResistance() == 0 && c.getFireResistance() == 0 && c.getLightningResistance() == 0 && c.getIceResistance() == 0) { ArmourItemData data = JSONHandler.getArmourData(item.getItem().getRegistryName()); // get the data from config file double[] resistanceConversions = data.getResConversion(); //get item's conversion ratios float i = data.getImpactRes(); // get item's base resistances float p = data.getPunctureRes(); float s = data.getSlashRes(); float f = data.getFireRes(); float l = data.getLightningRes(); float ic = data.getIceRes(); double IRes, PRes, SRes, FRes, LRes, ICRes; IRes = (val * resistanceConversions[0]) + i; //add them together. PRes = (val * resistanceConversions[1]) + p; SRes = (val * resistanceConversions[2]) + s; FRes = (val * resistanceConversions[3]) + f; LRes = (val * resistanceConversions[4]) + l; ICRes = (val * resistanceConversions[5]) + ic; c.setImpactResistance((float) IRes); c.setPunctureResistance((float) PRes); c.setSlashResistance((float) SRes); c.setFireResistance((float) FRes); c.setLightningResistance((float) LRes); c.setIceResistance((float) ICRes); } }); } private static void doDamageTypesCalc(double val, ItemStack item) { item.getCapability(CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY).ifPresent(c -> { //we only want to change the capability if it hasn't been affected yet. This assumes if an item has a damage capability, it isn't all 0. if (c.getSlashDamage() == 0 && c.getPunctureDamage() == 0 && c.getImpactDamage() == 0 && c.getFireDamage() == 0 && c.getLightningDamage() == 0 && c.getIceDamage() == 0) { WeaponItemData data = JSONHandler.getWeaponData(item.getItem().getRegistryName()); // get data from config file double[] damageConversions = data.getDmgConversion(); //get item's conversion ratios float i = data.getImpactDmg(); //get base damages float p = data.getPunctureDmg(); float s = data.getSlashDmg(); float f = data.getFireDmg(); float l = data.getLightningDmg(); float ic = data.getIceDmg(); double id, pd, sd, fd, ld, icd; id = (val * damageConversions[0]) + i; //add them together pd = (val * damageConversions[1]) + p; sd = (val * damageConversions[2]) + s; fd = (val * damageConversions[3]) + f; ld = (val * damageConversions[4]) + l; icd = (val * damageConversions[5]) + ic; c.setImpactDamage((float) id); c.setPunctureDamage((float) pd); c.setSlashDamage((float) sd); c.setFireDamage((float) fd); c.setLightningDamage((float) ld); c.setIceDamage((float) icd); } }); } @SubscribeEvent(priority = LOWEST) public static void addExtraDamageTooltip(ItemTooltipEvent event) { ItemStack item = event.getItemStack(); IDamageResistance res = item.getCapability(CapabilityDamageResistance.DAMAGE_RESISTANCE_CAPABILITY).orElse(null); IDamageTypes dmg = item.getCapability(CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY).orElse(null); if (res != null) { //MAKE VARIABLES float ir = res.getImpactResistance(); float pr = res.getPunctureResistance(); float sr = res.getSlashResistance(); float fr = res.getFireResistance(); float lr = res.getLightningResistance(); float icr = res.getIceResistance(); IFormattableTextComponent impactText; IFormattableTextComponent punctureText; IFormattableTextComponent slashText; IFormattableTextComponent fireText; IFormattableTextComponent lightningText; IFormattableTextComponent iceText; IFormattableTextComponent resistanceText; IFormattableTextComponent irText; IFormattableTextComponent prText; IFormattableTextComponent srText; IFormattableTextComponent frText; IFormattableTextComponent lrText; IFormattableTextComponent icrText; resistanceText = new TranslationTextComponent("----------Damage Resistances----------"); impactText = new TranslationTextComponent("Impact Resistance: "); punctureText = new TranslationTextComponent("Puncture Resistance: "); slashText = new TranslationTextComponent("Slash Resistance: "); fireText = new TranslationTextComponent("Fire Resistance: "); lightningText = new TranslationTextComponent("Lightning Resistance: "); iceText = new TranslationTextComponent("Ice Resistance: "); irText = new TranslationTextComponent(df.format(ir)); prText = new TranslationTextComponent(df.format(pr)); srText = new TranslationTextComponent(df.format(sr)); frText = new TranslationTextComponent(df.format(fr)); lrText = new TranslationTextComponent(df.format(lr)); icrText = new TranslationTextComponent(df.format(icr)); event.getToolTip().add(TextUtil.withColor(resistanceText, Color.MEDIUMPURPLE).withStyle(TextFormatting.BOLD)); event.getToolTip().add(TextUtil.withColor(impactText, Color.LIGHTGREEN).append(TextUtil.withColor(irText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(punctureText, Color.LIGHTGREEN).append(TextUtil.withColor(prText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(slashText, Color.LIGHTGREEN).append(TextUtil.withColor(srText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(fireText, Color.ORANGERED).append(TextUtil.withColor(frText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(lightningText, Color.YELLOW).append(TextUtil.withColor(lrText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(iceText, Color.LIGHTBLUE).append(TextUtil.withColor(icrText, Color.LIGHTSTEELBLUE))); } if (dmg != null) { double attackSpeedMainhand = item.getItem().getDefaultInstance().getAttributeModifiers(EquipmentSlotType.MAINHAND).get(ATTACK_SPEED).stream().mapToDouble(AttributeModifier::getAmount).sum(); double attackSpeedOffhand = item.getItem().getDefaultInstance().getAttributeModifiers(EquipmentSlotType.OFFHAND).get(ATTACK_SPEED).stream().mapToDouble(AttributeModifier::getAmount).sum(); float id = dmg.getImpactDamage(); float pd = dmg.getPunctureDamage(); float sd = dmg.getSlashDamage(); float fd = dmg.getFireDamage(); float ld = dmg.getLightningDamage(); float icd = dmg.getIceDamage(); IFormattableTextComponent impactText; IFormattableTextComponent punctureText; IFormattableTextComponent slashText; IFormattableTextComponent fireText; IFormattableTextComponent lightningText; IFormattableTextComponent iceText; IFormattableTextComponent damageText; IFormattableTextComponent idText; IFormattableTextComponent pdText; IFormattableTextComponent sdText; IFormattableTextComponent fdText; IFormattableTextComponent ldText; IFormattableTextComponent icdText; damageText = new TranslationTextComponent("----------Damage Typing----------"); impactText = new TranslationTextComponent("Impact Damage: "); punctureText = new TranslationTextComponent("Puncture Damage: "); slashText = new TranslationTextComponent("Slash Damage: "); fireText = new TranslationTextComponent("Fire Damage: "); lightningText = new TranslationTextComponent("Lightning Damage: "); iceText = new TranslationTextComponent("Ice Damage: "); idText = new TranslationTextComponent(df.format(id)); pdText = new TranslationTextComponent(df.format(pd)); sdText = new TranslationTextComponent(df.format(sd)); fdText = new TranslationTextComponent(df.format(fd)); ldText = new TranslationTextComponent(df.format(ld)); icdText = new TranslationTextComponent(df.format(icd)); event.getToolTip().add(TextUtil.withColor(damageText, Color.MEDIUMPURPLE).withStyle(TextFormatting.BOLD)); event.getToolTip().add(TextUtil.withColor(impactText, Color.LIGHTGREEN).append(TextUtil.withColor(idText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(punctureText, Color.LIGHTGREEN).append(TextUtil.withColor(pdText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(slashText, Color.LIGHTGREEN).append(TextUtil.withColor(sdText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(fireText, Color.ORANGERED).append(TextUtil.withColor(fdText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(lightningText, Color.YELLOW).append(TextUtil.withColor(ldText, Color.LIGHTSTEELBLUE))); event.getToolTip().add(TextUtil.withColor(iceText, Color.LIGHTBLUE).append(TextUtil.withColor(icdText, Color.LIGHTSTEELBLUE))); } } }
  9. So in my mod I'm attaching a capability to any item which is an armour piece, weapon, or entity. To test my code, I made printed messages to console whenever the event fired. I noticed that these events would be firing multiple times per entity/item being affected. Is this something I need to worry about? I'm not very familiar with the intricacies of how capabilities work. On an unrelated note, I'm getting slightly worried about how my mod will cause the game to lag. I have methods that hook into the ItemAttributeModifier and ItemTooltip events, and use my capabilities to operate on the item's attributes and provide a custom tooltip. I'm not iterating through lists or anything, but it seems as though these events fire every tick the player has the item equipped. While this doesn't lag me in my dev environment, will this have larger ramifications when playing on servers with 4 - 8 players?
  10. Wouldn't this screw up the MobEntity doHurtTarget method though? I was looking through it, and it calls target.hurt(DamageSource.mobAttack(this)). It then checks this boolean result and if its true applies knockback and something to do with shields. If I cancelled the original attack event, wouldn't this boolean check always result false and mean entity attacks will never apply knockback?
  11. So i'm messing with the way damage calculation is done by hooking into the LivingHurt event. The problem is that to do this, I need to be able to set whether or not a DamageSource is able to be blocked by the vanilla armour stat. In net.minecraft.util.DamageSource, this is done by calling the constructor of a DamageSource object with .bypassArmor() or .bypassMagic(). However, some of the DamageSources, like thorns or fireball, are called via methods. I can change the DamageSources that are static fields via access transformers, but I can't think of a way to change the DamageSources that are called with methods. Is this just impossible, or is there some way I can do it? Thanks.
  12. The end goal of this is to apply a set of capabilities to every registered mob in the game, including any mods. I figure the best way to do this would be to autogenerate a list of all registered mobs in some sort of config file, which then will send the values (3 floats) to my capability handler.
  13. I see. Is there an automated way to get a list of every mob for datapacks though?
  14. Hello. I'm currently trying to make a config to build a list of all registered LivingEntity instances from both installed mods and vanilla. Right now I'm attempting to use ForgeConfigSpec, but there's no documentation for it so I'm not sure what I'm doing. package com.cwjn.hardstuckintegration.Config; import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntityType; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.registries.ForgeRegistries; public class ResistancesConfig { public static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder(); public static final ForgeConfigSpec SPEC; static { for (EntityType<?> entity : ForgeRegistries.ENTITIES.getValues()) { EntityClassification type = entity.getCategory(); if (type == EntityClassification.CREATURE || type == EntityClassification.MONSTER || type == EntityClassification.WATER_CREATURE) { BUILDER.define("test_config_option_1_" + entity.toString(), 0.0f); BUILDER.define("test_config_option_2_" + entity.toString(), 0.0f); BUILDER.pop(); } } SPEC = BUILDER.build(); } } I guess the question would be, is there a better/easier way to do this? Someone has recommended using a JSON loader on startup, but before I go and learn how to do that I want to see if there's a way to make this work.
  15. Thanks for the advice, I'm now able to get the events working to a degree. The issue I'm having now is this: I have a capability for both damage type and damage resistance. There are 3 new damage types that each have a corresponding resistance. Damage type capabilities are attached to weapons, while resistance capabilities are applied to entities. I use the following methods to apply extra damage types as well as calculate resistances. The problem is that when attacking an entity, only 1 instance of the new damage types is applied. As for the debugging messages, the 3 sendMessages are being sent in the extraDamage method. In the damageResistance method, only 1 System.out.println statement is being sent. Is there something to do with the way LivingHurtEvent works that only allowed 1 to be applied? package com.cwjn.hardstuckintegration.Events; import com.cwjn.hardstuckintegration.Capabilities.DamageTypes.CapabilityDamageTypes; import com.cwjn.hardstuckintegration.Capabilities.DamageTypes.IDamageTypes; import com.cwjn.hardstuckintegration.Capabilities.Resistances.CapabilityDamageResistance; import com.cwjn.hardstuckintegration.Capabilities.Resistances.IDamageResistance; import com.cwjn.hardstuckintegration.DamageTypes.ImpactDamage; import com.cwjn.hardstuckintegration.DamageTypes.NewType; import com.cwjn.hardstuckintegration.DamageTypes.PunctureDamage; import com.cwjn.hardstuckintegration.DamageTypes.SlashDamage; import com.cwjn.hardstuckintegration.HardstuckIntegration; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; import net.minecraft.util.Hand; import net.minecraft.util.text.TranslationTextComponent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.AttackEntityEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(modid = HardstuckIntegration.modID) public class DamageEvents { @SubscribeEvent public static void extraDamage(AttackEntityEvent event) { PlayerEntity player = event.getPlayer(); //player that is attacking Entity target = event.getTarget(); //target being attacked ItemStack item = player.getItemInHand(Hand.MAIN_HAND); //item used to attack if (item != null) { IDamageTypes damage = item.getCapability(CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY).orElse(null); //get the extra damage types if (damage != null) { float impactDamage = damage.getImpactDamage(); float slashDamage = damage.getSlashDamage(); //store the extra damage types float punctureDamage = damage.getPunctureDamage(); if (impactDamage > 0) { player.sendMessage(new TranslationTextComponent("TARGET ENTITY DEALT: " + impactDamage + " POINTS OF IMPACT DAMAGE"), player.getUUID()); target.hurt(new ImpactDamage(), impactDamage); //if the item has extra impact damage, hurt the target with an instance of impact damage } if (slashDamage > 0) { player.sendMessage(new TranslationTextComponent("TARGET ENTITY DEALT: " + slashDamage + " POINTS OF SLASH DAMAGE"), player.getUUID()); target.hurt(new SlashDamage(), slashDamage); //if the item has extra slash damage, hurt the target with an instance of slash damage } if (punctureDamage > 0) { player.sendMessage(new TranslationTextComponent("TARGET ENTITY DEALT: " + punctureDamage + " POINTS OF PUNCTURE DAMAGE"), player.getUUID()); target.hurt(new PunctureDamage(), punctureDamage); //if the item has extra puncture damage, hurt the target with an instance of puncture damage } } } } @SubscribeEvent public static void damageResistance(LivingHurtEvent event) { DamageSource source = event.getSource(); //source of damage if (source instanceof NewType) { //check if the source is a subclass of the new damage types added with this mod float amount = event.getAmount(); //get initial amount of new damage, before resistances LivingEntity target = event.getEntityLiving(); //target of damage float newDamage = amount; //variable to hold post-resistance calculation damage IDamageResistance res = target.getCapability(CapabilityDamageResistance.DAMAGE_RESISTANCE_CAPABILITY).orElse(null); //get target's resistances if (res != null) { float impactRes = res.getImpactResistance(); float slashRes = res.getSlashResistance(); //store the resistances float punctureRes = res.getPunctureResistance(); switch (((NewType) source).getSourceAsString()) { //get the the source of damage as a string case "slash": if (slashRes > 0) newDamage = (amount * (100 / (100 + slashRes))); //if the target has resistances, apply math to reduce damage. else if (slashRes < 0) newDamage = (amount * (2 - (100 / (100 - slashRes)))); //if the target has negative resistances, apply math to boost damage. else newDamage = amount; //if the target has no resistances, apply initial damage unchanged System.out.println("TARGET ENTITY TOOK: " + newDamage + " SLASH DAMAGE"); //used for debugging break; case "puncture": //same as case slash, but for puncture damage if (punctureRes > 0) newDamage = (amount * (100 / (100 + punctureRes))); else if (punctureRes < 0) newDamage = (amount * (2 - (100 / (100 - punctureRes)))); else newDamage = amount; System.out.println("TARGET ENTITY TOOK: " + newDamage + " PUNCTURE DAMAGE"); break; case "impact": //same as case slash, but for impact damage if (impactRes > 0) newDamage = (amount * (100 / (100 + impactRes))); else if (impactRes < 0) newDamage = (amount * (2 - (100 / (100 - impactRes)))); else newDamage = amount; System.out.println("TARGET ENTITY TOOK: " + newDamage + " IMPACT DAMAGE"); break; } } event.setAmount(newDamage); //apply post-resistance calculation damage to the event } } }
×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.