Skip to content

Commit

Permalink
Damageable crafting ingredients
Browse files Browse the repository at this point in the history
  • Loading branch information
AechtRob committed Jan 29, 2023
1 parent e1a901c commit f7be403
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
22 changes: 21 additions & 1 deletion src/main/java/net/prehistoricdiner/PrehistoricDiner.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package net.prehistoricdiner;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.oredict.OreDictionary;
import net.prehistoricdiner.item.ItemDamageableCrafted;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -31,7 +36,22 @@ public void preInit(FMLPreInitializationEvent event) {

@EventHandler
public void init(FMLInitializationEvent event) {

try {
for (Object item : Item.REGISTRY) {
if (item instanceof ItemDamageableCrafted) {
String oreDict = ForgeRegistries.ITEMS.getKey((Item)item).toString();
OreDictionary.registerOre(oreDict, new ItemStack((Item) item, 1));
int i = 1;
while (i <= ((ItemDamageableCrafted) item).getMaxDamage()) {
ItemStack stack = new ItemStack((Item) item, 1);
stack.setItemDamage(i);
OreDictionary.registerOre(oreDict, stack);
i ++;
}
}
}
} catch (Exception e) {
}
}

@EventHandler
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/prehistoricdiner/RegistrationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public static void registerItems(RegistryEvent.Register<Item> event) {


//Non-food items:
((Item)(new ItemDamageableCrafted()).setRegistryName("prehistoricdiner", "skillet")).setTranslationKey("prehistoricdiner.skillet").setCreativeTab(PrehistoricDiner.CREATIVE_TAB),
((Item)(new ItemDamageableCrafted()).setRegistryName("prehistoricdiner", "pot")).setTranslationKey("prehistoricdiner.pot").setCreativeTab(PrehistoricDiner.CREATIVE_TAB),
((Item)(new ItemDamageableCrafted()).setRegistryName("prehistoricdiner", "knife")).setTranslationKey("prehistoricdiner.knife").setCreativeTab(PrehistoricDiner.CREATIVE_TAB),
((Item)(new ItemDamageableCrafted()).setRegistryName("prehistoricdiner", "ladle")).setTranslationKey("prehistoricdiner.ladle").setCreativeTab(PrehistoricDiner.CREATIVE_TAB),
((Item)(new ItemDamageableCrafted()).setRegistryName("prehistoricdiner", "grinder")).setTranslationKey("prehistoricdiner.grinder").setCreativeTab(PrehistoricDiner.CREATIVE_TAB),
((Item)(new ItemDamageableCrafted()).setRegistryName("prehistoricdiner", "rolling_pin")).setTranslationKey("prehistoricdiner.rolling_pin").setCreativeTab(PrehistoricDiner.CREATIVE_TAB)
((Item)(new ItemDamageableCrafted(32)).setRegistryName("prehistoricdiner", "skillet")).setTranslationKey("prehistoricdiner.skillet").setCreativeTab(PrehistoricDiner.CREATIVE_TAB),
((Item)(new ItemDamageableCrafted(32)).setRegistryName("prehistoricdiner", "pot")).setTranslationKey("prehistoricdiner.pot").setCreativeTab(PrehistoricDiner.CREATIVE_TAB),
((Item)(new ItemDamageableCrafted(32)).setRegistryName("prehistoricdiner", "knife")).setTranslationKey("prehistoricdiner.knife").setCreativeTab(PrehistoricDiner.CREATIVE_TAB),
((Item)(new ItemDamageableCrafted(32)).setRegistryName("prehistoricdiner", "ladle")).setTranslationKey("prehistoricdiner.ladle").setCreativeTab(PrehistoricDiner.CREATIVE_TAB),
((Item)(new ItemDamageableCrafted(32)).setRegistryName("prehistoricdiner", "grinder")).setTranslationKey("prehistoricdiner.grinder").setCreativeTab(PrehistoricDiner.CREATIVE_TAB),
((Item)(new ItemDamageableCrafted(32)).setRegistryName("prehistoricdiner", "rolling_pin")).setTranslationKey("prehistoricdiner.rolling_pin").setCreativeTab(PrehistoricDiner.CREATIVE_TAB)


};
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/net/prehistoricdiner/item/ItemDamageableCrafted.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

import javax.annotation.Nonnull;

public class ItemDamageableCrafted extends Item {

public ItemDamageableCrafted(int maxDamage) {
setContainerItem(this);
setMaxDamage(maxDamage);
}

@Override
public ItemStack getContainerItem(ItemStack stack) {
ItemStack result = stack.copy();
result.setItemDamage(stack.getItemDamage() + 1);
public ItemStack getContainerItem(@Nonnull ItemStack itemStack) {
ItemStack result = itemStack.copy();
result.setItemDamage(itemStack.getItemDamage() + 1);
return result;
}

@Override
public boolean hasContainerItem(ItemStack stack) {
public boolean hasContainerItem(@Nonnull ItemStack stack) {
return stack.getItemDamage() < stack.getMaxDamage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"ore": "cropWheat"
},
"7": {
"item": "prehistoricdiner:grinder"
"type": "forge:ore_dict",
"ore": "prehistoricdiner:grinder"
}
},
"result": {
Expand Down

0 comments on commit f7be403

Please sign in to comment.