Farm
This commit is contained in:
commit
54b9256d74
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/dist
|
4
.idea/.gitignore
generated
vendored
Normal file
4
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
./dist/
|
||||||
|
/workspace.xml
|
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
@ -0,0 +1 @@
|
|||||||
|
endstone-liko-farm
|
10
.idea/endstone-liko-farm.iml
generated
Normal file
10
.idea/endstone-liko-farm.iml
generated
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.12" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/endstone-farm.iml" filepath="$PROJECT_DIR$/.idea/endstone-farm.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
11
pyproject.toml
Normal file
11
pyproject.toml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "endstone-liko-farm"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "优秀的农场主!"
|
||||||
|
|
||||||
|
[project.entry-points."endstone"]
|
||||||
|
liko-farm = "endstone_liko_farm:LikoFarm"
|
4
src/endstone_liko_farm/__init__.py
Normal file
4
src/endstone_liko_farm/__init__.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
from endstone_liko_farm.liko_farm import LikoFarm
|
||||||
|
|
||||||
|
__all__ = ["LikoFarm"]
|
60
src/endstone_liko_farm/liko_farm.py
Normal file
60
src/endstone_liko_farm/liko_farm.py
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
from endstone.plugin import Plugin
|
||||||
|
from endstone import ColorFormat
|
||||||
|
from endstone.command import CommandSenderWrapper
|
||||||
|
from endstone.event import event_handler, PlayerInteractEvent
|
||||||
|
class LikoFarm(Plugin):
|
||||||
|
api_version = "0.5"
|
||||||
|
|
||||||
|
def on_load(self) -> None:
|
||||||
|
self.logger.info(f"{ColorFormat.GREEN}优秀的农场主加载成功!{ColorFormat.RESET}右击农作物即可采集")
|
||||||
|
|
||||||
|
def on_enable(self):
|
||||||
|
self.register_events(self)
|
||||||
|
|
||||||
|
@event_handler
|
||||||
|
def PlayerInteractEvent(self, event: PlayerInteractEvent):
|
||||||
|
block = event.block
|
||||||
|
player = event.player
|
||||||
|
if event.has_block:
|
||||||
|
# 检查block类型是否为wheat
|
||||||
|
growth_crops = {
|
||||||
|
"minecraft:wheat": {"growth": 7},
|
||||||
|
"minecraft:carrots": {"growth": 7},
|
||||||
|
"minecraft:potatoes": {"growth": 7},
|
||||||
|
"minecraft:beetroot": {"growth": 7}
|
||||||
|
}
|
||||||
|
age_crops = {
|
||||||
|
"minecraft:nether_wart": {"age": 3},
|
||||||
|
"minecraft:cocoa":{"age": 2}
|
||||||
|
}
|
||||||
|
# 遍历作物字典,检查当前方块是否符合条件
|
||||||
|
for crop_type, details in growth_crops.items():
|
||||||
|
if block.type == crop_type:
|
||||||
|
block_states = block.data.block_states
|
||||||
|
growth = block_states.get("growth", None)
|
||||||
|
|
||||||
|
if growth == details["growth"]:
|
||||||
|
# 构造破坏命令
|
||||||
|
command = f"execute as \"{player.name}\" at @s run setblock {block.x} {block.y} {block.z} {crop_type}[\"growth\"=0] destroy"
|
||||||
|
try:
|
||||||
|
self.server.dispatch_command(CommandSenderWrapper(self.server.command_sender), command)
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error(f"无法执行命令: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
for crop_type, details in age_crops.items():
|
||||||
|
if block.type == crop_type:
|
||||||
|
block_states = block.data.block_states
|
||||||
|
age = block_states.get("age", None)
|
||||||
|
|
||||||
|
if age == details["age"]:
|
||||||
|
# 构造破坏命令
|
||||||
|
if block.type == "minecraft:cocoa":
|
||||||
|
command = f"execute as \"{player.name}\" at @s run setblock {block.x} {block.y} {block.z} {crop_type}[\"direction\"={block_states.get("direction", None)}] destroy"
|
||||||
|
else:
|
||||||
|
command = f"execute as \"{player.name}\" at @s run setblock {block.x} {block.y} {block.z} {crop_type} destroy"
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.server.dispatch_command(CommandSenderWrapper(self.server.command_sender), command)
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error(f"无法执行命令: {e}")
|
Loading…
x
Reference in New Issue
Block a user