use of org.spongepowered.common.bridge.data.VanishableBridge in project SpongeCommon by SpongePowered.
the class PlayerListMixin method impl$onlySendAddPlayerForUnvanishedPlayers.
@Redirect(method = "placeNewPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;send(Lnet/minecraft/network/protocol/Packet;)V"), slice = @Slice(from = @At(value = "INVOKE", target = "Ljava/util/List;size()I", remap = false), to = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addNewPlayer(Lnet/minecraft/server/level/ServerPlayer;)V")))
private void impl$onlySendAddPlayerForUnvanishedPlayers(ServerGamePacketListenerImpl connection, Packet<?> packet) {
ClientboundPlayerInfoPacketAccessor playerInfoPacketAccessor = (ClientboundPlayerInfoPacketAccessor) packet;
// size is always 1
VanishableBridge p = (VanishableBridge) this.playersByUUID.get(playerInfoPacketAccessor.accessor$entries().get(0).getProfile().getId());
// Effectively, don't notify new players of vanished players
if (p.bridge$vanishState().invisible()) {
return;
}
connection.send(packet);
}
use of org.spongepowered.common.bridge.data.VanishableBridge in project SpongeCommon by SpongePowered.
the class VanishableData method register.
// @formatter:off
@SuppressWarnings("unchecked")
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(VanishableBridge.class).create(Keys.IS_INVISIBLE).get(VanishableBridge::bridge$isInvisible).set(VanishableBridge::bridge$setInvisible).create(Keys.VANISH).get(bridge -> bridge.bridge$vanishState().invisible()).setAnd((h, v) -> {
if (h instanceof Entity && ((Entity) h).level.isClientSide) {
return false;
}
h.bridge$vanishState(v ? VanishState.vanished() : VanishState.unvanished());
return true;
}).create(Keys.VANISH_IGNORES_COLLISION).get(b -> b.bridge$vanishState().ignoresCollisions()).setAnd((h, v) -> {
if (h instanceof Entity && ((Entity) h).level.isClientSide) {
return false;
}
if (!h.bridge$vanishState().invisible()) {
return false;
}
h.bridge$vanishState(h.bridge$vanishState().ignoreCollisions(v));
return true;
}).create(Keys.VANISH_PREVENTS_TARGETING).get(b -> b.bridge$vanishState().untargetable()).setAnd((h, v) -> {
if (h instanceof Entity && ((Entity) h).level.isClientSide) {
return false;
}
if (!h.bridge$vanishState().invisible()) {
return false;
}
h.bridge$vanishState(h.bridge$vanishState().untargetable(v));
return true;
}).create(Keys.VANISH_STATE).get(VanishableBridge::bridge$vanishState).setAnd((h, v) -> {
if (h instanceof Entity && ((Entity) h).level.isClientSide) {
return false;
}
h.bridge$vanishState(v);
return true;
});
final ResourceKey dataStoreKey = ResourceKey.sponge("invisibility");
registrator.spongeDataStore(dataStoreKey, VanishableBridge.class, Keys.IS_INVISIBLE, Keys.VANISH_STATE);
SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Sponge.Entity.IS_INVISIBLE, dataStoreKey, Keys.IS_INVISIBLE);
SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Sponge.Entity.IS_VANISHED, dataStoreKey, Keys.VANISH_STATE);
SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Sponge.Entity.VANISH_UNCOLLIDEABLE, dataStoreKey, Keys.VANISH_IGNORES_COLLISION);
SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Sponge.Entity.VANISH_UNTARGETABLE, dataStoreKey, Keys.VANISH_PREVENTS_TARGETING);
}
Aggregations