mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2026-01-04 15:41:46 +00:00
Fix interacting furniture
This commit is contained in:
@@ -331,6 +331,30 @@ public class WateringCanItem extends AbstractCustomCropsItem {
|
|||||||
return InteractionResult.COMPLETE;
|
return InteractionResult.COMPLETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check the clicked block/furniture
|
||||||
|
for (FillMethod method : wateringCanConfig.fillMethods()) {
|
||||||
|
if (method.getID().equals(targetBlockID)) {
|
||||||
|
if (method.checkRequirements(context)) {
|
||||||
|
if (waterInCan >= wateringCanConfig.storage()) {
|
||||||
|
ActionManager.trigger(context, wateringCanConfig.fullActions());
|
||||||
|
return InteractionResult.COMPLETE;
|
||||||
|
}
|
||||||
|
WateringCanFillEvent fillEvent = new WateringCanFillEvent(player, event.hand(), itemInHand, event.location(), wateringCanConfig, method);
|
||||||
|
if (EventUtils.fireAndCheckCancel(fillEvent))
|
||||||
|
return InteractionResult.COMPLETE;
|
||||||
|
int current = Math.min(waterInCan + method.amountOfWater(), wateringCanConfig.storage());
|
||||||
|
context.arg(ContextKeys.WATER_BAR, Optional.ofNullable(wateringCanConfig.waterBar()).map(bar -> bar.getWaterBar(current, wateringCanConfig.storage())).orElse(""));
|
||||||
|
context.arg(ContextKeys.STORAGE, wateringCanConfig.storage());
|
||||||
|
context.arg(ContextKeys.CURRENT_WATER, current);
|
||||||
|
setCurrentWater(itemInHand, wateringCanConfig, waterInCan + method.amountOfWater(), context);
|
||||||
|
method.triggerActions(context);
|
||||||
|
ActionManager.trigger(context, wateringCanConfig.addWaterActions());
|
||||||
|
}
|
||||||
|
return InteractionResult.COMPLETE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// the clicked block might be a block underwater, so we do raytracing to get the water (nearest fluid)
|
||||||
RayTraceResult result = player.getWorld().rayTraceBlocks(player.getEyeLocation(), player.getLocation().getDirection(), 5, FluidCollisionMode.ALWAYS);
|
RayTraceResult result = player.getWorld().rayTraceBlocks(player.getEyeLocation(), player.getLocation().getDirection(), 5, FluidCollisionMode.ALWAYS);
|
||||||
if (result == null)
|
if (result == null)
|
||||||
return InteractionResult.COMPLETE;
|
return InteractionResult.COMPLETE;
|
||||||
@@ -366,7 +390,8 @@ public class WateringCanItem extends AbstractCustomCropsItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// give it another try
|
// give it the last try, this time we don't use blockstate
|
||||||
|
// instead we use Bukkit Material Enum Names
|
||||||
if (targetBlock.getBlockData() instanceof Waterlogged waterlogged && waterlogged.isWaterlogged()) {
|
if (targetBlock.getBlockData() instanceof Waterlogged waterlogged && waterlogged.isWaterlogged()) {
|
||||||
blockID = "WATER";
|
blockID = "WATER";
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -72,6 +72,12 @@ public interface WorldManager extends Reloadable {
|
|||||||
*/
|
*/
|
||||||
boolean unloadWorld(World world, boolean disabling);
|
boolean unloadWorld(World world, boolean disabling);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if mechanism is enabled for a certain world
|
||||||
|
*
|
||||||
|
* @param world world
|
||||||
|
* @return enabled or not
|
||||||
|
*/
|
||||||
boolean isMechanicEnabled(World world);
|
boolean isMechanicEnabled(World world);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import io.th0rgal.oraxen.api.events.custom_block.stringblock.OraxenStringBlockPl
|
|||||||
import io.th0rgal.oraxen.api.events.furniture.OraxenFurnitureBreakEvent;
|
import io.th0rgal.oraxen.api.events.furniture.OraxenFurnitureBreakEvent;
|
||||||
import io.th0rgal.oraxen.api.events.furniture.OraxenFurnitureInteractEvent;
|
import io.th0rgal.oraxen.api.events.furniture.OraxenFurnitureInteractEvent;
|
||||||
import io.th0rgal.oraxen.api.events.furniture.OraxenFurniturePlaceEvent;
|
import io.th0rgal.oraxen.api.events.furniture.OraxenFurniturePlaceEvent;
|
||||||
|
import io.th0rgal.oraxen.font.Glyph;
|
||||||
import net.momirealms.customcrops.api.core.AbstractCustomEventListener;
|
import net.momirealms.customcrops.api.core.AbstractCustomEventListener;
|
||||||
import net.momirealms.customcrops.api.core.AbstractItemManager;
|
import net.momirealms.customcrops.api.core.AbstractItemManager;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|||||||
Reference in New Issue
Block a user