Skip to content

Commit ad6f942

Browse files
committed
Update WildBoarEntity.java
1 parent 4ef1557 commit ad6f942

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed
Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
package io.github.cadiboo.examplemod.entity;
22

3-
import io.github.cadiboo.examplemod.init.ModEntityTypes;
43
import net.minecraft.entity.AgeableEntity;
54
import net.minecraft.entity.EntityType;
65
import net.minecraft.entity.SharedMonsterAttributes;
76
import net.minecraft.entity.passive.PigEntity;
7+
import net.minecraft.entity.passive.horse.AbstractHorseEntity;
8+
import net.minecraft.network.IPacket;
89
import net.minecraft.world.World;
10+
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
11+
import net.minecraftforge.fml.network.FMLPlayMessages;
12+
import net.minecraftforge.fml.network.NetworkHooks;
913

1014
/**
1115
* A Wild Boar entity.
1216
* Literally just a pig (with a different texture).
13-
* TODO: Will have more stuff added to it soon.
17+
* TODO: Will have more stuff added to it soon. (Will charge at player
1418
*
1519
* @author Cadiboo
1620
*/
@@ -20,10 +24,6 @@ public WildBoarEntity(final EntityType<? extends WildBoarEntity> entityType, fin
2024
super(entityType, world);
2125
}
2226

23-
public WildBoarEntity(final World world) {
24-
super(ModEntityTypes.WILD_BOAR.get(), world);
25-
}
26-
2727
@Override
2828
protected void registerAttributes() {
2929
super.registerAttributes();
@@ -35,10 +35,34 @@ protected void registerAttributes() {
3535
this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(baseHealth * 1.5D);
3636
}
3737

38+
/**
39+
* Creates a child new entity from the parent entity.
40+
* Can be used to set additional on the child entity based on the parent.
41+
*
42+
* @param parent The entity that made this child
43+
* @return A new WildBoar
44+
* @see AbstractHorseEntity#setOffspringAttributes(AgeableEntity, AbstractHorseEntity)
45+
*/
3846
@Override
39-
public WildBoarEntity createChild(AgeableEntity parent) {
47+
public WildBoarEntity createChild(final AgeableEntity parent) {
4048
// Use getType to support overrides in subclasses
4149
return (WildBoarEntity) getType().create(this.world);
4250
}
4351

52+
/**
53+
* Called on the logical server to get a packet to send to the client containing data necessary to spawn your entity.
54+
* Using Forge's method instead of the default vanilla one allows extra stuff to work such as sending extra data,
55+
* using a non-default entity factory and having {@link IEntityAdditionalSpawnData} work.
56+
*
57+
* It is not actually necessary for our WildBoarEntity to use Forge's method as it doesn't need any of this extra
58+
* functionality, however, this is an example mod and many modders are unaware that Forge's method exists.
59+
*
60+
* @return The packet with data about your entity
61+
* @see FMLPlayMessages.SpawnEntity
62+
*/
63+
@Override
64+
public IPacket<?> createSpawnPacket() {
65+
return NetworkHooks.getEntitySpawningPacket(this);
66+
}
67+
4468
}

0 commit comments

Comments
 (0)