Advertisement
james1bow

Untitled

Feb 9th, 2024
1,071
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.34 KB | None | 0 0
  1.  
  2. package playertesting;
  3.  
  4. import java.util.ArrayList;
  5. import net.risingworld.api.Plugin;
  6. import net.risingworld.api.Server;
  7. import net.risingworld.api.Timer;
  8. import net.risingworld.api.World;
  9. import net.risingworld.api.assets.AssetBundle;
  10. import net.risingworld.api.events.EventMethod;
  11. import net.risingworld.api.events.Listener;
  12. import net.risingworld.api.events.npc.NpcSpawnEvent;
  13. import net.risingworld.api.events.player.PlayerChangePositionEvent;
  14. import net.risingworld.api.objects.Player;
  15. import net.risingworld.api.events.player.PlayerConnectEvent;
  16. import net.risingworld.api.objects.Npc;
  17. import net.risingworld.api.utils.Key;
  18. import net.risingworld.api.utils.Utils;
  19. import net.risingworld.api.utils.Vector3f;
  20. import net.risingworld.api.worldelements.Text3D;
  21.  
  22.  
  23. public class playertesting extends Plugin implements Listener {
  24.     public AssetBundle bundle;
  25.     public ArrayList<Text3D> text3d;
  26.    
  27.     @Override
  28.     public void onEnable() {
  29.         this.registerEventListener(this);
  30.        
  31.        initnpcs();
  32.        
  33.     }
  34.  
  35.     @Override
  36.     public void onDisable() {
  37.        
  38.     }
  39.    
  40.    
  41.    
  42.    
  43.     public void initnpcs(){
  44.         text3d = new ArrayList();
  45.         Npc[] npcs = World.getAllNpcs();
  46.         for(Npc npc : npcs){
  47.             String type = npc.getDefinition().type.name();
  48.             if(type.equalsIgnoreCase("Animal")){
  49.                 Text3D text = new Text3D("Wild");
  50.                 text.setBillboard(true);
  51.                 text.setFontSize(2.5f);
  52.                 text.setActive(true);
  53.                 float oy = npc.getPosition().y;
  54.                 float ny = oy+5.0f;  
  55.                 text.setFontColor(0, 1, 0, 1);
  56.                 String b = npc.getDefinition().behaviour.name();
  57.                 if(b.equalsIgnoreCase("Aggressive")){
  58.                     text.setFontColor(1, 0, 0, 1);
  59.                 }
  60.                 text.setLocalPosition(npc.getPosition().x, ny, npc.getPosition().z);
  61.                 npc.setAttribute("text", text);
  62.                
  63.                 text3d.add(text);
  64.             }
  65.         }
  66.         Timer();
  67.        
  68.     }
  69.    
  70.     public void loadplayertexts(Player player){
  71.        
  72.         for(int i = 0; i<text3d.size();i++){
  73.             Text3D text = (Text3D)text3d.get(i);
  74.             player.addGameObject(text);
  75.         }
  76.    
  77.     }
  78.  
  79.     @EventMethod
  80.     public void playerconnect(PlayerConnectEvent evt){
  81.        
  82.         Player player = evt.getPlayer();
  83.        
  84.  
  85.         player.registerKeys(Key.F);
  86.  
  87.         player.setListenForKeyInput(true);
  88.         player.setListenForMouseInput(true);
  89.         loadplayertexts(player);
  90.     }
  91.    
  92.    
  93.     public void Timer(){
  94.         Timer timer = new Timer(0.0025f, 0f, -1, () -> {
  95.             Npc[] npcs = World.getAllNpcs();
  96.             for(Npc npc : npcs){
  97.                 if(npc.hasAttribute("text")){
  98.                     Text3D text = (Text3D)npc.getAttribute("text");
  99.                     float oy = npc.getPosition().y;
  100.                     float ny = oy+3.25f;
  101.                     text.setLocalPosition(npc.getPosition().x, ny, npc.getPosition().z);
  102.                 }
  103.             }
  104.         });
  105.         timer.start();
  106.     }
  107.    
  108.     @EventMethod
  109.     public void npcspawn(NpcSpawnEvent evt){
  110.         Npc npc = evt.getNpc();
  111.         Timer  timer= new Timer(60f, 5f, 1, null);
  112.         timer.setTask(TimerRunnable(npc));
  113.         timer.start();
  114.        
  115.     }
  116.    
  117.     public Runnable TimerRunnable(Npc npc){
  118.  
  119.         Runnable setNpcInfo = ()->{
  120.             String type = npc.getDefinition().type.name();
  121.             if(type.equalsIgnoreCase("Animal")){
  122.                 Text3D text = new Text3D("Wild");
  123.                 text.setBillboard(true);
  124.                 text.setFontSize(2.5f);
  125.                 text.setActive(false);
  126.                 float oy = npc.getPosition().y;
  127.                 float ny = oy+3.25f;
  128.                 text.setFontColor(0, 1, 0, 1);
  129.                 String b = npc.getDefinition().behaviour.name();
  130.                 if(b.equalsIgnoreCase("Aggressive")){
  131.                     text.setFontColor(1, 0, 0, 1);
  132.                 }
  133.                 text.setLocalPosition(npc.getPosition().x, ny, npc.getPosition().z);
  134.                 npc.setAttribute("text", text);
  135.                 text3d.add(text);
  136.                 updateplayeruis(npc);
  137.             }
  138.         };
  139.         return setNpcInfo;
  140.     }
  141.    
  142.    
  143.     public void updateplayeruis(Npc npc){
  144.         Player[] players = Server.getAllPlayers();
  145.         for(Player player : players){
  146.             Text3D text = (Text3D)npc.getAttribute("text");
  147.             player.addGameObject(text);
  148.         }
  149.     }
  150.    
  151.    
  152.     @EventMethod
  153.     public void playerchangeposition(PlayerChangePositionEvent evt){
  154.         Player player = evt.getPlayer();
  155.         Npc[] npcs = World.getAllNpcs();
  156.         for(Npc npc : npcs){
  157.             if(npc.hasAttribute("text")){
  158.                 Text3D text = (Text3D)npc.getAttribute("text");
  159.                 Vector3f pos = npc.getPosition();
  160.                 float distance = Utils.MathUtils.distance(pos.x,pos.y,pos.z, player.getPosition().x,player.getPosition().y,player.getPosition().z);
  161.                 if(distance<=75){
  162.                     text.setActive(true);
  163.                 }if(distance>=76){
  164.                     text.setActive(false);
  165.                 }
  166.             }
  167.         }
  168.     }
  169.    
  170.  
  171. }
  172.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement