mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 14:14:46 +00:00
-Spawner, Transport, Healer, Guard, Bard jobs received more functions. -Added more functions to the transporter role. -IRole: Added getNpc() function. -IAnimal, IEntityLiving, and IEntityLivingBase received more functions from their MC counterparts. -Nearly every function with that takes position/vector parameters now has an equivalent with IPos as a parameter instead.
104 lines
2.7 KiB
Java
104 lines
2.7 KiB
Java
package noppes.npcs.roles;
|
|
|
|
import java.util.List;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.util.ChatComponentTranslation;
|
|
import noppes.npcs.NoppesUtilServer;
|
|
import noppes.npcs.constants.EnumGuiType;
|
|
import noppes.npcs.controllers.PlayerDataController;
|
|
import noppes.npcs.controllers.data.PlayerTransportData;
|
|
import noppes.npcs.controllers.TransportController;
|
|
import noppes.npcs.controllers.data.TransportLocation;
|
|
import noppes.npcs.entity.EntityNPCInterface;
|
|
import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation;
|
|
|
|
public class RoleTransporter extends RoleInterface{
|
|
|
|
public int transportId = -1;
|
|
public String name;
|
|
|
|
public RoleTransporter(EntityNPCInterface npc) {
|
|
super(npc);
|
|
}
|
|
|
|
|
|
@Override
|
|
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
|
|
nbttagcompound.setInteger("TransporterId", transportId);
|
|
return nbttagcompound;
|
|
}
|
|
|
|
@Override
|
|
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
|
transportId = nbttagcompound.getInteger("TransporterId");
|
|
TransportLocation loc = getLocation();
|
|
if(loc != null){
|
|
name = loc.name;
|
|
}
|
|
}
|
|
private int ticks = 10;
|
|
@Override
|
|
public boolean aiShouldExecute() {
|
|
ticks--;
|
|
if(ticks > 0)
|
|
return false;
|
|
ticks = 10;
|
|
|
|
if(!hasTransport())
|
|
return false;
|
|
|
|
TransportLocation loc = getLocation();
|
|
if(loc.type != 0)
|
|
return false;
|
|
|
|
List<EntityPlayer> inRange = npc.worldObj.getEntitiesWithinAABB(EntityPlayer.class,npc.boundingBox.expand(6D, 6D, 6D));
|
|
for(EntityPlayer player :inRange){
|
|
if(!npc.canSee(player))
|
|
continue;
|
|
unlock(player, loc);
|
|
}
|
|
return false;
|
|
|
|
}
|
|
@Override
|
|
public void aiStartExecuting() {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void interact(EntityPlayer player) {
|
|
if(hasTransport()){
|
|
TransportLocation loc = getLocation();
|
|
if(loc.type == 2){
|
|
unlock(player, loc);
|
|
}
|
|
NoppesUtilServer.sendOpenGui(player, EnumGuiType.PlayerTransporter, npc);
|
|
}
|
|
}
|
|
|
|
public void unlock(EntityPlayer player, ITransportLocation loc){
|
|
PlayerTransportData data = PlayerDataController.instance.getPlayerData(player).transportData;
|
|
if(data.transports.contains(transportId))
|
|
return;
|
|
data.transports.add(transportId);
|
|
player.addChatMessage(new ChatComponentTranslation("transporter.unlock", loc.getName()));
|
|
}
|
|
public TransportLocation getLocation(){
|
|
if(npc.isRemote())
|
|
return null;
|
|
return TransportController.getInstance().getTransport(transportId);
|
|
}
|
|
public boolean hasTransport(){
|
|
TransportLocation loc = getLocation();
|
|
return loc != null && loc.id == transportId;
|
|
}
|
|
|
|
public void setTransport(ITransportLocation location) {
|
|
transportId = location.getId();
|
|
name = location.getName();
|
|
}
|
|
|
|
}
|