Cake slicer crafting recipe, buff cake slicer

This commit is contained in:
DBotThePony 2022-09-11 20:52:28 +07:00
parent 88ff0fe7f7
commit 199b22dad5
Signed by: DBot
GPG Key ID: DCC23B5715498507
7 changed files with 127 additions and 37 deletions

View File

@ -205,4 +205,12 @@ fun addCraftingTableRecipes(consumer: Consumer<FinishedRecipe>) {
.row(MItemTags.PLATE_TRITANIUM, MItems.MACHINE_FRAME, MItemTags.PLATE_TRITANIUM)
.row(MItemTags.PLATE_TRITANIUM, MItems.ELECTRIC_PARTS, MItemTags.PLATE_TRITANIUM)
.build(consumer)
// Энерго меч
MatteryRecipe(MItems.ENERGY_SWORD)
.rowBC(MItemTags.PLATE_TRITANIUM, MItemTags.GOLD_WIRES)
.rowBC(MItemTags.PLATE_TRITANIUM, MItemTags.GOLD_WIRES)
.row(MItems.BATTERY_CAPACITOR, MItems.TRITANIUM_SWORD, MItemTags.ADVANCED_CIRCUIT)
.unlockedBy(MItems.BATTERY_CAPACITOR)
.buildEnergetic(consumer)
}

View File

@ -9,9 +9,11 @@ import net.minecraft.resources.ResourceLocation
import net.minecraft.tags.TagKey
import net.minecraft.world.item.Item
import net.minecraft.world.item.crafting.Ingredient
import net.minecraft.world.item.crafting.RecipeSerializer
import net.minecraft.world.level.ItemLike
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.core.registryName
import ru.dbotthepony.mc.otm.recipe.EnergyContainerRecipe
import java.util.function.Consumer
private interface RecipeCell {
@ -156,6 +158,16 @@ class MatteryRecipe(val result: ItemLike, val count: Int = 1) {
}
}
fun buildEnergetic(consumer: Consumer<FinishedRecipe>, name: String? = null) {
build({
consumer.accept(object : FinishedRecipe by it {
override fun getType(): RecipeSerializer<*> {
return EnergyContainerRecipe.Companion
}
})
}, name)
}
fun row(): MatteryRecipe {
if (index == 3) {
throw IllegalStateException("Already have all rows defined")

View File

@ -5,10 +5,10 @@ import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
import ru.dbotthepony.mc.otm.recipe.EnergyContainerRecipe;
import ru.dbotthepony.mc.otm.recipe.PlatePressRecipe;
import ru.dbotthepony.mc.otm.recipe.PlatePressRecipeFactory;
@ -27,17 +27,20 @@ public class MRecipes {
}
public static final MatteryRecipeType<PlatePressRecipe> PLATE_PRESS = new MatteryRecipeType<>(OverdriveThatMatters.loc(MNames.PLATE_PRESS));
public static final MatteryRecipeType<PlatePressRecipe> ENERGY_CONTAINER = new MatteryRecipeType<>(OverdriveThatMatters.loc("energy_container"));
private static final DeferredRegister<RecipeSerializer<?>> registry = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, OverdriveThatMatters.MOD_ID);
private static final DeferredRegister<RecipeType<?>> typesRegistry = DeferredRegister.create(ForgeRegistries.RECIPE_TYPES, OverdriveThatMatters.MOD_ID);
private static final DeferredRegister<RecipeSerializer<?>> serializerRegistry = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, OverdriveThatMatters.MOD_ID);
private static final DeferredRegister<RecipeType<?>> typeRegistry = DeferredRegister.create(ForgeRegistries.RECIPE_TYPES, OverdriveThatMatters.MOD_ID);
static {
registry.register(MNames.PLATE_PRESS, () -> PlatePressRecipeFactory.INSTANCE);
typesRegistry.register(MNames.PLATE_PRESS, () -> PLATE_PRESS);
serializerRegistry.register(MNames.PLATE_PRESS, () -> PlatePressRecipeFactory.INSTANCE);
serializerRegistry.register(ENERGY_CONTAINER.name.getPath(), () -> EnergyContainerRecipe.Companion);
typeRegistry.register(MNames.PLATE_PRESS, () -> PLATE_PRESS);
typeRegistry.register(ENERGY_CONTAINER.name.getPath(), () -> ENERGY_CONTAINER);
}
public static void register(IEventBus bus) {
registry.register(bus);
typesRegistry.register(bus);
serializerRegistry.register(bus);
typeRegistry.register(bus);
}
}

View File

@ -0,0 +1,25 @@
package ru.dbotthepony.mc.otm.container
import it.unimi.dsi.fastutil.objects.ObjectSpliterator
import it.unimi.dsi.fastutil.objects.ObjectSpliterators
import net.minecraft.world.Container
import net.minecraft.world.item.ItemStack
import java.util.stream.Stream
import java.util.stream.StreamSupport
class ContainerSpliterator(private val container: Container, offset: Int = 0, private val maxPos: Int = container.containerSize) : ObjectSpliterators.AbstractIndexBasedSpliterator<ItemStack>(offset) {
override fun get(location: Int): ItemStack {
return container[location]
}
override fun getMaxPos(): Int {
return maxPos
}
override fun makeForSplit(pos: Int, maxPos: Int): ObjectSpliterator<ItemStack> {
return ContainerSpliterator(container, pos, maxPos)
}
}
fun Container.spliterator() = ContainerSpliterator(this)
fun Container.stream(): Stream<out ItemStack> = StreamSupport.stream(spliterator(), false)

View File

@ -160,10 +160,10 @@ class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE).tab(Ov
}
companion object {
private val MAX_ENERGY = ImpreciseFraction(400_000)
private val ENERGY_ZAP = ImpreciseFraction(10_000)
private val ENERGY_PER_SWING = ImpreciseFraction(4_000)
private val COBWEB_POWER_COST = ImpreciseFraction(1_500)
private val MAX_ENERGY = ImpreciseFraction(500_000)
private val ENERGY_ZAP = ImpreciseFraction(4_000)
private val ENERGY_PER_SWING = ImpreciseFraction(2_000)
private val COBWEB_POWER_COST = ImpreciseFraction(2_500)
private val PLANT_POWER_COST = ImpreciseFraction(500)
private val DESCRIPTION = TranslatableComponent("item.overdrive_that_matters.energy_sword.desc").withStyle(ChatFormatting.DARK_GRAY)

View File

@ -0,0 +1,56 @@
package ru.dbotthepony.mc.otm.recipe
import com.google.gson.JsonObject
import net.minecraft.network.FriendlyByteBuf
import net.minecraft.resources.ResourceLocation
import net.minecraft.world.inventory.CraftingContainer
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.crafting.CraftingRecipe
import net.minecraft.world.item.crafting.Recipe
import net.minecraft.world.item.crafting.RecipeSerializer
import net.minecraft.world.item.crafting.RecipeType
import net.minecraft.world.item.crafting.ShapedRecipe
import ru.dbotthepony.mc.otm.capability.ItemEnergyStorageImpl
import ru.dbotthepony.mc.otm.capability.matteryEnergy
import ru.dbotthepony.mc.otm.container.stream
import ru.dbotthepony.mc.otm.core.set
import ru.dbotthepony.mc.otm.core.tagNotNull
class EnergyContainerRecipe(
val parent: ShapedRecipe
) : CraftingRecipe by parent {
override fun assemble(container: CraftingContainer): ItemStack {
if (container.stream().anyMatch { it.isDamaged }) {
return ItemStack.EMPTY
}
val itemStack = parent.assemble(container)
val battery = container.stream()
.filter { !it.isEmpty }
.map { it.matteryEnergy }
.filter { it != null }
.findAny().orElse(null)
if (battery != null) {
itemStack.tagNotNull[ItemEnergyStorageImpl.NBT_KEY] = battery.batteryLevel.serializeNBT()
}
return itemStack
}
companion object : RecipeSerializer<EnergyContainerRecipe> {
override fun fromJson(p_44103_: ResourceLocation, p_44104_: JsonObject): EnergyContainerRecipe {
return EnergyContainerRecipe(ShapedRecipe.Serializer.SHAPED_RECIPE.fromJson(p_44103_, p_44104_))
}
override fun fromNetwork(p_44105_: ResourceLocation, p_44106_: FriendlyByteBuf): EnergyContainerRecipe? {
return ShapedRecipe.Serializer.SHAPED_RECIPE.fromNetwork(p_44105_, p_44106_)?.let(::EnergyContainerRecipe)
}
override fun toNetwork(p_44101_: FriendlyByteBuf, p_44102_: EnergyContainerRecipe) {
ShapedRecipe.Serializer.SHAPED_RECIPE.toNetwork(p_44101_, p_44102_.parent)
}
}
}

View File

@ -34,44 +34,30 @@ class PlatePressRecipe(
return input.test(container[PlatePressBlockEntity.SLOT_INPUT])
}
private var outputStack: ItemStack? = null
private val outputStack: ItemStack by lazy {
if (output.isEmpty || input.isEmpty) {
ItemStack.EMPTY
} else {
val items = output.items
val bestMatch = items.firstOrNull { it.item.registryName?.namespace == OverdriveThatMatters.MOD_ID } ?: items[0]
bestMatch.copy().also { it.count = this.count }
}
}
override fun getIngredients(): NonNullList<Ingredient> {
if (input.isEmpty || output.isEmpty)
return super.getIngredients()
return NonNullList.of(null, input)
return NonNullList.of(Ingredient.EMPTY, input)
}
override fun isIncomplete(): Boolean {
return !(input.items.any { it.item != Items.BARRIER } && output.items.any { it.item != Items.BARRIER })
}
override fun assemble(p_44001_: Container): ItemStack = resultItem.copy()
override fun assemble(p_44001_: Container): ItemStack = outputStack.copy()
override fun canCraftInDimensions(p_43999_: Int, p_44000_: Int) = true
override fun getResultItem(): ItemStack {
if (outputStack == null) {
if (output.isEmpty || input.isEmpty) {
outputStack = ItemStack.EMPTY
} else {
val items = output.items
var bestMatch = items[0]
// прежде всего выдавать предметы из OTM
for (item in items) {
if (item.item.registryName?.namespace == OverdriveThatMatters.MOD_ID) {
bestMatch = item
break
}
}
outputStack = bestMatch.copy()
outputStack!!.count = this.count
}
}
return outputStack!!
}
override fun getResultItem(): ItemStack = outputStack
override fun getId() = id