Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@

package net.minecraftforge.event.entity.player;

import javax.annotation.Nonnull;

import net.minecraftforge.event.entity.living.LivingEvent;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ItemEntity;

/**
* PlayerEvent is fired whenever an event involving Living entities occurs.
Expand Down Expand Up @@ -57,16 +63,6 @@ public PlayerEntity getPlayer() {
return playerEntity;
}

/**
* Called on the server at the end of {@link net.minecraft.server.PlayerManager#onPlayerConnect(net.minecraft.network.ClientConnection, net.minecraft.server.network.ServerPlayerEntity)}
* when the player has finished logging in.
*/
public static class PlayerLoggedInEvent extends PlayerEvent {
public PlayerLoggedInEvent(PlayerEntity player) {
super(player);
}
}

/**
* Fired when an Entity is started to be "tracked" by this player (the player receives updates about this entity, e.g. motion).
*/
Expand Down Expand Up @@ -131,17 +127,125 @@ public boolean isWasDeath() {
}
}

public static class ItemPickupEvent extends PlayerEvent {
/**
* Original EntityItem with current remaining stack size.
*/
private final ItemEntity originalEntity;
/**
* Clone item stack, containing the item and amount picked up.
*/
private final ItemStack stack;

public ItemPickupEvent(PlayerEntity player, ItemEntity entPickedUp, ItemStack stack) {
super(player);
this.originalEntity = entPickedUp;
this.stack = stack;
}

public ItemStack getStack() {
return stack;
}

public ItemEntity getOriginalEntity() {
return originalEntity;
}
}

public static class ItemCraftedEvent extends PlayerEvent {
@Nonnull
private final ItemStack crafting;
private final Inventory craftMatrix;

public ItemCraftedEvent(PlayerEntity player, @Nonnull ItemStack crafting, Inventory craftMatrix) {
super(player);
this.crafting = crafting;
this.craftMatrix = craftMatrix;
}

@Nonnull
public ItemStack getCrafting() {
return this.crafting;
}

public Inventory getInventory() {
return this.craftMatrix;
}
}

public static class ItemSmeltedEvent extends PlayerEvent {
@Nonnull
private final ItemStack smelting;

public ItemSmeltedEvent(PlayerEntity player, @Nonnull ItemStack crafting) {
super(player);
this.smelting = crafting;
}

@Nonnull
public ItemStack getSmelting() {
return this.smelting;
}
}

/**
* Called on the server at the end of {@link net.minecraft.server.PlayerManager#onPlayerConnect(net.minecraft.network.ClientConnection, net.minecraft.server.network.ServerPlayerEntity)}
* when the player has finished logging in.
*/
public static class PlayerLoggedInEvent extends PlayerEvent {
public PlayerLoggedInEvent(PlayerEntity player) {
super(player);
}
}

public static class PlayerLoggedOutEvent extends PlayerEvent {
public PlayerLoggedOutEvent(PlayerEntity player) {
super(player);
}
}

public static class PlayerRespawnEvent extends PlayerEvent {
private final boolean alive;

public PlayerRespawnEvent(PlayerEntity player, boolean alive) {
super(player);
this.alive = alive;
}

/**
* Did this respawn event come from the player conquering the end?
* TODO: Forge should name this to isAlive.
* @return if this respawn was because the player conquered the end
*/
public boolean isEndConquered() {
return this.alive;
}
}

public static class PlayerChangedDimensionEvent extends PlayerEvent {
private final DimensionType fromDim;
private final DimensionType toDim;

public PlayerChangedDimensionEvent(PlayerEntity player, DimensionType fromDim, DimensionType toDim) {
super(player);
this.fromDim = fromDim;
this.toDim = toDim;
}

public DimensionType getFrom() {
return this.fromDim;
}

public DimensionType getTo() {
return this.toDim;
}
}

/*TODO Events:
HarvestCheck
BreakSpeed
NameFormat
LoadFromFile
SaveToFile
Visibility
ItemPickupEvent
ItemCraftedEvent
ItemSmeltedEvent
PlayerLoggedOutEvent
PlayerRespawnEvent
PlayerChangedDimensionEvent*/
Visibility called by ForgeHooks.getPlayerVisibilityDistance, but latter is not called elsewhere*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerFlyableFallEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.Event;
Expand Down Expand Up @@ -98,11 +97,6 @@ public static void onEnteringChunk(Entity entity, int newChunkX, int newChunkZ,
MinecraftForge.EVENT_BUS.post(new EntityEvent.EnteringChunk(entity, newChunkX, newChunkZ, oldChunkX, oldChunkZ));
}

// PlayerEvents
public static void onPlayerLoggedIn(PlayerEntity playerEntity) {
MinecraftForge.EVENT_BUS.post(new PlayerEvent.PlayerLoggedInEvent(playerEntity));
}

public static boolean onLivingAttack(LivingEntity entity, DamageSource src, float damage) {
return MinecraftForge.EVENT_BUS.post(new LivingAttackEvent(entity, src, damage));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Minecraft Forge, Patchwork Project
* Copyright (c) 2016-2020, 2019-2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.patchworkmc.impl.event.entity;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerEvent;

import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.dimension.DimensionType;

public class PlayerEvents {
public static void firePlayerChangedDimensionEvent(PlayerEntity player, DimensionType fromDim, DimensionType toDim) {
MinecraftForge.EVENT_BUS.post(new PlayerEvent.PlayerChangedDimensionEvent(player, fromDim, toDim));
}

public static void firePlayerLoggedIn(PlayerEntity player) {
MinecraftForge.EVENT_BUS.post(new PlayerEvent.PlayerLoggedInEvent(player));
}

public static void firePlayerLoggedOut(PlayerEntity player) {
MinecraftForge.EVENT_BUS.post(new PlayerEvent.PlayerLoggedOutEvent(player));
}

public static void firePlayerRespawnEvent(PlayerEntity player, boolean alive) {
MinecraftForge.EVENT_BUS.post(new PlayerEvent.PlayerRespawnEvent(player, alive));
}

public static void firePlayerItemPickupEvent(PlayerEntity player, ItemEntity item, ItemStack clone) {
MinecraftForge.EVENT_BUS.post(new PlayerEvent.ItemPickupEvent(player, item, clone));
}

public static void firePlayerCraftingEvent(PlayerEntity player, ItemStack crafted, Inventory craftMatrix) {
MinecraftForge.EVENT_BUS.post(new PlayerEvent.ItemCraftedEvent(player, crafted, craftMatrix));
}

public static void firePlayerSmeltedEvent(PlayerEntity player, ItemStack smelted) {
MinecraftForge.EVENT_BUS.post(new PlayerEvent.ItemSmeltedEvent(player, smelted));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Minecraft Forge, Patchwork Project
* Copyright (c) 2016-2020, 2019-2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.patchworkmc.mixin.event.entity;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.At.Shift;

import net.minecraft.container.CraftingResultSlot;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.ItemStack;

import net.patchworkmc.impl.event.entity.PlayerEvents;

@Mixin(CraftingResultSlot.class)
public abstract class MixinCraftingResultSlot {
@Shadow
@Final
private PlayerEntity player;

@Shadow
@Final
private CraftingInventory craftingInv;

@Inject(method = "onCrafted(Lnet/minecraft/item/ItemStack;)V",
at = @At(
value = "INVOKE",
shift = Shift.AFTER,
ordinal = 0,
target = "net/minecraft/item/ItemStack.onCraft(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;I)V"
)
)
private void onStackCrafted(ItemStack stack, CallbackInfo ci) {
PlayerEvents.firePlayerCraftingEvent(player, stack, craftingInv);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Minecraft Forge, Patchwork Project
* Copyright (c) 2016-2020, 2019-2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.patchworkmc.mixin.event.entity;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.container.FurnaceOutputSlot;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;

import net.patchworkmc.impl.event.entity.PlayerEvents;

@Mixin(FurnaceOutputSlot.class)
public abstract class MixinFurnaceOutputSlot {
@Shadow
@Final
private PlayerEntity player;

@Inject(method = "onCrafted(Lnet/minecraft/item/ItemStack;)V",
at = @At("RETURN")
)
private void onCraftingFinished(ItemStack stack, CallbackInfo ci) {
PlayerEvents.firePlayerSmeltedEvent(player, stack);
}
}
Loading