mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-27 19:47:00 -05:00
Add xp to break block
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id "architect-plugin" version "1.1.15"
|
||||
id "architect-plugin" version "1.1.19"
|
||||
id "org.cadixdev.licenser" version "0.5.0"
|
||||
id "com.jfrog.bintray" version "1.8.4"
|
||||
id "com.matthewprenger.cursegradle" version "1.4.0" apply false
|
||||
|
||||
@@ -18,6 +18,7 @@ package me.shedaniel.architectury.event.events;
|
||||
|
||||
import me.shedaniel.architectury.event.Event;
|
||||
import me.shedaniel.architectury.event.EventFactory;
|
||||
import me.shedaniel.architectury.utils.IntValue;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
@@ -32,6 +33,7 @@ import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface PlayerEvent {
|
||||
Event<PlayerJoin> PLAYER_JOIN = EventFactory.createLoop(PlayerJoin.class);
|
||||
@@ -92,7 +94,7 @@ public interface PlayerEvent {
|
||||
}
|
||||
|
||||
interface BreakBlock {
|
||||
InteractionResult breakBlock(Level world, BlockPos pos, BlockState state, ServerPlayer player);
|
||||
InteractionResult breakBlock(Level world, BlockPos pos, BlockState state, ServerPlayer player, @Nullable IntValue xp);
|
||||
}
|
||||
|
||||
interface OpenMenu {
|
||||
|
||||
@@ -41,7 +41,7 @@ public class MixinServerPlayerGameMode {
|
||||
ordinal = 0),
|
||||
locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
|
||||
private void onBreak(BlockPos blockPos, CallbackInfoReturnable<Boolean> cir, BlockState state) {
|
||||
if (PlayerEvent.BREAK_BLOCK.invoker().breakBlock(this.level, blockPos, state, this.player) == InteractionResult.FAIL) {
|
||||
if (PlayerEvent.BREAK_BLOCK.invoker().breakBlock(this.level, blockPos, state, this.player, null) == InteractionResult.FAIL) {
|
||||
cir.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package me.shedaniel.architectury.event.forge;
|
||||
|
||||
import me.shedaniel.architectury.event.events.*;
|
||||
import me.shedaniel.architectury.utils.IntValue;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
@@ -289,7 +290,17 @@ public class EventHandlerImplCommon {
|
||||
@SubscribeEvent
|
||||
public static void event(BlockEvent.BreakEvent event) {
|
||||
if (event.getPlayer() instanceof ServerPlayerEntity && event.getWorld() instanceof World) {
|
||||
ActionResultType result = PlayerEvent.BREAK_BLOCK.invoker().breakBlock((World) event.getWorld(), event.getPos(), event.getState(), (ServerPlayerEntity) event.getPlayer());
|
||||
ActionResultType result = PlayerEvent.BREAK_BLOCK.invoker().breakBlock((World) event.getWorld(), event.getPos(), event.getState(), (ServerPlayerEntity) event.getPlayer(), new IntValue() {
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
return event.getExpToDrop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(int value) {
|
||||
event.setExpToDrop(value);
|
||||
}
|
||||
});
|
||||
if (result != ActionResultType.PASS) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user