This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 33
/
TadpoleEntity.java
118 lines (102 loc) · 2.91 KB
/
TadpoleEntity.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package party.lemons.biomemakeover.entity;
import net.minecraft.entity.attribute.AttributeContainer;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.passive.FishEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.World;
import party.lemons.biomemakeover.init.BMEntities;
import party.lemons.biomemakeover.init.BMItems;
public class TadpoleEntity extends FishEntity
{
private AttributeContainer attributeContainer;
private int babyTime = -6000;
public TadpoleEntity(World world)
{
super(BMEntities.TADPOLE, world);
}
@Override
public void tick()
{
super.tick();
if(!world.isClient())
{
babyTime++;
if(!isBaby())
{
ToadEntity toad = BMEntities.TOAD.create(world);
toad.refreshPositionAndAngles(this.getX(), this.getY(), this.getZ(), bodyYaw, pitch);
toad.addStatusEffect(new StatusEffectInstance(StatusEffects.WATER_BREATHING, 200, 0));
((ServerWorld)world).spawnEntityAndPassengers(toad);
remove();
}
}
}
public ActionResult interactMob(PlayerEntity player, Hand hand) {
ItemStack itemStack = player.getStackInHand(hand);
if (!itemStack.isEmpty() && itemStack.getItem() == BMItems.DRAGONFLY_WINGS)
{
if (this.isBaby()) {
itemStack.decrement(1);
this.growUp(Math.abs(babyTime / 20));
return ActionResult.success(this.world.isClient);
}
if (this.world.isClient) {
return ActionResult.CONSUME;
}
}
return super.interactMob(player, hand);
}
public void growUp(int age) {
babyTime += age;
}
@Override
public void setBaby(boolean baby)
{
babyTime = baby ? -24000 : 0;
}
@Override
public boolean isBaby() {
return babyTime < 0;
}
@Override
public void writeCustomDataToTag(CompoundTag tag)
{
super.writeCustomDataToTag(tag);
tag.putInt("BabyTime", babyTime);
}
@Override
public void readCustomDataFromTag(CompoundTag tag)
{
super.readCustomDataFromTag(tag);
if(tag.contains("BabyTime"))
babyTime = tag.getInt("BabyTime");
}
@Override
protected ItemStack getFishBucketItem()
{
return new ItemStack(BMItems.TADPOLE_BUCKET);
}
@Override
protected SoundEvent getFlopSound()
{
return SoundEvents.ENTITY_TROPICAL_FISH_FLOP;
}
@Override
public AttributeContainer getAttributes()
{
if(attributeContainer == null)
attributeContainer = new AttributeContainer(
MobEntity.createMobAttributes().add(EntityAttributes.GENERIC_MAX_HEALTH, 10.0D).add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.25D).build());
return attributeContainer;
}
}