update entity tracking registration code for new snapshot changes (#145)

This commit is contained in:
Adrian Siekierka 2019-04-19 23:52:27 +02:00 committed by GitHub
parent 9ed3b4e145
commit f5024a75c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 79 additions and 15 deletions

View file

@ -19,6 +19,7 @@ package net.fabricmc.fabric.api.entity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.network.Packet;
import net.minecraft.util.registry.Registry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -28,14 +29,14 @@ import java.util.function.Function;
/**
* Registry for server->client entity tracking values.
*
* @deprecated Use FabricEntityTypeBuilder methods
*/
@SuppressWarnings("deprecation")
@Deprecated
public class EntityTrackingRegistry {
private static final Logger LOGGER = LogManager.getLogger();
/**
* @deprecated Should be hidden; will be removed in 0.3.0.
*/
@Deprecated
public static class Entry {
private final int trackingDistance;
@ -61,6 +62,7 @@ public class EntityTrackingRegistry {
}
}
@Deprecated
public static final EntityTrackingRegistry INSTANCE = new EntityTrackingRegistry();
private final Map<EntityType, Entry> entries = new HashMap<>();
@ -68,19 +70,19 @@ public class EntityTrackingRegistry {
}
/**
* @deprecated Should be hidden; will be removed in 0.3.0.
*/
@Deprecated
public Entry get(EntityType type) {
return entries.get(type);
}
@Deprecated
public void register(EntityType type, int trackingDistance, int updateIntervalTicks) {
register(type, trackingDistance, updateIntervalTicks, true);
}
@Deprecated
public void register(EntityType type, int trackingDistance, int updateIntervalTicks, boolean alwaysUpdateVelocity) {
LOGGER.warn("Deprecation warning: As of February 2019, registering tracking via EntityTrackingRegistry is no longer effective. Use FabricEntityTypeBuilder. (Entity: " + Registry.ENTITY_TYPE.getId(type) + ")");
entries.put(type, new Entry(trackingDistance, updateIntervalTicks, alwaysUpdateVelocity));
}
}

View file

@ -16,6 +16,7 @@
package net.fabricmc.fabric.api.entity;
import net.fabricmc.fabric.impl.entity.FabricEntityType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityCategory;
import net.minecraft.entity.EntitySize;
@ -41,7 +42,7 @@ public class FabricEntityTypeBuilder<T extends Entity> {
private boolean summonable = true;
private int trackingDistance = -1;
private int updateIntervalTicks = -1;
private boolean alwaysUpdateVelocity = true;
private Boolean alwaysUpdateVelocity;
private boolean immuneToFire = false;
private EntitySize size = EntitySize.resizeable(-1.0f, -1.0f);
@ -95,12 +96,12 @@ public class FabricEntityTypeBuilder<T extends Entity> {
return this;
}
public FabricEntityTypeBuilder<T> trackable(int trackingDistance, int updateIntervalTicks) {
return trackable(trackingDistance, updateIntervalTicks, true);
public FabricEntityTypeBuilder<T> trackable(int trackingDistanceBlocks, int updateIntervalTicks) {
return trackable(trackingDistanceBlocks, updateIntervalTicks, true);
}
public FabricEntityTypeBuilder<T> trackable(int trackingDistance, int updateIntervalTicks, boolean alwaysUpdateVelocity) {
this.trackingDistance = trackingDistance;
public FabricEntityTypeBuilder<T> trackable(int trackingDistanceBlocks, int updateIntervalTicks, boolean alwaysUpdateVelocity) {
this.trackingDistance = trackingDistanceBlocks;
this.updateIntervalTicks = updateIntervalTicks;
this.alwaysUpdateVelocity = alwaysUpdateVelocity;
return this;
@ -112,10 +113,8 @@ public class FabricEntityTypeBuilder<T extends Entity> {
// TODO: Flesh out once modded datafixers exist.
}
EntityType<T> type = new EntityType<T>(this.function, this.category, this.saveable, this.summonable, this.immuneToFire, null, size);
if (trackingDistance != -1) {
EntityTrackingRegistry.INSTANCE.register(type, trackingDistance, updateIntervalTicks, alwaysUpdateVelocity);
}
EntityType<T> type = new FabricEntityType<T>(this.function, this.category, this.saveable, this.summonable, this.immuneToFire, null, size, trackingDistance, updateIntervalTicks, alwaysUpdateVelocity);
return type;
}
}

View file

@ -0,0 +1,62 @@
/*
* 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.impl.entity;
import com.mojang.datafixers.types.Type;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityCategory;
import net.minecraft.entity.EntitySize;
import net.minecraft.entity.EntityType;
public class FabricEntityType<T extends Entity> extends EntityType<T> {
private final int maxTrackDistance, trackTickInterval;
private final Boolean alwaysUpdateVelocity;
public FabricEntityType(EntityFactory<T> entityType$EntityFactory_1, EntityCategory entityCategory_1, boolean boolean_1, boolean boolean_2, boolean boolean_3, Type<?> type_1, EntitySize entitySize_1, int maxTrackDistance, int trackTickInterval, boolean alwaysUpdateVelocity) {
super(entityType$EntityFactory_1, entityCategory_1, boolean_1, boolean_2, boolean_3, type_1, entitySize_1);
this.maxTrackDistance = maxTrackDistance;
this.trackTickInterval = trackTickInterval;
this.alwaysUpdateVelocity = alwaysUpdateVelocity;
}
@Override
public int getMaxTrackDistance() {
if (maxTrackDistance != -1) {
return (maxTrackDistance + 15) / 16;
}
return super.getMaxTrackDistance();
}
@Override
public int getTrackTickInterval() {
if (trackTickInterval != -1) {
return trackTickInterval;
}
return super.getTrackTickInterval();
}
@Override
public boolean alwaysUpdateVelocity() {
if (alwaysUpdateVelocity != null) {
return alwaysUpdateVelocity;
}
return super.alwaysUpdateVelocity();
}
}

View file

@ -59,6 +59,7 @@ public abstract class MixinSpriteAtlasTexture {
* method_18160 is a lambda used in runAsync.
*/
@SuppressWarnings("JavaDoc")
@Redirect(method = "method_18160", at = @At(value = "NEW", target = "net/minecraft/client/texture/Sprite"))
public Sprite newSprite(Identifier id, PngFile pngFile, AnimationResourceMetadata animationMetadata) {
if (fabric_injectedSprites.containsKey(id)) {