Search in sources :

Example 1 with PathfinderGoalSelector

use of net.minecraft.server.v1_12_R1.PathfinderGoalSelector in project solinia3-core by mixxit.

the class SoliniaLivingEntity method targetSelector.

public void targetSelector() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    final net.minecraft.server.v1_12_R1.EntityInsentient e = (net.minecraft.server.v1_12_R1.EntityInsentient) ((org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) getBukkitLivingEntity()).getHandle();
    if (!(e instanceof net.minecraft.server.v1_12_R1.EntityCreature) && !(e instanceof net.minecraft.server.v1_12_R1.EntityTameableAnimal))
        return;
    final Field goalsField = net.minecraft.server.v1_12_R1.EntityInsentient.class.getDeclaredField("targetSelector");
    goalsField.setAccessible(true);
    final net.minecraft.server.v1_12_R1.PathfinderGoalSelector goals = (net.minecraft.server.v1_12_R1.PathfinderGoalSelector) goalsField.get(e);
    Field listField = net.minecraft.server.v1_12_R1.PathfinderGoalSelector.class.getDeclaredField("b");
    listField.setAccessible(true);
    Set list = (Set) listField.get(goals);
    list.clear();
    listField = net.minecraft.server.v1_12_R1.PathfinderGoalSelector.class.getDeclaredField("c");
    listField.setAccessible(true);
    list = (Set) listField.get(goals);
    list.clear();
    goals.a(1, (net.minecraft.server.v1_12_R1.PathfinderGoalLookAtPlayer) new net.minecraft.server.v1_12_R1.PathfinderGoalLookAtPlayer(e, (Class) net.minecraft.server.v1_12_R1.EntityHuman.class, 5.0f, 1.0f));
    goals.a(2, (net.minecraft.server.v1_12_R1.PathfinderGoalLookAtPlayer) new net.minecraft.server.v1_12_R1.PathfinderGoalLookAtPlayer(e, (Class) net.minecraft.server.v1_12_R1.EntityHuman.class, 5.0f, 1.0f));
    goals.a(10, (net.minecraft.server.v1_12_R1.PathfinderGoalLookAtPlayer) new net.minecraft.server.v1_12_R1.PathfinderGoalLookAtPlayer(e, (Class) net.minecraft.server.v1_12_R1.EntityHuman.class, 5.0f, 1.0f));
    goals.a(1, new PathfinderGoalOwnerHurtByTarget((EntityTameableAnimal) e));
    goals.a(2, new PathfinderGoalOwnerHurtTarget((EntityTameableAnimal) e));
    goals.a(3, new PathfinderGoalHurtByTarget((EntityCreature) e, true, new Class[0]));
}
Also used : Set(java.util.Set) EntityCreature(net.minecraft.server.v1_12_R1.EntityCreature) EntityTameableAnimal(net.minecraft.server.v1_12_R1.EntityTameableAnimal) Field(java.lang.reflect.Field) EntityTameableAnimal(net.minecraft.server.v1_12_R1.EntityTameableAnimal) PathfinderGoalOwnerHurtTarget(net.minecraft.server.v1_12_R1.PathfinderGoalOwnerHurtTarget) PathfinderGoalOwnerHurtByTarget(net.minecraft.server.v1_12_R1.PathfinderGoalOwnerHurtByTarget) PathfinderGoalHurtByTarget(net.minecraft.server.v1_12_R1.PathfinderGoalHurtByTarget) ISoliniaClass(com.solinia.solinia.Interfaces.ISoliniaClass) EntityCreature(net.minecraft.server.v1_12_R1.EntityCreature)

Example 2 with PathfinderGoalSelector

use of net.minecraft.server.v1_12_R1.PathfinderGoalSelector in project Citizens2 by CitizensDev.

the class NMSImpl method clearGoals.

public static void clearGoals(NPC npc, PathfinderGoalSelector... goalSelectors) {
    if (GOAL_SET_FIELD == null || goalSelectors == null)
        return;
    int i = 0;
    for (PathfinderGoalSelector selector : goalSelectors) {
        try {
            Collection<?> list = (Collection<?>) GOAL_SET_FIELD.invoke(selector);
            if (!list.isEmpty()) {
                npc.data().set("selector" + i, Lists.newArrayList(list));
            }
            list.clear();
        } catch (Exception e) {
            Messaging.logTr(Messages.ERROR_CLEARING_GOALS, e.getLocalizedMessage());
        } catch (Throwable e) {
            Messaging.logTr(Messages.ERROR_CLEARING_GOALS, e.getLocalizedMessage());
        }
        i++;
    }
}
Also used : Collection(java.util.Collection) PathfinderGoalSelector(net.minecraft.server.v1_16_R3.PathfinderGoalSelector) PathPoint(net.minecraft.server.v1_16_R3.PathPoint) ReportedException(net.minecraft.server.v1_16_R3.ReportedException) CommandException(net.citizensnpcs.api.command.exception.CommandException)

Example 3 with PathfinderGoalSelector

use of net.minecraft.server.v1_12_R1.PathfinderGoalSelector in project Citizens2 by CitizensDev.

the class NMSImpl method clearGoals.

public static void clearGoals(NPC npc, PathfinderGoalSelector... goalSelectors) {
    if (GOAL_SET_FIELD == null || goalSelectors == null)
        return;
    int i = 0;
    for (PathfinderGoalSelector selector : goalSelectors) {
        try {
            Collection<?> list = (Collection<?>) GOAL_SET_FIELD.invoke(selector);
            if (!list.isEmpty()) {
                npc.data().set("selector" + i, Lists.newArrayList(list));
            }
            list.clear();
        } catch (Exception e) {
            Messaging.logTr(Messages.ERROR_CLEARING_GOALS, e.getLocalizedMessage());
        } catch (Throwable e) {
            Messaging.logTr(Messages.ERROR_CLEARING_GOALS, e.getLocalizedMessage());
        }
        i++;
    }
}
Also used : Collection(java.util.Collection) PathfinderGoalSelector(net.minecraft.server.v1_15_R1.PathfinderGoalSelector) PathPoint(net.minecraft.server.v1_15_R1.PathPoint) ReportedException(net.minecraft.server.v1_15_R1.ReportedException) CommandException(net.citizensnpcs.api.command.exception.CommandException)

Example 4 with PathfinderGoalSelector

use of net.minecraft.server.v1_12_R1.PathfinderGoalSelector in project Citizens2 by CitizensDev.

the class NMSImpl method restoreGoals.

public static void restoreGoals(NPC npc, PathfinderGoalSelector... goalSelectors) {
    if (GOAL_SET_FIELD == null || goalSelectors == null)
        return;
    int i = 0;
    for (PathfinderGoalSelector selector : goalSelectors) {
        try {
            Collection<Object> list = (Collection<Object>) GOAL_SET_FIELD.invoke(selector);
            list.clear();
            Collection<Object> old = npc.data().get("selector" + i);
            if (old != null) {
                list.addAll(old);
            }
        } catch (Exception e) {
            Messaging.logTr(Messages.ERROR_RESTORING_GOALS, e.getLocalizedMessage());
        } catch (Throwable e) {
            Messaging.logTr(Messages.ERROR_RESTORING_GOALS, e.getLocalizedMessage());
        }
        i++;
    }
}
Also used : Collection(java.util.Collection) DataWatcherObject(net.minecraft.server.v1_15_R1.DataWatcherObject) PathfinderGoalSelector(net.minecraft.server.v1_15_R1.PathfinderGoalSelector) PathPoint(net.minecraft.server.v1_15_R1.PathPoint) ReportedException(net.minecraft.server.v1_15_R1.ReportedException) CommandException(net.citizensnpcs.api.command.exception.CommandException)

Example 5 with PathfinderGoalSelector

use of net.minecraft.server.v1_12_R1.PathfinderGoalSelector in project Citizens2 by CitizensDev.

the class NMSImpl method clearGoals.

public static void clearGoals(PathfinderGoalSelector... goalSelectors) {
    if (GOAL_FIELD == null || goalSelectors == null)
        return;
    for (PathfinderGoalSelector selector : goalSelectors) {
        try {
            Collection<?> list = (Collection<?>) GOAL_FIELD.get(selector);
            list.clear();
        } catch (Exception e) {
            Messaging.logTr(Messages.ERROR_CLEARING_GOALS, e.getLocalizedMessage());
        }
    }
}
Also used : Collection(java.util.Collection) PathfinderGoalSelector(net.minecraft.server.v1_11_R1.PathfinderGoalSelector) ReportedException(net.minecraft.server.v1_11_R1.ReportedException) CommandException(net.citizensnpcs.api.command.exception.CommandException)

Aggregations

Collection (java.util.Collection)10 CommandException (net.citizensnpcs.api.command.exception.CommandException)10 Field (java.lang.reflect.Field)3 PathfinderGoalSelector (net.minecraft.server.v1_8_R3.PathfinderGoalSelector)3 PathfinderGoalSelector (net.minecraft.server.v1_12_R1.PathfinderGoalSelector)2 PathPoint (net.minecraft.server.v1_15_R1.PathPoint)2 PathfinderGoalSelector (net.minecraft.server.v1_15_R1.PathfinderGoalSelector)2 ReportedException (net.minecraft.server.v1_15_R1.ReportedException)2 PathPoint (net.minecraft.server.v1_16_R3.PathPoint)2 PathfinderGoalSelector (net.minecraft.server.v1_16_R3.PathfinderGoalSelector)2 ReportedException (net.minecraft.server.v1_16_R3.ReportedException)2 ISoliniaClass (com.solinia.solinia.Interfaces.ISoliniaClass)1 Set (java.util.Set)1 PathfinderGoalSelector (net.minecraft.server.v1_10_R1.PathfinderGoalSelector)1 ReportedException (net.minecraft.server.v1_10_R1.ReportedException)1 PathfinderGoalSelector (net.minecraft.server.v1_11_R1.PathfinderGoalSelector)1 ReportedException (net.minecraft.server.v1_11_R1.ReportedException)1 EntityCreature (net.minecraft.server.v1_12_R1.EntityCreature)1 EntityRabbit (net.minecraft.server.v1_12_R1.EntityRabbit)1 EntityTameableAnimal (net.minecraft.server.v1_12_R1.EntityTameableAnimal)1