Compare commits
27 Commits
alpha-1.0.
...
1.21.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3dc05dc6d0 | ||
|
|
99f5a85404 | ||
|
|
b269b12ea2 | ||
|
|
5582f593aa | ||
|
|
d3fed02fda | ||
|
|
f70415c49c | ||
|
|
36521b1cba | ||
|
|
784cae8e9c | ||
|
|
e908e2f5e1 | ||
|
|
b1c67f3e6b | ||
|
|
21d9716bcc | ||
|
|
ea3a57d70d | ||
|
|
ee3cb071d7 | ||
|
|
2b6f231efc | ||
|
|
135f495849 | ||
|
|
4d774a875f | ||
|
|
b6af4b2c18 | ||
|
|
d0cf1a2a29 | ||
|
|
d6028ab375 | ||
|
|
ecddd67a18 | ||
|
|
a330813d38 | ||
|
|
09048cc006 | ||
|
|
5423bf54fd | ||
|
|
154a44bfab | ||
|
|
9423ca840e | ||
|
|
f856281889 | ||
|
|
5eaf45a113 |
27
Readme.md
Normal file
27
Readme.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Maid Useful Tasks
|
||||||
|
|
||||||
|
如果需要中文,请访问 [中文版](Readme_zh.md)
|
||||||
|
|
||||||
|
An extension mod of TLM(Touhou Little Maid). Add some useful tasks to your Maid.
|
||||||
|
|
||||||
|
# Features
|
||||||
|
|
||||||
|
## Logging
|
||||||
|
|
||||||
|
The maid will cut down the logs around her and plant saplings. You can give the maid an axe and hoe or scissors to speed
|
||||||
|
up the maid's ability to cut down trees and destroy leaves!
|
||||||
|
|
||||||
|
## Locate
|
||||||
|
|
||||||
|
The maid will search for a specified structure or the player's respawn point based on the item in her hand. If the maid is on the same vehicle as the player (currently only brooms are supported), the player can press a designated button (V by default) to give the maid control or partial control of the carrier.
|
||||||
|
|
||||||
|
## Revive
|
||||||
|
|
||||||
|
Requires "Player Revive" mod.
|
||||||
|
|
||||||
|
The Maid will revive nearby fallen players. If there is an undead totem in the Maid's bauble, the Maid will use one (The maid consumes a totem to skip your revive countdown, instead of just consuming the totem to not die like that in vanilla).
|
||||||
|
|
||||||
|
# More
|
||||||
|
|
||||||
|
+ The Mod is currently in early development. Everything may change in the future.
|
||||||
|
+ Some content maybe move to the TLM Mod in the future.
|
||||||
26
Readme_zh.md
Normal file
26
Readme_zh.md
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# Maid Useful Tasks
|
||||||
|
|
||||||
|
For English version, visit [English Version](Readme.md)
|
||||||
|
|
||||||
|
一个车万女仆的拓展模组,添加了一些实用的女仆任务。
|
||||||
|
|
||||||
|
# Features
|
||||||
|
|
||||||
|
## Logging
|
||||||
|
|
||||||
|
女仆会砍伐身边的原木并种下树苗。你可以给女仆斧头和锄头或剪刀来加速女仆砍树和破坏树叶的速度。
|
||||||
|
|
||||||
|
## Locate
|
||||||
|
|
||||||
|
女仆会根据手上的物品寻找指定的结构或者玩家出生点。如果女仆和玩家在同一载具上(目前只支持扫帚),玩家可以按下指定按键(默认为V)来让女仆控制或部分控制载具。
|
||||||
|
|
||||||
|
## Revive
|
||||||
|
|
||||||
|
需要`玩家救援`模组
|
||||||
|
|
||||||
|
女仆会救援附近倒地的玩家。如果女仆饰品中有不死图腾,则女仆会使用一个。(女仆会消耗一个图腾来跳过你的复活倒计时,而不是像原版一样直接消耗图腾来不死)
|
||||||
|
|
||||||
|
# More
|
||||||
|
|
||||||
|
+ 模组处于早期开发阶段,一切功能在未来都有可能变化。
|
||||||
|
+ 模型的一些内容可能会直接合并到TLM中。
|
||||||
257
build.gradle
257
build.gradle
@@ -1,129 +1,90 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
// These repositories are only for Gradle plugins, put any other repositories in the repository block further below
|
|
||||||
maven { url = 'https://repo.spongepowered.org/repository/maven-public/' }
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
dependencies {
|
|
||||||
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'eclipse'
|
|
||||||
id 'idea'
|
id 'idea'
|
||||||
id 'net.minecraftforge.gradle' version '[6.0.16,6.2)'
|
id 'java-library'
|
||||||
|
id 'maven-publish'
|
||||||
|
id 'net.neoforged.moddev' version '2.0.89'
|
||||||
|
}
|
||||||
|
tasks.named('wrapper', Wrapper).configure {
|
||||||
|
// Define wrapper values here so as to not have to always do so when updating gradlew.properties.
|
||||||
|
// Switching this to Wrapper.DistributionType.ALL will download the full gradle sources that comes with
|
||||||
|
// documentation attached on cursor hover of gradle classes and methods. However, this comes with increased
|
||||||
|
// file size for Gradle. If you do switch this to ALL, run the Gradle wrapper task twice afterwards.
|
||||||
|
// (Verify by checking gradle/wrapper/gradle-wrapper.properties to see if distributionUrl now points to `-all`)
|
||||||
|
distributionType = Wrapper.DistributionType.BIN
|
||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'org.spongepowered.mixin'
|
|
||||||
|
|
||||||
group = mod_group_id
|
group = mod_group_id
|
||||||
version = mod_version
|
version = mod_version
|
||||||
|
|
||||||
base {
|
base {
|
||||||
archivesName = mod_id
|
archivesName = minecraft_version + "-" + mod_id
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
// Mojang ships Java 21 to end users starting in 1.20.5, so mods should target Java 21.
|
||||||
toolchain.languageVersion = JavaLanguageVersion.of(17)
|
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
|
||||||
}
|
java.withSourcesJar()
|
||||||
|
|
||||||
minecraft {
|
neoForge {
|
||||||
// The mappings can be changed at any time and must be in the following format.
|
// Specify the version of NeoForge to use.
|
||||||
// Channel: Version:
|
version = project.neo_version
|
||||||
// official MCVersion Official field/method names from Mojang mapping files
|
|
||||||
// parchment YYYY.MM.DD-MCVersion Open community-sourced parameter names and javadocs layered on top of official
|
|
||||||
//
|
|
||||||
// You must be aware of the Mojang license when using the 'official' or 'parchment' mappings.
|
|
||||||
// See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md
|
|
||||||
//
|
|
||||||
// Parchment is an unofficial project maintained by ParchmentMC, separate from MinecraftForge
|
|
||||||
// Additional setup is needed to use their mappings: https://parchmentmc.org/docs/getting-started
|
|
||||||
//
|
|
||||||
// Use non-default mappings at your own risk. They may not always work.
|
|
||||||
// Simply re-run your setup task after changing the mappings to update your workspace.
|
|
||||||
mappings channel: mapping_channel, version: mapping_version
|
|
||||||
|
|
||||||
// When true, this property will have all Eclipse/IntelliJ IDEA run configurations run the "prepareX" task for the given run configuration before launching the game.
|
|
||||||
// In most cases, it is not necessary to enable.
|
|
||||||
// enableEclipsePrepareRuns = true
|
|
||||||
// enableIdeaPrepareRuns = true
|
|
||||||
|
|
||||||
// This property allows configuring Gradle's ProcessResources task(s) to run on IDE output locations before launching the game.
|
|
||||||
// It is REQUIRED to be set to true for this template to function.
|
|
||||||
// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
|
|
||||||
copyIdeResources = true
|
|
||||||
|
|
||||||
// When true, this property will add the folder name of all declared run configurations to generated IDE run configurations.
|
|
||||||
// The folder name can be set on a run configuration using the "folderName" property.
|
|
||||||
// By default, the folder name of a run configuration is the name of the Gradle project containing it.
|
|
||||||
// generateRunFolders = true
|
|
||||||
|
|
||||||
// This property enables access transformers for use in development.
|
|
||||||
// They will be applied to the Minecraft artifact.
|
|
||||||
// The access transformer file can be anywhere in the project.
|
|
||||||
// However, it must be at "META-INF/accesstransformer.cfg" in the final mod jar to be loaded by Forge.
|
|
||||||
// This default location is a best practice to automatically put the file in the right place in the final jar.
|
|
||||||
// See https://docs.minecraftforge.net/en/latest/advanced/accesstransformers/ for more information.
|
|
||||||
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
|
|
||||||
|
|
||||||
// Default run configurations.
|
|
||||||
// These can be tweaked, removed, or duplicated as needed.
|
|
||||||
runs {
|
runs {
|
||||||
// applies to all the run configs below
|
|
||||||
configureEach {
|
|
||||||
workingDirectory project.file('run')
|
|
||||||
|
|
||||||
// Recommended logging data for a userdev environment
|
|
||||||
// The markers can be added/remove as needed separated by commas.
|
|
||||||
// "SCAN": For mods scan.
|
|
||||||
// "REGISTRIES": For firing of registry events.
|
|
||||||
// "REGISTRYDUMP": For getting the contents of all registries.
|
|
||||||
property 'forge.logging.markers', 'REGISTRIES'
|
|
||||||
|
|
||||||
|
|
||||||
// Recommended logging level for the console
|
|
||||||
// You can set various levels here.
|
|
||||||
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
|
|
||||||
property 'forge.logging.console.level', 'debug'
|
|
||||||
|
|
||||||
|
|
||||||
jvmArg "-XX:+AllowEnhancedClassRedefinition"
|
|
||||||
}
|
|
||||||
|
|
||||||
client {
|
client {
|
||||||
|
client()
|
||||||
|
|
||||||
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
|
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
|
||||||
property 'forge.enabledGameTestNamespaces', mod_id
|
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
|
||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
property 'forge.enabledGameTestNamespaces', mod_id
|
server()
|
||||||
args '--nogui'
|
programArgument '--nogui'
|
||||||
|
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
|
||||||
}
|
}
|
||||||
|
|
||||||
// This run config launches GameTestServer and runs all registered gametests, then exits.
|
// This run config launches GameTestServer and runs all registered gametests, then exits.
|
||||||
// By default, the server will crash when no gametests are provided.
|
// By default, the server will crash when no gametests are provided.
|
||||||
// The gametest system is also enabled by default for other run configs under the /test command.
|
// The gametest system is also enabled by default for other run configs under the /test command.
|
||||||
gameTestServer {
|
gameTestServer {
|
||||||
property 'forge.enabledGameTestNamespaces', mod_id
|
type = "gameTestServer"
|
||||||
|
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
|
||||||
}
|
}
|
||||||
|
|
||||||
data {
|
data {
|
||||||
// example of overriding the workingDirectory set in configureEach above
|
data()
|
||||||
workingDirectory project.file('run-data')
|
|
||||||
|
// example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it
|
||||||
|
// gameDirectory = project.file('run-data')
|
||||||
|
|
||||||
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
|
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
|
||||||
args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
|
programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
|
||||||
|
}
|
||||||
|
|
||||||
|
// applies to all the run configs above
|
||||||
|
configureEach {
|
||||||
|
// Recommended logging data for a userdev environment
|
||||||
|
// The markers can be added/remove as needed separated by commas.
|
||||||
|
// "SCAN": For mods scan.
|
||||||
|
// "REGISTRIES": For firing of registry events.
|
||||||
|
// "REGISTRYDUMP": For getting the contents of all registries.
|
||||||
|
systemProperty 'forge.logging.markers', 'REGISTRIES'
|
||||||
|
|
||||||
|
// Recommended logging level for the console
|
||||||
|
// You can set various levels here.
|
||||||
|
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
|
||||||
|
logLevel = org.slf4j.event.Level.DEBUG
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mods {
|
||||||
|
// define mod <-> source bindings
|
||||||
|
// these are used to tell the game which sources are for which mod
|
||||||
|
// mostly optional in a single mod project
|
||||||
|
// but multi mod projects should define one per mod
|
||||||
|
"${mod_id}" {
|
||||||
|
sourceSet(sourceSets.main)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mixin {
|
|
||||||
add sourceSets.main, "${mod_id}.refmap.json"
|
|
||||||
|
|
||||||
config "${mod_id}.mixins.json"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Include resources generated by data generators.
|
// Include resources generated by data generators.
|
||||||
sourceSets.main.resources { srcDir 'src/generated/resources' }
|
sourceSets.main.resources { srcDir 'src/generated/resources' }
|
||||||
|
|
||||||
@@ -133,80 +94,74 @@ repositories {
|
|||||||
|
|
||||||
// If you have mod jar dependencies in ./libs, you can declare them as a repository like so.
|
// If you have mod jar dependencies in ./libs, you can declare them as a repository like so.
|
||||||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html#sub:flat_dir_resolver
|
// See https://docs.gradle.org/current/userguide/declaring_repositories.html#sub:flat_dir_resolver
|
||||||
// flatDir {
|
flatDir {
|
||||||
// dir 'libs'
|
dir 'libs'
|
||||||
// }
|
}
|
||||||
maven {
|
maven {
|
||||||
url "https://cursemaven.com"
|
url "https://cursemaven.com"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// Specify the version of Minecraft to use.
|
compileOnly "curse.maven:touhou-little-maid-355044:6988538"
|
||||||
// Any artifact can be supplied so long as it has a "userdev" classifier artifact and is a compatible patcher artifact.
|
runtimeOnly "curse.maven:touhou-little-maid-355044:6988538"
|
||||||
// The "userdev" classifier will be requested and setup by ForgeGradle.
|
// compileOnly "libs:touhoulittlemaid-${minecraft_version}-release:1.3.7"
|
||||||
// If the group id is "net.minecraft" and the artifact id is one of ["client", "server", "joined"],
|
// runtimeOnly "libs:touhoulittlemaid-${minecraft_version}-release:1.3.7"
|
||||||
// then special handling is done to allow a setup of a vanilla dependency without the use of an external repository.
|
|
||||||
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
|
|
||||||
|
|
||||||
// Example mod dependency with JEI - using fg.deobf() ensures the dependency is remapped to your development mappings
|
compileOnly "curse.maven:playerrevive-266890:6383797"
|
||||||
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
|
compileOnly "curse.maven:creativecore-257814:6690762"
|
||||||
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-common-api:${jei_version}")
|
compileOnly "curse.maven:natures-compass-252848:5696042"
|
||||||
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-forge-api:${jei_version}")
|
compileOnly "curse.maven:explorers-compass-491794:5756947"
|
||||||
// runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}-forge:${jei_version}")
|
// runtimeOnly "curse.maven:playerrevive-266890:6383797"
|
||||||
|
runtimeOnly "curse.maven:creativecore-257814:6690762"
|
||||||
// Example mod dependency using a mod jar from ./libs with a flat dir repository
|
// runtimeOnly "curse.maven:natures-compass-252848:5696042"
|
||||||
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
|
// runtimeOnly "curse.maven:explorers-compass-491794:5756947"
|
||||||
// The group id is ignored when searching -- in this case, it is "blank"
|
|
||||||
// implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}")
|
|
||||||
|
|
||||||
// For more info:
|
|
||||||
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
|
|
||||||
// http://www.gradle.org/docs/current/userguide/dependency_management.html
|
|
||||||
|
|
||||||
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
|
|
||||||
compileOnly fg.deobf("curse.maven:touhou-little-maid-355044:6440955")
|
|
||||||
runtimeOnly fg.deobf("curse.maven:touhou-little-maid-355044:6440955")
|
|
||||||
runtimeOnly fg.deobf("curse.maven:maid-storage-manager-1210244:6455832")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This block of code expands all declared replace properties in the specified resource targets.
|
var generateModMetadata = tasks.register("generateModMetadata", ProcessResources) {
|
||||||
// A missing property will result in an error. Properties are expanded using ${} Groovy notation.
|
|
||||||
// When "copyIdeResources" is enabled, this will also run before the game launches in IDE environments.
|
|
||||||
// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
|
|
||||||
tasks.named('processResources', ProcessResources).configure {
|
|
||||||
var replaceProperties = [
|
var replaceProperties = [
|
||||||
minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range,
|
minecraft_version : minecraft_version,
|
||||||
forge_version: forge_version, forge_version_range: forge_version_range,
|
minecraft_version_range: minecraft_version_range,
|
||||||
loader_version_range: loader_version_range,
|
neo_version : neo_version,
|
||||||
mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version,
|
neo_version_range : neo_version_range,
|
||||||
mod_authors: mod_authors, mod_description: mod_description,
|
loader_version_range : loader_version_range,
|
||||||
|
mod_id : mod_id,
|
||||||
|
mod_name : mod_name,
|
||||||
|
mod_license : mod_license,
|
||||||
|
mod_version : mod_version,
|
||||||
|
mod_authors : mod_authors,
|
||||||
|
mod_description : mod_description
|
||||||
]
|
]
|
||||||
|
|
||||||
inputs.properties replaceProperties
|
inputs.properties replaceProperties
|
||||||
|
expand replaceProperties
|
||||||
|
from "src/main/templates"
|
||||||
|
into "build/generated/sources/modMetadata"
|
||||||
|
}
|
||||||
|
|
||||||
filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) {
|
sourceSets.main.resources.srcDir generateModMetadata
|
||||||
expand replaceProperties + [project: project]
|
neoForge.ideSyncTask generateModMetadata
|
||||||
}}
|
|
||||||
|
|
||||||
// Example for how to get properties into the manifest for reading at runtime.
|
publishing {
|
||||||
tasks.named('jar', Jar).configure {
|
publications {
|
||||||
manifest {
|
register('mavenJava', MavenPublication) {
|
||||||
attributes([
|
from components.java
|
||||||
"Specification-Title" : mod_id,
|
}
|
||||||
"Specification-Vendor" : mod_authors,
|
}
|
||||||
"Specification-Version" : "1", // We are version 1 of ourselves
|
repositories {
|
||||||
"Implementation-Title" : project.name,
|
maven {
|
||||||
"Implementation-Version" : project.jar.archiveVersion,
|
url "file://${project.projectDir}/repo"
|
||||||
"Implementation-Vendor" : mod_authors,
|
}
|
||||||
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the preferred method to reobfuscate your jar file
|
|
||||||
finalizedBy 'reobfJar'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(JavaCompile).configureEach {
|
tasks.withType(JavaCompile).configureEach {
|
||||||
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
|
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior.
|
||||||
|
idea {
|
||||||
|
module {
|
||||||
|
downloadSources = true
|
||||||
|
downloadJavadoc = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,19 +1,17 @@
|
|||||||
org.gradle.jvmargs=-Xmx3G
|
org.gradle.jvmargs=-Xmx3G
|
||||||
org.gradle.daemon=false
|
org.gradle.daemon=false
|
||||||
|
|
||||||
|
|
||||||
# The Minecraft version must agree with the Forge version to get a valid artifact
|
# The Minecraft version must agree with the Forge version to get a valid artifact
|
||||||
minecraft_version=1.20.1
|
minecraft_version=1.21.1
|
||||||
# The Minecraft version range can use any release version of Minecraft as bounds.
|
# The Minecraft version range can use any release version of Minecraft as bounds.
|
||||||
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
|
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
|
||||||
# as they do not follow standard versioning conventions.
|
# as they do not follow standard versioning conventions.
|
||||||
minecraft_version_range=[1.20.1,1.21)
|
minecraft_version_range=[1.21,1.22)
|
||||||
# The Forge version must agree with the Minecraft version to get a valid artifact
|
# The Forge version must agree with the Minecraft version to get a valid artifact
|
||||||
forge_version=47.3.0
|
neo_version=21.1.194
|
||||||
# The Forge version range can use any version of Forge as bounds or match the loader version range
|
# The Forge version range can use any version of Forge as bounds or match the loader version range
|
||||||
forge_version_range=[47,)
|
neo_version_range=[21.1,)
|
||||||
# The loader version range can only use the major version of Forge/FML as bounds
|
# The loader version range can only use the major version of Forge/FML as bounds
|
||||||
loader_version_range=[47,)
|
loader_version_range=[4,)
|
||||||
# The mapping channel to use for mappings.
|
# The mapping channel to use for mappings.
|
||||||
# The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"].
|
# The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"].
|
||||||
# Additional mapping channels can be registered through the "channelProviders" extension in a Gradle plugin.
|
# Additional mapping channels can be registered through the "channelProviders" extension in a Gradle plugin.
|
||||||
@@ -31,9 +29,7 @@ loader_version_range=[47,)
|
|||||||
mapping_channel=official
|
mapping_channel=official
|
||||||
# The mapping version to query from the mapping channel.
|
# The mapping version to query from the mapping channel.
|
||||||
# This must match the format required by the mapping channel.
|
# This must match the format required by the mapping channel.
|
||||||
mapping_version=1.20.1
|
mapping_version=1.21.1
|
||||||
|
|
||||||
|
|
||||||
# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
|
# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
|
||||||
# Must match the String constant located in the main mod class annotated with @Mod.
|
# Must match the String constant located in the main mod class annotated with @Mod.
|
||||||
mod_id=maid_useful_task
|
mod_id=maid_useful_task
|
||||||
@@ -42,12 +38,12 @@ mod_name=maid useful task
|
|||||||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||||
mod_license=MIT
|
mod_license=MIT
|
||||||
# The mod version. See https://semver.org/
|
# The mod version. See https://semver.org/
|
||||||
mod_version=1.0.1
|
mod_version=1.3.7
|
||||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||||
# This should match the base package used for the mod sources.
|
# This should match the base package used for the mod sources.
|
||||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||||
mod_group_id=studio.fantasyit
|
mod_group_id=studio.fantasyit
|
||||||
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list.
|
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list.
|
||||||
mod_authors=
|
mod_authors=xypp
|
||||||
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
|
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
|
||||||
mod_description=
|
mod_description=Add some useful task for touhou little maid.
|
||||||
|
|||||||
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,7 +1,7 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
@@ -1,15 +1,13 @@
|
|||||||
pluginManagement {
|
pluginManagement {
|
||||||
repositories {
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
maven {
|
maven { url = 'https://maven.neoforged.net/releases' }
|
||||||
name = 'MinecraftForge'
|
|
||||||
url = 'https://maven.minecraftforge.net/'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'
|
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.9.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
rootProject.name = 'maid_useful_task'
|
rootProject.name = 'maid_useful_task'
|
||||||
|
|||||||
66
src/main/java/studio/fantasyit/maid_useful_task/Config.java
Normal file
66
src/main/java/studio/fantasyit/maid_useful_task/Config.java
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task;
|
||||||
|
|
||||||
|
|
||||||
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
|
import net.neoforged.fml.event.config.ModConfigEvent;
|
||||||
|
import net.neoforged.neoforge.common.ModConfigSpec;
|
||||||
|
|
||||||
|
// An example config class. This is not required, but it's a good idea to have one to keep your config organized.
|
||||||
|
// Demonstrates how to use Forge's config APIs
|
||||||
|
@EventBusSubscriber(modid = MaidUsefulTask.MODID, bus = EventBusSubscriber.Bus.MOD)
|
||||||
|
public class Config {
|
||||||
|
private static final ModConfigSpec.Builder BUILDER = new ModConfigSpec.Builder();
|
||||||
|
|
||||||
|
private static final ModConfigSpec.BooleanValue SELF_RESCUE = BUILDER
|
||||||
|
.define("misc.self_rescue", true);
|
||||||
|
|
||||||
|
private static final ModConfigSpec.BooleanValue ENABLE_LOGGING = BUILDER
|
||||||
|
.define("functions.logging", true);
|
||||||
|
private static final ModConfigSpec.BooleanValue ENABLE_REVIVE = BUILDER
|
||||||
|
.define("functions.revive", true);
|
||||||
|
private static final ModConfigSpec.BooleanValue ENABLE_LOCATE = BUILDER
|
||||||
|
.define("functions.locate", true);
|
||||||
|
|
||||||
|
private static final ModConfigSpec.BooleanValue ENABLE_REVIVE_AGGRO = BUILDER
|
||||||
|
.define("revive.aggro", false);
|
||||||
|
private static final ModConfigSpec.BooleanValue ENABLE_REVIVE_TOTEM = BUILDER
|
||||||
|
.define("revive.totem", true);
|
||||||
|
|
||||||
|
private static final ModConfigSpec.BooleanValue LOGGING_DISABLE_BLOCKUP = BUILDER
|
||||||
|
.define("logging.disable_blockup", false);
|
||||||
|
|
||||||
|
private static final ModConfigSpec.BooleanValue ENABLE_VEHICLE_CONTROL_FULL = BUILDER
|
||||||
|
.define("vehicle_control.full", true);
|
||||||
|
private static final ModConfigSpec.BooleanValue ENABLE_VEHICLE_CONTROL_ROTATE = BUILDER
|
||||||
|
.define("vehicle_control.rotate", true);
|
||||||
|
|
||||||
|
static final ModConfigSpec SPEC = BUILDER.build();
|
||||||
|
|
||||||
|
public static boolean enableSelfRescue = false;
|
||||||
|
|
||||||
|
public static boolean enableLoggingTask = false;
|
||||||
|
public static boolean enableReviveTask = false;
|
||||||
|
public static boolean enableLocateTask = false;
|
||||||
|
|
||||||
|
public static boolean enableReviveAggro = false;
|
||||||
|
public static boolean enableReviveTotem = false;
|
||||||
|
|
||||||
|
public static boolean enableVehicleControlFull = false;
|
||||||
|
public static boolean enableVehicleControlRotate = false;
|
||||||
|
|
||||||
|
public static boolean disableLoggingBlockUp = false;
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
static void onLoad(final ModConfigEvent event) {
|
||||||
|
enableSelfRescue = SELF_RESCUE.get();
|
||||||
|
enableLoggingTask = ENABLE_LOGGING.get();
|
||||||
|
enableReviveTask = ENABLE_REVIVE.get();
|
||||||
|
enableLocateTask = ENABLE_LOCATE.get();
|
||||||
|
enableReviveAggro = ENABLE_REVIVE_AGGRO.get();
|
||||||
|
enableReviveTotem = ENABLE_REVIVE_TOTEM.get();
|
||||||
|
enableVehicleControlFull = ENABLE_VEHICLE_CONTROL_FULL.get();
|
||||||
|
enableVehicleControlRotate = ENABLE_VEHICLE_CONTROL_ROTATE.get();
|
||||||
|
disableLoggingBlockUp = LOGGING_DISABLE_BLOCKUP.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,34 +1,12 @@
|
|||||||
package studio.fantasyit.maid_useful_task;
|
package studio.fantasyit.maid_useful_task;
|
||||||
|
|
||||||
import com.mojang.logging.LogUtils;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.neoforged.fml.ModLoadingContext;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.neoforged.fml.common.Mod;
|
||||||
import net.minecraft.world.food.FoodProperties;
|
import net.neoforged.fml.config.ModConfig;
|
||||||
import net.minecraft.world.item.BlockItem;
|
import studio.fantasyit.maid_useful_task.registry.GuiRegistry;
|
||||||
import net.minecraft.world.item.CreativeModeTab;
|
|
||||||
import net.minecraft.world.item.CreativeModeTabs;
|
|
||||||
import net.minecraft.world.item.Item;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
|
||||||
import net.minecraft.world.level.block.Blocks;
|
|
||||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
|
||||||
import net.minecraft.world.level.material.MapColor;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
|
|
||||||
import net.minecraftforge.event.server.ServerStartingEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.ModLoadingContext;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.config.ModConfig;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
|
||||||
import net.minecraftforge.registries.DeferredRegister;
|
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
|
||||||
import net.minecraftforge.registries.RegistryObject;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import studio.fantasyit.maid_useful_task.registry.MemoryModuleRegistry;
|
import studio.fantasyit.maid_useful_task.registry.MemoryModuleRegistry;
|
||||||
|
import studio.fantasyit.maid_useful_task.vehicle.MaidVehicleManager;
|
||||||
|
|
||||||
// The value here should match an entry in the META-INF/mods.toml file
|
// The value here should match an entry in the META-INF/mods.toml file
|
||||||
@Mod(MaidUsefulTask.MODID)
|
@Mod(MaidUsefulTask.MODID)
|
||||||
@@ -37,9 +15,11 @@ public class MaidUsefulTask {
|
|||||||
// Define mod id in a common place for everything to reference
|
// Define mod id in a common place for everything to reference
|
||||||
public static final String MODID = "maid_useful_task";
|
public static final String MODID = "maid_useful_task";
|
||||||
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public MaidUsefulTask() {
|
public MaidUsefulTask() {
|
||||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
IEventBus modEventBus = ModLoadingContext.get().getActiveContainer().getEventBus();
|
||||||
|
ModLoadingContext.get().getActiveContainer().registerConfig(ModConfig.Type.COMMON, Config.SPEC);
|
||||||
MemoryModuleRegistry.register(modEventBus);
|
MemoryModuleRegistry.register(modEventBus);
|
||||||
|
GuiRegistry.init(modEventBus);
|
||||||
|
MaidVehicleManager.register();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,19 @@ import com.github.tartaricacid.touhoulittlemaid.api.ILittleMaid;
|
|||||||
import com.github.tartaricacid.touhoulittlemaid.api.LittleMaidExtension;
|
import com.github.tartaricacid.touhoulittlemaid.api.LittleMaidExtension;
|
||||||
import com.github.tartaricacid.touhoulittlemaid.api.entity.ai.IExtraMaidBrain;
|
import com.github.tartaricacid.touhoulittlemaid.api.entity.ai.IExtraMaidBrain;
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.ai.brain.ExtraMaidBrainManager;
|
import com.github.tartaricacid.touhoulittlemaid.entity.ai.brain.ExtraMaidBrainManager;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.data.TaskDataRegister;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.item.control.BroomControlManager;
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.task.TaskManager;
|
import com.github.tartaricacid.touhoulittlemaid.entity.task.TaskManager;
|
||||||
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
||||||
|
import studio.fantasyit.maid_useful_task.compat.PlayerRevive;
|
||||||
|
import studio.fantasyit.maid_useful_task.data.MaidConfigKeys;
|
||||||
|
import studio.fantasyit.maid_useful_task.data.MaidLoggingConfig;
|
||||||
|
import studio.fantasyit.maid_useful_task.data.MaidReviveConfig;
|
||||||
import studio.fantasyit.maid_useful_task.registry.MemoryModuleRegistry;
|
import studio.fantasyit.maid_useful_task.registry.MemoryModuleRegistry;
|
||||||
|
import studio.fantasyit.maid_useful_task.task.MaidLocateTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.task.MaidRevivePlayerTask;
|
||||||
import studio.fantasyit.maid_useful_task.task.MaidTreeTask;
|
import studio.fantasyit.maid_useful_task.task.MaidTreeTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.vehicle.broom.BroomController;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -16,7 +25,13 @@ public class UsefulTaskExtension implements ILittleMaid {
|
|||||||
@Override
|
@Override
|
||||||
public void addMaidTask(TaskManager manager) {
|
public void addMaidTask(TaskManager manager) {
|
||||||
ILittleMaid.super.addMaidTask(manager);
|
ILittleMaid.super.addMaidTask(manager);
|
||||||
manager.add(new MaidTreeTask());
|
if (Config.enableLoggingTask)
|
||||||
|
manager.add(new MaidTreeTask());
|
||||||
|
if (Config.enableLocateTask)
|
||||||
|
manager.add(new MaidLocateTask());
|
||||||
|
if (Config.enableReviveTask)
|
||||||
|
if (PlayerRevive.isEnable())
|
||||||
|
manager.add(new MaidRevivePlayerTask());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -28,9 +43,28 @@ public class UsefulTaskExtension implements ILittleMaid {
|
|||||||
MemoryModuleRegistry.DESTROY_TARGET.get(),
|
MemoryModuleRegistry.DESTROY_TARGET.get(),
|
||||||
MemoryModuleRegistry.PLACE_TARGET.get(),
|
MemoryModuleRegistry.PLACE_TARGET.get(),
|
||||||
MemoryModuleRegistry.BLOCK_UP_TARGET.get(),
|
MemoryModuleRegistry.BLOCK_UP_TARGET.get(),
|
||||||
MemoryModuleRegistry.RATE_LIMIT_TOKEN.get()
|
MemoryModuleRegistry.BLOCK_VALIDATION.get(),
|
||||||
|
MemoryModuleRegistry.CURRENT_WORK.get(),
|
||||||
|
MemoryModuleRegistry.COMMON_BLOCK_CACHE.get(),
|
||||||
|
MemoryModuleRegistry.IS_ALLOW_HANDLE_VEHICLE.get(),
|
||||||
|
MemoryModuleRegistry.LOCATE_ITEM.get()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerTaskData(TaskDataRegister register) {
|
||||||
|
MaidConfigKeys.addKey(MaidLoggingConfig.LOCATION,
|
||||||
|
MaidLoggingConfig.KEY = register.register(new MaidLoggingConfig()),
|
||||||
|
MaidLoggingConfig.Data::getDefault);
|
||||||
|
MaidConfigKeys.addKey(MaidReviveConfig.LOCATION,
|
||||||
|
MaidReviveConfig.KEY = register.register(new MaidReviveConfig()),
|
||||||
|
MaidReviveConfig.Data::getDefault);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerBroomControl(BroomControlManager register) {
|
||||||
|
register.register(BroomController::new);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.api;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.neoforged.bus.api.Event;
|
||||||
|
import net.neoforged.bus.api.ICancellableEvent;
|
||||||
|
|
||||||
|
public class ItemLocateEvent extends Event implements ICancellableEvent {
|
||||||
|
public final ItemStack itemStack;
|
||||||
|
public final EntityMaid maid;
|
||||||
|
public final BlockPos cache;
|
||||||
|
public BlockPos target = null;
|
||||||
|
|
||||||
|
public ItemLocateEvent(ItemStack itemStack, EntityMaid maid, BlockPos cache) {
|
||||||
|
this.itemStack = itemStack;
|
||||||
|
this.maid = maid;
|
||||||
|
this.cache = cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockPos getTarget() {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTarget(BlockPos target) {
|
||||||
|
this.target = target;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package studio.fantasyit.maid_useful_task.behavior;
|
|
||||||
|
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import net.minecraft.world.entity.ai.behavior.Behavior;
|
|
||||||
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
|
||||||
import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
|
||||||
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class LoopWithTokenBehavior extends Behavior<EntityMaid> {
|
|
||||||
public LoopWithTokenBehavior() {
|
|
||||||
super(Map.of());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void start(ServerLevel p_22540_, EntityMaid p_22541_, long p_22542_) {
|
|
||||||
MemoryUtil.getRateLimitToken(p_22541_).tick(p_22541_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,183 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.behavior;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.advancements.CriteriaTriggers;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.stats.Stats;
|
||||||
|
import net.minecraft.world.effect.MobEffectInstance;
|
||||||
|
import net.minecraft.world.effect.MobEffects;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import net.minecraft.world.entity.Mob;
|
||||||
|
import net.minecraft.world.entity.ai.behavior.Behavior;
|
||||||
|
import net.minecraft.world.entity.ai.behavior.BehaviorUtils;
|
||||||
|
import net.minecraft.world.entity.ai.goal.target.TargetGoal;
|
||||||
|
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
||||||
|
import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
||||||
|
import net.minecraft.world.entity.ai.memory.NearestVisibleLivingEntities;
|
||||||
|
import net.minecraft.world.entity.monster.Monster;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.Items;
|
||||||
|
import net.minecraft.world.level.entity.EntityTypeTest;
|
||||||
|
import net.minecraft.world.phys.AABB;
|
||||||
|
import studio.fantasyit.maid_useful_task.Config;
|
||||||
|
import studio.fantasyit.maid_useful_task.data.MaidReviveConfig;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.InvUtil;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.WrappedMaidFakePlayer;
|
||||||
|
import team.creative.playerrevive.PlayerRevive;
|
||||||
|
import team.creative.playerrevive.api.IBleeding;
|
||||||
|
import team.creative.playerrevive.server.PlayerReviveServer;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class PlayerReviveBehavior extends Behavior<EntityMaid> {
|
||||||
|
protected static class TryAttackMaidGoal extends TargetGoal {
|
||||||
|
private final EntityMaid maid;
|
||||||
|
|
||||||
|
public TryAttackMaidGoal(Mob p_26140_, EntityMaid maid) {
|
||||||
|
super(p_26140_, true);
|
||||||
|
this.maid = maid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canUse() {
|
||||||
|
return mob.canAttack(maid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start() {
|
||||||
|
mob.setTarget(maid);
|
||||||
|
super.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMaid(EntityMaid maid) {
|
||||||
|
return maid.getUUID().equals(this.maid.getUUID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerReviveBehavior() {
|
||||||
|
super(Map.of(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES, MemoryStatus.VALUE_PRESENT), 600);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean checkExtraStartConditions(ServerLevel p_22538_, EntityMaid maid) {
|
||||||
|
Optional<NearestVisibleLivingEntities> memory = maid.getBrain().getMemory(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES);
|
||||||
|
return memory.map(list -> list
|
||||||
|
.find(entity -> entity instanceof Player)
|
||||||
|
.map(ep -> PlayerReviveServer.getBleeding((ServerPlayer) ep))
|
||||||
|
.anyMatch(IBleeding::isBleeding)
|
||||||
|
).orElse(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerPlayer targetPlayer;
|
||||||
|
IBleeding bleeding;
|
||||||
|
boolean startedRevive;
|
||||||
|
Set<UUID> aggroEntities;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void start(ServerLevel level, EntityMaid maid, long p_22542_) {
|
||||||
|
super.start(level, maid, p_22542_);
|
||||||
|
aggroEntities = new HashSet<>();
|
||||||
|
startedRevive = false;
|
||||||
|
boolean ownerOnly = maid.getOrCreateData(MaidReviveConfig.KEY, MaidReviveConfig.Data.getDefault()).ownerOnly();
|
||||||
|
LivingEntity owner = maid.getOwner();
|
||||||
|
Optional<NearestVisibleLivingEntities> memory = maid.getBrain().getMemory(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES);
|
||||||
|
targetPlayer = memory.flatMap(list -> list
|
||||||
|
.find(entity -> entity instanceof Player)
|
||||||
|
.map(ep -> (ServerPlayer) ep)
|
||||||
|
.filter(sp -> (owner != null && sp.is(owner)) || !ownerOnly)
|
||||||
|
.filter(ep -> PlayerReviveServer.getBleeding(ep).isBleeding())
|
||||||
|
.findFirst()
|
||||||
|
).orElse(null);
|
||||||
|
if (targetPlayer != null) {
|
||||||
|
bleeding = PlayerReviveServer.getBleeding(targetPlayer);
|
||||||
|
BehaviorUtils.setWalkAndLookTargetMemories(maid, targetPlayer, 0.5f, 2);
|
||||||
|
}
|
||||||
|
useTotemOfUndying(level, maid);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void useTotemOfUndying(ServerLevel level, EntityMaid maid) {
|
||||||
|
if (!Config.enableReviveTotem) return;
|
||||||
|
ItemStack itemstack = InvUtil.tryExtractOneMatches(maid.getMaidBauble(), (stack) -> stack.is(Items.TOTEM_OF_UNDYING));
|
||||||
|
if (!itemstack.isEmpty()) {
|
||||||
|
targetPlayer.awardStat(Stats.ITEM_USED.get(Items.TOTEM_OF_UNDYING), 1);
|
||||||
|
CriteriaTriggers.USED_TOTEM.trigger(targetPlayer, itemstack);
|
||||||
|
|
||||||
|
targetPlayer.setHealth(1.0F);
|
||||||
|
targetPlayer.removeAllEffects();
|
||||||
|
targetPlayer.addEffect(new MobEffectInstance(MobEffects.REGENERATION, 900, 1));
|
||||||
|
targetPlayer.addEffect(new MobEffectInstance(MobEffects.ABSORPTION, 100, 1));
|
||||||
|
targetPlayer.addEffect(new MobEffectInstance(MobEffects.FIRE_RESISTANCE, 800, 0));
|
||||||
|
level.broadcastEntityEvent(targetPlayer, (byte) 35);
|
||||||
|
|
||||||
|
PlayerReviveServer.revive(targetPlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkCanReviveAndStartRevive(ServerLevel level, EntityMaid maid) {
|
||||||
|
if (PlayerRevive.CONFIG.revive.needReviveItem) {
|
||||||
|
if (PlayerRevive.CONFIG.revive.consumeReviveItem && !bleeding.isItemConsumed()) {
|
||||||
|
ItemStack extractedForConsume = InvUtil.tryExtractOneMatches(maid.getAvailableInv(true), PlayerRevive.CONFIG.revive.reviveItem::is);
|
||||||
|
if (!PlayerRevive.CONFIG.revive.reviveItem.is(extractedForConsume)) {
|
||||||
|
targetPlayer = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bleeding.setItemConsumed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerReviveServer.removePlayerAsHelper(WrappedMaidFakePlayer.get(maid));
|
||||||
|
bleeding.revivingPlayers().add(WrappedMaidFakePlayer.get(maid));
|
||||||
|
aggroEntitiesAround(level, maid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean canStillUse(ServerLevel p_22545_, EntityMaid maid, long p_22547_) {
|
||||||
|
if (targetPlayer == null) return false;
|
||||||
|
if (targetPlayer.distanceTo(maid) > PlayerRevive.CONFIG.revive.maxDistance) return false;
|
||||||
|
return bleeding.isBleeding();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void aggroEntitiesAround(ServerLevel level, EntityMaid maid) {
|
||||||
|
if (!Config.enableReviveAggro) return;
|
||||||
|
List<Monster> entities = level.getEntities(EntityTypeTest.forClass(Monster.class),
|
||||||
|
AABB.ofSize(maid.position(), 16, 16, 16),
|
||||||
|
entity -> true
|
||||||
|
);
|
||||||
|
for (Monster entity : entities) {
|
||||||
|
if (!aggroEntities.contains(entity.getUUID())) {
|
||||||
|
entity.targetSelector.addGoal(10, new TryAttackMaidGoal(entity, maid));
|
||||||
|
aggroEntities.add(entity.getUUID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tick(ServerLevel level, EntityMaid maid, long p_22553_) {
|
||||||
|
super.tick(level, maid, p_22553_);
|
||||||
|
if (p_22553_ % 20 == 0)
|
||||||
|
BehaviorUtils.setWalkAndLookTargetMemories(maid, targetPlayer, 0.5f, 2);
|
||||||
|
if (!startedRevive) {
|
||||||
|
if (maid.distanceTo(targetPlayer) < PlayerRevive.CONFIG.revive.maxDistance) {
|
||||||
|
checkCanReviveAndStartRevive(level, maid);
|
||||||
|
startedRevive = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (p_22553_ % 20 == 0)
|
||||||
|
aggroEntitiesAround(level, maid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void stop(ServerLevel p_22548_, EntityMaid maid, long p_22550_) {
|
||||||
|
PlayerReviveServer.removePlayerAsHelper(WrappedMaidFakePlayer.get(maid));
|
||||||
|
for (UUID uuid : aggroEntities) {
|
||||||
|
Entity entity = p_22548_.getEntity(uuid);
|
||||||
|
if (entity instanceof Monster monster && entity.isAlive())
|
||||||
|
monster.targetSelector.removeAllGoals(g -> g instanceof TryAttackMaidGoal tg && tg.isMaid(maid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package studio.fantasyit.maid_useful_task.behavior;
|
package studio.fantasyit.maid_useful_task.behavior.common;
|
||||||
|
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
@@ -7,8 +7,8 @@ import net.minecraft.world.InteractionHand;
|
|||||||
import net.minecraft.world.entity.ai.behavior.Behavior;
|
import net.minecraft.world.entity.ai.behavior.Behavior;
|
||||||
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
||||||
import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import studio.fantasyit.maid_useful_task.memory.BlockUpContext;
|
import studio.fantasyit.maid_useful_task.memory.BlockUpContext;
|
||||||
|
import studio.fantasyit.maid_useful_task.memory.CurrentWork;
|
||||||
import studio.fantasyit.maid_useful_task.task.IMaidBlockUpTask;
|
import studio.fantasyit.maid_useful_task.task.IMaidBlockUpTask;
|
||||||
import studio.fantasyit.maid_useful_task.util.Conditions;
|
import studio.fantasyit.maid_useful_task.util.Conditions;
|
||||||
import studio.fantasyit.maid_useful_task.util.MaidUtils;
|
import studio.fantasyit.maid_useful_task.util.MaidUtils;
|
||||||
@@ -28,14 +28,15 @@ public class BlockUpDestroyBehavior extends Behavior<EntityMaid> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BlockUpDestroyBehavior() {
|
public BlockUpDestroyBehavior() {
|
||||||
super(Map.of(),200);
|
super(Map.of(), 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean checkExtraStartConditions(ServerLevel p_22538_, EntityMaid p_22539_) {
|
protected boolean checkExtraStartConditions(ServerLevel p_22538_, EntityMaid p_22539_) {
|
||||||
|
if (!Conditions.isCurrent(p_22539_, CurrentWork.BLOCKUP_DOWN)) return false;
|
||||||
if (!MemoryUtil.getBlockUpContext(p_22539_).hasTarget()) return false;
|
if (!MemoryUtil.getBlockUpContext(p_22539_).hasTarget()) return false;
|
||||||
if (MemoryUtil.getBlockUpContext(p_22539_).getStatus() != BlockUpContext.STATUS.DOWN) return false;
|
if (MemoryUtil.getBlockUpContext(p_22539_).getStatus() != BlockUpContext.STATUS.DOWN) return false;
|
||||||
return Conditions.hasReachedValidTargetOrReset(p_22539_, 0.8f);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,8 +64,7 @@ public class BlockUpDestroyBehavior extends Behavior<EntityMaid> {
|
|||||||
BlockPos targetPos = maid.blockPosition().below();
|
BlockPos targetPos = maid.blockPosition().below();
|
||||||
maid.swing(InteractionHand.MAIN_HAND);
|
maid.swing(InteractionHand.MAIN_HAND);
|
||||||
MemoryUtil.setLookAt(maid, targetPos);
|
MemoryUtil.setLookAt(maid, targetPos);
|
||||||
BlockState targetBlockState = level.getBlockState(targetPos);
|
float speed = MaidUtils.getDestroyProgressDelta(maid, targetPos);
|
||||||
float speed = fakePlayer.getMainHandItem().getDestroySpeed(targetBlockState) / fakePlayer.getDigSpeed(targetBlockState, targetPos) / 30;
|
|
||||||
progress += speed;
|
progress += speed;
|
||||||
if (progress >= 1f) {
|
if (progress >= 1f) {
|
||||||
MaidUtils.destroyBlock(maid, targetPos);
|
MaidUtils.destroyBlock(maid, targetPos);
|
||||||
@@ -72,10 +72,12 @@ public class BlockUpDestroyBehavior extends Behavior<EntityMaid> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void stop(ServerLevel p_22548_, EntityMaid maid, long p_22550_) {
|
protected void stop(ServerLevel p_22548_, EntityMaid maid, long p_22550_) {
|
||||||
super.stop(p_22548_, maid, p_22550_);
|
super.stop(p_22548_, maid, p_22550_);
|
||||||
context.setStatus(BlockUpContext.STATUS.IDLE);
|
context.clearStartTarget();
|
||||||
MemoryUtil.clearTarget(maid);
|
MemoryUtil.clearTarget(maid);
|
||||||
|
MemoryUtil.setCurrent(maid, CurrentWork.IDLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package studio.fantasyit.maid_useful_task.behavior;
|
package studio.fantasyit.maid_useful_task.behavior.common;
|
||||||
|
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
@@ -7,10 +7,10 @@ import net.minecraft.world.InteractionHand;
|
|||||||
import net.minecraft.world.entity.ai.behavior.Behavior;
|
import net.minecraft.world.entity.ai.behavior.Behavior;
|
||||||
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
||||||
import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
||||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
|
||||||
import net.minecraft.world.phys.AABB;
|
import net.minecraft.world.phys.AABB;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import studio.fantasyit.maid_useful_task.memory.BlockUpContext;
|
import studio.fantasyit.maid_useful_task.memory.BlockUpContext;
|
||||||
|
import studio.fantasyit.maid_useful_task.memory.CurrentWork;
|
||||||
import studio.fantasyit.maid_useful_task.task.IMaidBlockUpTask;
|
import studio.fantasyit.maid_useful_task.task.IMaidBlockUpTask;
|
||||||
import studio.fantasyit.maid_useful_task.util.Conditions;
|
import studio.fantasyit.maid_useful_task.util.Conditions;
|
||||||
import studio.fantasyit.maid_useful_task.util.MaidUtils;
|
import studio.fantasyit.maid_useful_task.util.MaidUtils;
|
||||||
@@ -34,6 +34,7 @@ public class BlockUpPlaceBehavior extends Behavior<EntityMaid> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean checkExtraStartConditions(ServerLevel p_22538_, EntityMaid p_22539_) {
|
protected boolean checkExtraStartConditions(ServerLevel p_22538_, EntityMaid p_22539_) {
|
||||||
|
if (!Conditions.isCurrent(p_22539_, CurrentWork.BLOCKUP_UP)) return false;
|
||||||
if (!MemoryUtil.getBlockUpContext(p_22539_).hasTarget()) return false;
|
if (!MemoryUtil.getBlockUpContext(p_22539_).hasTarget()) return false;
|
||||||
if (MemoryUtil.getBlockUpContext(p_22539_).getStatus() != BlockUpContext.STATUS.UP) return false;
|
if (MemoryUtil.getBlockUpContext(p_22539_).getStatus() != BlockUpContext.STATUS.UP) return false;
|
||||||
return Conditions.hasReachedValidTargetOrReset(p_22539_, 0.8f);
|
return Conditions.hasReachedValidTargetOrReset(p_22539_, 0.8f);
|
||||||
@@ -42,7 +43,8 @@ public class BlockUpPlaceBehavior extends Behavior<EntityMaid> {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean canStillUse(ServerLevel p_22545_, EntityMaid maid, long p_22547_) {
|
protected boolean canStillUse(ServerLevel p_22545_, EntityMaid maid, long p_22547_) {
|
||||||
if (MemoryUtil.getBlockUpContext(maid).getStatus() != BlockUpContext.STATUS.UP) return false;
|
if (MemoryUtil.getBlockUpContext(maid).getStatus() != BlockUpContext.STATUS.UP) return false;
|
||||||
if (!p_22545_.getBlockState(maid.blockPosition().above().above()).isAir()) return false;
|
if (maid.onGround() && !p_22545_.getBlockState(maid.blockPosition().above().above()).isAir()) return false;
|
||||||
|
if (maid.getY() > context.getTargetPos().getY() + 2) return false;
|
||||||
return !(maid.blockPosition().equals(context.getTargetPos()) && maid.onGround());
|
return !(maid.blockPosition().equals(context.getTargetPos()) && maid.onGround());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,9 +60,7 @@ public class BlockUpPlaceBehavior extends Behavior<EntityMaid> {
|
|||||||
AABB boundingBox = maid.getBoundingBox();
|
AABB boundingBox = maid.getBoundingBox();
|
||||||
BlockPos startPos = context.getStartPos();
|
BlockPos startPos = context.getStartPos();
|
||||||
Vec3 move = maid.getDeltaMovement();
|
Vec3 move = maid.getDeltaMovement();
|
||||||
if (boundingBox.maxX <= startPos.getX() + 1 && boundingBox.maxZ <= startPos.getZ() + 1
|
if (boundingBox.maxX <= startPos.getX() + 1 && boundingBox.maxZ <= startPos.getZ() + 1 && boundingBox.minX >= startPos.getX() && boundingBox.minZ >= startPos.getZ()) {
|
||||||
&& boundingBox.minX >= startPos.getX() && boundingBox.minZ >= startPos.getZ()
|
|
||||||
) {
|
|
||||||
maid.setDeltaMovement(0, move.y, 0);
|
maid.setDeltaMovement(0, move.y, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -78,9 +78,7 @@ public class BlockUpPlaceBehavior extends Behavior<EntityMaid> {
|
|||||||
task.swapValidItemToHand(maid);
|
task.swapValidItemToHand(maid);
|
||||||
BlockPos pos = maid.blockPosition();
|
BlockPos pos = maid.blockPosition();
|
||||||
BlockPos below = pos.below();
|
BlockPos below = pos.below();
|
||||||
if (context.isOnLine(pos))
|
if (context.isOnLine(pos)) if (below.equals(context.getTargetPos())) return;
|
||||||
if (below.equals(context.getTargetPos()))
|
|
||||||
return;
|
|
||||||
if (level.getBlockState(below).canBeReplaced() && level.getBlockState(pos).canBeReplaced()) {
|
if (level.getBlockState(below).canBeReplaced() && level.getBlockState(pos).canBeReplaced()) {
|
||||||
maid.swing(InteractionHand.MAIN_HAND);
|
maid.swing(InteractionHand.MAIN_HAND);
|
||||||
MaidUtils.placeBlock(maid, below);
|
MaidUtils.placeBlock(maid, below);
|
||||||
@@ -99,10 +97,14 @@ public class BlockUpPlaceBehavior extends Behavior<EntityMaid> {
|
|||||||
protected void stop(ServerLevel p_22548_, EntityMaid maid, long p_22550_) {
|
protected void stop(ServerLevel p_22548_, EntityMaid maid, long p_22550_) {
|
||||||
super.stop(p_22548_, maid, p_22550_);
|
super.stop(p_22548_, maid, p_22550_);
|
||||||
context.setStatus(BlockUpContext.STATUS.IDLE);
|
context.setStatus(BlockUpContext.STATUS.IDLE);
|
||||||
if (!maid.blockPosition().equals(context.getTargetPos())) {
|
if (context.hasTarget()) {
|
||||||
BlockPos startPos = context.getStartPos();
|
if (!maid.blockPosition().equals(context.getTargetPos())) {
|
||||||
BlockPos blockPos = maid.blockPosition();
|
BlockPos startPos = context.getStartPos();
|
||||||
context.setStartTarget(new BlockPos(blockPos.getX(), startPos.getY(), blockPos.getZ()), blockPos);
|
BlockPos blockPos = maid.blockPosition();
|
||||||
|
context.setStartTarget(new BlockPos(blockPos.getX(), startPos.getY(), blockPos.getZ()), blockPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
MemoryUtil.setCurrent(maid, CurrentWork.BLOCKUP_DESTROY);
|
||||||
}
|
}
|
||||||
MemoryUtil.clearTarget(maid);
|
MemoryUtil.clearTarget(maid);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package studio.fantasyit.maid_useful_task.behavior;
|
package studio.fantasyit.maid_useful_task.behavior.common;
|
||||||
|
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.ai.brain.task.MaidCheckRateTask;
|
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
import com.github.tartaricacid.touhoulittlemaid.init.InitEntities;
|
import com.github.tartaricacid.touhoulittlemaid.init.InitEntities;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
@@ -13,12 +12,11 @@ import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
|||||||
import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
||||||
import oshi.util.tuples.Pair;
|
import oshi.util.tuples.Pair;
|
||||||
import studio.fantasyit.maid_useful_task.memory.BlockUpContext;
|
import studio.fantasyit.maid_useful_task.memory.BlockUpContext;
|
||||||
import studio.fantasyit.maid_useful_task.memory.TaskRateLimitToken;
|
import studio.fantasyit.maid_useful_task.memory.CurrentWork;
|
||||||
import studio.fantasyit.maid_useful_task.task.IMaidBlockUpTask;
|
import studio.fantasyit.maid_useful_task.task.IMaidBlockUpTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.MaidUtils;
|
||||||
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class BlockUpScheduleBehavior extends Behavior<EntityMaid> {
|
public class BlockUpScheduleBehavior extends Behavior<EntityMaid> {
|
||||||
public BlockUpScheduleBehavior() {
|
public BlockUpScheduleBehavior() {
|
||||||
super(ImmutableMap.of(MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT, InitEntities.TARGET_POS.get(), MemoryStatus.VALUE_ABSENT));
|
super(ImmutableMap.of(MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT, InitEntities.TARGET_POS.get(), MemoryStatus.VALUE_ABSENT));
|
||||||
@@ -26,7 +24,10 @@ public class BlockUpScheduleBehavior extends Behavior<EntityMaid> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean checkExtraStartConditions(ServerLevel p_22538_, EntityMaid p_22539_) {
|
protected boolean checkExtraStartConditions(ServerLevel p_22538_, EntityMaid p_22539_) {
|
||||||
if (MemoryUtil.getRateLimitToken(p_22539_).isFor(TaskRateLimitToken.Level.L3)) {
|
if (!switch (MemoryUtil.getCurrent(p_22539_)) {
|
||||||
|
case BLOCKUP_UP, BLOCKUP_DOWN, BLOCKUP_DESTROY, IDLE -> true;
|
||||||
|
default -> false;
|
||||||
|
}) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return super.checkExtraStartConditions(p_22538_, p_22539_);
|
return super.checkExtraStartConditions(p_22538_, p_22539_);
|
||||||
@@ -37,23 +38,35 @@ public class BlockUpScheduleBehavior extends Behavior<EntityMaid> {
|
|||||||
BlockUpContext context = MemoryUtil.getBlockUpContext(maid);
|
BlockUpContext context = MemoryUtil.getBlockUpContext(maid);
|
||||||
IMaidBlockUpTask task = (IMaidBlockUpTask) maid.getTask();
|
IMaidBlockUpTask task = (IMaidBlockUpTask) maid.getTask();
|
||||||
if (context.hasTarget()) {
|
if (context.hasTarget()) {
|
||||||
if (context.getStatus() != BlockUpContext.STATUS.IDLE && MemoryUtil.getTargetPos(maid) == null) {
|
if (context.getStatus() != BlockUpContext.STATUS.UP && !context.isOnLine(maid.blockPosition())) {
|
||||||
context.clearStartTarget();
|
context.clearStartTarget();
|
||||||
|
MemoryUtil.setCurrent(maid, CurrentWork.IDLE);
|
||||||
|
} else if (context.getStatus() != BlockUpContext.STATUS.IDLE && MemoryUtil.getTargetPos(maid) == null) {
|
||||||
|
if (context.getStatus() == BlockUpContext.STATUS.DOWN) {
|
||||||
|
MemoryUtil.setTarget(maid, context.getTargetPos(), 0.5f);
|
||||||
|
MemoryUtil.setCurrent(maid, CurrentWork.BLOCKUP_DOWN);
|
||||||
|
} else if (maid.canPathReach(context.getStartPos())) {
|
||||||
|
MemoryUtil.setTarget(maid, context.getStartPos(), 0.5f);
|
||||||
|
MemoryUtil.setCurrent(maid, CurrentWork.BLOCKUP_UP);
|
||||||
|
} else {
|
||||||
|
context.clearStartTarget();
|
||||||
|
}
|
||||||
} else if (!context.isOnLine(maid.blockPosition()) || context.getStartPos().equals(context.getTargetPos())) {
|
} else if (!context.isOnLine(maid.blockPosition()) || context.getStartPos().equals(context.getTargetPos())) {
|
||||||
context.clearStartTarget();
|
context.clearStartTarget();
|
||||||
} else if (context.getStatus() == BlockUpContext.STATUS.IDLE && !context.isTarget(maid.blockPosition()) && context.isOnLine(maid.blockPosition())) {
|
MemoryUtil.setCurrent(maid, CurrentWork.IDLE);
|
||||||
context.setStartTarget(context.getStartPos(), maid.blockPosition());
|
|
||||||
} else if (context.getStatus() == BlockUpContext.STATUS.IDLE && !task.stillValid(maid, maid.blockPosition())) {
|
} else if (context.getStatus() == BlockUpContext.STATUS.IDLE && !task.stillValid(maid, maid.blockPosition())) {
|
||||||
maid.getBrain().setMemory(InitEntities.TARGET_POS.get(), new BlockPosTracker(context.getTargetPos()));
|
maid.getBrain().setMemory(InitEntities.TARGET_POS.get(), new BlockPosTracker(context.getTargetPos()));
|
||||||
context.setStatus(BlockUpContext.STATUS.DOWN);
|
context.setStatus(BlockUpContext.STATUS.DOWN);
|
||||||
|
MemoryUtil.setCurrent(maid, CurrentWork.BLOCKUP_DOWN);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Pair<BlockPos, BlockPos> targetPosBlockUp = task.findTargetPosBlockUp(maid, maid.blockPosition());
|
Pair<BlockPos, BlockPos> targetPosBlockUp = task.findTargetPosBlockUp(maid, MaidUtils.getMaidRestrictCenter(maid), task.countMaxUsableBlockItems(maid));
|
||||||
if (targetPosBlockUp != null) {
|
if (targetPosBlockUp != null) {
|
||||||
context.setStartTarget(targetPosBlockUp.getA(), targetPosBlockUp.getB());
|
context.setStartTarget(targetPosBlockUp.getA(), targetPosBlockUp.getB());
|
||||||
maid.getBrain().setMemory(InitEntities.TARGET_POS.get(), new BlockPosTracker(targetPosBlockUp.getA()));
|
maid.getBrain().setMemory(InitEntities.TARGET_POS.get(), new BlockPosTracker(targetPosBlockUp.getA()));
|
||||||
BehaviorUtils.setWalkAndLookTargetMemories(maid, targetPosBlockUp.getA(), 0.5f, 0);
|
BehaviorUtils.setWalkAndLookTargetMemories(maid, targetPosBlockUp.getA(), 0.5f, 0);
|
||||||
context.setStatus(BlockUpContext.STATUS.UP);
|
context.setStatus(BlockUpContext.STATUS.UP);
|
||||||
|
MemoryUtil.setCurrent(maid, CurrentWork.BLOCKUP_UP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package studio.fantasyit.maid_useful_task.behavior;
|
package studio.fantasyit.maid_useful_task.behavior.common;
|
||||||
|
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
import com.github.tartaricacid.touhoulittlemaid.init.InitEntities;
|
import com.github.tartaricacid.touhoulittlemaid.init.InitEntities;
|
||||||
@@ -10,9 +10,11 @@ import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
|||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import studio.fantasyit.maid_useful_task.memory.BlockTargetMemory;
|
import studio.fantasyit.maid_useful_task.memory.BlockTargetMemory;
|
||||||
|
import studio.fantasyit.maid_useful_task.memory.CurrentWork;
|
||||||
import studio.fantasyit.maid_useful_task.registry.MemoryModuleRegistry;
|
import studio.fantasyit.maid_useful_task.registry.MemoryModuleRegistry;
|
||||||
import studio.fantasyit.maid_useful_task.task.IMaidBlockDestroyTask;
|
import studio.fantasyit.maid_useful_task.task.IMaidBlockDestroyTask;
|
||||||
import studio.fantasyit.maid_useful_task.util.Conditions;
|
import studio.fantasyit.maid_useful_task.util.Conditions;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.MaidUtils;
|
||||||
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
||||||
import studio.fantasyit.maid_useful_task.util.WrappedMaidFakePlayer;
|
import studio.fantasyit.maid_useful_task.util.WrappedMaidFakePlayer;
|
||||||
|
|
||||||
@@ -32,7 +34,9 @@ public class DestoryBlockBehavior extends Behavior<EntityMaid> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean checkExtraStartConditions(@NotNull ServerLevel worldIn, @NotNull EntityMaid maid) {
|
protected boolean checkExtraStartConditions(@NotNull ServerLevel worldIn, @NotNull EntityMaid maid) {
|
||||||
return Conditions.hasReachedValidTargetOrReset(maid,1);
|
if (!Conditions.isCurrent(maid, CurrentWork.DESTROY) && !Conditions.isCurrent(maid, CurrentWork.BLOCKUP_DESTROY))
|
||||||
|
return false;
|
||||||
|
return Conditions.hasReachedValidTargetOrReset(maid, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -48,8 +52,8 @@ public class DestoryBlockBehavior extends Behavior<EntityMaid> {
|
|||||||
super.start(p_22540_, maid, p_22542_);
|
super.start(p_22540_, maid, p_22542_);
|
||||||
BlockTargetMemory blockTargetMemory = MemoryUtil.getDestroyTargetMemory(maid);
|
BlockTargetMemory blockTargetMemory = MemoryUtil.getDestroyTargetMemory(maid);
|
||||||
if (blockTargetMemory != null) {
|
if (blockTargetMemory != null) {
|
||||||
blockPosSet =new ArrayList<>(blockTargetMemory.getBlockPosSet());
|
blockPosSet = new ArrayList<>(blockTargetMemory.getBlockPosSet());
|
||||||
blockPosSet.sort((o1, o2) -> (int) (o1.distSqr(maid.blockPosition()) - o2.distSqr(maid.blockPosition())));
|
blockPosSet.sort((o1, o2) -> (int) (o1.distSqr(maid.blockPosition().above()) - o2.distSqr(maid.blockPosition().above())));
|
||||||
}
|
}
|
||||||
index = 0;
|
index = 0;
|
||||||
task = (IMaidBlockDestroyTask) maid.getTask();
|
task = (IMaidBlockDestroyTask) maid.getTask();
|
||||||
@@ -61,6 +65,8 @@ public class DestoryBlockBehavior extends Behavior<EntityMaid> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean canStillUse(ServerLevel p_22545_, EntityMaid p_22546_, long p_22547_) {
|
protected boolean canStillUse(ServerLevel p_22545_, EntityMaid p_22546_, long p_22547_) {
|
||||||
|
if (MemoryUtil.getCurrent(p_22546_) != CurrentWork.DESTROY && MemoryUtil.getCurrent(p_22546_) != CurrentWork.BLOCKUP_DESTROY)
|
||||||
|
return false;
|
||||||
return (blockPosSet != null && index < blockPosSet.size()) || targetPos != null;
|
return (blockPosSet != null && index < blockPosSet.size()) || targetPos != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,14 +93,13 @@ public class DestoryBlockBehavior extends Behavior<EntityMaid> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void tickDestroyProgress(EntityMaid maid) {
|
private void tickDestroyProgress(EntityMaid maid) {
|
||||||
float speed = fakePlayer.getMainHandItem().getDestroySpeed(targetBlockState) / fakePlayer.getDigSpeed(targetBlockState, targetPos) / 30;
|
float speed = MaidUtils.getDestroyProgressDelta(maid, targetPos);
|
||||||
MemoryUtil.setLookAt(maid, targetPos);
|
MemoryUtil.setLookAt(maid, targetPos);
|
||||||
if (task.availableToGetDrop(maid, fakePlayer, targetPos, targetBlockState)) {
|
if (speed != 0.0f && task.availableToGetDrop(maid, fakePlayer, targetPos, targetBlockState)) {
|
||||||
maid.swing(InteractionHand.MAIN_HAND);
|
maid.swing(InteractionHand.MAIN_HAND);
|
||||||
destroyProgress += speed;
|
destroyProgress += speed;
|
||||||
if (destroyProgress >= 1f) {
|
if (destroyProgress >= 1f) {
|
||||||
maid.getMainHandItem().hurt(1, maid.getRandom(), fakePlayer);
|
task.tryDestroyBlock(maid, targetPos);
|
||||||
task.tryDestroyBlock(maid,targetPos);
|
|
||||||
destroyProgress = 0f;
|
destroyProgress = 0f;
|
||||||
targetPos = null;
|
targetPos = null;
|
||||||
targetBlockState = null;
|
targetBlockState = null;
|
||||||
@@ -110,6 +115,7 @@ public class DestoryBlockBehavior extends Behavior<EntityMaid> {
|
|||||||
super.stop(p_22548_, p_22549_, p_22550_);
|
super.stop(p_22548_, p_22549_, p_22550_);
|
||||||
MemoryUtil.clearDestroyTargetMemory(p_22549_);
|
MemoryUtil.clearDestroyTargetMemory(p_22549_);
|
||||||
MemoryUtil.clearTarget(p_22549_);
|
MemoryUtil.clearTarget(p_22549_);
|
||||||
|
MemoryUtil.setCurrent(p_22549_, CurrentWork.IDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
package studio.fantasyit.maid_useful_task.behavior;
|
package studio.fantasyit.maid_useful_task.behavior.common;
|
||||||
|
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.ai.brain.task.MaidMoveToBlockTask;
|
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.MaidPathFindingBFS;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.MaidPathFindingBFS;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import studio.fantasyit.maid_useful_task.memory.TaskRateLimitToken;
|
import studio.fantasyit.maid_useful_task.memory.CurrentWork;
|
||||||
import studio.fantasyit.maid_useful_task.task.IMaidBlockDestroyTask;
|
import studio.fantasyit.maid_useful_task.task.IMaidBlockDestroyTask;
|
||||||
import studio.fantasyit.maid_useful_task.util.Conditions;
|
import studio.fantasyit.maid_useful_task.util.Conditions;
|
||||||
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.PosUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -26,16 +26,17 @@ public class DestoryBlockMoveBehavior extends MaidCenterMoveToBlockTask {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean checkExtraStartConditions(ServerLevel p_22538_, EntityMaid p_22539_) {
|
protected boolean checkExtraStartConditions(ServerLevel p_22538_, EntityMaid maid) {
|
||||||
if (MemoryUtil.getRateLimitToken(p_22539_).isFor(TaskRateLimitToken.Level.L1)) {
|
if (!Conditions.isCurrent(maid, CurrentWork.IDLE) && !Conditions.isCurrent(maid, CurrentWork.BLOCKUP_DESTROY))
|
||||||
return false;
|
return false;
|
||||||
}
|
return super.checkExtraStartConditions(p_22538_, maid);
|
||||||
return super.checkExtraStartConditions(p_22538_, p_22539_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void start(@NotNull ServerLevel p_22540_, @NotNull EntityMaid maid, long p_22542_) {
|
protected void start(@NotNull ServerLevel p_22540_, @NotNull EntityMaid maid, long p_22542_) {
|
||||||
super.start(p_22540_, maid, p_22542_);
|
super.start(p_22540_, maid, p_22542_);
|
||||||
|
if (maid.hasRestriction())
|
||||||
|
this.setSearchRange((int) maid.getRestrictRadius());
|
||||||
task = (IMaidBlockDestroyTask) maid.getTask();
|
task = (IMaidBlockDestroyTask) maid.getTask();
|
||||||
task.tryTakeOutTool(maid);
|
task.tryTakeOutTool(maid);
|
||||||
searchForDestination(p_22540_, maid);
|
searchForDestination(p_22540_, maid);
|
||||||
@@ -43,20 +44,28 @@ public class DestoryBlockMoveBehavior extends MaidCenterMoveToBlockTask {
|
|||||||
if (target != null && blockPosSet != null) {
|
if (target != null && blockPosSet != null) {
|
||||||
blockPosSet.addAll(task.getTryDestroyBlockListBesidesStart(targetPos, target, maid));
|
blockPosSet.addAll(task.getTryDestroyBlockListBesidesStart(targetPos, target, maid));
|
||||||
MemoryUtil.setDestroyTargetMemory(maid, blockPosSet);
|
MemoryUtil.setDestroyTargetMemory(maid, blockPosSet);
|
||||||
|
if (Conditions.isCurrent(maid, CurrentWork.IDLE))
|
||||||
|
MemoryUtil.setCurrent(maid, CurrentWork.DESTROY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean shouldMoveTo(@NotNull ServerLevel serverLevel, @NotNull EntityMaid entityMaid, @NotNull BlockPos blockPos) {
|
protected boolean shouldMoveTo(@NotNull ServerLevel serverLevel, @NotNull EntityMaid entityMaid, @NotNull BlockPos blockPos) {
|
||||||
if (!task.shouldDestroyBlock(entityMaid, blockPos)) return false;
|
if (!task.shouldDestroyBlock(entityMaid, blockPos.immutable())) return false;
|
||||||
targetPos = blockPos.immutable();
|
targetPos = blockPos.immutable();
|
||||||
|
BlockPos startPos = entityMaid.blockPosition();
|
||||||
if (blockPos instanceof BlockPos.MutableBlockPos mb) {
|
if (blockPos instanceof BlockPos.MutableBlockPos mb) {
|
||||||
for (int dx = 0; dx < task.reachDistance(); dx = dx <= 0 ? 1 - dx : -dx) {
|
for (int dx = 0; dx < task.reachDistance(); dx = dx <= 0 ? 1 - dx : -dx) {
|
||||||
for (int dy = 0; dy < task.reachDistance(); dy = dy <= 0 ? 1 - dy : -dy) {
|
for (int dy = 0; dy < task.reachDistance(); dy = dy <= 0 ? 1 - dy : -dy) {
|
||||||
for (int dz = 0; dz < task.reachDistance(); dz = dz <= 0 ? 1 - dz : -dz) {
|
for (int dz = 0; dz < task.reachDistance(); dz = dz <= 0 ? 1 - dz : -dz) {
|
||||||
BlockPos pos = mb.offset(dx, dy, dz);
|
BlockPos pos = mb.offset(dx, dy, dz);
|
||||||
|
if (!PosUtils.isSafePos(serverLevel, pos)) continue;
|
||||||
if (!Conditions.isGlobalValidTarget(entityMaid, pos, targetPos)) continue;
|
if (!Conditions.isGlobalValidTarget(entityMaid, pos, targetPos)) continue;
|
||||||
if (pos.distSqr(targetPos) > task.reachDistance() * task.reachDistance()) continue;
|
if (pos.distSqr(targetPos) > task.reachDistance() * task.reachDistance()) continue;
|
||||||
if (entityMaid.isWithinRestriction(pos) && pathfindingBFS.canPathReach(pos)) {
|
if (Math.abs(startPos.getY() - pos.getY()) >= task.reachDistance()) continue;
|
||||||
|
if (Math.abs(startPos.getX() - pos.getX()) >= task.reachDistance()) continue;
|
||||||
|
if (Math.abs(startPos.getZ() - pos.getZ()) >= task.reachDistance()) continue;
|
||||||
|
if (pos.equals(entityMaid.blockPosition()) || (entityMaid.isWithinRestriction(pos) && pathfindingBFS.canPathReach(pos))) {
|
||||||
blockPosSet = task.toDestroyFromStanding(entityMaid, targetPos, pos);
|
blockPosSet = task.toDestroyFromStanding(entityMaid, targetPos, pos);
|
||||||
if (blockPosSet != null) {
|
if (blockPosSet != null) {
|
||||||
mb.set(pos);
|
mb.set(pos);
|
||||||
@@ -75,7 +84,10 @@ public class DestoryBlockMoveBehavior extends MaidCenterMoveToBlockTask {
|
|||||||
@Override
|
@Override
|
||||||
protected @NotNull MaidPathFindingBFS getOrCreateArrivalMap(@NotNull ServerLevel worldIn, @NotNull EntityMaid maid) {
|
protected @NotNull MaidPathFindingBFS getOrCreateArrivalMap(@NotNull ServerLevel worldIn, @NotNull EntityMaid maid) {
|
||||||
if (this.pathfindingBFS == null)
|
if (this.pathfindingBFS == null)
|
||||||
this.pathfindingBFS = new MaidPathFindingBFS(maid.getNavigation().getNodeEvaluator(), worldIn, maid, 14);
|
if (maid.hasRestriction())
|
||||||
|
this.pathfindingBFS = new MaidPathFindingBFS(maid.getNavigation().getNodeEvaluator(), worldIn, maid, (int) maid.getRestrictRadius() + 1, task.reachDistance() + 2);
|
||||||
|
else
|
||||||
|
this.pathfindingBFS = new MaidPathFindingBFS(maid.getNavigation().getNodeEvaluator(), worldIn, maid, task.reachDistance() + 1, task.reachDistance() + 2);
|
||||||
return this.pathfindingBFS;
|
return this.pathfindingBFS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,4 +96,4 @@ public class DestoryBlockMoveBehavior extends MaidCenterMoveToBlockTask {
|
|||||||
super.clearCurrentArrivalMap(pathFinding);
|
super.clearCurrentArrivalMap(pathFinding);
|
||||||
this.pathfindingBFS = null;
|
this.pathfindingBFS = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.behavior.common;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityBroom;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.init.InitEntities;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.tags.StructureTags;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import net.minecraft.world.entity.ai.behavior.Behavior;
|
||||||
|
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
||||||
|
import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
||||||
|
import net.minecraft.world.entity.vehicle.Boat;
|
||||||
|
import net.minecraft.world.item.Items;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import studio.fantasyit.maid_useful_task.registry.MemoryModuleRegistry;
|
||||||
|
import studio.fantasyit.maid_useful_task.task.IMaidFindTargetTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
||||||
|
import studio.fantasyit.maid_useful_task.vehicle.MaidVehicleControlType;
|
||||||
|
import studio.fantasyit.maid_useful_task.vehicle.MaidVehicleManager;
|
||||||
|
|
||||||
|
public class FindTargetMoveBehavior extends Behavior<EntityMaid> {
|
||||||
|
|
||||||
|
public FindTargetMoveBehavior() {
|
||||||
|
super(ImmutableMap.of(
|
||||||
|
MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT,
|
||||||
|
InitEntities.TARGET_POS.get(), MemoryStatus.VALUE_ABSENT
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean checkExtraStartConditions(ServerLevel p_22538_, EntityMaid maid) {
|
||||||
|
IMaidFindTargetTask task = (IMaidFindTargetTask) maid.getTask();
|
||||||
|
if (task.findTarget(p_22538_, maid) == null) return false;
|
||||||
|
if (maid.hasRestriction()) return false;
|
||||||
|
LivingEntity owner = maid.getOwner();
|
||||||
|
return (owner != null && maid.distanceTo(owner) < task.minReScheduleDistance());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void start(ServerLevel serverlevel, EntityMaid maid, long p_22542_) {
|
||||||
|
IMaidFindTargetTask task = (IMaidFindTargetTask) maid.getTask();
|
||||||
|
LivingEntity owner = maid.getOwner();
|
||||||
|
if (owner == null) return;
|
||||||
|
BlockPos target = task.findTarget(serverlevel, maid);
|
||||||
|
if (target != null) {
|
||||||
|
if (maid.distanceToSqr(target.getCenter()) < 9) {
|
||||||
|
maid.getJumpControl().jump();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BlockPos finalTarget = target;
|
||||||
|
BlockPos ownerPos = owner.blockPosition();
|
||||||
|
BlockPos maidPos = maid.blockPosition();
|
||||||
|
if (finalTarget.distSqr(ownerPos) > task.maxOutDistance() * task.maxOutDistance()) {
|
||||||
|
Vec3 dVec = target.getCenter().subtract(owner.position());
|
||||||
|
dVec = dVec.normalize().scale(task.maxOutDistance() - (double) (task.maxOutDistance() - task.minReScheduleDistance()) / 2);
|
||||||
|
BlockPos fTarget = maidPos.offset((int) dVec.x, (int) dVec.y, (int) dVec.z);
|
||||||
|
|
||||||
|
for (int x = 0; x < 3; x = x <= 0 ? 1 - x : -x) {
|
||||||
|
for (int z = 0; z < 3; z = z <= 0 ? 1 - z : -z) {
|
||||||
|
int y = 0;
|
||||||
|
while (!serverlevel.getBlockState(fTarget.offset(x, y, z)).isAir()) y++;
|
||||||
|
while (!serverlevel.getBlockState(fTarget.offset(x, y, z)).isAir()) y--;
|
||||||
|
|
||||||
|
if (fTarget.offset(x, y, z).distSqr(ownerPos) < task.maxOutDistance() * task.maxOutDistance()) {
|
||||||
|
finalTarget = fTarget.offset(x, y, z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (finalTarget.distSqr(maidPos) < task.maxOutDistance() * task.maxOutDistance()) {
|
||||||
|
double distanceToOwner = maidPos.distSqr(ownerPos);
|
||||||
|
double speed = 0.4;
|
||||||
|
if (distanceToOwner < 4 * 4) {
|
||||||
|
speed = 0.5;
|
||||||
|
}
|
||||||
|
if (distanceToOwner < 3 * 3) {
|
||||||
|
speed = 0.64;
|
||||||
|
}
|
||||||
|
MemoryUtil.setTarget(maid, finalTarget, (float) speed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.behavior.common;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.init.InitEntities;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import net.minecraft.world.entity.ai.behavior.Behavior;
|
||||||
|
import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
||||||
|
import net.minecraft.world.item.Items;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import studio.fantasyit.maid_useful_task.task.IMaidFindTargetTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.Conditions;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
||||||
|
|
||||||
|
public class FindTargetWaitBehavior extends Behavior<EntityMaid> {
|
||||||
|
|
||||||
|
public FindTargetWaitBehavior() {
|
||||||
|
super(ImmutableMap.of(InitEntities.TARGET_POS.get(), MemoryStatus.VALUE_PRESENT));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean checkExtraStartConditions(ServerLevel serverLevel, EntityMaid maid) {
|
||||||
|
IMaidFindTargetTask task = (IMaidFindTargetTask) maid.getTask();
|
||||||
|
if (task.findTarget(serverLevel, maid) == null) return true;
|
||||||
|
if (maid.hasRestriction()) return false;
|
||||||
|
LivingEntity owner = maid.getOwner();
|
||||||
|
if (owner != null && maid.distanceTo(owner) > task.maxOutDistance()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return Conditions.hasReachedValidTargetOrReset(maid, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void start(@NotNull ServerLevel serverLevel, EntityMaid maid, long p_22542_) {
|
||||||
|
IMaidFindTargetTask task = (IMaidFindTargetTask) maid.getTask();
|
||||||
|
if (task.findTarget(serverLevel, maid) == null) {
|
||||||
|
task.clearCache(maid);
|
||||||
|
}
|
||||||
|
MemoryUtil.clearTarget(maid);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package studio.fantasyit.maid_useful_task.behavior;
|
package studio.fantasyit.maid_useful_task.behavior.common;
|
||||||
|
|
||||||
|
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.ai.brain.task.MaidCheckRateTask;
|
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.MaidPathFindingBFS;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.MaidPathFindingBFS;
|
||||||
import com.github.tartaricacid.touhoulittlemaid.init.InitEntities;
|
import com.github.tartaricacid.touhoulittlemaid.init.InitEntities;
|
||||||
@@ -13,6 +12,7 @@ import net.minecraft.world.entity.ai.behavior.BehaviorUtils;
|
|||||||
import net.minecraft.world.entity.ai.behavior.BlockPosTracker;
|
import net.minecraft.world.entity.ai.behavior.BlockPosTracker;
|
||||||
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
||||||
import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.MaidUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* From https://github.com/TartaricAcid/TouhouLittleMaid
|
* From https://github.com/TartaricAcid/TouhouLittleMaid
|
||||||
@@ -23,7 +23,7 @@ abstract public class MaidCenterMoveToBlockTask extends Behavior<EntityMaid> {
|
|||||||
private static final int MAX_DELAY_TIME = 120;
|
private static final int MAX_DELAY_TIME = 120;
|
||||||
private final float movementSpeed;
|
private final float movementSpeed;
|
||||||
private final int verticalSearchRange;
|
private final int verticalSearchRange;
|
||||||
private final int searchRange;
|
private int searchRange;
|
||||||
protected int verticalSearchStart;
|
protected int verticalSearchStart;
|
||||||
|
|
||||||
public MaidCenterMoveToBlockTask(float movementSpeed) {
|
public MaidCenterMoveToBlockTask(float movementSpeed) {
|
||||||
@@ -33,11 +33,16 @@ abstract public class MaidCenterMoveToBlockTask extends Behavior<EntityMaid> {
|
|||||||
public MaidCenterMoveToBlockTask(float movementSpeed, int verticalSearchRange) {
|
public MaidCenterMoveToBlockTask(float movementSpeed, int verticalSearchRange) {
|
||||||
this(movementSpeed, verticalSearchRange, 7);
|
this(movementSpeed, verticalSearchRange, 7);
|
||||||
}
|
}
|
||||||
public MaidCenterMoveToBlockTask(float movementSpeed, int verticalSearchRange,int searchRange) {
|
|
||||||
|
public MaidCenterMoveToBlockTask(float movementSpeed, int verticalSearchRange, int defaultSearchRange) {
|
||||||
super(ImmutableMap.of(MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT, InitEntities.TARGET_POS.get(), MemoryStatus.VALUE_ABSENT));
|
super(ImmutableMap.of(MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT, InitEntities.TARGET_POS.get(), MemoryStatus.VALUE_ABSENT));
|
||||||
this.movementSpeed = movementSpeed;
|
this.movementSpeed = movementSpeed;
|
||||||
this.verticalSearchRange = verticalSearchRange;
|
this.verticalSearchRange = verticalSearchRange;
|
||||||
this.searchRange = searchRange;
|
this.searchRange = defaultSearchRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSearchRange(int searchRange) {
|
||||||
|
this.searchRange = searchRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void searchForDestination(ServerLevel worldIn, EntityMaid maid) {
|
protected final void searchForDestination(ServerLevel worldIn, EntityMaid maid) {
|
||||||
@@ -45,14 +50,14 @@ abstract public class MaidCenterMoveToBlockTask extends Behavior<EntityMaid> {
|
|||||||
BlockPos centrePos = this.getWorkSearchPos(maid);
|
BlockPos centrePos = this.getWorkSearchPos(maid);
|
||||||
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
|
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
|
||||||
|
|
||||||
for(int y = this.verticalSearchStart; y <= this.verticalSearchRange; y = y > 0 ? -y : 1 - y) {
|
for (int y = this.verticalSearchStart; y <= this.verticalSearchRange; y = y > 0 ? -y : 1 - y) {
|
||||||
for(int i = 0; i < searchRange; ++i) {
|
for (int i = 0; i < searchRange; ++i) {
|
||||||
for(int x = 0; x <= i; x = x > 0 ? -x : 1 - x) {
|
for (int x = 0; x <= i; x = x > 0 ? -x : 1 - x) {
|
||||||
for(int z = x < i && x > -i ? i : 0; z <= i; z = z > 0 ? -z : 1 - z) {
|
for (int z = x < i && x > -i ? i : 0; z <= i; z = z > 0 ? -z : 1 - z) {
|
||||||
mutableBlockPos.setWithOffset(centrePos, x, y - 1, z);
|
mutableBlockPos.setWithOffset(centrePos, x, y - 1, z);
|
||||||
if (maid.isWithinRestriction(mutableBlockPos) && this.shouldMoveTo(worldIn, maid, mutableBlockPos) && this.checkPathReach(maid, pathFinding, mutableBlockPos) && this.checkOwnerPos(maid, mutableBlockPos)) {
|
if (this.shouldMoveTo(worldIn, maid, mutableBlockPos) && this.checkPathReach(maid, pathFinding, mutableBlockPos) && this.checkOwnerPos(maid, mutableBlockPos)) {
|
||||||
BehaviorUtils.setWalkAndLookTargetMemories(maid, mutableBlockPos, this.movementSpeed, 0);
|
BehaviorUtils.setWalkAndLookTargetMemories(maid, mutableBlockPos, this.movementSpeed, 0);
|
||||||
maid.getBrain().setMemory((MemoryModuleType)InitEntities.TARGET_POS.get(), new BlockPosTracker(mutableBlockPos));
|
maid.getBrain().setMemory((MemoryModuleType) InitEntities.TARGET_POS.get(), new BlockPosTracker(mutableBlockPos));
|
||||||
this.clearCurrentArrivalMap(pathFinding);
|
this.clearCurrentArrivalMap(pathFinding);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -69,11 +74,11 @@ abstract public class MaidCenterMoveToBlockTask extends Behavior<EntityMaid> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected MaidPathFindingBFS getOrCreateArrivalMap(ServerLevel worldIn, EntityMaid maid) {
|
protected MaidPathFindingBFS getOrCreateArrivalMap(ServerLevel worldIn, EntityMaid maid) {
|
||||||
return new MaidPathFindingBFS(maid.getNavigation().getNodeEvaluator(), worldIn, maid);
|
return new MaidPathFindingBFS(maid.getNavigation().getNodeEvaluator(), worldIn, maid, maid.searchRadius(), 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlockPos getWorkSearchPos(EntityMaid maid) {
|
private BlockPos getWorkSearchPos(EntityMaid maid) {
|
||||||
return maid.blockPosition();
|
return MaidUtils.getMaidRestrictCenter(maid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkOwnerPos(EntityMaid maid, BlockPos mutableBlockPos) {
|
private boolean checkOwnerPos(EntityMaid maid, BlockPos mutableBlockPos) {
|
||||||
@@ -86,7 +91,9 @@ abstract public class MaidCenterMoveToBlockTask extends Behavior<EntityMaid> {
|
|||||||
|
|
||||||
protected abstract boolean shouldMoveTo(ServerLevel var1, EntityMaid var2, BlockPos var3);
|
protected abstract boolean shouldMoveTo(ServerLevel var1, EntityMaid var2, BlockPos var3);
|
||||||
|
|
||||||
/** @deprecated */
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
@Deprecated(
|
@Deprecated(
|
||||||
forRemoval = true
|
forRemoval = true
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.behavior.common;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.entity.ai.behavior.Behavior;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||||
|
import studio.fantasyit.maid_useful_task.Config;
|
||||||
|
import studio.fantasyit.maid_useful_task.memory.CurrentWork;
|
||||||
|
import studio.fantasyit.maid_useful_task.task.IMaidBlockDestroyTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MaidSelfRescueBehavior extends Behavior<EntityMaid> {
|
||||||
|
public MaidSelfRescueBehavior() {
|
||||||
|
super(Map.of(), 600);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean started = false;
|
||||||
|
|
||||||
|
private static boolean isNotSafeAndCanTryToDestroy(ServerLevel level, EntityMaid maid, BlockPos pos, IMaidBlockDestroyTask task) {
|
||||||
|
BlockState bs = level.getBlockState(pos);
|
||||||
|
if (bs.isAir()) return false;
|
||||||
|
VoxelShape collision = bs.getCollisionShape(level, pos);
|
||||||
|
if (collision.isEmpty()) return false;
|
||||||
|
return maid.getBoundingBox().intersects(collision.bounds().move(pos)) && bs.isSuffocating(level, pos) && task.mayDestroy(maid, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean checkExtraStartConditions(ServerLevel level, EntityMaid maid) {
|
||||||
|
if (!Config.enableSelfRescue) return false;
|
||||||
|
if (!(maid.getTask() instanceof IMaidBlockDestroyTask ibdt)) return false;
|
||||||
|
if (isNotSafeAndCanTryToDestroy(level, maid, maid.blockPosition(), ibdt) || isNotSafeAndCanTryToDestroy(level, maid, maid.blockPosition().above(), ibdt))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean canStillUse(ServerLevel p_22545_, EntityMaid p_22546_, long p_22547_) {
|
||||||
|
return started && checkExtraStartConditions(p_22545_, p_22546_);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void start(ServerLevel p_22540_, EntityMaid maid, long p_22542_) {
|
||||||
|
started = false;
|
||||||
|
if (MemoryUtil.getCurrent(maid) == CurrentWork.DESTROY) {
|
||||||
|
//如果执行中破坏任务,则立刻停止。用以清空相关状态
|
||||||
|
MemoryUtil.setCurrent(maid, CurrentWork.IDLE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//等待上一个任务结束
|
||||||
|
if (MemoryUtil.getDestroyTargetMemory(maid) != null)
|
||||||
|
return;
|
||||||
|
if (!(maid.getTask() instanceof IMaidBlockDestroyTask task))
|
||||||
|
return;
|
||||||
|
|
||||||
|
started = true;
|
||||||
|
|
||||||
|
List<BlockPos> list = new ArrayList<>();
|
||||||
|
if (isNotSafeAndCanTryToDestroy(p_22540_, maid, maid.blockPosition(), task)) {
|
||||||
|
list.add(maid.blockPosition());
|
||||||
|
}
|
||||||
|
if (isNotSafeAndCanTryToDestroy(p_22540_, maid, maid.blockPosition().above(), task)) {
|
||||||
|
list.add(maid.blockPosition().above());
|
||||||
|
}
|
||||||
|
MemoryUtil.setDestroyTargetMemory(maid, list);
|
||||||
|
MemoryUtil.setTarget(maid, maid.blockPosition(), 0.5f);
|
||||||
|
MemoryUtil.setCurrent(maid, CurrentWork.DESTROY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void stop(ServerLevel p_22548_, EntityMaid p_22549_, long p_22550_) {
|
||||||
|
MemoryUtil.clearTarget(p_22549_);
|
||||||
|
MemoryUtil.setCurrent(p_22549_, CurrentWork.IDLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package studio.fantasyit.maid_useful_task.behavior;
|
package studio.fantasyit.maid_useful_task.behavior.common;
|
||||||
|
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
import com.github.tartaricacid.touhoulittlemaid.init.InitEntities;
|
import com.github.tartaricacid.touhoulittlemaid.init.InitEntities;
|
||||||
@@ -7,6 +7,7 @@ import net.minecraft.server.level.ServerLevel;
|
|||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.entity.ai.behavior.Behavior;
|
import net.minecraft.world.entity.ai.behavior.Behavior;
|
||||||
import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
||||||
|
import studio.fantasyit.maid_useful_task.memory.CurrentWork;
|
||||||
import studio.fantasyit.maid_useful_task.registry.MemoryModuleRegistry;
|
import studio.fantasyit.maid_useful_task.registry.MemoryModuleRegistry;
|
||||||
import studio.fantasyit.maid_useful_task.task.IMaidBlockPlaceTask;
|
import studio.fantasyit.maid_useful_task.task.IMaidBlockPlaceTask;
|
||||||
import studio.fantasyit.maid_useful_task.util.Conditions;
|
import studio.fantasyit.maid_useful_task.util.Conditions;
|
||||||
@@ -24,8 +25,9 @@ public class PlaceBlockBehavior extends Behavior<EntityMaid> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean checkExtraStartConditions(ServerLevel p_22538_, EntityMaid p_22539_) {
|
protected boolean checkExtraStartConditions(ServerLevel p_22538_, EntityMaid maid) {
|
||||||
return Conditions.hasReachedValidTargetOrReset(p_22539_);
|
MemoryUtil.setCurrent(maid, CurrentWork.PLACE);
|
||||||
|
return Conditions.hasReachedValidTargetOrReset(maid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -59,5 +61,6 @@ public class PlaceBlockBehavior extends Behavior<EntityMaid> {
|
|||||||
super.stop(p_22548_, p_22549_, p_22550_);
|
super.stop(p_22548_, p_22549_, p_22550_);
|
||||||
MemoryUtil.clearPlaceTarget(p_22549_);
|
MemoryUtil.clearPlaceTarget(p_22549_);
|
||||||
MemoryUtil.clearTarget(p_22549_);
|
MemoryUtil.clearTarget(p_22549_);
|
||||||
|
MemoryUtil.setCurrent(p_22549_, CurrentWork.IDLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,15 @@
|
|||||||
package studio.fantasyit.maid_useful_task.behavior;
|
package studio.fantasyit.maid_useful_task.behavior.common;
|
||||||
|
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.ai.brain.task.MaidMoveToBlockTask;
|
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.MaidPathFindingBFS;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.MaidPathFindingBFS;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
import net.neoforged.neoforge.items.wrapper.CombinedInvWrapper;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import studio.fantasyit.maid_useful_task.memory.TaskRateLimitToken;
|
import studio.fantasyit.maid_useful_task.memory.CurrentWork;
|
||||||
import studio.fantasyit.maid_useful_task.task.IMaidBlockPlaceTask;
|
import studio.fantasyit.maid_useful_task.task.IMaidBlockPlaceTask;
|
||||||
import studio.fantasyit.maid_useful_task.util.Conditions;
|
import studio.fantasyit.maid_useful_task.util.Conditions;
|
||||||
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
||||||
@@ -30,16 +29,16 @@ public class PlaceBlockMoveBehavior extends MaidCenterMoveToBlockTask {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean checkExtraStartConditions(ServerLevel p_22538_, EntityMaid p_22539_) {
|
protected boolean checkExtraStartConditions(ServerLevel p_22538_, EntityMaid maid) {
|
||||||
if (MemoryUtil.getRateLimitToken(p_22539_).isFor(TaskRateLimitToken.Level.L2)) {
|
if (!Conditions.isCurrent(maid, CurrentWork.IDLE)) return false;
|
||||||
return false;
|
return super.checkExtraStartConditions(p_22538_, maid);
|
||||||
}
|
|
||||||
return super.checkExtraStartConditions(p_22538_, p_22539_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void start(ServerLevel p_22540_, EntityMaid maid, long p_22542_) {
|
protected void start(ServerLevel p_22540_, EntityMaid maid, long p_22542_) {
|
||||||
super.start(p_22540_, maid, p_22542_);
|
super.start(p_22540_, maid, p_22542_);
|
||||||
|
if (maid.hasRestriction())
|
||||||
|
this.setSearchRange((int) maid.getRestrictRadius());
|
||||||
task = (IMaidBlockPlaceTask) maid.getTask();
|
task = (IMaidBlockPlaceTask) maid.getTask();
|
||||||
CombinedInvWrapper inv = maid.getAvailableInv(true);
|
CombinedInvWrapper inv = maid.getAvailableInv(true);
|
||||||
List<ItemStack> markedVis = new ArrayList<>();
|
List<ItemStack> markedVis = new ArrayList<>();
|
||||||
@@ -52,6 +51,7 @@ public class PlaceBlockMoveBehavior extends MaidCenterMoveToBlockTask {
|
|||||||
@Nullable BlockPos target = MemoryUtil.getTargetPos(maid);
|
@Nullable BlockPos target = MemoryUtil.getTargetPos(maid);
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
MemoryUtil.setPlaceTarget(maid, targetPos);
|
MemoryUtil.setPlaceTarget(maid, targetPos);
|
||||||
|
MemoryUtil.setCurrent(maid, CurrentWork.PLACE);
|
||||||
inv.setStackInSlot(finalI, maid.getMainHandItem());
|
inv.setStackInSlot(finalI, maid.getMainHandItem());
|
||||||
maid.setItemInHand(InteractionHand.MAIN_HAND, targetItem);
|
maid.setItemInHand(InteractionHand.MAIN_HAND, targetItem);
|
||||||
return;
|
return;
|
||||||
@@ -62,7 +62,8 @@ public class PlaceBlockMoveBehavior extends MaidCenterMoveToBlockTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean shouldMoveTo(ServerLevel serverLevel, EntityMaid entityMaid, BlockPos blockPos) {
|
protected boolean shouldMoveTo(ServerLevel serverLevel, EntityMaid entityMaid, BlockPos blockPos) {
|
||||||
if (!task.shouldPlacePos(entityMaid, targetItem, blockPos)) return false;
|
if (!task.shouldPlacePos(entityMaid, targetItem, blockPos.immutable())) return false;
|
||||||
|
if (!entityMaid.isWithinRestriction(blockPos)) return false;
|
||||||
targetPos = blockPos.immutable();
|
targetPos = blockPos.immutable();
|
||||||
if (blockPos instanceof BlockPos.MutableBlockPos mb) {
|
if (blockPos instanceof BlockPos.MutableBlockPos mb) {
|
||||||
final int[] dv = {0, 1, -1};
|
final int[] dv = {0, 1, -1};
|
||||||
@@ -87,7 +88,10 @@ public class PlaceBlockMoveBehavior extends MaidCenterMoveToBlockTask {
|
|||||||
@Override
|
@Override
|
||||||
protected @NotNull MaidPathFindingBFS getOrCreateArrivalMap(@NotNull ServerLevel worldIn, @NotNull EntityMaid maid) {
|
protected @NotNull MaidPathFindingBFS getOrCreateArrivalMap(@NotNull ServerLevel worldIn, @NotNull EntityMaid maid) {
|
||||||
if (this.pathfindingBFS == null)
|
if (this.pathfindingBFS == null)
|
||||||
this.pathfindingBFS = new MaidPathFindingBFS(maid.getNavigation().getNodeEvaluator(), worldIn, maid, 10);
|
if (maid.hasRestriction())
|
||||||
|
this.pathfindingBFS = new MaidPathFindingBFS(maid.getNavigation().getNodeEvaluator(), worldIn, maid, (int) maid.getRestrictRadius(), 9);
|
||||||
|
else
|
||||||
|
this.pathfindingBFS = new MaidPathFindingBFS(maid.getNavigation().getNodeEvaluator(), worldIn, maid, 7, 9);
|
||||||
return this.pathfindingBFS;
|
return this.pathfindingBFS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.behavior.common;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.ai.brain.task.MaidCheckRateTask;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
||||||
|
import studio.fantasyit.maid_useful_task.registry.MemoryModuleRegistry;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class UpdateValidationMemoryBehavior extends MaidCheckRateTask {
|
||||||
|
public UpdateValidationMemoryBehavior() {
|
||||||
|
super(Map.of(MemoryModuleRegistry.BLOCK_VALIDATION.get(), MemoryStatus.VALUE_PRESENT));
|
||||||
|
this.setMaxCheckRate(600);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void start(ServerLevel p_22540_, EntityMaid p_22541_, long p_22542_) {
|
||||||
|
//Hardcoded range?
|
||||||
|
MemoryUtil.getBlockValidationMemory(p_22541_).clearFaraway(p_22541_.blockPosition(), 72);
|
||||||
|
MemoryUtil.getBlockValidationMemory(p_22541_).clearIf(pos -> p_22540_.getBlockState(pos).isAir());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.client;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.neoforged.api.distmarker.Dist;
|
||||||
|
import net.neoforged.api.distmarker.OnlyIn;
|
||||||
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
|
import net.neoforged.neoforge.client.event.InputEvent;
|
||||||
|
import net.neoforged.neoforge.network.PacketDistributor;
|
||||||
|
import studio.fantasyit.maid_useful_task.MaidUsefulTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.network.MaidAllowHandleVehicle;
|
||||||
|
|
||||||
|
import static studio.fantasyit.maid_useful_task.client.KeyMapping.KEY_SWITCH_VEHICLE_CONTROL;
|
||||||
|
|
||||||
|
@EventBusSubscriber(modid = MaidUsefulTask.MODID, bus = EventBusSubscriber.Bus.GAME, value = Dist.CLIENT)
|
||||||
|
public class KeyEvents {
|
||||||
|
@SubscribeEvent
|
||||||
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
public static void keyInput(InputEvent.Key event) {
|
||||||
|
while (KEY_SWITCH_VEHICLE_CONTROL.get().consumeClick()) {
|
||||||
|
Player player = Minecraft.getInstance().player;
|
||||||
|
if (!player.isPassenger()) return;
|
||||||
|
EntityMaid maid = player
|
||||||
|
.getVehicle()
|
||||||
|
.getPassengers()
|
||||||
|
.stream()
|
||||||
|
.filter(entity -> entity instanceof EntityMaid)
|
||||||
|
.map(entity -> (EntityMaid) entity)
|
||||||
|
.findAny()
|
||||||
|
.orElse(null);
|
||||||
|
if (maid == null) return;
|
||||||
|
PacketDistributor.sendToServer(new MaidAllowHandleVehicle(maid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.client;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.InputConstants;
|
||||||
|
import net.neoforged.api.distmarker.Dist;
|
||||||
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
|
import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent;
|
||||||
|
import net.neoforged.neoforge.common.util.Lazy;
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
import studio.fantasyit.maid_useful_task.MaidUsefulTask;
|
||||||
|
|
||||||
|
@EventBusSubscriber(modid = MaidUsefulTask.MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
|
||||||
|
public class KeyMapping {
|
||||||
|
|
||||||
|
public static final Lazy<net.minecraft.client.KeyMapping> KEY_SWITCH_VEHICLE_CONTROL = Lazy.of(() -> new net.minecraft.client.KeyMapping(
|
||||||
|
"key.maid_useful_tasks.switch_vehicle_control",
|
||||||
|
InputConstants.Type.KEYSYM,
|
||||||
|
GLFW.GLFW_KEY_V,
|
||||||
|
"key.maid_useful_tasks.categories.main"
|
||||||
|
));
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void registerKeyMappings(final RegisterKeyMappingsEvent event) {
|
||||||
|
event.register(KEY_SWITCH_VEHICLE_CONTROL.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.compat;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.neoforged.fml.ModList;
|
||||||
|
|
||||||
|
public class CompatEntry {
|
||||||
|
public static BlockPos getLocateTarget(EntityMaid maid, ItemStack itemStack) {
|
||||||
|
BlockPos tmp = null;
|
||||||
|
if (tmp == null && ModList.get().isLoaded("naturescompass")) {
|
||||||
|
tmp = NatureCompass.getCompassTarget(maid, itemStack);
|
||||||
|
}
|
||||||
|
if (tmp == null && ModList.get().isLoaded("explorerscompass")) {
|
||||||
|
tmp = ExplorerCompass.getCompassTarget(maid, itemStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.compat;
|
||||||
|
|
||||||
|
import com.chaosthedude.explorerscompass.ExplorersCompass;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
public class ExplorerCompass {
|
||||||
|
public static BlockPos getCompassTarget(EntityMaid maid, ItemStack itemStack) {
|
||||||
|
if (itemStack.is(ExplorersCompass.explorersCompass)) {
|
||||||
|
return new BlockPos(
|
||||||
|
ExplorersCompass.explorersCompass.getFoundStructureX(itemStack),
|
||||||
|
maid.level().getSeaLevel(),
|
||||||
|
ExplorersCompass.explorersCompass.getFoundStructureZ(itemStack)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.compat;
|
||||||
|
|
||||||
|
import com.chaosthedude.naturescompass.NaturesCompass;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
public class NatureCompass {
|
||||||
|
public static BlockPos getCompassTarget(EntityMaid maid, ItemStack itemStack) {
|
||||||
|
if (itemStack.is(NaturesCompass.naturesCompass)) {
|
||||||
|
return new BlockPos(
|
||||||
|
NaturesCompass.naturesCompass.getFoundBiomeX(itemStack),
|
||||||
|
maid.level().getSeaLevel(),
|
||||||
|
NaturesCompass.naturesCompass.getFoundBiomeZ(itemStack)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.compat;
|
||||||
|
|
||||||
|
|
||||||
|
import net.neoforged.fml.ModList;
|
||||||
|
|
||||||
|
public class PlayerRevive {
|
||||||
|
public static boolean isEnable(){
|
||||||
|
return ModList.get().isLoaded("playerrevive");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.data;
|
||||||
|
|
||||||
|
public interface IConfigSetter {
|
||||||
|
void setConfigValue(String name, String value);
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.data;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.api.entity.data.TaskDataKey;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import oshi.util.tuples.Pair;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class MaidConfigKeys {
|
||||||
|
record keyAndDefSupp<T>(TaskDataKey<T> key, Supplier<T> defaultValue) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<ResourceLocation, keyAndDefSupp<?>> keys = new HashMap<>();
|
||||||
|
|
||||||
|
public static <T> void addKey(ResourceLocation key, TaskDataKey<T> dataKey, Supplier<T> defaultValue) {
|
||||||
|
keys.put(key, new keyAndDefSupp<>(dataKey, defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T getValue(EntityMaid maid, ResourceLocation key) {
|
||||||
|
keyAndDefSupp<T> pair = (keyAndDefSupp<T>) keys.get(key);
|
||||||
|
return maid.getOrCreateData(pair.key, pair.defaultValue.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.data;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.api.entity.data.TaskDataKey;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import studio.fantasyit.maid_useful_task.MaidUsefulTask;
|
||||||
|
|
||||||
|
public class MaidLoggingConfig implements TaskDataKey<MaidLoggingConfig.Data> {
|
||||||
|
|
||||||
|
|
||||||
|
public static Data get(EntityMaid maid) {
|
||||||
|
return maid.getOrCreateData(KEY, Data.getDefault());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Data implements IConfigSetter {
|
||||||
|
private boolean plant;
|
||||||
|
private boolean blockUp;
|
||||||
|
private boolean skipNonNature;
|
||||||
|
|
||||||
|
public Data(boolean plant, boolean blockUp, boolean skipNonNature) {
|
||||||
|
this.plant = plant;
|
||||||
|
this.blockUp = blockUp;
|
||||||
|
this.skipNonNature = skipNonNature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Data getDefault() {
|
||||||
|
return new Data(true, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean plant() {
|
||||||
|
return plant;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void plant(boolean plant) {
|
||||||
|
this.plant = plant;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean blockUp() {
|
||||||
|
return blockUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void blockUp(boolean blockUp) {
|
||||||
|
this.blockUp = blockUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean skipNonNature() {
|
||||||
|
return skipNonNature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void skipNonNature(boolean skipNonNature) {
|
||||||
|
this.skipNonNature = skipNonNature;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setConfigValue(String name, String value) {
|
||||||
|
switch (name) {
|
||||||
|
case "plant":
|
||||||
|
plant = Boolean.parseBoolean(value);
|
||||||
|
break;
|
||||||
|
case "blockUp":
|
||||||
|
blockUp = Boolean.parseBoolean(value);
|
||||||
|
break;
|
||||||
|
case "skipNonNature":
|
||||||
|
skipNonNature = Boolean.parseBoolean(value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TaskDataKey<Data> KEY = null;
|
||||||
|
public static final ResourceLocation LOCATION = ResourceLocation.fromNamespaceAndPath(MaidUsefulTask.MODID, "logging");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getKey() {
|
||||||
|
return LOCATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundTag writeSaveData(Data data) {
|
||||||
|
CompoundTag tag = new CompoundTag();
|
||||||
|
tag.putBoolean("plant", data.plant);
|
||||||
|
tag.putBoolean("blockUp", data.blockUp);
|
||||||
|
tag.putBoolean("skipNonNature", data.skipNonNature);
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Data readSaveData(CompoundTag compound) {
|
||||||
|
boolean plant = compound.getBoolean("plant");
|
||||||
|
boolean blockUp = compound.getBoolean("blockUp");
|
||||||
|
boolean skipNonNature = compound.getBoolean("skipNonNature");
|
||||||
|
return new Data(plant, blockUp, skipNonNature);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.data;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.api.entity.data.TaskDataKey;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import studio.fantasyit.maid_useful_task.MaidUsefulTask;
|
||||||
|
|
||||||
|
public class MaidReviveConfig implements TaskDataKey<MaidReviveConfig.Data> {
|
||||||
|
public static final class Data implements IConfigSetter {
|
||||||
|
private boolean ownerOnly;
|
||||||
|
|
||||||
|
public Data(boolean ownerOnly) {
|
||||||
|
this.ownerOnly = ownerOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Data getDefault() {
|
||||||
|
return new Data(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean ownerOnly() {
|
||||||
|
return ownerOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ownerOnly(boolean ownerOnly) {
|
||||||
|
this.ownerOnly = ownerOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setConfigValue(String name, String value) {
|
||||||
|
switch (name) {
|
||||||
|
case "ownerOnly":
|
||||||
|
ownerOnly = Boolean.parseBoolean(value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TaskDataKey<Data> KEY = null;
|
||||||
|
public static final ResourceLocation LOCATION = ResourceLocation.fromNamespaceAndPath(MaidUsefulTask.MODID, "revive");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getKey() {
|
||||||
|
return LOCATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundTag writeSaveData(Data data) {
|
||||||
|
CompoundTag tag = new CompoundTag();
|
||||||
|
tag.putBoolean("ownerOnly", data.ownerOnly);
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Data readSaveData(CompoundTag compound) {
|
||||||
|
boolean plant = compound.getBoolean("ownerOnly");
|
||||||
|
return new Data(plant);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.event;
|
||||||
|
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
|
import studio.fantasyit.maid_useful_task.MaidUsefulTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.task.IMaidVehicleControlTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.vehicle.MaidVehicleManager;
|
||||||
|
|
||||||
|
@EventBusSubscriber(modid = MaidUsefulTask.MODID, bus = EventBusSubscriber.Bus.GAME)
|
||||||
|
public class MaidTickEvent {
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onTick(com.github.tartaricacid.touhoulittlemaid.api.event.MaidTickEvent event) {
|
||||||
|
if (event.getMaid().level() instanceof ServerLevel sl)
|
||||||
|
if (event.getMaid().getTask() instanceof IMaidVehicleControlTask imvc && event.getMaid().getVehicle() != null) {
|
||||||
|
imvc.tick(sl, event.getMaid());
|
||||||
|
MaidVehicleManager.syncVehicleParameter(event.getMaid());
|
||||||
|
} else if (event.getMaid().getVehicle() != null) {
|
||||||
|
MaidVehicleManager.stopControlling(event.getMaid());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.memory;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
public class BlockValidationMemory {
|
||||||
|
public static final Codec<BlockValidationMemory> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||||
|
Codec.list(BlockPos.CODEC).fieldOf("validList").forGetter(BlockValidationMemory::getValidList),
|
||||||
|
Codec.list(BlockPos.CODEC).fieldOf("invalidList").forGetter(BlockValidationMemory::getInvalidList)
|
||||||
|
).apply(instance, BlockValidationMemory::new)
|
||||||
|
);
|
||||||
|
|
||||||
|
private final Set<BlockPos> validSet = new HashSet<>();
|
||||||
|
private final Set<BlockPos> invalidSet = new HashSet<>();
|
||||||
|
|
||||||
|
public BlockValidationMemory() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockValidationMemory(List<BlockPos> validList, List<BlockPos> invalidList) {
|
||||||
|
validSet.addAll(validList);
|
||||||
|
invalidSet.addAll(invalidList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BlockPos> getValidList() {
|
||||||
|
return List.copyOf(validSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BlockPos> getInvalidList() {
|
||||||
|
return List.copyOf(invalidSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValid(BlockPos blockPos) {
|
||||||
|
validSet.add(blockPos);
|
||||||
|
invalidSet.remove(blockPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInvalid(BlockPos blockPos) {
|
||||||
|
invalidSet.add(blockPos);
|
||||||
|
validSet.remove(blockPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(BlockPos blockPos) {
|
||||||
|
validSet.remove(blockPos);
|
||||||
|
invalidSet.remove(blockPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValid(BlockPos blockPos, boolean defaultValue) {
|
||||||
|
if (validSet.contains(blockPos)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (invalidSet.contains(blockPos)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasRecord(BlockPos blockPos) {
|
||||||
|
return validSet.contains(blockPos) || invalidSet.contains(blockPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearFaraway(BlockPos blockPos, int range) {
|
||||||
|
clearIf(pos->pos.distSqr(blockPos) > range * range);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearIf(Predicate<BlockPos> o) {
|
||||||
|
validSet.removeIf(o);
|
||||||
|
invalidSet.removeIf(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.memory;
|
||||||
|
|
||||||
|
public enum CurrentWork {
|
||||||
|
IDLE,
|
||||||
|
PLACE,
|
||||||
|
DESTROY,
|
||||||
|
BLOCKUP_UP,
|
||||||
|
BLOCKUP_DOWN,
|
||||||
|
BLOCKUP_DESTROY
|
||||||
|
}
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package studio.fantasyit.maid_useful_task.memory;
|
|
||||||
|
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
|
||||||
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
|
||||||
|
|
||||||
public class TaskRateLimitToken {
|
|
||||||
public enum Level {
|
|
||||||
|
|
||||||
IDLE(0),
|
|
||||||
L1(1),
|
|
||||||
L2(2),
|
|
||||||
L3(3),
|
|
||||||
L4(4),
|
|
||||||
L5(5);
|
|
||||||
private final int level;
|
|
||||||
|
|
||||||
Level(int level) {
|
|
||||||
this.level = level;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLevel() {
|
|
||||||
return level;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int currentLevel = 0;
|
|
||||||
int cooldown = 100;
|
|
||||||
|
|
||||||
public void tick(EntityMaid maid) {
|
|
||||||
if (MemoryUtil.getTargetPos(maid) != null) {
|
|
||||||
currentLevel = 0;
|
|
||||||
cooldown = 20;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (cooldown > 0) {
|
|
||||||
cooldown--;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentLevel++;
|
|
||||||
if (currentLevel > 5) {
|
|
||||||
currentLevel = 0;
|
|
||||||
cooldown = 100;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isFor(Level level) {
|
|
||||||
return currentLevel == level.getLevel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.menu;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.client.gui.entity.maid.task.MaidTaskConfigGui;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.client.gui.widget.button.MaidConfigButton;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.inventory.container.task.TaskConfigContainer;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import studio.fantasyit.maid_useful_task.Config;
|
||||||
|
import studio.fantasyit.maid_useful_task.data.MaidLoggingConfig;
|
||||||
|
import studio.fantasyit.maid_useful_task.network.MaidConfigurePacket;
|
||||||
|
import studio.fantasyit.maid_useful_task.registry.GuiRegistry;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.TranslateUtil;
|
||||||
|
|
||||||
|
public class MaidLoggingConfigGui extends MaidTaskConfigGui<MaidLoggingConfigGui.Container> {
|
||||||
|
private MaidLoggingConfig.Data currentData;
|
||||||
|
|
||||||
|
public MaidLoggingConfigGui(Container screenContainer, Inventory inv, Component titleIn) {
|
||||||
|
super(screenContainer, inv, titleIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Container extends TaskConfigContainer {
|
||||||
|
public Container(int id, Inventory inventory, int entityId) {
|
||||||
|
super(GuiRegistry.MAID_LOGGING_CONFIG_GUI.get(), id, inventory, entityId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initAdditionData() {
|
||||||
|
this.currentData = this.maid.getOrCreateData(MaidLoggingConfig.KEY, MaidLoggingConfig.Data.getDefault());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initAdditionWidgets() {
|
||||||
|
super.initAdditionWidgets();
|
||||||
|
|
||||||
|
int startLeft = leftPos + 87;
|
||||||
|
int startTop = topPos + 36;
|
||||||
|
this.addRenderableWidget(new MaidConfigButton(startLeft, startTop,
|
||||||
|
Component.translatable("gui.maid_useful_task.logging.plant"),
|
||||||
|
TranslateUtil.getBooleanTranslate(this.currentData.plant()),
|
||||||
|
button -> {
|
||||||
|
this.currentData.plant(false);
|
||||||
|
button.setValue(TranslateUtil.getBooleanTranslate(false));
|
||||||
|
MaidConfigurePacket.send(this.maid, MaidLoggingConfig.LOCATION, "plant", "false");
|
||||||
|
},
|
||||||
|
button -> {
|
||||||
|
this.currentData.plant(true);
|
||||||
|
button.setValue(TranslateUtil.getBooleanTranslate(true));
|
||||||
|
MaidConfigurePacket.send(this.maid, MaidLoggingConfig.LOCATION, "plant", "true");
|
||||||
|
}
|
||||||
|
));
|
||||||
|
if (!Config.disableLoggingBlockUp) {
|
||||||
|
startTop += 13;
|
||||||
|
this.addRenderableWidget(new MaidConfigButton(startLeft, startTop,
|
||||||
|
Component.translatable("gui.maid_useful_task.logging.block_up"),
|
||||||
|
TranslateUtil.getBooleanTranslate(this.currentData.blockUp()),
|
||||||
|
button -> {
|
||||||
|
this.currentData.blockUp(false);
|
||||||
|
button.setValue(TranslateUtil.getBooleanTranslate(false));
|
||||||
|
MaidConfigurePacket.send(this.maid, MaidLoggingConfig.LOCATION, "blockUp", "false");
|
||||||
|
},
|
||||||
|
button -> {
|
||||||
|
this.currentData.blockUp(true);
|
||||||
|
button.setValue(TranslateUtil.getBooleanTranslate(true));
|
||||||
|
MaidConfigurePacket.send(this.maid, MaidLoggingConfig.LOCATION, "blockUp", "true");
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
startTop += 13;
|
||||||
|
this.addRenderableWidget(new MaidConfigButton(startLeft, startTop,
|
||||||
|
Component.translatable("gui.maid_useful_task.logging.skip_non_nature"),
|
||||||
|
TranslateUtil.getBooleanTranslate(this.currentData.skipNonNature()),
|
||||||
|
button -> {
|
||||||
|
this.currentData.skipNonNature(false);
|
||||||
|
button.setValue(TranslateUtil.getBooleanTranslate(false));
|
||||||
|
MaidConfigurePacket.send(this.maid, MaidLoggingConfig.LOCATION, "skipNonNature", "false");
|
||||||
|
},
|
||||||
|
button -> {
|
||||||
|
this.currentData.skipNonNature(true);
|
||||||
|
button.setValue(TranslateUtil.getBooleanTranslate(true));
|
||||||
|
MaidConfigurePacket.send(this.maid, MaidLoggingConfig.LOCATION, "skipNonNature", "true");
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.menu;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.client.gui.entity.maid.task.MaidTaskConfigGui;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.client.gui.widget.button.MaidConfigButton;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.inventory.container.task.TaskConfigContainer;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import studio.fantasyit.maid_useful_task.data.MaidLoggingConfig;
|
||||||
|
import studio.fantasyit.maid_useful_task.data.MaidReviveConfig;
|
||||||
|
import studio.fantasyit.maid_useful_task.network.MaidConfigurePacket;
|
||||||
|
import studio.fantasyit.maid_useful_task.registry.GuiRegistry;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.TranslateUtil;
|
||||||
|
|
||||||
|
public class MaidReviveConfigGui extends MaidTaskConfigGui<MaidReviveConfigGui.Container> {
|
||||||
|
private MaidReviveConfig.Data currentData;
|
||||||
|
|
||||||
|
public MaidReviveConfigGui(Container screenContainer, Inventory inv, Component titleIn) {
|
||||||
|
super(screenContainer, inv, titleIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Container extends TaskConfigContainer {
|
||||||
|
public Container(int id, Inventory inventory, int entityId) {
|
||||||
|
super(GuiRegistry.MAID_REVIVE_CONFIG_GUI.get(), id, inventory, entityId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initAdditionData() {
|
||||||
|
this.currentData = this.maid.getOrCreateData(MaidReviveConfig.KEY, MaidReviveConfig.Data.getDefault());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initAdditionWidgets() {
|
||||||
|
super.initAdditionWidgets();
|
||||||
|
|
||||||
|
int startLeft = leftPos + 87;
|
||||||
|
int startTop = topPos + 36;
|
||||||
|
this.addRenderableWidget(new MaidConfigButton(startLeft, startTop + 0,
|
||||||
|
Component.translatable("gui.maid_useful_task.revive.ownerOnly"),
|
||||||
|
TranslateUtil.getBooleanTranslate(this.currentData.ownerOnly()),
|
||||||
|
button -> {
|
||||||
|
this.currentData.ownerOnly(false);
|
||||||
|
button.setValue(TranslateUtil.getBooleanTranslate(false));
|
||||||
|
MaidConfigurePacket.send(this.maid, MaidReviveConfig.LOCATION, "ownerOnly", "false");
|
||||||
|
},
|
||||||
|
button -> {
|
||||||
|
this.currentData.ownerOnly(true);
|
||||||
|
button.setValue(TranslateUtil.getBooleanTranslate(true));
|
||||||
|
MaidConfigurePacket.send(this.maid, MaidReviveConfig.LOCATION, "ownerOnly", "true");
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.mixin;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.ai.brain.task.MaidFollowOwnerTask;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
import studio.fantasyit.maid_useful_task.task.MaidLocateTask;
|
||||||
|
|
||||||
|
@Mixin(MaidFollowOwnerTask.class)
|
||||||
|
abstract public class FollowMaidMixin {
|
||||||
|
@Shadow(remap = false)
|
||||||
|
@Final
|
||||||
|
private int stopDistance;
|
||||||
|
|
||||||
|
@Inject(method = "Lcom/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidFollowOwnerTask;checkExtraStartConditions(Lnet/minecraft/server/level/ServerLevel;Lcom/github/tartaricacid/touhoulittlemaid/entity/passive/EntityMaid;)Z", at = @At("HEAD"),remap = false, cancellable = true)
|
||||||
|
public void checkExtraStartConditions(ServerLevel level, EntityMaid maid, CallbackInfoReturnable<Boolean> cir) {
|
||||||
|
if (maid.getTask().getUid().equals(MaidLocateTask.UID)) {
|
||||||
|
LivingEntity owner = maid.getOwner();
|
||||||
|
if (owner != null && maid.distanceTo(owner) < 6) {
|
||||||
|
cir.setReturnValue(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModifyVariable(method = "start(Lnet/minecraft/server/level/ServerLevel;Lcom/github/tartaricacid/touhoulittlemaid/entity/passive/EntityMaid;J)V", at = @At(value = "STORE"),remap = false)
|
||||||
|
public int start(int startDistance, @Local(argsOnly = true) EntityMaid maid) {
|
||||||
|
if (maid.getTask().getUid().equals(MaidLocateTask.UID)) {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
return startDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModifyArg(method = "start(Lnet/minecraft/server/level/ServerLevel;Lcom/github/tartaricacid/touhoulittlemaid/entity/passive/EntityMaid;J)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/ai/behavior/BehaviorUtils;setWalkAndLookTargetMemories(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/entity/Entity;FI)V"))
|
||||||
|
public int maid_useful_task$stop_distance(int stopDistance, @Local(argsOnly = true) EntityMaid maid) {
|
||||||
|
if (maid.getTask().getUid().equals(MaidLocateTask.UID)) {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
return stopDistance;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,13 +6,15 @@ import org.spongepowered.asm.mixin.Mixin;
|
|||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
import studio.fantasyit.maid_useful_task.memory.CurrentWork;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.Conditions;
|
||||||
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
||||||
|
|
||||||
@Mixin(EntityMaid.class)
|
@Mixin(EntityMaid.class)
|
||||||
public abstract class MaidCheckPickupItem {
|
public abstract class MaidCheckPickupItem {
|
||||||
@Inject(method = "pickupItem", at = @At("HEAD"), cancellable = true, remap = false)
|
@Inject(method = "pickupItem", at = @At("HEAD"), cancellable = true, remap = false)
|
||||||
public void maid_storage_manager$pickupItem(ItemEntity entityItem, boolean simulate, CallbackInfoReturnable<Boolean> cir) {
|
public void maid_storage_manager$pickupItem(ItemEntity entityItem, boolean simulate, CallbackInfoReturnable<Boolean> cir) {
|
||||||
if (MemoryUtil.getBlockUpContext((EntityMaid) (Object) this).hasTarget()) {
|
if (!Conditions.isCurrent((EntityMaid) (Object) this, CurrentWork.IDLE)) {
|
||||||
cir.setReturnValue(false);
|
cir.setReturnValue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import org.spongepowered.asm.mixin.Shadow;
|
|||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import studio.fantasyit.maid_useful_task.task.MaidLocateTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.task.MaidTreeTask;
|
||||||
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
||||||
|
|
||||||
@Mixin(MaidMoveControl.class)
|
@Mixin(MaidMoveControl.class)
|
||||||
@@ -16,12 +18,14 @@ abstract public class MaidMoveControlMixin {
|
|||||||
@Final
|
@Final
|
||||||
private EntityMaid maid;
|
private EntityMaid maid;
|
||||||
|
|
||||||
@Inject(method = "tick", at = @At("HEAD"), remap = false, cancellable = true)
|
@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
|
||||||
public void tick(CallbackInfo ci) {
|
public void tick(CallbackInfo ci) {
|
||||||
if (MemoryUtil.getBlockUpContext(this.maid).hasTarget()) {
|
if (maid.getTask().getUid().equals(MaidTreeTask.UID))
|
||||||
if (MemoryUtil.getBlockUpContext(this.maid).isOnLine(this.maid.blockPosition())) {
|
if (switch (MemoryUtil.getCurrent(maid)) {
|
||||||
|
case BLOCKUP_DESTROY, BLOCKUP_DOWN -> true;
|
||||||
|
default -> false;
|
||||||
|
}) {
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,18 @@ import org.spongepowered.asm.mixin.Mixin;
|
|||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
import studio.fantasyit.maid_useful_task.memory.CurrentWork;
|
||||||
|
import studio.fantasyit.maid_useful_task.task.MaidTreeTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.Conditions;
|
||||||
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
||||||
|
|
||||||
@Mixin(MaidRunOne.class)
|
@Mixin(MaidRunOne.class)
|
||||||
abstract public class MaidRunOneMixin {
|
abstract public class MaidRunOneMixin {
|
||||||
@Inject(method = "tryStart(Lnet/minecraft/server/level/ServerLevel;Lcom/github/tartaricacid/touhoulittlemaid/entity/passive/EntityMaid;J)Z", at = @At("HEAD"), cancellable = true, remap = false)
|
@Inject(method = "tryStart(Lnet/minecraft/server/level/ServerLevel;Lcom/github/tartaricacid/touhoulittlemaid/entity/passive/EntityMaid;J)Z", at = @At("HEAD"), cancellable = true, remap = false)
|
||||||
public void runOne(ServerLevel pLevel, EntityMaid maid, long pGameTime, CallbackInfoReturnable<Boolean> cir) {
|
public void runOne(ServerLevel pLevel, EntityMaid maid, long pGameTime, CallbackInfoReturnable<Boolean> cir) {
|
||||||
if (MemoryUtil.getDestroyTargetMemory(maid) != null || MemoryUtil.getPlaceTarget(maid) != null || MemoryUtil.getBlockUpContext(maid).hasTarget())
|
if (maid.getTask().getUid().equals(MaidTreeTask.UID))
|
||||||
cir.setReturnValue(false);
|
if (!Conditions.isCurrent(maid, CurrentWork.IDLE)) {
|
||||||
|
cir.setReturnValue(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.network;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.codec.ByteBufCodecs;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||||
|
import studio.fantasyit.maid_useful_task.Config;
|
||||||
|
import studio.fantasyit.maid_useful_task.MaidUsefulTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
||||||
|
import studio.fantasyit.maid_useful_task.vehicle.MaidVehicleControlType;
|
||||||
|
|
||||||
|
public class MaidAllowHandleVehicle implements CustomPacketPayload {
|
||||||
|
public static final CustomPacketPayload.Type<MaidAllowHandleVehicle> TYPE = new CustomPacketPayload.Type<>(
|
||||||
|
ResourceLocation.fromNamespaceAndPath(
|
||||||
|
MaidUsefulTask.MODID, "allow_handle_vehicle"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CustomPacketPayload.Type<? extends CustomPacketPayload> type() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int maidId;
|
||||||
|
|
||||||
|
public MaidAllowHandleVehicle(EntityMaid maid) {
|
||||||
|
this.maidId = maid.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MaidAllowHandleVehicle(int maidId) {
|
||||||
|
this.maidId = maidId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Codec<MaidAllowHandleVehicle> CODEC = RecordCodecBuilder.create(instance ->
|
||||||
|
instance.group(
|
||||||
|
Codec.INT.fieldOf("maidId").forGetter(packet -> packet.maidId)
|
||||||
|
).apply(instance, MaidAllowHandleVehicle::new)
|
||||||
|
);
|
||||||
|
public static StreamCodec<ByteBuf, MaidAllowHandleVehicle> STREAM_CODEC = StreamCodec.composite(
|
||||||
|
ByteBufCodecs.INT,
|
||||||
|
t -> t.maidId,
|
||||||
|
MaidAllowHandleVehicle::new
|
||||||
|
);
|
||||||
|
|
||||||
|
public static void handle(MaidAllowHandleVehicle msg, IPayloadContext context) {
|
||||||
|
ServerPlayer sender = (ServerPlayer) context.player();
|
||||||
|
Entity entity = sender.level().getEntity(msg.maidId);
|
||||||
|
if (entity instanceof EntityMaid maid) {
|
||||||
|
MaidVehicleControlType[] values = MaidVehicleControlType.values();
|
||||||
|
MaidVehicleControlType allowMode = values[(MemoryUtil.getAllowHandleVehicle(maid).ordinal() + 1) % values.length];
|
||||||
|
while ((allowMode == MaidVehicleControlType.FULL && !Config.enableVehicleControlFull)
|
||||||
|
|| (allowMode == MaidVehicleControlType.ROT_ONLY && !Config.enableVehicleControlRotate)) {
|
||||||
|
allowMode = values[(allowMode.ordinal() + 1) % values.length];
|
||||||
|
}
|
||||||
|
MemoryUtil.setAllowHandleVehicle(maid, allowMode);
|
||||||
|
Component component = switch (allowMode) {
|
||||||
|
case NONE -> Component.translatable("maid_useful_task.allow_handle_vehicle.none");
|
||||||
|
case ROT_ONLY -> Component.translatable("maid_useful_task.allow_handle_vehicle.rot_only");
|
||||||
|
case FULL -> Component.translatable("maid_useful_task.allow_handle_vehicle.full");
|
||||||
|
};
|
||||||
|
sender.sendSystemMessage(component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.network;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minecraft.network.codec.ByteBufCodecs;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.neoforged.neoforge.network.PacketDistributor;
|
||||||
|
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import studio.fantasyit.maid_useful_task.MaidUsefulTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.data.IConfigSetter;
|
||||||
|
import studio.fantasyit.maid_useful_task.data.MaidConfigKeys;
|
||||||
|
|
||||||
|
public class MaidConfigurePacket implements CustomPacketPayload {
|
||||||
|
final public int maidId;
|
||||||
|
final public String name;
|
||||||
|
final public String value;
|
||||||
|
final public ResourceLocation key;
|
||||||
|
public static final CustomPacketPayload.Type<MaidConfigurePacket> TYPE = new CustomPacketPayload.Type<>(
|
||||||
|
ResourceLocation.fromNamespaceAndPath(
|
||||||
|
MaidUsefulTask.MODID, "maid_config"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type<? extends CustomPacketPayload> type() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MaidConfigurePacket(int maidId, ResourceLocation key, String name, String value) {
|
||||||
|
this.maidId = maidId;
|
||||||
|
this.key = key;
|
||||||
|
this.name = name;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Codec<MaidConfigurePacket> CODEC = RecordCodecBuilder.create(instance ->
|
||||||
|
instance.group(
|
||||||
|
Codec.INT.fieldOf("maidId").forGetter(packet -> packet.maidId),
|
||||||
|
ResourceLocation.CODEC.fieldOf("key").forGetter(packet -> packet.key),
|
||||||
|
Codec.STRING.fieldOf("name").forGetter(packet -> packet.name),
|
||||||
|
Codec.STRING.fieldOf("value").forGetter(packet -> packet.value)
|
||||||
|
).apply(instance, MaidConfigurePacket::new)
|
||||||
|
);
|
||||||
|
public static StreamCodec<ByteBuf, MaidConfigurePacket> STREAM_CODEC = StreamCodec.composite(
|
||||||
|
ByteBufCodecs.INT,
|
||||||
|
t -> t.maidId,
|
||||||
|
ResourceLocation.STREAM_CODEC,
|
||||||
|
t -> t.key,
|
||||||
|
ByteBufCodecs.STRING_UTF8,
|
||||||
|
t -> t.name,
|
||||||
|
ByteBufCodecs.STRING_UTF8,
|
||||||
|
t -> t.value,
|
||||||
|
MaidConfigurePacket::new
|
||||||
|
);
|
||||||
|
|
||||||
|
public static void send(EntityMaid maid, ResourceLocation key, String name, String value) {
|
||||||
|
PacketDistributor.sendToServer(new MaidConfigurePacket(maid.getId(), key, name, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void handle(MaidConfigurePacket msg, IPayloadContext context) {
|
||||||
|
@Nullable ServerPlayer sender = (ServerPlayer) context.player();
|
||||||
|
if (sender.level().getEntity(msg.maidId) instanceof EntityMaid entityMaid) {
|
||||||
|
if (MaidConfigKeys.getValue(entityMaid, msg.key) instanceof IConfigSetter ics) {
|
||||||
|
ics.setConfigValue(msg.name, msg.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.network;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
|
import net.minecraft.network.codec.ByteBufCodecs;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||||
|
import studio.fantasyit.maid_useful_task.MaidUsefulTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.vehicle.MaidVehicleManager;
|
||||||
|
|
||||||
|
public class MaidSyncVehiclePacket implements CustomPacketPayload {
|
||||||
|
|
||||||
|
public static final CustomPacketPayload.Type<MaidSyncVehiclePacket> TYPE = new CustomPacketPayload.Type<>(
|
||||||
|
ResourceLocation.fromNamespaceAndPath(
|
||||||
|
MaidUsefulTask.MODID, "sync_vehicle"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type<? extends CustomPacketPayload> type() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
final CompoundTag tag;
|
||||||
|
final int maidId;
|
||||||
|
|
||||||
|
public MaidSyncVehiclePacket(int maidId, CompoundTag tag) {
|
||||||
|
this.maidId = maidId;
|
||||||
|
this.tag = tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Codec<MaidSyncVehiclePacket> CODEC = RecordCodecBuilder.create(instance ->
|
||||||
|
instance.group(
|
||||||
|
Codec.INT.fieldOf("maidId").forGetter(packet -> packet.maidId),
|
||||||
|
CompoundTag.CODEC.fieldOf("tag").forGetter(packet -> packet.tag)
|
||||||
|
).apply(instance, MaidSyncVehiclePacket::new)
|
||||||
|
);
|
||||||
|
public static StreamCodec<RegistryFriendlyByteBuf, MaidSyncVehiclePacket> STREAM_CODEC = StreamCodec.composite(
|
||||||
|
ByteBufCodecs.INT,
|
||||||
|
t -> t.maidId,
|
||||||
|
ByteBufCodecs.COMPOUND_TAG,
|
||||||
|
t -> t.tag,
|
||||||
|
MaidSyncVehiclePacket::new
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
public static void handle(MaidSyncVehiclePacket msg, IPayloadContext context) {
|
||||||
|
Entity entity = context.player().level().getEntity(msg.maidId);
|
||||||
|
if (entity instanceof EntityMaid maid) {
|
||||||
|
MaidVehicleManager.getControllableVehicle(maid).ifPresent(vehicle -> {
|
||||||
|
vehicle.syncVehicleParameter(maid, msg.tag);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.network;
|
||||||
|
|
||||||
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
|
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||||
|
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
|
||||||
|
import studio.fantasyit.maid_useful_task.MaidUsefulTask;
|
||||||
|
|
||||||
|
public class Network {
|
||||||
|
private static final String PROTOCOL_VERSION = "1";
|
||||||
|
|
||||||
|
private static void registerMessage(PayloadRegistrar registrar) {
|
||||||
|
registrar.playToServer(
|
||||||
|
MaidConfigurePacket.TYPE,
|
||||||
|
MaidConfigurePacket.STREAM_CODEC,
|
||||||
|
MaidConfigurePacket::handle
|
||||||
|
);
|
||||||
|
registrar.playToServer(
|
||||||
|
MaidAllowHandleVehicle.TYPE,
|
||||||
|
MaidAllowHandleVehicle.STREAM_CODEC,
|
||||||
|
MaidAllowHandleVehicle::handle
|
||||||
|
);
|
||||||
|
registrar.playToClient(
|
||||||
|
MaidSyncVehiclePacket.TYPE,
|
||||||
|
MaidSyncVehiclePacket.STREAM_CODEC,
|
||||||
|
MaidSyncVehiclePacket::handle
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventBusSubscriber(modid = MaidUsefulTask.MODID, bus = EventBusSubscriber.Bus.MOD)
|
||||||
|
public static class Event {
|
||||||
|
@net.neoforged.bus.api.SubscribeEvent
|
||||||
|
public static void regis(RegisterPayloadHandlersEvent event) {
|
||||||
|
registerMessage(event.registrar(PROTOCOL_VERSION));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.registry;
|
||||||
|
|
||||||
|
import net.neoforged.api.distmarker.Dist;
|
||||||
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
|
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
|
||||||
|
import studio.fantasyit.maid_useful_task.MaidUsefulTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.menu.MaidLoggingConfigGui;
|
||||||
|
import studio.fantasyit.maid_useful_task.menu.MaidReviveConfigGui;
|
||||||
|
|
||||||
|
@EventBusSubscriber(modid = MaidUsefulTask.MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
|
||||||
|
public class ClientGuiRegistry {
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void init(RegisterMenuScreensEvent event) {
|
||||||
|
event.register(GuiRegistry.MAID_LOGGING_CONFIG_GUI.get(), MaidLoggingConfigGui::new);
|
||||||
|
event.register(GuiRegistry.MAID_REVIVE_CONFIG_GUI.get(), MaidReviveConfigGui::new);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.registry;
|
||||||
|
|
||||||
|
import net.minecraft.core.registries.Registries;
|
||||||
|
import net.minecraft.world.inventory.MenuType;
|
||||||
|
import net.neoforged.bus.api.IEventBus;
|
||||||
|
import net.neoforged.neoforge.common.extensions.IMenuTypeExtension;
|
||||||
|
import net.neoforged.neoforge.registries.DeferredHolder;
|
||||||
|
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||||
|
import studio.fantasyit.maid_useful_task.MaidUsefulTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.menu.MaidLoggingConfigGui;
|
||||||
|
import studio.fantasyit.maid_useful_task.menu.MaidReviveConfigGui;
|
||||||
|
|
||||||
|
public class GuiRegistry {
|
||||||
|
public static final DeferredRegister<MenuType<?>> MENU_TYPES = DeferredRegister.create(Registries.MENU, MaidUsefulTask.MODID);
|
||||||
|
public static final DeferredHolder<MenuType<?>, MenuType<MaidLoggingConfigGui.Container>> MAID_LOGGING_CONFIG_GUI = MENU_TYPES.register("maid_logging_config_gui",
|
||||||
|
() -> IMenuTypeExtension.create((windowId, inv, data) -> new MaidLoggingConfigGui.Container(windowId, inv, data.readInt())));
|
||||||
|
public static final DeferredHolder<MenuType<?>, MenuType<MaidReviveConfigGui.Container>> MAID_REVIVE_CONFIG_GUI = MENU_TYPES.register("maid_revive_config_gui",
|
||||||
|
() -> IMenuTypeExtension.create((windowId, inv, data) -> new MaidReviveConfigGui.Container(windowId, inv, data.readInt())));
|
||||||
|
|
||||||
|
public static void init(IEventBus modEventBus) {
|
||||||
|
MENU_TYPES.register(modEventBus);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,27 +3,35 @@ package studio.fantasyit.maid_useful_task.registry;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.registries.DeferredRegister;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.minecraftforge.registries.RegistryObject;
|
import net.neoforged.neoforge.registries.DeferredHolder;
|
||||||
|
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||||
import studio.fantasyit.maid_useful_task.MaidUsefulTask;
|
import studio.fantasyit.maid_useful_task.MaidUsefulTask;
|
||||||
import studio.fantasyit.maid_useful_task.memory.BlockTargetMemory;
|
import studio.fantasyit.maid_useful_task.memory.BlockTargetMemory;
|
||||||
import studio.fantasyit.maid_useful_task.memory.BlockUpContext;
|
import studio.fantasyit.maid_useful_task.memory.BlockUpContext;
|
||||||
import studio.fantasyit.maid_useful_task.memory.TaskRateLimitToken;
|
import studio.fantasyit.maid_useful_task.memory.BlockValidationMemory;
|
||||||
|
import studio.fantasyit.maid_useful_task.memory.CurrentWork;
|
||||||
|
import studio.fantasyit.maid_useful_task.vehicle.MaidVehicleControlType;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class MemoryModuleRegistry {
|
public class MemoryModuleRegistry {
|
||||||
public static final DeferredRegister<MemoryModuleType<?>> REGISTER
|
public static final DeferredRegister<MemoryModuleType<?>> REGISTER
|
||||||
= DeferredRegister.create(Registries.MEMORY_MODULE_TYPE, MaidUsefulTask.MODID);
|
= DeferredRegister.create(Registries.MEMORY_MODULE_TYPE, MaidUsefulTask.MODID);
|
||||||
public static final RegistryObject<MemoryModuleType<BlockTargetMemory>> DESTROY_TARGET
|
public static final DeferredHolder<MemoryModuleType<?>, MemoryModuleType<BlockTargetMemory>> DESTROY_TARGET
|
||||||
= REGISTER.register("block_targets", () -> new MemoryModuleType<>(Optional.of(BlockTargetMemory.CODEC)));
|
= REGISTER.register("block_targets", () -> new MemoryModuleType<>(Optional.of(BlockTargetMemory.CODEC)));
|
||||||
public static final RegistryObject<MemoryModuleType<BlockPos>> PLACE_TARGET
|
public static final DeferredHolder<MemoryModuleType<?>, MemoryModuleType<BlockPos>> PLACE_TARGET
|
||||||
= REGISTER.register("place_target", () -> new MemoryModuleType<>(Optional.empty()));
|
= REGISTER.register("place_target", () -> new MemoryModuleType<>(Optional.empty()));
|
||||||
public static final RegistryObject<MemoryModuleType<BlockUpContext>> BLOCK_UP_TARGET
|
public static final DeferredHolder<MemoryModuleType<?>, MemoryModuleType<BlockUpContext>> BLOCK_UP_TARGET
|
||||||
= REGISTER.register("block_up", () -> new MemoryModuleType<>(Optional.of(BlockUpContext.CODEC)));
|
= REGISTER.register("block_up", () -> new MemoryModuleType<>(Optional.of(BlockUpContext.CODEC)));
|
||||||
public static final RegistryObject<MemoryModuleType<TaskRateLimitToken>> RATE_LIMIT_TOKEN
|
public static final DeferredHolder<MemoryModuleType<?>, MemoryModuleType<BlockValidationMemory>> BLOCK_VALIDATION
|
||||||
= REGISTER.register("task_rate_limit", () -> new MemoryModuleType<>(Optional.empty()));
|
= REGISTER.register("block_validation", () -> new MemoryModuleType<>(Optional.of(BlockValidationMemory.CODEC)));
|
||||||
|
public static final DeferredHolder<MemoryModuleType<?>, MemoryModuleType<BlockPos>> COMMON_BLOCK_CACHE
|
||||||
|
= REGISTER.register("common_block_cache", () -> new MemoryModuleType<>(Optional.empty()));
|
||||||
|
public static final DeferredHolder<MemoryModuleType<?>, MemoryModuleType<ItemStack>> LOCATE_ITEM = REGISTER.register("locate_item", () -> new MemoryModuleType<>(Optional.empty()));
|
||||||
|
public static final DeferredHolder<MemoryModuleType<?>, MemoryModuleType<CurrentWork>> CURRENT_WORK = REGISTER.register("current_work", () -> new MemoryModuleType<>(Optional.empty()));
|
||||||
|
public static final DeferredHolder<MemoryModuleType<?>, MemoryModuleType<MaidVehicleControlType>> IS_ALLOW_HANDLE_VEHICLE = REGISTER.register("is_allow_handle_vehicle", () -> new MemoryModuleType<>(Optional.empty()));
|
||||||
|
|
||||||
public static void register(IEventBus eventBus) {
|
public static void register(IEventBus eventBus) {
|
||||||
REGISTER.register(eventBus);
|
REGISTER.register(eventBus);
|
||||||
|
|||||||
@@ -3,21 +3,14 @@ package studio.fantasyit.maid_useful_task.task;
|
|||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import net.minecraft.world.entity.ai.behavior.BehaviorControl;
|
import net.minecraft.world.entity.ai.behavior.BehaviorControl;
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.BlockGetter;
|
import net.minecraft.world.level.BlockGetter;
|
||||||
import net.minecraft.world.level.block.BaseFireBlock;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.gameevent.GameEvent;
|
|
||||||
import net.minecraft.world.level.material.FluidState;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import studio.fantasyit.maid_useful_task.behavior.DestoryBlockBehavior;
|
import studio.fantasyit.maid_useful_task.behavior.common.DestoryBlockBehavior;
|
||||||
import studio.fantasyit.maid_useful_task.behavior.DestoryBlockMoveBehavior;
|
import studio.fantasyit.maid_useful_task.behavior.common.DestoryBlockMoveBehavior;
|
||||||
import studio.fantasyit.maid_useful_task.util.MaidUtils;
|
import studio.fantasyit.maid_useful_task.util.MaidUtils;
|
||||||
import studio.fantasyit.maid_useful_task.util.WrappedMaidFakePlayer;
|
import studio.fantasyit.maid_useful_task.util.WrappedMaidFakePlayer;
|
||||||
|
|
||||||
@@ -69,8 +62,9 @@ public interface IMaidBlockDestroyTask {
|
|||||||
for (int dz : dv) {
|
for (int dz : dv) {
|
||||||
if (dx == 0 && dy == 0 && dz == 0) continue;
|
if (dx == 0 && dy == 0 && dz == 0) continue;
|
||||||
BlockPos target = pos.offset(dx, dy, dz);
|
BlockPos target = pos.offset(dx, dy, dz);
|
||||||
if (Math.abs(target.getX() - standPos.getX()) > maxDXZ || Math.abs(target.getZ() - standPos.getZ()) > maxDXZ)
|
// if (Math.abs(target.getX() - standPos.getX()) > maxDXZ || Math.abs(target.getZ() - standPos.getZ()) > maxDXZ)
|
||||||
continue;
|
// continue;
|
||||||
|
//上代码不明所以,删除待查
|
||||||
if (target.distSqr(standPos) > reachDistance() * reachDistance()) continue;
|
if (target.distSqr(standPos) > reachDistance() * reachDistance()) continue;
|
||||||
if (marked.contains(target)) continue;
|
if (marked.contains(target)) continue;
|
||||||
if (!shouldDestroyBlock(maid, target)) continue;
|
if (!shouldDestroyBlock(maid, target)) continue;
|
||||||
|
|||||||
@@ -3,19 +3,12 @@ package studio.fantasyit.maid_useful_task.task;
|
|||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.InteractionHand;
|
|
||||||
import net.minecraft.world.InteractionResult;
|
|
||||||
import net.minecraft.world.entity.ai.behavior.BehaviorControl;
|
import net.minecraft.world.entity.ai.behavior.BehaviorControl;
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
|
||||||
import net.minecraft.world.level.ClipContext;
|
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import studio.fantasyit.maid_useful_task.behavior.DestoryBlockBehavior;
|
import studio.fantasyit.maid_useful_task.behavior.common.DestoryBlockBehavior;
|
||||||
import studio.fantasyit.maid_useful_task.behavior.DestoryBlockMoveBehavior;
|
import studio.fantasyit.maid_useful_task.behavior.common.DestoryBlockMoveBehavior;
|
||||||
import studio.fantasyit.maid_useful_task.util.MaidUtils;
|
import studio.fantasyit.maid_useful_task.util.MaidUtils;
|
||||||
import studio.fantasyit.maid_useful_task.util.WrappedMaidFakePlayer;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@@ -3,14 +3,18 @@ package studio.fantasyit.maid_useful_task.task;
|
|||||||
import com.github.tartaricacid.touhoulittlemaid.api.task.IMaidTask;
|
import com.github.tartaricacid.touhoulittlemaid.api.task.IMaidTask;
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.MaidPathFindingBFS;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.MaidPathFindingBFS;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.util.CenterOffsetBlockPosSet;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
import net.neoforged.neoforge.items.wrapper.CombinedInvWrapper;
|
||||||
import oshi.util.tuples.Pair;
|
import oshi.util.tuples.Pair;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.MaidUtils;
|
||||||
import studio.fantasyit.maid_useful_task.util.PosUtils;
|
import studio.fantasyit.maid_useful_task.util.PosUtils;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
public interface IMaidBlockUpTask {
|
public interface IMaidBlockUpTask {
|
||||||
default boolean isFindingBlock(EntityMaid maid, BlockPos target, BlockPos standPos) {
|
default boolean isFindingBlock(EntityMaid maid, BlockPos target, BlockPos standPos) {
|
||||||
if (target.distSqr(standPos) > touchLimit() * touchLimit())
|
if (target.distSqr(standPos) > touchLimit() * touchLimit())
|
||||||
@@ -27,7 +31,6 @@ public interface IMaidBlockUpTask {
|
|||||||
for (int dz = 0; dz < touchLimit(); dz = dz <= 0 ? 1 - dz : -dz) {
|
for (int dz = 0; dz < touchLimit(); dz = dz <= 0 ? 1 - dz : -dz) {
|
||||||
for (int dy = 0; dy < verticalDistance(); dy++) {
|
for (int dy = 0; dy < verticalDistance(); dy++) {
|
||||||
BlockPos targetPos = startPos.offset(dx, dy, dz);
|
BlockPos targetPos = startPos.offset(dx, dy, dz);
|
||||||
if (maid.hasRestriction() && !maid.isWithinRestriction(targetPos)) break;
|
|
||||||
if (isFindingBlock(maid, targetPos, startPos)) {
|
if (isFindingBlock(maid, targetPos, startPos)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -37,55 +40,87 @@ public interface IMaidBlockUpTask {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
default Pair<BlockPos, BlockPos> findTargetPosBlockUp(EntityMaid maid, BlockPos center) {
|
default Pair<BlockPos, BlockPos> findTargetPosBlockUp(EntityMaid maid, BlockPos center, int maxUp) {
|
||||||
ServerLevel level = (ServerLevel) maid.level();
|
ServerLevel level = (ServerLevel) maid.level();
|
||||||
MaidPathFindingBFS pathFindingBFS = new MaidPathFindingBFS(maid.getNavigation().getNodeEvaluator(), level, maid);
|
int maxHeight = verticalOffset() + verticalDistance();
|
||||||
for (int dx = 0; dx < scanRange(); dx = dx <= 0 ? 1 - dx : -dx) {
|
boolean hasRestriction = maid.hasRestriction();
|
||||||
for (int dz = 0; dz < scanRange(); dz = dz <= 0 ? 1 - dz : -dz) {
|
BlockPos restrictCenter = maid.getRestrictCenter();
|
||||||
BlockPos.MutableBlockPos mb = center.offset(dx, 0, dz).mutable();
|
float restrictRadius = maid.getRestrictRadius();
|
||||||
while (level.getBlockState(mb).canBeReplaced()) mb.move(0, -1, 0);
|
int scanRange = scanRange(maid);
|
||||||
while (!level.getBlockState(mb).canBeReplaced()) mb.move(0, 1, 0);
|
Function<BlockPos, Boolean> withinRestriction = (BlockPos pos) -> {
|
||||||
if (!PosUtils.isFourSideAir(level, mb)) continue;
|
if (hasRestriction) {
|
||||||
if (!pathFindingBFS.canPathReach(mb)) continue;
|
return restrictCenter.distSqr(pos) < (double) (restrictRadius * restrictRadius);
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
CenterOffsetBlockPosSet notAvailable = new CenterOffsetBlockPosSet(scanRange, scanRange + maxHeight / 2 + 1, scanRange, center.getX(), center.getY() + maxHeight / 2, center.getZ());
|
||||||
|
MaidPathFindingBFS pathFindingBFS = new MaidPathFindingBFS(maid.getNavigation().getNodeEvaluator(), level, maid, 7, scanRange+2);
|
||||||
|
for (int dx = 0; dx < scanRange; dx = dx <= 0 ? 1 - dx : -dx) {
|
||||||
|
for (int dz = 0; dz < scanRange; dz = dz <= 0 ? 1 - dz : -dz) {
|
||||||
|
//计算地面的位置
|
||||||
|
BlockPos.MutableBlockPos ground = center.offset(dx, 0, dz).mutable();
|
||||||
|
while (level.getBlockState(ground).canBeReplaced()) ground.move(0, -1, 0);
|
||||||
|
while (!level.getBlockState(ground).canBeReplaced()) ground.move(0, 1, 0);
|
||||||
|
if (notAvailable.isVis(ground)) continue;
|
||||||
|
//地面基本判断
|
||||||
|
if (!PosUtils.isSafePos(level, ground)) continue;
|
||||||
|
if (!PosUtils.isFourSideAir(level, ground.immutable())) continue;
|
||||||
|
if (!pathFindingBFS.canPathReach(ground)) continue;
|
||||||
boolean valid = true;
|
boolean valid = true;
|
||||||
for (int dy = 0; dy < verticalOffset(); dy++) {
|
for (int dy = 0; dy < verticalOffset(); dy++) {
|
||||||
BlockPos targetPos = center.offset(dx, dy, dz);
|
BlockPos targetPos = ground.above(dy);
|
||||||
if (!level.getBlockState(targetPos).canBeReplaced()) {
|
if (!level.getBlockState(targetPos).canBeReplaced()) {
|
||||||
valid = false;
|
valid = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int dy = verticalDistance(); dy < verticalDistance() + 2; dy++) {
|
for (int dy = verticalOffset(); dy < verticalOffset() + 2; dy++) {
|
||||||
BlockPos targetPos = center.offset(dx, dy, dz);
|
BlockPos targetPos = ground.above(dy);
|
||||||
if (!level.getBlockState(targetPos).isAir()) {
|
if (!level.getBlockState(targetPos).isAir()) {
|
||||||
valid = false;
|
valid = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!valid)
|
if (!valid) {
|
||||||
|
notAvailable.markVis(ground.immutable());
|
||||||
continue;
|
continue;
|
||||||
int touchLimit = touchLimit() + 1;
|
|
||||||
boolean continuous = true;
|
|
||||||
BlockPos standPos = center.offset(dx, verticalOffset(), dz);
|
|
||||||
for (int dy = verticalOffset(); dy < verticalDistance() + verticalOffset(); dy++) {
|
|
||||||
BlockPos targetPos = center.offset(dx, dy, dz);
|
|
||||||
if (maid.hasRestriction() && !maid.isWithinRestriction(targetPos)) break;
|
|
||||||
if (isFindingBlock(maid, targetPos, standPos)) {
|
|
||||||
return new Pair<>(mb, standPos);
|
|
||||||
}
|
|
||||||
//头顶一格是不是空气,不是:不连续空间(不能继续垫了,那么需要计算触及范围
|
|
||||||
if (!level.getBlockState(standPos.above().above()).isAir()) {
|
|
||||||
continuous = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!continuous) {
|
|
||||||
touchLimit--;
|
|
||||||
} else {
|
|
||||||
standPos = standPos.above();
|
|
||||||
}
|
|
||||||
if (touchLimit <= 0)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
//竖直方向触及
|
||||||
|
for (int sdx = 0; sdx < 2; sdx = sdx <= 0 ? 1 - sdx : -sdx)
|
||||||
|
for (int sdz = 0; sdz < 2; sdz = sdz <= 0 ? 1 - sdz : -sdz) {
|
||||||
|
int touchLimit = touchLimit() + 1;
|
||||||
|
boolean continuous = true;
|
||||||
|
BlockPos standPos = ground.above(verticalOffset()).offset(sdx, 0, sdz);
|
||||||
|
if (standPos.getY() - ground.getY() > maxUp)
|
||||||
|
continue;
|
||||||
|
for (int dy = verticalOffset(); dy < verticalDistance() + verticalOffset(); dy++) {
|
||||||
|
BlockPos targetPos = ground.offset(sdx, dy, sdz);
|
||||||
|
if (targetPos.distSqr(standPos) > touchLimit * touchLimit) break;
|
||||||
|
if (hasRestriction && !withinRestriction.apply(standPos)) break;
|
||||||
|
if (isFindingBlock(maid, targetPos, standPos)) {
|
||||||
|
return new Pair<>(ground.immutable(), standPos);
|
||||||
|
}
|
||||||
|
//头顶一格是不是空气,不是:不连续空间(不能继续垫了,那么需要计算触及范围
|
||||||
|
if (continuous) {
|
||||||
|
if (!level.getBlockState(standPos.above().above()).isAir()) {
|
||||||
|
continuous = false;
|
||||||
|
} else if (hasRestriction && !withinRestriction.apply((standPos.above().above()))) {
|
||||||
|
continuous = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!continuous) {
|
||||||
|
touchLimit--;
|
||||||
|
} else {
|
||||||
|
standPos = standPos.above();
|
||||||
|
if (standPos.getY() - ground.getY() > maxUp)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (touchLimit <= 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -97,7 +132,7 @@ public interface IMaidBlockUpTask {
|
|||||||
for (int i = 0; i < inv.getSlots(); i++) {
|
for (int i = 0; i < inv.getSlots(); i++) {
|
||||||
ItemStack stack = inv.getStackInSlot(i);
|
ItemStack stack = inv.getStackInSlot(i);
|
||||||
if (isValidItemStack(maid, stack)) {
|
if (isValidItemStack(maid, stack)) {
|
||||||
count++;
|
count += stack.getCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
@@ -141,11 +176,19 @@ public interface IMaidBlockUpTask {
|
|||||||
return 15;
|
return 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
default int scanRange() {
|
default int scanRange(EntityMaid maid) {
|
||||||
return 10;
|
return maid.hasRestriction() ? (int) maid.getRestrictRadius() : 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
default int touchLimit() {
|
default int touchLimit() {
|
||||||
return 7;
|
return 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default boolean tryPlaceBlockUp(EntityMaid maid, BlockPos targetPos) {
|
||||||
|
return MaidUtils.placeBlock(maid, targetPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean tryDestroyBlockUp(EntityMaid maid, BlockPos targetPos) {
|
||||||
|
return MaidUtils.destroyBlock(maid, targetPos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.task;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public interface IMaidFindTargetTask extends IMaidVehicleControlTask {
|
||||||
|
@Nullable BlockPos findTarget(ServerLevel level, EntityMaid maid);
|
||||||
|
|
||||||
|
void clearCache(EntityMaid maid);
|
||||||
|
|
||||||
|
default int maxOutDistance() {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
default int minReScheduleDistance() {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
default int moveDistance() {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.task;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
||||||
|
import studio.fantasyit.maid_useful_task.vehicle.MaidVehicleControlType;
|
||||||
|
import studio.fantasyit.maid_useful_task.vehicle.MaidVehicleManager;
|
||||||
|
|
||||||
|
public interface IMaidVehicleControlTask {
|
||||||
|
BlockPos findTarget(ServerLevel level, EntityMaid maid);
|
||||||
|
|
||||||
|
default void tick(ServerLevel level, EntityMaid maid) {
|
||||||
|
MaidVehicleControlType allowHandleVehicle = MemoryUtil.getAllowHandleVehicle(maid);
|
||||||
|
BlockPos targetPos = findTarget(level, maid);
|
||||||
|
MaidVehicleManager.getControllableVehicle(maid).ifPresent(vehicle -> {
|
||||||
|
if (targetPos == null) {
|
||||||
|
vehicle.maidStopControlVehicle(maid);
|
||||||
|
} else {
|
||||||
|
vehicle.maidControlVehicle(maid, allowHandleVehicle, targetPos);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,174 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.task;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.api.task.IMaidTask;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import com.mojang.datafixers.util.Pair;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.GlobalPos;
|
||||||
|
import net.minecraft.core.component.DataComponents;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.sounds.SoundEvent;
|
||||||
|
import net.minecraft.tags.ItemTags;
|
||||||
|
import net.minecraft.tags.StructureTags;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import net.minecraft.world.entity.ai.behavior.BehaviorControl;
|
||||||
|
import net.minecraft.world.item.CompassItem;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.Items;
|
||||||
|
import net.minecraft.world.item.MapItem;
|
||||||
|
import net.minecraft.world.item.component.LodestoneTracker;
|
||||||
|
import net.minecraft.world.item.component.MapDecorations;
|
||||||
|
import net.minecraft.world.level.saveddata.maps.MapDecorationTypes;
|
||||||
|
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
|
||||||
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import studio.fantasyit.maid_useful_task.Config;
|
||||||
|
import studio.fantasyit.maid_useful_task.MaidUsefulTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.api.ItemLocateEvent;
|
||||||
|
import studio.fantasyit.maid_useful_task.behavior.common.FindTargetMoveBehavior;
|
||||||
|
import studio.fantasyit.maid_useful_task.behavior.common.FindTargetWaitBehavior;
|
||||||
|
import studio.fantasyit.maid_useful_task.compat.CompatEntry;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MaidLocateTask implements IMaidTask, IMaidFindTargetTask {
|
||||||
|
public static final ResourceLocation UID = ResourceLocation.fromNamespaceAndPath(MaidUsefulTask.MODID, "locate");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getUid() {
|
||||||
|
return UID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getIcon() {
|
||||||
|
return Items.ENDER_EYE.getDefaultInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public SoundEvent getAmbientSound(EntityMaid entityMaid) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pair<Integer, BehaviorControl<? super EntityMaid>>> createBrainTasks(EntityMaid entityMaid) {
|
||||||
|
List<Pair<Integer, BehaviorControl<? super EntityMaid>>> list = new ArrayList<>();
|
||||||
|
list.add(Pair.of(1, new FindTargetMoveBehavior()));
|
||||||
|
list.add(Pair.of(2, new FindTargetWaitBehavior()));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean enableLookAndRandomWalk(EntityMaid maid) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnable(EntityMaid maid) {
|
||||||
|
return Config.enableLocateTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable BlockPos findTarget(ServerLevel level, EntityMaid maid) {
|
||||||
|
BlockPos target = null;
|
||||||
|
ItemStack itemStack = maid.getMainHandItem();
|
||||||
|
ItemStack last = MemoryUtil.getLocateItem(maid);
|
||||||
|
if (!last.isEmpty() && !itemStack.isEmpty() && ItemStack.isSameItemSameComponents(last, itemStack)) {
|
||||||
|
MemoryUtil.setLocateItem(maid, itemStack);
|
||||||
|
MemoryUtil.clearCommonBlockCache(maid);
|
||||||
|
}
|
||||||
|
ItemLocateEvent event = new ItemLocateEvent(itemStack, maid, MemoryUtil.getCommonBlockCache(maid));
|
||||||
|
ItemLocateEvent posted = NeoForge.EVENT_BUS.post(event);
|
||||||
|
if (posted.isCanceled()) {
|
||||||
|
target = event.getTarget();
|
||||||
|
} else if (maid.getMainHandItem().is(Items.ENDER_EYE)) {
|
||||||
|
target = MemoryUtil.getCommonBlockCache(maid);
|
||||||
|
if (target == null) {
|
||||||
|
BlockPos blockpos = level.findNearestMapStructure(StructureTags.EYE_OF_ENDER_LOCATED, maid.blockPosition(), 100, false);
|
||||||
|
if (blockpos != null) {
|
||||||
|
MemoryUtil.setCommonBlockCache(maid, blockpos);
|
||||||
|
target = blockpos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (maid.getMainHandItem().is(Items.COMPASS)) {
|
||||||
|
target = MemoryUtil.getCommonBlockCache(maid);
|
||||||
|
if (target == null) {
|
||||||
|
GlobalPos globalPos;
|
||||||
|
LodestoneTracker lodeData = itemStack.get(DataComponents.LODESTONE_TRACKER);
|
||||||
|
if (lodeData != null && lodeData.target().isPresent()) {
|
||||||
|
globalPos = lodeData.target().get();
|
||||||
|
} else {
|
||||||
|
globalPos = CompassItem.getSpawnPosition(level);
|
||||||
|
}
|
||||||
|
if (globalPos != null && level.dimension().equals(globalPos.dimension())) {
|
||||||
|
MemoryUtil.setCommonBlockCache(maid, globalPos.pos());
|
||||||
|
target = globalPos.pos();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (maid.getMainHandItem().is(ItemTags.BEDS)) {
|
||||||
|
target = MemoryUtil.getCommonBlockCache(maid);
|
||||||
|
if (target == null) {
|
||||||
|
LivingEntity owner = maid.getOwner();
|
||||||
|
if (owner instanceof ServerPlayer player) {
|
||||||
|
if (player.getRespawnDimension().equals(level.dimension())) {
|
||||||
|
target = player.getRespawnPosition();
|
||||||
|
if (target == null) {
|
||||||
|
GlobalPos globalRespawn = CompassItem.getSpawnPosition(level);
|
||||||
|
if (globalRespawn != null && level.dimension().equals(globalRespawn.dimension())) {
|
||||||
|
target = globalRespawn.pos();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (target == null) {
|
||||||
|
MemoryUtil.setCommonBlockCache(maid, target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (maid.getMainHandItem().is(Items.FILLED_MAP)) {
|
||||||
|
target = MemoryUtil.getCommonBlockCache(maid);
|
||||||
|
if (target == null) {
|
||||||
|
MapItemSavedData savedData = MapItem.getSavedData(itemStack, maid.level());
|
||||||
|
if (savedData != null) {
|
||||||
|
BlockPos.MutableBlockPos tmpTarget = new BlockPos.MutableBlockPos(savedData.centerX, level.getSeaLevel(), savedData.centerZ);
|
||||||
|
|
||||||
|
savedData.getBanners()
|
||||||
|
.stream()
|
||||||
|
.findFirst()
|
||||||
|
.ifPresent(t -> {
|
||||||
|
tmpTarget.set(t.pos().immutable());
|
||||||
|
});
|
||||||
|
MapDecorations decoList = itemStack.get(DataComponents.MAP_DECORATIONS);
|
||||||
|
if (decoList != null)
|
||||||
|
decoList.decorations().entrySet().stream()
|
||||||
|
.filter(t -> t.getValue().type() == MapDecorationTypes.RED_X)
|
||||||
|
.findFirst()
|
||||||
|
.ifPresent(t -> {
|
||||||
|
tmpTarget.setX((int) t.getValue().x());
|
||||||
|
tmpTarget.setZ((int) t.getValue().z());
|
||||||
|
});
|
||||||
|
|
||||||
|
target = tmpTarget.immutable();
|
||||||
|
MemoryUtil.setCommonBlockCache(maid, target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
target = CompatEntry.getLocateTarget(maid, maid.getMainHandItem());
|
||||||
|
if (target != null) {
|
||||||
|
MemoryUtil.setCommonBlockCache(maid, target);
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
MemoryUtil.clearCommonBlockCache(maid);
|
||||||
|
}
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearCache(EntityMaid maid) {
|
||||||
|
MemoryUtil.clearCommonBlockCache(maid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.task;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
|
||||||
|
public class MaidMineTask implements IMaidBlockDestroyTask {
|
||||||
|
@Override
|
||||||
|
public boolean shouldDestroyBlock(EntityMaid maid, BlockPos pos) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mayDestroy(EntityMaid maid, BlockPos pos) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.task;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.api.task.IMaidTask;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import com.mojang.datafixers.util.Pair;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.sounds.SoundEvent;
|
||||||
|
import net.minecraft.world.MenuProvider;
|
||||||
|
import net.minecraft.world.entity.ai.behavior.BehaviorControl;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.Items;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import studio.fantasyit.maid_useful_task.Config;
|
||||||
|
import studio.fantasyit.maid_useful_task.MaidUsefulTask;
|
||||||
|
import studio.fantasyit.maid_useful_task.behavior.PlayerReviveBehavior;
|
||||||
|
import studio.fantasyit.maid_useful_task.compat.PlayerRevive;
|
||||||
|
import studio.fantasyit.maid_useful_task.menu.MaidLoggingConfigGui;
|
||||||
|
import studio.fantasyit.maid_useful_task.menu.MaidReviveConfigGui;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MaidRevivePlayerTask implements IMaidTask {
|
||||||
|
public static final ResourceLocation UID = ResourceLocation.fromNamespaceAndPath(MaidUsefulTask.MODID, "revive_player");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getUid() {
|
||||||
|
return UID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getIcon() {
|
||||||
|
return Items.ENCHANTED_GOLDEN_APPLE.getDefaultInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public SoundEvent getAmbientSound(EntityMaid entityMaid) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnable(EntityMaid maid) {
|
||||||
|
return PlayerRevive.isEnable() && Config.enableReviveTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean enableLookAndRandomWalk(EntityMaid maid) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean enablePanic(EntityMaid maid) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pair<Integer, BehaviorControl<? super EntityMaid>>> createBrainTasks(EntityMaid entityMaid) {
|
||||||
|
ArrayList<Pair<Integer, BehaviorControl<? super EntityMaid>>> ret = new ArrayList<>();
|
||||||
|
ret.add(Pair.of(1, new PlayerReviveBehavior()));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MenuProvider getTaskConfigGuiProvider(EntityMaid maid) {
|
||||||
|
return new MenuProvider() {
|
||||||
|
@Override
|
||||||
|
public Component getDisplayName() {
|
||||||
|
return Component.literal("");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractContainerMenu createMenu(int index, Inventory playerInventory, Player player) {
|
||||||
|
return new MaidReviveConfigGui.Container(index, playerInventory, maid.getId());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,31 +4,46 @@ import com.github.tartaricacid.touhoulittlemaid.api.task.IMaidTask;
|
|||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundEvent;
|
||||||
import net.minecraft.tags.BlockTags;
|
import net.minecraft.tags.BlockTags;
|
||||||
import net.minecraft.tags.ItemTags;
|
import net.minecraft.tags.ItemTags;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
|
import net.minecraft.world.MenuProvider;
|
||||||
import net.minecraft.world.entity.ai.behavior.BehaviorControl;
|
import net.minecraft.world.entity.ai.behavior.BehaviorControl;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Items;
|
import net.minecraft.world.item.Items;
|
||||||
import net.minecraft.world.level.block.LeavesBlock;
|
import net.minecraft.world.level.block.LeavesBlock;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
import net.neoforged.neoforge.items.wrapper.CombinedInvWrapper;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import studio.fantasyit.maid_useful_task.Config;
|
||||||
import studio.fantasyit.maid_useful_task.MaidUsefulTask;
|
import studio.fantasyit.maid_useful_task.MaidUsefulTask;
|
||||||
import studio.fantasyit.maid_useful_task.behavior.*;
|
import studio.fantasyit.maid_useful_task.behavior.common.*;
|
||||||
|
import studio.fantasyit.maid_useful_task.data.MaidLoggingConfig;
|
||||||
|
import studio.fantasyit.maid_useful_task.memory.BlockValidationMemory;
|
||||||
|
import studio.fantasyit.maid_useful_task.menu.MaidLoggingConfigGui;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.MaidUtils;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
|
||||||
import studio.fantasyit.maid_useful_task.util.WrappedMaidFakePlayer;
|
import studio.fantasyit.maid_useful_task.util.WrappedMaidFakePlayer;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MaidTreeTask implements IMaidTask, IMaidBlockPlaceTask, IMaidBlockDestroyTask, IMaidBlockUpTask {
|
public class MaidTreeTask implements IMaidTask, IMaidBlockPlaceTask, IMaidBlockDestroyTask, IMaidBlockUpTask {
|
||||||
|
public static final ResourceLocation UID = ResourceLocation.fromNamespaceAndPath(MaidUsefulTask.MODID, "maid_tree");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getUid() {
|
public ResourceLocation getUid() {
|
||||||
return new ResourceLocation(MaidUsefulTask.MODID, "maid_tree");
|
return UID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -47,14 +62,47 @@ public class MaidTreeTask implements IMaidTask, IMaidBlockPlaceTask, IMaidBlockD
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnable(EntityMaid maid) {
|
||||||
|
return Config.enableLoggingTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MenuProvider getTaskConfigGuiProvider(EntityMaid maid) {
|
||||||
|
return new MenuProvider() {
|
||||||
|
@Override
|
||||||
|
public Component getDisplayName() {
|
||||||
|
return Component.literal("");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractContainerMenu createMenu(int index, Inventory playerInventory, Player player) {
|
||||||
|
return new MaidLoggingConfigGui.Container(index, playerInventory, maid.getId());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldDestroyBlock(EntityMaid maid, BlockPos pos) {
|
public boolean shouldDestroyBlock(EntityMaid maid, BlockPos pos) {
|
||||||
|
if (MemoryUtil.getBlockUpContext(maid).hasTarget()) {
|
||||||
|
if (pos.getY() < maid.getBlockY() && pos.getX() == maid.getBlockX() && pos.getZ() == maid.getBlockZ()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
BlockState blockState = maid.level().getBlockState(pos);
|
BlockState blockState = maid.level().getBlockState(pos);
|
||||||
return blockState.is(BlockTags.LOGS) && isValidNatureTree(maid, pos);
|
if (blockState.is(BlockTags.LOGS)) {
|
||||||
|
return !MaidLoggingConfig.get(maid).skipNonNature() || isValidNatureTree(maid, pos);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mayDestroy(EntityMaid maid, BlockPos pos) {
|
public boolean mayDestroy(EntityMaid maid, BlockPos pos) {
|
||||||
|
if (MemoryUtil.getBlockUpContext(maid).hasTarget()) {
|
||||||
|
if (pos.getY() < maid.getBlockY() && pos.getX() == maid.getBlockX() && pos.getZ() == maid.getBlockZ()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
BlockState blockState = maid.level().getBlockState(pos);
|
BlockState blockState = maid.level().getBlockState(pos);
|
||||||
if (blockState.is(BlockTags.LEAVES)) {
|
if (blockState.is(BlockTags.LEAVES)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -64,6 +112,7 @@ public class MaidTreeTask implements IMaidTask, IMaidBlockPlaceTask, IMaidBlockD
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldPlaceItemStack(EntityMaid maid, ItemStack itemStack) {
|
public boolean shouldPlaceItemStack(EntityMaid maid, ItemStack itemStack) {
|
||||||
|
if (!maid.getOrCreateData(MaidLoggingConfig.KEY, MaidLoggingConfig.Data.getDefault()).plant()) return false;
|
||||||
return itemStack.is(ItemTags.SAPLINGS);
|
return itemStack.is(ItemTags.SAPLINGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +151,7 @@ public class MaidTreeTask implements IMaidTask, IMaidBlockPlaceTask, IMaidBlockD
|
|||||||
CombinedInvWrapper inv = maid.getAvailableInv(true);
|
CombinedInvWrapper inv = maid.getAvailableInv(true);
|
||||||
int target = -1;
|
int target = -1;
|
||||||
for (int i = 0; i < inv.getSlots(); i++) {
|
for (int i = 0; i < inv.getSlots(); i++) {
|
||||||
if (inv.getStackInSlot(i).is(Items.SHEARS)) {
|
if (inv.getStackInSlot(i).is(Items.SHEARS) || inv.getStackInSlot(i).is(ItemTags.HOES)) {
|
||||||
target = i;
|
target = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -133,34 +182,69 @@ public class MaidTreeTask implements IMaidTask, IMaidBlockPlaceTask, IMaidBlockD
|
|||||||
return IMaidBlockDestroyTask.super.availableToGetDrop(maid, fakePlayer, pos, targetBlockState);
|
return IMaidBlockDestroyTask.super.availableToGetDrop(maid, fakePlayer, pos, targetBlockState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected boolean isValidNatureTree(EntityMaid maid, BlockPos startPos) {
|
protected boolean isValidNatureTree(EntityMaid maid, BlockPos startPos) {
|
||||||
|
HashSet<BlockPos> vis = new HashSet<>();
|
||||||
|
BlockValidationMemory validationMemory = MemoryUtil.getBlockValidationMemory(maid);
|
||||||
|
boolean validNatureTree = isValidNatureTree(maid, startPos, vis, 0, validationMemory);
|
||||||
|
for (BlockPos pos : vis) {
|
||||||
|
BlockState blockState = maid.level().getBlockState(pos);
|
||||||
|
if (!blockState.is(BlockTags.LEAVES) && !blockState.is(BlockTags.LOGS))
|
||||||
|
continue;
|
||||||
|
if (validNatureTree)
|
||||||
|
validationMemory.setValid(pos);
|
||||||
|
else
|
||||||
|
validationMemory.setInvalid(pos);
|
||||||
|
}
|
||||||
|
return validNatureTree;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isValidNatureTree(EntityMaid maid, BlockPos startPos, Set<BlockPos> visited, int depth, BlockValidationMemory validationMemory) {
|
||||||
|
if (validationMemory.hasRecord(startPos))
|
||||||
|
return validationMemory.isValid(startPos, false);
|
||||||
|
if (visited.contains(startPos))
|
||||||
|
return false;
|
||||||
|
if (depth > 100) return false;
|
||||||
|
visited.add(startPos);
|
||||||
|
boolean valid = false;
|
||||||
final int[] dv = {0, 1, -1};
|
final int[] dv = {0, 1, -1};
|
||||||
for (int dx : dv) {
|
for (int dx : dv) {
|
||||||
for (int dz : dv) {
|
for (int dz : dv) {
|
||||||
for (int dy = 0; dy < 6; dy++) {
|
for (int dy : dv) {
|
||||||
BlockState blockState = maid.level().getBlockState(startPos.offset(dx, dy, dz));
|
BlockPos offset = startPos.offset(dx, dy, dz);
|
||||||
if (blockState.is(BlockTags.LEAVES) && !blockState.getValue(LeavesBlock.PERSISTENT)) {
|
BlockState blockState = maid.level().getBlockState(offset);
|
||||||
return true;
|
if (blockState.is(BlockTags.LEAVES) && blockState.hasProperty(LeavesBlock.PERSISTENT) && !blockState.getValue(LeavesBlock.PERSISTENT)) {
|
||||||
|
valid = true;
|
||||||
|
}
|
||||||
|
if (blockState.is(BlockTags.LOGS) && isValidNatureTree(maid, offset, visited, depth + 1, validationMemory)) {
|
||||||
|
valid = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
if (valid)
|
||||||
|
validationMemory.setValid(startPos);
|
||||||
|
else
|
||||||
|
validationMemory.setInvalid(startPos);
|
||||||
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Pair<Integer, BehaviorControl<? super EntityMaid>>> createBrainTasks(EntityMaid entityMaid) {
|
public List<Pair<Integer, BehaviorControl<? super EntityMaid>>> createBrainTasks(EntityMaid entityMaid) {
|
||||||
ArrayList<Pair<Integer, BehaviorControl<? super EntityMaid>>> list = new ArrayList<>();
|
ArrayList<Pair<Integer, BehaviorControl<? super EntityMaid>>> list = new ArrayList<>();
|
||||||
list.add(Pair.of(6, new LoopWithTokenBehavior()));
|
list.add(Pair.of(0, new MaidSelfRescueBehavior()));
|
||||||
|
|
||||||
|
list.add(Pair.of(1, new DestoryBlockBehavior()));
|
||||||
|
list.add(Pair.of(1, new DestoryBlockMoveBehavior()));
|
||||||
|
|
||||||
|
list.add(Pair.of(2, new BlockUpScheduleBehavior()));
|
||||||
|
list.add(Pair.of(2, new BlockUpPlaceBehavior()));
|
||||||
|
list.add(Pair.of(2, new BlockUpDestroyBehavior()));
|
||||||
|
|
||||||
list.add(Pair.of(5, new DestoryBlockBehavior()));
|
|
||||||
list.add(Pair.of(4, new DestoryBlockMoveBehavior()));
|
|
||||||
list.add(Pair.of(3, new PlaceBlockBehavior()));
|
list.add(Pair.of(3, new PlaceBlockBehavior()));
|
||||||
list.add(Pair.of(2, new PlaceBlockMoveBehavior()));
|
list.add(Pair.of(3, new PlaceBlockMoveBehavior()));
|
||||||
|
|
||||||
list.add(Pair.of(1, new BlockUpScheduleBehavior()));
|
list.add(Pair.of(4, new UpdateValidationMemoryBehavior()));
|
||||||
list.add(Pair.of(0, new BlockUpPlaceBehavior()));
|
|
||||||
list.add(Pair.of(0, new BlockUpDestroyBehavior()));
|
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@@ -179,6 +263,47 @@ public class MaidTreeTask implements IMaidTask, IMaidBlockPlaceTask, IMaidBlockD
|
|||||||
public boolean isFindingBlock(EntityMaid maid, BlockPos target, BlockPos standPos) {
|
public boolean isFindingBlock(EntityMaid maid, BlockPos target, BlockPos standPos) {
|
||||||
if (target.distSqr(standPos) > touchLimit() * touchLimit())
|
if (target.distSqr(standPos) > touchLimit() * touchLimit())
|
||||||
return false;
|
return false;
|
||||||
return maid.level().getBlockState(target).is(BlockTags.LOGS) && isValidNatureTree(maid, target);
|
if (maid.level().getBlockState(target).is(BlockTags.LOGS)) {
|
||||||
|
return !MaidLoggingConfig.get(maid).skipNonNature() || isValidNatureTree(maid, target);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public boolean tryDestroyBlockUp(EntityMaid maid, BlockPos targetPos) {
|
||||||
|
return tryDestroyBlock(maid, targetPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean tryPlaceBlock(EntityMaid maid, BlockPos pos) {
|
||||||
|
if (IMaidBlockPlaceTask.super.tryPlaceBlock(maid, pos)) {
|
||||||
|
MemoryUtil.getBlockValidationMemory(maid).setValid(pos);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean tryDestroyBlock(EntityMaid maid, BlockPos blockPos) {
|
||||||
|
if (MaidUtils.destroyBlock(maid, blockPos)) {
|
||||||
|
MemoryUtil.getBlockValidationMemory(maid).remove(blockPos);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 此处判断当home模式未开启时,不允许上搭。
|
||||||
|
*
|
||||||
|
* @param maid
|
||||||
|
* @param center
|
||||||
|
* @param maxUp
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public oshi.util.tuples.Pair<BlockPos, BlockPos> findTargetPosBlockUp(EntityMaid maid, BlockPos center, int maxUp) {
|
||||||
|
if (maid.isHomeModeEnable() && MaidLoggingConfig.get(maid).blockUp() && !Config.disableLoggingBlockUp)
|
||||||
|
return IMaidBlockUpTask.super.findTargetPosBlockUp(maid, center, maxUp);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,13 +7,13 @@ import net.minecraft.world.entity.ai.Brain;
|
|||||||
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
||||||
import net.minecraft.world.entity.ai.memory.WalkTarget;
|
import net.minecraft.world.entity.ai.memory.WalkTarget;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import studio.fantasyit.maid_useful_task.registry.MemoryModuleRegistry;
|
import studio.fantasyit.maid_useful_task.memory.CurrentWork;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class Conditions {
|
public class Conditions {
|
||||||
public static boolean hasReachedValidTargetOrReset(EntityMaid maid) {
|
public static boolean hasReachedValidTargetOrReset(EntityMaid maid) {
|
||||||
return hasReachedValidTargetOrReset(maid, 2);
|
return hasReachedValidTargetOrReset(maid, 2.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasReachedValidTargetOrReset(EntityMaid maid, float closeEnough) {
|
public static boolean hasReachedValidTargetOrReset(EntityMaid maid, float closeEnough) {
|
||||||
@@ -24,6 +24,7 @@ public class Conditions {
|
|||||||
Optional<WalkTarget> walkTarget = brain.getMemory(MemoryModuleType.WALK_TARGET);
|
Optional<WalkTarget> walkTarget = brain.getMemory(MemoryModuleType.WALK_TARGET);
|
||||||
if (walkTarget.isEmpty() || !walkTarget.get().getTarget().currentPosition().equals(targetV3d)) {
|
if (walkTarget.isEmpty() || !walkTarget.get().getTarget().currentPosition().equals(targetV3d)) {
|
||||||
brain.eraseMemory(InitEntities.TARGET_POS.get());
|
brain.eraseMemory(InitEntities.TARGET_POS.get());
|
||||||
|
MemoryUtil.setCurrent(maid, CurrentWork.IDLE);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -41,10 +42,12 @@ public class Conditions {
|
|||||||
|
|
||||||
public static boolean isGlobalValidTarget(EntityMaid maid, BlockPos pos, BlockPos targetPos) {
|
public static boolean isGlobalValidTarget(EntityMaid maid, BlockPos pos, BlockPos targetPos) {
|
||||||
if (MemoryUtil.getBlockUpContext(maid).hasTarget()) {
|
if (MemoryUtil.getBlockUpContext(maid).hasTarget()) {
|
||||||
if (targetPos.getY() < maid.getBlockY() && targetPos.getX() == maid.getBlockX() && targetPos.getZ() == maid.getBlockZ())
|
return pos.equals(maid.blockPosition());
|
||||||
return false;
|
|
||||||
return MemoryUtil.getBlockUpContext(maid).isTarget(pos);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isCurrent(EntityMaid maid, CurrentWork currentWork) {
|
||||||
|
return MemoryUtil.getCurrent(maid) == currentWork;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.util;
|
||||||
|
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.neoforged.neoforge.items.IItemHandler;
|
||||||
|
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
public class InvUtil {
|
||||||
|
public static ItemStack tryExtractOneMatches(IItemHandler inv, Predicate<ItemStack> predicate) {
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < inv.getSlots(); i++) {
|
||||||
|
ItemStack stackInSlot = inv.getStackInSlot(i);
|
||||||
|
if (stackInSlot.isEmpty()) continue;
|
||||||
|
if (predicate.test(stackInSlot)) {
|
||||||
|
ItemStack get = inv.extractItem(i, 1, false);
|
||||||
|
if (!get.isEmpty()) {
|
||||||
|
return get;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
package studio.fantasyit.maid_useful_task.util;
|
package studio.fantasyit.maid_useful_task.util;
|
||||||
|
|
||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.InteractionResult;
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.level.ClipContext;
|
import net.minecraft.world.level.ClipContext;
|
||||||
@@ -17,11 +16,8 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||||||
import net.minecraft.world.level.gameevent.GameEvent;
|
import net.minecraft.world.level.gameevent.GameEvent;
|
||||||
import net.minecraft.world.level.material.FluidState;
|
import net.minecraft.world.level.material.FluidState;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
import net.minecraftforge.common.util.FakePlayer;
|
import net.neoforged.neoforge.items.wrapper.RangedWrapper;
|
||||||
import net.minecraftforge.common.util.FakePlayerFactory;
|
|
||||||
import net.minecraftforge.items.wrapper.RangedWrapper;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class MaidUtils {
|
public class MaidUtils {
|
||||||
@@ -37,7 +33,25 @@ public class MaidUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static boolean destroyBlock(EntityMaid maid, BlockPos blockPos){
|
|
||||||
|
public static float getDestroyProgressDelta(EntityMaid maid, BlockPos blockPos) {
|
||||||
|
WrappedMaidFakePlayer fakePlayer = WrappedMaidFakePlayer.get(maid);
|
||||||
|
BlockState blockState = maid.level().getBlockState(blockPos);
|
||||||
|
return blockState.getDestroyProgress(fakePlayer, maid.level(), blockPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BlockPos getMaidRestrictCenter(EntityMaid maid) {
|
||||||
|
if (MemoryUtil.getBlockUpContext(maid).hasTarget()) {
|
||||||
|
return MemoryUtil.getBlockUpContext(maid).getTargetPos();
|
||||||
|
}
|
||||||
|
if (maid.hasRestriction())
|
||||||
|
return maid.getRestrictCenter();
|
||||||
|
return maid.blockPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean destroyBlock(EntityMaid maid, BlockPos blockPos) {
|
||||||
|
WrappedMaidFakePlayer fakePlayer = WrappedMaidFakePlayer.get(maid);
|
||||||
|
maid.getMainHandItem().hurtAndBreak(1, fakePlayer, EquipmentSlot.MAINHAND);
|
||||||
ServerLevel level = (ServerLevel) maid.level();
|
ServerLevel level = (ServerLevel) maid.level();
|
||||||
BlockState blockState = level.getBlockState(blockPos);
|
BlockState blockState = level.getBlockState(blockPos);
|
||||||
if (blockState.isAir()) {
|
if (blockState.isAir()) {
|
||||||
@@ -62,7 +76,7 @@ public class MaidUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean placeBlock(EntityMaid maid, BlockPos pos) {
|
public static boolean placeBlock(EntityMaid maid, BlockPos pos) {
|
||||||
Player fakePlayer = WrappedMaidFakePlayer.get(maid);
|
WrappedMaidFakePlayer fakePlayer = WrappedMaidFakePlayer.get(maid);
|
||||||
BlockHitResult result = null;
|
BlockHitResult result = null;
|
||||||
ClipContext rayTraceContext = new ClipContext(maid.getPosition(0).add(0, maid.getEyeHeight(), 0),
|
ClipContext rayTraceContext = new ClipContext(maid.getPosition(0).add(0, maid.getEyeHeight(), 0),
|
||||||
pos.getCenter(),
|
pos.getCenter(),
|
||||||
|
|||||||
@@ -5,14 +5,15 @@ import com.github.tartaricacid.touhoulittlemaid.init.InitEntities;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.ai.Brain;
|
import net.minecraft.world.entity.ai.Brain;
|
||||||
|
import net.minecraft.world.entity.ai.behavior.BehaviorUtils;
|
||||||
import net.minecraft.world.entity.ai.behavior.BlockPosTracker;
|
import net.minecraft.world.entity.ai.behavior.BlockPosTracker;
|
||||||
import net.minecraft.world.entity.ai.behavior.PositionTracker;
|
import net.minecraft.world.entity.ai.behavior.PositionTracker;
|
||||||
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import studio.fantasyit.maid_useful_task.memory.BlockTargetMemory;
|
import studio.fantasyit.maid_useful_task.memory.*;
|
||||||
import studio.fantasyit.maid_useful_task.memory.BlockUpContext;
|
|
||||||
import studio.fantasyit.maid_useful_task.memory.TaskRateLimitToken;
|
|
||||||
import studio.fantasyit.maid_useful_task.registry.MemoryModuleRegistry;
|
import studio.fantasyit.maid_useful_task.registry.MemoryModuleRegistry;
|
||||||
|
import studio.fantasyit.maid_useful_task.vehicle.MaidVehicleControlType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -22,6 +23,7 @@ public class MemoryUtil {
|
|||||||
Optional<BlockTargetMemory> memory = maid.getBrain().getMemory(MemoryModuleRegistry.DESTROY_TARGET.get());
|
Optional<BlockTargetMemory> memory = maid.getBrain().getMemory(MemoryModuleRegistry.DESTROY_TARGET.get());
|
||||||
return memory.orElse(null);
|
return memory.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setDestroyTargetMemory(EntityMaid maid, List<BlockPos> blockPosSet) {
|
public static void setDestroyTargetMemory(EntityMaid maid, List<BlockPos> blockPosSet) {
|
||||||
maid.getBrain().setMemory(MemoryModuleRegistry.DESTROY_TARGET.get(), new BlockTargetMemory(blockPosSet));
|
maid.getBrain().setMemory(MemoryModuleRegistry.DESTROY_TARGET.get(), new BlockTargetMemory(blockPosSet));
|
||||||
}
|
}
|
||||||
@@ -44,9 +46,11 @@ public class MemoryUtil {
|
|||||||
Optional<BlockPos> memory = maid.getBrain().getMemory(MemoryModuleRegistry.PLACE_TARGET.get());
|
Optional<BlockPos> memory = maid.getBrain().getMemory(MemoryModuleRegistry.PLACE_TARGET.get());
|
||||||
return memory.orElse(null);
|
return memory.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setPlaceTarget(EntityMaid maid, BlockPos blockPos) {
|
public static void setPlaceTarget(EntityMaid maid, BlockPos blockPos) {
|
||||||
maid.getBrain().setMemory(MemoryModuleRegistry.PLACE_TARGET.get(), blockPos);
|
maid.getBrain().setMemory(MemoryModuleRegistry.PLACE_TARGET.get(), blockPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearPlaceTarget(EntityMaid maid) {
|
public static void clearPlaceTarget(EntityMaid maid) {
|
||||||
maid.getBrain().eraseMemory(MemoryModuleRegistry.PLACE_TARGET.get());
|
maid.getBrain().eraseMemory(MemoryModuleRegistry.PLACE_TARGET.get());
|
||||||
}
|
}
|
||||||
@@ -55,19 +59,59 @@ public class MemoryUtil {
|
|||||||
maid.getBrain().setMemory(MemoryModuleType.LOOK_TARGET, new BlockPosTracker(pos));
|
maid.getBrain().setMemory(MemoryModuleType.LOOK_TARGET, new BlockPosTracker(pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockUpContext getBlockUpContext(EntityMaid maid){
|
public static BlockUpContext getBlockUpContext(EntityMaid maid) {
|
||||||
Brain<EntityMaid> brain = maid.getBrain();
|
Brain<EntityMaid> brain = maid.getBrain();
|
||||||
if(!brain.hasMemoryValue(MemoryModuleRegistry.BLOCK_UP_TARGET.get())){
|
if (!brain.hasMemoryValue(MemoryModuleRegistry.BLOCK_UP_TARGET.get())) {
|
||||||
brain.setMemory(MemoryModuleRegistry.BLOCK_UP_TARGET.get(), new BlockUpContext());
|
brain.setMemory(MemoryModuleRegistry.BLOCK_UP_TARGET.get(), new BlockUpContext());
|
||||||
}
|
}
|
||||||
return brain.getMemory(MemoryModuleRegistry.BLOCK_UP_TARGET.get()).get();
|
return brain.getMemory(MemoryModuleRegistry.BLOCK_UP_TARGET.get()).get();
|
||||||
}
|
}
|
||||||
public static TaskRateLimitToken getRateLimitToken(EntityMaid maid){
|
|
||||||
|
public static BlockValidationMemory getBlockValidationMemory(EntityMaid maid) {
|
||||||
Brain<EntityMaid> brain = maid.getBrain();
|
Brain<EntityMaid> brain = maid.getBrain();
|
||||||
if(!brain.hasMemoryValue(MemoryModuleRegistry.RATE_LIMIT_TOKEN.get())){
|
if (!brain.hasMemoryValue(MemoryModuleRegistry.BLOCK_VALIDATION.get())) {
|
||||||
brain.setMemory(MemoryModuleRegistry.RATE_LIMIT_TOKEN.get(), new TaskRateLimitToken());
|
brain.setMemory(MemoryModuleRegistry.BLOCK_VALIDATION.get(), new BlockValidationMemory());
|
||||||
}
|
}
|
||||||
return brain.getMemory(MemoryModuleRegistry.RATE_LIMIT_TOKEN.get()).get();
|
return brain.getMemory(MemoryModuleRegistry.BLOCK_VALIDATION.get()).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setTarget(EntityMaid maid, BlockPos targetPos, float speed) {
|
||||||
|
maid.getBrain().setMemory(InitEntities.TARGET_POS.get(), new BlockPosTracker(targetPos));
|
||||||
|
BehaviorUtils.setWalkAndLookTargetMemories(maid, targetPos, speed, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CurrentWork getCurrent(EntityMaid maid) {
|
||||||
|
return maid.getBrain().getMemory(MemoryModuleRegistry.CURRENT_WORK.get()).orElse(CurrentWork.IDLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCurrent(EntityMaid maid, CurrentWork currentWork) {
|
||||||
|
maid.getBrain().setMemory(MemoryModuleRegistry.CURRENT_WORK.get(), currentWork);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCommonBlockCache(EntityMaid maid, BlockPos pos) {
|
||||||
|
maid.getBrain().setMemory(MemoryModuleRegistry.COMMON_BLOCK_CACHE.get(), pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BlockPos getCommonBlockCache(EntityMaid maid) {
|
||||||
|
return maid.getBrain().getMemory(MemoryModuleRegistry.COMMON_BLOCK_CACHE.get()).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setAllowHandleVehicle(EntityMaid maid, MaidVehicleControlType allow) {
|
||||||
|
maid.getBrain().setMemory(MemoryModuleRegistry.IS_ALLOW_HANDLE_VEHICLE.get(), allow);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MaidVehicleControlType getAllowHandleVehicle(EntityMaid maid) {
|
||||||
|
return maid.getBrain().getMemory(MemoryModuleRegistry.IS_ALLOW_HANDLE_VEHICLE.get()).orElse(MaidVehicleControlType.NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearCommonBlockCache(EntityMaid maid) {
|
||||||
|
maid.getBrain().eraseMemory(MemoryModuleRegistry.COMMON_BLOCK_CACHE.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setLocateItem(EntityMaid maid, ItemStack item) {
|
||||||
|
maid.getBrain().setMemory(MemoryModuleRegistry.LOCATE_ITEM.get(), item);
|
||||||
|
}
|
||||||
|
public static ItemStack getLocateItem(EntityMaid maid) {
|
||||||
|
return maid.getBrain().getMemory(MemoryModuleRegistry.LOCATE_ITEM.get()).orElse(ItemStack.EMPTY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package studio.fantasyit.maid_useful_task.util;
|
|||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
import net.minecraft.world.level.BlockGetter;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||||
|
|
||||||
public class PosUtils {
|
public class PosUtils {
|
||||||
public static boolean isFourSideAir(BlockGetter level, BlockPos pos) {
|
public static boolean isFourSideAir(BlockGetter level, BlockPos pos) {
|
||||||
@@ -11,4 +13,17 @@ public class PosUtils {
|
|||||||
level.getBlockState(pos.east()).isAir() &&
|
level.getBlockState(pos.east()).isAir() &&
|
||||||
level.getBlockState(pos.west()).isAir();
|
level.getBlockState(pos.west()).isAir();
|
||||||
}
|
}
|
||||||
|
static protected boolean isEmptyBlockPos(Level level, BlockPos pos) {
|
||||||
|
return level.getBlockState(pos).isAir() || level.getBlockState(pos).getCollisionShape(
|
||||||
|
level,
|
||||||
|
pos,
|
||||||
|
CollisionContext.empty()
|
||||||
|
).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
static public boolean isSafePos(Level level, BlockPos pos) {
|
||||||
|
return isEmptyBlockPos(level, pos)
|
||||||
|
&& isEmptyBlockPos(level, pos.above())
|
||||||
|
&& !isEmptyBlockPos(level, pos.below());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.util;
|
||||||
|
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class RotUtil {
|
||||||
|
public static float getXRot(Vec3 from, Vec3 to) {
|
||||||
|
double d0 = to.x() - from.x();
|
||||||
|
double d1 = to.y() - from.y();
|
||||||
|
double d2 = to.z() - from.z();
|
||||||
|
double d3 = Math.sqrt(d0 * d0 + d2 * d2);
|
||||||
|
return Mth.wrapDegrees((float) (-(Mth.atan2(d1, d3) * (double) (180F / (float) Math.PI))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getYRot(Vec3 from, Vec3 to) {
|
||||||
|
double d0 = to.x() - from.x();
|
||||||
|
double d1 = to.y() - from.y();
|
||||||
|
double d2 = to.z() - from.z();
|
||||||
|
double d3 = Math.sqrt(d0 * d0 + d2 * d2);
|
||||||
|
return Mth.wrapDegrees((float) (-(Mth.atan2(d0, d2) * (double) (180F / (float) Math.PI))));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.util;
|
||||||
|
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
|
||||||
|
public class TranslateUtil {
|
||||||
|
public static Component getBooleanTranslate(boolean b) {
|
||||||
|
return (b ? Component.translatable("gui.maid_useful_task.yes") : Component.translatable("gui.maid_useful_task.no"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,9 +3,14 @@ package studio.fantasyit.maid_useful_task.util;
|
|||||||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.nbt.ListTag;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
|
import net.minecraft.world.Container;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
|
import net.minecraft.world.damagesource.DamageSource;
|
||||||
import net.minecraft.world.effect.MobEffect;
|
import net.minecraft.world.effect.MobEffect;
|
||||||
import net.minecraft.world.effect.MobEffectInstance;
|
import net.minecraft.world.effect.MobEffectInstance;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
@@ -13,13 +18,17 @@ import net.minecraft.world.entity.EquipmentSlot;
|
|||||||
import net.minecraft.world.entity.HumanoidArm;
|
import net.minecraft.world.entity.HumanoidArm;
|
||||||
import net.minecraft.world.entity.RelativeMovement;
|
import net.minecraft.world.entity.RelativeMovement;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.entity.player.StackedContents;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.material.Fluid;
|
import net.minecraft.world.level.material.Fluid;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.common.util.FakePlayer;
|
import net.neoforged.neoforge.common.util.FakePlayer;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -27,8 +36,28 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class WrappedMaidFakePlayer extends FakePlayer {
|
public class WrappedMaidFakePlayer extends FakePlayer {
|
||||||
|
public static class WrappedMaidInventory extends Inventory {
|
||||||
|
private final EntityMaid maid;
|
||||||
|
|
||||||
|
public WrappedMaidInventory(EntityMaid p_35983_, WrappedMaidFakePlayer fakePlayer) {
|
||||||
|
super(fakePlayer);
|
||||||
|
this.maid = p_35983_;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ItemStack getSelected() {
|
||||||
|
return maid.getMainHandItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getDestroySpeed(BlockState p_36021_) {
|
||||||
|
return maid.getMainHandItem().getDestroySpeed(p_36021_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static ConcurrentHashMap<UUID, WrappedMaidFakePlayer> cache = new ConcurrentHashMap<>();
|
private static ConcurrentHashMap<UUID, WrappedMaidFakePlayer> cache = new ConcurrentHashMap<>();
|
||||||
private final EntityMaid maid;
|
private final EntityMaid maid;
|
||||||
|
|
||||||
@@ -50,17 +79,18 @@ public class WrappedMaidFakePlayer extends FakePlayer {
|
|||||||
private WrappedMaidFakePlayer(EntityMaid maid) {
|
private WrappedMaidFakePlayer(EntityMaid maid) {
|
||||||
super((ServerLevel) maid.level(), new GameProfile(UUID.randomUUID(), maid.getName().getString()));
|
super((ServerLevel) maid.level(), new GameProfile(UUID.randomUUID(), maid.getName().getString()));
|
||||||
this.maid = maid;
|
this.maid = maid;
|
||||||
|
this.inventory = new WrappedMaidInventory(maid, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeEffect(MobEffect p_21196_) {
|
public boolean removeEffect(Holder<MobEffect> p_21196_) {
|
||||||
if (maid == null) return false;
|
if (maid == null) return false;
|
||||||
return maid.removeEffect(p_21196_);
|
return maid.removeEffect(p_21196_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public MobEffectInstance removeEffectNoUpdate(@Nullable MobEffect p_21164_) {
|
public MobEffectInstance removeEffectNoUpdate(@Nullable Holder<MobEffect> p_21164_) {
|
||||||
if (maid == null) return super.removeEffectNoUpdate(p_21164_);
|
if (maid == null) return super.removeEffectNoUpdate(p_21164_);
|
||||||
return maid.removeEffectNoUpdate(p_21164_);
|
return maid.removeEffectNoUpdate(p_21164_);
|
||||||
}
|
}
|
||||||
@@ -90,7 +120,7 @@ public class WrappedMaidFakePlayer extends FakePlayer {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public MobEffectInstance getEffect(MobEffect p_21125_) {
|
public MobEffectInstance getEffect(Holder<MobEffect> p_21125_) {
|
||||||
if (maid == null) return super.getEffect(p_21125_);
|
if (maid == null) return super.getEffect(p_21125_);
|
||||||
return maid.getEffect(p_21125_);
|
return maid.getEffect(p_21125_);
|
||||||
}
|
}
|
||||||
@@ -102,13 +132,13 @@ public class WrappedMaidFakePlayer extends FakePlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<MobEffect, MobEffectInstance> getActiveEffectsMap() {
|
public Map<Holder<MobEffect>, MobEffectInstance> getActiveEffectsMap() {
|
||||||
if (maid == null) return super.getActiveEffectsMap();
|
if (maid == null) return super.getActiveEffectsMap();
|
||||||
return maid.getActiveEffectsMap();
|
return maid.getActiveEffectsMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasEffect(MobEffect p_21024_) {
|
public boolean hasEffect(Holder<MobEffect> p_21024_) {
|
||||||
if (maid == null) return super.hasEffect(p_21024_);
|
if (maid == null) return super.hasEffect(p_21024_);
|
||||||
return maid.hasEffect(p_21024_);
|
return maid.hasEffect(p_21024_);
|
||||||
}
|
}
|
||||||
@@ -179,6 +209,24 @@ public class WrappedMaidFakePlayer extends FakePlayer {
|
|||||||
return maid.position();
|
return maid.position();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float distanceTo(Entity p_20271_) {
|
||||||
|
if (maid == null) return super.distanceTo(p_20271_);
|
||||||
|
return maid.distanceTo(p_20271_);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double distanceToSqr(double p_20276_, double p_20277_, double p_20278_) {
|
||||||
|
if (maid == null) return super.distanceToSqr(p_20276_, p_20277_, p_20278_);
|
||||||
|
return maid.distanceToSqr(p_20276_, p_20277_, p_20278_);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double distanceToSqr(Vec3 p_20239_) {
|
||||||
|
if (maid == null) return super.distanceToSqr(p_20239_);
|
||||||
|
return maid.distanceToSqr(p_20239_);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleportTo(double p_8969_, double p_8970_, double p_8971_) {
|
public void teleportTo(double p_8969_, double p_8970_, double p_8971_) {
|
||||||
if (maid == null) return;
|
if (maid == null) return;
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.vehicle;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
abstract public class AbstractMaidControllableVehicle {
|
||||||
|
abstract public boolean isMaidOnThisVehicle(EntityMaid maid);
|
||||||
|
|
||||||
|
abstract public void maidStopControlVehicle(EntityMaid maid);
|
||||||
|
|
||||||
|
abstract public void maidControlVehicle(EntityMaid maid, MaidVehicleControlType type, BlockPos target);
|
||||||
|
|
||||||
|
public void syncVehicleParameter(EntityMaid maid, CompoundTag tag){
|
||||||
|
if(maid.getVehicle() instanceof IVirtualControl vehicle){
|
||||||
|
vehicle.maid_useful_tasks$setControlParam(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public @Nullable CompoundTag getSyncVehicleParameter(EntityMaid maid) {
|
||||||
|
if (maid.getVehicle() instanceof IVirtualControl vehicle) {
|
||||||
|
return vehicle.maid_useful_tasks$getControlParam();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.vehicle;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
|
||||||
|
public interface IVirtualControl {
|
||||||
|
void maid_useful_tasks$setControlParam(float xRot, float yRot, float speed, MaidVehicleControlType type);
|
||||||
|
|
||||||
|
void maid_useful_tasks$stopControl();
|
||||||
|
|
||||||
|
CompoundTag maid_useful_tasks$getControlParam();
|
||||||
|
|
||||||
|
void maid_useful_tasks$setControlParam(CompoundTag target);
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.vehicle;
|
||||||
|
|
||||||
|
public enum MaidVehicleControlType {
|
||||||
|
NONE,
|
||||||
|
ROT_ONLY,
|
||||||
|
FULL
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.vehicle;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.neoforged.neoforge.network.PacketDistributor;
|
||||||
|
import studio.fantasyit.maid_useful_task.network.MaidSyncVehiclePacket;
|
||||||
|
import studio.fantasyit.maid_useful_task.network.Network;
|
||||||
|
import studio.fantasyit.maid_useful_task.vehicle.broom.VehicleBroom;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class MaidVehicleManager {
|
||||||
|
public static List<AbstractMaidControllableVehicle> controllableVehicles = new ArrayList<>();
|
||||||
|
|
||||||
|
public static void register() {
|
||||||
|
controllableVehicles.add(new VehicleBroom());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addControllableVehicle(AbstractMaidControllableVehicle vehicle) {
|
||||||
|
controllableVehicles.add(vehicle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<AbstractMaidControllableVehicle> getControllableVehicle(EntityMaid maid) {
|
||||||
|
for (AbstractMaidControllableVehicle vehicle : controllableVehicles) {
|
||||||
|
if (vehicle.isMaidOnThisVehicle(maid)) return Optional.of(vehicle);
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void syncVehicleParameter(EntityMaid maid) {
|
||||||
|
getControllableVehicle(maid).ifPresent(vehicle -> {
|
||||||
|
CompoundTag syncVehicleParameter = vehicle.getSyncVehicleParameter(maid);
|
||||||
|
if (syncVehicleParameter != null) {
|
||||||
|
PacketDistributor.sendToPlayersTrackingEntity(maid,
|
||||||
|
new MaidSyncVehiclePacket(maid.getId(), syncVehicleParameter)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void stopControlling(EntityMaid maid) {
|
||||||
|
MaidVehicleManager.getControllableVehicle(maid).ifPresent(vehicle -> vehicle.maidStopControlVehicle(maid));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.vehicle.broom;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import studio.fantasyit.maid_useful_task.vehicle.MaidVehicleControlType;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class BroomControlParamStore {
|
||||||
|
public record BroomControlParam(float xRot, float yRot, float vertical, float forward,
|
||||||
|
MaidVehicleControlType type) {
|
||||||
|
public static BroomControlParam fromNbt(CompoundTag tag) {
|
||||||
|
return new BroomControlParam(
|
||||||
|
tag.getFloat("xRot"),
|
||||||
|
tag.getFloat("yRot"),
|
||||||
|
tag.getFloat("vertical"),
|
||||||
|
tag.getFloat("forward"),
|
||||||
|
MaidVehicleControlType.valueOf(tag.getString("type"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompoundTag toNbt() {
|
||||||
|
CompoundTag tag = new CompoundTag();
|
||||||
|
tag.putFloat("xRot", xRot);
|
||||||
|
tag.putFloat("yRot", yRot);
|
||||||
|
tag.putFloat("vertical", vertical);
|
||||||
|
tag.putFloat("forward", forward);
|
||||||
|
tag.putString("type", type.name());
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final BroomControlParam NONE = new BroomControlParam(0, 0, 0, 0, MaidVehicleControlType.NONE);
|
||||||
|
|
||||||
|
private static final Map<UUID, BroomControlParam> store = new HashMap<>();
|
||||||
|
|
||||||
|
public static void setControlParam(EntityMaid maid, BroomControlParam param) {
|
||||||
|
store.put(maid.getUUID(), param);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BroomControlParam getControlParam(EntityMaid maid) {
|
||||||
|
if (!store.containsKey(maid.getUUID()))
|
||||||
|
return NONE;
|
||||||
|
return store.get(maid.getUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeControlParam(EntityMaid maid) {
|
||||||
|
store.remove(maid.getUUID());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.vehicle.broom;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.api.entity.IBroomControl;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityBroom;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import studio.fantasyit.maid_useful_task.vehicle.MaidVehicleControlType;
|
||||||
|
|
||||||
|
public class BroomController implements IBroomControl {
|
||||||
|
private final EntityBroom broom;
|
||||||
|
|
||||||
|
public BroomController(EntityBroom broom) {
|
||||||
|
this.broom = broom;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean inControl(Player player, EntityMaid entityMaid) {
|
||||||
|
return BroomControlParamStore.getControlParam(entityMaid).type() != MaidVehicleControlType.NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void travel(Player player, EntityMaid entityMaid) {
|
||||||
|
BroomControlParamStore.BroomControlParam param = BroomControlParamStore.getControlParam(entityMaid);
|
||||||
|
|
||||||
|
float forward = 0;
|
||||||
|
float strafe = 0;
|
||||||
|
float vertical = param.vertical();
|
||||||
|
if (param.type() == MaidVehicleControlType.FULL) {
|
||||||
|
forward = param.forward() / 15.0f;
|
||||||
|
} else {
|
||||||
|
boolean keyForward = player.zza > 0;
|
||||||
|
boolean keyBack = player.zza < 0;
|
||||||
|
boolean keyLeft = player.xxa > 0;
|
||||||
|
boolean keyRight = player.xxa < 0;
|
||||||
|
|
||||||
|
if (keyForward || keyBack || keyLeft || keyRight) {
|
||||||
|
strafe = keyLeft ? 0.2f : (keyRight ? -0.2f : 0);
|
||||||
|
forward = keyForward ? 0.375f : (keyBack ? -0.2f : 0);
|
||||||
|
} else {
|
||||||
|
vertical = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//来自PlayerBroomControl
|
||||||
|
double playerSpeed = player.getAttributeValue(Attributes.MOVEMENT_SPEED);
|
||||||
|
double speed = Math.max(playerSpeed - 0.1, 0) * 2.5 + 0.1;
|
||||||
|
Vec3 targetMotion = new Vec3(strafe, vertical, forward).scale(speed * 20);
|
||||||
|
targetMotion = targetMotion.yRot((float) (-broom.getYRot() * Math.PI / 180.0));
|
||||||
|
|
||||||
|
// 插值到目标速度,而不是直接累加
|
||||||
|
Vec3 currentMotion = broom.getDeltaMovement();
|
||||||
|
Vec3 newMotion = currentMotion.lerp(targetMotion, 0.25f);
|
||||||
|
broom.setDeltaMovement(newMotion);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tickRot(Player player, EntityMaid entityMaid) {
|
||||||
|
BroomControlParamStore.BroomControlParam param = BroomControlParamStore.getControlParam(entityMaid);
|
||||||
|
|
||||||
|
broom.yRotO = broom.yBodyRot = broom.yHeadRot = broom.getYRot();
|
||||||
|
broom.setRot(param.yRot(), param.xRot());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package studio.fantasyit.maid_useful_task.vehicle.broom;
|
||||||
|
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityBroom;
|
||||||
|
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import studio.fantasyit.maid_useful_task.util.RotUtil;
|
||||||
|
import studio.fantasyit.maid_useful_task.vehicle.AbstractMaidControllableVehicle;
|
||||||
|
import studio.fantasyit.maid_useful_task.vehicle.MaidVehicleControlType;
|
||||||
|
|
||||||
|
public class VehicleBroom extends AbstractMaidControllableVehicle {
|
||||||
|
@Override
|
||||||
|
public boolean isMaidOnThisVehicle(EntityMaid maid) {
|
||||||
|
return maid.getVehicle() instanceof EntityBroom;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void maidControlVehicle(EntityMaid maid, MaidVehicleControlType type, BlockPos target) {
|
||||||
|
if (maid.level().isClientSide) return;
|
||||||
|
if (maid.getVehicle() instanceof EntityBroom vehicle) {
|
||||||
|
if (type == MaidVehicleControlType.NONE) {
|
||||||
|
BroomControlParamStore.removeControlParam(maid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
double xzDistance = maid.distanceToSqr(target.getX(), maid.getY(), target.getZ());
|
||||||
|
double finalXRot = vehicle.getXRot();
|
||||||
|
double finalYRot = vehicle.getYRot();
|
||||||
|
double finalVertical = 0;
|
||||||
|
double finalForward;
|
||||||
|
if (vehicle.isInWater()) {
|
||||||
|
finalXRot = 0;
|
||||||
|
finalVertical = 0.1;
|
||||||
|
} else if (xzDistance < Math.pow(maid.getY() - maid.level().getSeaLevel(), 2)) {
|
||||||
|
finalXRot = 0;
|
||||||
|
if (maid.getY() - maid.level().getSeaLevel() < 50 || vehicle.onGround()) {
|
||||||
|
finalXRot = 5;
|
||||||
|
finalVertical = -0.2;
|
||||||
|
} else {
|
||||||
|
finalXRot = 50;
|
||||||
|
finalVertical = -0.35;
|
||||||
|
}
|
||||||
|
} else if (maid.getY() < 100) {
|
||||||
|
finalXRot = -50;
|
||||||
|
finalVertical = 0.2;
|
||||||
|
} else if (maid.getY() > 160) {
|
||||||
|
finalXRot = 0;
|
||||||
|
finalVertical = -0.1;
|
||||||
|
} else {
|
||||||
|
finalXRot = 0;
|
||||||
|
finalVertical = 0.05;
|
||||||
|
}
|
||||||
|
|
||||||
|
finalYRot = RotUtil.getYRot(maid.position(), target.getCenter());
|
||||||
|
|
||||||
|
finalForward = type == MaidVehicleControlType.FULL ? 3.0 : 0;
|
||||||
|
if (xzDistance < 5 * 5)
|
||||||
|
finalForward = 0;
|
||||||
|
|
||||||
|
BroomControlParamStore.setControlParam(maid, new BroomControlParamStore.BroomControlParam((float) finalXRot, (float) finalYRot, (float) finalVertical, (float) finalForward, type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void maidStopControlVehicle(EntityMaid maid) {
|
||||||
|
BroomControlParamStore.removeControlParam(maid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void syncVehicleParameter(EntityMaid maid, CompoundTag tag) {
|
||||||
|
BroomControlParamStore.BroomControlParam broomControlParam = BroomControlParamStore.BroomControlParam.fromNbt(tag);
|
||||||
|
BroomControlParamStore.setControlParam(maid, broomControlParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable CompoundTag getSyncVehicleParameter(EntityMaid maid) {
|
||||||
|
return BroomControlParamStore.getControlParam(maid).toNbt();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1,3 @@
|
|||||||
public net.minecraft.world.level.BlockGetter m_151361_(Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec3;Ljava/lang/Object;Ljava/util/function/BiFunction;Ljava/util/function/Function;)Ljava/lang/Object;
|
public net.minecraft.world.level.BlockGetter m_151361_(Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec3;Ljava/lang/Object;Ljava/util/function/BiFunction;Ljava/util/function/Function;)Ljava/lang/Object;
|
||||||
|
public-f net.minecraft.world.entity.player.Player inventory
|
||||||
|
public net.minecraft.world.entity.Entity m_19915_(FF)V
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
# This is an example mods.toml file. It contains the data relating to the loading mods.
|
|
||||||
# There are several mandatory fields (#mandatory), and many more that are optional (#optional).
|
|
||||||
# The overall format is standard TOML format, v0.5.0.
|
|
||||||
# Note that there are a couple of TOML lists in this file.
|
|
||||||
# Find more information on toml format here: https://github.com/toml-lang/toml
|
|
||||||
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
|
|
||||||
modLoader="javafml" #mandatory
|
|
||||||
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version
|
|
||||||
loaderVersion="${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
|
|
||||||
# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
|
|
||||||
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
|
|
||||||
license="${mod_license}"
|
|
||||||
# A URL to refer people to when problems occur with this mod
|
|
||||||
#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional
|
|
||||||
# If your mod is purely client-side and has no multiplayer functionality (be it dedicated servers or Open to LAN),
|
|
||||||
# set this to true, and Forge will set the correct displayTest for you and skip loading your mod on dedicated servers.
|
|
||||||
#clientSideOnly=true #optional - defaults to false if absent
|
|
||||||
# A list of mods - how many allowed here is determined by the individual mod loader
|
|
||||||
[[mods]] #mandatory
|
|
||||||
# The modid of the mod
|
|
||||||
modId="${mod_id}" #mandatory
|
|
||||||
# The version number of the mod
|
|
||||||
version="${mod_version}" #mandatory
|
|
||||||
# A display name for the mod
|
|
||||||
displayName="${mod_name}" #mandatory
|
|
||||||
# A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/
|
|
||||||
#updateJSONURL="https://change.me.example.invalid/updates.json" #optional
|
|
||||||
# A URL for the "homepage" for this mod, displayed in the mod UI
|
|
||||||
#displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional
|
|
||||||
# A file name (in the root of the mod JAR) containing a logo for display
|
|
||||||
#logoFile="maid_useful_task.png" #optional
|
|
||||||
# A text field displayed in the mod UI
|
|
||||||
#credits="Thanks for this example mod goes to Java" #optional
|
|
||||||
# A text field displayed in the mod UI
|
|
||||||
authors="${mod_authors}" #optional
|
|
||||||
# Display Test controls the display for your mod in the server connection screen
|
|
||||||
# MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod.
|
|
||||||
# IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod.
|
|
||||||
# IGNORE_ALL_VERSION means that your mod will not cause a red X if it's present on the client or the server. This is a special case and should only be used if your mod has no server component.
|
|
||||||
# NONE means that no display test is set on your mod. You need to do this yourself, see IExtensionPoint.DisplayTest for more information. You can define any scheme you wish with this value.
|
|
||||||
# IMPORTANT NOTE: this is NOT an instruction as to which environments (CLIENT or DEDICATED SERVER) your mod loads on. Your mod should load (and maybe do nothing!) whereever it finds itself.
|
|
||||||
#displayTest="MATCH_VERSION" # if nothing is specified, MATCH_VERSION is the default when clientSideOnly=false, otherwise IGNORE_ALL_VERSION when clientSideOnly=true (#optional)
|
|
||||||
|
|
||||||
# The description text for the mod (multi line!) (#mandatory)
|
|
||||||
description='''${mod_description}'''
|
|
||||||
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
|
|
||||||
[[dependencies."${mod_id}"]] #optional
|
|
||||||
# the modid of the dependency
|
|
||||||
modId="forge" #mandatory
|
|
||||||
# Does this dependency have to exist - if not, ordering below must be specified
|
|
||||||
mandatory=true #mandatory
|
|
||||||
# The version range of the dependency
|
|
||||||
versionRange="${forge_version_range}" #mandatory
|
|
||||||
# An ordering relationship for the dependency - BEFORE or AFTER required if the dependency is not mandatory
|
|
||||||
# BEFORE - This mod is loaded BEFORE the dependency
|
|
||||||
# AFTER - This mod is loaded AFTER the dependency
|
|
||||||
ordering="NONE"
|
|
||||||
# Side this dependency is applied on - BOTH, CLIENT, or SERVER
|
|
||||||
side="BOTH"# Here's another dependency
|
|
||||||
[[dependencies."${mod_id}"]]
|
|
||||||
modId="minecraft"
|
|
||||||
mandatory=true
|
|
||||||
# This version range declares a minimum of the current minecraft version up to but not including the next major version
|
|
||||||
versionRange="${minecraft_version_range}"
|
|
||||||
ordering="NONE"
|
|
||||||
side="BOTH"
|
|
||||||
@@ -1,3 +1,19 @@
|
|||||||
{
|
{
|
||||||
"task.maid_useful_task.maid_tree": "Logging"
|
"task.maid_useful_task.maid_tree": "Logging",
|
||||||
|
"task.maid_useful_task.maid_tree.desc": "The maid will cut down the logs around her and plant saplings.",
|
||||||
|
"task.maid_useful_task.locate": "Locate",
|
||||||
|
"task.maid_useful_task.locate.desc": "The maid can locate the some structure or your home with specific items.",
|
||||||
|
"task.maid_useful_task.revive_player": "Revive Player",
|
||||||
|
"task.maid_useful_task.revive_player.desc": "The maid will revive nearby bleeding player.",
|
||||||
|
"key.maid_useful_tasks.switch_vehicle_control": "Switch Vehicle Control Mode",
|
||||||
|
"maid_useful_task.allow_handle_vehicle.none": "Not allowing maid control vehicle",
|
||||||
|
"maid_useful_task.allow_handle_vehicle.rot_only": "Allow maid control rotation only",
|
||||||
|
"maid_useful_task.allow_handle_vehicle.full": "Allow maid control vehicle",
|
||||||
|
"key.maid_useful_tasks.categories.main": "Maid Useful Tasks",
|
||||||
|
"gui.maid_useful_task.logging.plant": "Plant Saplings",
|
||||||
|
"gui.maid_useful_task.no": "No",
|
||||||
|
"gui.maid_useful_task.yes": "Yes",
|
||||||
|
"gui.maid_useful_task.revive.ownerOnly": "Only revive owner",
|
||||||
|
"gui.maid_useful_task.logging.block_up": "Block Up",
|
||||||
|
"gui.maid_useful_task.logging.skip_non_nature": "Skip Non-nature Logs"
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,19 @@
|
|||||||
{
|
{
|
||||||
"task.maid_useful_task.maid_tree": "伐木"
|
"task.maid_useful_task.maid_tree": "伐木",
|
||||||
|
"task.maid_useful_task.maid_tree.desc": "女仆会砍伐身边的原木并种下树苗",
|
||||||
|
"task.maid_useful_task.locate": "定位",
|
||||||
|
"task.maid_useful_task.locate.desc": "女仆会根据手持物品定位指定的结构或你的出生点",
|
||||||
|
"task.maid_useful_task.revive_player": "救援玩家",
|
||||||
|
"task.maid_useful_task.revive_player.desc": "女仆会救援附近倒地的玩家",
|
||||||
|
"key.maid_useful_tasks.switch_vehicle_control": "切换载具控制模式",
|
||||||
|
"maid_useful_task.allow_handle_vehicle.none": "不允许女仆控制载具",
|
||||||
|
"maid_useful_task.allow_handle_vehicle.rot_only": "只允许女仆控制旋转",
|
||||||
|
"maid_useful_task.allow_handle_vehicle.full": "允许女仆控制载具",
|
||||||
|
"key.maid_useful_tasks.categories.main": "女仆实用任务",
|
||||||
|
"gui.maid_useful_task.logging.plant": "种植树苗",
|
||||||
|
"gui.maid_useful_task.no": "否",
|
||||||
|
"gui.maid_useful_task.yes": "是",
|
||||||
|
"gui.maid_useful_task.revive.ownerOnly": "只救援主人",
|
||||||
|
"gui.maid_useful_task.logging.block_up": "上搭方块",
|
||||||
|
"gui.maid_useful_task.logging.skip_non_nature": "跳过非自然原木"
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"refmap": "maid_useful_task.refmap.json",
|
"refmap": "maid_useful_task.refmap.json",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
"FollowMaidMixin",
|
||||||
"MaidCheckPickupItem",
|
"MaidCheckPickupItem",
|
||||||
"MaidMoveControlMixin",
|
"MaidMoveControlMixin",
|
||||||
"MaidRunOneMixin"
|
"MaidRunOneMixin"
|
||||||
|
|||||||
92
src/main/templates/META-INF/neoforge.mods.toml
Normal file
92
src/main/templates/META-INF/neoforge.mods.toml
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
modLoader="javafml" #mandatory
|
||||||
|
|
||||||
|
# A version range to match for said mod loader - for regular FML @Mod it will be the FML version. This is currently 2.
|
||||||
|
loaderVersion="${loader_version_range}" #mandatory
|
||||||
|
|
||||||
|
# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
|
||||||
|
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
|
||||||
|
license="${mod_license}"
|
||||||
|
|
||||||
|
# A URL to refer people to when problems occur with this mod
|
||||||
|
#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional
|
||||||
|
|
||||||
|
# A list of mods - how many allowed here is determined by the individual mod loader
|
||||||
|
[[mods]] #mandatory
|
||||||
|
|
||||||
|
# The modid of the mod
|
||||||
|
modId="${mod_id}" #mandatory
|
||||||
|
|
||||||
|
# The version number of the mod
|
||||||
|
version="${mod_version}" #mandatory
|
||||||
|
|
||||||
|
# A display name for the mod
|
||||||
|
displayName="${mod_name}" #mandatory
|
||||||
|
|
||||||
|
# A URL to query for updates for this mod. See the JSON update specification https://docs.neoforged.net/docs/misc/updatechecker/
|
||||||
|
#updateJSONURL="https://change.me.example.invalid/updates.json" #optional
|
||||||
|
|
||||||
|
# A URL for the "homepage" for this mod, displayed in the mod UI
|
||||||
|
#displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional
|
||||||
|
|
||||||
|
# A file name (in the root of the mod JAR) containing a logo for display
|
||||||
|
#logoFile="examplemod.png" #optional
|
||||||
|
|
||||||
|
# A text field displayed in the mod UI
|
||||||
|
#credits="" #optional
|
||||||
|
|
||||||
|
# A text field displayed in the mod UI
|
||||||
|
authors="${mod_authors}" #optional
|
||||||
|
|
||||||
|
# The description text for the mod (multi line!) (#mandatory)
|
||||||
|
description='''${mod_description}'''
|
||||||
|
|
||||||
|
# The [[mixins]] block allows you to declare your mixin config to FML so that it gets loaded.
|
||||||
|
[[mixins]]
|
||||||
|
config="${mod_id}.mixins.json"
|
||||||
|
|
||||||
|
# The [[accessTransformers]] block allows you to declare where your AT file is.
|
||||||
|
# If this block is omitted, a fallback attempt will be made to load an AT from META-INF/accesstransformer.cfg
|
||||||
|
[[accessTransformers]]
|
||||||
|
file="META-INF/accesstransformer.cfg"
|
||||||
|
|
||||||
|
# The coremods config file path is not configurable and is always loaded from META-INF/coremods.json
|
||||||
|
|
||||||
|
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
|
||||||
|
[[dependencies.${mod_id}]] #optional
|
||||||
|
# the modid of the dependency
|
||||||
|
modId="neoforge" #mandatory
|
||||||
|
# The type of the dependency. Can be one of "required", "optional", "incompatible" or "discouraged" (case insensitive).
|
||||||
|
# 'required' requires the mod to exist, 'optional' does not
|
||||||
|
# 'incompatible' will prevent the game from loading when the mod exists, and 'discouraged' will show a warning
|
||||||
|
type="required" #mandatory
|
||||||
|
# Optional field describing why the dependency is required or why it is incompatible
|
||||||
|
# reason="..."
|
||||||
|
# The version range of the dependency
|
||||||
|
versionRange="${neo_version_range}" #mandatory
|
||||||
|
# An ordering relationship for the dependency.
|
||||||
|
# BEFORE - This mod is loaded BEFORE the dependency
|
||||||
|
# AFTER - This mod is loaded AFTER the dependency
|
||||||
|
ordering="NONE"
|
||||||
|
# Side this dependency is applied on - BOTH, CLIENT, or SERVER
|
||||||
|
side="BOTH"
|
||||||
|
|
||||||
|
# Here's another dependency
|
||||||
|
[[dependencies."${mod_id}"]]
|
||||||
|
modId="minecraft"
|
||||||
|
type="required" #mandatory
|
||||||
|
# This version range declares a minimum of the current minecraft version up to but not including the next major version
|
||||||
|
versionRange="${minecraft_version_range}"
|
||||||
|
ordering="NONE"
|
||||||
|
side="BOTH"
|
||||||
|
[[dependencies."${mod_id}"]]
|
||||||
|
modId="touhou_little_maid"
|
||||||
|
type="required" #mandatory
|
||||||
|
versionRange="[1.3.7,)"
|
||||||
|
ordering="AFTER"
|
||||||
|
side="BOTH"
|
||||||
|
[[dependencies."${mod_id}"]]
|
||||||
|
modId="playerrevive"
|
||||||
|
type="optional" #mandatory
|
||||||
|
versionRange="[2.0.16,)"
|
||||||
|
ordering="AFTER"
|
||||||
|
side="BOTH"
|
||||||
Reference in New Issue
Block a user