Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IDRegistry.genItemID("angelRing");
- Item.createItem("angelRing", "Angel ring", {
- name: "angelRing"
- }, {
- stack: 1,
- isTech: true
- });
- mod_tip(ItemID.angelRing);
- var baubleEquip = false;
- var ringEquiped = false;
- Recipes.addShaped({
- id: ItemID.angelRing,
- count: 1,
- data: 0
- }, [
- "g#g",
- "#s#",
- " # "
- ], ['s', 399, 0, '#', 266, 0, 'g', 20, 0]);
- var ringVariations = [
- {
- name: 'Invisible Wings',
- texture: 'wings/wing0'
- },
- {
- name: 'Feathery Wings',
- texture: 'wings/wing1'
- },
- {
- name: 'Fairy Wings',
- texture: 'wings/wing2'
- },
- {
- name: 'Dragon Wings',
- texture: 'wings/wing3'
- },
- {
- name: 'Golden Wings',
- texture: 'wings/wing4'
- },
- {
- name: 'Dark Wings',
- texture: 'wings/wing5'
- }
- ]
- Item.addCreativeGroup("angelRings", Translation.translate("Angel Rings"), [ItemID.angelRing]);
- for(var i in ringVariations)Item.addToCreative(ItemID.angelRing, 1, i);
- Item.registerNameOverrideFunction(ItemID.angelRing, function(item, name){
- return name + (ringVariations[item.data] ? '\n§7' + Translation.translate(ringVariations[item.data].name) : "");
- })
- Item.registerIconOverrideFunction(ItemID.angelRing, function(item){
- return {name: 'angelRing', data: ringVariations[item.data] ? item.data : 0};
- })
- var _players = [];
- (function(){
- var superTempPlayerSetFlyingEnabled = Player.setFlyingEnabled;
- var superTempPlayerSetFlying = Player.setFlying;
- Player.setFlyingEnabled = function(enabled, forced){
- if(!ringEquiped || forced)superTempPlayerSetFlyingEnabled(enabled);
- }
- Player.setFlying = function(enabled, forced){
- if(!ringEquiped || forced)superTempPlayerSetFlying(enabled);
- }
- })();
- 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]];
- var tickTime = 0;
- Callback.addCallback("LocalTick", function() {
- var threadTime = World.getThreadTime();
- if(thisPlayerRingData = playerRenders[Player.get()])thisPlayerRingData.isFlying = Player.getBooleanAbility('flying');
- /* if(threadTime%40 == 0){
- var playerRingData = playerRenders[Player.get()];
- playerRingData.isFlying =
- //var tag = Entity.getCompoundTag(Player.get());
- //if(tag){
- //Logger.Log(JSON.stringify(tag.toScriptable()), 'Utils+Debug');
- //var tagAbilities = tag.getCompoundTag('abilities');
- //Game.tipMessage(Player.getBooleanAbility('flying'));
- //if(tagAbilities)Game.tipMessage(tagAbilities.getByte('flying') + " : " + Player.getBooleanAbility('flying') tagAbilities.getValueType('flying') );
- //}
- //if(tag)alert(tag.getValueType('flying') + " : " + JSON.stringify(tag.toScriptable()));
- //alert(Player.getBooleanAbility('flying'));
- } */
- if(threadTime%2 == 0) {
- if (!ringEquiped) {
- if (item = searchItem(ItemID.angelRing)) {
- var playerRingData = playerRenders[Player.get()];
- if(!playerRingData) return;
- playerRingData.texture = ringVariations[item.data].texture;
- if(playerRingData.lastTexture != playerRingData.texture){
- playerRingData.render.setTexture(playerRingData.texture);
- }
- Player.setFlyingEnabled(true);
- ringEquiped = true;
- playerRingData.ringEquiped = true;
- }
- } else if (ringEquiped && !baubleEquip) {
- if (!(item = searchItem(ItemID.angelRing))) {
- var playerRingData = playerRenders[Player.get()];
- if(!playerRingData) return;
- ringEquiped = false;
- playerRingData.ringEquiped = false;
- if(Game.getGameMode() != 1){
- Player.setFlyingEnabled(false);
- Player.setFlying(false);
- }
- }
- }
- }
- var settings_ = playerRenders[Player.get()];
- if(!settings_) return;
- //Game.tipMessage('Updating model');
- var xRotate = (1 + Math.cos((tickTime++) / 4)) * (settings_.isFlying ? 20 : 2) + 25;
- var wing1 = settings_.wing1;
- var wing2 = settings_.wing2;
- wing1.clear();
- wing2.clear();
- if(settings_.ringEquiped){
- //var wingVertexData = FileTools.ReadJSON(__dir__ + 'wingSettings.json').data;
- for(var i in wingVertexData){
- wing1.addVertex(wingVertexData[i][0],wingVertexData[i][1],wingVertexData[i][2],wingVertexData[i][3],wingVertexData[i][4]);
- wing2.addVertex(wingVertexData[i][0],wingVertexData[i][1],wingVertexData[i][2],wingVertexData[i][3],wingVertexData[i][4]);
- }
- /* wing1.rotate(0, xRotate * Math.PI/180 + 0.5, 0);
- wing2.rotate(0, -xRotate * Math.PI/180 - 0.5, 0); */
- wing1.rotate(0,1,0,0, -xRotate * Math.PI/180 - (settings_.isFlying ? 0 : 0.5), 0);
- wing2.rotate(0,1,0,0, xRotate * Math.PI/180 + (settings_.isFlying ? 0 : 0.5), 0);
- }
- wing1.invalidate();
- wing2.invalidate();
- });
- ModAPI.addAPICallback("BaublesAPI", function(api) {
- api.Baubles.registerBauble({
- id: ItemID.angelRing,
- type: "ring",
- onEquip: function() {
- Player.setFlyingEnabled(true);
- ringEquiped = true;
- baubleEquip = true;
- },
- onTakeOff: function() {
- ringEquiped = false;
- baubleEquip = false;
- Player.setFlyingEnabled(false);
- Player.setFlying(false);
- }
- });
- })
- Callback.addCallback("EntityHurt", function(attacker, victim, damage, damageType) {
- if ((searchItem(ItemID.angelRing) || baubleEquip) && victim == Player.get() && damageType == 5) {
- Game.prevent();
- }
- });
- Callback.addCallback('LevelLeft', function(){
- baubleEquip = false;
- ringEquiped = false;
- _players = [];
- });
- Callback.addCallback('LevelDisplayed', function(){
- _players.push(Player.get());
- });
- Callback.addCallback('ServerPlayerLoaded', function(player__){
- Network.sendToAllClients('Utils.updatePlayers', {players: Network.getConnectedPlayers(), player: player__});
- });
- var playerRenders = {};
- Network.addClientPacket('Utils.updatePlayers', function(packetData){
- _players = packetData.players;
- for(var i in _players){
- if(!playerRenders[_players[i]]){
- var __object = playerRenders[_players[i]] = {};
- __object.ringEquiped = false;
- __object.isFlying = false;
- __object.wing1 = new RenderMesh();
- __object.wing2 = new RenderMesh();
- __object.lastTexture = '';
- __object.texture = '';
- __object.render = new ActorRenderer();
- __object.attachable = new AttachableRender(_players[i]);
- __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();
- __object.attachable.setRenderer(__object.render);
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement