Advertisement
CerbonXD

Untitled

Nov 30th, 2023
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.96 KB | Source Code | 0 0
  1. package com.cerbon.bosses_of_mass_destruction.entity.custom.gauntlet;
  2.  
  3. import com.cerbon.bosses_of_mass_destruction.api.maelstrom.general.event.Event;
  4. import com.cerbon.bosses_of_mass_destruction.api.maelstrom.general.event.EventScheduler;
  5. import com.cerbon.bosses_of_mass_destruction.api.maelstrom.general.event.TimedEvent;
  6. import com.cerbon.bosses_of_mass_destruction.api.maelstrom.static_utilities.MobUtils;
  7. import com.cerbon.bosses_of_mass_destruction.api.maelstrom.static_utilities.RandomUtils;
  8. import com.cerbon.bosses_of_mass_destruction.api.maelstrom.static_utilities.VecUtils;
  9. import com.cerbon.bosses_of_mass_destruction.entity.util.IDataAccessorHandler;
  10. import com.cerbon.bosses_of_mass_destruction.particle.BMDParticles;
  11. import com.cerbon.bosses_of_mass_destruction.particle.ClientParticleBuilder;
  12. import com.cerbon.bosses_of_mass_destruction.util.BMDColors;
  13. import net.minecraft.network.syncher.EntityDataAccessor;
  14. import net.minecraft.world.phys.Vec3;
  15.  
  16. public class GauntletClientEnergyShieldHandler implements IDataAccessorHandler {
  17.     private final GauntletEntity entity;
  18.     private final EventScheduler eventScheduler;
  19.  
  20.     private float energizedRenderAlpha = 0.0f;
  21.     private final ClientParticleBuilder energizedParticles = new ClientParticleBuilder(BMDParticles.SPARKLES.get())
  22.             .brightness(BMDParticles.FULL_BRIGHT)
  23.             .color(BMDColors.LASER_RED)
  24.             .colorVariation(0.2)
  25.             .scale(0.25f);
  26.  
  27.     public GauntletClientEnergyShieldHandler(GauntletEntity entity, EventScheduler eventScheduler) {
  28.         this.entity = entity;
  29.         this.eventScheduler = eventScheduler;
  30.     }
  31.  
  32.     public float getRenderAlpha(){
  33.         return energizedRenderAlpha;
  34.     }
  35.  
  36.     @Override
  37.     public void onSyncedDataUpdated(EntityDataAccessor<?> data) {
  38.         if (GauntletEntity.isEnergized == data && entity.getEntityData().get(GauntletEntity.isEnergized) && entity.level.isClientSide()){
  39.             eventScheduler.addEvent(new TimedEvent(() -> energizedRenderAlpha += 0.1f, 0, 10, () -> false));
  40.             eventScheduler.addEvent(
  41.                     new Event(
  42.                             () -> true,
  43.                             this::spawnParticles,
  44.                             () -> !entity.isAlive() || !entity.getEntityData().get(GauntletEntity.isEnergized)
  45.                     )
  46.             );
  47.         } else
  48.             energizedRenderAlpha = 0.0f;
  49.     }
  50.  
  51.     private void spawnParticles(){
  52.         Vec3 look = entity.getLookAngle();
  53.         Vec3 cross = look.cross(VecUtils.yAxis);
  54.         Vec3 rotatedOffset = VecUtils.rotateVector(cross, look, RandomUtils.range(0, 359));
  55.         Vec3 particlePos = MobUtils.eyePos(entity).add(rotatedOffset);
  56.         Vec3 particleVel = VecUtils.rotateVector(rotatedOffset, look, 90).scale(0.1);
  57.         energizedParticles.build(particlePos, particleVel);
  58.     }
  59.  
  60.     public void initDataTracker(){
  61.         entity.getEntityData().define(GauntletEntity.isEnergized, false);
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement