forked from FrostDracony/NewFantasyMod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnicornEntity.java
82 lines (72 loc) · 3.2 KB
/
UnicornEntity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package mod.dragonita.fantasymod.entities;
import net.minecraft.entity.AgeableEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.goal.PanicGoal;
import net.minecraft.entity.passive.horse.AbstractHorseEntity;
import net.minecraft.entity.passive.horse.HorseEntity;
import net.minecraft.network.IPacket;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
import net.minecraftforge.fml.network.FMLPlayMessages;
import net.minecraftforge.fml.network.NetworkHooks;
public class UnicornEntity extends HorseEntity{
public static DataParameter<Boolean> PANIC = EntityDataManager.createKey(UnicornEntity.class, DataSerializers.BOOLEAN);
//private static Logger LOGGER = Main.LOGGER;
public UnicornEntity(final EntityType<? extends UnicornEntity> entityType, final World world) {
super(entityType, world);
dataManager.register(PANIC, false);
}
@Override
protected void registerAttributes() {
super.registerAttributes();
final double baseSpeed = this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getBaseValue();
final double baseHealth = this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).getBaseValue();
// Multiply base health and base speed by one and a half
this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(baseSpeed * 1.5D);
this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(baseHealth * 1.5D);
}
public boolean isPanic() {
return this.goalSelector.getRunningGoals().anyMatch(goal -> goal.getGoal().getClass() == PanicGoal.class);
}
@Override
public void tick() {
super.tick();
if (!world.isRemote) {
if (isPanic() && !dataManager.get(PANIC)) {
dataManager.set(PANIC, true);
} else dataManager.set(PANIC, false);
}
}
/**
* Creates a child new entity from the parent entity.
* Can be used to set additional on the child entity based on the parent.
*
* @param parent The entity that made this child
* @return A new Unicorn
* @see AbstractHorseEntity#setOffspringAttributes(AgeableEntity, AbstractHorseEntity)
*/
@Override
public UnicornEntity createChild(final AgeableEntity parent) {
// Use getType to support overrides in subclasses
return (UnicornEntity)getType().create(this.world);
}
/**
* Called on the logical server to get a packet to send to the client containing data necessary to spawn your entity.
* Using Forge's method instead of the default vanilla one allows extra stuff to work such as sending extra data,
* using a non-default entity factory and having {@link IEntityAdditionalSpawnData} work.
*
* It is not actually necessary for our WildBoarEntity to use Forge's method as it doesn't need any of this extra
* functionality, however, this is an example mod and many modders are unaware that Forge's method exists.
*
* @return The packet with data about your entity
* @see FMLPlayMessages.SpawnEntity
*/
@Override
public IPacket<?> createSpawnPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
}
}