From b425e4080aec8b80cfcef4198ef36383cd564c00 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Wed, 23 Oct 2024 02:02:55 -0400 Subject: [PATCH 01/31] init --- .../magus/input/KeyboardMouseInputModule.java | 7 +- .../test/avatar/TestProjectileEntity.java | 255 ++++++++++++++++-- 2 files changed, 242 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java b/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java index d0141f2..857c6b3 100644 --- a/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java +++ b/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java @@ -6,7 +6,6 @@ import com.amuzil.omegasource.magus.radix.*; import com.amuzil.omegasource.magus.skill.conditionals.InputData; import com.amuzil.omegasource.magus.skill.elements.Discipline; -import com.amuzil.omegasource.magus.skill.elements.Disciplines; import com.amuzil.omegasource.magus.skill.forms.Form; import com.amuzil.omegasource.magus.skill.forms.FormDataRegistry; import com.amuzil.omegasource.magus.skill.forms.Forms; @@ -190,12 +189,12 @@ public KeyboardMouseInputModule() { if (activeForm.get().name().equals("force")) resource = new ResourceLocation(Magus.MOD_ID, "blue_fire"); ServerLevel level = event.getServer().getAllLevels().iterator().next(); - System.out.println("LEVEL: " + level); +// System.out.println("LEVEL: " + level); if (!level.isClientSide && resource != null) { - c = 20; + c = 5; Player player = Minecraft.getInstance().player; assert player != null; - TestProjectileEntity element = new TestProjectileEntity(level, player); + TestProjectileEntity element = new TestProjectileEntity(player, level); // element.shootFromRotation(player, player.getXRot(), player.getYRot(), 0.0F, 1.5F, 1.0F); element.shoot(player.getViewVector(1).x, player.getViewVector(1).y, player.getViewVector(1).z, 2, 1); level.addFreshEntity(element); diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java index aca938c..9cc26b3 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java @@ -1,34 +1,251 @@ package com.amuzil.omegasource.magus.skill.test.avatar; +import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.monster.Blaze; -import net.minecraft.world.entity.projectile.AbstractArrow; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.ItemSupplier; +import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.EntityHitResult; -import net.minecraft.world.phys.HitResult; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.gameevent.GameEvent; +import net.minecraft.world.phys.*; +import net.minecraft.world.phys.shapes.VoxelShape; +import javax.annotation.Nullable; +import java.util.Optional; +import java.util.function.Predicate; -public class TestProjectileEntity extends AbstractArrow implements ItemSupplier { + +public class TestProjectileEntity extends Projectile implements ItemSupplier { public static final ItemStack PROJECTILE_ITEM = new ItemStack(Blocks.AIR); + private static final EntityDataAccessor ID_FLAGS = SynchedEntityData.defineId(TestProjectileEntity.class, EntityDataSerializers.BYTE); + private static final EntityDataAccessor PIERCE_LEVEL = SynchedEntityData.defineId(TestProjectileEntity.class, EntityDataSerializers.BYTE); + private boolean leftOwner; + private boolean hasBeenShot; + private int life; public TestProjectileEntity(EntityType type, Level level) { super(type, level); + this.setNoGravity(true); + } + + public TestProjectileEntity(double x, double y, double z, Level level) { + this(AvatarEntities.TEST_PROJECTILE.get(), level); + this.setPos(x, y, z); + } + + public TestProjectileEntity(LivingEntity livingEntity, Level level) { + this(livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level); + this.setOwner(livingEntity); + } + + public void projectileTick() { + if (!this.hasBeenShot) { + this.gameEvent(GameEvent.PROJECTILE_SHOOT, this.getOwner()); + this.hasBeenShot = true; + } + + if (!this.leftOwner) { + this.leftOwner = this.checkLeftOwner(); + } + + super.tick(); + } + + public void tick() { + this.projectileTick(); + boolean flag = this.isNoPhysics(); + Vec3 deltaMovement = this.getDeltaMovement(); + if (this.xRotO == 0.0F && this.yRotO == 0.0F) { + double distance = deltaMovement.horizontalDistance(); + this.setYRot((float)(Mth.atan2(deltaMovement.x, deltaMovement.z) * (double)(180F / (float)Math.PI))); + this.setXRot((float)(Mth.atan2(deltaMovement.y, distance) * (double)(180F / (float)Math.PI))); + this.yRotO = this.getYRot(); + this.xRotO = this.getXRot(); + } + + BlockPos blockpos = this.blockPosition(); + BlockState blockstate = this.level.getBlockState(blockpos); + if (!blockstate.isAir() && !flag) { + VoxelShape voxelshape = blockstate.getCollisionShape(this.level, blockpos); + if (!voxelshape.isEmpty()) { + Vec3 vec31 = this.position(); + + for(AABB aabb : voxelshape.toAabbs()) { + if (aabb.move(blockpos).contains(vec31)) { + break; + } + } + } + } + + if (this.isInWaterOrRain() || blockstate.is(Blocks.POWDER_SNOW) || this.isInFluidType((fluidType, height) -> this.canFluidExtinguish(fluidType))) { + this.clearFire(); + } + + Vec3 pos = this.position(); + Vec3 delta = pos.add(deltaMovement); + HitResult hitresult = this.level.clip(new ClipContext(pos, delta, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)); + if (hitresult.getType() != HitResult.Type.MISS) { + delta = hitresult.getLocation(); + } + + while(!this.isRemoved()) { + if (!this.level.isClientSide) { + this.tickDespawn(); + } + EntityHitResult entityhitresult = this.findHitEntity(pos, delta); + if (entityhitresult != null) { + hitresult = entityhitresult; + } + + if (hitresult != null && hitresult.getType() == HitResult.Type.ENTITY) { + assert hitresult instanceof EntityHitResult; + Entity entity = ((EntityHitResult)hitresult).getEntity(); + Entity owner = this.getOwner(); + if (entity instanceof Player && owner instanceof Player && !((Player)owner).canHarmPlayer((Player)entity)) { + hitresult = null; + entityhitresult = null; + } + } + + if (hitresult != null && hitresult.getType() != HitResult.Type.MISS && !flag) { + if (net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, hitresult)) + break; + this.onHit(hitresult); + this.hasImpulse = true; + } + + if (entityhitresult == null) { + break; + } + + hitresult = null; + } + deltaMovement = this.getDeltaMovement(); + double d5 = deltaMovement.x; + double d6 = deltaMovement.y; + double d1 = deltaMovement.z; + + double d7 = this.getX() + d5; + double d2 = this.getY() + d6; + double d3 = this.getZ() + d1; + double d4 = deltaMovement.horizontalDistance(); + if (flag) { + this.setYRot((float)(Mth.atan2(-d5, -d1) * (double)(180F / (float)Math.PI))); + } else { + this.setYRot((float)(Mth.atan2(d5, d1) * (double)(180F / (float)Math.PI))); + } + + this.setXRot((float)(Mth.atan2(d6, d4) * (double)(180F / (float)Math.PI))); + this.setXRot(lerpRotation(this.xRotO, this.getXRot())); + this.setYRot(lerpRotation(this.yRotO, this.getYRot())); + + float f = 0.99F; + this.setDeltaMovement(deltaMovement.scale((double)f)); + if (!this.isNoGravity() && !flag) { + Vec3 vec34 = this.getDeltaMovement(); + this.setDeltaMovement(vec34.x, vec34.y - (double)0.05F, vec34.z); + } + + this.setPos(d7, d2, d3); + this.checkInsideBlocks(); + } + + @Nullable + protected EntityHitResult findHitEntity(Vec3 pos, Vec3 delta) { + return getEntityHitResult(this.level, this, pos, delta, + this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(2.0D), + this::canHitEntity, 0.3F); + } + + @Nullable + public static EntityHitResult getEntityHitResult(Level level, Entity thisEntity, Vec3 pos, Vec3 delta, AABB thisAABB, Predicate canBeHit, float scale) { + double maxDist = Double.MAX_VALUE; + Entity entity = null; + + for(Entity otherEntity : level.getEntities(thisEntity, thisAABB, canBeHit)) { + System.out.println("ENTITY NEARBY: " + otherEntity); + AABB aabb = otherEntity.getBoundingBox().inflate(scale); + Optional optional = aabb.clip(pos, delta); + if (optional.isPresent()) { + double dist = pos.distanceToSqr(optional.get()); + if (dist < maxDist) { + entity = otherEntity; + maxDist = dist; + } + } + } + + return entity == null ? null : new EntityHitResult(entity); + } + + public boolean canHitEntity(Entity otherEntity) { + if (!otherEntity.canBeHitByProjectile()) { + return false; + } else { + Entity entity = this.getOwner(); +// if (entity != null) { +// if (otherEntity instanceof TestProjectileEntity other) { +// System.out.println("THIS OWNER: " + entity + " | " + !entity.isPassengerOfSameVehicle(otherEntity)); +// System.out.println("THAT OWNER: " + other.getOwner()); +// } +// } + return entity == null || this.leftOwner || !entity.isPassengerOfSameVehicle(otherEntity); + } + } + + protected void tickDespawn() { + ++this.life; + if (this.life >= 600) { + System.out.println("BYE BYE BBY"); + this.discard(); + } } - public TestProjectileEntity(Level Level, LivingEntity livingEntity) { - super(AvatarEntities.TEST_PROJECTILE.get(), livingEntity, Level); + @Override + public boolean isPickable() { + return true; + } + + @Override + protected void defineSynchedData() { + this.entityData.define(ID_FLAGS, (byte)0); + this.entityData.define(PIERCE_LEVEL, (byte)0); + } + + private boolean checkLeftOwner() { + Entity owner = this.getOwner(); + if (owner != null) { + for(Entity entity1 : this.level.getEntities(this, this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(1.0D), (entity) -> { + return !entity.isSpectator() && entity.isPickable(); + })) { + if (entity1.getRootVehicle() == owner.getRootVehicle()) { + return false; + } + } + } + return true; } - public TestProjectileEntity(Level Level, double x, double y, double z) { - super(AvatarEntities.TEST_PROJECTILE.get(), x, y, z, Level); + public boolean isNoPhysics() { + if (!this.level.isClientSide) { + return this.noPhysics; + } else { + return (this.entityData.get(ID_FLAGS) & 2) != 0; + } } public void handleEntityEvent(byte data) { @@ -40,15 +257,21 @@ public void handleEntityEvent(byte data) { } protected void onHitEntity(EntityHitResult entityHitResult) { -// super.onHitEntity(entityHitResult); Entity entity = entityHitResult.getEntity(); if (entity instanceof Blaze) { if (this.getOwner() != null) { this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); } - } else { - int i = 15; // Deal 15 damage + } else if (entity instanceof TestProjectileEntity) { + System.out.println("SUCCESS MADE IT HIT!!!"); + if (this.getOwner() != null) { + this.discard(); // kys asap +// this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); + } + } else { + int i = 10; // Deal 10 damage entity.hurt(this.damageSources().thrown(this, this.getOwner()), (float)i); + this.discard(); } } @@ -69,10 +292,10 @@ private ParticleOptions getParticle() { return ParticleTypes.FLAME; } - @Override - protected ItemStack getPickupItem() { - return PROJECTILE_ITEM; - } +// @Override +// protected ItemStack getPickupItem() { +// return PROJECTILE_ITEM; +// } @Override public ItemStack getItem() { From 880f029c2416b3f66bd09462f28f665c2629b0e8 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Wed, 23 Oct 2024 02:04:32 -0400 Subject: [PATCH 02/31] Update TestProjectileEntity.java --- .../magus/skill/test/avatar/TestProjectileEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java index 9cc26b3..a170602 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java @@ -209,7 +209,7 @@ public boolean canHitEntity(Entity otherEntity) { protected void tickDespawn() { ++this.life; - if (this.life >= 600) { + if (this.life >= 200) { System.out.println("BYE BYE BBY"); this.discard(); } From 2c3e9e95382f6620712a26930a0fe4817cb410c5 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Wed, 23 Oct 2024 02:54:21 -0400 Subject: [PATCH 03/31] collision working lowkey --- .../skill/test/avatar/TestProjectileEntity.java | 9 +++++++++ src/main/resources/assets/magus/fx/orb_bloom.fx | Bin 0 -> 2393 bytes 2 files changed, 9 insertions(+) create mode 100644 src/main/resources/assets/magus/fx/orb_bloom.fx diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java index a170602..1be5da0 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java @@ -1,11 +1,16 @@ package com.amuzil.omegasource.magus.skill.test.avatar; +import com.amuzil.omegasource.magus.Magus; +import com.lowdragmc.photon.client.fx.EntityEffect; +import com.lowdragmc.photon.client.fx.FX; +import com.lowdragmc.photon.client.fx.FXHelper; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; @@ -126,6 +131,7 @@ public void tick() { break; this.onHit(hitresult); this.hasImpulse = true; + break; } if (entityhitresult == null) { @@ -265,6 +271,9 @@ protected void onHitEntity(EntityHitResult entityHitResult) { } else if (entity instanceof TestProjectileEntity) { System.out.println("SUCCESS MADE IT HIT!!!"); if (this.getOwner() != null) { + FX fx = FXHelper.getFX(new ResourceLocation(Magus.MOD_ID, "orb_bloom")); + EntityEffect entityEffect = new EntityEffect(fx, level, entity); + entityEffect.start(); this.discard(); // kys asap // this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); } diff --git a/src/main/resources/assets/magus/fx/orb_bloom.fx b/src/main/resources/assets/magus/fx/orb_bloom.fx new file mode 100644 index 0000000000000000000000000000000000000000..a93ad863d40dab32fd77ad6805ae8d586332cab7 GIT binary patch literal 2393 zcmV-f38wZRiwFP!00000|Lt2{XdTBDp7qt$y>}&BR&AH0LZH(!E+)v7{??7tCmPXU?8EbIv#Ce4eW#R6|wbQXvTAIznhbL&KEM zh4ty^A*!MQ54!{nT9jE1siN|NXaxjS1Iz@4Cpx_Hy#`&>QI!$TCXBEu(xX2w`Zhte z3FW=Tb(~SnP1n63Ja0`?knrGPKPG}KNfQ%tdSIIb>T+PZ5i{*x}m7Zs`|} zffUz%y*pp*_Hz;tY&_{QVZY6wF|h8V3<1KdB<*0TQn~( z6E-iOl#`(y6K)SJqf;*Rs2jRh2@_;xipu8}IeX_l9sJOt4I-#ZvKnYz#AxWabcS)| zKKz)CQKs_2-_#kdnR@p)_spP_-TPtRV4$DCQ&$EC}c zrU4crub+^^VMQZ3=R?mzrSYk$NZ6z_WIXBwj9R$((xoeN3v;uR3*#4NUL22PXM5Gs zcPN?lJmEsqB3P4wev*1k&|b{M=%|Kk?J(5PiHyf3-UR+!W-@N2xxp#H$k(W7CPFw; z;Va-alGlL`C2)cD_1B(-w!Xf8`gCg5p#&db2RSn#Elw=}x8rpmT#w8Jj9^=8pO2rz(U8feM74Yv zYomN+k>O=3ayKs6=bM;=Z#Yz%MFUee7`3G3+u*zU{)=6;(p2kM2|7TLr0WR33kgrM3!1n@AW$7WK1oCe2Z5u zt8`%4CJhWDu3{%7QXl}6VW;pKOMT*6m1{XB(}*wyda-v1&nkD8NSro zR#%yu$EiW$3{Y9QYBQRNfvN-OT!=y%IIUcKg=hco$G zEazvFjDDgOzeA2Zcjahz$#RrxD5al!7YbXrj{15{gt@oTQpkm+1PMG9UFx>fW-f z|6rcXo^QfPfKB`CJxehC9zXgZ~9@Tyt>cvFX5>xViCL^_ij4a5= zf{ZN4$o?fGwTD7Rrf$9dHp_0L56(IoA3eqn2)_7ddd9emERk$zhInQ8og(J z>0i%2|BVlKhue&NY8SZ815`oFQGLT#4p=@b&P^6nWkFRIROMj<+Jkj&vQ1UO^{J>z zGqcq4O1x$;^?@GV(;*@2Fo_pM66$~ZKuH+*)~(&5Fdyc@$^4RIE3Q%!L<&)V)@T%5 zWpSReI8WK{TxD^dvcJz$YH?m#LzT$mPj|Y!yrj!3_Xn3Z?!W$tDpaBE9yzg`uXM^e z`>J(c1eEapu(nLP7ft>niXVs zwR3Sm^w3bAy{q^Ry1CnbgcVF^-!Y*_)MoMgiO>C3Z90D}( zx520yyYW->9zt^%)dWztK0sP9ss*E3FscQkS}>})jOzZSrH7n=JQ5R-M|Ma+YFiPI z4}e+nl9*+{mZ>o7%$YNrFl$6fAM-){Si&$+4`pF%=dAX*E}(T-7}A{|BE5%-L!`UN zs6JCLst1!%&0>~pjU?ZSeMxmnPoX>tptcqzV~MlH8XZJN^$R_JT(5}1f?M4Nw~GD; Lx8DL9{8In`bJ?4j literal 0 HcmV?d00001 From 93f8ae92c693b0235c254224245805fd83631bcc Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Wed, 23 Oct 2024 15:00:05 -0400 Subject: [PATCH 04/31] Update TestProjectileEntity.java --- .../magus/skill/test/avatar/TestProjectileEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java index 1be5da0..19f94ea 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java @@ -215,7 +215,7 @@ public boolean canHitEntity(Entity otherEntity) { protected void tickDespawn() { ++this.life; - if (this.life >= 200) { + if (this.life >= 150) { System.out.println("BYE BYE BBY"); this.discard(); } From 4e346f1525aac576ca1e553a54f5b277beab4d3d Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Wed, 23 Oct 2024 15:29:55 -0400 Subject: [PATCH 05/31] fix runServer error --- .../com/amuzil/omegasource/magus/Magus.java | 33 +++++-------------- .../omegasource/magus/input/InputModule.java | 33 +++++++++++-------- .../skill/test/avatar/AvatarCommand.java | 4 +-- 3 files changed, 30 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/Magus.java b/src/main/java/com/amuzil/omegasource/magus/Magus.java index 2dfbfe2..05c6b1e 100644 --- a/src/main/java/com/amuzil/omegasource/magus/Magus.java +++ b/src/main/java/com/amuzil/omegasource/magus/Magus.java @@ -47,11 +47,6 @@ public class Magus { public static InputModule mouseMotionModule; public Magus() { - // Register ourselves for server and other game events we are interested in - MinecraftForge.EVENT_BUS.register(this); - //Register the input modules - keyboardMouseInputModule = new KeyboardMouseInputModule(); - mouseMotionModule = new MouseMotionModule(); // Register capabilities FMLJavaModLoadingContext.get().getModEventBus().addListener(CapabilityHandler::registerCapabilities); // attach capabilities @@ -65,6 +60,9 @@ public Magus() { // Register the doClientStuff method for mod loading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); + // Register ourselves for server and other game events we are interested in + MinecraftForge.EVENT_BUS.register(this); + // Register Testing Entities // NOTE: This is strictly for testing and to be deleted later AvatarEntities.register(FMLJavaModLoadingContext.get().getModEventBus()); @@ -80,8 +78,11 @@ private void setup(final FMLCommonSetupEvent event) { private void doClientStuff(final FMLClientSetupEvent event) { // do something that can only be done on the client - //todo call this anytime the key mappings are updated - //Assign input data to forms + // Register the input modules + keyboardMouseInputModule = new KeyboardMouseInputModule(); + mouseMotionModule = new MouseMotionModule(); + // TODO - call this anytime the key mappings are updated + // Assign input data to forms FormDataRegistry.init(); ModifiersRegistry.init(); } @@ -124,22 +125,4 @@ public static void onClientSetup(FMLClientSetupEvent event) { LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName()); } } - - // Send a message to in-game chat - public static void sendDebugMsg(String msg) { - Minecraft minecraft = Minecraft.getInstance(); - if (minecraft == null) { - System.err.println("sendDebugMsg failed: Minecraft instance is null"); - return; - } - minecraft.execute(() -> { - LocalPlayer player = minecraft.player; - if (player != null) { - Component text = Component.literal(msg); - player.sendSystemMessage(text); - } else { - System.err.println("sendDebugMsg failed: player is null"); - } - }); - } } diff --git a/src/main/java/com/amuzil/omegasource/magus/input/InputModule.java b/src/main/java/com/amuzil/omegasource/magus/input/InputModule.java index 8db8c64..46d4ffb 100644 --- a/src/main/java/com/amuzil/omegasource/magus/input/InputModule.java +++ b/src/main/java/com/amuzil/omegasource/magus/input/InputModule.java @@ -17,7 +17,9 @@ import com.mojang.blaze3d.platform.InputConstants; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; +import net.minecraft.client.player.LocalPlayer; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; import net.minecraftforge.client.event.InputEvent; import org.apache.logging.log4j.LogManager; @@ -38,6 +40,24 @@ public abstract class InputModule { public boolean resetScrolling; protected AtomicReference
lastActivatedForm = new AtomicReference<>(Forms.NULL); + // Send a message to in-game chat + public static void sendDebugMsg(String msg) { + Minecraft minecraft = Minecraft.getInstance(); + if (minecraft == null) { + System.err.println("sendDebugMsg failed: Minecraft instance is null"); + return; + } + minecraft.execute(() -> { + LocalPlayer player = minecraft.player; + if (player != null) { + Component text = Component.literal(msg); + player.sendSystemMessage(text); + } else { + System.err.println("sendDebugMsg failed: player is null"); + } + }); + } + public static EventCondition keyToCondition(InputConstants.Key key, int actionCondition) { if (key.getType().equals(InputConstants.Type.MOUSE)) { return new EventCondition<>(InputEvent.MouseButton.class, @@ -140,19 +160,6 @@ public void resetConditions() { } } -// private Form checkForForm() { -// if (!activeConditions.isEmpty()) { -// List conditions = activeConditions.stream().toList(); -// List recognized = formsTree.search(conditions); -// if (recognized != null) { -// return FormDataRegistry.formsNamespace.get(recognized.hashCode()); -// System.out.println("RECOGNIZED FORM: " + activeForm.name() + " " + recognized); -// Magus.sendDebugMsg("RECOGNIZED FORM: " + activeForm.name()); -// } -// } -// return new Form(); -// } - public void init() { resetKeys(); registerInputs(); diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java index a071071..06eee37 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java @@ -26,7 +26,7 @@ public static void register(CommandDispatcher dispatcher) { .executes(c -> tree()) ) .executes(c -> { - Magus.sendDebugMsg("Possible modes: record, tree, reset"); + InputModule.sendDebugMsg("Possible modes: record, tree, reset"); return 1; }) ); @@ -53,7 +53,7 @@ private static int reset() { InputModule.resetFormsTree(); AvatarFormRegistry.registerForms(); kim.registerRunnables(Magus.keyboardMouseInputModule.getFormsTree()); - Magus.sendDebugMsg("Reset Forms RadixTree"); + InputModule.sendDebugMsg("Reset Forms RadixTree"); return 1; } } \ No newline at end of file From 399710176e21326c67bdc54bc2d7c01e5a4cb869 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Wed, 23 Oct 2024 15:31:16 -0400 Subject: [PATCH 06/31] comment out unnecessary code --- .../omegasource/magus/server/ServerEvents.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/server/ServerEvents.java b/src/main/java/com/amuzil/omegasource/magus/server/ServerEvents.java index c592fb1..eb2fa31 100644 --- a/src/main/java/com/amuzil/omegasource/magus/server/ServerEvents.java +++ b/src/main/java/com/amuzil/omegasource/magus/server/ServerEvents.java @@ -34,13 +34,13 @@ public static void onEntityJoinLevel(EntityJoinLevelEvent event) { // initialise the radix tree and set the player as an instance property for sending packets. //todo this is temporary manual tree construction for testing purposes. the true tree will be // generated at runtime based on available skills for the player/entity. - Node secondNode = NodeBuilder.middle() - .addModifiers(ModifiersRegistry.FOCUS.copy(), ModifiersRegistry.MULTI.copy(), - ModifiersRegistry.DIRECTION.copy(), ModifiersRegistry.TARGET.copy()) - .build(); - //Resets the tree; for testing purposes. - if (capability.getTree() != null) - capability.getTree().burn(); +// Node secondNode = NodeBuilder.middle() +// .addModifiers(ModifiersRegistry.FOCUS.copy(), ModifiersRegistry.MULTI.copy(), +// ModifiersRegistry.DIRECTION.copy(), ModifiersRegistry.TARGET.copy()) +// .build(); +// //Resets the tree; for testing purposes. +// if (capability.getTree() != null) +// capability.getTree().burn(); // TODO: Need a way to convert forms into conditions // Need to test out the condition tree. use left alt/arc > strike (left click). // While this test code will directly use conditions, Skills will reference Forms @@ -81,7 +81,7 @@ public static void onEntityJoinLevel(EntityJoinLevelEvent event) { // // Condition arc2 = new FormCondition(Forms.ARC, -1, Magus.keyboardInputModule); // arc2.register("ARC", () -> { -// Magus.sendDebugMsg("ARC FORM TRIGGERED"); +// Magus.keyboardMouseInputModule.sendDebugMsg("ARC FORM TRIGGERED"); // }, () -> {}); // // System.out.println("Test RadixTree"); @@ -121,7 +121,7 @@ public static void onEntityJoinLevel(EntityJoinLevelEvent event) { System.out.println("All RadixTree Branches:"); Magus.keyboardMouseInputModule.getFormsTree().printAllBranches(); Magus.keyboardMouseInputModule.init(); - Magus.keyboardMouseInputModule.registerModifiers(); +// Magus.keyboardMouseInputModule.registerModifiers(); Magus.mouseMotionModule.init(); } } From b06d17a3dc8b5dcc8a9316f85781cdef7db21e55 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Wed, 23 Oct 2024 15:38:36 -0400 Subject: [PATCH 07/31] Update TestProjectileEntity.java --- .../magus/skill/test/avatar/TestProjectileEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java index 19f94ea..c49509b 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java @@ -215,7 +215,7 @@ public boolean canHitEntity(Entity otherEntity) { protected void tickDespawn() { ++this.life; - if (this.life >= 150) { + if (this.life >= 100) { System.out.println("BYE BYE BBY"); this.discard(); } From 97c205eaaa82d1dfa4f381c61031105deb441105 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Wed, 23 Oct 2024 15:42:34 -0400 Subject: [PATCH 08/31] refactor sendDebugMsg method --- .../magus/input/KeyboardMouseInputModule.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java b/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java index 857c6b3..62e5f46 100644 --- a/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java +++ b/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java @@ -157,10 +157,10 @@ public KeyboardMouseInputModule() { lastActivatedForm.set(activeForm.get()); // Extra check for race conditions. Probably wont' help... -// synchronized (lastActivatedForm.get()) { -// if (!lastActivatedForm.get().name().equals("null")) -// Magus.sendDebugMsg("Form Activated: " + lastActivatedForm.get().name()); -// } + synchronized (lastActivatedForm.get()) { + if (!lastActivatedForm.get().name().equals("null")) + sendDebugMsg("Form Activated: " + lastActivatedForm.get().name()); + } activeForm.set(Forms.NULL); ticksSinceActivated.set(0); timeout.set(0); @@ -225,7 +225,7 @@ private void checkForForm() { if (recognized != null) { activeForm.set(FormDataRegistry.formsNamespace.get(recognized.hashCode())); // System.out.println("RECOGNIZED FORM: " + activeForm.name() + " " + recognized); -// Magus.sendDebugMsg("RECOGNIZED FORM: " + activeForm.name()); +// sendDebugMsg("RECOGNIZED FORM: " + activeForm.name()); } } } From 5769e30e6b406b25f327c3e46758705759ebc5b3 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Wed, 23 Oct 2024 15:55:48 -0400 Subject: [PATCH 09/31] Update ServerEvents.java --- .../java/com/amuzil/omegasource/magus/server/ServerEvents.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/amuzil/omegasource/magus/server/ServerEvents.java b/src/main/java/com/amuzil/omegasource/magus/server/ServerEvents.java index eb2fa31..eab4002 100644 --- a/src/main/java/com/amuzil/omegasource/magus/server/ServerEvents.java +++ b/src/main/java/com/amuzil/omegasource/magus/server/ServerEvents.java @@ -130,6 +130,9 @@ public static void onEntityJoinLevel(EntityJoinLevelEvent event) { @SubscribeEvent public static void OnPlayerLeaveWorld(EntityLeaveLevelEvent event) { if (event.getEntity() instanceof Player) { + // TODO - Causes whole server to crash when player leaves + // java.lang.NullPointerException: Cannot invoke "com.amuzil.omegasource.magus.input.InputModule.getFormsTree()" + // because "com.amuzil.omegasource.magus.Magus.keyboardMouseInputModule" is null Magus.keyboardMouseInputModule.getFormsTree().deactivateAllConditions(); Magus.keyboardMouseInputModule.terminate(); Magus.mouseMotionModule.terminate(); From 71b61af21a0e6d4275a0e85834cf8e75449db902 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Fri, 25 Oct 2024 03:11:18 -0400 Subject: [PATCH 10/31] run multiple clients with dif users --- build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle b/build.gradle index 38b3b7d..5aeda25 100644 --- a/build.gradle +++ b/build.gradle @@ -88,6 +88,8 @@ minecraft { client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id + // Set custom username + jvmArgs += ["--username", "Dev####"] } server { From 7ef6106fdc2ac54d6c3dfe251167d9019b36a403 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Fri, 25 Oct 2024 03:11:59 -0400 Subject: [PATCH 11/31] multiplayer fx working! stable so far --- .../com/amuzil/omegasource/magus/Magus.java | 4 +- .../magus/input/KeyboardMouseInputModule.java | 24 +++--- .../magus/network/MagusNetwork.java | 8 ++ .../network/packets/api/MagusPacket.java | 6 +- .../client_executed/FormActivatedPacket.java | 77 ++++++++++++++++--- .../radix/condition/MultiClientCondition.java | 2 +- .../magus/registry/Registries.java | 9 ++- .../magus/server/ServerEvents.java | 13 +++- .../omegasource/magus/skill/forms/Form.java | 1 + .../skill/test/avatar/AvatarFormRegistry.java | 7 ++ .../test/avatar/TestProjectileEntity.java | 13 +++- 11 files changed, 130 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/Magus.java b/src/main/java/com/amuzil/omegasource/magus/Magus.java index 05c6b1e..da3c8bb 100644 --- a/src/main/java/com/amuzil/omegasource/magus/Magus.java +++ b/src/main/java/com/amuzil/omegasource/magus/Magus.java @@ -9,11 +9,14 @@ import com.amuzil.omegasource.magus.skill.test.avatar.AvatarCommand; import com.amuzil.omegasource.magus.skill.test.avatar.AvatarEntities; import com.amuzil.omegasource.magus.skill.util.capability.CapabilityHandler; +import com.lowdragmc.photon.client.fx.FX; +import com.lowdragmc.photon.client.fx.FXHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.renderer.entity.EntityRenderers; import net.minecraft.client.renderer.entity.ThrownItemRenderer; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.server.ServerStartingEvent; @@ -73,7 +76,6 @@ private void setup(final FMLCommonSetupEvent event) { Registries.init(); CapabilityHandler.initialiseCaps(); MagusNetwork.registerMessages(); - Forms.init(); } private void doClientStuff(final FMLClientSetupEvent event) { diff --git a/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java b/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java index 62e5f46..2f22683 100644 --- a/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java +++ b/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java @@ -2,6 +2,7 @@ import com.amuzil.omegasource.magus.Magus; import com.amuzil.omegasource.magus.network.MagusNetwork; +import com.amuzil.omegasource.magus.network.packets.client_executed.FormActivatedPacket; import com.amuzil.omegasource.magus.network.packets.server_executed.SendModifierDataPacket; import com.amuzil.omegasource.magus.radix.*; import com.amuzil.omegasource.magus.skill.conditionals.InputData; @@ -145,7 +146,7 @@ public KeyboardMouseInputModule() { ticksSinceActivated.getAndIncrement(); if (ticksSinceActivated.get() >= tickActivationThreshold) { // Always to send modifier data right when the form is activated - sendModifierData(); +// sendModifierData(); // if (lastActivatedForm != null && lastActivatedForm.name().equals(activeForm.name())) { // // Send modifier data of it being multi. @@ -158,8 +159,12 @@ public KeyboardMouseInputModule() { lastActivatedForm.set(activeForm.get()); // Extra check for race conditions. Probably wont' help... synchronized (lastActivatedForm.get()) { - if (!lastActivatedForm.get().name().equals("null")) + if (!lastActivatedForm.get().name().equals("null")) { + if (Minecraft.getInstance().getConnection() != null) { + MagusNetwork.sendToServer(new FormActivatedPacket(activeForm.get(), 0)); + } sendDebugMsg("Form Activated: " + lastActivatedForm.get().name()); + } } activeForm.set(Forms.NULL); ticksSinceActivated.set(0); @@ -194,13 +199,13 @@ public KeyboardMouseInputModule() { c = 5; Player player = Minecraft.getInstance().player; assert player != null; - TestProjectileEntity element = new TestProjectileEntity(player, level); -// element.shootFromRotation(player, player.getXRot(), player.getYRot(), 0.0F, 1.5F, 1.0F); - element.shoot(player.getViewVector(1).x, player.getViewVector(1).y, player.getViewVector(1).z, 2, 1); - level.addFreshEntity(element); - FX fx = FXHelper.getFX(resource); - EntityEffect entityEffect = new EntityEffect(fx, level, element); - entityEffect.start(); +// TestProjectileEntity element = new TestProjectileEntity(player, level, activeForm.get()); +// element.shootFromRotation(player, player.getXRot(), player.getYRot(), 0.0F, 1.5F, 1.0F); +// element.shoot(player.getViewVector(1).x, player.getViewVector(1).y, player.getViewVector(1).z, 2, 1); +// level.addFreshEntity(element); +// FX fx = FXHelper.getFX(resource); +// EntityEffect entityEffect = new EntityEffect(fx, level, element); +// entityEffect.start(); } } } @@ -311,7 +316,6 @@ public void registerRunnables(Node current) { @Override public void registerListeners() { - MinecraftForge.EVENT_BUS.addListener(EventPriority.NORMAL, false, TickEvent.ServerTickEvent.class, tickServerEventConsumer); MinecraftForge.EVENT_BUS.addListener(EventPriority.NORMAL, false, TickEvent.ClientTickEvent.class, tickEventConsumer); MinecraftForge.EVENT_BUS.addListener(EventPriority.NORMAL, false, InputEvent.Key.class, keyboardListener); MinecraftForge.EVENT_BUS.addListener(EventPriority.NORMAL, false, InputEvent.MouseButton.class, mouseListener); diff --git a/src/main/java/com/amuzil/omegasource/magus/network/MagusNetwork.java b/src/main/java/com/amuzil/omegasource/magus/network/MagusNetwork.java index c919eca..9fa5d37 100644 --- a/src/main/java/com/amuzil/omegasource/magus/network/MagusNetwork.java +++ b/src/main/java/com/amuzil/omegasource/magus/network/MagusNetwork.java @@ -2,6 +2,7 @@ import com.amuzil.omegasource.magus.Magus; import com.amuzil.omegasource.magus.network.packets.api.MagusPacket; +import com.amuzil.omegasource.magus.network.packets.client_executed.FormActivatedPacket; import com.amuzil.omegasource.magus.network.packets.client_executed.RegisterModifierListenersPacket; import com.amuzil.omegasource.magus.network.packets.client_executed.SkillTriggeredPacket; import com.amuzil.omegasource.magus.network.packets.client_executed.UnregisterModifierListenersPacket; @@ -14,6 +15,7 @@ import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; + public class MagusNetwork { private static final String PROTOCOL_VERSION = "1.0.0"; private static int packetId = 0; @@ -29,6 +31,12 @@ private static int nextID() { } public static void registerMessages() { + CHANNEL.messageBuilder(FormActivatedPacket.class, nextID()) + .encoder(FormActivatedPacket::toBytes) + .decoder(FormActivatedPacket::fromBytes) + .consumerMainThread(FormActivatedPacket::handle) + .add(); + CHANNEL.messageBuilder(ConditionActivatedPacket.class, nextID()) .encoder(ConditionActivatedPacket::toBytes) .decoder(ConditionActivatedPacket::fromBytes) diff --git a/src/main/java/com/amuzil/omegasource/magus/network/packets/api/MagusPacket.java b/src/main/java/com/amuzil/omegasource/magus/network/packets/api/MagusPacket.java index 34043a8..882ba59 100644 --- a/src/main/java/com/amuzil/omegasource/magus/network/packets/api/MagusPacket.java +++ b/src/main/java/com/amuzil/omegasource/magus/network/packets/api/MagusPacket.java @@ -7,6 +7,10 @@ public interface MagusPacket { void toBytes(FriendlyByteBuf buffer); + static MagusPacket fromBytes(FriendlyByteBuf buffer) { return null; } - boolean handle(Supplier context); + + static boolean handle(MagusPacket packet, Supplier context) { + return false; + } } diff --git a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java index e35beb6..ff76629 100644 --- a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java +++ b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java @@ -1,42 +1,101 @@ package com.amuzil.omegasource.magus.network.packets.client_executed; +import com.amuzil.omegasource.magus.network.MagusNetwork; import com.amuzil.omegasource.magus.network.packets.api.MagusPacket; -import com.amuzil.omegasource.magus.radix.Condition; -import com.amuzil.omegasource.magus.radix.condition.ConditionRegistry; import com.amuzil.omegasource.magus.registry.Registries; import com.amuzil.omegasource.magus.skill.forms.Form; -import com.amuzil.omegasource.magus.skill.util.capability.CapabilityHandler; +import com.amuzil.omegasource.magus.skill.test.avatar.TestProjectileEntity; +import com.lowdragmc.photon.client.fx.EntityEffect; +import com.lowdragmc.photon.client.fx.FX; +import net.minecraft.client.Minecraft; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkEvent; +import org.apache.logging.log4j.core.jmx.Server; +import java.util.Objects; +import java.util.function.Predicate; import java.util.function.Supplier; +import static com.amuzil.omegasource.magus.Magus.MOD_ID; +import static com.amuzil.omegasource.magus.skill.test.avatar.AvatarFormRegistry.blue_fire; +import static com.amuzil.omegasource.magus.skill.test.avatar.AvatarFormRegistry.fire_bloom; + + public class FormActivatedPacket implements MagusPacket { private final Form form; + private final int entityId; - public FormActivatedPacket(com.amuzil.omegasource.magus.skill.forms.Form condition) { - this.form = condition; + public FormActivatedPacket(com.amuzil.omegasource.magus.skill.forms.Form form, int entityId) { + this.form = Objects.requireNonNullElseGet(form, Form::new); + this.entityId = entityId; } public void toBytes(FriendlyByteBuf buf) { if (form != null) { buf.writeUtf(form.name()); + buf.writeInt(entityId); } } public static FormActivatedPacket fromBytes(FriendlyByteBuf buf) { String name = buf.readUtf(); - Form form = Registries.FORMS.get().getValue(new ResourceLocation(name)); - return new FormActivatedPacket(form); + int entityId = buf.readInt(); + Form form = Registries.FORMS.get().getValue(new ResourceLocation(MOD_ID, name)); + return new FormActivatedPacket(form, entityId); + } + + // Client-side handler method + @OnlyIn(Dist.CLIENT) + private static void handleClientSide(Form form, int entityId) { + System.out.println("Packet received on client"); + // Perform client-side particle effect or other rendering logic here + Player player = Minecraft.getInstance().player; + assert player != null; + Level level = player.level; + FX fx = null; + if (form.name().equals("strike")) + fx = fire_bloom; + if (form.name().equals("force")) + fx = blue_fire; + if (fx != null && entityId != -1) { + TestProjectileEntity entity = (TestProjectileEntity) player.level.getEntity(entityId); + EntityEffect entityEffect = new EntityEffect(fx, level, entity); + entityEffect.start(); + System.out.println("HANDLE CLIENT PACKET ---> " + form); + } } public boolean handle(Supplier ctx) { ctx.get().enqueueWork(() -> { - // Publish Form Event here - Player player = ctx.get().getSender(); + if (ctx.get().getDirection().getReceptionSide().isClient()) { + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> handleClientSide(form, entityId)); + } else { + // Publish Form Event here + ServerPlayer player = ctx.get().getSender(); + assert player != null; + ServerLevel level = player.getLevel(); + TestProjectileEntity entity = new TestProjectileEntity(player, level, form); + entity.shoot(player.getViewVector(1).x, player.getViewVector(1).y, player.getViewVector(1).z, 2, 1); + level.addFreshEntity(entity); + MagusNetwork.sendToClient(new FormActivatedPacket(form, entity.getId()), player); + Predicate predicate = (serverPlayer) -> player.distanceToSqr(serverPlayer) < 2500; + for (ServerPlayer nearbyPlayer: level.getPlayers(predicate.and(LivingEntity::isAlive))) { + MagusNetwork.sendToClient(new FormActivatedPacket(form, entity.getId()), nearbyPlayer); + } + System.out.println("HANDLE SERVER PACKET ---> " + form); + } }); return true; } diff --git a/src/main/java/com/amuzil/omegasource/magus/radix/condition/MultiClientCondition.java b/src/main/java/com/amuzil/omegasource/magus/radix/condition/MultiClientCondition.java index c44b7b4..d40752e 100644 --- a/src/main/java/com/amuzil/omegasource/magus/radix/condition/MultiClientCondition.java +++ b/src/main/java/com/amuzil/omegasource/magus/radix/condition/MultiClientCondition.java @@ -41,7 +41,7 @@ public void register(String name, Runnable onSuccess, Runnable onFailure) { if (executionTime > TIMEOUT_IN_TICKS) { this.onFailure().run(); - LogManager.getLogger().info("MULTI CONDITION TIMED OUT"); +// LogManager.getLogger().info("MULTI CONDITION TIMED OUT"); this.reset(); } } diff --git a/src/main/java/com/amuzil/omegasource/magus/registry/Registries.java b/src/main/java/com/amuzil/omegasource/magus/registry/Registries.java index 0f882ad..da352b7 100644 --- a/src/main/java/com/amuzil/omegasource/magus/registry/Registries.java +++ b/src/main/java/com/amuzil/omegasource/magus/registry/Registries.java @@ -5,6 +5,7 @@ import com.amuzil.omegasource.magus.skill.elements.Discipline; import com.amuzil.omegasource.magus.skill.elements.Disciplines; import com.amuzil.omegasource.magus.skill.forms.Form; +import com.amuzil.omegasource.magus.skill.forms.Forms; import com.amuzil.omegasource.magus.skill.skill.Skill; import com.amuzil.omegasource.magus.skill.skill.SkillActive; import com.amuzil.omegasource.magus.skill.skill.SkillCategory; @@ -120,9 +121,9 @@ public static void onRegistryRegister(NewRegistryEvent event) { SKILLS = event.create(skills); //Forms - RegistryBuilder forms = new RegistryBuilder<>(); - forms.setName(new ResourceLocation(Magus.MOD_ID, "forms")); - FORMS = event.create(forms); + RegistryBuilder formRegistryBuilder = new RegistryBuilder<>(); + formRegistryBuilder.setName(new ResourceLocation(Magus.MOD_ID, "forms")); + FORMS = event.create(formRegistryBuilder); //Modifiers } @@ -148,6 +149,7 @@ public static void onMissing(MissingMappingsEvent event) { @SubscribeEvent public static void gameRegistry(RegisterEvent event) { + Forms.init(); // Moved here so that forms registry gets populated /* Skill Categories. */ if (event.getRegistryKey().equals(SKILL_CATEGORIES.get().getRegistryKey())) { IForgeRegistry registry = SKILL_CATEGORIES.get(); @@ -174,7 +176,6 @@ public static void gameRegistry(RegisterEvent event) { IForgeRegistry registry = FORMS.get(); ResourceKey> resKey = registry.getRegistryKey(); - event.register(resKey, helper -> { for (Form form : forms) registry.register(form.name(), form); diff --git a/src/main/java/com/amuzil/omegasource/magus/server/ServerEvents.java b/src/main/java/com/amuzil/omegasource/magus/server/ServerEvents.java index eab4002..5bad4f7 100644 --- a/src/main/java/com/amuzil/omegasource/magus/server/ServerEvents.java +++ b/src/main/java/com/amuzil/omegasource/magus/server/ServerEvents.java @@ -8,6 +8,9 @@ import com.amuzil.omegasource.magus.skill.test.avatar.AvatarFormRegistry; import com.amuzil.omegasource.magus.skill.util.capability.CapabilityHandler; import com.amuzil.omegasource.magus.skill.util.capability.entity.Data; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; import net.minecraftforge.event.entity.EntityJoinLevelEvent; import net.minecraftforge.event.entity.EntityLeaveLevelEvent; @@ -129,13 +132,15 @@ public static void onEntityJoinLevel(EntityJoinLevelEvent event) { @SubscribeEvent public static void OnPlayerLeaveWorld(EntityLeaveLevelEvent event) { - if (event.getEntity() instanceof Player) { + if (event.getEntity() instanceof ServerPlayer) { // TODO - Causes whole server to crash when player leaves // java.lang.NullPointerException: Cannot invoke "com.amuzil.omegasource.magus.input.InputModule.getFormsTree()" // because "com.amuzil.omegasource.magus.Magus.keyboardMouseInputModule" is null - Magus.keyboardMouseInputModule.getFormsTree().deactivateAllConditions(); - Magus.keyboardMouseInputModule.terminate(); - Magus.mouseMotionModule.terminate(); + if (Magus.keyboardMouseInputModule != null) { // Temporary fix until we decide which side to make InputModules + Magus.keyboardMouseInputModule.getFormsTree().deactivateAllConditions(); + Magus.keyboardMouseInputModule.terminate(); + Magus.mouseMotionModule.terminate(); + } } } } \ No newline at end of file diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/forms/Form.java b/src/main/java/com/amuzil/omegasource/magus/skill/forms/Form.java index 13e3aa2..c6dc50d 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/forms/Form.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/forms/Form.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.List; + public class Form { private final String name; diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarFormRegistry.java b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarFormRegistry.java index 6a42ead..5025a1f 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarFormRegistry.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarFormRegistry.java @@ -1,5 +1,6 @@ package com.amuzil.omegasource.magus.skill.test.avatar; +import com.amuzil.omegasource.magus.Magus; import com.amuzil.omegasource.magus.input.KeyboardMouseInputModule; import com.amuzil.omegasource.magus.radix.RadixTree; import com.amuzil.omegasource.magus.radix.builders.InputPathBuilder; @@ -11,13 +12,19 @@ import com.amuzil.omegasource.magus.skill.conditionals.mouse.MouseWheelInput; import com.amuzil.omegasource.magus.skill.forms.FormDataRegistry; import com.amuzil.omegasource.magus.skill.forms.Forms; +import com.lowdragmc.photon.client.fx.FX; +import com.lowdragmc.photon.client.fx.FXHelper; import net.minecraft.client.Minecraft; +import net.minecraft.resources.ResourceLocation; import java.util.LinkedList; import java.util.Map; public class AvatarFormRegistry { + public static FX fire_bloom = FXHelper.getFX(new ResourceLocation(Magus.MOD_ID, "fire_bloom")); + public static FX blue_fire = FXHelper.getFX(new ResourceLocation(Magus.MOD_ID, "blue_fire")); + public static FX orb_bloom =FXHelper.getFX(new ResourceLocation(Magus.MOD_ID, "orb_bloom")); public static void registerForms() { KeyInput left = KeyDataBuilder.createInput(Minecraft.getInstance().options.keyAttack.getKey(), 0); diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java index c49509b..7533eda 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java @@ -1,6 +1,9 @@ package com.amuzil.omegasource.magus.skill.test.avatar; import com.amuzil.omegasource.magus.Magus; +import com.amuzil.omegasource.magus.network.MagusNetwork; +import com.amuzil.omegasource.magus.network.packets.client_executed.FormActivatedPacket; +import com.amuzil.omegasource.magus.skill.forms.Form; import com.lowdragmc.photon.client.fx.EntityEffect; import com.lowdragmc.photon.client.fx.FX; import com.lowdragmc.photon.client.fx.FXHelper; @@ -11,6 +14,7 @@ import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; @@ -32,6 +36,8 @@ import java.util.Optional; import java.util.function.Predicate; +import static com.amuzil.omegasource.magus.skill.test.avatar.AvatarFormRegistry.orb_bloom; + public class TestProjectileEntity extends Projectile implements ItemSupplier { public static final ItemStack PROJECTILE_ITEM = new ItemStack(Blocks.AIR); @@ -51,7 +57,7 @@ public TestProjectileEntity(double x, double y, double z, Level level) { this.setPos(x, y, z); } - public TestProjectileEntity(LivingEntity livingEntity, Level level) { + public TestProjectileEntity(LivingEntity livingEntity, Level level, Form form) { this(livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level); this.setOwner(livingEntity); } @@ -270,9 +276,8 @@ protected void onHitEntity(EntityHitResult entityHitResult) { } } else if (entity instanceof TestProjectileEntity) { System.out.println("SUCCESS MADE IT HIT!!!"); - if (this.getOwner() != null) { - FX fx = FXHelper.getFX(new ResourceLocation(Magus.MOD_ID, "orb_bloom")); - EntityEffect entityEffect = new EntityEffect(fx, level, entity); + if (this.getOwner() != null && this.level.isClientSide) { + EntityEffect entityEffect = new EntityEffect(orb_bloom, level, entity); entityEffect.start(); this.discard(); // kys asap // this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); From caf1577f8fedfd4b4200db3425750713b6181115 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Fri, 25 Oct 2024 03:18:44 -0400 Subject: [PATCH 12/31] clean up some prints --- .../network/packets/client_executed/FormActivatedPacket.java | 1 - .../magus/skill/test/avatar/TestProjectileEntity.java | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java index ff76629..d2dcc91 100644 --- a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java +++ b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java @@ -59,7 +59,6 @@ public static FormActivatedPacket fromBytes(FriendlyByteBuf buf) { // Client-side handler method @OnlyIn(Dist.CLIENT) private static void handleClientSide(Form form, int entityId) { - System.out.println("Packet received on client"); // Perform client-side particle effect or other rendering logic here Player player = Minecraft.getInstance().player; assert player != null; diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java index 7533eda..194b47a 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java @@ -189,7 +189,7 @@ public static EntityHitResult getEntityHitResult(Level level, Entity thisEntity, Entity entity = null; for(Entity otherEntity : level.getEntities(thisEntity, thisAABB, canBeHit)) { - System.out.println("ENTITY NEARBY: " + otherEntity); +// System.out.println("ENTITY NEARBY: " + otherEntity); AABB aabb = otherEntity.getBoundingBox().inflate(scale); Optional optional = aabb.clip(pos, delta); if (optional.isPresent()) { @@ -222,7 +222,7 @@ public boolean canHitEntity(Entity otherEntity) { protected void tickDespawn() { ++this.life; if (this.life >= 100) { - System.out.println("BYE BYE BBY"); +// System.out.println("BYE BYE BBY"); this.discard(); } } From e287b695c834deff5d6eeb3ad0bc8b8a7e6d01bd Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Fri, 25 Oct 2024 03:32:02 -0400 Subject: [PATCH 13/31] fix custom username arg --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 5aeda25..87655af 100644 --- a/build.gradle +++ b/build.gradle @@ -89,7 +89,7 @@ minecraft { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id // Set custom username - jvmArgs += ["--username", "Dev####"] + args "--username", "Dev####" } server { From bea2005ff3d52b99f151a7a022e98ada28576080 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Fri, 25 Oct 2024 03:40:55 -0400 Subject: [PATCH 14/31] exclude player that fires --- .../packets/client_executed/FormActivatedPacket.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java index d2dcc91..a10b4fb 100644 --- a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java +++ b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java @@ -86,10 +86,12 @@ public boolean handle(Supplier ctx) { assert player != null; ServerLevel level = player.getLevel(); TestProjectileEntity entity = new TestProjectileEntity(player, level, form); - entity.shoot(player.getViewVector(1).x, player.getViewVector(1).y, player.getViewVector(1).z, 2, 1); + entity.shoot(player.getViewVector(1).x, player.getViewVector(1).y, player.getViewVector(1).z, 1, 1); level.addFreshEntity(entity); MagusNetwork.sendToClient(new FormActivatedPacket(form, entity.getId()), player); - Predicate predicate = (serverPlayer) -> player.distanceToSqr(serverPlayer) < 2500; + Predicate predicate = (serverPlayer) -> { + return player.distanceToSqr(serverPlayer) < 2500 && !player.equals(serverPlayer); + }; for (ServerPlayer nearbyPlayer: level.getPlayers(predicate.and(LivingEntity::isAlive))) { MagusNetwork.sendToClient(new FormActivatedPacket(form, entity.getId()), nearbyPlayer); } From 431fbea4aca7fb32b9b43b7928fac73fa4bad47a Mon Sep 17 00:00:00 2001 From: David Jake Morfe Date: Fri, 25 Oct 2024 05:06:15 -0400 Subject: [PATCH 15/31] no need to check entityId Signed-off-by: David Jake Morfe --- .../network/packets/client_executed/FormActivatedPacket.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java index a10b4fb..09d1d87 100644 --- a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java +++ b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java @@ -68,7 +68,7 @@ private static void handleClientSide(Form form, int entityId) { fx = fire_bloom; if (form.name().equals("force")) fx = blue_fire; - if (fx != null && entityId != -1) { + if (fx != null) { TestProjectileEntity entity = (TestProjectileEntity) player.level.getEntity(entityId); EntityEffect entityEffect = new EntityEffect(fx, level, entity); entityEffect.start(); From bd9723c3d07ff4d165b0a13da2058eb51a42a8ba Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Fri, 25 Oct 2024 14:50:21 -0400 Subject: [PATCH 16/31] use PacketDistributor to send to nearby clients --- .../client_executed/FormActivatedPacket.java | 18 +++++++++++------- .../test/avatar/TestProjectileEntity.java | 9 +-------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java index 09d1d87..595161d 100644 --- a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java +++ b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java @@ -21,6 +21,7 @@ import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkEvent; +import net.minecraftforge.network.PacketDistributor; import org.apache.logging.log4j.core.jmx.Server; import java.util.Objects; @@ -88,13 +89,16 @@ public boolean handle(Supplier ctx) { TestProjectileEntity entity = new TestProjectileEntity(player, level, form); entity.shoot(player.getViewVector(1).x, player.getViewVector(1).y, player.getViewVector(1).z, 1, 1); level.addFreshEntity(entity); - MagusNetwork.sendToClient(new FormActivatedPacket(form, entity.getId()), player); - Predicate predicate = (serverPlayer) -> { - return player.distanceToSqr(serverPlayer) < 2500 && !player.equals(serverPlayer); - }; - for (ServerPlayer nearbyPlayer: level.getPlayers(predicate.and(LivingEntity::isAlive))) { - MagusNetwork.sendToClient(new FormActivatedPacket(form, entity.getId()), nearbyPlayer); - } + FormActivatedPacket packet = new FormActivatedPacket(form, entity.getId()); +// MagusNetwork.sendToClient(packet, player); +// Predicate predicate = (serverPlayer) -> player.distanceToSqr(serverPlayer) < 2500 && !player.equals(serverPlayer); +// for (ServerPlayer nearbyPlayer: level.getPlayers(predicate.and(LivingEntity::isAlive))) { +// MagusNetwork.sendToClient(packet, nearbyPlayer); +// } + + MagusNetwork.CHANNEL.send(PacketDistributor.NEAR.with( + () -> new PacketDistributor.TargetPoint(player.getX(), player.getY(), player.getZ(), + 500, level.dimension())), packet); System.out.println("HANDLE SERVER PACKET ---> " + form); } }); diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java index 194b47a..19fac19 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java @@ -1,20 +1,13 @@ package com.amuzil.omegasource.magus.skill.test.avatar; -import com.amuzil.omegasource.magus.Magus; -import com.amuzil.omegasource.magus.network.MagusNetwork; -import com.amuzil.omegasource.magus.network.packets.client_executed.FormActivatedPacket; import com.amuzil.omegasource.magus.skill.forms.Form; import com.lowdragmc.photon.client.fx.EntityEffect; -import com.lowdragmc.photon.client.fx.FX; -import com.lowdragmc.photon.client.fx.FXHelper; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; @@ -275,10 +268,10 @@ protected void onHitEntity(EntityHitResult entityHitResult) { this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); } } else if (entity instanceof TestProjectileEntity) { - System.out.println("SUCCESS MADE IT HIT!!!"); if (this.getOwner() != null && this.level.isClientSide) { EntityEffect entityEffect = new EntityEffect(orb_bloom, level, entity); entityEffect.start(); + System.out.println("SUCCESS COLLISION!!!"); this.discard(); // kys asap // this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); } From ac3d6a99217421a6019d8c395c1b8d2463ab72ff Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Sun, 27 Oct 2024 00:36:51 -0400 Subject: [PATCH 17/31] create a command to trigger forms on specified player --- .../skill/test/avatar/AvatarCommand.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java index 06eee37..df45f84 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java @@ -3,10 +3,20 @@ import com.amuzil.omegasource.magus.Magus; import com.amuzil.omegasource.magus.input.InputModule; import com.amuzil.omegasource.magus.input.KeyboardMouseInputModule; +import com.amuzil.omegasource.magus.network.packets.client_executed.FormActivatedPacket; +import com.amuzil.omegasource.magus.registry.Registries; +import com.amuzil.omegasource.magus.skill.forms.Form; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; +import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; + +import static com.amuzil.omegasource.magus.Magus.MOD_ID; public class AvatarCommand { @@ -25,13 +35,25 @@ public static void register(CommandDispatcher dispatcher) { ) .executes(c -> tree()) ) + .then(createActivateFormCommand()) .executes(c -> { - InputModule.sendDebugMsg("Possible modes: record, tree, reset"); + InputModule.sendDebugMsg("Options: activate_form, tree, reset"); return 1; }) ); } + private static LiteralArgumentBuilder createActivateFormCommand() { + return Commands.literal("activate") + .then(Commands.argument("form", StringArgumentType.string()) + .then(Commands.argument("target", EntityArgument.player()) + .executes(c -> activateForm( + StringArgumentType.getString(c, "form"), + EntityArgument.getPlayer(c, "target"))) + ) + ); + } + private static int key(int keyValue) { return 1; } @@ -56,4 +78,10 @@ private static int reset() { InputModule.sendDebugMsg("Reset Forms RadixTree"); return 1; } + + private static int activateForm(String name, ServerPlayer player) { + Form form = Registries.FORMS.get().getValue(new ResourceLocation(MOD_ID, name)); + FormActivatedPacket.handleServerSide(form, player); + return 1; + } } \ No newline at end of file From 09f642fd36615825e1dd63d2e05d5b1d1c9b48a9 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Mon, 28 Oct 2024 01:57:07 -0400 Subject: [PATCH 18/31] improved entity collision --- .../magus/input/KeyboardMouseInputModule.java | 6 +-- .../client_executed/FormActivatedPacket.java | 49 +++++++++--------- .../test/avatar/TestProjectileEntity.java | 20 ++++--- .../resources/assets/magus/fx/orb_bloom.fx | Bin 2393 -> 2391 bytes 4 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java b/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java index 2f22683..1cbab3a 100644 --- a/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java +++ b/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java @@ -11,10 +11,6 @@ import com.amuzil.omegasource.magus.skill.forms.FormDataRegistry; import com.amuzil.omegasource.magus.skill.forms.Forms; import com.amuzil.omegasource.magus.skill.modifiers.api.ModifierData; -import com.amuzil.omegasource.magus.skill.test.avatar.TestProjectileEntity; -import com.lowdragmc.photon.client.fx.EntityEffect; -import com.lowdragmc.photon.client.fx.FX; -import com.lowdragmc.photon.client.fx.FXHelper; import com.mojang.blaze3d.platform.InputConstants; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; @@ -163,7 +159,7 @@ public KeyboardMouseInputModule() { if (Minecraft.getInstance().getConnection() != null) { MagusNetwork.sendToServer(new FormActivatedPacket(activeForm.get(), 0)); } - sendDebugMsg("Form Activated: " + lastActivatedForm.get().name()); +// sendDebugMsg("Form Activated: " + lastActivatedForm.get().name()); } } activeForm.set(Forms.NULL); diff --git a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java index 595161d..e4c06a5 100644 --- a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java +++ b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java @@ -12,20 +12,15 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.Vec3; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkEvent; import net.minecraftforge.network.PacketDistributor; -import org.apache.logging.log4j.core.jmx.Server; import java.util.Objects; -import java.util.function.Predicate; import java.util.function.Supplier; import static com.amuzil.omegasource.magus.Magus.MOD_ID; @@ -36,9 +31,9 @@ public class FormActivatedPacket implements MagusPacket { private final Form form; - private final int entityId; + private final int entityId; // Entity ID to send back to client for FX - public FormActivatedPacket(com.amuzil.omegasource.magus.skill.forms.Form form, int entityId) { + public FormActivatedPacket(Form form, int entityId) { this.form = Objects.requireNonNullElseGet(form, Form::new); this.entityId = entityId; } @@ -57,7 +52,7 @@ public static FormActivatedPacket fromBytes(FriendlyByteBuf buf) { return new FormActivatedPacket(form, entityId); } - // Client-side handler method + // Client-side handler @OnlyIn(Dist.CLIENT) private static void handleClientSide(Form form, int entityId) { // Perform client-side particle effect or other rendering logic here @@ -77,29 +72,35 @@ private static void handleClientSide(Form form, int entityId) { } } + // Server-side handler + @OnlyIn(Dist.DEDICATED_SERVER) + public static void handleServerSide(Form form, ServerPlayer player) { + // Perform server-side entity spawning and updating logic and fire Form Event here + ServerLevel level = player.getLevel(); + TestProjectileEntity entity = new TestProjectileEntity(player, level); + entity.shoot(player.getViewVector(1).x, player.getViewVector(1).y, player.getViewVector(1).z, 1, 1); + level.addFreshEntity(entity); + FormActivatedPacket packet = new FormActivatedPacket(form, entity.getId()); + +// Predicate predicate = (serverPlayer) -> player.distanceToSqr(serverPlayer) < 2500; +// for (ServerPlayer nearbyPlayer: level.getPlayers(predicate.and(LivingEntity::isAlive))) { +// MagusNetwork.sendToClient(packet, nearbyPlayer); +// } // Keep this in case we want a more specific client packet distribution filter + + MagusNetwork.CHANNEL.send(PacketDistributor.NEAR.with( + () -> new PacketDistributor.TargetPoint(player.getX(), player.getY(), player.getZ(), + 500, level.dimension())), packet); + System.out.println("HANDLE SERVER PACKET ---> " + form); + } + public boolean handle(Supplier ctx) { ctx.get().enqueueWork(() -> { if (ctx.get().getDirection().getReceptionSide().isClient()) { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> handleClientSide(form, entityId)); } else { - // Publish Form Event here ServerPlayer player = ctx.get().getSender(); assert player != null; - ServerLevel level = player.getLevel(); - TestProjectileEntity entity = new TestProjectileEntity(player, level, form); - entity.shoot(player.getViewVector(1).x, player.getViewVector(1).y, player.getViewVector(1).z, 1, 1); - level.addFreshEntity(entity); - FormActivatedPacket packet = new FormActivatedPacket(form, entity.getId()); -// MagusNetwork.sendToClient(packet, player); -// Predicate predicate = (serverPlayer) -> player.distanceToSqr(serverPlayer) < 2500 && !player.equals(serverPlayer); -// for (ServerPlayer nearbyPlayer: level.getPlayers(predicate.and(LivingEntity::isAlive))) { -// MagusNetwork.sendToClient(packet, nearbyPlayer); -// } - - MagusNetwork.CHANNEL.send(PacketDistributor.NEAR.with( - () -> new PacketDistributor.TargetPoint(player.getX(), player.getY(), player.getZ(), - 500, level.dimension())), packet); - System.out.println("HANDLE SERVER PACKET ---> " + form); + DistExecutor.unsafeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> handleServerSide(form, player)); } }); return true; diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java index 19fac19..da66880 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java @@ -39,6 +39,7 @@ public class TestProjectileEntity extends Projectile implements ItemSupplier { private boolean leftOwner; private boolean hasBeenShot; private int life; + private int ttk = 100; public TestProjectileEntity(EntityType type, Level level) { super(type, level); @@ -50,7 +51,7 @@ public TestProjectileEntity(double x, double y, double z, Level level) { this.setPos(x, y, z); } - public TestProjectileEntity(LivingEntity livingEntity, Level level, Form form) { + public TestProjectileEntity(LivingEntity livingEntity, Level level) { this(livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level); this.setOwner(livingEntity); } @@ -212,9 +213,13 @@ public boolean canHitEntity(Entity otherEntity) { } } + protected void setTimeToKill(int ticks) { + this.ttk = ticks; + } + protected void tickDespawn() { ++this.life; - if (this.life >= 100) { + if (this.life >= ttk) { // System.out.println("BYE BYE BBY"); this.discard(); } @@ -267,13 +272,16 @@ protected void onHitEntity(EntityHitResult entityHitResult) { if (this.getOwner() != null) { this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); } - } else if (entity instanceof TestProjectileEntity) { + } else if (entity instanceof TestProjectileEntity testProjectileEntity) { if (this.getOwner() != null && this.level.isClientSide) { - EntityEffect entityEffect = new EntityEffect(orb_bloom, level, entity); + TestProjectileEntity collisionEntity = new TestProjectileEntity(this.getX(), this.getY(), this.getZ(), level); + collisionEntity.setTimeToKill(5); + level.addFreshEntity(collisionEntity); + EntityEffect entityEffect = new EntityEffect(orb_bloom, level, collisionEntity); entityEffect.start(); System.out.println("SUCCESS COLLISION!!!"); - this.discard(); // kys asap -// this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); + this.discard(); + testProjectileEntity.discard(); } } else { int i = 10; // Deal 10 damage diff --git a/src/main/resources/assets/magus/fx/orb_bloom.fx b/src/main/resources/assets/magus/fx/orb_bloom.fx index a93ad863d40dab32fd77ad6805ae8d586332cab7..1b2bbb90de25423d9f37a7058c08fdca76f5c645 100644 GIT binary patch delta 991 zcmV<510ej_64w&2hXsEkP#jj7T3W>RSK^j$(P+VEW5ew!`atFj)rLiSAx~Mo-D^Np zg=gmmw~xex)}|hE@{m$H4?&?&c?h(|xqml|kIfn5`@c}F>Xh6VZ@qt8weSAuhB^B8 zma+c$HS@X252H@;jd}9jADZ<$SB!r={hImFU%zPH{Eg_yXmo#Rov}EqHsv#E$^THY z8K^^sK}x3ns{C8-U^#6|~?aYLXU;gSP^P5+GZ@m73adv6+p82JJ zJ^TDOKHME{GxDij;5H9X1uaMQ4PQB6`K&lMSx}V)RasD#hYe^C*15?xRSDOpqAJbI zQp+pxn!$h62YPrK)C1K!Ow|0xde3%C(^GlAcxJpS7DMbBQqfu~` z#d*r&JY~OgmBo3={ytBs#d&EBRU(f+-Rbi3k}j{@A6(wJ|N1AYP=&U83eam3@d*;nkj~Q=TAItV&(WU88&_^8Gq4oAjP?a$hCqO?1 zqgsFFuD?`Jss*K5P^tx`T2QKe_EYp*w{As0MgOGDvF`k*=*EAqzikeE`<0DM>mDBp z9oz<^YV5{O(R&EZVN?@9-TDA&!KfCDYQd-$jB3HC<}#}LmzExK0`f>qKpxp40jX_8 zKt2Fw$xC9E0b8cRtTSiMY{IM&C4I~X@ncsB!$3Whg{_^l+UL4})?r~tcYcWU9x4uz z?joc5Ou?ugOhz?}S+X^fd@J@P)hRuN@+g4XT9k|>&K7HQ5E<1k^!#zXA_fa?bsO9& N`XBJBt~mTt002fx_}u^i delta 993 zcmV<710MX>64?^4hXsEC6u~WrRi>5}vHg{}1ohnzg5)XqatC{!K-t#R((4dY{T#`yj(RI55AH^y7<-&XCrKe}O# z{=H?aKYq=8Zt}yZQ+#8deD{ZD{mvERA5Xt#e)QKbnm2zVIx>G6U0P=>4y#T1Oj`0k zlxzm-kYSLLslO_J+*Zk35oAS#jG)iQHE(>+pGxSmr(}}z<-l7^zd14=^-1d9vaJ7L zp3I(a!bpHk`|RWI=?AVHZtpo$#KE}^D{H?6hzB0kej4h zEXc_IB_p+mLPme4ZoU3C%Wk9(&N><&J;n|Q>o`8v6$y64I&KD7nN=w?ynXuzJpndL zMs^YL>dQ|`5yqoiiYPeBhs;rG2aKaM6n$QBl>5(7_Rh09+-GwPYptCRUESf(jYQ|s z^K^ySeL{0;1TZZYrvY&rtsN*1I3i*7KT1y_`Ji^=( zhJ5tb8NCO201Gd3q^Q3cN$WqhbdSrEf+hX`V@W$RA>)_7ddd9emERk$zhInQ8og(J z>0i%2|BVlKhue&NY8SZ815`oFQGLT#4p=@b&P^6nWkFRIROMj<+Jkj&vQ1UO^{J>z zGqcq4O1yt&F!g~R-qRr=>oAEIMH1?N`#?z;_|~o6qA(xk!O8rRV=Jyw5=077f7WOe zTxD^dvN%uK?_6bZp0dBsQ)+QuT0@n{<4*UdKB~#$98DFeG*h<48;l1 zPr-kvmbvRM6_jd0sTP!KL8%s$YM=cS{no8p(NEDoX>+VQ|0%lh-|KIiL*IU7Bh$La zhe8Lp!KfO$@l*63LUS0^1W>m=Kw2=W1*2Lpss*E3FsiwX>i(srhn#>s5)+U|c1S>K zTM>{CfLZdAm}S70sW9uznKPR(YeY#O^FdksSi&$+4`pF%=dAX*E}(T-7}A{|BE5%- zL!`UNs6JCLst1!%&0>~pjU?ZSeMxmnPoX>tptcqzV~MlH8XZJN^$R_JT(5}1f?M4N Pw~GD;x8DL9{8In`0|NE$ From 8521d9a43d7a618bed0ded2bc0efa9c93022fe84 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Mon, 28 Oct 2024 12:40:31 -0400 Subject: [PATCH 19/31] fixed bugs with singleplayer/multiplayer vs client/server --- .../packets/client_executed/FormActivatedPacket.java | 9 ++++----- .../magus/skill/test/avatar/TestProjectileEntity.java | 7 +------ 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java index e4c06a5..8944146 100644 --- a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java +++ b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java @@ -65,15 +65,14 @@ private static void handleClientSide(Form form, int entityId) { if (form.name().equals("force")) fx = blue_fire; if (fx != null) { - TestProjectileEntity entity = (TestProjectileEntity) player.level.getEntity(entityId); - EntityEffect entityEffect = new EntityEffect(fx, level, entity); - entityEffect.start(); +// TestProjectileEntity entity = (TestProjectileEntity) player.level.getEntity(entityId); +// EntityEffect entityEffect = new EntityEffect(fx, level, entity); +// entityEffect.start(); System.out.println("HANDLE CLIENT PACKET ---> " + form); } } // Server-side handler - @OnlyIn(Dist.DEDICATED_SERVER) public static void handleServerSide(Form form, ServerPlayer player) { // Perform server-side entity spawning and updating logic and fire Form Event here ServerLevel level = player.getLevel(); @@ -100,7 +99,7 @@ public boolean handle(Supplier ctx) { } else { ServerPlayer player = ctx.get().getSender(); assert player != null; - DistExecutor.unsafeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> handleServerSide(form, player)); + handleServerSide(form, player); } }); return true; diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java index da66880..c5f6975 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java @@ -1,6 +1,5 @@ package com.amuzil.omegasource.magus.skill.test.avatar; -import com.amuzil.omegasource.magus.skill.forms.Form; import com.lowdragmc.photon.client.fx.EntityEffect; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleOptions; @@ -284,6 +283,7 @@ protected void onHitEntity(EntityHitResult entityHitResult) { testProjectileEntity.discard(); } } else { + // TODO - Check if player entity has countered int i = 10; // Deal 10 damage entity.hurt(this.damageSources().thrown(this, this.getOwner()), (float)i); this.discard(); @@ -307,11 +307,6 @@ private ParticleOptions getParticle() { return ParticleTypes.FLAME; } -// @Override -// protected ItemStack getPickupItem() { -// return PROJECTILE_ITEM; -// } - @Override public ItemStack getItem() { return PROJECTILE_ITEM; From 0e784cd502732562f58039a0bbdb0ab4daeecb82 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Mon, 28 Oct 2024 12:49:13 -0400 Subject: [PATCH 20/31] move gravity setting --- .../magus/skill/test/avatar/TestProjectileEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java index c5f6975..6813f60 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java @@ -42,7 +42,6 @@ public class TestProjectileEntity extends Projectile implements ItemSupplier { public TestProjectileEntity(EntityType type, Level level) { super(type, level); - this.setNoGravity(true); } public TestProjectileEntity(double x, double y, double z, Level level) { @@ -53,6 +52,7 @@ public TestProjectileEntity(double x, double y, double z, Level level) { public TestProjectileEntity(LivingEntity livingEntity, Level level) { this(livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level); this.setOwner(livingEntity); + this.setNoGravity(true); } public void projectileTick() { From 7cd1c3352317f995b6d9abbc29982b4731b3db52 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Mon, 28 Oct 2024 15:36:53 -0400 Subject: [PATCH 21/31] refactor --- .../test/avatar => entity}/AvatarEntities.java | 2 +- .../avatar => entity}/TestProjectileEntity.java | 17 +++++++++-------- .../omegasource/magus/input/InputModule.java | 1 - .../client_executed/FormActivatedPacket.java | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) rename src/main/java/com/amuzil/omegasource/magus/{skill/test/avatar => entity}/AvatarEntities.java (94%) rename src/main/java/com/amuzil/omegasource/magus/{skill/test/avatar => entity}/TestProjectileEntity.java (96%) diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarEntities.java b/src/main/java/com/amuzil/omegasource/magus/entity/AvatarEntities.java similarity index 94% rename from src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarEntities.java rename to src/main/java/com/amuzil/omegasource/magus/entity/AvatarEntities.java index cf4afc7..3c0301d 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarEntities.java +++ b/src/main/java/com/amuzil/omegasource/magus/entity/AvatarEntities.java @@ -1,4 +1,4 @@ -package com.amuzil.omegasource.magus.skill.test.avatar; +package com.amuzil.omegasource.magus.entity; import com.amuzil.omegasource.magus.Magus; import net.minecraft.world.entity.EntityType; diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java b/src/main/java/com/amuzil/omegasource/magus/entity/TestProjectileEntity.java similarity index 96% rename from src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java rename to src/main/java/com/amuzil/omegasource/magus/entity/TestProjectileEntity.java index 6813f60..f209c04 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/TestProjectileEntity.java +++ b/src/main/java/com/amuzil/omegasource/magus/entity/TestProjectileEntity.java @@ -1,4 +1,4 @@ -package com.amuzil.omegasource.magus.skill.test.avatar; +package com.amuzil.omegasource.magus.entity; import com.lowdragmc.photon.client.fx.EntityEffect; import net.minecraft.core.BlockPos; @@ -257,13 +257,14 @@ public boolean isNoPhysics() { } } - public void handleEntityEvent(byte data) { - if (data == 3) { - for(int i = 0; i < 8; ++i) { - this.level.addParticle(this.getParticle(), this.getX(), this.getY(), this.getZ(), 0.0D, 0.0D, 0.0D); - } - } - } +// public void handleEntityEvent(byte data) { +// if (data == 3) { +// System.out.println("HANDLE ENTITY EVENT"); +// for(int i = 0; i < 8; ++i) { +// this.level.addParticle(this.getParticle(), this.getX(), this.getY(), this.getZ(), 0.0D, 0.0D, 0.0D); +// } +// } +// } protected void onHitEntity(EntityHitResult entityHitResult) { Entity entity = entityHitResult.getEntity(); diff --git a/src/main/java/com/amuzil/omegasource/magus/input/InputModule.java b/src/main/java/com/amuzil/omegasource/magus/input/InputModule.java index 46d4ffb..10ab846 100644 --- a/src/main/java/com/amuzil/omegasource/magus/input/InputModule.java +++ b/src/main/java/com/amuzil/omegasource/magus/input/InputModule.java @@ -194,5 +194,4 @@ public void unregisterModifiers() { public abstract boolean keyPressed(int key); - } diff --git a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java index 8944146..2db04bd 100644 --- a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java +++ b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java @@ -4,7 +4,7 @@ import com.amuzil.omegasource.magus.network.packets.api.MagusPacket; import com.amuzil.omegasource.magus.registry.Registries; import com.amuzil.omegasource.magus.skill.forms.Form; -import com.amuzil.omegasource.magus.skill.test.avatar.TestProjectileEntity; +import com.amuzil.omegasource.magus.entity.TestProjectileEntity; import com.lowdragmc.photon.client.fx.EntityEffect; import com.lowdragmc.photon.client.fx.FX; import net.minecraft.client.Minecraft; @@ -65,9 +65,9 @@ private static void handleClientSide(Form form, int entityId) { if (form.name().equals("force")) fx = blue_fire; if (fx != null) { -// TestProjectileEntity entity = (TestProjectileEntity) player.level.getEntity(entityId); -// EntityEffect entityEffect = new EntityEffect(fx, level, entity); -// entityEffect.start(); + TestProjectileEntity entity = (TestProjectileEntity) player.level.getEntity(entityId); + EntityEffect entityEffect = new EntityEffect(fx, level, entity); + entityEffect.start(); System.out.println("HANDLE CLIENT PACKET ---> " + form); } } From 8674a3117d6abb19da5dc869411bf4e895f423e7 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Tue, 29 Oct 2024 01:24:43 -0400 Subject: [PATCH 22/31] started implementing generic element entity handling system also improved commands --- .../com/amuzil/omegasource/magus/Magus.java | 17 +- .../magus/entity/AvatarEntities.java | 27 +- .../magus/entity/ElementProjectile.java | 235 ++++++++++++++++ .../entity/collision/ElementCollision.java | 262 ++++++++++++++++++ .../entity/projectile/AirProjectile.java | 260 +++++++++++++++++ .../entity/projectile/EarthProjectile.java | 260 +++++++++++++++++ .../FireProjectile.java} | 72 ++--- .../entity/projectile/WaterProjectile.java | 260 +++++++++++++++++ .../omegasource/magus/input/InputModule.java | 18 +- .../magus/input/KeyboardMouseInputModule.java | 15 +- .../client_executed/FormActivatedPacket.java | 46 ++- .../amuzil/omegasource/magus/radix/Node.java | 7 +- .../omegasource/magus/radix/RadixTree.java | 15 +- .../magus/registry/Registries.java | 13 +- .../magus/skill/elements/Disciplines.java | 17 -- .../{Discipline.java => Element.java} | 17 +- .../magus/skill/elements/Elements.java | 24 ++ .../omegasource/magus/skill/forms/Forms.java | 3 +- .../listeners/TargetModifierListener.java | 13 +- .../magus/skill/skill/SkillCategory.java | 2 + .../skill/test/avatar/AvatarCommand.java | 80 +++--- .../util/bending/BendingMaterialUtil.java | 6 +- 22 files changed, 1477 insertions(+), 192 deletions(-) create mode 100644 src/main/java/com/amuzil/omegasource/magus/entity/ElementProjectile.java create mode 100644 src/main/java/com/amuzil/omegasource/magus/entity/collision/ElementCollision.java create mode 100644 src/main/java/com/amuzil/omegasource/magus/entity/projectile/AirProjectile.java create mode 100644 src/main/java/com/amuzil/omegasource/magus/entity/projectile/EarthProjectile.java rename src/main/java/com/amuzil/omegasource/magus/entity/{TestProjectileEntity.java => projectile/FireProjectile.java} (81%) create mode 100644 src/main/java/com/amuzil/omegasource/magus/entity/projectile/WaterProjectile.java delete mode 100644 src/main/java/com/amuzil/omegasource/magus/skill/elements/Disciplines.java rename src/main/java/com/amuzil/omegasource/magus/skill/elements/{Discipline.java => Element.java} (51%) create mode 100644 src/main/java/com/amuzil/omegasource/magus/skill/elements/Elements.java diff --git a/src/main/java/com/amuzil/omegasource/magus/Magus.java b/src/main/java/com/amuzil/omegasource/magus/Magus.java index da3c8bb..196d21a 100644 --- a/src/main/java/com/amuzil/omegasource/magus/Magus.java +++ b/src/main/java/com/amuzil/omegasource/magus/Magus.java @@ -1,22 +1,18 @@ package com.amuzil.omegasource.magus; -import com.amuzil.omegasource.magus.input.*; +import com.amuzil.omegasource.magus.entity.AvatarEntities; +import com.amuzil.omegasource.magus.input.InputModule; +import com.amuzil.omegasource.magus.input.KeyboardMouseInputModule; +import com.amuzil.omegasource.magus.input.MouseMotionModule; import com.amuzil.omegasource.magus.network.MagusNetwork; import com.amuzil.omegasource.magus.registry.Registries; import com.amuzil.omegasource.magus.skill.forms.FormDataRegistry; -import com.amuzil.omegasource.magus.skill.forms.Forms; import com.amuzil.omegasource.magus.skill.modifiers.ModifiersRegistry; import com.amuzil.omegasource.magus.skill.test.avatar.AvatarCommand; -import com.amuzil.omegasource.magus.skill.test.avatar.AvatarEntities; import com.amuzil.omegasource.magus.skill.util.capability.CapabilityHandler; -import com.lowdragmc.photon.client.fx.FX; -import com.lowdragmc.photon.client.fx.FXHelper; import net.minecraft.client.Minecraft; -import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.renderer.entity.EntityRenderers; import net.minecraft.client.renderer.entity.ThrownItemRenderer; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.server.ServerStartingEvent; @@ -122,7 +118,10 @@ public static void onClientSetup(FMLClientSetupEvent event) { LOGGER.info("HELLO FROM CLIENT SETUP"); KeyboardMouseInputModule.determineMotionKeys(); - EntityRenderers.register(AvatarEntities.TEST_PROJECTILE.get(), ThrownItemRenderer::new); + EntityRenderers.register(AvatarEntities.AIR_PROJECTILE_ENTITY_TYPE.get(), ThrownItemRenderer::new); + EntityRenderers.register(AvatarEntities.WATER_PROJECTILE_ENTITY_TYPE.get(), ThrownItemRenderer::new); + EntityRenderers.register(AvatarEntities.EARTH_PROJECTILE_ENTITY_TYPE.get(), ThrownItemRenderer::new); + EntityRenderers.register(AvatarEntities.FIRE_PROJECTILE_ENTITY_TYPE.get(), ThrownItemRenderer::new); LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName()); } diff --git a/src/main/java/com/amuzil/omegasource/magus/entity/AvatarEntities.java b/src/main/java/com/amuzil/omegasource/magus/entity/AvatarEntities.java index 3c0301d..29af4c5 100644 --- a/src/main/java/com/amuzil/omegasource/magus/entity/AvatarEntities.java +++ b/src/main/java/com/amuzil/omegasource/magus/entity/AvatarEntities.java @@ -1,6 +1,11 @@ package com.amuzil.omegasource.magus.entity; import com.amuzil.omegasource.magus.Magus; +import com.amuzil.omegasource.magus.entity.collision.ElementCollision; +import com.amuzil.omegasource.magus.entity.projectile.AirProjectile; +import com.amuzil.omegasource.magus.entity.projectile.EarthProjectile; +import com.amuzil.omegasource.magus.entity.projectile.FireProjectile; +import com.amuzil.omegasource.magus.entity.projectile.WaterProjectile; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MobCategory; import net.minecraftforge.eventbus.api.IEventBus; @@ -13,9 +18,25 @@ public class AvatarEntities { public static final DeferredRegister> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, Magus.MOD_ID); - public static final RegistryObject> TEST_PROJECTILE = - ENTITY_TYPES.register("test_projectile", () -> EntityType.Builder.of(TestProjectileEntity::new, MobCategory.MISC) - .sized(0.5f, 0.5f).build("test_projectile")); + public static final RegistryObject> AIR_PROJECTILE_ENTITY_TYPE = + ENTITY_TYPES.register("air_projectile", () -> EntityType.Builder.of(AirProjectile::new, MobCategory.MISC) + .sized(0.5f, 0.5f).build("air_projectile")); + + public static final RegistryObject> WATER_PROJECTILE_ENTITY_TYPE = + ENTITY_TYPES.register("water_projectile", () -> EntityType.Builder.of(WaterProjectile::new, MobCategory.MISC) + .sized(0.5f, 0.5f).build("water_projectile")); + + public static final RegistryObject> EARTH_PROJECTILE_ENTITY_TYPE = + ENTITY_TYPES.register("earth_projectile", () -> EntityType.Builder.of(EarthProjectile::new, MobCategory.MISC) + .sized(0.5f, 0.5f).build("earth_projectile")); + + public static final RegistryObject> FIRE_PROJECTILE_ENTITY_TYPE = + ENTITY_TYPES.register("fire_projectile", () -> EntityType.Builder.of(FireProjectile::new, MobCategory.MISC) + .sized(0.5f, 0.5f).build("fire_projectile")); + + public static final RegistryObject> COLLISION_ENTITY_TYPE = + ENTITY_TYPES.register("element_collision", () -> EntityType.Builder.of(ElementCollision::new, MobCategory.MISC) + .sized(0.5f, 0.5f).build("element_collision")); public static void register(IEventBus eventBus) { ENTITY_TYPES.register(eventBus); diff --git a/src/main/java/com/amuzil/omegasource/magus/entity/ElementProjectile.java b/src/main/java/com/amuzil/omegasource/magus/entity/ElementProjectile.java new file mode 100644 index 0000000..a57a3e8 --- /dev/null +++ b/src/main/java/com/amuzil/omegasource/magus/entity/ElementProjectile.java @@ -0,0 +1,235 @@ +package com.amuzil.omegasource.magus.entity; + +import com.amuzil.omegasource.magus.entity.projectile.AirProjectile; +import com.amuzil.omegasource.magus.entity.projectile.EarthProjectile; +import com.amuzil.omegasource.magus.entity.projectile.FireProjectile; +import com.amuzil.omegasource.magus.entity.projectile.WaterProjectile; +import com.amuzil.omegasource.magus.skill.elements.Element; +import com.amuzil.omegasource.magus.skill.forms.Form; +import com.lowdragmc.photon.client.fx.EntityEffect; +import com.lowdragmc.photon.client.fx.FX; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.monster.Blaze; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.ItemSupplier; +import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.gameevent.GameEvent; +import net.minecraft.world.phys.*; + +import javax.annotation.Nullable; +import java.util.Optional; +import java.util.function.Predicate; + +import static com.amuzil.omegasource.magus.skill.test.avatar.AvatarFormRegistry.*; + + +public abstract class ElementProjectile extends Projectile implements ItemSupplier { + public static final ItemStack PROJECTILE_ITEM = new ItemStack(Blocks.AIR); + private static final EntityDataAccessor ID_FLAGS = SynchedEntityData.defineId(ElementProjectile.class, EntityDataSerializers.BYTE); + private static final EntityDataAccessor PIERCE_LEVEL = SynchedEntityData.defineId(ElementProjectile.class, EntityDataSerializers.BYTE); + protected boolean leftOwner; + private boolean hasBeenShot; + private int life; + private int ttk = 100; + + public ElementProjectile(EntityType type, Level level) { + super(type, level); + } + + public ElementProjectile(EntityType entityType, double x, double y, double z, Level level) { + this(entityType, level); + this.setPos(x, y, z); + } + + public ElementProjectile(EntityType entityType, LivingEntity livingEntity, Level level) { + this(entityType, livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level); + this.setOwner(livingEntity); + this.setNoGravity(true); + } + + public void tick() { + if (!this.hasBeenShot) { + this.gameEvent(GameEvent.PROJECTILE_SHOOT, this.getOwner()); + this.hasBeenShot = true; + } + + if (!this.leftOwner) { + this.leftOwner = this.checkLeftOwner(); + } + + super.tick(); + } + + @Nullable + protected EntityHitResult findHitEntity(Vec3 pos, Vec3 delta) { + return getEntityHitResult(this.level, this, pos, delta, + this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(2.0D), + this::canHitEntity, 0.3F); + } + + @Nullable + public static EntityHitResult getEntityHitResult(Level level, Entity thisEntity, Vec3 pos, Vec3 delta, AABB thisAABB, Predicate canBeHit, float scale) { + double maxDist = Double.MAX_VALUE; + Entity entity = null; + + for(Entity otherEntity : level.getEntities(thisEntity, thisAABB, canBeHit)) { +// System.out.println("ENTITY NEARBY: " + otherEntity); + AABB aabb = otherEntity.getBoundingBox().inflate(scale); + Optional optional = aabb.clip(pos, delta); + if (optional.isPresent()) { + double dist = pos.distanceToSqr(optional.get()); + if (dist < maxDist) { + entity = otherEntity; + maxDist = dist; + } + } + } + + return entity == null ? null : new EntityHitResult(entity); + } + + public boolean canHitEntity(Entity otherEntity) { + if (!otherEntity.canBeHitByProjectile()) { + return false; + } else { + Entity entity = this.getOwner(); +// if (entity != null) { +// if (otherEntity instanceof TestProjectileEntity other) { +// System.out.println("THIS OWNER: " + entity + " | " + !entity.isPassengerOfSameVehicle(otherEntity)); +// System.out.println("THAT OWNER: " + other.getOwner()); +// } +// } + return entity == null || this.leftOwner || !entity.isPassengerOfSameVehicle(otherEntity); + } + } + + public void setTimeToKill(int ticks) { + this.ttk = ticks; + } + + protected void tickDespawn() { + ++this.life; + if (this.life >= ttk) { +// System.out.println("BYE BYE BBY"); + this.discard(); + } + } + + @Override + public boolean isPickable() { + return true; + } + + @Override + protected void defineSynchedData() { + this.entityData.define(ID_FLAGS, (byte)0); + this.entityData.define(PIERCE_LEVEL, (byte)0); + } + + private boolean checkLeftOwner() { + Entity owner = this.getOwner(); + if (owner != null) { + for(Entity entity1 : this.level.getEntities(this, this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(1.0D), (entity) -> { + return !entity.isSpectator() && entity.isPickable(); + })) { + if (entity1.getRootVehicle() == owner.getRootVehicle()) { + return false; + } + } + } + return true; + } + + public boolean isNoPhysics() { + if (!this.level.isClientSide) { + return this.noPhysics; + } else { + return (this.entityData.get(ID_FLAGS) & 2) != 0; + } + } + +// public void handleEntityEvent(byte data) { +// if (data == 3) { +// System.out.println("HANDLE ENTITY EVENT"); +// for(int i = 0; i < 8; ++i) { +// this.level.addParticle(this.getParticle(), this.getX(), this.getY(), this.getZ(), 0.0D, 0.0D, 0.0D); +// } +// } +// } + + protected void onHitEntity(EntityHitResult entityHitResult) { + Entity entity = entityHitResult.getEntity(); + if (entity instanceof Blaze) { + if (this.getOwner() != null) { + this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); + } + } else if (entity instanceof ElementProjectile testProjectileEntity) { + if (this.getOwner() != null && this.level.isClientSide) { + ElementProjectile collisionEntity = new FireProjectile(this.getX(), this.getY(), this.getZ(), level); + collisionEntity.setTimeToKill(5); + level.addFreshEntity(collisionEntity); + EntityEffect entityEffect = new EntityEffect(orb_bloom, level, collisionEntity); + entityEffect.start(); + System.out.println("SUCCESS COLLISION!!!"); + this.discard(); + testProjectileEntity.discard(); + } + } else { + // TODO - Check if player entity has countered + int i = 10; // Deal 10 damage + entity.hurt(this.damageSources().thrown(this, this.getOwner()), (float)i); + this.discard(); + } + } + + protected void onHitBlock(BlockHitResult blockHitResult) { +// super.onHitBlock(blockHitResult); + this.discard(); + } + + protected void onHit(HitResult hitResult) { + super.onHit(hitResult); + if (!this.level.isClientSide) { + this.level.broadcastEntityEvent(this, (byte)3); +// this.discard(); + } + } + + @Override + public ItemStack getItem() { + return PROJECTILE_ITEM; + } + + public static ElementProjectile createElementEntity(Form form, Element element, ServerPlayer player, ServerLevel level) { + return switch (element.type()) { + case AIR -> new AirProjectile(player, level); + case WATER -> new WaterProjectile(player, level); + case EARTH -> new EarthProjectile(player, level); + case FIRE -> new FireProjectile(player, level); + }; + } + + public void startEffect(Form form, Player player) { + FX fx = null; + if (form.name().equals("strike")) + fx = fire_bloom; + if (form.name().equals("force")) + fx = blue_fire; + if (fx != null) { + EntityEffect entityEffect = new EntityEffect(fx, level, this); + entityEffect.start(); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/amuzil/omegasource/magus/entity/collision/ElementCollision.java b/src/main/java/com/amuzil/omegasource/magus/entity/collision/ElementCollision.java new file mode 100644 index 0000000..17b8bc9 --- /dev/null +++ b/src/main/java/com/amuzil/omegasource/magus/entity/collision/ElementCollision.java @@ -0,0 +1,262 @@ +package com.amuzil.omegasource.magus.entity.collision; + +import com.amuzil.omegasource.magus.entity.AvatarEntities; +import com.amuzil.omegasource.magus.entity.ElementProjectile; +import com.lowdragmc.photon.client.fx.EntityEffect; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.monster.Blaze; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.*; +import net.minecraft.world.phys.shapes.VoxelShape; + +import javax.annotation.Nullable; +import java.util.Optional; +import java.util.function.Predicate; + +import static com.amuzil.omegasource.magus.skill.test.avatar.AvatarFormRegistry.orb_bloom; + + +public class ElementCollision extends ElementProjectile { + private static final EntityDataAccessor ID_FLAGS = SynchedEntityData.defineId(ElementCollision.class, EntityDataSerializers.BYTE); + private static final EntityDataAccessor PIERCE_LEVEL = SynchedEntityData.defineId(ElementCollision.class, EntityDataSerializers.BYTE); + private boolean leftOwner; + private boolean hasBeenShot; + private int life; + private int ttk = 10; + + public ElementCollision(EntityType type, Level level) { + super(type, level); + } + + public ElementCollision(double x, double y, double z, Level level) { + this(AvatarEntities.COLLISION_ENTITY_TYPE.get(), level); + this.setPos(x, y, z); + } + + public ElementCollision(LivingEntity livingEntity, Level level) { + this(livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level); + this.setOwner(livingEntity); + this.setNoGravity(true); + } + + public void tick() { + super.tick(); + boolean flag = this.isNoPhysics(); + Vec3 deltaMovement = this.getDeltaMovement(); + if (this.xRotO == 0.0F && this.yRotO == 0.0F) { + double distance = deltaMovement.horizontalDistance(); + this.setYRot((float)(Mth.atan2(deltaMovement.x, deltaMovement.z) * (double)(180F / (float)Math.PI))); + this.setXRot((float)(Mth.atan2(deltaMovement.y, distance) * (double)(180F / (float)Math.PI))); + this.yRotO = this.getYRot(); + this.xRotO = this.getXRot(); + } + + BlockPos blockpos = this.blockPosition(); + BlockState blockstate = this.level.getBlockState(blockpos); + if (!blockstate.isAir() && !flag) { + VoxelShape voxelshape = blockstate.getCollisionShape(this.level, blockpos); + if (!voxelshape.isEmpty()) { + Vec3 vec31 = this.position(); + + for(AABB aabb : voxelshape.toAabbs()) { + if (aabb.move(blockpos).contains(vec31)) { + break; + } + } + } + } + + if (this.isInWaterOrRain() || blockstate.is(Blocks.POWDER_SNOW) || this.isInFluidType((fluidType, height) -> this.canFluidExtinguish(fluidType))) { + this.clearFire(); + } + + Vec3 pos = this.position(); + Vec3 delta = pos.add(deltaMovement); + HitResult hitresult = this.level.clip(new ClipContext(pos, delta, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)); + if (hitresult.getType() != HitResult.Type.MISS) { + delta = hitresult.getLocation(); + } + + while(!this.isRemoved()) { + if (!this.level.isClientSide) { + this.tickDespawn(); + } + EntityHitResult entityhitresult = this.findHitEntity(pos, delta); + if (entityhitresult != null) { + hitresult = entityhitresult; + } + + if (hitresult != null && hitresult.getType() == HitResult.Type.ENTITY) { + assert hitresult instanceof EntityHitResult; + Entity entity = ((EntityHitResult)hitresult).getEntity(); + Entity owner = this.getOwner(); + if (entity instanceof Player && owner instanceof Player && !((Player)owner).canHarmPlayer((Player)entity)) { + hitresult = null; + entityhitresult = null; + } + } + + if (hitresult != null && hitresult.getType() != HitResult.Type.MISS && !flag) { + if (net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, hitresult)) + break; + this.onHit(hitresult); + this.hasImpulse = true; + break; + } + + if (entityhitresult == null) { + break; + } + + hitresult = null; + } + deltaMovement = this.getDeltaMovement(); + double d5 = deltaMovement.x; + double d6 = deltaMovement.y; + double d1 = deltaMovement.z; + + double d7 = this.getX() + d5; + double d2 = this.getY() + d6; + double d3 = this.getZ() + d1; + double d4 = deltaMovement.horizontalDistance(); + if (flag) { + this.setYRot((float)(Mth.atan2(-d5, -d1) * (double)(180F / (float)Math.PI))); + } else { + this.setYRot((float)(Mth.atan2(d5, d1) * (double)(180F / (float)Math.PI))); + } + + this.setXRot((float)(Mth.atan2(d6, d4) * (double)(180F / (float)Math.PI))); + this.setXRot(lerpRotation(this.xRotO, this.getXRot())); + this.setYRot(lerpRotation(this.yRotO, this.getYRot())); + + float f = 0.99F; + this.setDeltaMovement(deltaMovement.scale((double)f)); + if (!this.isNoGravity() && !flag) { + Vec3 vec34 = this.getDeltaMovement(); + this.setDeltaMovement(vec34.x, vec34.y - (double)0.05F, vec34.z); + } + + this.setPos(d7, d2, d3); + this.checkInsideBlocks(); + } + + @Nullable + protected EntityHitResult findHitEntity(Vec3 pos, Vec3 delta) { + return getEntityHitResult(this.level, this, pos, delta, + this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(2.0D), + this::canHitEntity, 0.3F); + } + + @Nullable + public static EntityHitResult getEntityHitResult(Level level, Entity thisEntity, Vec3 pos, Vec3 delta, AABB thisAABB, Predicate canBeHit, float scale) { + double maxDist = Double.MAX_VALUE; + Entity entity = null; + + for(Entity otherEntity : level.getEntities(thisEntity, thisAABB, canBeHit)) { +// System.out.println("ENTITY NEARBY: " + otherEntity); + AABB aabb = otherEntity.getBoundingBox().inflate(scale); + Optional optional = aabb.clip(pos, delta); + if (optional.isPresent()) { + double dist = pos.distanceToSqr(optional.get()); + if (dist < maxDist) { + entity = otherEntity; + maxDist = dist; + } + } + } + + return entity == null ? null : new EntityHitResult(entity); + } + + public boolean canHitEntity(Entity otherEntity) { + if (!otherEntity.canBeHitByProjectile()) { + return false; + } else { + Entity entity = this.getOwner(); +// if (entity != null) { +// if (otherEntity instanceof TestProjectileEntity other) { +// System.out.println("THIS OWNER: " + entity + " | " + !entity.isPassengerOfSameVehicle(otherEntity)); +// System.out.println("THAT OWNER: " + other.getOwner()); +// } +// } + return entity == null || this.leftOwner || !entity.isPassengerOfSameVehicle(otherEntity); + } + } + + public void setTimeToKill(int ticks) { + this.ttk = ticks; + } + + protected void tickDespawn() { + ++this.life; + if (this.life >= ttk) { +// System.out.println("BYE BYE BBY"); + this.discard(); + } + } + + @Override + protected void defineSynchedData() { + this.entityData.define(ID_FLAGS, (byte)0); + this.entityData.define(PIERCE_LEVEL, (byte)0); + } + + public boolean isNoPhysics() { + if (!this.level.isClientSide) { + return this.noPhysics; + } else { + return (this.entityData.get(ID_FLAGS) & 2) != 0; + } + } + + protected void onHitEntity(EntityHitResult entityHitResult) { + Entity entity = entityHitResult.getEntity(); + if (entity instanceof Blaze) { + if (this.getOwner() != null) { + this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); + } + } else if (entity instanceof ElementCollision fireProjectileEntity) { + if (this.getOwner() != null && this.level.isClientSide) { + ElementCollision collisionEntity = new ElementCollision(this.getX(), this.getY(), this.getZ(), level); + collisionEntity.setTimeToKill(5); + level.addFreshEntity(collisionEntity); + EntityEffect entityEffect = new EntityEffect(orb_bloom, level, collisionEntity); + entityEffect.start(); + System.out.println("SUCCESS COLLISION!!!"); + this.discard(); + fireProjectileEntity.discard(); + } + } else { + // TODO - Check if player entity has countered + int i = 10; // Deal 10 damage + entity.hurt(this.damageSources().thrown(this, this.getOwner()), (float)i); + this.discard(); + } + } + + protected void onHitBlock(BlockHitResult blockHitResult) { +// super.onHitBlock(blockHitResult); + this.discard(); + } + + protected void onHit(HitResult hitResult) { + super.onHit(hitResult); + if (!this.level.isClientSide) { + this.level.broadcastEntityEvent(this, (byte)3); +// this.discard(); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/amuzil/omegasource/magus/entity/projectile/AirProjectile.java b/src/main/java/com/amuzil/omegasource/magus/entity/projectile/AirProjectile.java new file mode 100644 index 0000000..2b11f49 --- /dev/null +++ b/src/main/java/com/amuzil/omegasource/magus/entity/projectile/AirProjectile.java @@ -0,0 +1,260 @@ +package com.amuzil.omegasource.magus.entity.projectile; + +import com.amuzil.omegasource.magus.entity.AvatarEntities; +import com.amuzil.omegasource.magus.entity.ElementProjectile; +import com.lowdragmc.photon.client.fx.EntityEffect; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.monster.Blaze; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.*; +import net.minecraft.world.phys.shapes.VoxelShape; + +import javax.annotation.Nullable; +import java.util.Optional; +import java.util.function.Predicate; + +import static com.amuzil.omegasource.magus.skill.test.avatar.AvatarFormRegistry.orb_bloom; + + +public class AirProjectile extends ElementProjectile { + private static final EntityDataAccessor ID_FLAGS = SynchedEntityData.defineId(AirProjectile.class, EntityDataSerializers.BYTE); + private static final EntityDataAccessor PIERCE_LEVEL = SynchedEntityData.defineId(AirProjectile.class, EntityDataSerializers.BYTE); + private int life; + private int ttk = 100; + + public AirProjectile(EntityType type, Level level) { + super(type, level); + } + + public AirProjectile(double x, double y, double z, Level level) { + this(AvatarEntities.AIR_PROJECTILE_ENTITY_TYPE.get(), level); + this.setPos(x, y, z); + } + + public AirProjectile(LivingEntity livingEntity, Level level) { + this(livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level); + this.setOwner(livingEntity); + this.setNoGravity(true); + } + + public void tick() { + super.tick(); + boolean flag = this.isNoPhysics(); + Vec3 deltaMovement = this.getDeltaMovement(); + if (this.xRotO == 0.0F && this.yRotO == 0.0F) { + double distance = deltaMovement.horizontalDistance(); + this.setYRot((float)(Mth.atan2(deltaMovement.x, deltaMovement.z) * (double)(180F / (float)Math.PI))); + this.setXRot((float)(Mth.atan2(deltaMovement.y, distance) * (double)(180F / (float)Math.PI))); + this.yRotO = this.getYRot(); + this.xRotO = this.getXRot(); + } + + BlockPos blockpos = this.blockPosition(); + BlockState blockstate = this.level.getBlockState(blockpos); + if (!blockstate.isAir() && !flag) { + VoxelShape voxelshape = blockstate.getCollisionShape(this.level, blockpos); + if (!voxelshape.isEmpty()) { + Vec3 vec31 = this.position(); + + for(AABB aabb : voxelshape.toAabbs()) { + if (aabb.move(blockpos).contains(vec31)) { + break; + } + } + } + } + + if (this.isInWaterOrRain() || blockstate.is(Blocks.POWDER_SNOW) || this.isInFluidType((fluidType, height) -> this.canFluidExtinguish(fluidType))) { + this.clearFire(); + } + + Vec3 pos = this.position(); + Vec3 delta = pos.add(deltaMovement); + HitResult hitresult = this.level.clip(new ClipContext(pos, delta, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)); + if (hitresult.getType() != HitResult.Type.MISS) { + delta = hitresult.getLocation(); + } + + while(!this.isRemoved()) { + if (!this.level.isClientSide) { + this.tickDespawn(); + } + EntityHitResult entityhitresult = this.findHitEntity(pos, delta); + if (entityhitresult != null) { + hitresult = entityhitresult; + } + + if (hitresult != null && hitresult.getType() == HitResult.Type.ENTITY) { + assert hitresult instanceof EntityHitResult; + Entity entity = ((EntityHitResult)hitresult).getEntity(); + Entity owner = this.getOwner(); + if (entity instanceof Player && owner instanceof Player && !((Player)owner).canHarmPlayer((Player)entity)) { + hitresult = null; + entityhitresult = null; + } + } + + if (hitresult != null && hitresult.getType() != HitResult.Type.MISS && !flag) { + if (net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, hitresult)) + break; + this.onHit(hitresult); + this.hasImpulse = true; + break; + } + + if (entityhitresult == null) { + break; + } + + hitresult = null; + } + deltaMovement = this.getDeltaMovement(); + double d5 = deltaMovement.x; + double d6 = deltaMovement.y; + double d1 = deltaMovement.z; + + double d7 = this.getX() + d5; + double d2 = this.getY() + d6; + double d3 = this.getZ() + d1; + double d4 = deltaMovement.horizontalDistance(); + if (flag) { + this.setYRot((float)(Mth.atan2(-d5, -d1) * (double)(180F / (float)Math.PI))); + } else { + this.setYRot((float)(Mth.atan2(d5, d1) * (double)(180F / (float)Math.PI))); + } + + this.setXRot((float)(Mth.atan2(d6, d4) * (double)(180F / (float)Math.PI))); + this.setXRot(lerpRotation(this.xRotO, this.getXRot())); + this.setYRot(lerpRotation(this.yRotO, this.getYRot())); + + float f = 0.99F; + this.setDeltaMovement(deltaMovement.scale((double)f)); + if (!this.isNoGravity() && !flag) { + Vec3 vec34 = this.getDeltaMovement(); + this.setDeltaMovement(vec34.x, vec34.y - (double)0.05F, vec34.z); + } + + this.setPos(d7, d2, d3); + this.checkInsideBlocks(); + } + + @Nullable + protected EntityHitResult findHitEntity(Vec3 pos, Vec3 delta) { + return getEntityHitResult(this.level, this, pos, delta, + this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(2.0D), + this::canHitEntity, 0.3F); + } + + @Nullable + public static EntityHitResult getEntityHitResult(Level level, Entity thisEntity, Vec3 pos, Vec3 delta, AABB thisAABB, Predicate canBeHit, float scale) { + double maxDist = Double.MAX_VALUE; + Entity entity = null; + + for(Entity otherEntity : level.getEntities(thisEntity, thisAABB, canBeHit)) { +// System.out.println("ENTITY NEARBY: " + otherEntity); + AABB aabb = otherEntity.getBoundingBox().inflate(scale); + Optional optional = aabb.clip(pos, delta); + if (optional.isPresent()) { + double dist = pos.distanceToSqr(optional.get()); + if (dist < maxDist) { + entity = otherEntity; + maxDist = dist; + } + } + } + + return entity == null ? null : new EntityHitResult(entity); + } + + public boolean canHitEntity(Entity otherEntity) { + if (!otherEntity.canBeHitByProjectile()) { + return false; + } else { + Entity entity = this.getOwner(); +// if (entity != null) { +// if (otherEntity instanceof TestProjectileEntity other) { +// System.out.println("THIS OWNER: " + entity + " | " + !entity.isPassengerOfSameVehicle(otherEntity)); +// System.out.println("THAT OWNER: " + other.getOwner()); +// } +// } + return entity == null || this.leftOwner || !entity.isPassengerOfSameVehicle(otherEntity); + } + } + + public void setTimeToKill(int ticks) { + this.ttk = ticks; + } + + protected void tickDespawn() { + ++this.life; + if (this.life >= ttk) { +// System.out.println("BYE BYE BBY"); + this.discard(); + } + } + + @Override + protected void defineSynchedData() { + this.entityData.define(ID_FLAGS, (byte)0); + this.entityData.define(PIERCE_LEVEL, (byte)0); + } + + public boolean isNoPhysics() { + if (!this.level.isClientSide) { + return this.noPhysics; + } else { + return (this.entityData.get(ID_FLAGS) & 2) != 0; + } + } + + protected void onHitEntity(EntityHitResult entityHitResult) { + Entity entity = entityHitResult.getEntity(); + if (entity instanceof Blaze) { + if (this.getOwner() != null) { + this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); + } + } else if (entity instanceof AirProjectile fireProjectileEntity) { + if (this.getOwner() != null && this.level.isClientSide) { + AirProjectile collisionEntity = new AirProjectile(this.getX(), this.getY(), this.getZ(), level); + collisionEntity.setTimeToKill(5); + level.addFreshEntity(collisionEntity); + EntityEffect entityEffect = new EntityEffect(orb_bloom, level, collisionEntity); + entityEffect.start(); + System.out.println("SUCCESS COLLISION!!!"); + this.discard(); + fireProjectileEntity.discard(); + } + } else { + // TODO - Check if player entity has countered + int i = 10; // Deal 10 damage + entity.hurt(this.damageSources().thrown(this, this.getOwner()), (float)i); + this.discard(); + } + } + + protected void onHitBlock(BlockHitResult blockHitResult) { +// super.onHitBlock(blockHitResult); + this.discard(); + } + + protected void onHit(HitResult hitResult) { + super.onHit(hitResult); + if (!this.level.isClientSide) { + this.level.broadcastEntityEvent(this, (byte)3); +// this.discard(); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/amuzil/omegasource/magus/entity/projectile/EarthProjectile.java b/src/main/java/com/amuzil/omegasource/magus/entity/projectile/EarthProjectile.java new file mode 100644 index 0000000..b633400 --- /dev/null +++ b/src/main/java/com/amuzil/omegasource/magus/entity/projectile/EarthProjectile.java @@ -0,0 +1,260 @@ +package com.amuzil.omegasource.magus.entity.projectile; + +import com.amuzil.omegasource.magus.entity.AvatarEntities; +import com.amuzil.omegasource.magus.entity.ElementProjectile; +import com.lowdragmc.photon.client.fx.EntityEffect; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.monster.Blaze; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.*; +import net.minecraft.world.phys.shapes.VoxelShape; + +import javax.annotation.Nullable; +import java.util.Optional; +import java.util.function.Predicate; + +import static com.amuzil.omegasource.magus.skill.test.avatar.AvatarFormRegistry.orb_bloom; + + +public class EarthProjectile extends ElementProjectile { + private static final EntityDataAccessor ID_FLAGS = SynchedEntityData.defineId(EarthProjectile.class, EntityDataSerializers.BYTE); + private static final EntityDataAccessor PIERCE_LEVEL = SynchedEntityData.defineId(EarthProjectile.class, EntityDataSerializers.BYTE); + private int life; + private int ttk = 100; + + public EarthProjectile(EntityType type, Level level) { + super(type, level); + } + + public EarthProjectile(double x, double y, double z, Level level) { + this(AvatarEntities.EARTH_PROJECTILE_ENTITY_TYPE.get(), level); + this.setPos(x, y, z); + } + + public EarthProjectile(LivingEntity livingEntity, Level level) { + this(livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level); + this.setOwner(livingEntity); + this.setNoGravity(true); + } + + public void tick() { + super.tick(); + boolean flag = this.isNoPhysics(); + Vec3 deltaMovement = this.getDeltaMovement(); + if (this.xRotO == 0.0F && this.yRotO == 0.0F) { + double distance = deltaMovement.horizontalDistance(); + this.setYRot((float)(Mth.atan2(deltaMovement.x, deltaMovement.z) * (double)(180F / (float)Math.PI))); + this.setXRot((float)(Mth.atan2(deltaMovement.y, distance) * (double)(180F / (float)Math.PI))); + this.yRotO = this.getYRot(); + this.xRotO = this.getXRot(); + } + + BlockPos blockpos = this.blockPosition(); + BlockState blockstate = this.level.getBlockState(blockpos); + if (!blockstate.isAir() && !flag) { + VoxelShape voxelshape = blockstate.getCollisionShape(this.level, blockpos); + if (!voxelshape.isEmpty()) { + Vec3 vec31 = this.position(); + + for(AABB aabb : voxelshape.toAabbs()) { + if (aabb.move(blockpos).contains(vec31)) { + break; + } + } + } + } + + if (this.isInWaterOrRain() || blockstate.is(Blocks.POWDER_SNOW) || this.isInFluidType((fluidType, height) -> this.canFluidExtinguish(fluidType))) { + this.clearFire(); + } + + Vec3 pos = this.position(); + Vec3 delta = pos.add(deltaMovement); + HitResult hitresult = this.level.clip(new ClipContext(pos, delta, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)); + if (hitresult.getType() != HitResult.Type.MISS) { + delta = hitresult.getLocation(); + } + + while(!this.isRemoved()) { + if (!this.level.isClientSide) { + this.tickDespawn(); + } + EntityHitResult entityhitresult = this.findHitEntity(pos, delta); + if (entityhitresult != null) { + hitresult = entityhitresult; + } + + if (hitresult != null && hitresult.getType() == HitResult.Type.ENTITY) { + assert hitresult instanceof EntityHitResult; + Entity entity = ((EntityHitResult)hitresult).getEntity(); + Entity owner = this.getOwner(); + if (entity instanceof Player && owner instanceof Player && !((Player)owner).canHarmPlayer((Player)entity)) { + hitresult = null; + entityhitresult = null; + } + } + + if (hitresult != null && hitresult.getType() != HitResult.Type.MISS && !flag) { + if (net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, hitresult)) + break; + this.onHit(hitresult); + this.hasImpulse = true; + break; + } + + if (entityhitresult == null) { + break; + } + + hitresult = null; + } + deltaMovement = this.getDeltaMovement(); + double d5 = deltaMovement.x; + double d6 = deltaMovement.y; + double d1 = deltaMovement.z; + + double d7 = this.getX() + d5; + double d2 = this.getY() + d6; + double d3 = this.getZ() + d1; + double d4 = deltaMovement.horizontalDistance(); + if (flag) { + this.setYRot((float)(Mth.atan2(-d5, -d1) * (double)(180F / (float)Math.PI))); + } else { + this.setYRot((float)(Mth.atan2(d5, d1) * (double)(180F / (float)Math.PI))); + } + + this.setXRot((float)(Mth.atan2(d6, d4) * (double)(180F / (float)Math.PI))); + this.setXRot(lerpRotation(this.xRotO, this.getXRot())); + this.setYRot(lerpRotation(this.yRotO, this.getYRot())); + + float f = 0.99F; + this.setDeltaMovement(deltaMovement.scale((double)f)); + if (!this.isNoGravity() && !flag) { + Vec3 vec34 = this.getDeltaMovement(); + this.setDeltaMovement(vec34.x, vec34.y - (double)0.05F, vec34.z); + } + + this.setPos(d7, d2, d3); + this.checkInsideBlocks(); + } + + @Nullable + protected EntityHitResult findHitEntity(Vec3 pos, Vec3 delta) { + return getEntityHitResult(this.level, this, pos, delta, + this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(2.0D), + this::canHitEntity, 0.3F); + } + + @Nullable + public static EntityHitResult getEntityHitResult(Level level, Entity thisEntity, Vec3 pos, Vec3 delta, AABB thisAABB, Predicate canBeHit, float scale) { + double maxDist = Double.MAX_VALUE; + Entity entity = null; + + for(Entity otherEntity : level.getEntities(thisEntity, thisAABB, canBeHit)) { +// System.out.println("ENTITY NEARBY: " + otherEntity); + AABB aabb = otherEntity.getBoundingBox().inflate(scale); + Optional optional = aabb.clip(pos, delta); + if (optional.isPresent()) { + double dist = pos.distanceToSqr(optional.get()); + if (dist < maxDist) { + entity = otherEntity; + maxDist = dist; + } + } + } + + return entity == null ? null : new EntityHitResult(entity); + } + + public boolean canHitEntity(Entity otherEntity) { + if (!otherEntity.canBeHitByProjectile()) { + return false; + } else { + Entity entity = this.getOwner(); +// if (entity != null) { +// if (otherEntity instanceof TestProjectileEntity other) { +// System.out.println("THIS OWNER: " + entity + " | " + !entity.isPassengerOfSameVehicle(otherEntity)); +// System.out.println("THAT OWNER: " + other.getOwner()); +// } +// } + return entity == null || this.leftOwner || !entity.isPassengerOfSameVehicle(otherEntity); + } + } + + public void setTimeToKill(int ticks) { + this.ttk = ticks; + } + + protected void tickDespawn() { + ++this.life; + if (this.life >= ttk) { +// System.out.println("BYE BYE BBY"); + this.discard(); + } + } + + @Override + protected void defineSynchedData() { + this.entityData.define(ID_FLAGS, (byte)0); + this.entityData.define(PIERCE_LEVEL, (byte)0); + } + + public boolean isNoPhysics() { + if (!this.level.isClientSide) { + return this.noPhysics; + } else { + return (this.entityData.get(ID_FLAGS) & 2) != 0; + } + } + + protected void onHitEntity(EntityHitResult entityHitResult) { + Entity entity = entityHitResult.getEntity(); + if (entity instanceof Blaze) { + if (this.getOwner() != null) { + this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); + } + } else if (entity instanceof EarthProjectile fireProjectileEntity) { + if (this.getOwner() != null && this.level.isClientSide) { + EarthProjectile collisionEntity = new EarthProjectile(this.getX(), this.getY(), this.getZ(), level); + collisionEntity.setTimeToKill(5); + level.addFreshEntity(collisionEntity); + EntityEffect entityEffect = new EntityEffect(orb_bloom, level, collisionEntity); + entityEffect.start(); + System.out.println("SUCCESS COLLISION!!!"); + this.discard(); + fireProjectileEntity.discard(); + } + } else { + // TODO - Check if player entity has countered + int i = 10; // Deal 10 damage + entity.hurt(this.damageSources().thrown(this, this.getOwner()), (float)i); + this.discard(); + } + } + + protected void onHitBlock(BlockHitResult blockHitResult) { +// super.onHitBlock(blockHitResult); + this.discard(); + } + + protected void onHit(HitResult hitResult) { + super.onHit(hitResult); + if (!this.level.isClientSide) { + this.level.broadcastEntityEvent(this, (byte)3); +// this.discard(); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/amuzil/omegasource/magus/entity/TestProjectileEntity.java b/src/main/java/com/amuzil/omegasource/magus/entity/projectile/FireProjectile.java similarity index 81% rename from src/main/java/com/amuzil/omegasource/magus/entity/TestProjectileEntity.java rename to src/main/java/com/amuzil/omegasource/magus/entity/projectile/FireProjectile.java index f209c04..5334152 100644 --- a/src/main/java/com/amuzil/omegasource/magus/entity/TestProjectileEntity.java +++ b/src/main/java/com/amuzil/omegasource/magus/entity/projectile/FireProjectile.java @@ -1,5 +1,8 @@ -package com.amuzil.omegasource.magus.entity; +package com.amuzil.omegasource.magus.entity.projectile; +import com.amuzil.omegasource.magus.entity.AvatarEntities; +import com.amuzil.omegasource.magus.entity.ElementProjectile; +import com.amuzil.omegasource.magus.entity.collision.ElementCollision; import com.lowdragmc.photon.client.fx.EntityEffect; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleOptions; @@ -13,14 +16,10 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.monster.Blaze; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.entity.projectile.ItemSupplier; -import net.minecraft.world.entity.projectile.Projectile; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.*; import net.minecraft.world.phys.shapes.VoxelShape; @@ -31,45 +30,29 @@ import static com.amuzil.omegasource.magus.skill.test.avatar.AvatarFormRegistry.orb_bloom; -public class TestProjectileEntity extends Projectile implements ItemSupplier { - public static final ItemStack PROJECTILE_ITEM = new ItemStack(Blocks.AIR); - private static final EntityDataAccessor ID_FLAGS = SynchedEntityData.defineId(TestProjectileEntity.class, EntityDataSerializers.BYTE); - private static final EntityDataAccessor PIERCE_LEVEL = SynchedEntityData.defineId(TestProjectileEntity.class, EntityDataSerializers.BYTE); - private boolean leftOwner; - private boolean hasBeenShot; +public class FireProjectile extends ElementProjectile { + private static final EntityDataAccessor ID_FLAGS = SynchedEntityData.defineId(FireProjectile.class, EntityDataSerializers.BYTE); + private static final EntityDataAccessor PIERCE_LEVEL = SynchedEntityData.defineId(FireProjectile.class, EntityDataSerializers.BYTE); private int life; private int ttk = 100; - public TestProjectileEntity(EntityType type, Level level) { + public FireProjectile(EntityType type, Level level) { super(type, level); } - public TestProjectileEntity(double x, double y, double z, Level level) { - this(AvatarEntities.TEST_PROJECTILE.get(), level); + public FireProjectile(double x, double y, double z, Level level) { + this(AvatarEntities.FIRE_PROJECTILE_ENTITY_TYPE.get(), level); this.setPos(x, y, z); } - public TestProjectileEntity(LivingEntity livingEntity, Level level) { + public FireProjectile(LivingEntity livingEntity, Level level) { this(livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level); this.setOwner(livingEntity); this.setNoGravity(true); } - public void projectileTick() { - if (!this.hasBeenShot) { - this.gameEvent(GameEvent.PROJECTILE_SHOOT, this.getOwner()); - this.hasBeenShot = true; - } - - if (!this.leftOwner) { - this.leftOwner = this.checkLeftOwner(); - } - - super.tick(); - } - public void tick() { - this.projectileTick(); + super.tick(); boolean flag = this.isNoPhysics(); Vec3 deltaMovement = this.getDeltaMovement(); if (this.xRotO == 0.0F && this.yRotO == 0.0F) { @@ -212,7 +195,7 @@ public boolean canHitEntity(Entity otherEntity) { } } - protected void setTimeToKill(int ticks) { + public void setTimeToKill(int ticks) { this.ttk = ticks; } @@ -235,20 +218,6 @@ protected void defineSynchedData() { this.entityData.define(PIERCE_LEVEL, (byte)0); } - private boolean checkLeftOwner() { - Entity owner = this.getOwner(); - if (owner != null) { - for(Entity entity1 : this.level.getEntities(this, this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(1.0D), (entity) -> { - return !entity.isSpectator() && entity.isPickable(); - })) { - if (entity1.getRootVehicle() == owner.getRootVehicle()) { - return false; - } - } - } - return true; - } - public boolean isNoPhysics() { if (!this.level.isClientSide) { return this.noPhysics; @@ -272,16 +241,16 @@ protected void onHitEntity(EntityHitResult entityHitResult) { if (this.getOwner() != null) { this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); } - } else if (entity instanceof TestProjectileEntity testProjectileEntity) { + } else if (entity instanceof ElementProjectile elementProjectile) { if (this.getOwner() != null && this.level.isClientSide) { - TestProjectileEntity collisionEntity = new TestProjectileEntity(this.getX(), this.getY(), this.getZ(), level); + ElementCollision collisionEntity = new ElementCollision(this.getX(), this.getY(), this.getZ(), level); collisionEntity.setTimeToKill(5); level.addFreshEntity(collisionEntity); EntityEffect entityEffect = new EntityEffect(orb_bloom, level, collisionEntity); entityEffect.start(); System.out.println("SUCCESS COLLISION!!!"); this.discard(); - testProjectileEntity.discard(); + elementProjectile.discard(); } } else { // TODO - Check if player entity has countered @@ -303,13 +272,4 @@ protected void onHit(HitResult hitResult) { // this.discard(); } } - - private ParticleOptions getParticle() { - return ParticleTypes.FLAME; - } - - @Override - public ItemStack getItem() { - return PROJECTILE_ITEM; - } } \ No newline at end of file diff --git a/src/main/java/com/amuzil/omegasource/magus/entity/projectile/WaterProjectile.java b/src/main/java/com/amuzil/omegasource/magus/entity/projectile/WaterProjectile.java new file mode 100644 index 0000000..fca79fd --- /dev/null +++ b/src/main/java/com/amuzil/omegasource/magus/entity/projectile/WaterProjectile.java @@ -0,0 +1,260 @@ +package com.amuzil.omegasource.magus.entity.projectile; + +import com.amuzil.omegasource.magus.entity.AvatarEntities; +import com.amuzil.omegasource.magus.entity.ElementProjectile; +import com.lowdragmc.photon.client.fx.EntityEffect; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.monster.Blaze; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.*; +import net.minecraft.world.phys.shapes.VoxelShape; + +import javax.annotation.Nullable; +import java.util.Optional; +import java.util.function.Predicate; + +import static com.amuzil.omegasource.magus.skill.test.avatar.AvatarFormRegistry.orb_bloom; + + +public class WaterProjectile extends ElementProjectile { + private static final EntityDataAccessor ID_FLAGS = SynchedEntityData.defineId(WaterProjectile.class, EntityDataSerializers.BYTE); + private static final EntityDataAccessor PIERCE_LEVEL = SynchedEntityData.defineId(WaterProjectile.class, EntityDataSerializers.BYTE); + private int life; + private int ttk = 100; + + public WaterProjectile(EntityType type, Level level) { + super(type, level); + } + + public WaterProjectile(double x, double y, double z, Level level) { + this(AvatarEntities.WATER_PROJECTILE_ENTITY_TYPE.get(), level); + this.setPos(x, y, z); + } + + public WaterProjectile(LivingEntity livingEntity, Level level) { + this(livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level); + this.setOwner(livingEntity); + this.setNoGravity(true); + } + + public void tick() { + super.tick(); + boolean flag = this.isNoPhysics(); + Vec3 deltaMovement = this.getDeltaMovement(); + if (this.xRotO == 0.0F && this.yRotO == 0.0F) { + double distance = deltaMovement.horizontalDistance(); + this.setYRot((float)(Mth.atan2(deltaMovement.x, deltaMovement.z) * (double)(180F / (float)Math.PI))); + this.setXRot((float)(Mth.atan2(deltaMovement.y, distance) * (double)(180F / (float)Math.PI))); + this.yRotO = this.getYRot(); + this.xRotO = this.getXRot(); + } + + BlockPos blockpos = this.blockPosition(); + BlockState blockstate = this.level.getBlockState(blockpos); + if (!blockstate.isAir() && !flag) { + VoxelShape voxelshape = blockstate.getCollisionShape(this.level, blockpos); + if (!voxelshape.isEmpty()) { + Vec3 vec31 = this.position(); + + for(AABB aabb : voxelshape.toAabbs()) { + if (aabb.move(blockpos).contains(vec31)) { + break; + } + } + } + } + + if (this.isInWaterOrRain() || blockstate.is(Blocks.POWDER_SNOW) || this.isInFluidType((fluidType, height) -> this.canFluidExtinguish(fluidType))) { + this.clearFire(); + } + + Vec3 pos = this.position(); + Vec3 delta = pos.add(deltaMovement); + HitResult hitresult = this.level.clip(new ClipContext(pos, delta, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)); + if (hitresult.getType() != HitResult.Type.MISS) { + delta = hitresult.getLocation(); + } + + while(!this.isRemoved()) { + if (!this.level.isClientSide) { + this.tickDespawn(); + } + EntityHitResult entityhitresult = this.findHitEntity(pos, delta); + if (entityhitresult != null) { + hitresult = entityhitresult; + } + + if (hitresult != null && hitresult.getType() == HitResult.Type.ENTITY) { + assert hitresult instanceof EntityHitResult; + Entity entity = ((EntityHitResult)hitresult).getEntity(); + Entity owner = this.getOwner(); + if (entity instanceof Player && owner instanceof Player && !((Player)owner).canHarmPlayer((Player)entity)) { + hitresult = null; + entityhitresult = null; + } + } + + if (hitresult != null && hitresult.getType() != HitResult.Type.MISS && !flag) { + if (net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, hitresult)) + break; + this.onHit(hitresult); + this.hasImpulse = true; + break; + } + + if (entityhitresult == null) { + break; + } + + hitresult = null; + } + deltaMovement = this.getDeltaMovement(); + double d5 = deltaMovement.x; + double d6 = deltaMovement.y; + double d1 = deltaMovement.z; + + double d7 = this.getX() + d5; + double d2 = this.getY() + d6; + double d3 = this.getZ() + d1; + double d4 = deltaMovement.horizontalDistance(); + if (flag) { + this.setYRot((float)(Mth.atan2(-d5, -d1) * (double)(180F / (float)Math.PI))); + } else { + this.setYRot((float)(Mth.atan2(d5, d1) * (double)(180F / (float)Math.PI))); + } + + this.setXRot((float)(Mth.atan2(d6, d4) * (double)(180F / (float)Math.PI))); + this.setXRot(lerpRotation(this.xRotO, this.getXRot())); + this.setYRot(lerpRotation(this.yRotO, this.getYRot())); + + float f = 0.99F; + this.setDeltaMovement(deltaMovement.scale((double)f)); + if (!this.isNoGravity() && !flag) { + Vec3 vec34 = this.getDeltaMovement(); + this.setDeltaMovement(vec34.x, vec34.y - (double)0.05F, vec34.z); + } + + this.setPos(d7, d2, d3); + this.checkInsideBlocks(); + } + + @Nullable + protected EntityHitResult findHitEntity(Vec3 pos, Vec3 delta) { + return getEntityHitResult(this.level, this, pos, delta, + this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(2.0D), + this::canHitEntity, 0.3F); + } + + @Nullable + public static EntityHitResult getEntityHitResult(Level level, Entity thisEntity, Vec3 pos, Vec3 delta, AABB thisAABB, Predicate canBeHit, float scale) { + double maxDist = Double.MAX_VALUE; + Entity entity = null; + + for(Entity otherEntity : level.getEntities(thisEntity, thisAABB, canBeHit)) { +// System.out.println("ENTITY NEARBY: " + otherEntity); + AABB aabb = otherEntity.getBoundingBox().inflate(scale); + Optional optional = aabb.clip(pos, delta); + if (optional.isPresent()) { + double dist = pos.distanceToSqr(optional.get()); + if (dist < maxDist) { + entity = otherEntity; + maxDist = dist; + } + } + } + + return entity == null ? null : new EntityHitResult(entity); + } + + public boolean canHitEntity(Entity otherEntity) { + if (!otherEntity.canBeHitByProjectile()) { + return false; + } else { + Entity entity = this.getOwner(); +// if (entity != null) { +// if (otherEntity instanceof TestProjectileEntity other) { +// System.out.println("THIS OWNER: " + entity + " | " + !entity.isPassengerOfSameVehicle(otherEntity)); +// System.out.println("THAT OWNER: " + other.getOwner()); +// } +// } + return entity == null || this.leftOwner || !entity.isPassengerOfSameVehicle(otherEntity); + } + } + + public void setTimeToKill(int ticks) { + this.ttk = ticks; + } + + protected void tickDespawn() { + ++this.life; + if (this.life >= ttk) { +// System.out.println("BYE BYE BBY"); + this.discard(); + } + } + + @Override + protected void defineSynchedData() { + this.entityData.define(ID_FLAGS, (byte)0); + this.entityData.define(PIERCE_LEVEL, (byte)0); + } + + public boolean isNoPhysics() { + if (!this.level.isClientSide) { + return this.noPhysics; + } else { + return (this.entityData.get(ID_FLAGS) & 2) != 0; + } + } + + protected void onHitEntity(EntityHitResult entityHitResult) { + Entity entity = entityHitResult.getEntity(); + if (entity instanceof Blaze) { + if (this.getOwner() != null) { + this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); + } + } else if (entity instanceof WaterProjectile fireProjectileEntity) { + if (this.getOwner() != null && this.level.isClientSide) { + WaterProjectile collisionEntity = new WaterProjectile(this.getX(), this.getY(), this.getZ(), level); + collisionEntity.setTimeToKill(5); + level.addFreshEntity(collisionEntity); + EntityEffect entityEffect = new EntityEffect(orb_bloom, level, collisionEntity); + entityEffect.start(); + System.out.println("SUCCESS COLLISION!!!"); + this.discard(); + fireProjectileEntity.discard(); + } + } else { + // TODO - Check if player entity has countered + int i = 10; // Deal 10 damage + entity.hurt(this.damageSources().thrown(this, this.getOwner()), (float)i); + this.discard(); + } + } + + protected void onHitBlock(BlockHitResult blockHitResult) { +// super.onHitBlock(blockHitResult); + this.discard(); + } + + protected void onHit(HitResult hitResult) { + super.onHit(hitResult); + if (!this.level.isClientSide) { + this.level.broadcastEntityEvent(this, (byte)3); +// this.discard(); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/amuzil/omegasource/magus/input/InputModule.java b/src/main/java/com/amuzil/omegasource/magus/input/InputModule.java index 10ab846..98afccf 100644 --- a/src/main/java/com/amuzil/omegasource/magus/input/InputModule.java +++ b/src/main/java/com/amuzil/omegasource/magus/input/InputModule.java @@ -5,8 +5,8 @@ import com.amuzil.omegasource.magus.radix.RadixTree; import com.amuzil.omegasource.magus.radix.condition.minecraft.forge.EventCondition; import com.amuzil.omegasource.magus.skill.conditionals.InputData; -import com.amuzil.omegasource.magus.skill.elements.Discipline; -import com.amuzil.omegasource.magus.skill.elements.Disciplines; +import com.amuzil.omegasource.magus.skill.elements.Element; +import com.amuzil.omegasource.magus.skill.elements.Elements; import com.amuzil.omegasource.magus.skill.forms.Form; import com.amuzil.omegasource.magus.skill.forms.FormDataRegistry; import com.amuzil.omegasource.magus.skill.forms.Forms; @@ -28,7 +28,7 @@ public abstract class InputModule { - public static Discipline activeDiscipline = Disciplines.AIR; + public static Element activeElement = Elements.FIRE; protected static final List activeFormInputs = new ArrayList<>(); protected static final Map movementKeys = new HashMap<>(); protected static RadixTree formsTree = new RadixTree(); @@ -76,8 +76,12 @@ public static void determineMotionKeys() { }); } - public static Discipline getDiscipline() { - return activeDiscipline; + public static Element getDiscipline() { + return activeElement; + } + + public static void setDiscipline(Element element) { + activeElement = element; } public static Map getMovementKeys() { @@ -92,7 +96,7 @@ public static void resetFormsTree() { FormDataRegistry.init(); // Re-initialize formData since it's a static field formsTree = new RadixTree(); // Default is air. - formsTree.setDiscipline(activeDiscipline); + formsTree.setDiscipline(activeElement); } public abstract void registerInputData(List formExecutionInputs, Form formToExecute, List conditions); @@ -101,7 +105,7 @@ public void registerModifiers() { // registerModifierListener(ModifiersRegistry.CONTROL.listener(), Minecraft.getInstance().player.getPersistentData()); // Need to register this to the player's compound tag... CompoundTag listenerInstanceData = new CompoundTag(); - listenerInstanceData.putString("activeElement", activeDiscipline.name()); + listenerInstanceData.putString("activeElement", activeElement.name()); for (Modifier modifier : ModifiersRegistry.getModifiers()) { if (modifier.listener() != null) registerModifierListener(modifier.listener(), listenerInstanceData); diff --git a/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java b/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java index 1cbab3a..fc09f29 100644 --- a/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java +++ b/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java @@ -6,7 +6,7 @@ import com.amuzil.omegasource.magus.network.packets.server_executed.SendModifierDataPacket; import com.amuzil.omegasource.magus.radix.*; import com.amuzil.omegasource.magus.skill.conditionals.InputData; -import com.amuzil.omegasource.magus.skill.elements.Discipline; +import com.amuzil.omegasource.magus.skill.elements.Element; import com.amuzil.omegasource.magus.skill.forms.Form; import com.amuzil.omegasource.magus.skill.forms.FormDataRegistry; import com.amuzil.omegasource.magus.skill.forms.Forms; @@ -57,7 +57,7 @@ public class KeyboardMouseInputModule extends InputModule { // forms are activated. public KeyboardMouseInputModule() { - formsTree.setDiscipline(activeDiscipline); + formsTree.setDiscipline(activeElement); this.ticksSinceActivated = new AtomicInteger(0); this.activeForm = new AtomicReference<>(Forms.NULL); @@ -156,9 +156,8 @@ public KeyboardMouseInputModule() { // Extra check for race conditions. Probably wont' help... synchronized (lastActivatedForm.get()) { if (!lastActivatedForm.get().name().equals("null")) { - if (Minecraft.getInstance().getConnection() != null) { - MagusNetwork.sendToServer(new FormActivatedPacket(activeForm.get(), 0)); - } + if (Minecraft.getInstance().getConnection() != null) + MagusNetwork.sendToServer(new FormActivatedPacket(activeForm.get(), activeElement, 0)); // sendDebugMsg("Form Activated: " + lastActivatedForm.get().name()); } } @@ -211,9 +210,9 @@ public KeyboardMouseInputModule() { }; } - public static void setActiveDiscipline(Discipline discipline) { - activeDiscipline = discipline; - formsTree.setDiscipline(discipline); + public static void setActiveDiscipline(Element element) { + activeElement = element; + formsTree.setDiscipline(element); } private void checkForForm() { diff --git a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java index 2db04bd..07714cd 100644 --- a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java +++ b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java @@ -1,19 +1,17 @@ package com.amuzil.omegasource.magus.network.packets.client_executed; +import com.amuzil.omegasource.magus.entity.ElementProjectile; import com.amuzil.omegasource.magus.network.MagusNetwork; import com.amuzil.omegasource.magus.network.packets.api.MagusPacket; import com.amuzil.omegasource.magus.registry.Registries; +import com.amuzil.omegasource.magus.skill.elements.Element; import com.amuzil.omegasource.magus.skill.forms.Form; -import com.amuzil.omegasource.magus.entity.TestProjectileEntity; -import com.lowdragmc.photon.client.fx.EntityEffect; -import com.lowdragmc.photon.client.fx.FX; import net.minecraft.client.Minecraft; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.DistExecutor; @@ -24,32 +22,35 @@ import java.util.function.Supplier; import static com.amuzil.omegasource.magus.Magus.MOD_ID; -import static com.amuzil.omegasource.magus.skill.test.avatar.AvatarFormRegistry.blue_fire; -import static com.amuzil.omegasource.magus.skill.test.avatar.AvatarFormRegistry.fire_bloom; public class FormActivatedPacket implements MagusPacket { private final Form form; + private final Element element; private final int entityId; // Entity ID to send back to client for FX - public FormActivatedPacket(Form form, int entityId) { + public FormActivatedPacket(Form form, Element element, int entityId) { this.form = Objects.requireNonNullElseGet(form, Form::new); + this.element = element; this.entityId = entityId; } public void toBytes(FriendlyByteBuf buf) { if (form != null) { buf.writeUtf(form.name()); + buf.writeUtf(element.name()); buf.writeInt(entityId); } } public static FormActivatedPacket fromBytes(FriendlyByteBuf buf) { - String name = buf.readUtf(); + String formName = buf.readUtf(); + String elementName = buf.readUtf(); int entityId = buf.readInt(); - Form form = Registries.FORMS.get().getValue(new ResourceLocation(MOD_ID, name)); - return new FormActivatedPacket(form, entityId); + Form form = Registries.FORMS.get().getValue(new ResourceLocation(MOD_ID, formName)); + Element element = (Element) Registries.SKILL_CATEGORIES.get().getValue(new ResourceLocation(MOD_ID, elementName)); + return new FormActivatedPacket(form, element, entityId); } // Client-side handler @@ -58,28 +59,21 @@ private static void handleClientSide(Form form, int entityId) { // Perform client-side particle effect or other rendering logic here Player player = Minecraft.getInstance().player; assert player != null; - Level level = player.level; - FX fx = null; - if (form.name().equals("strike")) - fx = fire_bloom; - if (form.name().equals("force")) - fx = blue_fire; - if (fx != null) { - TestProjectileEntity entity = (TestProjectileEntity) player.level.getEntity(entityId); - EntityEffect entityEffect = new EntityEffect(fx, level, entity); - entityEffect.start(); - System.out.println("HANDLE CLIENT PACKET ---> " + form); - } + ElementProjectile elementProjectile = (ElementProjectile) player.level.getEntity(entityId); + assert elementProjectile != null; + elementProjectile.startEffect(form, player); + System.out.println("HANDLE CLIENT PACKET ---> " + form); } // Server-side handler - public static void handleServerSide(Form form, ServerPlayer player) { + public static void handleServerSide(Form form, Element element, ServerPlayer player) { // Perform server-side entity spawning and updating logic and fire Form Event here ServerLevel level = player.getLevel(); - TestProjectileEntity entity = new TestProjectileEntity(player, level); + // TODO - Create/perform certain entity updates based on form and element + ElementProjectile entity = ElementProjectile.createElementEntity(form, element, player, level); entity.shoot(player.getViewVector(1).x, player.getViewVector(1).y, player.getViewVector(1).z, 1, 1); level.addFreshEntity(entity); - FormActivatedPacket packet = new FormActivatedPacket(form, entity.getId()); + FormActivatedPacket packet = new FormActivatedPacket(form, element, entity.getId()); // Predicate predicate = (serverPlayer) -> player.distanceToSqr(serverPlayer) < 2500; // for (ServerPlayer nearbyPlayer: level.getPlayers(predicate.and(LivingEntity::isAlive))) { @@ -99,7 +93,7 @@ public boolean handle(Supplier ctx) { } else { ServerPlayer player = ctx.get().getSender(); assert player != null; - handleServerSide(form, player); + handleServerSide(form, element, player); } }); return true; diff --git a/src/main/java/com/amuzil/omegasource/magus/radix/Node.java b/src/main/java/com/amuzil/omegasource/magus/radix/Node.java index 9032acb..109530e 100644 --- a/src/main/java/com/amuzil/omegasource/magus/radix/Node.java +++ b/src/main/java/com/amuzil/omegasource/magus/radix/Node.java @@ -3,8 +3,7 @@ import com.amuzil.omegasource.magus.network.MagusNetwork; import com.amuzil.omegasource.magus.network.packets.client_executed.RegisterModifierListenersPacket; import com.amuzil.omegasource.magus.network.packets.client_executed.UnregisterModifierListenersPacket; -import com.amuzil.omegasource.magus.skill.elements.Discipline; -import com.amuzil.omegasource.magus.skill.modifiers.ModifiersRegistry; +import com.amuzil.omegasource.magus.skill.elements.Element; import com.amuzil.omegasource.magus.skill.modifiers.api.Modifier; import com.amuzil.omegasource.magus.skill.modifiers.api.ModifierData; import com.mojang.datafixers.util.Pair; @@ -128,11 +127,11 @@ public synchronized List getModifiers() { return modifiers; } - public void registerModifierListeners(Discipline activeDiscipline, ServerPlayer player) { + public void registerModifierListeners(Element activeElement, ServerPlayer player) { CompoundTag listenerInstanceData = new CompoundTag(); //here we can send information to the client to help build the Modifier Listeners appropriately. - listenerInstanceData.putString("activeElement", activeDiscipline.name()); + listenerInstanceData.putString("activeElement", activeElement.name()); List modifierTypes = new ArrayList<>(); List modifiers = getModifiers(); diff --git a/src/main/java/com/amuzil/omegasource/magus/radix/RadixTree.java b/src/main/java/com/amuzil/omegasource/magus/radix/RadixTree.java index d8a71df..6872a9a 100644 --- a/src/main/java/com/amuzil/omegasource/magus/radix/RadixTree.java +++ b/src/main/java/com/amuzil/omegasource/magus/radix/RadixTree.java @@ -3,8 +3,7 @@ import com.amuzil.omegasource.magus.network.MagusNetwork; import com.amuzil.omegasource.magus.network.packets.server_executed.ConditionActivatedPacket; import com.amuzil.omegasource.magus.radix.condition.MultiClientCondition; -import com.amuzil.omegasource.magus.skill.elements.Discipline; -import com.amuzil.omegasource.magus.skill.modifiers.ModifiersRegistry; +import com.amuzil.omegasource.magus.skill.elements.Element; import com.amuzil.omegasource.magus.skill.modifiers.api.ModifierData; import com.amuzil.omegasource.magus.skill.modifiers.data.MultiModifierData; import net.minecraft.server.level.ServerPlayer; @@ -22,7 +21,7 @@ public class RadixTree { private Node active; private Condition lastActivated = null; // Fire is a test - private Discipline activeDiscipline = null; // Disciplines.FIRE; + private Element activeElement = null; // Disciplines.FIRE; private ConditionPath path; private Entity owner; @@ -224,7 +223,7 @@ public void burn() { } active = null; - activeDiscipline = null; + activeElement = null; } // ---------- Cali's RadixTree Impl ---------- @@ -234,8 +233,8 @@ public void start() { path = new ConditionPath(); } - public void setDiscipline(Discipline discipline) { - this.activeDiscipline = discipline; + public void setDiscipline(Element element) { + this.activeElement = element; } private void setActive(Node node) { @@ -281,7 +280,7 @@ private void setActive(Node node) { if (active.getModifiers().size() > 0 && owner instanceof ServerPlayer player) - active.registerModifierListeners(activeDiscipline, player); + active.registerModifierListeners(activeElement, player); if (active.onEnter() != null) { active.onEnter().accept(this); @@ -317,7 +316,7 @@ private void terminate() { // TODO: // Rather than relying on the input module to send packets, handle everything in the condition runnables? public void moveDown(Condition executedCondition) { - if (activeDiscipline == null) { + if (activeElement == null) { LogManager.getLogger().info("NO ELEMENT SELECTED"); return; } diff --git a/src/main/java/com/amuzil/omegasource/magus/registry/Registries.java b/src/main/java/com/amuzil/omegasource/magus/registry/Registries.java index da352b7..9017adc 100644 --- a/src/main/java/com/amuzil/omegasource/magus/registry/Registries.java +++ b/src/main/java/com/amuzil/omegasource/magus/registry/Registries.java @@ -2,8 +2,8 @@ import com.amuzil.omegasource.magus.Magus; import com.amuzil.omegasource.magus.radix.Condition; -import com.amuzil.omegasource.magus.skill.elements.Discipline; -import com.amuzil.omegasource.magus.skill.elements.Disciplines; +import com.amuzil.omegasource.magus.skill.elements.Element; +import com.amuzil.omegasource.magus.skill.elements.Elements; import com.amuzil.omegasource.magus.skill.forms.Form; import com.amuzil.omegasource.magus.skill.forms.Forms; import com.amuzil.omegasource.magus.skill.skill.Skill; @@ -91,9 +91,9 @@ public static void registerCondition(Condition registryCondition) { conditions.add(registryCondition); } - public static void registerDiscipline(Discipline discipline) { - categories.add(discipline); - Disciplines.DISCIPLINES.add(discipline); + public static void registerDiscipline(Element element) { + categories.add(element); + Elements.ELEMENTS.add(element); } @@ -149,6 +149,7 @@ public static void onMissing(MissingMappingsEvent event) { @SubscribeEvent public static void gameRegistry(RegisterEvent event) { + Elements.init(); Forms.init(); // Moved here so that forms registry gets populated /* Skill Categories. */ if (event.getRegistryKey().equals(SKILL_CATEGORIES.get().getRegistryKey())) { @@ -157,6 +158,8 @@ public static void gameRegistry(RegisterEvent event) { event.register(resKey, helper -> { + for (SkillCategory category : categories) + registry.register(category.name(), category); }); } diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/elements/Disciplines.java b/src/main/java/com/amuzil/omegasource/magus/skill/elements/Disciplines.java deleted file mode 100644 index 5e9439c..0000000 --- a/src/main/java/com/amuzil/omegasource/magus/skill/elements/Disciplines.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.amuzil.omegasource.magus.skill.elements; - -import java.util.ArrayList; -import java.util.List; - -public class Disciplines { - public static final List DISCIPLINES = new ArrayList<>(); - - public static final Discipline AIR = new Discipline("air"); - public static final Discipline WATER = new Discipline("water"); - public static final Discipline EARTH = new Discipline("earth"); - public static final Discipline FIRE = new Discipline("fire"); - - public static Discipline fromName(String name) { - return DISCIPLINES.stream().filter(element -> element.name().equals(name)).findFirst().get(); - } -} diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/elements/Discipline.java b/src/main/java/com/amuzil/omegasource/magus/skill/elements/Element.java similarity index 51% rename from src/main/java/com/amuzil/omegasource/magus/skill/elements/Discipline.java rename to src/main/java/com/amuzil/omegasource/magus/skill/elements/Element.java index 6e9563a..5b81390 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/elements/Discipline.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/elements/Element.java @@ -3,15 +3,26 @@ import com.amuzil.omegasource.magus.registry.Registries; import com.amuzil.omegasource.magus.skill.skill.SkillCategory; -public class Discipline extends SkillCategory { + +public class Element extends SkillCategory { private final String name; + private final Art art; - public Discipline(String name) { - this.name = name; + public Element(Element.Art art) { + this.name = art.name().toLowerCase(); + this.art = art; Registries.registerDiscipline(this); } public String name() { return name; } + + public Art type() { + return art; + } + + public enum Art { + AIR, WATER, EARTH, FIRE + } } diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/elements/Elements.java b/src/main/java/com/amuzil/omegasource/magus/skill/elements/Elements.java new file mode 100644 index 0000000..3308a76 --- /dev/null +++ b/src/main/java/com/amuzil/omegasource/magus/skill/elements/Elements.java @@ -0,0 +1,24 @@ +package com.amuzil.omegasource.magus.skill.elements; + +import java.util.ArrayList; +import java.util.List; + + +public class Elements { + public static final List ELEMENTS = new ArrayList<>(); + + public static final Element AIR = new Element(Element.Art.AIR); + public static final Element WATER = new Element(Element.Art.WATER); + public static final Element EARTH = new Element(Element.Art.EARTH); + public static final Element FIRE = new Element(Element.Art.FIRE); + + public static Element fromName(String name) { + return ELEMENTS.stream().filter(element -> element.name().equals(name)).findFirst().get(); + } + + public static Element fromArt(Element.Art art) { + return ELEMENTS.stream().filter(element -> element.type().equals(art)).findFirst().get(); + } + + public static void init() {} +} diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/forms/Forms.java b/src/main/java/com/amuzil/omegasource/magus/skill/forms/Forms.java index 186305d..ae4e3c7 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/forms/Forms.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/forms/Forms.java @@ -25,6 +25,5 @@ public class Forms { public static final Form MENU = new Form("menu"); public static final Form HOTKEY = new Form("hotkey"); - public static void init() { - } + public static void init() {} } diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/modifiers/listeners/TargetModifierListener.java b/src/main/java/com/amuzil/omegasource/magus/skill/modifiers/listeners/TargetModifierListener.java index 0db2f4b..f13f15b 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/modifiers/listeners/TargetModifierListener.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/modifiers/listeners/TargetModifierListener.java @@ -1,9 +1,8 @@ package com.amuzil.omegasource.magus.skill.modifiers.listeners; -import com.amuzil.omegasource.magus.Magus; import com.amuzil.omegasource.magus.input.InputModule; -import com.amuzil.omegasource.magus.skill.elements.Discipline; -import com.amuzil.omegasource.magus.skill.elements.Disciplines; +import com.amuzil.omegasource.magus.skill.elements.Element; +import com.amuzil.omegasource.magus.skill.elements.Elements; import com.amuzil.omegasource.magus.skill.modifiers.api.ModifierData; import com.amuzil.omegasource.magus.skill.modifiers.api.ModifierListener; import com.amuzil.omegasource.magus.skill.modifiers.data.TargetModifierData; @@ -29,7 +28,7 @@ // TODO: Configure which key this listener uses public class TargetModifierListener extends ModifierListener { private Vec3 lastTargetPosition; - private Discipline activeDiscipline; + private Element activeElement; public TargetModifierListener() { this.modifierData = new TargetModifierData(); @@ -37,14 +36,14 @@ public TargetModifierListener() { @Override public void setupListener(CompoundTag compoundTag) { - this.activeDiscipline = Disciplines.fromName(compoundTag.getString("activeElement")); + this.activeElement = Elements.fromName(compoundTag.getString("activeElement")); } @Override public boolean shouldCollectModifierData(InputEvent.MouseButton event) { //TODO: Fix this - this.activeDiscipline = InputModule.getDiscipline(); + this.activeElement = InputModule.getDiscipline(); if(event instanceof InputEvent.MouseButton.Post && // prevents double activation(Pre- and Post-event firing) event.getButton() == InputConstants.MOUSE_BUTTON_MIDDLE && event.getAction() == InputConstants.PRESS) { @@ -54,7 +53,7 @@ public boolean shouldCollectModifierData(InputEvent.MouseButton event) { Vec3 vector3d1 = mc.player.getViewVector(1.0F); double distance = 20; //todo max distance make this configurable Vec3 vector3d2 = vector3d.add(vector3d1.x * distance, vector3d1.y * distance, vector3d1.z * distance); - List> bendableMaterials = BendingMaterialUtil.getBendableMaterialsForElement(activeDiscipline); + List> bendableMaterials = BendingMaterialUtil.getBendableMaterialsForElement(activeElement); BlockHitResult hitresult = mc.player.level.clip(new ClipContext(vector3d, vector3d2, ClipContext.Block.COLLIDER, ClipContext.Fluid.ANY, player)); if (hitresult.getType() == HitResult.Type.BLOCK) { BlockPos locationHit = hitresult.getBlockPos(); diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/skill/SkillCategory.java b/src/main/java/com/amuzil/omegasource/magus/skill/skill/SkillCategory.java index eeb5be9..0a8cc24 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/skill/SkillCategory.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/skill/SkillCategory.java @@ -7,5 +7,7 @@ public class SkillCategory { //List of all skills available within the category public LinkedList skills = new LinkedList<>(); + public String name() { return "SkillCategory[ Blank ]"; } + //TODO: GUI stuff as data } diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java index df45f84..97dfb54 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java @@ -5,61 +5,66 @@ import com.amuzil.omegasource.magus.input.KeyboardMouseInputModule; import com.amuzil.omegasource.magus.network.packets.client_executed.FormActivatedPacket; import com.amuzil.omegasource.magus.registry.Registries; +import com.amuzil.omegasource.magus.skill.elements.Element; +import com.amuzil.omegasource.magus.skill.elements.Elements; import com.amuzil.omegasource.magus.skill.forms.Form; +import com.amuzil.omegasource.magus.skill.forms.FormDataRegistry; import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; +import java.util.Arrays; + import static com.amuzil.omegasource.magus.Magus.MOD_ID; public class AvatarCommand { - // Class for registering the '/gesture' command + private static LiteralArgumentBuilder builder = Commands.literal("avatar"); + // Class for registering the '/avatar' command public static void register(CommandDispatcher dispatcher) { - dispatcher.register(Commands.literal("avatar") - .then(Commands.literal("key") - .then(Commands.argument("value", IntegerArgumentType.integer()) - .executes(c -> key(IntegerArgumentType.getInteger(c, "value"))) - ) - .executes(c -> record()) - ) - .then(Commands.literal("tree") - .then(Commands.literal("reset") - .executes(c -> reset()) - ) - .executes(c -> tree()) - ) - .then(createActivateFormCommand()) - .executes(c -> { - InputModule.sendDebugMsg("Options: activate_form, tree, reset"); - return 1; - }) + builder.then( + Commands.literal("tree") + .executes(c -> tree()) + .then(Commands.literal("reset") + .executes(c -> reset())) + ) + .executes(c -> { + // Default message when no options are provided. + InputModule.sendDebugMsg("Options: activate, tree, reset"); + return 1; + }); + + createActivateArtCommand(); + createActivateFormCommand(); + dispatcher.register(builder); + } + + private static void createActivateArtCommand() { + Arrays.stream(Element.Art.values()).toList().forEach(elem -> + builder.then(Commands.literal("activate") + .then(Commands.literal(elem.name().toLowerCase()).executes(c -> activateElement(c, elem)))) ); } - private static LiteralArgumentBuilder createActivateFormCommand() { - return Commands.literal("activate") - .then(Commands.argument("form", StringArgumentType.string()) + private static void createActivateFormCommand() { + var commandBuilder = builder.then(Commands.literal("activate")); + Registries.forms.forEach(form -> commandBuilder.then(Commands.literal("form") + .then(Commands.literal(form.name().toLowerCase()) .then(Commands.argument("target", EntityArgument.player()) .executes(c -> activateForm( - StringArgumentType.getString(c, "form"), + form.name().toLowerCase(), EntityArgument.getPlayer(c, "target"))) ) - ); - } - - private static int key(int keyValue) { - return 1; - } - - private static int record() { - return 1; + ) + )); } private static int tree() { @@ -81,7 +86,14 @@ private static int reset() { private static int activateForm(String name, ServerPlayer player) { Form form = Registries.FORMS.get().getValue(new ResourceLocation(MOD_ID, name)); - FormActivatedPacket.handleServerSide(form, player); + FormActivatedPacket.handleServerSide(form, InputModule.activeElement, player); + return 1; + } + + private static int activateElement(CommandContext ctx, Element.Art art) throws CommandSyntaxException { + InputModule.setDiscipline(Elements.fromArt(art)); + ServerPlayer player = ctx.getSource().getPlayerOrException(); + player.sendSystemMessage(Component.literal("Bending set to " + art)); return 1; } } \ No newline at end of file diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/util/bending/BendingMaterialUtil.java b/src/main/java/com/amuzil/omegasource/magus/skill/util/bending/BendingMaterialUtil.java index 9971cf2..9401647 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/util/bending/BendingMaterialUtil.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/util/bending/BendingMaterialUtil.java @@ -1,7 +1,7 @@ package com.amuzil.omegasource.magus.skill.util.bending; import com.amuzil.omegasource.magus.Magus; -import com.amuzil.omegasource.magus.skill.elements.Discipline; +import com.amuzil.omegasource.magus.skill.elements.Element; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; import net.minecraft.tags.TagKey; @@ -15,10 +15,10 @@ public class BendingMaterialUtil { public static final TagKey WATERBENDING_MATERIAL = BlockTags.create(new ResourceLocation(Magus.MOD_ID, "waterbending_material")); public static final TagKey EARTHBENDING_MATERIAL = BlockTags.create(new ResourceLocation(Magus.MOD_ID, "earthbending_material")); public static final TagKey FIREBENDING_MATERIAL = BlockTags.create(new ResourceLocation(Magus.MOD_ID, "firebending_material")); - public static List> getBendableMaterialsForElement(Discipline discipline) { + public static List> getBendableMaterialsForElement(Element element) { List> toReturn = new ArrayList<>(); - switch (discipline.name()) { + switch (element.name()) { case "air": //add nothing toReturn.add(AIRBENDING_MATERIAL); From 1fa53dde37c6807a7fff87258c4036f83a37f0ac Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Tue, 29 Oct 2024 01:29:50 -0400 Subject: [PATCH 23/31] Update AvatarCommand.java --- .../omegasource/magus/skill/test/avatar/AvatarCommand.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java index 97dfb54..e6060b7 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java @@ -55,8 +55,7 @@ private static void createActivateArtCommand() { } private static void createActivateFormCommand() { - var commandBuilder = builder.then(Commands.literal("activate")); - Registries.forms.forEach(form -> commandBuilder.then(Commands.literal("form") + Registries.forms.forEach(form -> builder.then(Commands.literal("form") .then(Commands.literal(form.name().toLowerCase()) .then(Commands.argument("target", EntityArgument.player()) .executes(c -> activateForm( From f544186c8acd0158d1ab2faa2c8ba7a068a73e28 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Tue, 29 Oct 2024 01:40:42 -0400 Subject: [PATCH 24/31] Update ElementCollision.java --- .../entity/collision/ElementCollision.java | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/entity/collision/ElementCollision.java b/src/main/java/com/amuzil/omegasource/magus/entity/collision/ElementCollision.java index 17b8bc9..2cf6078 100644 --- a/src/main/java/com/amuzil/omegasource/magus/entity/collision/ElementCollision.java +++ b/src/main/java/com/amuzil/omegasource/magus/entity/collision/ElementCollision.java @@ -224,27 +224,9 @@ public boolean isNoPhysics() { protected void onHitEntity(EntityHitResult entityHitResult) { Entity entity = entityHitResult.getEntity(); - if (entity instanceof Blaze) { - if (this.getOwner() != null) { - this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); - } - } else if (entity instanceof ElementCollision fireProjectileEntity) { - if (this.getOwner() != null && this.level.isClientSide) { - ElementCollision collisionEntity = new ElementCollision(this.getX(), this.getY(), this.getZ(), level); - collisionEntity.setTimeToKill(5); - level.addFreshEntity(collisionEntity); - EntityEffect entityEffect = new EntityEffect(orb_bloom, level, collisionEntity); - entityEffect.start(); - System.out.println("SUCCESS COLLISION!!!"); - this.discard(); - fireProjectileEntity.discard(); - } - } else { - // TODO - Check if player entity has countered - int i = 10; // Deal 10 damage - entity.hurt(this.damageSources().thrown(this, this.getOwner()), (float)i); - this.discard(); - } + int i = 5; + entity.hurt(this.damageSources().thrown(this, this.getOwner()), (float)i); + this.discard(); } protected void onHitBlock(BlockHitResult blockHitResult) { From 400dad609edd883847f0159d017efcdc7b5687b0 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Tue, 29 Oct 2024 01:41:53 -0400 Subject: [PATCH 25/31] Update ElementCollision.java --- .../omegasource/magus/entity/collision/ElementCollision.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/entity/collision/ElementCollision.java b/src/main/java/com/amuzil/omegasource/magus/entity/collision/ElementCollision.java index 2cf6078..acad32c 100644 --- a/src/main/java/com/amuzil/omegasource/magus/entity/collision/ElementCollision.java +++ b/src/main/java/com/amuzil/omegasource/magus/entity/collision/ElementCollision.java @@ -32,8 +32,6 @@ public class ElementCollision extends ElementProjectile { private static final EntityDataAccessor ID_FLAGS = SynchedEntityData.defineId(ElementCollision.class, EntityDataSerializers.BYTE); private static final EntityDataAccessor PIERCE_LEVEL = SynchedEntityData.defineId(ElementCollision.class, EntityDataSerializers.BYTE); - private boolean leftOwner; - private boolean hasBeenShot; private int life; private int ttk = 10; From 73325d14f75d9177a2046d04729323e3a0403619 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Tue, 29 Oct 2024 01:44:52 -0400 Subject: [PATCH 26/31] clean up --- .../magus/input/KeyboardMouseInputModule.java | 37 ------------------- 1 file changed, 37 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java b/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java index fc09f29..182aab8 100644 --- a/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java +++ b/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java @@ -1,6 +1,5 @@ package com.amuzil.omegasource.magus.input; -import com.amuzil.omegasource.magus.Magus; import com.amuzil.omegasource.magus.network.MagusNetwork; import com.amuzil.omegasource.magus.network.packets.client_executed.FormActivatedPacket; import com.amuzil.omegasource.magus.network.packets.server_executed.SendModifierDataPacket; @@ -14,9 +13,6 @@ import com.mojang.blaze3d.platform.InputConstants; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.entity.player.Player; import net.minecraftforge.client.event.InputEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.TickEvent; @@ -32,7 +28,6 @@ public class KeyboardMouseInputModule extends InputModule { private final Consumer tickEventConsumer; - private final Consumer tickServerEventConsumer; private final Consumer keyboardListener; private final Consumer mouseListener; private final Consumer mouseScrollListener; @@ -177,37 +172,6 @@ public KeyboardMouseInputModule() { } } }; - - this.tickServerEventConsumer = event -> { - // NOTE: This is strictly for testing and to be deleted later - if (c == 0) { - synchronized (activeForm.get()) { - if (!activeForm.get().name().equals("null")) { - ResourceLocation resource = null; - if (activeForm.get().name().equals("strike")) - resource = new ResourceLocation(Magus.MOD_ID, "fire_bloom"); - if (activeForm.get().name().equals("force")) - resource = new ResourceLocation(Magus.MOD_ID, "blue_fire"); - ServerLevel level = event.getServer().getAllLevels().iterator().next(); -// System.out.println("LEVEL: " + level); - if (!level.isClientSide && resource != null) { - c = 5; - Player player = Minecraft.getInstance().player; - assert player != null; -// TestProjectileEntity element = new TestProjectileEntity(player, level, activeForm.get()); -// element.shootFromRotation(player, player.getXRot(), player.getYRot(), 0.0F, 1.5F, 1.0F); -// element.shoot(player.getViewVector(1).x, player.getViewVector(1).y, player.getViewVector(1).z, 2, 1); -// level.addFreshEntity(element); -// FX fx = FXHelper.getFX(resource); -// EntityEffect entityEffect = new EntityEffect(fx, level, element); -// entityEffect.start(); - } - } - } - } else { - c--; - } - }; } public static void setActiveDiscipline(Element element) { @@ -353,5 +317,4 @@ public double getMouseScrollDelta() { return this.mouseScrollDelta; } - } From 4e4c93dc13c2de63b31fa82135d37f16a18f3077 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Tue, 29 Oct 2024 02:50:21 -0400 Subject: [PATCH 27/31] entity spawning system stable --- .../client_executed/FormActivatedPacket.java | 3 +-- .../resources/assets/magus/fx/orb_bloom.fx | Bin 2391 -> 2311 bytes 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java index 07714cd..eb74623 100644 --- a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java +++ b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java @@ -70,16 +70,15 @@ public static void handleServerSide(Form form, Element element, ServerPlayer pla // Perform server-side entity spawning and updating logic and fire Form Event here ServerLevel level = player.getLevel(); // TODO - Create/perform certain entity updates based on form and element + // - All Skills/techniques should be determined and handled here ElementProjectile entity = ElementProjectile.createElementEntity(form, element, player, level); entity.shoot(player.getViewVector(1).x, player.getViewVector(1).y, player.getViewVector(1).z, 1, 1); level.addFreshEntity(entity); FormActivatedPacket packet = new FormActivatedPacket(form, element, entity.getId()); - // Predicate predicate = (serverPlayer) -> player.distanceToSqr(serverPlayer) < 2500; // for (ServerPlayer nearbyPlayer: level.getPlayers(predicate.and(LivingEntity::isAlive))) { // MagusNetwork.sendToClient(packet, nearbyPlayer); // } // Keep this in case we want a more specific client packet distribution filter - MagusNetwork.CHANNEL.send(PacketDistributor.NEAR.with( () -> new PacketDistributor.TargetPoint(player.getX(), player.getY(), player.getZ(), 500, level.dimension())), packet); diff --git a/src/main/resources/assets/magus/fx/orb_bloom.fx b/src/main/resources/assets/magus/fx/orb_bloom.fx index 1b2bbb90de25423d9f37a7058c08fdca76f5c645..150ec89ec192b7b09cc396a2a1fd2fcd66ec05ca 100644 GIT binary patch literal 2311 zcmV+i3HbIOiwFP!00000|Lt2%Y#d1yuJ*V+Gi}FC*nn7xgJC6(EZMAtvI${(riYnj zpjk7pZ4J#47dLH!;6aOdj*hhM`|x%sdr{e!CDhLdPuA9>+NkWy5+M!EH*L>z)>|!N z3eZ)zaSxQ9-)7k5c3=`$fQ)%g`(&lJuQY_C&-(#R9 z<_RpQ=SHKQ{LQn>v+exR>OK`_C%;{(hwtak3z&{znA%`@i}$G|I=A)++m=uCxa-h> z)2=%DvO`_!1kN481nI6(`P?K|-g{zz9on=-1a(MO18syD4V{<9&`{>X?@AS**<7%v z?6$lm7=h6m=z{6l9+TQ#k0e)N26gE#a%@t`_zx=BxQgbuiuTBgRN?P2Y|+q`7ZX*~ zM4g%*6$b-6Pz=sowTLe|H!$DLK8Jba9Sj(N&iNfrcT? zwp9BYkpK`@1*hMZLTL3XvOBD3 zDCb(>nyA!RTMLD)%8876y#&2>ZhZgd?X8`y&DEX8^^G?hq3mp{YEp;dQEwA2G%bWR z>F5`!+X3yxMud*4yOz44hF;28Tx?BX&pMNSE2kTb5+?aB6`fcJN6LK#+=lXo@Sy}I zFc`e^9VnZF!KF*dtj@>y0A0{1BL;U?&tfB*L(x@7AOARBeR(}!V@hU6LnTzP0yPt^ zgeOC7PMpK7ffnMQn_wUbKz#T5<3Ek?>?)dT28;`iLhwmCE6=X1cVR`T+fL?Hp=Bbp zu{;LWs$pYT!KCfgaS&McJ3UTK0Jrl^4@{42`HWyoYM+mv3t^YljzqP57)w#U+-7)> zirkG0_W2IxU>i1-)1tvtw-`0$%%|Yn|LDz;+8LpC2Zu6BH+az^gbLWUiGAC*poiQ= zT#s@RZN>STrlYIG`&<4DR(y|Bp)5!1rsnc^q`Angeu6gryf)y-)fOZ70^*vz(A>-S z0&K&Apz=*Q=-1X@_>4H%H)N0m0`9(9EVHf+i|UX^pJtAR$| zBww#Qs?};8@UC8?OF3FlqL&%rfh}}Yg5C1Z;Y@W^z0t&+EURUZwYYmrg#!x~X<_Jb z2ipOW0s)w8?>=Gghra{gKd>k3O8v|tAr){X0VGdrGNEP&D;l~Go5rRJ7ekM{xJO_v zV9JKE>YR#Sz<+6r5|(Fo5L?*PC77LPq*p=n9&1v8ZG|&S4YwWGnB9p61WI|W7ANA= z!q0M~-iaz8*EDwA?3xbc0jCpx+O*vfsf}t9+oU62m(Q~TmPUgN-|bD*RL15}Xb>9% zWLA#aj5Z>m8Ui{8ypZ~KFBf0I+k(9Y#KJfPJ6%wS7)oJ;FN1@o^0auPyT-6{2*?GW zH+v9*NS_B6Y{}j#_@wz#AnwAkUdXuH@ociyAw#FpV4r^H=~I=QS^bx7qShLj6)t>)t)pUs>E}6gF8iH zLQAQKoH(SE#vv#WDh`3NcJumS_g@kOh#E z$-l~fnJDEg3(^$8!2A9$GiX=of1S&gTXPcs>*6=Y;VMiyjbK}Jq58L1r$ z8JU>%VDPi-MtXSGvG&>5*c7mivlFn6jpdO@@NBH()kl-Fj$=8hf^|G*)=@iatmDfM ze_61O)4)28kDP|g=V0U{t>Wli`$z10kh(l~jdqDu5SImUSrC^K5SJU%NL=cWfZ)6Z)&lHfeJJx0WQ4xMpSM(_;fowC=|uza(o$BNU21;JMkd}&BR&AH0LZH(!E+)v7{??7tCmPXU?8EbIv#Ce4eW#R6|wbQXvTAIznhbL&KEM zh4ty^A*!MQ54!{nT9jE1siN|NXaxjS1Iz@4Cpx_Hy#`&>QI!$TCXBEu(xX2w`Zhte z3FW=Tb(~SnP1n63Ja0`?knrGPKPG}KNfQ%tdSIIb>T+PZ5i{*x}m7Zs`|} zffUz%y*pp*_Hz;tY&_{QVZY6wF|h8V3<1KdB<*0TQn~( z6E-iOl#`(y6K)SJqf;*Rs2jRh2@_;xipu8}IeX_l9sJOt4I-#ZvKnYz#AxWabcS)| zKKz)CQKs_2-_#kdnR@p)_spP_-TPtRV4$DCQ&$EC}c zrU4crub+^^VMQZ3=R?mzrSYk$NZ6z_WIXBwj9R$((xoeN3v;uR3*#4NUL22PXM5Gs zcPN?lJmEsqB3P4wev*1k&|b{M=%|Kk?J(5PiHyf3-UR+!W-@N2xxp#H$k(W7CPFw; z;Va-alGlL`C2)cD_1B(-w!Xf8`gCg5p#&db2RSn#Elw=}x8rpmT#w8Jj9^=8pO2rz(U8feM74Yv zYomN+k>O=3ayKs6=bM;=Z#Yz%MFUee7`3G3+u*zU{)=6;(p2kM2|7TLr0WR33kgrM3!1n@AW$7WK1oCe2Z5u zt8`%4CJhWDu3{%7QXl}6VW;pKOMT*6m1{XB(}*wyda-v1&nkD8NSro zR#%yu$EiW$3{Y9QYBQRNfvN-OT!=y%IIUcKg=hco$G zEazvFjDDgOzeA2Zcjahz$#RrxD6su99EfHTEzBO;+AjGXu)S=!|f^hK;{e8hDCZIPg%X) zYd}aSe%^BnSzfi5}l-w9^y?u7xR7&{=W!tB-jz_xEWw&R;AGJ_U#|^1lTMY z*+s;wFFz?o7>{l#qTnbWGDoQ$Fpknt^m)Ni?mtJ_JJ0HHpUp9>wRS#qb%#SY5}ilS z(-mU(3C*b$G-p9`_94yL5o8-U^#6|~?aYLXU;gSP^P5+GZ@m73adv6+p82JJ zJ^TDOKHME{GxDij;5H9X1uaMQ4PQB6`K&lMSx}V)RasD#hYe^C*15?xRSDOpqAJbI zQp+pxn!(fudU#KVgsj6PUKB~F|Lp@MVc=W0c8kJ%mGJZDF0b4lT;90<`X{PTg|>U-#B#pUDd+5~ z-aRQtwkG+{XUu2*{1@})ci)t48ahgo9hJ2RbuVitUdh-c`IUnTn}Rt#l+0;XkloeJ z#R1VnLwWYD;ydW(ZvPQhFrj_NgdS0w#q%dV_gl5;{E6IA8^_B(N5&g({M2~jpI&K7HQ5E<1k^!#zXA_fa?bsO9&`XBJB Jt~mTt0035lo{0be From 735a092856fbda718f1b57a24247d0dc7c72440a Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Wed, 30 Oct 2024 17:54:37 -0400 Subject: [PATCH 28/31] fix commands --- .../magus/skill/test/avatar/AvatarCommand.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java index e6060b7..15ccb48 100644 --- a/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java +++ b/src/main/java/com/amuzil/omegasource/magus/skill/test/avatar/AvatarCommand.java @@ -30,15 +30,13 @@ public class AvatarCommand { private static LiteralArgumentBuilder builder = Commands.literal("avatar"); // Class for registering the '/avatar' command public static void register(CommandDispatcher dispatcher) { - builder.then( - Commands.literal("tree") - .executes(c -> tree()) - .then(Commands.literal("reset") + builder.then(Commands.literal("tree") + .then(Commands.literal("reset") .executes(c -> reset())) - ) + .executes(c -> tree())) .executes(c -> { // Default message when no options are provided. - InputModule.sendDebugMsg("Options: activate, tree, reset"); + InputModule.sendDebugMsg("Options: activate, form, tree"); return 1; }); From 4f1c3d1cc805f896ac6cb6e0129eb90834f6125d Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Wed, 30 Oct 2024 17:55:09 -0400 Subject: [PATCH 29/31] Update InputModule.java --- .../java/com/amuzil/omegasource/magus/input/InputModule.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/input/InputModule.java b/src/main/java/com/amuzil/omegasource/magus/input/InputModule.java index 98afccf..66e4053 100644 --- a/src/main/java/com/amuzil/omegasource/magus/input/InputModule.java +++ b/src/main/java/com/amuzil/omegasource/magus/input/InputModule.java @@ -43,10 +43,6 @@ public abstract class InputModule { // Send a message to in-game chat public static void sendDebugMsg(String msg) { Minecraft minecraft = Minecraft.getInstance(); - if (minecraft == null) { - System.err.println("sendDebugMsg failed: Minecraft instance is null"); - return; - } minecraft.execute(() -> { LocalPlayer player = minecraft.player; if (player != null) { From 31c9a6c24352229cd25d67b9491d8b4948edb5e9 Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Wed, 30 Oct 2024 18:17:54 -0400 Subject: [PATCH 30/31] fix toString --- .../condition/minecraft/forge/key/KeyHoldCondition.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/radix/condition/minecraft/forge/key/KeyHoldCondition.java b/src/main/java/com/amuzil/omegasource/magus/radix/condition/minecraft/forge/key/KeyHoldCondition.java index 04e4d97..aa6e97f 100644 --- a/src/main/java/com/amuzil/omegasource/magus/radix/condition/minecraft/forge/key/KeyHoldCondition.java +++ b/src/main/java/com/amuzil/omegasource/magus/radix/condition/minecraft/forge/key/KeyHoldCondition.java @@ -155,6 +155,11 @@ public void unregister() { @Override public String toString() { - return String.format("%s[ active=%b, key=%s, held=%d, d=%d, t=%d, r=%b ]", this.getClass().getSimpleName(), active, InputConstants.getKey(key, -1).getName().replace("key.", ""), currentHolding, duration, timeout, release); + String keyString = InputConstants.getKey(key, -1).getName().replace("key.", ""); + if (keyString.equals("keyboard.0")) + keyString = "mouse.left"; + if (keyString.equals("keyboard.1")) + keyString = "mouse.right"; + return String.format("%s[ active=%b, key=%s, held=%d, d=%d, t=%d, r=%b ]", this.getClass().getSimpleName(), active, keyString, currentHolding, duration, timeout, release); } } From 31e70cb85043c47073fc00c11020348111e0d16f Mon Sep 17 00:00:00 2001 From: Jake Morfe Date: Thu, 31 Oct 2024 23:18:16 -0400 Subject: [PATCH 31/31] implemented arc form & collisions stable --- .../magus/entity/ElementProjectile.java | 65 +++++-- .../entity/projectile/AirProjectile.java | 15 +- .../entity/projectile/EarthProjectile.java | 15 +- .../entity/projectile/FireProjectile.java | 174 +++++++++++------- .../entity/projectile/WaterProjectile.java | 15 +- .../magus/input/KeyboardMouseInputModule.java | 4 +- .../client_executed/FormActivatedPacket.java | 20 +- 7 files changed, 198 insertions(+), 110 deletions(-) diff --git a/src/main/java/com/amuzil/omegasource/magus/entity/ElementProjectile.java b/src/main/java/com/amuzil/omegasource/magus/entity/ElementProjectile.java index a57a3e8..1680f60 100644 --- a/src/main/java/com/amuzil/omegasource/magus/entity/ElementProjectile.java +++ b/src/main/java/com/amuzil/omegasource/magus/entity/ElementProjectile.java @@ -1,5 +1,6 @@ package com.amuzil.omegasource.magus.entity; +import com.amuzil.omegasource.magus.entity.collision.ElementCollision; import com.amuzil.omegasource.magus.entity.projectile.AirProjectile; import com.amuzil.omegasource.magus.entity.projectile.EarthProjectile; import com.amuzil.omegasource.magus.entity.projectile.FireProjectile; @@ -8,8 +9,7 @@ import com.amuzil.omegasource.magus.skill.forms.Form; import com.lowdragmc.photon.client.fx.EntityEffect; import com.lowdragmc.photon.client.fx.FX; -import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; @@ -29,6 +29,7 @@ import net.minecraft.world.phys.*; import javax.annotation.Nullable; +import java.util.List; import java.util.Optional; import java.util.function.Predicate; @@ -43,20 +44,23 @@ public abstract class ElementProjectile extends Projectile implements ItemSuppli private boolean hasBeenShot; private int life; private int ttk = 100; + public boolean arcActive = false; + public Form form; public ElementProjectile(EntityType type, Level level) { super(type, level); } - public ElementProjectile(EntityType entityType, double x, double y, double z, Level level) { + public ElementProjectile(EntityType entityType, double x, double y, double z, Level level, Form form) { this(entityType, level); this.setPos(x, y, z); + this.setNoGravity(true); + this.form = form; } - public ElementProjectile(EntityType entityType, LivingEntity livingEntity, Level level) { - this(entityType, livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level); + public ElementProjectile(EntityType entityType, LivingEntity livingEntity, Level level, Form form) { + this(entityType, livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level, form); this.setOwner(livingEntity); - this.setNoGravity(true); } public void tick() { @@ -105,12 +109,13 @@ public boolean canHitEntity(Entity otherEntity) { return false; } else { Entity entity = this.getOwner(); -// if (entity != null) { -// if (otherEntity instanceof TestProjectileEntity other) { -// System.out.println("THIS OWNER: " + entity + " | " + !entity.isPassengerOfSameVehicle(otherEntity)); -// System.out.println("THAT OWNER: " + other.getOwner()); -// } -// } + if (entity != null) { + if (otherEntity instanceof ElementProjectile other) { +// System.out.println("arcActive: " + other.arcActive); + if (other.arcActive) + return true; + } + } return entity == null || this.leftOwner || !entity.isPassengerOfSameVehicle(otherEntity); } } @@ -124,6 +129,7 @@ protected void tickDespawn() { if (this.life >= ttk) { // System.out.println("BYE BYE BBY"); this.discard(); +// this.arcActive = false; } } @@ -138,7 +144,7 @@ protected void defineSynchedData() { this.entityData.define(PIERCE_LEVEL, (byte)0); } - private boolean checkLeftOwner() { + public boolean checkLeftOwner() { Entity owner = this.getOwner(); if (owner != null) { for(Entity entity1 : this.level.getEntities(this, this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(1.0D), (entity) -> { @@ -177,7 +183,7 @@ protected void onHitEntity(EntityHitResult entityHitResult) { } } else if (entity instanceof ElementProjectile testProjectileEntity) { if (this.getOwner() != null && this.level.isClientSide) { - ElementProjectile collisionEntity = new FireProjectile(this.getX(), this.getY(), this.getZ(), level); + ElementProjectile collisionEntity = new ElementCollision(this.getX(), this.getY(), this.getZ(), level); collisionEntity.setTimeToKill(5); level.addFreshEntity(collisionEntity); EntityEffect entityEffect = new EntityEffect(orb_bloom, level, collisionEntity); @@ -207,6 +213,16 @@ protected void onHit(HitResult hitResult) { } } + public void arc(float scale, float offset) { + this.arcActive = true; + Entity owner = this.getOwner(); + assert owner != null; + Vec3[] pose = new Vec3[]{owner.position(), this.getOwner().getLookAngle()}; + pose[1] = pose[1].scale((scale)).add((0), (this.getOwner().getEyeHeight()), (0)); + Vec3 newPos = pose[1].add(pose[0]); + this.setPos(newPos.x, newPos.y, newPos.z); + } + @Override public ItemStack getItem() { return PROJECTILE_ITEM; @@ -214,22 +230,35 @@ public ItemStack getItem() { public static ElementProjectile createElementEntity(Form form, Element element, ServerPlayer player, ServerLevel level) { return switch (element.type()) { - case AIR -> new AirProjectile(player, level); - case WATER -> new WaterProjectile(player, level); - case EARTH -> new EarthProjectile(player, level); - case FIRE -> new FireProjectile(player, level); + case AIR -> new AirProjectile(player, level, form); + case WATER -> new WaterProjectile(player, level, form); + case EARTH -> new EarthProjectile(player, level, form); + case FIRE -> new FireProjectile(player, level, form); }; } public void startEffect(Form form, Player player) { + this.form = form; // NOTE: Need this to ensure form is set client-side before onHit event FX fx = null; if (form.name().equals("strike")) fx = fire_bloom; if (form.name().equals("force")) fx = blue_fire; + if (form.name().equals("arc")) { + // TODO - Make perma fire and allow it to be shootable. Also stop catching fire from damaging receiver + // Also allow user to curve shot projectiles. + fx = fire_bloom; + arcActive = true; + } if (fx != null) { EntityEffect entityEffect = new EntityEffect(fx, level, this); entityEffect.start(); } } + + public static List getNearbyEntities(Entity entity, double blocksRadius) { + AABB aabb = entity.getBoundingBox().expandTowards(entity.getDeltaMovement()).inflate(blocksRadius); + assert Minecraft.getInstance().level != null; + return Minecraft.getInstance().level.getEntities(entity, aabb).stream().toList(); + } } \ No newline at end of file diff --git a/src/main/java/com/amuzil/omegasource/magus/entity/projectile/AirProjectile.java b/src/main/java/com/amuzil/omegasource/magus/entity/projectile/AirProjectile.java index 2b11f49..eb0d9c1 100644 --- a/src/main/java/com/amuzil/omegasource/magus/entity/projectile/AirProjectile.java +++ b/src/main/java/com/amuzil/omegasource/magus/entity/projectile/AirProjectile.java @@ -2,6 +2,8 @@ import com.amuzil.omegasource.magus.entity.AvatarEntities; import com.amuzil.omegasource.magus.entity.ElementProjectile; +import com.amuzil.omegasource.magus.entity.collision.ElementCollision; +import com.amuzil.omegasource.magus.skill.forms.Form; import com.lowdragmc.photon.client.fx.EntityEffect; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleOptions; @@ -39,13 +41,14 @@ public AirProjectile(EntityType type, Level level) { super(type, level); } - public AirProjectile(double x, double y, double z, Level level) { + public AirProjectile(double x, double y, double z, Level level, Form form) { this(AvatarEntities.AIR_PROJECTILE_ENTITY_TYPE.get(), level); this.setPos(x, y, z); +// this.form = form; } - public AirProjectile(LivingEntity livingEntity, Level level) { - this(livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level); + public AirProjectile(LivingEntity livingEntity, Level level, Form form) { + this(livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level, form); this.setOwner(livingEntity); this.setNoGravity(true); } @@ -226,16 +229,16 @@ protected void onHitEntity(EntityHitResult entityHitResult) { if (this.getOwner() != null) { this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); } - } else if (entity instanceof AirProjectile fireProjectileEntity) { + } else if (entity instanceof ElementProjectile elementProjectile) { if (this.getOwner() != null && this.level.isClientSide) { - AirProjectile collisionEntity = new AirProjectile(this.getX(), this.getY(), this.getZ(), level); + ElementCollision collisionEntity = new ElementCollision(this.getX(), this.getY(), this.getZ(), level); collisionEntity.setTimeToKill(5); level.addFreshEntity(collisionEntity); EntityEffect entityEffect = new EntityEffect(orb_bloom, level, collisionEntity); entityEffect.start(); System.out.println("SUCCESS COLLISION!!!"); this.discard(); - fireProjectileEntity.discard(); + elementProjectile.discard(); } } else { // TODO - Check if player entity has countered diff --git a/src/main/java/com/amuzil/omegasource/magus/entity/projectile/EarthProjectile.java b/src/main/java/com/amuzil/omegasource/magus/entity/projectile/EarthProjectile.java index b633400..569a841 100644 --- a/src/main/java/com/amuzil/omegasource/magus/entity/projectile/EarthProjectile.java +++ b/src/main/java/com/amuzil/omegasource/magus/entity/projectile/EarthProjectile.java @@ -2,6 +2,8 @@ import com.amuzil.omegasource.magus.entity.AvatarEntities; import com.amuzil.omegasource.magus.entity.ElementProjectile; +import com.amuzil.omegasource.magus.entity.collision.ElementCollision; +import com.amuzil.omegasource.magus.skill.forms.Form; import com.lowdragmc.photon.client.fx.EntityEffect; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleOptions; @@ -39,13 +41,14 @@ public EarthProjectile(EntityType type, Level level) { super(type, level); } - public EarthProjectile(double x, double y, double z, Level level) { + public EarthProjectile(double x, double y, double z, Level level, Form form) { this(AvatarEntities.EARTH_PROJECTILE_ENTITY_TYPE.get(), level); this.setPos(x, y, z); +// this.form = form; } - public EarthProjectile(LivingEntity livingEntity, Level level) { - this(livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level); + public EarthProjectile(LivingEntity livingEntity, Level level, Form form) { + this(livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level, form); this.setOwner(livingEntity); this.setNoGravity(true); } @@ -226,16 +229,16 @@ protected void onHitEntity(EntityHitResult entityHitResult) { if (this.getOwner() != null) { this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); } - } else if (entity instanceof EarthProjectile fireProjectileEntity) { + } else if (entity instanceof ElementProjectile elementProjectile) { if (this.getOwner() != null && this.level.isClientSide) { - EarthProjectile collisionEntity = new EarthProjectile(this.getX(), this.getY(), this.getZ(), level); + ElementCollision collisionEntity = new ElementCollision(this.getX(), this.getY(), this.getZ(), level); collisionEntity.setTimeToKill(5); level.addFreshEntity(collisionEntity); EntityEffect entityEffect = new EntityEffect(orb_bloom, level, collisionEntity); entityEffect.start(); System.out.println("SUCCESS COLLISION!!!"); this.discard(); - fireProjectileEntity.discard(); + elementProjectile.discard(); } } else { // TODO - Check if player entity has countered diff --git a/src/main/java/com/amuzil/omegasource/magus/entity/projectile/FireProjectile.java b/src/main/java/com/amuzil/omegasource/magus/entity/projectile/FireProjectile.java index 5334152..bc95fa5 100644 --- a/src/main/java/com/amuzil/omegasource/magus/entity/projectile/FireProjectile.java +++ b/src/main/java/com/amuzil/omegasource/magus/entity/projectile/FireProjectile.java @@ -3,10 +3,9 @@ import com.amuzil.omegasource.magus.entity.AvatarEntities; import com.amuzil.omegasource.magus.entity.ElementProjectile; import com.amuzil.omegasource.magus.entity.collision.ElementCollision; +import com.amuzil.omegasource.magus.skill.forms.Form; import com.lowdragmc.photon.client.fx.EntityEffect; import net.minecraft.core.BlockPos; -import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.core.particles.ParticleTypes; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; @@ -16,6 +15,7 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.monster.Blaze; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.Fireball; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; @@ -40,13 +40,14 @@ public FireProjectile(EntityType type, Level level) { super(type, level); } - public FireProjectile(double x, double y, double z, Level level) { + public FireProjectile(double x, double y, double z, Level level, Form form) { this(AvatarEntities.FIRE_PROJECTILE_ENTITY_TYPE.get(), level); this.setPos(x, y, z); + this.form = form; } - public FireProjectile(LivingEntity livingEntity, Level level) { - this(livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level); + public FireProjectile(LivingEntity livingEntity, Level level, Form form) { + this(livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level, form); this.setOwner(livingEntity); this.setNoGravity(true); } @@ -123,77 +124,94 @@ public void tick() { hitresult = null; } deltaMovement = this.getDeltaMovement(); - double d5 = deltaMovement.x; - double d6 = deltaMovement.y; - double d1 = deltaMovement.z; + double x = deltaMovement.x; + double y = deltaMovement.y; + double z = deltaMovement.z; - double d7 = this.getX() + d5; - double d2 = this.getY() + d6; - double d3 = this.getZ() + d1; + double finalX = this.getX() + x; + double finalY = this.getY() + y; + double finalZ = this.getZ() + z; double d4 = deltaMovement.horizontalDistance(); if (flag) { - this.setYRot((float)(Mth.atan2(-d5, -d1) * (double)(180F / (float)Math.PI))); + this.setYRot((float)(Mth.atan2(-x, -z) * (double)(180F / (float)Math.PI))); } else { - this.setYRot((float)(Mth.atan2(d5, d1) * (double)(180F / (float)Math.PI))); + this.setYRot((float)(Mth.atan2(x, z) * (double)(180F / (float)Math.PI))); } - this.setXRot((float)(Mth.atan2(d6, d4) * (double)(180F / (float)Math.PI))); + this.setXRot((float)(Mth.atan2(y, d4) * (double)(180F / (float)Math.PI))); this.setXRot(lerpRotation(this.xRotO, this.getXRot())); this.setYRot(lerpRotation(this.yRotO, this.getYRot())); - float f = 0.99F; - this.setDeltaMovement(deltaMovement.scale((double)f)); - if (!this.isNoGravity() && !flag) { + float f = 0.49F; // Scale speed + this.setDeltaMovement(deltaMovement.scale(f)); + if (!this.isNoGravity() && !flag) { // Apply gravity Vec3 vec34 = this.getDeltaMovement(); this.setDeltaMovement(vec34.x, vec34.y - (double)0.05F, vec34.z); } - this.setPos(d7, d2, d3); - this.checkInsideBlocks(); - } - - @Nullable - protected EntityHitResult findHitEntity(Vec3 pos, Vec3 delta) { - return getEntityHitResult(this.level, this, pos, delta, - this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(2.0D), - this::canHitEntity, 0.3F); - } - - @Nullable - public static EntityHitResult getEntityHitResult(Level level, Entity thisEntity, Vec3 pos, Vec3 delta, AABB thisAABB, Predicate canBeHit, float scale) { - double maxDist = Double.MAX_VALUE; - Entity entity = null; - - for(Entity otherEntity : level.getEntities(thisEntity, thisAABB, canBeHit)) { -// System.out.println("ENTITY NEARBY: " + otherEntity); - AABB aabb = otherEntity.getBoundingBox().inflate(scale); - Optional optional = aabb.clip(pos, delta); - if (optional.isPresent()) { - double dist = pos.distanceToSqr(optional.get()); - if (dist < maxDist) { - entity = otherEntity; - maxDist = dist; - } + Entity owner = this.getOwner(); + if (arcActive) { + if (owner != null) { + Vec3[] pose = new Vec3[]{owner.position(), this.getOwner().getLookAngle()}; + pose[1] = pose[1].scale((1.5)).add((0), (this.getOwner().getEyeHeight()), (0)); + Vec3 newPos = pose[1].add(pose[0]); +// System.out.println("pos: " + newPos); + this.setPos(newPos.x, newPos.y, newPos.z); } + } else { + if (owner != null) { + Vec3 vec34 = this.getDeltaMovement(); + Vec3 aim = this.getOwner().getLookAngle().multiply(.3, .3, .3); + this.setDeltaMovement(vec34.add(aim)); + } + this.setPos(finalX, finalY, finalZ); } - return entity == null ? null : new EntityHitResult(entity); + this.checkInsideBlocks(); } - public boolean canHitEntity(Entity otherEntity) { - if (!otherEntity.canBeHitByProjectile()) { - return false; - } else { - Entity entity = this.getOwner(); -// if (entity != null) { -// if (otherEntity instanceof TestProjectileEntity other) { -// System.out.println("THIS OWNER: " + entity + " | " + !entity.isPassengerOfSameVehicle(otherEntity)); -// System.out.println("THAT OWNER: " + other.getOwner()); +// @Nullable +// protected EntityHitResult findHitEntity(Vec3 pos, Vec3 delta) { +// return getEntityHitResult(this.level, this, pos, delta, +// this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(2.0D), +// this::canHitEntity, 0.3F); +// } + +// @Nullable +// public static EntityHitResult getEntityHitResult(Level level, Entity thisEntity, Vec3 pos, Vec3 delta, AABB thisAABB, Predicate canBeHit, float scale) { +// double maxDist = Double.MAX_VALUE; +// Entity entity = null; +// +// for(Entity otherEntity : level.getEntities(thisEntity, thisAABB, canBeHit)) { +//// System.out.println("ENTITY NEARBY: " + otherEntity); +// AABB aabb = otherEntity.getBoundingBox().inflate(scale); +// Optional optional = aabb.clip(pos, delta); +// if (optional.isPresent()) { +// double dist = pos.distanceToSqr(optional.get()); +// if (dist < maxDist) { +// entity = otherEntity; +// maxDist = dist; // } // } - return entity == null || this.leftOwner || !entity.isPassengerOfSameVehicle(otherEntity); - } - } +// } +// +// return entity == null ? null : new EntityHitResult(entity); +// } + +// public boolean canHitEntity(Entity otherEntity) { +// if (!otherEntity.canBeHitByProjectile()) { +// return false; +// } else { +// Entity entity = this.getOwner(); +//// if (entity != null) { +//// if (otherEntity instanceof TestProjectileEntity other) { +//// System.out.println("THIS OWNER: " + entity + " | " + !entity.isPassengerOfSameVehicle(otherEntity)); +//// System.out.println("THAT OWNER: " + other.getOwner()); +//// } +//// } +// return entity == null || this.leftOwner || !entity.isPassengerOfSameVehicle(otherEntity); +// } +// } public void setTimeToKill(int ticks) { this.ttk = ticks; @@ -239,24 +257,42 @@ protected void onHitEntity(EntityHitResult entityHitResult) { Entity entity = entityHitResult.getEntity(); if (entity instanceof Blaze) { if (this.getOwner() != null) { - this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); +// this.setNoGravity(false); + this.setOwner(entity); + this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y, entity.getViewVector(1).z, 0.75F, 1); + this.leftOwner = true; } - } else if (entity instanceof ElementProjectile elementProjectile) { + } else if (entity instanceof FireProjectile elementProjectile) { if (this.getOwner() != null && this.level.isClientSide) { - ElementCollision collisionEntity = new ElementCollision(this.getX(), this.getY(), this.getZ(), level); - collisionEntity.setTimeToKill(5); - level.addFreshEntity(collisionEntity); - EntityEffect entityEffect = new EntityEffect(orb_bloom, level, collisionEntity); - entityEffect.start(); - System.out.println("SUCCESS COLLISION!!!"); - this.discard(); - elementProjectile.discard(); +// System.out.println("this form: " + this.form + " | checkLeftOwner: " + this.checkLeftOwner()); +// System.out.println("other form: " + elementProjectile.form + " | arcActive: " + elementProjectile.arcActive); + if (elementProjectile.arcActive && this.checkLeftOwner()) { + this.setOwner(elementProjectile.getOwner()); // Give control to receiver + this.setDeltaMovement(0,0,0); // Full stop + this.arcActive = true; // Enable control + this.setTimeToKill(500); + System.out.println("SUCCESS ARC!!!"); + } else { + if (!this.getOwner().equals(elementProjectile.getOwner())) { + ElementCollision collisionEntity = new ElementCollision(this.getX(), this.getY(), this.getZ(), level); + collisionEntity.setTimeToKill(5); + level.addFreshEntity(collisionEntity); + EntityEffect entityEffect = new EntityEffect(orb_bloom, level, collisionEntity); + entityEffect.start(); + this.discard(); + elementProjectile.discard(); +// System.out.println("SUCCESS COLLISION!!!"); + } + } + } + } else if (entity instanceof Fireball fireBall) { + if (!this.getOwner().equals(fireBall.getOwner())) { + fireBall.discard(); } - } else { - // TODO - Check if player entity has countered + } else { int i = 10; // Deal 10 damage entity.hurt(this.damageSources().thrown(this, this.getOwner()), (float)i); - this.discard(); +// this.discard(); } } diff --git a/src/main/java/com/amuzil/omegasource/magus/entity/projectile/WaterProjectile.java b/src/main/java/com/amuzil/omegasource/magus/entity/projectile/WaterProjectile.java index fca79fd..4e5649c 100644 --- a/src/main/java/com/amuzil/omegasource/magus/entity/projectile/WaterProjectile.java +++ b/src/main/java/com/amuzil/omegasource/magus/entity/projectile/WaterProjectile.java @@ -2,6 +2,8 @@ import com.amuzil.omegasource.magus.entity.AvatarEntities; import com.amuzil.omegasource.magus.entity.ElementProjectile; +import com.amuzil.omegasource.magus.entity.collision.ElementCollision; +import com.amuzil.omegasource.magus.skill.forms.Form; import com.lowdragmc.photon.client.fx.EntityEffect; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleOptions; @@ -39,13 +41,14 @@ public WaterProjectile(EntityType type, Level level) { super(type, level); } - public WaterProjectile(double x, double y, double z, Level level) { + public WaterProjectile(double x, double y, double z, Level level, Form form) { this(AvatarEntities.WATER_PROJECTILE_ENTITY_TYPE.get(), level); this.setPos(x, y, z); +// this.form = form; } - public WaterProjectile(LivingEntity livingEntity, Level level) { - this(livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level); + public WaterProjectile(LivingEntity livingEntity, Level level, Form form) { + this(livingEntity.getX(), livingEntity.getEyeY(), livingEntity.getZ(), level, form); this.setOwner(livingEntity); this.setNoGravity(true); } @@ -226,16 +229,16 @@ protected void onHitEntity(EntityHitResult entityHitResult) { if (this.getOwner() != null) { this.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y+0.5, entity.getViewVector(1).z, 0.75F, 1); } - } else if (entity instanceof WaterProjectile fireProjectileEntity) { + } else if (entity instanceof ElementProjectile elementProjectile) { if (this.getOwner() != null && this.level.isClientSide) { - WaterProjectile collisionEntity = new WaterProjectile(this.getX(), this.getY(), this.getZ(), level); + ElementCollision collisionEntity = new ElementCollision(this.getX(), this.getY(), this.getZ(), level); collisionEntity.setTimeToKill(5); level.addFreshEntity(collisionEntity); EntityEffect entityEffect = new EntityEffect(orb_bloom, level, collisionEntity); entityEffect.start(); System.out.println("SUCCESS COLLISION!!!"); this.discard(); - fireProjectileEntity.discard(); + elementProjectile.discard(); } } else { // TODO - Check if player entity has countered diff --git a/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java b/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java index 182aab8..8fe12f8 100644 --- a/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java +++ b/src/main/java/com/amuzil/omegasource/magus/input/KeyboardMouseInputModule.java @@ -44,7 +44,6 @@ public class KeyboardMouseInputModule extends InputModule { private boolean listen; // Used for modifier data private boolean checkForm = false; - private int c = 0; // module activating a form rather than relying on the raw input data for those forms. // This way, the trees for different complex methods (such as VR and multikey) @@ -151,8 +150,9 @@ public KeyboardMouseInputModule() { // Extra check for race conditions. Probably wont' help... synchronized (lastActivatedForm.get()) { if (!lastActivatedForm.get().name().equals("null")) { - if (Minecraft.getInstance().getConnection() != null) + if (Minecraft.getInstance().getConnection() != null) { MagusNetwork.sendToServer(new FormActivatedPacket(activeForm.get(), activeElement, 0)); + } // sendDebugMsg("Form Activated: " + lastActivatedForm.get().name()); } } diff --git a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java index eb74623..22c312e 100644 --- a/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java +++ b/src/main/java/com/amuzil/omegasource/magus/network/packets/client_executed/FormActivatedPacket.java @@ -6,12 +6,15 @@ import com.amuzil.omegasource.magus.registry.Registries; import com.amuzil.omegasource.magus.skill.elements.Element; import com.amuzil.omegasource.magus.skill.forms.Form; +import com.amuzil.omegasource.magus.skill.forms.Forms; import net.minecraft.client.Minecraft; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.DistExecutor; @@ -60,9 +63,14 @@ private static void handleClientSide(Form form, int entityId) { Player player = Minecraft.getInstance().player; assert player != null; ElementProjectile elementProjectile = (ElementProjectile) player.level.getEntity(entityId); + /** + NOTE: Need to ensure ElementProjectile's extra constructor args are set client-side. + @see ElementProjectile#ElementProjectile(EntityType, Level) This gets called first and server-side only. + Can't change this default constructor because it's needed to register entities. Add/use any extra args to Packet. + */ assert elementProjectile != null; elementProjectile.startEffect(form, player); - System.out.println("HANDLE CLIENT PACKET ---> " + form); +// System.out.println("HANDLE CLIENT PACKET ---> " + form); } // Server-side handler @@ -72,17 +80,23 @@ public static void handleServerSide(Form form, Element element, ServerPlayer pla // TODO - Create/perform certain entity updates based on form and element // - All Skills/techniques should be determined and handled here ElementProjectile entity = ElementProjectile.createElementEntity(form, element, player, level); - entity.shoot(player.getViewVector(1).x, player.getViewVector(1).y, player.getViewVector(1).z, 1, 1); + if (form == Forms.ARC) { + entity.arc(1.5f, 1); + } else { + entity.shoot(player.getViewVector(1).x, player.getViewVector(1).y, player.getViewVector(1).z, 1, 1); + } level.addFreshEntity(entity); FormActivatedPacket packet = new FormActivatedPacket(form, element, entity.getId()); // Predicate predicate = (serverPlayer) -> player.distanceToSqr(serverPlayer) < 2500; // for (ServerPlayer nearbyPlayer: level.getPlayers(predicate.and(LivingEntity::isAlive))) { // MagusNetwork.sendToClient(packet, nearbyPlayer); // } // Keep this in case we want a more specific client packet distribution filter + + // Distribute packet to clients within 500 blocks MagusNetwork.CHANNEL.send(PacketDistributor.NEAR.with( () -> new PacketDistributor.TargetPoint(player.getX(), player.getY(), player.getZ(), 500, level.dimension())), packet); - System.out.println("HANDLE SERVER PACKET ---> " + form); +// System.out.println("HANDLE SERVER PACKET ---> " + form); } public boolean handle(Supplier ctx) {