Skip to content

Commit

Permalink
refactor(next): entity
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Sep 27, 2022
1 parent 12371ef commit fd01a3a
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 156 deletions.
@@ -0,0 +1,46 @@
package org.auioc.mcmod.arnicalib.game.entity;

import java.util.function.Function;
import java.util.function.Predicate;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.MobType;
import net.minecraft.world.entity.player.Player;

public class EntityFunctions {

public static final Predicate<Entity> IS_LIVING = (entity) -> entity instanceof LivingEntity;
public static final Predicate<Entity> IS_PLAYER = (entity) -> entity instanceof Player;
public static final Predicate<Entity> IS_LOCAL_PLAYER = (entity) -> entity instanceof net.minecraft.client.player.LocalPlayer;
public static final Predicate<Entity> IS_SERVER_PLAYER = (entity) -> entity instanceof ServerPlayer;
public static final Predicate<Entity> IS_FAKE_PLAYER = (entity) -> entity instanceof net.minecraftforge.common.util.FakePlayer;
public static final Predicate<Entity> IS_PROJECTILE = (entity) -> entity instanceof net.minecraft.world.entity.projectile.Projectile;

public static final Predicate<Entity> IS_FRIENDLY = (entity) -> getCategory(entity).isFriendly();
public static final Predicate<Entity> IS_PERSISTENT = (entity) -> getCategory(entity).isPersistent();
public static final Predicate<Entity> IS_MISC = (entity) -> getCategory(entity) == MobCategory.MISC;
public static final Predicate<Entity> IS_MONSTER = (entity) -> getCategory(entity) == MobCategory.MONSTER;
public static final Predicate<Entity> IS_CREATURE = (entity) -> getCategory(entity) == MobCategory.CREATURE;
public static final Predicate<Entity> IS_AMBIENT = (entity) -> getCategory(entity) == MobCategory.AMBIENT;
public static final Predicate<Entity> IS_AXOLOTLS = (entity) -> getCategory(entity) == MobCategory.AXOLOTLS;
public static final Predicate<Entity> IS_UNDERGROUND_WATER_CREATURE = (entity) -> getCategory(entity) == MobCategory.UNDERGROUND_WATER_CREATURE;
public static final Predicate<Entity> IS_WATER_CREATURE = (entity) -> getCategory(entity) == MobCategory.WATER_CREATURE;
public static final Predicate<Entity> IS_WATER_AMBIENT = (entity) -> getCategory(entity) == MobCategory.WATER_AMBIENT;

public static final Predicate<LivingEntity> IS_UNDEFINED = (living) -> living.getMobType() == MobType.UNDEFINED;
public static final Predicate<LivingEntity> IS_DEFINED = (living) -> living.getMobType() != MobType.UNDEFINED;
public static final Predicate<LivingEntity> IS_UNDEAD = (living) -> living.getMobType() == MobType.UNDEAD;
public static final Predicate<LivingEntity> IS_ARTHROPOD = (living) -> living.getMobType() == MobType.ARTHROPOD;
public static final Predicate<LivingEntity> IS_ILLAGER = (living) -> living.getMobType() == MobType.ILLAGER;
public static final Predicate<LivingEntity> IS_WATER = (living) -> living.getMobType() == MobType.WATER;

public static final Function<Entity, LivingEntity> CAST_TO_LIVING = (entity) -> (LivingEntity) entity;
public static final Function<Player, ServerPlayer> CAST_TO_SERVER_PLAYER = (player) -> (ServerPlayer) player;

private static MobCategory getCategory(Entity entity) {
return entity.getType().getCategory();
}

}
@@ -0,0 +1,28 @@
package org.auioc.mcmod.arnicalib.game.entity;

import org.auioc.mcmod.arnicalib.game.world.LevelUtils;
import net.minecraft.core.Vec3i;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;

public class EntityUtils {

public static void teleportTo(Entity entity, Vec3i pos) {
entity.teleportTo(pos.getX() + 0.5D, pos.getY(), pos.getZ() + 0.5D);
}

public static void teleportTo(Entity entity, Vec3 pos) {
entity.teleportTo(pos.x, pos.y, pos.z);
}

public static void teleportTo(Entity entity, ResourceKey<Level> dim, Vec3 pos) {
entity.changeDimension(LevelUtils.getLevel(dim), LevelUtils.createSimpleTeleporter(pos));
}

public static void teleportTo(Entity entity, ResourceKey<Level> dim, Vec3i pos) {
entity.changeDimension(LevelUtils.getLevel(dim), LevelUtils.createSimpleTeleporter(pos));
}

}
@@ -1,6 +1,7 @@
package org.auioc.mcmod.arnicalib.utils.game;
package org.auioc.mcmod.arnicalib.game.entity;

import javax.annotation.Nullable;
import org.auioc.mcmod.arnicalib.utils.game.ItemUtils;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
Expand Down
@@ -1,4 +1,4 @@
package org.auioc.mcmod.arnicalib.game.entity;
package org.auioc.mcmod.arnicalib.game.entity.projectile;

import javax.annotation.Nullable;
import net.minecraft.world.phys.Vec3;
Expand Down
@@ -1,4 +1,4 @@
package org.auioc.mcmod.arnicalib.game.entity;
package org.auioc.mcmod.arnicalib.game.entity.projectile;

import java.util.Set;
import net.minecraft.world.effect.MobEffectInstance;
Expand Down
Expand Up @@ -2,8 +2,8 @@

import java.util.Optional;
import java.util.Random;
import org.auioc.mcmod.arnicalib.game.entity.EntityUtils;
import org.auioc.mcmod.arnicalib.game.world.phys.AABBUtils;
import org.auioc.mcmod.arnicalib.utils.game.EntityUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
Expand Down
@@ -1,6 +1,6 @@
package org.auioc.mcmod.arnicalib.mixin.common.api;

import org.auioc.mcmod.arnicalib.game.entity.ITippedArrow;
import org.auioc.mcmod.arnicalib.game.entity.projectile.ITippedArrow;

public interface IMixinArrow extends ITippedArrow {

Expand Down
@@ -1,6 +1,6 @@
package org.auioc.mcmod.arnicalib.mixin.common.api;

import org.auioc.mcmod.arnicalib.game.entity.IHProjectile;
import org.auioc.mcmod.arnicalib.game.entity.projectile.IHProjectile;

public interface IMixinProjectile extends IHProjectile {

Expand Down
Expand Up @@ -5,8 +5,8 @@
import java.util.List;
import java.util.Optional;
import org.auioc.mcmod.arnicalib.game.command.CommandSourceUtils;
import org.auioc.mcmod.arnicalib.game.entity.EntityFunctions;
import org.auioc.mcmod.arnicalib.game.world.position.RandomTeleporter;
import org.auioc.mcmod.arnicalib.utils.game.EntityUtils;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.DoubleArgumentType;
Expand Down Expand Up @@ -93,7 +93,7 @@ private static int unsafe(CommandContext<CommandSourceStack> ctx, Optional<Vec3>
}

private static List<? extends LivingEntity> getLivingEntities(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
return EntityArgument.getEntities(ctx, "entities").stream().filter(EntityUtils.IS_LIVING).map(EntityUtils.CAST_TO_LIVING).toList();
return EntityArgument.getEntities(ctx, "entities").stream().filter(EntityFunctions.IS_LIVING).map(EntityFunctions.CAST_TO_LIVING).toList();
}

}
148 changes: 0 additions & 148 deletions src/main/java/org/auioc/mcmod/arnicalib/utils/game/EntityUtils.java

This file was deleted.

0 comments on commit fd01a3a

Please sign in to comment.