Skip to content

Commit

Permalink
add option for #4
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle committed Sep 1, 2022
1 parent 51423b9 commit 867dbad
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 34 deletions.
13 changes: 10 additions & 3 deletions src/main/kotlin/com/possible_triangle/sliceanddice/Content.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,14 @@ import java.util.function.Supplier

object Content {

private val REGISTRATE = CreateRegistrate.lazy(MOD_ID).get()
.creativeModeTab { CreateItemGroup.TAB_TOOLS }
.startSection(AllSections.LOGISTICS)
private object REGISTRATE : CreateRegistrate(MOD_ID) {
fun register(bus: IEventBus) = registerEventListeners(bus)

init {
creativeModeTab { CreateItemGroup.TAB_TOOLS }
startSection(AllSections.LOGISTICS)
}
}

val RECIPE_SERIALIZERS = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, MOD_ID)
val RECIPE_TYPES = DeferredRegister.create(Registry.RECIPE_TYPE_REGISTRY, MOD_ID)
Expand Down Expand Up @@ -148,6 +153,8 @@ object Content {
.register()

fun register(modBus: IEventBus) {
REGISTRATE.register(modBus)

LOADING_CONTEXT.registerConfig(ModConfig.Type.COMMON, Configs.SERVER_SPEC)
LOADING_CONTEXT.registerConfig(ModConfig.Type.CLIENT, Configs.CLIENT_SPEC)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.possible_triangle.sliceanddice.block.tile

import com.possible_triangle.sliceanddice.Content
import com.possible_triangle.sliceanddice.SliceAndDice
import com.possible_triangle.sliceanddice.config.Configs
import com.possible_triangle.sliceanddice.recipe.CuttingProcessingRecipe
import com.simibubi.create.content.contraptions.components.press.PressingBehaviour
Expand All @@ -9,16 +10,18 @@ import com.simibubi.create.content.contraptions.components.press.PressingBehavio
import com.simibubi.create.content.contraptions.processing.BasinOperatingTileEntity
import com.simibubi.create.content.contraptions.processing.InWorldProcessing
import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack
import com.simibubi.create.foundation.item.TooltipHelper
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour
import com.simibubi.create.foundation.utility.Lang
import com.simibubi.create.foundation.utility.VecHelper
import com.simibubi.create.foundation.utility.recipe.RecipeFinder
import net.minecraft.ChatFormatting
import net.minecraft.client.resources.language.I18n
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.core.particles.ItemParticleOption
import net.minecraft.core.particles.ParticleOptions
import net.minecraft.core.particles.ParticleTypes
import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.NbtOps
import net.minecraft.network.chat.Component
import net.minecraft.server.level.ServerLevel
import net.minecraft.world.Container
import net.minecraft.world.entity.item.ItemEntity
Expand All @@ -40,6 +43,32 @@ class SlicerTile(type: BlockEntityType<*>, pos: BlockPos, state: BlockState) :

override fun getRecipeCacheKey() = basinCacheKey

val correctDirection get() = Configs.SERVER.IGNORE_ROTATION.get() || getSpeed() < 0
val canProcess get() = correctDirection && isSpeedRequirementFulfilled

override fun updateBasin(): Boolean {
return !correctDirection || super.updateBasin()
}

override fun addToTooltip(tooltip: MutableList<Component>?, isPlayerSneaking: Boolean): Boolean {
if (super.addToTooltip(tooltip, isPlayerSneaking)) return true
if (!correctDirection && speed != 0F) {
Lang.builder(SliceAndDice.MOD_ID)
.translate("tooltip.rotationDirection")
.style(ChatFormatting.GOLD)
.forGoggles(tooltip)
val hint = Lang.builder(SliceAndDice.MOD_ID)
.translate("gui.contraptions.wrong_direction", I18n.get(blockState.block.descriptionId))
.component()
val cutString = TooltipHelper.cutTextComponent(hint, ChatFormatting.GRAY, ChatFormatting.WHITE)
for (i in cutString.indices) {
Lang.builder().add(cutString[i].copy()).forGoggles(tooltip)
}
return true
}
return false
}

var heldItem = ItemStack.EMPTY
private lateinit var behaviour: PressingBehaviour
val cuttingBehaviour get() = behaviour
Expand Down Expand Up @@ -129,6 +158,7 @@ class SlicerTile(type: BlockEntityType<*>, pos: BlockPos, state: BlockState) :
}

override fun tryProcessInBasin(simulate: Boolean): Boolean {
if(!canProcess) return false
applyBasinRecipe()

basin.ifPresent {
Expand All @@ -148,6 +178,7 @@ class SlicerTile(type: BlockEntityType<*>, pos: BlockPos, state: BlockState) :
outputList: MutableList<ItemStack>?,
simulate: Boolean,
): Boolean {
if(!canProcess) return false
val recipe = recipeFor(input.stack) ?: return false
if (simulate) return true

Expand All @@ -173,32 +204,6 @@ class SlicerTile(type: BlockEntityType<*>, pos: BlockPos, state: BlockState) :
return recipe !is CuttingProcessingRecipe || recipe.tool?.test(heldItem) == true
}

override fun tick() {
super.tick()
if (isRunning) {

}
}

private fun renderParticles() {
if (level == null) return
behaviour.particleItems.filterNot { it.isEmpty }.forEach { stack ->
val data = ItemParticleOption(ParticleTypes.ITEM, stack)
spillParticle(data)
}
}

private fun spillParticle(data: ParticleOptions?) {
val angle = level!!.random.nextFloat() * 360
var offset = Vec3(0.0, 0.0, 0.25)
offset = VecHelper.rotate(offset, angle.toDouble(), Direction.Axis.Y)
var target = VecHelper.rotate(offset, (if (getSpeed() > 0) 25 else -25).toDouble(), Direction.Axis.Y)
.add(0.0, .25, 0.0)
val center = offset.add(VecHelper.getCenterOf(worldPosition))
target = VecHelper.offsetRandomly(target.subtract(offset), level!!.random, 1 / 128f)
level!!.addParticle(data, center.x, center.y - 1.75f, center.z, target.x, target.y, target.z)
}

override fun onPressingCompleted() {
val canContinue = behaviour.onBasin()
&& matchBasinRecipe(currentRecipe)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.util.function.Supplier
class ServerConfig(builder: ForgeConfigSpec.Builder) {

val CONSUME_DURABILTY = builder.define("slicer.consume_tool_durability", true)
val IGNORE_ROTATION = builder.define("slicer.ignore_rotation", false)

val BASIN_COOKING = builder.define("basin_cooking.enabled", true)
//val REPLACE_FLUID_CONTAINERS = builder.define("basin_cooking.replace_fluid_containers", true)
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/sliceanddice/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
"block.sliceanddice.wet_air": "Feuchte Luft",
"sliceanddice.ponder.slicer.header": "Automatisches Schneiden mit dem Thermomix",
"sliceanddice.ponder.slicer.text_1": "Recht-Klick mit einem erlaubten Werkzeug",
"sliceanddice.ponder.slicer.text_2": "Der Thermomix kann auch mit einem Behälter genutzt werden"
"sliceanddice.ponder.slicer.text_2": "Der Thermomix kann auch mit einem Behälter genutzt werden",
"sliceanddice.tooltip.rotationDirection": "Rotationsrichtung",
"sliceanddice.gui.contraptions.wrong_direction": "Es scheint, dass sich dieser %s in die _falsche Richtung_ dreht."
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/sliceanddice/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
"block.sliceanddice.wet_air": "Wet Air",
"sliceanddice.ponder.slicer.header": "Cutting with the slicer",
"sliceanddice.ponder.slicer.text_1": "Right-click it with a valid tool",
"sliceanddice.ponder.slicer.text_2": "The slicer can also operate on a basin"
"sliceanddice.ponder.slicer.text_2": "The slicer can also operate on a basin",
"sliceanddice.tooltip.rotationDirection": "Rotation Direction",
"sliceanddice.gui.contraptions.wrong_direction": "It appears that this %s is rotating in the _wrong direction_."
}

0 comments on commit 867dbad

Please sign in to comment.