This commit is contained in:
Mini-Chiss 2015-08-29 13:13:04 -07:00
parent 5d28509474
commit d2bc4b8cb4
4 changed files with 50 additions and 43 deletions

View File

@ -23,7 +23,7 @@ public class SnakeBoss extends WorldEvent
protected void customStart()
{
Bukkit.broadcastMessage("Custom Start");
spawnGolem(getCenterLocation());
spawn(getCenterLocation());
setState(EventState.LIVE);
announceStart();
}
@ -51,7 +51,7 @@ public class SnakeBoss extends WorldEvent
}
}
private SnakeCreature spawnGolem(Location location)
private SnakeCreature spawn(Location location)
{
SnakeCreature slimeCreature = new SnakeCreature(this, location);
registerCreature(slimeCreature);

View File

@ -15,6 +15,7 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
@ -27,10 +28,11 @@ import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy;
public class SnakeCreature extends EventCreature<Silverfish>
{
private ArrayList<SnakeTail> _snakeTail = new ArrayList<SnakeTail>();
private HashMap<SnakeTail, Vector> _direction = new HashMap<SnakeTail, Vector>();
private ArrayList<SnakeSegment> _segments = new ArrayList<SnakeSegment>();
private double _seperator = 0.5;
private ArrayList<Player> _canSee = new ArrayList<Player>();
private Location _waypoint;
public SnakeCreature(WorldEvent event, Location spawnLocation)
{
@ -44,16 +46,22 @@ public class SnakeCreature extends EventCreature<Silverfish>
UtilEnt.Vegetate(getEntity());
Vector dir = new Vector(UtilMath.rr(1, true), 0, UtilMath.rr(1, true)).normalize().multiply(_seperator);
getNewWaypoint();
for (int i = 0; i < getHealth() / 50; i++)
{
SnakeTail tail = new SnakeTail(getSpawnLocation().toVector().subtract(dir.clone().multiply(-i)),
SnakeSegment tail = new SnakeSegment(getSpawnLocation().toVector().subtract(dir.clone().multiply(-i)),
new ItemStack(i == 0 ? Material.COBBLESTONE : Material.STONE));
_direction.put(tail, dir);
_snakeTail.add(tail);
_segments.add(tail);
}
}
private void getNewWaypoint()
{
_waypoint = getSpawnLocation().clone().add(Math.random() * 40 - 20, Math.random() * 24 - 8, Math.random() * 40 - 20);
}
@EventHandler
public void onSecond(UpdateEvent event)
{
@ -62,7 +70,7 @@ public class SnakeCreature extends EventCreature<Silverfish>
return;
}
Location loc = _snakeTail.get(0).getLocation().toLocation(getSpawnLocation().getWorld());
Location loc = _segments.get(0).getLocation().toLocation(getSpawnLocation().getWorld());
ArrayList<Player> canSee = new ArrayList<Player>();
@ -74,23 +82,23 @@ public class SnakeCreature extends EventCreature<Silverfish>
}
}
Iterator<Player> itel2 = _canSee.iterator();
Iterator<Player> iter2 = _canSee.iterator();
int[] ids = new int[_snakeTail.size()];
int[] ids = new int[_segments.size()];
for (int a = 0; a < _snakeTail.size(); a++)
for (int a = 0; a < _segments.size(); a++)
{
ids[a] = _snakeTail.get(a).getId();
ids[a] = _segments.get(a).getId();
}
Packet destroy = new PacketPlayOutEntityDestroy(ids);
while (itel2.hasNext())
while (iter2.hasNext())
{
Player player = itel2.next();
Player player = iter2.next();
if (!canSee.contains(player))
{
itel2.remove();
iter2.remove();
UtilPlayer.sendPacket(player, destroy);
}
}
@ -100,7 +108,7 @@ public class SnakeCreature extends EventCreature<Silverfish>
{
_canSee.add(player);
for (SnakeTail tail : _snakeTail)
for (SnakeSegment tail : _segments)
{
UtilPlayer.sendPacket(player, tail.getSpawn());
}
@ -111,11 +119,11 @@ public class SnakeCreature extends EventCreature<Silverfish>
@Override
public void dieCustom()
{
int[] ids = new int[_snakeTail.size()];
int[] ids = new int[_segments.size()];
for (int a = 0; a < _snakeTail.size(); a++)
for (int a = 0; a < _segments.size(); a++)
{
ids[a] = _snakeTail.get(a).getId();
ids[a] = _segments.get(a).getId();
}
Packet destroy = new PacketPlayOutEntityDestroy(ids);
@ -127,34 +135,39 @@ public class SnakeCreature extends EventCreature<Silverfish>
}
@EventHandler
public void onTick(UpdateEvent event)
public void onTickMove(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
Packet[] packets = new Packet[_snakeTail.size()];
Packet[] packets = new Packet[_segments.size()];
for (int i = 0; i < _snakeTail.size(); i++)
for (int i = _segments.size()-1; i>=0; i++)
{
SnakeTail tail = _snakeTail.get(i);
Vector vec = _direction.get(tail);
SnakeSegment seg = _segments.get(i);
Vector vec = seg.getLocation();
if (i == 0)
{
vec.add(new Vector(0.01, 0, 0));
// TODO
vec.add(UtilAlg.getTrajectory(vec, _waypoint.toVector()).multiply(0.01));
if (UtilMath.offset(vec, _waypoint.toVector()) < 5)
{
getNewWaypoint();
}
}
else
{
vec.add(_direction.get(_snakeTail.get(i - 1)).multiply(0.9));
vec = _segments.get(i-1).getLocation();
}
vec.normalize().multiply(0.6);
packets[i] = tail.moveEntity(vec);
packets[i] = seg.moveEntity(vec);
}
for (Player player : _canSee)

View File

@ -13,14 +13,13 @@ import net.minecraft.server.v1_7_R4.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_7_R4.PacketPlayOutRelEntityMoveLook;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
public class SnakeTail
public class SnakeSegment
{
private int _entityId = UtilEnt.getNewEntityId();
private Vector _entityLocation;
private ItemStack _item;
private Vector _previous;
public SnakeTail(Vector location, ItemStack item)
public SnakeSegment(Vector location, ItemStack item)
{
_entityLocation = location.clone();
_item = item;
@ -31,11 +30,6 @@ public class SnakeTail
return _entityId;
}
public Vector getPrevious()
{
return _previous;
}
public Packet moveEntity(Vector newLocation)
{
Vector toMove = newLocation.clone().subtract(_entityLocation);

View File

@ -25,7 +25,7 @@ import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.boss.snake.SnakeTail;
import mineplex.minecraft.game.core.boss.snake.SnakeSegment;
import nautilus.game.arcade.game.games.bossbattles.BattleBoss;
import nautilus.game.arcade.game.games.bossbattles.BossBattles;
import net.minecraft.server.v1_7_R4.Packet;
@ -33,7 +33,7 @@ import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy;
public class SnakeDisplay extends BossDisplay
{
private ArrayList<SnakeTail> _snakeTail = new ArrayList<SnakeTail>();
private ArrayList<SnakeSegment> _snakeTail = new ArrayList<SnakeSegment>();
private double _seperator = 0.5;
private ArrayList<Player> _canSee = new ArrayList<Player>();
private Entity _entity;
@ -82,7 +82,7 @@ public class SnakeDisplay extends BossDisplay
Vector loc = getLocation().toVector()
.subtract(dir.clone().multiply(-i));
SnakeTail tail = new SnakeTail(loc, new ItemStack(
SnakeSegment tail = new SnakeSegment(loc, new ItemStack(
i == 0 ? Material.COBBLESTONE : Material.STONE));
_snakeTail.add(tail);
}
@ -146,7 +146,7 @@ public class SnakeDisplay extends BossDisplay
{
_canSee.add(player);
for (SnakeTail tail : _snakeTail)
for (SnakeSegment tail : _snakeTail)
{
UtilPlayer.sendPacket(player, tail.getSpawn());
}
@ -197,7 +197,7 @@ public class SnakeDisplay extends BossDisplay
for (int i = 0; i < _snakeTail.size(); i++)
{
SnakeTail tail = _snakeTail.get(i);
SnakeSegment tail = _snakeTail.get(i);
Vector vector = new Vector();
if (i == 0)
@ -218,7 +218,7 @@ public class SnakeDisplay extends BossDisplay
}
else
{
SnakeTail t = _snakeTail.get(i - 1);
SnakeSegment t = _snakeTail.get(i - 1);
vector = t.getPrevious().clone().subtract(tail.getLocation());
}