generated from HGLabor/fabric-sub-projects-kotlin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Spiderman hero #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
FabiPunktExe
wants to merge
9
commits into
HGLabor:dev/1.21.4
Choose a base branch
from
FabiPunktExe:dev/spiderman-hero
base: dev/1.21.4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5fd1b9c
Spiderman project setup
FabiPunktExe 4e17e03
feat: add web swing ability
FabiPunktExe 5721b8b
fix: disable swing web pickup
FabiPunktExe 21280cd
feat: swing web rendering
FabiPunktExe c1a7fb0
refactor: rename WebShootAbility to SwingAbility
FabiPunktExe 8076f00
feat: add throw webs ability
FabiPunktExe 13e7edd
feat: wall climb ability
FabiPunktExe 9591d33
feat: cobweb climb ability
FabiPunktExe 99eb701
feat: better falling cobweb implementation
FabiPunktExe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| version = "1.0.0" | ||
|
|
||
| dependencies { | ||
| implementation(project(":hero-api", configuration = "namedElements")) | ||
| implementation(project(":datatracker", configuration = "namedElements")) | ||
|
|
||
| modApi(libs.bundles.fabric) | ||
| modApi(libs.bundles.silk) | ||
| modApi(libs.bundles.performance) | ||
| modApi(libs.owolib) | ||
| modApi(libs.geckolib) | ||
| modApi(libs.emoteLib) | ||
| } | ||
|
|
||
| loom { | ||
| accessWidenerPath.set(file("src/main/resources/spiderman.accesswidener")) | ||
| } | ||
|
|
23 changes: 23 additions & 0 deletions
23
spiderman/src/main/java/gg/norisk/heroes/spiderman/mixin/CobwebBlockMixin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package gg.norisk.heroes.spiderman.mixin; | ||
|
|
||
| import gg.norisk.heroes.spiderman.ability.CobwebClimbAbilityKt; | ||
| import net.minecraft.block.BlockState; | ||
| import net.minecraft.block.CobwebBlock; | ||
| import net.minecraft.entity.Entity; | ||
| import net.minecraft.entity.player.PlayerEntity; | ||
| import net.minecraft.util.math.BlockPos; | ||
| import net.minecraft.world.World; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.injection.At; | ||
| import org.spongepowered.asm.mixin.injection.Inject; | ||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
|
||
| @Mixin(CobwebBlock.class) | ||
| public class CobwebBlockMixin { | ||
| @Inject(method = "onEntityCollision", at = @At("HEAD"), cancellable = true) | ||
| public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity, CallbackInfo ci) { | ||
| if (entity instanceof PlayerEntity player) { | ||
| CobwebClimbAbilityKt.handleCobwebCollision(player, ci); | ||
| } | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
spiderman/src/main/java/gg/norisk/heroes/spiderman/mixin/PlayerEntityMixin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package gg.norisk.heroes.spiderman.mixin; | ||
|
|
||
| import gg.norisk.heroes.spiderman.ability.CobwebClimbAbilityKt; | ||
| import gg.norisk.heroes.spiderman.ability.WallClimbAbilityKt; | ||
| import net.minecraft.entity.player.PlayerEntity; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.injection.At; | ||
| import org.spongepowered.asm.mixin.injection.Inject; | ||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
|
||
| @Mixin(PlayerEntity.class) | ||
| public class PlayerEntityMixin { | ||
| @Inject(method = "isClimbing", at = @At("RETURN"), cancellable = true) | ||
| private void isClimbing(CallbackInfoReturnable<Boolean> cir) { | ||
| PlayerEntity self = (PlayerEntity) (Object) this; | ||
| WallClimbAbilityKt.handleWallClimbCheck(self, cir); | ||
| CobwebClimbAbilityKt.handleCobwebClimbCheck(self, cir); | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
spiderman/src/main/kotlin/gg/norisk/heroes/spiderman/SpidermanManager.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package gg.norisk.heroes.spiderman | ||
|
|
||
| import gg.norisk.heroes.common.hero.Hero | ||
| import gg.norisk.heroes.common.hero.HeroManager.registerHero | ||
| import gg.norisk.heroes.spiderman.ability.SwingAbility | ||
| import gg.norisk.heroes.spiderman.ability.ThrowWebsAbility | ||
| import gg.norisk.heroes.spiderman.registry.EntityRegistry | ||
| import gg.norisk.heroes.spiderman.registry.EntityRendererRegistry | ||
| import net.fabricmc.api.ClientModInitializer | ||
| import net.fabricmc.api.DedicatedServerModInitializer | ||
| import net.fabricmc.api.ModInitializer | ||
| import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents | ||
| import net.minecraft.util.Identifier | ||
| import org.apache.logging.log4j.LogManager | ||
| import java.awt.Color | ||
|
|
||
| object SpidermanManager : ModInitializer, ClientModInitializer, DedicatedServerModInitializer { | ||
| private const val MOD_ID = "spiderman" | ||
| val logger = LogManager.getLogger(MOD_ID) | ||
| fun String.toId() = Identifier.of(MOD_ID, this) | ||
|
|
||
| override fun onInitialize() { | ||
| logger.info("Starting $MOD_ID Hero...") | ||
| EntityRegistry.init() | ||
| } | ||
|
|
||
| override fun onInitializeClient() { | ||
| ClientLifecycleEvents.CLIENT_STARTED.register { | ||
| registerHero(Spiderman) | ||
| } | ||
| EntityRendererRegistry.init() | ||
| } | ||
|
|
||
| override fun onInitializeServer() { | ||
| registerHero(Spiderman) | ||
| } | ||
|
|
||
| val Spiderman by Hero("Spiderman") { | ||
| color = Color.RED.rgb | ||
| ability(SwingAbility) | ||
| ability(ThrowWebsAbility) | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
spiderman/src/main/kotlin/gg/norisk/heroes/spiderman/ability/CobwebClimbAbility.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package gg.norisk.heroes.spiderman.ability | ||
|
|
||
| import gg.norisk.heroes.common.hero.getHero | ||
| import gg.norisk.heroes.spiderman.SpidermanManager | ||
| import net.minecraft.block.Blocks | ||
| import net.minecraft.entity.player.PlayerEntity | ||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfo | ||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable | ||
|
|
||
| fun handleCobwebCollision(player: PlayerEntity, ci: CallbackInfo) { | ||
| if (player.getHero() == SpidermanManager.Spiderman && !player.isSpectator) { | ||
| ci.cancel() | ||
| } | ||
| } | ||
|
|
||
| fun handleCobwebClimbCheck(player: PlayerEntity, cir: CallbackInfoReturnable<Boolean>) { | ||
| if (player.getHero() == SpidermanManager.Spiderman && !player.isSpectator && player.blockStateAtPos.block == Blocks.COBWEB) { | ||
| cir.returnValue = true | ||
| } | ||
| } | ||
71 changes: 71 additions & 0 deletions
71
spiderman/src/main/kotlin/gg/norisk/heroes/spiderman/ability/SwingAbility.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package gg.norisk.heroes.spiderman.ability | ||
|
|
||
| import gg.norisk.heroes.client.option.HeroKeyBindings | ||
| import gg.norisk.heroes.common.HeroesManager.client | ||
| import gg.norisk.heroes.common.ability.NumberProperty | ||
| import gg.norisk.heroes.common.ability.operation.AddValueTotal | ||
| import gg.norisk.heroes.common.hero.ability.AbilityScope | ||
| import gg.norisk.heroes.common.hero.ability.implementation.PressAbility | ||
| import gg.norisk.heroes.spiderman.entity.SwingWebEntity | ||
| import gg.norisk.heroes.spiderman.registry.EntityRegistry | ||
| import io.wispforest.owo.ui.component.Components | ||
| import io.wispforest.owo.ui.core.Component | ||
| import net.minecraft.entity.player.PlayerEntity | ||
| import net.minecraft.item.Items | ||
| import net.minecraft.server.world.ServerWorld | ||
| import net.minecraft.util.Identifier | ||
| import net.minecraft.util.TypeFilter | ||
| import net.silkmc.silk.core.annotations.ExperimentalSilkApi | ||
| import net.silkmc.silk.core.entity.directionVector | ||
| import net.silkmc.silk.core.item.itemStack | ||
|
|
||
| val ropeLength = NumberProperty(50.0, 3, "Rope length", AddValueTotal(5.0, 10.0, 15.0, 20.0), 10).apply { | ||
| icon = { | ||
| Components.item(Items.FIREWORK_ROCKET.defaultStack) | ||
| } | ||
| } | ||
|
|
||
| val webShootPower = NumberProperty(1.0, 3, "Web shoot power", AddValueTotal(1.4, 1.9, 2.5), 20).apply { | ||
| icon = { | ||
| Components.item(Items.FIREWORK_ROCKET.defaultStack) | ||
| } | ||
| } | ||
|
|
||
| @OptIn(ExperimentalSilkApi::class) | ||
| object SwingAbility : PressAbility("Swing") { | ||
| init { | ||
| client { | ||
| keyBind = HeroKeyBindings.firstKeyBind | ||
| } | ||
| properties = listOf(ropeLength, webShootPower) | ||
| cooldownProperty = buildCooldown(60.0, 5, AddValueTotal(-10.0, -5.0, -5.0, -5.0, -10.0)) | ||
| } | ||
|
|
||
| override fun getIconComponent(): Component { | ||
| return Components.item(itemStack(Items.STRING) {}) | ||
| } | ||
|
|
||
| override fun getBackgroundTexture(): Identifier { | ||
| return Identifier.of("textures/block/packed_mud.png") | ||
| } | ||
|
|
||
| override fun onStart(player: PlayerEntity, abilityScope: AbilityScope) { | ||
| if (player.world is ServerWorld) { | ||
| val web = SwingWebEntity(EntityRegistry.SWING_WEB, player.world) | ||
| web.setPosition(player.eyePos) | ||
| web.owner = player | ||
| web.velocity = player.directionVector.multiply(webShootPower.getValue(player.uuid)) | ||
| web.ropeLength = ropeLength.getValue(player.uuid) | ||
| player.world.spawnEntity(web) | ||
| } | ||
| } | ||
|
|
||
| override fun onDisable(player: PlayerEntity) { | ||
| val world = player.world as ServerWorld | ||
| for (entity in world.getEntitiesByType(TypeFilter.instanceOf(SwingWebEntity::class.java)) { true }) { | ||
| if (entity.owner == player) { | ||
| entity.discard() | ||
| } | ||
| } | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
spiderman/src/main/kotlin/gg/norisk/heroes/spiderman/ability/ThrowWebsAbility.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package gg.norisk.heroes.spiderman.ability | ||
|
|
||
| import gg.norisk.heroes.client.option.HeroKeyBindings | ||
| import gg.norisk.heroes.common.HeroesManager.client | ||
| import gg.norisk.heroes.common.ability.NumberProperty | ||
| import gg.norisk.heroes.common.ability.operation.AddValueTotal | ||
| import gg.norisk.heroes.common.hero.ability.AbilityScope | ||
| import gg.norisk.heroes.common.hero.ability.implementation.PressAbility | ||
| import gg.norisk.heroes.spiderman.entity.FallingCobwebEntity | ||
| import io.wispforest.owo.ui.component.Components | ||
| import io.wispforest.owo.ui.core.Component | ||
| import net.minecraft.entity.player.PlayerEntity | ||
| import net.minecraft.item.Items | ||
| import net.minecraft.server.world.ServerWorld | ||
| import net.minecraft.util.Identifier | ||
| import net.silkmc.silk.core.annotations.ExperimentalSilkApi | ||
| import net.silkmc.silk.core.entity.directionVector | ||
| import net.silkmc.silk.core.item.itemStack | ||
|
|
||
| val webAmount = NumberProperty(1.0, 4, "Web amount", AddValueTotal(1.0, 1.0, 2.0, 2.0)).apply { | ||
| icon = { | ||
| Components.item(Items.COBWEB.defaultStack) | ||
| } | ||
| } | ||
|
|
||
| @OptIn(ExperimentalSilkApi::class) | ||
| object ThrowWebsAbility : PressAbility("Throw webs") { | ||
| init { | ||
| client { | ||
| keyBind = HeroKeyBindings.secondKeyBind | ||
| } | ||
| properties = listOf(webAmount) | ||
| cooldownProperty = buildCooldown(90.0, 5, AddValueTotal(-9.0, -9.0, -9.0, -9.0, -9.0)) | ||
| } | ||
|
|
||
| override fun getIconComponent(): Component { | ||
| return Components.item(itemStack(Items.COBWEB) {}) | ||
| } | ||
|
|
||
| override fun getBackgroundTexture(): Identifier { | ||
| return Identifier.of("textures/block/packed_mud.png") | ||
| } | ||
|
|
||
| override fun onStart(player: PlayerEntity, abilityScope: AbilityScope) { | ||
| if (player.world is ServerWorld) { | ||
| repeat(webAmount.getValue(player.uuid).toInt()) { | ||
| val web = FallingCobwebEntity(player) | ||
| web.velocity = player.directionVector.multiply(0.6).addRandom(player.world.random, 0.3f) | ||
| player.world.spawnEntity(web) | ||
| } | ||
| } | ||
|
Comment on lines
+45
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use early returns, they help with code readablity and maintainability if (player.world !is ServerWorld) {
return
}
// Continue with your code |
||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
spiderman/src/main/kotlin/gg/norisk/heroes/spiderman/ability/WallClimbAbility.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package gg.norisk.heroes.spiderman.ability | ||
|
|
||
| import gg.norisk.heroes.common.hero.getHero | ||
| import gg.norisk.heroes.spiderman.SpidermanManager | ||
| import net.minecraft.entity.player.PlayerEntity | ||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable | ||
|
|
||
| fun handleWallClimbCheck(player: PlayerEntity, cir: CallbackInfoReturnable<Boolean>) { | ||
| if (player.getHero() == SpidermanManager.Spiderman && !player.isSpectator && player.horizontalCollision) { | ||
| cir.returnValue = true | ||
|
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This as well can be shortened cir.returnValue = player.getHero() == SpidermanManager.Spiderman && !player.isSpectator && player.horizontalCollision |
||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this if is unnecessary, just do