Skip to content

Commit

Permalink
event
Browse files Browse the repository at this point in the history
  • Loading branch information
17183248569 committed Oct 17, 2023
1 parent 19ca5a2 commit b1cc482
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/carpet/mixins/ServerPlayer_scarpetEventMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import carpet.fakes.EntityInterface;
import carpet.fakes.ServerPlayerInterface;
import carpet.script.CarpetEventServer;
import carpet.script.EntityEventsGroup;

import com.mojang.authlib.GameProfile;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.stats.Stat;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
Expand Down Expand Up @@ -45,6 +48,14 @@ public ServerPlayer_scarpetEventMixin(Level level, BlockPos blockPos, float f, G

@Shadow public boolean wonGame;

@Inject(method = "openMenu", at = @At("RETURN"))
private void grabStat(MenuProvider menuProvider, CallbackInfoReturnable<java.util.OptionalInt> cir)
{
if (cir.getReturnValue().isPresent()) {
CarpetEventServer.Event.PLAYER_OPEN_SCREEN.onPlayerEvent((ServerPlayer)(Object)this);
};
}

@Redirect(method = "completeUsingItem", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/entity/player/Player;completeUsingItem()V"
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/carpet/script/CarpetEventServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,17 @@ public void onSlotSwitch(ServerPlayer player, int from, int to)
), player::createCommandSourceStack);
}
};
public static final Event PLAYER_OPEN_SCREEN = new Event("player_open_screen", 1, false)
{
@Override
public boolean onPlayerEvent(ServerPlayer player)
{
return handler.call(() ->
Arrays.asList(
new EntityValue(player)
), player::createCommandSourceStack);
}
};
public static final Event PLAYER_SWAPS_HANDS = new Event("player_swaps_hands", 1, false)
{
@Override
Expand Down

0 comments on commit b1cc482

Please sign in to comment.