forked from FabricMC/fabric
as of 19w05a, spawn packets are provided by entities themselves
This commit is contained in:
parent
f1fa5cfd3c
commit
a3bd0bb883
2 changed files with 7 additions and 50 deletions
|
@ -19,6 +19,8 @@ package net.fabricmc.fabric.entity;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
import net.minecraft.network.Packet;
|
import net.minecraft.network.Packet;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -26,6 +28,7 @@ import java.util.function.Function;
|
||||||
|
|
||||||
// TODO: javadocs
|
// TODO: javadocs
|
||||||
public class EntityTrackingRegistry {
|
public class EntityTrackingRegistry {
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
public static class Entry {
|
public static class Entry {
|
||||||
private final int trackingDistance;
|
private final int trackingDistance;
|
||||||
private final int updateIntervalTicks;
|
private final int updateIntervalTicks;
|
||||||
|
@ -52,7 +55,6 @@ public class EntityTrackingRegistry {
|
||||||
|
|
||||||
public static final EntityTrackingRegistry INSTANCE = new EntityTrackingRegistry();
|
public static final EntityTrackingRegistry INSTANCE = new EntityTrackingRegistry();
|
||||||
private final Map<EntityType, Entry> entries = new HashMap<>();
|
private final Map<EntityType, Entry> entries = new HashMap<>();
|
||||||
private final Map<EntityType, Function<Entity, Packet>> spawnPacketProviders = new HashMap<>();
|
|
||||||
|
|
||||||
private EntityTrackingRegistry() {
|
private EntityTrackingRegistry() {
|
||||||
|
|
||||||
|
@ -62,14 +64,10 @@ public class EntityTrackingRegistry {
|
||||||
return entries.get(type);
|
return entries.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public Packet createSpawnPacket(Entity entity) {
|
public Packet createSpawnPacket(Entity entity) {
|
||||||
Function<Entity, Packet> packetFunction = spawnPacketProviders.get(entity.getType());
|
|
||||||
if (packetFunction != null) {
|
|
||||||
return packetFunction.apply(entity);
|
|
||||||
} else {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void register(EntityType type, int trackingDistance, int updateIntervalTicks) {
|
public void register(EntityType type, int trackingDistance, int updateIntervalTicks) {
|
||||||
register(type, trackingDistance, updateIntervalTicks, true);
|
register(type, trackingDistance, updateIntervalTicks, true);
|
||||||
|
@ -79,7 +77,8 @@ public class EntityTrackingRegistry {
|
||||||
entries.put(type, new Entry(trackingDistance, updateIntervalTicks, alwaysUpdateVelocity));
|
entries.put(type, new Entry(trackingDistance, updateIntervalTicks, alwaysUpdateVelocity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public void registerSpawnPacketProvider(EntityType type, Function<Entity, Packet> packetFunction) {
|
public void registerSpawnPacketProvider(EntityType type, Function<Entity, Packet> packetFunction) {
|
||||||
spawnPacketProviders.put(type, packetFunction);
|
LOGGER.warn("[EntityTrackingRegistry] As of 19w05a, registerSpawnPacketProvider is a no-op! Update your mod!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2016, 2017, 2018 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.entity;
|
|
||||||
|
|
||||||
import net.fabricmc.fabric.entity.EntityTrackingRegistry;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.network.Packet;
|
|
||||||
import net.minecraft.server.network.EntityTrackerEntry;
|
|
||||||
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.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
@Mixin(EntityTrackerEntry.class)
|
|
||||||
public class MixinEntityTrackerEntry {
|
|
||||||
@Shadow
|
|
||||||
private Entity entity;
|
|
||||||
|
|
||||||
@Inject(at = @At(value = "CONSTANT", args = {"stringValue=Don't know how to add "}), method = "createSpawnPacket", cancellable = true)
|
|
||||||
public void createSpawnPacket(CallbackInfoReturnable<Packet> info) {
|
|
||||||
Packet packet = EntityTrackingRegistry.INSTANCE.createSpawnPacket(entity);
|
|
||||||
if (packet != null) {
|
|
||||||
info.setReturnValue(packet);
|
|
||||||
info.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue