• 0

    posted a message on 1.12.2 How do i make my mob spawn with a weapon in hand?.

    I had a problem similar to this, and I was able to fix it, and as a matter of fact simplify the entire code by just extending both the render class and model classes of my mob to ModelBiped


    so basically;


    public_class ModelLost_one extends ModelBiped
    
    public_class RenderLost_one extends ModelBiped

    after that I just stole the model code from ModelZombie, and put that in my own model, and then the same thing for my entity's render class, just copy and pasted RenderZombie. Of course you would have to change certain bits of code to your own entity's name, but thats more or less it


    after that you can just go into your main Entity class and then add this bit of code;


    protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty)
        {
            this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(ModItems.SWORD));
            this.setItemStackToSlot(EntityEquipmentSlot.CHEST, new ItemStack(ModItems.CHESTPLATE));
            this.setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(ModItems.HELMET));
            this.setItemStackToSlot(EntityEquipmentSlot.LEGS, new ItemStack(ModItems.LEGGINGS));
            this.setItemStackToSlot(EntityEquipmentSlot.FEET, new ItemStack(ModItems.BOOTS));
        }


    Just replace the Items with whatever you want and it should work just fine.


    This is all if your custom entity has the exact same render/model as a zombie, however, im sure you can get this to work with other similar bipedal models. (instead of copy+pasting from zombie classes, use the render and model classes for skeleton, zombie pig, wither skeleton, etc.).


    If you have a custom model, then just try to figure out through the biped render and model classes what renders in the weapon.

    Posted in: Modification Development
  • 0

    posted a message on Trying to create an 'attack speed' enchantment. No luck :(

    Hi there!


    So in my mod (1.12.2), I'm trying to create an enchantment called lightweight, that basically does the same thing that sharpness does, except to the weapon's attack speed, instead of attack damage.


    package com.plutothe5th.starblock.enchantments;
    
    import com.google.common.collect.Multimap;
    import com.plutothe5th.starblock.init.ModEnchantments;
    import com.plutothe5th.starblock.util.Reference;
    
    import net.minecraft.enchantment.Enchantment;
    import net.minecraft.enchantment.EnchantmentMending;
    import net.minecraft.enchantment.EnumEnchantmentType;
    import net.minecraft.entity.EnumCreatureAttribute;
    import net.minecraft.entity.SharedMonsterAttributes;
    import net.minecraft.entity.ai.attributes.AttributeModifier;
    import net.minecraft.init.Enchantments;
    import net.minecraft.inventory.EntityEquipmentSlot;
    import net.minecraft.util.DamageSource;
    import net.minecraft.util.ResourceLocation;
    import net.minecraft.item.ItemTool;
    
    public class EnchantmentLightweight extends Enchantment{
    
    	
    	public final int damageType;
    	
    	public EnchantmentLightweight(int damageTypeIn) {
    		super(Rarity.RARE, EnumEnchantmentType.WEAPON, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND});
    		this.setName("lightweight");
    		this.setRegistryName(new ResourceLocation(Reference.MOD_ID + ":lightweight"));
    		this.damageType = damageTypeIn;
    		
    		ModEnchantments.ENCHANTMENTS.add(this);
    	}
    	
    	@Override
    	public int getMinEnchantability(int enchantmentLevel) {
    		return 20*enchantmentLevel;
    	}
    	
    	@Override
    	public int getMaxEnchantability(int enchantmentLevel) {
    		return this.getMinEnchantability(enchantmentLevel) + 10;
    	}
    	
    	@Override
    	public int getMaxLevel() {
    		return 5;
    	}
    	
    	@Override
    	protected boolean canApplyTogether(Enchantment ench) {
    		return super.canApplyTogether(ench) && ench != Enchantments.KNOCKBACK;
    	}	
    	
    	public float calcDamageByCreature(int level, EnumCreatureAttribute creatureType)
        {
            if (this.damageType == 0)
            {
                return 1.0F + (float)Math.max(0, level - 1) * 0.5F;
            }
            else if (this.damageType == 1 && creatureType == EnumCreatureAttribute.UNDEAD)
            {
                return (float)level * 2.5F;
            }
            else
            {
                return this.damageType == 2 && creatureType == EnumCreatureAttribute.ARTHROPOD ? (float)level * 2.5F : 0.0F;
            }
        }
    	
    }


    This is my code right now for my enchantment. As of right now it is just a second sharpness type enchant, (I have the creature attribute set to 0 in my init). I just want to know how I can use a system similar to this in order to change the attack speed of a weapon.


    Thanks for your time!

    Posted in: Modification Development
  • To post a comment, please .