Skip to content

Commit

Permalink
feat: update channeled logic for substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed May 5, 2022
1 parent e65be1f commit bbde117
Show file tree
Hide file tree
Showing 16 changed files with 164 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/sekwah/narutomod/NarutoMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.sekwah.narutomod.client.keybinds.NarutoKeyHandler;
import com.sekwah.narutomod.client.renderer.NarutoRenderEvents;
import com.sekwah.narutomod.commands.NarutoCommands;
import com.sekwah.narutomod.config.NarutoConfig;
import com.sekwah.narutomod.client.renderer.entity.config.NarutoConfig;
import com.sekwah.narutomod.entity.NarutoDataSerialisers;
import com.sekwah.narutomod.entity.NarutoEntities;
import com.sekwah.narutomod.item.NarutoDispenseItemBehavior;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/sekwah/narutomod/abilities/Ability.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ default boolean useChargedMessages() {
return false;
}

/**
* In case of other use cases where you don't want the messages. for custom states e.g. substitution.
* @return
*/
default boolean hideChannelMessages() {
return false;
}

/**
* Call every tick handleCost passes on server side.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.sekwah.narutomod.NarutoMod;
import com.sekwah.narutomod.abilities.jutsus.FireballJutsuAbility;
import com.sekwah.narutomod.abilities.jutsus.SubstitutionJutsuAbility;
import com.sekwah.narutomod.abilities.jutsus.WaterBulletJutsuAbility;
import com.sekwah.narutomod.abilities.utility.*;
import com.sekwah.narutomod.network.PacketHandler;
Expand Down Expand Up @@ -45,6 +46,8 @@ public class NarutoAbilities {

public static final RegistryObject<DoubleJumpAbility> DOUBLE_JUMP = ABILITY.register("double_jump", DoubleJumpAbility::new);

public static final RegistryObject<SubstitutionJutsuAbility> SUBSTITUTION = ABILITY.register("substitution", SubstitutionJutsuAbility::new);

public static void register(IEventBus eventBus) {
ABILITY.register(eventBus);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.sekwah.narutomod.abilities.jutsus;

import com.sekwah.narutomod.abilities.Ability;
import com.sekwah.narutomod.capabilities.INinjaData;
import com.sekwah.narutomod.sounds.NarutoSounds;
import com.sekwah.sekclib.player.PlayerUtil;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec3;

public class SubstitutionJutsuAbility extends Ability implements Ability.Channeled {
@Override
public ActivationType activationType() {
return ActivationType.CHANNELED;
}

@Override
public long defaultCombo() {
return 12;
}

@Override
public boolean handleCost(Player player, INinjaData ninjaData, int chargeAmount) {
return true;
}

/**
* Due to the nature of this ability all costs and other things will be handled here.
*/
@Override
public void performServer(Player player, INinjaData ninjaData, int ticksActive) {
if(ticksActive == 0) {
player.displayClientMessage(new TranslatableComponent("jutsu.cast.substitution"), false);
// Activate
ninjaData.useSubstitution(1);
} else {
player.displayClientMessage(new TranslatableComponent("jutsu.cast.substitution_mark"), false);
// Mark
}
}

@Override
public boolean hideChannelMessages() {
return true;
}
}
23 changes: 14 additions & 9 deletions src/main/java/com/sekwah/narutomod/capabilities/NinjaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.sekwah.narutomod.abilities.Ability;
import com.sekwah.narutomod.abilities.NarutoAbilities;
import com.sekwah.narutomod.capabilities.toggleabilitydata.ToggleAbilityData;
import com.sekwah.narutomod.config.NarutoConfig;
import com.sekwah.narutomod.client.renderer.entity.config.NarutoConfig;
import com.sekwah.sekclib.capabilitysync.capabilitysync.annotation.Sync;
import net.minecraft.ChatFormatting;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -208,21 +208,26 @@ public void setCurrentlyChanneledAbility(Player player, Ability ability) {
if (ability.castingSound() != null) {
player.getLevel().playSound(null, player, ability.castingSound(), SoundSource.PLAYERS, 0.5f, 1.0f);
}
if (ability instanceof Ability.Channeled channeled && channeled.useChargedMessages()) {
player.sendMessage(new TranslatableComponent("jutsu.charge.start", new TranslatableComponent(ability.getTranslationKey()).withStyle(ChatFormatting.YELLOW)).withStyle(ChatFormatting.GREEN), player.getUUID());
} else {
player.sendMessage(new TranslatableComponent("jutsu.channel.start", new TranslatableComponent(ability.getTranslationKey()).withStyle(ChatFormatting.YELLOW)).withStyle(ChatFormatting.GREEN), player.getUUID());

if(!(ability instanceof Ability.Channeled channeled && channeled.hideChannelMessages())) {
if (ability instanceof Ability.Channeled channeled && channeled.useChargedMessages()) {
player.sendMessage(new TranslatableComponent("jutsu.charge.start", new TranslatableComponent(ability.getTranslationKey()).withStyle(ChatFormatting.YELLOW)).withStyle(ChatFormatting.GREEN), player.getUUID());
} else {
player.sendMessage(new TranslatableComponent("jutsu.channel.start", new TranslatableComponent(ability.getTranslationKey()).withStyle(ChatFormatting.YELLOW)).withStyle(ChatFormatting.GREEN), player.getUUID());
}
}

this.currentlyChanneled = ability.getRegistryName();
} else {
if (this.currentlyChanneled != null) {
Ability currentAbility = NarutoAbilities.ABILITY_REGISTRY.getValue(this.currentlyChanneled);
if( currentAbility != null) {
if (currentAbility instanceof Ability.Channeled channeled && channeled.useChargedMessages()) {
player.sendMessage(new TranslatableComponent("jutsu.cast", new TranslatableComponent(currentAbility.getTranslationKey()).withStyle(ChatFormatting.YELLOW)).withStyle(ChatFormatting.GREEN), player.getUUID());
} else {
player.sendMessage(new TranslatableComponent("jutsu.channel.stop", new TranslatableComponent(currentAbility.getTranslationKey()).withStyle(ChatFormatting.YELLOW)).withStyle(ChatFormatting.RED), player.getUUID());
if(!(currentAbility instanceof Ability.Channeled channeled && channeled.hideChannelMessages())) {
if (currentAbility instanceof Ability.Channeled channeled && channeled.useChargedMessages()) {
player.sendMessage(new TranslatableComponent("jutsu.cast", new TranslatableComponent(currentAbility.getTranslationKey()).withStyle(ChatFormatting.YELLOW)).withStyle(ChatFormatting.GREEN), player.getUUID());
} else {
player.sendMessage(new TranslatableComponent("jutsu.channel.stop", new TranslatableComponent(currentAbility.getTranslationKey()).withStyle(ChatFormatting.YELLOW)).withStyle(ChatFormatting.RED), player.getUUID());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.sekwah.narutomod.capabilities.lingerabilitydata;

import com.sekwah.narutomod.abilities.Ability;
import com.sekwah.narutomod.capabilities.INinjaData;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;

import java.util.HashSet;
import java.util.Objects;

/**
* Tracks ability references and other information for the server side.
*
* On client side the ticks tracked will be since the client knows the ability is active.
* Do not use it for reliable triggering for effects or behavior when the user is not the player itssself.
*
* Try to keep as much behavior solely to server side as you can.
*/
public class LingerAbilityData {

private HashSet<ResourceLocation> abilities;

public LingerAbilityData(int size) {
this.abilities = new HashSet<>(size);
}

public LingerAbilityData() {
this.abilities = new HashSet<>();
}

public boolean addAbility(ResourceLocation ability) {
return this.abilities.add(ability);
}

public boolean addAbilityStarted(Player player, INinjaData ninjaData, Ability ability) {
if (ability.activationType() == Ability.ActivationType.TOGGLE && ability.logInChat()) {
player.sendMessage(new TranslatableComponent("jutsu.toggle.enabled", new TranslatableComponent(ability.getTranslationKey()).withStyle(ChatFormatting.YELLOW)).withStyle(ChatFormatting.GREEN), player.getUUID());
}
return this.addAbility(ability.getRegistryName());
}

public boolean removeAbilityEnded(Player player, INinjaData ninjaData, Ability ability) {
if(ability instanceof Ability.HandleEnded endedAbility) endedAbility.handleAbilityEnded(player, ninjaData, 0);
if (ability.activationType() == Ability.ActivationType.TOGGLE && ability.logInChat()) {
player.sendMessage(new TranslatableComponent("jutsu.toggle.disabled", new TranslatableComponent(ability.getTranslationKey()).withStyle(ChatFormatting.YELLOW)).withStyle(ChatFormatting.RED), player.getUUID());
}
return this.removeAbility(ability.getRegistryName());
}

public boolean removeAbility(ResourceLocation ability) {
return this.abilities.remove(ability);
}

public HashSet<ResourceLocation> getAbilitiesHashSet() {
return abilities;
}

@Override
public int hashCode() {
return Objects.hash(abilities);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof LingerAbilityData)) return false;
LingerAbilityData that = (LingerAbilityData) o;
return abilities.equals(that.abilities);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.sekwah.narutomod.NarutoMod;
import com.sekwah.narutomod.capabilities.NinjaCapabilityHandler;
import com.sekwah.narutomod.config.NarutoConfig;
import com.sekwah.narutomod.client.renderer.entity.config.NarutoConfig;
import com.sekwah.narutomod.util.ColorUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;

import java.awt.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.mojang.blaze3d.vertex.PoseStack;
import com.sekwah.narutomod.NarutoMod;
import com.sekwah.narutomod.capabilities.NinjaCapabilityHandler;
import com.sekwah.narutomod.config.NarutoConfig;
import com.sekwah.narutomod.util.ColorUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.sekwah.narutomod.NarutoMod;
import com.sekwah.narutomod.abilities.Ability;
import com.sekwah.narutomod.abilities.NarutoAbilities;
import com.sekwah.narutomod.config.NarutoConfig;
import com.sekwah.narutomod.client.renderer.entity.config.NarutoConfig;
import com.sekwah.narutomod.network.PacketHandler;
import com.sekwah.narutomod.network.c2s.ServerAbilityChannelPacket;
import com.sekwah.narutomod.network.c2s.ServerJutsuCastingPacket;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
import com.sekwah.narutomod.client.model.item.model.HeadbandModel;
import com.sekwah.narutomod.client.renderer.entity.jutsuprojectile.FireballJutsuRenderer;
import com.sekwah.narutomod.client.renderer.entity.jutsuprojectile.WaterBulletJutsuRenderer;
import com.sekwah.narutomod.client.renderer.worldinfo.SubstitutionWorldMarkerRenderer;
import com.sekwah.narutomod.entity.NarutoEntities;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.client.event.RegisterClientReloadListenersEvent;
import net.minecraftforge.client.event.RenderLevelLastEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sekwah.narutomod.config;
package com.sekwah.narutomod.client.renderer.entity.config;

import com.sekwah.narutomod.NarutoMod;
import com.sekwah.narutomod.client.gui.BarDesigns;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.sekwah.narutomod.client.renderer.worldinfo;

public class SubstitutionWorldMarkerRenderer {
public static void render() {

}
}
6 changes: 1 addition & 5 deletions src/main/java/com/sekwah/narutomod/datagen/RecipeGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import com.sekwah.narutomod.block.NarutoBlocks;
import com.sekwah.narutomod.item.NarutoItems;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.data.recipes.RecipeProvider;
import net.minecraft.data.recipes.ShapedRecipeBuilder;
import net.minecraft.data.recipes.ShapelessRecipeBuilder;
import net.minecraft.data.recipes.*;
import net.minecraft.world.item.Items;

import java.util.function.Consumer;
Expand Down Expand Up @@ -110,6 +107,5 @@ protected void buildCraftingRecipes(Consumer<FinishedRecipe> recipeConsumer) {
.unlockedBy("has_gunpowder", has(Items.GUNPOWDER))
.save(recipeConsumer);


}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.sekwah.narutomod.entity.item;

import com.sekwah.narutomod.block.NarutoBlocks;
import com.sekwah.narutomod.config.NarutoConfig;
import com.sekwah.narutomod.client.renderer.entity.config.NarutoConfig;
import com.sekwah.narutomod.entity.NarutoDataSerialisers;
import com.sekwah.narutomod.entity.NarutoEntities;
import net.minecraft.core.BlockPos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.sekwah.narutomod.entity.projectile;

import com.sekwah.narutomod.config.NarutoConfig;
import com.sekwah.narutomod.client.renderer.entity.config.NarutoConfig;
import com.sekwah.narutomod.entity.NarutoEntities;
import com.sekwah.narutomod.item.NarutoItems;
import com.sekwah.narutomod.sounds.NarutoSounds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public static void handle(ServerAbilityChannelPacket msg, Supplier<NetworkEvent.
} else if(msg.status == ChannelStatus.MIN_ACTIVATE) {
if (ability instanceof Ability.Channeled channeled && channeled.canActivateBelowMinCharge()) {
if(ability.handleCost(player, ninjaData, 0)) {
ability.performServer(player, ninjaData, 0);
}
} else {
player.sendMessage(new TranslatableComponent("jutsu.channel.needed", new TranslatableComponent(ability.getTranslationKey()).withStyle(ChatFormatting.YELLOW)).withStyle(ChatFormatting.RED), player.getUUID());
Expand Down

0 comments on commit bbde117

Please sign in to comment.