Skip to content

Commit

Permalink
configs & correct air usage
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle committed Aug 7, 2022
1 parent c6b9955 commit 02af8fb
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 27 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ minecraft {

arg '-mixin.config=create.mixins.json'
arg '-mixin.config=flywheel.mixins.json'
arg "-mixin.config=${project.mod_id}.mixins.json"
property 'mixin.env.remapRefMap', 'true'
property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"

Expand All @@ -70,6 +71,7 @@ minecraft {

arg '-mixin.config=create.mixins.json'
arg '-mixin.config=flywheel.mixins.json'
arg "-mixin.config=${project.mod_id}.mixins.json"
property 'mixin.env.remapRefMap', 'true'
property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"

Expand All @@ -87,6 +89,7 @@ minecraft {

arg '-mixin.config=create.mixins.json'
arg '-mixin.config=flywheel.mixins.json'
arg "-mixin.config=${project.mod_id}.mixins.json"
property 'mixin.env.remapRefMap', 'true'
property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"

Expand Down
27 changes: 10 additions & 17 deletions src/main/kotlin/com/possible_triangle/create_jetpack/Content.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.possible_triangle.create_jetpack.capability.IJetpack
import com.possible_triangle.create_jetpack.capability.JetpackLogic
import com.possible_triangle.create_jetpack.client.ControlsDisplay
import com.possible_triangle.create_jetpack.client.JetpackArmorLayer
import com.possible_triangle.create_jetpack.config.Configs
import com.possible_triangle.create_jetpack.item.Jetpack
import com.possible_triangle.create_jetpack.network.ControlManager
import com.possible_triangle.create_jetpack.network.ModNetwork
Expand All @@ -27,6 +28,7 @@ import com.simibubi.create.repack.registrate.util.nullness.NonNullFunction
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.RenderType
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider
import net.minecraft.core.Registry
import net.minecraft.resources.ResourceLocation
import net.minecraft.tags.TagKey
import net.minecraft.world.item.ItemStack
Expand All @@ -44,9 +46,12 @@ import net.minecraftforge.common.capabilities.CapabilityToken
import net.minecraftforge.common.capabilities.ICapabilityProvider
import net.minecraftforge.event.AttachCapabilitiesEvent
import net.minecraftforge.eventbus.api.IEventBus
import net.minecraftforge.fml.config.ModConfig
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent
import thedarkcolour.kotlinforforge.forge.FORGE_BUS
import thedarkcolour.kotlinforforge.forge.LOADING_CONTEXT
import thedarkcolour.kotlinforforge.forge.MOD_CONTEXT
import java.util.function.BiConsumer
import java.util.function.BiFunction
import java.util.function.Supplier
Expand All @@ -57,14 +62,7 @@ object Content {
.creativeModeTab { CreateItemGroup.TAB_TOOLS }
.startSection(AllSections.CURIOSITIES)

//private val ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MOD_ID)
//private val BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MOD_ID)
//private val TILES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, MOD_ID)
//private val EFFECTS = DeferredRegister.create(ForgeRegistries.POTIONS, MOD_ID)
//private val FLUIDS = DeferredRegister.create(ForgeRegistries.FLUIDS, MOD_ID)
//private val RECIPE_SERIALIZERS = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, MOD_ID)

val PRESSURIZED_AIR_SOURCES = TagKey.create(net.minecraft.core.Registry.ITEM_REGISTRY, Create.asResource("pressurized_air_sources"))
val PRESSURIZED_AIR_SOURCES = TagKey.create(Registry.ITEM_REGISTRY, Create.asResource("pressurized_air_sources"))

val JETPACK_BLOCK = REGISTRATE.block<JetpackBlock>("jetpack", ::JetpackBlock)
.initialProperties { SharedProperties.copperMetal() }
Expand Down Expand Up @@ -119,27 +117,22 @@ object Content {

val JETPACK_CAPABILITY = CapabilityManager.get(object : CapabilityToken<IJetpack>() {})

val THRUSTERS_MODEL = PartialModel(ResourceLocation(MOD_ID, "block/jetpack/thrusters"))

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

fun register(modBus: IEventBus) {
LOADING_CONTEXT.registerConfig(ModConfig.Type.COMMON, Configs.SERVER_SPEC)
LOADING_CONTEXT.registerConfig(ModConfig.Type.CLIENT, Configs.CLIENT_SPEC)

modBus.addListener { _: FMLCommonSetupEvent ->
// TODO check if neccessary
//CapabilityManager.INSTANCE.(IJetpack::class.java, JetpackStorage) { FakeJetpack }
ModNetwork.init()
}

modBus.addListener { _: FMLClientSetupEvent ->
ControlManager.registerKeybinds()
ControlsDisplay.register()

//InstancedRenderRegistry().register(Content.JETPACK_TILE, ::CopperBacktankInstance)
//ClientRegistry.bindTileEntityRenderer(Content.JETPACK_TILE, ::CopperBacktankRenderer)
//RenderTypeLookup.setRenderLayer(Content.JETPACK_BLOCK, RenderType.getCutoutMipped())
}

modBus.addListener { _: EntityRenderersEvent.AddLayers ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ interface IJetpack {

fun onUse(context: Context) {}

fun isHovering(context: Context): Boolean {
return JetpackLogic.active(hoverType(context), ControlManager.Key.TOGGLE_HOVER, context.entity)
}

fun isThrusting(context: Context): Boolean {
val entity = context.entity
if (JetpackLogic.active(hoverType(context), ControlManager.Key.TOGGLE_HOVER, entity)) return true
if (isHovering(context)) return true
return entity is Player && ControlManager.isPressed(entity, ControlManager.Key.UP)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.mojang.blaze3d.vertex.PoseStack
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.Jetpack
import com.possible_triangle.create_jetpack.network.ControlManager
import com.possible_triangle.create_jetpack.network.ControlManager.Key
Expand Down Expand Up @@ -42,6 +43,7 @@ object ControlsDisplay : IIngameOverlay {

override fun render(gui: ForgeIngameGui, poseStack: PoseStack, partialTick: Float, width: Int, height: Int) {
val mc = Minecraft.getInstance()
if(!Configs.CLIENT.SHOW_OVERLAY.get()) return
if (mc.options.hideGui) return
val player = mc.player ?: return
val (context, jetpack) = JetpackLogic.getJetpack(player) ?: return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.possible_triangle.create_jetpack.config

import net.minecraftforge.common.ForgeConfigSpec

class ClientConfig(builder: ForgeConfigSpec.Builder) {

val SHOW_OVERLAY = builder.define("overlay", true)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.possible_triangle.create_jetpack.config

import net.minecraftforge.common.ForgeConfigSpec

object Configs {

var SERVER_SPEC: ForgeConfigSpec
private set
var SERVER: ServerConfig
private set

var CLIENT_SPEC: ForgeConfigSpec
private set
var CLIENT: ClientConfig
private set

init {
with(ForgeConfigSpec.Builder().configure { ServerConfig(it) }) {
SERVER = left
SERVER_SPEC = right
}

with(ForgeConfigSpec.Builder().configure { ClientConfig(it) }) {
CLIENT = left
CLIENT_SPEC = right
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.possible_triangle.create_jetpack.config

import net.minecraftforge.common.ForgeConfigSpec

class ServerConfig(builder: ForgeConfigSpec.Builder) {

val USES_PER_TANK = builder.defineInRange("air.uses_per_tank", 2048, 1, Integer.MAX_VALUE)
val USES_PER_TANK_HOVER = builder.defineInRange("air.uses_per_tank_hover", 2048 * 10, 1, Integer.MAX_VALUE)

val HORIZONTAL_SPEED = builder.defineInRange("speed.horizontal", 0.02, 0.01, 100.0)
val VERTICAL_SPEED = builder.defineInRange("speed.vertical", 0.4, 0.01, 100.0)
val ACCELERATION = builder.defineInRange("speed.acceleration", 0.6, 0.01, 100.0)
val HOVER_SPEED = builder.defineInRange("speed.hover_descend", -0.03, -100.0, 0.0)

}
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.config.Configs
import com.simibubi.create.content.contraptions.particle.AirParticleData
import com.simibubi.create.content.curiosities.armor.BackTankUtil
import com.simibubi.create.content.curiosities.armor.CopperBacktankItem
Expand All @@ -15,17 +16,15 @@ import net.minecraftforge.common.capabilities.ICapabilityProvider
import net.minecraftforge.common.util.LazyOptional

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

override fun hoverSpeed(context: Context): Double {
return -0.03
return Configs.SERVER.HOVER_SPEED.get()
}

override fun verticalSpeed(context: Context): Double {
return 0.4
return Configs.SERVER.VERTICAL_SPEED.get()
}

override fun activeType(context: Context): ControlType {
Expand All @@ -37,15 +36,15 @@ class Jetpack(properties: Properties, blockItem: ItemEntry<CopperBacktankBlockIt
}

override fun horizontalSpeed(context: Context): Double {
return 0.02
return Configs.SERVER.HORIZONTAL_SPEED.get()
}

override fun acceleration(context: Context): Double {
return 0.6
return Configs.SERVER.ACCELERATION.get()
}

override fun onUse(context: Context) {
if(!isThrusting(context)) return
if (!isThrusting(context)) return
val yaw = (context.entity.yBodyRot / 180 * -Math.PI).toFloat()
listOf(-0.35, 0.35).forEach { offset ->
val pos = Vec3(offset, 0.7, -0.5).yRot(yaw)
Expand All @@ -59,10 +58,21 @@ class Jetpack(properties: Properties, blockItem: ItemEntry<CopperBacktankBlockIt
0.0
)
}

BackTankUtil.canAbsorbDamage(context.entity, usesPerTank(context))
}

private fun usesPerTank(context: Context): Int {
return if (isHovering(context)) Configs.SERVER.USES_PER_TANK_HOVER.get()
else Configs.SERVER.USES_PER_TANK.get()
}

override fun isUsable(context: Context): Boolean {
return BackTankUtil.canAbsorbDamage(context.entity, 10)
val tank = BackTankUtil.get(context.entity)
if (tank.isEmpty) return false
val air = BackTankUtil.getAir(tank)
val cost = BackTankUtil.maxAirWithoutEnchants() / usesPerTank(context)
return air >= cost
}

override fun <T : Any?> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"create_jetpack:jetpack"
]
}

0 comments on commit 02af8fb

Please sign in to comment.