mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-19 15:09:25 +00:00
Added CraftEngine Support
This commit is contained in:
25
compatibility-craftengine-r1/build.gradle.kts
Normal file
25
compatibility-craftengine-r1/build.gradle.kts
Normal file
@@ -0,0 +1,25 @@
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
maven("https://repo.momirealms.net/releases/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":api"))
|
||||
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
|
||||
compileOnly("net.momirealms:craft-engine-core:0.0.16")
|
||||
compileOnly("net.momirealms:craft-engine-bukkit:0.0.16")
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
options.encoding = "UTF-8"
|
||||
options.release.set(21)
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_21
|
||||
targetCompatibility = JavaVersion.VERSION_21
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (C) <2024> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customcrops.bukkit.integration.custom.craftengine_r1;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.api.event.*;
|
||||
import net.momirealms.craftengine.core.entity.player.InteractionHand;
|
||||
import net.momirealms.customcrops.api.core.AbstractCustomEventListener;
|
||||
import net.momirealms.customcrops.api.core.AbstractItemManager;
|
||||
import net.momirealms.customcrops.api.util.DummyCancellable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
|
||||
public class CraftEngineListener extends AbstractCustomEventListener {
|
||||
|
||||
public CraftEngineListener(AbstractItemManager itemManager) {
|
||||
super(itemManager);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInteractFurniture(FurnitureInteractEvent event) {
|
||||
EquipmentSlot slot = event.hand() == InteractionHand.MAIN_HAND ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND;
|
||||
itemManager.handlePlayerInteractFurniture(
|
||||
event.getPlayer(),
|
||||
event.furniture().location(),
|
||||
event.furniture().furnitureId().toString(),
|
||||
slot,
|
||||
event.getPlayer().getInventory().getItem(slot),
|
||||
event
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInteractCustomBlock(CustomBlockInteractEvent event) {
|
||||
EquipmentSlot slot = event.hand() == InteractionHand.MAIN_HAND ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND;
|
||||
itemManager.handlePlayerInteractBlock(
|
||||
event.getPlayer(),
|
||||
event.location().getBlock(),
|
||||
event.customBlock().id().toString(),
|
||||
event.clickedFace(),
|
||||
slot,
|
||||
event.getPlayer().getInventory().getItem(slot),
|
||||
event
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBreakFurniture(FurnitureBreakEvent event) {
|
||||
itemManager.handlePlayerBreak(
|
||||
event.getPlayer(),
|
||||
event.furniture().baseEntity().getLocation(),
|
||||
event.getPlayer().getInventory().getItemInMainHand(),
|
||||
event.furniture().furnitureId().toString(),
|
||||
event
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBreakCustomBlock(CustomBlockBreakEvent event) {
|
||||
itemManager.handlePlayerBreak(
|
||||
event.getPlayer(),
|
||||
event.bukkitBlock().getLocation(),
|
||||
event.getPlayer().getInventory().getItemInMainHand(),
|
||||
event.customBlock().id().toString(),
|
||||
event
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlaceCustomBlock(CustomBlockAttemptPlaceEvent event) {
|
||||
EquipmentSlot slot = event.hand() == InteractionHand.MAIN_HAND ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND;
|
||||
itemManager.handlePlayerPlace(
|
||||
event.getPlayer(),
|
||||
event.location(),
|
||||
event.customBlock().id().toString(),
|
||||
slot,
|
||||
event.getPlayer().getInventory().getItem(slot),
|
||||
event
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlaceFurniture(FurnitureAttemptPlaceEvent event) {
|
||||
EquipmentSlot slot = event.hand() == InteractionHand.MAIN_HAND ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND;
|
||||
Player player = event.getPlayer();
|
||||
itemManager.handlePlayerPlace(
|
||||
player,
|
||||
event.location(),
|
||||
event.furniture().id().toString(),
|
||||
slot,
|
||||
event.getPlayer().getInventory().getItem(slot),
|
||||
new DummyCancellable()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) <2024> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customcrops.bukkit.integration.custom.craftengine_r1;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.api.CraftEngineBlocks;
|
||||
import net.momirealms.craftengine.bukkit.api.CraftEngineFurniture;
|
||||
import net.momirealms.craftengine.bukkit.api.CraftEngineItems;
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.LoadedFurniture;
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.entity.furniture.AnchorType;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.libraries.nbt.CompoundTag;
|
||||
import net.momirealms.customcrops.api.core.CustomItemProvider;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class CraftEngineProvider implements CustomItemProvider {
|
||||
|
||||
@Override
|
||||
public boolean removeCustomBlock(Location location) {
|
||||
return CraftEngineBlocks.remove(location.getBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeCustomBlock(Location location, String id) {
|
||||
return CraftEngineBlocks.place(location, Key.of(id), new CompoundTag(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Entity placeFurniture(Location location, String id) {
|
||||
LoadedFurniture furniture = CraftEngineFurniture.place(location, Key.of(id), AnchorType.GROUND);
|
||||
if (furniture == null) return null;
|
||||
return furniture.baseEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFurniture(Entity entity) {
|
||||
return CraftEngineFurniture.remove(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String blockID(Block block) {
|
||||
ImmutableBlockState state = CraftEngineBlocks.getCustomBlockState(block);
|
||||
if (state == null) return null;
|
||||
return state.owner().value().id().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String itemID(ItemStack itemStack) {
|
||||
return Optional.ofNullable(CraftEngineItems.getCustomItemId(itemStack)).map(Key::toString).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ItemStack itemStack(Player player, String id) {
|
||||
return Optional.ofNullable(CraftEngineItems.byId(Key.of(id)))
|
||||
.map(it -> it.buildItemStack(null))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String furnitureID(Entity entity) {
|
||||
return Optional.ofNullable(CraftEngineFurniture.getLoadedFurnitureByBaseEntity(entity))
|
||||
.map(it -> it.furnitureId().toString())
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFurniture(Entity entity) {
|
||||
return CraftEngineFurniture.isFurniture(entity);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import dev.lone.itemsadder.api.CustomFurniture;
|
||||
import dev.lone.itemsadder.api.CustomStack;
|
||||
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.core.CustomItemProvider;
|
||||
import net.momirealms.customcrops.api.util.LocationUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -54,7 +55,7 @@ public class ItemsAdderProvider implements CustomItemProvider {
|
||||
@Override
|
||||
public Entity placeFurniture(Location location, String id) {
|
||||
try {
|
||||
CustomFurniture furniture = CustomFurniture.spawnPreciseNonSolid(id, location);
|
||||
CustomFurniture furniture = CustomFurniture.spawnPreciseNonSolid(id, LocationUtils.toSurfaceCenterLocation(location));
|
||||
if (furniture == null) return null;
|
||||
return furniture.getEntity();
|
||||
} catch (RuntimeException e) {
|
||||
|
||||
@@ -23,7 +23,8 @@ public class NexoListener extends AbstractCustomEventListener {
|
||||
private static final Set<Material> IGNORED = new HashSet<>(
|
||||
List.of(
|
||||
Material.NOTE_BLOCK,
|
||||
Material.TRIPWIRE
|
||||
Material.TRIPWIRE,
|
||||
Material.CHORUS_PLANT
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Project settings
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=3.6.29
|
||||
project_version=3.6.30
|
||||
config_version=42
|
||||
project_group=net.momirealms
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class BukkitItemManager extends AbstractItemManager {
|
||||
plugin.getPluginLogger().warn("Failed to load CustomItemProvider", e);
|
||||
}
|
||||
if (this.provider == null) {
|
||||
plugin.getPluginLogger().warn("ItemsAdder/Oraxen/Nexo/MythicCrucible are not installed. You can safely ignore this if you implemented the custom item interface with API.");
|
||||
plugin.getPluginLogger().warn("CraftEngine/ItemsAdder/Oraxen/Nexo/MythicCrucible are not installed. You can safely ignore this if you implemented the custom item interface with API.");
|
||||
}
|
||||
this.factory = BukkitItemFactory.create(plugin);
|
||||
}
|
||||
@@ -139,7 +139,20 @@ public class BukkitItemManager extends AbstractItemManager {
|
||||
}
|
||||
|
||||
private void hookDefaultPlugins() throws ReflectiveOperationException {
|
||||
if (PluginUtils.isEnabled("Oraxen")) {
|
||||
if (PluginUtils.isEnabled("CraftEngine")) {
|
||||
String rVersion = "r1";
|
||||
Class<?> craftEngineProviderClass = Class.forName("net.momirealms.customcrops.bukkit.integration.custom.craftengine_" + rVersion + ".CraftEngineProvider");
|
||||
Constructor<?> craftEngineProviderConstructor = craftEngineProviderClass.getDeclaredConstructor();
|
||||
craftEngineProviderConstructor.setAccessible(true);
|
||||
this.provider = (CustomItemProvider) craftEngineProviderConstructor.newInstance();
|
||||
|
||||
Class<?> craftEngineListenerClass = Class.forName("net.momirealms.customcrops.bukkit.integration.custom.craftengine_" + rVersion + ".CraftEngineListener");
|
||||
Constructor<?> craftEngineListenerConstructor = craftEngineListenerClass.getDeclaredConstructor(AbstractItemManager.class);
|
||||
craftEngineListenerConstructor.setAccessible(true);
|
||||
this.setCustomEventListener((AbstractCustomEventListener) craftEngineListenerConstructor.newInstance(this));
|
||||
|
||||
plugin.getPluginLogger().info("CraftEngine hooked!");
|
||||
} else if (PluginUtils.isEnabled("Oraxen")) {
|
||||
String rVersion;
|
||||
if (PluginUtils.getPluginVersion("Oraxen").startsWith("2")) {
|
||||
rVersion = "r2";
|
||||
|
||||
@@ -7,6 +7,7 @@ authors: [ XiaoMoMi ]
|
||||
folia-supported: true
|
||||
softdepend:
|
||||
- Vault
|
||||
- CraftEngine
|
||||
- ItemsAdder
|
||||
- Oraxen
|
||||
- Nexo
|
||||
|
||||
@@ -7,4 +7,5 @@ include(":compatibility-oraxen-r1")
|
||||
include(":compatibility-oraxen-r2")
|
||||
include(":compatibility-nexo-r1")
|
||||
include(":compatibility-itemsadder-r1")
|
||||
include(":compatibility-crucible-r1")
|
||||
include(":compatibility-crucible-r1")
|
||||
include(":compatibility-craftengine-r1")
|
||||
|
||||
Reference in New Issue
Block a user