Switching battery mode by right clicking while holding shift
This commit is contained in:
parent
805e760c52
commit
082f1478f5
@ -867,6 +867,7 @@ private fun androidFeatures(provider: MatteryLanguageProvider) {
|
|||||||
|
|
||||||
private fun gui(provider: MatteryLanguageProvider) {
|
private fun gui(provider: MatteryLanguageProvider) {
|
||||||
with(provider.english) {
|
with(provider.english) {
|
||||||
|
gui("flow_direction_set", "Flow direction set to %s")
|
||||||
gui("tick_timer_set", "Timer set to %s ticks")
|
gui("tick_timer_set", "Timer set to %s ticks")
|
||||||
|
|
||||||
gui("black_hole_generator.help0", "Generates energy using angular momentum of Singularities")
|
gui("black_hole_generator.help0", "Generates energy using angular momentum of Singularities")
|
||||||
|
@ -868,6 +868,7 @@ private fun androidFeatures(provider: MatteryLanguageProvider) {
|
|||||||
|
|
||||||
private fun gui(provider: MatteryLanguageProvider) {
|
private fun gui(provider: MatteryLanguageProvider) {
|
||||||
with(provider.russian) {
|
with(provider.russian) {
|
||||||
|
gui("flow_direction_set", "Направление потока установлено на %s")
|
||||||
gui("tick_timer_set", "Таймер установлен на %s тиков")
|
gui("tick_timer_set", "Таймер установлен на %s тиков")
|
||||||
|
|
||||||
gui("black_hole_generator.help0", "Генерирует электричество используя угловое ускорение сингулярностей")
|
gui("black_hole_generator.help0", "Генерирует электричество используя угловое ускорение сингулярностей")
|
||||||
|
@ -2,7 +2,11 @@ package ru.dbotthepony.mc.otm.capability
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableSet
|
import com.google.common.collect.ImmutableSet
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
|
import net.minecraft.network.chat.MutableComponent
|
||||||
|
import net.minecraft.util.StringRepresentable
|
||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
|
import java.util.Collections
|
||||||
|
import java.util.EnumSet
|
||||||
import java.util.function.Predicate
|
import java.util.function.Predicate
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +27,7 @@ import java.util.function.Predicate
|
|||||||
* * `BI_DIRECTIONAL.test(OUTPUT)` = `false`
|
* * `BI_DIRECTIONAL.test(OUTPUT)` = `false`
|
||||||
* * `BI_DIRECTIONAL.test(INPUT)` = `false`
|
* * `BI_DIRECTIONAL.test(INPUT)` = `false`
|
||||||
*/
|
*/
|
||||||
enum class FlowDirection(val input: Boolean, val output: Boolean, val translationKey: String) : Predicate<FlowDirection> {
|
enum class FlowDirection(val input: Boolean, val output: Boolean, val translationKey: String) : Predicate<FlowDirection>, StringRepresentable {
|
||||||
/**
|
/**
|
||||||
* Can only be inputted (consumer)
|
* Can only be inputted (consumer)
|
||||||
*/
|
*/
|
||||||
@ -64,9 +68,15 @@ enum class FlowDirection(val input: Boolean, val output: Boolean, val translatio
|
|||||||
}.build()
|
}.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
val title: Component
|
val title: MutableComponent
|
||||||
get() = TranslatableComponent(translationKey)
|
get() = TranslatableComponent(translationKey)
|
||||||
|
|
||||||
|
private val serializedName = name.lowercase()
|
||||||
|
|
||||||
|
override fun getSerializedName(): String {
|
||||||
|
return serializedName
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subtype test (returns true if we can assign [t] to this, for example if we can assign [BI_DIRECTIONAL] to [INPUT])
|
* Subtype test (returns true if we can assign [t] to this, for example if we can assign [BI_DIRECTIONAL] to [INPUT])
|
||||||
*/
|
*/
|
||||||
@ -106,7 +116,7 @@ enum class FlowDirection(val input: Boolean, val output: Boolean, val translatio
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField
|
@JvmField
|
||||||
val WITHOUT_NONE: ImmutableSet<FlowDirection> = ImmutableSet.of(INPUT, OUTPUT, BI_DIRECTIONAL)
|
val WITHOUT_NONE: Set<FlowDirection> = Collections.unmodifiableSet(EnumSet.of(INPUT, OUTPUT, BI_DIRECTIONAL))
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun of(input: Boolean, output: Boolean): FlowDirection {
|
fun of(input: Boolean, output: Boolean): FlowDirection {
|
||||||
|
@ -93,6 +93,18 @@ open class EnergyCapacitorItem(
|
|||||||
maxBatteryLevel: Decimal,
|
maxBatteryLevel: Decimal,
|
||||||
maxInput: Decimal? = null,
|
maxInput: Decimal? = null,
|
||||||
maxOutput: Decimal? = maxInput,
|
maxOutput: Decimal? = maxInput,
|
||||||
initialBatteryLevel: Decimal = Decimal.ZERO
|
override val initialBatteryLevel: Decimal = Decimal.ZERO
|
||||||
) : SimpleEnergyItem(FlowDirection.BI_DIRECTIONAL, stack, maxBatteryLevel, maxInput, maxOutput, initialBatteryLevel)
|
) : ItemEnergyStorageImpl(stack) {
|
||||||
|
override val energyFlow: FlowDirection
|
||||||
|
get() = itemStack[MDataComponentTypes.FLOW_DIRECTION] ?: FlowDirection.BI_DIRECTIONAL
|
||||||
|
|
||||||
|
override var maxInput: Decimal? = maxInput
|
||||||
|
protected set
|
||||||
|
|
||||||
|
override var maxOutput: Decimal? = maxOutput
|
||||||
|
protected set
|
||||||
|
|
||||||
|
override var maxBatteryLevel: Decimal = maxBatteryLevel
|
||||||
|
protected set
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
package ru.dbotthepony.mc.otm.core
|
package ru.dbotthepony.mc.otm.core
|
||||||
|
|
||||||
|
import net.minecraft.sounds.SoundEvents
|
||||||
|
import net.minecraft.sounds.SoundSource
|
||||||
import net.minecraft.world.entity.Entity
|
import net.minecraft.world.entity.Entity
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
import net.minecraft.world.phys.AABB
|
import net.minecraft.world.phys.AABB
|
||||||
import ru.dbotthepony.mc.otm.core.math.Vector
|
import ru.dbotthepony.mc.otm.core.math.Vector
|
||||||
|
import ru.dbotthepony.mc.otm.core.math.component1
|
||||||
|
import ru.dbotthepony.mc.otm.core.math.component2
|
||||||
|
import ru.dbotthepony.mc.otm.core.math.component3
|
||||||
import ru.dbotthepony.mc.otm.core.math.minus
|
import ru.dbotthepony.mc.otm.core.math.minus
|
||||||
|
import ru.dbotthepony.mc.otm.core.math.plus
|
||||||
import java.util.LinkedList
|
import java.util.LinkedList
|
||||||
import java.util.function.Predicate
|
import java.util.function.Predicate
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
@ -120,3 +127,8 @@ fun Level.getEntitiesInSphere(pos: Vector, radius: Double, predicate: Predicate<
|
|||||||
fun <T : Entity> Level.getEntitiesInSphere(type: Class<out T>, pos: Vector, radius: Double, predicate: Predicate<in Entity>): MutableList<EntityDistance<T>> {
|
fun <T : Entity> Level.getEntitiesInSphere(type: Class<out T>, pos: Vector, radius: Double, predicate: Predicate<in Entity>): MutableList<EntityDistance<T>> {
|
||||||
return getEntitiesInEllipsoid(type, pos, Vector(radius, radius, radius), predicate)
|
return getEntitiesInEllipsoid(type, pos, Vector(radius, radius, radius), predicate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Level.playClickSound(player: Player) {
|
||||||
|
val (x, y, z) = player.getEyePosition(1f) + player.getViewVector(1f)
|
||||||
|
playSound(player, x, y, z, SoundEvents.DISPENSER_FAIL, SoundSource.PLAYERS, 0.1f, 1.1f)
|
||||||
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package ru.dbotthepony.mc.otm.item
|
package ru.dbotthepony.mc.otm.item
|
||||||
|
|
||||||
import net.minecraft.ChatFormatting
|
import net.minecraft.ChatFormatting
|
||||||
import net.minecraft.nbt.CompoundTag
|
|
||||||
import net.minecraft.network.chat.Component
|
|
||||||
import net.minecraft.server.level.ServerPlayer
|
import net.minecraft.server.level.ServerPlayer
|
||||||
|
import net.minecraft.sounds.SoundEvents
|
||||||
|
import net.minecraft.sounds.SoundSource
|
||||||
import net.minecraft.world.InteractionHand
|
import net.minecraft.world.InteractionHand
|
||||||
import net.minecraft.world.InteractionResultHolder
|
import net.minecraft.world.InteractionResultHolder
|
||||||
import net.minecraft.world.effect.MobEffectInstance
|
import net.minecraft.world.effect.MobEffectInstance
|
||||||
@ -23,8 +23,13 @@ import ru.dbotthepony.mc.otm.client.minecraft
|
|||||||
import ru.dbotthepony.mc.otm.config.ItemsConfig
|
import ru.dbotthepony.mc.otm.config.ItemsConfig
|
||||||
import ru.dbotthepony.mc.otm.core.*
|
import ru.dbotthepony.mc.otm.core.*
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
|
import ru.dbotthepony.mc.otm.core.math.component1
|
||||||
|
import ru.dbotthepony.mc.otm.core.math.component2
|
||||||
|
import ru.dbotthepony.mc.otm.core.math.component3
|
||||||
|
import ru.dbotthepony.mc.otm.core.math.plus
|
||||||
import ru.dbotthepony.mc.otm.registry.CapabilitiesRegisterListener
|
import ru.dbotthepony.mc.otm.registry.CapabilitiesRegisterListener
|
||||||
import ru.dbotthepony.mc.otm.registry.MDamageTypes
|
import ru.dbotthepony.mc.otm.registry.MDamageTypes
|
||||||
|
import ru.dbotthepony.mc.otm.registry.MDataComponentTypes
|
||||||
import ru.dbotthepony.mc.otm.registry.MatteryDamageSource
|
import ru.dbotthepony.mc.otm.registry.MatteryDamageSource
|
||||||
import ru.dbotthepony.mc.otm.runIfClient
|
import ru.dbotthepony.mc.otm.runIfClient
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
@ -103,8 +108,39 @@ open class BatteryItem : MatteryItem, CapabilitiesRegisterListener {
|
|||||||
return p_150901_.matteryEnergy?.getBarColor() ?: super.getBarColor(p_150901_)
|
return p_150901_.matteryEnergy?.getBarColor() ?: super.getBarColor(p_150901_)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun use(level: Level, player: Player, hand: InteractionHand): InteractionResultHolder<ItemStack> {
|
||||||
|
if (player.isShiftKeyDown) {
|
||||||
|
val item = player.getItemInHand(hand)
|
||||||
|
level.playClickSound(player)
|
||||||
|
|
||||||
|
if (level.isClientSide) {
|
||||||
|
return InteractionResultHolder.success(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
val current = item[MDataComponentTypes.FLOW_DIRECTION] ?: FlowDirection.BI_DIRECTIONAL
|
||||||
|
val next = when (current) {
|
||||||
|
FlowDirection.INPUT -> FlowDirection.OUTPUT
|
||||||
|
FlowDirection.OUTPUT -> FlowDirection.BI_DIRECTIONAL
|
||||||
|
FlowDirection.BI_DIRECTIONAL, FlowDirection.NONE -> FlowDirection.INPUT
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendSystemMessage(TranslatableComponent("otm.gui.flow_direction_set", next.title))
|
||||||
|
item[MDataComponentTypes.FLOW_DIRECTION] = next
|
||||||
|
return InteractionResultHolder.consume(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.use(level, player, hand)
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
tooltips.itemEnergy()
|
tooltips.itemEnergy()
|
||||||
|
|
||||||
|
tooltips.addNormal(TooltipList.TooltipProvider { itemStack, context, acceptor ->
|
||||||
|
when (val f = itemStack[MDataComponentTypes.FLOW_DIRECTION] ?: FlowDirection.BI_DIRECTIONAL) {
|
||||||
|
FlowDirection.INPUT, FlowDirection.OUTPUT -> acceptor(TranslatableComponent("otm.gui.flow_direction_set", f.title).withStyle(ChatFormatting.GRAY))
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun capFor(stack: ItemStack): EnergyCapacitorItem {
|
private fun capFor(stack: ItemStack): EnergyCapacitorItem {
|
||||||
|
@ -7,9 +7,11 @@ import net.minecraft.core.component.DataComponentType
|
|||||||
import net.minecraft.core.registries.BuiltInRegistries
|
import net.minecraft.core.registries.BuiltInRegistries
|
||||||
import net.minecraft.network.RegistryFriendlyByteBuf
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
import net.minecraft.network.codec.StreamCodec
|
import net.minecraft.network.codec.StreamCodec
|
||||||
|
import net.minecraft.util.StringRepresentable
|
||||||
import net.neoforged.bus.api.IEventBus
|
import net.neoforged.bus.api.IEventBus
|
||||||
import net.neoforged.neoforge.fluids.FluidStack
|
import net.neoforged.neoforge.fluids.FluidStack
|
||||||
import net.neoforged.neoforge.fluids.SimpleFluidContent
|
import net.neoforged.neoforge.fluids.SimpleFluidContent
|
||||||
|
import ru.dbotthepony.mc.otm.capability.FlowDirection
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.PatternState
|
import ru.dbotthepony.mc.otm.capability.matter.PatternState
|
||||||
import ru.dbotthepony.mc.otm.container.ItemFilter
|
import ru.dbotthepony.mc.otm.container.ItemFilter
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
@ -46,6 +48,8 @@ object MDataComponentTypes {
|
|||||||
|
|
||||||
private fun uuid() = DataComponentType.builder<UUID>().persistent(UUIDUtil.CODEC).networkSynchronized(UUIDUtil.STREAM_CODEC).build()
|
private fun uuid() = DataComponentType.builder<UUID>().persistent(UUIDUtil.CODEC).networkSynchronized(UUIDUtil.STREAM_CODEC).build()
|
||||||
|
|
||||||
|
val FLOW_DIRECTION: DataComponentType<FlowDirection> by registry.register("flow_direction") { DataComponentType.builder<FlowDirection>().persistent(StringRepresentable.fromEnum(FlowDirection::values)).build() }
|
||||||
|
|
||||||
val BATTERY_LEVEL: DataComponentType<Decimal> by registry.register("battery_level") { DecimalComponent() }
|
val BATTERY_LEVEL: DataComponentType<Decimal> by registry.register("battery_level") { DecimalComponent() }
|
||||||
val MAX_BATTERY_LEVEL: DataComponentType<Decimal> by registry.register("max_battery_level") { DecimalComponent() }
|
val MAX_BATTERY_LEVEL: DataComponentType<Decimal> by registry.register("max_battery_level") { DecimalComponent() }
|
||||||
val MAX_BATTERY_INPUT: DataComponentType<Decimal> by registry.register("max_battery_input") { DecimalComponent() }
|
val MAX_BATTERY_INPUT: DataComponentType<Decimal> by registry.register("max_battery_input") { DecimalComponent() }
|
||||||
|
Loading…
Reference in New Issue
Block a user