Jump to content

Recommended Posts

Posted

Ok, so I have been trying for a while now to add knockback to an item I have modded in when it is crafted. I have seen people say to edit the .json recipe file like this:

{
	"type": "minecraft:crafting_shaped",
	"pattern": [
		"PPP",
		"PSI",
		"PSI"
	],
	"key": {
		"P": {
			"item": "halowip:pure_titanium"
		},
		"S": {
			"item": "minecraft:stick"
		},
		"I": {
			"item": "minecraft:iron_ingot"
		}
	},
	"result": {
		"item": "minecraft:gravity_hammer",
		"nbt": 
		{
			"ench":
			[
				{
					"id": "minecraft:knockback",
					"lvl": 99
				}
			]
		},
		"count": 1
	}
}

but it does not seem to work. I have also tried creating an enchantment class, but that doesn't work since I have my items purely under RegistryObject and not ItemStack (I may be stupid, feel free to correct me). I also have a github repo for my project for anyone who wants to look at it (it needs to be updated from about a day ago). Any help is appreciated!!!

Posted
package com.diglis.halowip.core.init;

import com.diglis.halowip.HaloWip;
import com.diglis.halowip.common.CustomArmorMaterial;
import com.diglis.halowip.common.PickaxeToolMaterial;
import com.diglis.halowip.core.itemgroup.HaloModItemGroupArmor;
import com.diglis.halowip.core.itemgroup.HaloModItemGroupMisc;
import com.diglis.halowip.core.itemgroup.HaloModItemGroupWeapons;

import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.AxeItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.PickaxeItem;
import net.minecraft.item.SwordItem;
import net.minecraft.util.IItemProvider;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class ItemInit {
	public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, HaloWip.MOD_ID);

	public static final RegistryObject<Item> ASSAULT_RIFLE = ITEMS.register("assault_rifle",
			() -> new Item(new Item.Properties().tab(HaloModItemGroupWeapons.HALO_CRAFTING_EVOLVED)));
	
	public static final RegistryObject<Item> RIFLE_AMMO = ITEMS.register("ammo_pouch", 
			() -> new Item(new Item.Properties().tab(HaloModItemGroupWeapons.HALO_CRAFTING_EVOLVED)));
	
	public static final RegistryObject<Item> RAW_TITANIUM = ITEMS.register("raw_titanium", 
			() -> new Item(new Item.Properties().tab(HaloModItemGroupMisc.HALO_CRAFTING_EVOLVED)));
	
	public static final RegistryObject<Item> PURE_TITANIUM = ITEMS.register("pure_titanium", 
			() -> new Item(new Item.Properties().tab(HaloModItemGroupMisc.HALO_CRAFTING_EVOLVED).fireResistant()));
	
	public static final RegistryObject<Item> TITANIUM_PICKAXE = ITEMS.register("titanium_pickaxe", 
			() -> new PickaxeItem(CustomToolMaterial.TITANIUM_PICKAXE, 10, -1f, new Item.Properties().tab(HaloModItemGroupWeapons.HALO_CRAFTING_EVOLVED)));
	
	public static final RegistryObject<Item> GRAVITY_HAMMER = ITEMS.register("gravity_hammer", 
			() -> new AxeItem(CustomToolMaterial.GRAVITY_HAMMER, 7, -1f, new Item.Properties().tab(HaloModItemGroupWeapons.HALO_CRAFTING_EVOLVED)));
	
	public static final RegistryObject<Item> ENERGY_SWORD = ITEMS.register("energy_sword", 
			() -> new SwordItem(CustomToolMaterial.ENERGY_SWORD, 5, -1f, new Item.Properties().tab(HaloModItemGroupWeapons.HALO_CRAFTING_EVOLVED).setNoRepair()));
	
	public static final RegistryObject<Item> MASTER_CHIEF_HELMET = ITEMS.register("mk6_helm",
			() -> new ArmorItem(CustomArmorMaterial.MK6_ARMOR, EquipmentSlotType.HEAD, new Item.Properties().tab(HaloModItemGroupArmor.HALO_CRAFTING_EVOLVED).fireResistant()));
	
	public static final RegistryObject<Item> MASTER_CHIEF_CHEST = ITEMS.register("mk6_chest", 
			() -> new ArmorItem(CustomArmorMaterial.MK6_ARMOR, EquipmentSlotType.CHEST, new Item.Properties().tab(HaloModItemGroupArmor.HALO_CRAFTING_EVOLVED).fireResistant()));
	
	public static final RegistryObject<Item> MASTER_CHIEF_LEGGINGS = ITEMS.register("mk6_legs", 
			() -> new ArmorItem(CustomArmorMaterial.MK6_ARMOR, EquipmentSlotType.LEGS, new Item.Properties().tab(HaloModItemGroupArmor.HALO_CRAFTING_EVOLVED).fireResistant()));
	
	public static final RegistryObject<Item> MASTER_CHIEF_BOOTS = ITEMS.register("mk6_boots", 
			() -> new ArmorItem(CustomArmorMaterial.MK6_ARMOR, EquipmentSlotType.FEET, new Item.Properties().tab(HaloModItemGroupArmor.HALO_CRAFTING_EVOLVED).fireResistant()));
	
	public static final RegistryObject<Item> TRANSPARENT_MK6_HELM = ITEMS.register("mk6_clear", 
			() -> new ArmorItem(CustomArmorMaterial.NOVISR_MK6_HELM, EquipmentSlotType.HEAD, new Item.Properties().tab(HaloModItemGroupArmor.HALO_CRAFTING_EVOLVED)));
	
	public static final RegistryObject<Item> BLUE_MK6_HELM = ITEMS.register("mk6_blue", 
			() -> new ArmorItem(CustomArmorMaterial.BLUE_MK6_HELM, EquipmentSlotType.HEAD, new Item.Properties().tab(HaloModItemGroupArmor.HALO_CRAFTING_EVOLVED).fireResistant()));
	
	
}

would it be in this class?

Posted

Ok i created a new class like this:

package com.diglis.halowip.common;

import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.item.Item;

public class weaponAttributes extends Item {

	public weaponAttributes(Properties p_i48487_1_) {
		super(p_i48487_1_);
		// TODO Auto-generated constructor stub
	}
	
	public Attribute getAttribute() {
		return null;
	}

}

Is this right or am i all wrong?

Posted

Yes, I am just very new to the forge api, and you are being rather vague. I am guessing getAttribute is a method you can use (with dot notation) but I am not sure as to where to apply it in my code.

Posted
public enum PickaxeToolMaterial implements IItemTier {
	TITANIUM_PICKAXE(4, 10000, 100f, 5f, 17, () -> Ingredient.of(ItemInit.PURE_TITANIUM.get())),
	ENERGY_SWORD(4, 100, 5f, 20f, 0, () -> Ingredient.of(ItemInit.PURE_TITANIUM.get())),
	GRAVITY_HAMMER(4, 7000, 1f, 9.6f, 17, () -> Ingredient.of(ItemInit.PURE_TITANIUM.get()));
	
	private final int harvestLevel;
	private final int maxUses;
	private final float efficiency;
	private final float attackDamage;
	private final int enchantability;
	private final Ingredient repairMaterial; 

	PickaxeToolMaterial(int harvestLevel, int maxUses, float efficiency, float attackDamage, int enchantability, Supplier<Ingredient> repairMaterial) {
		this.harvestLevel = harvestLevel;
		this.maxUses = maxUses;
		this.efficiency = efficiency;
		this.attackDamage = attackDamage;
		this.enchantability = enchantability;
		this.repairMaterial = repairMaterial.get();
	}
	
	@Override
	public int getUses() {
		// TODO Auto-generated method stub
		return this.maxUses;
	}

	@Override
	public float getSpeed() {
		// TODO Auto-generated method stub
		return this.efficiency;
	}

	@Override
	public float getAttackDamageBonus() {
		// TODO Auto-generated method stub
		return this.attackDamage;
	}

	@Override
	public int getLevel() {
		// TODO Auto-generated method stub
		return this.harvestLevel;
	}

	@Override
	public int getEnchantmentValue() {
		// TODO Auto-generated method stub
		return this.enchantability;
	}

	@Override
	public Ingredient getRepairIngredient() {
		// TODO Auto-generated method stub
		return this.repairMaterial;
	}
}

this is the class i use to actually set the values

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.