aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaximusbarcz <maxim.baranek@gmail.com>2023-01-21 14:59:09 +0100
committerMaximusbarcz <maxim.baranek@gmail.com>2023-01-21 14:59:09 +0100
commit189b1d5f1f41326becc614e32d78fbb2f5228530 (patch)
tree7f0f8295b70a7757bb4d33363236a34c1f59fdef
parentadaecef7df47ccdbfbda6f438c28696ff1ce8822 (diff)
downloadygasi-189b1d5f1f41326becc614e32d78fbb2f5228530.tar.gz
ygasi-189b1d5f1f41326becc614e32d78fbb2f5228530.tar.bz2
ygasi-189b1d5f1f41326becc614e32d78fbb2f5228530.zip
Something something kinda works other than removing the entity, making explosion and having a cool animation because minecraft said so?
-rw-r--r--src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence2.java22
-rw-r--r--src/main/java/dev/mayaqq/ygasi/events/PlayerConnectEvent.java2
-rw-r--r--src/main/java/dev/mayaqq/ygasi/events/TickEvent.java (renamed from src/main/java/dev/mayaqq/ygasi/events/ClickEvent.java)9
-rw-r--r--src/main/java/dev/mayaqq/ygasi/mixin/ItemMixin.java90
-rw-r--r--src/main/java/dev/mayaqq/ygasi/mixin/PlayerEntityMixin.java2
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/EventRegistry.java4
6 files changed, 105 insertions, 24 deletions
diff --git a/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence2.java b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence2.java
index 19ffd49..78ff513 100644
--- a/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence2.java
+++ b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence2.java
@@ -1,30 +1,24 @@
package dev.mayaqq.ygasi.abilities.mercenary;
import dev.mayaqq.ygasi.util.AdvUtils;
-import net.minecraft.entity.Entity;
-import net.minecraft.entity.EntityData;
-import net.minecraft.entity.EntityType;
-import net.minecraft.entity.SpawnReason;
+import net.minecraft.entity.EntityPose;
import net.minecraft.entity.decoration.ArmorStandEntity;
-import net.minecraft.entity.mob.MobEntity;
-import net.minecraft.nbt.NbtCompound;
-import net.minecraft.server.command.SummonCommand;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
-import net.minecraft.util.math.Vec3d;
-import net.minecraft.world.World;
+import net.minecraft.util.math.EulerAngle;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
public class Offence2 {
public static Map<String, ArrayList<String>> playerSwords = new HashMap<>();
+ public static Map<String, ArrayList<String>> playerSwordsBlacklist = new HashMap<>();
+
public static void give(ServerPlayerEntity player) {
if (!AdvUtils.getAdvancementProgress(player, "ygasi", "mercenary/offence2")) {
AdvUtils.grantAdvancementCriterion(player, new Identifier("ygasi", "mercenary/offence2"), "unlocked_offence2");
@@ -38,10 +32,14 @@ public class Offence2 {
public static void summonStand(ServerPlayerEntity player, Integer sword) {
BlockPos pos = player.getBlockPos();
ServerWorld world = player.getWorld();
- ArmorStandEntity armorStand = new ArmorStandEntity(world, pos.getX(), pos.getY(), pos.getZ());
+ ArmorStandEntity armorStand = new ArmorStandEntity(world, pos.getX(), pos.getY() - 1, pos.getZ());
armorStand.setCustomName(Text.of(armorStand.getUuidAsString()));
- armorStand.setCustomNameVisible(true);
armorStand.setStackInHand(Hand.MAIN_HAND, player.getMainHandStack());
+ armorStand.setInvisible(true);
+ armorStand.setNoGravity(true);
+ armorStand.setNoDrag(true);
+ armorStand.setInvulnerable(true);
+ armorStand.setRightArmRotation(new EulerAngle(0F, 270F, 270F));
if (playerSwords.get(player.getUuidAsString()) != null) {
playerSwords.get(player.getUuidAsString()).add(armorStand.getUuidAsString());
} else {
diff --git a/src/main/java/dev/mayaqq/ygasi/events/PlayerConnectEvent.java b/src/main/java/dev/mayaqq/ygasi/events/PlayerConnectEvent.java
index 6723d01..19649cc 100644
--- a/src/main/java/dev/mayaqq/ygasi/events/PlayerConnectEvent.java
+++ b/src/main/java/dev/mayaqq/ygasi/events/PlayerConnectEvent.java
@@ -8,6 +8,7 @@ import net.minecraft.item.ItemStack;
import java.util.UUID;
import static dev.mayaqq.ygasi.abilities.mercenary.Offence2.playerSwords;
+import static dev.mayaqq.ygasi.events.TickEvent.swords;
import static dev.mayaqq.ygasi.registry.ItemRegistry.SKILL_BOOK;
public class PlayerConnectEvent {
@@ -28,6 +29,7 @@ public class PlayerConnectEvent {
sword.remove(Entity.RemovalReason.DISCARDED);
});
playerSwords.remove(handler.player.getUuidAsString());
+ swords.remove(handler.player.getUuidAsString());
}
});
}
diff --git a/src/main/java/dev/mayaqq/ygasi/events/ClickEvent.java b/src/main/java/dev/mayaqq/ygasi/events/TickEvent.java
index c735fa4..ae6fc76 100644
--- a/src/main/java/dev/mayaqq/ygasi/events/ClickEvent.java
+++ b/src/main/java/dev/mayaqq/ygasi/events/TickEvent.java
@@ -15,8 +15,9 @@ import java.util.UUID;
import static dev.mayaqq.ygasi.Ygasi.LOGGER;
import static dev.mayaqq.ygasi.abilities.mercenary.Offence2.playerSwords;
+import static dev.mayaqq.ygasi.abilities.mercenary.Offence2.playerSwordsBlacklist;
-public class ClickEvent {
+public class TickEvent {
public static Map<String, Integer> playerCharge = new HashMap<>();
public static Map<String, Integer> swords = new HashMap<>();
private static Integer tick = 0;
@@ -24,9 +25,9 @@ public class ClickEvent {
ServerTickEvents.END_SERVER_TICK.register(server -> {
tick++;
server.getPlayerManager().getPlayerList().forEach(player -> {
- if (playerSwords.get(player.getUuidAsString()) != null && player.getWorld().getEntity(UUID.fromString(playerSwords.get(player.getUuidAsString()).get(0))) != null) {
+ if (playerSwords.get(player.getUuidAsString()) != null && playerSwordsBlacklist.get(player.getUuidAsString()) == null) {
playerSwords.get(player.getUuidAsString()).forEach(uuid -> {
- player.getWorld().getEntity(UUID.fromString(uuid)).setPos(player.getX(), player.getY(), player.getZ());
+ player.getWorld().getEntity(UUID.fromString(uuid)).setPos(player.getX(), player.getY() + 2, player.getZ());
});
}
if (tick == 20) {
@@ -38,7 +39,7 @@ public class ClickEvent {
playerCharge.remove(player.getUuidAsString());
swords.put(player.getUuidAsString(), swords.getOrDefault(player.getUuidAsString(), 0) + 1);
- Offence2.summonStand((ServerPlayerEntity) player, swords.get(player.getUuidAsString()));
+ Offence2.summonStand(player, swords.get(player.getUuidAsString()));
player.playSound(SoundEvent.of(new Identifier("entity.experience_orb.pickup")), SoundCategory.PLAYERS, 1.0F, 1.0F);
LOGGER.info("Sword charge: " + swords.get(player.getUuidAsString()));
} else {
diff --git a/src/main/java/dev/mayaqq/ygasi/mixin/ItemMixin.java b/src/main/java/dev/mayaqq/ygasi/mixin/ItemMixin.java
index f89d7c6..8cfbe8b 100644
--- a/src/main/java/dev/mayaqq/ygasi/mixin/ItemMixin.java
+++ b/src/main/java/dev/mayaqq/ygasi/mixin/ItemMixin.java
@@ -1,27 +1,107 @@
package dev.mayaqq.ygasi.mixin;
-import dev.mayaqq.ygasi.events.ClickEvent;
+import dev.mayaqq.ygasi.events.TickEvent;
+import dev.mayaqq.ygasi.util.Multithreading;
+import net.minecraft.block.Block;
+import net.minecraft.block.Blocks;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.damage.DamageSource;
+import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;
+import net.minecraft.server.network.ServerPlayerEntity;
+import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
+import net.minecraft.util.math.BlockPos;
+import net.minecraft.util.math.EulerAngle;
+import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
+import org.slf4j.Logger;
+import org.spongepowered.asm.mixin.Final;
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.CallbackInfoReturnable;
-import static dev.mayaqq.ygasi.Ygasi.LOGGER;
+import java.util.ArrayList;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+
+import static dev.mayaqq.ygasi.abilities.mercenary.Offence2.playerSwords;
+import static dev.mayaqq.ygasi.abilities.mercenary.Offence2.playerSwordsBlacklist;
@Mixin(Item.class)
public class ItemMixin {
+ @Shadow @Final private static Logger LOGGER;
+
@Inject(method = "use", at = @At("HEAD"))
private void injectRightClickBehavior(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> cir) {
- if (user.getMainHandStack().getItem() instanceof SwordItem && ClickEvent.swords.getOrDefault(user.getUuidAsString(), 0) >= 1) {
- LOGGER.info("Player " + user.getEntityName() + " launched " + ClickEvent.swords.get(user.getUuidAsString()) + " swords!");
- ClickEvent.swords.remove(user.getUuidAsString());
+ if (user.getMainHandStack().getItem() instanceof SwordItem && TickEvent.swords.getOrDefault(user.getUuidAsString(), 0) >= 1) {
+ LOGGER.info("Player " + user.getEntityName() + " launched " + TickEvent.swords.get(user.getUuidAsString()) + " swords!");
+ ArrayList<String> swords = new ArrayList<>();
+ playerSwords.get(user.getUuidAsString()).forEach(uuid -> {
+ ServerPlayerEntity player = (ServerPlayerEntity) user;
+ ArmorStandEntity sword = (ArmorStandEntity) player.getWorld().getEntity(UUID.fromString(uuid));
+ swords.add(uuid);
+ float yaw = player.getYaw(1);
+ float pitch = player.getPitch(1);
+ yaw = (float) (yaw - Math.PI);
+ pitch = (float) (pitch + Math.PI / 2);
+ sword.setRightArmRotation(new EulerAngle(pitch, yaw, sword.getRightArmRotation().getRoll()));
+ Multithreading.schedule(() -> {
+ playerSwordsBlacklist.put(player.getUuidAsString(), swords);
+ ServerWorld serverWorld = (ServerWorld) world;
+ boolean isAir = true;
+ while (isAir) {
+ Vec3d rotation = player.getRotationVec(1.0f);
+ sword.setPos(sword.getX() + rotation.x, sword.getY() + rotation.y, sword.getZ() + rotation.z);
+ BlockPos[] relativeBlockPositions = {new BlockPos(1, 1.5F, 0), new BlockPos(-1, 1.5F, 0), new BlockPos(0, 1.5F, 1), new BlockPos(0, 1.5F, -1)};
+ BlockPos pos = sword.getBlockPos();
+ boolean hitTarget = true;
+ for (BlockPos relativeBlockPos : relativeBlockPositions) {
+ BlockPos blockPos = pos.add(relativeBlockPos);
+ Block block = sword.world.getBlockState(blockPos).getBlock();
+ if(block != Blocks.AIR) {
+ LOGGER.info("Sword hit a block!");
+ hitTarget = onHit(serverWorld, player, sword, hitTarget);
+ isAir = false;
+ }
+ double entityCheckRadius = 1;
+ for (PlayerEntity pl : world.getPlayers()) {
+ if (pl.distanceTo(sword) <= entityCheckRadius && pl != player && pl.getScoreboardTeam() != player.getScoreboardTeam()) {
+ LOGGER.info("Sword hit a player!");
+ //create an explosion at the position of the sword
+ hitTarget = onHit(serverWorld, player, sword, hitTarget);
+ isAir = false;
+ }
+ }
+ }
+ try {
+ Thread.sleep(30);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ }, 1, TimeUnit.SECONDS);
+ });
+ Multithreading.schedule(() -> {
+ playerSwords.remove(user.getUuidAsString());
+ TickEvent.swords.remove(user.getUuidAsString());
+ playerSwordsBlacklist.remove(user.getUuidAsString());
+ }, 2, TimeUnit.SECONDS);
+ }
+ }
+ public boolean onHit(ServerWorld world, ServerPlayerEntity player, ArmorStandEntity sword, Boolean hitTraget) {
+ if (hitTraget) {
+ world.createExplosion(player, DamageSource.player(player), null, sword.getX(), sword.getY(), sword.getZ(), 10, false, World.ExplosionSourceType.MOB, false);
+ sword.remove(Entity.RemovalReason.DISCARDED);
+ return false;
}
+ return true;
}
}
diff --git a/src/main/java/dev/mayaqq/ygasi/mixin/PlayerEntityMixin.java b/src/main/java/dev/mayaqq/ygasi/mixin/PlayerEntityMixin.java
index a9687b1..f0efc1d 100644
--- a/src/main/java/dev/mayaqq/ygasi/mixin/PlayerEntityMixin.java
+++ b/src/main/java/dev/mayaqq/ygasi/mixin/PlayerEntityMixin.java
@@ -22,7 +22,7 @@ public abstract class PlayerEntityMixin {
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, "ygasi", "mercenary/offence1")) {
+ if (!attackList.containsKey(player.getUuidAsString() + target.getUuidAsString()) && AdvUtils.getAdvancementProgress(player, "ygasi", "mercenary/offence1") && !target.isInvulnerable()) {
attackList.put(player.getUuidAsString() + target.getUuidAsString(), true);
StatusEffectInstance currentEffect = player.getStatusEffect(StatusEffects.STRENGTH);
int currentLevel = currentEffect != null ? currentEffect.getAmplifier() : 0;
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/EventRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/EventRegistry.java
index 66b6be2..2edb22e 100644
--- a/src/main/java/dev/mayaqq/ygasi/registry/EventRegistry.java
+++ b/src/main/java/dev/mayaqq/ygasi/registry/EventRegistry.java
@@ -1,12 +1,12 @@
package dev.mayaqq.ygasi.registry;
-import dev.mayaqq.ygasi.events.ClickEvent;
+import dev.mayaqq.ygasi.events.TickEvent;
import dev.mayaqq.ygasi.events.PlayerConnectEvent;
public class EventRegistry {
public static void register() {
PlayerConnectEvent.onPlayerConnect();
PlayerConnectEvent.onPlayerDisconnect();
- ClickEvent.onTick();
+ TickEvent.onTick();
}
}