25 lines
1.7 KiB
Java
25 lines
1.7 KiB
Java
package com.thebrokenrail.scriptcraft.api.bridge;
|
|
|
|
import com.thebrokenrail.scriptcraft.core.ScriptCraftCore;
|
|
import com.thebrokenrail.scriptcraft.core.ValueUtil;
|
|
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
|
|
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
|
import net.fabricmc.fabric.api.event.player.UseItemCallback;
|
|
import net.fabricmc.fabric.api.event.world.WorldTickCallback;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.util.ActionResult;
|
|
import net.minecraft.util.TypedActionResult;
|
|
|
|
class EventBridges {
|
|
static void register() {
|
|
WorldTickCallback.EVENT.register(world -> ScriptCraftCore.useBridge("Event.worldTick", world));
|
|
AttackBlockCallback.EVENT.register((playerEntity, world, hand, blockPos, direction) -> ValueUtil.getEnumValue(ActionResult.class, (String) ScriptCraftCore.useBridge("Event.attackBlock", playerEntity, world, hand.name(), blockPos.getX(), blockPos.getY(), blockPos.getZ(), direction.name()), ActionResult.PASS));
|
|
UseBlockCallback.EVENT.register((playerEntity, world, hand, hitResult) -> ValueUtil.getEnumValue(ActionResult.class, (String) ScriptCraftCore.useBridge("Event.useBlock", playerEntity, world, hand.name(), hitResult.getBlockPos().getX(), hitResult.getBlockPos().getY(), hitResult.getBlockPos().getZ(), hitResult.getSide().name()), ActionResult.PASS));
|
|
UseItemCallback.EVENT.register((playerEntity, world, hand) -> {
|
|
ActionResult result = ValueUtil.getEnumValue(ActionResult.class, (String) ScriptCraftCore.useBridge("Event.useItem", playerEntity, world, hand.name()), ActionResult.PASS);
|
|
ItemStack stack = playerEntity.getStackInHand(hand);
|
|
return new TypedActionResult<>(result, stack);
|
|
});
|
|
}
|
|
}
|