Skip to content

Commit

Permalink
- Doped bread recipe attempt.
Browse files Browse the repository at this point in the history
  • Loading branch information
ttttdoy committed Apr 17, 2024
1 parent a8f2dc6 commit 28f766c
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/breadmod/datagen/ModItemModelProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ModItemModelProvider(output: PackOutput, modid: String, existingFileHelper
multiTexture("breadmod:bread_leggings", mcLoc("item/generated"), "layer0", modLoc("item/bread_leggings"), "layer1", modLoc("item/bread_leggings_overlay"))
multiTexture("breadmod:bread_chestplate", mcLoc("item/generated"), "layer0", modLoc("item/bread_chestplate"), "layer1", modLoc("item/bread_chestplate_overlay"))
multiTexture("breadmod:bread_helmet", mcLoc("item/generated"), "layer0", modLoc("item/bread_helmet"), "layer1", modLoc("item/bread_helmet_overlay"))
multiTexture("breadmod:doped_bread", mcLoc("item/generated"), "layer0", modLoc("item/doped_bread"), "layer1", modLoc("item/doped_bread_overlay"))
}

private fun <T: Item> singleItem(item: RegistryObject<T>) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/breadmod/datagen/ModRecipeProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ class ModRecipeProvider(pOutput: PackOutput) : RecipeProvider(pOutput) {
SpecialRecipeBuilder.special(ModRecipeSerializers.ARMOR_POTION_CRAFTING.get())
.save(pWriter, "bread_potion_crafting")

SpecialRecipeBuilder.special(ModRecipeSerializers.DOPED_BREAD_CRAFTING.get())
.save(pWriter, "doped_bread_crafting")

// // Compat
// Create
if(ModList.get().isLoaded("create")) {
Expand Down
41 changes: 37 additions & 4 deletions src/main/kotlin/breadmod/item/DopedBreadItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,49 @@ package breadmod.item
import breadmod.BreadMod.modTranslatable
import net.minecraft.ChatFormatting
import net.minecraft.network.chat.Component
import net.minecraft.world.effect.MobEffect
import net.minecraft.world.effect.MobEffectInstance
import net.minecraft.world.effect.MobEffects
import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.food.FoodProperties
import net.minecraft.world.item.Item
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.TooltipFlag
import net.minecraft.world.item.alchemy.PotionUtils
import net.minecraft.world.level.Level
import net.minecraftforge.common.ForgeHooks
import java.util.function.Consumer

class DopedBreadItem : Item(Properties().food(FoodProperties.Builder().nutrition(6).build())) {
override fun inventoryTick(pStack: ItemStack, pLevel: Level, pEntity: Entity, pSlotId: Int, pIsSelected: Boolean) {
if(pEntity is LivingEntity) pEntity.addEffect(MobEffectInstance(MobEffects.INVISIBILITY,200,0))
// override fun inventoryTick(pStack: ItemStack, pLevel: Level, pEntity: Entity, pSlotId: Int, pIsSelected: Boolean) {
// if(pEntity is LivingEntity) pEntity.addEffect(MobEffectInstance(MobEffects.INVISIBILITY,200,0))
// }

private fun listPotionEffects(pStack: ItemStack, pOutput: Consumer<MobEffectInstance>) {
val compoundTag = pStack.tag
if (compoundTag != null && compoundTag.contains("Effects", 9)) {
val listTag = compoundTag.getList("Effects", 10)

for (i in listTag.indices) {
val compoundTag1 = listTag.getCompound(i)
val j = if (compoundTag1.contains("EffectDuration", 99)) {
compoundTag1.getInt("EffectDuration")
} else {
160
}

var mobeffect = MobEffect.byId(compoundTag1.getInt("EffectId"))
mobeffect = ForgeHooks.loadMobEffect(compoundTag1, "forge:effect_id", mobeffect)
if (mobeffect != null) {
pOutput.accept(MobEffectInstance(mobeffect, j))
}
}
}
}

override fun finishUsingItem(pStack: ItemStack, pLevel: Level, pLivingEntity: LivingEntity): ItemStack {
val itemStack = super.finishUsingItem(pStack, pLevel, pLivingEntity)
listPotionEffects(itemStack, pLivingEntity::addEffect)
return super.finishUsingItem(pStack, pLevel, pLivingEntity)
}

override fun appendHoverText(
Expand All @@ -28,6 +58,9 @@ class DopedBreadItem : Item(Properties().food(FoodProperties.Builder().nutrition
modTranslatable("item", "doped_bread", "tooltip")
.withStyle(ChatFormatting.GREEN)
)
val list: List<MobEffectInstance> = ArrayList()
listPotionEffects(pStack) { e: MobEffectInstance? -> list.contains(e) }
PotionUtils.addPotionTooltip(list, pTooltip, 1.0F)
super.appendHoverText(pStack, pLevel, pTooltip, pFlag)
}
}
98 changes: 98 additions & 0 deletions src/main/kotlin/breadmod/recipe/DopedBreadRecipe.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package breadmod.recipe

import breadmod.item.DopedBreadItem
import breadmod.registry.recipe.ModRecipeSerializers.DOPED_BREAD_CRAFTING
import breadmod.util.applyColor
import net.minecraft.core.RegistryAccess
import net.minecraft.resources.ResourceLocation
import net.minecraft.world.inventory.CraftingContainer
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.PotionItem
import net.minecraft.world.item.alchemy.PotionUtils
import net.minecraft.world.item.crafting.CraftingBookCategory
import net.minecraft.world.item.crafting.CustomRecipe
import net.minecraft.world.item.crafting.RecipeSerializer
import net.minecraft.world.level.Level
import java.awt.Color

class DopedBreadRecipe(pId: ResourceLocation, pCategory: CraftingBookCategory) : CustomRecipe(pId, pCategory) {
// override fun matches(pContainer: CraftingContainer, pLevel: Level): Boolean {
// var hasItem = false; var hasEffect = false
// for (slot in 0 until pContainer.containerSize ) {
// pContainer.getItem(slot).also { stack ->
// if(stack.isEmpty) {
// return false
// }
// else if(stack.`is`(Items.BREAD.asItem())) {
// hasItem = true
// }
// else if (stack.`is`(Items.POTION)) {
// hasEffect = true
// }
// else return false
// }
// }
//
// return hasItem && hasEffect
// }
//
// override fun assemble(pContainer: CraftingContainer, pRegistryAccess: RegistryAccess): ItemStack {
// val itemStack = ItemStack(ModItems.DOPED_BREAD.get(), 1)
// for (slot in 0 until pContainer.containerSize) {
// pContainer.getItem(slot).also { stack ->
// PotionUtils.setPotion(itemStack, PotionUtils.getPotion(stack))
// PotionUtils.setCustomEffects(itemStack, PotionUtils.getCustomEffects(stack))
// }
// }
// return itemStack
// }

override fun matches(pContainer: CraftingContainer, pLevel: Level): Boolean {
var hasItem = false; var hasEffect = false
for (slot in 0 until pContainer.containerSize) {
pContainer.getItem(slot).also { stack ->
if(!stack.isEmpty) when(stack.item) {
is PotionItem -> {
if(hasEffect) return false
PotionUtils.getPotion(stack).effects.also {
if(it.size != 1 || it.firstOrNull()?.effect?.isInstantenous == true) return false }
hasEffect = true
}
is DopedBreadItem -> {
if(hasItem ||stack.tag?.contains("Potion") == true) return false
hasItem = true
}
else -> return false
}
}
}

return hasItem && hasEffect
}

override fun assemble(pContainer: CraftingContainer, pRegistryAccess: RegistryAccess): ItemStack {
var itemStack: ItemStack = ItemStack.EMPTY
val potions = buildList {
for (slot in 0 until pContainer.containerSize) {
val stack = pContainer.getItem(slot)
when(stack.item) {
is PotionItem -> addAll(PotionUtils.getPotion(stack).effects)
is DopedBreadItem -> if(itemStack.isEmpty) itemStack = stack else return ItemStack.EMPTY
}
}
}

return if(!itemStack.isEmpty && potions.isNotEmpty())
itemStack.copy().also { stack ->
// stack.applyColor(Color(PotionUtils.getColor(potions)))
PotionUtils.setPotion(stack, PotionUtils.getPotion(stack))
PotionUtils.setCustomEffects(stack, potions)
}
else ItemStack.EMPTY
}


override fun canCraftInDimensions(pWidth: Int, pHeight: Int): Boolean = (pWidth * pHeight) >= 2

override fun getSerializer(): RecipeSerializer<*> = DOPED_BREAD_CRAFTING.get()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package breadmod.registry.recipe

import breadmod.BreadMod
import breadmod.recipe.ArmorPotionRecipe
import breadmod.recipe.DopedBreadRecipe
import net.minecraft.world.item.crafting.*
import net.minecraftforge.registries.DeferredRegister
import net.minecraftforge.registries.ForgeRegistries
Expand All @@ -13,6 +14,10 @@ object ModRecipeSerializers {

val ARMOR_POTION_CRAFTING: RegistryObject<SimpleCraftingRecipeSerializer<ArmorPotionRecipe>> = deferredRegister.register("bread_potion_crafting") {
SimpleCraftingRecipeSerializer { pId, pCategory -> ArmorPotionRecipe(pId, pCategory) } }

val DOPED_BREAD_CRAFTING: RegistryObject<SimpleCraftingRecipeSerializer<DopedBreadRecipe>> = deferredRegister.register("doped_bread_crafting") {
SimpleCraftingRecipeSerializer { pId, pCategory -> DopedBreadRecipe(pId, pCategory) } }

/*val BREAD_REFINEMENT = REGISTRY.register("bread_refinement") {
SimpleCookingSerializer({
pId, pGroup, pCategory, pIngredient, pResult, pExperience, pCookingTime ->
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 28f766c

Please sign in to comment.