Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IDRegistry.genItemID("flacon_for_souls");
- Item.createItem("flacon_for_souls", "Flacon for souls", {
- name: "flacon_for_souls"
- }, {
- stack: 1
- });
- mod_tip(ItemID.flacon_for_souls);
- IDRegistry.genItemID("flacon_with_soul");
- Item.createItem("flacon_with_soul", "Flacon with soul", {
- name: "flacon_with_soul"
- }, {
- stack: 1
- });
- mod_tip(ItemID.flacon_with_soul);
- Recipes.addShaped({
- id: ItemID.flacon_for_souls,
- count: 1,
- data: 0
- }, [
- " s ",
- "g g",
- " g "
- ], ['s', 158, -1, 'g', 20, 0]);
- function createMobData(tag){
- var isListTag = !tag.getAllKeys;
- //Logger.Log('IsListTag: ' + isListTag, 'UtilsDebug');
- var mobData = isListTag ? [] : {};
- var keys = !isListTag ? tag.getAllKeys() : false;
- var length_ = keys ? keys.length : tag.length();
- if (keys != null) {
- for (var _key = 0; _key < length_; _key++) {
- var key = keys ? keys[_key] : _key;
- //Logger.Log('Key: ' + key, 'UtilsDebug');
- var keyType = tag.getValueType(key);
- var _data = {type: keyType};
- switch (keyType) {
- case 1:
- _data.value = Number(tag.getByte(key));
- break;
- case 2:
- _data.value = Number(tag.getShort(key));
- break;
- case 3:
- _data.value = Number(tag.getInt(key));
- break;
- case 4:
- _data.value = Number(tag.getInt64(key));
- break;
- case 5:
- _data.value = Number(tag.getFloat(key));
- break;
- case 6:
- _data.value = Number(tag.getDouble(key));
- break;
- case 7:
- _data.value = '';
- break;
- case 8:
- _data.value = tag.getString(key) + "";
- break;
- case 9:
- var listTag = tag.getListTag(key);
- if (listTag != null) {
- _data.value = createMobData(listTag)
- } else {
- _data.value = [];
- }
- break;
- case 10:
- var compoundTag = tag.getCompoundTag(key);
- if (compoundTag != null) {
- _data.value = createMobData(compoundTag)
- } else {
- _data.value = {};
- }
- break;
- case 11:
- _data.value = '';
- break;
- }
- //Logger.Log('Data: ' + JSON.stringify(_data), 'UtilsDebug');
- mobData[key] = _data;
- }
- }
- return mobData;
- }
- function createMobTag(tag_json){
- var isListTag = Array.isArray(tag_json);
- Logger.Log('IsListTag: ' + isListTag, 'UtilsDebug');
- var tag = isListTag ? new NBT.ListTag() : new NBT.CompoundTag();
- for (var key in tag_json) {
- Logger.Log('Key: ' + key, 'UtilsDebug');
- var _data = tag_json[key];
- switch (_data.type) {
- case 1:
- tag.putByte(key, _data.value);
- break;
- case 2:
- tag.putShort(key, _data.value);
- break;
- case 3:
- tag.putInt(key, _data.value);
- break;
- case 4:
- tag.putInt64(key, _data.value);
- break;
- case 5:
- tag.putFloat(key, _data.value);
- break;
- case 6:
- tag.putDouble(key, _data.value);
- break;
- case 8:
- tag.putString(key, _data.value);
- break;
- case 9:
- Logger.Log('Pushing listTag: ' + JSON.stringify(_data.value), 'UtilsDebug');
- var newTag = createMobTag(_data.value);
- Logger.Log('New listTag: ' + JSON.stringify(newTag.toScriptable()), 'UtilsDebug');
- Logger.Log('New listTag: ' + newTag, 'UtilsDebug');
- tag.putListTag(key, newTag);
- break;
- case 10:
- Logger.Log('Pushing compoundTag: ' + JSON.stringify(_data.value), 'UtilsDebug');
- var newTag = createMobTag(_data.value);
- Logger.Log('New compoundTag: ' + JSON.stringify(newTag.toScriptable()), 'UtilsDebug');
- Logger.Log('New compoundTag: ' + newTag, 'UtilsDebug');
- tag.putCompoundTag(key, newTag);
- break;
- }
- }
- return tag;
- }
- Item.registerNoTargetUseFunction("flacon_for_souls", function(item, _player) {
- var data = getPointed();
- if (data.entity != -1) {
- var mobData = createMobData(Entity.getCompoundTag(data.entity));
- Entity.remove(data.entity);
- var extra = new ItemExtraData();
- extra.putString("entity", JSON.stringify(mobData));
- var player = new PlayerActor(_player);
- player.setInventorySlot(player.getSelectedSlot(), ItemID.flacon_with_soul, 1, 0, extra);
- }
- })
- Item.registerUseFunction("flacon_with_soul", function(coords, item, block, player) {
- var extra = new ItemExtraData(item.extra);
- if (!(entityTag = createMobTag(JSON.parse(extra.getString("entity"))))) return;
- _playerActor = new PlayerActor(player);
- var newCoords = {
- x: coords.x + 0.5,
- y: coords.y + 1,
- z: coords.z + 0.5
- }
- var newEntity = Entity.spawnAtCoords(newCoords, entity.type);
- Debug.big(entityTag.toSciptable());
- Entity.setCompoundTag(newEntity, entityTag);
- _playerActor.setInventorySlot(_playerActor.getSelectedSlot(), ItemID.flacon_for_souls, 1, 0);
- })
Add Comment
Please, Sign In to add comment