Fix FML entity network spawning not using EntityBuilder's facctory. Closes #4845 and #4846

This commit is contained in:
LexManos 2018-06-27 12:51:06 -07:00
parent 464cccaa3e
commit 74c3aab720
4 changed files with 41 additions and 18 deletions

View file

@ -266,13 +266,13 @@
}
},
{
"name": "com.mojang:realms:1.10.21",
"name": "com.mojang:realms:1.10.22",
"downloads": {
"artifact": {
"size": 7134971,
"sha1": "cfc457545a482027c066f13c262b9a4df64bc3f3",
"path": "com/mojang/realms/1.10.21/realms-1.10.21.jar",
"url": "https://libraries.minecraft.net/com/mojang/realms/1.10.21/realms-1.10.21.jar"
"size": 7135057,
"sha1": "bd0dccebdf3744c75f1ca20063f16e8f7d5e663f",
"path": "com/mojang/realms/1.10.22/realms-1.10.22.jar",
"url": "https://libraries.minecraft.net/com/mojang/realms/1.10.22/realms-1.10.22.jar"
}
}
},
@ -719,6 +719,6 @@
"minecraftArguments": "--username ${auth_player_name} --version ${version_name} --gameDir ${game_directory} --assetsDir ${assets_root} --assetIndex ${assets_index_name} --uuid ${auth_uuid} --accessToken ${auth_access_token} --userType ${user_type} --versionType ${version_type}",
"minimumLauncherVersion": 18,
"releaseTime": "2017-09-18T08:39:46+00:00",
"time": "2018-05-25T15:20:02+00:00",
"time": "2018-06-25T15:37:20+00:00",
"type": "release"
}

View file

@ -76,7 +76,6 @@ public class EntitySpawnHandler extends SimpleChannelInboundHandler<FMLMessage.E
" at ( " + spawnMsg.rawX + "," + spawnMsg.rawY + ", " + spawnMsg.rawZ + ") Please contact mod author or server admin.");
}
WorldClient wc = FMLClientHandler.instance().getWorldClient();
Class<? extends Entity> cls = er.getEntityClass();
try
{
Entity entity;
@ -85,7 +84,7 @@ public class EntitySpawnHandler extends SimpleChannelInboundHandler<FMLMessage.E
entity = er.doCustomSpawning(spawnMsg);
} else
{
entity = cls.getConstructor(World.class).newInstance(wc);
entity = er.newInstance(wc);
int offset = spawnMsg.entityId - entity.getEntityId();
entity.setEntityId(spawnMsg.entityId);

View file

@ -276,15 +276,6 @@ public final class EntityEntryBuilder<E extends Entity>
return entry;
}
@Nonnull
private EntityRegistry.EntityRegistration createRegistration()
{
return EntityRegistry.instance().new EntityRegistration(
this.mod, this.id, this.entity, this.name, this.network,
this.trackingRange, this.trackingUpdateFrequency, this.trackingVelocityUpdates
);
}
private void registerStatistics()
{
if (!this.statisticsRegistered && (this.killEntityStatistic != null && this.entityKilledByStatistic != null))
@ -340,7 +331,7 @@ public final class EntityEntryBuilder<E extends Entity>
if (this.added) return;
this.added = true;
EntityEntryBuilder.this.registerStatistics();
EntityRegistry.instance().insert(EntityEntryBuilder.this.entity, EntityEntryBuilder.this.createRegistration());
EntityRegistry.instance().insert(EntityEntryBuilder.this.entity, createRegistration());
if (EntityEntryBuilder.this.spawns != null)
{
for (final Spawn spawn : EntityEntryBuilder.this.spawns)
@ -350,6 +341,17 @@ public final class EntityEntryBuilder<E extends Entity>
EntityEntryBuilder.this.spawns = null;
}
}
@Nonnull
private EntityRegistry.EntityRegistration createRegistration()
{
EntityEntryBuilder<E> builder = EntityEntryBuilder.this;
return EntityRegistry.instance().new EntityRegistration(
builder.mod, builder.id, builder.entity, builder.name, builder.network,
builder.trackingRange, builder.trackingUpdateFrequency, builder.trackingVelocityUpdates, this.factory
);
}
}
public final class Spawn

View file

@ -29,6 +29,7 @@ import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityTracker;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biome.SpawnListEntry;
import net.minecraftforge.fml.common.FMLCommonHandler;
@ -48,7 +49,9 @@ public class EntityRegistry
{
public class EntityRegistration
{
@Deprecated
private Class<? extends Entity> entityClass;
private Function<World, ? extends Entity> factory;
private ModContainer container;
private ResourceLocation regName;
private String entityName;
@ -58,7 +61,14 @@ public class EntityRegistry
private boolean sendsVelocityUpdates;
private Function<EntitySpawnMessage, Entity> customSpawnCallback;
private boolean usesVanillaSpawning;
@Deprecated //1.13
public EntityRegistration(ModContainer mc, ResourceLocation registryName, Class<? extends Entity> entityClass, String entityName, int id, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates)
{
this(mc, registryName, entityClass, entityName, id, trackingRange, updateFrequency, sendsVelocityUpdates, null);
}
public EntityRegistration(ModContainer mc, ResourceLocation registryName, Class<? extends Entity> entityClass, String entityName, int id, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates, Function<World, ? extends Entity> factory)
{
this.container = mc;
this.regName = registryName;
@ -68,15 +78,27 @@ public class EntityRegistry
this.trackingRange = trackingRange;
this.updateFrequency = updateFrequency;
this.sendsVelocityUpdates = sendsVelocityUpdates;
this.factory = factory != null ? factory :
new EntityEntryBuilder.ConstructorFactory<Entity>(entityClass) {
@Override
protected String describeEntity() {
return String.valueOf(EntityRegistration.this.getRegistryName());
}
};
}
public ResourceLocation getRegistryName()
{
return regName;
}
@Deprecated //Used only for creating a new instance in EntitySpawnHandler, use newInstance(world) instead.
public Class<? extends Entity> getEntityClass()
{
return entityClass;
}
public Entity newInstance(World world)
{
return this.factory.apply(world);
}
public ModContainer getContainer()
{
return container;