Advertisement
Bot213123

AngelRing

Feb 27th, 2021
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. IDRegistry.genItemID("angelRing");
  2. Item.createItem("angelRing", "Angel ring", {
  3.     name: "angelRing"
  4. }, {
  5.     stack: 1,
  6.     isTech: true
  7. });
  8. mod_tip(ItemID.angelRing);
  9. var baubleEquip = false;
  10. var ringEquiped = false;
  11.  
  12. Recipes.addShaped({
  13.     id: ItemID.angelRing,
  14.     count: 1,
  15.     data: 0
  16. }, [
  17.     "g#g",
  18.     "#s#",
  19.     " # "
  20. ], ['s', 399, 0, '#', 266, 0, 'g', 20, 0]);
  21.  
  22. var ringVariations = [
  23.     {
  24.         name: 'Invisible Wings',
  25.         texture: 'wings/wing0'
  26.     },
  27.     {
  28.         name: 'Feathery Wings',
  29.         texture: 'wings/wing1'
  30.     },
  31.     {
  32.         name: 'Fairy Wings',
  33.         texture: 'wings/wing2'
  34.     },
  35.     {
  36.         name: 'Dragon Wings',
  37.         texture: 'wings/wing3'
  38.     },
  39.     {
  40.         name: 'Golden Wings',
  41.         texture: 'wings/wing4'
  42.     },
  43.     {
  44.         name: 'Dark Wings',
  45.         texture: 'wings/wing5'
  46.     }
  47. ]
  48.  
  49. Item.addCreativeGroup("angelRings", Translation.translate("Angel Rings"), [ItemID.angelRing]);
  50.  
  51. for(var i in ringVariations)Item.addToCreative(ItemID.angelRing, 1, i);
  52.  
  53. Item.registerNameOverrideFunction(ItemID.angelRing, function(item, name){
  54.     return name + (ringVariations[item.data] ? '\n§7' + Translation.translate(ringVariations[item.data].name) : "");
  55. })
  56.  
  57. Item.registerIconOverrideFunction(ItemID.angelRing, function(item){
  58.     return {name: 'angelRing', data: ringVariations[item.data] ? item.data : 0};
  59. })
  60.  
  61. var _players = [];
  62.  
  63. (function(){
  64.     var superTempPlayerSetFlyingEnabled = Player.setFlyingEnabled;
  65.     var superTempPlayerSetFlying = Player.setFlying;
  66.     Player.setFlyingEnabled = function(enabled, forced){
  67.         if(!ringEquiped || forced)superTempPlayerSetFlyingEnabled(enabled);
  68.     }
  69.     Player.setFlying = function(enabled, forced){
  70.         if(!ringEquiped || forced)superTempPlayerSetFlying(enabled);
  71.     }
  72. })();
  73.  
  74. var wingVertexData = [[0,0,0,0,0],[0,0,1,16,0],[0,-1,0,0,16],[0,-1,1,16,16],[0,0,1,16,0],[0,-1,0,0,16]];
  75. var tickTime = 0;
  76. Callback.addCallback("LocalTick", function() {
  77.     var threadTime = World.getThreadTime();
  78.     if(thisPlayerRingData = playerRenders[Player.get()])thisPlayerRingData.isFlying = Player.getBooleanAbility('flying');
  79.     /* if(threadTime%40 == 0){
  80.         var playerRingData = playerRenders[Player.get()];
  81.         playerRingData.isFlying =
  82.         //var tag = Entity.getCompoundTag(Player.get());
  83.         //if(tag){
  84.             //Logger.Log(JSON.stringify(tag.toScriptable()), 'Utils+Debug');
  85.             //var tagAbilities = tag.getCompoundTag('abilities');
  86.             //Game.tipMessage(Player.getBooleanAbility('flying'));
  87.             //if(tagAbilities)Game.tipMessage(tagAbilities.getByte('flying') + " : " + Player.getBooleanAbility('flying') tagAbilities.getValueType('flying') );
  88.         //}
  89.         //if(tag)alert(tag.getValueType('flying') + " : " + JSON.stringify(tag.toScriptable()));
  90.         //alert(Player.getBooleanAbility('flying'));
  91.     } */
  92.     if(threadTime%2 == 0) {
  93.         if (!ringEquiped) {
  94.             if (item = searchItem(ItemID.angelRing)) {
  95.                 var playerRingData = playerRenders[Player.get()];
  96.                 if(!playerRingData) return;
  97.                 playerRingData.texture = ringVariations[item.data].texture;
  98.                 if(playerRingData.lastTexture != playerRingData.texture){
  99.                     playerRingData.render.setTexture(playerRingData.texture);
  100.                 }
  101.                 Player.setFlyingEnabled(true);
  102.                 ringEquiped = true;
  103.                 playerRingData.ringEquiped = true;
  104.             }
  105.         } else if (ringEquiped && !baubleEquip) {
  106.             if (!(item = searchItem(ItemID.angelRing))) {
  107.                 var playerRingData = playerRenders[Player.get()];
  108.                 if(!playerRingData) return;
  109.                 ringEquiped = false;
  110.                 playerRingData.ringEquiped = false;
  111.                 if(Game.getGameMode() != 1){
  112.                     Player.setFlyingEnabled(false);
  113.                     Player.setFlying(false);
  114.                 }
  115.             }
  116.         }
  117.     }
  118.     var settings_ = playerRenders[Player.get()];
  119.     if(!settings_) return;
  120.     //Game.tipMessage('Updating model');
  121.     var xRotate = (1 + Math.cos((tickTime++) / 4)) * (settings_.isFlying ? 20 : 2) + 25;
  122.     var wing1 = settings_.wing1;
  123.     var wing2 = settings_.wing2;
  124.     wing1.clear();
  125.     wing2.clear();
  126.     if(settings_.ringEquiped){
  127.         //var wingVertexData = FileTools.ReadJSON(__dir__ + 'wingSettings.json').data;
  128.         for(var i in wingVertexData){
  129.             wing1.addVertex(wingVertexData[i][0],wingVertexData[i][1],wingVertexData[i][2],wingVertexData[i][3],wingVertexData[i][4]);
  130.             wing2.addVertex(wingVertexData[i][0],wingVertexData[i][1],wingVertexData[i][2],wingVertexData[i][3],wingVertexData[i][4]);
  131.         }
  132.         /* wing1.rotate(0, xRotate * Math.PI/180 + 0.5, 0);
  133.         wing2.rotate(0, -xRotate * Math.PI/180 - 0.5, 0); */
  134.         wing1.rotate(0,1,0,0, -xRotate * Math.PI/180 - (settings_.isFlying ? 0 : 0.5), 0);
  135.         wing2.rotate(0,1,0,0, xRotate * Math.PI/180 + (settings_.isFlying ? 0 : 0.5), 0);
  136.     }
  137.     wing1.invalidate();
  138.     wing2.invalidate();
  139. });
  140.  
  141. ModAPI.addAPICallback("BaublesAPI", function(api) {
  142.     api.Baubles.registerBauble({
  143.         id: ItemID.angelRing,
  144.         type: "ring",
  145.         onEquip: function() {
  146.             Player.setFlyingEnabled(true);
  147.             ringEquiped = true;
  148.             baubleEquip = true;
  149.         },
  150.         onTakeOff: function() {
  151.             ringEquiped = false;
  152.             baubleEquip = false;
  153.             Player.setFlyingEnabled(false);
  154.             Player.setFlying(false);
  155.         }
  156.     });
  157. })
  158.  
  159. Callback.addCallback("EntityHurt", function(attacker, victim, damage, damageType) {
  160.     if ((searchItem(ItemID.angelRing) || baubleEquip) && victim == Player.get() && damageType == 5) {
  161.         Game.prevent();
  162.     }
  163. });
  164.  
  165. Callback.addCallback('LevelLeft', function(){
  166.     baubleEquip = false;
  167.     ringEquiped = false;
  168.     _players = [];
  169. });
  170.  
  171. Callback.addCallback('LevelDisplayed', function(){
  172.     _players.push(Player.get());
  173. });
  174.  
  175. Callback.addCallback('ServerPlayerLoaded', function(player__){
  176.     Network.sendToAllClients('Utils.updatePlayers', {players: Network.getConnectedPlayers(), player: player__});
  177. });
  178.  
  179. var playerRenders = {};
  180. Network.addClientPacket('Utils.updatePlayers', function(packetData){
  181.     _players = packetData.players;
  182.     for(var i in _players){
  183.         if(!playerRenders[_players[i]]){
  184.             var __object = playerRenders[_players[i]] = {};
  185.             __object.ringEquiped = false;
  186.             __object.isFlying = false;
  187.             __object.wing1 = new RenderMesh();
  188.             __object.wing2 = new RenderMesh();
  189.             __object.lastTexture = '';
  190.             __object.texture = '';
  191.             __object.render = new ActorRenderer();
  192.             __object.attachable = new AttachableRender(_players[i]);
  193.             __object.render.addPart('body').endPart().addPart('wing1', 'body', __object.wing1).setOffset(1, -4, 1.5).endPart().addPart('wing2', 'body', __object.wing2).setOffset(-1, -4, 1.5).endPart();
  194.             __object.attachable.setRenderer(__object.render);
  195.         }
  196.     }
  197. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement