Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
package org.valkyrienskies.clockwork.content.kinetics.resistor

import com.mojang.blaze3d.vertex.PoseStack
import com.simibubi.create.api.equipment.goggles.IHaveGoggleInformation
import com.simibubi.create.content.contraptions.DirectionalExtenderScrollOptionSlot
import com.simibubi.create.content.kinetics.RotationPropagator
import com.simibubi.create.content.kinetics.base.AbstractEncasedShaftBlock
import com.simibubi.create.content.kinetics.motor.CreativeMotorBlock
import com.simibubi.create.content.kinetics.transmission.SplitShaftBlockEntity
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour
import com.simibubi.create.foundation.blockEntity.behaviour.ValueBoxTransform
import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.INamedIconOptions
import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ScrollOptionBehaviour
import com.simibubi.create.foundation.gui.AllIcons
import com.simibubi.create.foundation.utility.CreateLang
import dev.engine_room.flywheel.lib.transform.TransformStack
import net.createmod.catnip.data.Iterate
import net.createmod.catnip.lang.Lang
import net.createmod.catnip.math.AngleHelper
import net.createmod.catnip.math.VecHelper
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.nbt.CompoundTag
import net.minecraft.network.chat.Component
import net.minecraft.world.level.Level
import net.minecraft.world.level.LevelAccessor
import net.minecraft.world.level.block.entity.BlockEntityType
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.phys.Vec3
import net.minecraft.world.ticks.TickPriority
import org.valkyrienskies.clockwork.ClockworkLang
import org.valkyrienskies.clockwork.ClockworkMod
import org.valkyrienskies.clockwork.content.contraptions.propeller.PropellerBearingBlockEntity.RotationDirection
import org.valkyrienskies.clockwork.util.ClockworkConstants
import kotlin.math.abs
import kotlin.math.round
Expand All @@ -22,6 +40,7 @@ open class RedstoneResistorBlockEntity(type: BlockEntityType<*>?, pos: BlockPos,
SplitShaftBlockEntity(type, pos, state), IHaveGoggleInformation {
var state = 0
var lastChange = 0
lateinit var resistDirection: ScrollOptionBehaviour<ResistDirection>
override fun tick() {
super.tick()
lastChange = state
Expand Down Expand Up @@ -62,16 +81,74 @@ open class RedstoneResistorBlockEntity(type: BlockEntityType<*>?, pos: BlockPos,
override fun getRotationSpeedModifier(face: Direction): Float {
if (hasSource()) {
if (face != sourceFacing) {
var i = abs(state - 15) / 15.0;
// We only keep 1 decimal place of precision on the mult, because anymore and
// create is stupid and fucks everything up with bad float math
i = round(i*10.0) / 10.0
var i = if (resistDirection.get() == ResistDirection.MAX_TO_NONE) {
abs(state - 15) / 15.0
} else {
abs(state) / 15.0
}
i = round(i*10)/10
return i.toFloat()
}
}
return 1f
}

//add behavior for resistor direction
override fun addBehaviours(behaviours: MutableList<BlockEntityBehaviour?>) {
super.addBehaviours(behaviours)
resistDirection = ScrollOptionBehaviour(
ResistDirection::class.java,
ClockworkLang.translateDirect("contraptions.resistor.resist_direction"), this,
ResistorValueBox()
)
behaviours.add(resistDirection)
}

//resistor direction enum
enum class ResistDirection(private val icon: AllIcons) : INamedIconOptions {
MAX_TO_NONE(AllIcons.I_REFRESH),
NONE_TO_MAX(AllIcons.I_ROTATE_CCW); //don't know what else to put, "0 RPM to 256 RPM" is pretty long and not even accurate most the time.

private val translationKey: String = "resistor.resist_direction." + Lang.asId(name)

override fun getIcon(): AllIcons {
return icon
}

override fun getTranslationKey(): String {
return translationKey
}
}

//value box class for scroll behavior
class ResistorValueBox : ValueBoxTransform.Sided() {
override fun getSouthLocation(): Vec3? {
return VecHelper.voxelSpace(8.0, 8.0, 16.0)
}
override fun rotate(level: LevelAccessor?, pos: BlockPos?, state: BlockState, ms: PoseStack?) {
super.rotate(level, pos, state, ms)
val axis = state.getValue(AbstractEncasedShaftBlock.AXIS)

if (axis === Direction.Axis.Y) return
if (side != Direction.UP) return //default rotation so ignore/return

val horizontalAngle = when (axis) {
Direction.Axis.X -> 90f
Direction.Axis.Z -> 0f
else -> return
}

TransformStack.of(ms)
.rotateZDegrees(-horizontalAngle + 180f)
}

override fun isSideActive(state: BlockState, direction: Direction): Boolean {
val axis = state.getValue(AbstractEncasedShaftBlock.AXIS)
return direction.getAxis() !== axis
}

}

override fun addToGoggleTooltip(tooltip: MutableList<Component>, isPlayerSneaking: Boolean): Boolean {
tooltip.add(
CreateLang.translateDirect(
Expand Down
3 changes: 3 additions & 0 deletions common/src/main/resources/assets/vs_clockwork/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,13 @@
"vs_clockwork.logistics.filter.click_to_set": "Click with an item to set.",

"vs_clockwork.contraptions.propeller.rotation_direction": "Rotation Direction",
"vs_clockwork.contraptions.resistor.resist_direction": "Resistor Resist Direction",
"contraptions.propeller.controller_wrong_way": "Blade Controller facing wrong way",
"contraptions.propeller.not_prop": "Not a propeller",
"propeller.rotation_direction.normal": "Normal",
"propeller.rotation_direction.inverted": "Reversed",
"resistor.resist_direction.none_to_max": "None To Max",
"resistor.resist_direction.max_to_none": "Max To None",

"vs_clockwork.gas_heater.heater_info": " Heater Info",
"vs_clockwork.gas_heater.heat_level": "Heat Level: %s",
Expand Down