What snake mount code I did
This commit is contained in:
parent
3c98243201
commit
5f8f643d95
@ -639,6 +639,11 @@ public class UtilEnt
|
|||||||
return CreatureLook(ent, UtilAlg.GetPitch(vec), UtilAlg.GetYaw(vec));
|
return CreatureLook(ent, UtilAlg.GetPitch(vec), UtilAlg.GetYaw(vec));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean CreatureLook(Entity ent, Vector target)
|
||||||
|
{
|
||||||
|
return CreatureLook(ent, UtilAlg.GetPitch(target), UtilAlg.GetYaw(target));
|
||||||
|
}
|
||||||
|
|
||||||
public static void setFakeHead(Entity ent, boolean fakeHead)
|
public static void setFakeHead(Entity ent, boolean fakeHead)
|
||||||
{
|
{
|
||||||
net.minecraft.server.v1_8_R3.Entity ec = ((CraftEntity) ent).getHandle();
|
net.minecraft.server.v1_8_R3.Entity ec = ((CraftEntity) ent).getHandle();
|
||||||
|
@ -28,59 +28,59 @@ public class MountTitan extends Mount<MountTitanData>
|
|||||||
{
|
{
|
||||||
public MountTitan(MountManager manager)
|
public MountTitan(MountManager manager)
|
||||||
{
|
{
|
||||||
super(manager, "Molten Snake", Material.REDSTONE_BLOCK, (byte)0, new String[]
|
super(manager, "Molten Snake", Material.REDSTONE_BLOCK, (byte) 0, new String[]
|
||||||
{
|
{
|
||||||
C.cWhite + "From the distant ether realm,",
|
C.cWhite + "From the distant ether realm,",
|
||||||
C.cWhite + "this prized dragon is said to",
|
C.cWhite + "this prized dragon is said to",
|
||||||
C.cWhite + "obey only true Heroes!",
|
C.cWhite + "obey only true Heroes!",
|
||||||
" ",
|
" ",
|
||||||
C.cRed + "Unlocked with Titan Rank",
|
C.cRed + "Unlocked with Titan Rank",
|
||||||
}, -1);
|
}, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void EnableCustom(Player player)
|
public void EnableCustom(Player player)
|
||||||
{
|
{
|
||||||
player.leaveVehicle();
|
player.leaveVehicle();
|
||||||
player.eject();
|
player.eject();
|
||||||
|
|
||||||
//Remove other mounts
|
// Remove other mounts
|
||||||
Manager.DeregisterAll(player);
|
Manager.DeregisterAll(player);
|
||||||
|
|
||||||
//Inform
|
// Inform
|
||||||
UtilPlayer.message(player, F.main("Mount", "You spawned " + F.elem(GetName()) + "."));
|
UtilPlayer.message(player, F.main("Mount", "You spawned " + F.elem(GetName()) + "."));
|
||||||
|
|
||||||
//Store
|
// Store
|
||||||
_active.put(player, new MountTitanData(player, GetName()));
|
_active.put(player, new MountTitanData(Manager.getDisguiseManager(), player, GetName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void Disable(Player player)
|
public void Disable(Player player)
|
||||||
{
|
{
|
||||||
MountTitanData data = _active.remove(player);
|
MountTitanData data = _active.remove(player);
|
||||||
if (data != null)
|
if (data != null)
|
||||||
{
|
{
|
||||||
data.clean();
|
data.clean();
|
||||||
|
|
||||||
//Inform
|
// Inform
|
||||||
UtilPlayer.message(player, F.main("Mount", "You despawned " + F.elem(GetName()) + "."));
|
UtilPlayer.message(player, F.main("Mount", "You despawned " + F.elem(GetName()) + "."));
|
||||||
|
|
||||||
Manager.removeActive(player);
|
Manager.removeActive(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void update(UpdateEvent event)
|
public void update(UpdateEvent event)
|
||||||
{
|
{
|
||||||
if (event.getType() != UpdateType.TICK)
|
if (event.getType() != UpdateType.TICK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (MountTitanData data : _active.values())
|
for (MountTitanData data : _active.values())
|
||||||
{
|
{
|
||||||
data.update();
|
data.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void interactMount(PlayerInteractEntityEvent event)
|
public void interactMount(PlayerInteractEntityEvent event)
|
||||||
{
|
{
|
||||||
@ -89,7 +89,7 @@ public class MountTitan extends Mount<MountTitanData>
|
|||||||
|
|
||||||
if (!GetActive().containsKey(event.getPlayer()))
|
if (!GetActive().containsKey(event.getPlayer()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!GetActive().get(event.getPlayer()).ownsMount(event.getPlayer()))
|
if (!GetActive().get(event.getPlayer()).ownsMount(event.getPlayer()))
|
||||||
{
|
{
|
||||||
UtilPlayer.message(event.getPlayer(), F.main("Mount", "This is not your Mount!"));
|
UtilPlayer.message(event.getPlayer(), F.main("Mount", "This is not your Mount!"));
|
||||||
@ -98,29 +98,29 @@ public class MountTitan extends Mount<MountTitanData>
|
|||||||
|
|
||||||
event.getPlayer().leaveVehicle();
|
event.getPlayer().leaveVehicle();
|
||||||
event.getPlayer().eject();
|
event.getPlayer().eject();
|
||||||
|
|
||||||
GetActive().get(event.getPlayer()).mount(event.getPlayer(), event.getRightClicked());
|
GetActive().get(event.getPlayer()).mount(event.getPlayer(), event.getRightClicked());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void target(EntityTargetEvent event)
|
public void target(EntityTargetEvent event)
|
||||||
{
|
{
|
||||||
if (!(event.getEntity() instanceof Player))
|
if (!(event.getEntity() instanceof Player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!GetActive().containsKey(event.getTarget()))
|
if (!GetActive().containsKey(event.getTarget()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!GetActive().get(event.getTarget()).ownsMount((Player)event.getEntity()))
|
if (!GetActive().get(event.getTarget()).ownsMount((Player) event.getEntity()))
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void titanOwner(PlayerJoinEvent event)
|
public void titanOwner(PlayerJoinEvent event)
|
||||||
{
|
{
|
||||||
if (Manager.getClientManager().Get(event.getPlayer()).GetRank().has(Rank.TITAN))
|
if (Manager.getClientManager().Get(event.getPlayer()).GetRank().has(Rank.TITAN))
|
||||||
{
|
{
|
||||||
Manager.getDonationManager().Get(event.getPlayer().getName()).AddUnknownSalesPackagesOwned(GetName());
|
Manager.getDonationManager().Get(event.getPlayer().getName()).AddUnknownSalesPackagesOwned(GetName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,40 +1,49 @@
|
|||||||
|
|
||||||
|
|
||||||
package mineplex.core.mount.types;
|
package mineplex.core.mount.types;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import mineplex.core.common.util.UtilAlg;
|
import mineplex.core.common.util.UtilAlg;
|
||||||
|
import mineplex.core.common.util.UtilEnt;
|
||||||
import mineplex.core.common.util.UtilMath;
|
import mineplex.core.common.util.UtilMath;
|
||||||
|
import mineplex.core.disguise.DisguiseManager;
|
||||||
|
import mineplex.core.disguise.disguises.DisguiseGuardian;
|
||||||
|
import mineplex.core.disguise.disguises.DisguiseMagmaCube;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity;
|
||||||
import org.bukkit.entity.ArmorStand;
|
import org.bukkit.entity.ArmorStand;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.MagmaCube;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Slime;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.util.EulerAngle;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public class MountTitanData
|
public class MountTitanData
|
||||||
{
|
{
|
||||||
private String _owner;
|
private String _owner;
|
||||||
|
|
||||||
private Slime _head;
|
private LivingEntity _head;
|
||||||
|
|
||||||
private ArrayList<ArmorStand> _nodes;
|
private ArrayList<ArmorStand> _nodes;
|
||||||
|
|
||||||
public MountTitanData(Player player, String name)
|
public MountTitanData(DisguiseManager disguiseManager, Player player, String name)
|
||||||
{
|
{
|
||||||
_owner = player.getName();
|
_owner = player.getName();
|
||||||
|
|
||||||
//Nodes
|
// Nodes
|
||||||
_nodes = new ArrayList<ArmorStand>();
|
_nodes = new ArrayList<ArmorStand>();
|
||||||
|
|
||||||
for (int i=0 ; i<30 ; i++)
|
Location loc = player.getLocation();
|
||||||
|
loc.setYaw(0);
|
||||||
|
loc.setPitch(0);
|
||||||
|
|
||||||
|
for (int i = 0; i < 30; i++)
|
||||||
{
|
{
|
||||||
ArmorStand node = player.getWorld().spawn(player.getLocation(), ArmorStand.class);
|
ArmorStand node = player.getWorld().spawn(loc, ArmorStand.class);
|
||||||
|
|
||||||
node.setVisible(false);
|
node.setVisible(false);
|
||||||
node.setGravity(false);
|
node.setGravity(false);
|
||||||
@ -43,12 +52,21 @@ public class MountTitanData
|
|||||||
|
|
||||||
_nodes.add(node);
|
_nodes.add(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Head
|
// Head
|
||||||
_head = player.getWorld().spawn(player.getLocation(), MagmaCube.class);
|
_head = (LivingEntity) player.getWorld().spawnEntity(loc, EntityType.BAT);
|
||||||
_head.setSize(2);
|
UtilEnt.Vegetate(_head, true);
|
||||||
|
UtilEnt.silence(_head, true);
|
||||||
|
UtilEnt.setFakeHead(_head, true);
|
||||||
|
|
||||||
_head.setCustomName(player.getName() + "'s " + name);
|
_head.setCustomName(player.getName() + "'s " + name);
|
||||||
|
|
||||||
|
((CraftLivingEntity) _head).getHandle().setMineplexInvisible(true);
|
||||||
|
|
||||||
|
DisguiseMagmaCube disguise = new DisguiseMagmaCube(_head);
|
||||||
|
disguise.SetSize(2);
|
||||||
|
|
||||||
|
disguiseManager.disguise(disguise);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mount(Player player, Entity entity)
|
public void mount(Player player, Entity entity)
|
||||||
@ -59,58 +77,102 @@ public class MountTitanData
|
|||||||
|
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
//Head
|
// Head
|
||||||
if (_head.getPassenger() != null)
|
if (_head.getPassenger() != null)
|
||||||
_head.setVelocity(_head.getPassenger().getLocation().getDirection().add(new Vector(0,0.2,0)));
|
{
|
||||||
|
_head.setVelocity(_head.getPassenger().getLocation().getDirection().add(new Vector(0, 0.2, 0)));
|
||||||
|
|
||||||
Location infront = _head.getLocation().add(0, -1.5, 0);
|
UtilEnt.CreatureLook(_head, _head.getPassenger().getLocation().getDirection());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Player player = Bukkit.getPlayerExact(_owner);
|
||||||
|
|
||||||
//Move
|
if (player != null)
|
||||||
for (int i=0 ; i<30 ; i++)
|
{
|
||||||
|
Vector moving = null;
|
||||||
|
|
||||||
|
if (UtilMath.offset(player, _head) > 12)
|
||||||
|
{
|
||||||
|
moving = _head.getLocation().getDirection().normalize();
|
||||||
|
|
||||||
|
Vector vec = moving.clone().subtract(UtilAlg.getTrajectory(player, _head)).normalize();
|
||||||
|
|
||||||
|
vec.setY(-vec.getY());
|
||||||
|
|
||||||
|
moving.add(vec.multiply(0.15));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
moving = _head.getLocation().getDirection();
|
||||||
|
|
||||||
|
moving.setX(moving.getX() + UtilMath.rr(0.1, true));
|
||||||
|
moving.setY(moving.getY() + UtilMath.rr(0.3, true));
|
||||||
|
moving.setZ(moving.getZ() + UtilMath.rr(0.1, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
moving.normalize().multiply(0.5);
|
||||||
|
|
||||||
|
UtilEnt.CreatureLook(_head, moving);
|
||||||
|
|
||||||
|
_head.setVelocity(moving);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Location infront = _head.getLocation().add(0, -1.3, 0);
|
||||||
|
infront.setYaw(0);
|
||||||
|
infront.setPitch(0);
|
||||||
|
|
||||||
|
// Move
|
||||||
|
for (int i = 0; i < 30; i++)
|
||||||
{
|
{
|
||||||
ArmorStand node = _nodes.get(i);
|
ArmorStand node = _nodes.get(i);
|
||||||
|
|
||||||
//Move
|
Location loc = node.getLocation();
|
||||||
|
|
||||||
|
// Move
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
node.teleport(infront);
|
node.teleport(infront);
|
||||||
else if (UtilMath.offset(node.getLocation(), infront) > 0.5)
|
else if (UtilMath.offset(node.getLocation(), infront) > 0.5)
|
||||||
node.teleport(infront.add(UtilAlg.getTrajectory(infront, node.getLocation()).multiply(0.5)));
|
node.teleport(infront.add(UtilAlg.getTrajectory(infront, node.getLocation()).multiply(0.5)));
|
||||||
|
|
||||||
|
// Rotation
|
||||||
|
node.setHeadPose(UtilAlg.vectorToEuler(UtilAlg.getTrajectory(node.getLocation(), loc)));
|
||||||
|
|
||||||
infront = node.getLocation();
|
infront = node.getLocation();
|
||||||
|
|
||||||
//Rotation
|
|
||||||
node.setHeadPose(UtilAlg.vectorToEuler(UtilAlg.getTrajectory(infront, node.getLocation())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shuffle In
|
||||||
//Shuffle In
|
|
||||||
if (_head.getPassenger() == null)
|
if (_head.getPassenger() == null)
|
||||||
{
|
{
|
||||||
for (int i=_nodes.size()-1 ; i>=0 ; i--)
|
for (int i = _nodes.size() - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
ArmorStand node = _nodes.get(i);
|
ArmorStand node = _nodes.get(i);
|
||||||
|
|
||||||
if (i>0)
|
Location loc = node.getLocation();
|
||||||
infront = _nodes.get(i-1).getLocation();
|
|
||||||
|
if (i > 0)
|
||||||
|
infront = _nodes.get(i - 1).getLocation();
|
||||||
else
|
else
|
||||||
infront = _head.getLocation().add(0, -1.5, 0);
|
infront = _head.getLocation().add(0, -1.3, 0);
|
||||||
|
|
||||||
node.teleport(infront);
|
node.teleport(infront);
|
||||||
|
|
||||||
|
node.setHeadPose(new EulerAngle(0, -UtilAlg.GetYaw(UtilAlg.getTrajectory(node.getLocation(), loc)), 0));
|
||||||
|
// node.setHeadPose(UtilAlg.vectorToEuler(UtilAlg.getTrajectory(node.getLocation(), loc)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clean()
|
||||||
|
|
||||||
public void clean()
|
|
||||||
{
|
{
|
||||||
_head.remove();
|
_head.remove();
|
||||||
|
|
||||||
for (ArmorStand stand : _nodes)
|
for (ArmorStand stand : _nodes)
|
||||||
stand.remove();
|
stand.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean ownsMount(Player player)
|
public boolean ownsMount(Player player)
|
||||||
{
|
{
|
||||||
return _owner.equals(player.getName());
|
return _owner.equals(player.getName());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user