Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey Guys!

 

I wanted to create a crafting table which uses a special item to craft. The item has a durability of 64. One damage point should be added on crafting. The problem is that this doesn't work.

 

Code:

 

Item:

 

package com.bedrockminer.magicum.item;

import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.Item;
import net.minecraft.util.IIcon;

import com.bedrockminer.magicum.Main;
import com.bedrockminer.magicum.creative.Tabs;
import com.bedrockminer.magicum.element.Elements;

public class ItemEssence extends Item {

private final Elements element;
private IIcon iconDamage1;
private IIcon iconDamage2;

public ItemEssence(String unlocalizedName, Elements element) {
	super();
	this.setUnlocalizedName(unlocalizedName);
	this.setTextureName(Main.MODID + ":" + unlocalizedName);
	this.setCreativeTab(Tabs.essences);
	this.setMaxDamage(64);
	this.setMaxStackSize(1);
	this.element = element;
}

public Elements getElement() {
	return this.element;
}

@Override
public IIcon getIconFromDamage(int damage) {
	if (damage > 2 * this.getMaxDamage() / 3)
		return this.iconDamage2;
	if (damage > this.getMaxDamage() / 3)
		return this.iconDamage1;
	return this.itemIcon;
}

@Override
public void registerIcons(IIconRegister reg) {
	this.itemIcon = reg.registerIcon(this.getIconString() + "_stage_0");
	this.iconDamage1 = reg.registerIcon(this.getIconString() + "_stage_1");
	this.iconDamage2 = reg.registerIcon(this.getIconString() + "_stage_2");
}
}

 

 

onCrafting:

 

public void onPlayerCrafting(EntityPlayer player, ItemStack stack) {
	for (int i = 9; i < 12; i ++) {
		Main.log("loop");
		Elements element = Elements.None;
	   	if (i - 9 < this.neededElements.size())
	   		element = this.neededElements.get(i - 9);

	   	if (element != Elements.None) {
	   		this.te.getStackInSlot(i).damageItem(1, player);
	   		Main.log("damage");
	   	}
	}
}

 

The log "damage" is written in the console.

The method is called from onSlotChange of the corresponding slot.

@Override
public void onSlotChanged() {
	super.onSlotChanged();
	this.owner.onCraftMatrixChanged(this.inventory);
}

 

 

I hope someone understands the problem...

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.