start to update flight effect
This commit is contained in:
parent
70a68282aa
commit
39ca2dc948
1 changed files with 90 additions and 0 deletions
90
src/main/java/com/zontreck/effects/FlightEffect.java
Normal file
90
src/main/java/com/zontreck/effects/FlightEffect.java
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
package com.zontreck.effects;
|
||||||
|
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2DoubleFunction;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.effect.MobEffect;
|
||||||
|
import net.minecraft.world.effect.MobEffectCategory;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.Attribute;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.AttributeMap;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation;
|
||||||
|
import net.minecraft.world.entity.player.Abilities;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
||||||
|
public class FlightEffect extends MobEffect {
|
||||||
|
int lastDuration = -1;
|
||||||
|
ServerPlayer myPlayer;
|
||||||
|
protected FlightEffect(MobEffectCategory pCategory, int pColor) {
|
||||||
|
super(pCategory, pColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldApplyEffectTickThisTick(int pDuration, int pAmplifier) {
|
||||||
|
lastDuration=pDuration;
|
||||||
|
|
||||||
|
if(myPlayer!=null) {
|
||||||
|
Abilities myAbilities = myPlayer.getAbilities();
|
||||||
|
if(myAbilities.mayfly == false) {
|
||||||
|
myAbilities.mayfly = true;
|
||||||
|
myPlayer.onUpdateAbilities();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//OTEMod.LOGGER.info("Effect duration: " + lastDuration);
|
||||||
|
return pDuration > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBeneficial() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addAttributeModifiers(AttributeMap attributeMap, int amplifier) {
|
||||||
|
super.addAttributeModifiers(attributeMap, amplifier);
|
||||||
|
|
||||||
|
if(entity instanceof ServerPlayer player)
|
||||||
|
{
|
||||||
|
if(player.getAbilities().mayfly==false)
|
||||||
|
{
|
||||||
|
myPlayer=player;
|
||||||
|
player.getAbilities().mayfly=true;
|
||||||
|
player.onUpdateAbilities();
|
||||||
|
|
||||||
|
ChatHelpers.broadcastTo(player, ChatHelpers.macro(Messages.FLIGHT_GIVEN), player.server);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void removeFlightModifier(LivingEntity entity)
|
||||||
|
{
|
||||||
|
if(lastDuration == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( entity instanceof Player player )
|
||||||
|
{
|
||||||
|
if(ServerUtilities.isServer() && lastDuration < (5*20))
|
||||||
|
{
|
||||||
|
ServerPlayer serverPlayer = (ServerPlayer) player;
|
||||||
|
serverPlayer.getAbilities().mayfly = false;
|
||||||
|
serverPlayer.getAbilities().flying = false;
|
||||||
|
|
||||||
|
serverPlayer.onUpdateAbilities();
|
||||||
|
|
||||||
|
ChatHelpers.broadcastTo(serverPlayer, ChatHelpers.macro(Messages.FLIGHT_REMOVED), serverPlayer.server);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeAttributeModifiers(LivingEntity entity, AttributeMap p_19470_, int p_19471_) {
|
||||||
|
super.removeAttributeModifiers(entity, p_19470_, p_19471_);
|
||||||
|
removeFlightModifier(entity);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue