Skip to content

Commit

Permalink
feat: uranium ingot extractor and infinity singularity reactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ybw0014 committed Nov 27, 2024
1 parent 9a146f1 commit 2e88cf6
Show file tree
Hide file tree
Showing 9 changed files with 330 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import net.guizhanss.infinityexpansion2.implementation.items.gear.InfinityTool
import net.guizhanss.infinityexpansion2.implementation.items.generators.EnergyGenerator
import net.guizhanss.infinityexpansion2.implementation.items.generators.GeneratorType
import net.guizhanss.infinityexpansion2.implementation.items.generators.InfinityReactor
import net.guizhanss.infinityexpansion2.implementation.items.generators.InfinitySingularityReactor
import net.guizhanss.infinityexpansion2.implementation.items.machines.AdvancedAnvil
import net.guizhanss.infinityexpansion2.implementation.items.machines.CobblePress
import net.guizhanss.infinityexpansion2.implementation.items.machines.Decompressor
Expand All @@ -38,6 +39,7 @@ import net.guizhanss.infinityexpansion2.implementation.items.machines.SmithingTe
import net.guizhanss.infinityexpansion2.implementation.items.machines.StoneworksFactory
import net.guizhanss.infinityexpansion2.implementation.items.machines.TreeGrower
import net.guizhanss.infinityexpansion2.implementation.items.machines.UraniumExtractor
import net.guizhanss.infinityexpansion2.implementation.items.machines.UraniumIngotExtractor
import net.guizhanss.infinityexpansion2.implementation.items.machines.VirtualFarm
import net.guizhanss.infinityexpansion2.implementation.items.machines.VoidHarvester
import net.guizhanss.infinityexpansion2.implementation.items.materials.EnderEssence
Expand Down Expand Up @@ -707,15 +709,15 @@ object IEItems : ItemRegistry(InfinityExpansion2.instance, InfinityExpansion2.lo
recipeType = IERecipeTypes.INFINITY_WORKBENCH
recipe = buildRecipe(6) {
+" IVVI "
+" IOOI "
+" ICCI "
+" IEEI "
+" IEEI "
+" ICCI "
+" IOOI "
+" IVVI "
'V' means VOID_INGOT
'I' means INFINITY_INGOT
'C' means INFINITY_MACHINE_CORE
'E' means SlimefunItems.ENERGIZED_CAPACITOR
'O' means INFINITY_MACHINE_CORE
'C' means VOID_CAPACITOR
}
}

Expand Down Expand Up @@ -1759,6 +1761,8 @@ object IEItems : ItemRegistry(InfinityExpansion2.instance, InfinityExpansion2.lo
}
}

// TODO: more tiers of obsidian generator

val EXTREME_FREEZER by buildSlimefunItem<ExtremeFreezer>(90) {
material = Material.LIGHT_BLUE_CONCRETE.asMaterialType()
itemGroup = IEItemGroups.MACHINES
Expand Down Expand Up @@ -1918,6 +1922,20 @@ object IEItems : ItemRegistry(InfinityExpansion2.instance, InfinityExpansion2.lo
}
}

val URANIUM_INGOT_EXTRACTOR by buildSlimefunItem<UraniumIngotExtractor>(800, 4, 1) {
material = Material.GREEN_CONCRETE.asMaterialType()
itemGroup = IEItemGroups.MACHINES
recipeType = RecipeType.ENHANCED_CRAFTING_TABLE
recipe = buildRecipe {
+"NEN"
+"NUN"
+"UUU"
'N' means Material.NETHERITE_BLOCK.toItem()
'E' means SlimefunItems.ENERGIZED_CAPACITOR
'U' means URANIUM_EXTRACTOR
}
}

val COBBLE_PRESS by buildSlimefunItem<CobblePress>(200) {
material = Material.SMOOTH_STONE.asMaterialType()
itemGroup = IEItemGroups.MACHINES
Expand Down Expand Up @@ -2269,6 +2287,26 @@ object IEItems : ItemRegistry(InfinityExpansion2.instance, InfinityExpansion2.lo
'O' means INFINITY_MACHINE_CORE
}
}

val INFINITY_SINGULARITY_REACTOR by buildSlimefunItem<InfinitySingularityReactor>(180_000) {
material = Material.BEACON.asMaterialType()
itemGroup = IEItemGroups.GENERATORS
recipeType = IERecipeTypes.INFINITY_WORKBENCH
recipe = buildRecipe(6) {
+" S S "
+"IIIIII"
+"P CC P"
+"P RO P"
+"IIIIII"
+" "
'S' means INFINITY_SINGULARITY
'I' means INFINITY_INGOT
'P' means MACHINE_PLATE
'R' means INFINITY_REACTOR
'C' means INFINITY_MACHINE_CIRCUIT
'O' means INFINITY_MACHINE_CORE
}
}
//</editor-fold>

//<editor-fold desc="Mob Simulation" defaultstate="collapsed">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@file:Suppress("deprecation")

package net.guizhanss.infinityexpansion2.implementation.items.generators

import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack
import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetProvider
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu
import net.guizhanss.guizhanlib.slimefun.machines.MenuBlock
import net.guizhanss.infinityexpansion2.core.items.attributes.CustomTickRateMachine
import net.guizhanss.infinityexpansion2.core.items.attributes.EnergyProducer
import net.guizhanss.infinityexpansion2.core.items.attributes.InformationalRecipeDisplayItem
import net.guizhanss.infinityexpansion2.utils.getInt
import net.guizhanss.infinityexpansion2.utils.setInt
import org.bukkit.Location
import org.bukkit.block.Block
import org.bukkit.inventory.ItemStack

abstract class AbstractReactor(
itemGroup: ItemGroup,
itemStack: SlimefunItemStack,
recipeType: RecipeType,
recipe: Array<out ItemStack?>,
defaultProduction: Int,
) : MenuBlock(itemGroup, itemStack, recipeType, recipe), EnergyNetProvider, CustomTickRateMachine, EnergyProducer,
InformationalRecipeDisplayItem {

private val tickRateSetting = IntRangeSetting(this, "tick-rate", 1, 1, 3600)
private val energyProductionSetting =
IntRangeSetting(this, "energy-production", 1, defaultProduction, Int.MAX_VALUE)

init {
addItemSetting(tickRateSetting, energyProductionSetting)
}

override fun onNewInstance(menu: BlockMenu, b: Block) {
b.location.setProgress(0)
}

override fun getOutputSlots() = intArrayOf()

override fun getCustomTickRate() = tickRateSetting.value

override fun getCapacity() = getEnergyProduction()

override fun getEnergyProduction() = energyProductionSetting.value

protected fun Location.setProgress(progress: Int) {
setInt(PROGRESS_KEY, progress)
}

protected fun Location.getProgress() = getInt(PROGRESS_KEY)

companion object {

private const val PROGRESS_KEY = "progress"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,18 @@ import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack
import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetProvider
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config
import me.mrCookieSlime.Slimefun.api.BlockStorage
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset
import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu
import net.guizhanss.guizhanlib.slimefun.machines.MenuBlock
import net.guizhanss.infinityexpansion2.InfinityExpansion2
import net.guizhanss.infinityexpansion2.core.items.attributes.CustomTickRateMachine
import net.guizhanss.infinityexpansion2.core.items.attributes.EnergyProducer
import net.guizhanss.infinityexpansion2.core.items.attributes.InformationalRecipeDisplayItem
import net.guizhanss.infinityexpansion2.implementation.IEItems
import net.guizhanss.infinityexpansion2.utils.getInt
import net.guizhanss.infinityexpansion2.utils.items.GuiItems
import net.guizhanss.infinityexpansion2.utils.items.MachineLore
import net.guizhanss.infinityexpansion2.utils.setInt
import org.bukkit.ChatColor
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.block.Block
import org.bukkit.inventory.ItemStack
import java.util.logging.Level

Expand All @@ -37,19 +29,15 @@ class InfinityReactor(
recipeType: RecipeType,
recipe: Array<out ItemStack?>,
defaultProduction: Int,
) : MenuBlock(itemGroup, itemStack, recipeType, recipe), EnergyNetProvider, CustomTickRateMachine, EnergyProducer,
InformationalRecipeDisplayItem {
) : AbstractReactor(itemGroup, itemStack, recipeType, recipe, defaultProduction) {

private val tickRateSetting = IntRangeSetting(this, "tick-rate", 1, 1, 3600)
private val energyProductionSetting =
IntRangeSetting(this, "energy-production", 1, defaultProduction, Int.MAX_VALUE)
private val voidIngotDurationSetting =
IntRangeSetting(this, "void-ingot-duration", 1, 28_800, Int.MAX_VALUE) // 4 hours
private val infinityIngotDurationSetting =
IntRangeSetting(this, "infinity-ingot-duration", 1, 172_800, Int.MAX_VALUE) // 24 hours

init {
addItemSetting(tickRateSetting, energyProductionSetting, voidIngotDurationSetting, infinityIngotDurationSetting)
addItemSetting(voidIngotDurationSetting, infinityIngotDurationSetting)
}

override fun postRegister() {
Expand All @@ -76,10 +64,6 @@ class InfinityReactor(
preset.drawBackground(INFINITY_BORDER_ITEM, INFINITY_BORDER)
}

override fun onNewInstance(menu: BlockMenu, b: Block) {
b.setInt(PROGRESS_KEY, 0)
}

override fun getInputSlots() = intArrayOf(VOID_INPUT, INFINITY_INPUT)

override fun getInputSlots(menu: DirtyChestMenu, item: ItemStack): IntArray {
Expand All @@ -88,17 +72,9 @@ class InfinityReactor(
else intArrayOf()
}

override fun getOutputSlots() = intArrayOf()

override fun getCustomTickRate() = tickRateSetting.value

override fun getCapacity() = getEnergyProduction()

override fun getEnergyProduction() = energyProductionSetting.value

override fun getGeneratedOutput(l: Location, data: Config): Int {
val menu = BlockStorage.getInventory(l) ?: return 0
val progress = l.getInt(PROGRESS_KEY)
val progress = l.getProgress()
val voidInput = menu.getItemInSlot(VOID_INPUT)
val infinityInput = menu.getItemInSlot(INFINITY_INPUT)

Expand All @@ -116,13 +92,13 @@ class InfinityReactor(
menu.consumeItem(VOID_INPUT)
menu.consumeItem(INFINITY_INPUT)
menu.setStatus { info(infinityIngotDurationSetting.value, voidIngotDurationSetting.value) }
l.setInt(PROGRESS_KEY, 1)
l.setProgress(1)
return getEnergyProduction()
}

if (progress > infinityIngotDurationSetting.value) { // done
menu.setStatus { GuiItems.PRODUCING }
l.setInt(PROGRESS_KEY, 0)
l.setProgress(0)
return getEnergyProduction()
}

Expand All @@ -132,19 +108,11 @@ class InfinityReactor(
return 0
}

l.setInt(PROGRESS_KEY, progress + 1)
menu.consumeItem(VOID_INPUT)
menu.setStatus {
info(
infinityIngotDurationSetting.value - progress,
voidIngotDurationSetting.value - Math.floorMod(progress, voidIngotDurationSetting.value)
)
}
return getEnergyProduction()
}

// progressing
l.setInt(PROGRESS_KEY, progress + 1)
l.setProgress(progress + 1)
menu.setStatus {
info(
infinityIngotDurationSetting.value - progress,
Expand Down Expand Up @@ -172,7 +140,6 @@ class InfinityReactor(

companion object {

private const val PROGRESS_KEY = "progress"
private val BACKGROUND = intArrayOf(3, 4, 5)
private val VOID_BORDER = intArrayOf(0, 2)
private val INFINITY_BORDER = intArrayOf(6, 8)
Expand All @@ -195,13 +162,13 @@ class InfinityReactor(

private fun infoVoid(ticks: Int) = InfinityExpansion2.localization.getGuiItem(
Material.LIME_STAINED_GLASS_PANE.asMaterialType(),
"ir_info_void",
"ir_duration_void",
"${ChatColor.GRAY}${MachineLore.format(ticks)}"
)

private fun infoInfinity(ticks: Int) = InfinityExpansion2.localization.getGuiItem(
Material.LIME_STAINED_GLASS_PANE.asMaterialType(),
"ir_info_infinity",
"ir_duration_infinity",
"${ChatColor.GRAY}${MachineLore.format(ticks)}"
)

Expand Down
Loading

0 comments on commit 2e88cf6

Please sign in to comment.