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

What im trying to do is make custom recipes for my custom furnace

 

private boolean canSmelt() {

if(this.slots[0] == null){

return false;

}else{

ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]);

 

if(itemstack == null) return false;

if(this.slots[2] == null) return true;

if(!this.slots[2].isItemEqual(itemstack)) return false;

 

int result  = this.slots[2].stackSize + itemstack.stackSize;

 

return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());

}

}

 

 

 

The ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]); line makes any vanilla furnace recipe possible but I want only custom recipies. How am I able to do that?

 

  • Author

Have you seen the mc code? its pretty hard to use and work with....

  • Author

Have you seen the mc code? its pretty hard to use and work with....

Really, all you need is a HashMap<ItemStack,ItemStack>.

Please, explain more. I know where the hash map thing is, but what do I do with it? Where do I put it (like do I create a method for it or add it to my mod base class)?

  • Author

Please learn basic java.

You can put it wherever you want, but the "most OOP" way would be to make a new class for it.

I know basic java, but im new to modding.

You don't have to do this, but it would be great if you told my exactly what to do. If you don't want to, its ok, i'll keep trying to find out myself.

  • Author

Just because I am bored. Please do not copy paste.

 

import static com.google.common.base.Preconditions.checkNotNull;

enum MyAwesomeMachineRecipes {

INSTANCE; // enum Singleton pattern

public void addRecipe(ItemStack input, ItemStack output) {
	recipes.put(checkNotNull(input), checkNotNull(output));
}

public ItemStack findResult(ItemStack input) {
	ItemStack result = recipes.get(input);
	if (result != null) {
		return result;
	}
	// if you don't need metadata-agnostic recipes you can remove this
	return recipes.get(new ItemStack(input.getItem(), 1, OreDictionary.WILDCARD_VALUE));
}

// use custom HashMap from Trove to support hashCode and equals for ItemStacks
// this implementation only uses the Item and the damage value, if you need NBT sensitive checks you need to
// include that
private final TMap<ItemStack, ItemStack> recipes = new TCustomHashMap<ItemStack, ItemStack>(new HashingStrategy<ItemStack>() {
	@Override
	public int computeHashCode(ItemStack stack) {
		// not the most efficient hashCode probably
		int result = stack.getItem().hashCode();
		result = 31 * result + stack.getItemDamage();
		return result;
	}

	@Override
	public boolean equals(ItemStack o1, ItemStack o2) {
		if (o1 == o2) {
			return true;
		}
		if (o1.getItem() != o2.getItem()) {
			return false;
		}
		if (o1.getItemDamage() != o2.getItemDamage()) {
			return false;
		}
		return true;
	}
});

}

 

This doesn't compare ItemStack NBT tags. If you need that, you'll have to add it.

Also: Untested.

 

 

OMG! Your the best! I thought you would just say "learn it yourself" or something, but no! You actually did it! +1 Karma

 

Edit: What do I put in my TileEntity class? For the vanilla recipies I would put: ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]);

    @Override
      public int computeHashCode(ItemStack stack) {
         // not the most efficient hashCode probably
         int result = stack.getItem().hashCode();
         result = 31 * result + stack.getItemDamage();
         return result;
      }

 

Why the 31x in the packing?

I would have figured a bitshift to pack the two values, which would be a 2power multiplier,

but with that 31 you have the low 5 bits all set, but followed with a + instead of an AND to pack.... also, while block Metadata has the 16 limit, cant Items have far more 'damage' subtypes than would fit in a  31x& pack?

 

I am not using the code, I just want to understand it better.

If you just picked 31x cause it looked good, ok, I can live with that,

but I am wondering if there is some reason, some significance to using 31x that I am missing

  • Author

Seriously? I give you full, working code and you don't even bother trying to read and understand it? Nope. Not gonna happen.

I have read the whole thing many, many times, even fixed some errors, but still, I can't figure out how to put it in my tileentity class. Its kind of obvious how to add a new recipe tho, I got that.

  • Author

It should be kind of obvious on how to use it, too. Just call

findResult

with your input.

Ok, thanks, I finally got it to work, you can close the topic now

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.