Skip to content

Commit 45b7fbe

Browse files
committed
实体标准库
1 parent e56eced commit 45b7fbe

File tree

132 files changed

+19085
-279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+19085
-279
lines changed

src/main/antlr/mcfppParser.g4

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ templateMember
180180
: templateFunctionDeclaration
181181
| templateFieldDeclaration
182182
| templateConstructorDeclaration
183+
| innerTemplateDeclaration
184+
| innerTemplateListDeclaration
183185
| annotation
184186
;
185187

@@ -199,6 +201,14 @@ unionTemplateFieldType
199201
: '(' type (PIPE type)* ')' QUEST?
200202
;
201203

204+
innerTemplateDeclaration
205+
: DATA Identifier (COLON className (',' className)*)? templateBody
206+
;
207+
208+
innerTemplateListDeclaration
209+
: LIST '<' DATA '>' Identifier (COLON className (',' className)*)? templateBody
210+
;
211+
202212
//接口声明
203213
interfaceDeclaration
204214
: INTERFACE classWithoutNamespace (ARROW className (',' className)*)? interfaceBody
@@ -622,7 +632,7 @@ annotation
622632
;
623633

624634
annotationArgs
625-
: '<' value* '>'
635+
: '<' (value (',' value)*)? '>'
626636
;
627637

628638
range
@@ -631,11 +641,6 @@ range
631641
| '..' num2=var
632642
;
633643

634-
namespacePath
635-
: Identifier ':' Identifier ('/' Identifier)*
636-
;
637-
638-
639644
nbtValue
640645
: LineString
641646
| nbtBool

src/main/java/top/mcfpp/mni/minecraft/EntityVarData.java

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ public static void setAttributeBase(MCFloat value, String attribute, EntityVar c
6666
);
6767
}
6868
ArrayList<Command> commandList = new ArrayList<>(Arrays.asList(commands));
69-
var last = commandList.get(commandList.size() - 1);
69+
var last = commandList.getLast();
7070
if(last.isMacro()){
71-
commandList.remove(commandList.size() - 1);
71+
commandList.removeLast();
7272
commandList.addAll(Arrays.asList(last.buildMacroFunction()));
73-
returnValue.setValue(new CommandReturn(commandList.get(commandList.size() - 1), "return"));
73+
returnValue.setValue(new CommandReturn(commandList.getLast(), "return"));
7474
}else {
7575
returnValue.setValue(new CommandReturn(last, "return"));
7676
}
@@ -85,11 +85,11 @@ public static void getAttributeBase(String attribute, EntityVar caller, MCFloat
8585
buildingCommand = buildingCommand.buildMacro(scale, true);
8686
}
8787
ArrayList<Command> commands = new ArrayList<>(Arrays.stream(Commands.INSTANCE.runAsEntity(caller, buildingCommand)).toList());
88-
var last = commands.get(commands.size() - 1);
88+
var last = commands.getLast();
8989
if(last.isMacro()){
90-
commands.remove(commands.size() - 1);
90+
commands.removeLast();
9191
commands.addAll(Arrays.stream(last.buildMacroFunction()).toList());
92-
returnValue.setValue(new CommandReturn(commands.get(commands.size() - 1), "return"));
92+
returnValue.setValue(new CommandReturn(commands.getLast(), "return"));
9393
}else {
9494
returnValue.setValue(new CommandReturn(last, "return"));
9595
}
@@ -104,11 +104,11 @@ public static void getAttribute(String attribute, EntityVar caller, MCFloat scal
104104
buildingCommand = buildingCommand.buildMacro(scale, true);
105105
}
106106
ArrayList<Command> commands = new ArrayList<>(Arrays.stream(Commands.INSTANCE.runAsEntity(caller, buildingCommand)).toList());
107-
var last = commands.get(commands.size() - 1);
107+
var last = commands.getLast();
108108
if(last.isMacro()){
109-
commands.remove(commands.size() - 1);
109+
commands.removeLast();
110110
commands.addAll(Arrays.stream(last.buildMacroFunction()).toList());
111-
returnValue.setValue(new CommandReturn(commands.get(commands.size() - 1), "return"));
111+
returnValue.setValue(new CommandReturn(commands.getLast(), "return"));
112112
}else {
113113
returnValue.setValue(new CommandReturn(last, "return"));
114114
}
@@ -121,9 +121,8 @@ public static void addAttributeModifier(String attribute, EntityVar caller, Data
121121
commands = Commands.INSTANCE.runAsEntity(caller,
122122
new Command("return run attribute @s " + AttributeData.attributeMap.get(attribute) + " modifier add "
123123
+ modifierC.getValue().get("id", StringTag.class).getValue() + " "
124-
+ modifierC.getValue().get("value", DoubleTag.class).asDouble() + " "
125-
+ modifierC.getValue().get("operation", StringTag.class).getValue() + " "
126-
+ modifierC.getValue().get("mode", StringTag.class).getValue())
124+
+ modifierC.getValue().get("amount", DoubleTag.class).asDouble() + " "
125+
+ modifierC.getValue().get("operation", StringTag.class).getValue())
127126
);
128127
} else {
129128
var buildingCommand = new Command("return run attribute @s " + AttributeData.attributeMap.get(attribute) + " modifier add");
@@ -133,7 +132,7 @@ public static void addAttributeModifier(String attribute, EntityVar caller, Data
133132
}else {
134133
buildingCommand = buildingCommand.buildMacro(id, true);
135134
}
136-
var value = modifier.getMemberVar("value", Member.AccessModifier.PUBLIC).getFirst();
135+
var value = modifier.getMemberVar("amount", Member.AccessModifier.PUBLIC).getFirst();
137136
if(value instanceof MCFloatConcrete valueC){
138137
buildingCommand = buildingCommand.build(valueC.getValue().toString(), true);
139138
}else {
@@ -145,18 +144,12 @@ public static void addAttributeModifier(String attribute, EntityVar caller, Data
145144
}else {
146145
buildingCommand = buildingCommand.buildMacro(operation, true);
147146
}
148-
var mode = modifier.getMemberVar("mode", Member.AccessModifier.PUBLIC).getFirst();
149-
if(mode instanceof MCStringConcrete modeC){
150-
buildingCommand = buildingCommand.build(modeC.getValue().getValue(), true);
151-
}else {
152-
buildingCommand = buildingCommand.buildMacro(mode, true);
153-
}
154147
ArrayList<Command> commandArrayList = new ArrayList<>(Arrays.stream(Commands.INSTANCE.runAsEntity(caller, buildingCommand)).toList());
155-
var last = commandArrayList.get(commandArrayList.size() - 1);
148+
var last = commandArrayList.getLast();
156149
if(last.isMacro()){
157-
commandArrayList.remove(commandArrayList.size() - 1);
150+
commandArrayList.removeLast();
158151
commandArrayList.addAll(Arrays.stream(last.buildMacroFunction()).toList());
159-
returnValue.setValue(new CommandReturn(commandArrayList.get(commandArrayList.size() - 1), "return"));
152+
returnValue.setValue(new CommandReturn(commandArrayList.getLast(), "return"));
160153
}else {
161154
returnValue.setValue(new CommandReturn(last, "return"));
162155
}
@@ -182,11 +175,11 @@ public static void removeAttributeModifier(String attribute, EntityVar caller, D
182175
buildingCommand = buildingCommand.buildMacro(id, true);
183176
}
184177
ArrayList<Command> commandArrayList = new ArrayList<>(Arrays.stream(Commands.INSTANCE.runAsEntity(caller, buildingCommand)).toList());
185-
var last = commandArrayList.get(commandArrayList.size() - 1);
178+
var last = commandArrayList.getLast();
186179
if(last.isMacro()){
187-
commandArrayList.remove(commandArrayList.size() - 1);
180+
commandArrayList.removeLast();
188181
commandArrayList.addAll(Arrays.stream(last.buildMacroFunction()).toList());
189-
returnValue.setValue(new CommandReturn(commandArrayList.get(commandArrayList.size() - 1), "return"));
182+
returnValue.setValue(new CommandReturn(commandArrayList.getLast(), "return"));
190183
}else {
191184
returnValue.setValue(new CommandReturn(last, "return"));
192185
}
@@ -197,7 +190,6 @@ public static void removeAttributeModifier(String attribute, EntityVar caller, D
197190
}
198191

199192
public static void getAttributeModifier(String attribute, EntityVar caller, DataTemplateObject modifier, MCFloat scale, ValueWrapper<CommandReturn> returnValue){
200-
Command[] commands;
201193
var buildingCommand = new Command("attribute @s " + AttributeData.attributeMap.get(attribute) + " modifier value get");
202194
var id = modifier.getMemberVar("id", Member.AccessModifier.PUBLIC).getFirst();
203195

@@ -218,12 +210,12 @@ public static void getAttributeModifier(String attribute, EntityVar caller, Data
218210
buildingCommand.prepend("return run", true);
219211
}
220212
var commandArrayList = new ArrayList<>(Arrays.asList(Commands.INSTANCE.runAsEntity(caller, buildingCommand)));
221-
var last = commandArrayList.get(commandArrayList.size() - 1);
213+
var last = commandArrayList.getLast();
222214
if(last.isMacro()){
223-
commandArrayList.remove(commandArrayList.size() - 1);
215+
commandArrayList.removeLast();
224216
commandArrayList.addAll(Arrays.stream(last.buildMacroFunction()).toList());
225217
}
226-
returnValue.setValue(new CommandReturn(commandArrayList.get(commandArrayList.size() - 1), "return"));
218+
returnValue.setValue(new CommandReturn(commandArrayList.getLast(), "return"));
227219
Function.Companion.addCommands(commandArrayList.toArray(new Command[0]));
228220
}
229221
}

src/main/kotlin/top/mcfpp/antlr/MCFPPExprVisitor.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,6 @@ class MCFPPExprVisitor(private var defaultGenericClassType : MCFPPGenericClassTy
636636

637637

638638
override fun visitNbtValue(ctx: mcfppParser.NbtValueContext): Var<*> {
639-
val qwq: Byte = 1;
640639
if(ctx.LineString() != null) {
641640
return NBTBasedDataConcrete(StringTag(ctx.LineString().text))
642641
}else if(ctx.nbtBool() != null){

src/main/kotlin/top/mcfpp/model/DataTemplate.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ import top.mcfpp.core.lang.DataTemplateObject
66
import top.mcfpp.core.lang.MCAny
77
import top.mcfpp.core.lang.UnknownVar
88
import top.mcfpp.core.lang.Var
9-
import top.mcfpp.type.MCFPPDataTemplateType
10-
import top.mcfpp.mni.DataObjectData
119
import top.mcfpp.model.accessor.Property
1210
import top.mcfpp.model.field.CompoundDataField
1311
import top.mcfpp.model.function.DataTemplateConstructor
1412
import top.mcfpp.model.function.Function
1513
import top.mcfpp.type.MCFPPBaseType
14+
import top.mcfpp.type.MCFPPDataTemplateType
1615
import top.mcfpp.type.MCFPPType
1716
import top.mcfpp.util.LogProcessor
18-
import kotlin.collections.ArrayList
1917

2018
/**
2119
* 结构体是一种和类的语法极为相似的数据结构。在结构体中,只能有int类型的数据,或者说记分板的数据作为结构体的成员。
@@ -116,30 +114,37 @@ open class DataTemplate : FieldContainer, CompoundData {
116114
is Property -> {
117115
field.putProperty(member.identifier, member)
118116
}
119-
else -> TODO()
117+
else -> {
118+
throw IllegalArgumentException("")
119+
}
120120
}
121121
}
122122

123123
override fun extends(compoundData: CompoundData): CompoundData {
124124
super.extends(compoundData)
125+
if(parent.contains(compoundData)){
126+
LogProcessor.warn("Already extends template '${compoundData.identifier}'")
127+
return this
128+
}
125129
//把所有成员都塞进去
126130
compoundData.field.forEachVar {
127131
val b = field.getVar(it.identifier) != null
128132
if(b){
129-
LogProcessor.warn("Duplicate var ${it.identifier} in template ${compoundData.identifier}. Overriding it.")
133+
LogProcessor.warn("Duplicate var '${it.identifier}' in template '${compoundData.identifier}'. Overriding it.")
130134
}
131135
field.putVar(it.identifier, it, true)
132136
}
133137
compoundData.field.forEachProperty {
134138
val b = field.getProperty(it.identifier) != null
135139
if(b){
136-
LogProcessor.warn("Duplicate property ${it.identifier} in template ${compoundData.identifier}. Overriding it.")
140+
LogProcessor.warn("Duplicate property '${it.identifier}' in template '${compoundData.identifier}'. Overriding it.")
137141
}
138142
field.putProperty(it.identifier, it, true)
139143
}
140144
return this
141145
}
142146

147+
//TODO 不能正常检测循环引用
143148
fun ifInfinitiveReference(template: DataTemplate): Boolean{
144149
return template == this && reference.any { it == template || it.ifInfinitiveReference(template) }
145150
}

src/main/kotlin/top/mcfpp/model/function/ClassConstructor.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,19 @@ open class ClassConstructor
3939
}
4040
funcs.append("}")
4141
//对象实体创建
42-
if(target.baseEntity == Class.ENTITY_MARKER){
43-
addCommand("data merge entity @s {Tags:[${target.tag},${target.tag}_data,mcfpp_ptr,just],data:{$funcs}}")
44-
}else if(target.baseEntity == Class.ENTITY_ITEM_DISPLAY){
45-
addCommand("data modify entity @s item.components.\"minecraft:custom_data\".mcfppData set value {Tags:[${target.tag},${target.tag}_data,mcfpp_ptr,just],data:{$funcs}}")
46-
}else{
47-
addCommand("tag @s add ${target.tag}")
48-
addCommand("summon marker ~ ~ ~ {Tags:[${target.tag}_data,mcfpp_ptr,just],data:{$funcs}}")
49-
addCommand("ride @n[tag=just, type=marker] mount @s")
50-
addCommand("tag @n[tag=just, type=marker] remove just")
42+
when (target.baseEntity) {
43+
Class.ENTITY_MARKER -> {
44+
addCommand("data merge entity @s {Tags:[${target.tag},${target.tag}_data,mcfpp_ptr,just],data:{$funcs}}")
45+
}
46+
Class.ENTITY_ITEM_DISPLAY -> {
47+
addCommand("data modify entity @s item.components.\"minecraft:custom_data\".mcfppData set value {Tags:[${target.tag},${target.tag}_data,mcfpp_ptr,just],data:{$funcs}}")
48+
}
49+
else -> {
50+
addCommand("tag @s add ${target.tag}")
51+
addCommand("summon marker ~ ~ ~ {Tags:[${target.tag}_data,mcfpp_ptr,just],data:{$funcs}}")
52+
addCommand("ride @n[tag=just, type=marker] mount @s")
53+
addCommand("tag @n[tag=just, type=marker] remove just")
54+
}
5155
}
5256
//初始指针
5357
addCommand(Command("data modify").build(Class.tempPtr.toCommandPart()).build("set from entity @s UUID"))

src/main/mcfpp/minecraft/Attribute.mcfpp

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
data AIMobData {
2+
@Name<"ArmorDropChances">
3+
list<float> armorDropChances;
4+
5+
@Name<"ArmorItems">
6+
list<Item> armorItems;
7+
8+
@Name<"body_armor_drop_chance">
9+
float bodyArmorDropChance;
10+
11+
@Name<"body_armor_item">
12+
list<Item> bodyArmorItem;
13+
14+
@Name<"CanPickUpLoot">
15+
bool canPickUpLoot;
16+
17+
@Name<"DeathLootTable">
18+
list<AIMobData> deathLootTable;
19+
20+
@Name<"DeathLootTableSeed">
21+
long deathLootTableSeed;
22+
23+
@Name<"HandDropChances">
24+
list<float> handDropChances;
25+
26+
@Name<"HandItems">
27+
list<Item> handItems;
28+
29+
@Name<"leash">
30+
(IntArray|nbt) leash;
31+
32+
@Name<"LeftHanded">
33+
bool leftHanded;
34+
35+
@Name<"NoAI">
36+
bool noAI;
37+
38+
@Name<"PersistenceRequired">
39+
bool persistenceRequired;
40+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
data Allay: EntityData, AIMobData, CreatureData {
2+
@Name<"CanDuplicate">
3+
byte canDuplicate;
4+
5+
@Name<"DuplicationCooldown">
6+
long duplicationCooldown;
7+
8+
@Name<"Inventory">
9+
list<Item> inventory;
10+
11+
@Name<"Listener">
12+
Listener listener;
13+
}
14+
15+
data Listener {
16+
data event {
17+
float distance;
18+
19+
@Name<"game_event">
20+
string gameEvent;
21+
22+
list<double> pos;
23+
24+
@Name<"projectile_owner">
25+
IntArray projectileOwner;
26+
27+
IntArray source;
28+
}
29+
30+
@Name<"event_delay">
31+
int eventDelay;
32+
33+
@Name<"selector">
34+
data _selector {
35+
long tick;
36+
37+
data event {
38+
float distance;
39+
40+
@Name<"game_event">
41+
string gameEvent;
42+
43+
list<double> pos;
44+
45+
@Name<"projectile_owner">
46+
IntArray projectileOwner;
47+
48+
IntArray source;
49+
}
50+
}
51+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
data AnimalData{
2+
@Name<"InLove">
3+
int inLove;
4+
5+
@Name<"LoveCause">
6+
IntArray loveCause;
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
data Armadillo: EntityData, CreatureData, AIMobData, GrowableData, AnimalData {
2+
@Name<"Scute_Time">
3+
int scuteTime;
4+
5+
@Name<"State">
6+
ArmadilloState state;
7+
}
8+
9+
enum ArmadilloState {
10+
idle,
11+
rolling,
12+
scared
13+
}

0 commit comments

Comments
 (0)