Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions .classpath

This file was deleted.

38 changes: 34 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
/media
/bin
/.externalToolBuilders
# Eclipse stuff
/.classpath
/.project
/.settings
/archive

# netbeans
/nbproject
/nbactions.xml
/nb-configuration.xml

# we use maven!
/build.xml

# maven
/target
/dependency-reduced-pom.xml
*/target
*/dependency-reduced-pom.xml

# vim
.*.sw[a-p]

# various other potential build files
/build
/bin
/dist
/manifest.mf

# Mac filesystem dust
/.DS_Store

# intellij
*.iml
*.ipr
*.iws
.idea/
84 changes: 0 additions & 84 deletions .project

This file was deleted.

9 changes: 0 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,4 @@

</plugins>
</build>

<distributionManagement>
<repository>
<id>internal.repo</id>
<name>Temporary Staging Repository</name>
<url>file://${project.build.directory}/mvn-repo</url>
</repository>
</distributionManagement>

</project>
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package de.ntcomputer.minecraft.controllablemobs.api.ai.behaviors;

import de.ntcomputer.minecraft.controllablemobs.api.ai.AIType;
import de.ntcomputer.minecraft.controllablemobs.implementation.CraftControllableMob;
import net.minecraft.server.v1_7_R1.PathfinderGoal;
import net.minecraft.server.v1_7_R1.PathfinderGoalFloat;

import org.bukkit.entity.LivingEntity;

import de.ntcomputer.minecraft.controllablemobs.api.ai.AIType;
import de.ntcomputer.minecraft.controllablemobs.implementation.CraftControllableMob;

/**
* Very important AIBehavior that lets the entity swim.
* Must be added if the entity should not drown when it gets into the water.
Expand All @@ -34,14 +32,13 @@ public AISwim(final int priority) {
super(priority);
}

@Override
public PathfinderGoal createPathfinderGoal(CraftControllableMob<?> mob) {
return new PathfinderGoalFloat(mob.nmsEntity);
}

@Override
public AIType getType() {
return AIType.MOVE_SWIM;
}

@Override
public PathfinderGoal createPathfinderGoal(CraftControllableMob<? extends LivingEntity> mob) {
return new PathfinderGoalFloat(mob.nmsEntity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public AITargetNearest(int priority, double maximumDistance, boolean ignoreInvul
}

@Override
public PathfinderGoal createPathfinderGoal(CraftControllableMob<?> mob) {
public PathfinderGoal createPathfinderGoal(CraftControllableMob<? extends LivingEntity> mob) {
return new PathfinderGoalTargetNearest(mob, this.maximumNoEyeContactTicks, this.ignoreInvulnerability, this.maximumDistance, this.targetClasses, this.entitySelector);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package de.ntcomputer.minecraft.controllablemobs.implementation;

import java.util.ArrayList;

import org.bukkit.entity.LivingEntity;

import de.ntcomputer.minecraft.controllablemobs.api.ControllableMobAI;
import de.ntcomputer.minecraft.controllablemobs.api.ai.AIPart;
import de.ntcomputer.minecraft.controllablemobs.api.ai.AIType;
import de.ntcomputer.minecraft.controllablemobs.api.ai.behaviors.AIBehavior;
import de.ntcomputer.minecraft.controllablemobs.implementation.ai.AIDispatcher;
import org.bukkit.entity.LivingEntity;

import java.util.ArrayList;

public class CraftControllableMobAI<E extends LivingEntity> implements ControllableMobAI<E> {
private AIDispatcher<E> dispatcher;
Expand Down Expand Up @@ -67,7 +66,7 @@ public void reset() {
public AIPart<E,?>[] getParts() {
ArrayList<AIPart<E,?>> parts = new ArrayList<AIPart<E,?>>();
this.dispatcher.get(parts,null);
return parts.toArray(new AIPart[0]);
return parts.toArray(new AIPart[parts.size()]);
}

@Override
Expand All @@ -80,7 +79,7 @@ public boolean hasBehavior(AIType type) {
public AIPart<E, ?>[] getPartsOf(AIType... types) {
ArrayList<AIPart<E,?>> parts = new ArrayList<AIPart<E,?>>();
this.dispatcher.get(parts,types);
return parts.toArray(new AIPart[0]);
return parts.toArray(new AIPart[parts.size()]);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
package de.ntcomputer.minecraft.controllablemobs.implementation.ai;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import net.minecraft.server.v1_7_R1.EntityInsentient;
import net.minecraft.server.v1_7_R1.PathfinderGoal;
import net.minecraft.server.v1_7_R1.PathfinderGoalSelector;

import org.bukkit.craftbukkit.v1_7_R1.util.UnsafeList;
import org.bukkit.entity.LivingEntity;

import de.ntcomputer.minecraft.controllablemobs.api.ai.AIState;
import de.ntcomputer.minecraft.controllablemobs.api.ai.AIType;
import de.ntcomputer.minecraft.controllablemobs.api.ai.behaviors.AIBehavior;
Expand All @@ -26,9 +8,16 @@
import de.ntcomputer.minecraft.controllablemobs.implementation.ai.behaviors.PathfinderGoalWrapper;
import de.ntcomputer.minecraft.controllablemobs.implementation.nativeinterfaces.NativeInterfaces;
import de.ntcomputer.minecraft.controllablemobs.implementation.nativeinterfaces.primitives.NativeFieldObject;
import net.minecraft.server.v1_7_R1.EntityInsentient;
import net.minecraft.server.v1_7_R1.PathfinderGoal;
import net.minecraft.server.v1_7_R1.PathfinderGoalSelector;
import org.bukkit.craftbukkit.v1_7_R1.util.UnsafeList;
import org.bukkit.entity.LivingEntity;

import java.util.*;

public abstract class AIController<E extends LivingEntity> implements Comparator<Object> {
private List<PathfinderGoalWrapper> actionGoals;
private List<PathfinderGoal> actionGoals;
private List<CraftAIPart<E,?>> attachedParts;
private List<CraftAIPart<E,?>> defaultParts;
private PathfinderGoalAIMonitor monitor;
Expand Down Expand Up @@ -62,7 +51,7 @@ public AIController(CraftControllableMob<E> mob, NativeFieldObject<EntityInsenti
}

// create action goals and monitor and sort with default goals
this.actionGoals = new ArrayList<PathfinderGoalWrapper>();
this.actionGoals = new ArrayList<PathfinderGoal>();
this.createActionGoals();
this.monitor = new PathfinderGoalAIMonitor(this,activeDefaultGoals);
this.addActionGoal(0, monitor);
Expand Down Expand Up @@ -99,7 +88,7 @@ private void removeGoal(PathfinderGoal goal) {
break;
}
}
((UnsafeList<Object>.Itr) iterator).valid = false;
((UnsafeList.Itr) iterator).valid = false;

// remove item
iterator = NativeInterfaces.PATHFINDERGOALSELECTOR.FIELD_GOALITEMS.get(this.selector).iterator();
Expand All @@ -110,7 +99,7 @@ private void removeGoal(PathfinderGoal goal) {
break;
}
}
((UnsafeList<Object>.Itr) iterator).valid = false;
((UnsafeList.Itr) iterator).valid = false;
}

private void clearGoals() {
Expand All @@ -125,15 +114,15 @@ private void clearGoals() {
iterator.remove();
}
}
((UnsafeList<Object>.Itr) iterator).valid = false;
((UnsafeList.Itr) iterator).valid = false;

// remove all non-action items
iterator = NativeInterfaces.PATHFINDERGOALSELECTOR.FIELD_GOALITEMS.get(this.selector).iterator();
while(iterator.hasNext()) {
searchGoal = NativeInterfaces.PATHFINDERGOALSELECTORITEM.FIELD_GOAL.get(iterator.next());
if(!this.actionGoals.contains(searchGoal) ) iterator.remove();
}
((UnsafeList<Object>.Itr) iterator).valid = false;
((UnsafeList.Itr) iterator).valid = false;
}

private void sortGoals() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package de.ntcomputer.minecraft.controllablemobs.implementation.ai;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.bukkit.entity.LivingEntity;

import de.ntcomputer.minecraft.controllablemobs.api.ai.AIPart;
import de.ntcomputer.minecraft.controllablemobs.api.ai.AIType;
import de.ntcomputer.minecraft.controllablemobs.api.ai.behaviors.AIBehavior;
import de.ntcomputer.minecraft.controllablemobs.api.ai.behaviors.AITargetBehavior;
import de.ntcomputer.minecraft.controllablemobs.implementation.CraftControllableMob;
import org.bukkit.entity.LivingEntity;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class AIDispatcher<E extends LivingEntity> {
private AIController<E> goalController;
Expand All @@ -35,10 +34,8 @@ public void remove(AIType[] types, boolean remove) {
}

public boolean contains(AIType type) {
if(this.goalController.contains(type)) return true;
if(this.targetController.contains(type)) return true;
return false;
}
return this.goalController.contains(type) || this.targetController.contains(type);
}

public boolean contains(AIType... types) {
for(AIType type: types) {
Expand Down
Loading