Hello good,
I'm new to the forum, so the first thing is to tell you: hello everyone!
Now I am going to explain my problem. A friend and I are making our first mod. and we're having a problem registering an item. and it is that it appears in all the creative tabs and in the icon to delete your inventory.
I give you a couple of screenshots to illustrate the problem:
My items in redstone tab: https://prnt.sc/B4bgpAXdgxqz
My items in my own tab: https://prnt.sc/iT_1LQoyzfYG
My items in "Destroy Item" slot: https://prnt.sc/XEVrxJvW46Td
This doesn't make much sense to me, since I register them like other items. I give you where I register the item and the class of the item.
> ModItems.class
//The rest of the class
// REGISTER VIALS
public static RegistryObject<Item> LARGE_VIAL= register("big_vial",
() -> {
return new LargeVial(new Item.Properties().tab(ModItemGroup.METALLIC_ARTS_TAG).stacksTo(1).food(new Food.Builder().nutrition(0).build()));
});
public static RegistryObject<Item> SMALL_VIAL = register("small_vial",
() -> {
return new SmallVial(new Item.Properties().tab(ModItemGroup.METALLIC_ARTS_TAG).stacksTo(1).food(new Food.Builder().nutrition(0).build()));
});
// UTILS METHODS
public static void register() {
}
private static <T extends Item> RegistryObject<T> register(String name, Supplier<T> itemSupplier) {
return Registration.ITEMS.register(name, itemSupplier);
}
> ModItemGroup.class
public class ModItemGroup {
public static final ItemGroup METALLIC_ARTS_TAG = new ItemGroup("metallic_arts_tag") {
@Override
public ItemStack makeIcon() {
return new ItemStack(ModItems.ITEM_METAL_INGOT.get("aluminum").getItem());
}
};
}
> Vial.class
public abstract class Vial extends Item {
CompoundNBT compoundNBT = new CompoundNBT();
private int maxNuggets;
public Vial(Properties properties,int maxNuggets) {
super(properties);
this.maxNuggets = maxNuggets;
for (MetalsNBTData metal : MetalsNBTData.values()){
this.compoundNBT.putInt(metal.getNameLower(),0);
}
}
public Vial(Properties properties, CompoundNBT compoundNBT) {
super(properties);
}
public Vial(Properties properties) {
super(properties);
}
public Vial() {
super(new Item.Properties().tab(ModItemGroup.METALLIC_ARTS_TAG).stacksTo(1).food(new Food.Builder().nutrition(0).build()));
}
@Override
public void releaseUsing(ItemStack itemStack, World world, LivingEntity livingEntity, int number) {
super.releaseUsing(itemStack, world, livingEntity, number);
}
@Override
public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
ItemStack itemStackIn = player.getItemInHand(hand);
ActionResult<ItemStack> res = player.getCapability(InvestedCapability.PLAYER_CAP).map(data -> {
//If all the ones being filled are full, don't allow
if (itemStackIn.hasTag()) {
for (MetalsNBTData metal : MetalsNBTData.values()) {
if (itemStackIn.getTag().contains(metal.getNameLower()) && itemStackIn.getTag().getInt(metal.getNameLower())>0) {
player.startUsingItem(hand);
return new ActionResult<>(ActionResultType.SUCCESS, itemStackIn);
}
}
}
return new ActionResult<>(ActionResultType.FAIL, itemStackIn);
}).orElse(new ActionResult<>(ActionResultType.FAIL, itemStackIn));
return res;
}
@Override
public ItemStack finishUsingItem(ItemStack itemStack, World world, LivingEntity livingEntity) {
if (!itemStack.hasTag()) {
return itemStack;
}
livingEntity.getCapability(InvestedCapability.PLAYER_CAP).ifPresent(data -> {
for (MetalsNBTData metal : MetalsNBTData.values()) {
if (itemStack.getTag().contains(metal.getNameLower()) && itemStack.getTag().getInt(metal.getNameLower())>0) {
data.setAllomanticMetalsAmount(metal,itemStack.getTag().getInt(metal.getNameLower()));
}
}
});
if (!((PlayerEntity) (livingEntity)).abilities.instabuild) {
itemStack.shrink(1);
ItemStack item = null;
if(this.maxNuggets==5){
item = new ItemStack(ModItems.SMALL_VIAL.get());
}else {
item = new ItemStack(ModItems.LARGE_VIAL.get());
}
CompoundNBT data = new CompoundNBT();
for (MetalsNBTData metal : MetalsNBTData.values()){
data.putInt(metal.getNameLower(),0);
}
item.setTag(data);
if (!((PlayerEntity) livingEntity).inventory.add(item)) {
if(this.maxNuggets==5){
world.addFreshEntity(new ItemEntity(world, livingEntity.getX(), livingEntity.getY(), livingEntity.getZ(), new ItemStack(ModItems.SMALL_VIAL.get(), 1)));
}else {
world.addFreshEntity(new ItemEntity(world, livingEntity.getX(), livingEntity.getY(), livingEntity.getZ(), new ItemStack(ModItems.LARGE_VIAL.get(), 1)));
}
}
}
return itemStack;
}
@Override
public int getUseDuration(ItemStack itemStack) {
return 32;
}
@Override
public boolean isEnchantable(ItemStack itemStack) {
return false;
}
@Override
public UseAction getUseAnimation(ItemStack itemStack) {
return UseAction.DRINK;
}
@Override
public boolean isEdible() {
return true;
}
@Override
public void fillItemCategory(ItemGroup group, NonNullList<ItemStack> items) {
ItemStack resultItem = null;
if(this.maxNuggets==5){
resultItem = new ItemStack(ModItems.SMALL_VIAL.get(),1);
}else{
resultItem = new ItemStack(ModItems.LARGE_VIAL.get(),1);
}
CompoundNBT nbt = new CompoundNBT();
for (MetalsNBTData mt : MetalsNBTData.values()) {
nbt.putInt(mt.getGemNameLower(), 0);
}
resultItem.setTag(nbt);
items.add(resultItem);
}
public CompoundNBT getCompoundNBT() {
return compoundNBT;
}
}
> SmallVial.java (the LargeVial class is the same)
public class SmallVial extends Vial {
public SmallVial(Properties properties) {
super(properties,5);
}
}
In addition to this, I also leave you our github repository, in case you find it more convenient to consult it.
Github Repo: https://github.com/rudahee/Metallics-Arts
Finally, I want to apologize for my English, since I do not express myself fluently in this language. (And I've used a translator for some things haha).
Thank you in advance for your help. You are awesome!
Byebye!