From cd4b74b2ce3ddab5f1684b0ed7e3511e4c414367 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 26 Apr 2020 19:33:10 +0200 Subject: [PATCH] Move levels and such to a MagicReserves --- .../unicopia/TreeTraverser.java | 157 +++++++++++++ .../ability/ChangelingDisguiseAbility.java | 4 +- .../ability/ChangelingFeedAbility.java | 2 +- .../ability/EarthPonyGrowAbility.java | 6 +- .../ability/EarthPonyStompAbility.java | 210 ++---------------- .../ability/UnicornTeleportAbility.java | 2 +- .../unicopia/ability/data/Multi.java | 7 +- .../unicopia/ability/data/Pos.java | 6 +- .../minelittlepony/unicopia/entity/Owned.java | 6 - .../entity/player/GravityDelegate.java | 4 +- .../unicopia/entity/player/MagicReserves.java | 40 ++++ .../unicopia/entity/player/PlayerCamera.java | 4 +- .../unicopia/entity/player/PlayerImpl.java | 9 +- .../unicopia/entity/player/Pony.java | 51 +---- .../gas/{CloudType.java => GasState.java} | 0 .../unicopia/item/AlicornAmuletItem.java | 11 +- .../unicopia/item/SugaryItem.java | 2 +- .../unicopia/magic/spell/DisguiseSpell.java | 3 +- 18 files changed, 257 insertions(+), 267 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/TreeTraverser.java create mode 100644 src/main/java/com/minelittlepony/unicopia/entity/player/MagicReserves.java rename src/main/java/com/minelittlepony/unicopia/gas/{CloudType.java => GasState.java} (100%) diff --git a/src/main/java/com/minelittlepony/unicopia/TreeTraverser.java b/src/main/java/com/minelittlepony/unicopia/TreeTraverser.java new file mode 100644 index 00000000..baffe68a --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/TreeTraverser.java @@ -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(), 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 ascendTrunk(Set 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 descendTree(World w, BlockState log, BlockPos pos) { + return descendTreePart(new HashSet(), w, log, new BlockPos.Mutable(pos)); + } + + private static Optional descendTreePart(Set 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 logs = new HashSet<>(); + Set 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 logs, Set 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)); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java index ca7688c4..72a6b370 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java @@ -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); } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java index e7a39afe..33aac988 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java @@ -147,7 +147,7 @@ public class ChangelingFeedAbility implements Ability { @Override public void preApply(Pony player) { - player.addExertion(6); + player.getMagicalReserves().addExertion(6); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java index a7a31646..1ce03159 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java @@ -58,8 +58,8 @@ public class EarthPonyGrowAbility implements Ability { 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 { @Override public void preApply(Pony player) { - player.addExertion(3); + player.getMagicalReserves().addExertion(3); if (player.getWorld().isClient()) { player.spawnParticles(MagicParticleEffect.UNICORN, 1); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java index 759058d9..83006cac 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java @@ -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 { 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 { 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 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 { }); 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 { 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 { @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 { } } - 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 { } } - 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(), w, pos, log, 0), 0); - } - } - - private BlockPos ascendTrunk(List 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 capturedDrops = Lists.newArrayList(); @@ -326,11 +243,11 @@ public class EarthPonyStompAbility implements Ability { return 0; } - private void dropApplesPart(List drops, List done, World w, BlockState log, BlockPos pos, int level) { + private static void dropApplesPart(List drops, List 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 { } } - private int measureTree(World w, BlockState log, BlockPos pos) { - List logs = new ArrayList<>(); - List 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(), w, log, pos); - } - - private BlockPos getBaseOfTreePart(List 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; - } - - 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); + if (Block.isFaceFullSquare(w.getBlockState(pos).getCollisionShape(w, pos, EntityContext.absent()), Direction.UP)) { + return 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 logs, List 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)); - } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java index 6074b088..ab364cbc 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java @@ -152,7 +152,7 @@ public class UnicornTeleportAbility implements Ability { @Override public void preApply(Pony player) { - player.addExertion(3); + player.getMagicalReserves().addExertion(3); player.spawnParticles(MagicParticleEffect.UNICORN, 5); } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/data/Multi.java b/src/main/java/com/minelittlepony/unicopia/ability/data/Multi.java index 27efad17..1defe557 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/data/Multi.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/data/Multi.java @@ -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 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; } } \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/unicopia/ability/data/Pos.java b/src/main/java/com/minelittlepony/unicopia/ability/data/Pos.java index e8324563..6c85c249 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/data/Pos.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/data/Pos.java @@ -7,9 +7,9 @@ public class Pos extends Hit { public static final Serializer 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(); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/Owned.java b/src/main/java/com/minelittlepony/unicopia/entity/Owned.java index aaea3e6b..510c5469 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/Owned.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/Owned.java @@ -16,10 +16,4 @@ public interface Owned { * Gets the owner that holds this object. */ E getOwner(); - - - @SuppressWarnings("unchecked") - static Owned cast(Object o) { - return (Owned)o; - } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/GravityDelegate.java b/src/main/java/com/minelittlepony/unicopia/entity/player/GravityDelegate.java index 90c89304..76f5374b 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/GravityDelegate.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/GravityDelegate.java @@ -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())) { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/MagicReserves.java b/src/main/java/com/minelittlepony/unicopia/entity/player/MagicReserves.java new file mode 100644 index 00000000..8aa04df0 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/MagicReserves.java @@ -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); + } + +} diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java index 2c40682f..858c1219 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java @@ -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; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerImpl.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerImpl.java index 3ffe79c8..b06e2c20 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerImpl.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerImpl.java @@ -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 PLAYER_RACE = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.INTEGER); private static final TrackedData 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) { } - } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java index ec838af0..0fbd993c 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -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, RaceContainer, */ PlayerCamera getCamera(); + MagicReserves getMagicalReserves(); + /** * Gets the inventory delegate for this player. */ @@ -60,47 +60,9 @@ public interface Pony extends Caster, RaceContainer, 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, RaceContainer, */ 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. */ diff --git a/src/main/java/com/minelittlepony/unicopia/gas/CloudType.java b/src/main/java/com/minelittlepony/unicopia/gas/GasState.java similarity index 100% rename from src/main/java/com/minelittlepony/unicopia/gas/CloudType.java rename to src/main/java/com/minelittlepony/unicopia/gas/GasState.java diff --git a/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java b/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java index 407e0745..992467dd 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java @@ -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) { diff --git a/src/main/java/com/minelittlepony/unicopia/item/SugaryItem.java b/src/main/java/com/minelittlepony/unicopia/item/SugaryItem.java index ee7a9985..dcbaf2de 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/SugaryItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/SugaryItem.java @@ -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); diff --git a/src/main/java/com/minelittlepony/unicopia/magic/spell/DisguiseSpell.java b/src/main/java/com/minelittlepony/unicopia/magic/spell/DisguiseSpell.java index e8711a2e..37308d44 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/spell/DisguiseSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/spell/DisguiseSpell.java @@ -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)entity).setOwner(player.getOwner()); } if (entity instanceof PlayerEntity) {