mirror of
https://github.com/FabricMC/fabric.git
synced 2025-07-28 15:09:35 -04:00
Update networking API to 20w46a+, simplify mixin impl (#1245)
This commit is contained in:
parent
27f445e70d
commit
fd9375dd4f
5 changed files with 23 additions and 64 deletions
fabric-networking-api-v1/src/main
java/net/fabricmc/fabric
api/networking/v1
mixin/networking
resources
|
@ -33,8 +33,10 @@ import net.minecraft.util.math.ChunkPos;
|
|||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.chunk.ChunkManager;
|
||||
import net.minecraft.class_5629;
|
||||
|
||||
import net.fabricmc.fabric.impl.networking.ThreadedAnvilChunkStorageTrackingExtensions;
|
||||
import net.fabricmc.fabric.mixin.networking.accessor.EntityTrackerAccessor;
|
||||
import net.fabricmc.fabric.mixin.networking.accessor.ThreadedAnvilChunkStorageAccessor;
|
||||
|
||||
/**
|
||||
* For example, a block entity may use the methods in this class to send a packet to all clients which can see the block entity in order notify clients about a change.
|
||||
|
@ -111,9 +113,15 @@ public final class PlayerLookup {
|
|||
|
||||
if (manager instanceof ServerChunkManager) {
|
||||
ThreadedAnvilChunkStorage storage = ((ServerChunkManager) manager).threadedAnvilChunkStorage;
|
||||
EntityTrackerAccessor tracker = ((ThreadedAnvilChunkStorageAccessor) storage).getEntityTrackers().get(entity.getEntityId());
|
||||
|
||||
// return an immutable collection to guard against accidental removals.
|
||||
return Collections.unmodifiableCollection(((ThreadedAnvilChunkStorageTrackingExtensions) storage).fabric_getTrackingPlayers(entity));
|
||||
if (tracker != null) {
|
||||
return Collections.unmodifiableCollection(tracker.getPlayersTracking()
|
||||
.stream().map(class_5629::method_32311).collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Only supported on server worlds!");
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.mixin.networking;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
|
||||
|
||||
import net.fabricmc.fabric.impl.networking.ThreadedAnvilChunkStorageTrackingExtensions;
|
||||
import net.fabricmc.fabric.mixin.networking.accessor.EntityTrackerAccessor;
|
||||
|
||||
@Mixin(ThreadedAnvilChunkStorage.class)
|
||||
abstract class ThreadedAnvilChunkStorageMixin implements ThreadedAnvilChunkStorageTrackingExtensions {
|
||||
@Shadow
|
||||
@Final
|
||||
// We can abuse type erasure here and just get the type in the map as the accessor.
|
||||
// This allows us to avoid an access widener for the package-private `EntityTracker` subclass.
|
||||
private Int2ObjectMap<EntityTrackerAccessor> entityTrackers;
|
||||
|
||||
@Override
|
||||
public Collection<ServerPlayerEntity> fabric_getTrackingPlayers(Entity entity) {
|
||||
EntityTrackerAccessor accessor = this.entityTrackers.get(entity.getEntityId());
|
||||
|
||||
if (accessor != null) {
|
||||
return accessor.getPlayersTracking();
|
||||
}
|
||||
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
|
@ -21,10 +21,10 @@ import java.util.Set;
|
|||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.class_5629;
|
||||
|
||||
@Mixin(targets = "net/minecraft/server/world/ThreadedAnvilChunkStorage$EntityTracker")
|
||||
public interface EntityTrackerAccessor {
|
||||
@Accessor
|
||||
Set<ServerPlayerEntity> getPlayersTracking();
|
||||
Set<class_5629> getPlayersTracking();
|
||||
}
|
||||
|
|
|
@ -14,13 +14,16 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.impl.networking;
|
||||
package net.fabricmc.fabric.mixin.networking.accessor;
|
||||
|
||||
import java.util.Collection;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
|
||||
|
||||
public interface ThreadedAnvilChunkStorageTrackingExtensions {
|
||||
Collection<ServerPlayerEntity> fabric_getTrackingPlayers(Entity entity);
|
||||
@Mixin(ThreadedAnvilChunkStorage.class)
|
||||
public interface ThreadedAnvilChunkStorageAccessor {
|
||||
@Accessor
|
||||
Int2ObjectMap<EntityTrackerAccessor> getEntityTrackers();
|
||||
}
|
|
@ -8,12 +8,12 @@
|
|||
"PlayerManagerMixin",
|
||||
"ServerLoginNetworkHandlerMixin",
|
||||
"ServerPlayNetworkHandlerMixin",
|
||||
"ThreadedAnvilChunkStorageMixin",
|
||||
"accessor.CustomPayloadC2SPacketAccessor",
|
||||
"accessor.EntityTrackerAccessor",
|
||||
"accessor.LoginQueryRequestS2CPacketAccessor",
|
||||
"accessor.LoginQueryResponseC2SPacketAccessor",
|
||||
"accessor.ServerLoginNetworkHandlerAccessor"
|
||||
"accessor.ServerLoginNetworkHandlerAccessor",
|
||||
"accessor.ThreadedAnvilChunkStorageAccessor"
|
||||
],
|
||||
"client": [
|
||||
"accessor.ConnectScreenAccessor",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue