-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathEntityCockroachEgg.java
More file actions
79 lines (67 loc) · 3.26 KB
/
Copy pathEntityCockroachEgg.java
File metadata and controls
79 lines (67 loc) · 3.26 KB
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
package com.github.alexthe666.alexsmobs.entity;
import com.github.alexthe666.alexsmobs.item.AMItemRegistry;
import net.minecraft.core.particles.ItemParticleOption;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.HitResult;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PlayMessages;
public class EntityCockroachEgg extends ThrowableItemProjectile {
public EntityCockroachEgg(EntityType p_i50154_1_, Level p_i50154_2_) {
super(p_i50154_1_, p_i50154_2_);
}
public EntityCockroachEgg(Level worldIn, LivingEntity throwerIn) {
super(AMEntityRegistry.COCKROACH_EGG.get(), throwerIn, worldIn);
}
public EntityCockroachEgg(Level worldIn, double x, double y, double z) {
super(AMEntityRegistry.COCKROACH_EGG.get(), x, y, z, worldIn);
}
public EntityCockroachEgg(PlayMessages.SpawnEntity spawnEntity, Level world) {
this(AMEntityRegistry.COCKROACH_EGG.get(), world);
}
@Override
public Packet<ClientGamePacketListener> getAddEntityPacket() {
return (Packet<ClientGamePacketListener>) NetworkHooks.getEntitySpawningPacket(this);
}
@OnlyIn(Dist.CLIENT)
public void handleEntityEvent(byte id) {
if (id == 3) {
for (int i = 0; i < 8; ++i) {
this.level().addParticle(new ItemParticleOption(ParticleTypes.ITEM, this.getItem()), this.getX(), this.getY(), this.getZ(), ((double)this.random.nextFloat() - 0.5D) * 0.08D, ((double)this.random.nextFloat() - 0.5D) * 0.08D, ((double)this.random.nextFloat() - 0.5D) * 0.08D);
}
}
}
protected void onHit(HitResult result) {
super.onHit(result);
if (!this.level().isClientSide) {
this.level().broadcastEntityEvent(this, (byte)3);
int i = random.nextInt(3);
for (int j = 0; j < i; ++j) {
final EntityCockroach croc = AMEntityRegistry.COCKROACH.get().create(this.level());
croc.setAge(-24000);
croc.moveTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), 0.0F);
croc.finalizeSpawn((ServerLevel)level(), level().getCurrentDifficultyAt(this.blockPosition()), MobSpawnType.TRIGGERED, (SpawnGroupData)null, (CompoundTag)null);
croc.restrictTo(this.blockPosition(), 20);
croc.setBreaded(true);
this.level().addFreshEntity(croc);
}
this.level().broadcastEntityEvent(this, (byte)3);
this.remove(RemovalReason.DISCARDED);
}
}
protected Item getDefaultItem() {
return AMItemRegistry.COCKROACH_OOTHECA.get();
}
}