Skip to content

Commit

Permalink
Made water vision of Merling togglable
Browse files Browse the repository at this point in the history
  • Loading branch information
apace100 committed Jul 29, 2020
1 parent 0582294 commit d58b08f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class PowerType<T extends Power> {
private BiFunction<PowerType, PlayerEntity, T> factory;
private boolean isHidden = false;

protected PowerType(BiFunction<PowerType, PlayerEntity, T> factory) {
public PowerType(BiFunction<PowerType, PlayerEntity, T> factory) {
this.factory = factory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class PowerTypes {

public static final PowerType<Power> WATER_BREATHING;
public static final PowerType<Power> AQUA_AFFINITY;
public static final PowerType<NightVisionPower> WATER_VISION;
public static final PowerType<ToggleNightVisionPower> WATER_VISION;
public static final PowerType<FloatPower> SWIM_SPEED;
public static final PowerType<Power> LIKE_WATER;
public static final PowerType<SetEntityGroupPower> AQUATIC;
Expand Down Expand Up @@ -81,7 +81,7 @@ public class PowerTypes {

WATER_BREATHING = register("water_breathing", new PowerType<>(Power::new));
AQUA_AFFINITY = register("aqua_affinity", new PowerType<>(Power::new));
WATER_VISION = register("water_vision", new PowerType<>((type, player) -> (NightVisionPower)new NightVisionPower(type, player).addCondition(p -> p.isSubmergedIn(FluidTags.WATER))));
WATER_VISION = register("water_vision", new PowerType<>((type, player) -> (ToggleNightVisionPower)new ToggleNightVisionPower(type, player).addCondition(p -> p.isSubmergedIn(FluidTags.WATER))));
SWIM_SPEED = register("swim_speed", new PowerType<>((type, player) -> new FloatPower(type, player, 0.04F)));
LIKE_WATER = register("like_water", new PowerType<>(Power::new));
AQUATIC = register("aquatic", new PowerType<>((type, player) -> new SetEntityGroupPower(type, player, EntityGroup.AQUATIC)).setHidden());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.apace100.origins.power;

import io.github.apace100.origins.component.OriginComponent;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.ByteTag;
import net.minecraft.nbt.Tag;

public class ToggleNightVisionPower extends NightVisionPower implements Active {
private boolean isActive;

public ToggleNightVisionPower(PowerType<?> type, PlayerEntity player) {
super(type, player);
this.isActive = true;
}

@Override
public void onUse() {
this.isActive = !this.isActive;
OriginComponent.sync(player);
}

public boolean isActive() {
return this.isActive && super.isActive();
}

@Override
public Tag toTag() {
return ByteTag.of(isActive);
}

@Override
public void fromTag(Tag tag) {
isActive = ((ByteTag)tag).getByte() > 0;
}
}

0 comments on commit d58b08f

Please sign in to comment.