Skip to content

Commit

Permalink
feat: health boost effect
Browse files Browse the repository at this point in the history
  • Loading branch information
IWareQ committed Jun 28, 2024
1 parent 7d35532 commit 49dc567
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Allay-API/src/main/java/org/allaymc/api/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.allaymc.api.datastruct.aabbtree.HasAABB;
import org.allaymc.api.datastruct.aabbtree.HasLongId;
import org.allaymc.api.entity.component.common.EntityAttributeComponent;
import org.allaymc.api.entity.component.common.EntityBaseComponent;
import org.joml.primitives.AABBf;

Expand All @@ -11,7 +12,7 @@
* @author daoge_cmd
*/
public interface Entity extends
EntityBaseComponent,
EntityBaseComponent, EntityAttributeComponent,
HasAABB, HasLongId {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ default boolean onInteract(EntityPlayer player, ItemStack itemStack) {
return false;
}

void setAbsorption(float absorption);

float getAbsorption();

void setAbsorption(float absorption);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ default boolean isBad() {
return false;
}

default void onTick(Entity entity, EffectInstance effectInstance) {}

default void onAdd(Entity entity, EffectInstance effectInstance) {}

default void onRemove(Entity entity, EffectInstance effectInstance) {}

default void onTick(Entity entity, EffectInstance effectInstance) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ private EffectAbsorptionType() {

@Override
public void onAdd(Entity entity, EffectInstance effectInstance) {
var amplifier = effectInstance.getAmplifier();
int newValue = (amplifier + 1) << 2;
var amplifier = effectInstance.getAmplifier() + 1;
var newValue = amplifier * 4;
if (newValue > entity.getAbsorption()) {
entity.setAbsorption(newValue);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.allaymc.api.entity.effect.type;

import org.allaymc.api.entity.Entity;
import org.allaymc.api.entity.effect.AbstractEffectType;
import org.allaymc.api.entity.effect.EffectInstance;
import org.allaymc.api.utils.Identifier;

import java.awt.*;
Expand All @@ -16,4 +18,19 @@ public class EffectHealthBoostType extends AbstractEffectType {
private EffectHealthBoostType() {
super(21, new Identifier("minecraft:health_boost"), new Color(248, 125, 35));
}

@Override
public void onAdd(Entity entity, EffectInstance effectInstance) {
var amplifier = effectInstance.getAmplifier() + 1;
entity.setMaxHealth(entity.getMaxHealth() + (amplifier * 4));
}

@Override
public void onRemove(Entity entity, EffectInstance effectInstance) {
var amplifier = effectInstance.getAmplifier() + 1;
entity.setMaxHealth(entity.getMaxHealth() - (amplifier * 4));
if (entity.getHealth() > entity.getMaxHealth()) {
entity.setHealth(entity.getMaxHealth());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.allaymc.api.entity.effect.AbstractEffectType;
import org.allaymc.api.entity.effect.EffectInstance;
import org.allaymc.api.utils.Identifier;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;

import java.awt.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package org.allaymc.api.entity.interfaces;

import org.allaymc.api.entity.Entity;
import org.allaymc.api.entity.component.common.EntityAttributeComponent;
import org.allaymc.api.entity.component.common.EntityDamageComponent;

/**
* @author daoge_cmd <br>
* Allay Project <br>
*/
public interface EntityVillagerV2 extends
Entity,
EntityAttributeComponent,
EntityDamageComponent {
public interface EntityVillagerV2 extends Entity, EntityDamageComponent {
}

0 comments on commit 49dc567

Please sign in to comment.