Search in sources :

Example 1 with EntitySnowman

use of net.minecraft.entity.monster.EntitySnowman in project Tale-of-Kingdoms by Ivasik78.

the class EntitySantaClaus method onDeath.

@Override
public void onDeath(DamageSource damageSource) {
    if (!worldObj.isRemote) {
        if (damageSource.getSourceOfDamage() instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) damageSource.getEntity();
            player.addChatMessage(new ChatComponentTranslation("npc.santa.badKid.dialog"));
            player.dropItem(Items.coal, worldObj.rand.nextInt(32));
            PlayerProvider.get(player).badKid = true;
            IntStream.range(1, rand.nextInt(5)).mapToObj(i -> new EntitySnowman(worldObj)).forEach(golem -> {
                golem.setLocationAndAngles(this.posX, this.posY, this.posZ, 0.0F, 0.0F);
                golem.setAttackTarget(player);
                worldObj.spawnEntityInWorld(golem);
            });
        }
    }
}
Also used : IntStream(java.util.stream.IntStream) Entity(net.minecraft.entity.Entity) Blocks(net.minecraft.init.Blocks) MathHelper(net.minecraft.util.MathHelper) PlayerProvider(kingdoms.server.PlayerProvider) Items(net.minecraft.init.Items) Item(net.minecraft.item.Item) World(net.minecraft.world.World) Date(java.util.Date) EntityNPC(kingdoms.api.entities.EntityNPC) DamageSource(net.minecraft.util.DamageSource) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) Calendar(java.util.Calendar) Material(net.minecraft.block.material.Material) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntitySnowman(net.minecraft.entity.monster.EntitySnowman) TileEntity(net.minecraft.tileentity.TileEntity) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) EntitySnowman(net.minecraft.entity.monster.EntitySnowman) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 2 with EntitySnowman

use of net.minecraft.entity.monster.EntitySnowman in project Tale-of-Kingdoms by Ivasik78.

the class EntitySantaClaus method onUpdate.

@Override
public void onUpdate() {
    super.onUpdate();
    if (!worldObj.isRemote) {
        int posX, posY, posZ;
        --timer;
        for (int l = 0; l < 4; ++l) {
            posX = MathHelper.floor_double(this.posX + (double) ((float) (l % 2 * 2 - 1) * 0.25F));
            posY = MathHelper.floor_double(this.posY);
            posZ = MathHelper.floor_double(this.posZ + (double) ((float) (l / 2 % 2 * 2 - 1) * 0.25F));
            if (this.worldObj.getBlock(posX, posY, posZ).getMaterial() == Material.air && Blocks.snow_layer.canPlaceBlockAt(this.worldObj, posX, posY, posZ))
                this.worldObj.setBlock(posX, posY, posZ, Blocks.snow_layer);
        }
        List<Entity> list = worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(30, 30, 30));
        for (Entity entity : list) {
            if (entity instanceof EntityPlayer) {
                EntityPlayer player = (EntityPlayer) entity;
                if (player.getDistanceToEntity(this) > 2F && player.getDistanceToEntity(this) < 8F) {
                    if (timer <= 0) {
                        if (!PlayerProvider.get(player).badKid) {
                            this.dropItem(Items.cookie, worldObj.rand.nextInt(25));
                            this.worldObj.setBlock((int) this.posX - 1, (int) this.posY, (int) this.posZ - 1, Blocks.cake);
                            if (worldObj.rand.nextInt(4) == 2) {
                                this.worldObj.setBlock((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1, Blocks.chest);
                                TileEntity te = worldObj.getTileEntity((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1);
                                if (te instanceof TileEntityChest) {
                                    IntStream.range(worldObj.rand.nextInt(25), worldObj.rand.nextInt(27)).forEach(i -> {
                                        Item item = stacks.get(i) == null ? Item.getItemFromBlock(Blocks.air) : stacks.get(i);
                                        ((TileEntityChest) te).setInventorySlotContents(i, new ItemStack(item, i));
                                    });
                                }
                            }
                        } else {
                            this.dropItem(Items.coal, worldObj.rand.nextInt(25));
                            EntitySnowman golem = new EntitySnowman(worldObj);
                            golem.setPosition(this.posX, this.posY, this.posZ);
                            golem.setAttackTarget(player);
                            worldObj.spawnEntityInWorld(golem);
                        }
                        timer = 6000;
                    }
                    if (timer < 0) {
                        timer = 6000;
                    }
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EntitySnowman(net.minecraft.entity.monster.EntitySnowman) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) Item(net.minecraft.item.Item) TileEntityChest(net.minecraft.tileentity.TileEntityChest) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Aggregations

Entity (net.minecraft.entity.Entity)2 EntitySnowman (net.minecraft.entity.monster.EntitySnowman)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 Item (net.minecraft.item.Item)2 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 TileEntityChest (net.minecraft.tileentity.TileEntityChest)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 List (java.util.List)1 IntStream (java.util.stream.IntStream)1 EntityNPC (kingdoms.api.entities.EntityNPC)1 PlayerProvider (kingdoms.server.PlayerProvider)1 Material (net.minecraft.block.material.Material)1 Blocks (net.minecraft.init.Blocks)1 Items (net.minecraft.init.Items)1 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)1 DamageSource (net.minecraft.util.DamageSource)1 MathHelper (net.minecraft.util.MathHelper)1