Jump to content

[Solved] [1.7.2] Custom Recipes For Custom Furnace


tiffit

Recommended Posts

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?

 

Link to comment
Share on other sites

Use your own FurnaceRecipes equivalent... copy and paste, if that's what you do best. Rename and modify to suit.

Link to comment
Share on other sites

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)?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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]);

Link to comment
Share on other sites

    @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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have a problem, I am trying to put two different effects to two different armors but when I run it only the emerald armor effect works. This is the code public class ModArmorItem extends ArmorItem{ private static final Map<ArmorMaterial, MobEffectInstance> MATERIAL_TO_EFFECT_MAP = (new ImmutableMap.Builder<ArmorMaterial, MobEffectInstance>()) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.HERO_OF_THE_VILLAGE,200, 1,false,false, true)) .put(ModArmorMaterials.OBSIDIAN, new MobEffectInstance(MobEffects.FIRE_RESISTANCE,200, 1,false,false, true)).build(); public ModArmorItem(ArmorMaterial pMaterial, Type pType, Properties pProperties) { super(pMaterial, pType, pProperties); } @Override public void onArmorTick(ItemStack stack, Level world, Player player){ if (!world.isClientSide()) { if (hasFullSuitOfArmorOn(player)) { evaluateArmorEffects(player); } } } private void evaluateArmorEffects(Player player) { for (Map.Entry<ArmorMaterial,MobEffectInstance> entry : MATERIAL_TO_EFFECT_MAP.entrySet()){ ArmorMaterial mapArmorMaterial = entry.getKey(); MobEffectInstance mapStatusEffect = entry.getValue(); if (hasCorrectArmorOn(mapArmorMaterial, player)) { addStatusEffectForMaterial(player, mapArmorMaterial, mapStatusEffect); } } } private void addStatusEffectForMaterial(Player player, ArmorMaterial mapArmorMaterial, MobEffectInstance mapStatusEffect) { boolean hasPlayerEffect = player.hasEffect(mapStatusEffect.getEffect()); if (hasCorrectArmorOn(mapArmorMaterial, player) && !hasPlayerEffect) { player.addEffect(new MobEffectInstance(mapStatusEffect)); } } private boolean hasCorrectArmorOn(ArmorMaterial material, Player player) { for (ItemStack armorStack : player.getInventory().armor){ if (!(armorStack.getItem() instanceof ArmorItem)) { return false; } } ArmorItem helmet = ((ArmorItem)player.getInventory().getArmor(3).getItem()); ArmorItem breastplace = ((ArmorItem)player.getInventory().getArmor(2).getItem()); ArmorItem leggins = ((ArmorItem)player.getInventory().getArmor(1).getItem()); ArmorItem boots = ((ArmorItem)player.getInventory().getArmor(0).getItem()); return helmet.getMaterial() == material && breastplace.getMaterial() == material && leggins.getMaterial() == material && boots.getMaterial() == material; } private boolean hasFullSuitOfArmorOn(Player player){ ItemStack helmet = player.getInventory().getArmor(3); ItemStack breastplace = player.getInventory().getArmor(2); ItemStack leggins = player.getInventory().getArmor(1); ItemStack boots = player.getInventory().getArmor(0); return !helmet.isEmpty() && !breastplace.isEmpty() && !leggins.isEmpty() && !boots.isEmpty(); } } Also when I place two effects on the same armor, the game crashes. Here is the crash file. The code is the same, only this part is different   private static final Map<ArmorMaterial, MobEffectInstance> MATERIAL_TO_EFFECT_MAP = (new ImmutableMap.Builder<ArmorMaterial, MobEffectInstance>()) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.HERO_OF_THE_VILLAGE,200, 1,false,false, true)) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.FIRE_RESISTANCE,200, 1,false,false, true)).build(); I hope you guys can help me. Thanks.
    • I removed all related embeddium and oculus mods, i just tested it by disconnecting and the error happened again. heres the report https://pastebin.com/1kcR5wAt   EDIT: i tried removing xaeros and also smoothboot thinking there may be an issue there, nothing, heres that report too. https://pastebin.com/zQS7i9rM
    • Hi, I need suggestions. I am a beginner in Minecraft Modding. I would like to apply custom effects to some armors, something like: more chance to drop seeds, change zombie awareness, drop more pieces of wood when chopping logs, and things like that. How would you recommend me to do it, is there any library that has something similar and which ones would you recommend me?.
    • "downloading minecraft server failed, invalid Checksum. try again, or manually place server.jar to skip download"    
    • You have to create an Entity class called PlayerPart and use multiple of them to make the different parts of the player. See EnderDragonPart.java source code. The green hitboxes of the dragon are all EnderDragonParts
  • Topics

×
×
  • Create New...

Important Information

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