Skip to content

Commit

Permalink
NPC Class
Browse files Browse the repository at this point in the history
  • Loading branch information
TheblueMan003 committed Jul 28, 2021
1 parent 19d8a86 commit e994b61
Show file tree
Hide file tree
Showing 26 changed files with 693 additions and 363 deletions.
Binary file modified .vs/BluePhoenix/v16/.suo
Binary file not shown.
1 change: 1 addition & 0 deletions JSharp/BluePhoenix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
<Compile Include="Inspector.Designer.cs">
<DependentUpon>Inspector.cs</DependentUpon>
</Compile>
<Compile Include="JsonMerger.cs" />
<Compile Include="LibImport.cs">
<SubType>Form</SubType>
</Compile>
Expand Down
859 changes: 534 additions & 325 deletions JSharp/Compiler.cs

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions JSharp/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public void Save(string projectPath)
string dirRes = Path.GetDirectoryName(projectPath) + "/resources/";
string dirLib = Path.GetDirectoryName(projectPath) + "/lib";

if (!Directory.Exists(dirLib))
if (!Directory.Exists(dirLib) && project.compilationSetting.isLibrary)
Directory.CreateDirectory(dirLib);

foreach (string file in codeOrder)
Expand Down Expand Up @@ -541,8 +541,6 @@ private void FetchFilesInDirectory()
}
}
}

UpdateRPTimes();
}
public void UpdateRPTimes()
{
Expand All @@ -559,7 +557,8 @@ public bool WasRPChanged()
if (Directory.Exists(rpdir))
{
bool res = rpmoddate.Any(x => !File.Exists(x.Key) || File.GetLastWriteTime(x.Key) > x.Value) ||
Directory.EnumerateFiles(rpdir, "*.*", SearchOption.AllDirectories).Any(x => !rpmoddate.ContainsKey(x));
Directory.EnumerateFiles(rpdir, "*.*", SearchOption.AllDirectories).Any(x => !rpmoddate.ContainsKey(x))
|| !File.Exists(currentResourcesPack);
return res;
}
else
Expand Down Expand Up @@ -863,7 +862,10 @@ public void NewProject()
}
if (res == DialogResult.OK)
{
projectName = form.ProjectName;
projectName = form.ProjectName.ToLower().Replace(" ","");
compilerSetting = new Compiler.CompilerSetting();
compilerSetting.packformat = 7;
compilerSetting.rppackformat = 7;
compilerSetting.MCVersion = form.MCVersion;
compilerSetting.libraryFolder.Add("./lib/1_17/");
compilerSetting.libraryFolder.Add("./lib/1_16_5/");
Expand Down Expand Up @@ -1337,7 +1339,6 @@ public void ExportFiles(string path)
}
if (Directory.Exists(rpdir) && exportRP)
{

string rpPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "/tmp_rp";
if (Directory.Exists(rpPath))
{
Expand Down Expand Up @@ -1498,8 +1499,9 @@ public void ExportResourcePack(string path)
ZipFile.CreateFromDirectory(rpPath, path);
}
Directory.Delete(rpPath, true);

DebugThread("Resources Pack successfully exported!", Color.Aqua);
}
DebugThread("Resources Pack successfully exported!", Color.Aqua);
}
catch(Exception e)
{
Expand Down
111 changes: 111 additions & 0 deletions JSharp/JsonMerger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using JSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BluePhoenix
{
public static class JsonMerger
{
public static JsonElement GetObject(string jsonstring)
{
jsonstring = Compiler.smartExtract(jsonstring);

if (jsonstring.StartsWith("{"))
{
return new JsonObject(jsonstring);
}
if (jsonstring.StartsWith("["))
{
return new JsonArray(jsonstring);
}
return new JsonUnit(jsonstring);
}
}
public abstract class JsonElement
{
public abstract void Merge(JsonElement element, bool keepOld);
}
public class JsonObject: JsonElement
{
public Dictionary<string, JsonElement> values = new Dictionary<string, JsonElement>();

public JsonObject(string element)
{
string[][] block = Compiler.smartSplit(Compiler.getCodeBlock(element), ',')
.Select(x => Compiler.smartSplitJson(x, ':').Select(y => Compiler.smartExtract(y)).ToArray())
.ToArray();
foreach(string[] kv in block)
{
values[kv[0]] = JsonMerger.GetObject(kv[1]);
}
}

public override void Merge(JsonElement element, bool keepOld)
{
JsonObject other = (JsonObject)element;
foreach(string key in other.values.Keys)
{
if (!values.ContainsKey(key))
{
values.Add(key, other.values[key]);
}
else
{
values[key].Merge(other.values[key], keepOld);
}
}
}
public override string ToString()
{
if (values.Count > 0)
return "{" + values.Select(x => x.Key.ToString() + ":" + x.Value.ToString()).Aggregate((x, y) => x + ", " + y) + "}";
else
return "{}";
}
}
public class JsonArray: JsonElement
{
public List<JsonElement> elements = new List<JsonElement>();

public JsonArray(string element)
{
string st = Compiler.smartExtract(element);
st = st.Substring(1, st.Length - 2);
elements.AddRange(Compiler.smartSplitJson(st, ',').Select(x => JsonMerger.GetObject(x)));
}

public override void Merge(JsonElement element, bool keepOld)
{
elements.AddRange(((JsonArray)element).elements);
}
public override string ToString()
{
if (elements.Count > 0)
return "[" + elements.Select(x => x.ToString()).Aggregate((x, y) => x + ", " + y) + "]";
else
return "[]";
}
}
public class JsonUnit : JsonElement
{
public string value;

public JsonUnit(string value){
this.value = value;
}

public override void Merge(JsonElement element, bool keepOld)
{
if (!keepOld)
value = ((JsonUnit)element).value;
}

public override string ToString()
{
return value;
}
}
}
Binary file modified JSharp/bin/Debug/BluePhoenix.exe
Binary file not shown.
Binary file modified JSharp/bin/Debug/BluePhoenix.pdb
Binary file not shown.
10 changes: 8 additions & 2 deletions JSharp/bin/Debug/formating.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion JSharp/bin/Debug/lib/1_16_5/cmd/effect.tbms
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"projectName":"effect","datapackDirectory":null,"resourcesPackDirectory":null,"offuscate":true,"isLibrary":true,"description":"","files":[{"name":"import","content":"import standard.java\nimport standard.entity_id\nimport standard.object","index":0},{"name":"effect","content":"package effect\n\nenum(\"effectlist\",\"effectlist\",\"CSV\")\nforgenerate($eff, effectlist){\n lazy clear$eff(){\n /effect clear @s minecraft:$eff\n }\n lazy clear$eff(entity $ent){\n /effect clear $ent minecraft:$eff\n }\n \n lazy $eff(){\n /effect give @s minecraft:$eff 30 0 true\n }\n lazy $eff(int $pow, int $duration){\n require $pow <= 255\n require $pow >= 0\n require $duration <= 1000000\n require $duration >= 0\n /effect give @s minecraft:$eff $pow $duration true\n }\n lazy $eff(int $pow, int $duration, int $particle){\n require $pow <= 255\n require $pow >= 0\n require $duration <= 1000000\n require $duration >= 0\n /effect give @s minecraft:$eff $pow $duration $particle\n }\n \n lazy $eff(entity $ent){\n /effect give $ent minecraft:$eff 30 0 true\n }\n lazy $eff(entity $ent, int $pow, int $duration){\n require $pow <= 255\n require $pow >= 0\n require $duration <= 1000000\n require $duration >= 0\n /effect give $ent minecraft:$eff $pow $duration true\n }\n lazy $eff(entity $ent, int $pow, int $duration, int $particle){\n require $pow <= 255\n require $pow >= 0\n require $duration <= 1000000\n require $duration >= 0\n /effect give $ent minecraft:$eff $pow $duration $particle\n }\n}","index":0}],"resources":[{"name":"effectlist","content":"name\nabsorption\nunluck\nbad_omen\nblindness\nconduit_power\ndolphins_grace\nfire_resistance\nglowing\nhaste\nhealth_boost\nhero_of_the_village\nhunger\ninstant_damage\ninstant_health\ninvisibility\njump_boost\nlevitation\nluck\nmining_fatigue\nnausea\nnight_vision\npoison\nregeneration\nresistance\nsaturation\nslow_falling\nslowness\nspeed\nstrength\nwater_breathing\nweakness\nwither","index":0}],"TagsList":{"blocks":{},"functions":{}},"mcTagsList":{"blocks":{},"functions":{"load":{"values":["load"]},"tick":{"values":["main"]}}},"compileOrder":[],"version":{"major":1,"minor":0,"patch":0,"build":0},"compilationSetting":{"TreeMaxSize":20,"FloatPrecision":1000,"removeUselessFile":true,"offuscate":true,"scoreboardValue":"tbms.value","scoreboardConst":"tbms.const","scoreboardTmp":"tbms.tmp","tagsFolder":true,"forcedOffuscation":{},"libraryFolder":["./lib/1_17/","./lib/1_16_5/","./lib/shared/"],"MCVersion":"1.16.5","ExportAsZip":false,"packformat":6,"rppackformat":7,"CompilerCoreName":"java","Authors":"","generateMAPSFile":true,"generateREADMEFile":true,"opti_FunctionTagsReplace":true,"opti_ExportComment":false,"opti_ShowException":true,"opti_ShowDebug":true,"advanced_debug":false,"isLibrary":false}}
{"projectName":"effect","datapackDirectory":null,"resourcesPackDirectory":null,"offuscate":true,"isLibrary":true,"description":"","files":[{"name":"import","content":"import standard.java\nimport standard.entity_id\nimport standard.object","index":0},{"name":"effect","content":"package effect\n\nenum(\"effectlist\",\"effectlist\",\"CSV\")\nforgenerate($eff, effectlist){\n lazy clear$eff(){\n /effect clear @s minecraft:$eff\n }\n lazy clear$eff(entity $ent){\n /effect clear $ent minecraft:$eff\n }\n \n lazy $eff(){\n /effect give @s minecraft:$eff 30 0 true\n }\n lazy $eff(int $duration, int $pow){\n require $pow <= 255\n require $pow >= 0\n require $duration <= 1000000\n require $duration >= 0\n /effect give @s minecraft:$duration $pow $pow true\n }\n lazy $eff(int $duration, int $pow, int $particle){\n require $pow <= 255\n require $pow >= 0\n require $duration <= 1000000\n require $duration >= 0\n /effect give @s minecraft:$eff $duration $pow $particle\n }\n \n lazy $eff(entity $ent){\n /effect give $ent minecraft:$eff 30 0 true\n }\n lazy $eff(entity $ent, int $duration, int $pow){\n require $pow <= 255\n require $pow >= 0\n require $duration <= 1000000\n require $duration >= 0\n /effect give $ent minecraft:$eff $duration $pow true\n }\n lazy $eff(entity $ent, int $duration, int $pow, int $particle){\n require $pow <= 255\n require $pow >= 0\n require $duration <= 1000000\n require $duration >= 0\n /effect give $ent minecraft:$eff $duration $pow $particle\n }\n}","index":0}],"resources":[{"name":"effectlist","content":"name\nabsorption\nunluck\nbad_omen\nblindness\nconduit_power\ndolphins_grace\nfire_resistance\nglowing\nhaste\nhealth_boost\nhero_of_the_village\nhunger\ninstant_damage\ninstant_health\ninvisibility\njump_boost\nlevitation\nluck\nmining_fatigue\nnausea\nnight_vision\npoison\nregeneration\nresistance\nsaturation\nslow_falling\nslowness\nspeed\nstrength\nwater_breathing\nweakness\nwither","index":0}],"TagsList":{"blocks":{},"functions":{}},"mcTagsList":{"blocks":{},"functions":{"load":{"values":["load"]},"tick":{"values":["main"]}}},"compileOrder":[],"version":{"major":1,"minor":0,"patch":0,"build":1},"compilationSetting":{"TreeMaxSize":20,"FloatPrecision":1000,"removeUselessFile":true,"offuscate":true,"scoreboardValue":"tbms.value","scoreboardConst":"tbms.const","scoreboardTmp":"tbms.tmp","tagsFolder":true,"forcedOffuscation":{},"libraryFolder":["./lib/1_17/","./lib/1_16_5/","./lib/shared/"],"MCVersion":"1.16.5","ExportAsZip":false,"packformat":6,"rppackformat":7,"CompilerCoreName":"java","Authors":"","generateMAPSFile":true,"generateREADMEFile":true,"opti_FunctionTagsReplace":true,"opti_ExportComment":false,"opti_ShowException":true,"opti_ShowDebug":true,"advanced_debug":false,"isLibrary":false}}
2 changes: 1 addition & 1 deletion JSharp/bin/Debug/lib/1_16_5/cmd/music.tbms
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"projectName":"music","datapackDirectory":null,"resourcesPackDirectory":null,"offuscate":true,"isLibrary":true,"description":"Made With BluePhoenix","files":[{"name":"import","content":"import standard.java\r\nimport standard.entity_id\r\n","index":0},{"name":"music","content":"package music\r\n\r\nenum track = none\r\nTRACK currTrack\r\nINT MusicTick\r\nBOOL Intro\r\n\r\n[inplace]\r\ndef lazy addMusic(int $name,int $file, int $length){\r\n enum track = $name\r\n def play$name(){\r\n currTrack = $name\r\n MusicTick = 10000000\r\n }\r\n def @music_track music$name(){\r\n if (currTrack == $name && MusicTick >= $length){\r\n /playsound $file record @s ~ ~ ~ 1\r\n MusicTick = 0\r\n }\r\n }\r\n}\r\n\r\n[inplace]\r\ndef lazy addMusic(int $name,int $file_intro, int $file_loop, int $length_intro, int $length_loop){\r\n enum track = $name\r\n def play$name(){\r\n currTrack = $name\r\n MusicTick = 0\r\n /playsound $file_intro record @s ~ ~ ~ 1\r\n Intro = true\r\n }\r\n def @music_track music$name(){\r\n if (currTrack == $name && MusicTick >= $length_loop && !Intro){\r\n /playsound $file_loop record @s ~ ~ ~ 1\r\n MusicTick = 0\r\n }\r\n if (currTrack == $name && MusicTick >= $length_intro && Intro){\r\n /playsound $file_loop record @s ~ ~ ~ 1\r\n MusicTick = 0\r\n Intro = false\r\n }\r\n }\r\n}\r\n\r\ndef ticking music(){\r\n with(@a,true){\r\n MusicTick++\r\n @music_track()\r\n }\r\n}\r\n\r\ndef stop(){\r\n MusicTick = -10000000\r\n /stopsound @s record\r\n}\r\n\r\ndef continue(){\r\n MusicTick = 10000000\r\n}","index":0}],"resources":[],"TagsList":{"blocks":{},"functions":{}},"mcTagsList":{"blocks":{},"functions":{"load":{"values":["load"]},"tick":{"values":["main"]}}},"compileOrder":[],"version":{"major":1,"minor":0,"patch":0,"build":5},"compilationSetting":{"TreeMaxSize":20,"FloatPrecision":1000,"removeUselessFile":true,"offuscate":true,"scoreboardValue":"tbms.value","scoreboardConst":"tbms.const","scoreboardTmp":"tbms.tmp","tagsFolder":true,"forcedOffuscation":{},"libraryFolder":["./lib/1_16_5/","./lib/shared/"],"MCVersion":"1.16.5","ExportAsZip":false,"packformat":6,"rppackformat":7,"CompilerCoreName":"java","Authors":"","generateMAPSFile":true,"generateREADMEFile":true,"opti_FunctionTagsReplace":true,"opti_ExportComment":false,"opti_ShowException":true,"opti_ShowDebug":true,"advanced_debug":false,"isLibrary":false}}
{"projectName":"music","datapackDirectory":null,"resourcesPackDirectory":null,"offuscate":true,"isLibrary":true,"description":"Made With BluePhoenix","files":[{"name":"import","content":"import standard.java\nimport standard.entity_id\n","index":0},{"name":"music","content":"package music\n\nenum track = none\nTRACK currTrack\nINT MusicTick\nBOOL Intro\n\n[inplace]\ndef lazy addMusic(int $name,int $file, int $length){\n enum track = $name\n def play$name(){\n currTrack = $name\n MusicTick = 10000000\n }\n def @music_track music$name(){\n if (currTrack == $name && MusicTick >= $length){\n /stopsound @s record\n /playsound $file record @s ~ ~ ~ 1\n MusicTick = 0\n }\n }\n}\n\n[inplace]\ndef lazy addMusic(int $name,int $file_intro, int $file_loop, int $length_intro, int $length_loop){\n enum track = $name\n def play$name(){\n if (currTrack != $name){\n currTrack = $name\n MusicTick = 0\n /stopsound @s record\n /playsound $file_intro record @s ~ ~ ~ 1\n Intro = true\n }\n }\n def @music_track music$name(){\n if (currTrack == $name && MusicTick >= $length_loop && !Intro){\n /stopsound @s record\n /playsound $file_loop record @s ~ ~ ~ 1\n MusicTick = 0\n }\n if (currTrack == $name && MusicTick >= $length_intro && Intro){\n /stopsound @s record\n /playsound $file_loop record @s ~ ~ ~ 1\n MusicTick = 0\n Intro = false\n }\n }\n}\n\ndef ticking music(){\n with(@a,true){\n MusicTick++\n @music_track()\n }\n}\n\ndef stop(){\n MusicTick = -10000000\n /stopsound @s record\n}\n\ndef continue(){\n MusicTick = 10000000\n}","index":0}],"resources":[],"TagsList":{"blocks":{},"functions":{}},"mcTagsList":{"blocks":{},"functions":{"load":{"values":["load"]},"tick":{"values":["main"]}}},"compileOrder":[],"version":{"major":1,"minor":0,"patch":0,"build":7},"compilationSetting":{"TreeMaxSize":20,"FloatPrecision":1000,"removeUselessFile":true,"offuscate":true,"scoreboardValue":"tbms.value","scoreboardConst":"tbms.const","scoreboardTmp":"tbms.tmp","tagsFolder":true,"forcedOffuscation":{},"libraryFolder":["./lib/1_16_5/","./lib/shared/"],"MCVersion":"1.16.5","ExportAsZip":false,"packformat":6,"rppackformat":7,"CompilerCoreName":"java","Authors":"","generateMAPSFile":true,"generateREADMEFile":true,"opti_FunctionTagsReplace":true,"opti_ExportComment":false,"opti_ShowException":true,"opti_ShowDebug":true,"advanced_debug":false,"isLibrary":false}}

0 comments on commit e994b61

Please sign in to comment.