aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/dev/mayaqq/ygasi/Ygasi.java1
-rw-r--r--src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence1.java10
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java2
-rw-r--r--src/main/java/dev/mayaqq/ygasi/mixin/PlayerEntityMixin.java34
-rw-r--r--src/main/java/dev/mayaqq/ygasi/mixin/StatusEffectMixin.java42
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java2
-rw-r--r--src/main/java/dev/mayaqq/ygasi/util/Multithreading.java75
-rw-r--r--src/main/resources/ygasi.mixins.json4
8 files changed, 161 insertions, 9 deletions
diff --git a/src/main/java/dev/mayaqq/ygasi/Ygasi.java b/src/main/java/dev/mayaqq/ygasi/Ygasi.java
index 608472a..bc738dc 100644
--- a/src/main/java/dev/mayaqq/ygasi/Ygasi.java
+++ b/src/main/java/dev/mayaqq/ygasi/Ygasi.java
@@ -14,7 +14,6 @@ public class Ygasi implements ModInitializer {
@Override
public void onInitialize() {
//load the config data and register everything that needs to be registered on startup
- //test
ConfigRegistry.load();
ItemRegistry.register();
StatRegistry.register();
diff --git a/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence1.java b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence1.java
index 73b99e0..506fa18 100644
--- a/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence1.java
+++ b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence1.java
@@ -1,21 +1,23 @@
package dev.mayaqq.ygasi.abilities.mercenary;
-import dev.mayaqq.ygasi.registry.ConfigRegistry;
import dev.mayaqq.ygasi.util.AdvUtils;
-import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
+import java.util.HashMap;
+import java.util.Map;
+
public class Offence1 {
+
+ public static Map<String, Boolean> attackList = new HashMap<>();
+
public static void give(ServerPlayerEntity player) {
if (!AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/offence1")) {
- player.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE).setBaseValue(player.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE).getBaseValue() + ConfigRegistry.CONFIG.offence1DefIncrease);
AdvUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/offence1"), "unlocked_offence1");
}
}
public static void revoke(ServerPlayerEntity player) {
if (AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/offence1")) {
- player.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE).setBaseValue(player.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE).getBaseValue() - ConfigRegistry.CONFIG.offence1DefIncrease);
AdvUtils.revokeAllAdvancements(player, "minecraft", "ygasi/offence1");
}
}
diff --git a/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java b/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java
index 2f79874..c4a60a4 100644
--- a/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java
+++ b/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java
@@ -61,8 +61,6 @@ public class ResetGui {
gui.open();
}
public static void reset(ServerPlayerEntity player) {
- //check if player experience level is greater than 10
- //revoke the abilities first
AdvUtils.revokeAllAdvancements(player, "minecraft", "ygasi/root");
if (AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/mercenary")) {
AdvUtils.revokeAllAdvancements(player, "minecraft", "ygasi/mercenary");
diff --git a/src/main/java/dev/mayaqq/ygasi/mixin/PlayerEntityMixin.java b/src/main/java/dev/mayaqq/ygasi/mixin/PlayerEntityMixin.java
new file mode 100644
index 0000000..5eeea63
--- /dev/null
+++ b/src/main/java/dev/mayaqq/ygasi/mixin/PlayerEntityMixin.java
@@ -0,0 +1,34 @@
+package dev.mayaqq.ygasi.mixin;
+
+import dev.mayaqq.ygasi.util.AdvUtils;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.effect.StatusEffectInstance;
+import net.minecraft.entity.effect.StatusEffects;
+import net.minecraft.entity.player.PlayerEntity;
+import net.minecraft.server.network.ServerPlayerEntity;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import static dev.mayaqq.ygasi.abilities.mercenary.Offence1.attackList;
+
+@Mixin(PlayerEntity.class)
+public abstract class PlayerEntityMixin {
+ @Shadow public abstract boolean isPlayer();
+
+ @Inject(method = "attack", at = @At("HEAD"))
+ public void onAttack(Entity target, CallbackInfo ci) {
+ if (this.isPlayer()) {
+ ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;
+ if (!attackList.containsKey(player.getUuidAsString() + target.getUuidAsString()) && AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/offence1")) {
+ attackList.put(player.getUuidAsString() + target.getUuidAsString(), true);
+ StatusEffectInstance currentEffect = player.getStatusEffect(StatusEffects.STRENGTH);
+ int currentLevel = currentEffect != null ? currentEffect.getAmplifier() : 0;
+ int currentTime = currentEffect != null ? currentEffect.getDuration() : 0;
+ player.addStatusEffect(new StatusEffectInstance(StatusEffects.STRENGTH, currentTime + 2 * 20, currentLevel, false, false, true));
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/java/dev/mayaqq/ygasi/mixin/StatusEffectMixin.java b/src/main/java/dev/mayaqq/ygasi/mixin/StatusEffectMixin.java
new file mode 100644
index 0000000..e2df799
--- /dev/null
+++ b/src/main/java/dev/mayaqq/ygasi/mixin/StatusEffectMixin.java
@@ -0,0 +1,42 @@
+package dev.mayaqq.ygasi.mixin;
+
+import dev.mayaqq.ygasi.util.AdvUtils;
+import dev.mayaqq.ygasi.util.Multithreading;
+import net.minecraft.entity.LivingEntity;
+import net.minecraft.entity.attribute.AttributeContainer;
+import net.minecraft.entity.effect.StatusEffect;
+import net.minecraft.entity.effect.StatusEffects;
+import net.minecraft.server.network.ServerPlayerEntity;
+import net.minecraft.sound.SoundCategory;
+import net.minecraft.sound.SoundEvent;
+import net.minecraft.sound.SoundEvents;
+import net.minecraft.text.Text;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import java.util.concurrent.TimeUnit;
+
+import static dev.mayaqq.ygasi.Ygasi.LOGGER;
+import static dev.mayaqq.ygasi.abilities.mercenary.Offence1.attackList;
+
+@Mixin(StatusEffect.class)
+public abstract class StatusEffectMixin {
+
+ @Shadow public abstract Text getName();
+
+ @Inject(method = "onRemoved", at = @At("HEAD"))
+ public void onUpdateStatusEffect(LivingEntity entity, AttributeContainer attributes, int amplifier, CallbackInfo ci) {
+ LOGGER.info("onRemovedTick");
+ if (entity.isPlayer()) {
+ ServerPlayerEntity player = (ServerPlayerEntity) entity;
+ if (this.getName() != null && this.getName().equals(StatusEffects.STRENGTH.getName()) && AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/offence1")) {
+ Multithreading.schedule(() -> {
+ attackList.entrySet().removeIf(entry -> entry.getKey().startsWith(player.getUuidAsString()));
+ },4, TimeUnit.SECONDS);
+ }
+ }
+ }
+}
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java
index c48cd6e..19b4563 100644
--- a/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java
+++ b/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java
@@ -54,7 +54,7 @@ public class ConfigRegistry {
public int T1Cost = 5;
public int T2Cost = 10;
public int T3Cost = 15;
- public int offence1DefIncrease = 3;
+ public int offence1DefIncrease = 1;
public Config() {}
}
diff --git a/src/main/java/dev/mayaqq/ygasi/util/Multithreading.java b/src/main/java/dev/mayaqq/ygasi/util/Multithreading.java
new file mode 100644
index 0000000..89914d1
--- /dev/null
+++ b/src/main/java/dev/mayaqq/ygasi/util/Multithreading.java
@@ -0,0 +1,75 @@
+package dev.mayaqq.ygasi.util;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+import java.util.concurrent.*;
+
+/**
+ * Allows for easy multithreading.
+ * <p>
+ * Taken from Seraph by Scherso under LGPL-2.1
+ * <a href="https://github.com/Scherso/Seraph/blob/master/LICENSE">https://github.com/Scherso/Seraph/blob/master/LICENSE</a>
+ * </p>
+ */
+public class Multithreading {
+ private static final ExecutorService executorService = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("OneConfig-%d").build());
+ private static final ScheduledExecutorService runnableExecutor = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors() + 1);
+
+ /**
+ * Runs the runnable asynchronously.
+ *
+ * @param runnable The runnable to run.
+ * @see Multithreading#submit(Runnable)
+ */
+ public static void runAsync(Runnable runnable) {
+ submit(runnable);
+ }
+
+ /**
+ * Runs the provided runnables asynchronously.
+ *
+ * @param runnables The runnables to run.
+ * @see Multithreading#runAsync(Runnable)
+ */
+ public static void runAsync(Runnable... runnables) {
+ for (Runnable runnable : runnables) {
+ runAsync(runnable);
+ }
+ }
+
+ /**
+ * Submits the Runnable to the executor, making it run asynchronously.
+ *
+ * @param runnable The runnable to run.
+ * @return The future representing the submitted runnable.
+ * @see ExecutorService#submit(Runnable)
+ */
+ public static Future<?> submit(Runnable runnable) {
+ return executorService.submit(runnable);
+ }
+
+ /**
+ * Schedules the runnable to run asynchronously after the specified delay.
+ *
+ * @param runnable The runnable to run.
+ * @param delay The delay before the runnable is run.
+ * @param timeUnit The {@link TimeUnit} of the delay.
+ * @see Multithreading#submitScheduled(Runnable, long, TimeUnit)
+ */
+ public static void schedule(Runnable runnable, long delay, TimeUnit timeUnit) {
+ submitScheduled(runnable, delay, timeUnit);
+ }
+
+ /**
+ * Submits the Runnable to the executor after a delay, making it run asynchronously.
+ *
+ * @param runnable The runnable to run.
+ * @param delay The delay before the runnable is run.
+ * @param timeUnit The {@link TimeUnit} of the delay.
+ * @return The future representing the submitted runnable.
+ * @see ScheduledExecutorService#schedule(Runnable, long, TimeUnit)
+ */
+ public static ScheduledFuture<?> submitScheduled(Runnable runnable, long delay, TimeUnit timeUnit) {
+ return runnableExecutor.schedule(runnable, delay, timeUnit);
+ }
+}
diff --git a/src/main/resources/ygasi.mixins.json b/src/main/resources/ygasi.mixins.json
index f82afc7..a2dba96 100644
--- a/src/main/resources/ygasi.mixins.json
+++ b/src/main/resources/ygasi.mixins.json
@@ -4,7 +4,9 @@
"package": "dev.mayaqq.ygasi.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
- "AdvancementRewardsMixin"
+ "AdvancementRewardsMixin",
+ "PlayerEntityMixin",
+ "StatusEffectMixin"
],
"client": [
],