Skip to content

Commit ccd80fd

Browse files
Merge pull request CloudburstMC#914 from PowerNukkit/v1.4/feature/iron-golem
Adds Iron Golem
2 parents 439e94e + 9ad96eb commit ccd80fd

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

src/main/java/cn/nukkit/Server.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,6 +2508,7 @@ private void registerEntities() {
25082508
Entity.registerEntity("Silverfish", EntitySilverfish.class);
25092509
Entity.registerEntity("Skeleton", EntitySkeleton.class);
25102510
Entity.registerEntity("Slime", EntitySlime.class);
2511+
Entity.registerEntity("IronGolem", EntityIronGolem.class);
25112512
Entity.registerEntity("SnowGolem", EntitySnowGolem.class);
25122513
Entity.registerEntity("Spider", EntitySpider.class);
25132514
Entity.registerEntity("Stray", EntityStray.class);
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* https://PowerNukkit.org - The Nukkit you know but Powerful!
3+
* Copyright (C) 2020 José Roberto de Araújo Júnior
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package cn.nukkit.entity.mob;
20+
21+
import cn.nukkit.api.PowerNukkitOnly;
22+
import cn.nukkit.api.Since;
23+
import cn.nukkit.block.BlockID;
24+
import cn.nukkit.item.Item;
25+
import cn.nukkit.item.ItemID;
26+
import cn.nukkit.level.format.FullChunk;
27+
import cn.nukkit.nbt.tag.CompoundTag;
28+
29+
import javax.annotation.Nonnull;
30+
import java.util.concurrent.ThreadLocalRandom;
31+
32+
/**
33+
* @author joserobjr
34+
* @since 2021-01-13
35+
*/
36+
@PowerNukkitOnly
37+
@Since("1.4.0.0-PN")
38+
public class EntityIronGolem extends EntityMob {
39+
@PowerNukkitOnly
40+
@Since("1.4.0.0-PN")
41+
public static final int NETWORK_ID = 20;
42+
43+
@PowerNukkitOnly
44+
@Since("1.4.0.0-PN")
45+
public EntityIronGolem(FullChunk chunk, CompoundTag nbt) {
46+
super(chunk, nbt);
47+
}
48+
49+
@Override
50+
public int getNetworkId() {
51+
return NETWORK_ID;
52+
}
53+
54+
@Nonnull
55+
@Override
56+
public String getName() {
57+
return "Iron Golem";
58+
}
59+
60+
@Override
61+
public float getWidth() {
62+
return 1.4f;
63+
}
64+
65+
@Override
66+
public float getHeight() {
67+
return 2.9f;
68+
}
69+
70+
@Override
71+
protected void initEntity() {
72+
super.initEntity();
73+
this.setMaxHealth(100);
74+
this.setHealth(100);
75+
}
76+
77+
@Override
78+
public Item[] getDrops() {
79+
// Item drops
80+
ThreadLocalRandom random = ThreadLocalRandom.current();
81+
int flowerAmount = random.nextInt(3);
82+
Item[] drops;
83+
if (flowerAmount > 0) {
84+
drops = new Item[2];
85+
drops[1] = Item.getBlock(BlockID.RED_FLOWER, 0, flowerAmount);
86+
} else {
87+
drops = new Item[1];
88+
}
89+
90+
drops[0] = Item.get(ItemID.IRON_INGOT, 0, random.nextInt(3, 6));
91+
92+
return drops;
93+
}
94+
}

0 commit comments

Comments
 (0)