Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
Update to v1.9.1 (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmitch215 committed Jul 11, 2023
2 parents 1d4b365 + a793d4f commit a6f1077
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public PathfinderAvoidEntity(@NotNull Creature m, @NotNull Class<T> filter, floa
* @param walkMod Walking away modifier
* @throws IllegalArgumentException if filter is null
*/
public PathfinderAvoidEntity(@NotNull Creature m, @NotNull Class<T> filter, float dist, double sprintMod, double walkMod) throws IllegalArgumentException {
this(m, filter, dist, sprintMod, walkMod, null);
public PathfinderAvoidEntity(@NotNull Creature m, @NotNull Class<T> filter, float dist, double walkMod, double sprintMod) throws IllegalArgumentException {
this(m, filter, dist, walkMod, sprintMod, null);
}

/**
Expand All @@ -68,8 +68,8 @@ public PathfinderAvoidEntity(@NotNull Creature m, @NotNull Class<T> filter, floa
* @param avoidPredicate Predicate to check when determining the entity to avoid
* @throws IllegalArgumentException if filter is null
*/
public PathfinderAvoidEntity(@NotNull Creature m, @NotNull Class<T> filter, float dist, double sprintMod, double walkMod, @Nullable Predicate<T> avoidPredicate) throws IllegalArgumentException {
this(m, filter, dist, sprintMod, walkMod, avoidPredicate, null);
public PathfinderAvoidEntity(@NotNull Creature m, @NotNull Class<T> filter, float dist, double walkMod, double sprintMod, @Nullable Predicate<T> avoidPredicate) throws IllegalArgumentException {
this(m, filter, dist, walkMod, sprintMod, avoidPredicate, null);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.gamercoder215.mobchip.ai.goal;

import me.gamercoder215.mobchip.ai.SpeedModifier;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Creature;
import org.jetbrains.annotations.NotNull;
Expand All @@ -11,40 +12,92 @@
public final class PathfinderRemoveBlock extends Pathfinder implements SpeedModifier {

private double speedMod;
private Block toRemove;
private Material toRemove;
private int verticalSearchRange;

/**
* Constructs a PathfinderRemoveBlock
* Constructs a PathfinderRemoveBlock.
* @param c Creature to use
* @param remove Block to remove
* @throws IllegalArgumentException if block is null or differing worlds
*/
public PathfinderRemoveBlock(@NotNull Creature c, @NotNull Block remove) throws IllegalArgumentException {
public PathfinderRemoveBlock(@NotNull Creature c, @NotNull Block remove) {
this(c, remove, 1);
}
}

/**
* Constructs a PathfinderRemoveBlock with a vertical search range of 1.
* @param c Creature to use
* @param remove Block to remove
* @param speedMod Speed Modifier while moving
* @throws IllegalArgumentException if block data is null
*/
public PathfinderRemoveBlock(@NotNull Creature c, @NotNull Block remove, double speedMod) {
this(c, remove, speedMod, 1);
}

/**
* Constructs a PathfinderRemoveBlock.
* @param c Creature to use
* @param remove Block to remove
* @param speedMod Speed Modifier while moving
* @throws IllegalArgumentException if block is null or differing worlds
* @param verticalSearchRange Vertical search range
* @throws IllegalArgumentException if block is null, differing worlds, or range is not positive
*/
public PathfinderRemoveBlock(@NotNull Creature c, @NotNull Block remove, double speedMod) throws IllegalArgumentException {
public PathfinderRemoveBlock(@NotNull Creature c, @NotNull Block remove, double speedMod, int verticalSearchRange) {
super(c);
if (remove == null) throw new IllegalArgumentException("Block cannot be null");
if (!(remove.getWorld().getName().equals(c.getWorld().getName()))) throw new IllegalArgumentException("Differing worlds: Creature[" + c.getWorld().getName() + "] not matching Block[" + remove.getWorld().getName() + "]");
if (!(remove.getWorld().getUID().equals(c.getWorld().getUID()))) throw new IllegalArgumentException("Differing worlds: Creature[" + c.getWorld().getName() + "] not matching Block[" + remove.getWorld().getName() + "]");
if (verticalSearchRange < 1) throw new IllegalArgumentException("Vertical search range must be positive");

this.toRemove = remove.getType();
this.speedMod = speedMod;
}

/**
* Constructs a PathfinderRemoveBlock
* @param c Creature to use
* @param remove Material to remove
* @throws IllegalArgumentException if block is null or differing worlds
*/
public PathfinderRemoveBlock(@NotNull Creature c, @NotNull Material remove) throws IllegalArgumentException {
this(c, remove, 1);
}

/**
* Constructs a PathfinderRemoveBlock with a vertical search range of 1.
* @param c Creature to use
* @param remove Material to remove
* @param speedMod Speed Modifier while moving
* @throws IllegalArgumentException if material is null
*/
public PathfinderRemoveBlock(@NotNull Creature c, @NotNull Material remove, double speedMod) throws IllegalArgumentException {
this(c, remove, speedMod, 1);
}

/**
* Constructs a PathfinderRemoveBlock.
* @param c Creature to use
* @param remove Material to remove
* @param speedMod Speed Modifier while moving
* @param verticalSearchRange Vertical search range
* @throws IllegalArgumentException if material is null or range is not positive
*/
public PathfinderRemoveBlock(@NotNull Creature c, @NotNull Material remove, double speedMod, int verticalSearchRange) throws IllegalArgumentException {
super(c);
if (remove == null) throw new IllegalArgumentException("Material cannot be null");
if (verticalSearchRange < 1) throw new IllegalArgumentException("Vertical search range must be positive");

this.toRemove = remove;
this.speedMod = speedMod;
this.verticalSearchRange = verticalSearchRange;
}

/**
* Gets the Block to remove.
* @return Block to remove
* Gets the Material to remove.
* @return Material to remove
*/
@NotNull
public Block getBlock() {
public Material getBlock() {
return this.toRemove;
}

Expand All @@ -57,6 +110,17 @@ public void setBlock(@NotNull Block remove) throws IllegalArgumentException {
if (remove == null) throw new IllegalArgumentException("Block cannot be null");
if (!(remove.getWorld().getName().equals(entity.getWorld().getName()))) throw new IllegalArgumentException("Differing worlds: Creature[" + entity.getWorld().getName() + "] not matching Block[" + remove.getWorld().getName() + "]");

setBlock(remove.getType());
}

/**
* Sets the Material to remove.
* @param remove Material to remove
* @throws IllegalArgumentException if block data is null
* @since 1.9.1
*/
public void setBlock(@NotNull Material remove) throws IllegalArgumentException {
if (remove == null) throw new IllegalArgumentException("Block cannot be null");
this.toRemove = remove;
}

Expand All @@ -70,6 +134,24 @@ public void setSpeedModifier(double mod) {
this.speedMod = mod;
}

/**
* Gets the vertical search range for looking for the specified Material.
* @return Vertical search range
* @since 1.9.1
*/
public int getVerticalSearchRange() {
return verticalSearchRange;
}

/**
* Sets the vertical search range for looking for the specified Material.
* @param verticalSearchRange Vertical search range
* @since 1.9.1
*/
public void setVerticalSearchRange(int verticalSearchRange) {
this.verticalSearchRange = verticalSearchRange;
}

@Override
public @NotNull PathfinderFlag[] getFlags() {
return new PathfinderFlag[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,21 @@ public final class EntityMemory<T> implements Memory<T> {
*/
public static final EntityMemory<Integer> ITEM_PICKUP_COOLDOWN_TICKS = new EntityMemory<>(Integer.class, "item_pickup_cooldown_ticks");

/**
* Represents an array of explored positions this Sniffer has looked at.
*/
public static final EntityMemory<Location[]> SNIFFER_SNIFFING_TARGET = new EntityMemory<>(Location[].class, "sniffer_sniffing_target");

/**
* Represents whether the Sniffer is digging.
*/
public static final EntityMemory<Boolean> SNIFFER_DIGGING = new EntityMemory<>(Boolean.class, "sniffer_digging");

/**
* Represents whether the Sniffer is happy.
*/
public static final EntityMemory<Boolean> SNIFFER_HAPPY = new EntityMemory<>(Boolean.class, "sniffer_happy");

private final Class<T> bukkit;

private final String key;
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
}

val pGroup = "me.gamercoder215"
val pVersion = "1.9.0-SNAPSHOT"
val pVersion = "1.9.1-SNAPSHOT"
val pAuthor = "GamerCoder215"

val github = "$pAuthor/MobChip"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.bukkit.craftbukkit.v1_13_R1.block.CraftBlock;
import org.bukkit.craftbukkit.v1_13_R1.entity.*;
import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_13_R1.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.v1_13_R1.util.CraftNamespacedKey;
import org.bukkit.entity.Entity;
import org.bukkit.entity.*;
Expand Down Expand Up @@ -291,7 +292,7 @@ public static PathfinderGoal toNMS(Pathfinder b) {
}
case "RemoveBlock": {
PathfinderRemoveBlock p = (PathfinderRemoveBlock) b;
return new PathfinderGoalRemoveBlock(((CraftBlock) p.getBlock()).getNMS().getBlock(), (EntityCreature) m, p.getSpeedModifier(), Math.min((int) p.getBlock().getLocation().distance(mob.getLocation()), 1));
return new PathfinderGoalRemoveBlock(CraftMagicNumbers.getBlock(p.getBlock()), (EntityCreature) m, p.getSpeedModifier(), p.getVerticalSearchRange());
}
case "RestrictSun": return new PathfinderGoalRestrictSun((EntityCreature) m);
case "Sit": return new PathfinderGoalSit((EntityTameableAnimal) m);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.bukkit.craftbukkit.v1_13_R2.block.CraftBlock;
import org.bukkit.craftbukkit.v1_13_R2.entity.*;
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_13_R2.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.v1_13_R2.util.CraftNamespacedKey;
import org.bukkit.entity.Entity;
import org.bukkit.entity.*;
Expand Down Expand Up @@ -294,7 +295,7 @@ public static PathfinderGoal toNMS(Pathfinder b) {
}
case "RemoveBlock": {
PathfinderRemoveBlock p = (PathfinderRemoveBlock) b;
return new PathfinderGoalRemoveBlock(((CraftBlock) p.getBlock()).getNMS().getBlock(), (EntityCreature) m, p.getSpeedModifier(), Math.min((int) p.getBlock().getLocation().distance(mob.getLocation()), 1));
return new PathfinderGoalRemoveBlock(CraftMagicNumbers.getBlock(p.getBlock()), (EntityCreature) m, p.getSpeedModifier(), p.getVerticalSearchRange());
}
case "RestrictSun": return new PathfinderGoalRestrictSun((EntityCreature) m);
case "Sit": return new PathfinderGoalSit((EntityTameableAnimal) m);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import org.bukkit.*;
import org.bukkit.craftbukkit.v1_14_R1.CraftSound;
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_14_R1.block.CraftBlock;
import org.bukkit.craftbukkit.v1_14_R1.entity.*;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_14_R1.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.v1_14_R1.util.CraftNamespacedKey;
import org.bukkit.entity.Entity;
import org.bukkit.entity.*;
Expand Down Expand Up @@ -308,7 +308,7 @@ public static PathfinderGoal toNMS(Pathfinder b) {
}
case "RemoveBlock": {
PathfinderRemoveBlock p = (PathfinderRemoveBlock) b;
return new PathfinderGoalRemoveBlock(((CraftBlock) p.getBlock()).getNMS().getBlock(), (EntityCreature) m, p.getSpeedModifier(), Math.min((int) p.getBlock().getLocation().distance(mob.getLocation()), 1));
return new PathfinderGoalRemoveBlock(CraftMagicNumbers.getBlock(p.getBlock()), (EntityCreature) m, p.getSpeedModifier(), p.getVerticalSearchRange());
}
case "RestrictSun": return new PathfinderGoalRestrictSun((EntityCreature) m);
case "Sit": return new PathfinderGoalSit((EntityTameableAnimal) m);
Expand Down Expand Up @@ -688,6 +688,10 @@ else if (value instanceof DamageSource) {
value = fromNMS(c);
}
else if (value instanceof Unit) value = me.gamercoder215.mobchip.ai.memories.Unit.INSTANCE;
else if (value instanceof Optional<?>) {
Optional<?> o = (Optional<?>) value;
value = fromNMS(m, key, o.orElse(null));
}
else value = nmsValue;

return value;
Expand Down Expand Up @@ -1279,7 +1283,7 @@ private Pathfinder fromNMS(PathfinderGoal g) {
case "RandomStrollLand": return new PathfinderRandomStrollLand((Creature) m, getDouble(g, "e"), getFloat(g, "h"));
case "RandomSwim": return new PathfinderRandomSwim((Creature) m, getDouble(g, "e"), getInt(g, "f"));
case "RandomFly": return new PathfinderRandomStrollFlying((Creature) m, getDouble(g, "e"));
case "RemoveBlock": return new PathfinderRemoveBlock((Creature) m, m.getWorld().getBlockAt(fromNMS(getPosWithBlock(getObject(g, "g", Block.class), toNMS(m.getLocation()), toNMS(m.getWorld())), m.getWorld())), getDouble(g, "b"));
case "RemoveBlock": return new PathfinderRemoveBlock((Creature) m, CraftMagicNumbers.getMaterial(getObject(g, "g", Block.class)), getDouble(g, "b"), getInt(g, "i"));
case "RestrictSun": return new PathfinderRestrictSun((Creature) m);
case "Sit": return new PathfinderSit((Tameable) m);
case "StrollVillage": return new PathfinderRandomStrollToVillage((Creature) m, getDouble(g, "e"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock;
import org.bukkit.craftbukkit.v1_15_R1.entity.*;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_15_R1.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.v1_15_R1.util.CraftNamespacedKey;
import org.bukkit.entity.Entity;
import org.bukkit.entity.*;
Expand Down Expand Up @@ -298,7 +299,7 @@ public static PathfinderGoal toNMS(Pathfinder b) {
}
case "RemoveBlock": {
PathfinderRemoveBlock p = (PathfinderRemoveBlock) b;
return new PathfinderGoalRemoveBlock(((CraftBlock) p.getBlock()).getNMS().getBlock(), (EntityCreature) m, p.getSpeedModifier(), Math.min((int) p.getBlock().getLocation().distance(mob.getLocation()), 1));
return new PathfinderGoalRemoveBlock(CraftMagicNumbers.getBlock(p.getBlock()), (EntityCreature) m, p.getSpeedModifier(), p.getVerticalSearchRange());
}
case "RestrictSun": return new PathfinderGoalRestrictSun((EntityCreature) m);
case "Sit": return new PathfinderGoalSit((EntityTameableAnimal) m);
Expand Down Expand Up @@ -727,6 +728,10 @@ else if (value instanceof DamageSource) {
value = fromNMS(c);
}
else if (value instanceof Unit) value = me.gamercoder215.mobchip.ai.memories.Unit.INSTANCE;
else if (value instanceof Optional<?>) {
Optional<?> o = (Optional<?>) value;
value = fromNMS(m, key, o.orElse(null));
}
else value = nmsValue;

return value;
Expand Down Expand Up @@ -1279,7 +1284,7 @@ private Pathfinder fromNMS(PathfinderGoal g) {
case "RandomStrollLand": return new PathfinderRandomStrollLand((Creature) m, getDouble(g, "e"), getFloat(g, "h"));
case "RandomSwim": return new PathfinderRandomSwim((Creature) m, getDouble(g, "e"), getInt(g, "f"));
case "RandomFly": return new PathfinderRandomStrollFlying((Creature) m, getDouble(g, "e"));
case "RemoveBlock": return new PathfinderRemoveBlock((Creature) m, m.getWorld().getBlockAt(fromNMS(getPosWithBlock(getObject(g, "g", Block.class), toNMS(m.getLocation()), toNMS(m.getWorld())), m.getWorld())), getDouble(g, "b"));
case "RemoveBlock": return new PathfinderRemoveBlock((Creature) m, CraftMagicNumbers.getMaterial(getObject(g, "g", Block.class)), getDouble(g, "b"), getInt(g, "i"));
case "RestrictSun": return new PathfinderRestrictSun((Creature) m);
case "Sit": return new PathfinderSit((Tameable) m);
case "StrollVillage": return new PathfinderRandomStrollToVillage((Creature) m, getDouble(g, "e"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.bukkit.craftbukkit.v1_16_R1.block.CraftBlock;
import org.bukkit.craftbukkit.v1_16_R1.entity.*;
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_16_R1.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.v1_16_R1.util.CraftNamespacedKey;
import org.bukkit.entity.Entity;
import org.bukkit.entity.*;
Expand Down Expand Up @@ -337,7 +338,7 @@ public static PathfinderGoal toNMS(Pathfinder b) {
}
case "RemoveBlock": {
PathfinderRemoveBlock p = (PathfinderRemoveBlock) b;
return new PathfinderGoalRemoveBlock(((CraftBlock) p.getBlock()).getNMS().getBlock(), (EntityCreature) m, p.getSpeedModifier(), Math.min((int) p.getBlock().getLocation().distance(mob.getLocation()), 1));
return new PathfinderGoalRemoveBlock(CraftMagicNumbers.getBlock(p.getBlock()), (EntityCreature) m, p.getSpeedModifier(), p.getVerticalSearchRange());
}
case "RestrictSun": return new PathfinderGoalRestrictSun((EntityCreature) m);
case "Sit": return new PathfinderGoalSit((EntityTameableAnimal) m);
Expand Down Expand Up @@ -746,6 +747,10 @@ else if (value instanceof DamageSource) {
value = fromNMS(c);
}
else if (value instanceof Unit) value = me.gamercoder215.mobchip.ai.memories.Unit.INSTANCE;
else if (value instanceof Optional<?>) {
Optional<?> o = (Optional<?>) value;
value = fromNMS(m, key, o.orElse(null));
}
else value = nmsValue;

return value;
Expand Down Expand Up @@ -1306,7 +1311,7 @@ private Pathfinder fromNMS(PathfinderGoal g) {
case "RandomStrollLand": return new PathfinderRandomStrollLand((Creature) m, getDouble(g, "e"), getFloat(g, "h"));
case "RandomSwim": return new PathfinderRandomSwim((Creature) m, getDouble(g, "e"), getInt(g, "f"));
case "RandomFly": return new PathfinderRandomStrollFlying((Creature) m, getDouble(g, "e"));
case "RemoveBlock": return new PathfinderRemoveBlock((Creature) m, m.getWorld().getBlockAt(fromNMS(getPosWithBlock(getObject(g, "g", Block.class), toNMS(m.getLocation()), toNMS(m.getWorld())), m.getWorld())), getDouble(g, "b"));
case "RemoveBlock": return new PathfinderRemoveBlock((Creature) m, CraftMagicNumbers.getMaterial(getObject(g, "g", Block.class)), getDouble(g, "b"), getInt(g, "i"));
case "RestrictSun": return new PathfinderRestrictSun((Creature) m);
case "Sit": return new PathfinderSit((Tameable) m);
case "StrollVillage": return new PathfinderRandomStrollToVillage((Creature) m, getDouble(g, "e"));
Expand Down
Loading

0 comments on commit a6f1077

Please sign in to comment.