Skip to content

Commit

Permalink
Merge pull request CloudburstMC#914 from PowerNukkit/v1.4/feature/iro…
Browse files Browse the repository at this point in the history
…n-golem

Adds Iron Golem
  • Loading branch information
LoboMetalurgico committed Feb 13, 2021
2 parents 439e94e + 9ad96eb commit ccd80fd
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/cn/nukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -2508,6 +2508,7 @@ private void registerEntities() {
Entity.registerEntity("Silverfish", EntitySilverfish.class);
Entity.registerEntity("Skeleton", EntitySkeleton.class);
Entity.registerEntity("Slime", EntitySlime.class);
Entity.registerEntity("IronGolem", EntityIronGolem.class);
Entity.registerEntity("SnowGolem", EntitySnowGolem.class);
Entity.registerEntity("Spider", EntitySpider.class);
Entity.registerEntity("Stray", EntityStray.class);
Expand Down
94 changes: 94 additions & 0 deletions src/main/java/cn/nukkit/entity/mob/EntityIronGolem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* https://PowerNukkit.org - The Nukkit you know but Powerful!
* Copyright (C) 2020 José Roberto de Araújo Júnior
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package cn.nukkit.entity.mob;

import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.api.Since;
import cn.nukkit.block.BlockID;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemID;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.nbt.tag.CompoundTag;

import javax.annotation.Nonnull;
import java.util.concurrent.ThreadLocalRandom;

/**
* @author joserobjr
* @since 2021-01-13
*/
@PowerNukkitOnly
@Since("1.4.0.0-PN")
public class EntityIronGolem extends EntityMob {
@PowerNukkitOnly
@Since("1.4.0.0-PN")
public static final int NETWORK_ID = 20;

@PowerNukkitOnly
@Since("1.4.0.0-PN")
public EntityIronGolem(FullChunk chunk, CompoundTag nbt) {
super(chunk, nbt);
}

@Override
public int getNetworkId() {
return NETWORK_ID;
}

@Nonnull
@Override
public String getName() {
return "Iron Golem";
}

@Override
public float getWidth() {
return 1.4f;
}

@Override
public float getHeight() {
return 2.9f;
}

@Override
protected void initEntity() {
super.initEntity();
this.setMaxHealth(100);
this.setHealth(100);
}

@Override
public Item[] getDrops() {
// Item drops
ThreadLocalRandom random = ThreadLocalRandom.current();
int flowerAmount = random.nextInt(3);
Item[] drops;
if (flowerAmount > 0) {
drops = new Item[2];
drops[1] = Item.getBlock(BlockID.RED_FLOWER, 0, flowerAmount);
} else {
drops = new Item[1];
}

drops[0] = Item.get(ItemID.IRON_INGOT, 0, random.nextInt(3, 6));

return drops;
}
}

0 comments on commit ccd80fd

Please sign in to comment.