Make customClientFactory optional again (#6191)

This commit is contained in:
Vincent Lee 2019-10-10 13:23:27 -05:00 committed by LexManos
parent 5e9380ab85
commit 7070bd0340
2 changed files with 9 additions and 5 deletions

View file

@ -85,7 +85,7 @@
} }
+ public T customClientSpawn(net.minecraftforge.fml.network.FMLPlayMessages.SpawnEntity packet, World world) { + public T customClientSpawn(net.minecraftforge.fml.network.FMLPlayMessages.SpawnEntity packet, World world) {
+ if (customClientFactory == null) throw new RuntimeException("Missing custom spawn data for entity type "+this); + if (customClientFactory == null) return this.func_200721_a(world);
+ return customClientFactory.apply(packet, world); + return customClientFactory.apply(packet, world);
+ } + }
+ +
@ -111,7 +111,7 @@
private boolean field_225436_f; private boolean field_225436_f;
private EntitySize field_220326_f = EntitySize.func_220314_b(0.6F, 1.8F); private EntitySize field_220326_f = EntitySize.func_220314_b(0.6F, 1.8F);
@@ -553,11 +591,31 @@ @@ -553,11 +591,35 @@
return this; return this;
} }
@ -130,6 +130,10 @@
+ return this; + return this;
+ } + }
+ +
+ /**
+ * By default, entities are spawned clientside via {@link EntityType#create(World)}.
+ * If you need finer control over the spawning process, use this to get read access to the spawn packet.
+ */
+ public EntityType.Builder<T> setCustomClientFactory(java.util.function.BiFunction<net.minecraftforge.fml.network.FMLPlayMessages.SpawnEntity, World, T> customClientFactory) { + public EntityType.Builder<T> setCustomClientFactory(java.util.function.BiFunction<net.minecraftforge.fml.network.FMLPlayMessages.SpawnEntity, World, T> customClientFactory) {
+ this.customClientFactory = customClientFactory; + this.customClientFactory = customClientFactory;
+ return this; + return this;
@ -144,7 +148,7 @@
if (SharedConstants.field_206244_b) { if (SharedConstants.field_206244_b) {
throw illegalstateexception; throw illegalstateexception;
} }
@@ -566,7 +624,7 @@ @@ -566,7 +628,7 @@
} }
} }

View file

@ -52,8 +52,8 @@ public class FMLPlayMessages
* Used to spawn a custom entity without the same restrictions as * Used to spawn a custom entity without the same restrictions as
* {@link net.minecraft.network.play.server.SSpawnObjectPacket} or {@link net.minecraft.network.play.server.SSpawnMobPacket} * {@link net.minecraft.network.play.server.SSpawnObjectPacket} or {@link net.minecraft.network.play.server.SSpawnMobPacket}
* *
* Ensure your {@link EntityType} registration supplies a {@link EntityType.Builder#customClientFactory} or the * To customize how your entity is created clientside (instead of using the default factory provided to the {@link EntityType})
* mob won't actually spawn on the client. * see {@link EntityType.Builder#setCustomClientFactory}.
*/ */
public static class SpawnEntity public static class SpawnEntity
{ {