From 780e41f130d12a2a3c3395e3e601c4da5104f08d Mon Sep 17 00:00:00 2001 From: cosmeak Date: Fri, 16 Jan 2026 15:22:35 +0100 Subject: [PATCH] wip: predicate --- .../conditions/damage_source_properties.go | 4 +- predicate/entity.go | 123 ----------- predicate/subpredicate/distance.go | 9 + predicate/subpredicate/effect.go | 10 + predicate/subpredicate/entity.go | 39 ++++ .../{ => subpredicate}/entity_to_check.go | 2 +- .../subpredicate/entity_type_specific.go | 192 ++++++++++++++++++ predicate/subpredicate/equipement.go | 9 + predicate/subpredicate/equipement_slot.go | 13 ++ predicate/subpredicate/location.go | 26 +++ predicate/subpredicate/min_max.go | 11 + predicate/subpredicate/movement.go | 11 + predicate/subpredicate/slot.go | 9 + 13 files changed, 332 insertions(+), 126 deletions(-) delete mode 100644 predicate/entity.go create mode 100644 predicate/subpredicate/distance.go create mode 100644 predicate/subpredicate/effect.go create mode 100644 predicate/subpredicate/entity.go rename predicate/{ => subpredicate}/entity_to_check.go (94%) create mode 100644 predicate/subpredicate/entity_type_specific.go create mode 100644 predicate/subpredicate/equipement.go create mode 100644 predicate/subpredicate/equipement_slot.go create mode 100644 predicate/subpredicate/location.go create mode 100644 predicate/subpredicate/min_max.go create mode 100644 predicate/subpredicate/movement.go create mode 100644 predicate/subpredicate/slot.go diff --git a/predicate/conditions/damage_source_properties.go b/predicate/conditions/damage_source_properties.go index 5839f82..ed14419 100644 --- a/predicate/conditions/damage_source_properties.go +++ b/predicate/conditions/damage_source_properties.go @@ -1,10 +1,10 @@ package conditions import ( - "tangled.org/cosmeak.tngl.sh/weave/predicate" "tangled.org/cosmeak.tngl.sh/weave/predicate/internal/condition" + "tangled.org/cosmeak.tngl.sh/weave/predicate/subpredicate" ) -func DamageSourceProperties(name string, directEntity predicate.Entity, sourceEntity predicate.Entity, isDirect bool, tags []string) condition.Condition { +func DamageSourceProperties(name string, directEntity subpredicate.Entity, sourceEntity subpredicate.Entity, isDirect bool, tags []string) condition.Condition { // todo } diff --git a/predicate/entity.go b/predicate/entity.go deleted file mode 100644 index 447c93d..0000000 --- a/predicate/entity.go +++ /dev/null @@ -1,123 +0,0 @@ -package predicate - -type minMaxInt struct { - Min int - Max int -} - -type minMaxDouble struct { - Min float64 - Max float64 -} - -type Entity struct { - type_ []string - // components - distance Distance - effects []Effect - equipement []Equipement - flags EntityFlag - location Location - nbt string - passenger *Entity - slots []Slot - steppingOn Location - movementAffectedBy Location - team string - targetedEntity *Entity - vehicle *Entity - movement Movement - periodicTick int - // predicates - -} - -type Distance struct { - Absolute float32 - Horizontal float32 - X float32 - Y float32 - Z float32 -} - -// todo: Amplifier and Duration can be an object with min and max value -type Effect struct { - Name string - Amplifier int - Duration int - Ambiant bool - Visible bool -} - -type EquipementSlot string - -const ( - MainHand EquipementSlot = "mainhand" - OffHand EquipementSlot = "offhand" - Head EquipementSlot = "head" - Chest EquipementSlot = "chest" - Legs EquipementSlot = "legs" - Feet EquipementSlot = "feet" - Body EquipementSlot = "body" -) - -type Equipement struct { - Slot EquipementSlot - Items []string - Count minMaxInt - // Components - // Predicates -} - -type EntityFlag struct { - IsBaby bool - IsOnFire bool - IsSneaking bool - IsSprinting bool - IsSwimming bool - IsOnGround bool - IsFlying bool -} - -type Location struct { - Biome []string - Block struct { - Blocks []string - Nbt string - State map[string]string - // Components - // Predicates - } - Dimension string - Fluid struct { - Fluids []string - State map[string]string - } - Light minMaxInt - Position struct { - X minMaxDouble - Y minMaxDouble - Z minMaxDouble - } - Smokey bool - CanSeeSky bool - Structures []string -} - -type Slot struct { - Range string - Items []string - Count minMaxInt - // Components - // Predicatess -} - -type Movement struct { - X minMaxDouble - Y minMaxDouble - Z minMaxDouble - Speed minMaxDouble - HorizontalSpeed minMaxDouble - VerticalSpeed minMaxDouble - FallDistance minMaxDouble -} diff --git a/predicate/subpredicate/distance.go b/predicate/subpredicate/distance.go new file mode 100644 index 0000000..66f8bd2 --- /dev/null +++ b/predicate/subpredicate/distance.go @@ -0,0 +1,9 @@ +package subpredicate + +type Distance struct { + Absolute float32 + Horizontal float32 + X float32 + Y float32 + Z float32 +} diff --git a/predicate/subpredicate/effect.go b/predicate/subpredicate/effect.go new file mode 100644 index 0000000..6a104b6 --- /dev/null +++ b/predicate/subpredicate/effect.go @@ -0,0 +1,10 @@ +package subpredicate + +// todo: Amplifier and Duration can be an object with min and max value +type Effect struct { + Name string + Amplifier int + Duration int + Ambiant bool + Visible bool +} diff --git a/predicate/subpredicate/entity.go b/predicate/subpredicate/entity.go new file mode 100644 index 0000000..bbb3df4 --- /dev/null +++ b/predicate/subpredicate/entity.go @@ -0,0 +1,39 @@ +package subpredicate + +type Entity struct { + Type []string + Components []Component + Distance Distance + Effects []Effect + Equipement []Equipement + Flags EntityFlag + Location Location + Nbt string + Passenger *Entity + Slots []Slot + SteppingOn Location + MovementAffectedBy Location + Team string + TargetedEntity *Entity + Vehicle *Entity + Movement Movement + PeriodicTick int + Predicates []PredicateComponent + TypeSpecific EntityTypeSpecific + SourceEntity *Entity + IsDirect bool + tags []struct { + Id string + Expected bool + } +} + +type EntityFlag struct { + IsBaby bool + IsOnFire bool + IsSneaking bool + IsSprinting bool + IsSwimming bool + IsOnGround bool + IsFlying bool +} diff --git a/predicate/entity_to_check.go b/predicate/subpredicate/entity_to_check.go similarity index 94% rename from predicate/entity_to_check.go rename to predicate/subpredicate/entity_to_check.go index 7ee0e5c..5e87332 100644 --- a/predicate/entity_to_check.go +++ b/predicate/subpredicate/entity_to_check.go @@ -1,4 +1,4 @@ -package predicate +package subpredicate type EntityToCheck string diff --git a/predicate/subpredicate/entity_type_specific.go b/predicate/subpredicate/entity_type_specific.go new file mode 100644 index 0000000..d4ddd72 --- /dev/null +++ b/predicate/subpredicate/entity_type_specific.go @@ -0,0 +1,192 @@ +package subpredicate + +type EntityTypeSpecific struct { + Type string + Fields map[string]any +} + +func AxolotlTypeSpecific(variant string) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "axolotl", + Fields: map[string]any{ + "variant": variant, + }, + } +} + +func CatTypeSpecific(variants ...string) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "cat", + Fields: map[string]any{ + "variant": variants, + }, + } +} + +func FishingHookTypeSpecific(inOpenWater bool) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "cat", + Fields: map[string]any{ + "in_open_water": inOpenWater, + }, + } +} + +func FoxTypeSpecific(variant string) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "fox", + Fields: map[string]any{ + "variant": variant, + }, + } +} + +func FrogTypeSpecific(variants ...string) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "frog", + Fields: map[string]any{ + "variant": variants, + }, + } +} + +func HorseTypeSpecific(variant string) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "horse", + Fields: map[string]any{ + "variant": variant, + }, + } +} + +func LightningTypeSpecific(blocksSetOnFire MinMaxInt, entityStruck Entity) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "lightning", + Fields: map[string]any{ + "blocks_set_on_fire": blocksSetOnFire, + "entity_struck": entityStruck, + }, + } +} + +func LlamaTypeSpecific(variant string) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "llama", + Fields: map[string]any{ + "variant": variant, + }, + } +} + +func MooshroomTypeSpecific(variant string) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "mooshroom", + Fields: map[string]any{ + "variant": variant, + }, + } +} + +func PaintingTypeSpecific(variants ...string) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "painting", + Fields: map[string]any{ + "variant": variants, + }, + } +} + +func ParrotTypeSpecific(variant string) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "parrot", + Fields: map[string]any{ + "variant": variant, + }, + } +} + +func PlayerTypeSpecific(lookingAt Entity) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "player", + Fields: map[string]any{ + // + }, + } +} + +func RabbitTypeSpecific(variant string) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "rabbit", + Fields: map[string]any{ + "variant": variant, + }, + } +} + +func RaiderTypeSpecific(isCaptain, hasRaid bool) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "raider", + Fields: map[string]any{ + "is_captain": isCaptain, + "has_raid": hasRaid, + }, + } +} + +func SalmonTypeSpecific(variant string) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "salmon", + Fields: map[string]any{ + "variant": variant, + }, + } +} + +func SheepTypeSpecific(sheared bool, variant string) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "sheep", + Fields: map[string]any{ + "sheared": sheared, + "variant": variant, + }, + } +} + +func SlimeTypeSpecific(min, max int) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "slime", + Fields: map[string]any{ + "size": map[string]int{ + "min": min, + "max": max, + }, + }, + } +} + +func TropicalFishTypeSpecific(variant string) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "tropical_fish", + Fields: map[string]any{ + "variant": variant, + }, + } +} + +func VillagerTypeSpecific(variant string) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "villager", + Fields: map[string]any{ + "variant": variant, + }, + } +} + +func WolfTypeSpecific(variants ...string) EntityTypeSpecific { + return EntityTypeSpecific{ + Type: "wolf", + Fields: map[string]any{ + "variant": variants, + }, + } +} diff --git a/predicate/subpredicate/equipement.go b/predicate/subpredicate/equipement.go new file mode 100644 index 0000000..12205d6 --- /dev/null +++ b/predicate/subpredicate/equipement.go @@ -0,0 +1,9 @@ +package subpredicate + +type Equipement struct { + Slot EquipementSlot + Items []string + Count MinMaxInt + // Components + // Predicates +} diff --git a/predicate/subpredicate/equipement_slot.go b/predicate/subpredicate/equipement_slot.go new file mode 100644 index 0000000..f4b1151 --- /dev/null +++ b/predicate/subpredicate/equipement_slot.go @@ -0,0 +1,13 @@ +package subpredicate + +type EquipementSlot string + +const ( + MainHand EquipementSlot = "mainhand" + OffHand EquipementSlot = "offhand" + Head EquipementSlot = "head" + Chest EquipementSlot = "chest" + Legs EquipementSlot = "legs" + Feet EquipementSlot = "feet" + Body EquipementSlot = "body" +) diff --git a/predicate/subpredicate/location.go b/predicate/subpredicate/location.go new file mode 100644 index 0000000..0c4b14f --- /dev/null +++ b/predicate/subpredicate/location.go @@ -0,0 +1,26 @@ +package subpredicate + +type Location struct { + Biome []string + Block struct { + Blocks []string + Nbt string + State map[string]string + // Components + // Predicates + } + Dimension string + Fluid struct { + Fluids []string + State map[string]string + } + Light MinMaxInt + Position struct { + X MinMaxDouble + Y MinMaxDouble + Z MinMaxDouble + } + Smokey bool + CanSeeSky bool + Structures []string +} diff --git a/predicate/subpredicate/min_max.go b/predicate/subpredicate/min_max.go new file mode 100644 index 0000000..36baf24 --- /dev/null +++ b/predicate/subpredicate/min_max.go @@ -0,0 +1,11 @@ +package subpredicate + +type MinMaxInt struct { + Min int + Max int +} + +type MinMaxDouble struct { + Min float64 + Max float64 +} diff --git a/predicate/subpredicate/movement.go b/predicate/subpredicate/movement.go new file mode 100644 index 0000000..fb31cbd --- /dev/null +++ b/predicate/subpredicate/movement.go @@ -0,0 +1,11 @@ +package subpredicate + +type Movement struct { + X MinMaxDouble + Y MinMaxDouble + Z MinMaxDouble + Speed MinMaxDouble + HorizontalSpeed MinMaxDouble + VerticalSpeed MinMaxDouble + FallDistance MinMaxDouble +} diff --git a/predicate/subpredicate/slot.go b/predicate/subpredicate/slot.go new file mode 100644 index 0000000..3bacdc4 --- /dev/null +++ b/predicate/subpredicate/slot.go @@ -0,0 +1,9 @@ +package subpredicate + +type Slot struct { + Range string + Items []string + Count MinMaxInt + // Components + // Predicatess +} -- 2.51.2