mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
A bit of cleanup
This commit is contained in:
parent
508a680237
commit
5e331016ff
16 changed files with 52 additions and 81 deletions
|
@ -2,6 +2,7 @@ package com.minelittlepony.unicopia;
|
|||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||
import com.minelittlepony.unicopia.ability.magic.Spell;
|
||||
import com.minelittlepony.unicopia.entity.Equine;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
|
@ -20,6 +21,8 @@ public interface EquinePredicates {
|
|||
Predicate<Entity> PLAYER_CHANGELING = IS_PLAYER.and(entity -> Equine.of(entity).getSpecies() == Race.CHANGELING);
|
||||
Predicate<Entity> PLAYER_PEGASUS = IS_PLAYER.and(entity -> ((PlayerEntity)entity).abilities.creativeMode || RACE_INTERACT_WITH_CLOUDS.test(entity));
|
||||
|
||||
Predicate<Entity> IS_CASTER = e -> !e.removed && (e instanceof Caster || PLAYER_UNICORN.test(e));
|
||||
|
||||
static Predicate<Entity> carryingSpell(Class<? extends Spell> type) {
|
||||
return IS_PLAYER.and(entity -> Pony.of((PlayerEntity)entity).getSpellOrEmpty(type, false).isPresent());
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ public class ChangelingFeedAbility implements Ability<Hit> {
|
|||
}
|
||||
|
||||
protected List<LivingEntity> getTargets(Pony player) {
|
||||
List<Entity> list = VecHelper.getWithinReach(player.getOwner(), 3, this::canDrain);
|
||||
List<Entity> list = VecHelper.findInReach(player.getOwner(), 3, this::canDrain);
|
||||
|
||||
RayTraceHelper.<LivingEntity>findEntity(player.getOwner(), 17, 1,
|
||||
looked -> looked instanceof LivingEntity && !list.contains(looked) && canDrain(looked))
|
||||
|
|
|
@ -14,7 +14,6 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
|
@ -89,13 +88,6 @@ public interface Caster<E extends LivingEntity> extends Owned<E>, Levelled, Affi
|
|||
return getWorld().isClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if we're executing on the server.
|
||||
*/
|
||||
default boolean isLocal() {
|
||||
return !isClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the center position where this caster is located.
|
||||
*/
|
||||
|
@ -112,11 +104,7 @@ public interface Caster<E extends LivingEntity> extends Owned<E>, Levelled, Affi
|
|||
return CasterUtils.findInRange(this, radius);
|
||||
}
|
||||
|
||||
default Stream<Caster<?>> findAllSpellsInRange(Box bb) {
|
||||
return CasterUtils.findInRange(this, bb);
|
||||
}
|
||||
|
||||
default Stream<Entity> findAllEntitiesInRange(double radius) {
|
||||
return VecHelper.findAllEntitiesInRange(getEntity(), getWorld(), getOrigin(), radius);
|
||||
return VecHelper.findInRange(getEntity(), getWorld(), getOrigin(), radius, null).stream();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,43 +7,20 @@ import javax.annotation.Nullable;
|
|||
|
||||
import com.minelittlepony.unicopia.EquinePredicates;
|
||||
import com.minelittlepony.unicopia.entity.PonyContainer;
|
||||
import com.minelittlepony.unicopia.util.VecHelper;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Box;
|
||||
|
||||
public class CasterUtils {
|
||||
/**
|
||||
* Finds all surrounding spells withing range from the given caster.
|
||||
* Finds all surrounding spells within range from the given caster.
|
||||
*/
|
||||
public static Stream<Caster<?>> findInRange(Caster<?> source, double radius) {
|
||||
|
||||
BlockPos origin = source.getOrigin();
|
||||
|
||||
BlockPos begin = origin.add(-radius, -radius, -radius);
|
||||
BlockPos end = origin.add(radius, radius, radius);
|
||||
|
||||
Box bb = new Box(begin, end);
|
||||
|
||||
return source.getWorld().getOtherEntities(source.getEntity(), bb, e ->
|
||||
!e.removed && (e instanceof Caster || e instanceof PlayerEntity)
|
||||
).stream().filter(e -> {
|
||||
double dist = e.squaredDistanceTo(origin.getX(), origin.getY(), origin.getZ());
|
||||
double dist2 = e.squaredDistanceTo(origin.getX(), origin.getY() - e.getStandingEyeHeight(), origin.getZ());
|
||||
|
||||
return dist <= radius || dist2 <= radius;
|
||||
})
|
||||
.map(CasterUtils::toCaster)
|
||||
.filter(o -> o.isPresent() && o.get() != source)
|
||||
.map(Optional::get);
|
||||
}
|
||||
|
||||
static Stream<Caster<?>> findInRange(Caster<?> source, Box bb) {
|
||||
return source.getWorld().getOtherEntities(source.getEntity(), bb, e -> !e.removed && (e instanceof Caster || EquinePredicates.PLAYER_UNICORN.test(e))).stream()
|
||||
.map(CasterUtils::toCaster)
|
||||
.filter(o -> o.isPresent() && o.get() != source)
|
||||
static Stream<Caster<?>> findInRange(Caster<?> source, double radius) {
|
||||
return VecHelper.findInRange(source.getEntity(), source.getWorld(), source.getOrigin(), radius, EquinePredicates.IS_CASTER)
|
||||
.stream()
|
||||
.map(e -> toCaster(e).filter(o -> o != source))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get);
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ public interface ThrowableSpell extends Spell {
|
|||
|
||||
world.playSound(null, entity.getX(), entity.getY(), entity.getZ(), getThrowSound(caster), SoundCategory.NEUTRAL, 0.7F, 0.4F / (world.random.nextFloat() * 0.4F + 0.8F));
|
||||
|
||||
if (caster.isLocal()) {
|
||||
if (!caster.isClient()) {
|
||||
Projectile projectile = new MagicProjectileEntity(UEntities.THROWN_ITEM, world, caster.getOwner());
|
||||
|
||||
projectile.setItem(getCastAppearance(caster));
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package com.minelittlepony.unicopia.ability.magic.spell;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.minelittlepony.unicopia.Affinity;
|
||||
|
@ -61,9 +59,7 @@ public class AttractiveSpell extends ShieldSpell {
|
|||
protected List<Entity> getTargets(Caster<?> source, double radius) {
|
||||
|
||||
if (homingPos != null) {
|
||||
return VecHelper.findAllEntitiesInRange(source.getEntity(), source.getWorld(), source.getOrigin(), radius)
|
||||
.filter(i -> i instanceof ItemEntity)
|
||||
.collect(Collectors.toList());
|
||||
return VecHelper.findInRange(source.getEntity(), source.getWorld(), source.getOrigin(), radius, i -> i instanceof ItemEntity);
|
||||
}
|
||||
|
||||
return super.getTargets(source, radius);
|
||||
|
|
|
@ -122,10 +122,7 @@ public class FireSpell extends AbstractRangedAreaSpell {
|
|||
}
|
||||
|
||||
protected boolean applyEntities(Entity owner, World world, BlockPos pos) {
|
||||
return VecHelper
|
||||
.findAllEntitiesInRange(owner, world, pos, 3)
|
||||
.filter(i -> applyEntitySingle(owner, world, i))
|
||||
.count() > 0;
|
||||
return !VecHelper.findInRange(owner, world, pos, 3, i -> applyEntitySingle(owner, world, i)).isEmpty();
|
||||
}
|
||||
|
||||
protected boolean applyEntitySingle(Entity owner, World world, Entity e) {
|
||||
|
|
|
@ -57,9 +57,7 @@ public class IceSpell extends AbstractRangedAreaSpell {
|
|||
}
|
||||
|
||||
protected boolean applyEntities(LivingEntity owner, World world, BlockPos pos) {
|
||||
return VecHelper.findAllEntitiesInRange(owner, world, pos, 3).filter(i ->
|
||||
applyEntitySingle(owner, i)
|
||||
).count() > 0;
|
||||
return !VecHelper.findInRange(owner, world, pos, 3, i -> applyEntitySingle(owner, i)).isEmpty();
|
||||
}
|
||||
|
||||
protected boolean applyEntitySingle(LivingEntity owner, Entity e) {
|
||||
|
|
|
@ -62,9 +62,7 @@ public class NecromancySpell extends AbstractRangedAreaSpell {
|
|||
|
||||
Vec3d origin = source.getOriginVector();
|
||||
|
||||
if (VecHelper.findAllEntitiesInRange(source.getEntity(), source.getWorld(), source.getOrigin(), radius * 4)
|
||||
.filter(e -> e instanceof ZombieEntity)
|
||||
.count() >= 10 * (1 + additional)) {
|
||||
if (VecHelper.findInRange(source.getEntity(), source.getWorld(), source.getOrigin(), radius * 4, e -> e instanceof ZombieEntity).size() >= 10 * (1 + additional)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ public class ScorchSpell extends FireSpell implements ThrowableSpell {
|
|||
|
||||
@Override
|
||||
public void onImpact(Caster<?> caster, BlockPos pos, BlockState state) {
|
||||
if (caster.isLocal()) {
|
||||
if (!caster.isClient()) {
|
||||
caster.getWorld().createExplosion(caster.getOwner(), pos.getX(), pos.getY(), pos.getZ(), 2, DestructionType.DESTROY);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,37 @@
|
|||
package com.minelittlepony.unicopia.client;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.minelittlepony.common.client.gui.element.Cycler;
|
||||
import com.minelittlepony.common.event.ScreenInitCallback;
|
||||
import com.minelittlepony.common.event.ScreenInitCallback.ButtonList;
|
||||
import com.minelittlepony.unicopia.InteractionManager;
|
||||
import com.minelittlepony.unicopia.Race;
|
||||
import com.minelittlepony.unicopia.Unicopia;
|
||||
import com.minelittlepony.unicopia.entity.player.PlayerCamera;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.world.CreateWorldScreen;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
public class UnicopiaClient implements ClientModInitializer {
|
||||
|
||||
public static Optional<PlayerCamera> getCamera() {
|
||||
PlayerEntity player = MinecraftClient.getInstance().player;
|
||||
|
||||
if (player != null && MinecraftClient.getInstance().cameraEntity == player) {
|
||||
return Optional.of(Pony.of(player).getCamera());
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static Race getPreferredRace() {
|
||||
if (!Unicopia.getConfig().ignoresMineLittlePony()
|
||||
&& MinecraftClient.getInstance().player != null) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.entity.player;
|
|||
import java.util.UUID;
|
||||
|
||||
import com.minelittlepony.unicopia.Race;
|
||||
|
||||
import net.minecraft.entity.attribute.ClampedEntityAttribute;
|
||||
import net.minecraft.entity.attribute.EntityAttribute;
|
||||
import net.minecraft.entity.attribute.EntityAttributeInstance;
|
||||
|
|
|
@ -8,13 +8,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||
|
||||
import com.minelittlepony.unicopia.EquinePredicates;
|
||||
import com.minelittlepony.unicopia.client.UnicopiaClient;
|
||||
import com.minelittlepony.unicopia.client.render.WorldRenderDelegate;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.Camera;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.effect.StatusEffects;
|
||||
import net.minecraft.resource.SynchronousResourceReloadListener;
|
||||
|
@ -25,15 +22,13 @@ abstract class MixinGameRenderer implements AutoCloseable, SynchronousResourceRe
|
|||
at = @At("RETURN"),
|
||||
cancellable = true)
|
||||
private void onGetFov(Camera camera, float f, boolean z, CallbackInfoReturnable<Double> info) {
|
||||
info.setReturnValue(Pony.of(MinecraftClient.getInstance().player)
|
||||
.getCamera()
|
||||
.calculateFieldOfView(info.getReturnValue()));
|
||||
UnicopiaClient.getCamera().ifPresent(c -> info.setReturnValue(c.calculateFieldOfView(info.getReturnValue())));
|
||||
}
|
||||
|
||||
@Inject(method = "renderWorld(FJLnet/minecraft/client/util/math/MatrixStack;)V",
|
||||
at = @At("HEAD"))
|
||||
private void onRenderWorld(float tickDelta, long limitTime, MatrixStack matrices, CallbackInfo info) {
|
||||
WorldRenderDelegate.INSTANCE.applyWorldTransform(matrices, tickDelta);
|
||||
UnicopiaClient.getCamera().ifPresent(c -> matrices.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(c.calculateRoll())));
|
||||
}
|
||||
|
||||
@Inject(method = "getNightVisionStrength(Lnet/minecraft/entity/LivingEntity;F)F",
|
||||
|
|
|
@ -17,7 +17,7 @@ abstract class MixinKeyboardInput extends Input {
|
|||
private void onTick(boolean strafe, CallbackInfo info) {
|
||||
Pony player = Pony.of(MinecraftClient.getInstance().player);
|
||||
|
||||
if (player.getPhysics().isGravityNegative()) {
|
||||
if (player != null && player.getPhysics().isGravityNegative()) {
|
||||
boolean tmp = pressingLeft;
|
||||
|
||||
pressingLeft = pressingRight;
|
||||
|
|
|
@ -21,7 +21,7 @@ abstract class MixinMouse {
|
|||
@Inject(method = "updateMouse()V", at = @At("HEAD"))
|
||||
private void onUpdateMouse(CallbackInfo info) {
|
||||
Pony player = Pony.of(MinecraftClient.getInstance().player);
|
||||
if (player != null&& player.getPhysics().isGravityNegative()) {
|
||||
if (player != null && player.getPhysics().isGravityNegative()) {
|
||||
cursorDeltaX = -cursorDeltaX;
|
||||
cursorDeltaY = -cursorDeltaY;
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@ package com.minelittlepony.unicopia.util;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
|
@ -14,19 +12,23 @@ import net.minecraft.util.math.Vec3d;
|
|||
import net.minecraft.world.World;
|
||||
|
||||
public interface VecHelper {
|
||||
static Stream<Entity> findAllEntitiesInRange(@Nullable Entity origin, World w, BlockPos pos, double radius) {
|
||||
return w.getOtherEntities(origin, new Box(pos).expand(radius), e -> {
|
||||
double dist = Math.sqrt(e.squaredDistanceTo(pos.getX(), pos.getY(), pos.getZ()));
|
||||
double dist2 = Math.sqrt(e.squaredDistanceTo(pos.getX(), pos.getY() - e.getStandingEyeHeight(), pos.getZ()));
|
||||
|
||||
return dist <= radius || dist2 <= radius;
|
||||
}).stream();
|
||||
static Predicate<Entity> inRange(BlockPos center, double range) {
|
||||
double rad = Math.pow(range, 2);
|
||||
return e -> {
|
||||
return e.squaredDistanceTo(center.getX(), center.getY(), center.getZ()) <= rad
|
||||
|| e.squaredDistanceTo(center.getX(), center.getY() - e.getStandingEyeHeight(), center.getZ()) <= rad;
|
||||
};
|
||||
}
|
||||
|
||||
static List<Entity> findInRange(@Nullable Entity origin, World w, BlockPos pos, double radius, @Nullable Predicate<Entity> predicate) {
|
||||
return w.getOtherEntities(origin, new Box(pos).expand(radius), predicate == null ? inRange(pos, radius) : inRange(pos, radius).and(predicate));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all entities within a given range from the player.
|
||||
*/
|
||||
static List<Entity> getWithinReach(PlayerEntity player, double reach, @Nullable Predicate<? super Entity> predicate) {
|
||||
static List<Entity> findInReach(PlayerEntity player, double reach, @Nullable Predicate<? super Entity> predicate) {
|
||||
Vec3d look = player.getCameraPosVec(1).multiply(reach);
|
||||
|
||||
return player.world.getOtherEntities(player, player
|
||||
|
|
Loading…
Reference in a new issue