From c28204d2e00905b7ba8e0d6c464ce6bff1f7dc66 Mon Sep 17 00:00:00 2001 From: PssbleTrngle Date: Tue, 11 Oct 2022 10:21:23 +0200 Subject: [PATCH] add enchantment white/blacklist --- .../possible_triangle/create_jetpack/Content.kt | 8 ++++---- .../create_jetpack/capability/IJetpack.kt | 2 +- .../create_jetpack/capability/JetpackLogic.kt | 7 +++++-- .../create_jetpack/client/ControlsDisplay.kt | 5 ++--- .../create_jetpack/client/JetpackArmorLayer.kt | 4 ++-- .../create_jetpack/config/ServerConfig.kt | 15 ++++++++++++++- .../item/{BronzeJetpack.kt => BrassJetpack.kt} | 17 ++++++++++------- 7 files changed, 38 insertions(+), 20 deletions(-) rename src/main/kotlin/com/possible_triangle/create_jetpack/item/{BronzeJetpack.kt => BrassJetpack.kt} (81%) diff --git a/src/main/kotlin/com/possible_triangle/create_jetpack/Content.kt b/src/main/kotlin/com/possible_triangle/create_jetpack/Content.kt index 5e8849b..d317435 100644 --- a/src/main/kotlin/com/possible_triangle/create_jetpack/Content.kt +++ b/src/main/kotlin/com/possible_triangle/create_jetpack/Content.kt @@ -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 @@ -123,8 +123,8 @@ object Content { provider.withExistingParent(context.name, provider.mcLoc("item/barrier")) }.register() - val JETPACK: ItemEntry = - REGISTRATE.item("jetpack") { BronzeJetpack(it, JETPACK_PLACEABLE) } + val JETPACK: ItemEntry = + REGISTRATE.item("jetpack") { BrassJetpack(it, JETPACK_PLACEABLE) } .model(AssetLookup.customGenericItemModel("_", "item")) .tag(PRESSURIZED_AIR_SOURCES) .register() @@ -137,7 +137,7 @@ object Content { private fun attachCapabilities(stack: ItemStack, add: BiConsumer) { 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) { diff --git a/src/main/kotlin/com/possible_triangle/create_jetpack/capability/IJetpack.kt b/src/main/kotlin/com/possible_triangle/create_jetpack/capability/IJetpack.kt index d059276..a0a831f 100644 --- a/src/main/kotlin/com/possible_triangle/create_jetpack/capability/IJetpack.kt +++ b/src/main/kotlin/com/possible_triangle/create_jetpack/capability/IJetpack.kt @@ -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 diff --git a/src/main/kotlin/com/possible_triangle/create_jetpack/capability/JetpackLogic.kt b/src/main/kotlin/com/possible_triangle/create_jetpack/capability/JetpackLogic.kt index 1ea4c3f..3b1bd16 100644 --- a/src/main/kotlin/com/possible_triangle/create_jetpack/capability/JetpackLogic.kt +++ b/src/main/kotlin/com/possible_triangle/create_jetpack/capability/JetpackLogic.kt @@ -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 @@ -239,4 +238,8 @@ object JetpackLogic { } } + enum class ControlType { + ALWAYS, NEVER, TOGGLE + } + } \ No newline at end of file diff --git a/src/main/kotlin/com/possible_triangle/create_jetpack/client/ControlsDisplay.kt b/src/main/kotlin/com/possible_triangle/create_jetpack/client/ControlsDisplay.kt index ac36cac..07a32ed 100644 --- a/src/main/kotlin/com/possible_triangle/create_jetpack/client/ControlsDisplay.kt +++ b/src/main/kotlin/com/possible_triangle/create_jetpack/client/ControlsDisplay.kt @@ -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 @@ -32,7 +31,7 @@ object ControlsDisplay : IIngameOverlay { ) } - private val ICONS = mapOf BronzeJetpack.ControlType>( + private val ICONS = mapOf JetpackLogic.ControlType>( Key.TOGGLE_ACTIVE to { it.jetpack.activeType(it) }, Key.TOGGLE_HOVER to { it.jetpack.hoverType(it) }, ) @@ -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() diff --git a/src/main/kotlin/com/possible_triangle/create_jetpack/client/JetpackArmorLayer.kt b/src/main/kotlin/com/possible_triangle/create_jetpack/client/JetpackArmorLayer.kt index 225d281..928163b 100644 --- a/src/main/kotlin/com/possible_triangle/create_jetpack/client/JetpackArmorLayer.kt +++ b/src/main/kotlin/com/possible_triangle/create_jetpack/client/JetpackArmorLayer.kt @@ -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 @@ -62,7 +62,7 @@ class JetpackArmorLayer>(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) diff --git a/src/main/kotlin/com/possible_triangle/create_jetpack/config/ServerConfig.kt b/src/main/kotlin/com/possible_triangle/create_jetpack/config/ServerConfig.kt index aa33787..aa66216 100644 --- a/src/main/kotlin/com/possible_triangle/create_jetpack/config/ServerConfig.kt +++ b/src/main/kotlin/com/possible_triangle/create_jetpack/config/ServerConfig.kt @@ -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 { @@ -10,6 +13,7 @@ interface IServerConfig { val acceleration: Double val hoverSpeed: Double val swimModifier: Double + fun isAllowed(ench: Enchantment): Boolean } data class SyncedConfig( @@ -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 { @@ -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()) { 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() + } } \ No newline at end of file diff --git a/src/main/kotlin/com/possible_triangle/create_jetpack/item/BronzeJetpack.kt b/src/main/kotlin/com/possible_triangle/create_jetpack/item/BrassJetpack.kt similarity index 81% rename from src/main/kotlin/com/possible_triangle/create_jetpack/item/BronzeJetpack.kt rename to src/main/kotlin/com/possible_triangle/create_jetpack/item/BrassJetpack.kt index d7bbc00..7284874 100644 --- a/src/main/kotlin/com/possible_triangle/create_jetpack/item/BronzeJetpack.kt +++ b/src/main/kotlin/com/possible_triangle/create_jetpack/item/BrassJetpack.kt @@ -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 @@ -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) : +class BrassJetpack(properties: Properties, blockItem: ItemEntry) : CopperBacktankItem(properties.rarity(Rarity.RARE), blockItem), IJetpack, ICapabilityProvider { private val capability = LazyOptional.of { this } @@ -29,12 +32,12 @@ class BronzeJetpack(properties: Properties, blockItem: ItemEntry