Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Takakura-Anri committed Mar 21, 2020
1 parent b876030 commit 1f586d1
Show file tree
Hide file tree
Showing 25 changed files with 528 additions and 56 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
buildscript {
repositories {
jcenter()
maven {
url = "https://maven.aliyun.com/repository/public"
}
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
Expand All @@ -19,6 +21,7 @@ buildscript {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
classpath 'co.riiid:gradle-github-plugin:0.4.2'
classpath 'gradle.plugin.com.matthewprenger:CurseGradle:1.4.0'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.70'
}
}

Expand Down Expand Up @@ -74,6 +77,7 @@ minecraft {
dependencies {
compileOnly "mezz.jei:jei_1.12.2:4.15.0.293:api"
compile "net.shadowfacts:Forgelin:1.8.4"
compile "io.reactivex.rxjava3:rxjava:3.0.0"
deobfCompile "org.cyclops.commoncapabilities:CommonCapabilities:1.12.2-1.4.0-174:deobf"

compileOnly "mcjty.theoneprobe:TheOneProbe-1.12:1.12-1.4.28-17:api"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
11 changes: 11 additions & 0 deletions src/main/java/com/projecturanus/foodcraft/FoodCraftReloaded.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.projecturanus.foodcraft

import com.projecturanus.foodcraft.common.GuiHandler
import com.projecturanus.foodcraft.common.block.entity.*
import com.projecturanus.foodcraft.common.capability.DefaultCapabilities
import com.projecturanus.foodcraft.common.init.RegisterHandler
import com.projecturanus.foodcraft.common.network.registerMessages
import com.projecturanus.foodcraft.common.recipe.RecipeRegistryHandler
Expand Down Expand Up @@ -61,6 +62,16 @@ object FoodCraftReloaded {
RegisterHandler.mirrorOres("listAlloil", "foodSesameoil")
RegisterHandler.mirrorOres("listAlloil", "foodOliveoil")
}

if (!Loader.isModLoaded("commoncapabilities")) {
DefaultCapabilities.registerDefaultCapabilities()
}
}

@Mod.EventHandler
fun loadComplete(event: FMLLoadCompleteEvent) {
logger.info("Caching Allowed Fluid for Machines")
RecipeRegistryHandler.reloadRecipeFluids()
}

@Mod.EventHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
package com.projecturanus.foodcraft.client.gui

import com.projecturanus.foodcraft.MODID
import com.projecturanus.foodcraft.common.block.container.ContainerMachine
import com.projecturanus.foodcraft.client.gui.widget.WidgetCookBar
import com.projecturanus.foodcraft.client.gui.widget.WidgetHeat
import com.projecturanus.foodcraft.client.gui.widget.WidgetProgressBar
import com.projecturanus.foodcraft.common.block.container.ContainerPan
import net.minecraft.util.ResourceLocation

val PAN_TEXTURES = ResourceLocation(MODID, "textures/gui/container/pan.png")

class GuiContainerPan(container: ContainerMachine) : GuiContainerMachine(container, PAN_TEXTURES) {
class GuiContainerPan(override val container: ContainerPan) : GuiContainerMachine(container, PAN_TEXTURES) {
val tileEntity by lazy { container.tileEntity }
val heatHandler by lazy { tileEntity.heatHandler }
val progress get() = container.progress / container.minProgress.toDouble()
val overcookProgress get() = (container.progress - container.minProgress) / (container.maxProgress - container.minProgress).toDouble()

val widgetHeat = WidgetHeat(176, 0, container::heat.getter)
val widgetProgress by lazy { WidgetProgressBar(176, 14, this::progress.getter) }
val widgetCookBar by lazy { WidgetCookBar(176, 31, this::overcookProgress.getter) }

override fun initGui() {
super.initGui()
widgetHeat.temperature = heatHandler
widgetHeat.setWorldAndResolution(mc, width, height)
widgetProgress.setWorldAndResolution(mc, width, height)
widgetCookBar.setWorldAndResolution(mc, width, height)
}

override fun drawGuiContainerBackgroundLayer(partialTicks: Float, mouseX: Int, mouseY: Int) {
super.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY)
val i = (width - xSize) / 2
val j = (height - ySize) / 2

widgetHeat.draw(i + 81, j + 19, mouseX, mouseY, partialTicks)
widgetProgress.draw(i + 72, j + 39, mouseX, mouseY, partialTicks)
widgetCookBar.draw(i + 46, j + 62, mouseX, mouseY, partialTicks)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
package com.projecturanus.foodcraft.client.gui

import com.projecturanus.foodcraft.MODID
import com.projecturanus.foodcraft.common.block.container.ContainerMachine
import com.projecturanus.foodcraft.client.gui.widget.WidgetCookBar
import com.projecturanus.foodcraft.client.gui.widget.WidgetHeat
import com.projecturanus.foodcraft.client.gui.widget.WidgetProgressBar
import com.projecturanus.foodcraft.common.block.container.ContainerPot
import net.minecraft.util.ResourceLocation

val POT_TEXTURES = ResourceLocation(MODID, "textures/gui/container/pot.png")

class GuiContainerPot(container: ContainerMachine) : GuiContainerMachine(container, POT_TEXTURES) {
class GuiContainerPot(override val container: ContainerPot) : GuiContainerMachine(container, POT_TEXTURES) {
val tileEntity by lazy { container.tileEntity }
val heatHandler by lazy { tileEntity.heatHandler }
val progress get() = container.progress / container.minProgress.toDouble()
val overcookProgress get() = (container.progress - container.minProgress) / (container.maxProgress - container.minProgress).toDouble()

val widgetHeat = WidgetHeat(176, 0, container::heat.getter)
val widgetProgress by lazy { WidgetProgressBar(176, 15, this::progress.getter) }
val widgetCookBar by lazy { WidgetCookBar(176, 31, this::overcookProgress.getter) }

override fun initGui() {
super.initGui()
widgetHeat.temperature = heatHandler
widgetHeat.setWorldAndResolution(mc, width, height)
widgetProgress.setWorldAndResolution(mc, width, height)
widgetCookBar.setWorldAndResolution(mc, width, height)
}

override fun drawGuiContainerBackgroundLayer(partialTicks: Float, mouseX: Int, mouseY: Int) {
super.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY)
val i = (width - xSize) / 2
val j = (height - ySize) / 2

widgetHeat.draw(i + 81, j + 64, mouseX, mouseY, partialTicks)
widgetProgress.draw(i + 93, j + 20, mouseX, mouseY, partialTicks)
widgetCookBar.draw(i + 48, j + 38, mouseX, mouseY, partialTicks)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.projecturanus.foodcraft.client.gui.widget

import kotlin.reflect.KProperty0

class WidgetCookBar(val x: Int, val y: Int, val progress: KProperty0.Getter<Double>) : Widget() {

companion object {
const val WIDTH = 78
const val HEIGHT = 3
}

override fun isMouseIn(x: Int, y: Int, mouseX: Int, mouseY: Int): Boolean {
return mouseX > x && mouseY > y && mouseX < x + WIDTH && mouseY < y + HEIGHT
}

override fun draw(x: Int, y: Int, mouseX: Int, mouseY: Int, partialTicks: Float) {
val l: Int = (progress.invoke() * WIDTH).toInt()
this.drawTexturedModalRect(x, y, this.x, this.y, l, HEIGHT)
if (isMouseIn(x, y, mouseX, mouseY) && l >= 0) {
this.drawHoveringText(listOf("Overcooked progress: ${progress.invoke()}"), x, y, fontRenderer)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package com.projecturanus.foodcraft.common.block.container

import com.projecturanus.foodcraft.MODID
import com.projecturanus.foodcraft.common.block.entity.TileEntityPan
import com.projecturanus.foodcraft.common.network.CHANNAL
import com.projecturanus.foodcraft.common.network.S2CContainerHeatUpdate
import net.minecraft.entity.player.EntityPlayerMP
import net.minecraft.entity.player.InventoryPlayer
import net.minecraft.inventory.Slot
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.items.CapabilityItemHandler
import net.minecraftforge.items.SlotItemHandler


class ContainerPan(playerInventory: InventoryPlayer, tileEntity: TileEntity) : ContainerMachine(playerInventory, tileEntity) {
class ContainerPan(playerInventory: InventoryPlayer, tileEntity: TileEntity) : ContainerRecipeMachine<TileEntityPan>(playerInventory, tileEntity as TileEntityPan), HeatContainer {
override var heat = 0.0
var minProgress = 0
var maxProgress = 0

init {
val itemHandler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)!!
addSlotToContainer(SlotItemHandler(itemHandler, 0, 45, 39))
addSlotToContainer(SlotItemHandler(itemHandler, 1, 95, 60))
addSlotToContainer(SlotItemHandler(itemHandler, 2, 37, 59))
addSlotToContainer(SlotOutput(playerInventory.player, itemHandler, 3, 130, 31))
// addSlotToContainer(SlotItemHandler(itemHandler, 1, 95, 60)) TODO unused
addSlotToContainer(SlotOutput(playerInventory.player, itemHandler, 1, 108, 39))
addSlotToContainer(SlotOutput(playerInventory.player, itemHandler, 2, 137, 39))

for (x in 0 until 3) {
for (y in 0 until 9) {
Expand All @@ -27,5 +35,24 @@ class ContainerPan(playerInventory: InventoryPlayer, tileEntity: TileEntity) : C
}
}

override fun detectAndSendChanges() {
super.detectAndSendChanges()
listeners.forEach {
if (it is EntityPlayerMP) {
CHANNAL.sendTo(S2CContainerHeatUpdate(tileEntity.heatHandler.temperature), it)
}
it.sendWindowProperty(this, 1, tileEntity.recipe?.minTime ?: 0)
it.sendWindowProperty(this, 2, tileEntity.recipe?.maxTime ?: 0)
}
}

override fun updateProgressBar(id: Int, data: Int) {
super.updateProgressBar(id, data)
if (id == 1)
minProgress = data
if (id == 2)
maxProgress = data
}

override fun getName(): String = "tile.$MODID.pan.name"
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package com.projecturanus.foodcraft.common.block.container

import com.projecturanus.foodcraft.MODID
import com.projecturanus.foodcraft.common.block.entity.TileEntityPot
import com.projecturanus.foodcraft.common.network.CHANNAL
import com.projecturanus.foodcraft.common.network.S2CContainerHeatUpdate
import net.minecraft.entity.player.EntityPlayerMP
import net.minecraft.entity.player.InventoryPlayer
import net.minecraft.inventory.Slot
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.items.CapabilityItemHandler
import net.minecraftforge.items.SlotItemHandler


class ContainerPot(playerInventory: InventoryPlayer, tileEntity: TileEntity) : ContainerMachine(playerInventory, tileEntity) {
class ContainerPot(playerInventory: InventoryPlayer, tileEntity: TileEntity) : ContainerRecipeMachine<TileEntityPot>(playerInventory, tileEntity as TileEntityPot), HeatContainer {
override var heat = 0.0
var minProgress = 0
var maxProgress = 0

init {
val itemHandler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)!!
for (i in 0..3) {
Expand All @@ -31,5 +39,24 @@ class ContainerPot(playerInventory: InventoryPlayer, tileEntity: TileEntity) : C
}
}

override fun detectAndSendChanges() {
super.detectAndSendChanges()
listeners.forEach {
if (it is EntityPlayerMP) {
CHANNAL.sendTo(S2CContainerHeatUpdate(tileEntity.heatHandler.temperature), it)
}
it.sendWindowProperty(this, 1, tileEntity.recipe?.minTime ?: 0)
it.sendWindowProperty(this, 2, tileEntity.recipe?.maxTime ?: 0)
}
}

override fun updateProgressBar(id: Int, data: Int) {
super.updateProgressBar(id, data)
if (id == 1)
minProgress = data
if (id == 2)
maxProgress = data
}

override fun getName(): String = "tile.$MODID.pot.name"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,76 @@
package com.projecturanus.foodcraft.common.block.entity

class TileEntityPan : TileEntityMachine(4) {
import com.projecturanus.foodcraft.common.heat.FuelHeatHandler
import com.projecturanus.foodcraft.common.init.FCRItems
import com.projecturanus.foodcraft.common.recipe.PAN_RECIPES
import com.projecturanus.foodcraft.common.recipe.PanRecipe
import com.projecturanus.foodcraft.common.util.get
import com.projecturanus.foodcraft.common.util.shrink
import net.minecraft.item.ItemStack
import org.cyclops.commoncapabilities.api.capability.temperature.ITemperature

class TileEntityPan : TileEntityHeatRecipeMachine<PanRecipe>(PAN_RECIPES, 0..0, 1..1, 3) {
var waitingExtract = false

init {
inventory.contentChangedListener += {
if (it == 1 && inventory[1].isEmpty) {
reset()
}
}
}

override fun update() {
// Don't run tick on client
if (world.isRemote) return

beforeProgress()

if (recipe != null) {
// Finish
if (canFinish()) {
consumeInput()
working = false
val stack = recipe?.getRecipeOutput()?.copy()?: ItemStack.EMPTY
inventory.insertItem(1, stack, false)
waitingExtract = true
markDirty()
} else if (waitingExtract && progress > recipe!!.maxTime) { // Overcooked
inventory.shrink(1)
inventory.insertItem(2, ItemStack(FCRItems.OVERCOOKED_FOOD), false)
reset()
} else {
if (canProgress())
progress++
working = true
}
} else if (progress > 0) {
progress = 0
working = false
}
}

override fun reset() {
waitingExtract = false
progress = 0
markDirty()
recipe = findRecipe()
}

override fun beforeProgress() {
heatHandler.update(0.0)
}

override fun canProgress(): Boolean = heatHandler.temperature > ITemperature.ZERO_CELCIUS + 80

override fun canFinish(): Boolean = progress > recipe?.minTime ?: Int.MAX_VALUE && progress < recipe?.maxTime ?: -1 && !waitingExtract

override fun createFuelHandler(): FuelHeatHandler {
val heatHandler = FuelHeatHandler()
heatHandler.radiation = 0.02
heatHandler.heatPower = 1.0
heatHandler.minHeat = ITemperature.ZERO_CELCIUS
heatHandler.setMaxHeat(ITemperature.ZERO_CELCIUS + 160)
return heatHandler
}
}
Loading

0 comments on commit 1f586d1

Please sign in to comment.