Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Jun 29, 2024
2 parents cb5098f + fe1c6b1 commit 3e8bf37
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,25 @@
*/
public interface EffectInstance {

static EffectInstance fromNBT(NbtMap nbt) {
var effectType = EffectRegistry.getRegistry().getByK1((int) nbt.getByte("Id"));
Preconditions.checkNotNull(effectType, "Effect type not found for id: " + nbt.getByte("Id") + "!");
int amplifier = nbt.getByte("Amplifier");
int duration = nbt.getInt("Duration");
boolean visible = nbt.getBoolean("ShowParticles");
return new SimpleEffectInstance(effectType, amplifier, duration, visible);
}

EffectType getType();

int getAmplifier();

void setAmplifier(int amplifier);

default int getLevel() {
return getAmplifier() + 1;
}

boolean isVisible();

void setVisible(boolean visible);
Expand All @@ -25,13 +38,4 @@ public interface EffectInstance {
void setDuration(int duration);

NbtMap saveNBT();

static EffectInstance fromNBT(NbtMap nbt) {
var effectType = EffectRegistry.getRegistry().getByK1((int) nbt.getByte("Id"));
Preconditions.checkNotNull(effectType, "Effect type not found for id: " + nbt.getByte("Id") + "!");
int amplifier = nbt.getByte("Amplifier");
int duration = nbt.getInt("Duration");
boolean visible = nbt.getBoolean("ShowParticles");
return new SimpleEffectInstance(effectType, amplifier, duration, visible);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ private EffectAbsorptionType() {

@Override
public void onAdd(Entity entity, EffectInstance effectInstance) {
var amplifier = effectInstance.getAmplifier() + 1;
var newValue = amplifier * 4;
if (newValue > entity.getAbsorption()) {
entity.setAbsorption(newValue);
}
entity.setAbsorption(effectInstance.getLevel() * 4);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ private EffectHealthBoostType() {

@Override
public void onAdd(Entity entity, EffectInstance effectInstance) {
var amplifier = effectInstance.getAmplifier() + 1;
if (!(entity instanceof EntityAttributeComponent attributeComponent)) return;
attributeComponent.setMaxHealth(attributeComponent.getMaxHealth() + (amplifier * 4));
var level = effectInstance.getLevel();
attributeComponent.setMaxHealth(attributeComponent.getMaxHealth() + (level * 4));
}

@Override
public void onRemove(Entity entity, EffectInstance effectInstance) {
var amplifier = effectInstance.getAmplifier() + 1;
if (!(entity instanceof EntityAttributeComponent attributeComponent)) return;
attributeComponent.setMaxHealth(attributeComponent.getMaxHealth() - (amplifier * 4));
var level = effectInstance.getLevel();
attributeComponent.setMaxHealth(attributeComponent.getMaxHealth() - (level * 4));
if (attributeComponent.getHealth() > attributeComponent.getMaxHealth()) {
attributeComponent.setHealth(attributeComponent.getMaxHealth());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ private EffectSlownessType() {
@Override
public void onAdd(Entity entity, EffectInstance effectInstance) {
if (!(entity instanceof EntityPlayer player)) return;
var amplifier = effectInstance.getAmplifier() + 1;
var slowness = 1 - amplifier * 0.15f;
var level = effectInstance.getLevel();
var slowness = 1 - level * 0.15f;
if (slowness <= 0) slowness = 0.00001f;
player.setMovementSpeed(player.getMovementSpeed() * slowness);
}

@Override
public void onRemove(Entity entity, EffectInstance effectInstance) {
if (!(entity instanceof EntityPlayer player)) return;
var amplifier = effectInstance.getAmplifier() + 1;
var slowness = 1 - amplifier * 0.15f;
var level = effectInstance.getLevel();
var slowness = 1 - level * 0.15f;
if (slowness <= 0) slowness = 0.00001f;
player.setMovementSpeed(player.getMovementSpeed() / slowness);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ private EffectSpeedType() {
@Override
public void onAdd(Entity entity, EffectInstance effectInstance) {
if (!(entity instanceof EntityPlayer player)) return;
var amplifier = effectInstance.getAmplifier() + 1;
var speed = 1 + amplifier * 0.2f;
var level = effectInstance.getLevel();
var speed = 1 + level * 0.2f;
player.setMovementSpeed(player.getMovementSpeed() * speed);
}

@Override
public void onRemove(Entity entity, EffectInstance effectInstance) {
if (!(entity instanceof EntityPlayer player)) return;
var amplifier = effectInstance.getAmplifier() + 1;
var speed = 1 + amplifier * 0.2f;
var level = effectInstance.getLevel();
var speed = 1 + level * 0.2f;
player.setMovementSpeed(player.getMovementSpeed() / speed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ protected void sendMobEffectPacket(MobEffectPacket packet) {

@Override
public void setAbsorption(float absorption) {
if (this.absorption == absorption) return;
super.setAbsorption(absorption);
attributeComponent.setAttribute(AttributeType.ABSORPTION, absorption);
}
Expand Down

0 comments on commit 3e8bf37

Please sign in to comment.