Skip to content

Commit

Permalink
Transition 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkona committed Jun 11, 2024
1 parent ea5daa2 commit b6725c5
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 112 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ dependencies {
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"

compileOnly ("curse.maven:parcool-482378:${parcool_file_id}")
compileOnly ("curse.maven:create-328085:${create_file_id}")
implementation fg.deobf("curse.maven:create-328085:${create_file_id}")


runtimeOnly fg.deobf("curse.maven:cloth-config-api-348521:${cloth_config_id}")
Expand All @@ -168,6 +168,10 @@ dependencies {
implementation fg.deobf("curse.maven:paragliders-289240:${mod_paragliders_file_id}")
implementation fg.deobf("curse.maven:player-animator-658587:${player_animator_file_id}")
implementation fg.deobf("curse.maven:elenai-dodge-442962:${elenai_dodge_file_id}")
//runtimeOnly fg.deobf("curse.maven:applied-energistics-2-223794:${applied_energistics_file_id}")
runtimeOnly fg.deobf("curse.maven:jei-238222:5101366")
runtimeOnly fg.deobf("curse.maven:dummy-225738:5319203")
runtimeOnly fg.deobf("curse.maven:moonlight-499980:5409387")
// not available for 1.20.1 :/( // implementation fg.deobf("curse.maven:wall-jump-622370:${wall_jump_file_id}")


Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ wall_jump_file_id=3597135
architectury_file_id=5137938
mod_id=actions-of-stamina
mod_authors=ccr4ft3r,Darkona
elenai_dodge_file_id=4814313
elenai_dodge_file_id=4814313
applied_energistics_file_id=5401948
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.ccr4ft3r.actionsofstamina.actions;

import com.ccr4ft3r.actionsofstamina.config.AoSAction;
import net.minecraft.world.entity.player.Player;

public class ActionProvider {

public static ActionProvider INSTANCE;

private ActionProvider() {

}

public static ActionProvider getInstance() {
if (INSTANCE == null) {
INSTANCE = new ActionProvider();
}
return INSTANCE;
}

public void getAction(Player player, AoSAction action) {

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.ccr4ft3r.actionsofstamina.actions.minecraft.attack;

import com.ccr4ft3r.actionsofstamina.ModConstants;
import com.ccr4ft3r.actionsofstamina.config.ProfileConfig;
import com.ccr4ft3r.actionsofstamina.data.ServerPlayerData;
import com.ccr4ft3r.actionsofstamina.network.PacketHandler;
import com.ccr4ft3r.actionsofstamina.network.ServerboundPacket;
import com.google.common.collect.Multimap;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.Iterator;

import static com.ccr4ft3r.actionsofstamina.config.AoSAction.ATTACKING;
import static com.ccr4ft3r.actionsofstamina.config.ProfileConfig.getProfile;
import static com.ccr4ft3r.actionsofstamina.data.ServerData.getPlayerData;
import static com.ccr4ft3r.actionsofstamina.network.ServerboundPacket.Action.WEAPON_SWING;
import static com.ccr4ft3r.actionsofstamina.util.PlayerUtil.cannotBeExhausted;

@Mod.EventBusSubscriber(modid = ModConstants.MOD_ID)
public class AttackHandler {

@SubscribeEvent
public static void onPlayerAttack(AttackEntityEvent event) {


var player = event.getEntity();

boolean canAttack = ProfileConfig.canPlayerDo(player, ATTACKING);

if (!canAttack) {
event.setCanceled(true);
return;
}

exhaustForWeaponSwing(player);

}

@SubscribeEvent
public static void onPlayerAttack(PlayerInteractEvent.LeftClickEmpty event) {
if(!getProfile().onlyForHits.get())
PacketHandler.sendToServer(new ServerboundPacket(WEAPON_SWING));
}

public static void exhaustForWeaponSwing(Player p) {
if (!getProfile().isActionAvailable.get(ATTACKING).get()) return;

if (!(p instanceof ServerPlayer player) || cannotBeExhausted(player))
return;

ServerPlayerData playerData = getPlayerData(player);
ItemStack itemstack = player.getItemInHand(InteractionHand.MAIN_HAND);
Multimap<Attribute, AttributeModifier> modifiers = itemstack.getItem().getAttributeModifiers(EquipmentSlot.MAINHAND, itemstack);
Iterator<AttributeModifier> attackDamages = modifiers.get(Attributes.ATTACK_DAMAGE).iterator();

double multiplier = 0d;
if (attackDamages.hasNext()) {
AttributeModifier attackDamage = attackDamages.next();
multiplier = getProfile().attackDamageMultiplier.get() * (attackDamage.getAmount() + 1);
} else if (!getProfile().alsoForNonWeapons.get())
return;
/* ****** */
playerData.set(ATTACKING, Math.max(0, 1 + multiplier), player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public enum ActionType {

TICKS, TIMES;

public static final Set<AoSAction> TIME_ACTIONS = Sets.newConcurrentHashSet();
public static final Set<AoSAction> CONTINUOUS_ACTIONS = Sets.newConcurrentHashSet();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.ccr4ft3r.actionsofstamina.config;

import com.google.common.base.CaseFormat;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import tictim.paraglider.forge.capability.PlayerMovementProvider;

Expand Down Expand Up @@ -51,7 +50,7 @@ public enum AoSAction {
this.delayByProfile = delayByProfile;
this.description = description.length > 0 ? " (" + description[0] + ")" : "";
if (type == TICKS)
TIME_ACTIONS.add(this);
CONTINUOUS_ACTIONS.add(this);
}

String getText(boolean forDescription) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,15 @@ public static void stopIfExhausted(Player player, AoSAction action, Runnable sto
}

public static boolean shouldStop(Player player, AoSAction action) {

return getProfile().enabledByAction.get(action).get()
return getProfile().isActionAvailable.get(action).get()
&& !hasEnoughFeathers(getProfile().costsByAction.get(action).get(), getProfile().minByAction.get(action).get(), player);
}

public static boolean canDo(Player player, AoSAction action) {
return getProfile().enabledByAction.get(action).get()
public static boolean canPlayerDo(Player player, AoSAction action) {
return getProfile().isActionAvailable.get(action).get()
&& hasEnoughFeathers(getProfile().costsByAction.get(action).get(), getProfile().minByAction.get(action).get(), player);
}

public static boolean shouldStop(ServerPlayer player, AoSAction action) {
return getProfile().enabledByAction.get(action).get()
&& !hasEnoughFeathers(getProfile().costsByAction.get(action).get(), getProfile().minByAction.get(action).get(), player);
}

public static void updateChosenProfile() {
AoSProfile profile = MainConfig.CONFIG_DATA.profileToUse.get();
Expand Down Expand Up @@ -88,7 +83,7 @@ public static class Data {
public ForgeConfigSpec.BooleanValue alsoForNonWeapons;

public Map<AoSAction, ForgeConfigSpec.IntValue> initialCostsByAction = Maps.newConcurrentMap();
public Map<AoSAction, ForgeConfigSpec.BooleanValue> enabledByAction = Maps.newConcurrentMap();
public Map<AoSAction, ForgeConfigSpec.BooleanValue> isActionAvailable = Maps.newConcurrentMap();
public Map<AoSAction, ForgeConfigSpec.IntValue> costsByAction = Maps.newConcurrentMap();
public Map<AoSAction, ForgeConfigSpec.IntValue> minByAction = Maps.newConcurrentMap();
public Map<AoSAction, ForgeConfigSpec.BooleanValue> regenerationByAction = Maps.newConcurrentMap();
Expand All @@ -106,7 +101,7 @@ public Data(ForgeConfigSpec.Builder builder, AoSProfile profile) {

for (AoSAction action : AoSAction.values()) {
builder.push(action.getText(false));
enabledByAction.put(action, define(ENABLE_FOR + action.getText(true)
isActionAvailable.put(action, define(ENABLE_FOR + action.getText(true)
+ action.getDescription(), "enableFor" + action.getText(false),
action.isEnabled(profile)));
costsByAction.put(action, defineRange(COSTS + action.getText(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,31 @@ public void setMoving(boolean moving) {
}

public void set(AoSAction action, boolean newState, double increment, Player player) {
AtomicBoolean currentState = stateByAction.get(action);
boolean wasStarted = checkStarting(action, currentState.get(), newState, player);
currentState.set(newState);
if (currentState.get()) {
AtomicBoolean previousState = stateByAction.get(action);
boolean wasNotDoing = checkStarting(action, previousState.get(), newState, player);
previousState.set(newState);
if (newState) {
if (tickByAction.get(action).get() >= player.tickCount) {
return;
}

long factor = 1;
if (action.getType() == ActionType.TICKS && !wasStarted)
if (action.getType() == ActionType.TICKS && !wasNotDoing)
factor = player.tickCount - tickByAction.get(action).get();
tickByAction.get(action).set(player.tickCount);

amountByAction.get(action).addAndGet(increment * factor);

exhaust(player, action);
}

if (ActionType.TIME_ACTIONS.contains(action) && action.getStopper() != null) {
if (ActionType.CONTINUOUS_ACTIONS.contains(action) && action.getStopper() != null) {
stopIfExhausted(player, action, () -> action.getStopper().accept(player));
}
}

public void update(ServerPlayer player) {
ActionType.TIME_ACTIONS.forEach(action -> {
ActionType.CONTINUOUS_ACTIONS.forEach(action -> {
if (is(action) && tickByAction.get(action).get() + 20 < player.tickCount)
set(action, false, player);
});
Expand All @@ -92,14 +95,8 @@ public void set(AoSAction action, boolean newState, Player player) {
set(action, newState, 1d, player);
}

private boolean checkStarting(AoSAction action, boolean currentValue, boolean newValue, Player player) {
if (!currentValue && newValue) {
if (action.getType() == ActionType.TICKS)
//return FeathersAPI.spendFeathers(player, getProfile().initialCostsByAction.get(action).get(), 0);
return true;

}
return false;
private boolean checkStarting(AoSAction action, boolean previousState, boolean newState, Player player) {
return !previousState && newState && action.getType() == ActionType.TICKS;
}

public boolean is(AoSAction action) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.ccr4ft3r.actionsofstamina.ModConstants;
import com.ccr4ft3r.actionsofstamina.data.ServerPlayerData;
import com.ccr4ft3r.actionsofstamina.util.PlayerUtil;
import com.darkona.feathers.api.FeathersAPI;
import com.google.common.collect.Multimap;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
Expand All @@ -16,14 +17,13 @@
import net.minecraft.world.item.ShieldItem;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.Iterator;
import java.util.Objects;

import static com.ccr4ft3r.actionsofstamina.config.AoSAction.*;
import static com.ccr4ft3r.actionsofstamina.config.ProfileConfig.canDo;
import static com.ccr4ft3r.actionsofstamina.config.ProfileConfig.getProfile;
import static com.ccr4ft3r.actionsofstamina.data.ServerData.getPlayerData;
import static com.ccr4ft3r.actionsofstamina.util.PlayerUtil.cannotBeExhausted;
Expand All @@ -41,42 +41,14 @@ public static void onPlayerJump(LivingEvent.LivingJumpEvent event) {
getPlayerData(player).set(JUMPING, !player.isInWater() && !player.onClimbable(), player);
}

@SubscribeEvent
public static void onPlayerAttack(AttackEntityEvent event) {
if (event.getEntity() instanceof ServerPlayer player && !event.isCanceled()) {

event.setCanceled(!canDo(player, ATTACKING));
if (!event.isCanceled()) {

exhaustForWeaponSwing(player);
}
}
}

public static void exhaustForWeaponSwing(Player player) {
if (/*!(p instanceof ServerPlayer player) || */cannotBeExhausted(player))
return;
ServerPlayerData playerData = getPlayerData(player);
ItemStack itemstack = player.getItemInHand(InteractionHand.MAIN_HAND);
Multimap<Attribute, AttributeModifier> modifiers = itemstack.getItem().getAttributeModifiers(EquipmentSlot.MAINHAND, itemstack);
Iterator<AttributeModifier> attackDamages = modifiers.get(Attributes.ATTACK_DAMAGE).iterator();

double multiplier = 0d;
if (attackDamages.hasNext()) {
AttributeModifier attackDamage = attackDamages.next();
multiplier = getProfile().attackDamageMultiplier.get() * (attackDamage.getAmount() + 1);
} else if (!getProfile().alsoForNonWeapons.get())
return;
playerData.set(ATTACKING, Math.max(0, 1 + multiplier), player);
}

private static void changeAttackByFeathers(Player player) {
/*if (FeathersAPI.getFeathers(player) < 4) {
player.getAttribute(Attributes.ATTACK_DAMAGE).addTransientModifier(Exhaustion);
if (FeathersAPI.getAvailableFeathers(player) < 4) {
Objects.requireNonNull(player.getAttribute(Attributes.ATTACK_DAMAGE)).addTransientModifier(Exhaustion);
} else {
player.getAttribute(Attributes.ATTACK_DAMAGE).removeModifier(Exhaustion);
}*/
Objects.requireNonNull(player.getAttribute(Attributes.ATTACK_DAMAGE)).removeModifier(Exhaustion);
}
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ private static void stopWallJump(CallbackInfo ci) {

//@Inject(method = "doWallClingJump", at = @At("HEAD"), remap = false)
private static void exhaustForWallJump(CallbackInfo ci) {
PacketHandler.sendToServer(new ServerboundPacket(PLAYER_WALL_JUMP));
//PacketHandler.sendToServer(new ServerboundPacket(PLAYER_WALL_JUMP));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ccr4ft3r.actionsofstamina.network;

import com.ccr4ft3r.actionsofstamina.ModConstants;
import com.ccr4ft3r.actionsofstamina.actions.minecraft.attack.AttackHandler;
import com.ccr4ft3r.actionsofstamina.events.ExhaustionHandler;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -38,7 +39,9 @@ private static void handle(ServerboundPacket packet, Supplier<NetworkEvent.Conte
switch (packet.getAction()) {
case PLAYER_MOVING -> getPlayerData(player).setMoving(true);
case PLAYER_STOP_MOVING -> getPlayerData(player).setMoving(false);
case WEAPON_SWING -> ExhaustionHandler.exhaustForWeaponSwing(player);
case WEAPON_SWING -> {
if(!getProfile().onlyForHits.get()) AttackHandler.exhaustForWeaponSwing(player);
}
case PLAYER_WALL_JUMP -> getPlayerData(player).set(WALL_JUMPING, true, player);
}
context.setPacketHandled(true);
Expand Down
Loading

0 comments on commit b6725c5

Please sign in to comment.