Move levels and such to a MagicReserves

This commit is contained in:
Sollace 2020-04-26 19:33:10 +02:00
parent 766911e402
commit cd4b74b2ce
18 changed files with 257 additions and 267 deletions

View file

@ -0,0 +1,157 @@
package com.minelittlepony.unicopia;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import com.minelittlepony.unicopia.util.PosHelper;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.LeavesBlock;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
public class TreeTraverser {
public static void removeTree(World w, BlockPos pos) {
BlockState log = w.getBlockState(pos);
int size = measureTree(w, log, pos);
if (size > 0) {
removeTreePart(w, log, ascendTrunk(new HashSet<BlockPos>(), w, pos, log, 0).get(), 0);
}
}
private static void removeTreePart(World w, BlockState log, BlockPos pos, int level) {
if (level < 10 && isWoodOrLeaf(w, log, pos)) {
if (level < 5) {
w.breakBlock(pos, true);
} else {
Block.dropStacks(w.getBlockState(pos), w, pos);
w.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
}
PosHelper.all(pos, p -> {
removeTreePart(w, log, p, level + 1);
}, Direction.UP, Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST);
}
}
private static Optional<BlockPos> ascendTrunk(Set<BlockPos> done, World w, BlockPos pos, BlockState log, int level) {
if (level < 3 && !done.contains(pos)) {
done.add(pos);
BlockPos.Mutable result = new BlockPos.Mutable(ascendTree(w, log, pos, true));
PosHelper.all(pos, p -> {
if (variantAndBlockEquals(w.getBlockState(pos.east()), log)) {
ascendTrunk(done, w, pos.east(), log, level + 1).filter(a -> a.getY() > result.getY()).ifPresent(result::set);
}
}, Direction.EAST, Direction.WEST, Direction.NORTH, Direction.SOUTH);
done.add(result.toImmutable());
return Optional.of(result.toImmutable());
}
return Optional.of(pos);
}
public static BlockPos ascendTree(World w, BlockState log, BlockPos pos, boolean remove) {
int breaks = 0;
BlockState state;
while (variantAndBlockEquals(w.getBlockState(pos.up()), log)) {
if (PosHelper.some(pos, p -> isLeaves(w.getBlockState(p), log), Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST)) {
break;
}
if (remove) {
if (breaks < 10) {
w.breakBlock(pos, true);
} else {
state = w.getBlockState(pos);
Block.dropStacks(state, w, pos);
w.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
}
breaks++;
}
pos = pos.up();
}
return pos;
}
public static Optional<BlockPos> descendTree(World w, BlockState log, BlockPos pos) {
return descendTreePart(new HashSet<BlockPos>(), w, log, new BlockPos.Mutable(pos));
}
private static Optional<BlockPos> descendTreePart(Set<BlockPos> done, World w, BlockState log, BlockPos.Mutable pos) {
if (done.contains(pos) || !variantAndBlockEquals(w.getBlockState(pos), log)) {
return Optional.empty();
}
done.add(pos.toImmutable());
while (variantAndBlockEquals(w.getBlockState(pos.down()), log)) {
pos.setOffset(Direction.DOWN);
done.add(pos.toImmutable());
}
PosHelper.all(pos.toImmutable(), p -> {
descendTreePart(done, w, log, new BlockPos.Mutable(p)).filter(a -> a.getY() < pos.getY()).ifPresent(pos::set);
}, Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST);
done.add(pos.toImmutable());
return Optional.of(pos.toImmutable());
}
public static int measureTree(World w, BlockState log, BlockPos pos) {
Set<BlockPos> logs = new HashSet<>();
Set<BlockPos> leaves = new HashSet<>();
countParts(logs, leaves, w, log, pos);
return logs.size() <= (leaves.size() / 2) ? logs.size() + leaves.size() : 0;
}
private static void countParts(Set<BlockPos> logs, Set<BlockPos> leaves, World w, BlockState log, BlockPos pos) {
if (logs.contains(pos) || leaves.contains(pos)) {
return;
}
BlockState state = w.getBlockState(pos);
boolean yay = false;
if (isLeaves(state, log) && state.get(LeavesBlock.PERSISTENT)) {
leaves.add(pos);
yay = true;
} else if (variantAndBlockEquals(state, log)) {
logs.add(pos);
yay = true;
}
if (yay) {
PosHelper.all(pos, p -> {
countParts(logs, leaves, w, log, p);
}, Direction.UP, Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST);
}
}
public static boolean isWoodOrLeaf(World w, BlockState log, BlockPos pos) {
BlockState state = w.getBlockState(pos);
return variantAndBlockEquals(state, log) || (isLeaves(state, log) && state.get(LeavesBlock.PERSISTENT));
}
private static boolean isLeaves(BlockState state, BlockState log) {
return state.getBlock() instanceof LeavesBlock && variantEquals(state, log);
}
private static boolean variantAndBlockEquals(BlockState one, BlockState two) {
return (one.getBlock() == two.getBlock()) && variantEquals(one, two);
}
private static boolean variantEquals(BlockState one, BlockState two) {
return TreeType.get(one).equals(TreeType.get(two));
}
}

View file

@ -79,13 +79,13 @@ public class ChangelingDisguiseAbility extends ChangelingFeedAbility {
@Override
public void preApply(Pony player) {
player.addEnergy(2);
player.getMagicalReserves().addEnergy(2);
player.spawnParticles(UParticles.CHANGELING_MAGIC, 5);
}
@Override
public void postApply(Pony player) {
player.setEnergy(0);
player.getMagicalReserves().setEnergy(0);
player.spawnParticles(UParticles.CHANGELING_MAGIC, 5);
}
}

View file

@ -147,7 +147,7 @@ public class ChangelingFeedAbility implements Ability<Hit> {
@Override
public void preApply(Pony player) {
player.addExertion(6);
player.getMagicalReserves().addExertion(6);
}
@Override

View file

@ -58,8 +58,8 @@ public class EarthPonyGrowAbility implements Ability<Pos> {
int count = 0;
for (BlockPos pos : BlockPos.iterate(
new BlockPos(data.x - 2, data.y - 2, data.z - 2),
new BlockPos(data.x + 2, data.y + 2, data.z + 2))) {
data.pos().add(-2, -2, -2),
data.pos().add( 2, 2, 2))) {
count += applySingle(player.getWorld(), player.getWorld().getBlockState(pos), pos);
}
@ -82,7 +82,7 @@ public class EarthPonyGrowAbility implements Ability<Pos> {
@Override
public void preApply(Pony player) {
player.addExertion(3);
player.getMagicalReserves().addExertion(3);
if (player.getWorld().isClient()) {
player.spawnParticles(MagicParticleEffect.UNICORN, 1);

View file

@ -2,9 +2,13 @@ package com.minelittlepony.unicopia.ability;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import com.google.common.collect.Lists;
import com.minelittlepony.unicopia.AwaitTickQueue;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.TreeTraverser;
import com.minelittlepony.unicopia.TreeType;
import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.ability.data.Multi;
@ -34,6 +38,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
/**
@ -63,6 +68,7 @@ public class EarthPonyStompAbility implements Ability<Multi> {
return playerSpecies.canUseEarth();
}
@Nullable
@Override
public Multi tryActivate(Pony player) {
HitResult mop = VecHelper.getObjectMouseOver(player.getOwner(), 6, 1);
@ -72,36 +78,27 @@ public class EarthPonyStompAbility implements Ability<Multi> {
BlockState state = player.getWorld().getBlockState(pos);
if (state.getBlock() instanceof LogBlock) {
pos = getBaseOfTree(player.getWorld(), state, pos);
if (measureTree(player.getWorld(), state, pos) > 0) {
return new Multi(pos.getX(), pos.getY(), pos.getZ(), 1);
pos = TreeTraverser.descendTree(player.getWorld(), state, pos).get();
if (TreeTraverser.measureTree(player.getWorld(), state, pos) > 0) {
return new Multi(pos, 1);
}
}
}
if (!player.getOwner().onGround && !player.getOwner().abilities.flying) {
player.getOwner().addVelocity(0, -6, 0);
return new Multi(0, 0, 0, 0);
return new Multi(Vec3i.ZERO, 0);
}
return null;
}
@Override
public Hit.Serializer<Multi> getSerializer() {
return Multi.SERIALIZER;
}
public static BlockPos getSolidBlockBelow(BlockPos pos, World w) {
while (World.isValid(pos)) {
pos = pos.down();
if (Block.isFaceFullSquare(w.getBlockState(pos).getCollisionShape(w, pos, EntityContext.absent()), Direction.UP)) {
return pos;
}
}
return pos;
}
@Override
public void apply(Pony iplayer, Multi data) {
@ -150,7 +147,7 @@ public class EarthPonyStompAbility implements Ability<Multi> {
});
for (int i = 1; i < 202; i+= 2) {
spawnParticleRing(player, i);
spawnParticleRing(player, i, 0);
}
iplayer.subtractEnergyCost(rad);
@ -166,7 +163,7 @@ public class EarthPonyStompAbility implements Ability<Multi> {
if (harmed || player.world.random.nextInt(5) == 0) {
if (!harmed || player.world.random.nextInt(30) == 0) {
AwaitTickQueue.enqueueTask(w -> removeTree(w, data.pos()));
AwaitTickQueue.enqueueTask(w -> TreeTraverser.removeTree(w, data.pos()));
}
iplayer.subtractEnergyCost(3);
@ -190,7 +187,7 @@ public class EarthPonyStompAbility implements Ability<Multi> {
@Override
public void preApply(Pony player) {
player.addExertion(40);
player.getMagicalReserves().addExertion(40);
player.getOwner().attemptSprintingParticles();
}
@ -203,10 +200,6 @@ public class EarthPonyStompAbility implements Ability<Multi> {
}
}
private void spawnParticleRing(PlayerEntity player, int timeDiff) {
spawnParticleRing(player, timeDiff, 0);
}
private void spawnParticleRing(PlayerEntity player, int timeDiff, double yVel) {
int animationTicks = timeDiff / 10;
if (animationTicks < 6) {
@ -228,85 +221,9 @@ public class EarthPonyStompAbility implements Ability<Multi> {
}
}
private void removeTree(World w, BlockPos pos) {
BlockState log = w.getBlockState(pos);
int size = measureTree(w, log, pos);
if (size > 0) {
removeTreePart( w, log, ascendTrunk(new ArrayList<BlockPos>(), w, pos, log, 0), 0);
}
}
private BlockPos ascendTrunk(List<BlockPos> done, World w, BlockPos pos, BlockState log, int level) {
if (level < 3 && !done.contains(pos)) {
done.add(pos);
BlockPos result = ascendTree(w, log, pos, true);
if (variantAndBlockEquals(w.getBlockState(pos.east()), log)) {
result = ascendTrunk(done, w, pos.east(), log, level + 1);
}
if (variantAndBlockEquals(w.getBlockState(pos.west()), log)) {
result = ascendTrunk(done, w, pos.west(), log, level + 1);
}
if (variantAndBlockEquals(w.getBlockState(pos.north()), log)) {
result = ascendTrunk(done, w, pos.north(), log, level + 1);
}
if (variantAndBlockEquals(w.getBlockState(pos.south()), log)) {
result = ascendTrunk(done, w, pos.south(), log, level + 1);
}
return result;
}
return pos;
}
private void removeTreePart(World w, BlockState log, BlockPos pos, int level) {
if (level < 10 && isWoodOrLeaf(w, log, pos)) {
if (level < 5) {
w.breakBlock(pos, true);
} else {
Block.dropStacks(w.getBlockState(pos), w, pos);
w.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
}
PosHelper.all(pos, p -> {
removeTreePart(w, log, p, level + 1);
}, Direction.UP, Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST);
}
}
private BlockPos ascendTree(World w, BlockState log, BlockPos pos, boolean remove) {
int breaks = 0;
BlockState state;
while (variantAndBlockEquals(w.getBlockState(pos.up()), log)) {
if (PosHelper.some(pos, p -> isLeaves(w.getBlockState(p), log), Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST)) {
break;
}
if (remove) {
if (breaks < 10) {
w.breakBlock(pos, true);
} else {
state = w.getBlockState(pos);
Block.dropStacks(state, w, pos);
w.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
}
breaks++;
}
pos = pos.up();
}
return pos;
}
private int dropApples(World w, BlockPos pos) {
BlockState log = w.getBlockState(pos);
int size = measureTree(w, log, pos);
int size = TreeTraverser.measureTree(w, log, pos);
if (size > 0) {
List<ItemEntity> capturedDrops = Lists.newArrayList();
@ -326,11 +243,11 @@ public class EarthPonyStompAbility implements Ability<Multi> {
return 0;
}
private void dropApplesPart(List<ItemEntity> drops, List<BlockPos> done, World w, BlockState log, BlockPos pos, int level) {
private static void dropApplesPart(List<ItemEntity> drops, List<BlockPos> done, World w, BlockState log, BlockPos pos, int level) {
if (!done.contains(pos)) {
done.add(pos);
pos = ascendTree(w, log, pos, false);
if (level < 10 && isWoodOrLeaf(w, log, pos)) {
pos = TreeTraverser.ascendTree(w, log, pos, false);
if (level < 10 && TreeTraverser.isWoodOrLeaf(w, log, pos)) {
BlockState state = w.getBlockState(pos);
if (state.getBlock() instanceof LeavesBlock && w.getBlockState(pos.down()).isAir()) {
@ -350,94 +267,15 @@ public class EarthPonyStompAbility implements Ability<Multi> {
}
}
private int measureTree(World w, BlockState log, BlockPos pos) {
List<BlockPos> logs = new ArrayList<>();
List<BlockPos> leaves = new ArrayList<>();
countParts(logs, leaves, w, log, pos);
return logs.size() <= (leaves.size() / 2) ? logs.size() + leaves.size() : 0;
}
private BlockPos getBaseOfTree(World w, BlockState log, BlockPos pos) {
return getBaseOfTreePart(new ArrayList<BlockPos>(), w, log, pos);
}
private BlockPos getBaseOfTreePart(List<BlockPos> done, World w, BlockState log, BlockPos pos) {
if (done.contains(pos) || !variantAndBlockEquals(w.getBlockState(pos), log)) {
return null;
}
done.add(pos);
while (variantAndBlockEquals(w.getBlockState(pos.down()), log)) {
private static BlockPos getSolidBlockBelow(BlockPos pos, World w) {
while (World.isValid(pos)) {
pos = pos.down();
done.add(pos);
}
BlockPos adjacent = getBaseOfTreePart(done, w, log, pos.north());
if (adjacent != null && adjacent.getY() < pos.getY()) {
pos = adjacent;
if (Block.isFaceFullSquare(w.getBlockState(pos).getCollisionShape(w, pos, EntityContext.absent()), Direction.UP)) {
return pos;
}
adjacent = getBaseOfTreePart(done, w, log, pos.south());
if (adjacent != null && adjacent.getY() < pos.getY()) {
pos = adjacent;
}
adjacent = getBaseOfTreePart(done, w, log, pos.east());
if (adjacent != null && adjacent.getY() < pos.getY()) {
pos = adjacent;
}
adjacent = getBaseOfTreePart(done, w, log, pos.west());
if (adjacent != null && adjacent.getY() < pos.getY()) {
pos = adjacent;
}
if (!done.contains(pos)) {
done.add(pos);
}
return pos;
}
private boolean isWoodOrLeaf(World w, BlockState log, BlockPos pos) {
BlockState state = w.getBlockState(pos);
return variantAndBlockEquals(state, log) || (isLeaves(state, log) && state.get(LeavesBlock.PERSISTENT));
}
private void countParts(List<BlockPos> logs, List<BlockPos> leaves, World w, BlockState log, BlockPos pos) {
if (logs.contains(pos) || leaves.contains(pos)) {
return;
}
BlockState state = w.getBlockState(pos);
boolean yay = false;
if (state.getBlock() instanceof LeavesBlock && state.get(LeavesBlock.PERSISTENT) && variantEquals(state, log)) {
leaves.add(pos);
yay = true;
} else if (variantAndBlockEquals(state, log)) {
logs.add(pos);
yay = true;
}
if (yay) {
PosHelper.all(pos, p -> {
countParts(logs, leaves, w, log, p);
}, Direction.UP, Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST);
}
}
private boolean isLeaves(BlockState state, BlockState log) {
return state.getBlock() instanceof LeavesBlock && variantEquals(state, log);
}
private boolean variantAndBlockEquals(BlockState one, BlockState two) {
return (one.getBlock() == two.getBlock()) && variantEquals(one, two);
}
private boolean variantEquals(BlockState one, BlockState two) {
return TreeType.get(one).equals(TreeType.get(two));
}
}

View file

@ -152,7 +152,7 @@ public class UnicornTeleportAbility implements Ability<Pos> {
@Override
public void preApply(Pony player) {
player.addExertion(3);
player.getMagicalReserves().addExertion(3);
player.spawnParticles(MagicParticleEffect.UNICORN, 5);
}

View file

@ -1,11 +1,12 @@
package com.minelittlepony.unicopia.ability.data;
import net.minecraft.util.PacketByteBuf;
import net.minecraft.util.math.Vec3i;
public class Multi extends Pos {
public static final Serializer<Multi> SERIALIZER = Multi::new;
public int hitType;
public final int hitType;
Multi(PacketByteBuf buf) {
super(buf);
@ -18,8 +19,8 @@ public class Multi extends Pos {
buf.writeInt(hitType);
}
public Multi(int x, int y, int z, int hit) {
super(x, y, z);
public Multi(Vec3i pos, int hit) {
super(pos.getX(), pos.getY(), pos.getZ());
hitType = hit;
}
}

View file

@ -7,9 +7,9 @@ public class Pos extends Hit {
public static final Serializer<Pos> SERIALIZER = Pos::new;
public int x;
public int y;
public int z;
public final int x;
public final int y;
public final int z;
Pos(PacketByteBuf buf) {
x = buf.readInt();

View file

@ -16,10 +16,4 @@ public interface Owned<E> {
* Gets the owner that holds this object.
*/
E getOwner();
@SuppressWarnings("unchecked")
static <T> Owned<T> cast(Object o) {
return (Owned<T>)o;
}
}

View file

@ -163,8 +163,8 @@ public class GravityDelegate implements Updatable, FlightControl, NbtSerialisabl
if (isExperienceCritical()) {
if (player.getEnergy() <= 0.25F) {
player.addEnergy(2);
if (player.getMagicalReserves().getEnergy() <= 0.25F) {
player.getMagicalReserves().addEnergy(2);
}
if (isRainbooming || (entity.isSneaking() && isRainboom())) {

View file

@ -0,0 +1,40 @@
package com.minelittlepony.unicopia.entity.player;
public interface MagicReserves {
/**
* Gets the amount of exertion this player has put toward any given activity.
* This is simillar to tiredness.
*/
float getExertion();
/**
* Sets the player's exertion level.
*/
void setExertion(float exertion);
/**
* Adds player tiredness.
*/
default void addExertion(int exertion) {
setExertion(getExertion() + exertion/100F);
}
/**
* Gets the amount of excess energy the player has.
* This is increased by eating sugar.
*/
float getEnergy();
/**
* Sets the player's energy level.
*/
void setEnergy(float energy);
/**
* Adds energy to the player's existing energy level.
*/
default void addEnergy(int energy) {
setEnergy(getEnergy() + energy / 100F);
}
}

View file

@ -45,14 +45,14 @@ public class PlayerCamera extends MotionCompositor {
}
public double calculateFieldOfView(double fov) {
fov += player.getExertion() / 5;
fov += player.getMagicalReserves().getExertion() / 5;
fov += getEnergyAddition();
return fov;
}
protected float getEnergyAddition() {
int maxE = (int)Math.floor(player.getEnergy() * 100);
int maxE = (int)Math.floor(player.getMagicalReserves().getEnergy() * 100);
if (maxE <= 0) {
return 0;

View file

@ -44,7 +44,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.Difficulty;
public class PlayerImpl implements Pony {
public class PlayerImpl implements Pony, MagicReserves {
private static final TrackedData<Integer> PLAYER_RACE = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.INTEGER);
private static final TrackedData<Float> ENERGY = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT);
@ -108,6 +108,11 @@ public class PlayerImpl implements Pony {
entity.sendAbilitiesUpdate();
}
@Override
public MagicReserves getMagicalReserves() {
return this;
}
@Override
public float getExertion() {
return getOwner().getDataTracker().get(EXERTION);
@ -139,7 +144,6 @@ public class PlayerImpl implements Pony {
}
@Nullable
@Override
public HeldMagicEffect getHeldEffect(ItemStack stack) {
if (!getSpecies().canCast()) {
@ -457,5 +461,4 @@ public class PlayerImpl implements Pony {
@Override
public void setCurrentLevel(int level) {
}
}

View file

@ -9,14 +9,12 @@ import com.minelittlepony.unicopia.entity.FlightControl;
import com.minelittlepony.unicopia.entity.Ponylike;
import com.minelittlepony.unicopia.entity.RaceContainer;
import com.minelittlepony.unicopia.magic.Caster;
import com.minelittlepony.unicopia.magic.HeldMagicEffect;
import com.minelittlepony.unicopia.network.Transmittable;
import com.minelittlepony.util.IInterpolator;
import com.mojang.authlib.GameProfile;
import com.mojang.datafixers.util.Either;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Unit;
import net.minecraft.util.math.BlockPos;
@ -47,6 +45,8 @@ public interface Pony extends Caster<PlayerEntity>, RaceContainer<PlayerEntity>,
*/
PlayerCamera getCamera();
MagicReserves getMagicalReserves();
/**
* Gets the inventory delegate for this player.
*/
@ -60,47 +60,9 @@ public interface Pony extends Caster<PlayerEntity>, RaceContainer<PlayerEntity>,
PageOwner getPages();
/**
* Gets the amount of exertion this player has put toward any given activity.
* This is simillar to tiredness.
*/
float getExertion();
/**
* Sets the player's exertion level.
*/
void setExertion(float exertion);
/**
*
* @return
*/
float getExtendedReach();
/**
* Adds player tiredness.
*/
default void addExertion(int exertion) {
setExertion(getExertion() + exertion/100F);
}
/**
* Gets the amount of excess energy the player has.
* This is increased by eating sugar.
*/
float getEnergy();
/**
* Sets the player's energy level.
*/
void setEnergy(float energy);
/**
* Adds energy to the player's existing energy level.
*/
default void addEnergy(int energy) {
setEnergy(getEnergy() + energy / 100F);
}
void copyFrom(Pony oldPlayer);
/**
@ -108,15 +70,6 @@ public interface Pony extends Caster<PlayerEntity>, RaceContainer<PlayerEntity>,
*/
boolean stepOnCloud();
/**
* Gets the held effect for the given item.
* Updates it if the current held effect doesn't match or is empty.
*
* Returns null if the passed item has no held effect.
*/
@Nullable
HeldMagicEffect getHeldEffect(ItemStack stack);
/**
* Called when this player falls.
*/

View file

@ -9,6 +9,7 @@ import com.google.common.collect.Multimap;
import com.minelittlepony.unicopia.AwaitTickQueue;
import com.minelittlepony.unicopia.ducks.IItemEntity;
import com.minelittlepony.unicopia.entity.ItemEntityCapabilities;
import com.minelittlepony.unicopia.entity.player.MagicReserves;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.magic.Affinity;
import com.minelittlepony.unicopia.magic.AddictiveMagicalItem;
@ -163,12 +164,14 @@ public class AlicornAmuletItem extends ArmorItem implements AddictiveMagicalItem
float attachedTime = iplayer.getInventory().getTicksAttached(this);
if (iplayer.getExertion() < 1) {
iplayer.addExertion(2);
MagicReserves reserves = iplayer.getMagicalReserves();
if (reserves.getExertion() < 1) {
reserves.addExertion(2);
}
if (iplayer.getEnergy() < 0.005F + (attachedTime / 1000000)) {
iplayer.addEnergy(2);
if (reserves.getEnergy() < 0.005F + (attachedTime / 1000000)) {
reserves.addEnergy(2);
}
if (attachedTime == 1) {

View file

@ -20,7 +20,7 @@ public class SugaryItem extends Item {
@Override
public ItemStack finishUsing(ItemStack stack, World world, LivingEntity entity) {
if (sugarAmount != 0 && entity instanceof PlayerEntity) {
Pony.of((PlayerEntity)entity).addEnergy(sugarAmount);
Pony.of((PlayerEntity)entity).getMagicalReserves().addEnergy(sugarAmount);
}
return super.finishUsing(stack, world, entity);

View file

@ -305,6 +305,7 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
return update(caster);
}
@SuppressWarnings("unchecked")
@Override
public boolean update(Caster<?> source) {
LivingEntity owner = source.getOwner();
@ -397,7 +398,7 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
source.getOwner().setInvisible(true);
if (entity instanceof Owned) {
Owned.cast(entity).setOwner(player.getOwner());
((Owned<LivingEntity>)entity).setOwner(player.getOwner());
}
if (entity instanceof PlayerEntity) {