Skip to content

Commit

Permalink
Merge pull request #30 from PssbleTrngle/feature/configurable-enchant…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
PssbleTrngle authored Oct 11, 2022
2 parents 0706be3 + c28204d commit c21071e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.possible_triangle.create_jetpack.client.ControlsDisplay
import com.possible_triangle.create_jetpack.client.JetpackArmorLayer
import com.possible_triangle.create_jetpack.compat.CuriosCompat
import com.possible_triangle.create_jetpack.config.Configs
import com.possible_triangle.create_jetpack.item.BronzeJetpack
import com.possible_triangle.create_jetpack.item.BrassJetpack
import com.possible_triangle.create_jetpack.network.ControlManager
import com.possible_triangle.create_jetpack.network.ModNetwork
import com.simibubi.create.AllTags.pickaxeOnly
Expand Down Expand Up @@ -123,8 +123,8 @@ object Content {
provider.withExistingParent(context.name, provider.mcLoc("item/barrier"))
}.register()

val JETPACK: ItemEntry<BronzeJetpack> =
REGISTRATE.item<BronzeJetpack>("jetpack") { BronzeJetpack(it, JETPACK_PLACEABLE) }
val JETPACK: ItemEntry<BrassJetpack> =
REGISTRATE.item<BrassJetpack>("jetpack") { BrassJetpack(it, JETPACK_PLACEABLE) }
.model(AssetLookup.customGenericItemModel("_", "item"))
.tag(PRESSURIZED_AIR_SOURCES)
.register()
Expand All @@ -137,7 +137,7 @@ object Content {

private fun attachCapabilities(stack: ItemStack, add: BiConsumer<ResourceLocation, ICapabilityProvider>) {
val item = stack.item
if (item is BronzeJetpack) add.accept(ResourceLocation(MOD_ID, "jetpack"), item)
if (item is BrassJetpack) add.accept(ResourceLocation(MOD_ID, "jetpack"), item)
}

fun register(modBus: IEventBus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.possible_triangle.create_jetpack.capability

import com.possible_triangle.create_jetpack.capability.JetpackLogic.FlyingPose
import com.possible_triangle.create_jetpack.capability.sources.ISource
import com.possible_triangle.create_jetpack.item.BronzeJetpack.ControlType
import com.possible_triangle.create_jetpack.capability.JetpackLogic.ControlType
import com.possible_triangle.create_jetpack.network.ControlManager
import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.level.Level
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import com.possible_triangle.create_jetpack.Content
import com.possible_triangle.create_jetpack.Content.JETPACK_CAPABILITY
import com.possible_triangle.create_jetpack.CreateJetpackMod
import com.possible_triangle.create_jetpack.capability.IJetpack.Context
import com.possible_triangle.create_jetpack.capability.JetpackLogic.ControlType.*
import com.possible_triangle.create_jetpack.capability.sources.EntitySource
import com.possible_triangle.create_jetpack.capability.sources.EquipmentSource
import com.possible_triangle.create_jetpack.capability.sources.ISource
import com.possible_triangle.create_jetpack.item.BronzeJetpack.ControlType
import com.possible_triangle.create_jetpack.item.BronzeJetpack.ControlType.*
import com.possible_triangle.create_jetpack.network.ControlManager.Key
import com.simibubi.create.content.contraptions.particle.AirParticleData
import net.minecraft.core.particles.ParticleTypes
Expand Down Expand Up @@ -239,4 +238,8 @@ object JetpackLogic {
}
}

enum class ControlType {
ALWAYS, NEVER, TOGGLE
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.possible_triangle.create_jetpack.CreateJetpackMod.MOD_ID
import com.possible_triangle.create_jetpack.capability.IJetpack
import com.possible_triangle.create_jetpack.capability.JetpackLogic
import com.possible_triangle.create_jetpack.config.Configs
import com.possible_triangle.create_jetpack.item.BronzeJetpack
import com.possible_triangle.create_jetpack.network.ControlManager.Key
import com.simibubi.create.content.curiosities.armor.BackTankUtil
import net.minecraft.client.Minecraft
Expand All @@ -32,7 +31,7 @@ object ControlsDisplay : IIngameOverlay {
)
}

private val ICONS = mapOf<Key, (IJetpack.Context) -> BronzeJetpack.ControlType>(
private val ICONS = mapOf<Key, (IJetpack.Context) -> JetpackLogic.ControlType>(
Key.TOGGLE_ACTIVE to { it.jetpack.activeType(it) },
Key.TOGGLE_HOVER to { it.jetpack.hoverType(it) },
)
Expand Down Expand Up @@ -63,7 +62,7 @@ object ControlsDisplay : IIngameOverlay {
val engineActive = Key.TOGGLE_ACTIVE.isPressed(player)

val renderedIcons = ICONS.filterKeys { it == Key.TOGGLE_ACTIVE || engineActive }
.filterValues { getType -> getType(context) == BronzeJetpack.ControlType.TOGGLE }
.filterValues { getType -> getType(context) == JetpackLogic.ControlType.TOGGLE }
.keys.mapIndexed { index, key ->
poseStack.pushPose()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.possible_triangle.create_jetpack.client
import com.mojang.blaze3d.vertex.PoseStack
import com.possible_triangle.create_jetpack.Content
import com.possible_triangle.create_jetpack.capability.JetpackLogic
import com.possible_triangle.create_jetpack.item.BronzeJetpack
import com.possible_triangle.create_jetpack.item.BrassJetpack
import com.simibubi.create.AllBlockPartials
import com.simibubi.create.content.curiosities.armor.CopperBacktankBlock
import com.simibubi.create.foundation.render.CachedBufferer
Expand Down Expand Up @@ -62,7 +62,7 @@ class JetpackArmorLayer<T : LivingEntity, M : EntityModel<T>>(private val render
if (entityModel !is HumanoidModel<*>) return

val context = JetpackLogic.getJetpack(entity) ?: return
if(context.jetpack !is BronzeJetpack) return
if(context.jetpack !is BrassJetpack) return

val renderedState =
Content.JETPACK_BLOCK.defaultState.setValue(CopperBacktankBlock.HORIZONTAL_FACING, Direction.SOUTH)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.possible_triangle.create_jetpack.config

import net.minecraft.core.Registry
import net.minecraft.resources.ResourceLocation
import net.minecraft.world.item.enchantment.Enchantment
import net.minecraftforge.common.ForgeConfigSpec

interface IServerConfig {
Expand All @@ -10,6 +13,7 @@ interface IServerConfig {
val acceleration: Double
val hoverSpeed: Double
val swimModifier: Double
fun isAllowed(ench: Enchantment): Boolean
}

data class SyncedConfig(
Expand All @@ -20,7 +24,9 @@ data class SyncedConfig(
override val acceleration: Double,
override val hoverSpeed: Double,
override val swimModifier: Double,
) : IServerConfig
) : IServerConfig {
override fun isAllowed(ench: Enchantment) = true
}

class ServerConfig(builder: ForgeConfigSpec.Builder) : IServerConfig {

Expand All @@ -46,4 +52,11 @@ class ServerConfig(builder: ForgeConfigSpec.Builder) : IServerConfig {
private val swimModifierValue = builder.defineInRange("speed.swim_modifier", 1.8, 0.0, 100.0)
override val swimModifier get() = swimModifierValue.get()!!

private val enchantmentsList = builder.defineList("enchantments.list", emptyList<String>()) { true }
private val enchantmentsIsBlacklist = builder.define("enchantments.is_blacklist", true)
override fun isAllowed(ench: Enchantment): Boolean {
val key = Registry.ENCHANTMENT.getKey(ench) ?: return true
val contained = enchantmentsList.get().map(::ResourceLocation).any { key == it }
return contained != enchantmentsIsBlacklist.get()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.possible_triangle.create_jetpack.item
import com.possible_triangle.create_jetpack.Content.JETPACK_CAPABILITY
import com.possible_triangle.create_jetpack.capability.IJetpack
import com.possible_triangle.create_jetpack.capability.IJetpack.Context
import com.possible_triangle.create_jetpack.capability.JetpackLogic
import com.possible_triangle.create_jetpack.capability.sources.CuriosSource
import com.possible_triangle.create_jetpack.capability.sources.EquipmentSource
import com.possible_triangle.create_jetpack.config.Configs
Expand All @@ -11,13 +12,15 @@ import com.simibubi.create.content.curiosities.armor.CopperBacktankItem
import com.tterrag.registrate.util.entry.ItemEntry
import net.minecraft.core.Direction
import net.minecraft.world.entity.EquipmentSlot
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Rarity
import net.minecraft.world.item.enchantment.Enchantment
import net.minecraft.world.phys.Vec3
import net.minecraftforge.common.capabilities.Capability
import net.minecraftforge.common.capabilities.ICapabilityProvider
import net.minecraftforge.common.util.LazyOptional

class BronzeJetpack(properties: Properties, blockItem: ItemEntry<CopperBacktankBlockItem>) :
class BrassJetpack(properties: Properties, blockItem: ItemEntry<CopperBacktankBlockItem>) :
CopperBacktankItem(properties.rarity(Rarity.RARE), blockItem), IJetpack, ICapabilityProvider {
private val capability = LazyOptional.of<IJetpack> { this }

Expand All @@ -29,12 +32,12 @@ class BronzeJetpack(properties: Properties, blockItem: ItemEntry<CopperBacktankB
return Configs.SERVER.verticalSpeed
}

override fun activeType(context: Context): ControlType {
return ControlType.TOGGLE
override fun activeType(context: Context): JetpackLogic.ControlType {
return JetpackLogic.ControlType.TOGGLE
}

override fun hoverType(context: Context): ControlType {
return ControlType.TOGGLE
override fun hoverType(context: Context): JetpackLogic.ControlType {
return JetpackLogic.ControlType.TOGGLE
}

override fun horizontalSpeed(context: Context): Double {
Expand Down Expand Up @@ -87,8 +90,8 @@ class BronzeJetpack(properties: Properties, blockItem: ItemEntry<CopperBacktankB
return LazyOptional.empty()
}

enum class ControlType {
ALWAYS, NEVER, TOGGLE
override fun canApplyAtEnchantingTable(stack: ItemStack, enchantment: Enchantment): Boolean {
return super.canApplyAtEnchantingTable(stack, enchantment) && Configs.SERVER.isAllowed(enchantment)
}

}

0 comments on commit c21071e

Please sign in to comment.