mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
Add way for other mods to indicate that they are fake players (#202)
* Add way for other mods to indicate that they are fake players
* Implement "reasonable default" for fake players and fix inverted logic
Signed-off-by: Max <maxh2709@gmail.com>
Co-authored-by: Max <maxh2709@gmail.com>
(cherry picked from commit 42684fd87a)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is part of architectury.
|
||||
* Copyright (C) 2020, 2021, 2022 architectury
|
||||
*
|
||||
* This program 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; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package dev.architectury.hooks.level.entity.fabric;
|
||||
|
||||
import dev.architectury.event.Event;
|
||||
import dev.architectury.event.EventFactory;
|
||||
import dev.architectury.event.EventResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public interface FakePlayers {
|
||||
Event<FakePlayers> EVENT = EventFactory.createEventResult();
|
||||
|
||||
EventResult isFakePlayer(Player player);
|
||||
}
|
||||
@@ -19,10 +19,17 @@
|
||||
|
||||
package dev.architectury.hooks.level.entity.fabric;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public class PlayerHooksImpl {
|
||||
public static boolean isFake(Player player) {
|
||||
return false;
|
||||
var result = FakePlayers.EVENT.invoker().isFakePlayer(player);
|
||||
if (result.isPresent()) {
|
||||
return result.isTrue();
|
||||
}
|
||||
// If no result has been returned, assume that player classes extending ServerPlayer
|
||||
// (apart from ServerPlayer itself) are fake players, as a "reasonable default"
|
||||
return player instanceof ServerPlayer && player.getClass() != ServerPlayer.class;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user