mount stuff is fixed

This commit is contained in:
Cheese 2015-12-09 08:19:55 +11:00
parent 2decc049c5
commit fba88ec231
2 changed files with 51 additions and 49 deletions

View File

@ -75,7 +75,7 @@ public class MountCart extends Mount<SingleEntityMountData<Minecart>>
if (event.getRightClicked() == null)
return;
SingleEntityMountData<Minecart> mount = GetActive().get(event.getPlayer());
SingleEntityMountData<Minecart> mount = getMountData(event.getRightClicked());
if(mount == null) return;

View File

@ -30,11 +30,11 @@ public class MountSlime extends Mount<SingleEntityMountData<Slime>>
{
super(manager, "Slime Mount", Material.SLIME_BALL, (byte)0, new String[]
{
ChatColor.RESET + "Bounce around on your very",
ChatColor.RESET + "own personal slime friend!",
ChatColor.RESET + "Bounce around on your very",
ChatColor.RESET + "own personal slime friend!",
},
15000);
KnownPackage = false;
}
@ -42,153 +42,155 @@ public class MountSlime extends Mount<SingleEntityMountData<Slime>>
{
player.leaveVehicle();
player.eject();
//Remove other mounts
Manager.DeregisterAll(player);
SingleEntityMountData<Slime> mount = new SingleEntityMountData<Slime>(player, player.getWorld().spawn(player.getLocation(), Slime.class));
mount.getEntity().setSize(2);
mount.getEntity().setCustomName(player.getName() + "'s " + GetName());
//Inform
UtilPlayer.message(player, F.main("Mount", "You spawned " + F.elem(GetName()) + "."));
//Store
_active.put(player, mount);
}
public void Disable(Player player)
{
SingleEntityMountData<Slime> mount = _active.remove(player);
if (mount != null)
{
mount.remove();
//Inform
UtilPlayer.message(player, F.main("Mount", "You despawned " + F.elem(GetName()) + "."));
Manager.removeActive(player);
}
}
@EventHandler
public void interactMount(PlayerInteractEntityEvent event)
{
if (event.getRightClicked() == null)
return;
if (!GetActive().containsKey(event.getPlayer()))
return;
if(!GetActive().get(event.getPlayer()).ownsMount(event.getPlayer()))
return;
SingleEntityMountData<Slime> data = GetActive().get(event.getPlayer());
if(data == null) return;
if(!data.ownsMount(event.getPlayer())) return;
if(!data.isPartOfMount(event.getRightClicked())) return;
event.getPlayer().leaveVehicle();
event.getPlayer().eject();
event.getRightClicked().setPassenger(event.getPlayer());
}
@EventHandler
public void target(EntityTargetEvent event)
{
if (!GetActive().containsKey(event.getTarget()))
return;
if (!GetActive().get(event.getTarget()).equals(event.getEntity()))
event.setCancelled(true);
}
@EventHandler
public void updateBounce(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
//Bounce
for (SingleEntityMountData<Slime> slimeData : GetActive().values())
{
Slime slime = slimeData.getEntity();
if (slime.getPassenger() == null)
{
UtilEnt.setFakeHead(slime, false);
continue;
}
if (!UtilEnt.isGrounded(slime))
continue;
if (!(slime.getPassenger() instanceof Player))
continue;
Player player = (Player)slime.getPassenger();
if (!Recharge.Instance.use(player, GetName(), 200, false, false))
continue;
Vector dir = slime.getPassenger().getLocation().getDirection();
UtilAction.velocity(slime, dir, 1, true, 0, 0.4, 1, true);
UtilEnt.CreatureForceLook(slime, 0, UtilAlg.GetYaw(dir));
slime.getWorld().playSound(slime.getLocation(), Sound.SLIME_WALK, 1f, 0.75f);
}
//Collide
for (SingleEntityMountData<Slime> slimeData : GetActive().values())
{
Slime slime = slimeData.getEntity();
if (slime.getPassenger() == null)
continue;
if (!(slime.getPassenger() instanceof Player))
continue;
Player player = (Player)slime.getPassenger();
if (!Recharge.Instance.usable(player, GetName() + " Collide"))
continue;
for (SingleEntityMountData<Slime> otherSlime : GetActive().values())
{
Slime other = otherSlime.getEntity();
if (other.equals(slime))
continue;
if (other.getPassenger() == null)
continue;
if (!(other.getPassenger() instanceof Player))
continue;
Player otherPlayer = (Player)other.getPassenger();
if (!Recharge.Instance.usable(otherPlayer, GetName() + " Collide"))
continue;
//Collide
if (UtilMath.offset(slime, other) > 2)
continue;
Recharge.Instance.useForce(player, GetName() + " Collide", 500);
Recharge.Instance.useForce(otherPlayer, GetName() + " Collide", 500);
UtilAction.velocity(slime, UtilAlg.getTrajectory(other, slime), 1.2, false, 0, 0.8, 10, true);
UtilAction.velocity(other, UtilAlg.getTrajectory(slime, other), 1.2, false, 0, 0.8, 10, true);
slime.getWorld().playSound(slime.getLocation(), Sound.SLIME_ATTACK, 1f, 0.5f);
slime.getWorld().playSound(slime.getLocation(), Sound.SLIME_WALK, 1f, 0.5f);
other.getWorld().playSound(other.getLocation(), Sound.SLIME_WALK, 1f, 0.5f);
slime.playEffect(EntityEffect.HURT);
other.playEffect(EntityEffect.HURT);
}
}
}
}